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_ialloc.h"
41 #include "xfs_rtalloc.h"
42 #include "xfs_error.h"
43 #include "xfs_itable.h"
44 #include "xfs_fsops.h"
48 #include "xfs_buf_item.h"
49 #include "xfs_utils.h"
50 #include "xfs_vnodeops.h"
51 #include "xfs_vfsops.h"
52 #include "xfs_version.h"
53 #include "xfs_log_priv.h"
54 #include "xfs_trans_priv.h"
55 #include "xfs_filestream.h"
56 #include "xfs_da_btree.h"
57 #include "xfs_dir2_trace.h"
58 #include "xfs_extfree_item.h"
59 #include "xfs_mru_cache.h"
60 #include "xfs_inode_item.h"
62 #include <linux/namei.h>
63 #include <linux/init.h>
64 #include <linux/mount.h>
65 #include <linux/mempool.h>
66 #include <linux/writeback.h>
67 #include <linux/kthread.h>
68 #include <linux/freezer.h>
69 #include <linux/parser.h>
71 static struct quotactl_ops xfs_quotactl_operations;
72 static struct super_operations xfs_super_operations;
73 static kmem_zone_t *xfs_vnode_zone;
74 static kmem_zone_t *xfs_ioend_zone;
75 mempool_t *xfs_ioend_pool;
77 STATIC struct xfs_mount_args *
79 struct super_block *sb,
82 struct xfs_mount_args *args;
84 args = kzalloc(sizeof(struct xfs_mount_args), GFP_KERNEL);
88 args->logbufs = args->logbufsize = -1;
89 strncpy(args->fsname, sb->s_id, MAXNAMELEN);
91 /* Copy the already-parsed mount(2) flags we're interested in */
92 if (sb->s_flags & MS_DIRSYNC)
93 args->flags |= XFSMNT_DIRSYNC;
94 if (sb->s_flags & MS_SYNCHRONOUS)
95 args->flags |= XFSMNT_WSYNC;
97 args->flags |= XFSMNT_QUIET;
98 args->flags |= XFSMNT_32BITINODES;
103 #define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
104 #define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
105 #define MNTOPT_LOGDEV "logdev" /* log device */
106 #define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
107 #define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
108 #define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
109 #define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
110 #define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
111 #define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
112 #define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
113 #define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
114 #define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
115 #define MNTOPT_MTPT "mtpt" /* filesystem mount point */
116 #define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
117 #define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
118 #define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
119 #define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
120 #define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
121 #define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
122 #define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
123 * unwritten extent conversion */
124 #define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
125 #define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
126 #define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
127 #define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
128 #define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
129 #define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
130 #define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
132 #define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
133 #define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
134 #define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
135 #define MNTOPT_QUOTA "quota" /* disk quotas (user) */
136 #define MNTOPT_NOQUOTA "noquota" /* no quotas */
137 #define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */
138 #define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */
139 #define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */
140 #define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */
141 #define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */
142 #define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */
143 #define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
144 #define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
145 #define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
146 #define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */
147 #define MNTOPT_DMAPI "dmapi" /* DMI enabled (DMAPI / XDSM) */
148 #define MNTOPT_XDSM "xdsm" /* DMI enabled (DMAPI / XDSM) */
149 #define MNTOPT_DMI "dmi" /* DMI enabled (DMAPI / XDSM) */
152 * Table driven mount option parser.
154 * Currently only used for remount, but it will be used for mount
155 * in the future, too.
158 Opt_barrier, Opt_nobarrier, Opt_err
161 static const match_table_t tokens = {
162 {Opt_barrier, "barrier"},
163 {Opt_nobarrier, "nobarrier"},
169 suffix_strtoul(char *s, char **endp, unsigned int base)
171 int last, shift_left_factor = 0;
174 last = strlen(value) - 1;
175 if (value[last] == 'K' || value[last] == 'k') {
176 shift_left_factor = 10;
179 if (value[last] == 'M' || value[last] == 'm') {
180 shift_left_factor = 20;
183 if (value[last] == 'G' || value[last] == 'g') {
184 shift_left_factor = 30;
188 return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
193 struct xfs_mount *mp,
195 struct xfs_mount_args *args,
198 char *this_char, *value, *eov;
199 int dsunit, dswidth, vol_dsunit, vol_dswidth;
201 int dmapi_implies_ikeep = 1;
203 args->flags |= XFSMNT_BARRIER;
204 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
209 iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0;
211 while ((this_char = strsep(&options, ",")) != NULL) {
214 if ((value = strchr(this_char, '=')) != NULL)
217 if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
218 if (!value || !*value) {
220 "XFS: %s option requires an argument",
224 args->logbufs = simple_strtoul(value, &eov, 10);
225 } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
226 if (!value || !*value) {
228 "XFS: %s option requires an argument",
232 args->logbufsize = suffix_strtoul(value, &eov, 10);
233 } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
234 if (!value || !*value) {
236 "XFS: %s option requires an argument",
240 strncpy(args->logname, value, MAXNAMELEN);
241 } else if (!strcmp(this_char, MNTOPT_MTPT)) {
242 if (!value || !*value) {
244 "XFS: %s option requires an argument",
248 strncpy(args->mtpt, value, MAXNAMELEN);
249 } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
250 if (!value || !*value) {
252 "XFS: %s option requires an argument",
256 strncpy(args->rtname, value, MAXNAMELEN);
257 } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
258 if (!value || !*value) {
260 "XFS: %s option requires an argument",
264 iosize = simple_strtoul(value, &eov, 10);
265 args->flags |= XFSMNT_IOSIZE;
266 args->iosizelog = (uint8_t) iosize;
267 } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
268 if (!value || !*value) {
270 "XFS: %s option requires an argument",
274 iosize = suffix_strtoul(value, &eov, 10);
275 args->flags |= XFSMNT_IOSIZE;
276 args->iosizelog = ffs(iosize) - 1;
277 } else if (!strcmp(this_char, MNTOPT_GRPID) ||
278 !strcmp(this_char, MNTOPT_BSDGROUPS)) {
279 mp->m_flags |= XFS_MOUNT_GRPID;
280 } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
281 !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
282 mp->m_flags &= ~XFS_MOUNT_GRPID;
283 } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
284 args->flags |= XFSMNT_WSYNC;
285 } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
286 args->flags |= XFSMNT_OSYNCISOSYNC;
287 } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
288 args->flags |= XFSMNT_NORECOVERY;
289 } else if (!strcmp(this_char, MNTOPT_INO64)) {
290 args->flags |= XFSMNT_INO64;
293 "XFS: %s option not allowed on this system",
297 } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
298 args->flags |= XFSMNT_NOALIGN;
299 } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
300 args->flags |= XFSMNT_SWALLOC;
301 } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
302 if (!value || !*value) {
304 "XFS: %s option requires an argument",
308 dsunit = simple_strtoul(value, &eov, 10);
309 } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
310 if (!value || !*value) {
312 "XFS: %s option requires an argument",
316 dswidth = simple_strtoul(value, &eov, 10);
317 } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
318 args->flags &= ~XFSMNT_32BITINODES;
321 "XFS: %s option not allowed on this system",
325 } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
326 args->flags |= XFSMNT_NOUUID;
327 } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
328 args->flags |= XFSMNT_BARRIER;
329 } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
330 args->flags &= ~XFSMNT_BARRIER;
331 } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
332 args->flags |= XFSMNT_IKEEP;
333 } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
334 dmapi_implies_ikeep = 0;
335 args->flags &= ~XFSMNT_IKEEP;
336 } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
337 args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE;
338 } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
339 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
340 } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
341 args->flags |= XFSMNT_ATTR2;
342 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
343 args->flags &= ~XFSMNT_ATTR2;
344 args->flags |= XFSMNT_NOATTR2;
345 } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
346 args->flags2 |= XFSMNT2_FILESTREAMS;
347 } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
348 args->flags &= ~(XFSMNT_UQUOTAENF|XFSMNT_UQUOTA);
349 args->flags &= ~(XFSMNT_GQUOTAENF|XFSMNT_GQUOTA);
350 } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
351 !strcmp(this_char, MNTOPT_UQUOTA) ||
352 !strcmp(this_char, MNTOPT_USRQUOTA)) {
353 args->flags |= XFSMNT_UQUOTA | XFSMNT_UQUOTAENF;
354 } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
355 !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
356 args->flags |= XFSMNT_UQUOTA;
357 args->flags &= ~XFSMNT_UQUOTAENF;
358 } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
359 !strcmp(this_char, MNTOPT_PRJQUOTA)) {
360 args->flags |= XFSMNT_PQUOTA | XFSMNT_PQUOTAENF;
361 } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
362 args->flags |= XFSMNT_PQUOTA;
363 args->flags &= ~XFSMNT_PQUOTAENF;
364 } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
365 !strcmp(this_char, MNTOPT_GRPQUOTA)) {
366 args->flags |= XFSMNT_GQUOTA | XFSMNT_GQUOTAENF;
367 } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
368 args->flags |= XFSMNT_GQUOTA;
369 args->flags &= ~XFSMNT_GQUOTAENF;
370 } else if (!strcmp(this_char, MNTOPT_DMAPI)) {
371 args->flags |= XFSMNT_DMAPI;
372 } else if (!strcmp(this_char, MNTOPT_XDSM)) {
373 args->flags |= XFSMNT_DMAPI;
374 } else if (!strcmp(this_char, MNTOPT_DMI)) {
375 args->flags |= XFSMNT_DMAPI;
376 } else if (!strcmp(this_char, "ihashsize")) {
378 "XFS: ihashsize no longer used, option is deprecated.");
379 } else if (!strcmp(this_char, "osyncisdsync")) {
380 /* no-op, this is now the default */
382 "XFS: osyncisdsync is now the default, option is deprecated.");
383 } else if (!strcmp(this_char, "irixsgid")) {
385 "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
388 "XFS: unknown mount option [%s].", this_char);
393 if (args->flags & XFSMNT_NORECOVERY) {
394 if ((mp->m_flags & XFS_MOUNT_RDONLY) == 0) {
396 "XFS: no-recovery mounts must be read-only.");
401 if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) {
403 "XFS: sunit and swidth options incompatible with the noalign option");
407 if ((args->flags & XFSMNT_GQUOTA) && (args->flags & XFSMNT_PQUOTA)) {
409 "XFS: cannot mount with both project and group quota");
413 if ((args->flags & XFSMNT_DMAPI) && *args->mtpt == '\0') {
414 printk("XFS: %s option needs the mount point option as well\n",
419 if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
421 "XFS: sunit and swidth must be specified together");
425 if (dsunit && (dswidth % dsunit != 0)) {
427 "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
433 * Applications using DMI filesystems often expect the
434 * inode generation number to be monotonically increasing.
435 * If we delete inode chunks we break this assumption, so
436 * keep unused inode chunks on disk for DMI filesystems
437 * until we come up with a better solution.
438 * Note that if "ikeep" or "noikeep" mount options are
439 * supplied, then they are honored.
441 if ((args->flags & XFSMNT_DMAPI) && dmapi_implies_ikeep)
442 args->flags |= XFSMNT_IKEEP;
444 if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
446 args->sunit = dsunit;
447 args->flags |= XFSMNT_RETERR;
449 args->sunit = vol_dsunit;
451 dswidth ? (args->swidth = dswidth) :
452 (args->swidth = vol_dswidth);
454 args->sunit = args->swidth = 0;
458 if (args->flags & XFSMNT_32BITINODES)
459 mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
461 args->flags |= XFSMNT_FLAGS2;
465 struct proc_xfs_info {
472 struct xfs_mount *mp,
475 static struct proc_xfs_info xfs_info_set[] = {
476 /* the few simple ones we can get from the mount struct */
477 { XFS_MOUNT_IKEEP, "," MNTOPT_IKEEP },
478 { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
479 { XFS_MOUNT_INO64, "," MNTOPT_INO64 },
480 { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
481 { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
482 { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
483 { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
484 { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
485 { XFS_MOUNT_ATTR2, "," MNTOPT_ATTR2 },
486 { XFS_MOUNT_FILESTREAMS, "," MNTOPT_FILESTREAM },
487 { XFS_MOUNT_DMAPI, "," MNTOPT_DMAPI },
488 { XFS_MOUNT_GRPID, "," MNTOPT_GRPID },
491 static struct proc_xfs_info xfs_info_unset[] = {
492 /* the few simple ones we can get from the mount struct */
493 { XFS_MOUNT_COMPAT_IOSIZE, "," MNTOPT_LARGEIO },
494 { XFS_MOUNT_BARRIER, "," MNTOPT_NOBARRIER },
495 { XFS_MOUNT_SMALL_INUMS, "," MNTOPT_64BITINODE },
498 struct proc_xfs_info *xfs_infop;
500 for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
501 if (mp->m_flags & xfs_infop->flag)
502 seq_puts(m, xfs_infop->str);
504 for (xfs_infop = xfs_info_unset; xfs_infop->flag; xfs_infop++) {
505 if (!(mp->m_flags & xfs_infop->flag))
506 seq_puts(m, xfs_infop->str);
509 if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
510 seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
511 (int)(1 << mp->m_writeio_log) >> 10);
513 if (mp->m_logbufs > 0)
514 seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
515 if (mp->m_logbsize > 0)
516 seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
519 seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
521 seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
523 if (mp->m_dalign > 0)
524 seq_printf(m, "," MNTOPT_SUNIT "=%d",
525 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
526 if (mp->m_swidth > 0)
527 seq_printf(m, "," MNTOPT_SWIDTH "=%d",
528 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
530 if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD))
531 seq_puts(m, "," MNTOPT_USRQUOTA);
532 else if (mp->m_qflags & XFS_UQUOTA_ACCT)
533 seq_puts(m, "," MNTOPT_UQUOTANOENF);
535 if (mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_OQUOTA_ENFD))
536 seq_puts(m, "," MNTOPT_PRJQUOTA);
537 else if (mp->m_qflags & XFS_PQUOTA_ACCT)
538 seq_puts(m, "," MNTOPT_PQUOTANOENF);
540 if (mp->m_qflags & (XFS_GQUOTA_ACCT|XFS_OQUOTA_ENFD))
541 seq_puts(m, "," MNTOPT_GRPQUOTA);
542 else if (mp->m_qflags & XFS_GQUOTA_ACCT)
543 seq_puts(m, "," MNTOPT_GQUOTANOENF);
545 if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
546 seq_puts(m, "," MNTOPT_NOQUOTA);
552 unsigned int blockshift)
554 unsigned int pagefactor = 1;
555 unsigned int bitshift = BITS_PER_LONG - 1;
557 /* Figure out maximum filesize, on Linux this can depend on
558 * the filesystem blocksize (on 32 bit platforms).
559 * __block_prepare_write does this in an [unsigned] long...
560 * page->index << (PAGE_CACHE_SHIFT - bbits)
561 * So, for page sized blocks (4K on 32 bit platforms),
562 * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
563 * (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
564 * but for smaller blocksizes it is less (bbits = log2 bsize).
565 * Note1: get_block_t takes a long (implicit cast from above)
566 * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch
567 * can optionally convert the [unsigned] long from above into
568 * an [unsigned] long long.
571 #if BITS_PER_LONG == 32
572 # if defined(CONFIG_LBD)
573 ASSERT(sizeof(sector_t) == 8);
574 pagefactor = PAGE_CACHE_SIZE;
575 bitshift = BITS_PER_LONG;
577 pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift);
581 return (((__uint64_t)pagefactor) << bitshift) - 1;
588 struct block_device **bdevp)
592 *bdevp = open_bdev_exclusive(name, FMODE_READ|FMODE_WRITE, mp);
593 if (IS_ERR(*bdevp)) {
594 error = PTR_ERR(*bdevp);
595 printk("XFS: Invalid device [%s], error=%d\n", name, error);
603 struct block_device *bdev)
606 close_bdev_exclusive(bdev, FMODE_READ|FMODE_WRITE);
610 * Try to write out the superblock using barriers.
616 xfs_buf_t *sbp = xfs_getsb(mp, 0);
621 XFS_BUF_UNDELAYWRITE(sbp);
623 XFS_BUF_UNASYNC(sbp);
624 XFS_BUF_ORDERED(sbp);
627 error = xfs_iowait(sbp);
630 * Clear all the flags we set and possible error state in the
631 * buffer. We only did the write to try out whether barriers
632 * worked and shouldn't leave any traces in the superblock
636 XFS_BUF_ERROR(sbp, 0);
637 XFS_BUF_UNORDERED(sbp);
644 xfs_mountfs_check_barriers(xfs_mount_t *mp)
648 if (mp->m_logdev_targp != mp->m_ddev_targp) {
649 xfs_fs_cmn_err(CE_NOTE, mp,
650 "Disabling barriers, not supported with external log device");
651 mp->m_flags &= ~XFS_MOUNT_BARRIER;
655 if (xfs_readonly_buftarg(mp->m_ddev_targp)) {
656 xfs_fs_cmn_err(CE_NOTE, mp,
657 "Disabling barriers, underlying device is readonly");
658 mp->m_flags &= ~XFS_MOUNT_BARRIER;
662 error = xfs_barrier_test(mp);
664 xfs_fs_cmn_err(CE_NOTE, mp,
665 "Disabling barriers, trial barrier write failed");
666 mp->m_flags &= ~XFS_MOUNT_BARRIER;
672 xfs_blkdev_issue_flush(
673 xfs_buftarg_t *buftarg)
675 blkdev_issue_flush(buftarg->bt_bdev, NULL);
680 struct xfs_mount *mp)
682 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
683 struct block_device *logdev = mp->m_logdev_targp->bt_bdev;
684 xfs_free_buftarg(mp->m_logdev_targp);
685 xfs_blkdev_put(logdev);
687 if (mp->m_rtdev_targp) {
688 struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev;
689 xfs_free_buftarg(mp->m_rtdev_targp);
690 xfs_blkdev_put(rtdev);
692 xfs_free_buftarg(mp->m_ddev_targp);
696 * The file system configurations are:
697 * (1) device (partition) with data and internal log
698 * (2) logical volume with data and log subvolumes.
699 * (3) logical volume with data, log, and realtime subvolumes.
701 * We only have to handle opening the log and realtime volumes here if
702 * they are present. The data subvolume has already been opened by
703 * get_sb_bdev() and is stored in sb->s_bdev.
707 struct xfs_mount *mp,
708 struct xfs_mount_args *args)
710 struct block_device *ddev = mp->m_super->s_bdev;
711 struct block_device *logdev = NULL, *rtdev = NULL;
715 * Open real time and log devices - order is important.
717 if (args->logname[0]) {
718 error = xfs_blkdev_get(mp, args->logname, &logdev);
723 if (args->rtname[0]) {
724 error = xfs_blkdev_get(mp, args->rtname, &rtdev);
726 goto out_close_logdev;
728 if (rtdev == ddev || rtdev == logdev) {
730 "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
732 goto out_close_rtdev;
737 * Setup xfs_mount buffer target pointers
740 mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
741 if (!mp->m_ddev_targp)
742 goto out_close_rtdev;
745 mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
746 if (!mp->m_rtdev_targp)
747 goto out_free_ddev_targ;
750 if (logdev && logdev != ddev) {
751 mp->m_logdev_targp = xfs_alloc_buftarg(logdev, 1);
752 if (!mp->m_logdev_targp)
753 goto out_free_rtdev_targ;
755 mp->m_logdev_targp = mp->m_ddev_targp;
761 if (mp->m_rtdev_targp)
762 xfs_free_buftarg(mp->m_rtdev_targp);
764 xfs_free_buftarg(mp->m_ddev_targp);
767 xfs_blkdev_put(rtdev);
769 if (logdev && logdev != ddev)
770 xfs_blkdev_put(logdev);
776 * Setup xfs_mount buffer target pointers based on superblock
780 struct xfs_mount *mp)
784 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
785 mp->m_sb.sb_sectsize);
789 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
790 unsigned int log_sector_size = BBSIZE;
792 if (xfs_sb_version_hassector(&mp->m_sb))
793 log_sector_size = mp->m_sb.sb_logsectsize;
794 error = xfs_setsize_buftarg(mp->m_logdev_targp,
795 mp->m_sb.sb_blocksize,
800 if (mp->m_rtdev_targp) {
801 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
802 mp->m_sb.sb_blocksize,
803 mp->m_sb.sb_sectsize);
812 * XFS AIL push thread support
817 xfs_lsn_t threshold_lsn)
819 mp->m_ail.xa_target = threshold_lsn;
820 wake_up_process(mp->m_ail.xa_task);
827 xfs_mount_t *mp = (xfs_mount_t *)data;
828 xfs_lsn_t last_pushed_lsn = 0;
831 while (!kthread_should_stop()) {
833 schedule_timeout_interruptible(msecs_to_jiffies(tout));
840 if (XFS_FORCED_SHUTDOWN(mp))
843 tout = xfsaild_push(mp, &last_pushed_lsn);
853 mp->m_ail.xa_target = 0;
854 mp->m_ail.xa_task = kthread_run(xfsaild, mp, "xfsaild");
855 if (IS_ERR(mp->m_ail.xa_task))
856 return -PTR_ERR(mp->m_ail.xa_task);
864 kthread_stop(mp->m_ail.xa_task);
869 STATIC struct inode *
871 struct super_block *sb)
873 return kmem_zone_alloc(xfs_vnode_zone, KM_SLEEP);
877 xfs_fs_destroy_inode(
880 kmem_zone_free(xfs_vnode_zone, inode);
884 xfs_fs_inode_init_once(
887 inode_init_once((struct inode *)vnode);
891 * Attempt to flush the inode, this will actually fail
892 * if the inode is pinned, but we dirty the inode again
893 * at the point when it is unpinned after a log write,
894 * since this is when the inode itself becomes flushable.
904 xfs_itrace_entry(XFS_I(inode));
906 filemap_fdatawait(inode->i_mapping);
909 error = xfs_inode_flush(XFS_I(inode), flags);
911 * if we failed to write out the inode then mark
912 * it dirty again so we'll try again later.
915 mark_inode_dirty_sync(inode);
924 xfs_inode_t *ip = XFS_I(inode);
927 * ip can be null when xfs_iget_core calls xfs_idestroy if we
928 * find an inode with di_mode == 0 but without IGET_CREATE set.
931 xfs_itrace_entry(ip);
932 XFS_STATS_INC(vn_rele);
933 XFS_STATS_INC(vn_remove);
934 XFS_STATS_INC(vn_reclaim);
935 XFS_STATS_DEC(vn_active);
938 xfs_iflags_clear(ip, XFS_IMODIFIED);
940 panic("%s: cannot reclaim 0x%p\n", __func__, inode);
943 ASSERT(XFS_I(inode) == NULL);
947 * Enqueue a work item to be picked up by the vfs xfssyncd thread.
948 * Doing this has two advantages:
949 * - It saves on stack space, which is tight in certain situations
950 * - It can be used (with care) as a mechanism to avoid deadlocks.
951 * Flushing while allocating in a full filesystem requires both.
954 xfs_syncd_queue_work(
955 struct xfs_mount *mp,
957 void (*syncer)(struct xfs_mount *, void *))
959 struct bhv_vfs_sync_work *work;
961 work = kmem_alloc(sizeof(struct bhv_vfs_sync_work), KM_SLEEP);
962 INIT_LIST_HEAD(&work->w_list);
963 work->w_syncer = syncer;
966 spin_lock(&mp->m_sync_lock);
967 list_add_tail(&work->w_list, &mp->m_sync_list);
968 spin_unlock(&mp->m_sync_lock);
969 wake_up_process(mp->m_sync_task);
973 * Flush delayed allocate data, attempting to free up reserved space
974 * from existing allocations. At this point a new allocation attempt
975 * has failed with ENOSPC and we are in the process of scratching our
976 * heads, looking about for more room...
979 xfs_flush_inode_work(
980 struct xfs_mount *mp,
983 struct inode *inode = arg;
984 filemap_flush(inode->i_mapping);
992 struct inode *inode = VFS_I(ip);
995 xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_inode_work);
996 delay(msecs_to_jiffies(500));
1000 * This is the "bigger hammer" version of xfs_flush_inode_work...
1001 * (IOW, "If at first you don't succeed, use a Bigger Hammer").
1004 xfs_flush_device_work(
1005 struct xfs_mount *mp,
1008 struct inode *inode = arg;
1009 sync_blockdev(mp->m_super->s_bdev);
1017 struct inode *inode = VFS_I(ip);
1020 xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_device_work);
1021 delay(msecs_to_jiffies(500));
1022 xfs_log_force(ip->i_mount, (xfs_lsn_t)0, XFS_LOG_FORCE|XFS_LOG_SYNC);
1027 struct xfs_mount *mp,
1032 if (!(mp->m_flags & XFS_MOUNT_RDONLY))
1033 error = xfs_sync(mp, SYNC_FSDATA | SYNC_BDFLUSH | SYNC_ATTR);
1035 wake_up(&mp->m_wait_single_sync_task);
1042 struct xfs_mount *mp = arg;
1044 bhv_vfs_sync_work_t *work, *n;
1048 timeleft = xfs_syncd_centisecs * msecs_to_jiffies(10);
1050 timeleft = schedule_timeout_interruptible(timeleft);
1053 if (kthread_should_stop() && list_empty(&mp->m_sync_list))
1056 spin_lock(&mp->m_sync_lock);
1058 * We can get woken by laptop mode, to do a sync -
1059 * that's the (only!) case where the list would be
1060 * empty with time remaining.
1062 if (!timeleft || list_empty(&mp->m_sync_list)) {
1064 timeleft = xfs_syncd_centisecs *
1065 msecs_to_jiffies(10);
1066 INIT_LIST_HEAD(&mp->m_sync_work.w_list);
1067 list_add_tail(&mp->m_sync_work.w_list,
1070 list_for_each_entry_safe(work, n, &mp->m_sync_list, w_list)
1071 list_move(&work->w_list, &tmp);
1072 spin_unlock(&mp->m_sync_lock);
1074 list_for_each_entry_safe(work, n, &tmp, w_list) {
1075 (*work->w_syncer)(mp, work->w_data);
1076 list_del(&work->w_list);
1077 if (work == &mp->m_sync_work)
1088 struct xfs_mount *mp)
1090 kfree(mp->m_fsname);
1091 kfree(mp->m_rtname);
1092 kfree(mp->m_logname);
1097 struct super_block *sb)
1099 struct xfs_mount *mp = XFS_M(sb);
1100 struct xfs_inode *rip = mp->m_rootip;
1101 int unmount_event_flags = 0;
1104 kthread_stop(mp->m_sync_task);
1106 xfs_sync(mp, SYNC_ATTR | SYNC_DELWRI);
1109 if (mp->m_flags & XFS_MOUNT_DMAPI) {
1110 unmount_event_flags =
1111 (mp->m_dmevmask & (1 << DM_EVENT_UNMOUNT)) ?
1112 0 : DM_FLAGS_UNWANTED;
1114 * Ignore error from dmapi here, first unmount is not allowed
1115 * to fail anyway, and second we wouldn't want to fail a
1116 * unmount because of dmapi.
1118 XFS_SEND_PREUNMOUNT(mp, rip, DM_RIGHT_NULL, rip, DM_RIGHT_NULL,
1119 NULL, NULL, 0, 0, unmount_event_flags);
1124 * Blow away any referenced inode in the filestreams cache.
1125 * This can and will cause log traffic as inodes go inactive
1128 xfs_filestream_unmount(mp);
1130 XFS_bflush(mp->m_ddev_targp);
1131 error = xfs_unmount_flush(mp, 0);
1135 * If we're forcing a shutdown, typically because of a media error,
1136 * we want to make sure we invalidate dirty pages that belong to
1137 * referenced vnodes as well.
1139 if (XFS_FORCED_SHUTDOWN(mp)) {
1140 error = xfs_sync(mp, SYNC_WAIT | SYNC_CLOSE);
1141 ASSERT(error != EFSCORRUPTED);
1144 if (mp->m_flags & XFS_MOUNT_DMAPI) {
1145 XFS_SEND_UNMOUNT(mp, rip, DM_RIGHT_NULL, 0, 0,
1146 unmount_event_flags);
1151 xfs_icsb_destroy_counters(mp);
1152 xfs_close_devices(mp);
1155 xfs_free_fsname(mp);
1161 struct super_block *sb)
1163 if (!(sb->s_flags & MS_RDONLY))
1164 xfs_sync(XFS_M(sb), SYNC_FSDATA);
1170 struct super_block *sb,
1173 struct xfs_mount *mp = XFS_M(sb);
1178 * Treat a sync operation like a freeze. This is to work
1179 * around a race in sync_inodes() which works in two phases
1180 * - an asynchronous flush, which can write out an inode
1181 * without waiting for file size updates to complete, and a
1182 * synchronous flush, which wont do anything because the
1183 * async flush removed the inode's dirty flag. Also
1184 * sync_inodes() will not see any files that just have
1185 * outstanding transactions to be flushed because we don't
1186 * dirty the Linux inode until after the transaction I/O
1189 if (wait || unlikely(sb->s_frozen == SB_FREEZE_WRITE)) {
1191 * First stage of freeze - no more writers will make progress
1192 * now we are here, so we flush delwri and delalloc buffers
1193 * here, then wait for all I/O to complete. Data is frozen at
1194 * that point. Metadata is not frozen, transactions can still
1195 * occur here so don't bother flushing the buftarg (i.e
1196 * SYNC_QUIESCE) because it'll just get dirty again.
1198 flags = SYNC_DATA_QUIESCE;
1200 flags = SYNC_FSDATA;
1202 error = xfs_sync(mp, flags);
1205 if (unlikely(laptop_mode)) {
1206 int prev_sync_seq = mp->m_sync_seq;
1209 * The disk must be active because we're syncing.
1210 * We schedule xfssyncd now (now that the disk is
1211 * active) instead of later (when it might not be).
1213 wake_up_process(mp->m_sync_task);
1215 * We have to wait for the sync iteration to complete.
1216 * If we don't, the disk activity caused by the sync
1217 * will come after the sync is completed, and that
1218 * triggers another sync from laptop mode.
1220 wait_event(mp->m_wait_single_sync_task,
1221 mp->m_sync_seq != prev_sync_seq);
1229 struct dentry *dentry,
1230 struct kstatfs *statp)
1232 struct xfs_mount *mp = XFS_M(dentry->d_sb);
1233 xfs_sb_t *sbp = &mp->m_sb;
1234 __uint64_t fakeinos, id;
1237 statp->f_type = XFS_SB_MAGIC;
1238 statp->f_namelen = MAXNAMELEN - 1;
1240 id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
1241 statp->f_fsid.val[0] = (u32)id;
1242 statp->f_fsid.val[1] = (u32)(id >> 32);
1244 xfs_icsb_sync_counters(mp, XFS_ICSB_LAZY_COUNT);
1246 spin_lock(&mp->m_sb_lock);
1247 statp->f_bsize = sbp->sb_blocksize;
1248 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
1249 statp->f_blocks = sbp->sb_dblocks - lsize;
1250 statp->f_bfree = statp->f_bavail =
1251 sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
1252 fakeinos = statp->f_bfree << sbp->sb_inopblog;
1254 fakeinos += mp->m_inoadd;
1257 MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
1258 if (mp->m_maxicount)
1262 statp->f_files = min_t(typeof(statp->f_files),
1265 statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
1266 spin_unlock(&mp->m_sb_lock);
1268 XFS_QM_DQSTATVFS(XFS_I(dentry->d_inode), statp);
1274 struct super_block *sb,
1278 struct xfs_mount *mp = XFS_M(sb);
1279 substring_t args[MAX_OPT_ARGS];
1282 while ((p = strsep(&options, ",")) != NULL) {
1288 token = match_token(p, tokens, args);
1291 mp->m_flags |= XFS_MOUNT_BARRIER;
1294 * Test if barriers are actually working if we can,
1295 * else delay this check until the filesystem is
1298 if (!(mp->m_flags & XFS_MOUNT_RDONLY))
1299 xfs_mountfs_check_barriers(mp);
1302 mp->m_flags &= ~XFS_MOUNT_BARRIER;
1306 * Logically we would return an error here to prevent
1307 * users from believing they might have changed
1308 * mount options using remount which can't be changed.
1310 * But unfortunately mount(8) adds all options from
1311 * mtab and fstab to the mount arguments in some cases
1312 * so we can't blindly reject options, but have to
1313 * check for each specified option if it actually
1314 * differs from the currently set option and only
1315 * reject it if that's the case.
1317 * Until that is implemented we return success for
1318 * every remount request, and silently ignore all
1319 * options that we can't actually change.
1323 "XFS: mount option \"%s\" not supported for remount\n", p);
1332 if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(*flags & MS_RDONLY)) {
1333 mp->m_flags &= ~XFS_MOUNT_RDONLY;
1334 if (mp->m_flags & XFS_MOUNT_BARRIER)
1335 xfs_mountfs_check_barriers(mp);
1339 if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (*flags & MS_RDONLY)) {
1340 xfs_filestream_flush(mp);
1341 xfs_sync(mp, SYNC_DATA_QUIESCE);
1342 xfs_attr_quiesce(mp);
1343 mp->m_flags |= XFS_MOUNT_RDONLY;
1350 * Second stage of a freeze. The data is already frozen so we only
1351 * need to take care of themetadata. Once that's done write a dummy
1352 * record to dirty the log in case of a crash while frozen.
1356 struct super_block *sb)
1358 struct xfs_mount *mp = XFS_M(sb);
1360 xfs_attr_quiesce(mp);
1361 xfs_fs_log_dummy(mp);
1365 xfs_fs_show_options(
1367 struct vfsmount *mnt)
1369 return -xfs_showargs(XFS_M(mnt->mnt_sb), m);
1374 struct super_block *sb,
1377 return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XQUOTASYNC, 0, NULL);
1382 struct super_block *sb,
1383 struct fs_quota_stat *fqs)
1385 return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XGETQSTAT, 0, (caddr_t)fqs);
1390 struct super_block *sb,
1394 return -XFS_QM_QUOTACTL(XFS_M(sb), op, 0, (caddr_t)&flags);
1399 struct super_block *sb,
1402 struct fs_disk_quota *fdq)
1404 return -XFS_QM_QUOTACTL(XFS_M(sb),
1405 (type == USRQUOTA) ? Q_XGETQUOTA :
1406 ((type == GRPQUOTA) ? Q_XGETGQUOTA :
1407 Q_XGETPQUOTA), id, (caddr_t)fdq);
1412 struct super_block *sb,
1415 struct fs_disk_quota *fdq)
1417 return -XFS_QM_QUOTACTL(XFS_M(sb),
1418 (type == USRQUOTA) ? Q_XSETQLIM :
1419 ((type == GRPQUOTA) ? Q_XSETGQLIM :
1420 Q_XSETPQLIM), id, (caddr_t)fdq);
1424 * This function fills in xfs_mount_t fields based on mount args.
1425 * Note: the superblock has _not_ yet been read in.
1429 struct xfs_mount_args *ap,
1430 struct xfs_mount *mp)
1434 /* Values are in BBs */
1435 if ((ap->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
1437 * At this point the superblock has not been read
1438 * in, therefore we do not know the block size.
1439 * Before the mount call ends we will convert
1442 mp->m_dalign = ap->sunit;
1443 mp->m_swidth = ap->swidth;
1446 if (ap->logbufs != -1 &&
1448 (ap->logbufs < XLOG_MIN_ICLOGS ||
1449 ap->logbufs > XLOG_MAX_ICLOGS)) {
1451 "XFS: invalid logbufs value: %d [not %d-%d]",
1452 ap->logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
1453 return XFS_ERROR(EINVAL);
1455 mp->m_logbufs = ap->logbufs;
1456 if (ap->logbufsize != -1 &&
1457 ap->logbufsize != 0 &&
1458 (ap->logbufsize < XLOG_MIN_RECORD_BSIZE ||
1459 ap->logbufsize > XLOG_MAX_RECORD_BSIZE ||
1460 !is_power_of_2(ap->logbufsize))) {
1462 "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
1464 return XFS_ERROR(EINVAL);
1469 mp->m_logbsize = ap->logbufsize;
1470 mp->m_fsname_len = strlen(ap->fsname) + 1;
1472 mp->m_fsname = kstrdup(ap->fsname, GFP_KERNEL);
1476 if (ap->rtname[0]) {
1477 mp->m_rtname = kstrdup(ap->rtname, GFP_KERNEL);
1479 goto out_free_fsname;
1483 if (ap->logname[0]) {
1484 mp->m_logname = kstrdup(ap->logname, GFP_KERNEL);
1486 goto out_free_rtname;
1489 if (ap->flags & XFSMNT_WSYNC)
1490 mp->m_flags |= XFS_MOUNT_WSYNC;
1492 if (ap->flags & XFSMNT_INO64) {
1493 mp->m_flags |= XFS_MOUNT_INO64;
1494 mp->m_inoadd = XFS_INO64_OFFSET;
1497 if (ap->flags & XFSMNT_RETERR)
1498 mp->m_flags |= XFS_MOUNT_RETERR;
1499 if (ap->flags & XFSMNT_NOALIGN)
1500 mp->m_flags |= XFS_MOUNT_NOALIGN;
1501 if (ap->flags & XFSMNT_SWALLOC)
1502 mp->m_flags |= XFS_MOUNT_SWALLOC;
1503 if (ap->flags & XFSMNT_OSYNCISOSYNC)
1504 mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
1505 if (ap->flags & XFSMNT_32BITINODES)
1506 mp->m_flags |= XFS_MOUNT_32BITINODES;
1508 if (ap->flags & XFSMNT_IOSIZE) {
1509 if (ap->iosizelog > XFS_MAX_IO_LOG ||
1510 ap->iosizelog < XFS_MIN_IO_LOG) {
1512 "XFS: invalid log iosize: %d [not %d-%d]",
1513 ap->iosizelog, XFS_MIN_IO_LOG,
1515 return XFS_ERROR(EINVAL);
1518 mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
1519 mp->m_readio_log = mp->m_writeio_log = ap->iosizelog;
1522 if (ap->flags & XFSMNT_IKEEP)
1523 mp->m_flags |= XFS_MOUNT_IKEEP;
1524 if (ap->flags & XFSMNT_DIRSYNC)
1525 mp->m_flags |= XFS_MOUNT_DIRSYNC;
1526 if (ap->flags & XFSMNT_ATTR2)
1527 mp->m_flags |= XFS_MOUNT_ATTR2;
1528 if (ap->flags & XFSMNT_NOATTR2)
1529 mp->m_flags |= XFS_MOUNT_NOATTR2;
1531 if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
1532 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
1535 * no recovery flag requires a read-only mount
1537 if (ap->flags & XFSMNT_NORECOVERY) {
1538 if (!(mp->m_flags & XFS_MOUNT_RDONLY)) {
1540 "XFS: tried to mount a FS read-write without recovery!");
1541 return XFS_ERROR(EINVAL);
1543 mp->m_flags |= XFS_MOUNT_NORECOVERY;
1546 if (ap->flags & XFSMNT_NOUUID)
1547 mp->m_flags |= XFS_MOUNT_NOUUID;
1548 if (ap->flags & XFSMNT_BARRIER)
1549 mp->m_flags |= XFS_MOUNT_BARRIER;
1551 mp->m_flags &= ~XFS_MOUNT_BARRIER;
1553 if (ap->flags2 & XFSMNT2_FILESTREAMS)
1554 mp->m_flags |= XFS_MOUNT_FILESTREAMS;
1556 if (ap->flags & XFSMNT_DMAPI)
1557 mp->m_flags |= XFS_MOUNT_DMAPI;
1562 kfree(mp->m_rtname);
1564 kfree(mp->m_fsname);
1570 * This function fills in xfs_mount_t fields based on mount args.
1571 * Note: the superblock _has_ now been read in.
1575 struct xfs_mount_args *ap,
1576 struct xfs_mount *mp)
1578 int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
1580 /* Fail a mount where the logbuf is smaller then the log stripe */
1581 if (xfs_sb_version_haslogv2(&mp->m_sb)) {
1582 if ((ap->logbufsize <= 0) &&
1583 (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) {
1584 mp->m_logbsize = mp->m_sb.sb_logsunit;
1585 } else if (ap->logbufsize > 0 &&
1586 ap->logbufsize < mp->m_sb.sb_logsunit) {
1588 "XFS: logbuf size must be greater than or equal to log stripe size");
1589 return XFS_ERROR(EINVAL);
1592 /* Fail a mount if the logbuf is larger than 32K */
1593 if (ap->logbufsize > XLOG_BIG_RECORD_BSIZE) {
1595 "XFS: logbuf size for version 1 logs must be 16K or 32K");
1596 return XFS_ERROR(EINVAL);
1601 * mkfs'ed attr2 will turn on attr2 mount unless explicitly
1602 * told by noattr2 to turn it off
1604 if (xfs_sb_version_hasattr2(&mp->m_sb) &&
1605 !(ap->flags & XFSMNT_NOATTR2))
1606 mp->m_flags |= XFS_MOUNT_ATTR2;
1609 * prohibit r/w mounts of read-only filesystems
1611 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
1613 "XFS: cannot mount a read-only filesystem as read-write");
1614 return XFS_ERROR(EROFS);
1618 * check for shared mount.
1620 if (ap->flags & XFSMNT_SHARED) {
1621 if (!xfs_sb_version_hasshared(&mp->m_sb))
1622 return XFS_ERROR(EINVAL);
1625 * For IRIX 6.5, shared mounts must have the shared
1626 * version bit set, have the persistent readonly
1627 * field set, must be version 0 and can only be mounted
1630 if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) ||
1631 (mp->m_sb.sb_shared_vn != 0))
1632 return XFS_ERROR(EINVAL);
1634 mp->m_flags |= XFS_MOUNT_SHARED;
1637 * Shared XFS V0 can't deal with DMI. Return EINVAL.
1639 if (mp->m_sb.sb_shared_vn == 0 && (ap->flags & XFSMNT_DMAPI))
1640 return XFS_ERROR(EINVAL);
1643 if (ap->flags & XFSMNT_UQUOTA) {
1644 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
1645 if (ap->flags & XFSMNT_UQUOTAENF)
1646 mp->m_qflags |= XFS_UQUOTA_ENFD;
1649 if (ap->flags & XFSMNT_GQUOTA) {
1650 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
1651 if (ap->flags & XFSMNT_GQUOTAENF)
1652 mp->m_qflags |= XFS_OQUOTA_ENFD;
1653 } else if (ap->flags & XFSMNT_PQUOTA) {
1654 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
1655 if (ap->flags & XFSMNT_PQUOTAENF)
1656 mp->m_qflags |= XFS_OQUOTA_ENFD;
1664 struct super_block *sb,
1669 struct xfs_mount *mp = NULL;
1670 struct xfs_mount_args *args;
1671 int flags = 0, error = ENOMEM;
1673 args = xfs_args_allocate(sb, silent);
1677 mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
1681 spin_lock_init(&mp->m_sb_lock);
1682 mutex_init(&mp->m_ilock);
1683 mutex_init(&mp->m_growlock);
1684 atomic_set(&mp->m_active_trans, 0);
1685 INIT_LIST_HEAD(&mp->m_sync_list);
1686 spin_lock_init(&mp->m_sync_lock);
1687 init_waitqueue_head(&mp->m_wait_single_sync_task);
1692 if (sb->s_flags & MS_RDONLY)
1693 mp->m_flags |= XFS_MOUNT_RDONLY;
1695 error = xfs_parseargs(mp, (char *)data, args, 0);
1699 sb_min_blocksize(sb, BBSIZE);
1700 sb->s_xattr = xfs_xattr_handlers;
1701 sb->s_export_op = &xfs_export_operations;
1702 sb->s_qcop = &xfs_quotactl_operations;
1703 sb->s_op = &xfs_super_operations;
1705 error = xfs_dmops_get(mp, args);
1708 error = xfs_qmops_get(mp, args);
1712 if (args->flags & XFSMNT_QUIET)
1713 flags |= XFS_MFSI_QUIET;
1715 error = xfs_open_devices(mp, args);
1719 if (xfs_icsb_init_counters(mp))
1720 mp->m_flags |= XFS_MOUNT_NO_PERCPU_SB;
1723 * Setup flags based on mount(2) options and then the superblock
1725 error = xfs_start_flags(args, mp);
1727 goto out_free_fsname;
1728 error = xfs_readsb(mp, flags);
1730 goto out_free_fsname;
1731 error = xfs_finish_flags(args, mp);
1735 error = xfs_setup_devices(mp);
1739 if (mp->m_flags & XFS_MOUNT_BARRIER)
1740 xfs_mountfs_check_barriers(mp);
1742 error = xfs_filestream_mount(mp);
1746 error = xfs_mountfs(mp);
1748 goto out_filestream_unmount;
1750 XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, args->mtpt, args->fsname);
1753 sb->s_magic = XFS_SB_MAGIC;
1754 sb->s_blocksize = mp->m_sb.sb_blocksize;
1755 sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
1756 sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
1757 sb->s_time_gran = 1;
1758 set_posix_acl_flag(sb);
1760 root = igrab(VFS_I(mp->m_rootip));
1765 if (is_bad_inode(root)) {
1769 sb->s_root = d_alloc_root(root);
1775 mp->m_sync_work.w_syncer = xfs_sync_worker;
1776 mp->m_sync_work.w_mount = mp;
1777 mp->m_sync_task = kthread_run(xfssyncd, mp, "xfssyncd");
1778 if (IS_ERR(mp->m_sync_task)) {
1779 error = -PTR_ERR(mp->m_sync_task);
1783 xfs_itrace_exit(XFS_I(sb->s_root->d_inode));
1788 out_filestream_unmount:
1789 xfs_filestream_unmount(mp);
1793 xfs_free_fsname(mp);
1794 xfs_icsb_destroy_counters(mp);
1795 xfs_close_devices(mp);
1816 * Blow away any referenced inode in the filestreams cache.
1817 * This can and will cause log traffic as inodes go inactive
1820 xfs_filestream_unmount(mp);
1822 XFS_bflush(mp->m_ddev_targp);
1823 error = xfs_unmount_flush(mp, 0);
1832 struct file_system_type *fs_type,
1834 const char *dev_name,
1836 struct vfsmount *mnt)
1838 return get_sb_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super,
1842 static struct super_operations xfs_super_operations = {
1843 .alloc_inode = xfs_fs_alloc_inode,
1844 .destroy_inode = xfs_fs_destroy_inode,
1845 .write_inode = xfs_fs_write_inode,
1846 .clear_inode = xfs_fs_clear_inode,
1847 .put_super = xfs_fs_put_super,
1848 .write_super = xfs_fs_write_super,
1849 .sync_fs = xfs_fs_sync_super,
1850 .write_super_lockfs = xfs_fs_lockfs,
1851 .statfs = xfs_fs_statfs,
1852 .remount_fs = xfs_fs_remount,
1853 .show_options = xfs_fs_show_options,
1856 static struct quotactl_ops xfs_quotactl_operations = {
1857 .quota_sync = xfs_fs_quotasync,
1858 .get_xstate = xfs_fs_getxstate,
1859 .set_xstate = xfs_fs_setxstate,
1860 .get_xquota = xfs_fs_getxquota,
1861 .set_xquota = xfs_fs_setxquota,
1864 static struct file_system_type xfs_fs_type = {
1865 .owner = THIS_MODULE,
1867 .get_sb = xfs_fs_get_sb,
1868 .kill_sb = kill_block_super,
1869 .fs_flags = FS_REQUIRES_DEV,
1873 xfs_alloc_trace_bufs(void)
1875 #ifdef XFS_ALLOC_TRACE
1876 xfs_alloc_trace_buf = ktrace_alloc(XFS_ALLOC_TRACE_SIZE, KM_MAYFAIL);
1877 if (!xfs_alloc_trace_buf)
1880 #ifdef XFS_BMAP_TRACE
1881 xfs_bmap_trace_buf = ktrace_alloc(XFS_BMAP_TRACE_SIZE, KM_MAYFAIL);
1882 if (!xfs_bmap_trace_buf)
1883 goto out_free_alloc_trace;
1885 #ifdef XFS_BMBT_TRACE
1886 xfs_bmbt_trace_buf = ktrace_alloc(XFS_BMBT_TRACE_SIZE, KM_MAYFAIL);
1887 if (!xfs_bmbt_trace_buf)
1888 goto out_free_bmap_trace;
1890 #ifdef XFS_ATTR_TRACE
1891 xfs_attr_trace_buf = ktrace_alloc(XFS_ATTR_TRACE_SIZE, KM_MAYFAIL);
1892 if (!xfs_attr_trace_buf)
1893 goto out_free_bmbt_trace;
1895 #ifdef XFS_DIR2_TRACE
1896 xfs_dir2_trace_buf = ktrace_alloc(XFS_DIR2_GTRACE_SIZE, KM_MAYFAIL);
1897 if (!xfs_dir2_trace_buf)
1898 goto out_free_attr_trace;
1903 #ifdef XFS_DIR2_TRACE
1904 out_free_attr_trace:
1906 #ifdef XFS_ATTR_TRACE
1907 ktrace_free(xfs_attr_trace_buf);
1908 out_free_bmbt_trace:
1910 #ifdef XFS_BMBT_TRACE
1911 ktrace_free(xfs_bmbt_trace_buf);
1912 out_free_bmap_trace:
1914 #ifdef XFS_BMAP_TRACE
1915 ktrace_free(xfs_bmap_trace_buf);
1916 out_free_alloc_trace:
1918 #ifdef XFS_ALLOC_TRACE
1919 ktrace_free(xfs_alloc_trace_buf);
1926 xfs_free_trace_bufs(void)
1928 #ifdef XFS_DIR2_TRACE
1929 ktrace_free(xfs_dir2_trace_buf);
1931 #ifdef XFS_ATTR_TRACE
1932 ktrace_free(xfs_attr_trace_buf);
1934 #ifdef XFS_BMBT_TRACE
1935 ktrace_free(xfs_bmbt_trace_buf);
1937 #ifdef XFS_BMAP_TRACE
1938 ktrace_free(xfs_bmap_trace_buf);
1940 #ifdef XFS_ALLOC_TRACE
1941 ktrace_free(xfs_alloc_trace_buf);
1946 xfs_init_zones(void)
1948 xfs_vnode_zone = kmem_zone_init_flags(sizeof(struct inode), "xfs_vnode",
1949 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM |
1951 xfs_fs_inode_init_once);
1952 if (!xfs_vnode_zone)
1955 xfs_ioend_zone = kmem_zone_init(sizeof(xfs_ioend_t), "xfs_ioend");
1956 if (!xfs_ioend_zone)
1957 goto out_destroy_vnode_zone;
1959 xfs_ioend_pool = mempool_create_slab_pool(4 * MAX_BUF_PER_PAGE,
1961 if (!xfs_ioend_pool)
1962 goto out_destroy_ioend_zone;
1964 xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t),
1966 if (!xfs_log_ticket_zone)
1967 goto out_destroy_ioend_pool;
1969 xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
1970 "xfs_bmap_free_item");
1971 if (!xfs_bmap_free_item_zone)
1972 goto out_destroy_log_ticket_zone;
1973 xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
1975 if (!xfs_btree_cur_zone)
1976 goto out_destroy_bmap_free_item_zone;
1978 xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t),
1980 if (!xfs_da_state_zone)
1981 goto out_destroy_btree_cur_zone;
1983 xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf");
1984 if (!xfs_dabuf_zone)
1985 goto out_destroy_da_state_zone;
1987 xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
1988 if (!xfs_ifork_zone)
1989 goto out_destroy_dabuf_zone;
1991 xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
1992 if (!xfs_trans_zone)
1993 goto out_destroy_ifork_zone;
1996 * The size of the zone allocated buf log item is the maximum
1997 * size possible under XFS. This wastes a little bit of memory,
1998 * but it is much faster.
2000 xfs_buf_item_zone = kmem_zone_init((sizeof(xfs_buf_log_item_t) +
2001 (((XFS_MAX_BLOCKSIZE / XFS_BLI_CHUNK) /
2002 NBWORD) * sizeof(int))), "xfs_buf_item");
2003 if (!xfs_buf_item_zone)
2004 goto out_destroy_trans_zone;
2006 xfs_efd_zone = kmem_zone_init((sizeof(xfs_efd_log_item_t) +
2007 ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
2008 sizeof(xfs_extent_t))), "xfs_efd_item");
2010 goto out_destroy_buf_item_zone;
2012 xfs_efi_zone = kmem_zone_init((sizeof(xfs_efi_log_item_t) +
2013 ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
2014 sizeof(xfs_extent_t))), "xfs_efi_item");
2016 goto out_destroy_efd_zone;
2019 kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
2020 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM |
2021 KM_ZONE_SPREAD, NULL);
2022 if (!xfs_inode_zone)
2023 goto out_destroy_efi_zone;
2026 kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
2027 KM_ZONE_SPREAD, NULL);
2029 goto out_destroy_inode_zone;
2031 #ifdef CONFIG_XFS_POSIX_ACL
2032 xfs_acl_zone = kmem_zone_init(sizeof(xfs_acl_t), "xfs_acl");
2034 goto out_destroy_ili_zone;
2039 #ifdef CONFIG_XFS_POSIX_ACL
2040 out_destroy_ili_zone:
2042 kmem_zone_destroy(xfs_ili_zone);
2043 out_destroy_inode_zone:
2044 kmem_zone_destroy(xfs_inode_zone);
2045 out_destroy_efi_zone:
2046 kmem_zone_destroy(xfs_efi_zone);
2047 out_destroy_efd_zone:
2048 kmem_zone_destroy(xfs_efd_zone);
2049 out_destroy_buf_item_zone:
2050 kmem_zone_destroy(xfs_buf_item_zone);
2051 out_destroy_trans_zone:
2052 kmem_zone_destroy(xfs_trans_zone);
2053 out_destroy_ifork_zone:
2054 kmem_zone_destroy(xfs_ifork_zone);
2055 out_destroy_dabuf_zone:
2056 kmem_zone_destroy(xfs_dabuf_zone);
2057 out_destroy_da_state_zone:
2058 kmem_zone_destroy(xfs_da_state_zone);
2059 out_destroy_btree_cur_zone:
2060 kmem_zone_destroy(xfs_btree_cur_zone);
2061 out_destroy_bmap_free_item_zone:
2062 kmem_zone_destroy(xfs_bmap_free_item_zone);
2063 out_destroy_log_ticket_zone:
2064 kmem_zone_destroy(xfs_log_ticket_zone);
2065 out_destroy_ioend_pool:
2066 mempool_destroy(xfs_ioend_pool);
2067 out_destroy_ioend_zone:
2068 kmem_zone_destroy(xfs_ioend_zone);
2069 out_destroy_vnode_zone:
2070 kmem_zone_destroy(xfs_vnode_zone);
2076 xfs_destroy_zones(void)
2078 #ifdef CONFIG_XFS_POSIX_ACL
2079 kmem_zone_destroy(xfs_acl_zone);
2081 kmem_zone_destroy(xfs_ili_zone);
2082 kmem_zone_destroy(xfs_inode_zone);
2083 kmem_zone_destroy(xfs_efi_zone);
2084 kmem_zone_destroy(xfs_efd_zone);
2085 kmem_zone_destroy(xfs_buf_item_zone);
2086 kmem_zone_destroy(xfs_trans_zone);
2087 kmem_zone_destroy(xfs_ifork_zone);
2088 kmem_zone_destroy(xfs_dabuf_zone);
2089 kmem_zone_destroy(xfs_da_state_zone);
2090 kmem_zone_destroy(xfs_btree_cur_zone);
2091 kmem_zone_destroy(xfs_bmap_free_item_zone);
2092 kmem_zone_destroy(xfs_log_ticket_zone);
2093 mempool_destroy(xfs_ioend_pool);
2094 kmem_zone_destroy(xfs_ioend_zone);
2095 kmem_zone_destroy(xfs_vnode_zone);
2103 static char message[] __initdata = KERN_INFO \
2104 XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled\n";
2112 error = xfs_init_zones();
2116 error = xfs_alloc_trace_bufs();
2118 goto out_destroy_zones;
2120 error = xfs_mru_cache_init();
2122 goto out_free_trace_buffers;
2124 error = xfs_filestream_init();
2126 goto out_mru_cache_uninit;
2128 error = xfs_buf_init();
2130 goto out_filestream_uninit;
2132 error = xfs_init_procfs();
2134 goto out_buf_terminate;
2136 error = xfs_sysctl_register();
2138 goto out_cleanup_procfs;
2142 error = register_filesystem(&xfs_fs_type);
2144 goto out_sysctl_unregister;
2147 out_sysctl_unregister:
2148 xfs_sysctl_unregister();
2150 xfs_cleanup_procfs();
2152 xfs_buf_terminate();
2153 out_filestream_uninit:
2154 xfs_filestream_uninit();
2155 out_mru_cache_uninit:
2156 xfs_mru_cache_uninit();
2157 out_free_trace_buffers:
2158 xfs_free_trace_bufs();
2160 xfs_destroy_zones();
2169 unregister_filesystem(&xfs_fs_type);
2170 xfs_sysctl_unregister();
2171 xfs_cleanup_procfs();
2172 xfs_buf_terminate();
2173 xfs_filestream_uninit();
2174 xfs_mru_cache_uninit();
2175 xfs_free_trace_bufs();
2176 xfs_destroy_zones();
2180 module_init(init_xfs_fs);
2181 module_exit(exit_xfs_fs);
2183 MODULE_AUTHOR("Silicon Graphics, Inc.");
2184 MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
2185 MODULE_LICENSE("GPL");