1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2006 Silicon Graphics, Inc.
8 #include "xfs_shared.h"
9 #include "xfs_format.h"
10 #include "xfs_log_format.h"
11 #include "xfs_trans_resv.h"
13 #include "xfs_mount.h"
14 #include "xfs_inode.h"
15 #include "xfs_btree.h"
17 #include "xfs_alloc.h"
18 #include "xfs_fsops.h"
19 #include "xfs_trans.h"
20 #include "xfs_buf_item.h"
22 #include "xfs_log_priv.h"
24 #include "xfs_extfree_item.h"
25 #include "xfs_mru_cache.h"
26 #include "xfs_inode_item.h"
27 #include "xfs_icache.h"
28 #include "xfs_trace.h"
29 #include "xfs_icreate_item.h"
30 #include "xfs_filestream.h"
31 #include "xfs_quota.h"
32 #include "xfs_sysfs.h"
33 #include "xfs_ondisk.h"
34 #include "xfs_rmap_item.h"
35 #include "xfs_refcount_item.h"
36 #include "xfs_bmap_item.h"
37 #include "xfs_reflink.h"
39 #include <linux/magic.h>
40 #include <linux/parser.h>
42 static const struct super_operations xfs_super_operations;
44 static struct kset *xfs_kset; /* top-level xfs sysfs dir */
46 static struct xfs_kobj xfs_dbg_kobj; /* global debug sysfs attrs */
50 * Table driven mount option parser.
53 Opt_logbufs, Opt_logbsize, Opt_logdev, Opt_rtdev,
54 Opt_wsync, Opt_noalign, Opt_swalloc, Opt_sunit, Opt_swidth, Opt_nouuid,
55 Opt_grpid, Opt_nogrpid, Opt_bsdgroups, Opt_sysvgroups,
56 Opt_allocsize, Opt_norecovery, Opt_inode64, Opt_inode32, Opt_ikeep,
57 Opt_noikeep, Opt_largeio, Opt_nolargeio, Opt_attr2, Opt_noattr2,
58 Opt_filestreams, Opt_quota, Opt_noquota, Opt_usrquota, Opt_grpquota,
59 Opt_prjquota, Opt_uquota, Opt_gquota, Opt_pquota,
60 Opt_uqnoenforce, Opt_gqnoenforce, Opt_pqnoenforce, Opt_qnoenforce,
61 Opt_discard, Opt_nodiscard, Opt_dax, Opt_err,
64 static const match_table_t tokens = {
65 {Opt_logbufs, "logbufs=%u"}, /* number of XFS log buffers */
66 {Opt_logbsize, "logbsize=%s"}, /* size of XFS log buffers */
67 {Opt_logdev, "logdev=%s"}, /* log device */
68 {Opt_rtdev, "rtdev=%s"}, /* realtime I/O device */
69 {Opt_wsync, "wsync"}, /* safe-mode nfs compatible mount */
70 {Opt_noalign, "noalign"}, /* turn off stripe alignment */
71 {Opt_swalloc, "swalloc"}, /* turn on stripe width allocation */
72 {Opt_sunit, "sunit=%u"}, /* data volume stripe unit */
73 {Opt_swidth, "swidth=%u"}, /* data volume stripe width */
74 {Opt_nouuid, "nouuid"}, /* ignore filesystem UUID */
75 {Opt_grpid, "grpid"}, /* group-ID from parent directory */
76 {Opt_nogrpid, "nogrpid"}, /* group-ID from current process */
77 {Opt_bsdgroups, "bsdgroups"}, /* group-ID from parent directory */
78 {Opt_sysvgroups,"sysvgroups"}, /* group-ID from current process */
79 {Opt_allocsize, "allocsize=%s"},/* preferred allocation size */
80 {Opt_norecovery,"norecovery"}, /* don't run XFS recovery */
81 {Opt_inode64, "inode64"}, /* inodes can be allocated anywhere */
82 {Opt_inode32, "inode32"}, /* inode allocation limited to
83 * XFS_MAXINUMBER_32 */
84 {Opt_ikeep, "ikeep"}, /* do not free empty inode clusters */
85 {Opt_noikeep, "noikeep"}, /* free empty inode clusters */
86 {Opt_largeio, "largeio"}, /* report large I/O sizes in stat() */
87 {Opt_nolargeio, "nolargeio"}, /* do not report large I/O sizes
89 {Opt_attr2, "attr2"}, /* do use attr2 attribute format */
90 {Opt_noattr2, "noattr2"}, /* do not use attr2 attribute format */
91 {Opt_filestreams,"filestreams"},/* use filestreams allocator */
92 {Opt_quota, "quota"}, /* disk quotas (user) */
93 {Opt_noquota, "noquota"}, /* no quotas */
94 {Opt_usrquota, "usrquota"}, /* user quota enabled */
95 {Opt_grpquota, "grpquota"}, /* group quota enabled */
96 {Opt_prjquota, "prjquota"}, /* project quota enabled */
97 {Opt_uquota, "uquota"}, /* user quota (IRIX variant) */
98 {Opt_gquota, "gquota"}, /* group quota (IRIX variant) */
99 {Opt_pquota, "pquota"}, /* project quota (IRIX variant) */
100 {Opt_uqnoenforce,"uqnoenforce"},/* user quota limit enforcement */
101 {Opt_gqnoenforce,"gqnoenforce"},/* group quota limit enforcement */
102 {Opt_pqnoenforce,"pqnoenforce"},/* project quota limit enforcement */
103 {Opt_qnoenforce, "qnoenforce"}, /* same as uqnoenforce */
104 {Opt_discard, "discard"}, /* Discard unused blocks */
105 {Opt_nodiscard, "nodiscard"}, /* Do not discard unused blocks */
106 {Opt_dax, "dax"}, /* Enable direct access to bdev pages */
112 suffix_kstrtoint(const substring_t *s, unsigned int base, int *res)
114 int last, shift_left_factor = 0, _res;
118 value = match_strdup(s);
122 last = strlen(value) - 1;
123 if (value[last] == 'K' || value[last] == 'k') {
124 shift_left_factor = 10;
127 if (value[last] == 'M' || value[last] == 'm') {
128 shift_left_factor = 20;
131 if (value[last] == 'G' || value[last] == 'g') {
132 shift_left_factor = 30;
136 if (kstrtoint(value, base, &_res))
139 *res = _res << shift_left_factor;
144 * This function fills in xfs_mount_t fields based on mount args.
145 * Note: the superblock has _not_ yet been read in.
147 * Note that this function leaks the various device name allocations on
148 * failure. The caller takes care of them.
150 * *sb is const because this is also used to test options on the remount
151 * path, and we don't want this to have any side effects at remount time.
152 * Today this function does not change *sb, but just to future-proof...
156 struct xfs_mount *mp,
159 const struct super_block *sb = mp->m_super;
161 substring_t args[MAX_OPT_ARGS];
163 uint8_t iosizelog = 0;
166 * set up the mount name first so all the errors will refer to the
169 mp->m_fsname = kstrndup(sb->s_id, MAXNAMELEN, GFP_KERNEL);
172 mp->m_fsname_len = strlen(mp->m_fsname) + 1;
175 * Copy binary VFS mount flags we are interested in.
178 mp->m_flags |= XFS_MOUNT_RDONLY;
179 if (sb->s_flags & SB_DIRSYNC)
180 mp->m_flags |= XFS_MOUNT_DIRSYNC;
181 if (sb->s_flags & SB_SYNCHRONOUS)
182 mp->m_flags |= XFS_MOUNT_WSYNC;
185 * Set some default flags that could be cleared by the mount option
188 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
191 * These can be overridden by the mount option parsing.
199 while ((p = strsep(&options, ",")) != NULL) {
205 token = match_token(p, tokens, args);
208 if (match_int(args, &mp->m_logbufs))
212 if (suffix_kstrtoint(args, 10, &mp->m_logbsize))
216 kfree(mp->m_logname);
217 mp->m_logname = match_strdup(args);
223 mp->m_rtname = match_strdup(args);
228 if (suffix_kstrtoint(args, 10, &iosize))
230 iosizelog = ffs(iosize) - 1;
234 mp->m_flags |= XFS_MOUNT_GRPID;
238 mp->m_flags &= ~XFS_MOUNT_GRPID;
241 mp->m_flags |= XFS_MOUNT_WSYNC;
244 mp->m_flags |= XFS_MOUNT_NORECOVERY;
247 mp->m_flags |= XFS_MOUNT_NOALIGN;
250 mp->m_flags |= XFS_MOUNT_SWALLOC;
253 if (match_int(args, &mp->m_dalign))
257 if (match_int(args, &mp->m_swidth))
261 mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
264 mp->m_flags &= ~XFS_MOUNT_SMALL_INUMS;
267 mp->m_flags |= XFS_MOUNT_NOUUID;
270 mp->m_flags |= XFS_MOUNT_IKEEP;
273 mp->m_flags &= ~XFS_MOUNT_IKEEP;
276 mp->m_flags &= ~XFS_MOUNT_COMPAT_IOSIZE;
279 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
282 mp->m_flags |= XFS_MOUNT_ATTR2;
285 mp->m_flags &= ~XFS_MOUNT_ATTR2;
286 mp->m_flags |= XFS_MOUNT_NOATTR2;
288 case Opt_filestreams:
289 mp->m_flags |= XFS_MOUNT_FILESTREAMS;
292 mp->m_qflags &= ~XFS_ALL_QUOTA_ACCT;
293 mp->m_qflags &= ~XFS_ALL_QUOTA_ENFD;
294 mp->m_qflags &= ~XFS_ALL_QUOTA_ACTIVE;
299 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE |
303 case Opt_uqnoenforce:
304 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
305 mp->m_qflags &= ~XFS_UQUOTA_ENFD;
309 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE |
312 case Opt_pqnoenforce:
313 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
314 mp->m_qflags &= ~XFS_PQUOTA_ENFD;
318 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE |
321 case Opt_gqnoenforce:
322 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
323 mp->m_qflags &= ~XFS_GQUOTA_ENFD;
326 mp->m_flags |= XFS_MOUNT_DISCARD;
329 mp->m_flags &= ~XFS_MOUNT_DISCARD;
333 mp->m_flags |= XFS_MOUNT_DAX;
337 xfs_warn(mp, "unknown mount option [%s].", p);
343 * no recovery flag requires a read-only mount
345 if ((mp->m_flags & XFS_MOUNT_NORECOVERY) &&
346 !(mp->m_flags & XFS_MOUNT_RDONLY)) {
347 xfs_warn(mp, "no-recovery mounts must be read-only.");
351 if ((mp->m_flags & XFS_MOUNT_NOALIGN) &&
352 (mp->m_dalign || mp->m_swidth)) {
354 "sunit and swidth options incompatible with the noalign option");
358 #ifndef CONFIG_XFS_QUOTA
359 if (XFS_IS_QUOTA_RUNNING(mp)) {
360 xfs_warn(mp, "quota support not available in this kernel.");
365 if ((mp->m_dalign && !mp->m_swidth) ||
366 (!mp->m_dalign && mp->m_swidth)) {
367 xfs_warn(mp, "sunit and swidth must be specified together");
371 if (mp->m_dalign && (mp->m_swidth % mp->m_dalign != 0)) {
373 "stripe width (%d) must be a multiple of the stripe unit (%d)",
374 mp->m_swidth, mp->m_dalign);
379 if (mp->m_logbufs != -1 &&
380 mp->m_logbufs != 0 &&
381 (mp->m_logbufs < XLOG_MIN_ICLOGS ||
382 mp->m_logbufs > XLOG_MAX_ICLOGS)) {
383 xfs_warn(mp, "invalid logbufs value: %d [not %d-%d]",
384 mp->m_logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
387 if (mp->m_logbsize != -1 &&
388 mp->m_logbsize != 0 &&
389 (mp->m_logbsize < XLOG_MIN_RECORD_BSIZE ||
390 mp->m_logbsize > XLOG_MAX_RECORD_BSIZE ||
391 !is_power_of_2(mp->m_logbsize))) {
393 "invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
399 if (iosizelog > XFS_MAX_IO_LOG ||
400 iosizelog < XFS_MIN_IO_LOG) {
401 xfs_warn(mp, "invalid log iosize: %d [not %d-%d]",
402 iosizelog, XFS_MIN_IO_LOG,
407 mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
408 mp->m_readio_log = iosizelog;
409 mp->m_writeio_log = iosizelog;
415 struct proc_xfs_info {
422 struct xfs_mount *mp,
425 static struct proc_xfs_info xfs_info_set[] = {
426 /* the few simple ones we can get from the mount struct */
427 { XFS_MOUNT_IKEEP, ",ikeep" },
428 { XFS_MOUNT_WSYNC, ",wsync" },
429 { XFS_MOUNT_NOALIGN, ",noalign" },
430 { XFS_MOUNT_SWALLOC, ",swalloc" },
431 { XFS_MOUNT_NOUUID, ",nouuid" },
432 { XFS_MOUNT_NORECOVERY, ",norecovery" },
433 { XFS_MOUNT_ATTR2, ",attr2" },
434 { XFS_MOUNT_FILESTREAMS, ",filestreams" },
435 { XFS_MOUNT_GRPID, ",grpid" },
436 { XFS_MOUNT_DISCARD, ",discard" },
437 { XFS_MOUNT_SMALL_INUMS, ",inode32" },
438 { XFS_MOUNT_DAX, ",dax" },
441 static struct proc_xfs_info xfs_info_unset[] = {
442 /* the few simple ones we can get from the mount struct */
443 { XFS_MOUNT_COMPAT_IOSIZE, ",largeio" },
444 { XFS_MOUNT_SMALL_INUMS, ",inode64" },
447 struct proc_xfs_info *xfs_infop;
449 for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
450 if (mp->m_flags & xfs_infop->flag)
451 seq_puts(m, xfs_infop->str);
453 for (xfs_infop = xfs_info_unset; xfs_infop->flag; xfs_infop++) {
454 if (!(mp->m_flags & xfs_infop->flag))
455 seq_puts(m, xfs_infop->str);
458 if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
459 seq_printf(m, ",allocsize=%dk",
460 (int)(1 << mp->m_writeio_log) >> 10);
462 if (mp->m_logbufs > 0)
463 seq_printf(m, ",logbufs=%d", mp->m_logbufs);
464 if (mp->m_logbsize > 0)
465 seq_printf(m, ",logbsize=%dk", mp->m_logbsize >> 10);
468 seq_show_option(m, "logdev", mp->m_logname);
470 seq_show_option(m, "rtdev", mp->m_rtname);
472 if (mp->m_dalign > 0)
473 seq_printf(m, ",sunit=%d",
474 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
475 if (mp->m_swidth > 0)
476 seq_printf(m, ",swidth=%d",
477 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
479 if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD))
480 seq_puts(m, ",usrquota");
481 else if (mp->m_qflags & XFS_UQUOTA_ACCT)
482 seq_puts(m, ",uqnoenforce");
484 if (mp->m_qflags & XFS_PQUOTA_ACCT) {
485 if (mp->m_qflags & XFS_PQUOTA_ENFD)
486 seq_puts(m, ",prjquota");
488 seq_puts(m, ",pqnoenforce");
490 if (mp->m_qflags & XFS_GQUOTA_ACCT) {
491 if (mp->m_qflags & XFS_GQUOTA_ENFD)
492 seq_puts(m, ",grpquota");
494 seq_puts(m, ",gqnoenforce");
497 if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
498 seq_puts(m, ",noquota");
503 unsigned int blockshift)
505 unsigned int pagefactor = 1;
506 unsigned int bitshift = BITS_PER_LONG - 1;
508 /* Figure out maximum filesize, on Linux this can depend on
509 * the filesystem blocksize (on 32 bit platforms).
510 * __block_write_begin does this in an [unsigned] long long...
511 * page->index << (PAGE_SHIFT - bbits)
512 * So, for page sized blocks (4K on 32 bit platforms),
513 * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
514 * (((u64)PAGE_SIZE << (BITS_PER_LONG-1))-1)
515 * but for smaller blocksizes it is less (bbits = log2 bsize).
518 #if BITS_PER_LONG == 32
519 ASSERT(sizeof(sector_t) == 8);
520 pagefactor = PAGE_SIZE;
521 bitshift = BITS_PER_LONG;
524 return (((uint64_t)pagefactor) << bitshift) - 1;
528 * Set parameters for inode allocation heuristics, taking into account
529 * filesystem size and inode32/inode64 mount options; i.e. specifically
530 * whether or not XFS_MOUNT_SMALL_INUMS is set.
532 * Inode allocation patterns are altered only if inode32 is requested
533 * (XFS_MOUNT_SMALL_INUMS), and the filesystem is sufficiently large.
534 * If altered, XFS_MOUNT_32BITINODES is set as well.
536 * An agcount independent of that in the mount structure is provided
537 * because in the growfs case, mp->m_sb.sb_agcount is not yet updated
538 * to the potentially higher ag count.
540 * Returns the maximum AG index which may contain inodes.
544 struct xfs_mount *mp,
545 xfs_agnumber_t agcount)
547 xfs_agnumber_t index;
548 xfs_agnumber_t maxagi = 0;
549 xfs_sb_t *sbp = &mp->m_sb;
550 xfs_agnumber_t max_metadata;
555 * Calculate how much should be reserved for inodes to meet
556 * the max inode percentage. Used only for inode32.
558 if (M_IGEO(mp)->maxicount) {
561 icount = sbp->sb_dblocks * sbp->sb_imax_pct;
563 icount += sbp->sb_agblocks - 1;
564 do_div(icount, sbp->sb_agblocks);
565 max_metadata = icount;
567 max_metadata = agcount;
570 /* Get the last possible inode in the filesystem */
571 agino = XFS_AGB_TO_AGINO(mp, sbp->sb_agblocks - 1);
572 ino = XFS_AGINO_TO_INO(mp, agcount - 1, agino);
575 * If user asked for no more than 32-bit inodes, and the fs is
576 * sufficiently large, set XFS_MOUNT_32BITINODES if we must alter
577 * the allocator to accommodate the request.
579 if ((mp->m_flags & XFS_MOUNT_SMALL_INUMS) && ino > XFS_MAXINUMBER_32)
580 mp->m_flags |= XFS_MOUNT_32BITINODES;
582 mp->m_flags &= ~XFS_MOUNT_32BITINODES;
584 for (index = 0; index < agcount; index++) {
585 struct xfs_perag *pag;
587 ino = XFS_AGINO_TO_INO(mp, index, agino);
589 pag = xfs_perag_get(mp, index);
591 if (mp->m_flags & XFS_MOUNT_32BITINODES) {
592 if (ino > XFS_MAXINUMBER_32) {
593 pag->pagi_inodeok = 0;
594 pag->pagf_metadata = 0;
596 pag->pagi_inodeok = 1;
598 if (index < max_metadata)
599 pag->pagf_metadata = 1;
601 pag->pagf_metadata = 0;
604 pag->pagi_inodeok = 1;
605 pag->pagf_metadata = 0;
611 return (mp->m_flags & XFS_MOUNT_32BITINODES) ? maxagi : agcount;
618 struct block_device **bdevp)
622 *bdevp = blkdev_get_by_path(name, FMODE_READ|FMODE_WRITE|FMODE_EXCL,
624 if (IS_ERR(*bdevp)) {
625 error = PTR_ERR(*bdevp);
626 xfs_warn(mp, "Invalid device [%s], error=%d", name, error);
634 struct block_device *bdev)
637 blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
641 xfs_blkdev_issue_flush(
642 xfs_buftarg_t *buftarg)
644 blkdev_issue_flush(buftarg->bt_bdev, GFP_NOFS, NULL);
649 struct xfs_mount *mp)
651 struct dax_device *dax_ddev = mp->m_ddev_targp->bt_daxdev;
653 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
654 struct block_device *logdev = mp->m_logdev_targp->bt_bdev;
655 struct dax_device *dax_logdev = mp->m_logdev_targp->bt_daxdev;
657 xfs_free_buftarg(mp->m_logdev_targp);
658 xfs_blkdev_put(logdev);
659 fs_put_dax(dax_logdev);
661 if (mp->m_rtdev_targp) {
662 struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev;
663 struct dax_device *dax_rtdev = mp->m_rtdev_targp->bt_daxdev;
665 xfs_free_buftarg(mp->m_rtdev_targp);
666 xfs_blkdev_put(rtdev);
667 fs_put_dax(dax_rtdev);
669 xfs_free_buftarg(mp->m_ddev_targp);
670 fs_put_dax(dax_ddev);
674 * The file system configurations are:
675 * (1) device (partition) with data and internal log
676 * (2) logical volume with data and log subvolumes.
677 * (3) logical volume with data, log, and realtime subvolumes.
679 * We only have to handle opening the log and realtime volumes here if
680 * they are present. The data subvolume has already been opened by
681 * get_sb_bdev() and is stored in sb->s_bdev.
685 struct xfs_mount *mp)
687 struct block_device *ddev = mp->m_super->s_bdev;
688 struct dax_device *dax_ddev = fs_dax_get_by_bdev(ddev);
689 struct dax_device *dax_logdev = NULL, *dax_rtdev = NULL;
690 struct block_device *logdev = NULL, *rtdev = NULL;
694 * Open real time and log devices - order is important.
697 error = xfs_blkdev_get(mp, mp->m_logname, &logdev);
700 dax_logdev = fs_dax_get_by_bdev(logdev);
704 error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev);
706 goto out_close_logdev;
708 if (rtdev == ddev || rtdev == logdev) {
710 "Cannot mount filesystem with identical rtdev and ddev/logdev.");
712 goto out_close_rtdev;
714 dax_rtdev = fs_dax_get_by_bdev(rtdev);
718 * Setup xfs_mount buffer target pointers
721 mp->m_ddev_targp = xfs_alloc_buftarg(mp, ddev, dax_ddev);
722 if (!mp->m_ddev_targp)
723 goto out_close_rtdev;
726 mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev, dax_rtdev);
727 if (!mp->m_rtdev_targp)
728 goto out_free_ddev_targ;
731 if (logdev && logdev != ddev) {
732 mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev, dax_logdev);
733 if (!mp->m_logdev_targp)
734 goto out_free_rtdev_targ;
736 mp->m_logdev_targp = mp->m_ddev_targp;
742 if (mp->m_rtdev_targp)
743 xfs_free_buftarg(mp->m_rtdev_targp);
745 xfs_free_buftarg(mp->m_ddev_targp);
747 xfs_blkdev_put(rtdev);
748 fs_put_dax(dax_rtdev);
750 if (logdev && logdev != ddev) {
751 xfs_blkdev_put(logdev);
752 fs_put_dax(dax_logdev);
755 fs_put_dax(dax_ddev);
760 * Setup xfs_mount buffer target pointers based on superblock
764 struct xfs_mount *mp)
768 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_sectsize);
772 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
773 unsigned int log_sector_size = BBSIZE;
775 if (xfs_sb_version_hassector(&mp->m_sb))
776 log_sector_size = mp->m_sb.sb_logsectsize;
777 error = xfs_setsize_buftarg(mp->m_logdev_targp,
782 if (mp->m_rtdev_targp) {
783 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
784 mp->m_sb.sb_sectsize);
793 xfs_init_mount_workqueues(
794 struct xfs_mount *mp)
796 mp->m_buf_workqueue = alloc_workqueue("xfs-buf/%s",
797 WQ_MEM_RECLAIM|WQ_FREEZABLE, 1, mp->m_fsname);
798 if (!mp->m_buf_workqueue)
801 mp->m_unwritten_workqueue = alloc_workqueue("xfs-conv/%s",
802 WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_fsname);
803 if (!mp->m_unwritten_workqueue)
804 goto out_destroy_buf;
806 mp->m_cil_workqueue = alloc_workqueue("xfs-cil/%s",
807 WQ_MEM_RECLAIM | WQ_FREEZABLE | WQ_UNBOUND,
809 if (!mp->m_cil_workqueue)
810 goto out_destroy_unwritten;
812 mp->m_reclaim_workqueue = alloc_workqueue("xfs-reclaim/%s",
813 WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_fsname);
814 if (!mp->m_reclaim_workqueue)
815 goto out_destroy_cil;
817 mp->m_eofblocks_workqueue = alloc_workqueue("xfs-eofblocks/%s",
818 WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_fsname);
819 if (!mp->m_eofblocks_workqueue)
820 goto out_destroy_reclaim;
822 mp->m_sync_workqueue = alloc_workqueue("xfs-sync/%s", WQ_FREEZABLE, 0,
824 if (!mp->m_sync_workqueue)
825 goto out_destroy_eofb;
830 destroy_workqueue(mp->m_eofblocks_workqueue);
832 destroy_workqueue(mp->m_reclaim_workqueue);
834 destroy_workqueue(mp->m_cil_workqueue);
835 out_destroy_unwritten:
836 destroy_workqueue(mp->m_unwritten_workqueue);
838 destroy_workqueue(mp->m_buf_workqueue);
844 xfs_destroy_mount_workqueues(
845 struct xfs_mount *mp)
847 destroy_workqueue(mp->m_sync_workqueue);
848 destroy_workqueue(mp->m_eofblocks_workqueue);
849 destroy_workqueue(mp->m_reclaim_workqueue);
850 destroy_workqueue(mp->m_cil_workqueue);
851 destroy_workqueue(mp->m_unwritten_workqueue);
852 destroy_workqueue(mp->m_buf_workqueue);
856 * Flush all dirty data to disk. Must not be called while holding an XFS_ILOCK
857 * or a page lock. We use sync_inodes_sb() here to ensure we block while waiting
858 * for IO to complete so that we effectively throttle multiple callers to the
859 * rate at which IO is completing.
863 struct xfs_mount *mp)
865 struct super_block *sb = mp->m_super;
867 if (down_read_trylock(&sb->s_umount)) {
869 up_read(&sb->s_umount);
873 /* Catch misguided souls that try to use this interface on XFS */
874 STATIC struct inode *
876 struct super_block *sb)
885 struct xfs_inode *ip,
888 struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, whichfork);
889 struct xfs_bmbt_irec got;
890 struct xfs_iext_cursor icur;
892 if (!ifp || !xfs_iext_lookup_extent(ip, ifp, 0, &icur, &got))
895 if (isnullstartblock(got.br_startblock)) {
896 xfs_warn(ip->i_mount,
897 "ino %llx %s fork has delalloc extent at [0x%llx:0x%llx]",
899 whichfork == XFS_DATA_FORK ? "data" : "cow",
900 got.br_startoff, got.br_blockcount);
902 } while (xfs_iext_next_extent(ifp, &icur, &got));
905 #define xfs_check_delalloc(ip, whichfork) do { } while (0)
909 * Now that the generic code is guaranteed not to be accessing
910 * the linux inode, we can inactivate and reclaim the inode.
913 xfs_fs_destroy_inode(
916 struct xfs_inode *ip = XFS_I(inode);
918 trace_xfs_destroy_inode(ip);
920 ASSERT(!rwsem_is_locked(&inode->i_rwsem));
921 XFS_STATS_INC(ip->i_mount, vn_rele);
922 XFS_STATS_INC(ip->i_mount, vn_remove);
926 if (!XFS_FORCED_SHUTDOWN(ip->i_mount) && ip->i_delayed_blks) {
927 xfs_check_delalloc(ip, XFS_DATA_FORK);
928 xfs_check_delalloc(ip, XFS_COW_FORK);
932 XFS_STATS_INC(ip->i_mount, vn_reclaim);
935 * We should never get here with one of the reclaim flags already set.
937 ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIMABLE));
938 ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIM));
941 * We always use background reclaim here because even if the
942 * inode is clean, it still may be under IO and hence we have
943 * to take the flush lock. The background reclaim path handles
944 * this more efficiently than we can here, so simply let background
945 * reclaim tear down all inodes.
947 xfs_inode_set_reclaim_tag(ip);
955 struct xfs_inode *ip = XFS_I(inode);
956 struct xfs_mount *mp = ip->i_mount;
957 struct xfs_trans *tp;
959 if (!(inode->i_sb->s_flags & SB_LAZYTIME))
961 if (flag != I_DIRTY_SYNC || !(inode->i_state & I_DIRTY_TIME))
964 if (xfs_trans_alloc(mp, &M_RES(mp)->tr_fsyncts, 0, 0, 0, &tp))
966 xfs_ilock(ip, XFS_ILOCK_EXCL);
967 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
968 xfs_trans_log_inode(tp, ip, XFS_ILOG_TIMESTAMP);
969 xfs_trans_commit(tp);
973 * Slab object creation initialisation for the XFS inode.
974 * This covers only the idempotent fields in the XFS inode;
975 * all other fields need to be initialised on allocation
976 * from the slab. This avoids the need to repeatedly initialise
977 * fields in the xfs inode that left in the initialise state
978 * when freeing the inode.
981 xfs_fs_inode_init_once(
984 struct xfs_inode *ip = inode;
986 memset(ip, 0, sizeof(struct xfs_inode));
989 inode_init_once(VFS_I(ip));
992 atomic_set(&ip->i_pincount, 0);
993 spin_lock_init(&ip->i_flags_lock);
995 mrlock_init(&ip->i_mmaplock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
996 "xfsino", ip->i_ino);
997 mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
998 "xfsino", ip->i_ino);
1002 * We do an unlocked check for XFS_IDONTCACHE here because we are already
1003 * serialised against cache hits here via the inode->i_lock and igrab() in
1004 * xfs_iget_cache_hit(). Hence a lookup that might clear this flag will not be
1005 * racing with us, and it avoids needing to grab a spinlock here for every inode
1006 * we drop the final reference on.
1010 struct inode *inode)
1012 struct xfs_inode *ip = XFS_I(inode);
1015 * If this unlinked inode is in the middle of recovery, don't
1016 * drop the inode just yet; log recovery will take care of
1017 * that. See the comment for this inode flag.
1019 if (ip->i_flags & XFS_IRECOVERY) {
1020 ASSERT(ip->i_mount->m_log->l_flags & XLOG_RECOVERY_NEEDED);
1024 return generic_drop_inode(inode) || (ip->i_flags & XFS_IDONTCACHE);
1029 struct xfs_mount *mp)
1031 kfree(mp->m_fsname);
1032 kfree(mp->m_rtname);
1033 kfree(mp->m_logname);
1038 struct super_block *sb,
1041 struct xfs_mount *mp = XFS_M(sb);
1044 * Doing anything during the async pass would be counterproductive.
1049 xfs_log_force(mp, XFS_LOG_SYNC);
1052 * The disk must be active because we're syncing.
1053 * We schedule log work now (now that the disk is
1054 * active) instead of later (when it might not be).
1056 flush_delayed_work(&mp->m_log->l_work);
1064 struct dentry *dentry,
1065 struct kstatfs *statp)
1067 struct xfs_mount *mp = XFS_M(dentry->d_sb);
1068 xfs_sb_t *sbp = &mp->m_sb;
1069 struct xfs_inode *ip = XFS_I(d_inode(dentry));
1070 uint64_t fakeinos, id;
1077 statp->f_type = XFS_SUPER_MAGIC;
1078 statp->f_namelen = MAXNAMELEN - 1;
1080 id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
1081 statp->f_fsid.val[0] = (u32)id;
1082 statp->f_fsid.val[1] = (u32)(id >> 32);
1084 icount = percpu_counter_sum(&mp->m_icount);
1085 ifree = percpu_counter_sum(&mp->m_ifree);
1086 fdblocks = percpu_counter_sum(&mp->m_fdblocks);
1088 spin_lock(&mp->m_sb_lock);
1089 statp->f_bsize = sbp->sb_blocksize;
1090 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
1091 statp->f_blocks = sbp->sb_dblocks - lsize;
1092 spin_unlock(&mp->m_sb_lock);
1094 statp->f_bfree = fdblocks - mp->m_alloc_set_aside;
1095 statp->f_bavail = statp->f_bfree;
1097 fakeinos = XFS_FSB_TO_INO(mp, statp->f_bfree);
1098 statp->f_files = min(icount + fakeinos, (uint64_t)XFS_MAXINUMBER);
1099 if (M_IGEO(mp)->maxicount)
1100 statp->f_files = min_t(typeof(statp->f_files),
1102 M_IGEO(mp)->maxicount);
1104 /* If sb_icount overshot maxicount, report actual allocation */
1105 statp->f_files = max_t(typeof(statp->f_files),
1109 /* make sure statp->f_ffree does not underflow */
1110 ffree = statp->f_files - (icount - ifree);
1111 statp->f_ffree = max_t(int64_t, ffree, 0);
1114 if ((ip->i_d.di_flags & XFS_DIFLAG_PROJINHERIT) &&
1115 ((mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))) ==
1116 (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))
1117 xfs_qm_statvfs(ip, statp);
1119 if (XFS_IS_REALTIME_MOUNT(mp) &&
1120 (ip->i_d.di_flags & (XFS_DIFLAG_RTINHERIT | XFS_DIFLAG_REALTIME))) {
1121 statp->f_blocks = sbp->sb_rblocks;
1122 statp->f_bavail = statp->f_bfree =
1123 sbp->sb_frextents * sbp->sb_rextsize;
1130 xfs_save_resvblks(struct xfs_mount *mp)
1132 uint64_t resblks = 0;
1134 mp->m_resblks_save = mp->m_resblks;
1135 xfs_reserve_blocks(mp, &resblks, NULL);
1139 xfs_restore_resvblks(struct xfs_mount *mp)
1143 if (mp->m_resblks_save) {
1144 resblks = mp->m_resblks_save;
1145 mp->m_resblks_save = 0;
1147 resblks = xfs_default_resblks(mp);
1149 xfs_reserve_blocks(mp, &resblks, NULL);
1153 * Trigger writeback of all the dirty metadata in the file system.
1155 * This ensures that the metadata is written to their location on disk rather
1156 * than just existing in transactions in the log. This means after a quiesce
1157 * there is no log replay required to write the inodes to disk - this is the
1158 * primary difference between a sync and a quiesce.
1160 * Note: xfs_log_quiesce() stops background log work - the callers must ensure
1161 * it is started again when appropriate.
1165 struct xfs_mount *mp)
1169 /* wait for all modifications to complete */
1170 while (atomic_read(&mp->m_active_trans) > 0)
1173 /* force the log to unpin objects from the now complete transactions */
1174 xfs_log_force(mp, XFS_LOG_SYNC);
1176 /* reclaim inodes to do any IO before the freeze completes */
1177 xfs_reclaim_inodes(mp, 0);
1178 xfs_reclaim_inodes(mp, SYNC_WAIT);
1180 /* Push the superblock and write an unmount record */
1181 error = xfs_log_sbcount(mp);
1183 xfs_warn(mp, "xfs_attr_quiesce: failed to log sb changes. "
1184 "Frozen image may not be consistent.");
1186 * Just warn here till VFS can correctly support
1187 * read-only remount without racing.
1189 WARN_ON(atomic_read(&mp->m_active_trans) != 0);
1191 xfs_log_quiesce(mp);
1195 xfs_test_remount_options(
1196 struct super_block *sb,
1200 struct xfs_mount *tmp_mp;
1202 tmp_mp = kmem_zalloc(sizeof(*tmp_mp), KM_MAYFAIL);
1206 tmp_mp->m_super = sb;
1207 error = xfs_parseargs(tmp_mp, options);
1208 xfs_free_fsname(tmp_mp);
1216 struct super_block *sb,
1220 struct xfs_mount *mp = XFS_M(sb);
1221 xfs_sb_t *sbp = &mp->m_sb;
1222 substring_t args[MAX_OPT_ARGS];
1226 /* First, check for complete junk; i.e. invalid options */
1227 error = xfs_test_remount_options(sb, options);
1231 sync_filesystem(sb);
1232 while ((p = strsep(&options, ",")) != NULL) {
1238 token = match_token(p, tokens, args);
1241 mp->m_flags &= ~XFS_MOUNT_SMALL_INUMS;
1242 mp->m_maxagi = xfs_set_inode_alloc(mp, sbp->sb_agcount);
1245 mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
1246 mp->m_maxagi = xfs_set_inode_alloc(mp, sbp->sb_agcount);
1250 * Logically we would return an error here to prevent
1251 * users from believing they might have changed
1252 * mount options using remount which can't be changed.
1254 * But unfortunately mount(8) adds all options from
1255 * mtab and fstab to the mount arguments in some cases
1256 * so we can't blindly reject options, but have to
1257 * check for each specified option if it actually
1258 * differs from the currently set option and only
1259 * reject it if that's the case.
1261 * Until that is implemented we return success for
1262 * every remount request, and silently ignore all
1263 * options that we can't actually change.
1267 "mount option \"%s\" not supported for remount", p);
1276 if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(*flags & SB_RDONLY)) {
1277 if (mp->m_flags & XFS_MOUNT_NORECOVERY) {
1279 "ro->rw transition prohibited on norecovery mount");
1283 if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 &&
1284 xfs_sb_has_ro_compat_feature(sbp,
1285 XFS_SB_FEAT_RO_COMPAT_UNKNOWN)) {
1287 "ro->rw transition prohibited on unknown (0x%x) ro-compat filesystem",
1288 (sbp->sb_features_ro_compat &
1289 XFS_SB_FEAT_RO_COMPAT_UNKNOWN));
1293 mp->m_flags &= ~XFS_MOUNT_RDONLY;
1296 * If this is the first remount to writeable state we
1297 * might have some superblock changes to update.
1299 if (mp->m_update_sb) {
1300 error = xfs_sync_sb(mp, false);
1302 xfs_warn(mp, "failed to write sb changes");
1305 mp->m_update_sb = false;
1309 * Fill out the reserve pool if it is empty. Use the stashed
1310 * value if it is non-zero, otherwise go with the default.
1312 xfs_restore_resvblks(mp);
1313 xfs_log_work_queue(mp);
1315 /* Recover any CoW blocks that never got remapped. */
1316 error = xfs_reflink_recover_cow(mp);
1319 "Error %d recovering leftover CoW allocations.", error);
1320 xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
1323 xfs_start_block_reaping(mp);
1325 /* Create the per-AG metadata reservation pool .*/
1326 error = xfs_fs_reserve_ag_blocks(mp);
1327 if (error && error != -ENOSPC)
1332 if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (*flags & SB_RDONLY)) {
1334 * Cancel background eofb scanning so it cannot race with the
1335 * final log force+buftarg wait and deadlock the remount.
1337 xfs_stop_block_reaping(mp);
1339 /* Get rid of any leftover CoW reservations... */
1340 error = xfs_icache_free_cowblocks(mp, NULL);
1342 xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
1346 /* Free the per-AG metadata reservation pool. */
1347 error = xfs_fs_unreserve_ag_blocks(mp);
1349 xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
1354 * Before we sync the metadata, we need to free up the reserve
1355 * block pool so that the used block count in the superblock on
1356 * disk is correct at the end of the remount. Stash the current
1357 * reserve pool size so that if we get remounted rw, we can
1358 * return it to the same size.
1360 xfs_save_resvblks(mp);
1362 xfs_quiesce_attr(mp);
1363 mp->m_flags |= XFS_MOUNT_RDONLY;
1370 * Second stage of a freeze. The data is already frozen so we only
1371 * need to take care of the metadata. Once that's done sync the superblock
1372 * to the log to dirty it in case of a crash while frozen. This ensures that we
1373 * will recover the unlinked inode lists on the next mount.
1377 struct super_block *sb)
1379 struct xfs_mount *mp = XFS_M(sb);
1381 xfs_stop_block_reaping(mp);
1382 xfs_save_resvblks(mp);
1383 xfs_quiesce_attr(mp);
1384 return xfs_sync_sb(mp, true);
1389 struct super_block *sb)
1391 struct xfs_mount *mp = XFS_M(sb);
1393 xfs_restore_resvblks(mp);
1394 xfs_log_work_queue(mp);
1395 xfs_start_block_reaping(mp);
1400 xfs_fs_show_options(
1402 struct dentry *root)
1404 xfs_showargs(XFS_M(root->d_sb), m);
1409 * This function fills in xfs_mount_t fields based on mount args.
1410 * Note: the superblock _has_ now been read in.
1414 struct xfs_mount *mp)
1416 int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
1418 /* Fail a mount where the logbuf is smaller than the log stripe */
1419 if (xfs_sb_version_haslogv2(&mp->m_sb)) {
1420 if (mp->m_logbsize <= 0 &&
1421 mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE) {
1422 mp->m_logbsize = mp->m_sb.sb_logsunit;
1423 } else if (mp->m_logbsize > 0 &&
1424 mp->m_logbsize < mp->m_sb.sb_logsunit) {
1426 "logbuf size must be greater than or equal to log stripe size");
1430 /* Fail a mount if the logbuf is larger than 32K */
1431 if (mp->m_logbsize > XLOG_BIG_RECORD_BSIZE) {
1433 "logbuf size for version 1 logs must be 16K or 32K");
1439 * V5 filesystems always use attr2 format for attributes.
1441 if (xfs_sb_version_hascrc(&mp->m_sb) &&
1442 (mp->m_flags & XFS_MOUNT_NOATTR2)) {
1443 xfs_warn(mp, "Cannot mount a V5 filesystem as noattr2. "
1444 "attr2 is always enabled for V5 filesystems.");
1449 * mkfs'ed attr2 will turn on attr2 mount unless explicitly
1450 * told by noattr2 to turn it off
1452 if (xfs_sb_version_hasattr2(&mp->m_sb) &&
1453 !(mp->m_flags & XFS_MOUNT_NOATTR2))
1454 mp->m_flags |= XFS_MOUNT_ATTR2;
1457 * prohibit r/w mounts of read-only filesystems
1459 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
1461 "cannot mount a read-only filesystem as read-write");
1465 if ((mp->m_qflags & (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE)) &&
1466 (mp->m_qflags & (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE)) &&
1467 !xfs_sb_version_has_pquotino(&mp->m_sb)) {
1469 "Super block does not support project and group quota together");
1477 xfs_init_percpu_counters(
1478 struct xfs_mount *mp)
1482 error = percpu_counter_init(&mp->m_icount, 0, GFP_KERNEL);
1486 error = percpu_counter_init(&mp->m_ifree, 0, GFP_KERNEL);
1490 error = percpu_counter_init(&mp->m_fdblocks, 0, GFP_KERNEL);
1494 error = percpu_counter_init(&mp->m_delalloc_blks, 0, GFP_KERNEL);
1501 percpu_counter_destroy(&mp->m_fdblocks);
1503 percpu_counter_destroy(&mp->m_ifree);
1505 percpu_counter_destroy(&mp->m_icount);
1510 xfs_reinit_percpu_counters(
1511 struct xfs_mount *mp)
1513 percpu_counter_set(&mp->m_icount, mp->m_sb.sb_icount);
1514 percpu_counter_set(&mp->m_ifree, mp->m_sb.sb_ifree);
1515 percpu_counter_set(&mp->m_fdblocks, mp->m_sb.sb_fdblocks);
1519 xfs_destroy_percpu_counters(
1520 struct xfs_mount *mp)
1522 percpu_counter_destroy(&mp->m_icount);
1523 percpu_counter_destroy(&mp->m_ifree);
1524 percpu_counter_destroy(&mp->m_fdblocks);
1525 ASSERT(XFS_FORCED_SHUTDOWN(mp) ||
1526 percpu_counter_sum(&mp->m_delalloc_blks) == 0);
1527 percpu_counter_destroy(&mp->m_delalloc_blks);
1530 static struct xfs_mount *
1532 struct super_block *sb)
1534 struct xfs_mount *mp;
1536 mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
1541 spin_lock_init(&mp->m_sb_lock);
1542 spin_lock_init(&mp->m_agirotor_lock);
1543 INIT_RADIX_TREE(&mp->m_perag_tree, GFP_ATOMIC);
1544 spin_lock_init(&mp->m_perag_lock);
1545 mutex_init(&mp->m_growlock);
1546 atomic_set(&mp->m_active_trans, 0);
1547 INIT_DELAYED_WORK(&mp->m_reclaim_work, xfs_reclaim_worker);
1548 INIT_DELAYED_WORK(&mp->m_eofblocks_work, xfs_eofblocks_worker);
1549 INIT_DELAYED_WORK(&mp->m_cowblocks_work, xfs_cowblocks_worker);
1550 mp->m_kobj.kobject.kset = xfs_kset;
1552 * We don't create the finobt per-ag space reservation until after log
1553 * recovery, so we must set this to true so that an ifree transaction
1554 * started during log recovery will not depend on space reservations
1555 * for finobt expansion.
1557 mp->m_finobt_nores = true;
1564 struct super_block *sb,
1569 struct xfs_mount *mp = NULL;
1570 int flags = 0, error = -ENOMEM;
1573 * allocate mp and do all low-level struct initializations before we
1574 * attach it to the super
1576 mp = xfs_mount_alloc(sb);
1581 error = xfs_parseargs(mp, (char *)data);
1583 goto out_free_fsname;
1585 sb_min_blocksize(sb, BBSIZE);
1586 sb->s_xattr = xfs_xattr_handlers;
1587 sb->s_export_op = &xfs_export_operations;
1588 #ifdef CONFIG_XFS_QUOTA
1589 sb->s_qcop = &xfs_quotactl_operations;
1590 sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ;
1592 sb->s_op = &xfs_super_operations;
1595 * Delay mount work if the debug hook is set. This is debug
1596 * instrumention to coordinate simulation of xfs mount failures with
1597 * VFS superblock operations
1599 if (xfs_globals.mount_delay) {
1600 xfs_notice(mp, "Delaying mount for %d seconds.",
1601 xfs_globals.mount_delay);
1602 msleep(xfs_globals.mount_delay * 1000);
1606 flags |= XFS_MFSI_QUIET;
1608 error = xfs_open_devices(mp);
1610 goto out_free_fsname;
1612 error = xfs_init_mount_workqueues(mp);
1614 goto out_close_devices;
1616 error = xfs_init_percpu_counters(mp);
1618 goto out_destroy_workqueues;
1620 /* Allocate stats memory before we do operations that might use it */
1621 mp->m_stats.xs_stats = alloc_percpu(struct xfsstats);
1622 if (!mp->m_stats.xs_stats) {
1624 goto out_destroy_counters;
1627 error = xfs_readsb(mp, flags);
1629 goto out_free_stats;
1631 error = xfs_finish_flags(mp);
1635 error = xfs_setup_devices(mp);
1639 error = xfs_filestream_mount(mp);
1644 * we must configure the block size in the superblock before we run the
1645 * full mount process as the mount process can lookup and cache inodes.
1647 sb->s_magic = XFS_SUPER_MAGIC;
1648 sb->s_blocksize = mp->m_sb.sb_blocksize;
1649 sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
1650 sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
1651 sb->s_max_links = XFS_MAXLINK;
1652 sb->s_time_gran = 1;
1653 sb->s_time_min = S32_MIN;
1654 sb->s_time_max = S32_MAX;
1655 sb->s_iflags |= SB_I_CGROUPWB;
1657 set_posix_acl_flag(sb);
1659 /* version 5 superblocks support inode version counters. */
1660 if (XFS_SB_VERSION_NUM(&mp->m_sb) == XFS_SB_VERSION_5)
1661 sb->s_flags |= SB_I_VERSION;
1663 if (mp->m_flags & XFS_MOUNT_DAX) {
1664 bool rtdev_is_dax = false, datadev_is_dax;
1667 "DAX enabled. Warning: EXPERIMENTAL, use at your own risk");
1669 datadev_is_dax = bdev_dax_supported(mp->m_ddev_targp->bt_bdev,
1671 if (mp->m_rtdev_targp)
1672 rtdev_is_dax = bdev_dax_supported(
1673 mp->m_rtdev_targp->bt_bdev, sb->s_blocksize);
1674 if (!rtdev_is_dax && !datadev_is_dax) {
1676 "DAX unsupported by block device. Turning off DAX.");
1677 mp->m_flags &= ~XFS_MOUNT_DAX;
1679 if (xfs_sb_version_hasreflink(&mp->m_sb)) {
1681 "DAX and reflink cannot be used together!");
1683 goto out_filestream_unmount;
1687 if (mp->m_flags & XFS_MOUNT_DISCARD) {
1688 struct request_queue *q = bdev_get_queue(sb->s_bdev);
1690 if (!blk_queue_discard(q)) {
1691 xfs_warn(mp, "mounting with \"discard\" option, but "
1692 "the device does not support discard");
1693 mp->m_flags &= ~XFS_MOUNT_DISCARD;
1697 if (xfs_sb_version_hasreflink(&mp->m_sb)) {
1698 if (mp->m_sb.sb_rblocks) {
1700 "reflink not compatible with realtime device!");
1702 goto out_filestream_unmount;
1705 if (xfs_globals.always_cow) {
1706 xfs_info(mp, "using DEBUG-only always_cow mode.");
1707 mp->m_always_cow = true;
1711 if (xfs_sb_version_hasrmapbt(&mp->m_sb) && mp->m_sb.sb_rblocks) {
1713 "reverse mapping btree not compatible with realtime device!");
1715 goto out_filestream_unmount;
1718 error = xfs_mountfs(mp);
1720 goto out_filestream_unmount;
1722 root = igrab(VFS_I(mp->m_rootip));
1727 sb->s_root = d_make_root(root);
1735 out_filestream_unmount:
1736 xfs_filestream_unmount(mp);
1740 free_percpu(mp->m_stats.xs_stats);
1741 out_destroy_counters:
1742 xfs_destroy_percpu_counters(mp);
1743 out_destroy_workqueues:
1744 xfs_destroy_mount_workqueues(mp);
1746 xfs_close_devices(mp);
1748 sb->s_fs_info = NULL;
1749 xfs_free_fsname(mp);
1755 xfs_filestream_unmount(mp);
1762 struct super_block *sb)
1764 struct xfs_mount *mp = XFS_M(sb);
1766 /* if ->fill_super failed, we have no mount to tear down */
1770 xfs_notice(mp, "Unmounting Filesystem");
1771 xfs_filestream_unmount(mp);
1775 free_percpu(mp->m_stats.xs_stats);
1776 xfs_destroy_percpu_counters(mp);
1777 xfs_destroy_mount_workqueues(mp);
1778 xfs_close_devices(mp);
1780 sb->s_fs_info = NULL;
1781 xfs_free_fsname(mp);
1785 STATIC struct dentry *
1787 struct file_system_type *fs_type,
1789 const char *dev_name,
1792 return mount_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super);
1796 xfs_fs_nr_cached_objects(
1797 struct super_block *sb,
1798 struct shrink_control *sc)
1800 /* Paranoia: catch incorrect calls during mount setup or teardown */
1801 if (WARN_ON_ONCE(!sb->s_fs_info))
1803 return xfs_reclaim_inodes_count(XFS_M(sb));
1807 xfs_fs_free_cached_objects(
1808 struct super_block *sb,
1809 struct shrink_control *sc)
1811 return xfs_reclaim_inodes_nr(XFS_M(sb), sc->nr_to_scan);
1814 static const struct super_operations xfs_super_operations = {
1815 .alloc_inode = xfs_fs_alloc_inode,
1816 .destroy_inode = xfs_fs_destroy_inode,
1817 .dirty_inode = xfs_fs_dirty_inode,
1818 .drop_inode = xfs_fs_drop_inode,
1819 .put_super = xfs_fs_put_super,
1820 .sync_fs = xfs_fs_sync_fs,
1821 .freeze_fs = xfs_fs_freeze,
1822 .unfreeze_fs = xfs_fs_unfreeze,
1823 .statfs = xfs_fs_statfs,
1824 .remount_fs = xfs_fs_remount,
1825 .show_options = xfs_fs_show_options,
1826 .nr_cached_objects = xfs_fs_nr_cached_objects,
1827 .free_cached_objects = xfs_fs_free_cached_objects,
1830 static struct file_system_type xfs_fs_type = {
1831 .owner = THIS_MODULE,
1833 .mount = xfs_fs_mount,
1834 .kill_sb = kill_block_super,
1835 .fs_flags = FS_REQUIRES_DEV,
1837 MODULE_ALIAS_FS("xfs");
1840 xfs_init_zones(void)
1842 xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t),
1844 if (!xfs_log_ticket_zone)
1847 xfs_bmap_free_item_zone = kmem_zone_init(
1848 sizeof(struct xfs_extent_free_item),
1849 "xfs_bmap_free_item");
1850 if (!xfs_bmap_free_item_zone)
1851 goto out_destroy_log_ticket_zone;
1853 xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
1855 if (!xfs_btree_cur_zone)
1856 goto out_destroy_bmap_free_item_zone;
1858 xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t),
1860 if (!xfs_da_state_zone)
1861 goto out_destroy_btree_cur_zone;
1863 xfs_ifork_zone = kmem_zone_init(sizeof(struct xfs_ifork), "xfs_ifork");
1864 if (!xfs_ifork_zone)
1865 goto out_destroy_da_state_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;
1873 * The size of the zone allocated buf log item is the maximum
1874 * size possible under XFS. This wastes a little bit of memory,
1875 * but it is much faster.
1877 xfs_buf_item_zone = kmem_zone_init(sizeof(struct xfs_buf_log_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 KM_ZONE_ACCOUNT, 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;
1906 xfs_icreate_zone = kmem_zone_init(sizeof(struct xfs_icreate_item),
1908 if (!xfs_icreate_zone)
1909 goto out_destroy_ili_zone;
1911 xfs_rud_zone = kmem_zone_init(sizeof(struct xfs_rud_log_item),
1914 goto out_destroy_icreate_zone;
1916 xfs_rui_zone = kmem_zone_init(
1917 xfs_rui_log_item_sizeof(XFS_RUI_MAX_FAST_EXTENTS),
1920 goto out_destroy_rud_zone;
1922 xfs_cud_zone = kmem_zone_init(sizeof(struct xfs_cud_log_item),
1925 goto out_destroy_rui_zone;
1927 xfs_cui_zone = kmem_zone_init(
1928 xfs_cui_log_item_sizeof(XFS_CUI_MAX_FAST_EXTENTS),
1931 goto out_destroy_cud_zone;
1933 xfs_bud_zone = kmem_zone_init(sizeof(struct xfs_bud_log_item),
1936 goto out_destroy_cui_zone;
1938 xfs_bui_zone = kmem_zone_init(
1939 xfs_bui_log_item_sizeof(XFS_BUI_MAX_FAST_EXTENTS),
1942 goto out_destroy_bud_zone;
1946 out_destroy_bud_zone:
1947 kmem_zone_destroy(xfs_bud_zone);
1948 out_destroy_cui_zone:
1949 kmem_zone_destroy(xfs_cui_zone);
1950 out_destroy_cud_zone:
1951 kmem_zone_destroy(xfs_cud_zone);
1952 out_destroy_rui_zone:
1953 kmem_zone_destroy(xfs_rui_zone);
1954 out_destroy_rud_zone:
1955 kmem_zone_destroy(xfs_rud_zone);
1956 out_destroy_icreate_zone:
1957 kmem_zone_destroy(xfs_icreate_zone);
1958 out_destroy_ili_zone:
1959 kmem_zone_destroy(xfs_ili_zone);
1960 out_destroy_inode_zone:
1961 kmem_zone_destroy(xfs_inode_zone);
1962 out_destroy_efi_zone:
1963 kmem_zone_destroy(xfs_efi_zone);
1964 out_destroy_efd_zone:
1965 kmem_zone_destroy(xfs_efd_zone);
1966 out_destroy_buf_item_zone:
1967 kmem_zone_destroy(xfs_buf_item_zone);
1968 out_destroy_trans_zone:
1969 kmem_zone_destroy(xfs_trans_zone);
1970 out_destroy_ifork_zone:
1971 kmem_zone_destroy(xfs_ifork_zone);
1972 out_destroy_da_state_zone:
1973 kmem_zone_destroy(xfs_da_state_zone);
1974 out_destroy_btree_cur_zone:
1975 kmem_zone_destroy(xfs_btree_cur_zone);
1976 out_destroy_bmap_free_item_zone:
1977 kmem_zone_destroy(xfs_bmap_free_item_zone);
1978 out_destroy_log_ticket_zone:
1979 kmem_zone_destroy(xfs_log_ticket_zone);
1985 xfs_destroy_zones(void)
1988 * Make sure all delayed rcu free are flushed before we
1992 kmem_zone_destroy(xfs_bui_zone);
1993 kmem_zone_destroy(xfs_bud_zone);
1994 kmem_zone_destroy(xfs_cui_zone);
1995 kmem_zone_destroy(xfs_cud_zone);
1996 kmem_zone_destroy(xfs_rui_zone);
1997 kmem_zone_destroy(xfs_rud_zone);
1998 kmem_zone_destroy(xfs_icreate_zone);
1999 kmem_zone_destroy(xfs_ili_zone);
2000 kmem_zone_destroy(xfs_inode_zone);
2001 kmem_zone_destroy(xfs_efi_zone);
2002 kmem_zone_destroy(xfs_efd_zone);
2003 kmem_zone_destroy(xfs_buf_item_zone);
2004 kmem_zone_destroy(xfs_trans_zone);
2005 kmem_zone_destroy(xfs_ifork_zone);
2006 kmem_zone_destroy(xfs_da_state_zone);
2007 kmem_zone_destroy(xfs_btree_cur_zone);
2008 kmem_zone_destroy(xfs_bmap_free_item_zone);
2009 kmem_zone_destroy(xfs_log_ticket_zone);
2013 xfs_init_workqueues(void)
2016 * The allocation workqueue can be used in memory reclaim situations
2017 * (writepage path), and parallelism is only limited by the number of
2018 * AGs in all the filesystems mounted. Hence use the default large
2019 * max_active value for this workqueue.
2021 xfs_alloc_wq = alloc_workqueue("xfsalloc",
2022 WQ_MEM_RECLAIM|WQ_FREEZABLE, 0);
2026 xfs_discard_wq = alloc_workqueue("xfsdiscard", WQ_UNBOUND, 0);
2027 if (!xfs_discard_wq)
2028 goto out_free_alloc_wq;
2032 destroy_workqueue(xfs_alloc_wq);
2037 xfs_destroy_workqueues(void)
2039 destroy_workqueue(xfs_discard_wq);
2040 destroy_workqueue(xfs_alloc_wq);
2048 xfs_check_ondisk_structs();
2050 printk(KERN_INFO XFS_VERSION_STRING " with "
2051 XFS_BUILD_OPTIONS " enabled\n");
2055 error = xfs_init_zones();
2059 error = xfs_init_workqueues();
2061 goto out_destroy_zones;
2063 error = xfs_mru_cache_init();
2065 goto out_destroy_wq;
2067 error = xfs_buf_init();
2069 goto out_mru_cache_uninit;
2071 error = xfs_init_procfs();
2073 goto out_buf_terminate;
2075 error = xfs_sysctl_register();
2077 goto out_cleanup_procfs;
2079 xfs_kset = kset_create_and_add("xfs", NULL, fs_kobj);
2082 goto out_sysctl_unregister;
2085 xfsstats.xs_kobj.kobject.kset = xfs_kset;
2087 xfsstats.xs_stats = alloc_percpu(struct xfsstats);
2088 if (!xfsstats.xs_stats) {
2090 goto out_kset_unregister;
2093 error = xfs_sysfs_init(&xfsstats.xs_kobj, &xfs_stats_ktype, NULL,
2096 goto out_free_stats;
2099 xfs_dbg_kobj.kobject.kset = xfs_kset;
2100 error = xfs_sysfs_init(&xfs_dbg_kobj, &xfs_dbg_ktype, NULL, "debug");
2102 goto out_remove_stats_kobj;
2105 error = xfs_qm_init();
2107 goto out_remove_dbg_kobj;
2109 error = register_filesystem(&xfs_fs_type);
2116 out_remove_dbg_kobj:
2118 xfs_sysfs_del(&xfs_dbg_kobj);
2119 out_remove_stats_kobj:
2121 xfs_sysfs_del(&xfsstats.xs_kobj);
2123 free_percpu(xfsstats.xs_stats);
2124 out_kset_unregister:
2125 kset_unregister(xfs_kset);
2126 out_sysctl_unregister:
2127 xfs_sysctl_unregister();
2129 xfs_cleanup_procfs();
2131 xfs_buf_terminate();
2132 out_mru_cache_uninit:
2133 xfs_mru_cache_uninit();
2135 xfs_destroy_workqueues();
2137 xfs_destroy_zones();
2146 unregister_filesystem(&xfs_fs_type);
2148 xfs_sysfs_del(&xfs_dbg_kobj);
2150 xfs_sysfs_del(&xfsstats.xs_kobj);
2151 free_percpu(xfsstats.xs_stats);
2152 kset_unregister(xfs_kset);
2153 xfs_sysctl_unregister();
2154 xfs_cleanup_procfs();
2155 xfs_buf_terminate();
2156 xfs_mru_cache_uninit();
2157 xfs_destroy_workqueues();
2158 xfs_destroy_zones();
2159 xfs_uuid_table_free();
2162 module_init(init_xfs_fs);
2163 module_exit(exit_xfs_fs);
2165 MODULE_AUTHOR("Silicon Graphics, Inc.");
2166 MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
2167 MODULE_LICENSE("GPL");