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"
43 #include "xfs_iunlink_item.h"
44 #include "xfs_dahash_test.h"
45 #include "xfs_rtbitmap.h"
46 #include "xfs_exchmaps_item.h"
47 #include "xfs_parent.h"
48 #include "scrub/stats.h"
49 #include "scrub/rcbag_btree.h"
51 #include <linux/magic.h>
52 #include <linux/fs_context.h>
53 #include <linux/fs_parser.h>
55 static const struct super_operations xfs_super_operations;
57 static struct dentry *xfs_debugfs; /* top-level xfs debugfs dir */
58 static struct kset *xfs_kset; /* top-level xfs sysfs dir */
60 static struct xfs_kobj xfs_dbg_kobj; /* global debug sysfs attrs */
70 xfs_mount_set_dax_mode(
72 enum xfs_dax_mode mode)
76 mp->m_features &= ~(XFS_FEAT_DAX_ALWAYS | XFS_FEAT_DAX_NEVER);
79 mp->m_features |= XFS_FEAT_DAX_ALWAYS;
80 mp->m_features &= ~XFS_FEAT_DAX_NEVER;
83 mp->m_features |= XFS_FEAT_DAX_NEVER;
84 mp->m_features &= ~XFS_FEAT_DAX_ALWAYS;
89 static const struct constant_table dax_param_enums[] = {
90 {"inode", XFS_DAX_INODE },
91 {"always", XFS_DAX_ALWAYS },
92 {"never", XFS_DAX_NEVER },
97 * Table driven mount option parser.
100 Opt_logbufs, Opt_logbsize, Opt_logdev, Opt_rtdev,
101 Opt_wsync, Opt_noalign, Opt_swalloc, Opt_sunit, Opt_swidth, Opt_nouuid,
102 Opt_grpid, Opt_nogrpid, Opt_bsdgroups, Opt_sysvgroups,
103 Opt_allocsize, Opt_norecovery, Opt_inode64, Opt_inode32, Opt_ikeep,
104 Opt_noikeep, Opt_largeio, Opt_nolargeio, Opt_attr2, Opt_noattr2,
105 Opt_filestreams, Opt_quota, Opt_noquota, Opt_usrquota, Opt_grpquota,
106 Opt_prjquota, Opt_uquota, Opt_gquota, Opt_pquota,
107 Opt_uqnoenforce, Opt_gqnoenforce, Opt_pqnoenforce, Opt_qnoenforce,
108 Opt_discard, Opt_nodiscard, Opt_dax, Opt_dax_enum,
111 static const struct fs_parameter_spec xfs_fs_parameters[] = {
112 fsparam_u32("logbufs", Opt_logbufs),
113 fsparam_string("logbsize", Opt_logbsize),
114 fsparam_string("logdev", Opt_logdev),
115 fsparam_string("rtdev", Opt_rtdev),
116 fsparam_flag("wsync", Opt_wsync),
117 fsparam_flag("noalign", Opt_noalign),
118 fsparam_flag("swalloc", Opt_swalloc),
119 fsparam_u32("sunit", Opt_sunit),
120 fsparam_u32("swidth", Opt_swidth),
121 fsparam_flag("nouuid", Opt_nouuid),
122 fsparam_flag("grpid", Opt_grpid),
123 fsparam_flag("nogrpid", Opt_nogrpid),
124 fsparam_flag("bsdgroups", Opt_bsdgroups),
125 fsparam_flag("sysvgroups", Opt_sysvgroups),
126 fsparam_string("allocsize", Opt_allocsize),
127 fsparam_flag("norecovery", Opt_norecovery),
128 fsparam_flag("inode64", Opt_inode64),
129 fsparam_flag("inode32", Opt_inode32),
130 fsparam_flag("ikeep", Opt_ikeep),
131 fsparam_flag("noikeep", Opt_noikeep),
132 fsparam_flag("largeio", Opt_largeio),
133 fsparam_flag("nolargeio", Opt_nolargeio),
134 fsparam_flag("attr2", Opt_attr2),
135 fsparam_flag("noattr2", Opt_noattr2),
136 fsparam_flag("filestreams", Opt_filestreams),
137 fsparam_flag("quota", Opt_quota),
138 fsparam_flag("noquota", Opt_noquota),
139 fsparam_flag("usrquota", Opt_usrquota),
140 fsparam_flag("grpquota", Opt_grpquota),
141 fsparam_flag("prjquota", Opt_prjquota),
142 fsparam_flag("uquota", Opt_uquota),
143 fsparam_flag("gquota", Opt_gquota),
144 fsparam_flag("pquota", Opt_pquota),
145 fsparam_flag("uqnoenforce", Opt_uqnoenforce),
146 fsparam_flag("gqnoenforce", Opt_gqnoenforce),
147 fsparam_flag("pqnoenforce", Opt_pqnoenforce),
148 fsparam_flag("qnoenforce", Opt_qnoenforce),
149 fsparam_flag("discard", Opt_discard),
150 fsparam_flag("nodiscard", Opt_nodiscard),
151 fsparam_flag("dax", Opt_dax),
152 fsparam_enum("dax", Opt_dax_enum, dax_param_enums),
156 struct proc_xfs_info {
166 static struct proc_xfs_info xfs_info_set[] = {
167 /* the few simple ones we can get from the mount struct */
168 { XFS_FEAT_IKEEP, ",ikeep" },
169 { XFS_FEAT_WSYNC, ",wsync" },
170 { XFS_FEAT_NOALIGN, ",noalign" },
171 { XFS_FEAT_SWALLOC, ",swalloc" },
172 { XFS_FEAT_NOUUID, ",nouuid" },
173 { XFS_FEAT_NORECOVERY, ",norecovery" },
174 { XFS_FEAT_ATTR2, ",attr2" },
175 { XFS_FEAT_FILESTREAMS, ",filestreams" },
176 { XFS_FEAT_GRPID, ",grpid" },
177 { XFS_FEAT_DISCARD, ",discard" },
178 { XFS_FEAT_LARGE_IOSIZE, ",largeio" },
179 { XFS_FEAT_DAX_ALWAYS, ",dax=always" },
180 { XFS_FEAT_DAX_NEVER, ",dax=never" },
183 struct xfs_mount *mp = XFS_M(root->d_sb);
184 struct proc_xfs_info *xfs_infop;
186 for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
187 if (mp->m_features & xfs_infop->flag)
188 seq_puts(m, xfs_infop->str);
191 seq_printf(m, ",inode%d", xfs_has_small_inums(mp) ? 32 : 64);
193 if (xfs_has_allocsize(mp))
194 seq_printf(m, ",allocsize=%dk",
195 (1 << mp->m_allocsize_log) >> 10);
197 if (mp->m_logbufs > 0)
198 seq_printf(m, ",logbufs=%d", mp->m_logbufs);
199 if (mp->m_logbsize > 0)
200 seq_printf(m, ",logbsize=%dk", mp->m_logbsize >> 10);
203 seq_show_option(m, "logdev", mp->m_logname);
205 seq_show_option(m, "rtdev", mp->m_rtname);
207 if (mp->m_dalign > 0)
208 seq_printf(m, ",sunit=%d",
209 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
210 if (mp->m_swidth > 0)
211 seq_printf(m, ",swidth=%d",
212 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
214 if (mp->m_qflags & XFS_UQUOTA_ENFD)
215 seq_puts(m, ",usrquota");
216 else if (mp->m_qflags & XFS_UQUOTA_ACCT)
217 seq_puts(m, ",uqnoenforce");
219 if (mp->m_qflags & XFS_PQUOTA_ENFD)
220 seq_puts(m, ",prjquota");
221 else if (mp->m_qflags & XFS_PQUOTA_ACCT)
222 seq_puts(m, ",pqnoenforce");
224 if (mp->m_qflags & XFS_GQUOTA_ENFD)
225 seq_puts(m, ",grpquota");
226 else if (mp->m_qflags & XFS_GQUOTA_ACCT)
227 seq_puts(m, ",gqnoenforce");
229 if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
230 seq_puts(m, ",noquota");
236 xfs_set_inode_alloc_perag(
237 struct xfs_perag *pag,
239 xfs_agnumber_t max_metadata)
241 if (!xfs_is_inode32(pag->pag_mount)) {
242 set_bit(XFS_AGSTATE_ALLOWS_INODES, &pag->pag_opstate);
243 clear_bit(XFS_AGSTATE_PREFERS_METADATA, &pag->pag_opstate);
247 if (ino > XFS_MAXINUMBER_32) {
248 clear_bit(XFS_AGSTATE_ALLOWS_INODES, &pag->pag_opstate);
249 clear_bit(XFS_AGSTATE_PREFERS_METADATA, &pag->pag_opstate);
253 set_bit(XFS_AGSTATE_ALLOWS_INODES, &pag->pag_opstate);
254 if (pag->pag_agno < max_metadata)
255 set_bit(XFS_AGSTATE_PREFERS_METADATA, &pag->pag_opstate);
257 clear_bit(XFS_AGSTATE_PREFERS_METADATA, &pag->pag_opstate);
262 * Set parameters for inode allocation heuristics, taking into account
263 * filesystem size and inode32/inode64 mount options; i.e. specifically
264 * whether or not XFS_FEAT_SMALL_INUMS is set.
266 * Inode allocation patterns are altered only if inode32 is requested
267 * (XFS_FEAT_SMALL_INUMS), and the filesystem is sufficiently large.
268 * If altered, XFS_OPSTATE_INODE32 is set as well.
270 * An agcount independent of that in the mount structure is provided
271 * because in the growfs case, mp->m_sb.sb_agcount is not yet updated
272 * to the potentially higher ag count.
274 * Returns the maximum AG index which may contain inodes.
278 struct xfs_mount *mp,
279 xfs_agnumber_t agcount)
281 xfs_agnumber_t index;
282 xfs_agnumber_t maxagi = 0;
283 xfs_sb_t *sbp = &mp->m_sb;
284 xfs_agnumber_t max_metadata;
289 * Calculate how much should be reserved for inodes to meet
290 * the max inode percentage. Used only for inode32.
292 if (M_IGEO(mp)->maxicount) {
295 icount = sbp->sb_dblocks * sbp->sb_imax_pct;
297 icount += sbp->sb_agblocks - 1;
298 do_div(icount, sbp->sb_agblocks);
299 max_metadata = icount;
301 max_metadata = agcount;
304 /* Get the last possible inode in the filesystem */
305 agino = XFS_AGB_TO_AGINO(mp, sbp->sb_agblocks - 1);
306 ino = XFS_AGINO_TO_INO(mp, agcount - 1, agino);
309 * If user asked for no more than 32-bit inodes, and the fs is
310 * sufficiently large, set XFS_OPSTATE_INODE32 if we must alter
311 * the allocator to accommodate the request.
313 if (xfs_has_small_inums(mp) && ino > XFS_MAXINUMBER_32)
314 set_bit(XFS_OPSTATE_INODE32, &mp->m_opstate);
316 clear_bit(XFS_OPSTATE_INODE32, &mp->m_opstate);
318 for (index = 0; index < agcount; index++) {
319 struct xfs_perag *pag;
321 ino = XFS_AGINO_TO_INO(mp, index, agino);
323 pag = xfs_perag_get(mp, index);
324 if (xfs_set_inode_alloc_perag(pag, ino, max_metadata))
329 return xfs_is_inode32(mp) ? maxagi : agcount;
333 xfs_setup_dax_always(
334 struct xfs_mount *mp)
336 if (!mp->m_ddev_targp->bt_daxdev &&
337 (!mp->m_rtdev_targp || !mp->m_rtdev_targp->bt_daxdev)) {
339 "DAX unsupported by block device. Turning off DAX.");
343 if (mp->m_super->s_blocksize != PAGE_SIZE) {
345 "DAX not supported for blocksize. Turning off DAX.");
349 if (xfs_has_reflink(mp) &&
350 bdev_is_partition(mp->m_ddev_targp->bt_bdev)) {
352 "DAX and reflink cannot work with multi-partitions!");
359 xfs_mount_set_dax_mode(mp, XFS_DAX_NEVER);
367 struct file **bdev_filep)
371 *bdev_filep = bdev_file_open_by_path(name,
372 BLK_OPEN_READ | BLK_OPEN_WRITE | BLK_OPEN_RESTRICT_WRITES,
373 mp->m_super, &fs_holder_ops);
374 if (IS_ERR(*bdev_filep)) {
375 error = PTR_ERR(*bdev_filep);
377 xfs_warn(mp, "Invalid device [%s], error=%d", name, error);
384 xfs_shutdown_devices(
385 struct xfs_mount *mp)
388 * Udev is triggered whenever anyone closes a block device or unmounts
389 * a file systemm on a block device.
390 * The default udev rules invoke blkid to read the fs super and create
391 * symlinks to the bdev under /dev/disk. For this, it uses buffered
392 * reads through the page cache.
394 * xfs_db also uses buffered reads to examine metadata. There is no
395 * coordination between xfs_db and udev, which means that they can run
396 * concurrently. Note there is no coordination between the kernel and
399 * On a system with 64k pages, the page cache can cache the superblock
400 * and the root inode (and hence the root directory) with the same 64k
401 * page. If udev spawns blkid after the mkfs and the system is busy
402 * enough that it is still running when xfs_db starts up, they'll both
403 * read from the same page in the pagecache.
405 * The unmount writes updated inode metadata to disk directly. The XFS
406 * buffer cache does not use the bdev pagecache, so it needs to
407 * invalidate that pagecache on unmount. If the above scenario occurs,
408 * the pagecache no longer reflects what's on disk, xfs_db reads the
409 * stale metadata, and fails to find /a. Most of the time this succeeds
410 * because closing a bdev invalidates the page cache, but when processes
411 * race, everyone loses.
413 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
414 blkdev_issue_flush(mp->m_logdev_targp->bt_bdev);
415 invalidate_bdev(mp->m_logdev_targp->bt_bdev);
417 if (mp->m_rtdev_targp) {
418 blkdev_issue_flush(mp->m_rtdev_targp->bt_bdev);
419 invalidate_bdev(mp->m_rtdev_targp->bt_bdev);
421 blkdev_issue_flush(mp->m_ddev_targp->bt_bdev);
422 invalidate_bdev(mp->m_ddev_targp->bt_bdev);
426 * The file system configurations are:
427 * (1) device (partition) with data and internal log
428 * (2) logical volume with data and log subvolumes.
429 * (3) logical volume with data, log, and realtime subvolumes.
431 * We only have to handle opening the log and realtime volumes here if
432 * they are present. The data subvolume has already been opened by
433 * get_sb_bdev() and is stored in sb->s_bdev.
437 struct xfs_mount *mp)
439 struct super_block *sb = mp->m_super;
440 struct block_device *ddev = sb->s_bdev;
441 struct file *logdev_file = NULL, *rtdev_file = NULL;
445 * Open real time and log devices - order is important.
448 error = xfs_blkdev_get(mp, mp->m_logname, &logdev_file);
454 error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev_file);
456 goto out_close_logdev;
458 if (file_bdev(rtdev_file) == ddev ||
460 file_bdev(rtdev_file) == file_bdev(logdev_file))) {
462 "Cannot mount filesystem with identical rtdev and ddev/logdev.");
464 goto out_close_rtdev;
469 * Setup xfs_mount buffer target pointers
472 mp->m_ddev_targp = xfs_alloc_buftarg(mp, sb->s_bdev_file);
473 if (!mp->m_ddev_targp)
474 goto out_close_rtdev;
477 mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev_file);
478 if (!mp->m_rtdev_targp)
479 goto out_free_ddev_targ;
482 if (logdev_file && file_bdev(logdev_file) != ddev) {
483 mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev_file);
484 if (!mp->m_logdev_targp)
485 goto out_free_rtdev_targ;
487 mp->m_logdev_targp = mp->m_ddev_targp;
488 /* Handle won't be used, drop it */
490 bdev_fput(logdev_file);
496 if (mp->m_rtdev_targp)
497 xfs_free_buftarg(mp->m_rtdev_targp);
499 xfs_free_buftarg(mp->m_ddev_targp);
502 bdev_fput(rtdev_file);
505 bdev_fput(logdev_file);
510 * Setup xfs_mount buffer target pointers based on superblock
514 struct xfs_mount *mp)
518 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_sectsize);
522 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
523 unsigned int log_sector_size = BBSIZE;
525 if (xfs_has_sector(mp))
526 log_sector_size = mp->m_sb.sb_logsectsize;
527 error = xfs_setsize_buftarg(mp->m_logdev_targp,
532 if (mp->m_rtdev_targp) {
533 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
534 mp->m_sb.sb_sectsize);
543 xfs_init_mount_workqueues(
544 struct xfs_mount *mp)
546 mp->m_buf_workqueue = alloc_workqueue("xfs-buf/%s",
547 XFS_WQFLAGS(WQ_FREEZABLE | WQ_MEM_RECLAIM),
548 1, mp->m_super->s_id);
549 if (!mp->m_buf_workqueue)
552 mp->m_unwritten_workqueue = alloc_workqueue("xfs-conv/%s",
553 XFS_WQFLAGS(WQ_FREEZABLE | WQ_MEM_RECLAIM),
554 0, mp->m_super->s_id);
555 if (!mp->m_unwritten_workqueue)
556 goto out_destroy_buf;
558 mp->m_reclaim_workqueue = alloc_workqueue("xfs-reclaim/%s",
559 XFS_WQFLAGS(WQ_FREEZABLE | WQ_MEM_RECLAIM),
560 0, mp->m_super->s_id);
561 if (!mp->m_reclaim_workqueue)
562 goto out_destroy_unwritten;
564 mp->m_blockgc_wq = alloc_workqueue("xfs-blockgc/%s",
565 XFS_WQFLAGS(WQ_UNBOUND | WQ_FREEZABLE | WQ_MEM_RECLAIM),
566 0, mp->m_super->s_id);
567 if (!mp->m_blockgc_wq)
568 goto out_destroy_reclaim;
570 mp->m_inodegc_wq = alloc_workqueue("xfs-inodegc/%s",
571 XFS_WQFLAGS(WQ_FREEZABLE | WQ_MEM_RECLAIM),
572 1, mp->m_super->s_id);
573 if (!mp->m_inodegc_wq)
574 goto out_destroy_blockgc;
576 mp->m_sync_workqueue = alloc_workqueue("xfs-sync/%s",
577 XFS_WQFLAGS(WQ_FREEZABLE), 0, mp->m_super->s_id);
578 if (!mp->m_sync_workqueue)
579 goto out_destroy_inodegc;
584 destroy_workqueue(mp->m_inodegc_wq);
586 destroy_workqueue(mp->m_blockgc_wq);
588 destroy_workqueue(mp->m_reclaim_workqueue);
589 out_destroy_unwritten:
590 destroy_workqueue(mp->m_unwritten_workqueue);
592 destroy_workqueue(mp->m_buf_workqueue);
598 xfs_destroy_mount_workqueues(
599 struct xfs_mount *mp)
601 destroy_workqueue(mp->m_sync_workqueue);
602 destroy_workqueue(mp->m_blockgc_wq);
603 destroy_workqueue(mp->m_inodegc_wq);
604 destroy_workqueue(mp->m_reclaim_workqueue);
605 destroy_workqueue(mp->m_unwritten_workqueue);
606 destroy_workqueue(mp->m_buf_workqueue);
610 xfs_flush_inodes_worker(
611 struct work_struct *work)
613 struct xfs_mount *mp = container_of(work, struct xfs_mount,
614 m_flush_inodes_work);
615 struct super_block *sb = mp->m_super;
617 if (down_read_trylock(&sb->s_umount)) {
619 up_read(&sb->s_umount);
624 * Flush all dirty data to disk. Must not be called while holding an XFS_ILOCK
625 * or a page lock. We use sync_inodes_sb() here to ensure we block while waiting
626 * for IO to complete so that we effectively throttle multiple callers to the
627 * rate at which IO is completing.
631 struct xfs_mount *mp)
634 * If flush_work() returns true then that means we waited for a flush
635 * which was already in progress. Don't bother running another scan.
637 if (flush_work(&mp->m_flush_inodes_work))
640 queue_work(mp->m_sync_workqueue, &mp->m_flush_inodes_work);
641 flush_work(&mp->m_flush_inodes_work);
644 /* Catch misguided souls that try to use this interface on XFS */
645 STATIC struct inode *
647 struct super_block *sb)
654 * Now that the generic code is guaranteed not to be accessing
655 * the linux inode, we can inactivate and reclaim the inode.
658 xfs_fs_destroy_inode(
661 struct xfs_inode *ip = XFS_I(inode);
663 trace_xfs_destroy_inode(ip);
665 ASSERT(!rwsem_is_locked(&inode->i_rwsem));
666 XFS_STATS_INC(ip->i_mount, vn_rele);
667 XFS_STATS_INC(ip->i_mount, vn_remove);
668 xfs_inode_mark_reclaimable(ip);
676 struct xfs_inode *ip = XFS_I(inode);
677 struct xfs_mount *mp = ip->i_mount;
678 struct xfs_trans *tp;
680 if (!(inode->i_sb->s_flags & SB_LAZYTIME))
684 * Only do the timestamp update if the inode is dirty (I_DIRTY_SYNC)
685 * and has dirty timestamp (I_DIRTY_TIME). I_DIRTY_TIME can be passed
686 * in flags possibly together with I_DIRTY_SYNC.
688 if ((flags & ~I_DIRTY_TIME) != I_DIRTY_SYNC || !(flags & I_DIRTY_TIME))
691 if (xfs_trans_alloc(mp, &M_RES(mp)->tr_fsyncts, 0, 0, 0, &tp))
693 xfs_ilock(ip, XFS_ILOCK_EXCL);
694 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
695 xfs_trans_log_inode(tp, ip, XFS_ILOG_TIMESTAMP);
696 xfs_trans_commit(tp);
700 * Slab object creation initialisation for the XFS inode.
701 * This covers only the idempotent fields in the XFS inode;
702 * all other fields need to be initialised on allocation
703 * from the slab. This avoids the need to repeatedly initialise
704 * fields in the xfs inode that left in the initialise state
705 * when freeing the inode.
708 xfs_fs_inode_init_once(
711 struct xfs_inode *ip = inode;
713 memset(ip, 0, sizeof(struct xfs_inode));
716 inode_init_once(VFS_I(ip));
719 atomic_set(&ip->i_pincount, 0);
720 spin_lock_init(&ip->i_flags_lock);
721 init_rwsem(&ip->i_lock);
725 * We do an unlocked check for XFS_IDONTCACHE here because we are already
726 * serialised against cache hits here via the inode->i_lock and igrab() in
727 * xfs_iget_cache_hit(). Hence a lookup that might clear this flag will not be
728 * racing with us, and it avoids needing to grab a spinlock here for every inode
729 * we drop the final reference on.
735 struct xfs_inode *ip = XFS_I(inode);
738 * If this unlinked inode is in the middle of recovery, don't
739 * drop the inode just yet; log recovery will take care of
740 * that. See the comment for this inode flag.
742 if (ip->i_flags & XFS_IRECOVERY) {
743 ASSERT(xlog_recovery_needed(ip->i_mount->m_log));
747 return generic_drop_inode(inode);
752 struct xfs_mount *mp)
754 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp)
755 xfs_free_buftarg(mp->m_logdev_targp);
756 if (mp->m_rtdev_targp)
757 xfs_free_buftarg(mp->m_rtdev_targp);
758 if (mp->m_ddev_targp)
759 xfs_free_buftarg(mp->m_ddev_targp);
761 debugfs_remove(mp->m_debugfs);
763 kfree(mp->m_logname);
769 struct super_block *sb,
772 struct xfs_mount *mp = XFS_M(sb);
775 trace_xfs_fs_sync_fs(mp, __return_address);
778 * Doing anything during the async pass would be counterproductive.
783 error = xfs_log_force(mp, XFS_LOG_SYNC);
789 * The disk must be active because we're syncing.
790 * We schedule log work now (now that the disk is
791 * active) instead of later (when it might not be).
793 flush_delayed_work(&mp->m_log->l_work);
797 * If we are called with page faults frozen out, it means we are about
798 * to freeze the transaction subsystem. Take the opportunity to shut
799 * down inodegc because once SB_FREEZE_FS is set it's too late to
800 * prevent inactivation races with freeze. The fs doesn't get called
801 * again by the freezing process until after SB_FREEZE_FS has been set,
802 * so it's now or never. Same logic applies to speculative allocation
803 * garbage collection.
805 * We don't care if this is a normal syncfs call that does this or
806 * freeze that does this - we can run this multiple times without issue
807 * and we won't race with a restart because a restart can only occur
808 * when the state is either SB_FREEZE_FS or SB_FREEZE_COMPLETE.
810 if (sb->s_writers.frozen == SB_FREEZE_PAGEFAULT) {
811 xfs_inodegc_stop(mp);
812 xfs_blockgc_stop(mp);
820 struct dentry *dentry,
821 struct kstatfs *statp)
823 struct xfs_mount *mp = XFS_M(dentry->d_sb);
824 xfs_sb_t *sbp = &mp->m_sb;
825 struct xfs_inode *ip = XFS_I(d_inode(dentry));
826 uint64_t fakeinos, id;
834 * Expedite background inodegc but don't wait. We do not want to block
835 * here waiting hours for a billion extent file to be truncated.
837 xfs_inodegc_push(mp);
839 statp->f_type = XFS_SUPER_MAGIC;
840 statp->f_namelen = MAXNAMELEN - 1;
842 id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
843 statp->f_fsid = u64_to_fsid(id);
845 icount = percpu_counter_sum(&mp->m_icount);
846 ifree = percpu_counter_sum(&mp->m_ifree);
847 fdblocks = percpu_counter_sum(&mp->m_fdblocks);
849 spin_lock(&mp->m_sb_lock);
850 statp->f_bsize = sbp->sb_blocksize;
851 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
852 statp->f_blocks = sbp->sb_dblocks - lsize;
853 spin_unlock(&mp->m_sb_lock);
855 /* make sure statp->f_bfree does not underflow */
856 statp->f_bfree = max_t(int64_t, 0,
857 fdblocks - xfs_fdblocks_unavailable(mp));
858 statp->f_bavail = statp->f_bfree;
860 fakeinos = XFS_FSB_TO_INO(mp, statp->f_bfree);
861 statp->f_files = min(icount + fakeinos, (uint64_t)XFS_MAXINUMBER);
862 if (M_IGEO(mp)->maxicount)
863 statp->f_files = min_t(typeof(statp->f_files),
865 M_IGEO(mp)->maxicount);
867 /* If sb_icount overshot maxicount, report actual allocation */
868 statp->f_files = max_t(typeof(statp->f_files),
872 /* make sure statp->f_ffree does not underflow */
873 ffree = statp->f_files - (icount - ifree);
874 statp->f_ffree = max_t(int64_t, ffree, 0);
877 if ((ip->i_diflags & XFS_DIFLAG_PROJINHERIT) &&
878 ((mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))) ==
879 (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))
880 xfs_qm_statvfs(ip, statp);
882 if (XFS_IS_REALTIME_MOUNT(mp) &&
883 (ip->i_diflags & (XFS_DIFLAG_RTINHERIT | XFS_DIFLAG_REALTIME))) {
886 statp->f_blocks = sbp->sb_rblocks;
887 freertx = percpu_counter_sum_positive(&mp->m_frextents);
888 statp->f_bavail = statp->f_bfree = xfs_rtx_to_rtb(mp, freertx);
895 xfs_save_resvblks(struct xfs_mount *mp)
897 mp->m_resblks_save = mp->m_resblks;
898 xfs_reserve_blocks(mp, 0);
902 xfs_restore_resvblks(struct xfs_mount *mp)
906 if (mp->m_resblks_save) {
907 resblks = mp->m_resblks_save;
908 mp->m_resblks_save = 0;
910 resblks = xfs_default_resblks(mp);
912 xfs_reserve_blocks(mp, resblks);
916 * Second stage of a freeze. The data is already frozen so we only
917 * need to take care of the metadata. Once that's done sync the superblock
918 * to the log to dirty it in case of a crash while frozen. This ensures that we
919 * will recover the unlinked inode lists on the next mount.
923 struct super_block *sb)
925 struct xfs_mount *mp = XFS_M(sb);
930 * The filesystem is now frozen far enough that memory reclaim
931 * cannot safely operate on the filesystem. Hence we need to
932 * set a GFP_NOFS context here to avoid recursion deadlocks.
934 flags = memalloc_nofs_save();
935 xfs_save_resvblks(mp);
936 ret = xfs_log_quiesce(mp);
937 memalloc_nofs_restore(flags);
940 * For read-write filesystems, we need to restart the inodegc on error
941 * because we stopped it at SB_FREEZE_PAGEFAULT level and a thaw is not
942 * going to be run to restart it now. We are at SB_FREEZE_FS level
943 * here, so we can restart safely without racing with a stop in
946 if (ret && !xfs_is_readonly(mp)) {
947 xfs_blockgc_start(mp);
948 xfs_inodegc_start(mp);
956 struct super_block *sb)
958 struct xfs_mount *mp = XFS_M(sb);
960 xfs_restore_resvblks(mp);
961 xfs_log_work_queue(mp);
964 * Don't reactivate the inodegc worker on a readonly filesystem because
965 * inodes are sent directly to reclaim. Don't reactivate the blockgc
966 * worker because there are no speculative preallocations on a readonly
969 if (!xfs_is_readonly(mp)) {
970 xfs_blockgc_start(mp);
971 xfs_inodegc_start(mp);
978 * This function fills in xfs_mount_t fields based on mount args.
979 * Note: the superblock _has_ now been read in.
983 struct xfs_mount *mp)
985 /* Fail a mount where the logbuf is smaller than the log stripe */
986 if (xfs_has_logv2(mp)) {
987 if (mp->m_logbsize <= 0 &&
988 mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE) {
989 mp->m_logbsize = mp->m_sb.sb_logsunit;
990 } else if (mp->m_logbsize > 0 &&
991 mp->m_logbsize < mp->m_sb.sb_logsunit) {
993 "logbuf size must be greater than or equal to log stripe size");
997 /* Fail a mount if the logbuf is larger than 32K */
998 if (mp->m_logbsize > XLOG_BIG_RECORD_BSIZE) {
1000 "logbuf size for version 1 logs must be 16K or 32K");
1006 * V5 filesystems always use attr2 format for attributes.
1008 if (xfs_has_crc(mp) && xfs_has_noattr2(mp)) {
1009 xfs_warn(mp, "Cannot mount a V5 filesystem as noattr2. "
1010 "attr2 is always enabled for V5 filesystems.");
1015 * prohibit r/w mounts of read-only filesystems
1017 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !xfs_is_readonly(mp)) {
1019 "cannot mount a read-only filesystem as read-write");
1023 if ((mp->m_qflags & XFS_GQUOTA_ACCT) &&
1024 (mp->m_qflags & XFS_PQUOTA_ACCT) &&
1025 !xfs_has_pquotino(mp)) {
1027 "Super block does not support project and group quota together");
1035 xfs_init_percpu_counters(
1036 struct xfs_mount *mp)
1040 error = percpu_counter_init(&mp->m_icount, 0, GFP_KERNEL);
1044 error = percpu_counter_init(&mp->m_ifree, 0, GFP_KERNEL);
1048 error = percpu_counter_init(&mp->m_fdblocks, 0, GFP_KERNEL);
1052 error = percpu_counter_init(&mp->m_delalloc_blks, 0, GFP_KERNEL);
1056 error = percpu_counter_init(&mp->m_delalloc_rtextents, 0, GFP_KERNEL);
1060 error = percpu_counter_init(&mp->m_frextents, 0, GFP_KERNEL);
1062 goto free_delalloc_rt;
1067 percpu_counter_destroy(&mp->m_delalloc_rtextents);
1069 percpu_counter_destroy(&mp->m_delalloc_blks);
1071 percpu_counter_destroy(&mp->m_fdblocks);
1073 percpu_counter_destroy(&mp->m_ifree);
1075 percpu_counter_destroy(&mp->m_icount);
1080 xfs_reinit_percpu_counters(
1081 struct xfs_mount *mp)
1083 percpu_counter_set(&mp->m_icount, mp->m_sb.sb_icount);
1084 percpu_counter_set(&mp->m_ifree, mp->m_sb.sb_ifree);
1085 percpu_counter_set(&mp->m_fdblocks, mp->m_sb.sb_fdblocks);
1086 percpu_counter_set(&mp->m_frextents, mp->m_sb.sb_frextents);
1090 xfs_destroy_percpu_counters(
1091 struct xfs_mount *mp)
1093 percpu_counter_destroy(&mp->m_icount);
1094 percpu_counter_destroy(&mp->m_ifree);
1095 percpu_counter_destroy(&mp->m_fdblocks);
1096 ASSERT(xfs_is_shutdown(mp) ||
1097 percpu_counter_sum(&mp->m_delalloc_rtextents) == 0);
1098 percpu_counter_destroy(&mp->m_delalloc_rtextents);
1099 ASSERT(xfs_is_shutdown(mp) ||
1100 percpu_counter_sum(&mp->m_delalloc_blks) == 0);
1101 percpu_counter_destroy(&mp->m_delalloc_blks);
1102 percpu_counter_destroy(&mp->m_frextents);
1106 xfs_inodegc_init_percpu(
1107 struct xfs_mount *mp)
1109 struct xfs_inodegc *gc;
1112 mp->m_inodegc = alloc_percpu(struct xfs_inodegc);
1116 for_each_possible_cpu(cpu) {
1117 gc = per_cpu_ptr(mp->m_inodegc, cpu);
1120 init_llist_head(&gc->list);
1123 INIT_DELAYED_WORK(&gc->work, xfs_inodegc_worker);
1129 xfs_inodegc_free_percpu(
1130 struct xfs_mount *mp)
1134 free_percpu(mp->m_inodegc);
1139 struct super_block *sb)
1141 struct xfs_mount *mp = XFS_M(sb);
1143 xfs_notice(mp, "Unmounting Filesystem %pU", &mp->m_sb.sb_uuid);
1144 xfs_filestream_unmount(mp);
1148 xchk_mount_stats_free(mp);
1149 free_percpu(mp->m_stats.xs_stats);
1150 xfs_inodegc_free_percpu(mp);
1151 xfs_destroy_percpu_counters(mp);
1152 xfs_destroy_mount_workqueues(mp);
1153 xfs_shutdown_devices(mp);
1157 xfs_fs_nr_cached_objects(
1158 struct super_block *sb,
1159 struct shrink_control *sc)
1161 /* Paranoia: catch incorrect calls during mount setup or teardown */
1162 if (WARN_ON_ONCE(!sb->s_fs_info))
1164 return xfs_reclaim_inodes_count(XFS_M(sb));
1168 xfs_fs_free_cached_objects(
1169 struct super_block *sb,
1170 struct shrink_control *sc)
1172 return xfs_reclaim_inodes_nr(XFS_M(sb), sc->nr_to_scan);
1177 struct super_block *sb)
1179 xfs_force_shutdown(XFS_M(sb), SHUTDOWN_DEVICE_REMOVED);
1182 static const struct super_operations xfs_super_operations = {
1183 .alloc_inode = xfs_fs_alloc_inode,
1184 .destroy_inode = xfs_fs_destroy_inode,
1185 .dirty_inode = xfs_fs_dirty_inode,
1186 .drop_inode = xfs_fs_drop_inode,
1187 .put_super = xfs_fs_put_super,
1188 .sync_fs = xfs_fs_sync_fs,
1189 .freeze_fs = xfs_fs_freeze,
1190 .unfreeze_fs = xfs_fs_unfreeze,
1191 .statfs = xfs_fs_statfs,
1192 .show_options = xfs_fs_show_options,
1193 .nr_cached_objects = xfs_fs_nr_cached_objects,
1194 .free_cached_objects = xfs_fs_free_cached_objects,
1195 .shutdown = xfs_fs_shutdown,
1204 int last, shift_left_factor = 0, _res;
1208 value = kstrdup(s, GFP_KERNEL);
1212 last = strlen(value) - 1;
1213 if (value[last] == 'K' || value[last] == 'k') {
1214 shift_left_factor = 10;
1217 if (value[last] == 'M' || value[last] == 'm') {
1218 shift_left_factor = 20;
1221 if (value[last] == 'G' || value[last] == 'g') {
1222 shift_left_factor = 30;
1226 if (kstrtoint(value, base, &_res))
1229 *res = _res << shift_left_factor;
1234 xfs_fs_warn_deprecated(
1235 struct fs_context *fc,
1236 struct fs_parameter *param,
1240 /* Don't print the warning if reconfiguring and current mount point
1241 * already had the flag set
1243 if ((fc->purpose & FS_CONTEXT_FOR_RECONFIGURE) &&
1244 !!(XFS_M(fc->root->d_sb)->m_features & flag) == value)
1246 xfs_warn(fc->s_fs_info, "%s mount option is deprecated.", param->key);
1250 * Set mount state from a mount option.
1252 * NOTE: mp->m_super is NULL here!
1256 struct fs_context *fc,
1257 struct fs_parameter *param)
1259 struct xfs_mount *parsing_mp = fc->s_fs_info;
1260 struct fs_parse_result result;
1264 opt = fs_parse(fc, xfs_fs_parameters, param, &result);
1270 parsing_mp->m_logbufs = result.uint_32;
1273 if (suffix_kstrtoint(param->string, 10, &parsing_mp->m_logbsize))
1277 kfree(parsing_mp->m_logname);
1278 parsing_mp->m_logname = kstrdup(param->string, GFP_KERNEL);
1279 if (!parsing_mp->m_logname)
1283 kfree(parsing_mp->m_rtname);
1284 parsing_mp->m_rtname = kstrdup(param->string, GFP_KERNEL);
1285 if (!parsing_mp->m_rtname)
1289 if (suffix_kstrtoint(param->string, 10, &size))
1291 parsing_mp->m_allocsize_log = ffs(size) - 1;
1292 parsing_mp->m_features |= XFS_FEAT_ALLOCSIZE;
1296 parsing_mp->m_features |= XFS_FEAT_GRPID;
1299 case Opt_sysvgroups:
1300 parsing_mp->m_features &= ~XFS_FEAT_GRPID;
1303 parsing_mp->m_features |= XFS_FEAT_WSYNC;
1305 case Opt_norecovery:
1306 parsing_mp->m_features |= XFS_FEAT_NORECOVERY;
1309 parsing_mp->m_features |= XFS_FEAT_NOALIGN;
1312 parsing_mp->m_features |= XFS_FEAT_SWALLOC;
1315 parsing_mp->m_dalign = result.uint_32;
1318 parsing_mp->m_swidth = result.uint_32;
1321 parsing_mp->m_features |= XFS_FEAT_SMALL_INUMS;
1324 parsing_mp->m_features &= ~XFS_FEAT_SMALL_INUMS;
1327 parsing_mp->m_features |= XFS_FEAT_NOUUID;
1330 parsing_mp->m_features |= XFS_FEAT_LARGE_IOSIZE;
1333 parsing_mp->m_features &= ~XFS_FEAT_LARGE_IOSIZE;
1335 case Opt_filestreams:
1336 parsing_mp->m_features |= XFS_FEAT_FILESTREAMS;
1339 parsing_mp->m_qflags &= ~XFS_ALL_QUOTA_ACCT;
1340 parsing_mp->m_qflags &= ~XFS_ALL_QUOTA_ENFD;
1345 parsing_mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ENFD);
1347 case Opt_qnoenforce:
1348 case Opt_uqnoenforce:
1349 parsing_mp->m_qflags |= XFS_UQUOTA_ACCT;
1350 parsing_mp->m_qflags &= ~XFS_UQUOTA_ENFD;
1354 parsing_mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ENFD);
1356 case Opt_pqnoenforce:
1357 parsing_mp->m_qflags |= XFS_PQUOTA_ACCT;
1358 parsing_mp->m_qflags &= ~XFS_PQUOTA_ENFD;
1362 parsing_mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ENFD);
1364 case Opt_gqnoenforce:
1365 parsing_mp->m_qflags |= XFS_GQUOTA_ACCT;
1366 parsing_mp->m_qflags &= ~XFS_GQUOTA_ENFD;
1369 parsing_mp->m_features |= XFS_FEAT_DISCARD;
1372 parsing_mp->m_features &= ~XFS_FEAT_DISCARD;
1374 #ifdef CONFIG_FS_DAX
1376 xfs_mount_set_dax_mode(parsing_mp, XFS_DAX_ALWAYS);
1379 xfs_mount_set_dax_mode(parsing_mp, result.uint_32);
1382 /* Following mount options will be removed in September 2025 */
1384 xfs_fs_warn_deprecated(fc, param, XFS_FEAT_IKEEP, true);
1385 parsing_mp->m_features |= XFS_FEAT_IKEEP;
1388 xfs_fs_warn_deprecated(fc, param, XFS_FEAT_IKEEP, false);
1389 parsing_mp->m_features &= ~XFS_FEAT_IKEEP;
1392 xfs_fs_warn_deprecated(fc, param, XFS_FEAT_ATTR2, true);
1393 parsing_mp->m_features |= XFS_FEAT_ATTR2;
1396 xfs_fs_warn_deprecated(fc, param, XFS_FEAT_NOATTR2, true);
1397 parsing_mp->m_features |= XFS_FEAT_NOATTR2;
1400 xfs_warn(parsing_mp, "unknown mount option [%s].", param->key);
1408 xfs_fs_validate_params(
1409 struct xfs_mount *mp)
1411 /* No recovery flag requires a read-only mount */
1412 if (xfs_has_norecovery(mp) && !xfs_is_readonly(mp)) {
1413 xfs_warn(mp, "no-recovery mounts must be read-only.");
1418 * We have not read the superblock at this point, so only the attr2
1419 * mount option can set the attr2 feature by this stage.
1421 if (xfs_has_attr2(mp) && xfs_has_noattr2(mp)) {
1422 xfs_warn(mp, "attr2 and noattr2 cannot both be specified.");
1427 if (xfs_has_noalign(mp) && (mp->m_dalign || mp->m_swidth)) {
1429 "sunit and swidth options incompatible with the noalign option");
1433 if (!IS_ENABLED(CONFIG_XFS_QUOTA) && mp->m_qflags != 0) {
1434 xfs_warn(mp, "quota support not available in this kernel.");
1438 if ((mp->m_dalign && !mp->m_swidth) ||
1439 (!mp->m_dalign && mp->m_swidth)) {
1440 xfs_warn(mp, "sunit and swidth must be specified together");
1444 if (mp->m_dalign && (mp->m_swidth % mp->m_dalign != 0)) {
1446 "stripe width (%d) must be a multiple of the stripe unit (%d)",
1447 mp->m_swidth, mp->m_dalign);
1451 if (mp->m_logbufs != -1 &&
1452 mp->m_logbufs != 0 &&
1453 (mp->m_logbufs < XLOG_MIN_ICLOGS ||
1454 mp->m_logbufs > XLOG_MAX_ICLOGS)) {
1455 xfs_warn(mp, "invalid logbufs value: %d [not %d-%d]",
1456 mp->m_logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
1460 if (mp->m_logbsize != -1 &&
1461 mp->m_logbsize != 0 &&
1462 (mp->m_logbsize < XLOG_MIN_RECORD_BSIZE ||
1463 mp->m_logbsize > XLOG_MAX_RECORD_BSIZE ||
1464 !is_power_of_2(mp->m_logbsize))) {
1466 "invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
1471 if (xfs_has_allocsize(mp) &&
1472 (mp->m_allocsize_log > XFS_MAX_IO_LOG ||
1473 mp->m_allocsize_log < XFS_MIN_IO_LOG)) {
1474 xfs_warn(mp, "invalid log iosize: %d [not %d-%d]",
1475 mp->m_allocsize_log, XFS_MIN_IO_LOG, XFS_MAX_IO_LOG);
1485 struct dentry *parent)
1487 struct dentry *child;
1489 /* Apparently we're expected to ignore error returns?? */
1490 child = debugfs_create_dir(name, parent);
1499 struct super_block *sb,
1500 struct fs_context *fc)
1502 struct xfs_mount *mp = sb->s_fs_info;
1504 int flags = 0, error;
1509 * Copy VFS mount flags from the context now that all parameter parsing
1510 * is guaranteed to have been completed by either the old mount API or
1511 * the newer fsopen/fsconfig API.
1513 if (fc->sb_flags & SB_RDONLY)
1514 set_bit(XFS_OPSTATE_READONLY, &mp->m_opstate);
1515 if (fc->sb_flags & SB_DIRSYNC)
1516 mp->m_features |= XFS_FEAT_DIRSYNC;
1517 if (fc->sb_flags & SB_SYNCHRONOUS)
1518 mp->m_features |= XFS_FEAT_WSYNC;
1520 error = xfs_fs_validate_params(mp);
1524 sb_min_blocksize(sb, BBSIZE);
1525 sb->s_xattr = xfs_xattr_handlers;
1526 sb->s_export_op = &xfs_export_operations;
1527 #ifdef CONFIG_XFS_QUOTA
1528 sb->s_qcop = &xfs_quotactl_operations;
1529 sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ;
1531 sb->s_op = &xfs_super_operations;
1534 * Delay mount work if the debug hook is set. This is debug
1535 * instrumention to coordinate simulation of xfs mount failures with
1536 * VFS superblock operations
1538 if (xfs_globals.mount_delay) {
1539 xfs_notice(mp, "Delaying mount for %d seconds.",
1540 xfs_globals.mount_delay);
1541 msleep(xfs_globals.mount_delay * 1000);
1544 if (fc->sb_flags & SB_SILENT)
1545 flags |= XFS_MFSI_QUIET;
1547 error = xfs_open_devices(mp);
1552 mp->m_debugfs = xfs_debugfs_mkdir(mp->m_super->s_id,
1555 mp->m_debugfs = NULL;
1558 error = xfs_init_mount_workqueues(mp);
1560 goto out_shutdown_devices;
1562 error = xfs_init_percpu_counters(mp);
1564 goto out_destroy_workqueues;
1566 error = xfs_inodegc_init_percpu(mp);
1568 goto out_destroy_counters;
1570 /* Allocate stats memory before we do operations that might use it */
1571 mp->m_stats.xs_stats = alloc_percpu(struct xfsstats);
1572 if (!mp->m_stats.xs_stats) {
1574 goto out_destroy_inodegc;
1577 error = xchk_mount_stats_alloc(mp);
1579 goto out_free_stats;
1581 error = xfs_readsb(mp, flags);
1583 goto out_free_scrub_stats;
1585 error = xfs_finish_flags(mp);
1589 error = xfs_setup_devices(mp);
1594 * V4 support is undergoing deprecation.
1596 * Note: this has to use an open coded m_features check as xfs_has_crc
1597 * always returns false for !CONFIG_XFS_SUPPORT_V4.
1599 if (!(mp->m_features & XFS_FEAT_CRC)) {
1600 if (!IS_ENABLED(CONFIG_XFS_SUPPORT_V4)) {
1602 "Deprecated V4 format (crc=0) not supported by kernel.");
1607 "Deprecated V4 format (crc=0) will not be supported after September 2030.");
1610 /* ASCII case insensitivity is undergoing deprecation. */
1611 if (xfs_has_asciici(mp)) {
1612 #ifdef CONFIG_XFS_SUPPORT_ASCII_CI
1614 "Deprecated ASCII case-insensitivity feature (ascii-ci=1) will not be supported after September 2030.");
1617 "Deprecated ASCII case-insensitivity feature (ascii-ci=1) not supported by kernel.");
1623 /* Filesystem claims it needs repair, so refuse the mount. */
1624 if (xfs_has_needsrepair(mp)) {
1625 xfs_warn(mp, "Filesystem needs repair. Please run xfs_repair.");
1626 error = -EFSCORRUPTED;
1631 * Don't touch the filesystem if a user tool thinks it owns the primary
1632 * superblock. mkfs doesn't clear the flag from secondary supers, so
1633 * we don't check them at all.
1635 if (mp->m_sb.sb_inprogress) {
1636 xfs_warn(mp, "Offline file system operation in progress!");
1637 error = -EFSCORRUPTED;
1642 * Until this is fixed only page-sized or smaller data blocks work.
1644 if (mp->m_sb.sb_blocksize > PAGE_SIZE) {
1646 "File system with blocksize %d bytes. "
1647 "Only pagesize (%ld) or less will currently work.",
1648 mp->m_sb.sb_blocksize, PAGE_SIZE);
1653 /* Ensure this filesystem fits in the page cache limits */
1654 if (xfs_sb_validate_fsb_count(&mp->m_sb, mp->m_sb.sb_dblocks) ||
1655 xfs_sb_validate_fsb_count(&mp->m_sb, mp->m_sb.sb_rblocks)) {
1657 "file system too large to be mounted on this system.");
1663 * XFS block mappings use 54 bits to store the logical block offset.
1664 * This should suffice to handle the maximum file size that the VFS
1665 * supports (currently 2^63 bytes on 64-bit and ULONG_MAX << PAGE_SHIFT
1666 * bytes on 32-bit), but as XFS and VFS have gotten the s_maxbytes
1667 * calculation wrong on 32-bit kernels in the past, we'll add a WARN_ON
1668 * to check this assertion.
1670 * Avoid integer overflow by comparing the maximum bmbt offset to the
1671 * maximum pagecache offset in units of fs blocks.
1673 if (!xfs_verify_fileoff(mp, XFS_B_TO_FSBT(mp, MAX_LFS_FILESIZE))) {
1675 "MAX_LFS_FILESIZE block offset (%llu) exceeds extent map maximum (%llu)!",
1676 XFS_B_TO_FSBT(mp, MAX_LFS_FILESIZE),
1682 error = xfs_filestream_mount(mp);
1687 * we must configure the block size in the superblock before we run the
1688 * full mount process as the mount process can lookup and cache inodes.
1690 sb->s_magic = XFS_SUPER_MAGIC;
1691 sb->s_blocksize = mp->m_sb.sb_blocksize;
1692 sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
1693 sb->s_maxbytes = MAX_LFS_FILESIZE;
1694 sb->s_max_links = XFS_MAXLINK;
1695 sb->s_time_gran = 1;
1696 if (xfs_has_bigtime(mp)) {
1697 sb->s_time_min = xfs_bigtime_to_unix(XFS_BIGTIME_TIME_MIN);
1698 sb->s_time_max = xfs_bigtime_to_unix(XFS_BIGTIME_TIME_MAX);
1700 sb->s_time_min = XFS_LEGACY_TIME_MIN;
1701 sb->s_time_max = XFS_LEGACY_TIME_MAX;
1703 trace_xfs_inode_timestamp_range(mp, sb->s_time_min, sb->s_time_max);
1704 sb->s_iflags |= SB_I_CGROUPWB;
1706 set_posix_acl_flag(sb);
1708 /* version 5 superblocks support inode version counters. */
1709 if (xfs_has_crc(mp))
1710 sb->s_flags |= SB_I_VERSION;
1712 if (xfs_has_dax_always(mp)) {
1713 error = xfs_setup_dax_always(mp);
1715 goto out_filestream_unmount;
1718 if (xfs_has_discard(mp) && !bdev_max_discard_sectors(sb->s_bdev)) {
1720 "mounting with \"discard\" option, but the device does not support discard");
1721 mp->m_features &= ~XFS_FEAT_DISCARD;
1724 if (xfs_has_reflink(mp)) {
1725 if (mp->m_sb.sb_rblocks) {
1727 "reflink not compatible with realtime device!");
1729 goto out_filestream_unmount;
1732 if (xfs_globals.always_cow) {
1733 xfs_info(mp, "using DEBUG-only always_cow mode.");
1734 mp->m_always_cow = true;
1738 if (xfs_has_rmapbt(mp) && mp->m_sb.sb_rblocks) {
1740 "reverse mapping btree not compatible with realtime device!");
1742 goto out_filestream_unmount;
1745 if (xfs_has_exchange_range(mp))
1747 "EXPERIMENTAL exchange-range feature enabled. Use at your own risk!");
1749 if (xfs_has_parent(mp))
1751 "EXPERIMENTAL parent pointer feature enabled. Use at your own risk!");
1753 error = xfs_mountfs(mp);
1755 goto out_filestream_unmount;
1757 root = igrab(VFS_I(mp->m_rootip));
1762 sb->s_root = d_make_root(root);
1770 out_filestream_unmount:
1771 xfs_filestream_unmount(mp);
1774 out_free_scrub_stats:
1775 xchk_mount_stats_free(mp);
1777 free_percpu(mp->m_stats.xs_stats);
1778 out_destroy_inodegc:
1779 xfs_inodegc_free_percpu(mp);
1780 out_destroy_counters:
1781 xfs_destroy_percpu_counters(mp);
1782 out_destroy_workqueues:
1783 xfs_destroy_mount_workqueues(mp);
1784 out_shutdown_devices:
1785 xfs_shutdown_devices(mp);
1789 xfs_filestream_unmount(mp);
1796 struct fs_context *fc)
1798 return get_tree_bdev(fc, xfs_fs_fill_super);
1803 struct xfs_mount *mp)
1805 struct xfs_sb *sbp = &mp->m_sb;
1808 if (xfs_has_norecovery(mp)) {
1810 "ro->rw transition prohibited on norecovery mount");
1814 if (xfs_sb_is_v5(sbp) &&
1815 xfs_sb_has_ro_compat_feature(sbp, XFS_SB_FEAT_RO_COMPAT_UNKNOWN)) {
1817 "ro->rw transition prohibited on unknown (0x%x) ro-compat filesystem",
1818 (sbp->sb_features_ro_compat &
1819 XFS_SB_FEAT_RO_COMPAT_UNKNOWN));
1823 clear_bit(XFS_OPSTATE_READONLY, &mp->m_opstate);
1826 * If this is the first remount to writeable state we might have some
1827 * superblock changes to update.
1829 if (mp->m_update_sb) {
1830 error = xfs_sync_sb(mp, false);
1832 xfs_warn(mp, "failed to write sb changes");
1835 mp->m_update_sb = false;
1839 * Fill out the reserve pool if it is empty. Use the stashed value if
1840 * it is non-zero, otherwise go with the default.
1842 xfs_restore_resvblks(mp);
1843 xfs_log_work_queue(mp);
1844 xfs_blockgc_start(mp);
1846 /* Create the per-AG metadata reservation pool .*/
1847 error = xfs_fs_reserve_ag_blocks(mp);
1848 if (error && error != -ENOSPC)
1851 /* Re-enable the background inode inactivation worker. */
1852 xfs_inodegc_start(mp);
1859 struct xfs_mount *mp)
1861 struct xfs_icwalk icw = {
1862 .icw_flags = XFS_ICWALK_FLAG_SYNC,
1866 /* Flush all the dirty data to disk. */
1867 error = sync_filesystem(mp->m_super);
1872 * Cancel background eofb scanning so it cannot race with the final
1873 * log force+buftarg wait and deadlock the remount.
1875 xfs_blockgc_stop(mp);
1878 * Clear out all remaining COW staging extents and speculative post-EOF
1879 * preallocations so that we don't leave inodes requiring inactivation
1880 * cleanups during reclaim on a read-only mount. We must process every
1881 * cached inode, so this requires a synchronous cache scan.
1883 error = xfs_blockgc_free_space(mp, &icw);
1885 xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
1890 * Stop the inodegc background worker. xfs_fs_reconfigure already
1891 * flushed all pending inodegc work when it sync'd the filesystem.
1892 * The VFS holds s_umount, so we know that inodes cannot enter
1893 * xfs_fs_destroy_inode during a remount operation. In readonly mode
1894 * we send inodes straight to reclaim, so no inodes will be queued.
1896 xfs_inodegc_stop(mp);
1898 /* Free the per-AG metadata reservation pool. */
1899 xfs_fs_unreserve_ag_blocks(mp);
1902 * Before we sync the metadata, we need to free up the reserve block
1903 * pool so that the used block count in the superblock on disk is
1904 * correct at the end of the remount. Stash the current* reserve pool
1905 * size so that if we get remounted rw, we can return it to the same
1908 xfs_save_resvblks(mp);
1911 set_bit(XFS_OPSTATE_READONLY, &mp->m_opstate);
1917 * Logically we would return an error here to prevent users from believing
1918 * they might have changed mount options using remount which can't be changed.
1920 * But unfortunately mount(8) adds all options from mtab and fstab to the mount
1921 * arguments in some cases so we can't blindly reject options, but have to
1922 * check for each specified option if it actually differs from the currently
1923 * set option and only reject it if that's the case.
1925 * Until that is implemented we return success for every remount request, and
1926 * silently ignore all options that we can't actually change.
1930 struct fs_context *fc)
1932 struct xfs_mount *mp = XFS_M(fc->root->d_sb);
1933 struct xfs_mount *new_mp = fc->s_fs_info;
1934 int flags = fc->sb_flags;
1937 /* version 5 superblocks always support version counters. */
1938 if (xfs_has_crc(mp))
1939 fc->sb_flags |= SB_I_VERSION;
1941 error = xfs_fs_validate_params(new_mp);
1945 /* inode32 -> inode64 */
1946 if (xfs_has_small_inums(mp) && !xfs_has_small_inums(new_mp)) {
1947 mp->m_features &= ~XFS_FEAT_SMALL_INUMS;
1948 mp->m_maxagi = xfs_set_inode_alloc(mp, mp->m_sb.sb_agcount);
1951 /* inode64 -> inode32 */
1952 if (!xfs_has_small_inums(mp) && xfs_has_small_inums(new_mp)) {
1953 mp->m_features |= XFS_FEAT_SMALL_INUMS;
1954 mp->m_maxagi = xfs_set_inode_alloc(mp, mp->m_sb.sb_agcount);
1958 if (xfs_is_readonly(mp) && !(flags & SB_RDONLY)) {
1959 error = xfs_remount_rw(mp);
1965 if (!xfs_is_readonly(mp) && (flags & SB_RDONLY)) {
1966 error = xfs_remount_ro(mp);
1976 struct fs_context *fc)
1978 struct xfs_mount *mp = fc->s_fs_info;
1981 * mp is stored in the fs_context when it is initialized.
1982 * mp is transferred to the superblock on a successful mount,
1983 * but if an error occurs before the transfer we have to free
1990 static const struct fs_context_operations xfs_context_ops = {
1991 .parse_param = xfs_fs_parse_param,
1992 .get_tree = xfs_fs_get_tree,
1993 .reconfigure = xfs_fs_reconfigure,
1994 .free = xfs_fs_free,
1998 * WARNING: do not initialise any parameters in this function that depend on
1999 * mount option parsing having already been performed as this can be called from
2000 * fsopen() before any parameters have been set.
2002 static int xfs_init_fs_context(
2003 struct fs_context *fc)
2005 struct xfs_mount *mp;
2007 mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL | __GFP_NOFAIL);
2011 spin_lock_init(&mp->m_sb_lock);
2012 INIT_RADIX_TREE(&mp->m_perag_tree, GFP_ATOMIC);
2013 spin_lock_init(&mp->m_perag_lock);
2014 mutex_init(&mp->m_growlock);
2015 INIT_WORK(&mp->m_flush_inodes_work, xfs_flush_inodes_worker);
2016 INIT_DELAYED_WORK(&mp->m_reclaim_work, xfs_reclaim_worker);
2017 mp->m_kobj.kobject.kset = xfs_kset;
2019 * We don't create the finobt per-ag space reservation until after log
2020 * recovery, so we must set this to true so that an ifree transaction
2021 * started during log recovery will not depend on space reservations
2022 * for finobt expansion.
2024 mp->m_finobt_nores = true;
2027 * These can be overridden by the mount option parsing.
2030 mp->m_logbsize = -1;
2031 mp->m_allocsize_log = 16; /* 64k */
2033 xfs_hooks_init(&mp->m_dir_update_hooks);
2036 fc->ops = &xfs_context_ops;
2043 struct super_block *sb)
2045 kill_block_super(sb);
2046 xfs_mount_free(XFS_M(sb));
2049 static struct file_system_type xfs_fs_type = {
2050 .owner = THIS_MODULE,
2052 .init_fs_context = xfs_init_fs_context,
2053 .parameters = xfs_fs_parameters,
2054 .kill_sb = xfs_kill_sb,
2055 .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP,
2057 MODULE_ALIAS_FS("xfs");
2060 xfs_init_caches(void)
2064 xfs_buf_cache = kmem_cache_create("xfs_buf", sizeof(struct xfs_buf), 0,
2065 SLAB_HWCACHE_ALIGN |
2066 SLAB_RECLAIM_ACCOUNT,
2071 xfs_log_ticket_cache = kmem_cache_create("xfs_log_ticket",
2072 sizeof(struct xlog_ticket),
2074 if (!xfs_log_ticket_cache)
2075 goto out_destroy_buf_cache;
2077 error = xfs_btree_init_cur_caches();
2079 goto out_destroy_log_ticket_cache;
2081 error = rcbagbt_init_cur_cache();
2083 goto out_destroy_btree_cur_cache;
2085 error = xfs_defer_init_item_caches();
2087 goto out_destroy_rcbagbt_cur_cache;
2089 xfs_da_state_cache = kmem_cache_create("xfs_da_state",
2090 sizeof(struct xfs_da_state),
2092 if (!xfs_da_state_cache)
2093 goto out_destroy_defer_item_cache;
2095 xfs_ifork_cache = kmem_cache_create("xfs_ifork",
2096 sizeof(struct xfs_ifork),
2098 if (!xfs_ifork_cache)
2099 goto out_destroy_da_state_cache;
2101 xfs_trans_cache = kmem_cache_create("xfs_trans",
2102 sizeof(struct xfs_trans),
2104 if (!xfs_trans_cache)
2105 goto out_destroy_ifork_cache;
2109 * The size of the cache-allocated buf log item is the maximum
2110 * size possible under XFS. This wastes a little bit of memory,
2111 * but it is much faster.
2113 xfs_buf_item_cache = kmem_cache_create("xfs_buf_item",
2114 sizeof(struct xfs_buf_log_item),
2116 if (!xfs_buf_item_cache)
2117 goto out_destroy_trans_cache;
2119 xfs_efd_cache = kmem_cache_create("xfs_efd_item",
2120 xfs_efd_log_item_sizeof(XFS_EFD_MAX_FAST_EXTENTS),
2123 goto out_destroy_buf_item_cache;
2125 xfs_efi_cache = kmem_cache_create("xfs_efi_item",
2126 xfs_efi_log_item_sizeof(XFS_EFI_MAX_FAST_EXTENTS),
2129 goto out_destroy_efd_cache;
2131 xfs_inode_cache = kmem_cache_create("xfs_inode",
2132 sizeof(struct xfs_inode), 0,
2133 (SLAB_HWCACHE_ALIGN |
2134 SLAB_RECLAIM_ACCOUNT |
2136 xfs_fs_inode_init_once);
2137 if (!xfs_inode_cache)
2138 goto out_destroy_efi_cache;
2140 xfs_ili_cache = kmem_cache_create("xfs_ili",
2141 sizeof(struct xfs_inode_log_item), 0,
2142 SLAB_RECLAIM_ACCOUNT,
2145 goto out_destroy_inode_cache;
2147 xfs_icreate_cache = kmem_cache_create("xfs_icr",
2148 sizeof(struct xfs_icreate_item),
2150 if (!xfs_icreate_cache)
2151 goto out_destroy_ili_cache;
2153 xfs_rud_cache = kmem_cache_create("xfs_rud_item",
2154 sizeof(struct xfs_rud_log_item),
2157 goto out_destroy_icreate_cache;
2159 xfs_rui_cache = kmem_cache_create("xfs_rui_item",
2160 xfs_rui_log_item_sizeof(XFS_RUI_MAX_FAST_EXTENTS),
2163 goto out_destroy_rud_cache;
2165 xfs_cud_cache = kmem_cache_create("xfs_cud_item",
2166 sizeof(struct xfs_cud_log_item),
2169 goto out_destroy_rui_cache;
2171 xfs_cui_cache = kmem_cache_create("xfs_cui_item",
2172 xfs_cui_log_item_sizeof(XFS_CUI_MAX_FAST_EXTENTS),
2175 goto out_destroy_cud_cache;
2177 xfs_bud_cache = kmem_cache_create("xfs_bud_item",
2178 sizeof(struct xfs_bud_log_item),
2181 goto out_destroy_cui_cache;
2183 xfs_bui_cache = kmem_cache_create("xfs_bui_item",
2184 xfs_bui_log_item_sizeof(XFS_BUI_MAX_FAST_EXTENTS),
2187 goto out_destroy_bud_cache;
2189 xfs_attrd_cache = kmem_cache_create("xfs_attrd_item",
2190 sizeof(struct xfs_attrd_log_item),
2192 if (!xfs_attrd_cache)
2193 goto out_destroy_bui_cache;
2195 xfs_attri_cache = kmem_cache_create("xfs_attri_item",
2196 sizeof(struct xfs_attri_log_item),
2198 if (!xfs_attri_cache)
2199 goto out_destroy_attrd_cache;
2201 xfs_iunlink_cache = kmem_cache_create("xfs_iul_item",
2202 sizeof(struct xfs_iunlink_item),
2204 if (!xfs_iunlink_cache)
2205 goto out_destroy_attri_cache;
2207 xfs_xmd_cache = kmem_cache_create("xfs_xmd_item",
2208 sizeof(struct xfs_xmd_log_item),
2211 goto out_destroy_iul_cache;
2213 xfs_xmi_cache = kmem_cache_create("xfs_xmi_item",
2214 sizeof(struct xfs_xmi_log_item),
2217 goto out_destroy_xmd_cache;
2219 xfs_parent_args_cache = kmem_cache_create("xfs_parent_args",
2220 sizeof(struct xfs_parent_args),
2222 if (!xfs_parent_args_cache)
2223 goto out_destroy_xmi_cache;
2227 out_destroy_xmi_cache:
2228 kmem_cache_destroy(xfs_xmi_cache);
2229 out_destroy_xmd_cache:
2230 kmem_cache_destroy(xfs_xmd_cache);
2231 out_destroy_iul_cache:
2232 kmem_cache_destroy(xfs_iunlink_cache);
2233 out_destroy_attri_cache:
2234 kmem_cache_destroy(xfs_attri_cache);
2235 out_destroy_attrd_cache:
2236 kmem_cache_destroy(xfs_attrd_cache);
2237 out_destroy_bui_cache:
2238 kmem_cache_destroy(xfs_bui_cache);
2239 out_destroy_bud_cache:
2240 kmem_cache_destroy(xfs_bud_cache);
2241 out_destroy_cui_cache:
2242 kmem_cache_destroy(xfs_cui_cache);
2243 out_destroy_cud_cache:
2244 kmem_cache_destroy(xfs_cud_cache);
2245 out_destroy_rui_cache:
2246 kmem_cache_destroy(xfs_rui_cache);
2247 out_destroy_rud_cache:
2248 kmem_cache_destroy(xfs_rud_cache);
2249 out_destroy_icreate_cache:
2250 kmem_cache_destroy(xfs_icreate_cache);
2251 out_destroy_ili_cache:
2252 kmem_cache_destroy(xfs_ili_cache);
2253 out_destroy_inode_cache:
2254 kmem_cache_destroy(xfs_inode_cache);
2255 out_destroy_efi_cache:
2256 kmem_cache_destroy(xfs_efi_cache);
2257 out_destroy_efd_cache:
2258 kmem_cache_destroy(xfs_efd_cache);
2259 out_destroy_buf_item_cache:
2260 kmem_cache_destroy(xfs_buf_item_cache);
2261 out_destroy_trans_cache:
2262 kmem_cache_destroy(xfs_trans_cache);
2263 out_destroy_ifork_cache:
2264 kmem_cache_destroy(xfs_ifork_cache);
2265 out_destroy_da_state_cache:
2266 kmem_cache_destroy(xfs_da_state_cache);
2267 out_destroy_defer_item_cache:
2268 xfs_defer_destroy_item_caches();
2269 out_destroy_rcbagbt_cur_cache:
2270 rcbagbt_destroy_cur_cache();
2271 out_destroy_btree_cur_cache:
2272 xfs_btree_destroy_cur_caches();
2273 out_destroy_log_ticket_cache:
2274 kmem_cache_destroy(xfs_log_ticket_cache);
2275 out_destroy_buf_cache:
2276 kmem_cache_destroy(xfs_buf_cache);
2282 xfs_destroy_caches(void)
2285 * Make sure all delayed rcu free are flushed before we
2289 kmem_cache_destroy(xfs_parent_args_cache);
2290 kmem_cache_destroy(xfs_xmd_cache);
2291 kmem_cache_destroy(xfs_xmi_cache);
2292 kmem_cache_destroy(xfs_iunlink_cache);
2293 kmem_cache_destroy(xfs_attri_cache);
2294 kmem_cache_destroy(xfs_attrd_cache);
2295 kmem_cache_destroy(xfs_bui_cache);
2296 kmem_cache_destroy(xfs_bud_cache);
2297 kmem_cache_destroy(xfs_cui_cache);
2298 kmem_cache_destroy(xfs_cud_cache);
2299 kmem_cache_destroy(xfs_rui_cache);
2300 kmem_cache_destroy(xfs_rud_cache);
2301 kmem_cache_destroy(xfs_icreate_cache);
2302 kmem_cache_destroy(xfs_ili_cache);
2303 kmem_cache_destroy(xfs_inode_cache);
2304 kmem_cache_destroy(xfs_efi_cache);
2305 kmem_cache_destroy(xfs_efd_cache);
2306 kmem_cache_destroy(xfs_buf_item_cache);
2307 kmem_cache_destroy(xfs_trans_cache);
2308 kmem_cache_destroy(xfs_ifork_cache);
2309 kmem_cache_destroy(xfs_da_state_cache);
2310 xfs_defer_destroy_item_caches();
2311 rcbagbt_destroy_cur_cache();
2312 xfs_btree_destroy_cur_caches();
2313 kmem_cache_destroy(xfs_log_ticket_cache);
2314 kmem_cache_destroy(xfs_buf_cache);
2318 xfs_init_workqueues(void)
2321 * The allocation workqueue can be used in memory reclaim situations
2322 * (writepage path), and parallelism is only limited by the number of
2323 * AGs in all the filesystems mounted. Hence use the default large
2324 * max_active value for this workqueue.
2326 xfs_alloc_wq = alloc_workqueue("xfsalloc",
2327 XFS_WQFLAGS(WQ_MEM_RECLAIM | WQ_FREEZABLE), 0);
2331 xfs_discard_wq = alloc_workqueue("xfsdiscard", XFS_WQFLAGS(WQ_UNBOUND),
2333 if (!xfs_discard_wq)
2334 goto out_free_alloc_wq;
2338 destroy_workqueue(xfs_alloc_wq);
2343 xfs_destroy_workqueues(void)
2345 destroy_workqueue(xfs_discard_wq);
2346 destroy_workqueue(xfs_alloc_wq);
2354 xfs_check_ondisk_structs();
2356 error = xfs_dahash_test();
2360 printk(KERN_INFO XFS_VERSION_STRING " with "
2361 XFS_BUILD_OPTIONS " enabled\n");
2365 error = xfs_init_caches();
2369 error = xfs_init_workqueues();
2371 goto out_destroy_caches;
2373 error = xfs_mru_cache_init();
2375 goto out_destroy_wq;
2377 error = xfs_init_procfs();
2379 goto out_mru_cache_uninit;
2381 error = xfs_sysctl_register();
2383 goto out_cleanup_procfs;
2385 xfs_debugfs = xfs_debugfs_mkdir("xfs", NULL);
2387 xfs_kset = kset_create_and_add("xfs", NULL, fs_kobj);
2390 goto out_debugfs_unregister;
2393 xfsstats.xs_kobj.kobject.kset = xfs_kset;
2395 xfsstats.xs_stats = alloc_percpu(struct xfsstats);
2396 if (!xfsstats.xs_stats) {
2398 goto out_kset_unregister;
2401 error = xfs_sysfs_init(&xfsstats.xs_kobj, &xfs_stats_ktype, NULL,
2404 goto out_free_stats;
2406 error = xchk_global_stats_setup(xfs_debugfs);
2408 goto out_remove_stats_kobj;
2411 xfs_dbg_kobj.kobject.kset = xfs_kset;
2412 error = xfs_sysfs_init(&xfs_dbg_kobj, &xfs_dbg_ktype, NULL, "debug");
2414 goto out_remove_scrub_stats;
2417 error = xfs_qm_init();
2419 goto out_remove_dbg_kobj;
2421 error = register_filesystem(&xfs_fs_type);
2428 out_remove_dbg_kobj:
2430 xfs_sysfs_del(&xfs_dbg_kobj);
2431 out_remove_scrub_stats:
2433 xchk_global_stats_teardown();
2434 out_remove_stats_kobj:
2435 xfs_sysfs_del(&xfsstats.xs_kobj);
2437 free_percpu(xfsstats.xs_stats);
2438 out_kset_unregister:
2439 kset_unregister(xfs_kset);
2440 out_debugfs_unregister:
2441 debugfs_remove(xfs_debugfs);
2442 xfs_sysctl_unregister();
2444 xfs_cleanup_procfs();
2445 out_mru_cache_uninit:
2446 xfs_mru_cache_uninit();
2448 xfs_destroy_workqueues();
2450 xfs_destroy_caches();
2459 unregister_filesystem(&xfs_fs_type);
2461 xfs_sysfs_del(&xfs_dbg_kobj);
2463 xchk_global_stats_teardown();
2464 xfs_sysfs_del(&xfsstats.xs_kobj);
2465 free_percpu(xfsstats.xs_stats);
2466 kset_unregister(xfs_kset);
2467 debugfs_remove(xfs_debugfs);
2468 xfs_sysctl_unregister();
2469 xfs_cleanup_procfs();
2470 xfs_mru_cache_uninit();
2471 xfs_destroy_workqueues();
2472 xfs_destroy_caches();
2473 xfs_uuid_table_free();
2476 module_init(init_xfs_fs);
2477 module_exit(exit_xfs_fs);
2479 MODULE_AUTHOR("Silicon Graphics, Inc.");
2480 MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
2481 MODULE_LICENSE("GPL");