2 * Copyright (c) 2000-2006 Silicon Graphics, Inc.
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
7 * published by the Free Software Foundation.
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.
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
23 #include "xfs_trans.h"
27 #include "xfs_alloc.h"
28 #include "xfs_dmapi.h"
29 #include "xfs_quota.h"
30 #include "xfs_mount.h"
31 #include "xfs_bmap_btree.h"
32 #include "xfs_alloc_btree.h"
33 #include "xfs_ialloc_btree.h"
34 #include "xfs_dir2_sf.h"
35 #include "xfs_attr_sf.h"
36 #include "xfs_dinode.h"
37 #include "xfs_inode.h"
38 #include "xfs_btree.h"
39 #include "xfs_btree_trace.h"
40 #include "xfs_ialloc.h"
42 #include "xfs_rtalloc.h"
43 #include "xfs_error.h"
44 #include "xfs_itable.h"
45 #include "xfs_fsops.h"
49 #include "xfs_buf_item.h"
50 #include "xfs_utils.h"
51 #include "xfs_vnodeops.h"
52 #include "xfs_vfsops.h"
53 #include "xfs_version.h"
54 #include "xfs_log_priv.h"
55 #include "xfs_trans_priv.h"
56 #include "xfs_filestream.h"
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"
64 #include <linux/namei.h>
65 #include <linux/init.h>
66 #include <linux/mount.h>
67 #include <linux/mempool.h>
68 #include <linux/writeback.h>
69 #include <linux/kthread.h>
70 #include <linux/freezer.h>
71 #include <linux/parser.h>
73 static struct quotactl_ops xfs_quotactl_operations;
74 static struct super_operations xfs_super_operations;
75 static kmem_zone_t *xfs_ioend_zone;
76 mempool_t *xfs_ioend_pool;
78 STATIC struct xfs_mount_args *
80 struct super_block *sb,
83 struct xfs_mount_args *args;
85 args = kzalloc(sizeof(struct xfs_mount_args), GFP_KERNEL);
89 args->logbufs = args->logbufsize = -1;
90 strncpy(args->fsname, sb->s_id, MAXNAMELEN);
92 /* Copy the already-parsed mount(2) flags we're interested in */
93 if (sb->s_flags & MS_DIRSYNC)
94 args->flags |= XFSMNT_DIRSYNC;
95 if (sb->s_flags & MS_SYNCHRONOUS)
96 args->flags |= XFSMNT_WSYNC;
98 args->flags |= XFSMNT_QUIET;
99 args->flags |= XFSMNT_32BITINODES;
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
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) */
153 * Table driven mount option parser.
155 * Currently only used for remount, but it will be used for mount
156 * in the future, too.
159 Opt_barrier, Opt_nobarrier, Opt_err
162 static const match_table_t tokens = {
163 {Opt_barrier, "barrier"},
164 {Opt_nobarrier, "nobarrier"},
170 suffix_strtoul(char *s, char **endp, unsigned int base)
172 int last, shift_left_factor = 0;
175 last = strlen(value) - 1;
176 if (value[last] == 'K' || value[last] == 'k') {
177 shift_left_factor = 10;
180 if (value[last] == 'M' || value[last] == 'm') {
181 shift_left_factor = 20;
184 if (value[last] == 'G' || value[last] == 'g') {
185 shift_left_factor = 30;
189 return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
194 struct xfs_mount *mp,
196 struct xfs_mount_args *args,
199 char *this_char, *value, *eov;
200 int dsunit, dswidth, vol_dsunit, vol_dswidth;
202 int dmapi_implies_ikeep = 1;
204 args->flags |= XFSMNT_BARRIER;
205 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
210 iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0;
212 while ((this_char = strsep(&options, ",")) != NULL) {
215 if ((value = strchr(this_char, '=')) != NULL)
218 if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
219 if (!value || !*value) {
221 "XFS: %s option requires an argument",
225 args->logbufs = simple_strtoul(value, &eov, 10);
226 } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
227 if (!value || !*value) {
229 "XFS: %s option requires an argument",
233 args->logbufsize = suffix_strtoul(value, &eov, 10);
234 } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
235 if (!value || !*value) {
237 "XFS: %s option requires an argument",
241 strncpy(args->logname, value, MAXNAMELEN);
242 } else if (!strcmp(this_char, MNTOPT_MTPT)) {
243 if (!value || !*value) {
245 "XFS: %s option requires an argument",
249 strncpy(args->mtpt, value, MAXNAMELEN);
250 } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
251 if (!value || !*value) {
253 "XFS: %s option requires an argument",
257 strncpy(args->rtname, value, MAXNAMELEN);
258 } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
259 if (!value || !*value) {
261 "XFS: %s option requires an argument",
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) {
271 "XFS: %s option requires an argument",
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;
294 "XFS: %s option not allowed on this system",
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) {
305 "XFS: %s option requires an argument",
309 dsunit = simple_strtoul(value, &eov, 10);
310 } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
311 if (!value || !*value) {
313 "XFS: %s option requires an argument",
317 dswidth = simple_strtoul(value, &eov, 10);
318 } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
319 args->flags &= ~XFSMNT_32BITINODES;
322 "XFS: %s option not allowed on this system",
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)) {
333 args->flags |= XFSMNT_IKEEP;
334 } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
335 dmapi_implies_ikeep = 0;
336 args->flags &= ~XFSMNT_IKEEP;
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;
345 args->flags |= XFSMNT_NOATTR2;
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")) {
379 "XFS: ihashsize no longer used, option is deprecated.");
380 } else if (!strcmp(this_char, "osyncisdsync")) {
381 /* no-op, this is now the default */
383 "XFS: osyncisdsync is now the default, option is deprecated.");
384 } else if (!strcmp(this_char, "irixsgid")) {
386 "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
389 "XFS: unknown mount option [%s].", this_char);
394 if (args->flags & XFSMNT_NORECOVERY) {
395 if ((mp->m_flags & XFS_MOUNT_RDONLY) == 0) {
397 "XFS: no-recovery mounts must be read-only.");
402 if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) {
404 "XFS: sunit and swidth options incompatible with the noalign option");
408 if ((args->flags & XFSMNT_GQUOTA) && (args->flags & XFSMNT_PQUOTA)) {
410 "XFS: cannot mount with both project and group quota");
414 if ((args->flags & XFSMNT_DMAPI) && *args->mtpt == '\0') {
415 printk("XFS: %s option needs the mount point option as well\n",
420 if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
422 "XFS: sunit and swidth must be specified together");
426 if (dsunit && (dswidth % dsunit != 0)) {
428 "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
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.
442 if ((args->flags & XFSMNT_DMAPI) && dmapi_implies_ikeep)
443 args->flags |= XFSMNT_IKEEP;
445 if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
447 args->sunit = dsunit;
448 args->flags |= XFSMNT_RETERR;
450 args->sunit = vol_dsunit;
452 dswidth ? (args->swidth = dswidth) :
453 (args->swidth = vol_dswidth);
455 args->sunit = args->swidth = 0;
459 if (args->flags & XFSMNT_32BITINODES)
460 mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
462 args->flags |= XFSMNT_FLAGS2;
466 struct proc_xfs_info {
473 struct xfs_mount *mp,
476 static struct proc_xfs_info xfs_info_set[] = {
477 /* the few simple ones we can get from the mount struct */
478 { XFS_MOUNT_IKEEP, "," MNTOPT_IKEEP },
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 },
492 static struct proc_xfs_info xfs_info_unset[] = {
493 /* the few simple ones we can get from the mount struct */
494 { XFS_MOUNT_COMPAT_IOSIZE, "," MNTOPT_LARGEIO },
495 { XFS_MOUNT_BARRIER, "," MNTOPT_NOBARRIER },
496 { XFS_MOUNT_SMALL_INUMS, "," MNTOPT_64BITINODE },
499 struct proc_xfs_info *xfs_infop;
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);
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);
510 if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
511 seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
512 (int)(1 << mp->m_writeio_log) >> 10);
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);
520 seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
522 seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
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));
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);
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);
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);
546 if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
547 seq_puts(m, "," MNTOPT_NOQUOTA);
553 unsigned int blockshift)
555 unsigned int pagefactor = 1;
556 unsigned int bitshift = BITS_PER_LONG - 1;
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.
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;
578 pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift);
582 return (((__uint64_t)pagefactor) << bitshift) - 1;
589 struct block_device **bdevp)
593 *bdevp = open_bdev_exclusive(name, FMODE_READ|FMODE_WRITE, mp);
594 if (IS_ERR(*bdevp)) {
595 error = PTR_ERR(*bdevp);
596 printk("XFS: Invalid device [%s], error=%d\n", name, error);
604 struct block_device *bdev)
607 close_bdev_exclusive(bdev, FMODE_READ|FMODE_WRITE);
611 * Try to write out the superblock using barriers.
617 xfs_buf_t *sbp = xfs_getsb(mp, 0);
622 XFS_BUF_UNDELAYWRITE(sbp);
624 XFS_BUF_UNASYNC(sbp);
625 XFS_BUF_ORDERED(sbp);
628 error = xfs_iowait(sbp);
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
637 XFS_BUF_ERROR(sbp, 0);
638 XFS_BUF_UNORDERED(sbp);
645 xfs_mountfs_check_barriers(xfs_mount_t *mp)
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;
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;
663 error = xfs_barrier_test(mp);
665 xfs_fs_cmn_err(CE_NOTE, mp,
666 "Disabling barriers, trial barrier write failed");
667 mp->m_flags &= ~XFS_MOUNT_BARRIER;
673 xfs_blkdev_issue_flush(
674 xfs_buftarg_t *buftarg)
676 blkdev_issue_flush(buftarg->bt_bdev, NULL);
681 struct xfs_mount *mp)
683 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
684 struct block_device *logdev = mp->m_logdev_targp->bt_bdev;
685 xfs_free_buftarg(mp->m_logdev_targp);
686 xfs_blkdev_put(logdev);
688 if (mp->m_rtdev_targp) {
689 struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev;
690 xfs_free_buftarg(mp->m_rtdev_targp);
691 xfs_blkdev_put(rtdev);
693 xfs_free_buftarg(mp->m_ddev_targp);
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.
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.
708 struct xfs_mount *mp,
709 struct xfs_mount_args *args)
711 struct block_device *ddev = mp->m_super->s_bdev;
712 struct block_device *logdev = NULL, *rtdev = NULL;
716 * Open real time and log devices - order is important.
718 if (args->logname[0]) {
719 error = xfs_blkdev_get(mp, args->logname, &logdev);
724 if (args->rtname[0]) {
725 error = xfs_blkdev_get(mp, args->rtname, &rtdev);
727 goto out_close_logdev;
729 if (rtdev == ddev || rtdev == logdev) {
731 "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
733 goto out_close_rtdev;
738 * Setup xfs_mount buffer target pointers
741 mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
742 if (!mp->m_ddev_targp)
743 goto out_close_rtdev;
746 mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
747 if (!mp->m_rtdev_targp)
748 goto out_free_ddev_targ;
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;
756 mp->m_logdev_targp = mp->m_ddev_targp;
762 if (mp->m_rtdev_targp)
763 xfs_free_buftarg(mp->m_rtdev_targp);
765 xfs_free_buftarg(mp->m_ddev_targp);
768 xfs_blkdev_put(rtdev);
770 if (logdev && logdev != ddev)
771 xfs_blkdev_put(logdev);
777 * Setup xfs_mount buffer target pointers based on superblock
781 struct xfs_mount *mp)
785 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
786 mp->m_sb.sb_sectsize);
790 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
791 unsigned int log_sector_size = BBSIZE;
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,
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);
813 * XFS AIL push thread support
818 xfs_lsn_t threshold_lsn)
820 mp->m_ail.xa_target = threshold_lsn;
821 wake_up_process(mp->m_ail.xa_task);
828 xfs_mount_t *mp = (xfs_mount_t *)data;
829 xfs_lsn_t last_pushed_lsn = 0;
832 while (!kthread_should_stop()) {
834 schedule_timeout_interruptible(msecs_to_jiffies(tout));
841 if (XFS_FORCED_SHUTDOWN(mp))
844 tout = xfsaild_push(mp, &last_pushed_lsn);
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);
865 kthread_stop(mp->m_ail.xa_task);
869 /* Catch misguided souls that try to use this interface on XFS */
870 STATIC struct inode *
872 struct super_block *sb)
878 * we need to provide an empty inode free function to prevent
879 * the generic code from trying to free our combined inode.
882 xfs_fs_destroy_inode(
888 * Slab object creation initialisation for the XFS inode.
889 * This covers only the idempotent fields in the XFS inode;
890 * all other fields need to be initialised on allocation
891 * from the slab. This avoids the need to repeatedly intialise
892 * fields in the xfs inode that left in the initialise state
893 * when freeing the inode.
896 xfs_fs_inode_init_once(
899 struct xfs_inode *ip = inode;
901 memset(ip, 0, sizeof(struct xfs_inode));
904 inode_init_once(VFS_I(ip));
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);
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.
917 init_completion(&ip->i_flush);
918 complete(&ip->i_flush);
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);
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,
929 * since this is when the inode itself becomes flushable.
939 xfs_itrace_entry(XFS_I(inode));
941 filemap_fdatawait(inode->i_mapping);
944 error = xfs_inode_flush(XFS_I(inode), flags);
946 * if we failed to write out the inode then mark
947 * it dirty again so we'll try again later.
950 xfs_mark_inode_dirty_sync(XFS_I(inode));
959 xfs_inode_t *ip = XFS_I(inode);
962 * ip can be null when xfs_iget_core calls xfs_idestroy if we
963 * find an inode with di_mode == 0 but without IGET_CREATE set.
966 xfs_itrace_entry(ip);
967 XFS_STATS_INC(vn_rele);
968 XFS_STATS_INC(vn_remove);
969 XFS_STATS_INC(vn_reclaim);
970 XFS_STATS_DEC(vn_active);
973 xfs_iflags_clear(ip, XFS_IMODIFIED);
975 panic("%s: cannot reclaim 0x%p\n", __func__, inode);
981 struct xfs_mount *mp)
985 kfree(mp->m_logname);
990 struct super_block *sb)
992 struct xfs_mount *mp = XFS_M(sb);
993 struct xfs_inode *rip = mp->m_rootip;
994 int unmount_event_flags = 0;
998 xfs_sync_inodes(mp, SYNC_ATTR|SYNC_DELWRI);
1001 if (mp->m_flags & XFS_MOUNT_DMAPI) {
1002 unmount_event_flags =
1003 (mp->m_dmevmask & (1 << DM_EVENT_UNMOUNT)) ?
1004 0 : DM_FLAGS_UNWANTED;
1006 * Ignore error from dmapi here, first unmount is not allowed
1007 * to fail anyway, and second we wouldn't want to fail a
1008 * unmount because of dmapi.
1010 XFS_SEND_PREUNMOUNT(mp, rip, DM_RIGHT_NULL, rip, DM_RIGHT_NULL,
1011 NULL, NULL, 0, 0, unmount_event_flags);
1016 * Blow away any referenced inode in the filestreams cache.
1017 * This can and will cause log traffic as inodes go inactive
1020 xfs_filestream_unmount(mp);
1022 XFS_bflush(mp->m_ddev_targp);
1023 error = xfs_unmount_flush(mp, 0);
1026 if (mp->m_flags & XFS_MOUNT_DMAPI) {
1027 XFS_SEND_UNMOUNT(mp, rip, DM_RIGHT_NULL, 0, 0,
1028 unmount_event_flags);
1033 xfs_icsb_destroy_counters(mp);
1034 xfs_close_devices(mp);
1037 xfs_free_fsname(mp);
1043 struct super_block *sb)
1045 if (!(sb->s_flags & MS_RDONLY))
1046 xfs_sync_fsdata(XFS_M(sb), 0);
1052 struct super_block *sb,
1055 struct xfs_mount *mp = XFS_M(sb);
1059 * Treat a sync operation like a freeze. This is to work
1060 * around a race in sync_inodes() which works in two phases
1061 * - an asynchronous flush, which can write out an inode
1062 * without waiting for file size updates to complete, and a
1063 * synchronous flush, which wont do anything because the
1064 * async flush removed the inode's dirty flag. Also
1065 * sync_inodes() will not see any files that just have
1066 * outstanding transactions to be flushed because we don't
1067 * dirty the Linux inode until after the transaction I/O
1070 if (wait || unlikely(sb->s_frozen == SB_FREEZE_WRITE))
1071 error = xfs_quiesce_data(mp);
1073 error = xfs_sync_fsdata(mp, 0);
1076 if (unlikely(laptop_mode)) {
1077 int prev_sync_seq = mp->m_sync_seq;
1080 * The disk must be active because we're syncing.
1081 * We schedule xfssyncd now (now that the disk is
1082 * active) instead of later (when it might not be).
1084 wake_up_process(mp->m_sync_task);
1086 * We have to wait for the sync iteration to complete.
1087 * If we don't, the disk activity caused by the sync
1088 * will come after the sync is completed, and that
1089 * triggers another sync from laptop mode.
1091 wait_event(mp->m_wait_single_sync_task,
1092 mp->m_sync_seq != prev_sync_seq);
1100 struct dentry *dentry,
1101 struct kstatfs *statp)
1103 struct xfs_mount *mp = XFS_M(dentry->d_sb);
1104 xfs_sb_t *sbp = &mp->m_sb;
1105 __uint64_t fakeinos, id;
1108 statp->f_type = XFS_SB_MAGIC;
1109 statp->f_namelen = MAXNAMELEN - 1;
1111 id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
1112 statp->f_fsid.val[0] = (u32)id;
1113 statp->f_fsid.val[1] = (u32)(id >> 32);
1115 xfs_icsb_sync_counters(mp, XFS_ICSB_LAZY_COUNT);
1117 spin_lock(&mp->m_sb_lock);
1118 statp->f_bsize = sbp->sb_blocksize;
1119 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
1120 statp->f_blocks = sbp->sb_dblocks - lsize;
1121 statp->f_bfree = statp->f_bavail =
1122 sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
1123 fakeinos = statp->f_bfree << sbp->sb_inopblog;
1125 fakeinos += mp->m_inoadd;
1128 MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
1129 if (mp->m_maxicount)
1133 statp->f_files = min_t(typeof(statp->f_files),
1136 statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
1137 spin_unlock(&mp->m_sb_lock);
1139 XFS_QM_DQSTATVFS(XFS_I(dentry->d_inode), statp);
1145 struct super_block *sb,
1149 struct xfs_mount *mp = XFS_M(sb);
1150 substring_t args[MAX_OPT_ARGS];
1153 while ((p = strsep(&options, ",")) != NULL) {
1159 token = match_token(p, tokens, args);
1162 mp->m_flags |= XFS_MOUNT_BARRIER;
1165 * Test if barriers are actually working if we can,
1166 * else delay this check until the filesystem is
1169 if (!(mp->m_flags & XFS_MOUNT_RDONLY))
1170 xfs_mountfs_check_barriers(mp);
1173 mp->m_flags &= ~XFS_MOUNT_BARRIER;
1177 * Logically we would return an error here to prevent
1178 * users from believing they might have changed
1179 * mount options using remount which can't be changed.
1181 * But unfortunately mount(8) adds all options from
1182 * mtab and fstab to the mount arguments in some cases
1183 * so we can't blindly reject options, but have to
1184 * check for each specified option if it actually
1185 * differs from the currently set option and only
1186 * reject it if that's the case.
1188 * Until that is implemented we return success for
1189 * every remount request, and silently ignore all
1190 * options that we can't actually change.
1194 "XFS: mount option \"%s\" not supported for remount\n", p);
1203 if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(*flags & MS_RDONLY)) {
1204 mp->m_flags &= ~XFS_MOUNT_RDONLY;
1205 if (mp->m_flags & XFS_MOUNT_BARRIER)
1206 xfs_mountfs_check_barriers(mp);
1210 if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (*flags & MS_RDONLY)) {
1211 xfs_quiesce_data(mp);
1212 xfs_quiesce_attr(mp);
1213 mp->m_flags |= XFS_MOUNT_RDONLY;
1220 * Second stage of a freeze. The data is already frozen so we only
1221 * need to take care of the metadata. Once that's done write a dummy
1222 * record to dirty the log in case of a crash while frozen.
1226 struct super_block *sb)
1228 struct xfs_mount *mp = XFS_M(sb);
1230 xfs_quiesce_attr(mp);
1231 xfs_fs_log_dummy(mp);
1235 xfs_fs_show_options(
1237 struct vfsmount *mnt)
1239 return -xfs_showargs(XFS_M(mnt->mnt_sb), m);
1244 struct super_block *sb,
1247 return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XQUOTASYNC, 0, NULL);
1252 struct super_block *sb,
1253 struct fs_quota_stat *fqs)
1255 return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XGETQSTAT, 0, (caddr_t)fqs);
1260 struct super_block *sb,
1264 return -XFS_QM_QUOTACTL(XFS_M(sb), op, 0, (caddr_t)&flags);
1269 struct super_block *sb,
1272 struct fs_disk_quota *fdq)
1274 return -XFS_QM_QUOTACTL(XFS_M(sb),
1275 (type == USRQUOTA) ? Q_XGETQUOTA :
1276 ((type == GRPQUOTA) ? Q_XGETGQUOTA :
1277 Q_XGETPQUOTA), id, (caddr_t)fdq);
1282 struct super_block *sb,
1285 struct fs_disk_quota *fdq)
1287 return -XFS_QM_QUOTACTL(XFS_M(sb),
1288 (type == USRQUOTA) ? Q_XSETQLIM :
1289 ((type == GRPQUOTA) ? Q_XSETGQLIM :
1290 Q_XSETPQLIM), id, (caddr_t)fdq);
1294 * This function fills in xfs_mount_t fields based on mount args.
1295 * Note: the superblock has _not_ yet been read in.
1299 struct xfs_mount_args *ap,
1300 struct xfs_mount *mp)
1304 /* Values are in BBs */
1305 if ((ap->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
1307 * At this point the superblock has not been read
1308 * in, therefore we do not know the block size.
1309 * Before the mount call ends we will convert
1312 mp->m_dalign = ap->sunit;
1313 mp->m_swidth = ap->swidth;
1316 if (ap->logbufs != -1 &&
1318 (ap->logbufs < XLOG_MIN_ICLOGS ||
1319 ap->logbufs > XLOG_MAX_ICLOGS)) {
1321 "XFS: invalid logbufs value: %d [not %d-%d]",
1322 ap->logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
1323 return XFS_ERROR(EINVAL);
1325 mp->m_logbufs = ap->logbufs;
1326 if (ap->logbufsize != -1 &&
1327 ap->logbufsize != 0 &&
1328 (ap->logbufsize < XLOG_MIN_RECORD_BSIZE ||
1329 ap->logbufsize > XLOG_MAX_RECORD_BSIZE ||
1330 !is_power_of_2(ap->logbufsize))) {
1332 "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
1334 return XFS_ERROR(EINVAL);
1339 mp->m_logbsize = ap->logbufsize;
1340 mp->m_fsname_len = strlen(ap->fsname) + 1;
1342 mp->m_fsname = kstrdup(ap->fsname, GFP_KERNEL);
1346 if (ap->rtname[0]) {
1347 mp->m_rtname = kstrdup(ap->rtname, GFP_KERNEL);
1349 goto out_free_fsname;
1353 if (ap->logname[0]) {
1354 mp->m_logname = kstrdup(ap->logname, GFP_KERNEL);
1356 goto out_free_rtname;
1359 if (ap->flags & XFSMNT_WSYNC)
1360 mp->m_flags |= XFS_MOUNT_WSYNC;
1362 if (ap->flags & XFSMNT_INO64) {
1363 mp->m_flags |= XFS_MOUNT_INO64;
1364 mp->m_inoadd = XFS_INO64_OFFSET;
1367 if (ap->flags & XFSMNT_RETERR)
1368 mp->m_flags |= XFS_MOUNT_RETERR;
1369 if (ap->flags & XFSMNT_NOALIGN)
1370 mp->m_flags |= XFS_MOUNT_NOALIGN;
1371 if (ap->flags & XFSMNT_SWALLOC)
1372 mp->m_flags |= XFS_MOUNT_SWALLOC;
1373 if (ap->flags & XFSMNT_OSYNCISOSYNC)
1374 mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
1375 if (ap->flags & XFSMNT_32BITINODES)
1376 mp->m_flags |= XFS_MOUNT_32BITINODES;
1378 if (ap->flags & XFSMNT_IOSIZE) {
1379 if (ap->iosizelog > XFS_MAX_IO_LOG ||
1380 ap->iosizelog < XFS_MIN_IO_LOG) {
1382 "XFS: invalid log iosize: %d [not %d-%d]",
1383 ap->iosizelog, XFS_MIN_IO_LOG,
1385 return XFS_ERROR(EINVAL);
1388 mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
1389 mp->m_readio_log = mp->m_writeio_log = ap->iosizelog;
1392 if (ap->flags & XFSMNT_IKEEP)
1393 mp->m_flags |= XFS_MOUNT_IKEEP;
1394 if (ap->flags & XFSMNT_DIRSYNC)
1395 mp->m_flags |= XFS_MOUNT_DIRSYNC;
1396 if (ap->flags & XFSMNT_ATTR2)
1397 mp->m_flags |= XFS_MOUNT_ATTR2;
1398 if (ap->flags & XFSMNT_NOATTR2)
1399 mp->m_flags |= XFS_MOUNT_NOATTR2;
1401 if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
1402 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
1405 * no recovery flag requires a read-only mount
1407 if (ap->flags & XFSMNT_NORECOVERY) {
1408 if (!(mp->m_flags & XFS_MOUNT_RDONLY)) {
1410 "XFS: tried to mount a FS read-write without recovery!");
1411 return XFS_ERROR(EINVAL);
1413 mp->m_flags |= XFS_MOUNT_NORECOVERY;
1416 if (ap->flags & XFSMNT_NOUUID)
1417 mp->m_flags |= XFS_MOUNT_NOUUID;
1418 if (ap->flags & XFSMNT_BARRIER)
1419 mp->m_flags |= XFS_MOUNT_BARRIER;
1421 mp->m_flags &= ~XFS_MOUNT_BARRIER;
1423 if (ap->flags2 & XFSMNT2_FILESTREAMS)
1424 mp->m_flags |= XFS_MOUNT_FILESTREAMS;
1426 if (ap->flags & XFSMNT_DMAPI)
1427 mp->m_flags |= XFS_MOUNT_DMAPI;
1432 kfree(mp->m_rtname);
1434 kfree(mp->m_fsname);
1440 * This function fills in xfs_mount_t fields based on mount args.
1441 * Note: the superblock _has_ now been read in.
1445 struct xfs_mount_args *ap,
1446 struct xfs_mount *mp)
1448 int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
1450 /* Fail a mount where the logbuf is smaller then the log stripe */
1451 if (xfs_sb_version_haslogv2(&mp->m_sb)) {
1452 if ((ap->logbufsize <= 0) &&
1453 (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) {
1454 mp->m_logbsize = mp->m_sb.sb_logsunit;
1455 } else if (ap->logbufsize > 0 &&
1456 ap->logbufsize < mp->m_sb.sb_logsunit) {
1458 "XFS: logbuf size must be greater than or equal to log stripe size");
1459 return XFS_ERROR(EINVAL);
1462 /* Fail a mount if the logbuf is larger than 32K */
1463 if (ap->logbufsize > XLOG_BIG_RECORD_BSIZE) {
1465 "XFS: logbuf size for version 1 logs must be 16K or 32K");
1466 return XFS_ERROR(EINVAL);
1471 * mkfs'ed attr2 will turn on attr2 mount unless explicitly
1472 * told by noattr2 to turn it off
1474 if (xfs_sb_version_hasattr2(&mp->m_sb) &&
1475 !(ap->flags & XFSMNT_NOATTR2))
1476 mp->m_flags |= XFS_MOUNT_ATTR2;
1479 * prohibit r/w mounts of read-only filesystems
1481 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
1483 "XFS: cannot mount a read-only filesystem as read-write");
1484 return XFS_ERROR(EROFS);
1488 * check for shared mount.
1490 if (ap->flags & XFSMNT_SHARED) {
1491 if (!xfs_sb_version_hasshared(&mp->m_sb))
1492 return XFS_ERROR(EINVAL);
1495 * For IRIX 6.5, shared mounts must have the shared
1496 * version bit set, have the persistent readonly
1497 * field set, must be version 0 and can only be mounted
1500 if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) ||
1501 (mp->m_sb.sb_shared_vn != 0))
1502 return XFS_ERROR(EINVAL);
1504 mp->m_flags |= XFS_MOUNT_SHARED;
1507 * Shared XFS V0 can't deal with DMI. Return EINVAL.
1509 if (mp->m_sb.sb_shared_vn == 0 && (ap->flags & XFSMNT_DMAPI))
1510 return XFS_ERROR(EINVAL);
1513 if (ap->flags & XFSMNT_UQUOTA) {
1514 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
1515 if (ap->flags & XFSMNT_UQUOTAENF)
1516 mp->m_qflags |= XFS_UQUOTA_ENFD;
1519 if (ap->flags & XFSMNT_GQUOTA) {
1520 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
1521 if (ap->flags & XFSMNT_GQUOTAENF)
1522 mp->m_qflags |= XFS_OQUOTA_ENFD;
1523 } else if (ap->flags & XFSMNT_PQUOTA) {
1524 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
1525 if (ap->flags & XFSMNT_PQUOTAENF)
1526 mp->m_qflags |= XFS_OQUOTA_ENFD;
1534 struct super_block *sb,
1539 struct xfs_mount *mp = NULL;
1540 struct xfs_mount_args *args;
1541 int flags = 0, error = ENOMEM;
1543 args = xfs_args_allocate(sb, silent);
1547 mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
1551 spin_lock_init(&mp->m_sb_lock);
1552 mutex_init(&mp->m_ilock);
1553 mutex_init(&mp->m_growlock);
1554 atomic_set(&mp->m_active_trans, 0);
1555 INIT_LIST_HEAD(&mp->m_sync_list);
1556 spin_lock_init(&mp->m_sync_lock);
1557 init_waitqueue_head(&mp->m_wait_single_sync_task);
1562 if (sb->s_flags & MS_RDONLY)
1563 mp->m_flags |= XFS_MOUNT_RDONLY;
1565 error = xfs_parseargs(mp, (char *)data, args, 0);
1569 sb_min_blocksize(sb, BBSIZE);
1570 sb->s_xattr = xfs_xattr_handlers;
1571 sb->s_export_op = &xfs_export_operations;
1572 sb->s_qcop = &xfs_quotactl_operations;
1573 sb->s_op = &xfs_super_operations;
1575 error = xfs_dmops_get(mp, args);
1578 error = xfs_qmops_get(mp, args);
1582 if (args->flags & XFSMNT_QUIET)
1583 flags |= XFS_MFSI_QUIET;
1585 error = xfs_open_devices(mp, args);
1589 if (xfs_icsb_init_counters(mp))
1590 mp->m_flags |= XFS_MOUNT_NO_PERCPU_SB;
1593 * Setup flags based on mount(2) options and then the superblock
1595 error = xfs_start_flags(args, mp);
1597 goto out_free_fsname;
1598 error = xfs_readsb(mp, flags);
1600 goto out_free_fsname;
1601 error = xfs_finish_flags(args, mp);
1605 error = xfs_setup_devices(mp);
1609 if (mp->m_flags & XFS_MOUNT_BARRIER)
1610 xfs_mountfs_check_barriers(mp);
1612 error = xfs_filestream_mount(mp);
1616 error = xfs_mountfs(mp);
1618 goto out_filestream_unmount;
1620 XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, args->mtpt, args->fsname);
1623 sb->s_magic = XFS_SB_MAGIC;
1624 sb->s_blocksize = mp->m_sb.sb_blocksize;
1625 sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
1626 sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
1627 sb->s_time_gran = 1;
1628 set_posix_acl_flag(sb);
1630 root = igrab(VFS_I(mp->m_rootip));
1635 if (is_bad_inode(root)) {
1639 sb->s_root = d_alloc_root(root);
1645 error = xfs_syncd_init(mp);
1649 xfs_itrace_exit(XFS_I(sb->s_root->d_inode));
1654 out_filestream_unmount:
1655 xfs_filestream_unmount(mp);
1659 xfs_free_fsname(mp);
1660 xfs_icsb_destroy_counters(mp);
1661 xfs_close_devices(mp);
1682 * Blow away any referenced inode in the filestreams cache.
1683 * This can and will cause log traffic as inodes go inactive
1686 xfs_filestream_unmount(mp);
1688 XFS_bflush(mp->m_ddev_targp);
1689 error = xfs_unmount_flush(mp, 0);
1698 struct file_system_type *fs_type,
1700 const char *dev_name,
1702 struct vfsmount *mnt)
1704 return get_sb_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super,
1708 static struct super_operations xfs_super_operations = {
1709 .alloc_inode = xfs_fs_alloc_inode,
1710 .destroy_inode = xfs_fs_destroy_inode,
1711 .write_inode = xfs_fs_write_inode,
1712 .clear_inode = xfs_fs_clear_inode,
1713 .put_super = xfs_fs_put_super,
1714 .write_super = xfs_fs_write_super,
1715 .sync_fs = xfs_fs_sync_super,
1716 .write_super_lockfs = xfs_fs_lockfs,
1717 .statfs = xfs_fs_statfs,
1718 .remount_fs = xfs_fs_remount,
1719 .show_options = xfs_fs_show_options,
1722 static struct quotactl_ops xfs_quotactl_operations = {
1723 .quota_sync = xfs_fs_quotasync,
1724 .get_xstate = xfs_fs_getxstate,
1725 .set_xstate = xfs_fs_setxstate,
1726 .get_xquota = xfs_fs_getxquota,
1727 .set_xquota = xfs_fs_setxquota,
1730 static struct file_system_type xfs_fs_type = {
1731 .owner = THIS_MODULE,
1733 .get_sb = xfs_fs_get_sb,
1734 .kill_sb = kill_block_super,
1735 .fs_flags = FS_REQUIRES_DEV,
1739 xfs_alloc_trace_bufs(void)
1741 #ifdef XFS_ALLOC_TRACE
1742 xfs_alloc_trace_buf = ktrace_alloc(XFS_ALLOC_TRACE_SIZE, KM_MAYFAIL);
1743 if (!xfs_alloc_trace_buf)
1746 #ifdef XFS_BMAP_TRACE
1747 xfs_bmap_trace_buf = ktrace_alloc(XFS_BMAP_TRACE_SIZE, KM_MAYFAIL);
1748 if (!xfs_bmap_trace_buf)
1749 goto out_free_alloc_trace;
1751 #ifdef XFS_BTREE_TRACE
1752 xfs_allocbt_trace_buf = ktrace_alloc(XFS_ALLOCBT_TRACE_SIZE,
1754 if (!xfs_allocbt_trace_buf)
1755 goto out_free_bmap_trace;
1757 xfs_inobt_trace_buf = ktrace_alloc(XFS_INOBT_TRACE_SIZE, KM_MAYFAIL);
1758 if (!xfs_inobt_trace_buf)
1759 goto out_free_allocbt_trace;
1761 xfs_bmbt_trace_buf = ktrace_alloc(XFS_BMBT_TRACE_SIZE, KM_MAYFAIL);
1762 if (!xfs_bmbt_trace_buf)
1763 goto out_free_inobt_trace;
1765 #ifdef XFS_ATTR_TRACE
1766 xfs_attr_trace_buf = ktrace_alloc(XFS_ATTR_TRACE_SIZE, KM_MAYFAIL);
1767 if (!xfs_attr_trace_buf)
1768 goto out_free_bmbt_trace;
1770 #ifdef XFS_DIR2_TRACE
1771 xfs_dir2_trace_buf = ktrace_alloc(XFS_DIR2_GTRACE_SIZE, KM_MAYFAIL);
1772 if (!xfs_dir2_trace_buf)
1773 goto out_free_attr_trace;
1778 #ifdef XFS_DIR2_TRACE
1779 out_free_attr_trace:
1781 #ifdef XFS_ATTR_TRACE
1782 ktrace_free(xfs_attr_trace_buf);
1783 out_free_bmbt_trace:
1785 #ifdef XFS_BTREE_TRACE
1786 ktrace_free(xfs_bmbt_trace_buf);
1787 out_free_inobt_trace:
1788 ktrace_free(xfs_inobt_trace_buf);
1789 out_free_allocbt_trace:
1790 ktrace_free(xfs_allocbt_trace_buf);
1791 out_free_bmap_trace:
1793 #ifdef XFS_BMAP_TRACE
1794 ktrace_free(xfs_bmap_trace_buf);
1795 out_free_alloc_trace:
1797 #ifdef XFS_ALLOC_TRACE
1798 ktrace_free(xfs_alloc_trace_buf);
1805 xfs_free_trace_bufs(void)
1807 #ifdef XFS_DIR2_TRACE
1808 ktrace_free(xfs_dir2_trace_buf);
1810 #ifdef XFS_ATTR_TRACE
1811 ktrace_free(xfs_attr_trace_buf);
1813 #ifdef XFS_BTREE_TRACE
1814 ktrace_free(xfs_bmbt_trace_buf);
1815 ktrace_free(xfs_inobt_trace_buf);
1816 ktrace_free(xfs_allocbt_trace_buf);
1818 #ifdef XFS_BMAP_TRACE
1819 ktrace_free(xfs_bmap_trace_buf);
1821 #ifdef XFS_ALLOC_TRACE
1822 ktrace_free(xfs_alloc_trace_buf);
1827 xfs_init_zones(void)
1830 xfs_ioend_zone = kmem_zone_init(sizeof(xfs_ioend_t), "xfs_ioend");
1831 if (!xfs_ioend_zone)
1834 xfs_ioend_pool = mempool_create_slab_pool(4 * MAX_BUF_PER_PAGE,
1836 if (!xfs_ioend_pool)
1837 goto out_destroy_ioend_zone;
1839 xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t),
1841 if (!xfs_log_ticket_zone)
1842 goto out_destroy_ioend_pool;
1844 xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
1845 "xfs_bmap_free_item");
1846 if (!xfs_bmap_free_item_zone)
1847 goto out_destroy_log_ticket_zone;
1849 xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
1851 if (!xfs_btree_cur_zone)
1852 goto out_destroy_bmap_free_item_zone;
1854 xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t),
1856 if (!xfs_da_state_zone)
1857 goto out_destroy_btree_cur_zone;
1859 xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf");
1860 if (!xfs_dabuf_zone)
1861 goto out_destroy_da_state_zone;
1863 xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
1864 if (!xfs_ifork_zone)
1865 goto out_destroy_dabuf_zone;
1867 xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
1868 if (!xfs_trans_zone)
1869 goto out_destroy_ifork_zone;
1872 * The size of the zone allocated buf log item is the maximum
1873 * size possible under XFS. This wastes a little bit of memory,
1874 * but it is much faster.
1876 xfs_buf_item_zone = kmem_zone_init((sizeof(xfs_buf_log_item_t) +
1877 (((XFS_MAX_BLOCKSIZE / XFS_BLI_CHUNK) /
1878 NBWORD) * sizeof(int))), "xfs_buf_item");
1879 if (!xfs_buf_item_zone)
1880 goto out_destroy_trans_zone;
1882 xfs_efd_zone = kmem_zone_init((sizeof(xfs_efd_log_item_t) +
1883 ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
1884 sizeof(xfs_extent_t))), "xfs_efd_item");
1886 goto out_destroy_buf_item_zone;
1888 xfs_efi_zone = kmem_zone_init((sizeof(xfs_efi_log_item_t) +
1889 ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
1890 sizeof(xfs_extent_t))), "xfs_efi_item");
1892 goto out_destroy_efd_zone;
1895 kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
1896 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM | KM_ZONE_SPREAD,
1897 xfs_fs_inode_init_once);
1898 if (!xfs_inode_zone)
1899 goto out_destroy_efi_zone;
1902 kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
1903 KM_ZONE_SPREAD, NULL);
1905 goto out_destroy_inode_zone;
1907 #ifdef CONFIG_XFS_POSIX_ACL
1908 xfs_acl_zone = kmem_zone_init(sizeof(xfs_acl_t), "xfs_acl");
1910 goto out_destroy_ili_zone;
1915 #ifdef CONFIG_XFS_POSIX_ACL
1916 out_destroy_ili_zone:
1918 kmem_zone_destroy(xfs_ili_zone);
1919 out_destroy_inode_zone:
1920 kmem_zone_destroy(xfs_inode_zone);
1921 out_destroy_efi_zone:
1922 kmem_zone_destroy(xfs_efi_zone);
1923 out_destroy_efd_zone:
1924 kmem_zone_destroy(xfs_efd_zone);
1925 out_destroy_buf_item_zone:
1926 kmem_zone_destroy(xfs_buf_item_zone);
1927 out_destroy_trans_zone:
1928 kmem_zone_destroy(xfs_trans_zone);
1929 out_destroy_ifork_zone:
1930 kmem_zone_destroy(xfs_ifork_zone);
1931 out_destroy_dabuf_zone:
1932 kmem_zone_destroy(xfs_dabuf_zone);
1933 out_destroy_da_state_zone:
1934 kmem_zone_destroy(xfs_da_state_zone);
1935 out_destroy_btree_cur_zone:
1936 kmem_zone_destroy(xfs_btree_cur_zone);
1937 out_destroy_bmap_free_item_zone:
1938 kmem_zone_destroy(xfs_bmap_free_item_zone);
1939 out_destroy_log_ticket_zone:
1940 kmem_zone_destroy(xfs_log_ticket_zone);
1941 out_destroy_ioend_pool:
1942 mempool_destroy(xfs_ioend_pool);
1943 out_destroy_ioend_zone:
1944 kmem_zone_destroy(xfs_ioend_zone);
1950 xfs_destroy_zones(void)
1952 #ifdef CONFIG_XFS_POSIX_ACL
1953 kmem_zone_destroy(xfs_acl_zone);
1955 kmem_zone_destroy(xfs_ili_zone);
1956 kmem_zone_destroy(xfs_inode_zone);
1957 kmem_zone_destroy(xfs_efi_zone);
1958 kmem_zone_destroy(xfs_efd_zone);
1959 kmem_zone_destroy(xfs_buf_item_zone);
1960 kmem_zone_destroy(xfs_trans_zone);
1961 kmem_zone_destroy(xfs_ifork_zone);
1962 kmem_zone_destroy(xfs_dabuf_zone);
1963 kmem_zone_destroy(xfs_da_state_zone);
1964 kmem_zone_destroy(xfs_btree_cur_zone);
1965 kmem_zone_destroy(xfs_bmap_free_item_zone);
1966 kmem_zone_destroy(xfs_log_ticket_zone);
1967 mempool_destroy(xfs_ioend_pool);
1968 kmem_zone_destroy(xfs_ioend_zone);
1976 static char message[] __initdata = KERN_INFO \
1977 XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled\n";
1985 error = xfs_init_zones();
1989 error = xfs_alloc_trace_bufs();
1991 goto out_destroy_zones;
1993 error = xfs_mru_cache_init();
1995 goto out_free_trace_buffers;
1997 error = xfs_filestream_init();
1999 goto out_mru_cache_uninit;
2001 error = xfs_buf_init();
2003 goto out_filestream_uninit;
2005 error = xfs_init_procfs();
2007 goto out_buf_terminate;
2009 error = xfs_sysctl_register();
2011 goto out_cleanup_procfs;
2015 error = register_filesystem(&xfs_fs_type);
2017 goto out_sysctl_unregister;
2020 out_sysctl_unregister:
2021 xfs_sysctl_unregister();
2023 xfs_cleanup_procfs();
2025 xfs_buf_terminate();
2026 out_filestream_uninit:
2027 xfs_filestream_uninit();
2028 out_mru_cache_uninit:
2029 xfs_mru_cache_uninit();
2030 out_free_trace_buffers:
2031 xfs_free_trace_bufs();
2033 xfs_destroy_zones();
2042 unregister_filesystem(&xfs_fs_type);
2043 xfs_sysctl_unregister();
2044 xfs_cleanup_procfs();
2045 xfs_buf_terminate();
2046 xfs_filestream_uninit();
2047 xfs_mru_cache_uninit();
2048 xfs_free_trace_bufs();
2049 xfs_destroy_zones();
2053 module_init(init_xfs_fs);
2054 module_exit(exit_xfs_fs);
2056 MODULE_AUTHOR("Silicon Graphics, Inc.");
2057 MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
2058 MODULE_LICENSE("GPL");