[XFS] Show buffer address with debug hexdump on corruption
[deliverable/linux.git] / fs / xfs / linux-2.6 / xfs_super.c
CommitLineData
1da177e4 1/*
a805bad5 2 * Copyright (c) 2000-2006 Silicon Graphics, Inc.
7b718769 3 * All Rights Reserved.
1da177e4 4 *
7b718769
NS
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
1da177e4
LT
7 * published by the Free Software Foundation.
8 *
7b718769
NS
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
1da177e4 13 *
7b718769
NS
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1da177e4 17 */
1da177e4 18#include "xfs.h"
a844f451 19#include "xfs_bit.h"
1da177e4
LT
20#include "xfs_log.h"
21#include "xfs_clnt.h"
a844f451 22#include "xfs_inum.h"
1da177e4
LT
23#include "xfs_trans.h"
24#include "xfs_sb.h"
a844f451 25#include "xfs_ag.h"
1da177e4
LT
26#include "xfs_dir2.h"
27#include "xfs_alloc.h"
28#include "xfs_dmapi.h"
29#include "xfs_quota.h"
30#include "xfs_mount.h"
1da177e4 31#include "xfs_bmap_btree.h"
a844f451 32#include "xfs_alloc_btree.h"
1da177e4 33#include "xfs_ialloc_btree.h"
1da177e4 34#include "xfs_dir2_sf.h"
a844f451 35#include "xfs_attr_sf.h"
1da177e4
LT
36#include "xfs_dinode.h"
37#include "xfs_inode.h"
a844f451 38#include "xfs_btree.h"
8c4ed633 39#include "xfs_btree_trace.h"
a844f451 40#include "xfs_ialloc.h"
1da177e4 41#include "xfs_bmap.h"
1da177e4
LT
42#include "xfs_rtalloc.h"
43#include "xfs_error.h"
44#include "xfs_itable.h"
9909c4aa 45#include "xfs_fsops.h"
1da177e4
LT
46#include "xfs_rw.h"
47#include "xfs_acl.h"
1da177e4
LT
48#include "xfs_attr.h"
49#include "xfs_buf_item.h"
50#include "xfs_utils.h"
739bfb2a 51#include "xfs_vnodeops.h"
745f6919 52#include "xfs_vfsops.h"
1da177e4 53#include "xfs_version.h"
a67d7c5f 54#include "xfs_log_priv.h"
249a8c11 55#include "xfs_trans_priv.h"
48b62a1a 56#include "xfs_filestream.h"
9f8868ff
CH
57#include "xfs_da_btree.h"
58#include "xfs_dir2_trace.h"
59#include "xfs_extfree_item.h"
60#include "xfs_mru_cache.h"
61#include "xfs_inode_item.h"
1da177e4
LT
62
63#include <linux/namei.h>
64#include <linux/init.h>
65#include <linux/mount.h>
0829c360 66#include <linux/mempool.h>
1da177e4 67#include <linux/writeback.h>
4df08c52 68#include <linux/kthread.h>
7dfb7103 69#include <linux/freezer.h>
62a877e3 70#include <linux/parser.h>
1da177e4 71
7989cb8e
DC
72static struct quotactl_ops xfs_quotactl_operations;
73static struct super_operations xfs_super_operations;
74static kmem_zone_t *xfs_vnode_zone;
75static kmem_zone_t *xfs_ioend_zone;
0829c360 76mempool_t *xfs_ioend_pool;
1da177e4
LT
77
78STATIC struct xfs_mount_args *
79xfs_args_allocate(
764d1f89
NS
80 struct super_block *sb,
81 int silent)
1da177e4
LT
82{
83 struct xfs_mount_args *args;
84
bdd907ba
CH
85 args = kzalloc(sizeof(struct xfs_mount_args), GFP_KERNEL);
86 if (!args)
87 return NULL;
88
1da177e4
LT
89 args->logbufs = args->logbufsize = -1;
90 strncpy(args->fsname, sb->s_id, MAXNAMELEN);
91
92 /* Copy the already-parsed mount(2) flags we're interested in */
1da177e4
LT
93 if (sb->s_flags & MS_DIRSYNC)
94 args->flags |= XFSMNT_DIRSYNC;
95 if (sb->s_flags & MS_SYNCHRONOUS)
96 args->flags |= XFSMNT_WSYNC;
764d1f89
NS
97 if (silent)
98 args->flags |= XFSMNT_QUIET;
1da177e4
LT
99 args->flags |= XFSMNT_32BITINODES;
100
101 return args;
102}
103
a67d7c5f
DC
104#define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
105#define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
106#define MNTOPT_LOGDEV "logdev" /* log device */
107#define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
108#define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
109#define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
110#define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
111#define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
112#define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
113#define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
114#define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
115#define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
116#define MNTOPT_MTPT "mtpt" /* filesystem mount point */
117#define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
118#define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
119#define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
120#define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
121#define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
122#define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
123#define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
124 * unwritten extent conversion */
125#define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
126#define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
127#define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
128#define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
129#define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
130#define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
131#define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
132 * in stat(). */
133#define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
134#define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
135#define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
136#define MNTOPT_QUOTA "quota" /* disk quotas (user) */
137#define MNTOPT_NOQUOTA "noquota" /* no quotas */
138#define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */
139#define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */
140#define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */
141#define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */
142#define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */
143#define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */
144#define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
145#define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
146#define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
147#define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */
148#define MNTOPT_DMAPI "dmapi" /* DMI enabled (DMAPI / XDSM) */
149#define MNTOPT_XDSM "xdsm" /* DMI enabled (DMAPI / XDSM) */
150#define MNTOPT_DMI "dmi" /* DMI enabled (DMAPI / XDSM) */
151
62a877e3
CH
152/*
153 * Table driven mount option parser.
154 *
155 * Currently only used for remount, but it will be used for mount
156 * in the future, too.
157 */
158enum {
159 Opt_barrier, Opt_nobarrier, Opt_err
160};
161
a447c093 162static const match_table_t tokens = {
62a877e3
CH
163 {Opt_barrier, "barrier"},
164 {Opt_nobarrier, "nobarrier"},
165 {Opt_err, NULL}
166};
167
168
a67d7c5f
DC
169STATIC unsigned long
170suffix_strtoul(char *s, char **endp, unsigned int base)
171{
172 int last, shift_left_factor = 0;
173 char *value = s;
174
175 last = strlen(value) - 1;
176 if (value[last] == 'K' || value[last] == 'k') {
177 shift_left_factor = 10;
178 value[last] = '\0';
179 }
180 if (value[last] == 'M' || value[last] == 'm') {
181 shift_left_factor = 20;
182 value[last] = '\0';
183 }
184 if (value[last] == 'G' || value[last] == 'g') {
185 shift_left_factor = 30;
186 value[last] = '\0';
187 }
188
189 return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
190}
191
192STATIC int
193xfs_parseargs(
194 struct xfs_mount *mp,
195 char *options,
196 struct xfs_mount_args *args,
197 int update)
198{
199 char *this_char, *value, *eov;
200 int dsunit, dswidth, vol_dsunit, vol_dswidth;
201 int iosize;
1bd960ee 202 int dmapi_implies_ikeep = 1;
a67d7c5f
DC
203
204 args->flags |= XFSMNT_BARRIER;
205 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
206
207 if (!options)
208 goto done;
209
210 iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0;
211
212 while ((this_char = strsep(&options, ",")) != NULL) {
213 if (!*this_char)
214 continue;
215 if ((value = strchr(this_char, '=')) != NULL)
216 *value++ = 0;
217
218 if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
219 if (!value || !*value) {
220 cmn_err(CE_WARN,
221 "XFS: %s option requires an argument",
222 this_char);
223 return EINVAL;
224 }
225 args->logbufs = simple_strtoul(value, &eov, 10);
226 } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
227 if (!value || !*value) {
228 cmn_err(CE_WARN,
229 "XFS: %s option requires an argument",
230 this_char);
231 return EINVAL;
232 }
233 args->logbufsize = suffix_strtoul(value, &eov, 10);
234 } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
235 if (!value || !*value) {
236 cmn_err(CE_WARN,
237 "XFS: %s option requires an argument",
238 this_char);
239 return EINVAL;
240 }
241 strncpy(args->logname, value, MAXNAMELEN);
242 } else if (!strcmp(this_char, MNTOPT_MTPT)) {
243 if (!value || !*value) {
244 cmn_err(CE_WARN,
245 "XFS: %s option requires an argument",
246 this_char);
247 return EINVAL;
248 }
249 strncpy(args->mtpt, value, MAXNAMELEN);
250 } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
251 if (!value || !*value) {
252 cmn_err(CE_WARN,
253 "XFS: %s option requires an argument",
254 this_char);
255 return EINVAL;
256 }
257 strncpy(args->rtname, value, MAXNAMELEN);
258 } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
259 if (!value || !*value) {
260 cmn_err(CE_WARN,
261 "XFS: %s option requires an argument",
262 this_char);
263 return EINVAL;
264 }
265 iosize = simple_strtoul(value, &eov, 10);
266 args->flags |= XFSMNT_IOSIZE;
267 args->iosizelog = (uint8_t) iosize;
268 } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
269 if (!value || !*value) {
270 cmn_err(CE_WARN,
271 "XFS: %s option requires an argument",
272 this_char);
273 return EINVAL;
274 }
275 iosize = suffix_strtoul(value, &eov, 10);
276 args->flags |= XFSMNT_IOSIZE;
277 args->iosizelog = ffs(iosize) - 1;
278 } else if (!strcmp(this_char, MNTOPT_GRPID) ||
279 !strcmp(this_char, MNTOPT_BSDGROUPS)) {
280 mp->m_flags |= XFS_MOUNT_GRPID;
281 } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
282 !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
283 mp->m_flags &= ~XFS_MOUNT_GRPID;
284 } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
285 args->flags |= XFSMNT_WSYNC;
286 } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
287 args->flags |= XFSMNT_OSYNCISOSYNC;
288 } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
289 args->flags |= XFSMNT_NORECOVERY;
290 } else if (!strcmp(this_char, MNTOPT_INO64)) {
291 args->flags |= XFSMNT_INO64;
292#if !XFS_BIG_INUMS
293 cmn_err(CE_WARN,
294 "XFS: %s option not allowed on this system",
295 this_char);
296 return EINVAL;
297#endif
298 } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
299 args->flags |= XFSMNT_NOALIGN;
300 } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
301 args->flags |= XFSMNT_SWALLOC;
302 } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
303 if (!value || !*value) {
304 cmn_err(CE_WARN,
305 "XFS: %s option requires an argument",
306 this_char);
307 return EINVAL;
308 }
309 dsunit = simple_strtoul(value, &eov, 10);
310 } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
311 if (!value || !*value) {
312 cmn_err(CE_WARN,
313 "XFS: %s option requires an argument",
314 this_char);
315 return EINVAL;
316 }
317 dswidth = simple_strtoul(value, &eov, 10);
318 } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
319 args->flags &= ~XFSMNT_32BITINODES;
320#if !XFS_BIG_INUMS
321 cmn_err(CE_WARN,
322 "XFS: %s option not allowed on this system",
323 this_char);
324 return EINVAL;
325#endif
326 } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
327 args->flags |= XFSMNT_NOUUID;
328 } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
329 args->flags |= XFSMNT_BARRIER;
330 } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
331 args->flags &= ~XFSMNT_BARRIER;
332 } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
1bd960ee 333 args->flags |= XFSMNT_IKEEP;
a67d7c5f 334 } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
1bd960ee
JJS
335 dmapi_implies_ikeep = 0;
336 args->flags &= ~XFSMNT_IKEEP;
a67d7c5f
DC
337 } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
338 args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE;
339 } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
340 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
341 } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
342 args->flags |= XFSMNT_ATTR2;
343 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
344 args->flags &= ~XFSMNT_ATTR2;
7c12f296 345 args->flags |= XFSMNT_NOATTR2;
a67d7c5f
DC
346 } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
347 args->flags2 |= XFSMNT2_FILESTREAMS;
348 } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
349 args->flags &= ~(XFSMNT_UQUOTAENF|XFSMNT_UQUOTA);
350 args->flags &= ~(XFSMNT_GQUOTAENF|XFSMNT_GQUOTA);
351 } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
352 !strcmp(this_char, MNTOPT_UQUOTA) ||
353 !strcmp(this_char, MNTOPT_USRQUOTA)) {
354 args->flags |= XFSMNT_UQUOTA | XFSMNT_UQUOTAENF;
355 } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
356 !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
357 args->flags |= XFSMNT_UQUOTA;
358 args->flags &= ~XFSMNT_UQUOTAENF;
359 } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
360 !strcmp(this_char, MNTOPT_PRJQUOTA)) {
361 args->flags |= XFSMNT_PQUOTA | XFSMNT_PQUOTAENF;
362 } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
363 args->flags |= XFSMNT_PQUOTA;
364 args->flags &= ~XFSMNT_PQUOTAENF;
365 } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
366 !strcmp(this_char, MNTOPT_GRPQUOTA)) {
367 args->flags |= XFSMNT_GQUOTA | XFSMNT_GQUOTAENF;
368 } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
369 args->flags |= XFSMNT_GQUOTA;
370 args->flags &= ~XFSMNT_GQUOTAENF;
371 } else if (!strcmp(this_char, MNTOPT_DMAPI)) {
372 args->flags |= XFSMNT_DMAPI;
373 } else if (!strcmp(this_char, MNTOPT_XDSM)) {
374 args->flags |= XFSMNT_DMAPI;
375 } else if (!strcmp(this_char, MNTOPT_DMI)) {
376 args->flags |= XFSMNT_DMAPI;
377 } else if (!strcmp(this_char, "ihashsize")) {
378 cmn_err(CE_WARN,
379 "XFS: ihashsize no longer used, option is deprecated.");
380 } else if (!strcmp(this_char, "osyncisdsync")) {
381 /* no-op, this is now the default */
382 cmn_err(CE_WARN,
383 "XFS: osyncisdsync is now the default, option is deprecated.");
384 } else if (!strcmp(this_char, "irixsgid")) {
385 cmn_err(CE_WARN,
386 "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
387 } else {
388 cmn_err(CE_WARN,
389 "XFS: unknown mount option [%s].", this_char);
390 return EINVAL;
391 }
392 }
393
394 if (args->flags & XFSMNT_NORECOVERY) {
395 if ((mp->m_flags & XFS_MOUNT_RDONLY) == 0) {
396 cmn_err(CE_WARN,
397 "XFS: no-recovery mounts must be read-only.");
398 return EINVAL;
399 }
400 }
401
402 if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) {
403 cmn_err(CE_WARN,
404 "XFS: sunit and swidth options incompatible with the noalign option");
405 return EINVAL;
406 }
407
408 if ((args->flags & XFSMNT_GQUOTA) && (args->flags & XFSMNT_PQUOTA)) {
409 cmn_err(CE_WARN,
410 "XFS: cannot mount with both project and group quota");
411 return EINVAL;
412 }
413
414 if ((args->flags & XFSMNT_DMAPI) && *args->mtpt == '\0') {
415 printk("XFS: %s option needs the mount point option as well\n",
416 MNTOPT_DMAPI);
417 return EINVAL;
418 }
419
420 if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
421 cmn_err(CE_WARN,
422 "XFS: sunit and swidth must be specified together");
423 return EINVAL;
424 }
425
426 if (dsunit && (dswidth % dsunit != 0)) {
427 cmn_err(CE_WARN,
428 "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
429 dswidth, dsunit);
430 return EINVAL;
431 }
432
433 /*
434 * Applications using DMI filesystems often expect the
435 * inode generation number to be monotonically increasing.
436 * If we delete inode chunks we break this assumption, so
437 * keep unused inode chunks on disk for DMI filesystems
438 * until we come up with a better solution.
439 * Note that if "ikeep" or "noikeep" mount options are
440 * supplied, then they are honored.
441 */
1bd960ee
JJS
442 if ((args->flags & XFSMNT_DMAPI) && dmapi_implies_ikeep)
443 args->flags |= XFSMNT_IKEEP;
a67d7c5f
DC
444
445 if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
446 if (dsunit) {
447 args->sunit = dsunit;
448 args->flags |= XFSMNT_RETERR;
449 } else {
450 args->sunit = vol_dsunit;
451 }
452 dswidth ? (args->swidth = dswidth) :
453 (args->swidth = vol_dswidth);
454 } else {
455 args->sunit = args->swidth = 0;
456 }
457
458done:
459 if (args->flags & XFSMNT_32BITINODES)
460 mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
461 if (args->flags2)
462 args->flags |= XFSMNT_FLAGS2;
463 return 0;
464}
465
466struct proc_xfs_info {
467 int flag;
468 char *str;
469};
470
471STATIC int
472xfs_showargs(
473 struct xfs_mount *mp,
474 struct seq_file *m)
475{
476 static struct proc_xfs_info xfs_info_set[] = {
477 /* the few simple ones we can get from the mount struct */
1bd960ee 478 { XFS_MOUNT_IKEEP, "," MNTOPT_IKEEP },
a67d7c5f
DC
479 { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
480 { XFS_MOUNT_INO64, "," MNTOPT_INO64 },
481 { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
482 { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
483 { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
484 { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
485 { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
486 { XFS_MOUNT_ATTR2, "," MNTOPT_ATTR2 },
487 { XFS_MOUNT_FILESTREAMS, "," MNTOPT_FILESTREAM },
488 { XFS_MOUNT_DMAPI, "," MNTOPT_DMAPI },
489 { XFS_MOUNT_GRPID, "," MNTOPT_GRPID },
490 { 0, NULL }
491 };
492 static struct proc_xfs_info xfs_info_unset[] = {
493 /* the few simple ones we can get from the mount struct */
a67d7c5f
DC
494 { XFS_MOUNT_COMPAT_IOSIZE, "," MNTOPT_LARGEIO },
495 { XFS_MOUNT_BARRIER, "," MNTOPT_NOBARRIER },
496 { XFS_MOUNT_SMALL_INUMS, "," MNTOPT_64BITINODE },
497 { 0, NULL }
498 };
499 struct proc_xfs_info *xfs_infop;
500
501 for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
502 if (mp->m_flags & xfs_infop->flag)
503 seq_puts(m, xfs_infop->str);
504 }
505 for (xfs_infop = xfs_info_unset; xfs_infop->flag; xfs_infop++) {
506 if (!(mp->m_flags & xfs_infop->flag))
507 seq_puts(m, xfs_infop->str);
508 }
509
510 if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
511 seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
512 (int)(1 << mp->m_writeio_log) >> 10);
513
514 if (mp->m_logbufs > 0)
515 seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
516 if (mp->m_logbsize > 0)
517 seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
518
519 if (mp->m_logname)
520 seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
521 if (mp->m_rtname)
522 seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
523
524 if (mp->m_dalign > 0)
525 seq_printf(m, "," MNTOPT_SUNIT "=%d",
526 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
527 if (mp->m_swidth > 0)
528 seq_printf(m, "," MNTOPT_SWIDTH "=%d",
529 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
530
531 if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD))
532 seq_puts(m, "," MNTOPT_USRQUOTA);
533 else if (mp->m_qflags & XFS_UQUOTA_ACCT)
534 seq_puts(m, "," MNTOPT_UQUOTANOENF);
535
536 if (mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_OQUOTA_ENFD))
537 seq_puts(m, "," MNTOPT_PRJQUOTA);
538 else if (mp->m_qflags & XFS_PQUOTA_ACCT)
539 seq_puts(m, "," MNTOPT_PQUOTANOENF);
540
541 if (mp->m_qflags & (XFS_GQUOTA_ACCT|XFS_OQUOTA_ENFD))
542 seq_puts(m, "," MNTOPT_GRPQUOTA);
543 else if (mp->m_qflags & XFS_GQUOTA_ACCT)
544 seq_puts(m, "," MNTOPT_GQUOTANOENF);
545
546 if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
547 seq_puts(m, "," MNTOPT_NOQUOTA);
548
549 return 0;
550}
1da177e4
LT
551__uint64_t
552xfs_max_file_offset(
553 unsigned int blockshift)
554{
555 unsigned int pagefactor = 1;
556 unsigned int bitshift = BITS_PER_LONG - 1;
557
558 /* Figure out maximum filesize, on Linux this can depend on
559 * the filesystem blocksize (on 32 bit platforms).
560 * __block_prepare_write does this in an [unsigned] long...
561 * page->index << (PAGE_CACHE_SHIFT - bbits)
562 * So, for page sized blocks (4K on 32 bit platforms),
563 * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
564 * (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
565 * but for smaller blocksizes it is less (bbits = log2 bsize).
566 * Note1: get_block_t takes a long (implicit cast from above)
567 * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch
568 * can optionally convert the [unsigned] long from above into
569 * an [unsigned] long long.
570 */
571
572#if BITS_PER_LONG == 32
573# if defined(CONFIG_LBD)
574 ASSERT(sizeof(sector_t) == 8);
575 pagefactor = PAGE_CACHE_SIZE;
576 bitshift = BITS_PER_LONG;
577# else
578 pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift);
579# endif
580#endif
581
582 return (((__uint64_t)pagefactor) << bitshift) - 1;
583}
584
1da177e4
LT
585int
586xfs_blkdev_get(
587 xfs_mount_t *mp,
588 const char *name,
589 struct block_device **bdevp)
590{
591 int error = 0;
592
30c40d2c 593 *bdevp = open_bdev_exclusive(name, FMODE_READ|FMODE_WRITE, mp);
1da177e4
LT
594 if (IS_ERR(*bdevp)) {
595 error = PTR_ERR(*bdevp);
596 printk("XFS: Invalid device [%s], error=%d\n", name, error);
597 }
598
599 return -error;
600}
601
602void
603xfs_blkdev_put(
604 struct block_device *bdev)
605{
606 if (bdev)
30c40d2c 607 close_bdev_exclusive(bdev, FMODE_READ|FMODE_WRITE);
1da177e4
LT
608}
609
f538d4da
CH
610/*
611 * Try to write out the superblock using barriers.
612 */
613STATIC int
614xfs_barrier_test(
615 xfs_mount_t *mp)
616{
617 xfs_buf_t *sbp = xfs_getsb(mp, 0);
618 int error;
619
620 XFS_BUF_UNDONE(sbp);
621 XFS_BUF_UNREAD(sbp);
622 XFS_BUF_UNDELAYWRITE(sbp);
623 XFS_BUF_WRITE(sbp);
624 XFS_BUF_UNASYNC(sbp);
625 XFS_BUF_ORDERED(sbp);
626
627 xfsbdstrat(mp, sbp);
628 error = xfs_iowait(sbp);
629
630 /*
631 * Clear all the flags we set and possible error state in the
632 * buffer. We only did the write to try out whether barriers
633 * worked and shouldn't leave any traces in the superblock
634 * buffer.
635 */
636 XFS_BUF_DONE(sbp);
637 XFS_BUF_ERROR(sbp, 0);
638 XFS_BUF_UNORDERED(sbp);
639
640 xfs_buf_relse(sbp);
641 return error;
642}
643
644void
645xfs_mountfs_check_barriers(xfs_mount_t *mp)
646{
647 int error;
648
649 if (mp->m_logdev_targp != mp->m_ddev_targp) {
650 xfs_fs_cmn_err(CE_NOTE, mp,
651 "Disabling barriers, not supported with external log device");
652 mp->m_flags &= ~XFS_MOUNT_BARRIER;
4ef19ddd 653 return;
f538d4da
CH
654 }
655
b2ea401b
NS
656 if (xfs_readonly_buftarg(mp->m_ddev_targp)) {
657 xfs_fs_cmn_err(CE_NOTE, mp,
658 "Disabling barriers, underlying device is readonly");
659 mp->m_flags &= ~XFS_MOUNT_BARRIER;
660 return;
661 }
662
f538d4da
CH
663 error = xfs_barrier_test(mp);
664 if (error) {
665 xfs_fs_cmn_err(CE_NOTE, mp,
666 "Disabling barriers, trial barrier write failed");
667 mp->m_flags &= ~XFS_MOUNT_BARRIER;
4ef19ddd 668 return;
f538d4da
CH
669 }
670}
671
672void
673xfs_blkdev_issue_flush(
674 xfs_buftarg_t *buftarg)
675{
ce8e922c 676 blkdev_issue_flush(buftarg->bt_bdev, NULL);
f538d4da 677}
1da177e4 678
19f354d4
CH
679STATIC void
680xfs_close_devices(
681 struct xfs_mount *mp)
682{
683 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
c032bfcf 684 struct block_device *logdev = mp->m_logdev_targp->bt_bdev;
19f354d4 685 xfs_free_buftarg(mp->m_logdev_targp);
c032bfcf 686 xfs_blkdev_put(logdev);
19f354d4
CH
687 }
688 if (mp->m_rtdev_targp) {
c032bfcf 689 struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev;
19f354d4 690 xfs_free_buftarg(mp->m_rtdev_targp);
c032bfcf 691 xfs_blkdev_put(rtdev);
19f354d4
CH
692 }
693 xfs_free_buftarg(mp->m_ddev_targp);
694}
695
696/*
697 * The file system configurations are:
698 * (1) device (partition) with data and internal log
699 * (2) logical volume with data and log subvolumes.
700 * (3) logical volume with data, log, and realtime subvolumes.
701 *
702 * We only have to handle opening the log and realtime volumes here if
703 * they are present. The data subvolume has already been opened by
704 * get_sb_bdev() and is stored in sb->s_bdev.
705 */
706STATIC int
707xfs_open_devices(
708 struct xfs_mount *mp,
709 struct xfs_mount_args *args)
710{
711 struct block_device *ddev = mp->m_super->s_bdev;
712 struct block_device *logdev = NULL, *rtdev = NULL;
713 int error;
714
715 /*
716 * Open real time and log devices - order is important.
717 */
718 if (args->logname[0]) {
719 error = xfs_blkdev_get(mp, args->logname, &logdev);
720 if (error)
721 goto out;
722 }
723
724 if (args->rtname[0]) {
725 error = xfs_blkdev_get(mp, args->rtname, &rtdev);
726 if (error)
727 goto out_close_logdev;
728
729 if (rtdev == ddev || rtdev == logdev) {
730 cmn_err(CE_WARN,
731 "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
732 error = EINVAL;
733 goto out_close_rtdev;
734 }
735 }
736
737 /*
738 * Setup xfs_mount buffer target pointers
739 */
740 error = ENOMEM;
741 mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
742 if (!mp->m_ddev_targp)
743 goto out_close_rtdev;
744
745 if (rtdev) {
746 mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
747 if (!mp->m_rtdev_targp)
748 goto out_free_ddev_targ;
749 }
750
751 if (logdev && logdev != ddev) {
752 mp->m_logdev_targp = xfs_alloc_buftarg(logdev, 1);
753 if (!mp->m_logdev_targp)
754 goto out_free_rtdev_targ;
755 } else {
756 mp->m_logdev_targp = mp->m_ddev_targp;
757 }
758
759 return 0;
760
761 out_free_rtdev_targ:
762 if (mp->m_rtdev_targp)
763 xfs_free_buftarg(mp->m_rtdev_targp);
764 out_free_ddev_targ:
765 xfs_free_buftarg(mp->m_ddev_targp);
766 out_close_rtdev:
767 if (rtdev)
768 xfs_blkdev_put(rtdev);
769 out_close_logdev:
770 if (logdev && logdev != ddev)
771 xfs_blkdev_put(logdev);
772 out:
773 return error;
774}
775
e34b562c
CH
776/*
777 * Setup xfs_mount buffer target pointers based on superblock
778 */
779STATIC int
780xfs_setup_devices(
781 struct xfs_mount *mp)
782{
783 int error;
19f354d4 784
e34b562c
CH
785 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
786 mp->m_sb.sb_sectsize);
787 if (error)
788 return error;
789
790 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
791 unsigned int log_sector_size = BBSIZE;
792
793 if (xfs_sb_version_hassector(&mp->m_sb))
794 log_sector_size = mp->m_sb.sb_logsectsize;
795 error = xfs_setsize_buftarg(mp->m_logdev_targp,
796 mp->m_sb.sb_blocksize,
797 log_sector_size);
798 if (error)
799 return error;
800 }
801 if (mp->m_rtdev_targp) {
802 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
803 mp->m_sb.sb_blocksize,
804 mp->m_sb.sb_sectsize);
805 if (error)
806 return error;
807 }
808
809 return 0;
810}
19f354d4 811
249a8c11
DC
812/*
813 * XFS AIL push thread support
814 */
815void
816xfsaild_wakeup(
817 xfs_mount_t *mp,
818 xfs_lsn_t threshold_lsn)
819{
820 mp->m_ail.xa_target = threshold_lsn;
821 wake_up_process(mp->m_ail.xa_task);
822}
823
824int
825xfsaild(
826 void *data)
827{
828 xfs_mount_t *mp = (xfs_mount_t *)data;
829 xfs_lsn_t last_pushed_lsn = 0;
830 long tout = 0;
831
832 while (!kthread_should_stop()) {
833 if (tout)
834 schedule_timeout_interruptible(msecs_to_jiffies(tout));
835 tout = 1000;
836
837 /* swsusp */
838 try_to_freeze();
839
840 ASSERT(mp->m_log);
841 if (XFS_FORCED_SHUTDOWN(mp))
842 continue;
843
844 tout = xfsaild_push(mp, &last_pushed_lsn);
845 }
846
847 return 0;
848} /* xfsaild */
849
850int
851xfsaild_start(
852 xfs_mount_t *mp)
853{
854 mp->m_ail.xa_target = 0;
855 mp->m_ail.xa_task = kthread_run(xfsaild, mp, "xfsaild");
856 if (IS_ERR(mp->m_ail.xa_task))
857 return -PTR_ERR(mp->m_ail.xa_task);
858 return 0;
859}
860
861void
862xfsaild_stop(
863 xfs_mount_t *mp)
864{
865 kthread_stop(mp->m_ail.xa_task);
866}
867
868
869
1da177e4 870STATIC struct inode *
a50cd269 871xfs_fs_alloc_inode(
1da177e4
LT
872 struct super_block *sb)
873{
df80c933 874 return kmem_zone_alloc(xfs_vnode_zone, KM_SLEEP);
1da177e4
LT
875}
876
877STATIC void
a50cd269 878xfs_fs_destroy_inode(
1da177e4
LT
879 struct inode *inode)
880{
a19d033c 881 kmem_zone_free(xfs_vnode_zone, inode);
1da177e4
LT
882}
883
884STATIC void
a50cd269 885xfs_fs_inode_init_once(
4ba9b9d0 886 void *vnode)
1da177e4 887{
863890cd 888 inode_init_once((struct inode *)vnode);
1da177e4
LT
889}
890
07c8f675
DC
891
892/*
893 * Slab object creation initialisation for the XFS inode.
894 * This covers only the idempotent fields in the XFS inode;
895 * all other fields need to be initialised on allocation
896 * from the slab. This avoids the need to repeatedly intialise
897 * fields in the xfs inode that left in the initialise state
898 * when freeing the inode.
899 */
900void
901xfs_inode_init_once(
07c8f675
DC
902 void *inode)
903{
904 struct xfs_inode *ip = inode;
905
906 memset(ip, 0, sizeof(struct xfs_inode));
907 atomic_set(&ip->i_iocount, 0);
908 atomic_set(&ip->i_pincount, 0);
909 spin_lock_init(&ip->i_flags_lock);
910 INIT_LIST_HEAD(&ip->i_reclaim);
911 init_waitqueue_head(&ip->i_ipin_wait);
912 /*
913 * Because we want to use a counting completion, complete
914 * the flush completion once to allow a single access to
915 * the flush completion without blocking.
916 */
917 init_completion(&ip->i_flush);
918 complete(&ip->i_flush);
919
920 mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
921 "xfsino", ip->i_ino);
922 mrlock_init(&ip->i_iolock, MRLOCK_BARRIER, "xfsio", ip->i_ino);
923}
924
1da177e4
LT
925/*
926 * Attempt to flush the inode, this will actually fail
927 * if the inode is pinned, but we dirty the inode again
928 * at the point when it is unpinned after a log write,
8758280f 929 * since this is when the inode itself becomes flushable.
1da177e4
LT
930 */
931STATIC int
a50cd269 932xfs_fs_write_inode(
1da177e4
LT
933 struct inode *inode,
934 int sync)
935{
a3f74ffb
DC
936 int error = 0;
937 int flags = 0;
1da177e4 938
cf441eeb 939 xfs_itrace_entry(XFS_I(inode));
739bfb2a
CH
940 if (sync) {
941 filemap_fdatawait(inode->i_mapping);
942 flags |= FLUSH_SYNC;
1da177e4 943 }
739bfb2a 944 error = xfs_inode_flush(XFS_I(inode), flags);
e893bffd
LM
945 /*
946 * if we failed to write out the inode then mark
947 * it dirty again so we'll try again later.
948 */
949 if (error)
950 mark_inode_dirty_sync(inode);
739bfb2a 951
1da177e4
LT
952 return -error;
953}
954
955STATIC void
a50cd269 956xfs_fs_clear_inode(
1da177e4
LT
957 struct inode *inode)
958{
1543d79c 959 xfs_inode_t *ip = XFS_I(inode);
56d433e4 960
02ba71de 961 /*
1543d79c 962 * ip can be null when xfs_iget_core calls xfs_idestroy if we
02ba71de
CH
963 * find an inode with di_mode == 0 but without IGET_CREATE set.
964 */
1543d79c 965 if (ip) {
cf441eeb 966 xfs_itrace_entry(ip);
1543d79c
CH
967 XFS_STATS_INC(vn_rele);
968 XFS_STATS_INC(vn_remove);
969 XFS_STATS_INC(vn_reclaim);
970 XFS_STATS_DEC(vn_active);
971
972 xfs_inactive(ip);
973 xfs_iflags_clear(ip, XFS_IMODIFIED);
974 if (xfs_reclaim(ip))
34a622b2 975 panic("%s: cannot reclaim 0x%p\n", __func__, inode);
b3aea4ed 976 }
56d433e4 977
739bfb2a 978 ASSERT(XFS_I(inode) == NULL);
56d433e4 979}
1da177e4
LT
980
981/*
982 * Enqueue a work item to be picked up by the vfs xfssyncd thread.
983 * Doing this has two advantages:
984 * - It saves on stack space, which is tight in certain situations
985 * - It can be used (with care) as a mechanism to avoid deadlocks.
986 * Flushing while allocating in a full filesystem requires both.
987 */
988STATIC void
989xfs_syncd_queue_work(
74394496 990 struct xfs_mount *mp,
1da177e4 991 void *data,
74394496 992 void (*syncer)(struct xfs_mount *, void *))
1da177e4 993{
b83bd138 994 struct bhv_vfs_sync_work *work;
1da177e4 995
b83bd138 996 work = kmem_alloc(sizeof(struct bhv_vfs_sync_work), KM_SLEEP);
1da177e4
LT
997 INIT_LIST_HEAD(&work->w_list);
998 work->w_syncer = syncer;
999 work->w_data = data;
74394496
CH
1000 work->w_mount = mp;
1001 spin_lock(&mp->m_sync_lock);
1002 list_add_tail(&work->w_list, &mp->m_sync_list);
1003 spin_unlock(&mp->m_sync_lock);
1004 wake_up_process(mp->m_sync_task);
1da177e4
LT
1005}
1006
1007/*
1008 * Flush delayed allocate data, attempting to free up reserved space
1009 * from existing allocations. At this point a new allocation attempt
1010 * has failed with ENOSPC and we are in the process of scratching our
1011 * heads, looking about for more room...
1012 */
1013STATIC void
1014xfs_flush_inode_work(
74394496
CH
1015 struct xfs_mount *mp,
1016 void *arg)
1da177e4 1017{
74394496
CH
1018 struct inode *inode = arg;
1019 filemap_flush(inode->i_mapping);
1020 iput(inode);
1da177e4
LT
1021}
1022
1023void
1024xfs_flush_inode(
1025 xfs_inode_t *ip)
1026{
01651646 1027 struct inode *inode = VFS_I(ip);
1da177e4
LT
1028
1029 igrab(inode);
74394496 1030 xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_inode_work);
041e0e3b 1031 delay(msecs_to_jiffies(500));
1da177e4
LT
1032}
1033
1034/*
1035 * This is the "bigger hammer" version of xfs_flush_inode_work...
1036 * (IOW, "If at first you don't succeed, use a Bigger Hammer").
1037 */
1038STATIC void
1039xfs_flush_device_work(
74394496
CH
1040 struct xfs_mount *mp,
1041 void *arg)
1da177e4 1042{
74394496 1043 struct inode *inode = arg;
b267ce99 1044 sync_blockdev(mp->m_super->s_bdev);
74394496 1045 iput(inode);
1da177e4
LT
1046}
1047
1048void
1049xfs_flush_device(
1050 xfs_inode_t *ip)
1051{
e4f75291 1052 struct inode *inode = VFS_I(ip);
1da177e4
LT
1053
1054 igrab(inode);
74394496 1055 xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_device_work);
041e0e3b 1056 delay(msecs_to_jiffies(500));
1da177e4
LT
1057 xfs_log_force(ip->i_mount, (xfs_lsn_t)0, XFS_LOG_FORCE|XFS_LOG_SYNC);
1058}
1059
1da177e4 1060STATIC void
74394496
CH
1061xfs_sync_worker(
1062 struct xfs_mount *mp,
1da177e4
LT
1063 void *unused)
1064{
1065 int error;
1066
74394496 1067 if (!(mp->m_flags & XFS_MOUNT_RDONLY))
7e20694d 1068 error = xfs_sync(mp, SYNC_FSDATA | SYNC_BDFLUSH | SYNC_ATTR);
74394496
CH
1069 mp->m_sync_seq++;
1070 wake_up(&mp->m_wait_single_sync_task);
1da177e4
LT
1071}
1072
1073STATIC int
1074xfssyncd(
1075 void *arg)
1076{
74394496 1077 struct xfs_mount *mp = arg;
1da177e4 1078 long timeleft;
b83bd138 1079 bhv_vfs_sync_work_t *work, *n;
4df08c52 1080 LIST_HEAD (tmp);
1da177e4 1081
83144186 1082 set_freezable();
041e0e3b 1083 timeleft = xfs_syncd_centisecs * msecs_to_jiffies(10);
1da177e4 1084 for (;;) {
041e0e3b 1085 timeleft = schedule_timeout_interruptible(timeleft);
1da177e4 1086 /* swsusp */
3e1d1d28 1087 try_to_freeze();
74394496 1088 if (kthread_should_stop() && list_empty(&mp->m_sync_list))
1da177e4
LT
1089 break;
1090
74394496 1091 spin_lock(&mp->m_sync_lock);
1da177e4
LT
1092 /*
1093 * We can get woken by laptop mode, to do a sync -
1094 * that's the (only!) case where the list would be
1095 * empty with time remaining.
1096 */
74394496 1097 if (!timeleft || list_empty(&mp->m_sync_list)) {
1da177e4 1098 if (!timeleft)
041e0e3b
NA
1099 timeleft = xfs_syncd_centisecs *
1100 msecs_to_jiffies(10);
74394496
CH
1101 INIT_LIST_HEAD(&mp->m_sync_work.w_list);
1102 list_add_tail(&mp->m_sync_work.w_list,
1103 &mp->m_sync_list);
1da177e4 1104 }
74394496 1105 list_for_each_entry_safe(work, n, &mp->m_sync_list, w_list)
1da177e4 1106 list_move(&work->w_list, &tmp);
74394496 1107 spin_unlock(&mp->m_sync_lock);
1da177e4
LT
1108
1109 list_for_each_entry_safe(work, n, &tmp, w_list) {
74394496 1110 (*work->w_syncer)(mp, work->w_data);
1da177e4 1111 list_del(&work->w_list);
74394496 1112 if (work == &mp->m_sync_work)
1da177e4 1113 continue;
f0e2d93c 1114 kmem_free(work);
1da177e4
LT
1115 }
1116 }
1117
1da177e4
LT
1118 return 0;
1119}
1120
a738159d
CH
1121STATIC void
1122xfs_free_fsname(
1123 struct xfs_mount *mp)
1124{
1125 kfree(mp->m_fsname);
1126 kfree(mp->m_rtname);
1127 kfree(mp->m_logname);
1128}
1129
1da177e4 1130STATIC void
a50cd269 1131xfs_fs_put_super(
1da177e4
LT
1132 struct super_block *sb)
1133{
745f6919 1134 struct xfs_mount *mp = XFS_M(sb);
e48ad316
CH
1135 struct xfs_inode *rip = mp->m_rootip;
1136 int unmount_event_flags = 0;
1da177e4
LT
1137 int error;
1138
74394496
CH
1139 kthread_stop(mp->m_sync_task);
1140
745f6919 1141 xfs_sync(mp, SYNC_ATTR | SYNC_DELWRI);
e48ad316
CH
1142
1143#ifdef HAVE_DMAPI
1144 if (mp->m_flags & XFS_MOUNT_DMAPI) {
1145 unmount_event_flags =
1146 (mp->m_dmevmask & (1 << DM_EVENT_UNMOUNT)) ?
1147 0 : DM_FLAGS_UNWANTED;
1148 /*
1149 * Ignore error from dmapi here, first unmount is not allowed
1150 * to fail anyway, and second we wouldn't want to fail a
1151 * unmount because of dmapi.
1152 */
1153 XFS_SEND_PREUNMOUNT(mp, rip, DM_RIGHT_NULL, rip, DM_RIGHT_NULL,
1154 NULL, NULL, 0, 0, unmount_event_flags);
1155 }
1156#endif
1157
1158 /*
1159 * Blow away any referenced inode in the filestreams cache.
1160 * This can and will cause log traffic as inodes go inactive
1161 * here.
1162 */
1163 xfs_filestream_unmount(mp);
1164
1165 XFS_bflush(mp->m_ddev_targp);
1166 error = xfs_unmount_flush(mp, 0);
1167 WARN_ON(error);
1168
e48ad316
CH
1169 /*
1170 * If we're forcing a shutdown, typically because of a media error,
1171 * we want to make sure we invalidate dirty pages that belong to
1172 * referenced vnodes as well.
1173 */
1174 if (XFS_FORCED_SHUTDOWN(mp)) {
1175 error = xfs_sync(mp, SYNC_WAIT | SYNC_CLOSE);
1176 ASSERT(error != EFSCORRUPTED);
1177 }
1178
1179 if (mp->m_flags & XFS_MOUNT_DMAPI) {
1180 XFS_SEND_UNMOUNT(mp, rip, DM_RIGHT_NULL, 0, 0,
1181 unmount_event_flags);
1182 }
1183
19f354d4 1184 xfs_unmountfs(mp);
6203300e 1185 xfs_freesb(mp);
c962fb79 1186 xfs_icsb_destroy_counters(mp);
19f354d4 1187 xfs_close_devices(mp);
e48ad316
CH
1188 xfs_qmops_put(mp);
1189 xfs_dmops_put(mp);
a738159d 1190 xfs_free_fsname(mp);
c962fb79 1191 kfree(mp);
1da177e4
LT
1192}
1193
1194STATIC void
a50cd269 1195xfs_fs_write_super(
1da177e4
LT
1196 struct super_block *sb)
1197{
b83bd138 1198 if (!(sb->s_flags & MS_RDONLY))
745f6919 1199 xfs_sync(XFS_M(sb), SYNC_FSDATA);
1da177e4
LT
1200 sb->s_dirt = 0;
1201}
1202
1203STATIC int
a50cd269 1204xfs_fs_sync_super(
1da177e4
LT
1205 struct super_block *sb,
1206 int wait)
1207{
745f6919 1208 struct xfs_mount *mp = XFS_M(sb);
b83bd138
NS
1209 int error;
1210 int flags;
1da177e4 1211
e893bffd
LM
1212 /*
1213 * Treat a sync operation like a freeze. This is to work
1214 * around a race in sync_inodes() which works in two phases
1215 * - an asynchronous flush, which can write out an inode
1216 * without waiting for file size updates to complete, and a
1217 * synchronous flush, which wont do anything because the
1218 * async flush removed the inode's dirty flag. Also
1219 * sync_inodes() will not see any files that just have
1220 * outstanding transactions to be flushed because we don't
1221 * dirty the Linux inode until after the transaction I/O
1222 * completes.
1223 */
1224 if (wait || unlikely(sb->s_frozen == SB_FREEZE_WRITE)) {
2823945f
DC
1225 /*
1226 * First stage of freeze - no more writers will make progress
1227 * now we are here, so we flush delwri and delalloc buffers
1228 * here, then wait for all I/O to complete. Data is frozen at
1229 * that point. Metadata is not frozen, transactions can still
1230 * occur here so don't bother flushing the buftarg (i.e
1231 * SYNC_QUIESCE) because it'll just get dirty again.
1232 */
516b2e7c 1233 flags = SYNC_DATA_QUIESCE;
2823945f 1234 } else
e893bffd 1235 flags = SYNC_FSDATA;
1da177e4 1236
745f6919 1237 error = xfs_sync(mp, flags);
1da177e4
LT
1238 sb->s_dirt = 0;
1239
1240 if (unlikely(laptop_mode)) {
74394496 1241 int prev_sync_seq = mp->m_sync_seq;
1da177e4
LT
1242
1243 /*
1244 * The disk must be active because we're syncing.
1245 * We schedule xfssyncd now (now that the disk is
1246 * active) instead of later (when it might not be).
1247 */
74394496 1248 wake_up_process(mp->m_sync_task);
1da177e4
LT
1249 /*
1250 * We have to wait for the sync iteration to complete.
1251 * If we don't, the disk activity caused by the sync
1252 * will come after the sync is completed, and that
1253 * triggers another sync from laptop mode.
1254 */
74394496
CH
1255 wait_event(mp->m_wait_single_sync_task,
1256 mp->m_sync_seq != prev_sync_seq);
1da177e4
LT
1257 }
1258
1259 return -error;
1260}
1261
1262STATIC int
a50cd269 1263xfs_fs_statfs(
726c3342 1264 struct dentry *dentry,
1da177e4
LT
1265 struct kstatfs *statp)
1266{
4ca488eb
CH
1267 struct xfs_mount *mp = XFS_M(dentry->d_sb);
1268 xfs_sb_t *sbp = &mp->m_sb;
1269 __uint64_t fakeinos, id;
1270 xfs_extlen_t lsize;
1271
1272 statp->f_type = XFS_SB_MAGIC;
1273 statp->f_namelen = MAXNAMELEN - 1;
1274
1275 id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
1276 statp->f_fsid.val[0] = (u32)id;
1277 statp->f_fsid.val[1] = (u32)(id >> 32);
1278
d4d90b57 1279 xfs_icsb_sync_counters(mp, XFS_ICSB_LAZY_COUNT);
4ca488eb
CH
1280
1281 spin_lock(&mp->m_sb_lock);
1282 statp->f_bsize = sbp->sb_blocksize;
1283 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
1284 statp->f_blocks = sbp->sb_dblocks - lsize;
1285 statp->f_bfree = statp->f_bavail =
1286 sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
1287 fakeinos = statp->f_bfree << sbp->sb_inopblog;
1288#if XFS_BIG_INUMS
1289 fakeinos += mp->m_inoadd;
1290#endif
1291 statp->f_files =
1292 MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
1293 if (mp->m_maxicount)
1294#if XFS_BIG_INUMS
1295 if (!mp->m_inoadd)
1296#endif
1297 statp->f_files = min_t(typeof(statp->f_files),
1298 statp->f_files,
1299 mp->m_maxicount);
1300 statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
1301 spin_unlock(&mp->m_sb_lock);
1302
1303 XFS_QM_DQSTATVFS(XFS_I(dentry->d_inode), statp);
1304 return 0;
1da177e4
LT
1305}
1306
1307STATIC int
a50cd269 1308xfs_fs_remount(
1da177e4
LT
1309 struct super_block *sb,
1310 int *flags,
1311 char *options)
1312{
745f6919 1313 struct xfs_mount *mp = XFS_M(sb);
62a877e3
CH
1314 substring_t args[MAX_OPT_ARGS];
1315 char *p;
1da177e4 1316
62a877e3
CH
1317 while ((p = strsep(&options, ",")) != NULL) {
1318 int token;
bdd907ba 1319
62a877e3
CH
1320 if (!*p)
1321 continue;
48b62a1a 1322
62a877e3
CH
1323 token = match_token(p, tokens, args);
1324 switch (token) {
1325 case Opt_barrier:
48b62a1a 1326 mp->m_flags |= XFS_MOUNT_BARRIER;
62a877e3
CH
1327
1328 /*
1329 * Test if barriers are actually working if we can,
1330 * else delay this check until the filesystem is
1331 * marked writeable.
1332 */
1333 if (!(mp->m_flags & XFS_MOUNT_RDONLY))
1334 xfs_mountfs_check_barriers(mp);
1335 break;
1336 case Opt_nobarrier:
48b62a1a 1337 mp->m_flags &= ~XFS_MOUNT_BARRIER;
62a877e3
CH
1338 break;
1339 default:
6efdf281
CH
1340 /*
1341 * Logically we would return an error here to prevent
1342 * users from believing they might have changed
1343 * mount options using remount which can't be changed.
1344 *
1345 * But unfortunately mount(8) adds all options from
1346 * mtab and fstab to the mount arguments in some cases
1347 * so we can't blindly reject options, but have to
1348 * check for each specified option if it actually
1349 * differs from the currently set option and only
1350 * reject it if that's the case.
1351 *
1352 * Until that is implemented we return success for
1353 * every remount request, and silently ignore all
1354 * options that we can't actually change.
1355 */
1356#if 0
62a877e3
CH
1357 printk(KERN_INFO
1358 "XFS: mount option \"%s\" not supported for remount\n", p);
1359 return -EINVAL;
6efdf281 1360#else
6c5e51da 1361 break;
6efdf281 1362#endif
48b62a1a 1363 }
62a877e3
CH
1364 }
1365
1366 /* rw/ro -> rw */
1367 if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(*flags & MS_RDONLY)) {
1368 mp->m_flags &= ~XFS_MOUNT_RDONLY;
1369 if (mp->m_flags & XFS_MOUNT_BARRIER)
1370 xfs_mountfs_check_barriers(mp);
1371 }
1372
1373 /* rw -> ro */
1374 if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (*flags & MS_RDONLY)) {
48b62a1a
CH
1375 xfs_filestream_flush(mp);
1376 xfs_sync(mp, SYNC_DATA_QUIESCE);
1377 xfs_attr_quiesce(mp);
1378 mp->m_flags |= XFS_MOUNT_RDONLY;
1379 }
1380
62a877e3 1381 return 0;
1da177e4
LT
1382}
1383
9909c4aa
CH
1384/*
1385 * Second stage of a freeze. The data is already frozen so we only
1386 * need to take care of themetadata. Once that's done write a dummy
1387 * record to dirty the log in case of a crash while frozen.
1388 */
1da177e4 1389STATIC void
a50cd269 1390xfs_fs_lockfs(
1da177e4
LT
1391 struct super_block *sb)
1392{
9909c4aa
CH
1393 struct xfs_mount *mp = XFS_M(sb);
1394
1395 xfs_attr_quiesce(mp);
1396 xfs_fs_log_dummy(mp);
1da177e4
LT
1397}
1398
1399STATIC int
a50cd269 1400xfs_fs_show_options(
1da177e4
LT
1401 struct seq_file *m,
1402 struct vfsmount *mnt)
1403{
745f6919 1404 return -xfs_showargs(XFS_M(mnt->mnt_sb), m);
1da177e4
LT
1405}
1406
ee34807a 1407STATIC int
a50cd269 1408xfs_fs_quotasync(
ee34807a
NS
1409 struct super_block *sb,
1410 int type)
1411{
b09cc771 1412 return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XQUOTASYNC, 0, NULL);
ee34807a
NS
1413}
1414
1da177e4 1415STATIC int
a50cd269 1416xfs_fs_getxstate(
1da177e4
LT
1417 struct super_block *sb,
1418 struct fs_quota_stat *fqs)
1419{
b09cc771 1420 return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XGETQSTAT, 0, (caddr_t)fqs);
1da177e4
LT
1421}
1422
1423STATIC int
a50cd269 1424xfs_fs_setxstate(
1da177e4
LT
1425 struct super_block *sb,
1426 unsigned int flags,
1427 int op)
1428{
b09cc771 1429 return -XFS_QM_QUOTACTL(XFS_M(sb), op, 0, (caddr_t)&flags);
1da177e4
LT
1430}
1431
1432STATIC int
a50cd269 1433xfs_fs_getxquota(
1da177e4
LT
1434 struct super_block *sb,
1435 int type,
1436 qid_t id,
1437 struct fs_disk_quota *fdq)
1438{
b09cc771 1439 return -XFS_QM_QUOTACTL(XFS_M(sb),
b83bd138
NS
1440 (type == USRQUOTA) ? Q_XGETQUOTA :
1441 ((type == GRPQUOTA) ? Q_XGETGQUOTA :
1442 Q_XGETPQUOTA), id, (caddr_t)fdq);
1da177e4
LT
1443}
1444
1445STATIC int
a50cd269 1446xfs_fs_setxquota(
1da177e4
LT
1447 struct super_block *sb,
1448 int type,
1449 qid_t id,
1450 struct fs_disk_quota *fdq)
1451{
b09cc771 1452 return -XFS_QM_QUOTACTL(XFS_M(sb),
b83bd138
NS
1453 (type == USRQUOTA) ? Q_XSETQLIM :
1454 ((type == GRPQUOTA) ? Q_XSETGQLIM :
1455 Q_XSETPQLIM), id, (caddr_t)fdq);
1da177e4
LT
1456}
1457
f8f15e42
CH
1458/*
1459 * This function fills in xfs_mount_t fields based on mount args.
1460 * Note: the superblock has _not_ yet been read in.
1461 */
1462STATIC int
1463xfs_start_flags(
1464 struct xfs_mount_args *ap,
1465 struct xfs_mount *mp)
1466{
a738159d
CH
1467 int error;
1468
f8f15e42
CH
1469 /* Values are in BBs */
1470 if ((ap->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
1471 /*
1472 * At this point the superblock has not been read
1473 * in, therefore we do not know the block size.
1474 * Before the mount call ends we will convert
1475 * these to FSBs.
1476 */
1477 mp->m_dalign = ap->sunit;
1478 mp->m_swidth = ap->swidth;
1479 }
1480
1481 if (ap->logbufs != -1 &&
1482 ap->logbufs != 0 &&
1483 (ap->logbufs < XLOG_MIN_ICLOGS ||
1484 ap->logbufs > XLOG_MAX_ICLOGS)) {
1485 cmn_err(CE_WARN,
1486 "XFS: invalid logbufs value: %d [not %d-%d]",
1487 ap->logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
1488 return XFS_ERROR(EINVAL);
1489 }
1490 mp->m_logbufs = ap->logbufs;
1491 if (ap->logbufsize != -1 &&
1492 ap->logbufsize != 0 &&
1493 (ap->logbufsize < XLOG_MIN_RECORD_BSIZE ||
1494 ap->logbufsize > XLOG_MAX_RECORD_BSIZE ||
1495 !is_power_of_2(ap->logbufsize))) {
1496 cmn_err(CE_WARN,
1497 "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
1498 ap->logbufsize);
1499 return XFS_ERROR(EINVAL);
1500 }
a738159d
CH
1501
1502 error = ENOMEM;
1503
f8f15e42
CH
1504 mp->m_logbsize = ap->logbufsize;
1505 mp->m_fsname_len = strlen(ap->fsname) + 1;
a738159d
CH
1506
1507 mp->m_fsname = kstrdup(ap->fsname, GFP_KERNEL);
1508 if (!mp->m_fsname)
1509 goto out;
1510
f8f15e42 1511 if (ap->rtname[0]) {
a738159d
CH
1512 mp->m_rtname = kstrdup(ap->rtname, GFP_KERNEL);
1513 if (!mp->m_rtname)
1514 goto out_free_fsname;
1515
f8f15e42 1516 }
a738159d 1517
f8f15e42 1518 if (ap->logname[0]) {
a738159d
CH
1519 mp->m_logname = kstrdup(ap->logname, GFP_KERNEL);
1520 if (!mp->m_logname)
1521 goto out_free_rtname;
f8f15e42
CH
1522 }
1523
1524 if (ap->flags & XFSMNT_WSYNC)
1525 mp->m_flags |= XFS_MOUNT_WSYNC;
1526#if XFS_BIG_INUMS
1527 if (ap->flags & XFSMNT_INO64) {
1528 mp->m_flags |= XFS_MOUNT_INO64;
1529 mp->m_inoadd = XFS_INO64_OFFSET;
1530 }
1531#endif
1532 if (ap->flags & XFSMNT_RETERR)
1533 mp->m_flags |= XFS_MOUNT_RETERR;
1534 if (ap->flags & XFSMNT_NOALIGN)
1535 mp->m_flags |= XFS_MOUNT_NOALIGN;
1536 if (ap->flags & XFSMNT_SWALLOC)
1537 mp->m_flags |= XFS_MOUNT_SWALLOC;
1538 if (ap->flags & XFSMNT_OSYNCISOSYNC)
1539 mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
1540 if (ap->flags & XFSMNT_32BITINODES)
1541 mp->m_flags |= XFS_MOUNT_32BITINODES;
1542
1543 if (ap->flags & XFSMNT_IOSIZE) {
1544 if (ap->iosizelog > XFS_MAX_IO_LOG ||
1545 ap->iosizelog < XFS_MIN_IO_LOG) {
1546 cmn_err(CE_WARN,
1547 "XFS: invalid log iosize: %d [not %d-%d]",
1548 ap->iosizelog, XFS_MIN_IO_LOG,
1549 XFS_MAX_IO_LOG);
1550 return XFS_ERROR(EINVAL);
1551 }
1552
1553 mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
1554 mp->m_readio_log = mp->m_writeio_log = ap->iosizelog;
1555 }
1556
1557 if (ap->flags & XFSMNT_IKEEP)
1558 mp->m_flags |= XFS_MOUNT_IKEEP;
1559 if (ap->flags & XFSMNT_DIRSYNC)
1560 mp->m_flags |= XFS_MOUNT_DIRSYNC;
1561 if (ap->flags & XFSMNT_ATTR2)
1562 mp->m_flags |= XFS_MOUNT_ATTR2;
1563 if (ap->flags & XFSMNT_NOATTR2)
1564 mp->m_flags |= XFS_MOUNT_NOATTR2;
1565
1566 if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
1567 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
1568
1569 /*
1570 * no recovery flag requires a read-only mount
1571 */
1572 if (ap->flags & XFSMNT_NORECOVERY) {
1573 if (!(mp->m_flags & XFS_MOUNT_RDONLY)) {
1574 cmn_err(CE_WARN,
1575 "XFS: tried to mount a FS read-write without recovery!");
1576 return XFS_ERROR(EINVAL);
1577 }
1578 mp->m_flags |= XFS_MOUNT_NORECOVERY;
1579 }
1580
1581 if (ap->flags & XFSMNT_NOUUID)
1582 mp->m_flags |= XFS_MOUNT_NOUUID;
1583 if (ap->flags & XFSMNT_BARRIER)
1584 mp->m_flags |= XFS_MOUNT_BARRIER;
1585 else
1586 mp->m_flags &= ~XFS_MOUNT_BARRIER;
1587
1588 if (ap->flags2 & XFSMNT2_FILESTREAMS)
1589 mp->m_flags |= XFS_MOUNT_FILESTREAMS;
1590
1591 if (ap->flags & XFSMNT_DMAPI)
1592 mp->m_flags |= XFS_MOUNT_DMAPI;
1593 return 0;
a738159d
CH
1594
1595
1596 out_free_rtname:
1597 kfree(mp->m_rtname);
1598 out_free_fsname:
1599 kfree(mp->m_fsname);
1600 out:
1601 return error;
f8f15e42
CH
1602}
1603
1604/*
1605 * This function fills in xfs_mount_t fields based on mount args.
1606 * Note: the superblock _has_ now been read in.
1607 */
1608STATIC int
1609xfs_finish_flags(
1610 struct xfs_mount_args *ap,
1611 struct xfs_mount *mp)
1612{
1613 int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
1614
1615 /* Fail a mount where the logbuf is smaller then the log stripe */
1616 if (xfs_sb_version_haslogv2(&mp->m_sb)) {
1617 if ((ap->logbufsize <= 0) &&
1618 (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) {
1619 mp->m_logbsize = mp->m_sb.sb_logsunit;
1620 } else if (ap->logbufsize > 0 &&
1621 ap->logbufsize < mp->m_sb.sb_logsunit) {
1622 cmn_err(CE_WARN,
1623 "XFS: logbuf size must be greater than or equal to log stripe size");
1624 return XFS_ERROR(EINVAL);
1625 }
1626 } else {
1627 /* Fail a mount if the logbuf is larger than 32K */
1628 if (ap->logbufsize > XLOG_BIG_RECORD_BSIZE) {
1629 cmn_err(CE_WARN,
1630 "XFS: logbuf size for version 1 logs must be 16K or 32K");
1631 return XFS_ERROR(EINVAL);
1632 }
1633 }
1634
1635 /*
1636 * mkfs'ed attr2 will turn on attr2 mount unless explicitly
1637 * told by noattr2 to turn it off
1638 */
1639 if (xfs_sb_version_hasattr2(&mp->m_sb) &&
1640 !(ap->flags & XFSMNT_NOATTR2))
1641 mp->m_flags |= XFS_MOUNT_ATTR2;
1642
1643 /*
1644 * prohibit r/w mounts of read-only filesystems
1645 */
1646 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
1647 cmn_err(CE_WARN,
1648 "XFS: cannot mount a read-only filesystem as read-write");
1649 return XFS_ERROR(EROFS);
1650 }
1651
1652 /*
1653 * check for shared mount.
1654 */
1655 if (ap->flags & XFSMNT_SHARED) {
1656 if (!xfs_sb_version_hasshared(&mp->m_sb))
1657 return XFS_ERROR(EINVAL);
1658
1659 /*
1660 * For IRIX 6.5, shared mounts must have the shared
1661 * version bit set, have the persistent readonly
1662 * field set, must be version 0 and can only be mounted
1663 * read-only.
1664 */
1665 if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) ||
1666 (mp->m_sb.sb_shared_vn != 0))
1667 return XFS_ERROR(EINVAL);
1668
1669 mp->m_flags |= XFS_MOUNT_SHARED;
1670
1671 /*
1672 * Shared XFS V0 can't deal with DMI. Return EINVAL.
1673 */
1674 if (mp->m_sb.sb_shared_vn == 0 && (ap->flags & XFSMNT_DMAPI))
1675 return XFS_ERROR(EINVAL);
1676 }
1677
1678 if (ap->flags & XFSMNT_UQUOTA) {
1679 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
1680 if (ap->flags & XFSMNT_UQUOTAENF)
1681 mp->m_qflags |= XFS_UQUOTA_ENFD;
1682 }
1683
1684 if (ap->flags & XFSMNT_GQUOTA) {
1685 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
1686 if (ap->flags & XFSMNT_GQUOTAENF)
1687 mp->m_qflags |= XFS_OQUOTA_ENFD;
1688 } else if (ap->flags & XFSMNT_PQUOTA) {
1689 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
1690 if (ap->flags & XFSMNT_PQUOTAENF)
1691 mp->m_qflags |= XFS_OQUOTA_ENFD;
1692 }
1693
1694 return 0;
1695}
1696
1da177e4 1697STATIC int
a50cd269 1698xfs_fs_fill_super(
1da177e4
LT
1699 struct super_block *sb,
1700 void *data,
1701 int silent)
1702{
f3dcc13f 1703 struct inode *root;
745f6919 1704 struct xfs_mount *mp = NULL;
bdd907ba 1705 struct xfs_mount_args *args;
c962fb79 1706 int flags = 0, error = ENOMEM;
1da177e4 1707
bdd907ba
CH
1708 args = xfs_args_allocate(sb, silent);
1709 if (!args)
1710 return -ENOMEM;
1711
c962fb79
CH
1712 mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
1713 if (!mp)
1714 goto out_free_args;
1da177e4 1715
c962fb79
CH
1716 spin_lock_init(&mp->m_sb_lock);
1717 mutex_init(&mp->m_ilock);
1718 mutex_init(&mp->m_growlock);
1719 atomic_set(&mp->m_active_trans, 0);
74394496
CH
1720 INIT_LIST_HEAD(&mp->m_sync_list);
1721 spin_lock_init(&mp->m_sync_lock);
1722 init_waitqueue_head(&mp->m_wait_single_sync_task);
1723
b267ce99
CH
1724 mp->m_super = sb;
1725 sb->s_fs_info = mp;
1da177e4 1726
bd186aa9
CH
1727 if (sb->s_flags & MS_RDONLY)
1728 mp->m_flags |= XFS_MOUNT_RDONLY;
1729
745f6919
CH
1730 error = xfs_parseargs(mp, (char *)data, args, 0);
1731 if (error)
c962fb79 1732 goto out_free_mp;
1da177e4
LT
1733
1734 sb_min_blocksize(sb, BBSIZE);
0ec58516 1735 sb->s_xattr = xfs_xattr_handlers;
a50cd269 1736 sb->s_export_op = &xfs_export_operations;
a50cd269
NS
1737 sb->s_qcop = &xfs_quotactl_operations;
1738 sb->s_op = &xfs_super_operations;
1da177e4 1739
f8f15e42
CH
1740 error = xfs_dmops_get(mp, args);
1741 if (error)
c962fb79 1742 goto out_free_mp;
f8f15e42 1743 error = xfs_qmops_get(mp, args);
745f6919 1744 if (error)
19f354d4 1745 goto out_put_dmops;
1da177e4 1746
f8f15e42
CH
1747 if (args->flags & XFSMNT_QUIET)
1748 flags |= XFS_MFSI_QUIET;
1749
19f354d4
CH
1750 error = xfs_open_devices(mp, args);
1751 if (error)
1752 goto out_put_qmops;
f8f15e42 1753
c962fb79
CH
1754 if (xfs_icsb_init_counters(mp))
1755 mp->m_flags |= XFS_MOUNT_NO_PERCPU_SB;
1756
f8f15e42
CH
1757 /*
1758 * Setup flags based on mount(2) options and then the superblock
1759 */
1760 error = xfs_start_flags(args, mp);
1761 if (error)
a738159d 1762 goto out_free_fsname;
f8f15e42
CH
1763 error = xfs_readsb(mp, flags);
1764 if (error)
a738159d 1765 goto out_free_fsname;
f8f15e42
CH
1766 error = xfs_finish_flags(args, mp);
1767 if (error)
effa2eda 1768 goto out_free_sb;
f8f15e42 1769
e34b562c 1770 error = xfs_setup_devices(mp);
19f354d4 1771 if (error)
effa2eda 1772 goto out_free_sb;
f8f15e42
CH
1773
1774 if (mp->m_flags & XFS_MOUNT_BARRIER)
1775 xfs_mountfs_check_barriers(mp);
1776
1777 error = xfs_filestream_mount(mp);
1778 if (error)
effa2eda 1779 goto out_free_sb;
f8f15e42 1780
4249023a 1781 error = xfs_mountfs(mp);
f8f15e42 1782 if (error)
120226c1 1783 goto out_filestream_unmount;
f8f15e42
CH
1784
1785 XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, args->mtpt, args->fsname);
1786
1da177e4 1787 sb->s_dirt = 1;
4ca488eb
CH
1788 sb->s_magic = XFS_SB_MAGIC;
1789 sb->s_blocksize = mp->m_sb.sb_blocksize;
1790 sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
1da177e4
LT
1791 sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
1792 sb->s_time_gran = 1;
1793 set_posix_acl_flag(sb);
1794
01651646 1795 root = igrab(VFS_I(mp->m_rootip));
f3dcc13f 1796 if (!root) {
cbc89dcf 1797 error = ENOENT;
1da177e4 1798 goto fail_unmount;
cbc89dcf 1799 }
f3dcc13f
CH
1800 if (is_bad_inode(root)) {
1801 error = EINVAL;
1da177e4
LT
1802 goto fail_vnrele;
1803 }
f3dcc13f
CH
1804 sb->s_root = d_alloc_root(root);
1805 if (!sb->s_root) {
1806 error = ENOMEM;
1da177e4
LT
1807 goto fail_vnrele;
1808 }
74394496
CH
1809
1810 mp->m_sync_work.w_syncer = xfs_sync_worker;
1811 mp->m_sync_work.w_mount = mp;
1812 mp->m_sync_task = kthread_run(xfssyncd, mp, "xfssyncd");
1813 if (IS_ERR(mp->m_sync_task)) {
1814 error = -PTR_ERR(mp->m_sync_task);
1da177e4 1815 goto fail_vnrele;
74394496
CH
1816 }
1817
cf441eeb 1818 xfs_itrace_exit(XFS_I(sb->s_root->d_inode));
1da177e4 1819
bdd907ba 1820 kfree(args);
1da177e4
LT
1821 return 0;
1822
120226c1
CH
1823 out_filestream_unmount:
1824 xfs_filestream_unmount(mp);
effa2eda
CH
1825 out_free_sb:
1826 xfs_freesb(mp);
a738159d
CH
1827 out_free_fsname:
1828 xfs_free_fsname(mp);
c962fb79 1829 xfs_icsb_destroy_counters(mp);
19f354d4
CH
1830 xfs_close_devices(mp);
1831 out_put_qmops:
f8f15e42 1832 xfs_qmops_put(mp);
19f354d4 1833 out_put_dmops:
f8f15e42 1834 xfs_dmops_put(mp);
c962fb79
CH
1835 out_free_mp:
1836 kfree(mp);
1837 out_free_args:
1838 kfree(args);
1839 return -error;
f8f15e42
CH
1840
1841 fail_vnrele:
1da177e4
LT
1842 if (sb->s_root) {
1843 dput(sb->s_root);
1844 sb->s_root = NULL;
1845 } else {
f3dcc13f 1846 iput(root);
1da177e4
LT
1847 }
1848
f8f15e42 1849 fail_unmount:
e48ad316
CH
1850 /*
1851 * Blow away any referenced inode in the filestreams cache.
1852 * This can and will cause log traffic as inodes go inactive
1853 * here.
1854 */
1855 xfs_filestream_unmount(mp);
1856
1857 XFS_bflush(mp->m_ddev_targp);
1858 error = xfs_unmount_flush(mp, 0);
1859 WARN_ON(error);
1860
19f354d4 1861 xfs_unmountfs(mp);
6203300e 1862 goto out_free_sb;
1da177e4
LT
1863}
1864
454e2398 1865STATIC int
a50cd269 1866xfs_fs_get_sb(
1da177e4
LT
1867 struct file_system_type *fs_type,
1868 int flags,
1869 const char *dev_name,
454e2398
DH
1870 void *data,
1871 struct vfsmount *mnt)
1da177e4 1872{
454e2398
DH
1873 return get_sb_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super,
1874 mnt);
a50cd269
NS
1875}
1876
7989cb8e 1877static struct super_operations xfs_super_operations = {
a50cd269
NS
1878 .alloc_inode = xfs_fs_alloc_inode,
1879 .destroy_inode = xfs_fs_destroy_inode,
1880 .write_inode = xfs_fs_write_inode,
1881 .clear_inode = xfs_fs_clear_inode,
1882 .put_super = xfs_fs_put_super,
1883 .write_super = xfs_fs_write_super,
1884 .sync_fs = xfs_fs_sync_super,
1885 .write_super_lockfs = xfs_fs_lockfs,
1886 .statfs = xfs_fs_statfs,
1887 .remount_fs = xfs_fs_remount,
1888 .show_options = xfs_fs_show_options,
1da177e4
LT
1889};
1890
7989cb8e 1891static struct quotactl_ops xfs_quotactl_operations = {
a50cd269
NS
1892 .quota_sync = xfs_fs_quotasync,
1893 .get_xstate = xfs_fs_getxstate,
1894 .set_xstate = xfs_fs_setxstate,
1895 .get_xquota = xfs_fs_getxquota,
1896 .set_xquota = xfs_fs_setxquota,
1da177e4
LT
1897};
1898
5085b607 1899static struct file_system_type xfs_fs_type = {
1da177e4
LT
1900 .owner = THIS_MODULE,
1901 .name = "xfs",
a50cd269 1902 .get_sb = xfs_fs_get_sb,
1da177e4
LT
1903 .kill_sb = kill_block_super,
1904 .fs_flags = FS_REQUIRES_DEV,
1905};
1906
9f8868ff
CH
1907STATIC int __init
1908xfs_alloc_trace_bufs(void)
1909{
1910#ifdef XFS_ALLOC_TRACE
1911 xfs_alloc_trace_buf = ktrace_alloc(XFS_ALLOC_TRACE_SIZE, KM_MAYFAIL);
1912 if (!xfs_alloc_trace_buf)
1913 goto out;
1914#endif
1915#ifdef XFS_BMAP_TRACE
1916 xfs_bmap_trace_buf = ktrace_alloc(XFS_BMAP_TRACE_SIZE, KM_MAYFAIL);
1917 if (!xfs_bmap_trace_buf)
1918 goto out_free_alloc_trace;
1919#endif
8c4ed633
CH
1920#ifdef XFS_BTREE_TRACE
1921 xfs_allocbt_trace_buf = ktrace_alloc(XFS_ALLOCBT_TRACE_SIZE,
1922 KM_MAYFAIL);
1923 if (!xfs_allocbt_trace_buf)
1924 goto out_free_bmap_trace;
1925
1926 xfs_inobt_trace_buf = ktrace_alloc(XFS_INOBT_TRACE_SIZE, KM_MAYFAIL);
1927 if (!xfs_inobt_trace_buf)
1928 goto out_free_allocbt_trace;
1929
9f8868ff
CH
1930 xfs_bmbt_trace_buf = ktrace_alloc(XFS_BMBT_TRACE_SIZE, KM_MAYFAIL);
1931 if (!xfs_bmbt_trace_buf)
8c4ed633 1932 goto out_free_inobt_trace;
9f8868ff
CH
1933#endif
1934#ifdef XFS_ATTR_TRACE
1935 xfs_attr_trace_buf = ktrace_alloc(XFS_ATTR_TRACE_SIZE, KM_MAYFAIL);
1936 if (!xfs_attr_trace_buf)
1937 goto out_free_bmbt_trace;
1938#endif
1939#ifdef XFS_DIR2_TRACE
1940 xfs_dir2_trace_buf = ktrace_alloc(XFS_DIR2_GTRACE_SIZE, KM_MAYFAIL);
1941 if (!xfs_dir2_trace_buf)
1942 goto out_free_attr_trace;
1943#endif
1944
1945 return 0;
1946
1947#ifdef XFS_DIR2_TRACE
1948 out_free_attr_trace:
1949#endif
1950#ifdef XFS_ATTR_TRACE
1951 ktrace_free(xfs_attr_trace_buf);
1952 out_free_bmbt_trace:
1953#endif
8c4ed633 1954#ifdef XFS_BTREE_TRACE
9f8868ff 1955 ktrace_free(xfs_bmbt_trace_buf);
8c4ed633
CH
1956 out_free_inobt_trace:
1957 ktrace_free(xfs_inobt_trace_buf);
1958 out_free_allocbt_trace:
1959 ktrace_free(xfs_allocbt_trace_buf);
9f8868ff
CH
1960 out_free_bmap_trace:
1961#endif
1962#ifdef XFS_BMAP_TRACE
1963 ktrace_free(xfs_bmap_trace_buf);
1964 out_free_alloc_trace:
1965#endif
1966#ifdef XFS_ALLOC_TRACE
1967 ktrace_free(xfs_alloc_trace_buf);
1968 out:
1969#endif
1970 return -ENOMEM;
1971}
1972
1973STATIC void
1974xfs_free_trace_bufs(void)
1975{
1976#ifdef XFS_DIR2_TRACE
1977 ktrace_free(xfs_dir2_trace_buf);
1978#endif
1979#ifdef XFS_ATTR_TRACE
1980 ktrace_free(xfs_attr_trace_buf);
1981#endif
8c4ed633 1982#ifdef XFS_BTREE_TRACE
9f8868ff 1983 ktrace_free(xfs_bmbt_trace_buf);
8c4ed633
CH
1984 ktrace_free(xfs_inobt_trace_buf);
1985 ktrace_free(xfs_allocbt_trace_buf);
9f8868ff
CH
1986#endif
1987#ifdef XFS_BMAP_TRACE
1988 ktrace_free(xfs_bmap_trace_buf);
1989#endif
1990#ifdef XFS_ALLOC_TRACE
1991 ktrace_free(xfs_alloc_trace_buf);
1992#endif
1993}
1994
1995STATIC int __init
1996xfs_init_zones(void)
1997{
5ec7f8c7 1998 xfs_vnode_zone = kmem_zone_init_flags(sizeof(struct inode), "xfs_vnode",
9f8868ff
CH
1999 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM |
2000 KM_ZONE_SPREAD,
2001 xfs_fs_inode_init_once);
2002 if (!xfs_vnode_zone)
2003 goto out;
2004
2005 xfs_ioend_zone = kmem_zone_init(sizeof(xfs_ioend_t), "xfs_ioend");
2006 if (!xfs_ioend_zone)
2007 goto out_destroy_vnode_zone;
2008
2009 xfs_ioend_pool = mempool_create_slab_pool(4 * MAX_BUF_PER_PAGE,
2010 xfs_ioend_zone);
2011 if (!xfs_ioend_pool)
2012 goto out_destroy_ioend_zone;
2013
2014 xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t),
2015 "xfs_log_ticket");
2016 if (!xfs_log_ticket_zone)
2017 goto out_destroy_ioend_pool;
2018
2019 xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
2020 "xfs_bmap_free_item");
2021 if (!xfs_bmap_free_item_zone)
2022 goto out_destroy_log_ticket_zone;
2023 xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
2024 "xfs_btree_cur");
2025 if (!xfs_btree_cur_zone)
2026 goto out_destroy_bmap_free_item_zone;
2027
2028 xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t),
2029 "xfs_da_state");
2030 if (!xfs_da_state_zone)
2031 goto out_destroy_btree_cur_zone;
2032
2033 xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf");
2034 if (!xfs_dabuf_zone)
2035 goto out_destroy_da_state_zone;
2036
2037 xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
2038 if (!xfs_ifork_zone)
2039 goto out_destroy_dabuf_zone;
2040
2041 xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
2042 if (!xfs_trans_zone)
2043 goto out_destroy_ifork_zone;
2044
2045 /*
2046 * The size of the zone allocated buf log item is the maximum
2047 * size possible under XFS. This wastes a little bit of memory,
2048 * but it is much faster.
2049 */
2050 xfs_buf_item_zone = kmem_zone_init((sizeof(xfs_buf_log_item_t) +
2051 (((XFS_MAX_BLOCKSIZE / XFS_BLI_CHUNK) /
2052 NBWORD) * sizeof(int))), "xfs_buf_item");
2053 if (!xfs_buf_item_zone)
2054 goto out_destroy_trans_zone;
2055
2056 xfs_efd_zone = kmem_zone_init((sizeof(xfs_efd_log_item_t) +
2057 ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
2058 sizeof(xfs_extent_t))), "xfs_efd_item");
2059 if (!xfs_efd_zone)
2060 goto out_destroy_buf_item_zone;
2061
2062 xfs_efi_zone = kmem_zone_init((sizeof(xfs_efi_log_item_t) +
2063 ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
2064 sizeof(xfs_extent_t))), "xfs_efi_item");
2065 if (!xfs_efi_zone)
2066 goto out_destroy_efd_zone;
2067
2068 xfs_inode_zone =
2069 kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
2070 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM |
07c8f675 2071 KM_ZONE_SPREAD, xfs_inode_init_once);
9f8868ff
CH
2072 if (!xfs_inode_zone)
2073 goto out_destroy_efi_zone;
2074
2075 xfs_ili_zone =
2076 kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
2077 KM_ZONE_SPREAD, NULL);
2078 if (!xfs_ili_zone)
2079 goto out_destroy_inode_zone;
2080
2081#ifdef CONFIG_XFS_POSIX_ACL
2082 xfs_acl_zone = kmem_zone_init(sizeof(xfs_acl_t), "xfs_acl");
2083 if (!xfs_acl_zone)
2084 goto out_destroy_ili_zone;
2085#endif
2086
2087 return 0;
2088
2089#ifdef CONFIG_XFS_POSIX_ACL
2090 out_destroy_ili_zone:
2091#endif
2092 kmem_zone_destroy(xfs_ili_zone);
2093 out_destroy_inode_zone:
2094 kmem_zone_destroy(xfs_inode_zone);
2095 out_destroy_efi_zone:
2096 kmem_zone_destroy(xfs_efi_zone);
2097 out_destroy_efd_zone:
2098 kmem_zone_destroy(xfs_efd_zone);
2099 out_destroy_buf_item_zone:
2100 kmem_zone_destroy(xfs_buf_item_zone);
2101 out_destroy_trans_zone:
2102 kmem_zone_destroy(xfs_trans_zone);
2103 out_destroy_ifork_zone:
2104 kmem_zone_destroy(xfs_ifork_zone);
2105 out_destroy_dabuf_zone:
2106 kmem_zone_destroy(xfs_dabuf_zone);
2107 out_destroy_da_state_zone:
2108 kmem_zone_destroy(xfs_da_state_zone);
2109 out_destroy_btree_cur_zone:
2110 kmem_zone_destroy(xfs_btree_cur_zone);
2111 out_destroy_bmap_free_item_zone:
2112 kmem_zone_destroy(xfs_bmap_free_item_zone);
2113 out_destroy_log_ticket_zone:
2114 kmem_zone_destroy(xfs_log_ticket_zone);
2115 out_destroy_ioend_pool:
2116 mempool_destroy(xfs_ioend_pool);
2117 out_destroy_ioend_zone:
2118 kmem_zone_destroy(xfs_ioend_zone);
2119 out_destroy_vnode_zone:
2120 kmem_zone_destroy(xfs_vnode_zone);
2121 out:
2122 return -ENOMEM;
2123}
2124
2125STATIC void
2126xfs_destroy_zones(void)
2127{
2128#ifdef CONFIG_XFS_POSIX_ACL
2129 kmem_zone_destroy(xfs_acl_zone);
2130#endif
2131 kmem_zone_destroy(xfs_ili_zone);
2132 kmem_zone_destroy(xfs_inode_zone);
2133 kmem_zone_destroy(xfs_efi_zone);
2134 kmem_zone_destroy(xfs_efd_zone);
2135 kmem_zone_destroy(xfs_buf_item_zone);
2136 kmem_zone_destroy(xfs_trans_zone);
2137 kmem_zone_destroy(xfs_ifork_zone);
2138 kmem_zone_destroy(xfs_dabuf_zone);
2139 kmem_zone_destroy(xfs_da_state_zone);
2140 kmem_zone_destroy(xfs_btree_cur_zone);
2141 kmem_zone_destroy(xfs_bmap_free_item_zone);
2142 kmem_zone_destroy(xfs_log_ticket_zone);
2143 mempool_destroy(xfs_ioend_pool);
2144 kmem_zone_destroy(xfs_ioend_zone);
2145 kmem_zone_destroy(xfs_vnode_zone);
2146
2147}
1da177e4
LT
2148
2149STATIC int __init
9f8868ff 2150init_xfs_fs(void)
1da177e4
LT
2151{
2152 int error;
1da177e4
LT
2153 static char message[] __initdata = KERN_INFO \
2154 XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled\n";
2155
2156 printk(message);
2157
1da177e4 2158 ktrace_init(64);
9f8868ff
CH
2159 vn_init();
2160 xfs_dir_startup();
1da177e4 2161
8758280f 2162 error = xfs_init_zones();
9f8868ff
CH
2163 if (error)
2164 goto out;
2165
2166 error = xfs_alloc_trace_bufs();
2167 if (error)
2168 goto out_destroy_zones;
2169
2170 error = xfs_mru_cache_init();
2171 if (error)
2172 goto out_free_trace_buffers;
2173
2174 error = xfs_filestream_init();
2175 if (error)
2176 goto out_mru_cache_uninit;
1da177e4 2177
ce8e922c 2178 error = xfs_buf_init();
9f8868ff
CH
2179 if (error)
2180 goto out_filestream_uninit;
2181
2182 error = xfs_init_procfs();
2183 if (error)
2184 goto out_buf_terminate;
2185
2186 error = xfs_sysctl_register();
2187 if (error)
2188 goto out_cleanup_procfs;
1da177e4 2189
1da177e4
LT
2190 vfs_initquota();
2191
2192 error = register_filesystem(&xfs_fs_type);
2193 if (error)
9f8868ff 2194 goto out_sysctl_unregister;
1da177e4
LT
2195 return 0;
2196
9f8868ff
CH
2197 out_sysctl_unregister:
2198 xfs_sysctl_unregister();
2199 out_cleanup_procfs:
2200 xfs_cleanup_procfs();
2201 out_buf_terminate:
ce8e922c 2202 xfs_buf_terminate();
9f8868ff
CH
2203 out_filestream_uninit:
2204 xfs_filestream_uninit();
2205 out_mru_cache_uninit:
2206 xfs_mru_cache_uninit();
2207 out_free_trace_buffers:
2208 xfs_free_trace_bufs();
2209 out_destroy_zones:
8758280f 2210 xfs_destroy_zones();
9f8868ff 2211 out:
1da177e4
LT
2212 return error;
2213}
2214
2215STATIC void __exit
9f8868ff 2216exit_xfs_fs(void)
1da177e4
LT
2217{
2218 vfs_exitquota();
1da177e4 2219 unregister_filesystem(&xfs_fs_type);
9f8868ff
CH
2220 xfs_sysctl_unregister();
2221 xfs_cleanup_procfs();
ce8e922c 2222 xfs_buf_terminate();
9f8868ff
CH
2223 xfs_filestream_uninit();
2224 xfs_mru_cache_uninit();
2225 xfs_free_trace_bufs();
8758280f 2226 xfs_destroy_zones();
1da177e4
LT
2227 ktrace_uninit();
2228}
2229
2230module_init(init_xfs_fs);
2231module_exit(exit_xfs_fs);
2232
2233MODULE_AUTHOR("Silicon Graphics, Inc.");
2234MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
2235MODULE_LICENSE("GPL");
This page took 0.534328 seconds and 5 git commands to generate.