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"
38 #include "xfs_pwork.h"
40 #include "xfs_defer.h"
41 #include "xfs_attr_item.h"
42 #include "xfs_xattr.h"
44 #include <linux/magic.h>
45 #include <linux/fs_context.h>
46 #include <linux/fs_parser.h>
48 static const struct super_operations xfs_super_operations;
50 static struct kset *xfs_kset; /* top-level xfs sysfs dir */
52 static struct xfs_kobj xfs_dbg_kobj; /* global debug sysfs attrs */
55 #ifdef CONFIG_HOTPLUG_CPU
56 static LIST_HEAD(xfs_mount_list);
57 static DEFINE_SPINLOCK(xfs_mount_list_lock);
59 static inline void xfs_mount_list_add(struct xfs_mount *mp)
61 spin_lock(&xfs_mount_list_lock);
62 list_add(&mp->m_mount_list, &xfs_mount_list);
63 spin_unlock(&xfs_mount_list_lock);
66 static inline void xfs_mount_list_del(struct xfs_mount *mp)
68 spin_lock(&xfs_mount_list_lock);
69 list_del(&mp->m_mount_list);
70 spin_unlock(&xfs_mount_list_lock);
72 #else /* !CONFIG_HOTPLUG_CPU */
73 static inline void xfs_mount_list_add(struct xfs_mount *mp) {}
74 static inline void xfs_mount_list_del(struct xfs_mount *mp) {}
84 xfs_mount_set_dax_mode(
86 enum xfs_dax_mode mode)
90 mp->m_features &= ~(XFS_FEAT_DAX_ALWAYS | XFS_FEAT_DAX_NEVER);
93 mp->m_features |= XFS_FEAT_DAX_ALWAYS;
94 mp->m_features &= ~XFS_FEAT_DAX_NEVER;
97 mp->m_features |= XFS_FEAT_DAX_NEVER;
98 mp->m_features &= ~XFS_FEAT_DAX_ALWAYS;
103 static const struct constant_table dax_param_enums[] = {
104 {"inode", XFS_DAX_INODE },
105 {"always", XFS_DAX_ALWAYS },
106 {"never", XFS_DAX_NEVER },
111 * Table driven mount option parser.
114 Opt_logbufs, Opt_logbsize, Opt_logdev, Opt_rtdev,
115 Opt_wsync, Opt_noalign, Opt_swalloc, Opt_sunit, Opt_swidth, Opt_nouuid,
116 Opt_grpid, Opt_nogrpid, Opt_bsdgroups, Opt_sysvgroups,
117 Opt_allocsize, Opt_norecovery, Opt_inode64, Opt_inode32, Opt_ikeep,
118 Opt_noikeep, Opt_largeio, Opt_nolargeio, Opt_attr2, Opt_noattr2,
119 Opt_filestreams, Opt_quota, Opt_noquota, Opt_usrquota, Opt_grpquota,
120 Opt_prjquota, Opt_uquota, Opt_gquota, Opt_pquota,
121 Opt_uqnoenforce, Opt_gqnoenforce, Opt_pqnoenforce, Opt_qnoenforce,
122 Opt_discard, Opt_nodiscard, Opt_dax, Opt_dax_enum,
125 static const struct fs_parameter_spec xfs_fs_parameters[] = {
126 fsparam_u32("logbufs", Opt_logbufs),
127 fsparam_string("logbsize", Opt_logbsize),
128 fsparam_string("logdev", Opt_logdev),
129 fsparam_string("rtdev", Opt_rtdev),
130 fsparam_flag("wsync", Opt_wsync),
131 fsparam_flag("noalign", Opt_noalign),
132 fsparam_flag("swalloc", Opt_swalloc),
133 fsparam_u32("sunit", Opt_sunit),
134 fsparam_u32("swidth", Opt_swidth),
135 fsparam_flag("nouuid", Opt_nouuid),
136 fsparam_flag("grpid", Opt_grpid),
137 fsparam_flag("nogrpid", Opt_nogrpid),
138 fsparam_flag("bsdgroups", Opt_bsdgroups),
139 fsparam_flag("sysvgroups", Opt_sysvgroups),
140 fsparam_string("allocsize", Opt_allocsize),
141 fsparam_flag("norecovery", Opt_norecovery),
142 fsparam_flag("inode64", Opt_inode64),
143 fsparam_flag("inode32", Opt_inode32),
144 fsparam_flag("ikeep", Opt_ikeep),
145 fsparam_flag("noikeep", Opt_noikeep),
146 fsparam_flag("largeio", Opt_largeio),
147 fsparam_flag("nolargeio", Opt_nolargeio),
148 fsparam_flag("attr2", Opt_attr2),
149 fsparam_flag("noattr2", Opt_noattr2),
150 fsparam_flag("filestreams", Opt_filestreams),
151 fsparam_flag("quota", Opt_quota),
152 fsparam_flag("noquota", Opt_noquota),
153 fsparam_flag("usrquota", Opt_usrquota),
154 fsparam_flag("grpquota", Opt_grpquota),
155 fsparam_flag("prjquota", Opt_prjquota),
156 fsparam_flag("uquota", Opt_uquota),
157 fsparam_flag("gquota", Opt_gquota),
158 fsparam_flag("pquota", Opt_pquota),
159 fsparam_flag("uqnoenforce", Opt_uqnoenforce),
160 fsparam_flag("gqnoenforce", Opt_gqnoenforce),
161 fsparam_flag("pqnoenforce", Opt_pqnoenforce),
162 fsparam_flag("qnoenforce", Opt_qnoenforce),
163 fsparam_flag("discard", Opt_discard),
164 fsparam_flag("nodiscard", Opt_nodiscard),
165 fsparam_flag("dax", Opt_dax),
166 fsparam_enum("dax", Opt_dax_enum, dax_param_enums),
170 struct proc_xfs_info {
180 static struct proc_xfs_info xfs_info_set[] = {
181 /* the few simple ones we can get from the mount struct */
182 { XFS_FEAT_IKEEP, ",ikeep" },
183 { XFS_FEAT_WSYNC, ",wsync" },
184 { XFS_FEAT_NOALIGN, ",noalign" },
185 { XFS_FEAT_SWALLOC, ",swalloc" },
186 { XFS_FEAT_NOUUID, ",nouuid" },
187 { XFS_FEAT_NORECOVERY, ",norecovery" },
188 { XFS_FEAT_ATTR2, ",attr2" },
189 { XFS_FEAT_FILESTREAMS, ",filestreams" },
190 { XFS_FEAT_GRPID, ",grpid" },
191 { XFS_FEAT_DISCARD, ",discard" },
192 { XFS_FEAT_LARGE_IOSIZE, ",largeio" },
193 { XFS_FEAT_DAX_ALWAYS, ",dax=always" },
194 { XFS_FEAT_DAX_NEVER, ",dax=never" },
197 struct xfs_mount *mp = XFS_M(root->d_sb);
198 struct proc_xfs_info *xfs_infop;
200 for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
201 if (mp->m_features & xfs_infop->flag)
202 seq_puts(m, xfs_infop->str);
205 seq_printf(m, ",inode%d", xfs_has_small_inums(mp) ? 32 : 64);
207 if (xfs_has_allocsize(mp))
208 seq_printf(m, ",allocsize=%dk",
209 (1 << mp->m_allocsize_log) >> 10);
211 if (mp->m_logbufs > 0)
212 seq_printf(m, ",logbufs=%d", mp->m_logbufs);
213 if (mp->m_logbsize > 0)
214 seq_printf(m, ",logbsize=%dk", mp->m_logbsize >> 10);
217 seq_show_option(m, "logdev", mp->m_logname);
219 seq_show_option(m, "rtdev", mp->m_rtname);
221 if (mp->m_dalign > 0)
222 seq_printf(m, ",sunit=%d",
223 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
224 if (mp->m_swidth > 0)
225 seq_printf(m, ",swidth=%d",
226 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
228 if (mp->m_qflags & XFS_UQUOTA_ENFD)
229 seq_puts(m, ",usrquota");
230 else if (mp->m_qflags & XFS_UQUOTA_ACCT)
231 seq_puts(m, ",uqnoenforce");
233 if (mp->m_qflags & XFS_PQUOTA_ENFD)
234 seq_puts(m, ",prjquota");
235 else if (mp->m_qflags & XFS_PQUOTA_ACCT)
236 seq_puts(m, ",pqnoenforce");
238 if (mp->m_qflags & XFS_GQUOTA_ENFD)
239 seq_puts(m, ",grpquota");
240 else if (mp->m_qflags & XFS_GQUOTA_ACCT)
241 seq_puts(m, ",gqnoenforce");
243 if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
244 seq_puts(m, ",noquota");
250 * Set parameters for inode allocation heuristics, taking into account
251 * filesystem size and inode32/inode64 mount options; i.e. specifically
252 * whether or not XFS_FEAT_SMALL_INUMS is set.
254 * Inode allocation patterns are altered only if inode32 is requested
255 * (XFS_FEAT_SMALL_INUMS), and the filesystem is sufficiently large.
256 * If altered, XFS_OPSTATE_INODE32 is set as well.
258 * An agcount independent of that in the mount structure is provided
259 * because in the growfs case, mp->m_sb.sb_agcount is not yet updated
260 * to the potentially higher ag count.
262 * Returns the maximum AG index which may contain inodes.
266 struct xfs_mount *mp,
267 xfs_agnumber_t agcount)
269 xfs_agnumber_t index;
270 xfs_agnumber_t maxagi = 0;
271 xfs_sb_t *sbp = &mp->m_sb;
272 xfs_agnumber_t max_metadata;
277 * Calculate how much should be reserved for inodes to meet
278 * the max inode percentage. Used only for inode32.
280 if (M_IGEO(mp)->maxicount) {
283 icount = sbp->sb_dblocks * sbp->sb_imax_pct;
285 icount += sbp->sb_agblocks - 1;
286 do_div(icount, sbp->sb_agblocks);
287 max_metadata = icount;
289 max_metadata = agcount;
292 /* Get the last possible inode in the filesystem */
293 agino = XFS_AGB_TO_AGINO(mp, sbp->sb_agblocks - 1);
294 ino = XFS_AGINO_TO_INO(mp, agcount - 1, agino);
297 * If user asked for no more than 32-bit inodes, and the fs is
298 * sufficiently large, set XFS_OPSTATE_INODE32 if we must alter
299 * the allocator to accommodate the request.
301 if (xfs_has_small_inums(mp) && ino > XFS_MAXINUMBER_32)
302 set_bit(XFS_OPSTATE_INODE32, &mp->m_opstate);
304 clear_bit(XFS_OPSTATE_INODE32, &mp->m_opstate);
306 for (index = 0; index < agcount; index++) {
307 struct xfs_perag *pag;
309 ino = XFS_AGINO_TO_INO(mp, index, agino);
311 pag = xfs_perag_get(mp, index);
313 if (xfs_is_inode32(mp)) {
314 if (ino > XFS_MAXINUMBER_32) {
315 pag->pagi_inodeok = 0;
316 pag->pagf_metadata = 0;
318 pag->pagi_inodeok = 1;
320 if (index < max_metadata)
321 pag->pagf_metadata = 1;
323 pag->pagf_metadata = 0;
326 pag->pagi_inodeok = 1;
327 pag->pagf_metadata = 0;
333 return xfs_is_inode32(mp) ? maxagi : agcount;
337 xfs_setup_dax_always(
338 struct xfs_mount *mp)
340 if (!mp->m_ddev_targp->bt_daxdev &&
341 (!mp->m_rtdev_targp || !mp->m_rtdev_targp->bt_daxdev)) {
343 "DAX unsupported by block device. Turning off DAX.");
347 if (mp->m_super->s_blocksize != PAGE_SIZE) {
349 "DAX not supported for blocksize. Turning off DAX.");
353 if (xfs_has_reflink(mp)) {
354 xfs_alert(mp, "DAX and reflink cannot be used together!");
358 xfs_warn(mp, "DAX enabled. Warning: EXPERIMENTAL, use at your own risk");
362 xfs_mount_set_dax_mode(mp, XFS_DAX_NEVER);
370 struct block_device **bdevp)
374 *bdevp = blkdev_get_by_path(name, FMODE_READ|FMODE_WRITE|FMODE_EXCL,
376 if (IS_ERR(*bdevp)) {
377 error = PTR_ERR(*bdevp);
378 xfs_warn(mp, "Invalid device [%s], error=%d", name, error);
386 struct block_device *bdev)
389 blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
394 struct xfs_mount *mp)
396 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
397 struct block_device *logdev = mp->m_logdev_targp->bt_bdev;
399 xfs_free_buftarg(mp->m_logdev_targp);
400 xfs_blkdev_put(logdev);
402 if (mp->m_rtdev_targp) {
403 struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev;
405 xfs_free_buftarg(mp->m_rtdev_targp);
406 xfs_blkdev_put(rtdev);
408 xfs_free_buftarg(mp->m_ddev_targp);
412 * The file system configurations are:
413 * (1) device (partition) with data and internal log
414 * (2) logical volume with data and log subvolumes.
415 * (3) logical volume with data, log, and realtime subvolumes.
417 * We only have to handle opening the log and realtime volumes here if
418 * they are present. The data subvolume has already been opened by
419 * get_sb_bdev() and is stored in sb->s_bdev.
423 struct xfs_mount *mp)
425 struct block_device *ddev = mp->m_super->s_bdev;
426 struct block_device *logdev = NULL, *rtdev = NULL;
430 * Open real time and log devices - order is important.
433 error = xfs_blkdev_get(mp, mp->m_logname, &logdev);
439 error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev);
441 goto out_close_logdev;
443 if (rtdev == ddev || rtdev == logdev) {
445 "Cannot mount filesystem with identical rtdev and ddev/logdev.");
447 goto out_close_rtdev;
452 * Setup xfs_mount buffer target pointers
455 mp->m_ddev_targp = xfs_alloc_buftarg(mp, ddev);
456 if (!mp->m_ddev_targp)
457 goto out_close_rtdev;
460 mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev);
461 if (!mp->m_rtdev_targp)
462 goto out_free_ddev_targ;
465 if (logdev && logdev != ddev) {
466 mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev);
467 if (!mp->m_logdev_targp)
468 goto out_free_rtdev_targ;
470 mp->m_logdev_targp = mp->m_ddev_targp;
476 if (mp->m_rtdev_targp)
477 xfs_free_buftarg(mp->m_rtdev_targp);
479 xfs_free_buftarg(mp->m_ddev_targp);
481 xfs_blkdev_put(rtdev);
483 if (logdev && logdev != ddev)
484 xfs_blkdev_put(logdev);
489 * Setup xfs_mount buffer target pointers based on superblock
493 struct xfs_mount *mp)
497 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_sectsize);
501 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
502 unsigned int log_sector_size = BBSIZE;
504 if (xfs_has_sector(mp))
505 log_sector_size = mp->m_sb.sb_logsectsize;
506 error = xfs_setsize_buftarg(mp->m_logdev_targp,
511 if (mp->m_rtdev_targp) {
512 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
513 mp->m_sb.sb_sectsize);
522 xfs_init_mount_workqueues(
523 struct xfs_mount *mp)
525 mp->m_buf_workqueue = alloc_workqueue("xfs-buf/%s",
526 XFS_WQFLAGS(WQ_FREEZABLE | WQ_MEM_RECLAIM),
527 1, mp->m_super->s_id);
528 if (!mp->m_buf_workqueue)
531 mp->m_unwritten_workqueue = alloc_workqueue("xfs-conv/%s",
532 XFS_WQFLAGS(WQ_FREEZABLE | WQ_MEM_RECLAIM),
533 0, mp->m_super->s_id);
534 if (!mp->m_unwritten_workqueue)
535 goto out_destroy_buf;
537 mp->m_reclaim_workqueue = alloc_workqueue("xfs-reclaim/%s",
538 XFS_WQFLAGS(WQ_FREEZABLE | WQ_MEM_RECLAIM),
539 0, mp->m_super->s_id);
540 if (!mp->m_reclaim_workqueue)
541 goto out_destroy_unwritten;
543 mp->m_blockgc_wq = alloc_workqueue("xfs-blockgc/%s",
544 XFS_WQFLAGS(WQ_UNBOUND | WQ_FREEZABLE | WQ_MEM_RECLAIM),
545 0, mp->m_super->s_id);
546 if (!mp->m_blockgc_wq)
547 goto out_destroy_reclaim;
549 mp->m_inodegc_wq = alloc_workqueue("xfs-inodegc/%s",
550 XFS_WQFLAGS(WQ_FREEZABLE | WQ_MEM_RECLAIM),
551 1, mp->m_super->s_id);
552 if (!mp->m_inodegc_wq)
553 goto out_destroy_blockgc;
555 mp->m_sync_workqueue = alloc_workqueue("xfs-sync/%s",
556 XFS_WQFLAGS(WQ_FREEZABLE), 0, mp->m_super->s_id);
557 if (!mp->m_sync_workqueue)
558 goto out_destroy_inodegc;
563 destroy_workqueue(mp->m_inodegc_wq);
565 destroy_workqueue(mp->m_blockgc_wq);
567 destroy_workqueue(mp->m_reclaim_workqueue);
568 out_destroy_unwritten:
569 destroy_workqueue(mp->m_unwritten_workqueue);
571 destroy_workqueue(mp->m_buf_workqueue);
577 xfs_destroy_mount_workqueues(
578 struct xfs_mount *mp)
580 destroy_workqueue(mp->m_sync_workqueue);
581 destroy_workqueue(mp->m_blockgc_wq);
582 destroy_workqueue(mp->m_inodegc_wq);
583 destroy_workqueue(mp->m_reclaim_workqueue);
584 destroy_workqueue(mp->m_unwritten_workqueue);
585 destroy_workqueue(mp->m_buf_workqueue);
589 xfs_flush_inodes_worker(
590 struct work_struct *work)
592 struct xfs_mount *mp = container_of(work, struct xfs_mount,
593 m_flush_inodes_work);
594 struct super_block *sb = mp->m_super;
596 if (down_read_trylock(&sb->s_umount)) {
598 up_read(&sb->s_umount);
603 * Flush all dirty data to disk. Must not be called while holding an XFS_ILOCK
604 * or a page lock. We use sync_inodes_sb() here to ensure we block while waiting
605 * for IO to complete so that we effectively throttle multiple callers to the
606 * rate at which IO is completing.
610 struct xfs_mount *mp)
613 * If flush_work() returns true then that means we waited for a flush
614 * which was already in progress. Don't bother running another scan.
616 if (flush_work(&mp->m_flush_inodes_work))
619 queue_work(mp->m_sync_workqueue, &mp->m_flush_inodes_work);
620 flush_work(&mp->m_flush_inodes_work);
623 /* Catch misguided souls that try to use this interface on XFS */
624 STATIC struct inode *
626 struct super_block *sb)
633 * Now that the generic code is guaranteed not to be accessing
634 * the linux inode, we can inactivate and reclaim the inode.
637 xfs_fs_destroy_inode(
640 struct xfs_inode *ip = XFS_I(inode);
642 trace_xfs_destroy_inode(ip);
644 ASSERT(!rwsem_is_locked(&inode->i_rwsem));
645 XFS_STATS_INC(ip->i_mount, vn_rele);
646 XFS_STATS_INC(ip->i_mount, vn_remove);
647 xfs_inode_mark_reclaimable(ip);
655 struct xfs_inode *ip = XFS_I(inode);
656 struct xfs_mount *mp = ip->i_mount;
657 struct xfs_trans *tp;
659 if (!(inode->i_sb->s_flags & SB_LAZYTIME))
661 if (flag != I_DIRTY_SYNC || !(inode->i_state & I_DIRTY_TIME))
664 if (xfs_trans_alloc(mp, &M_RES(mp)->tr_fsyncts, 0, 0, 0, &tp))
666 xfs_ilock(ip, XFS_ILOCK_EXCL);
667 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
668 xfs_trans_log_inode(tp, ip, XFS_ILOG_TIMESTAMP);
669 xfs_trans_commit(tp);
673 * Slab object creation initialisation for the XFS inode.
674 * This covers only the idempotent fields in the XFS inode;
675 * all other fields need to be initialised on allocation
676 * from the slab. This avoids the need to repeatedly initialise
677 * fields in the xfs inode that left in the initialise state
678 * when freeing the inode.
681 xfs_fs_inode_init_once(
684 struct xfs_inode *ip = inode;
686 memset(ip, 0, sizeof(struct xfs_inode));
689 inode_init_once(VFS_I(ip));
692 atomic_set(&ip->i_pincount, 0);
693 spin_lock_init(&ip->i_flags_lock);
695 mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
696 "xfsino", ip->i_ino);
700 * We do an unlocked check for XFS_IDONTCACHE here because we are already
701 * serialised against cache hits here via the inode->i_lock and igrab() in
702 * xfs_iget_cache_hit(). Hence a lookup that might clear this flag will not be
703 * racing with us, and it avoids needing to grab a spinlock here for every inode
704 * we drop the final reference on.
710 struct xfs_inode *ip = XFS_I(inode);
713 * If this unlinked inode is in the middle of recovery, don't
714 * drop the inode just yet; log recovery will take care of
715 * that. See the comment for this inode flag.
717 if (ip->i_flags & XFS_IRECOVERY) {
718 ASSERT(xlog_recovery_needed(ip->i_mount->m_log));
722 return generic_drop_inode(inode);
727 struct xfs_mount *mp)
730 kfree(mp->m_logname);
736 struct super_block *sb,
739 struct xfs_mount *mp = XFS_M(sb);
742 trace_xfs_fs_sync_fs(mp, __return_address);
745 * Doing anything during the async pass would be counterproductive.
750 error = xfs_log_force(mp, XFS_LOG_SYNC);
756 * The disk must be active because we're syncing.
757 * We schedule log work now (now that the disk is
758 * active) instead of later (when it might not be).
760 flush_delayed_work(&mp->m_log->l_work);
764 * If we are called with page faults frozen out, it means we are about
765 * to freeze the transaction subsystem. Take the opportunity to shut
766 * down inodegc because once SB_FREEZE_FS is set it's too late to
767 * prevent inactivation races with freeze. The fs doesn't get called
768 * again by the freezing process until after SB_FREEZE_FS has been set,
769 * so it's now or never. Same logic applies to speculative allocation
770 * garbage collection.
772 * We don't care if this is a normal syncfs call that does this or
773 * freeze that does this - we can run this multiple times without issue
774 * and we won't race with a restart because a restart can only occur
775 * when the state is either SB_FREEZE_FS or SB_FREEZE_COMPLETE.
777 if (sb->s_writers.frozen == SB_FREEZE_PAGEFAULT) {
778 xfs_inodegc_stop(mp);
779 xfs_blockgc_stop(mp);
787 struct dentry *dentry,
788 struct kstatfs *statp)
790 struct xfs_mount *mp = XFS_M(dentry->d_sb);
791 xfs_sb_t *sbp = &mp->m_sb;
792 struct xfs_inode *ip = XFS_I(d_inode(dentry));
793 uint64_t fakeinos, id;
800 /* Wait for whatever inactivations are in progress. */
801 xfs_inodegc_flush(mp);
803 statp->f_type = XFS_SUPER_MAGIC;
804 statp->f_namelen = MAXNAMELEN - 1;
806 id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
807 statp->f_fsid = u64_to_fsid(id);
809 icount = percpu_counter_sum(&mp->m_icount);
810 ifree = percpu_counter_sum(&mp->m_ifree);
811 fdblocks = percpu_counter_sum(&mp->m_fdblocks);
813 spin_lock(&mp->m_sb_lock);
814 statp->f_bsize = sbp->sb_blocksize;
815 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
816 statp->f_blocks = sbp->sb_dblocks - lsize;
817 spin_unlock(&mp->m_sb_lock);
819 /* make sure statp->f_bfree does not underflow */
820 statp->f_bfree = max_t(int64_t, 0,
821 fdblocks - xfs_fdblocks_unavailable(mp));
822 statp->f_bavail = statp->f_bfree;
824 fakeinos = XFS_FSB_TO_INO(mp, statp->f_bfree);
825 statp->f_files = min(icount + fakeinos, (uint64_t)XFS_MAXINUMBER);
826 if (M_IGEO(mp)->maxicount)
827 statp->f_files = min_t(typeof(statp->f_files),
829 M_IGEO(mp)->maxicount);
831 /* If sb_icount overshot maxicount, report actual allocation */
832 statp->f_files = max_t(typeof(statp->f_files),
836 /* make sure statp->f_ffree does not underflow */
837 ffree = statp->f_files - (icount - ifree);
838 statp->f_ffree = max_t(int64_t, ffree, 0);
841 if ((ip->i_diflags & XFS_DIFLAG_PROJINHERIT) &&
842 ((mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))) ==
843 (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))
844 xfs_qm_statvfs(ip, statp);
846 if (XFS_IS_REALTIME_MOUNT(mp) &&
847 (ip->i_diflags & (XFS_DIFLAG_RTINHERIT | XFS_DIFLAG_REALTIME))) {
850 statp->f_blocks = sbp->sb_rblocks;
851 freertx = percpu_counter_sum_positive(&mp->m_frextents);
852 statp->f_bavail = statp->f_bfree = freertx * sbp->sb_rextsize;
859 xfs_save_resvblks(struct xfs_mount *mp)
861 uint64_t resblks = 0;
863 mp->m_resblks_save = mp->m_resblks;
864 xfs_reserve_blocks(mp, &resblks, NULL);
868 xfs_restore_resvblks(struct xfs_mount *mp)
872 if (mp->m_resblks_save) {
873 resblks = mp->m_resblks_save;
874 mp->m_resblks_save = 0;
876 resblks = xfs_default_resblks(mp);
878 xfs_reserve_blocks(mp, &resblks, NULL);
882 * Second stage of a freeze. The data is already frozen so we only
883 * need to take care of the metadata. Once that's done sync the superblock
884 * to the log to dirty it in case of a crash while frozen. This ensures that we
885 * will recover the unlinked inode lists on the next mount.
889 struct super_block *sb)
891 struct xfs_mount *mp = XFS_M(sb);
896 * The filesystem is now frozen far enough that memory reclaim
897 * cannot safely operate on the filesystem. Hence we need to
898 * set a GFP_NOFS context here to avoid recursion deadlocks.
900 flags = memalloc_nofs_save();
901 xfs_save_resvblks(mp);
902 ret = xfs_log_quiesce(mp);
903 memalloc_nofs_restore(flags);
906 * For read-write filesystems, we need to restart the inodegc on error
907 * because we stopped it at SB_FREEZE_PAGEFAULT level and a thaw is not
908 * going to be run to restart it now. We are at SB_FREEZE_FS level
909 * here, so we can restart safely without racing with a stop in
912 if (ret && !xfs_is_readonly(mp)) {
913 xfs_blockgc_start(mp);
914 xfs_inodegc_start(mp);
922 struct super_block *sb)
924 struct xfs_mount *mp = XFS_M(sb);
926 xfs_restore_resvblks(mp);
927 xfs_log_work_queue(mp);
930 * Don't reactivate the inodegc worker on a readonly filesystem because
931 * inodes are sent directly to reclaim. Don't reactivate the blockgc
932 * worker because there are no speculative preallocations on a readonly
935 if (!xfs_is_readonly(mp)) {
936 xfs_blockgc_start(mp);
937 xfs_inodegc_start(mp);
944 * This function fills in xfs_mount_t fields based on mount args.
945 * Note: the superblock _has_ now been read in.
949 struct xfs_mount *mp)
951 /* Fail a mount where the logbuf is smaller than the log stripe */
952 if (xfs_has_logv2(mp)) {
953 if (mp->m_logbsize <= 0 &&
954 mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE) {
955 mp->m_logbsize = mp->m_sb.sb_logsunit;
956 } else if (mp->m_logbsize > 0 &&
957 mp->m_logbsize < mp->m_sb.sb_logsunit) {
959 "logbuf size must be greater than or equal to log stripe size");
963 /* Fail a mount if the logbuf is larger than 32K */
964 if (mp->m_logbsize > XLOG_BIG_RECORD_BSIZE) {
966 "logbuf size for version 1 logs must be 16K or 32K");
972 * V5 filesystems always use attr2 format for attributes.
974 if (xfs_has_crc(mp) && xfs_has_noattr2(mp)) {
975 xfs_warn(mp, "Cannot mount a V5 filesystem as noattr2. "
976 "attr2 is always enabled for V5 filesystems.");
981 * prohibit r/w mounts of read-only filesystems
983 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !xfs_is_readonly(mp)) {
985 "cannot mount a read-only filesystem as read-write");
989 if ((mp->m_qflags & XFS_GQUOTA_ACCT) &&
990 (mp->m_qflags & XFS_PQUOTA_ACCT) &&
991 !xfs_has_pquotino(mp)) {
993 "Super block does not support project and group quota together");
1001 xfs_init_percpu_counters(
1002 struct xfs_mount *mp)
1006 error = percpu_counter_init(&mp->m_icount, 0, GFP_KERNEL);
1010 error = percpu_counter_init(&mp->m_ifree, 0, GFP_KERNEL);
1014 error = percpu_counter_init(&mp->m_fdblocks, 0, GFP_KERNEL);
1018 error = percpu_counter_init(&mp->m_delalloc_blks, 0, GFP_KERNEL);
1022 error = percpu_counter_init(&mp->m_frextents, 0, GFP_KERNEL);
1029 percpu_counter_destroy(&mp->m_delalloc_blks);
1031 percpu_counter_destroy(&mp->m_fdblocks);
1033 percpu_counter_destroy(&mp->m_ifree);
1035 percpu_counter_destroy(&mp->m_icount);
1040 xfs_reinit_percpu_counters(
1041 struct xfs_mount *mp)
1043 percpu_counter_set(&mp->m_icount, mp->m_sb.sb_icount);
1044 percpu_counter_set(&mp->m_ifree, mp->m_sb.sb_ifree);
1045 percpu_counter_set(&mp->m_fdblocks, mp->m_sb.sb_fdblocks);
1046 percpu_counter_set(&mp->m_frextents, mp->m_sb.sb_frextents);
1050 xfs_destroy_percpu_counters(
1051 struct xfs_mount *mp)
1053 percpu_counter_destroy(&mp->m_icount);
1054 percpu_counter_destroy(&mp->m_ifree);
1055 percpu_counter_destroy(&mp->m_fdblocks);
1056 ASSERT(xfs_is_shutdown(mp) ||
1057 percpu_counter_sum(&mp->m_delalloc_blks) == 0);
1058 percpu_counter_destroy(&mp->m_delalloc_blks);
1059 percpu_counter_destroy(&mp->m_frextents);
1063 xfs_inodegc_init_percpu(
1064 struct xfs_mount *mp)
1066 struct xfs_inodegc *gc;
1069 mp->m_inodegc = alloc_percpu(struct xfs_inodegc);
1073 for_each_possible_cpu(cpu) {
1074 gc = per_cpu_ptr(mp->m_inodegc, cpu);
1075 init_llist_head(&gc->list);
1077 INIT_WORK(&gc->work, xfs_inodegc_worker);
1083 xfs_inodegc_free_percpu(
1084 struct xfs_mount *mp)
1088 free_percpu(mp->m_inodegc);
1093 struct super_block *sb)
1095 struct xfs_mount *mp = XFS_M(sb);
1097 /* if ->fill_super failed, we have no mount to tear down */
1101 xfs_notice(mp, "Unmounting Filesystem");
1102 xfs_filestream_unmount(mp);
1106 free_percpu(mp->m_stats.xs_stats);
1107 xfs_mount_list_del(mp);
1108 xfs_inodegc_free_percpu(mp);
1109 xfs_destroy_percpu_counters(mp);
1110 xfs_destroy_mount_workqueues(mp);
1111 xfs_close_devices(mp);
1113 sb->s_fs_info = NULL;
1118 xfs_fs_nr_cached_objects(
1119 struct super_block *sb,
1120 struct shrink_control *sc)
1122 /* Paranoia: catch incorrect calls during mount setup or teardown */
1123 if (WARN_ON_ONCE(!sb->s_fs_info))
1125 return xfs_reclaim_inodes_count(XFS_M(sb));
1129 xfs_fs_free_cached_objects(
1130 struct super_block *sb,
1131 struct shrink_control *sc)
1133 return xfs_reclaim_inodes_nr(XFS_M(sb), sc->nr_to_scan);
1136 static const struct super_operations xfs_super_operations = {
1137 .alloc_inode = xfs_fs_alloc_inode,
1138 .destroy_inode = xfs_fs_destroy_inode,
1139 .dirty_inode = xfs_fs_dirty_inode,
1140 .drop_inode = xfs_fs_drop_inode,
1141 .put_super = xfs_fs_put_super,
1142 .sync_fs = xfs_fs_sync_fs,
1143 .freeze_fs = xfs_fs_freeze,
1144 .unfreeze_fs = xfs_fs_unfreeze,
1145 .statfs = xfs_fs_statfs,
1146 .show_options = xfs_fs_show_options,
1147 .nr_cached_objects = xfs_fs_nr_cached_objects,
1148 .free_cached_objects = xfs_fs_free_cached_objects,
1157 int last, shift_left_factor = 0, _res;
1161 value = kstrdup(s, GFP_KERNEL);
1165 last = strlen(value) - 1;
1166 if (value[last] == 'K' || value[last] == 'k') {
1167 shift_left_factor = 10;
1170 if (value[last] == 'M' || value[last] == 'm') {
1171 shift_left_factor = 20;
1174 if (value[last] == 'G' || value[last] == 'g') {
1175 shift_left_factor = 30;
1179 if (kstrtoint(value, base, &_res))
1182 *res = _res << shift_left_factor;
1187 xfs_fs_warn_deprecated(
1188 struct fs_context *fc,
1189 struct fs_parameter *param,
1193 /* Don't print the warning if reconfiguring and current mount point
1194 * already had the flag set
1196 if ((fc->purpose & FS_CONTEXT_FOR_RECONFIGURE) &&
1197 !!(XFS_M(fc->root->d_sb)->m_features & flag) == value)
1199 xfs_warn(fc->s_fs_info, "%s mount option is deprecated.", param->key);
1203 * Set mount state from a mount option.
1205 * NOTE: mp->m_super is NULL here!
1209 struct fs_context *fc,
1210 struct fs_parameter *param)
1212 struct xfs_mount *parsing_mp = fc->s_fs_info;
1213 struct fs_parse_result result;
1217 opt = fs_parse(fc, xfs_fs_parameters, param, &result);
1223 parsing_mp->m_logbufs = result.uint_32;
1226 if (suffix_kstrtoint(param->string, 10, &parsing_mp->m_logbsize))
1230 kfree(parsing_mp->m_logname);
1231 parsing_mp->m_logname = kstrdup(param->string, GFP_KERNEL);
1232 if (!parsing_mp->m_logname)
1236 kfree(parsing_mp->m_rtname);
1237 parsing_mp->m_rtname = kstrdup(param->string, GFP_KERNEL);
1238 if (!parsing_mp->m_rtname)
1242 if (suffix_kstrtoint(param->string, 10, &size))
1244 parsing_mp->m_allocsize_log = ffs(size) - 1;
1245 parsing_mp->m_features |= XFS_FEAT_ALLOCSIZE;
1249 parsing_mp->m_features |= XFS_FEAT_GRPID;
1252 case Opt_sysvgroups:
1253 parsing_mp->m_features &= ~XFS_FEAT_GRPID;
1256 parsing_mp->m_features |= XFS_FEAT_WSYNC;
1258 case Opt_norecovery:
1259 parsing_mp->m_features |= XFS_FEAT_NORECOVERY;
1262 parsing_mp->m_features |= XFS_FEAT_NOALIGN;
1265 parsing_mp->m_features |= XFS_FEAT_SWALLOC;
1268 parsing_mp->m_dalign = result.uint_32;
1271 parsing_mp->m_swidth = result.uint_32;
1274 parsing_mp->m_features |= XFS_FEAT_SMALL_INUMS;
1277 parsing_mp->m_features &= ~XFS_FEAT_SMALL_INUMS;
1280 parsing_mp->m_features |= XFS_FEAT_NOUUID;
1283 parsing_mp->m_features |= XFS_FEAT_LARGE_IOSIZE;
1286 parsing_mp->m_features &= ~XFS_FEAT_LARGE_IOSIZE;
1288 case Opt_filestreams:
1289 parsing_mp->m_features |= XFS_FEAT_FILESTREAMS;
1292 parsing_mp->m_qflags &= ~XFS_ALL_QUOTA_ACCT;
1293 parsing_mp->m_qflags &= ~XFS_ALL_QUOTA_ENFD;
1298 parsing_mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ENFD);
1300 case Opt_qnoenforce:
1301 case Opt_uqnoenforce:
1302 parsing_mp->m_qflags |= XFS_UQUOTA_ACCT;
1303 parsing_mp->m_qflags &= ~XFS_UQUOTA_ENFD;
1307 parsing_mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ENFD);
1309 case Opt_pqnoenforce:
1310 parsing_mp->m_qflags |= XFS_PQUOTA_ACCT;
1311 parsing_mp->m_qflags &= ~XFS_PQUOTA_ENFD;
1315 parsing_mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ENFD);
1317 case Opt_gqnoenforce:
1318 parsing_mp->m_qflags |= XFS_GQUOTA_ACCT;
1319 parsing_mp->m_qflags &= ~XFS_GQUOTA_ENFD;
1322 parsing_mp->m_features |= XFS_FEAT_DISCARD;
1325 parsing_mp->m_features &= ~XFS_FEAT_DISCARD;
1327 #ifdef CONFIG_FS_DAX
1329 xfs_mount_set_dax_mode(parsing_mp, XFS_DAX_ALWAYS);
1332 xfs_mount_set_dax_mode(parsing_mp, result.uint_32);
1335 /* Following mount options will be removed in September 2025 */
1337 xfs_fs_warn_deprecated(fc, param, XFS_FEAT_IKEEP, true);
1338 parsing_mp->m_features |= XFS_FEAT_IKEEP;
1341 xfs_fs_warn_deprecated(fc, param, XFS_FEAT_IKEEP, false);
1342 parsing_mp->m_features &= ~XFS_FEAT_IKEEP;
1345 xfs_fs_warn_deprecated(fc, param, XFS_FEAT_ATTR2, true);
1346 parsing_mp->m_features |= XFS_FEAT_ATTR2;
1349 xfs_fs_warn_deprecated(fc, param, XFS_FEAT_NOATTR2, true);
1350 parsing_mp->m_features |= XFS_FEAT_NOATTR2;
1353 xfs_warn(parsing_mp, "unknown mount option [%s].", param->key);
1361 xfs_fs_validate_params(
1362 struct xfs_mount *mp)
1364 /* No recovery flag requires a read-only mount */
1365 if (xfs_has_norecovery(mp) && !xfs_is_readonly(mp)) {
1366 xfs_warn(mp, "no-recovery mounts must be read-only.");
1371 * We have not read the superblock at this point, so only the attr2
1372 * mount option can set the attr2 feature by this stage.
1374 if (xfs_has_attr2(mp) && xfs_has_noattr2(mp)) {
1375 xfs_warn(mp, "attr2 and noattr2 cannot both be specified.");
1380 if (xfs_has_noalign(mp) && (mp->m_dalign || mp->m_swidth)) {
1382 "sunit and swidth options incompatible with the noalign option");
1386 if (!IS_ENABLED(CONFIG_XFS_QUOTA) && mp->m_qflags != 0) {
1387 xfs_warn(mp, "quota support not available in this kernel.");
1391 if ((mp->m_dalign && !mp->m_swidth) ||
1392 (!mp->m_dalign && mp->m_swidth)) {
1393 xfs_warn(mp, "sunit and swidth must be specified together");
1397 if (mp->m_dalign && (mp->m_swidth % mp->m_dalign != 0)) {
1399 "stripe width (%d) must be a multiple of the stripe unit (%d)",
1400 mp->m_swidth, mp->m_dalign);
1404 if (mp->m_logbufs != -1 &&
1405 mp->m_logbufs != 0 &&
1406 (mp->m_logbufs < XLOG_MIN_ICLOGS ||
1407 mp->m_logbufs > XLOG_MAX_ICLOGS)) {
1408 xfs_warn(mp, "invalid logbufs value: %d [not %d-%d]",
1409 mp->m_logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
1413 if (mp->m_logbsize != -1 &&
1414 mp->m_logbsize != 0 &&
1415 (mp->m_logbsize < XLOG_MIN_RECORD_BSIZE ||
1416 mp->m_logbsize > XLOG_MAX_RECORD_BSIZE ||
1417 !is_power_of_2(mp->m_logbsize))) {
1419 "invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
1424 if (xfs_has_allocsize(mp) &&
1425 (mp->m_allocsize_log > XFS_MAX_IO_LOG ||
1426 mp->m_allocsize_log < XFS_MIN_IO_LOG)) {
1427 xfs_warn(mp, "invalid log iosize: %d [not %d-%d]",
1428 mp->m_allocsize_log, XFS_MIN_IO_LOG, XFS_MAX_IO_LOG);
1437 struct super_block *sb,
1438 struct fs_context *fc)
1440 struct xfs_mount *mp = sb->s_fs_info;
1442 int flags = 0, error;
1446 error = xfs_fs_validate_params(mp);
1448 goto out_free_names;
1450 sb_min_blocksize(sb, BBSIZE);
1451 sb->s_xattr = xfs_xattr_handlers;
1452 sb->s_export_op = &xfs_export_operations;
1453 #ifdef CONFIG_XFS_QUOTA
1454 sb->s_qcop = &xfs_quotactl_operations;
1455 sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ;
1457 sb->s_op = &xfs_super_operations;
1460 * Delay mount work if the debug hook is set. This is debug
1461 * instrumention to coordinate simulation of xfs mount failures with
1462 * VFS superblock operations
1464 if (xfs_globals.mount_delay) {
1465 xfs_notice(mp, "Delaying mount for %d seconds.",
1466 xfs_globals.mount_delay);
1467 msleep(xfs_globals.mount_delay * 1000);
1470 if (fc->sb_flags & SB_SILENT)
1471 flags |= XFS_MFSI_QUIET;
1473 error = xfs_open_devices(mp);
1475 goto out_free_names;
1477 error = xfs_init_mount_workqueues(mp);
1479 goto out_close_devices;
1481 error = xfs_init_percpu_counters(mp);
1483 goto out_destroy_workqueues;
1485 error = xfs_inodegc_init_percpu(mp);
1487 goto out_destroy_counters;
1490 * All percpu data structures requiring cleanup when a cpu goes offline
1491 * must be allocated before adding this @mp to the cpu-dead handler's
1494 xfs_mount_list_add(mp);
1496 /* Allocate stats memory before we do operations that might use it */
1497 mp->m_stats.xs_stats = alloc_percpu(struct xfsstats);
1498 if (!mp->m_stats.xs_stats) {
1500 goto out_destroy_inodegc;
1503 error = xfs_readsb(mp, flags);
1505 goto out_free_stats;
1507 error = xfs_finish_flags(mp);
1511 error = xfs_setup_devices(mp);
1515 /* V4 support is undergoing deprecation. */
1516 if (!xfs_has_crc(mp)) {
1517 #ifdef CONFIG_XFS_SUPPORT_V4
1519 "Deprecated V4 format (crc=0) will not be supported after September 2030.");
1522 "Deprecated V4 format (crc=0) not supported by kernel.");
1528 /* Filesystem claims it needs repair, so refuse the mount. */
1529 if (xfs_has_needsrepair(mp)) {
1530 xfs_warn(mp, "Filesystem needs repair. Please run xfs_repair.");
1531 error = -EFSCORRUPTED;
1536 * Don't touch the filesystem if a user tool thinks it owns the primary
1537 * superblock. mkfs doesn't clear the flag from secondary supers, so
1538 * we don't check them at all.
1540 if (mp->m_sb.sb_inprogress) {
1541 xfs_warn(mp, "Offline file system operation in progress!");
1542 error = -EFSCORRUPTED;
1547 * Until this is fixed only page-sized or smaller data blocks work.
1549 if (mp->m_sb.sb_blocksize > PAGE_SIZE) {
1551 "File system with blocksize %d bytes. "
1552 "Only pagesize (%ld) or less will currently work.",
1553 mp->m_sb.sb_blocksize, PAGE_SIZE);
1558 /* Ensure this filesystem fits in the page cache limits */
1559 if (xfs_sb_validate_fsb_count(&mp->m_sb, mp->m_sb.sb_dblocks) ||
1560 xfs_sb_validate_fsb_count(&mp->m_sb, mp->m_sb.sb_rblocks)) {
1562 "file system too large to be mounted on this system.");
1568 * XFS block mappings use 54 bits to store the logical block offset.
1569 * This should suffice to handle the maximum file size that the VFS
1570 * supports (currently 2^63 bytes on 64-bit and ULONG_MAX << PAGE_SHIFT
1571 * bytes on 32-bit), but as XFS and VFS have gotten the s_maxbytes
1572 * calculation wrong on 32-bit kernels in the past, we'll add a WARN_ON
1573 * to check this assertion.
1575 * Avoid integer overflow by comparing the maximum bmbt offset to the
1576 * maximum pagecache offset in units of fs blocks.
1578 if (!xfs_verify_fileoff(mp, XFS_B_TO_FSBT(mp, MAX_LFS_FILESIZE))) {
1580 "MAX_LFS_FILESIZE block offset (%llu) exceeds extent map maximum (%llu)!",
1581 XFS_B_TO_FSBT(mp, MAX_LFS_FILESIZE),
1587 error = xfs_filestream_mount(mp);
1592 * we must configure the block size in the superblock before we run the
1593 * full mount process as the mount process can lookup and cache inodes.
1595 sb->s_magic = XFS_SUPER_MAGIC;
1596 sb->s_blocksize = mp->m_sb.sb_blocksize;
1597 sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
1598 sb->s_maxbytes = MAX_LFS_FILESIZE;
1599 sb->s_max_links = XFS_MAXLINK;
1600 sb->s_time_gran = 1;
1601 if (xfs_has_bigtime(mp)) {
1602 sb->s_time_min = xfs_bigtime_to_unix(XFS_BIGTIME_TIME_MIN);
1603 sb->s_time_max = xfs_bigtime_to_unix(XFS_BIGTIME_TIME_MAX);
1605 sb->s_time_min = XFS_LEGACY_TIME_MIN;
1606 sb->s_time_max = XFS_LEGACY_TIME_MAX;
1608 trace_xfs_inode_timestamp_range(mp, sb->s_time_min, sb->s_time_max);
1609 sb->s_iflags |= SB_I_CGROUPWB;
1611 set_posix_acl_flag(sb);
1613 /* version 5 superblocks support inode version counters. */
1614 if (xfs_has_crc(mp))
1615 sb->s_flags |= SB_I_VERSION;
1617 if (xfs_has_dax_always(mp)) {
1618 error = xfs_setup_dax_always(mp);
1620 goto out_filestream_unmount;
1623 if (xfs_has_discard(mp) && !bdev_max_discard_sectors(sb->s_bdev)) {
1625 "mounting with \"discard\" option, but the device does not support discard");
1626 mp->m_features &= ~XFS_FEAT_DISCARD;
1629 if (xfs_has_reflink(mp)) {
1630 if (mp->m_sb.sb_rblocks) {
1632 "reflink not compatible with realtime device!");
1634 goto out_filestream_unmount;
1637 if (xfs_globals.always_cow) {
1638 xfs_info(mp, "using DEBUG-only always_cow mode.");
1639 mp->m_always_cow = true;
1643 if (xfs_has_rmapbt(mp) && mp->m_sb.sb_rblocks) {
1645 "reverse mapping btree not compatible with realtime device!");
1647 goto out_filestream_unmount;
1650 if (xfs_has_large_extent_counts(mp))
1652 "EXPERIMENTAL Large extent counts feature in use. Use at your own risk!");
1654 error = xfs_mountfs(mp);
1656 goto out_filestream_unmount;
1658 root = igrab(VFS_I(mp->m_rootip));
1663 sb->s_root = d_make_root(root);
1671 out_filestream_unmount:
1672 xfs_filestream_unmount(mp);
1676 free_percpu(mp->m_stats.xs_stats);
1677 out_destroy_inodegc:
1678 xfs_mount_list_del(mp);
1679 xfs_inodegc_free_percpu(mp);
1680 out_destroy_counters:
1681 xfs_destroy_percpu_counters(mp);
1682 out_destroy_workqueues:
1683 xfs_destroy_mount_workqueues(mp);
1685 xfs_close_devices(mp);
1687 sb->s_fs_info = NULL;
1692 xfs_filestream_unmount(mp);
1699 struct fs_context *fc)
1701 return get_tree_bdev(fc, xfs_fs_fill_super);
1706 struct xfs_mount *mp)
1708 struct xfs_sb *sbp = &mp->m_sb;
1711 if (xfs_has_norecovery(mp)) {
1713 "ro->rw transition prohibited on norecovery mount");
1717 if (xfs_sb_is_v5(sbp) &&
1718 xfs_sb_has_ro_compat_feature(sbp, XFS_SB_FEAT_RO_COMPAT_UNKNOWN)) {
1720 "ro->rw transition prohibited on unknown (0x%x) ro-compat filesystem",
1721 (sbp->sb_features_ro_compat &
1722 XFS_SB_FEAT_RO_COMPAT_UNKNOWN));
1726 clear_bit(XFS_OPSTATE_READONLY, &mp->m_opstate);
1729 * If this is the first remount to writeable state we might have some
1730 * superblock changes to update.
1732 if (mp->m_update_sb) {
1733 error = xfs_sync_sb(mp, false);
1735 xfs_warn(mp, "failed to write sb changes");
1738 mp->m_update_sb = false;
1742 * Fill out the reserve pool if it is empty. Use the stashed value if
1743 * it is non-zero, otherwise go with the default.
1745 xfs_restore_resvblks(mp);
1746 xfs_log_work_queue(mp);
1747 xfs_blockgc_start(mp);
1749 /* Create the per-AG metadata reservation pool .*/
1750 error = xfs_fs_reserve_ag_blocks(mp);
1751 if (error && error != -ENOSPC)
1754 /* Re-enable the background inode inactivation worker. */
1755 xfs_inodegc_start(mp);
1762 struct xfs_mount *mp)
1764 struct xfs_icwalk icw = {
1765 .icw_flags = XFS_ICWALK_FLAG_SYNC,
1769 /* Flush all the dirty data to disk. */
1770 error = sync_filesystem(mp->m_super);
1775 * Cancel background eofb scanning so it cannot race with the final
1776 * log force+buftarg wait and deadlock the remount.
1778 xfs_blockgc_stop(mp);
1781 * Clear out all remaining COW staging extents and speculative post-EOF
1782 * preallocations so that we don't leave inodes requiring inactivation
1783 * cleanups during reclaim on a read-only mount. We must process every
1784 * cached inode, so this requires a synchronous cache scan.
1786 error = xfs_blockgc_free_space(mp, &icw);
1788 xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
1793 * Stop the inodegc background worker. xfs_fs_reconfigure already
1794 * flushed all pending inodegc work when it sync'd the filesystem.
1795 * The VFS holds s_umount, so we know that inodes cannot enter
1796 * xfs_fs_destroy_inode during a remount operation. In readonly mode
1797 * we send inodes straight to reclaim, so no inodes will be queued.
1799 xfs_inodegc_stop(mp);
1801 /* Free the per-AG metadata reservation pool. */
1802 error = xfs_fs_unreserve_ag_blocks(mp);
1804 xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
1809 * Before we sync the metadata, we need to free up the reserve block
1810 * pool so that the used block count in the superblock on disk is
1811 * correct at the end of the remount. Stash the current* reserve pool
1812 * size so that if we get remounted rw, we can return it to the same
1815 xfs_save_resvblks(mp);
1818 set_bit(XFS_OPSTATE_READONLY, &mp->m_opstate);
1824 * Logically we would return an error here to prevent users from believing
1825 * they might have changed mount options using remount which can't be changed.
1827 * But unfortunately mount(8) adds all options from mtab and fstab to the mount
1828 * arguments in some cases so we can't blindly reject options, but have to
1829 * check for each specified option if it actually differs from the currently
1830 * set option and only reject it if that's the case.
1832 * Until that is implemented we return success for every remount request, and
1833 * silently ignore all options that we can't actually change.
1837 struct fs_context *fc)
1839 struct xfs_mount *mp = XFS_M(fc->root->d_sb);
1840 struct xfs_mount *new_mp = fc->s_fs_info;
1841 int flags = fc->sb_flags;
1844 /* version 5 superblocks always support version counters. */
1845 if (xfs_has_crc(mp))
1846 fc->sb_flags |= SB_I_VERSION;
1848 error = xfs_fs_validate_params(new_mp);
1852 /* inode32 -> inode64 */
1853 if (xfs_has_small_inums(mp) && !xfs_has_small_inums(new_mp)) {
1854 mp->m_features &= ~XFS_FEAT_SMALL_INUMS;
1855 mp->m_maxagi = xfs_set_inode_alloc(mp, mp->m_sb.sb_agcount);
1858 /* inode64 -> inode32 */
1859 if (!xfs_has_small_inums(mp) && xfs_has_small_inums(new_mp)) {
1860 mp->m_features |= XFS_FEAT_SMALL_INUMS;
1861 mp->m_maxagi = xfs_set_inode_alloc(mp, mp->m_sb.sb_agcount);
1865 if (xfs_is_readonly(mp) && !(flags & SB_RDONLY)) {
1866 error = xfs_remount_rw(mp);
1872 if (!xfs_is_readonly(mp) && (flags & SB_RDONLY)) {
1873 error = xfs_remount_ro(mp);
1881 static void xfs_fs_free(
1882 struct fs_context *fc)
1884 struct xfs_mount *mp = fc->s_fs_info;
1887 * mp is stored in the fs_context when it is initialized.
1888 * mp is transferred to the superblock on a successful mount,
1889 * but if an error occurs before the transfer we have to free
1896 static const struct fs_context_operations xfs_context_ops = {
1897 .parse_param = xfs_fs_parse_param,
1898 .get_tree = xfs_fs_get_tree,
1899 .reconfigure = xfs_fs_reconfigure,
1900 .free = xfs_fs_free,
1903 static int xfs_init_fs_context(
1904 struct fs_context *fc)
1906 struct xfs_mount *mp;
1908 mp = kmem_alloc(sizeof(struct xfs_mount), KM_ZERO);
1912 spin_lock_init(&mp->m_sb_lock);
1913 spin_lock_init(&mp->m_agirotor_lock);
1914 INIT_RADIX_TREE(&mp->m_perag_tree, GFP_ATOMIC);
1915 spin_lock_init(&mp->m_perag_lock);
1916 mutex_init(&mp->m_growlock);
1917 INIT_WORK(&mp->m_flush_inodes_work, xfs_flush_inodes_worker);
1918 INIT_DELAYED_WORK(&mp->m_reclaim_work, xfs_reclaim_worker);
1919 mp->m_kobj.kobject.kset = xfs_kset;
1921 * We don't create the finobt per-ag space reservation until after log
1922 * recovery, so we must set this to true so that an ifree transaction
1923 * started during log recovery will not depend on space reservations
1924 * for finobt expansion.
1926 mp->m_finobt_nores = true;
1929 * These can be overridden by the mount option parsing.
1932 mp->m_logbsize = -1;
1933 mp->m_allocsize_log = 16; /* 64k */
1936 * Copy binary VFS mount flags we are interested in.
1938 if (fc->sb_flags & SB_RDONLY)
1939 set_bit(XFS_OPSTATE_READONLY, &mp->m_opstate);
1940 if (fc->sb_flags & SB_DIRSYNC)
1941 mp->m_features |= XFS_FEAT_DIRSYNC;
1942 if (fc->sb_flags & SB_SYNCHRONOUS)
1943 mp->m_features |= XFS_FEAT_WSYNC;
1946 fc->ops = &xfs_context_ops;
1951 static struct file_system_type xfs_fs_type = {
1952 .owner = THIS_MODULE,
1954 .init_fs_context = xfs_init_fs_context,
1955 .parameters = xfs_fs_parameters,
1956 .kill_sb = kill_block_super,
1957 .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP,
1959 MODULE_ALIAS_FS("xfs");
1962 xfs_init_caches(void)
1966 xfs_log_ticket_cache = kmem_cache_create("xfs_log_ticket",
1967 sizeof(struct xlog_ticket),
1969 if (!xfs_log_ticket_cache)
1972 error = xfs_btree_init_cur_caches();
1974 goto out_destroy_log_ticket_cache;
1976 error = xfs_defer_init_item_caches();
1978 goto out_destroy_btree_cur_cache;
1980 xfs_da_state_cache = kmem_cache_create("xfs_da_state",
1981 sizeof(struct xfs_da_state),
1983 if (!xfs_da_state_cache)
1984 goto out_destroy_defer_item_cache;
1986 xfs_ifork_cache = kmem_cache_create("xfs_ifork",
1987 sizeof(struct xfs_ifork),
1989 if (!xfs_ifork_cache)
1990 goto out_destroy_da_state_cache;
1992 xfs_trans_cache = kmem_cache_create("xfs_trans",
1993 sizeof(struct xfs_trans),
1995 if (!xfs_trans_cache)
1996 goto out_destroy_ifork_cache;
2000 * The size of the cache-allocated buf log item is the maximum
2001 * size possible under XFS. This wastes a little bit of memory,
2002 * but it is much faster.
2004 xfs_buf_item_cache = kmem_cache_create("xfs_buf_item",
2005 sizeof(struct xfs_buf_log_item),
2007 if (!xfs_buf_item_cache)
2008 goto out_destroy_trans_cache;
2010 xfs_efd_cache = kmem_cache_create("xfs_efd_item",
2011 (sizeof(struct xfs_efd_log_item) +
2012 (XFS_EFD_MAX_FAST_EXTENTS - 1) *
2013 sizeof(struct xfs_extent)),
2016 goto out_destroy_buf_item_cache;
2018 xfs_efi_cache = kmem_cache_create("xfs_efi_item",
2019 (sizeof(struct xfs_efi_log_item) +
2020 (XFS_EFI_MAX_FAST_EXTENTS - 1) *
2021 sizeof(struct xfs_extent)),
2024 goto out_destroy_efd_cache;
2026 xfs_inode_cache = kmem_cache_create("xfs_inode",
2027 sizeof(struct xfs_inode), 0,
2028 (SLAB_HWCACHE_ALIGN |
2029 SLAB_RECLAIM_ACCOUNT |
2030 SLAB_MEM_SPREAD | SLAB_ACCOUNT),
2031 xfs_fs_inode_init_once);
2032 if (!xfs_inode_cache)
2033 goto out_destroy_efi_cache;
2035 xfs_ili_cache = kmem_cache_create("xfs_ili",
2036 sizeof(struct xfs_inode_log_item), 0,
2037 SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD,
2040 goto out_destroy_inode_cache;
2042 xfs_icreate_cache = kmem_cache_create("xfs_icr",
2043 sizeof(struct xfs_icreate_item),
2045 if (!xfs_icreate_cache)
2046 goto out_destroy_ili_cache;
2048 xfs_rud_cache = kmem_cache_create("xfs_rud_item",
2049 sizeof(struct xfs_rud_log_item),
2052 goto out_destroy_icreate_cache;
2054 xfs_rui_cache = kmem_cache_create("xfs_rui_item",
2055 xfs_rui_log_item_sizeof(XFS_RUI_MAX_FAST_EXTENTS),
2058 goto out_destroy_rud_cache;
2060 xfs_cud_cache = kmem_cache_create("xfs_cud_item",
2061 sizeof(struct xfs_cud_log_item),
2064 goto out_destroy_rui_cache;
2066 xfs_cui_cache = kmem_cache_create("xfs_cui_item",
2067 xfs_cui_log_item_sizeof(XFS_CUI_MAX_FAST_EXTENTS),
2070 goto out_destroy_cud_cache;
2072 xfs_bud_cache = kmem_cache_create("xfs_bud_item",
2073 sizeof(struct xfs_bud_log_item),
2076 goto out_destroy_cui_cache;
2078 xfs_bui_cache = kmem_cache_create("xfs_bui_item",
2079 xfs_bui_log_item_sizeof(XFS_BUI_MAX_FAST_EXTENTS),
2082 goto out_destroy_bud_cache;
2084 xfs_attrd_cache = kmem_cache_create("xfs_attrd_item",
2085 sizeof(struct xfs_attrd_log_item),
2087 if (!xfs_attrd_cache)
2088 goto out_destroy_bui_cache;
2090 xfs_attri_cache = kmem_cache_create("xfs_attri_item",
2091 sizeof(struct xfs_attri_log_item),
2093 if (!xfs_attri_cache)
2094 goto out_destroy_attrd_cache;
2098 out_destroy_attrd_cache:
2099 kmem_cache_destroy(xfs_attrd_cache);
2100 out_destroy_bui_cache:
2101 kmem_cache_destroy(xfs_bui_cache);
2102 out_destroy_bud_cache:
2103 kmem_cache_destroy(xfs_bud_cache);
2104 out_destroy_cui_cache:
2105 kmem_cache_destroy(xfs_cui_cache);
2106 out_destroy_cud_cache:
2107 kmem_cache_destroy(xfs_cud_cache);
2108 out_destroy_rui_cache:
2109 kmem_cache_destroy(xfs_rui_cache);
2110 out_destroy_rud_cache:
2111 kmem_cache_destroy(xfs_rud_cache);
2112 out_destroy_icreate_cache:
2113 kmem_cache_destroy(xfs_icreate_cache);
2114 out_destroy_ili_cache:
2115 kmem_cache_destroy(xfs_ili_cache);
2116 out_destroy_inode_cache:
2117 kmem_cache_destroy(xfs_inode_cache);
2118 out_destroy_efi_cache:
2119 kmem_cache_destroy(xfs_efi_cache);
2120 out_destroy_efd_cache:
2121 kmem_cache_destroy(xfs_efd_cache);
2122 out_destroy_buf_item_cache:
2123 kmem_cache_destroy(xfs_buf_item_cache);
2124 out_destroy_trans_cache:
2125 kmem_cache_destroy(xfs_trans_cache);
2126 out_destroy_ifork_cache:
2127 kmem_cache_destroy(xfs_ifork_cache);
2128 out_destroy_da_state_cache:
2129 kmem_cache_destroy(xfs_da_state_cache);
2130 out_destroy_defer_item_cache:
2131 xfs_defer_destroy_item_caches();
2132 out_destroy_btree_cur_cache:
2133 xfs_btree_destroy_cur_caches();
2134 out_destroy_log_ticket_cache:
2135 kmem_cache_destroy(xfs_log_ticket_cache);
2141 xfs_destroy_caches(void)
2144 * Make sure all delayed rcu free are flushed before we
2148 kmem_cache_destroy(xfs_attri_cache);
2149 kmem_cache_destroy(xfs_attrd_cache);
2150 kmem_cache_destroy(xfs_bui_cache);
2151 kmem_cache_destroy(xfs_bud_cache);
2152 kmem_cache_destroy(xfs_cui_cache);
2153 kmem_cache_destroy(xfs_cud_cache);
2154 kmem_cache_destroy(xfs_rui_cache);
2155 kmem_cache_destroy(xfs_rud_cache);
2156 kmem_cache_destroy(xfs_icreate_cache);
2157 kmem_cache_destroy(xfs_ili_cache);
2158 kmem_cache_destroy(xfs_inode_cache);
2159 kmem_cache_destroy(xfs_efi_cache);
2160 kmem_cache_destroy(xfs_efd_cache);
2161 kmem_cache_destroy(xfs_buf_item_cache);
2162 kmem_cache_destroy(xfs_trans_cache);
2163 kmem_cache_destroy(xfs_ifork_cache);
2164 kmem_cache_destroy(xfs_da_state_cache);
2165 xfs_defer_destroy_item_caches();
2166 xfs_btree_destroy_cur_caches();
2167 kmem_cache_destroy(xfs_log_ticket_cache);
2171 xfs_init_workqueues(void)
2174 * The allocation workqueue can be used in memory reclaim situations
2175 * (writepage path), and parallelism is only limited by the number of
2176 * AGs in all the filesystems mounted. Hence use the default large
2177 * max_active value for this workqueue.
2179 xfs_alloc_wq = alloc_workqueue("xfsalloc",
2180 XFS_WQFLAGS(WQ_MEM_RECLAIM | WQ_FREEZABLE), 0);
2184 xfs_discard_wq = alloc_workqueue("xfsdiscard", XFS_WQFLAGS(WQ_UNBOUND),
2186 if (!xfs_discard_wq)
2187 goto out_free_alloc_wq;
2191 destroy_workqueue(xfs_alloc_wq);
2196 xfs_destroy_workqueues(void)
2198 destroy_workqueue(xfs_discard_wq);
2199 destroy_workqueue(xfs_alloc_wq);
2202 #ifdef CONFIG_HOTPLUG_CPU
2207 struct xfs_mount *mp, *n;
2209 spin_lock(&xfs_mount_list_lock);
2210 list_for_each_entry_safe(mp, n, &xfs_mount_list, m_mount_list) {
2211 spin_unlock(&xfs_mount_list_lock);
2212 xfs_inodegc_cpu_dead(mp, cpu);
2213 spin_lock(&xfs_mount_list_lock);
2215 spin_unlock(&xfs_mount_list_lock);
2220 xfs_cpu_hotplug_init(void)
2224 error = cpuhp_setup_state_nocalls(CPUHP_XFS_DEAD, "xfs:dead", NULL,
2228 "Failed to initialise CPU hotplug, error %d. XFS is non-functional.",
2234 xfs_cpu_hotplug_destroy(void)
2236 cpuhp_remove_state_nocalls(CPUHP_XFS_DEAD);
2239 #else /* !CONFIG_HOTPLUG_CPU */
2240 static inline int xfs_cpu_hotplug_init(void) { return 0; }
2241 static inline void xfs_cpu_hotplug_destroy(void) {}
2249 xfs_check_ondisk_structs();
2251 printk(KERN_INFO XFS_VERSION_STRING " with "
2252 XFS_BUILD_OPTIONS " enabled\n");
2256 error = xfs_cpu_hotplug_init();
2260 error = xfs_init_caches();
2262 goto out_destroy_hp;
2264 error = xfs_init_workqueues();
2266 goto out_destroy_caches;
2268 error = xfs_mru_cache_init();
2270 goto out_destroy_wq;
2272 error = xfs_buf_init();
2274 goto out_mru_cache_uninit;
2276 error = xfs_init_procfs();
2278 goto out_buf_terminate;
2280 error = xfs_sysctl_register();
2282 goto out_cleanup_procfs;
2284 xfs_kset = kset_create_and_add("xfs", NULL, fs_kobj);
2287 goto out_sysctl_unregister;
2290 xfsstats.xs_kobj.kobject.kset = xfs_kset;
2292 xfsstats.xs_stats = alloc_percpu(struct xfsstats);
2293 if (!xfsstats.xs_stats) {
2295 goto out_kset_unregister;
2298 error = xfs_sysfs_init(&xfsstats.xs_kobj, &xfs_stats_ktype, NULL,
2301 goto out_free_stats;
2304 xfs_dbg_kobj.kobject.kset = xfs_kset;
2305 error = xfs_sysfs_init(&xfs_dbg_kobj, &xfs_dbg_ktype, NULL, "debug");
2307 goto out_remove_stats_kobj;
2310 error = xfs_qm_init();
2312 goto out_remove_dbg_kobj;
2314 error = register_filesystem(&xfs_fs_type);
2321 out_remove_dbg_kobj:
2323 xfs_sysfs_del(&xfs_dbg_kobj);
2324 out_remove_stats_kobj:
2326 xfs_sysfs_del(&xfsstats.xs_kobj);
2328 free_percpu(xfsstats.xs_stats);
2329 out_kset_unregister:
2330 kset_unregister(xfs_kset);
2331 out_sysctl_unregister:
2332 xfs_sysctl_unregister();
2334 xfs_cleanup_procfs();
2336 xfs_buf_terminate();
2337 out_mru_cache_uninit:
2338 xfs_mru_cache_uninit();
2340 xfs_destroy_workqueues();
2342 xfs_destroy_caches();
2344 xfs_cpu_hotplug_destroy();
2353 unregister_filesystem(&xfs_fs_type);
2355 xfs_sysfs_del(&xfs_dbg_kobj);
2357 xfs_sysfs_del(&xfsstats.xs_kobj);
2358 free_percpu(xfsstats.xs_stats);
2359 kset_unregister(xfs_kset);
2360 xfs_sysctl_unregister();
2361 xfs_cleanup_procfs();
2362 xfs_buf_terminate();
2363 xfs_mru_cache_uninit();
2364 xfs_destroy_workqueues();
2365 xfs_destroy_caches();
2366 xfs_uuid_table_free();
2367 xfs_cpu_hotplug_destroy();
2370 module_init(init_xfs_fs);
2371 module_exit(exit_xfs_fs);
2373 MODULE_AUTHOR("Silicon Graphics, Inc.");
2374 MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
2375 MODULE_LICENSE("GPL");