1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2006 Silicon Graphics, Inc.
8 #include "xfs_shared.h"
9 #include "xfs_format.h"
10 #include "xfs_log_format.h"
11 #include "xfs_trans_resv.h"
13 #include "xfs_mount.h"
14 #include "xfs_inode.h"
15 #include "xfs_btree.h"
17 #include "xfs_alloc.h"
18 #include "xfs_fsops.h"
19 #include "xfs_trans.h"
20 #include "xfs_buf_item.h"
22 #include "xfs_log_priv.h"
24 #include "xfs_extfree_item.h"
25 #include "xfs_mru_cache.h"
26 #include "xfs_inode_item.h"
27 #include "xfs_icache.h"
28 #include "xfs_trace.h"
29 #include "xfs_icreate_item.h"
30 #include "xfs_filestream.h"
31 #include "xfs_quota.h"
32 #include "xfs_sysfs.h"
33 #include "xfs_ondisk.h"
34 #include "xfs_rmap_item.h"
35 #include "xfs_refcount_item.h"
36 #include "xfs_bmap_item.h"
37 #include "xfs_reflink.h"
39 #include <linux/magic.h>
40 #include <linux/fs_context.h>
41 #include <linux/fs_parser.h>
43 static const struct super_operations xfs_super_operations;
45 static struct kset *xfs_kset; /* top-level xfs sysfs dir */
47 static struct xfs_kobj xfs_dbg_kobj; /* global debug sysfs attrs */
51 * Table driven mount option parser.
54 Opt_logbufs, Opt_logbsize, Opt_logdev, Opt_rtdev,
55 Opt_wsync, Opt_noalign, Opt_swalloc, Opt_sunit, Opt_swidth, Opt_nouuid,
56 Opt_grpid, Opt_nogrpid, Opt_bsdgroups, Opt_sysvgroups,
57 Opt_allocsize, Opt_norecovery, Opt_inode64, Opt_inode32, Opt_ikeep,
58 Opt_noikeep, Opt_largeio, Opt_nolargeio, Opt_attr2, Opt_noattr2,
59 Opt_filestreams, Opt_quota, Opt_noquota, Opt_usrquota, Opt_grpquota,
60 Opt_prjquota, Opt_uquota, Opt_gquota, Opt_pquota,
61 Opt_uqnoenforce, Opt_gqnoenforce, Opt_pqnoenforce, Opt_qnoenforce,
62 Opt_discard, Opt_nodiscard, Opt_dax,
65 static const struct fs_parameter_spec xfs_param_specs[] = {
66 fsparam_u32("logbufs", Opt_logbufs),
67 fsparam_string("logbsize", Opt_logbsize),
68 fsparam_string("logdev", Opt_logdev),
69 fsparam_string("rtdev", Opt_rtdev),
70 fsparam_flag("wsync", Opt_wsync),
71 fsparam_flag("noalign", Opt_noalign),
72 fsparam_flag("swalloc", Opt_swalloc),
73 fsparam_u32("sunit", Opt_sunit),
74 fsparam_u32("swidth", Opt_swidth),
75 fsparam_flag("nouuid", Opt_nouuid),
76 fsparam_flag("grpid", Opt_grpid),
77 fsparam_flag("nogrpid", Opt_nogrpid),
78 fsparam_flag("bsdgroups", Opt_bsdgroups),
79 fsparam_flag("sysvgroups", Opt_sysvgroups),
80 fsparam_string("allocsize", Opt_allocsize),
81 fsparam_flag("norecovery", Opt_norecovery),
82 fsparam_flag("inode64", Opt_inode64),
83 fsparam_flag("inode32", Opt_inode32),
84 fsparam_flag("ikeep", Opt_ikeep),
85 fsparam_flag("noikeep", Opt_noikeep),
86 fsparam_flag("largeio", Opt_largeio),
87 fsparam_flag("nolargeio", Opt_nolargeio),
88 fsparam_flag("attr2", Opt_attr2),
89 fsparam_flag("noattr2", Opt_noattr2),
90 fsparam_flag("filestreams", Opt_filestreams),
91 fsparam_flag("quota", Opt_quota),
92 fsparam_flag("noquota", Opt_noquota),
93 fsparam_flag("usrquota", Opt_usrquota),
94 fsparam_flag("grpquota", Opt_grpquota),
95 fsparam_flag("prjquota", Opt_prjquota),
96 fsparam_flag("uquota", Opt_uquota),
97 fsparam_flag("gquota", Opt_gquota),
98 fsparam_flag("pquota", Opt_pquota),
99 fsparam_flag("uqnoenforce", Opt_uqnoenforce),
100 fsparam_flag("gqnoenforce", Opt_gqnoenforce),
101 fsparam_flag("pqnoenforce", Opt_pqnoenforce),
102 fsparam_flag("qnoenforce", Opt_qnoenforce),
103 fsparam_flag("discard", Opt_discard),
104 fsparam_flag("nodiscard", Opt_nodiscard),
105 fsparam_flag("dax", Opt_dax),
109 static const struct fs_parameter_description xfs_fs_parameters = {
110 .specs = xfs_param_specs,
113 struct proc_xfs_info {
123 static struct proc_xfs_info xfs_info_set[] = {
124 /* the few simple ones we can get from the mount struct */
125 { XFS_MOUNT_IKEEP, ",ikeep" },
126 { XFS_MOUNT_WSYNC, ",wsync" },
127 { XFS_MOUNT_NOALIGN, ",noalign" },
128 { XFS_MOUNT_SWALLOC, ",swalloc" },
129 { XFS_MOUNT_NOUUID, ",nouuid" },
130 { XFS_MOUNT_NORECOVERY, ",norecovery" },
131 { XFS_MOUNT_ATTR2, ",attr2" },
132 { XFS_MOUNT_FILESTREAMS, ",filestreams" },
133 { XFS_MOUNT_GRPID, ",grpid" },
134 { XFS_MOUNT_DISCARD, ",discard" },
135 { XFS_MOUNT_LARGEIO, ",largeio" },
136 { XFS_MOUNT_DAX, ",dax" },
139 struct xfs_mount *mp = XFS_M(root->d_sb);
140 struct proc_xfs_info *xfs_infop;
142 for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
143 if (mp->m_flags & xfs_infop->flag)
144 seq_puts(m, xfs_infop->str);
147 seq_printf(m, ",inode%d",
148 (mp->m_flags & XFS_MOUNT_SMALL_INUMS) ? 32 : 64);
150 if (mp->m_flags & XFS_MOUNT_ALLOCSIZE)
151 seq_printf(m, ",allocsize=%dk",
152 (1 << mp->m_allocsize_log) >> 10);
154 if (mp->m_logbufs > 0)
155 seq_printf(m, ",logbufs=%d", mp->m_logbufs);
156 if (mp->m_logbsize > 0)
157 seq_printf(m, ",logbsize=%dk", mp->m_logbsize >> 10);
160 seq_show_option(m, "logdev", mp->m_logname);
162 seq_show_option(m, "rtdev", mp->m_rtname);
164 if (mp->m_dalign > 0)
165 seq_printf(m, ",sunit=%d",
166 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
167 if (mp->m_swidth > 0)
168 seq_printf(m, ",swidth=%d",
169 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
171 if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD))
172 seq_puts(m, ",usrquota");
173 else if (mp->m_qflags & XFS_UQUOTA_ACCT)
174 seq_puts(m, ",uqnoenforce");
176 if (mp->m_qflags & XFS_PQUOTA_ACCT) {
177 if (mp->m_qflags & XFS_PQUOTA_ENFD)
178 seq_puts(m, ",prjquota");
180 seq_puts(m, ",pqnoenforce");
182 if (mp->m_qflags & XFS_GQUOTA_ACCT) {
183 if (mp->m_qflags & XFS_GQUOTA_ENFD)
184 seq_puts(m, ",grpquota");
186 seq_puts(m, ",gqnoenforce");
189 if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
190 seq_puts(m, ",noquota");
197 unsigned int blockshift)
199 unsigned int pagefactor = 1;
200 unsigned int bitshift = BITS_PER_LONG - 1;
202 /* Figure out maximum filesize, on Linux this can depend on
203 * the filesystem blocksize (on 32 bit platforms).
204 * __block_write_begin does this in an [unsigned] long long...
205 * page->index << (PAGE_SHIFT - bbits)
206 * So, for page sized blocks (4K on 32 bit platforms),
207 * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
208 * (((u64)PAGE_SIZE << (BITS_PER_LONG-1))-1)
209 * but for smaller blocksizes it is less (bbits = log2 bsize).
212 #if BITS_PER_LONG == 32
213 ASSERT(sizeof(sector_t) == 8);
214 pagefactor = PAGE_SIZE;
215 bitshift = BITS_PER_LONG;
218 return (((uint64_t)pagefactor) << bitshift) - 1;
222 * Set parameters for inode allocation heuristics, taking into account
223 * filesystem size and inode32/inode64 mount options; i.e. specifically
224 * whether or not XFS_MOUNT_SMALL_INUMS is set.
226 * Inode allocation patterns are altered only if inode32 is requested
227 * (XFS_MOUNT_SMALL_INUMS), and the filesystem is sufficiently large.
228 * If altered, XFS_MOUNT_32BITINODES is set as well.
230 * An agcount independent of that in the mount structure is provided
231 * because in the growfs case, mp->m_sb.sb_agcount is not yet updated
232 * to the potentially higher ag count.
234 * Returns the maximum AG index which may contain inodes.
238 struct xfs_mount *mp,
239 xfs_agnumber_t agcount)
241 xfs_agnumber_t index;
242 xfs_agnumber_t maxagi = 0;
243 xfs_sb_t *sbp = &mp->m_sb;
244 xfs_agnumber_t max_metadata;
249 * Calculate how much should be reserved for inodes to meet
250 * the max inode percentage. Used only for inode32.
252 if (M_IGEO(mp)->maxicount) {
255 icount = sbp->sb_dblocks * sbp->sb_imax_pct;
257 icount += sbp->sb_agblocks - 1;
258 do_div(icount, sbp->sb_agblocks);
259 max_metadata = icount;
261 max_metadata = agcount;
264 /* Get the last possible inode in the filesystem */
265 agino = XFS_AGB_TO_AGINO(mp, sbp->sb_agblocks - 1);
266 ino = XFS_AGINO_TO_INO(mp, agcount - 1, agino);
269 * If user asked for no more than 32-bit inodes, and the fs is
270 * sufficiently large, set XFS_MOUNT_32BITINODES if we must alter
271 * the allocator to accommodate the request.
273 if ((mp->m_flags & XFS_MOUNT_SMALL_INUMS) && ino > XFS_MAXINUMBER_32)
274 mp->m_flags |= XFS_MOUNT_32BITINODES;
276 mp->m_flags &= ~XFS_MOUNT_32BITINODES;
278 for (index = 0; index < agcount; index++) {
279 struct xfs_perag *pag;
281 ino = XFS_AGINO_TO_INO(mp, index, agino);
283 pag = xfs_perag_get(mp, index);
285 if (mp->m_flags & XFS_MOUNT_32BITINODES) {
286 if (ino > XFS_MAXINUMBER_32) {
287 pag->pagi_inodeok = 0;
288 pag->pagf_metadata = 0;
290 pag->pagi_inodeok = 1;
292 if (index < max_metadata)
293 pag->pagf_metadata = 1;
295 pag->pagf_metadata = 0;
298 pag->pagi_inodeok = 1;
299 pag->pagf_metadata = 0;
305 return (mp->m_flags & XFS_MOUNT_32BITINODES) ? maxagi : agcount;
312 struct block_device **bdevp)
316 *bdevp = blkdev_get_by_path(name, FMODE_READ|FMODE_WRITE|FMODE_EXCL,
318 if (IS_ERR(*bdevp)) {
319 error = PTR_ERR(*bdevp);
320 xfs_warn(mp, "Invalid device [%s], error=%d", name, error);
328 struct block_device *bdev)
331 blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
335 xfs_blkdev_issue_flush(
336 xfs_buftarg_t *buftarg)
338 blkdev_issue_flush(buftarg->bt_bdev, GFP_NOFS, NULL);
343 struct xfs_mount *mp)
345 struct dax_device *dax_ddev = mp->m_ddev_targp->bt_daxdev;
347 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
348 struct block_device *logdev = mp->m_logdev_targp->bt_bdev;
349 struct dax_device *dax_logdev = mp->m_logdev_targp->bt_daxdev;
351 xfs_free_buftarg(mp->m_logdev_targp);
352 xfs_blkdev_put(logdev);
353 fs_put_dax(dax_logdev);
355 if (mp->m_rtdev_targp) {
356 struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev;
357 struct dax_device *dax_rtdev = mp->m_rtdev_targp->bt_daxdev;
359 xfs_free_buftarg(mp->m_rtdev_targp);
360 xfs_blkdev_put(rtdev);
361 fs_put_dax(dax_rtdev);
363 xfs_free_buftarg(mp->m_ddev_targp);
364 fs_put_dax(dax_ddev);
368 * The file system configurations are:
369 * (1) device (partition) with data and internal log
370 * (2) logical volume with data and log subvolumes.
371 * (3) logical volume with data, log, and realtime subvolumes.
373 * We only have to handle opening the log and realtime volumes here if
374 * they are present. The data subvolume has already been opened by
375 * get_sb_bdev() and is stored in sb->s_bdev.
379 struct xfs_mount *mp)
381 struct block_device *ddev = mp->m_super->s_bdev;
382 struct dax_device *dax_ddev = fs_dax_get_by_bdev(ddev);
383 struct dax_device *dax_logdev = NULL, *dax_rtdev = NULL;
384 struct block_device *logdev = NULL, *rtdev = NULL;
388 * Open real time and log devices - order is important.
391 error = xfs_blkdev_get(mp, mp->m_logname, &logdev);
394 dax_logdev = fs_dax_get_by_bdev(logdev);
398 error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev);
400 goto out_close_logdev;
402 if (rtdev == ddev || rtdev == logdev) {
404 "Cannot mount filesystem with identical rtdev and ddev/logdev.");
406 goto out_close_rtdev;
408 dax_rtdev = fs_dax_get_by_bdev(rtdev);
412 * Setup xfs_mount buffer target pointers
415 mp->m_ddev_targp = xfs_alloc_buftarg(mp, ddev, dax_ddev);
416 if (!mp->m_ddev_targp)
417 goto out_close_rtdev;
420 mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev, dax_rtdev);
421 if (!mp->m_rtdev_targp)
422 goto out_free_ddev_targ;
425 if (logdev && logdev != ddev) {
426 mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev, dax_logdev);
427 if (!mp->m_logdev_targp)
428 goto out_free_rtdev_targ;
430 mp->m_logdev_targp = mp->m_ddev_targp;
436 if (mp->m_rtdev_targp)
437 xfs_free_buftarg(mp->m_rtdev_targp);
439 xfs_free_buftarg(mp->m_ddev_targp);
441 xfs_blkdev_put(rtdev);
442 fs_put_dax(dax_rtdev);
444 if (logdev && logdev != ddev) {
445 xfs_blkdev_put(logdev);
446 fs_put_dax(dax_logdev);
449 fs_put_dax(dax_ddev);
454 * Setup xfs_mount buffer target pointers based on superblock
458 struct xfs_mount *mp)
462 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_sectsize);
466 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
467 unsigned int log_sector_size = BBSIZE;
469 if (xfs_sb_version_hassector(&mp->m_sb))
470 log_sector_size = mp->m_sb.sb_logsectsize;
471 error = xfs_setsize_buftarg(mp->m_logdev_targp,
476 if (mp->m_rtdev_targp) {
477 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
478 mp->m_sb.sb_sectsize);
487 xfs_init_mount_workqueues(
488 struct xfs_mount *mp)
490 mp->m_buf_workqueue = alloc_workqueue("xfs-buf/%s",
491 WQ_MEM_RECLAIM|WQ_FREEZABLE, 1, mp->m_super->s_id);
492 if (!mp->m_buf_workqueue)
495 mp->m_unwritten_workqueue = alloc_workqueue("xfs-conv/%s",
496 WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_super->s_id);
497 if (!mp->m_unwritten_workqueue)
498 goto out_destroy_buf;
500 mp->m_cil_workqueue = alloc_workqueue("xfs-cil/%s",
501 WQ_MEM_RECLAIM | WQ_FREEZABLE | WQ_UNBOUND,
502 0, mp->m_super->s_id);
503 if (!mp->m_cil_workqueue)
504 goto out_destroy_unwritten;
506 mp->m_reclaim_workqueue = alloc_workqueue("xfs-reclaim/%s",
507 WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_super->s_id);
508 if (!mp->m_reclaim_workqueue)
509 goto out_destroy_cil;
511 mp->m_eofblocks_workqueue = alloc_workqueue("xfs-eofblocks/%s",
512 WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_super->s_id);
513 if (!mp->m_eofblocks_workqueue)
514 goto out_destroy_reclaim;
516 mp->m_sync_workqueue = alloc_workqueue("xfs-sync/%s", WQ_FREEZABLE, 0,
518 if (!mp->m_sync_workqueue)
519 goto out_destroy_eofb;
524 destroy_workqueue(mp->m_eofblocks_workqueue);
526 destroy_workqueue(mp->m_reclaim_workqueue);
528 destroy_workqueue(mp->m_cil_workqueue);
529 out_destroy_unwritten:
530 destroy_workqueue(mp->m_unwritten_workqueue);
532 destroy_workqueue(mp->m_buf_workqueue);
538 xfs_destroy_mount_workqueues(
539 struct xfs_mount *mp)
541 destroy_workqueue(mp->m_sync_workqueue);
542 destroy_workqueue(mp->m_eofblocks_workqueue);
543 destroy_workqueue(mp->m_reclaim_workqueue);
544 destroy_workqueue(mp->m_cil_workqueue);
545 destroy_workqueue(mp->m_unwritten_workqueue);
546 destroy_workqueue(mp->m_buf_workqueue);
550 * Flush all dirty data to disk. Must not be called while holding an XFS_ILOCK
551 * or a page lock. We use sync_inodes_sb() here to ensure we block while waiting
552 * for IO to complete so that we effectively throttle multiple callers to the
553 * rate at which IO is completing.
557 struct xfs_mount *mp)
559 struct super_block *sb = mp->m_super;
561 if (down_read_trylock(&sb->s_umount)) {
563 up_read(&sb->s_umount);
567 /* Catch misguided souls that try to use this interface on XFS */
568 STATIC struct inode *
570 struct super_block *sb)
579 struct xfs_inode *ip,
582 struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, whichfork);
583 struct xfs_bmbt_irec got;
584 struct xfs_iext_cursor icur;
586 if (!ifp || !xfs_iext_lookup_extent(ip, ifp, 0, &icur, &got))
589 if (isnullstartblock(got.br_startblock)) {
590 xfs_warn(ip->i_mount,
591 "ino %llx %s fork has delalloc extent at [0x%llx:0x%llx]",
593 whichfork == XFS_DATA_FORK ? "data" : "cow",
594 got.br_startoff, got.br_blockcount);
596 } while (xfs_iext_next_extent(ifp, &icur, &got));
599 #define xfs_check_delalloc(ip, whichfork) do { } while (0)
603 * Now that the generic code is guaranteed not to be accessing
604 * the linux inode, we can inactivate and reclaim the inode.
607 xfs_fs_destroy_inode(
610 struct xfs_inode *ip = XFS_I(inode);
612 trace_xfs_destroy_inode(ip);
614 ASSERT(!rwsem_is_locked(&inode->i_rwsem));
615 XFS_STATS_INC(ip->i_mount, vn_rele);
616 XFS_STATS_INC(ip->i_mount, vn_remove);
620 if (!XFS_FORCED_SHUTDOWN(ip->i_mount) && ip->i_delayed_blks) {
621 xfs_check_delalloc(ip, XFS_DATA_FORK);
622 xfs_check_delalloc(ip, XFS_COW_FORK);
626 XFS_STATS_INC(ip->i_mount, vn_reclaim);
629 * We should never get here with one of the reclaim flags already set.
631 ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIMABLE));
632 ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIM));
635 * We always use background reclaim here because even if the
636 * inode is clean, it still may be under IO and hence we have
637 * to take the flush lock. The background reclaim path handles
638 * this more efficiently than we can here, so simply let background
639 * reclaim tear down all inodes.
641 xfs_inode_set_reclaim_tag(ip);
649 struct xfs_inode *ip = XFS_I(inode);
650 struct xfs_mount *mp = ip->i_mount;
651 struct xfs_trans *tp;
653 if (!(inode->i_sb->s_flags & SB_LAZYTIME))
655 if (flag != I_DIRTY_SYNC || !(inode->i_state & I_DIRTY_TIME))
658 if (xfs_trans_alloc(mp, &M_RES(mp)->tr_fsyncts, 0, 0, 0, &tp))
660 xfs_ilock(ip, XFS_ILOCK_EXCL);
661 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
662 xfs_trans_log_inode(tp, ip, XFS_ILOG_TIMESTAMP);
663 xfs_trans_commit(tp);
667 * Slab object creation initialisation for the XFS inode.
668 * This covers only the idempotent fields in the XFS inode;
669 * all other fields need to be initialised on allocation
670 * from the slab. This avoids the need to repeatedly initialise
671 * fields in the xfs inode that left in the initialise state
672 * when freeing the inode.
675 xfs_fs_inode_init_once(
678 struct xfs_inode *ip = inode;
680 memset(ip, 0, sizeof(struct xfs_inode));
683 inode_init_once(VFS_I(ip));
686 atomic_set(&ip->i_pincount, 0);
687 spin_lock_init(&ip->i_flags_lock);
689 mrlock_init(&ip->i_mmaplock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
690 "xfsino", ip->i_ino);
691 mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
692 "xfsino", ip->i_ino);
696 * We do an unlocked check for XFS_IDONTCACHE here because we are already
697 * serialised against cache hits here via the inode->i_lock and igrab() in
698 * xfs_iget_cache_hit(). Hence a lookup that might clear this flag will not be
699 * racing with us, and it avoids needing to grab a spinlock here for every inode
700 * we drop the final reference on.
706 struct xfs_inode *ip = XFS_I(inode);
709 * If this unlinked inode is in the middle of recovery, don't
710 * drop the inode just yet; log recovery will take care of
711 * that. See the comment for this inode flag.
713 if (ip->i_flags & XFS_IRECOVERY) {
714 ASSERT(ip->i_mount->m_log->l_flags & XLOG_RECOVERY_NEEDED);
718 return generic_drop_inode(inode) || (ip->i_flags & XFS_IDONTCACHE);
723 struct xfs_mount *mp)
726 kfree(mp->m_logname);
732 struct super_block *sb,
735 struct xfs_mount *mp = XFS_M(sb);
738 * Doing anything during the async pass would be counterproductive.
743 xfs_log_force(mp, XFS_LOG_SYNC);
746 * The disk must be active because we're syncing.
747 * We schedule log work now (now that the disk is
748 * active) instead of later (when it might not be).
750 flush_delayed_work(&mp->m_log->l_work);
758 struct dentry *dentry,
759 struct kstatfs *statp)
761 struct xfs_mount *mp = XFS_M(dentry->d_sb);
762 xfs_sb_t *sbp = &mp->m_sb;
763 struct xfs_inode *ip = XFS_I(d_inode(dentry));
764 uint64_t fakeinos, id;
771 statp->f_type = XFS_SUPER_MAGIC;
772 statp->f_namelen = MAXNAMELEN - 1;
774 id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
775 statp->f_fsid.val[0] = (u32)id;
776 statp->f_fsid.val[1] = (u32)(id >> 32);
778 icount = percpu_counter_sum(&mp->m_icount);
779 ifree = percpu_counter_sum(&mp->m_ifree);
780 fdblocks = percpu_counter_sum(&mp->m_fdblocks);
782 spin_lock(&mp->m_sb_lock);
783 statp->f_bsize = sbp->sb_blocksize;
784 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
785 statp->f_blocks = sbp->sb_dblocks - lsize;
786 spin_unlock(&mp->m_sb_lock);
788 statp->f_bfree = fdblocks - mp->m_alloc_set_aside;
789 statp->f_bavail = statp->f_bfree;
791 fakeinos = XFS_FSB_TO_INO(mp, statp->f_bfree);
792 statp->f_files = min(icount + fakeinos, (uint64_t)XFS_MAXINUMBER);
793 if (M_IGEO(mp)->maxicount)
794 statp->f_files = min_t(typeof(statp->f_files),
796 M_IGEO(mp)->maxicount);
798 /* If sb_icount overshot maxicount, report actual allocation */
799 statp->f_files = max_t(typeof(statp->f_files),
803 /* make sure statp->f_ffree does not underflow */
804 ffree = statp->f_files - (icount - ifree);
805 statp->f_ffree = max_t(int64_t, ffree, 0);
808 if ((ip->i_d.di_flags & XFS_DIFLAG_PROJINHERIT) &&
809 ((mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))) ==
810 (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))
811 xfs_qm_statvfs(ip, statp);
813 if (XFS_IS_REALTIME_MOUNT(mp) &&
814 (ip->i_d.di_flags & (XFS_DIFLAG_RTINHERIT | XFS_DIFLAG_REALTIME))) {
815 statp->f_blocks = sbp->sb_rblocks;
816 statp->f_bavail = statp->f_bfree =
817 sbp->sb_frextents * sbp->sb_rextsize;
824 xfs_save_resvblks(struct xfs_mount *mp)
826 uint64_t resblks = 0;
828 mp->m_resblks_save = mp->m_resblks;
829 xfs_reserve_blocks(mp, &resblks, NULL);
833 xfs_restore_resvblks(struct xfs_mount *mp)
837 if (mp->m_resblks_save) {
838 resblks = mp->m_resblks_save;
839 mp->m_resblks_save = 0;
841 resblks = xfs_default_resblks(mp);
843 xfs_reserve_blocks(mp, &resblks, NULL);
847 * Trigger writeback of all the dirty metadata in the file system.
849 * This ensures that the metadata is written to their location on disk rather
850 * than just existing in transactions in the log. This means after a quiesce
851 * there is no log replay required to write the inodes to disk - this is the
852 * primary difference between a sync and a quiesce.
854 * Note: xfs_log_quiesce() stops background log work - the callers must ensure
855 * it is started again when appropriate.
859 struct xfs_mount *mp)
863 /* wait for all modifications to complete */
864 while (atomic_read(&mp->m_active_trans) > 0)
867 /* force the log to unpin objects from the now complete transactions */
868 xfs_log_force(mp, XFS_LOG_SYNC);
870 /* reclaim inodes to do any IO before the freeze completes */
871 xfs_reclaim_inodes(mp, 0);
872 xfs_reclaim_inodes(mp, SYNC_WAIT);
874 /* Push the superblock and write an unmount record */
875 error = xfs_log_sbcount(mp);
877 xfs_warn(mp, "xfs_attr_quiesce: failed to log sb changes. "
878 "Frozen image may not be consistent.");
880 * Just warn here till VFS can correctly support
881 * read-only remount without racing.
883 WARN_ON(atomic_read(&mp->m_active_trans) != 0);
889 * Second stage of a freeze. The data is already frozen so we only
890 * need to take care of the metadata. Once that's done sync the superblock
891 * to the log to dirty it in case of a crash while frozen. This ensures that we
892 * will recover the unlinked inode lists on the next mount.
896 struct super_block *sb)
898 struct xfs_mount *mp = XFS_M(sb);
900 xfs_stop_block_reaping(mp);
901 xfs_save_resvblks(mp);
902 xfs_quiesce_attr(mp);
903 return xfs_sync_sb(mp, true);
908 struct super_block *sb)
910 struct xfs_mount *mp = XFS_M(sb);
912 xfs_restore_resvblks(mp);
913 xfs_log_work_queue(mp);
914 xfs_start_block_reaping(mp);
919 * This function fills in xfs_mount_t fields based on mount args.
920 * Note: the superblock _has_ now been read in.
924 struct xfs_mount *mp)
926 int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
928 /* Fail a mount where the logbuf is smaller than the log stripe */
929 if (xfs_sb_version_haslogv2(&mp->m_sb)) {
930 if (mp->m_logbsize <= 0 &&
931 mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE) {
932 mp->m_logbsize = mp->m_sb.sb_logsunit;
933 } else if (mp->m_logbsize > 0 &&
934 mp->m_logbsize < mp->m_sb.sb_logsunit) {
936 "logbuf size must be greater than or equal to log stripe size");
940 /* Fail a mount if the logbuf is larger than 32K */
941 if (mp->m_logbsize > XLOG_BIG_RECORD_BSIZE) {
943 "logbuf size for version 1 logs must be 16K or 32K");
949 * V5 filesystems always use attr2 format for attributes.
951 if (xfs_sb_version_hascrc(&mp->m_sb) &&
952 (mp->m_flags & XFS_MOUNT_NOATTR2)) {
953 xfs_warn(mp, "Cannot mount a V5 filesystem as noattr2. "
954 "attr2 is always enabled for V5 filesystems.");
959 * mkfs'ed attr2 will turn on attr2 mount unless explicitly
960 * told by noattr2 to turn it off
962 if (xfs_sb_version_hasattr2(&mp->m_sb) &&
963 !(mp->m_flags & XFS_MOUNT_NOATTR2))
964 mp->m_flags |= XFS_MOUNT_ATTR2;
967 * prohibit r/w mounts of read-only filesystems
969 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
971 "cannot mount a read-only filesystem as read-write");
975 if ((mp->m_qflags & (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE)) &&
976 (mp->m_qflags & (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE)) &&
977 !xfs_sb_version_has_pquotino(&mp->m_sb)) {
979 "Super block does not support project and group quota together");
987 xfs_init_percpu_counters(
988 struct xfs_mount *mp)
992 error = percpu_counter_init(&mp->m_icount, 0, GFP_KERNEL);
996 error = percpu_counter_init(&mp->m_ifree, 0, GFP_KERNEL);
1000 error = percpu_counter_init(&mp->m_fdblocks, 0, GFP_KERNEL);
1004 error = percpu_counter_init(&mp->m_delalloc_blks, 0, GFP_KERNEL);
1011 percpu_counter_destroy(&mp->m_fdblocks);
1013 percpu_counter_destroy(&mp->m_ifree);
1015 percpu_counter_destroy(&mp->m_icount);
1020 xfs_reinit_percpu_counters(
1021 struct xfs_mount *mp)
1023 percpu_counter_set(&mp->m_icount, mp->m_sb.sb_icount);
1024 percpu_counter_set(&mp->m_ifree, mp->m_sb.sb_ifree);
1025 percpu_counter_set(&mp->m_fdblocks, mp->m_sb.sb_fdblocks);
1029 xfs_destroy_percpu_counters(
1030 struct xfs_mount *mp)
1032 percpu_counter_destroy(&mp->m_icount);
1033 percpu_counter_destroy(&mp->m_ifree);
1034 percpu_counter_destroy(&mp->m_fdblocks);
1035 ASSERT(XFS_FORCED_SHUTDOWN(mp) ||
1036 percpu_counter_sum(&mp->m_delalloc_blks) == 0);
1037 percpu_counter_destroy(&mp->m_delalloc_blks);
1042 struct super_block *sb)
1044 struct xfs_mount *mp = XFS_M(sb);
1046 /* if ->fill_super failed, we have no mount to tear down */
1050 xfs_notice(mp, "Unmounting Filesystem");
1051 xfs_filestream_unmount(mp);
1055 free_percpu(mp->m_stats.xs_stats);
1056 xfs_destroy_percpu_counters(mp);
1057 xfs_destroy_mount_workqueues(mp);
1058 xfs_close_devices(mp);
1060 sb->s_fs_info = NULL;
1065 xfs_fs_nr_cached_objects(
1066 struct super_block *sb,
1067 struct shrink_control *sc)
1069 /* Paranoia: catch incorrect calls during mount setup or teardown */
1070 if (WARN_ON_ONCE(!sb->s_fs_info))
1072 return xfs_reclaim_inodes_count(XFS_M(sb));
1076 xfs_fs_free_cached_objects(
1077 struct super_block *sb,
1078 struct shrink_control *sc)
1080 return xfs_reclaim_inodes_nr(XFS_M(sb), sc->nr_to_scan);
1083 static const struct super_operations xfs_super_operations = {
1084 .alloc_inode = xfs_fs_alloc_inode,
1085 .destroy_inode = xfs_fs_destroy_inode,
1086 .dirty_inode = xfs_fs_dirty_inode,
1087 .drop_inode = xfs_fs_drop_inode,
1088 .put_super = xfs_fs_put_super,
1089 .sync_fs = xfs_fs_sync_fs,
1090 .freeze_fs = xfs_fs_freeze,
1091 .unfreeze_fs = xfs_fs_unfreeze,
1092 .statfs = xfs_fs_statfs,
1093 .show_options = xfs_fs_show_options,
1094 .nr_cached_objects = xfs_fs_nr_cached_objects,
1095 .free_cached_objects = xfs_fs_free_cached_objects,
1104 int last, shift_left_factor = 0, _res;
1108 value = kstrdup(s, GFP_KERNEL);
1112 last = strlen(value) - 1;
1113 if (value[last] == 'K' || value[last] == 'k') {
1114 shift_left_factor = 10;
1117 if (value[last] == 'M' || value[last] == 'm') {
1118 shift_left_factor = 20;
1121 if (value[last] == 'G' || value[last] == 'g') {
1122 shift_left_factor = 30;
1126 if (kstrtoint(value, base, &_res))
1129 *res = _res << shift_left_factor;
1134 * Set mount state from a mount option.
1136 * NOTE: mp->m_super is NULL here!
1140 struct fs_context *fc,
1141 struct fs_parameter *param)
1143 struct xfs_mount *mp = fc->s_fs_info;
1144 struct fs_parse_result result;
1148 opt = fs_parse(fc, &xfs_fs_parameters, param, &result);
1154 mp->m_logbufs = result.uint_32;
1157 if (suffix_kstrtoint(param->string, 10, &mp->m_logbsize))
1161 kfree(mp->m_logname);
1162 mp->m_logname = kstrdup(param->string, GFP_KERNEL);
1167 kfree(mp->m_rtname);
1168 mp->m_rtname = kstrdup(param->string, GFP_KERNEL);
1173 if (suffix_kstrtoint(param->string, 10, &size))
1175 mp->m_allocsize_log = ffs(size) - 1;
1176 mp->m_flags |= XFS_MOUNT_ALLOCSIZE;
1180 mp->m_flags |= XFS_MOUNT_GRPID;
1183 case Opt_sysvgroups:
1184 mp->m_flags &= ~XFS_MOUNT_GRPID;
1187 mp->m_flags |= XFS_MOUNT_WSYNC;
1189 case Opt_norecovery:
1190 mp->m_flags |= XFS_MOUNT_NORECOVERY;
1193 mp->m_flags |= XFS_MOUNT_NOALIGN;
1196 mp->m_flags |= XFS_MOUNT_SWALLOC;
1199 mp->m_dalign = result.uint_32;
1202 mp->m_swidth = result.uint_32;
1205 mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
1208 mp->m_flags &= ~XFS_MOUNT_SMALL_INUMS;
1211 mp->m_flags |= XFS_MOUNT_NOUUID;
1214 mp->m_flags |= XFS_MOUNT_IKEEP;
1217 mp->m_flags &= ~XFS_MOUNT_IKEEP;
1220 mp->m_flags |= XFS_MOUNT_LARGEIO;
1223 mp->m_flags &= ~XFS_MOUNT_LARGEIO;
1226 mp->m_flags |= XFS_MOUNT_ATTR2;
1229 mp->m_flags &= ~XFS_MOUNT_ATTR2;
1230 mp->m_flags |= XFS_MOUNT_NOATTR2;
1232 case Opt_filestreams:
1233 mp->m_flags |= XFS_MOUNT_FILESTREAMS;
1236 mp->m_qflags &= ~XFS_ALL_QUOTA_ACCT;
1237 mp->m_qflags &= ~XFS_ALL_QUOTA_ENFD;
1238 mp->m_qflags &= ~XFS_ALL_QUOTA_ACTIVE;
1243 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE |
1246 case Opt_qnoenforce:
1247 case Opt_uqnoenforce:
1248 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
1249 mp->m_qflags &= ~XFS_UQUOTA_ENFD;
1253 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE |
1256 case Opt_pqnoenforce:
1257 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
1258 mp->m_qflags &= ~XFS_PQUOTA_ENFD;
1262 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE |
1265 case Opt_gqnoenforce:
1266 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
1267 mp->m_qflags &= ~XFS_GQUOTA_ENFD;
1270 mp->m_flags |= XFS_MOUNT_DISCARD;
1273 mp->m_flags &= ~XFS_MOUNT_DISCARD;
1275 #ifdef CONFIG_FS_DAX
1277 mp->m_flags |= XFS_MOUNT_DAX;
1281 xfs_warn(mp, "unknown mount option [%s].", param->key);
1289 xfs_fc_validate_params(
1290 struct xfs_mount *mp)
1293 * no recovery flag requires a read-only mount
1295 if ((mp->m_flags & XFS_MOUNT_NORECOVERY) &&
1296 !(mp->m_flags & XFS_MOUNT_RDONLY)) {
1297 xfs_warn(mp, "no-recovery mounts must be read-only.");
1301 if ((mp->m_flags & XFS_MOUNT_NOALIGN) &&
1302 (mp->m_dalign || mp->m_swidth)) {
1304 "sunit and swidth options incompatible with the noalign option");
1308 if (!IS_ENABLED(CONFIG_XFS_QUOTA) && mp->m_qflags != 0) {
1309 xfs_warn(mp, "quota support not available in this kernel.");
1313 if ((mp->m_dalign && !mp->m_swidth) ||
1314 (!mp->m_dalign && mp->m_swidth)) {
1315 xfs_warn(mp, "sunit and swidth must be specified together");
1319 if (mp->m_dalign && (mp->m_swidth % mp->m_dalign != 0)) {
1321 "stripe width (%d) must be a multiple of the stripe unit (%d)",
1322 mp->m_swidth, mp->m_dalign);
1326 if (mp->m_logbufs != -1 &&
1327 mp->m_logbufs != 0 &&
1328 (mp->m_logbufs < XLOG_MIN_ICLOGS ||
1329 mp->m_logbufs > XLOG_MAX_ICLOGS)) {
1330 xfs_warn(mp, "invalid logbufs value: %d [not %d-%d]",
1331 mp->m_logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
1335 if (mp->m_logbsize != -1 &&
1336 mp->m_logbsize != 0 &&
1337 (mp->m_logbsize < XLOG_MIN_RECORD_BSIZE ||
1338 mp->m_logbsize > XLOG_MAX_RECORD_BSIZE ||
1339 !is_power_of_2(mp->m_logbsize))) {
1341 "invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
1346 if ((mp->m_flags & XFS_MOUNT_ALLOCSIZE) &&
1347 (mp->m_allocsize_log > XFS_MAX_IO_LOG ||
1348 mp->m_allocsize_log < XFS_MIN_IO_LOG)) {
1349 xfs_warn(mp, "invalid log iosize: %d [not %d-%d]",
1350 mp->m_allocsize_log, XFS_MIN_IO_LOG, XFS_MAX_IO_LOG);
1359 struct super_block *sb,
1360 struct fs_context *fc)
1362 struct xfs_mount *mp = sb->s_fs_info;
1364 int flags = 0, error;
1368 error = xfs_fc_validate_params(mp);
1370 goto out_free_names;
1372 sb_min_blocksize(sb, BBSIZE);
1373 sb->s_xattr = xfs_xattr_handlers;
1374 sb->s_export_op = &xfs_export_operations;
1375 #ifdef CONFIG_XFS_QUOTA
1376 sb->s_qcop = &xfs_quotactl_operations;
1377 sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ;
1379 sb->s_op = &xfs_super_operations;
1382 * Delay mount work if the debug hook is set. This is debug
1383 * instrumention to coordinate simulation of xfs mount failures with
1384 * VFS superblock operations
1386 if (xfs_globals.mount_delay) {
1387 xfs_notice(mp, "Delaying mount for %d seconds.",
1388 xfs_globals.mount_delay);
1389 msleep(xfs_globals.mount_delay * 1000);
1392 if (fc->sb_flags & SB_SILENT)
1393 flags |= XFS_MFSI_QUIET;
1395 error = xfs_open_devices(mp);
1397 goto out_free_names;
1399 error = xfs_init_mount_workqueues(mp);
1401 goto out_close_devices;
1403 error = xfs_init_percpu_counters(mp);
1405 goto out_destroy_workqueues;
1407 /* Allocate stats memory before we do operations that might use it */
1408 mp->m_stats.xs_stats = alloc_percpu(struct xfsstats);
1409 if (!mp->m_stats.xs_stats) {
1411 goto out_destroy_counters;
1414 error = xfs_readsb(mp, flags);
1416 goto out_free_stats;
1418 error = xfs_finish_flags(mp);
1422 error = xfs_setup_devices(mp);
1426 error = xfs_filestream_mount(mp);
1431 * we must configure the block size in the superblock before we run the
1432 * full mount process as the mount process can lookup and cache inodes.
1434 sb->s_magic = XFS_SUPER_MAGIC;
1435 sb->s_blocksize = mp->m_sb.sb_blocksize;
1436 sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
1437 sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
1438 sb->s_max_links = XFS_MAXLINK;
1439 sb->s_time_gran = 1;
1440 sb->s_time_min = S32_MIN;
1441 sb->s_time_max = S32_MAX;
1442 sb->s_iflags |= SB_I_CGROUPWB;
1444 set_posix_acl_flag(sb);
1446 /* version 5 superblocks support inode version counters. */
1447 if (XFS_SB_VERSION_NUM(&mp->m_sb) == XFS_SB_VERSION_5)
1448 sb->s_flags |= SB_I_VERSION;
1450 if (mp->m_flags & XFS_MOUNT_DAX) {
1451 bool rtdev_is_dax = false, datadev_is_dax;
1454 "DAX enabled. Warning: EXPERIMENTAL, use at your own risk");
1456 datadev_is_dax = bdev_dax_supported(mp->m_ddev_targp->bt_bdev,
1458 if (mp->m_rtdev_targp)
1459 rtdev_is_dax = bdev_dax_supported(
1460 mp->m_rtdev_targp->bt_bdev, sb->s_blocksize);
1461 if (!rtdev_is_dax && !datadev_is_dax) {
1463 "DAX unsupported by block device. Turning off DAX.");
1464 mp->m_flags &= ~XFS_MOUNT_DAX;
1466 if (xfs_sb_version_hasreflink(&mp->m_sb)) {
1468 "DAX and reflink cannot be used together!");
1470 goto out_filestream_unmount;
1474 if (mp->m_flags & XFS_MOUNT_DISCARD) {
1475 struct request_queue *q = bdev_get_queue(sb->s_bdev);
1477 if (!blk_queue_discard(q)) {
1478 xfs_warn(mp, "mounting with \"discard\" option, but "
1479 "the device does not support discard");
1480 mp->m_flags &= ~XFS_MOUNT_DISCARD;
1484 if (xfs_sb_version_hasreflink(&mp->m_sb)) {
1485 if (mp->m_sb.sb_rblocks) {
1487 "reflink not compatible with realtime device!");
1489 goto out_filestream_unmount;
1492 if (xfs_globals.always_cow) {
1493 xfs_info(mp, "using DEBUG-only always_cow mode.");
1494 mp->m_always_cow = true;
1498 if (xfs_sb_version_hasrmapbt(&mp->m_sb) && mp->m_sb.sb_rblocks) {
1500 "reverse mapping btree not compatible with realtime device!");
1502 goto out_filestream_unmount;
1505 error = xfs_mountfs(mp);
1507 goto out_filestream_unmount;
1509 root = igrab(VFS_I(mp->m_rootip));
1514 sb->s_root = d_make_root(root);
1522 out_filestream_unmount:
1523 xfs_filestream_unmount(mp);
1527 free_percpu(mp->m_stats.xs_stats);
1528 out_destroy_counters:
1529 xfs_destroy_percpu_counters(mp);
1530 out_destroy_workqueues:
1531 xfs_destroy_mount_workqueues(mp);
1533 xfs_close_devices(mp);
1535 sb->s_fs_info = NULL;
1540 xfs_filestream_unmount(mp);
1547 struct fs_context *fc)
1549 return get_tree_bdev(fc, xfs_fc_fill_super);
1554 struct xfs_mount *mp)
1556 struct xfs_sb *sbp = &mp->m_sb;
1559 if (mp->m_flags & XFS_MOUNT_NORECOVERY) {
1561 "ro->rw transition prohibited on norecovery mount");
1565 if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 &&
1566 xfs_sb_has_ro_compat_feature(sbp, XFS_SB_FEAT_RO_COMPAT_UNKNOWN)) {
1568 "ro->rw transition prohibited on unknown (0x%x) ro-compat filesystem",
1569 (sbp->sb_features_ro_compat &
1570 XFS_SB_FEAT_RO_COMPAT_UNKNOWN));
1574 mp->m_flags &= ~XFS_MOUNT_RDONLY;
1577 * If this is the first remount to writeable state we might have some
1578 * superblock changes to update.
1580 if (mp->m_update_sb) {
1581 error = xfs_sync_sb(mp, false);
1583 xfs_warn(mp, "failed to write sb changes");
1586 mp->m_update_sb = false;
1590 * Fill out the reserve pool if it is empty. Use the stashed value if
1591 * it is non-zero, otherwise go with the default.
1593 xfs_restore_resvblks(mp);
1594 xfs_log_work_queue(mp);
1596 /* Recover any CoW blocks that never got remapped. */
1597 error = xfs_reflink_recover_cow(mp);
1600 "Error %d recovering leftover CoW allocations.", error);
1601 xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
1604 xfs_start_block_reaping(mp);
1606 /* Create the per-AG metadata reservation pool .*/
1607 error = xfs_fs_reserve_ag_blocks(mp);
1608 if (error && error != -ENOSPC)
1616 struct xfs_mount *mp)
1621 * Cancel background eofb scanning so it cannot race with the final
1622 * log force+buftarg wait and deadlock the remount.
1624 xfs_stop_block_reaping(mp);
1626 /* Get rid of any leftover CoW reservations... */
1627 error = xfs_icache_free_cowblocks(mp, NULL);
1629 xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
1633 /* Free the per-AG metadata reservation pool. */
1634 error = xfs_fs_unreserve_ag_blocks(mp);
1636 xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
1641 * Before we sync the metadata, we need to free up the reserve block
1642 * pool so that the used block count in the superblock on disk is
1643 * correct at the end of the remount. Stash the current* reserve pool
1644 * size so that if we get remounted rw, we can return it to the same
1647 xfs_save_resvblks(mp);
1649 xfs_quiesce_attr(mp);
1650 mp->m_flags |= XFS_MOUNT_RDONLY;
1656 * Logically we would return an error here to prevent users from believing
1657 * they might have changed mount options using remount which can't be changed.
1659 * But unfortunately mount(8) adds all options from mtab and fstab to the mount
1660 * arguments in some cases so we can't blindly reject options, but have to
1661 * check for each specified option if it actually differs from the currently
1662 * set option and only reject it if that's the case.
1664 * Until that is implemented we return success for every remount request, and
1665 * silently ignore all options that we can't actually change.
1669 struct fs_context *fc)
1671 struct xfs_mount *mp = XFS_M(fc->root->d_sb);
1672 struct xfs_mount *new_mp = fc->s_fs_info;
1673 xfs_sb_t *sbp = &mp->m_sb;
1674 int flags = fc->sb_flags;
1677 error = xfs_fc_validate_params(new_mp);
1681 sync_filesystem(mp->m_super);
1683 /* inode32 -> inode64 */
1684 if ((mp->m_flags & XFS_MOUNT_SMALL_INUMS) &&
1685 !(new_mp->m_flags & XFS_MOUNT_SMALL_INUMS)) {
1686 mp->m_flags &= ~XFS_MOUNT_SMALL_INUMS;
1687 mp->m_maxagi = xfs_set_inode_alloc(mp, sbp->sb_agcount);
1690 /* inode64 -> inode32 */
1691 if (!(mp->m_flags & XFS_MOUNT_SMALL_INUMS) &&
1692 (new_mp->m_flags & XFS_MOUNT_SMALL_INUMS)) {
1693 mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
1694 mp->m_maxagi = xfs_set_inode_alloc(mp, sbp->sb_agcount);
1698 if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(flags & SB_RDONLY)) {
1699 error = xfs_remount_rw(mp);
1705 if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (flags & SB_RDONLY)) {
1706 error = xfs_remount_ro(mp);
1714 static void xfs_fc_free(
1715 struct fs_context *fc)
1717 struct xfs_mount *mp = fc->s_fs_info;
1720 * mp is stored in the fs_context when it is initialized.
1721 * mp is transferred to the superblock on a successful mount,
1722 * but if an error occurs before the transfer we have to free
1729 static const struct fs_context_operations xfs_context_ops = {
1730 .parse_param = xfs_fc_parse_param,
1731 .get_tree = xfs_fc_get_tree,
1732 .reconfigure = xfs_fc_reconfigure,
1733 .free = xfs_fc_free,
1736 static int xfs_init_fs_context(
1737 struct fs_context *fc)
1739 struct xfs_mount *mp;
1741 mp = kmem_alloc(sizeof(struct xfs_mount), KM_ZERO);
1745 spin_lock_init(&mp->m_sb_lock);
1746 spin_lock_init(&mp->m_agirotor_lock);
1747 INIT_RADIX_TREE(&mp->m_perag_tree, GFP_ATOMIC);
1748 spin_lock_init(&mp->m_perag_lock);
1749 mutex_init(&mp->m_growlock);
1750 atomic_set(&mp->m_active_trans, 0);
1751 INIT_DELAYED_WORK(&mp->m_reclaim_work, xfs_reclaim_worker);
1752 INIT_DELAYED_WORK(&mp->m_eofblocks_work, xfs_eofblocks_worker);
1753 INIT_DELAYED_WORK(&mp->m_cowblocks_work, xfs_cowblocks_worker);
1754 mp->m_kobj.kobject.kset = xfs_kset;
1756 * We don't create the finobt per-ag space reservation until after log
1757 * recovery, so we must set this to true so that an ifree transaction
1758 * started during log recovery will not depend on space reservations
1759 * for finobt expansion.
1761 mp->m_finobt_nores = true;
1764 * These can be overridden by the mount option parsing.
1767 mp->m_logbsize = -1;
1768 mp->m_allocsize_log = 16; /* 64k */
1771 * Copy binary VFS mount flags we are interested in.
1773 if (fc->sb_flags & SB_RDONLY)
1774 mp->m_flags |= XFS_MOUNT_RDONLY;
1775 if (fc->sb_flags & SB_DIRSYNC)
1776 mp->m_flags |= XFS_MOUNT_DIRSYNC;
1777 if (fc->sb_flags & SB_SYNCHRONOUS)
1778 mp->m_flags |= XFS_MOUNT_WSYNC;
1781 fc->ops = &xfs_context_ops;
1786 static struct file_system_type xfs_fs_type = {
1787 .owner = THIS_MODULE,
1789 .init_fs_context = xfs_init_fs_context,
1790 .parameters = &xfs_fs_parameters,
1791 .kill_sb = kill_block_super,
1792 .fs_flags = FS_REQUIRES_DEV,
1794 MODULE_ALIAS_FS("xfs");
1797 xfs_init_zones(void)
1799 xfs_log_ticket_zone = kmem_cache_create("xfs_log_ticket",
1800 sizeof(struct xlog_ticket),
1802 if (!xfs_log_ticket_zone)
1805 xfs_bmap_free_item_zone = kmem_cache_create("xfs_bmap_free_item",
1806 sizeof(struct xfs_extent_free_item),
1808 if (!xfs_bmap_free_item_zone)
1809 goto out_destroy_log_ticket_zone;
1811 xfs_btree_cur_zone = kmem_cache_create("xfs_btree_cur",
1812 sizeof(struct xfs_btree_cur),
1814 if (!xfs_btree_cur_zone)
1815 goto out_destroy_bmap_free_item_zone;
1817 xfs_da_state_zone = kmem_cache_create("xfs_da_state",
1818 sizeof(struct xfs_da_state),
1820 if (!xfs_da_state_zone)
1821 goto out_destroy_btree_cur_zone;
1823 xfs_ifork_zone = kmem_cache_create("xfs_ifork",
1824 sizeof(struct xfs_ifork),
1826 if (!xfs_ifork_zone)
1827 goto out_destroy_da_state_zone;
1829 xfs_trans_zone = kmem_cache_create("xf_trans",
1830 sizeof(struct xfs_trans),
1832 if (!xfs_trans_zone)
1833 goto out_destroy_ifork_zone;
1837 * The size of the zone allocated buf log item is the maximum
1838 * size possible under XFS. This wastes a little bit of memory,
1839 * but it is much faster.
1841 xfs_buf_item_zone = kmem_cache_create("xfs_buf_item",
1842 sizeof(struct xfs_buf_log_item),
1844 if (!xfs_buf_item_zone)
1845 goto out_destroy_trans_zone;
1847 xfs_efd_zone = kmem_cache_create("xfs_efd_item",
1848 (sizeof(struct xfs_efd_log_item) +
1849 (XFS_EFD_MAX_FAST_EXTENTS - 1) *
1850 sizeof(struct xfs_extent)),
1853 goto out_destroy_buf_item_zone;
1855 xfs_efi_zone = kmem_cache_create("xfs_efi_item",
1856 (sizeof(struct xfs_efi_log_item) +
1857 (XFS_EFI_MAX_FAST_EXTENTS - 1) *
1858 sizeof(struct xfs_extent)),
1861 goto out_destroy_efd_zone;
1863 xfs_inode_zone = kmem_cache_create("xfs_inode",
1864 sizeof(struct xfs_inode), 0,
1865 (SLAB_HWCACHE_ALIGN |
1866 SLAB_RECLAIM_ACCOUNT |
1867 SLAB_MEM_SPREAD | SLAB_ACCOUNT),
1868 xfs_fs_inode_init_once);
1869 if (!xfs_inode_zone)
1870 goto out_destroy_efi_zone;
1872 xfs_ili_zone = kmem_cache_create("xfs_ili",
1873 sizeof(struct xfs_inode_log_item), 0,
1874 SLAB_MEM_SPREAD, NULL);
1876 goto out_destroy_inode_zone;
1878 xfs_icreate_zone = kmem_cache_create("xfs_icr",
1879 sizeof(struct xfs_icreate_item),
1881 if (!xfs_icreate_zone)
1882 goto out_destroy_ili_zone;
1884 xfs_rud_zone = kmem_cache_create("xfs_rud_item",
1885 sizeof(struct xfs_rud_log_item),
1888 goto out_destroy_icreate_zone;
1890 xfs_rui_zone = kmem_cache_create("xfs_rui_item",
1891 xfs_rui_log_item_sizeof(XFS_RUI_MAX_FAST_EXTENTS),
1894 goto out_destroy_rud_zone;
1896 xfs_cud_zone = kmem_cache_create("xfs_cud_item",
1897 sizeof(struct xfs_cud_log_item),
1900 goto out_destroy_rui_zone;
1902 xfs_cui_zone = kmem_cache_create("xfs_cui_item",
1903 xfs_cui_log_item_sizeof(XFS_CUI_MAX_FAST_EXTENTS),
1906 goto out_destroy_cud_zone;
1908 xfs_bud_zone = kmem_cache_create("xfs_bud_item",
1909 sizeof(struct xfs_bud_log_item),
1912 goto out_destroy_cui_zone;
1914 xfs_bui_zone = kmem_cache_create("xfs_bui_item",
1915 xfs_bui_log_item_sizeof(XFS_BUI_MAX_FAST_EXTENTS),
1918 goto out_destroy_bud_zone;
1922 out_destroy_bud_zone:
1923 kmem_cache_destroy(xfs_bud_zone);
1924 out_destroy_cui_zone:
1925 kmem_cache_destroy(xfs_cui_zone);
1926 out_destroy_cud_zone:
1927 kmem_cache_destroy(xfs_cud_zone);
1928 out_destroy_rui_zone:
1929 kmem_cache_destroy(xfs_rui_zone);
1930 out_destroy_rud_zone:
1931 kmem_cache_destroy(xfs_rud_zone);
1932 out_destroy_icreate_zone:
1933 kmem_cache_destroy(xfs_icreate_zone);
1934 out_destroy_ili_zone:
1935 kmem_cache_destroy(xfs_ili_zone);
1936 out_destroy_inode_zone:
1937 kmem_cache_destroy(xfs_inode_zone);
1938 out_destroy_efi_zone:
1939 kmem_cache_destroy(xfs_efi_zone);
1940 out_destroy_efd_zone:
1941 kmem_cache_destroy(xfs_efd_zone);
1942 out_destroy_buf_item_zone:
1943 kmem_cache_destroy(xfs_buf_item_zone);
1944 out_destroy_trans_zone:
1945 kmem_cache_destroy(xfs_trans_zone);
1946 out_destroy_ifork_zone:
1947 kmem_cache_destroy(xfs_ifork_zone);
1948 out_destroy_da_state_zone:
1949 kmem_cache_destroy(xfs_da_state_zone);
1950 out_destroy_btree_cur_zone:
1951 kmem_cache_destroy(xfs_btree_cur_zone);
1952 out_destroy_bmap_free_item_zone:
1953 kmem_cache_destroy(xfs_bmap_free_item_zone);
1954 out_destroy_log_ticket_zone:
1955 kmem_cache_destroy(xfs_log_ticket_zone);
1961 xfs_destroy_zones(void)
1964 * Make sure all delayed rcu free are flushed before we
1968 kmem_cache_destroy(xfs_bui_zone);
1969 kmem_cache_destroy(xfs_bud_zone);
1970 kmem_cache_destroy(xfs_cui_zone);
1971 kmem_cache_destroy(xfs_cud_zone);
1972 kmem_cache_destroy(xfs_rui_zone);
1973 kmem_cache_destroy(xfs_rud_zone);
1974 kmem_cache_destroy(xfs_icreate_zone);
1975 kmem_cache_destroy(xfs_ili_zone);
1976 kmem_cache_destroy(xfs_inode_zone);
1977 kmem_cache_destroy(xfs_efi_zone);
1978 kmem_cache_destroy(xfs_efd_zone);
1979 kmem_cache_destroy(xfs_buf_item_zone);
1980 kmem_cache_destroy(xfs_trans_zone);
1981 kmem_cache_destroy(xfs_ifork_zone);
1982 kmem_cache_destroy(xfs_da_state_zone);
1983 kmem_cache_destroy(xfs_btree_cur_zone);
1984 kmem_cache_destroy(xfs_bmap_free_item_zone);
1985 kmem_cache_destroy(xfs_log_ticket_zone);
1989 xfs_init_workqueues(void)
1992 * The allocation workqueue can be used in memory reclaim situations
1993 * (writepage path), and parallelism is only limited by the number of
1994 * AGs in all the filesystems mounted. Hence use the default large
1995 * max_active value for this workqueue.
1997 xfs_alloc_wq = alloc_workqueue("xfsalloc",
1998 WQ_MEM_RECLAIM|WQ_FREEZABLE, 0);
2002 xfs_discard_wq = alloc_workqueue("xfsdiscard", WQ_UNBOUND, 0);
2003 if (!xfs_discard_wq)
2004 goto out_free_alloc_wq;
2008 destroy_workqueue(xfs_alloc_wq);
2013 xfs_destroy_workqueues(void)
2015 destroy_workqueue(xfs_discard_wq);
2016 destroy_workqueue(xfs_alloc_wq);
2024 xfs_check_ondisk_structs();
2026 printk(KERN_INFO XFS_VERSION_STRING " with "
2027 XFS_BUILD_OPTIONS " enabled\n");
2031 error = xfs_init_zones();
2035 error = xfs_init_workqueues();
2037 goto out_destroy_zones;
2039 error = xfs_mru_cache_init();
2041 goto out_destroy_wq;
2043 error = xfs_buf_init();
2045 goto out_mru_cache_uninit;
2047 error = xfs_init_procfs();
2049 goto out_buf_terminate;
2051 error = xfs_sysctl_register();
2053 goto out_cleanup_procfs;
2055 xfs_kset = kset_create_and_add("xfs", NULL, fs_kobj);
2058 goto out_sysctl_unregister;
2061 xfsstats.xs_kobj.kobject.kset = xfs_kset;
2063 xfsstats.xs_stats = alloc_percpu(struct xfsstats);
2064 if (!xfsstats.xs_stats) {
2066 goto out_kset_unregister;
2069 error = xfs_sysfs_init(&xfsstats.xs_kobj, &xfs_stats_ktype, NULL,
2072 goto out_free_stats;
2075 xfs_dbg_kobj.kobject.kset = xfs_kset;
2076 error = xfs_sysfs_init(&xfs_dbg_kobj, &xfs_dbg_ktype, NULL, "debug");
2078 goto out_remove_stats_kobj;
2081 error = xfs_qm_init();
2083 goto out_remove_dbg_kobj;
2085 error = register_filesystem(&xfs_fs_type);
2092 out_remove_dbg_kobj:
2094 xfs_sysfs_del(&xfs_dbg_kobj);
2095 out_remove_stats_kobj:
2097 xfs_sysfs_del(&xfsstats.xs_kobj);
2099 free_percpu(xfsstats.xs_stats);
2100 out_kset_unregister:
2101 kset_unregister(xfs_kset);
2102 out_sysctl_unregister:
2103 xfs_sysctl_unregister();
2105 xfs_cleanup_procfs();
2107 xfs_buf_terminate();
2108 out_mru_cache_uninit:
2109 xfs_mru_cache_uninit();
2111 xfs_destroy_workqueues();
2113 xfs_destroy_zones();
2122 unregister_filesystem(&xfs_fs_type);
2124 xfs_sysfs_del(&xfs_dbg_kobj);
2126 xfs_sysfs_del(&xfsstats.xs_kobj);
2127 free_percpu(xfsstats.xs_stats);
2128 kset_unregister(xfs_kset);
2129 xfs_sysctl_unregister();
2130 xfs_cleanup_procfs();
2131 xfs_buf_terminate();
2132 xfs_mru_cache_uninit();
2133 xfs_destroy_workqueues();
2134 xfs_destroy_zones();
2135 xfs_uuid_table_free();
2138 module_init(init_xfs_fs);
2139 module_exit(exit_xfs_fs);
2141 MODULE_AUTHOR("Silicon Graphics, Inc.");
2142 MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
2143 MODULE_LICENSE("GPL");