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/fs_context.h>
41 #include <linux/fs_parser.h>
43 static const struct super_operations xfs_super_operations;
45 static struct kset *xfs_kset; /* top-level xfs sysfs dir */
47 static struct xfs_kobj xfs_dbg_kobj; /* global debug sysfs attrs */
51 * Table driven mount option parser.
54 Opt_logbufs, Opt_logbsize, Opt_logdev, Opt_rtdev,
55 Opt_wsync, Opt_noalign, Opt_swalloc, Opt_sunit, Opt_swidth, Opt_nouuid,
56 Opt_grpid, Opt_nogrpid, Opt_bsdgroups, Opt_sysvgroups,
57 Opt_allocsize, Opt_norecovery, Opt_inode64, Opt_inode32, Opt_ikeep,
58 Opt_noikeep, Opt_largeio, Opt_nolargeio, Opt_attr2, Opt_noattr2,
59 Opt_filestreams, Opt_quota, Opt_noquota, Opt_usrquota, Opt_grpquota,
60 Opt_prjquota, Opt_uquota, Opt_gquota, Opt_pquota,
61 Opt_uqnoenforce, Opt_gqnoenforce, Opt_pqnoenforce, Opt_qnoenforce,
62 Opt_discard, Opt_nodiscard, Opt_dax,
65 static const struct fs_parameter_spec xfs_fs_parameters[] = {
66 fsparam_u32("logbufs", Opt_logbufs),
67 fsparam_string("logbsize", Opt_logbsize),
68 fsparam_string("logdev", Opt_logdev),
69 fsparam_string("rtdev", Opt_rtdev),
70 fsparam_flag("wsync", Opt_wsync),
71 fsparam_flag("noalign", Opt_noalign),
72 fsparam_flag("swalloc", Opt_swalloc),
73 fsparam_u32("sunit", Opt_sunit),
74 fsparam_u32("swidth", Opt_swidth),
75 fsparam_flag("nouuid", Opt_nouuid),
76 fsparam_flag("grpid", Opt_grpid),
77 fsparam_flag("nogrpid", Opt_nogrpid),
78 fsparam_flag("bsdgroups", Opt_bsdgroups),
79 fsparam_flag("sysvgroups", Opt_sysvgroups),
80 fsparam_string("allocsize", Opt_allocsize),
81 fsparam_flag("norecovery", Opt_norecovery),
82 fsparam_flag("inode64", Opt_inode64),
83 fsparam_flag("inode32", Opt_inode32),
84 fsparam_flag("ikeep", Opt_ikeep),
85 fsparam_flag("noikeep", Opt_noikeep),
86 fsparam_flag("largeio", Opt_largeio),
87 fsparam_flag("nolargeio", Opt_nolargeio),
88 fsparam_flag("attr2", Opt_attr2),
89 fsparam_flag("noattr2", Opt_noattr2),
90 fsparam_flag("filestreams", Opt_filestreams),
91 fsparam_flag("quota", Opt_quota),
92 fsparam_flag("noquota", Opt_noquota),
93 fsparam_flag("usrquota", Opt_usrquota),
94 fsparam_flag("grpquota", Opt_grpquota),
95 fsparam_flag("prjquota", Opt_prjquota),
96 fsparam_flag("uquota", Opt_uquota),
97 fsparam_flag("gquota", Opt_gquota),
98 fsparam_flag("pquota", Opt_pquota),
99 fsparam_flag("uqnoenforce", Opt_uqnoenforce),
100 fsparam_flag("gqnoenforce", Opt_gqnoenforce),
101 fsparam_flag("pqnoenforce", Opt_pqnoenforce),
102 fsparam_flag("qnoenforce", Opt_qnoenforce),
103 fsparam_flag("discard", Opt_discard),
104 fsparam_flag("nodiscard", Opt_nodiscard),
105 fsparam_flag("dax", Opt_dax),
109 struct proc_xfs_info {
119 static struct proc_xfs_info xfs_info_set[] = {
120 /* the few simple ones we can get from the mount struct */
121 { XFS_MOUNT_IKEEP, ",ikeep" },
122 { XFS_MOUNT_WSYNC, ",wsync" },
123 { XFS_MOUNT_NOALIGN, ",noalign" },
124 { XFS_MOUNT_SWALLOC, ",swalloc" },
125 { XFS_MOUNT_NOUUID, ",nouuid" },
126 { XFS_MOUNT_NORECOVERY, ",norecovery" },
127 { XFS_MOUNT_ATTR2, ",attr2" },
128 { XFS_MOUNT_FILESTREAMS, ",filestreams" },
129 { XFS_MOUNT_GRPID, ",grpid" },
130 { XFS_MOUNT_DISCARD, ",discard" },
131 { XFS_MOUNT_LARGEIO, ",largeio" },
132 { XFS_MOUNT_DAX, ",dax" },
135 struct xfs_mount *mp = XFS_M(root->d_sb);
136 struct proc_xfs_info *xfs_infop;
138 for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
139 if (mp->m_flags & xfs_infop->flag)
140 seq_puts(m, xfs_infop->str);
143 seq_printf(m, ",inode%d",
144 (mp->m_flags & XFS_MOUNT_SMALL_INUMS) ? 32 : 64);
146 if (mp->m_flags & XFS_MOUNT_ALLOCSIZE)
147 seq_printf(m, ",allocsize=%dk",
148 (1 << mp->m_allocsize_log) >> 10);
150 if (mp->m_logbufs > 0)
151 seq_printf(m, ",logbufs=%d", mp->m_logbufs);
152 if (mp->m_logbsize > 0)
153 seq_printf(m, ",logbsize=%dk", mp->m_logbsize >> 10);
156 seq_show_option(m, "logdev", mp->m_logname);
158 seq_show_option(m, "rtdev", mp->m_rtname);
160 if (mp->m_dalign > 0)
161 seq_printf(m, ",sunit=%d",
162 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
163 if (mp->m_swidth > 0)
164 seq_printf(m, ",swidth=%d",
165 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
167 if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD))
168 seq_puts(m, ",usrquota");
169 else if (mp->m_qflags & XFS_UQUOTA_ACCT)
170 seq_puts(m, ",uqnoenforce");
172 if (mp->m_qflags & XFS_PQUOTA_ACCT) {
173 if (mp->m_qflags & XFS_PQUOTA_ENFD)
174 seq_puts(m, ",prjquota");
176 seq_puts(m, ",pqnoenforce");
178 if (mp->m_qflags & XFS_GQUOTA_ACCT) {
179 if (mp->m_qflags & XFS_GQUOTA_ENFD)
180 seq_puts(m, ",grpquota");
182 seq_puts(m, ",gqnoenforce");
185 if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
186 seq_puts(m, ",noquota");
193 unsigned int blockshift)
195 unsigned int pagefactor = 1;
196 unsigned int bitshift = BITS_PER_LONG - 1;
198 /* Figure out maximum filesize, on Linux this can depend on
199 * the filesystem blocksize (on 32 bit platforms).
200 * __block_write_begin does this in an [unsigned] long long...
201 * page->index << (PAGE_SHIFT - bbits)
202 * So, for page sized blocks (4K on 32 bit platforms),
203 * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
204 * (((u64)PAGE_SIZE << (BITS_PER_LONG-1))-1)
205 * but for smaller blocksizes it is less (bbits = log2 bsize).
208 #if BITS_PER_LONG == 32
209 ASSERT(sizeof(sector_t) == 8);
210 pagefactor = PAGE_SIZE;
211 bitshift = BITS_PER_LONG;
214 return (((uint64_t)pagefactor) << bitshift) - 1;
218 * Set parameters for inode allocation heuristics, taking into account
219 * filesystem size and inode32/inode64 mount options; i.e. specifically
220 * whether or not XFS_MOUNT_SMALL_INUMS is set.
222 * Inode allocation patterns are altered only if inode32 is requested
223 * (XFS_MOUNT_SMALL_INUMS), and the filesystem is sufficiently large.
224 * If altered, XFS_MOUNT_32BITINODES is set as well.
226 * An agcount independent of that in the mount structure is provided
227 * because in the growfs case, mp->m_sb.sb_agcount is not yet updated
228 * to the potentially higher ag count.
230 * Returns the maximum AG index which may contain inodes.
234 struct xfs_mount *mp,
235 xfs_agnumber_t agcount)
237 xfs_agnumber_t index;
238 xfs_agnumber_t maxagi = 0;
239 xfs_sb_t *sbp = &mp->m_sb;
240 xfs_agnumber_t max_metadata;
245 * Calculate how much should be reserved for inodes to meet
246 * the max inode percentage. Used only for inode32.
248 if (M_IGEO(mp)->maxicount) {
251 icount = sbp->sb_dblocks * sbp->sb_imax_pct;
253 icount += sbp->sb_agblocks - 1;
254 do_div(icount, sbp->sb_agblocks);
255 max_metadata = icount;
257 max_metadata = agcount;
260 /* Get the last possible inode in the filesystem */
261 agino = XFS_AGB_TO_AGINO(mp, sbp->sb_agblocks - 1);
262 ino = XFS_AGINO_TO_INO(mp, agcount - 1, agino);
265 * If user asked for no more than 32-bit inodes, and the fs is
266 * sufficiently large, set XFS_MOUNT_32BITINODES if we must alter
267 * the allocator to accommodate the request.
269 if ((mp->m_flags & XFS_MOUNT_SMALL_INUMS) && ino > XFS_MAXINUMBER_32)
270 mp->m_flags |= XFS_MOUNT_32BITINODES;
272 mp->m_flags &= ~XFS_MOUNT_32BITINODES;
274 for (index = 0; index < agcount; index++) {
275 struct xfs_perag *pag;
277 ino = XFS_AGINO_TO_INO(mp, index, agino);
279 pag = xfs_perag_get(mp, index);
281 if (mp->m_flags & XFS_MOUNT_32BITINODES) {
282 if (ino > XFS_MAXINUMBER_32) {
283 pag->pagi_inodeok = 0;
284 pag->pagf_metadata = 0;
286 pag->pagi_inodeok = 1;
288 if (index < max_metadata)
289 pag->pagf_metadata = 1;
291 pag->pagf_metadata = 0;
294 pag->pagi_inodeok = 1;
295 pag->pagf_metadata = 0;
301 return (mp->m_flags & XFS_MOUNT_32BITINODES) ? maxagi : agcount;
308 struct block_device **bdevp)
312 *bdevp = blkdev_get_by_path(name, FMODE_READ|FMODE_WRITE|FMODE_EXCL,
314 if (IS_ERR(*bdevp)) {
315 error = PTR_ERR(*bdevp);
316 xfs_warn(mp, "Invalid device [%s], error=%d", name, error);
324 struct block_device *bdev)
327 blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
331 xfs_blkdev_issue_flush(
332 xfs_buftarg_t *buftarg)
334 blkdev_issue_flush(buftarg->bt_bdev, GFP_NOFS, NULL);
339 struct xfs_mount *mp)
341 struct dax_device *dax_ddev = mp->m_ddev_targp->bt_daxdev;
343 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
344 struct block_device *logdev = mp->m_logdev_targp->bt_bdev;
345 struct dax_device *dax_logdev = mp->m_logdev_targp->bt_daxdev;
347 xfs_free_buftarg(mp->m_logdev_targp);
348 xfs_blkdev_put(logdev);
349 fs_put_dax(dax_logdev);
351 if (mp->m_rtdev_targp) {
352 struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev;
353 struct dax_device *dax_rtdev = mp->m_rtdev_targp->bt_daxdev;
355 xfs_free_buftarg(mp->m_rtdev_targp);
356 xfs_blkdev_put(rtdev);
357 fs_put_dax(dax_rtdev);
359 xfs_free_buftarg(mp->m_ddev_targp);
360 fs_put_dax(dax_ddev);
364 * The file system configurations are:
365 * (1) device (partition) with data and internal log
366 * (2) logical volume with data and log subvolumes.
367 * (3) logical volume with data, log, and realtime subvolumes.
369 * We only have to handle opening the log and realtime volumes here if
370 * they are present. The data subvolume has already been opened by
371 * get_sb_bdev() and is stored in sb->s_bdev.
375 struct xfs_mount *mp)
377 struct block_device *ddev = mp->m_super->s_bdev;
378 struct dax_device *dax_ddev = fs_dax_get_by_bdev(ddev);
379 struct dax_device *dax_logdev = NULL, *dax_rtdev = NULL;
380 struct block_device *logdev = NULL, *rtdev = NULL;
384 * Open real time and log devices - order is important.
387 error = xfs_blkdev_get(mp, mp->m_logname, &logdev);
390 dax_logdev = fs_dax_get_by_bdev(logdev);
394 error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev);
396 goto out_close_logdev;
398 if (rtdev == ddev || rtdev == logdev) {
400 "Cannot mount filesystem with identical rtdev and ddev/logdev.");
402 goto out_close_rtdev;
404 dax_rtdev = fs_dax_get_by_bdev(rtdev);
408 * Setup xfs_mount buffer target pointers
411 mp->m_ddev_targp = xfs_alloc_buftarg(mp, ddev, dax_ddev);
412 if (!mp->m_ddev_targp)
413 goto out_close_rtdev;
416 mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev, dax_rtdev);
417 if (!mp->m_rtdev_targp)
418 goto out_free_ddev_targ;
421 if (logdev && logdev != ddev) {
422 mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev, dax_logdev);
423 if (!mp->m_logdev_targp)
424 goto out_free_rtdev_targ;
426 mp->m_logdev_targp = mp->m_ddev_targp;
432 if (mp->m_rtdev_targp)
433 xfs_free_buftarg(mp->m_rtdev_targp);
435 xfs_free_buftarg(mp->m_ddev_targp);
437 xfs_blkdev_put(rtdev);
438 fs_put_dax(dax_rtdev);
440 if (logdev && logdev != ddev) {
441 xfs_blkdev_put(logdev);
442 fs_put_dax(dax_logdev);
445 fs_put_dax(dax_ddev);
450 * Setup xfs_mount buffer target pointers based on superblock
454 struct xfs_mount *mp)
458 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_sectsize);
462 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
463 unsigned int log_sector_size = BBSIZE;
465 if (xfs_sb_version_hassector(&mp->m_sb))
466 log_sector_size = mp->m_sb.sb_logsectsize;
467 error = xfs_setsize_buftarg(mp->m_logdev_targp,
472 if (mp->m_rtdev_targp) {
473 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
474 mp->m_sb.sb_sectsize);
483 xfs_init_mount_workqueues(
484 struct xfs_mount *mp)
486 mp->m_buf_workqueue = alloc_workqueue("xfs-buf/%s",
487 WQ_MEM_RECLAIM|WQ_FREEZABLE, 1, mp->m_super->s_id);
488 if (!mp->m_buf_workqueue)
491 mp->m_unwritten_workqueue = alloc_workqueue("xfs-conv/%s",
492 WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_super->s_id);
493 if (!mp->m_unwritten_workqueue)
494 goto out_destroy_buf;
496 mp->m_cil_workqueue = alloc_workqueue("xfs-cil/%s",
497 WQ_MEM_RECLAIM | WQ_FREEZABLE | WQ_UNBOUND,
498 0, mp->m_super->s_id);
499 if (!mp->m_cil_workqueue)
500 goto out_destroy_unwritten;
502 mp->m_reclaim_workqueue = alloc_workqueue("xfs-reclaim/%s",
503 WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_super->s_id);
504 if (!mp->m_reclaim_workqueue)
505 goto out_destroy_cil;
507 mp->m_eofblocks_workqueue = alloc_workqueue("xfs-eofblocks/%s",
508 WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_super->s_id);
509 if (!mp->m_eofblocks_workqueue)
510 goto out_destroy_reclaim;
512 mp->m_sync_workqueue = alloc_workqueue("xfs-sync/%s", WQ_FREEZABLE, 0,
514 if (!mp->m_sync_workqueue)
515 goto out_destroy_eofb;
520 destroy_workqueue(mp->m_eofblocks_workqueue);
522 destroy_workqueue(mp->m_reclaim_workqueue);
524 destroy_workqueue(mp->m_cil_workqueue);
525 out_destroy_unwritten:
526 destroy_workqueue(mp->m_unwritten_workqueue);
528 destroy_workqueue(mp->m_buf_workqueue);
534 xfs_destroy_mount_workqueues(
535 struct xfs_mount *mp)
537 destroy_workqueue(mp->m_sync_workqueue);
538 destroy_workqueue(mp->m_eofblocks_workqueue);
539 destroy_workqueue(mp->m_reclaim_workqueue);
540 destroy_workqueue(mp->m_cil_workqueue);
541 destroy_workqueue(mp->m_unwritten_workqueue);
542 destroy_workqueue(mp->m_buf_workqueue);
546 * Flush all dirty data to disk. Must not be called while holding an XFS_ILOCK
547 * or a page lock. We use sync_inodes_sb() here to ensure we block while waiting
548 * for IO to complete so that we effectively throttle multiple callers to the
549 * rate at which IO is completing.
553 struct xfs_mount *mp)
555 struct super_block *sb = mp->m_super;
557 if (down_read_trylock(&sb->s_umount)) {
559 up_read(&sb->s_umount);
563 /* Catch misguided souls that try to use this interface on XFS */
564 STATIC struct inode *
566 struct super_block *sb)
575 struct xfs_inode *ip,
578 struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, whichfork);
579 struct xfs_bmbt_irec got;
580 struct xfs_iext_cursor icur;
582 if (!ifp || !xfs_iext_lookup_extent(ip, ifp, 0, &icur, &got))
585 if (isnullstartblock(got.br_startblock)) {
586 xfs_warn(ip->i_mount,
587 "ino %llx %s fork has delalloc extent at [0x%llx:0x%llx]",
589 whichfork == XFS_DATA_FORK ? "data" : "cow",
590 got.br_startoff, got.br_blockcount);
592 } while (xfs_iext_next_extent(ifp, &icur, &got));
595 #define xfs_check_delalloc(ip, whichfork) do { } while (0)
599 * Now that the generic code is guaranteed not to be accessing
600 * the linux inode, we can inactivate and reclaim the inode.
603 xfs_fs_destroy_inode(
606 struct xfs_inode *ip = XFS_I(inode);
608 trace_xfs_destroy_inode(ip);
610 ASSERT(!rwsem_is_locked(&inode->i_rwsem));
611 XFS_STATS_INC(ip->i_mount, vn_rele);
612 XFS_STATS_INC(ip->i_mount, vn_remove);
616 if (!XFS_FORCED_SHUTDOWN(ip->i_mount) && ip->i_delayed_blks) {
617 xfs_check_delalloc(ip, XFS_DATA_FORK);
618 xfs_check_delalloc(ip, XFS_COW_FORK);
622 XFS_STATS_INC(ip->i_mount, vn_reclaim);
625 * We should never get here with one of the reclaim flags already set.
627 ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIMABLE));
628 ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIM));
631 * We always use background reclaim here because even if the
632 * inode is clean, it still may be under IO and hence we have
633 * to take the flush lock. The background reclaim path handles
634 * this more efficiently than we can here, so simply let background
635 * reclaim tear down all inodes.
637 xfs_inode_set_reclaim_tag(ip);
645 struct xfs_inode *ip = XFS_I(inode);
646 struct xfs_mount *mp = ip->i_mount;
647 struct xfs_trans *tp;
649 if (!(inode->i_sb->s_flags & SB_LAZYTIME))
651 if (flag != I_DIRTY_SYNC || !(inode->i_state & I_DIRTY_TIME))
654 if (xfs_trans_alloc(mp, &M_RES(mp)->tr_fsyncts, 0, 0, 0, &tp))
656 xfs_ilock(ip, XFS_ILOCK_EXCL);
657 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
658 xfs_trans_log_inode(tp, ip, XFS_ILOG_TIMESTAMP);
659 xfs_trans_commit(tp);
663 * Slab object creation initialisation for the XFS inode.
664 * This covers only the idempotent fields in the XFS inode;
665 * all other fields need to be initialised on allocation
666 * from the slab. This avoids the need to repeatedly initialise
667 * fields in the xfs inode that left in the initialise state
668 * when freeing the inode.
671 xfs_fs_inode_init_once(
674 struct xfs_inode *ip = inode;
676 memset(ip, 0, sizeof(struct xfs_inode));
679 inode_init_once(VFS_I(ip));
682 atomic_set(&ip->i_pincount, 0);
683 spin_lock_init(&ip->i_flags_lock);
685 mrlock_init(&ip->i_mmaplock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
686 "xfsino", ip->i_ino);
687 mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
688 "xfsino", ip->i_ino);
692 * We do an unlocked check for XFS_IDONTCACHE here because we are already
693 * serialised against cache hits here via the inode->i_lock and igrab() in
694 * xfs_iget_cache_hit(). Hence a lookup that might clear this flag will not be
695 * racing with us, and it avoids needing to grab a spinlock here for every inode
696 * we drop the final reference on.
702 struct xfs_inode *ip = XFS_I(inode);
705 * If this unlinked inode is in the middle of recovery, don't
706 * drop the inode just yet; log recovery will take care of
707 * that. See the comment for this inode flag.
709 if (ip->i_flags & XFS_IRECOVERY) {
710 ASSERT(ip->i_mount->m_log->l_flags & XLOG_RECOVERY_NEEDED);
714 return generic_drop_inode(inode) || (ip->i_flags & XFS_IDONTCACHE);
719 struct xfs_mount *mp)
722 kfree(mp->m_logname);
728 struct super_block *sb,
731 struct xfs_mount *mp = XFS_M(sb);
734 * Doing anything during the async pass would be counterproductive.
739 xfs_log_force(mp, XFS_LOG_SYNC);
742 * The disk must be active because we're syncing.
743 * We schedule log work now (now that the disk is
744 * active) instead of later (when it might not be).
746 flush_delayed_work(&mp->m_log->l_work);
754 struct dentry *dentry,
755 struct kstatfs *statp)
757 struct xfs_mount *mp = XFS_M(dentry->d_sb);
758 xfs_sb_t *sbp = &mp->m_sb;
759 struct xfs_inode *ip = XFS_I(d_inode(dentry));
760 uint64_t fakeinos, id;
767 statp->f_type = XFS_SUPER_MAGIC;
768 statp->f_namelen = MAXNAMELEN - 1;
770 id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
771 statp->f_fsid.val[0] = (u32)id;
772 statp->f_fsid.val[1] = (u32)(id >> 32);
774 icount = percpu_counter_sum(&mp->m_icount);
775 ifree = percpu_counter_sum(&mp->m_ifree);
776 fdblocks = percpu_counter_sum(&mp->m_fdblocks);
778 spin_lock(&mp->m_sb_lock);
779 statp->f_bsize = sbp->sb_blocksize;
780 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
781 statp->f_blocks = sbp->sb_dblocks - lsize;
782 spin_unlock(&mp->m_sb_lock);
784 statp->f_bfree = fdblocks - mp->m_alloc_set_aside;
785 statp->f_bavail = statp->f_bfree;
787 fakeinos = XFS_FSB_TO_INO(mp, statp->f_bfree);
788 statp->f_files = min(icount + fakeinos, (uint64_t)XFS_MAXINUMBER);
789 if (M_IGEO(mp)->maxicount)
790 statp->f_files = min_t(typeof(statp->f_files),
792 M_IGEO(mp)->maxicount);
794 /* If sb_icount overshot maxicount, report actual allocation */
795 statp->f_files = max_t(typeof(statp->f_files),
799 /* make sure statp->f_ffree does not underflow */
800 ffree = statp->f_files - (icount - ifree);
801 statp->f_ffree = max_t(int64_t, ffree, 0);
804 if ((ip->i_d.di_flags & XFS_DIFLAG_PROJINHERIT) &&
805 ((mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))) ==
806 (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))
807 xfs_qm_statvfs(ip, statp);
809 if (XFS_IS_REALTIME_MOUNT(mp) &&
810 (ip->i_d.di_flags & (XFS_DIFLAG_RTINHERIT | XFS_DIFLAG_REALTIME))) {
811 statp->f_blocks = sbp->sb_rblocks;
812 statp->f_bavail = statp->f_bfree =
813 sbp->sb_frextents * sbp->sb_rextsize;
820 xfs_save_resvblks(struct xfs_mount *mp)
822 uint64_t resblks = 0;
824 mp->m_resblks_save = mp->m_resblks;
825 xfs_reserve_blocks(mp, &resblks, NULL);
829 xfs_restore_resvblks(struct xfs_mount *mp)
833 if (mp->m_resblks_save) {
834 resblks = mp->m_resblks_save;
835 mp->m_resblks_save = 0;
837 resblks = xfs_default_resblks(mp);
839 xfs_reserve_blocks(mp, &resblks, NULL);
843 * Trigger writeback of all the dirty metadata in the file system.
845 * This ensures that the metadata is written to their location on disk rather
846 * than just existing in transactions in the log. This means after a quiesce
847 * there is no log replay required to write the inodes to disk - this is the
848 * primary difference between a sync and a quiesce.
850 * Note: xfs_log_quiesce() stops background log work - the callers must ensure
851 * it is started again when appropriate.
855 struct xfs_mount *mp)
859 /* wait for all modifications to complete */
860 while (atomic_read(&mp->m_active_trans) > 0)
863 /* force the log to unpin objects from the now complete transactions */
864 xfs_log_force(mp, XFS_LOG_SYNC);
866 /* reclaim inodes to do any IO before the freeze completes */
867 xfs_reclaim_inodes(mp, 0);
868 xfs_reclaim_inodes(mp, SYNC_WAIT);
870 /* Push the superblock and write an unmount record */
871 error = xfs_log_sbcount(mp);
873 xfs_warn(mp, "xfs_attr_quiesce: failed to log sb changes. "
874 "Frozen image may not be consistent.");
876 * Just warn here till VFS can correctly support
877 * read-only remount without racing.
879 WARN_ON(atomic_read(&mp->m_active_trans) != 0);
885 * Second stage of a freeze. The data is already frozen so we only
886 * need to take care of the metadata. Once that's done sync the superblock
887 * to the log to dirty it in case of a crash while frozen. This ensures that we
888 * will recover the unlinked inode lists on the next mount.
892 struct super_block *sb)
894 struct xfs_mount *mp = XFS_M(sb);
896 xfs_stop_block_reaping(mp);
897 xfs_save_resvblks(mp);
898 xfs_quiesce_attr(mp);
899 return xfs_sync_sb(mp, true);
904 struct super_block *sb)
906 struct xfs_mount *mp = XFS_M(sb);
908 xfs_restore_resvblks(mp);
909 xfs_log_work_queue(mp);
910 xfs_start_block_reaping(mp);
915 * This function fills in xfs_mount_t fields based on mount args.
916 * Note: the superblock _has_ now been read in.
920 struct xfs_mount *mp)
922 int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
924 /* Fail a mount where the logbuf is smaller than the log stripe */
925 if (xfs_sb_version_haslogv2(&mp->m_sb)) {
926 if (mp->m_logbsize <= 0 &&
927 mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE) {
928 mp->m_logbsize = mp->m_sb.sb_logsunit;
929 } else if (mp->m_logbsize > 0 &&
930 mp->m_logbsize < mp->m_sb.sb_logsunit) {
932 "logbuf size must be greater than or equal to log stripe size");
936 /* Fail a mount if the logbuf is larger than 32K */
937 if (mp->m_logbsize > XLOG_BIG_RECORD_BSIZE) {
939 "logbuf size for version 1 logs must be 16K or 32K");
945 * V5 filesystems always use attr2 format for attributes.
947 if (xfs_sb_version_hascrc(&mp->m_sb) &&
948 (mp->m_flags & XFS_MOUNT_NOATTR2)) {
949 xfs_warn(mp, "Cannot mount a V5 filesystem as noattr2. "
950 "attr2 is always enabled for V5 filesystems.");
955 * mkfs'ed attr2 will turn on attr2 mount unless explicitly
956 * told by noattr2 to turn it off
958 if (xfs_sb_version_hasattr2(&mp->m_sb) &&
959 !(mp->m_flags & XFS_MOUNT_NOATTR2))
960 mp->m_flags |= XFS_MOUNT_ATTR2;
963 * prohibit r/w mounts of read-only filesystems
965 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
967 "cannot mount a read-only filesystem as read-write");
971 if ((mp->m_qflags & (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE)) &&
972 (mp->m_qflags & (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE)) &&
973 !xfs_sb_version_has_pquotino(&mp->m_sb)) {
975 "Super block does not support project and group quota together");
983 xfs_init_percpu_counters(
984 struct xfs_mount *mp)
988 error = percpu_counter_init(&mp->m_icount, 0, GFP_KERNEL);
992 error = percpu_counter_init(&mp->m_ifree, 0, GFP_KERNEL);
996 error = percpu_counter_init(&mp->m_fdblocks, 0, GFP_KERNEL);
1000 error = percpu_counter_init(&mp->m_delalloc_blks, 0, GFP_KERNEL);
1007 percpu_counter_destroy(&mp->m_fdblocks);
1009 percpu_counter_destroy(&mp->m_ifree);
1011 percpu_counter_destroy(&mp->m_icount);
1016 xfs_reinit_percpu_counters(
1017 struct xfs_mount *mp)
1019 percpu_counter_set(&mp->m_icount, mp->m_sb.sb_icount);
1020 percpu_counter_set(&mp->m_ifree, mp->m_sb.sb_ifree);
1021 percpu_counter_set(&mp->m_fdblocks, mp->m_sb.sb_fdblocks);
1025 xfs_destroy_percpu_counters(
1026 struct xfs_mount *mp)
1028 percpu_counter_destroy(&mp->m_icount);
1029 percpu_counter_destroy(&mp->m_ifree);
1030 percpu_counter_destroy(&mp->m_fdblocks);
1031 ASSERT(XFS_FORCED_SHUTDOWN(mp) ||
1032 percpu_counter_sum(&mp->m_delalloc_blks) == 0);
1033 percpu_counter_destroy(&mp->m_delalloc_blks);
1038 struct super_block *sb)
1040 struct xfs_mount *mp = XFS_M(sb);
1042 /* if ->fill_super failed, we have no mount to tear down */
1046 xfs_notice(mp, "Unmounting Filesystem");
1047 xfs_filestream_unmount(mp);
1051 free_percpu(mp->m_stats.xs_stats);
1052 xfs_destroy_percpu_counters(mp);
1053 xfs_destroy_mount_workqueues(mp);
1054 xfs_close_devices(mp);
1056 sb->s_fs_info = NULL;
1061 xfs_fs_nr_cached_objects(
1062 struct super_block *sb,
1063 struct shrink_control *sc)
1065 /* Paranoia: catch incorrect calls during mount setup or teardown */
1066 if (WARN_ON_ONCE(!sb->s_fs_info))
1068 return xfs_reclaim_inodes_count(XFS_M(sb));
1072 xfs_fs_free_cached_objects(
1073 struct super_block *sb,
1074 struct shrink_control *sc)
1076 return xfs_reclaim_inodes_nr(XFS_M(sb), sc->nr_to_scan);
1079 static const struct super_operations xfs_super_operations = {
1080 .alloc_inode = xfs_fs_alloc_inode,
1081 .destroy_inode = xfs_fs_destroy_inode,
1082 .dirty_inode = xfs_fs_dirty_inode,
1083 .drop_inode = xfs_fs_drop_inode,
1084 .put_super = xfs_fs_put_super,
1085 .sync_fs = xfs_fs_sync_fs,
1086 .freeze_fs = xfs_fs_freeze,
1087 .unfreeze_fs = xfs_fs_unfreeze,
1088 .statfs = xfs_fs_statfs,
1089 .show_options = xfs_fs_show_options,
1090 .nr_cached_objects = xfs_fs_nr_cached_objects,
1091 .free_cached_objects = xfs_fs_free_cached_objects,
1100 int last, shift_left_factor = 0, _res;
1104 value = kstrdup(s, GFP_KERNEL);
1108 last = strlen(value) - 1;
1109 if (value[last] == 'K' || value[last] == 'k') {
1110 shift_left_factor = 10;
1113 if (value[last] == 'M' || value[last] == 'm') {
1114 shift_left_factor = 20;
1117 if (value[last] == 'G' || value[last] == 'g') {
1118 shift_left_factor = 30;
1122 if (kstrtoint(value, base, &_res))
1125 *res = _res << shift_left_factor;
1130 * Set mount state from a mount option.
1132 * NOTE: mp->m_super is NULL here!
1136 struct fs_context *fc,
1137 struct fs_parameter *param)
1139 struct xfs_mount *mp = fc->s_fs_info;
1140 struct fs_parse_result result;
1144 opt = fs_parse(fc, xfs_fs_parameters, param, &result);
1150 mp->m_logbufs = result.uint_32;
1153 if (suffix_kstrtoint(param->string, 10, &mp->m_logbsize))
1157 kfree(mp->m_logname);
1158 mp->m_logname = kstrdup(param->string, GFP_KERNEL);
1163 kfree(mp->m_rtname);
1164 mp->m_rtname = kstrdup(param->string, GFP_KERNEL);
1169 if (suffix_kstrtoint(param->string, 10, &size))
1171 mp->m_allocsize_log = ffs(size) - 1;
1172 mp->m_flags |= XFS_MOUNT_ALLOCSIZE;
1176 mp->m_flags |= XFS_MOUNT_GRPID;
1179 case Opt_sysvgroups:
1180 mp->m_flags &= ~XFS_MOUNT_GRPID;
1183 mp->m_flags |= XFS_MOUNT_WSYNC;
1185 case Opt_norecovery:
1186 mp->m_flags |= XFS_MOUNT_NORECOVERY;
1189 mp->m_flags |= XFS_MOUNT_NOALIGN;
1192 mp->m_flags |= XFS_MOUNT_SWALLOC;
1195 mp->m_dalign = result.uint_32;
1198 mp->m_swidth = result.uint_32;
1201 mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
1204 mp->m_flags &= ~XFS_MOUNT_SMALL_INUMS;
1207 mp->m_flags |= XFS_MOUNT_NOUUID;
1210 mp->m_flags |= XFS_MOUNT_IKEEP;
1213 mp->m_flags &= ~XFS_MOUNT_IKEEP;
1216 mp->m_flags |= XFS_MOUNT_LARGEIO;
1219 mp->m_flags &= ~XFS_MOUNT_LARGEIO;
1222 mp->m_flags |= XFS_MOUNT_ATTR2;
1225 mp->m_flags &= ~XFS_MOUNT_ATTR2;
1226 mp->m_flags |= XFS_MOUNT_NOATTR2;
1228 case Opt_filestreams:
1229 mp->m_flags |= XFS_MOUNT_FILESTREAMS;
1232 mp->m_qflags &= ~XFS_ALL_QUOTA_ACCT;
1233 mp->m_qflags &= ~XFS_ALL_QUOTA_ENFD;
1234 mp->m_qflags &= ~XFS_ALL_QUOTA_ACTIVE;
1239 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE |
1242 case Opt_qnoenforce:
1243 case Opt_uqnoenforce:
1244 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
1245 mp->m_qflags &= ~XFS_UQUOTA_ENFD;
1249 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE |
1252 case Opt_pqnoenforce:
1253 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
1254 mp->m_qflags &= ~XFS_PQUOTA_ENFD;
1258 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE |
1261 case Opt_gqnoenforce:
1262 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
1263 mp->m_qflags &= ~XFS_GQUOTA_ENFD;
1266 mp->m_flags |= XFS_MOUNT_DISCARD;
1269 mp->m_flags &= ~XFS_MOUNT_DISCARD;
1271 #ifdef CONFIG_FS_DAX
1273 mp->m_flags |= XFS_MOUNT_DAX;
1277 xfs_warn(mp, "unknown mount option [%s].", param->key);
1285 xfs_fc_validate_params(
1286 struct xfs_mount *mp)
1289 * no recovery flag requires a read-only mount
1291 if ((mp->m_flags & XFS_MOUNT_NORECOVERY) &&
1292 !(mp->m_flags & XFS_MOUNT_RDONLY)) {
1293 xfs_warn(mp, "no-recovery mounts must be read-only.");
1297 if ((mp->m_flags & XFS_MOUNT_NOALIGN) &&
1298 (mp->m_dalign || mp->m_swidth)) {
1300 "sunit and swidth options incompatible with the noalign option");
1304 if (!IS_ENABLED(CONFIG_XFS_QUOTA) && mp->m_qflags != 0) {
1305 xfs_warn(mp, "quota support not available in this kernel.");
1309 if ((mp->m_dalign && !mp->m_swidth) ||
1310 (!mp->m_dalign && mp->m_swidth)) {
1311 xfs_warn(mp, "sunit and swidth must be specified together");
1315 if (mp->m_dalign && (mp->m_swidth % mp->m_dalign != 0)) {
1317 "stripe width (%d) must be a multiple of the stripe unit (%d)",
1318 mp->m_swidth, mp->m_dalign);
1322 if (mp->m_logbufs != -1 &&
1323 mp->m_logbufs != 0 &&
1324 (mp->m_logbufs < XLOG_MIN_ICLOGS ||
1325 mp->m_logbufs > XLOG_MAX_ICLOGS)) {
1326 xfs_warn(mp, "invalid logbufs value: %d [not %d-%d]",
1327 mp->m_logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
1331 if (mp->m_logbsize != -1 &&
1332 mp->m_logbsize != 0 &&
1333 (mp->m_logbsize < XLOG_MIN_RECORD_BSIZE ||
1334 mp->m_logbsize > XLOG_MAX_RECORD_BSIZE ||
1335 !is_power_of_2(mp->m_logbsize))) {
1337 "invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
1342 if ((mp->m_flags & XFS_MOUNT_ALLOCSIZE) &&
1343 (mp->m_allocsize_log > XFS_MAX_IO_LOG ||
1344 mp->m_allocsize_log < XFS_MIN_IO_LOG)) {
1345 xfs_warn(mp, "invalid log iosize: %d [not %d-%d]",
1346 mp->m_allocsize_log, XFS_MIN_IO_LOG, XFS_MAX_IO_LOG);
1355 struct super_block *sb,
1356 struct fs_context *fc)
1358 struct xfs_mount *mp = sb->s_fs_info;
1360 int flags = 0, error;
1364 error = xfs_fc_validate_params(mp);
1366 goto out_free_names;
1368 sb_min_blocksize(sb, BBSIZE);
1369 sb->s_xattr = xfs_xattr_handlers;
1370 sb->s_export_op = &xfs_export_operations;
1371 #ifdef CONFIG_XFS_QUOTA
1372 sb->s_qcop = &xfs_quotactl_operations;
1373 sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ;
1375 sb->s_op = &xfs_super_operations;
1378 * Delay mount work if the debug hook is set. This is debug
1379 * instrumention to coordinate simulation of xfs mount failures with
1380 * VFS superblock operations
1382 if (xfs_globals.mount_delay) {
1383 xfs_notice(mp, "Delaying mount for %d seconds.",
1384 xfs_globals.mount_delay);
1385 msleep(xfs_globals.mount_delay * 1000);
1388 if (fc->sb_flags & SB_SILENT)
1389 flags |= XFS_MFSI_QUIET;
1391 error = xfs_open_devices(mp);
1393 goto out_free_names;
1395 error = xfs_init_mount_workqueues(mp);
1397 goto out_close_devices;
1399 error = xfs_init_percpu_counters(mp);
1401 goto out_destroy_workqueues;
1403 /* Allocate stats memory before we do operations that might use it */
1404 mp->m_stats.xs_stats = alloc_percpu(struct xfsstats);
1405 if (!mp->m_stats.xs_stats) {
1407 goto out_destroy_counters;
1410 error = xfs_readsb(mp, flags);
1412 goto out_free_stats;
1414 error = xfs_finish_flags(mp);
1418 error = xfs_setup_devices(mp);
1422 error = xfs_filestream_mount(mp);
1427 * we must configure the block size in the superblock before we run the
1428 * full mount process as the mount process can lookup and cache inodes.
1430 sb->s_magic = XFS_SUPER_MAGIC;
1431 sb->s_blocksize = mp->m_sb.sb_blocksize;
1432 sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
1433 sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
1434 sb->s_max_links = XFS_MAXLINK;
1435 sb->s_time_gran = 1;
1436 sb->s_time_min = S32_MIN;
1437 sb->s_time_max = S32_MAX;
1438 sb->s_iflags |= SB_I_CGROUPWB;
1440 set_posix_acl_flag(sb);
1442 /* version 5 superblocks support inode version counters. */
1443 if (XFS_SB_VERSION_NUM(&mp->m_sb) == XFS_SB_VERSION_5)
1444 sb->s_flags |= SB_I_VERSION;
1446 if (mp->m_flags & XFS_MOUNT_DAX) {
1447 bool rtdev_is_dax = false, datadev_is_dax;
1450 "DAX enabled. Warning: EXPERIMENTAL, use at your own risk");
1452 datadev_is_dax = bdev_dax_supported(mp->m_ddev_targp->bt_bdev,
1454 if (mp->m_rtdev_targp)
1455 rtdev_is_dax = bdev_dax_supported(
1456 mp->m_rtdev_targp->bt_bdev, sb->s_blocksize);
1457 if (!rtdev_is_dax && !datadev_is_dax) {
1459 "DAX unsupported by block device. Turning off DAX.");
1460 mp->m_flags &= ~XFS_MOUNT_DAX;
1462 if (xfs_sb_version_hasreflink(&mp->m_sb)) {
1464 "DAX and reflink cannot be used together!");
1466 goto out_filestream_unmount;
1470 if (mp->m_flags & XFS_MOUNT_DISCARD) {
1471 struct request_queue *q = bdev_get_queue(sb->s_bdev);
1473 if (!blk_queue_discard(q)) {
1474 xfs_warn(mp, "mounting with \"discard\" option, but "
1475 "the device does not support discard");
1476 mp->m_flags &= ~XFS_MOUNT_DISCARD;
1480 if (xfs_sb_version_hasreflink(&mp->m_sb)) {
1481 if (mp->m_sb.sb_rblocks) {
1483 "reflink not compatible with realtime device!");
1485 goto out_filestream_unmount;
1488 if (xfs_globals.always_cow) {
1489 xfs_info(mp, "using DEBUG-only always_cow mode.");
1490 mp->m_always_cow = true;
1494 if (xfs_sb_version_hasrmapbt(&mp->m_sb) && mp->m_sb.sb_rblocks) {
1496 "reverse mapping btree not compatible with realtime device!");
1498 goto out_filestream_unmount;
1501 error = xfs_mountfs(mp);
1503 goto out_filestream_unmount;
1505 root = igrab(VFS_I(mp->m_rootip));
1510 sb->s_root = d_make_root(root);
1518 out_filestream_unmount:
1519 xfs_filestream_unmount(mp);
1523 free_percpu(mp->m_stats.xs_stats);
1524 out_destroy_counters:
1525 xfs_destroy_percpu_counters(mp);
1526 out_destroy_workqueues:
1527 xfs_destroy_mount_workqueues(mp);
1529 xfs_close_devices(mp);
1531 sb->s_fs_info = NULL;
1536 xfs_filestream_unmount(mp);
1543 struct fs_context *fc)
1545 return get_tree_bdev(fc, xfs_fc_fill_super);
1550 struct xfs_mount *mp)
1552 struct xfs_sb *sbp = &mp->m_sb;
1555 if (mp->m_flags & XFS_MOUNT_NORECOVERY) {
1557 "ro->rw transition prohibited on norecovery mount");
1561 if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 &&
1562 xfs_sb_has_ro_compat_feature(sbp, XFS_SB_FEAT_RO_COMPAT_UNKNOWN)) {
1564 "ro->rw transition prohibited on unknown (0x%x) ro-compat filesystem",
1565 (sbp->sb_features_ro_compat &
1566 XFS_SB_FEAT_RO_COMPAT_UNKNOWN));
1570 mp->m_flags &= ~XFS_MOUNT_RDONLY;
1573 * If this is the first remount to writeable state we might have some
1574 * superblock changes to update.
1576 if (mp->m_update_sb) {
1577 error = xfs_sync_sb(mp, false);
1579 xfs_warn(mp, "failed to write sb changes");
1582 mp->m_update_sb = false;
1586 * Fill out the reserve pool if it is empty. Use the stashed value if
1587 * it is non-zero, otherwise go with the default.
1589 xfs_restore_resvblks(mp);
1590 xfs_log_work_queue(mp);
1592 /* Recover any CoW blocks that never got remapped. */
1593 error = xfs_reflink_recover_cow(mp);
1596 "Error %d recovering leftover CoW allocations.", error);
1597 xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
1600 xfs_start_block_reaping(mp);
1602 /* Create the per-AG metadata reservation pool .*/
1603 error = xfs_fs_reserve_ag_blocks(mp);
1604 if (error && error != -ENOSPC)
1612 struct xfs_mount *mp)
1617 * Cancel background eofb scanning so it cannot race with the final
1618 * log force+buftarg wait and deadlock the remount.
1620 xfs_stop_block_reaping(mp);
1622 /* Get rid of any leftover CoW reservations... */
1623 error = xfs_icache_free_cowblocks(mp, NULL);
1625 xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
1629 /* Free the per-AG metadata reservation pool. */
1630 error = xfs_fs_unreserve_ag_blocks(mp);
1632 xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
1637 * Before we sync the metadata, we need to free up the reserve block
1638 * pool so that the used block count in the superblock on disk is
1639 * correct at the end of the remount. Stash the current* reserve pool
1640 * size so that if we get remounted rw, we can return it to the same
1643 xfs_save_resvblks(mp);
1645 xfs_quiesce_attr(mp);
1646 mp->m_flags |= XFS_MOUNT_RDONLY;
1652 * Logically we would return an error here to prevent users from believing
1653 * they might have changed mount options using remount which can't be changed.
1655 * But unfortunately mount(8) adds all options from mtab and fstab to the mount
1656 * arguments in some cases so we can't blindly reject options, but have to
1657 * check for each specified option if it actually differs from the currently
1658 * set option and only reject it if that's the case.
1660 * Until that is implemented we return success for every remount request, and
1661 * silently ignore all options that we can't actually change.
1665 struct fs_context *fc)
1667 struct xfs_mount *mp = XFS_M(fc->root->d_sb);
1668 struct xfs_mount *new_mp = fc->s_fs_info;
1669 xfs_sb_t *sbp = &mp->m_sb;
1670 int flags = fc->sb_flags;
1673 error = xfs_fc_validate_params(new_mp);
1677 sync_filesystem(mp->m_super);
1679 /* inode32 -> inode64 */
1680 if ((mp->m_flags & XFS_MOUNT_SMALL_INUMS) &&
1681 !(new_mp->m_flags & XFS_MOUNT_SMALL_INUMS)) {
1682 mp->m_flags &= ~XFS_MOUNT_SMALL_INUMS;
1683 mp->m_maxagi = xfs_set_inode_alloc(mp, sbp->sb_agcount);
1686 /* inode64 -> inode32 */
1687 if (!(mp->m_flags & XFS_MOUNT_SMALL_INUMS) &&
1688 (new_mp->m_flags & XFS_MOUNT_SMALL_INUMS)) {
1689 mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
1690 mp->m_maxagi = xfs_set_inode_alloc(mp, sbp->sb_agcount);
1694 if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(flags & SB_RDONLY)) {
1695 error = xfs_remount_rw(mp);
1701 if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (flags & SB_RDONLY)) {
1702 error = xfs_remount_ro(mp);
1710 static void xfs_fc_free(
1711 struct fs_context *fc)
1713 struct xfs_mount *mp = fc->s_fs_info;
1716 * mp is stored in the fs_context when it is initialized.
1717 * mp is transferred to the superblock on a successful mount,
1718 * but if an error occurs before the transfer we have to free
1725 static const struct fs_context_operations xfs_context_ops = {
1726 .parse_param = xfs_fc_parse_param,
1727 .get_tree = xfs_fc_get_tree,
1728 .reconfigure = xfs_fc_reconfigure,
1729 .free = xfs_fc_free,
1732 static int xfs_init_fs_context(
1733 struct fs_context *fc)
1735 struct xfs_mount *mp;
1737 mp = kmem_alloc(sizeof(struct xfs_mount), KM_ZERO);
1741 spin_lock_init(&mp->m_sb_lock);
1742 spin_lock_init(&mp->m_agirotor_lock);
1743 INIT_RADIX_TREE(&mp->m_perag_tree, GFP_ATOMIC);
1744 spin_lock_init(&mp->m_perag_lock);
1745 mutex_init(&mp->m_growlock);
1746 atomic_set(&mp->m_active_trans, 0);
1747 INIT_DELAYED_WORK(&mp->m_reclaim_work, xfs_reclaim_worker);
1748 INIT_DELAYED_WORK(&mp->m_eofblocks_work, xfs_eofblocks_worker);
1749 INIT_DELAYED_WORK(&mp->m_cowblocks_work, xfs_cowblocks_worker);
1750 mp->m_kobj.kobject.kset = xfs_kset;
1752 * We don't create the finobt per-ag space reservation until after log
1753 * recovery, so we must set this to true so that an ifree transaction
1754 * started during log recovery will not depend on space reservations
1755 * for finobt expansion.
1757 mp->m_finobt_nores = true;
1760 * These can be overridden by the mount option parsing.
1763 mp->m_logbsize = -1;
1764 mp->m_allocsize_log = 16; /* 64k */
1767 * Copy binary VFS mount flags we are interested in.
1769 if (fc->sb_flags & SB_RDONLY)
1770 mp->m_flags |= XFS_MOUNT_RDONLY;
1771 if (fc->sb_flags & SB_DIRSYNC)
1772 mp->m_flags |= XFS_MOUNT_DIRSYNC;
1773 if (fc->sb_flags & SB_SYNCHRONOUS)
1774 mp->m_flags |= XFS_MOUNT_WSYNC;
1777 fc->ops = &xfs_context_ops;
1782 static struct file_system_type xfs_fs_type = {
1783 .owner = THIS_MODULE,
1785 .init_fs_context = xfs_init_fs_context,
1786 .parameters = xfs_fs_parameters,
1787 .kill_sb = kill_block_super,
1788 .fs_flags = FS_REQUIRES_DEV,
1790 MODULE_ALIAS_FS("xfs");
1793 xfs_init_zones(void)
1795 xfs_log_ticket_zone = kmem_cache_create("xfs_log_ticket",
1796 sizeof(struct xlog_ticket),
1798 if (!xfs_log_ticket_zone)
1801 xfs_bmap_free_item_zone = kmem_cache_create("xfs_bmap_free_item",
1802 sizeof(struct xfs_extent_free_item),
1804 if (!xfs_bmap_free_item_zone)
1805 goto out_destroy_log_ticket_zone;
1807 xfs_btree_cur_zone = kmem_cache_create("xfs_btree_cur",
1808 sizeof(struct xfs_btree_cur),
1810 if (!xfs_btree_cur_zone)
1811 goto out_destroy_bmap_free_item_zone;
1813 xfs_da_state_zone = kmem_cache_create("xfs_da_state",
1814 sizeof(struct xfs_da_state),
1816 if (!xfs_da_state_zone)
1817 goto out_destroy_btree_cur_zone;
1819 xfs_ifork_zone = kmem_cache_create("xfs_ifork",
1820 sizeof(struct xfs_ifork),
1822 if (!xfs_ifork_zone)
1823 goto out_destroy_da_state_zone;
1825 xfs_trans_zone = kmem_cache_create("xf_trans",
1826 sizeof(struct xfs_trans),
1828 if (!xfs_trans_zone)
1829 goto out_destroy_ifork_zone;
1833 * The size of the zone allocated buf log item is the maximum
1834 * size possible under XFS. This wastes a little bit of memory,
1835 * but it is much faster.
1837 xfs_buf_item_zone = kmem_cache_create("xfs_buf_item",
1838 sizeof(struct xfs_buf_log_item),
1840 if (!xfs_buf_item_zone)
1841 goto out_destroy_trans_zone;
1843 xfs_efd_zone = kmem_cache_create("xfs_efd_item",
1844 (sizeof(struct xfs_efd_log_item) +
1845 (XFS_EFD_MAX_FAST_EXTENTS - 1) *
1846 sizeof(struct xfs_extent)),
1849 goto out_destroy_buf_item_zone;
1851 xfs_efi_zone = kmem_cache_create("xfs_efi_item",
1852 (sizeof(struct xfs_efi_log_item) +
1853 (XFS_EFI_MAX_FAST_EXTENTS - 1) *
1854 sizeof(struct xfs_extent)),
1857 goto out_destroy_efd_zone;
1859 xfs_inode_zone = kmem_cache_create("xfs_inode",
1860 sizeof(struct xfs_inode), 0,
1861 (SLAB_HWCACHE_ALIGN |
1862 SLAB_RECLAIM_ACCOUNT |
1863 SLAB_MEM_SPREAD | SLAB_ACCOUNT),
1864 xfs_fs_inode_init_once);
1865 if (!xfs_inode_zone)
1866 goto out_destroy_efi_zone;
1868 xfs_ili_zone = kmem_cache_create("xfs_ili",
1869 sizeof(struct xfs_inode_log_item), 0,
1870 SLAB_MEM_SPREAD, NULL);
1872 goto out_destroy_inode_zone;
1874 xfs_icreate_zone = kmem_cache_create("xfs_icr",
1875 sizeof(struct xfs_icreate_item),
1877 if (!xfs_icreate_zone)
1878 goto out_destroy_ili_zone;
1880 xfs_rud_zone = kmem_cache_create("xfs_rud_item",
1881 sizeof(struct xfs_rud_log_item),
1884 goto out_destroy_icreate_zone;
1886 xfs_rui_zone = kmem_cache_create("xfs_rui_item",
1887 xfs_rui_log_item_sizeof(XFS_RUI_MAX_FAST_EXTENTS),
1890 goto out_destroy_rud_zone;
1892 xfs_cud_zone = kmem_cache_create("xfs_cud_item",
1893 sizeof(struct xfs_cud_log_item),
1896 goto out_destroy_rui_zone;
1898 xfs_cui_zone = kmem_cache_create("xfs_cui_item",
1899 xfs_cui_log_item_sizeof(XFS_CUI_MAX_FAST_EXTENTS),
1902 goto out_destroy_cud_zone;
1904 xfs_bud_zone = kmem_cache_create("xfs_bud_item",
1905 sizeof(struct xfs_bud_log_item),
1908 goto out_destroy_cui_zone;
1910 xfs_bui_zone = kmem_cache_create("xfs_bui_item",
1911 xfs_bui_log_item_sizeof(XFS_BUI_MAX_FAST_EXTENTS),
1914 goto out_destroy_bud_zone;
1918 out_destroy_bud_zone:
1919 kmem_cache_destroy(xfs_bud_zone);
1920 out_destroy_cui_zone:
1921 kmem_cache_destroy(xfs_cui_zone);
1922 out_destroy_cud_zone:
1923 kmem_cache_destroy(xfs_cud_zone);
1924 out_destroy_rui_zone:
1925 kmem_cache_destroy(xfs_rui_zone);
1926 out_destroy_rud_zone:
1927 kmem_cache_destroy(xfs_rud_zone);
1928 out_destroy_icreate_zone:
1929 kmem_cache_destroy(xfs_icreate_zone);
1930 out_destroy_ili_zone:
1931 kmem_cache_destroy(xfs_ili_zone);
1932 out_destroy_inode_zone:
1933 kmem_cache_destroy(xfs_inode_zone);
1934 out_destroy_efi_zone:
1935 kmem_cache_destroy(xfs_efi_zone);
1936 out_destroy_efd_zone:
1937 kmem_cache_destroy(xfs_efd_zone);
1938 out_destroy_buf_item_zone:
1939 kmem_cache_destroy(xfs_buf_item_zone);
1940 out_destroy_trans_zone:
1941 kmem_cache_destroy(xfs_trans_zone);
1942 out_destroy_ifork_zone:
1943 kmem_cache_destroy(xfs_ifork_zone);
1944 out_destroy_da_state_zone:
1945 kmem_cache_destroy(xfs_da_state_zone);
1946 out_destroy_btree_cur_zone:
1947 kmem_cache_destroy(xfs_btree_cur_zone);
1948 out_destroy_bmap_free_item_zone:
1949 kmem_cache_destroy(xfs_bmap_free_item_zone);
1950 out_destroy_log_ticket_zone:
1951 kmem_cache_destroy(xfs_log_ticket_zone);
1957 xfs_destroy_zones(void)
1960 * Make sure all delayed rcu free are flushed before we
1964 kmem_cache_destroy(xfs_bui_zone);
1965 kmem_cache_destroy(xfs_bud_zone);
1966 kmem_cache_destroy(xfs_cui_zone);
1967 kmem_cache_destroy(xfs_cud_zone);
1968 kmem_cache_destroy(xfs_rui_zone);
1969 kmem_cache_destroy(xfs_rud_zone);
1970 kmem_cache_destroy(xfs_icreate_zone);
1971 kmem_cache_destroy(xfs_ili_zone);
1972 kmem_cache_destroy(xfs_inode_zone);
1973 kmem_cache_destroy(xfs_efi_zone);
1974 kmem_cache_destroy(xfs_efd_zone);
1975 kmem_cache_destroy(xfs_buf_item_zone);
1976 kmem_cache_destroy(xfs_trans_zone);
1977 kmem_cache_destroy(xfs_ifork_zone);
1978 kmem_cache_destroy(xfs_da_state_zone);
1979 kmem_cache_destroy(xfs_btree_cur_zone);
1980 kmem_cache_destroy(xfs_bmap_free_item_zone);
1981 kmem_cache_destroy(xfs_log_ticket_zone);
1985 xfs_init_workqueues(void)
1988 * The allocation workqueue can be used in memory reclaim situations
1989 * (writepage path), and parallelism is only limited by the number of
1990 * AGs in all the filesystems mounted. Hence use the default large
1991 * max_active value for this workqueue.
1993 xfs_alloc_wq = alloc_workqueue("xfsalloc",
1994 WQ_MEM_RECLAIM|WQ_FREEZABLE, 0);
1998 xfs_discard_wq = alloc_workqueue("xfsdiscard", WQ_UNBOUND, 0);
1999 if (!xfs_discard_wq)
2000 goto out_free_alloc_wq;
2004 destroy_workqueue(xfs_alloc_wq);
2009 xfs_destroy_workqueues(void)
2011 destroy_workqueue(xfs_discard_wq);
2012 destroy_workqueue(xfs_alloc_wq);
2020 xfs_check_ondisk_structs();
2022 printk(KERN_INFO XFS_VERSION_STRING " with "
2023 XFS_BUILD_OPTIONS " enabled\n");
2027 error = xfs_init_zones();
2031 error = xfs_init_workqueues();
2033 goto out_destroy_zones;
2035 error = xfs_mru_cache_init();
2037 goto out_destroy_wq;
2039 error = xfs_buf_init();
2041 goto out_mru_cache_uninit;
2043 error = xfs_init_procfs();
2045 goto out_buf_terminate;
2047 error = xfs_sysctl_register();
2049 goto out_cleanup_procfs;
2051 xfs_kset = kset_create_and_add("xfs", NULL, fs_kobj);
2054 goto out_sysctl_unregister;
2057 xfsstats.xs_kobj.kobject.kset = xfs_kset;
2059 xfsstats.xs_stats = alloc_percpu(struct xfsstats);
2060 if (!xfsstats.xs_stats) {
2062 goto out_kset_unregister;
2065 error = xfs_sysfs_init(&xfsstats.xs_kobj, &xfs_stats_ktype, NULL,
2068 goto out_free_stats;
2071 xfs_dbg_kobj.kobject.kset = xfs_kset;
2072 error = xfs_sysfs_init(&xfs_dbg_kobj, &xfs_dbg_ktype, NULL, "debug");
2074 goto out_remove_stats_kobj;
2077 error = xfs_qm_init();
2079 goto out_remove_dbg_kobj;
2081 error = register_filesystem(&xfs_fs_type);
2088 out_remove_dbg_kobj:
2090 xfs_sysfs_del(&xfs_dbg_kobj);
2091 out_remove_stats_kobj:
2093 xfs_sysfs_del(&xfsstats.xs_kobj);
2095 free_percpu(xfsstats.xs_stats);
2096 out_kset_unregister:
2097 kset_unregister(xfs_kset);
2098 out_sysctl_unregister:
2099 xfs_sysctl_unregister();
2101 xfs_cleanup_procfs();
2103 xfs_buf_terminate();
2104 out_mru_cache_uninit:
2105 xfs_mru_cache_uninit();
2107 xfs_destroy_workqueues();
2109 xfs_destroy_zones();
2118 unregister_filesystem(&xfs_fs_type);
2120 xfs_sysfs_del(&xfs_dbg_kobj);
2122 xfs_sysfs_del(&xfsstats.xs_kobj);
2123 free_percpu(xfsstats.xs_stats);
2124 kset_unregister(xfs_kset);
2125 xfs_sysctl_unregister();
2126 xfs_cleanup_procfs();
2127 xfs_buf_terminate();
2128 xfs_mru_cache_uninit();
2129 xfs_destroy_workqueues();
2130 xfs_destroy_zones();
2131 xfs_uuid_table_free();
2134 module_init(init_xfs_fs);
2135 module_exit(exit_xfs_fs);
2137 MODULE_AUTHOR("Silicon Graphics, Inc.");
2138 MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
2139 MODULE_LICENSE("GPL");