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 "scrub/stats.h"
47 #include <linux/magic.h>
48 #include <linux/fs_context.h>
49 #include <linux/fs_parser.h>
51 static const struct super_operations xfs_super_operations;
53 static struct dentry *xfs_debugfs; /* top-level xfs debugfs dir */
54 static struct kset *xfs_kset; /* top-level xfs sysfs dir */
56 static struct xfs_kobj xfs_dbg_kobj; /* global debug sysfs attrs */
59 #ifdef CONFIG_HOTPLUG_CPU
60 static LIST_HEAD(xfs_mount_list);
61 static DEFINE_SPINLOCK(xfs_mount_list_lock);
63 static inline void xfs_mount_list_add(struct xfs_mount *mp)
65 spin_lock(&xfs_mount_list_lock);
66 list_add(&mp->m_mount_list, &xfs_mount_list);
67 spin_unlock(&xfs_mount_list_lock);
70 static inline void xfs_mount_list_del(struct xfs_mount *mp)
72 spin_lock(&xfs_mount_list_lock);
73 list_del(&mp->m_mount_list);
74 spin_unlock(&xfs_mount_list_lock);
76 #else /* !CONFIG_HOTPLUG_CPU */
77 static inline void xfs_mount_list_add(struct xfs_mount *mp) {}
78 static inline void xfs_mount_list_del(struct xfs_mount *mp) {}
88 xfs_mount_set_dax_mode(
90 enum xfs_dax_mode mode)
94 mp->m_features &= ~(XFS_FEAT_DAX_ALWAYS | XFS_FEAT_DAX_NEVER);
97 mp->m_features |= XFS_FEAT_DAX_ALWAYS;
98 mp->m_features &= ~XFS_FEAT_DAX_NEVER;
101 mp->m_features |= XFS_FEAT_DAX_NEVER;
102 mp->m_features &= ~XFS_FEAT_DAX_ALWAYS;
107 static const struct constant_table dax_param_enums[] = {
108 {"inode", XFS_DAX_INODE },
109 {"always", XFS_DAX_ALWAYS },
110 {"never", XFS_DAX_NEVER },
115 * Table driven mount option parser.
118 Opt_logbufs, Opt_logbsize, Opt_logdev, Opt_rtdev,
119 Opt_wsync, Opt_noalign, Opt_swalloc, Opt_sunit, Opt_swidth, Opt_nouuid,
120 Opt_grpid, Opt_nogrpid, Opt_bsdgroups, Opt_sysvgroups,
121 Opt_allocsize, Opt_norecovery, Opt_inode64, Opt_inode32, Opt_ikeep,
122 Opt_noikeep, Opt_largeio, Opt_nolargeio, Opt_attr2, Opt_noattr2,
123 Opt_filestreams, Opt_quota, Opt_noquota, Opt_usrquota, Opt_grpquota,
124 Opt_prjquota, Opt_uquota, Opt_gquota, Opt_pquota,
125 Opt_uqnoenforce, Opt_gqnoenforce, Opt_pqnoenforce, Opt_qnoenforce,
126 Opt_discard, Opt_nodiscard, Opt_dax, Opt_dax_enum,
129 static const struct fs_parameter_spec xfs_fs_parameters[] = {
130 fsparam_u32("logbufs", Opt_logbufs),
131 fsparam_string("logbsize", Opt_logbsize),
132 fsparam_string("logdev", Opt_logdev),
133 fsparam_string("rtdev", Opt_rtdev),
134 fsparam_flag("wsync", Opt_wsync),
135 fsparam_flag("noalign", Opt_noalign),
136 fsparam_flag("swalloc", Opt_swalloc),
137 fsparam_u32("sunit", Opt_sunit),
138 fsparam_u32("swidth", Opt_swidth),
139 fsparam_flag("nouuid", Opt_nouuid),
140 fsparam_flag("grpid", Opt_grpid),
141 fsparam_flag("nogrpid", Opt_nogrpid),
142 fsparam_flag("bsdgroups", Opt_bsdgroups),
143 fsparam_flag("sysvgroups", Opt_sysvgroups),
144 fsparam_string("allocsize", Opt_allocsize),
145 fsparam_flag("norecovery", Opt_norecovery),
146 fsparam_flag("inode64", Opt_inode64),
147 fsparam_flag("inode32", Opt_inode32),
148 fsparam_flag("ikeep", Opt_ikeep),
149 fsparam_flag("noikeep", Opt_noikeep),
150 fsparam_flag("largeio", Opt_largeio),
151 fsparam_flag("nolargeio", Opt_nolargeio),
152 fsparam_flag("attr2", Opt_attr2),
153 fsparam_flag("noattr2", Opt_noattr2),
154 fsparam_flag("filestreams", Opt_filestreams),
155 fsparam_flag("quota", Opt_quota),
156 fsparam_flag("noquota", Opt_noquota),
157 fsparam_flag("usrquota", Opt_usrquota),
158 fsparam_flag("grpquota", Opt_grpquota),
159 fsparam_flag("prjquota", Opt_prjquota),
160 fsparam_flag("uquota", Opt_uquota),
161 fsparam_flag("gquota", Opt_gquota),
162 fsparam_flag("pquota", Opt_pquota),
163 fsparam_flag("uqnoenforce", Opt_uqnoenforce),
164 fsparam_flag("gqnoenforce", Opt_gqnoenforce),
165 fsparam_flag("pqnoenforce", Opt_pqnoenforce),
166 fsparam_flag("qnoenforce", Opt_qnoenforce),
167 fsparam_flag("discard", Opt_discard),
168 fsparam_flag("nodiscard", Opt_nodiscard),
169 fsparam_flag("dax", Opt_dax),
170 fsparam_enum("dax", Opt_dax_enum, dax_param_enums),
174 struct proc_xfs_info {
184 static struct proc_xfs_info xfs_info_set[] = {
185 /* the few simple ones we can get from the mount struct */
186 { XFS_FEAT_IKEEP, ",ikeep" },
187 { XFS_FEAT_WSYNC, ",wsync" },
188 { XFS_FEAT_NOALIGN, ",noalign" },
189 { XFS_FEAT_SWALLOC, ",swalloc" },
190 { XFS_FEAT_NOUUID, ",nouuid" },
191 { XFS_FEAT_NORECOVERY, ",norecovery" },
192 { XFS_FEAT_ATTR2, ",attr2" },
193 { XFS_FEAT_FILESTREAMS, ",filestreams" },
194 { XFS_FEAT_GRPID, ",grpid" },
195 { XFS_FEAT_DISCARD, ",discard" },
196 { XFS_FEAT_LARGE_IOSIZE, ",largeio" },
197 { XFS_FEAT_DAX_ALWAYS, ",dax=always" },
198 { XFS_FEAT_DAX_NEVER, ",dax=never" },
201 struct xfs_mount *mp = XFS_M(root->d_sb);
202 struct proc_xfs_info *xfs_infop;
204 for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
205 if (mp->m_features & xfs_infop->flag)
206 seq_puts(m, xfs_infop->str);
209 seq_printf(m, ",inode%d", xfs_has_small_inums(mp) ? 32 : 64);
211 if (xfs_has_allocsize(mp))
212 seq_printf(m, ",allocsize=%dk",
213 (1 << mp->m_allocsize_log) >> 10);
215 if (mp->m_logbufs > 0)
216 seq_printf(m, ",logbufs=%d", mp->m_logbufs);
217 if (mp->m_logbsize > 0)
218 seq_printf(m, ",logbsize=%dk", mp->m_logbsize >> 10);
221 seq_show_option(m, "logdev", mp->m_logname);
223 seq_show_option(m, "rtdev", mp->m_rtname);
225 if (mp->m_dalign > 0)
226 seq_printf(m, ",sunit=%d",
227 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
228 if (mp->m_swidth > 0)
229 seq_printf(m, ",swidth=%d",
230 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
232 if (mp->m_qflags & XFS_UQUOTA_ENFD)
233 seq_puts(m, ",usrquota");
234 else if (mp->m_qflags & XFS_UQUOTA_ACCT)
235 seq_puts(m, ",uqnoenforce");
237 if (mp->m_qflags & XFS_PQUOTA_ENFD)
238 seq_puts(m, ",prjquota");
239 else if (mp->m_qflags & XFS_PQUOTA_ACCT)
240 seq_puts(m, ",pqnoenforce");
242 if (mp->m_qflags & XFS_GQUOTA_ENFD)
243 seq_puts(m, ",grpquota");
244 else if (mp->m_qflags & XFS_GQUOTA_ACCT)
245 seq_puts(m, ",gqnoenforce");
247 if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
248 seq_puts(m, ",noquota");
254 xfs_set_inode_alloc_perag(
255 struct xfs_perag *pag,
257 xfs_agnumber_t max_metadata)
259 if (!xfs_is_inode32(pag->pag_mount)) {
260 set_bit(XFS_AGSTATE_ALLOWS_INODES, &pag->pag_opstate);
261 clear_bit(XFS_AGSTATE_PREFERS_METADATA, &pag->pag_opstate);
265 if (ino > XFS_MAXINUMBER_32) {
266 clear_bit(XFS_AGSTATE_ALLOWS_INODES, &pag->pag_opstate);
267 clear_bit(XFS_AGSTATE_PREFERS_METADATA, &pag->pag_opstate);
271 set_bit(XFS_AGSTATE_ALLOWS_INODES, &pag->pag_opstate);
272 if (pag->pag_agno < max_metadata)
273 set_bit(XFS_AGSTATE_PREFERS_METADATA, &pag->pag_opstate);
275 clear_bit(XFS_AGSTATE_PREFERS_METADATA, &pag->pag_opstate);
280 * Set parameters for inode allocation heuristics, taking into account
281 * filesystem size and inode32/inode64 mount options; i.e. specifically
282 * whether or not XFS_FEAT_SMALL_INUMS is set.
284 * Inode allocation patterns are altered only if inode32 is requested
285 * (XFS_FEAT_SMALL_INUMS), and the filesystem is sufficiently large.
286 * If altered, XFS_OPSTATE_INODE32 is set as well.
288 * An agcount independent of that in the mount structure is provided
289 * because in the growfs case, mp->m_sb.sb_agcount is not yet updated
290 * to the potentially higher ag count.
292 * Returns the maximum AG index which may contain inodes.
296 struct xfs_mount *mp,
297 xfs_agnumber_t agcount)
299 xfs_agnumber_t index;
300 xfs_agnumber_t maxagi = 0;
301 xfs_sb_t *sbp = &mp->m_sb;
302 xfs_agnumber_t max_metadata;
307 * Calculate how much should be reserved for inodes to meet
308 * the max inode percentage. Used only for inode32.
310 if (M_IGEO(mp)->maxicount) {
313 icount = sbp->sb_dblocks * sbp->sb_imax_pct;
315 icount += sbp->sb_agblocks - 1;
316 do_div(icount, sbp->sb_agblocks);
317 max_metadata = icount;
319 max_metadata = agcount;
322 /* Get the last possible inode in the filesystem */
323 agino = XFS_AGB_TO_AGINO(mp, sbp->sb_agblocks - 1);
324 ino = XFS_AGINO_TO_INO(mp, agcount - 1, agino);
327 * If user asked for no more than 32-bit inodes, and the fs is
328 * sufficiently large, set XFS_OPSTATE_INODE32 if we must alter
329 * the allocator to accommodate the request.
331 if (xfs_has_small_inums(mp) && ino > XFS_MAXINUMBER_32)
332 set_bit(XFS_OPSTATE_INODE32, &mp->m_opstate);
334 clear_bit(XFS_OPSTATE_INODE32, &mp->m_opstate);
336 for (index = 0; index < agcount; index++) {
337 struct xfs_perag *pag;
339 ino = XFS_AGINO_TO_INO(mp, index, agino);
341 pag = xfs_perag_get(mp, index);
342 if (xfs_set_inode_alloc_perag(pag, ino, max_metadata))
347 return xfs_is_inode32(mp) ? maxagi : agcount;
351 xfs_setup_dax_always(
352 struct xfs_mount *mp)
354 if (!mp->m_ddev_targp->bt_daxdev &&
355 (!mp->m_rtdev_targp || !mp->m_rtdev_targp->bt_daxdev)) {
357 "DAX unsupported by block device. Turning off DAX.");
361 if (mp->m_super->s_blocksize != PAGE_SIZE) {
363 "DAX not supported for blocksize. Turning off DAX.");
367 if (xfs_has_reflink(mp) &&
368 bdev_is_partition(mp->m_ddev_targp->bt_bdev)) {
370 "DAX and reflink cannot work with multi-partitions!");
374 xfs_warn(mp, "DAX enabled. Warning: EXPERIMENTAL, use at your own risk");
378 xfs_mount_set_dax_mode(mp, XFS_DAX_NEVER);
386 struct block_device **bdevp)
390 *bdevp = blkdev_get_by_path(name, BLK_OPEN_READ | BLK_OPEN_WRITE,
391 mp->m_super, &fs_holder_ops);
392 if (IS_ERR(*bdevp)) {
393 error = PTR_ERR(*bdevp);
394 xfs_warn(mp, "Invalid device [%s], error=%d", name, error);
401 xfs_shutdown_devices(
402 struct xfs_mount *mp)
405 * Udev is triggered whenever anyone closes a block device or unmounts
406 * a file systemm on a block device.
407 * The default udev rules invoke blkid to read the fs super and create
408 * symlinks to the bdev under /dev/disk. For this, it uses buffered
409 * reads through the page cache.
411 * xfs_db also uses buffered reads to examine metadata. There is no
412 * coordination between xfs_db and udev, which means that they can run
413 * concurrently. Note there is no coordination between the kernel and
416 * On a system with 64k pages, the page cache can cache the superblock
417 * and the root inode (and hence the root directory) with the same 64k
418 * page. If udev spawns blkid after the mkfs and the system is busy
419 * enough that it is still running when xfs_db starts up, they'll both
420 * read from the same page in the pagecache.
422 * The unmount writes updated inode metadata to disk directly. The XFS
423 * buffer cache does not use the bdev pagecache, so it needs to
424 * invalidate that pagecache on unmount. If the above scenario occurs,
425 * the pagecache no longer reflects what's on disk, xfs_db reads the
426 * stale metadata, and fails to find /a. Most of the time this succeeds
427 * because closing a bdev invalidates the page cache, but when processes
428 * race, everyone loses.
430 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
431 blkdev_issue_flush(mp->m_logdev_targp->bt_bdev);
432 invalidate_bdev(mp->m_logdev_targp->bt_bdev);
434 if (mp->m_rtdev_targp) {
435 blkdev_issue_flush(mp->m_rtdev_targp->bt_bdev);
436 invalidate_bdev(mp->m_rtdev_targp->bt_bdev);
438 blkdev_issue_flush(mp->m_ddev_targp->bt_bdev);
439 invalidate_bdev(mp->m_ddev_targp->bt_bdev);
443 * The file system configurations are:
444 * (1) device (partition) with data and internal log
445 * (2) logical volume with data and log subvolumes.
446 * (3) logical volume with data, log, and realtime subvolumes.
448 * We only have to handle opening the log and realtime volumes here if
449 * they are present. The data subvolume has already been opened by
450 * get_sb_bdev() and is stored in sb->s_bdev.
454 struct xfs_mount *mp)
456 struct super_block *sb = mp->m_super;
457 struct block_device *ddev = sb->s_bdev;
458 struct block_device *logdev = NULL, *rtdev = NULL;
462 * blkdev_put() can't be called under s_umount, see the comment
463 * in get_tree_bdev() for more details
465 up_write(&sb->s_umount);
468 * Open real time and log devices - order is important.
471 error = xfs_blkdev_get(mp, mp->m_logname, &logdev);
477 error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev);
479 goto out_close_logdev;
481 if (rtdev == ddev || rtdev == logdev) {
483 "Cannot mount filesystem with identical rtdev and ddev/logdev.");
485 goto out_close_rtdev;
490 * Setup xfs_mount buffer target pointers
493 mp->m_ddev_targp = xfs_alloc_buftarg(mp, ddev);
494 if (!mp->m_ddev_targp)
495 goto out_close_rtdev;
498 mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev);
499 if (!mp->m_rtdev_targp)
500 goto out_free_ddev_targ;
503 if (logdev && logdev != ddev) {
504 mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev);
505 if (!mp->m_logdev_targp)
506 goto out_free_rtdev_targ;
508 mp->m_logdev_targp = mp->m_ddev_targp;
513 down_write(&sb->s_umount);
517 if (mp->m_rtdev_targp)
518 xfs_free_buftarg(mp->m_rtdev_targp);
520 xfs_free_buftarg(mp->m_ddev_targp);
523 blkdev_put(rtdev, sb);
525 if (logdev && logdev != ddev)
526 blkdev_put(logdev, sb);
531 * Setup xfs_mount buffer target pointers based on superblock
535 struct xfs_mount *mp)
539 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_sectsize);
543 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
544 unsigned int log_sector_size = BBSIZE;
546 if (xfs_has_sector(mp))
547 log_sector_size = mp->m_sb.sb_logsectsize;
548 error = xfs_setsize_buftarg(mp->m_logdev_targp,
553 if (mp->m_rtdev_targp) {
554 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
555 mp->m_sb.sb_sectsize);
564 xfs_init_mount_workqueues(
565 struct xfs_mount *mp)
567 mp->m_buf_workqueue = alloc_workqueue("xfs-buf/%s",
568 XFS_WQFLAGS(WQ_FREEZABLE | WQ_MEM_RECLAIM),
569 1, mp->m_super->s_id);
570 if (!mp->m_buf_workqueue)
573 mp->m_unwritten_workqueue = alloc_workqueue("xfs-conv/%s",
574 XFS_WQFLAGS(WQ_FREEZABLE | WQ_MEM_RECLAIM),
575 0, mp->m_super->s_id);
576 if (!mp->m_unwritten_workqueue)
577 goto out_destroy_buf;
579 mp->m_reclaim_workqueue = alloc_workqueue("xfs-reclaim/%s",
580 XFS_WQFLAGS(WQ_FREEZABLE | WQ_MEM_RECLAIM),
581 0, mp->m_super->s_id);
582 if (!mp->m_reclaim_workqueue)
583 goto out_destroy_unwritten;
585 mp->m_blockgc_wq = alloc_workqueue("xfs-blockgc/%s",
586 XFS_WQFLAGS(WQ_UNBOUND | WQ_FREEZABLE | WQ_MEM_RECLAIM),
587 0, mp->m_super->s_id);
588 if (!mp->m_blockgc_wq)
589 goto out_destroy_reclaim;
591 mp->m_inodegc_wq = alloc_workqueue("xfs-inodegc/%s",
592 XFS_WQFLAGS(WQ_FREEZABLE | WQ_MEM_RECLAIM),
593 1, mp->m_super->s_id);
594 if (!mp->m_inodegc_wq)
595 goto out_destroy_blockgc;
597 mp->m_sync_workqueue = alloc_workqueue("xfs-sync/%s",
598 XFS_WQFLAGS(WQ_FREEZABLE), 0, mp->m_super->s_id);
599 if (!mp->m_sync_workqueue)
600 goto out_destroy_inodegc;
605 destroy_workqueue(mp->m_inodegc_wq);
607 destroy_workqueue(mp->m_blockgc_wq);
609 destroy_workqueue(mp->m_reclaim_workqueue);
610 out_destroy_unwritten:
611 destroy_workqueue(mp->m_unwritten_workqueue);
613 destroy_workqueue(mp->m_buf_workqueue);
619 xfs_destroy_mount_workqueues(
620 struct xfs_mount *mp)
622 destroy_workqueue(mp->m_sync_workqueue);
623 destroy_workqueue(mp->m_blockgc_wq);
624 destroy_workqueue(mp->m_inodegc_wq);
625 destroy_workqueue(mp->m_reclaim_workqueue);
626 destroy_workqueue(mp->m_unwritten_workqueue);
627 destroy_workqueue(mp->m_buf_workqueue);
631 xfs_flush_inodes_worker(
632 struct work_struct *work)
634 struct xfs_mount *mp = container_of(work, struct xfs_mount,
635 m_flush_inodes_work);
636 struct super_block *sb = mp->m_super;
638 if (down_read_trylock(&sb->s_umount)) {
640 up_read(&sb->s_umount);
645 * Flush all dirty data to disk. Must not be called while holding an XFS_ILOCK
646 * or a page lock. We use sync_inodes_sb() here to ensure we block while waiting
647 * for IO to complete so that we effectively throttle multiple callers to the
648 * rate at which IO is completing.
652 struct xfs_mount *mp)
655 * If flush_work() returns true then that means we waited for a flush
656 * which was already in progress. Don't bother running another scan.
658 if (flush_work(&mp->m_flush_inodes_work))
661 queue_work(mp->m_sync_workqueue, &mp->m_flush_inodes_work);
662 flush_work(&mp->m_flush_inodes_work);
665 /* Catch misguided souls that try to use this interface on XFS */
666 STATIC struct inode *
668 struct super_block *sb)
675 * Now that the generic code is guaranteed not to be accessing
676 * the linux inode, we can inactivate and reclaim the inode.
679 xfs_fs_destroy_inode(
682 struct xfs_inode *ip = XFS_I(inode);
684 trace_xfs_destroy_inode(ip);
686 ASSERT(!rwsem_is_locked(&inode->i_rwsem));
687 XFS_STATS_INC(ip->i_mount, vn_rele);
688 XFS_STATS_INC(ip->i_mount, vn_remove);
689 xfs_inode_mark_reclaimable(ip);
697 struct xfs_inode *ip = XFS_I(inode);
698 struct xfs_mount *mp = ip->i_mount;
699 struct xfs_trans *tp;
701 if (!(inode->i_sb->s_flags & SB_LAZYTIME))
705 * Only do the timestamp update if the inode is dirty (I_DIRTY_SYNC)
706 * and has dirty timestamp (I_DIRTY_TIME). I_DIRTY_TIME can be passed
707 * in flags possibly together with I_DIRTY_SYNC.
709 if ((flags & ~I_DIRTY_TIME) != I_DIRTY_SYNC || !(flags & I_DIRTY_TIME))
712 if (xfs_trans_alloc(mp, &M_RES(mp)->tr_fsyncts, 0, 0, 0, &tp))
714 xfs_ilock(ip, XFS_ILOCK_EXCL);
715 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
716 xfs_trans_log_inode(tp, ip, XFS_ILOG_TIMESTAMP);
717 xfs_trans_commit(tp);
721 * Slab object creation initialisation for the XFS inode.
722 * This covers only the idempotent fields in the XFS inode;
723 * all other fields need to be initialised on allocation
724 * from the slab. This avoids the need to repeatedly initialise
725 * fields in the xfs inode that left in the initialise state
726 * when freeing the inode.
729 xfs_fs_inode_init_once(
732 struct xfs_inode *ip = inode;
734 memset(ip, 0, sizeof(struct xfs_inode));
737 inode_init_once(VFS_I(ip));
740 atomic_set(&ip->i_pincount, 0);
741 spin_lock_init(&ip->i_flags_lock);
743 mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
744 "xfsino", ip->i_ino);
748 * We do an unlocked check for XFS_IDONTCACHE here because we are already
749 * serialised against cache hits here via the inode->i_lock and igrab() in
750 * xfs_iget_cache_hit(). Hence a lookup that might clear this flag will not be
751 * racing with us, and it avoids needing to grab a spinlock here for every inode
752 * we drop the final reference on.
758 struct xfs_inode *ip = XFS_I(inode);
761 * If this unlinked inode is in the middle of recovery, don't
762 * drop the inode just yet; log recovery will take care of
763 * that. See the comment for this inode flag.
765 if (ip->i_flags & XFS_IRECOVERY) {
766 ASSERT(xlog_recovery_needed(ip->i_mount->m_log));
770 return generic_drop_inode(inode);
775 struct xfs_mount *mp)
778 * Free the buftargs here because blkdev_put needs to be called outside
779 * of sb->s_umount, which is held around the call to ->put_super.
781 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp)
782 xfs_free_buftarg(mp->m_logdev_targp);
783 if (mp->m_rtdev_targp)
784 xfs_free_buftarg(mp->m_rtdev_targp);
785 if (mp->m_ddev_targp)
786 xfs_free_buftarg(mp->m_ddev_targp);
788 debugfs_remove(mp->m_debugfs);
790 kfree(mp->m_logname);
796 struct super_block *sb,
799 struct xfs_mount *mp = XFS_M(sb);
802 trace_xfs_fs_sync_fs(mp, __return_address);
805 * Doing anything during the async pass would be counterproductive.
810 error = xfs_log_force(mp, XFS_LOG_SYNC);
816 * The disk must be active because we're syncing.
817 * We schedule log work now (now that the disk is
818 * active) instead of later (when it might not be).
820 flush_delayed_work(&mp->m_log->l_work);
824 * If we are called with page faults frozen out, it means we are about
825 * to freeze the transaction subsystem. Take the opportunity to shut
826 * down inodegc because once SB_FREEZE_FS is set it's too late to
827 * prevent inactivation races with freeze. The fs doesn't get called
828 * again by the freezing process until after SB_FREEZE_FS has been set,
829 * so it's now or never. Same logic applies to speculative allocation
830 * garbage collection.
832 * We don't care if this is a normal syncfs call that does this or
833 * freeze that does this - we can run this multiple times without issue
834 * and we won't race with a restart because a restart can only occur
835 * when the state is either SB_FREEZE_FS or SB_FREEZE_COMPLETE.
837 if (sb->s_writers.frozen == SB_FREEZE_PAGEFAULT) {
838 xfs_inodegc_stop(mp);
839 xfs_blockgc_stop(mp);
847 struct dentry *dentry,
848 struct kstatfs *statp)
850 struct xfs_mount *mp = XFS_M(dentry->d_sb);
851 xfs_sb_t *sbp = &mp->m_sb;
852 struct xfs_inode *ip = XFS_I(d_inode(dentry));
853 uint64_t fakeinos, id;
861 * Expedite background inodegc but don't wait. We do not want to block
862 * here waiting hours for a billion extent file to be truncated.
864 xfs_inodegc_push(mp);
866 statp->f_type = XFS_SUPER_MAGIC;
867 statp->f_namelen = MAXNAMELEN - 1;
869 id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
870 statp->f_fsid = u64_to_fsid(id);
872 icount = percpu_counter_sum(&mp->m_icount);
873 ifree = percpu_counter_sum(&mp->m_ifree);
874 fdblocks = percpu_counter_sum(&mp->m_fdblocks);
876 spin_lock(&mp->m_sb_lock);
877 statp->f_bsize = sbp->sb_blocksize;
878 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
879 statp->f_blocks = sbp->sb_dblocks - lsize;
880 spin_unlock(&mp->m_sb_lock);
882 /* make sure statp->f_bfree does not underflow */
883 statp->f_bfree = max_t(int64_t, 0,
884 fdblocks - xfs_fdblocks_unavailable(mp));
885 statp->f_bavail = statp->f_bfree;
887 fakeinos = XFS_FSB_TO_INO(mp, statp->f_bfree);
888 statp->f_files = min(icount + fakeinos, (uint64_t)XFS_MAXINUMBER);
889 if (M_IGEO(mp)->maxicount)
890 statp->f_files = min_t(typeof(statp->f_files),
892 M_IGEO(mp)->maxicount);
894 /* If sb_icount overshot maxicount, report actual allocation */
895 statp->f_files = max_t(typeof(statp->f_files),
899 /* make sure statp->f_ffree does not underflow */
900 ffree = statp->f_files - (icount - ifree);
901 statp->f_ffree = max_t(int64_t, ffree, 0);
904 if ((ip->i_diflags & XFS_DIFLAG_PROJINHERIT) &&
905 ((mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))) ==
906 (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))
907 xfs_qm_statvfs(ip, statp);
909 if (XFS_IS_REALTIME_MOUNT(mp) &&
910 (ip->i_diflags & (XFS_DIFLAG_RTINHERIT | XFS_DIFLAG_REALTIME))) {
913 statp->f_blocks = sbp->sb_rblocks;
914 freertx = percpu_counter_sum_positive(&mp->m_frextents);
915 statp->f_bavail = statp->f_bfree = freertx * sbp->sb_rextsize;
922 xfs_save_resvblks(struct xfs_mount *mp)
924 uint64_t resblks = 0;
926 mp->m_resblks_save = mp->m_resblks;
927 xfs_reserve_blocks(mp, &resblks, NULL);
931 xfs_restore_resvblks(struct xfs_mount *mp)
935 if (mp->m_resblks_save) {
936 resblks = mp->m_resblks_save;
937 mp->m_resblks_save = 0;
939 resblks = xfs_default_resblks(mp);
941 xfs_reserve_blocks(mp, &resblks, NULL);
945 * Second stage of a freeze. The data is already frozen so we only
946 * need to take care of the metadata. Once that's done sync the superblock
947 * to the log to dirty it in case of a crash while frozen. This ensures that we
948 * will recover the unlinked inode lists on the next mount.
952 struct super_block *sb)
954 struct xfs_mount *mp = XFS_M(sb);
959 * The filesystem is now frozen far enough that memory reclaim
960 * cannot safely operate on the filesystem. Hence we need to
961 * set a GFP_NOFS context here to avoid recursion deadlocks.
963 flags = memalloc_nofs_save();
964 xfs_save_resvblks(mp);
965 ret = xfs_log_quiesce(mp);
966 memalloc_nofs_restore(flags);
969 * For read-write filesystems, we need to restart the inodegc on error
970 * because we stopped it at SB_FREEZE_PAGEFAULT level and a thaw is not
971 * going to be run to restart it now. We are at SB_FREEZE_FS level
972 * here, so we can restart safely without racing with a stop in
975 if (ret && !xfs_is_readonly(mp)) {
976 xfs_blockgc_start(mp);
977 xfs_inodegc_start(mp);
985 struct super_block *sb)
987 struct xfs_mount *mp = XFS_M(sb);
989 xfs_restore_resvblks(mp);
990 xfs_log_work_queue(mp);
993 * Don't reactivate the inodegc worker on a readonly filesystem because
994 * inodes are sent directly to reclaim. Don't reactivate the blockgc
995 * worker because there are no speculative preallocations on a readonly
998 if (!xfs_is_readonly(mp)) {
999 xfs_blockgc_start(mp);
1000 xfs_inodegc_start(mp);
1007 * This function fills in xfs_mount_t fields based on mount args.
1008 * Note: the superblock _has_ now been read in.
1012 struct xfs_mount *mp)
1014 /* Fail a mount where the logbuf is smaller than the log stripe */
1015 if (xfs_has_logv2(mp)) {
1016 if (mp->m_logbsize <= 0 &&
1017 mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE) {
1018 mp->m_logbsize = mp->m_sb.sb_logsunit;
1019 } else if (mp->m_logbsize > 0 &&
1020 mp->m_logbsize < mp->m_sb.sb_logsunit) {
1022 "logbuf size must be greater than or equal to log stripe size");
1026 /* Fail a mount if the logbuf is larger than 32K */
1027 if (mp->m_logbsize > XLOG_BIG_RECORD_BSIZE) {
1029 "logbuf size for version 1 logs must be 16K or 32K");
1035 * V5 filesystems always use attr2 format for attributes.
1037 if (xfs_has_crc(mp) && xfs_has_noattr2(mp)) {
1038 xfs_warn(mp, "Cannot mount a V5 filesystem as noattr2. "
1039 "attr2 is always enabled for V5 filesystems.");
1044 * prohibit r/w mounts of read-only filesystems
1046 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !xfs_is_readonly(mp)) {
1048 "cannot mount a read-only filesystem as read-write");
1052 if ((mp->m_qflags & XFS_GQUOTA_ACCT) &&
1053 (mp->m_qflags & XFS_PQUOTA_ACCT) &&
1054 !xfs_has_pquotino(mp)) {
1056 "Super block does not support project and group quota together");
1064 xfs_init_percpu_counters(
1065 struct xfs_mount *mp)
1069 error = percpu_counter_init(&mp->m_icount, 0, GFP_KERNEL);
1073 error = percpu_counter_init(&mp->m_ifree, 0, GFP_KERNEL);
1077 error = percpu_counter_init(&mp->m_fdblocks, 0, GFP_KERNEL);
1081 error = percpu_counter_init(&mp->m_delalloc_blks, 0, GFP_KERNEL);
1085 error = percpu_counter_init(&mp->m_frextents, 0, GFP_KERNEL);
1092 percpu_counter_destroy(&mp->m_delalloc_blks);
1094 percpu_counter_destroy(&mp->m_fdblocks);
1096 percpu_counter_destroy(&mp->m_ifree);
1098 percpu_counter_destroy(&mp->m_icount);
1103 xfs_reinit_percpu_counters(
1104 struct xfs_mount *mp)
1106 percpu_counter_set(&mp->m_icount, mp->m_sb.sb_icount);
1107 percpu_counter_set(&mp->m_ifree, mp->m_sb.sb_ifree);
1108 percpu_counter_set(&mp->m_fdblocks, mp->m_sb.sb_fdblocks);
1109 percpu_counter_set(&mp->m_frextents, mp->m_sb.sb_frextents);
1113 xfs_destroy_percpu_counters(
1114 struct xfs_mount *mp)
1116 percpu_counter_destroy(&mp->m_icount);
1117 percpu_counter_destroy(&mp->m_ifree);
1118 percpu_counter_destroy(&mp->m_fdblocks);
1119 ASSERT(xfs_is_shutdown(mp) ||
1120 percpu_counter_sum(&mp->m_delalloc_blks) == 0);
1121 percpu_counter_destroy(&mp->m_delalloc_blks);
1122 percpu_counter_destroy(&mp->m_frextents);
1126 xfs_inodegc_init_percpu(
1127 struct xfs_mount *mp)
1129 struct xfs_inodegc *gc;
1132 mp->m_inodegc = alloc_percpu(struct xfs_inodegc);
1136 for_each_possible_cpu(cpu) {
1137 gc = per_cpu_ptr(mp->m_inodegc, cpu);
1138 #if defined(DEBUG) || defined(XFS_WARN)
1141 init_llist_head(&gc->list);
1144 INIT_DELAYED_WORK(&gc->work, xfs_inodegc_worker);
1150 xfs_inodegc_free_percpu(
1151 struct xfs_mount *mp)
1155 free_percpu(mp->m_inodegc);
1160 struct super_block *sb)
1162 struct xfs_mount *mp = XFS_M(sb);
1164 xfs_notice(mp, "Unmounting Filesystem %pU", &mp->m_sb.sb_uuid);
1165 xfs_filestream_unmount(mp);
1169 xchk_mount_stats_free(mp);
1170 free_percpu(mp->m_stats.xs_stats);
1171 xfs_mount_list_del(mp);
1172 xfs_inodegc_free_percpu(mp);
1173 xfs_destroy_percpu_counters(mp);
1174 xfs_destroy_mount_workqueues(mp);
1175 xfs_shutdown_devices(mp);
1179 xfs_fs_nr_cached_objects(
1180 struct super_block *sb,
1181 struct shrink_control *sc)
1183 /* Paranoia: catch incorrect calls during mount setup or teardown */
1184 if (WARN_ON_ONCE(!sb->s_fs_info))
1186 return xfs_reclaim_inodes_count(XFS_M(sb));
1190 xfs_fs_free_cached_objects(
1191 struct super_block *sb,
1192 struct shrink_control *sc)
1194 return xfs_reclaim_inodes_nr(XFS_M(sb), sc->nr_to_scan);
1199 struct super_block *sb)
1201 xfs_force_shutdown(XFS_M(sb), SHUTDOWN_DEVICE_REMOVED);
1204 static const struct super_operations xfs_super_operations = {
1205 .alloc_inode = xfs_fs_alloc_inode,
1206 .destroy_inode = xfs_fs_destroy_inode,
1207 .dirty_inode = xfs_fs_dirty_inode,
1208 .drop_inode = xfs_fs_drop_inode,
1209 .put_super = xfs_fs_put_super,
1210 .sync_fs = xfs_fs_sync_fs,
1211 .freeze_fs = xfs_fs_freeze,
1212 .unfreeze_fs = xfs_fs_unfreeze,
1213 .statfs = xfs_fs_statfs,
1214 .show_options = xfs_fs_show_options,
1215 .nr_cached_objects = xfs_fs_nr_cached_objects,
1216 .free_cached_objects = xfs_fs_free_cached_objects,
1217 .shutdown = xfs_fs_shutdown,
1226 int last, shift_left_factor = 0, _res;
1230 value = kstrdup(s, GFP_KERNEL);
1234 last = strlen(value) - 1;
1235 if (value[last] == 'K' || value[last] == 'k') {
1236 shift_left_factor = 10;
1239 if (value[last] == 'M' || value[last] == 'm') {
1240 shift_left_factor = 20;
1243 if (value[last] == 'G' || value[last] == 'g') {
1244 shift_left_factor = 30;
1248 if (kstrtoint(value, base, &_res))
1251 *res = _res << shift_left_factor;
1256 xfs_fs_warn_deprecated(
1257 struct fs_context *fc,
1258 struct fs_parameter *param,
1262 /* Don't print the warning if reconfiguring and current mount point
1263 * already had the flag set
1265 if ((fc->purpose & FS_CONTEXT_FOR_RECONFIGURE) &&
1266 !!(XFS_M(fc->root->d_sb)->m_features & flag) == value)
1268 xfs_warn(fc->s_fs_info, "%s mount option is deprecated.", param->key);
1272 * Set mount state from a mount option.
1274 * NOTE: mp->m_super is NULL here!
1278 struct fs_context *fc,
1279 struct fs_parameter *param)
1281 struct xfs_mount *parsing_mp = fc->s_fs_info;
1282 struct fs_parse_result result;
1286 opt = fs_parse(fc, xfs_fs_parameters, param, &result);
1292 parsing_mp->m_logbufs = result.uint_32;
1295 if (suffix_kstrtoint(param->string, 10, &parsing_mp->m_logbsize))
1299 kfree(parsing_mp->m_logname);
1300 parsing_mp->m_logname = kstrdup(param->string, GFP_KERNEL);
1301 if (!parsing_mp->m_logname)
1305 kfree(parsing_mp->m_rtname);
1306 parsing_mp->m_rtname = kstrdup(param->string, GFP_KERNEL);
1307 if (!parsing_mp->m_rtname)
1311 if (suffix_kstrtoint(param->string, 10, &size))
1313 parsing_mp->m_allocsize_log = ffs(size) - 1;
1314 parsing_mp->m_features |= XFS_FEAT_ALLOCSIZE;
1318 parsing_mp->m_features |= XFS_FEAT_GRPID;
1321 case Opt_sysvgroups:
1322 parsing_mp->m_features &= ~XFS_FEAT_GRPID;
1325 parsing_mp->m_features |= XFS_FEAT_WSYNC;
1327 case Opt_norecovery:
1328 parsing_mp->m_features |= XFS_FEAT_NORECOVERY;
1331 parsing_mp->m_features |= XFS_FEAT_NOALIGN;
1334 parsing_mp->m_features |= XFS_FEAT_SWALLOC;
1337 parsing_mp->m_dalign = result.uint_32;
1340 parsing_mp->m_swidth = result.uint_32;
1343 parsing_mp->m_features |= XFS_FEAT_SMALL_INUMS;
1346 parsing_mp->m_features &= ~XFS_FEAT_SMALL_INUMS;
1349 parsing_mp->m_features |= XFS_FEAT_NOUUID;
1352 parsing_mp->m_features |= XFS_FEAT_LARGE_IOSIZE;
1355 parsing_mp->m_features &= ~XFS_FEAT_LARGE_IOSIZE;
1357 case Opt_filestreams:
1358 parsing_mp->m_features |= XFS_FEAT_FILESTREAMS;
1361 parsing_mp->m_qflags &= ~XFS_ALL_QUOTA_ACCT;
1362 parsing_mp->m_qflags &= ~XFS_ALL_QUOTA_ENFD;
1367 parsing_mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ENFD);
1369 case Opt_qnoenforce:
1370 case Opt_uqnoenforce:
1371 parsing_mp->m_qflags |= XFS_UQUOTA_ACCT;
1372 parsing_mp->m_qflags &= ~XFS_UQUOTA_ENFD;
1376 parsing_mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ENFD);
1378 case Opt_pqnoenforce:
1379 parsing_mp->m_qflags |= XFS_PQUOTA_ACCT;
1380 parsing_mp->m_qflags &= ~XFS_PQUOTA_ENFD;
1384 parsing_mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ENFD);
1386 case Opt_gqnoenforce:
1387 parsing_mp->m_qflags |= XFS_GQUOTA_ACCT;
1388 parsing_mp->m_qflags &= ~XFS_GQUOTA_ENFD;
1391 parsing_mp->m_features |= XFS_FEAT_DISCARD;
1394 parsing_mp->m_features &= ~XFS_FEAT_DISCARD;
1396 #ifdef CONFIG_FS_DAX
1398 xfs_mount_set_dax_mode(parsing_mp, XFS_DAX_ALWAYS);
1401 xfs_mount_set_dax_mode(parsing_mp, result.uint_32);
1404 /* Following mount options will be removed in September 2025 */
1406 xfs_fs_warn_deprecated(fc, param, XFS_FEAT_IKEEP, true);
1407 parsing_mp->m_features |= XFS_FEAT_IKEEP;
1410 xfs_fs_warn_deprecated(fc, param, XFS_FEAT_IKEEP, false);
1411 parsing_mp->m_features &= ~XFS_FEAT_IKEEP;
1414 xfs_fs_warn_deprecated(fc, param, XFS_FEAT_ATTR2, true);
1415 parsing_mp->m_features |= XFS_FEAT_ATTR2;
1418 xfs_fs_warn_deprecated(fc, param, XFS_FEAT_NOATTR2, true);
1419 parsing_mp->m_features |= XFS_FEAT_NOATTR2;
1422 xfs_warn(parsing_mp, "unknown mount option [%s].", param->key);
1430 xfs_fs_validate_params(
1431 struct xfs_mount *mp)
1433 /* No recovery flag requires a read-only mount */
1434 if (xfs_has_norecovery(mp) && !xfs_is_readonly(mp)) {
1435 xfs_warn(mp, "no-recovery mounts must be read-only.");
1440 * We have not read the superblock at this point, so only the attr2
1441 * mount option can set the attr2 feature by this stage.
1443 if (xfs_has_attr2(mp) && xfs_has_noattr2(mp)) {
1444 xfs_warn(mp, "attr2 and noattr2 cannot both be specified.");
1449 if (xfs_has_noalign(mp) && (mp->m_dalign || mp->m_swidth)) {
1451 "sunit and swidth options incompatible with the noalign option");
1455 if (!IS_ENABLED(CONFIG_XFS_QUOTA) && mp->m_qflags != 0) {
1456 xfs_warn(mp, "quota support not available in this kernel.");
1460 if ((mp->m_dalign && !mp->m_swidth) ||
1461 (!mp->m_dalign && mp->m_swidth)) {
1462 xfs_warn(mp, "sunit and swidth must be specified together");
1466 if (mp->m_dalign && (mp->m_swidth % mp->m_dalign != 0)) {
1468 "stripe width (%d) must be a multiple of the stripe unit (%d)",
1469 mp->m_swidth, mp->m_dalign);
1473 if (mp->m_logbufs != -1 &&
1474 mp->m_logbufs != 0 &&
1475 (mp->m_logbufs < XLOG_MIN_ICLOGS ||
1476 mp->m_logbufs > XLOG_MAX_ICLOGS)) {
1477 xfs_warn(mp, "invalid logbufs value: %d [not %d-%d]",
1478 mp->m_logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
1482 if (mp->m_logbsize != -1 &&
1483 mp->m_logbsize != 0 &&
1484 (mp->m_logbsize < XLOG_MIN_RECORD_BSIZE ||
1485 mp->m_logbsize > XLOG_MAX_RECORD_BSIZE ||
1486 !is_power_of_2(mp->m_logbsize))) {
1488 "invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
1493 if (xfs_has_allocsize(mp) &&
1494 (mp->m_allocsize_log > XFS_MAX_IO_LOG ||
1495 mp->m_allocsize_log < XFS_MIN_IO_LOG)) {
1496 xfs_warn(mp, "invalid log iosize: %d [not %d-%d]",
1497 mp->m_allocsize_log, XFS_MIN_IO_LOG, XFS_MAX_IO_LOG);
1507 struct dentry *parent)
1509 struct dentry *child;
1511 /* Apparently we're expected to ignore error returns?? */
1512 child = debugfs_create_dir(name, parent);
1521 struct super_block *sb,
1522 struct fs_context *fc)
1524 struct xfs_mount *mp = sb->s_fs_info;
1526 int flags = 0, error;
1530 error = xfs_fs_validate_params(mp);
1534 sb_min_blocksize(sb, BBSIZE);
1535 sb->s_xattr = xfs_xattr_handlers;
1536 sb->s_export_op = &xfs_export_operations;
1537 #ifdef CONFIG_XFS_QUOTA
1538 sb->s_qcop = &xfs_quotactl_operations;
1539 sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ;
1541 sb->s_op = &xfs_super_operations;
1544 * Delay mount work if the debug hook is set. This is debug
1545 * instrumention to coordinate simulation of xfs mount failures with
1546 * VFS superblock operations
1548 if (xfs_globals.mount_delay) {
1549 xfs_notice(mp, "Delaying mount for %d seconds.",
1550 xfs_globals.mount_delay);
1551 msleep(xfs_globals.mount_delay * 1000);
1554 if (fc->sb_flags & SB_SILENT)
1555 flags |= XFS_MFSI_QUIET;
1557 error = xfs_open_devices(mp);
1562 mp->m_debugfs = xfs_debugfs_mkdir(mp->m_super->s_id,
1565 mp->m_debugfs = NULL;
1568 error = xfs_init_mount_workqueues(mp);
1570 goto out_shutdown_devices;
1572 error = xfs_init_percpu_counters(mp);
1574 goto out_destroy_workqueues;
1576 error = xfs_inodegc_init_percpu(mp);
1578 goto out_destroy_counters;
1581 * All percpu data structures requiring cleanup when a cpu goes offline
1582 * must be allocated before adding this @mp to the cpu-dead handler's
1585 xfs_mount_list_add(mp);
1587 /* Allocate stats memory before we do operations that might use it */
1588 mp->m_stats.xs_stats = alloc_percpu(struct xfsstats);
1589 if (!mp->m_stats.xs_stats) {
1591 goto out_destroy_inodegc;
1594 error = xchk_mount_stats_alloc(mp);
1596 goto out_free_stats;
1598 error = xfs_readsb(mp, flags);
1600 goto out_free_scrub_stats;
1602 error = xfs_finish_flags(mp);
1606 error = xfs_setup_devices(mp);
1610 /* V4 support is undergoing deprecation. */
1611 if (!xfs_has_crc(mp)) {
1612 #ifdef CONFIG_XFS_SUPPORT_V4
1614 "Deprecated V4 format (crc=0) will not be supported after September 2030.");
1617 "Deprecated V4 format (crc=0) not supported by kernel.");
1623 /* ASCII case insensitivity is undergoing deprecation. */
1624 if (xfs_has_asciici(mp)) {
1625 #ifdef CONFIG_XFS_SUPPORT_ASCII_CI
1627 "Deprecated ASCII case-insensitivity feature (ascii-ci=1) will not be supported after September 2030.");
1630 "Deprecated ASCII case-insensitivity feature (ascii-ci=1) not supported by kernel.");
1636 /* Filesystem claims it needs repair, so refuse the mount. */
1637 if (xfs_has_needsrepair(mp)) {
1638 xfs_warn(mp, "Filesystem needs repair. Please run xfs_repair.");
1639 error = -EFSCORRUPTED;
1644 * Don't touch the filesystem if a user tool thinks it owns the primary
1645 * superblock. mkfs doesn't clear the flag from secondary supers, so
1646 * we don't check them at all.
1648 if (mp->m_sb.sb_inprogress) {
1649 xfs_warn(mp, "Offline file system operation in progress!");
1650 error = -EFSCORRUPTED;
1655 * Until this is fixed only page-sized or smaller data blocks work.
1657 if (mp->m_sb.sb_blocksize > PAGE_SIZE) {
1659 "File system with blocksize %d bytes. "
1660 "Only pagesize (%ld) or less will currently work.",
1661 mp->m_sb.sb_blocksize, PAGE_SIZE);
1666 /* Ensure this filesystem fits in the page cache limits */
1667 if (xfs_sb_validate_fsb_count(&mp->m_sb, mp->m_sb.sb_dblocks) ||
1668 xfs_sb_validate_fsb_count(&mp->m_sb, mp->m_sb.sb_rblocks)) {
1670 "file system too large to be mounted on this system.");
1676 * XFS block mappings use 54 bits to store the logical block offset.
1677 * This should suffice to handle the maximum file size that the VFS
1678 * supports (currently 2^63 bytes on 64-bit and ULONG_MAX << PAGE_SHIFT
1679 * bytes on 32-bit), but as XFS and VFS have gotten the s_maxbytes
1680 * calculation wrong on 32-bit kernels in the past, we'll add a WARN_ON
1681 * to check this assertion.
1683 * Avoid integer overflow by comparing the maximum bmbt offset to the
1684 * maximum pagecache offset in units of fs blocks.
1686 if (!xfs_verify_fileoff(mp, XFS_B_TO_FSBT(mp, MAX_LFS_FILESIZE))) {
1688 "MAX_LFS_FILESIZE block offset (%llu) exceeds extent map maximum (%llu)!",
1689 XFS_B_TO_FSBT(mp, MAX_LFS_FILESIZE),
1695 error = xfs_filestream_mount(mp);
1700 * we must configure the block size in the superblock before we run the
1701 * full mount process as the mount process can lookup and cache inodes.
1703 sb->s_magic = XFS_SUPER_MAGIC;
1704 sb->s_blocksize = mp->m_sb.sb_blocksize;
1705 sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
1706 sb->s_maxbytes = MAX_LFS_FILESIZE;
1707 sb->s_max_links = XFS_MAXLINK;
1708 sb->s_time_gran = 1;
1709 if (xfs_has_bigtime(mp)) {
1710 sb->s_time_min = xfs_bigtime_to_unix(XFS_BIGTIME_TIME_MIN);
1711 sb->s_time_max = xfs_bigtime_to_unix(XFS_BIGTIME_TIME_MAX);
1713 sb->s_time_min = XFS_LEGACY_TIME_MIN;
1714 sb->s_time_max = XFS_LEGACY_TIME_MAX;
1716 trace_xfs_inode_timestamp_range(mp, sb->s_time_min, sb->s_time_max);
1717 sb->s_iflags |= SB_I_CGROUPWB;
1719 set_posix_acl_flag(sb);
1721 /* version 5 superblocks support inode version counters. */
1722 if (xfs_has_crc(mp))
1723 sb->s_flags |= SB_I_VERSION;
1725 if (xfs_has_dax_always(mp)) {
1726 error = xfs_setup_dax_always(mp);
1728 goto out_filestream_unmount;
1731 if (xfs_has_discard(mp) && !bdev_max_discard_sectors(sb->s_bdev)) {
1733 "mounting with \"discard\" option, but the device does not support discard");
1734 mp->m_features &= ~XFS_FEAT_DISCARD;
1737 if (xfs_has_reflink(mp)) {
1738 if (mp->m_sb.sb_rblocks) {
1740 "reflink not compatible with realtime device!");
1742 goto out_filestream_unmount;
1745 if (xfs_globals.always_cow) {
1746 xfs_info(mp, "using DEBUG-only always_cow mode.");
1747 mp->m_always_cow = true;
1751 if (xfs_has_rmapbt(mp) && mp->m_sb.sb_rblocks) {
1753 "reverse mapping btree not compatible with realtime device!");
1755 goto out_filestream_unmount;
1758 error = xfs_mountfs(mp);
1760 goto out_filestream_unmount;
1762 root = igrab(VFS_I(mp->m_rootip));
1767 sb->s_root = d_make_root(root);
1775 out_filestream_unmount:
1776 xfs_filestream_unmount(mp);
1779 out_free_scrub_stats:
1780 xchk_mount_stats_free(mp);
1782 free_percpu(mp->m_stats.xs_stats);
1783 out_destroy_inodegc:
1784 xfs_mount_list_del(mp);
1785 xfs_inodegc_free_percpu(mp);
1786 out_destroy_counters:
1787 xfs_destroy_percpu_counters(mp);
1788 out_destroy_workqueues:
1789 xfs_destroy_mount_workqueues(mp);
1790 out_shutdown_devices:
1791 xfs_shutdown_devices(mp);
1795 xfs_filestream_unmount(mp);
1802 struct fs_context *fc)
1804 return get_tree_bdev(fc, xfs_fs_fill_super);
1809 struct xfs_mount *mp)
1811 struct xfs_sb *sbp = &mp->m_sb;
1814 if (xfs_has_norecovery(mp)) {
1816 "ro->rw transition prohibited on norecovery mount");
1820 if (xfs_sb_is_v5(sbp) &&
1821 xfs_sb_has_ro_compat_feature(sbp, XFS_SB_FEAT_RO_COMPAT_UNKNOWN)) {
1823 "ro->rw transition prohibited on unknown (0x%x) ro-compat filesystem",
1824 (sbp->sb_features_ro_compat &
1825 XFS_SB_FEAT_RO_COMPAT_UNKNOWN));
1829 clear_bit(XFS_OPSTATE_READONLY, &mp->m_opstate);
1832 * If this is the first remount to writeable state we might have some
1833 * superblock changes to update.
1835 if (mp->m_update_sb) {
1836 error = xfs_sync_sb(mp, false);
1838 xfs_warn(mp, "failed to write sb changes");
1841 mp->m_update_sb = false;
1845 * Fill out the reserve pool if it is empty. Use the stashed value if
1846 * it is non-zero, otherwise go with the default.
1848 xfs_restore_resvblks(mp);
1849 xfs_log_work_queue(mp);
1850 xfs_blockgc_start(mp);
1852 /* Create the per-AG metadata reservation pool .*/
1853 error = xfs_fs_reserve_ag_blocks(mp);
1854 if (error && error != -ENOSPC)
1857 /* Re-enable the background inode inactivation worker. */
1858 xfs_inodegc_start(mp);
1865 struct xfs_mount *mp)
1867 struct xfs_icwalk icw = {
1868 .icw_flags = XFS_ICWALK_FLAG_SYNC,
1872 /* Flush all the dirty data to disk. */
1873 error = sync_filesystem(mp->m_super);
1878 * Cancel background eofb scanning so it cannot race with the final
1879 * log force+buftarg wait and deadlock the remount.
1881 xfs_blockgc_stop(mp);
1884 * Clear out all remaining COW staging extents and speculative post-EOF
1885 * preallocations so that we don't leave inodes requiring inactivation
1886 * cleanups during reclaim on a read-only mount. We must process every
1887 * cached inode, so this requires a synchronous cache scan.
1889 error = xfs_blockgc_free_space(mp, &icw);
1891 xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
1896 * Stop the inodegc background worker. xfs_fs_reconfigure already
1897 * flushed all pending inodegc work when it sync'd the filesystem.
1898 * The VFS holds s_umount, so we know that inodes cannot enter
1899 * xfs_fs_destroy_inode during a remount operation. In readonly mode
1900 * we send inodes straight to reclaim, so no inodes will be queued.
1902 xfs_inodegc_stop(mp);
1904 /* Free the per-AG metadata reservation pool. */
1905 error = xfs_fs_unreserve_ag_blocks(mp);
1907 xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
1912 * Before we sync the metadata, we need to free up the reserve block
1913 * pool so that the used block count in the superblock on disk is
1914 * correct at the end of the remount. Stash the current* reserve pool
1915 * size so that if we get remounted rw, we can return it to the same
1918 xfs_save_resvblks(mp);
1921 set_bit(XFS_OPSTATE_READONLY, &mp->m_opstate);
1927 * Logically we would return an error here to prevent users from believing
1928 * they might have changed mount options using remount which can't be changed.
1930 * But unfortunately mount(8) adds all options from mtab and fstab to the mount
1931 * arguments in some cases so we can't blindly reject options, but have to
1932 * check for each specified option if it actually differs from the currently
1933 * set option and only reject it if that's the case.
1935 * Until that is implemented we return success for every remount request, and
1936 * silently ignore all options that we can't actually change.
1940 struct fs_context *fc)
1942 struct xfs_mount *mp = XFS_M(fc->root->d_sb);
1943 struct xfs_mount *new_mp = fc->s_fs_info;
1944 int flags = fc->sb_flags;
1947 /* version 5 superblocks always support version counters. */
1948 if (xfs_has_crc(mp))
1949 fc->sb_flags |= SB_I_VERSION;
1951 error = xfs_fs_validate_params(new_mp);
1955 /* inode32 -> inode64 */
1956 if (xfs_has_small_inums(mp) && !xfs_has_small_inums(new_mp)) {
1957 mp->m_features &= ~XFS_FEAT_SMALL_INUMS;
1958 mp->m_maxagi = xfs_set_inode_alloc(mp, mp->m_sb.sb_agcount);
1961 /* inode64 -> inode32 */
1962 if (!xfs_has_small_inums(mp) && xfs_has_small_inums(new_mp)) {
1963 mp->m_features |= XFS_FEAT_SMALL_INUMS;
1964 mp->m_maxagi = xfs_set_inode_alloc(mp, mp->m_sb.sb_agcount);
1968 if (xfs_is_readonly(mp) && !(flags & SB_RDONLY)) {
1969 error = xfs_remount_rw(mp);
1975 if (!xfs_is_readonly(mp) && (flags & SB_RDONLY)) {
1976 error = xfs_remount_ro(mp);
1986 struct fs_context *fc)
1988 struct xfs_mount *mp = fc->s_fs_info;
1991 * mp is stored in the fs_context when it is initialized.
1992 * mp is transferred to the superblock on a successful mount,
1993 * but if an error occurs before the transfer we have to free
2000 static const struct fs_context_operations xfs_context_ops = {
2001 .parse_param = xfs_fs_parse_param,
2002 .get_tree = xfs_fs_get_tree,
2003 .reconfigure = xfs_fs_reconfigure,
2004 .free = xfs_fs_free,
2007 static int xfs_init_fs_context(
2008 struct fs_context *fc)
2010 struct xfs_mount *mp;
2012 mp = kmem_alloc(sizeof(struct xfs_mount), KM_ZERO);
2016 spin_lock_init(&mp->m_sb_lock);
2017 INIT_RADIX_TREE(&mp->m_perag_tree, GFP_ATOMIC);
2018 spin_lock_init(&mp->m_perag_lock);
2019 mutex_init(&mp->m_growlock);
2020 INIT_WORK(&mp->m_flush_inodes_work, xfs_flush_inodes_worker);
2021 INIT_DELAYED_WORK(&mp->m_reclaim_work, xfs_reclaim_worker);
2022 mp->m_kobj.kobject.kset = xfs_kset;
2024 * We don't create the finobt per-ag space reservation until after log
2025 * recovery, so we must set this to true so that an ifree transaction
2026 * started during log recovery will not depend on space reservations
2027 * for finobt expansion.
2029 mp->m_finobt_nores = true;
2032 * These can be overridden by the mount option parsing.
2035 mp->m_logbsize = -1;
2036 mp->m_allocsize_log = 16; /* 64k */
2039 * Copy binary VFS mount flags we are interested in.
2041 if (fc->sb_flags & SB_RDONLY)
2042 set_bit(XFS_OPSTATE_READONLY, &mp->m_opstate);
2043 if (fc->sb_flags & SB_DIRSYNC)
2044 mp->m_features |= XFS_FEAT_DIRSYNC;
2045 if (fc->sb_flags & SB_SYNCHRONOUS)
2046 mp->m_features |= XFS_FEAT_WSYNC;
2049 fc->ops = &xfs_context_ops;
2056 struct super_block *sb)
2058 kill_block_super(sb);
2059 xfs_mount_free(XFS_M(sb));
2062 static struct file_system_type xfs_fs_type = {
2063 .owner = THIS_MODULE,
2065 .init_fs_context = xfs_init_fs_context,
2066 .parameters = xfs_fs_parameters,
2067 .kill_sb = xfs_kill_sb,
2068 .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP | FS_MGTIME,
2070 MODULE_ALIAS_FS("xfs");
2073 xfs_init_caches(void)
2077 xfs_buf_cache = kmem_cache_create("xfs_buf", sizeof(struct xfs_buf), 0,
2078 SLAB_HWCACHE_ALIGN |
2079 SLAB_RECLAIM_ACCOUNT |
2085 xfs_log_ticket_cache = kmem_cache_create("xfs_log_ticket",
2086 sizeof(struct xlog_ticket),
2088 if (!xfs_log_ticket_cache)
2089 goto out_destroy_buf_cache;
2091 error = xfs_btree_init_cur_caches();
2093 goto out_destroy_log_ticket_cache;
2095 error = xfs_defer_init_item_caches();
2097 goto out_destroy_btree_cur_cache;
2099 xfs_da_state_cache = kmem_cache_create("xfs_da_state",
2100 sizeof(struct xfs_da_state),
2102 if (!xfs_da_state_cache)
2103 goto out_destroy_defer_item_cache;
2105 xfs_ifork_cache = kmem_cache_create("xfs_ifork",
2106 sizeof(struct xfs_ifork),
2108 if (!xfs_ifork_cache)
2109 goto out_destroy_da_state_cache;
2111 xfs_trans_cache = kmem_cache_create("xfs_trans",
2112 sizeof(struct xfs_trans),
2114 if (!xfs_trans_cache)
2115 goto out_destroy_ifork_cache;
2119 * The size of the cache-allocated buf log item is the maximum
2120 * size possible under XFS. This wastes a little bit of memory,
2121 * but it is much faster.
2123 xfs_buf_item_cache = kmem_cache_create("xfs_buf_item",
2124 sizeof(struct xfs_buf_log_item),
2126 if (!xfs_buf_item_cache)
2127 goto out_destroy_trans_cache;
2129 xfs_efd_cache = kmem_cache_create("xfs_efd_item",
2130 xfs_efd_log_item_sizeof(XFS_EFD_MAX_FAST_EXTENTS),
2133 goto out_destroy_buf_item_cache;
2135 xfs_efi_cache = kmem_cache_create("xfs_efi_item",
2136 xfs_efi_log_item_sizeof(XFS_EFI_MAX_FAST_EXTENTS),
2139 goto out_destroy_efd_cache;
2141 xfs_inode_cache = kmem_cache_create("xfs_inode",
2142 sizeof(struct xfs_inode), 0,
2143 (SLAB_HWCACHE_ALIGN |
2144 SLAB_RECLAIM_ACCOUNT |
2145 SLAB_MEM_SPREAD | SLAB_ACCOUNT),
2146 xfs_fs_inode_init_once);
2147 if (!xfs_inode_cache)
2148 goto out_destroy_efi_cache;
2150 xfs_ili_cache = kmem_cache_create("xfs_ili",
2151 sizeof(struct xfs_inode_log_item), 0,
2152 SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD,
2155 goto out_destroy_inode_cache;
2157 xfs_icreate_cache = kmem_cache_create("xfs_icr",
2158 sizeof(struct xfs_icreate_item),
2160 if (!xfs_icreate_cache)
2161 goto out_destroy_ili_cache;
2163 xfs_rud_cache = kmem_cache_create("xfs_rud_item",
2164 sizeof(struct xfs_rud_log_item),
2167 goto out_destroy_icreate_cache;
2169 xfs_rui_cache = kmem_cache_create("xfs_rui_item",
2170 xfs_rui_log_item_sizeof(XFS_RUI_MAX_FAST_EXTENTS),
2173 goto out_destroy_rud_cache;
2175 xfs_cud_cache = kmem_cache_create("xfs_cud_item",
2176 sizeof(struct xfs_cud_log_item),
2179 goto out_destroy_rui_cache;
2181 xfs_cui_cache = kmem_cache_create("xfs_cui_item",
2182 xfs_cui_log_item_sizeof(XFS_CUI_MAX_FAST_EXTENTS),
2185 goto out_destroy_cud_cache;
2187 xfs_bud_cache = kmem_cache_create("xfs_bud_item",
2188 sizeof(struct xfs_bud_log_item),
2191 goto out_destroy_cui_cache;
2193 xfs_bui_cache = kmem_cache_create("xfs_bui_item",
2194 xfs_bui_log_item_sizeof(XFS_BUI_MAX_FAST_EXTENTS),
2197 goto out_destroy_bud_cache;
2199 xfs_attrd_cache = kmem_cache_create("xfs_attrd_item",
2200 sizeof(struct xfs_attrd_log_item),
2202 if (!xfs_attrd_cache)
2203 goto out_destroy_bui_cache;
2205 xfs_attri_cache = kmem_cache_create("xfs_attri_item",
2206 sizeof(struct xfs_attri_log_item),
2208 if (!xfs_attri_cache)
2209 goto out_destroy_attrd_cache;
2211 xfs_iunlink_cache = kmem_cache_create("xfs_iul_item",
2212 sizeof(struct xfs_iunlink_item),
2214 if (!xfs_iunlink_cache)
2215 goto out_destroy_attri_cache;
2219 out_destroy_attri_cache:
2220 kmem_cache_destroy(xfs_attri_cache);
2221 out_destroy_attrd_cache:
2222 kmem_cache_destroy(xfs_attrd_cache);
2223 out_destroy_bui_cache:
2224 kmem_cache_destroy(xfs_bui_cache);
2225 out_destroy_bud_cache:
2226 kmem_cache_destroy(xfs_bud_cache);
2227 out_destroy_cui_cache:
2228 kmem_cache_destroy(xfs_cui_cache);
2229 out_destroy_cud_cache:
2230 kmem_cache_destroy(xfs_cud_cache);
2231 out_destroy_rui_cache:
2232 kmem_cache_destroy(xfs_rui_cache);
2233 out_destroy_rud_cache:
2234 kmem_cache_destroy(xfs_rud_cache);
2235 out_destroy_icreate_cache:
2236 kmem_cache_destroy(xfs_icreate_cache);
2237 out_destroy_ili_cache:
2238 kmem_cache_destroy(xfs_ili_cache);
2239 out_destroy_inode_cache:
2240 kmem_cache_destroy(xfs_inode_cache);
2241 out_destroy_efi_cache:
2242 kmem_cache_destroy(xfs_efi_cache);
2243 out_destroy_efd_cache:
2244 kmem_cache_destroy(xfs_efd_cache);
2245 out_destroy_buf_item_cache:
2246 kmem_cache_destroy(xfs_buf_item_cache);
2247 out_destroy_trans_cache:
2248 kmem_cache_destroy(xfs_trans_cache);
2249 out_destroy_ifork_cache:
2250 kmem_cache_destroy(xfs_ifork_cache);
2251 out_destroy_da_state_cache:
2252 kmem_cache_destroy(xfs_da_state_cache);
2253 out_destroy_defer_item_cache:
2254 xfs_defer_destroy_item_caches();
2255 out_destroy_btree_cur_cache:
2256 xfs_btree_destroy_cur_caches();
2257 out_destroy_log_ticket_cache:
2258 kmem_cache_destroy(xfs_log_ticket_cache);
2259 out_destroy_buf_cache:
2260 kmem_cache_destroy(xfs_buf_cache);
2266 xfs_destroy_caches(void)
2269 * Make sure all delayed rcu free are flushed before we
2273 kmem_cache_destroy(xfs_iunlink_cache);
2274 kmem_cache_destroy(xfs_attri_cache);
2275 kmem_cache_destroy(xfs_attrd_cache);
2276 kmem_cache_destroy(xfs_bui_cache);
2277 kmem_cache_destroy(xfs_bud_cache);
2278 kmem_cache_destroy(xfs_cui_cache);
2279 kmem_cache_destroy(xfs_cud_cache);
2280 kmem_cache_destroy(xfs_rui_cache);
2281 kmem_cache_destroy(xfs_rud_cache);
2282 kmem_cache_destroy(xfs_icreate_cache);
2283 kmem_cache_destroy(xfs_ili_cache);
2284 kmem_cache_destroy(xfs_inode_cache);
2285 kmem_cache_destroy(xfs_efi_cache);
2286 kmem_cache_destroy(xfs_efd_cache);
2287 kmem_cache_destroy(xfs_buf_item_cache);
2288 kmem_cache_destroy(xfs_trans_cache);
2289 kmem_cache_destroy(xfs_ifork_cache);
2290 kmem_cache_destroy(xfs_da_state_cache);
2291 xfs_defer_destroy_item_caches();
2292 xfs_btree_destroy_cur_caches();
2293 kmem_cache_destroy(xfs_log_ticket_cache);
2294 kmem_cache_destroy(xfs_buf_cache);
2298 xfs_init_workqueues(void)
2301 * The allocation workqueue can be used in memory reclaim situations
2302 * (writepage path), and parallelism is only limited by the number of
2303 * AGs in all the filesystems mounted. Hence use the default large
2304 * max_active value for this workqueue.
2306 xfs_alloc_wq = alloc_workqueue("xfsalloc",
2307 XFS_WQFLAGS(WQ_MEM_RECLAIM | WQ_FREEZABLE), 0);
2311 xfs_discard_wq = alloc_workqueue("xfsdiscard", XFS_WQFLAGS(WQ_UNBOUND),
2313 if (!xfs_discard_wq)
2314 goto out_free_alloc_wq;
2318 destroy_workqueue(xfs_alloc_wq);
2323 xfs_destroy_workqueues(void)
2325 destroy_workqueue(xfs_discard_wq);
2326 destroy_workqueue(xfs_alloc_wq);
2329 #ifdef CONFIG_HOTPLUG_CPU
2334 struct xfs_mount *mp, *n;
2336 spin_lock(&xfs_mount_list_lock);
2337 list_for_each_entry_safe(mp, n, &xfs_mount_list, m_mount_list) {
2338 spin_unlock(&xfs_mount_list_lock);
2339 xfs_inodegc_cpu_dead(mp, cpu);
2340 xlog_cil_pcp_dead(mp->m_log, cpu);
2341 spin_lock(&xfs_mount_list_lock);
2343 spin_unlock(&xfs_mount_list_lock);
2348 xfs_cpu_hotplug_init(void)
2352 error = cpuhp_setup_state_nocalls(CPUHP_XFS_DEAD, "xfs:dead", NULL,
2356 "Failed to initialise CPU hotplug, error %d. XFS is non-functional.",
2362 xfs_cpu_hotplug_destroy(void)
2364 cpuhp_remove_state_nocalls(CPUHP_XFS_DEAD);
2367 #else /* !CONFIG_HOTPLUG_CPU */
2368 static inline int xfs_cpu_hotplug_init(void) { return 0; }
2369 static inline void xfs_cpu_hotplug_destroy(void) {}
2377 xfs_check_ondisk_structs();
2379 error = xfs_dahash_test();
2383 printk(KERN_INFO XFS_VERSION_STRING " with "
2384 XFS_BUILD_OPTIONS " enabled\n");
2388 error = xfs_cpu_hotplug_init();
2392 error = xfs_init_caches();
2394 goto out_destroy_hp;
2396 error = xfs_init_workqueues();
2398 goto out_destroy_caches;
2400 error = xfs_mru_cache_init();
2402 goto out_destroy_wq;
2404 error = xfs_init_procfs();
2406 goto out_mru_cache_uninit;
2408 error = xfs_sysctl_register();
2410 goto out_cleanup_procfs;
2412 xfs_debugfs = xfs_debugfs_mkdir("xfs", NULL);
2414 xfs_kset = kset_create_and_add("xfs", NULL, fs_kobj);
2417 goto out_debugfs_unregister;
2420 xfsstats.xs_kobj.kobject.kset = xfs_kset;
2422 xfsstats.xs_stats = alloc_percpu(struct xfsstats);
2423 if (!xfsstats.xs_stats) {
2425 goto out_kset_unregister;
2428 error = xfs_sysfs_init(&xfsstats.xs_kobj, &xfs_stats_ktype, NULL,
2431 goto out_free_stats;
2433 error = xchk_global_stats_setup(xfs_debugfs);
2435 goto out_remove_stats_kobj;
2438 xfs_dbg_kobj.kobject.kset = xfs_kset;
2439 error = xfs_sysfs_init(&xfs_dbg_kobj, &xfs_dbg_ktype, NULL, "debug");
2441 goto out_remove_scrub_stats;
2444 error = xfs_qm_init();
2446 goto out_remove_dbg_kobj;
2448 error = register_filesystem(&xfs_fs_type);
2455 out_remove_dbg_kobj:
2457 xfs_sysfs_del(&xfs_dbg_kobj);
2458 out_remove_scrub_stats:
2460 xchk_global_stats_teardown();
2461 out_remove_stats_kobj:
2462 xfs_sysfs_del(&xfsstats.xs_kobj);
2464 free_percpu(xfsstats.xs_stats);
2465 out_kset_unregister:
2466 kset_unregister(xfs_kset);
2467 out_debugfs_unregister:
2468 debugfs_remove(xfs_debugfs);
2469 xfs_sysctl_unregister();
2471 xfs_cleanup_procfs();
2472 out_mru_cache_uninit:
2473 xfs_mru_cache_uninit();
2475 xfs_destroy_workqueues();
2477 xfs_destroy_caches();
2479 xfs_cpu_hotplug_destroy();
2488 unregister_filesystem(&xfs_fs_type);
2490 xfs_sysfs_del(&xfs_dbg_kobj);
2492 xchk_global_stats_teardown();
2493 xfs_sysfs_del(&xfsstats.xs_kobj);
2494 free_percpu(xfsstats.xs_stats);
2495 kset_unregister(xfs_kset);
2496 debugfs_remove(xfs_debugfs);
2497 xfs_sysctl_unregister();
2498 xfs_cleanup_procfs();
2499 xfs_mru_cache_uninit();
2500 xfs_destroy_workqueues();
2501 xfs_destroy_caches();
2502 xfs_uuid_table_free();
2503 xfs_cpu_hotplug_destroy();
2506 module_init(init_xfs_fs);
2507 module_exit(exit_xfs_fs);
2509 MODULE_AUTHOR("Silicon Graphics, Inc.");
2510 MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
2511 MODULE_LICENSE("GPL");