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 = {
111 .specs = xfs_param_specs,
120 int last, shift_left_factor = 0, _res;
124 value = kstrdup(s, GFP_KERNEL);
128 last = strlen(value) - 1;
129 if (value[last] == 'K' || value[last] == 'k') {
130 shift_left_factor = 10;
133 if (value[last] == 'M' || value[last] == 'm') {
134 shift_left_factor = 20;
137 if (value[last] == 'G' || value[last] == 'g') {
138 shift_left_factor = 30;
142 if (kstrtoint(value, base, &_res))
145 *res = _res << shift_left_factor;
150 * Set mount state from a mount option.
152 * NOTE: mp->m_super is NULL here!
156 struct fs_context *fc,
157 struct fs_parameter *param)
159 struct xfs_mount *mp = fc->s_fs_info;
160 struct fs_parse_result result;
164 opt = fs_parse(fc, &xfs_fs_parameters, param, &result);
170 mp->m_logbufs = result.uint_32;
173 if (suffix_kstrtoint(param->string, 10, &mp->m_logbsize))
177 kfree(mp->m_logname);
178 mp->m_logname = kstrdup(param->string, GFP_KERNEL);
184 mp->m_rtname = kstrdup(param->string, GFP_KERNEL);
189 if (suffix_kstrtoint(param->string, 10, &size))
191 mp->m_allocsize_log = ffs(size) - 1;
192 mp->m_flags |= XFS_MOUNT_ALLOCSIZE;
196 mp->m_flags |= XFS_MOUNT_GRPID;
200 mp->m_flags &= ~XFS_MOUNT_GRPID;
203 mp->m_flags |= XFS_MOUNT_WSYNC;
206 mp->m_flags |= XFS_MOUNT_NORECOVERY;
209 mp->m_flags |= XFS_MOUNT_NOALIGN;
212 mp->m_flags |= XFS_MOUNT_SWALLOC;
215 mp->m_dalign = result.uint_32;
218 mp->m_swidth = result.uint_32;
221 mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
224 mp->m_flags &= ~XFS_MOUNT_SMALL_INUMS;
227 mp->m_flags |= XFS_MOUNT_NOUUID;
230 mp->m_flags |= XFS_MOUNT_IKEEP;
233 mp->m_flags &= ~XFS_MOUNT_IKEEP;
236 mp->m_flags |= XFS_MOUNT_LARGEIO;
239 mp->m_flags &= ~XFS_MOUNT_LARGEIO;
242 mp->m_flags |= XFS_MOUNT_ATTR2;
245 mp->m_flags &= ~XFS_MOUNT_ATTR2;
246 mp->m_flags |= XFS_MOUNT_NOATTR2;
248 case Opt_filestreams:
249 mp->m_flags |= XFS_MOUNT_FILESTREAMS;
252 mp->m_qflags &= ~XFS_ALL_QUOTA_ACCT;
253 mp->m_qflags &= ~XFS_ALL_QUOTA_ENFD;
254 mp->m_qflags &= ~XFS_ALL_QUOTA_ACTIVE;
259 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE |
263 case Opt_uqnoenforce:
264 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
265 mp->m_qflags &= ~XFS_UQUOTA_ENFD;
269 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE |
272 case Opt_pqnoenforce:
273 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
274 mp->m_qflags &= ~XFS_PQUOTA_ENFD;
278 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE |
281 case Opt_gqnoenforce:
282 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
283 mp->m_qflags &= ~XFS_GQUOTA_ENFD;
286 mp->m_flags |= XFS_MOUNT_DISCARD;
289 mp->m_flags &= ~XFS_MOUNT_DISCARD;
293 mp->m_flags |= XFS_MOUNT_DAX;
297 xfs_warn(mp, "unknown mount option [%s].", param->key);
305 xfs_fc_validate_params(
306 struct xfs_mount *mp)
309 * no recovery flag requires a read-only mount
311 if ((mp->m_flags & XFS_MOUNT_NORECOVERY) &&
312 !(mp->m_flags & XFS_MOUNT_RDONLY)) {
313 xfs_warn(mp, "no-recovery mounts must be read-only.");
317 if ((mp->m_flags & XFS_MOUNT_NOALIGN) &&
318 (mp->m_dalign || mp->m_swidth)) {
320 "sunit and swidth options incompatible with the noalign option");
324 if (!IS_ENABLED(CONFIG_XFS_QUOTA) && mp->m_qflags != 0) {
325 xfs_warn(mp, "quota support not available in this kernel.");
329 if ((mp->m_dalign && !mp->m_swidth) ||
330 (!mp->m_dalign && mp->m_swidth)) {
331 xfs_warn(mp, "sunit and swidth must be specified together");
335 if (mp->m_dalign && (mp->m_swidth % mp->m_dalign != 0)) {
337 "stripe width (%d) must be a multiple of the stripe unit (%d)",
338 mp->m_swidth, mp->m_dalign);
342 if (mp->m_logbufs != -1 &&
343 mp->m_logbufs != 0 &&
344 (mp->m_logbufs < XLOG_MIN_ICLOGS ||
345 mp->m_logbufs > XLOG_MAX_ICLOGS)) {
346 xfs_warn(mp, "invalid logbufs value: %d [not %d-%d]",
347 mp->m_logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
350 if (mp->m_logbsize != -1 &&
351 mp->m_logbsize != 0 &&
352 (mp->m_logbsize < XLOG_MIN_RECORD_BSIZE ||
353 mp->m_logbsize > XLOG_MAX_RECORD_BSIZE ||
354 !is_power_of_2(mp->m_logbsize))) {
356 "invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
361 if ((mp->m_flags & XFS_MOUNT_ALLOCSIZE) &&
362 (mp->m_allocsize_log > XFS_MAX_IO_LOG ||
363 mp->m_allocsize_log < XFS_MIN_IO_LOG)) {
364 xfs_warn(mp, "invalid log iosize: %d [not %d-%d]",
365 mp->m_allocsize_log, XFS_MIN_IO_LOG, XFS_MAX_IO_LOG);
372 struct proc_xfs_info {
382 static struct proc_xfs_info xfs_info_set[] = {
383 /* the few simple ones we can get from the mount struct */
384 { XFS_MOUNT_IKEEP, ",ikeep" },
385 { XFS_MOUNT_WSYNC, ",wsync" },
386 { XFS_MOUNT_NOALIGN, ",noalign" },
387 { XFS_MOUNT_SWALLOC, ",swalloc" },
388 { XFS_MOUNT_NOUUID, ",nouuid" },
389 { XFS_MOUNT_NORECOVERY, ",norecovery" },
390 { XFS_MOUNT_ATTR2, ",attr2" },
391 { XFS_MOUNT_FILESTREAMS, ",filestreams" },
392 { XFS_MOUNT_GRPID, ",grpid" },
393 { XFS_MOUNT_DISCARD, ",discard" },
394 { XFS_MOUNT_LARGEIO, ",largeio" },
395 { XFS_MOUNT_DAX, ",dax" },
398 struct xfs_mount *mp = XFS_M(root->d_sb);
399 struct proc_xfs_info *xfs_infop;
401 for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
402 if (mp->m_flags & xfs_infop->flag)
403 seq_puts(m, xfs_infop->str);
406 seq_printf(m, ",inode%d",
407 (mp->m_flags & XFS_MOUNT_SMALL_INUMS) ? 32 : 64);
409 if (mp->m_flags & XFS_MOUNT_ALLOCSIZE)
410 seq_printf(m, ",allocsize=%dk",
411 (1 << mp->m_allocsize_log) >> 10);
413 if (mp->m_logbufs > 0)
414 seq_printf(m, ",logbufs=%d", mp->m_logbufs);
415 if (mp->m_logbsize > 0)
416 seq_printf(m, ",logbsize=%dk", mp->m_logbsize >> 10);
419 seq_show_option(m, "logdev", mp->m_logname);
421 seq_show_option(m, "rtdev", mp->m_rtname);
423 if (mp->m_dalign > 0)
424 seq_printf(m, ",sunit=%d",
425 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
426 if (mp->m_swidth > 0)
427 seq_printf(m, ",swidth=%d",
428 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
430 if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD))
431 seq_puts(m, ",usrquota");
432 else if (mp->m_qflags & XFS_UQUOTA_ACCT)
433 seq_puts(m, ",uqnoenforce");
435 if (mp->m_qflags & XFS_PQUOTA_ACCT) {
436 if (mp->m_qflags & XFS_PQUOTA_ENFD)
437 seq_puts(m, ",prjquota");
439 seq_puts(m, ",pqnoenforce");
441 if (mp->m_qflags & XFS_GQUOTA_ACCT) {
442 if (mp->m_qflags & XFS_GQUOTA_ENFD)
443 seq_puts(m, ",grpquota");
445 seq_puts(m, ",gqnoenforce");
448 if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
449 seq_puts(m, ",noquota");
456 unsigned int blockshift)
458 unsigned int pagefactor = 1;
459 unsigned int bitshift = BITS_PER_LONG - 1;
461 /* Figure out maximum filesize, on Linux this can depend on
462 * the filesystem blocksize (on 32 bit platforms).
463 * __block_write_begin does this in an [unsigned] long long...
464 * page->index << (PAGE_SHIFT - bbits)
465 * So, for page sized blocks (4K on 32 bit platforms),
466 * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
467 * (((u64)PAGE_SIZE << (BITS_PER_LONG-1))-1)
468 * but for smaller blocksizes it is less (bbits = log2 bsize).
471 #if BITS_PER_LONG == 32
472 ASSERT(sizeof(sector_t) == 8);
473 pagefactor = PAGE_SIZE;
474 bitshift = BITS_PER_LONG;
477 return (((uint64_t)pagefactor) << bitshift) - 1;
481 * Set parameters for inode allocation heuristics, taking into account
482 * filesystem size and inode32/inode64 mount options; i.e. specifically
483 * whether or not XFS_MOUNT_SMALL_INUMS is set.
485 * Inode allocation patterns are altered only if inode32 is requested
486 * (XFS_MOUNT_SMALL_INUMS), and the filesystem is sufficiently large.
487 * If altered, XFS_MOUNT_32BITINODES is set as well.
489 * An agcount independent of that in the mount structure is provided
490 * because in the growfs case, mp->m_sb.sb_agcount is not yet updated
491 * to the potentially higher ag count.
493 * Returns the maximum AG index which may contain inodes.
497 struct xfs_mount *mp,
498 xfs_agnumber_t agcount)
500 xfs_agnumber_t index;
501 xfs_agnumber_t maxagi = 0;
502 xfs_sb_t *sbp = &mp->m_sb;
503 xfs_agnumber_t max_metadata;
508 * Calculate how much should be reserved for inodes to meet
509 * the max inode percentage. Used only for inode32.
511 if (M_IGEO(mp)->maxicount) {
514 icount = sbp->sb_dblocks * sbp->sb_imax_pct;
516 icount += sbp->sb_agblocks - 1;
517 do_div(icount, sbp->sb_agblocks);
518 max_metadata = icount;
520 max_metadata = agcount;
523 /* Get the last possible inode in the filesystem */
524 agino = XFS_AGB_TO_AGINO(mp, sbp->sb_agblocks - 1);
525 ino = XFS_AGINO_TO_INO(mp, agcount - 1, agino);
528 * If user asked for no more than 32-bit inodes, and the fs is
529 * sufficiently large, set XFS_MOUNT_32BITINODES if we must alter
530 * the allocator to accommodate the request.
532 if ((mp->m_flags & XFS_MOUNT_SMALL_INUMS) && ino > XFS_MAXINUMBER_32)
533 mp->m_flags |= XFS_MOUNT_32BITINODES;
535 mp->m_flags &= ~XFS_MOUNT_32BITINODES;
537 for (index = 0; index < agcount; index++) {
538 struct xfs_perag *pag;
540 ino = XFS_AGINO_TO_INO(mp, index, agino);
542 pag = xfs_perag_get(mp, index);
544 if (mp->m_flags & XFS_MOUNT_32BITINODES) {
545 if (ino > XFS_MAXINUMBER_32) {
546 pag->pagi_inodeok = 0;
547 pag->pagf_metadata = 0;
549 pag->pagi_inodeok = 1;
551 if (index < max_metadata)
552 pag->pagf_metadata = 1;
554 pag->pagf_metadata = 0;
557 pag->pagi_inodeok = 1;
558 pag->pagf_metadata = 0;
564 return (mp->m_flags & XFS_MOUNT_32BITINODES) ? maxagi : agcount;
571 struct block_device **bdevp)
575 *bdevp = blkdev_get_by_path(name, FMODE_READ|FMODE_WRITE|FMODE_EXCL,
577 if (IS_ERR(*bdevp)) {
578 error = PTR_ERR(*bdevp);
579 xfs_warn(mp, "Invalid device [%s], error=%d", name, error);
587 struct block_device *bdev)
590 blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
594 xfs_blkdev_issue_flush(
595 xfs_buftarg_t *buftarg)
597 blkdev_issue_flush(buftarg->bt_bdev, GFP_NOFS, NULL);
602 struct xfs_mount *mp)
604 struct dax_device *dax_ddev = mp->m_ddev_targp->bt_daxdev;
606 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
607 struct block_device *logdev = mp->m_logdev_targp->bt_bdev;
608 struct dax_device *dax_logdev = mp->m_logdev_targp->bt_daxdev;
610 xfs_free_buftarg(mp->m_logdev_targp);
611 xfs_blkdev_put(logdev);
612 fs_put_dax(dax_logdev);
614 if (mp->m_rtdev_targp) {
615 struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev;
616 struct dax_device *dax_rtdev = mp->m_rtdev_targp->bt_daxdev;
618 xfs_free_buftarg(mp->m_rtdev_targp);
619 xfs_blkdev_put(rtdev);
620 fs_put_dax(dax_rtdev);
622 xfs_free_buftarg(mp->m_ddev_targp);
623 fs_put_dax(dax_ddev);
627 * The file system configurations are:
628 * (1) device (partition) with data and internal log
629 * (2) logical volume with data and log subvolumes.
630 * (3) logical volume with data, log, and realtime subvolumes.
632 * We only have to handle opening the log and realtime volumes here if
633 * they are present. The data subvolume has already been opened by
634 * get_sb_bdev() and is stored in sb->s_bdev.
638 struct xfs_mount *mp)
640 struct block_device *ddev = mp->m_super->s_bdev;
641 struct dax_device *dax_ddev = fs_dax_get_by_bdev(ddev);
642 struct dax_device *dax_logdev = NULL, *dax_rtdev = NULL;
643 struct block_device *logdev = NULL, *rtdev = NULL;
647 * Open real time and log devices - order is important.
650 error = xfs_blkdev_get(mp, mp->m_logname, &logdev);
653 dax_logdev = fs_dax_get_by_bdev(logdev);
657 error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev);
659 goto out_close_logdev;
661 if (rtdev == ddev || rtdev == logdev) {
663 "Cannot mount filesystem with identical rtdev and ddev/logdev.");
665 goto out_close_rtdev;
667 dax_rtdev = fs_dax_get_by_bdev(rtdev);
671 * Setup xfs_mount buffer target pointers
674 mp->m_ddev_targp = xfs_alloc_buftarg(mp, ddev, dax_ddev);
675 if (!mp->m_ddev_targp)
676 goto out_close_rtdev;
679 mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev, dax_rtdev);
680 if (!mp->m_rtdev_targp)
681 goto out_free_ddev_targ;
684 if (logdev && logdev != ddev) {
685 mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev, dax_logdev);
686 if (!mp->m_logdev_targp)
687 goto out_free_rtdev_targ;
689 mp->m_logdev_targp = mp->m_ddev_targp;
695 if (mp->m_rtdev_targp)
696 xfs_free_buftarg(mp->m_rtdev_targp);
698 xfs_free_buftarg(mp->m_ddev_targp);
700 xfs_blkdev_put(rtdev);
701 fs_put_dax(dax_rtdev);
703 if (logdev && logdev != ddev) {
704 xfs_blkdev_put(logdev);
705 fs_put_dax(dax_logdev);
708 fs_put_dax(dax_ddev);
713 * Setup xfs_mount buffer target pointers based on superblock
717 struct xfs_mount *mp)
721 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_sectsize);
725 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
726 unsigned int log_sector_size = BBSIZE;
728 if (xfs_sb_version_hassector(&mp->m_sb))
729 log_sector_size = mp->m_sb.sb_logsectsize;
730 error = xfs_setsize_buftarg(mp->m_logdev_targp,
735 if (mp->m_rtdev_targp) {
736 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
737 mp->m_sb.sb_sectsize);
746 xfs_init_mount_workqueues(
747 struct xfs_mount *mp)
749 mp->m_buf_workqueue = alloc_workqueue("xfs-buf/%s",
750 WQ_MEM_RECLAIM|WQ_FREEZABLE, 1, mp->m_super->s_id);
751 if (!mp->m_buf_workqueue)
754 mp->m_unwritten_workqueue = alloc_workqueue("xfs-conv/%s",
755 WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_super->s_id);
756 if (!mp->m_unwritten_workqueue)
757 goto out_destroy_buf;
759 mp->m_cil_workqueue = alloc_workqueue("xfs-cil/%s",
760 WQ_MEM_RECLAIM | WQ_FREEZABLE | WQ_UNBOUND,
761 0, mp->m_super->s_id);
762 if (!mp->m_cil_workqueue)
763 goto out_destroy_unwritten;
765 mp->m_reclaim_workqueue = alloc_workqueue("xfs-reclaim/%s",
766 WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_super->s_id);
767 if (!mp->m_reclaim_workqueue)
768 goto out_destroy_cil;
770 mp->m_eofblocks_workqueue = alloc_workqueue("xfs-eofblocks/%s",
771 WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_super->s_id);
772 if (!mp->m_eofblocks_workqueue)
773 goto out_destroy_reclaim;
775 mp->m_sync_workqueue = alloc_workqueue("xfs-sync/%s", WQ_FREEZABLE, 0,
777 if (!mp->m_sync_workqueue)
778 goto out_destroy_eofb;
783 destroy_workqueue(mp->m_eofblocks_workqueue);
785 destroy_workqueue(mp->m_reclaim_workqueue);
787 destroy_workqueue(mp->m_cil_workqueue);
788 out_destroy_unwritten:
789 destroy_workqueue(mp->m_unwritten_workqueue);
791 destroy_workqueue(mp->m_buf_workqueue);
797 xfs_destroy_mount_workqueues(
798 struct xfs_mount *mp)
800 destroy_workqueue(mp->m_sync_workqueue);
801 destroy_workqueue(mp->m_eofblocks_workqueue);
802 destroy_workqueue(mp->m_reclaim_workqueue);
803 destroy_workqueue(mp->m_cil_workqueue);
804 destroy_workqueue(mp->m_unwritten_workqueue);
805 destroy_workqueue(mp->m_buf_workqueue);
809 * Flush all dirty data to disk. Must not be called while holding an XFS_ILOCK
810 * or a page lock. We use sync_inodes_sb() here to ensure we block while waiting
811 * for IO to complete so that we effectively throttle multiple callers to the
812 * rate at which IO is completing.
816 struct xfs_mount *mp)
818 struct super_block *sb = mp->m_super;
820 if (down_read_trylock(&sb->s_umount)) {
822 up_read(&sb->s_umount);
826 /* Catch misguided souls that try to use this interface on XFS */
827 STATIC struct inode *
829 struct super_block *sb)
838 struct xfs_inode *ip,
841 struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, whichfork);
842 struct xfs_bmbt_irec got;
843 struct xfs_iext_cursor icur;
845 if (!ifp || !xfs_iext_lookup_extent(ip, ifp, 0, &icur, &got))
848 if (isnullstartblock(got.br_startblock)) {
849 xfs_warn(ip->i_mount,
850 "ino %llx %s fork has delalloc extent at [0x%llx:0x%llx]",
852 whichfork == XFS_DATA_FORK ? "data" : "cow",
853 got.br_startoff, got.br_blockcount);
855 } while (xfs_iext_next_extent(ifp, &icur, &got));
858 #define xfs_check_delalloc(ip, whichfork) do { } while (0)
862 * Now that the generic code is guaranteed not to be accessing
863 * the linux inode, we can inactivate and reclaim the inode.
866 xfs_fs_destroy_inode(
869 struct xfs_inode *ip = XFS_I(inode);
871 trace_xfs_destroy_inode(ip);
873 ASSERT(!rwsem_is_locked(&inode->i_rwsem));
874 XFS_STATS_INC(ip->i_mount, vn_rele);
875 XFS_STATS_INC(ip->i_mount, vn_remove);
879 if (!XFS_FORCED_SHUTDOWN(ip->i_mount) && ip->i_delayed_blks) {
880 xfs_check_delalloc(ip, XFS_DATA_FORK);
881 xfs_check_delalloc(ip, XFS_COW_FORK);
885 XFS_STATS_INC(ip->i_mount, vn_reclaim);
888 * We should never get here with one of the reclaim flags already set.
890 ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIMABLE));
891 ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIM));
894 * We always use background reclaim here because even if the
895 * inode is clean, it still may be under IO and hence we have
896 * to take the flush lock. The background reclaim path handles
897 * this more efficiently than we can here, so simply let background
898 * reclaim tear down all inodes.
900 xfs_inode_set_reclaim_tag(ip);
908 struct xfs_inode *ip = XFS_I(inode);
909 struct xfs_mount *mp = ip->i_mount;
910 struct xfs_trans *tp;
912 if (!(inode->i_sb->s_flags & SB_LAZYTIME))
914 if (flag != I_DIRTY_SYNC || !(inode->i_state & I_DIRTY_TIME))
917 if (xfs_trans_alloc(mp, &M_RES(mp)->tr_fsyncts, 0, 0, 0, &tp))
919 xfs_ilock(ip, XFS_ILOCK_EXCL);
920 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
921 xfs_trans_log_inode(tp, ip, XFS_ILOG_TIMESTAMP);
922 xfs_trans_commit(tp);
926 * Slab object creation initialisation for the XFS inode.
927 * This covers only the idempotent fields in the XFS inode;
928 * all other fields need to be initialised on allocation
929 * from the slab. This avoids the need to repeatedly initialise
930 * fields in the xfs inode that left in the initialise state
931 * when freeing the inode.
934 xfs_fs_inode_init_once(
937 struct xfs_inode *ip = inode;
939 memset(ip, 0, sizeof(struct xfs_inode));
942 inode_init_once(VFS_I(ip));
945 atomic_set(&ip->i_pincount, 0);
946 spin_lock_init(&ip->i_flags_lock);
948 mrlock_init(&ip->i_mmaplock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
949 "xfsino", ip->i_ino);
950 mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
951 "xfsino", ip->i_ino);
955 * We do an unlocked check for XFS_IDONTCACHE here because we are already
956 * serialised against cache hits here via the inode->i_lock and igrab() in
957 * xfs_iget_cache_hit(). Hence a lookup that might clear this flag will not be
958 * racing with us, and it avoids needing to grab a spinlock here for every inode
959 * we drop the final reference on.
965 struct xfs_inode *ip = XFS_I(inode);
968 * If this unlinked inode is in the middle of recovery, don't
969 * drop the inode just yet; log recovery will take care of
970 * that. See the comment for this inode flag.
972 if (ip->i_flags & XFS_IRECOVERY) {
973 ASSERT(ip->i_mount->m_log->l_flags & XLOG_RECOVERY_NEEDED);
977 return generic_drop_inode(inode) || (ip->i_flags & XFS_IDONTCACHE);
982 struct xfs_mount *mp)
985 kfree(mp->m_logname);
991 struct super_block *sb,
994 struct xfs_mount *mp = XFS_M(sb);
997 * Doing anything during the async pass would be counterproductive.
1002 xfs_log_force(mp, XFS_LOG_SYNC);
1005 * The disk must be active because we're syncing.
1006 * We schedule log work now (now that the disk is
1007 * active) instead of later (when it might not be).
1009 flush_delayed_work(&mp->m_log->l_work);
1017 struct dentry *dentry,
1018 struct kstatfs *statp)
1020 struct xfs_mount *mp = XFS_M(dentry->d_sb);
1021 xfs_sb_t *sbp = &mp->m_sb;
1022 struct xfs_inode *ip = XFS_I(d_inode(dentry));
1023 uint64_t fakeinos, id;
1030 statp->f_type = XFS_SUPER_MAGIC;
1031 statp->f_namelen = MAXNAMELEN - 1;
1033 id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
1034 statp->f_fsid.val[0] = (u32)id;
1035 statp->f_fsid.val[1] = (u32)(id >> 32);
1037 icount = percpu_counter_sum(&mp->m_icount);
1038 ifree = percpu_counter_sum(&mp->m_ifree);
1039 fdblocks = percpu_counter_sum(&mp->m_fdblocks);
1041 spin_lock(&mp->m_sb_lock);
1042 statp->f_bsize = sbp->sb_blocksize;
1043 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
1044 statp->f_blocks = sbp->sb_dblocks - lsize;
1045 spin_unlock(&mp->m_sb_lock);
1047 statp->f_bfree = fdblocks - mp->m_alloc_set_aside;
1048 statp->f_bavail = statp->f_bfree;
1050 fakeinos = XFS_FSB_TO_INO(mp, statp->f_bfree);
1051 statp->f_files = min(icount + fakeinos, (uint64_t)XFS_MAXINUMBER);
1052 if (M_IGEO(mp)->maxicount)
1053 statp->f_files = min_t(typeof(statp->f_files),
1055 M_IGEO(mp)->maxicount);
1057 /* If sb_icount overshot maxicount, report actual allocation */
1058 statp->f_files = max_t(typeof(statp->f_files),
1062 /* make sure statp->f_ffree does not underflow */
1063 ffree = statp->f_files - (icount - ifree);
1064 statp->f_ffree = max_t(int64_t, ffree, 0);
1067 if ((ip->i_d.di_flags & XFS_DIFLAG_PROJINHERIT) &&
1068 ((mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))) ==
1069 (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))
1070 xfs_qm_statvfs(ip, statp);
1072 if (XFS_IS_REALTIME_MOUNT(mp) &&
1073 (ip->i_d.di_flags & (XFS_DIFLAG_RTINHERIT | XFS_DIFLAG_REALTIME))) {
1074 statp->f_blocks = sbp->sb_rblocks;
1075 statp->f_bavail = statp->f_bfree =
1076 sbp->sb_frextents * sbp->sb_rextsize;
1083 xfs_save_resvblks(struct xfs_mount *mp)
1085 uint64_t resblks = 0;
1087 mp->m_resblks_save = mp->m_resblks;
1088 xfs_reserve_blocks(mp, &resblks, NULL);
1092 xfs_restore_resvblks(struct xfs_mount *mp)
1096 if (mp->m_resblks_save) {
1097 resblks = mp->m_resblks_save;
1098 mp->m_resblks_save = 0;
1100 resblks = xfs_default_resblks(mp);
1102 xfs_reserve_blocks(mp, &resblks, NULL);
1106 * Trigger writeback of all the dirty metadata in the file system.
1108 * This ensures that the metadata is written to their location on disk rather
1109 * than just existing in transactions in the log. This means after a quiesce
1110 * there is no log replay required to write the inodes to disk - this is the
1111 * primary difference between a sync and a quiesce.
1113 * Note: xfs_log_quiesce() stops background log work - the callers must ensure
1114 * it is started again when appropriate.
1118 struct xfs_mount *mp)
1122 /* wait for all modifications to complete */
1123 while (atomic_read(&mp->m_active_trans) > 0)
1126 /* force the log to unpin objects from the now complete transactions */
1127 xfs_log_force(mp, XFS_LOG_SYNC);
1129 /* reclaim inodes to do any IO before the freeze completes */
1130 xfs_reclaim_inodes(mp, 0);
1131 xfs_reclaim_inodes(mp, SYNC_WAIT);
1133 /* Push the superblock and write an unmount record */
1134 error = xfs_log_sbcount(mp);
1136 xfs_warn(mp, "xfs_attr_quiesce: failed to log sb changes. "
1137 "Frozen image may not be consistent.");
1139 * Just warn here till VFS can correctly support
1140 * read-only remount without racing.
1142 WARN_ON(atomic_read(&mp->m_active_trans) != 0);
1144 xfs_log_quiesce(mp);
1148 * Second stage of a freeze. The data is already frozen so we only
1149 * need to take care of the metadata. Once that's done sync the superblock
1150 * to the log to dirty it in case of a crash while frozen. This ensures that we
1151 * will recover the unlinked inode lists on the next mount.
1155 struct super_block *sb)
1157 struct xfs_mount *mp = XFS_M(sb);
1159 xfs_stop_block_reaping(mp);
1160 xfs_save_resvblks(mp);
1161 xfs_quiesce_attr(mp);
1162 return xfs_sync_sb(mp, true);
1167 struct super_block *sb)
1169 struct xfs_mount *mp = XFS_M(sb);
1171 xfs_restore_resvblks(mp);
1172 xfs_log_work_queue(mp);
1173 xfs_start_block_reaping(mp);
1178 * This function fills in xfs_mount_t fields based on mount args.
1179 * Note: the superblock _has_ now been read in.
1183 struct xfs_mount *mp)
1185 int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
1187 /* Fail a mount where the logbuf is smaller than the log stripe */
1188 if (xfs_sb_version_haslogv2(&mp->m_sb)) {
1189 if (mp->m_logbsize <= 0 &&
1190 mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE) {
1191 mp->m_logbsize = mp->m_sb.sb_logsunit;
1192 } else if (mp->m_logbsize > 0 &&
1193 mp->m_logbsize < mp->m_sb.sb_logsunit) {
1195 "logbuf size must be greater than or equal to log stripe size");
1199 /* Fail a mount if the logbuf is larger than 32K */
1200 if (mp->m_logbsize > XLOG_BIG_RECORD_BSIZE) {
1202 "logbuf size for version 1 logs must be 16K or 32K");
1208 * V5 filesystems always use attr2 format for attributes.
1210 if (xfs_sb_version_hascrc(&mp->m_sb) &&
1211 (mp->m_flags & XFS_MOUNT_NOATTR2)) {
1212 xfs_warn(mp, "Cannot mount a V5 filesystem as noattr2. "
1213 "attr2 is always enabled for V5 filesystems.");
1218 * mkfs'ed attr2 will turn on attr2 mount unless explicitly
1219 * told by noattr2 to turn it off
1221 if (xfs_sb_version_hasattr2(&mp->m_sb) &&
1222 !(mp->m_flags & XFS_MOUNT_NOATTR2))
1223 mp->m_flags |= XFS_MOUNT_ATTR2;
1226 * prohibit r/w mounts of read-only filesystems
1228 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
1230 "cannot mount a read-only filesystem as read-write");
1234 if ((mp->m_qflags & (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE)) &&
1235 (mp->m_qflags & (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE)) &&
1236 !xfs_sb_version_has_pquotino(&mp->m_sb)) {
1238 "Super block does not support project and group quota together");
1246 xfs_init_percpu_counters(
1247 struct xfs_mount *mp)
1251 error = percpu_counter_init(&mp->m_icount, 0, GFP_KERNEL);
1255 error = percpu_counter_init(&mp->m_ifree, 0, GFP_KERNEL);
1259 error = percpu_counter_init(&mp->m_fdblocks, 0, GFP_KERNEL);
1263 error = percpu_counter_init(&mp->m_delalloc_blks, 0, GFP_KERNEL);
1270 percpu_counter_destroy(&mp->m_fdblocks);
1272 percpu_counter_destroy(&mp->m_ifree);
1274 percpu_counter_destroy(&mp->m_icount);
1279 xfs_reinit_percpu_counters(
1280 struct xfs_mount *mp)
1282 percpu_counter_set(&mp->m_icount, mp->m_sb.sb_icount);
1283 percpu_counter_set(&mp->m_ifree, mp->m_sb.sb_ifree);
1284 percpu_counter_set(&mp->m_fdblocks, mp->m_sb.sb_fdblocks);
1288 xfs_destroy_percpu_counters(
1289 struct xfs_mount *mp)
1291 percpu_counter_destroy(&mp->m_icount);
1292 percpu_counter_destroy(&mp->m_ifree);
1293 percpu_counter_destroy(&mp->m_fdblocks);
1294 ASSERT(XFS_FORCED_SHUTDOWN(mp) ||
1295 percpu_counter_sum(&mp->m_delalloc_blks) == 0);
1296 percpu_counter_destroy(&mp->m_delalloc_blks);
1299 static struct xfs_mount *
1300 xfs_mount_alloc(void)
1302 struct xfs_mount *mp;
1304 mp = kmem_alloc(sizeof(struct xfs_mount), KM_ZERO);
1308 spin_lock_init(&mp->m_sb_lock);
1309 spin_lock_init(&mp->m_agirotor_lock);
1310 INIT_RADIX_TREE(&mp->m_perag_tree, GFP_ATOMIC);
1311 spin_lock_init(&mp->m_perag_lock);
1312 mutex_init(&mp->m_growlock);
1313 atomic_set(&mp->m_active_trans, 0);
1314 INIT_DELAYED_WORK(&mp->m_reclaim_work, xfs_reclaim_worker);
1315 INIT_DELAYED_WORK(&mp->m_eofblocks_work, xfs_eofblocks_worker);
1316 INIT_DELAYED_WORK(&mp->m_cowblocks_work, xfs_cowblocks_worker);
1317 mp->m_kobj.kobject.kset = xfs_kset;
1319 * We don't create the finobt per-ag space reservation until after log
1320 * recovery, so we must set this to true so that an ifree transaction
1321 * started during log recovery will not depend on space reservations
1322 * for finobt expansion.
1324 mp->m_finobt_nores = true;
1330 struct super_block *sb,
1331 struct fs_context *fc)
1333 struct xfs_mount *mp = sb->s_fs_info;
1335 int flags = 0, error = -ENOMEM;
1339 error = xfs_fc_validate_params(mp);
1341 goto out_free_names;
1343 sb_min_blocksize(sb, BBSIZE);
1344 sb->s_xattr = xfs_xattr_handlers;
1345 sb->s_export_op = &xfs_export_operations;
1346 #ifdef CONFIG_XFS_QUOTA
1347 sb->s_qcop = &xfs_quotactl_operations;
1348 sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ;
1350 sb->s_op = &xfs_super_operations;
1353 * Delay mount work if the debug hook is set. This is debug
1354 * instrumention to coordinate simulation of xfs mount failures with
1355 * VFS superblock operations
1357 if (xfs_globals.mount_delay) {
1358 xfs_notice(mp, "Delaying mount for %d seconds.",
1359 xfs_globals.mount_delay);
1360 msleep(xfs_globals.mount_delay * 1000);
1363 if (fc->sb_flags & SB_SILENT)
1364 flags |= XFS_MFSI_QUIET;
1366 error = xfs_open_devices(mp);
1368 goto out_free_names;
1370 error = xfs_init_mount_workqueues(mp);
1372 goto out_close_devices;
1374 error = xfs_init_percpu_counters(mp);
1376 goto out_destroy_workqueues;
1378 /* Allocate stats memory before we do operations that might use it */
1379 mp->m_stats.xs_stats = alloc_percpu(struct xfsstats);
1380 if (!mp->m_stats.xs_stats) {
1382 goto out_destroy_counters;
1385 error = xfs_readsb(mp, flags);
1387 goto out_free_stats;
1389 error = xfs_finish_flags(mp);
1393 error = xfs_setup_devices(mp);
1397 error = xfs_filestream_mount(mp);
1402 * we must configure the block size in the superblock before we run the
1403 * full mount process as the mount process can lookup and cache inodes.
1405 sb->s_magic = XFS_SUPER_MAGIC;
1406 sb->s_blocksize = mp->m_sb.sb_blocksize;
1407 sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
1408 sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
1409 sb->s_max_links = XFS_MAXLINK;
1410 sb->s_time_gran = 1;
1411 sb->s_time_min = S32_MIN;
1412 sb->s_time_max = S32_MAX;
1413 sb->s_iflags |= SB_I_CGROUPWB;
1415 set_posix_acl_flag(sb);
1417 /* version 5 superblocks support inode version counters. */
1418 if (XFS_SB_VERSION_NUM(&mp->m_sb) == XFS_SB_VERSION_5)
1419 sb->s_flags |= SB_I_VERSION;
1421 if (mp->m_flags & XFS_MOUNT_DAX) {
1422 bool rtdev_is_dax = false, datadev_is_dax;
1425 "DAX enabled. Warning: EXPERIMENTAL, use at your own risk");
1427 datadev_is_dax = bdev_dax_supported(mp->m_ddev_targp->bt_bdev,
1429 if (mp->m_rtdev_targp)
1430 rtdev_is_dax = bdev_dax_supported(
1431 mp->m_rtdev_targp->bt_bdev, sb->s_blocksize);
1432 if (!rtdev_is_dax && !datadev_is_dax) {
1434 "DAX unsupported by block device. Turning off DAX.");
1435 mp->m_flags &= ~XFS_MOUNT_DAX;
1437 if (xfs_sb_version_hasreflink(&mp->m_sb)) {
1439 "DAX and reflink cannot be used together!");
1441 goto out_filestream_unmount;
1445 if (mp->m_flags & XFS_MOUNT_DISCARD) {
1446 struct request_queue *q = bdev_get_queue(sb->s_bdev);
1448 if (!blk_queue_discard(q)) {
1449 xfs_warn(mp, "mounting with \"discard\" option, but "
1450 "the device does not support discard");
1451 mp->m_flags &= ~XFS_MOUNT_DISCARD;
1455 if (xfs_sb_version_hasreflink(&mp->m_sb)) {
1456 if (mp->m_sb.sb_rblocks) {
1458 "reflink not compatible with realtime device!");
1460 goto out_filestream_unmount;
1463 if (xfs_globals.always_cow) {
1464 xfs_info(mp, "using DEBUG-only always_cow mode.");
1465 mp->m_always_cow = true;
1469 if (xfs_sb_version_hasrmapbt(&mp->m_sb) && mp->m_sb.sb_rblocks) {
1471 "reverse mapping btree not compatible with realtime device!");
1473 goto out_filestream_unmount;
1476 error = xfs_mountfs(mp);
1478 goto out_filestream_unmount;
1480 root = igrab(VFS_I(mp->m_rootip));
1485 sb->s_root = d_make_root(root);
1493 out_filestream_unmount:
1494 xfs_filestream_unmount(mp);
1498 free_percpu(mp->m_stats.xs_stats);
1499 out_destroy_counters:
1500 xfs_destroy_percpu_counters(mp);
1501 out_destroy_workqueues:
1502 xfs_destroy_mount_workqueues(mp);
1504 xfs_close_devices(mp);
1506 sb->s_fs_info = NULL;
1511 xfs_filestream_unmount(mp);
1518 struct fs_context *fc)
1520 return get_tree_bdev(fc, xfs_fc_fill_super);
1525 struct super_block *sb)
1527 struct xfs_mount *mp = XFS_M(sb);
1529 /* if ->fill_super failed, we have no mount to tear down */
1533 xfs_notice(mp, "Unmounting Filesystem");
1534 xfs_filestream_unmount(mp);
1538 free_percpu(mp->m_stats.xs_stats);
1539 xfs_destroy_percpu_counters(mp);
1540 xfs_destroy_mount_workqueues(mp);
1541 xfs_close_devices(mp);
1543 sb->s_fs_info = NULL;
1548 xfs_fs_nr_cached_objects(
1549 struct super_block *sb,
1550 struct shrink_control *sc)
1552 /* Paranoia: catch incorrect calls during mount setup or teardown */
1553 if (WARN_ON_ONCE(!sb->s_fs_info))
1555 return xfs_reclaim_inodes_count(XFS_M(sb));
1559 xfs_fs_free_cached_objects(
1560 struct super_block *sb,
1561 struct shrink_control *sc)
1563 return xfs_reclaim_inodes_nr(XFS_M(sb), sc->nr_to_scan);
1566 static const struct super_operations xfs_super_operations = {
1567 .alloc_inode = xfs_fs_alloc_inode,
1568 .destroy_inode = xfs_fs_destroy_inode,
1569 .dirty_inode = xfs_fs_dirty_inode,
1570 .drop_inode = xfs_fs_drop_inode,
1571 .put_super = xfs_fs_put_super,
1572 .sync_fs = xfs_fs_sync_fs,
1573 .freeze_fs = xfs_fs_freeze,
1574 .unfreeze_fs = xfs_fs_unfreeze,
1575 .statfs = xfs_fs_statfs,
1576 .show_options = xfs_fs_show_options,
1577 .nr_cached_objects = xfs_fs_nr_cached_objects,
1578 .free_cached_objects = xfs_fs_free_cached_objects,
1583 struct xfs_mount *mp)
1585 struct xfs_sb *sbp = &mp->m_sb;
1588 if (mp->m_flags & XFS_MOUNT_NORECOVERY) {
1590 "ro->rw transition prohibited on norecovery mount");
1594 if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 &&
1595 xfs_sb_has_ro_compat_feature(sbp, XFS_SB_FEAT_RO_COMPAT_UNKNOWN)) {
1597 "ro->rw transition prohibited on unknown (0x%x) ro-compat filesystem",
1598 (sbp->sb_features_ro_compat &
1599 XFS_SB_FEAT_RO_COMPAT_UNKNOWN));
1603 mp->m_flags &= ~XFS_MOUNT_RDONLY;
1606 * If this is the first remount to writeable state we might have some
1607 * superblock changes to update.
1609 if (mp->m_update_sb) {
1610 error = xfs_sync_sb(mp, false);
1612 xfs_warn(mp, "failed to write sb changes");
1615 mp->m_update_sb = false;
1619 * Fill out the reserve pool if it is empty. Use the stashed value if
1620 * it is non-zero, otherwise go with the default.
1622 xfs_restore_resvblks(mp);
1623 xfs_log_work_queue(mp);
1625 /* Recover any CoW blocks that never got remapped. */
1626 error = xfs_reflink_recover_cow(mp);
1629 "Error %d recovering leftover CoW allocations.", error);
1630 xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
1633 xfs_start_block_reaping(mp);
1635 /* Create the per-AG metadata reservation pool .*/
1636 error = xfs_fs_reserve_ag_blocks(mp);
1637 if (error && error != -ENOSPC)
1645 struct xfs_mount *mp)
1650 * Cancel background eofb scanning so it cannot race with the final
1651 * log force+buftarg wait and deadlock the remount.
1653 xfs_stop_block_reaping(mp);
1655 /* Get rid of any leftover CoW reservations... */
1656 error = xfs_icache_free_cowblocks(mp, NULL);
1658 xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
1662 /* Free the per-AG metadata reservation pool. */
1663 error = xfs_fs_unreserve_ag_blocks(mp);
1665 xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
1670 * Before we sync the metadata, we need to free up the reserve block
1671 * pool so that the used block count in the superblock on disk is
1672 * correct at the end of the remount. Stash the current* reserve pool
1673 * size so that if we get remounted rw, we can return it to the same
1676 xfs_save_resvblks(mp);
1678 xfs_quiesce_attr(mp);
1679 mp->m_flags |= XFS_MOUNT_RDONLY;
1685 * Logically we would return an error here to prevent users from believing
1686 * they might have changed mount options using remount which can't be changed.
1688 * But unfortunately mount(8) adds all options from mtab and fstab to the mount
1689 * arguments in some cases so we can't blindly reject options, but have to
1690 * check for each specified option if it actually differs from the currently
1691 * set option and only reject it if that's the case.
1693 * Until that is implemented we return success for every remount request, and
1694 * silently ignore all options that we can't actually change.
1698 struct fs_context *fc)
1700 struct xfs_mount *mp = XFS_M(fc->root->d_sb);
1701 struct xfs_mount *new_mp = fc->s_fs_info;
1702 xfs_sb_t *sbp = &mp->m_sb;
1703 int flags = fc->sb_flags;
1706 error = xfs_fc_validate_params(new_mp);
1710 sync_filesystem(mp->m_super);
1712 /* inode32 -> inode64 */
1713 if ((mp->m_flags & XFS_MOUNT_SMALL_INUMS) &&
1714 !(new_mp->m_flags & XFS_MOUNT_SMALL_INUMS)) {
1715 mp->m_flags &= ~XFS_MOUNT_SMALL_INUMS;
1716 mp->m_maxagi = xfs_set_inode_alloc(mp, sbp->sb_agcount);
1719 /* inode64 -> inode32 */
1720 if (!(mp->m_flags & XFS_MOUNT_SMALL_INUMS) &&
1721 (new_mp->m_flags & XFS_MOUNT_SMALL_INUMS)) {
1722 mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
1723 mp->m_maxagi = xfs_set_inode_alloc(mp, sbp->sb_agcount);
1727 if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(flags & SB_RDONLY)) {
1728 error = xfs_remount_rw(mp);
1734 if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (flags & SB_RDONLY)) {
1735 error = xfs_remount_ro(mp);
1743 static void xfs_fc_free(
1744 struct fs_context *fc)
1746 struct xfs_mount *mp = fc->s_fs_info;
1749 * mp is stored in the fs_context when it is initialized.
1750 * mp is transferred to the superblock on a successful mount,
1751 * but if an error occurs before the transfer we have to free
1758 static const struct fs_context_operations xfs_context_ops = {
1759 .parse_param = xfs_fc_parse_param,
1760 .get_tree = xfs_fc_get_tree,
1761 .reconfigure = xfs_fc_reconfigure,
1762 .free = xfs_fc_free,
1765 static int xfs_init_fs_context(
1766 struct fs_context *fc)
1768 struct xfs_mount *mp;
1770 mp = xfs_mount_alloc();
1775 * These can be overridden by the mount option parsing.
1778 mp->m_logbsize = -1;
1779 mp->m_allocsize_log = 16; /* 64k */
1782 * Copy binary VFS mount flags we are interested in.
1784 if (fc->sb_flags & SB_RDONLY)
1785 mp->m_flags |= XFS_MOUNT_RDONLY;
1786 if (fc->sb_flags & SB_DIRSYNC)
1787 mp->m_flags |= XFS_MOUNT_DIRSYNC;
1788 if (fc->sb_flags & SB_SYNCHRONOUS)
1789 mp->m_flags |= XFS_MOUNT_WSYNC;
1792 fc->ops = &xfs_context_ops;
1797 static struct file_system_type xfs_fs_type = {
1798 .owner = THIS_MODULE,
1800 .init_fs_context = xfs_init_fs_context,
1801 .parameters = &xfs_fs_parameters,
1802 .kill_sb = kill_block_super,
1803 .fs_flags = FS_REQUIRES_DEV,
1805 MODULE_ALIAS_FS("xfs");
1808 xfs_init_zones(void)
1810 xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t),
1812 if (!xfs_log_ticket_zone)
1815 xfs_bmap_free_item_zone = kmem_zone_init(
1816 sizeof(struct xfs_extent_free_item),
1817 "xfs_bmap_free_item");
1818 if (!xfs_bmap_free_item_zone)
1819 goto out_destroy_log_ticket_zone;
1821 xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
1823 if (!xfs_btree_cur_zone)
1824 goto out_destroy_bmap_free_item_zone;
1826 xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t),
1828 if (!xfs_da_state_zone)
1829 goto out_destroy_btree_cur_zone;
1831 xfs_ifork_zone = kmem_zone_init(sizeof(struct xfs_ifork), "xfs_ifork");
1832 if (!xfs_ifork_zone)
1833 goto out_destroy_da_state_zone;
1835 xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
1836 if (!xfs_trans_zone)
1837 goto out_destroy_ifork_zone;
1841 * The size of the zone allocated buf log item is the maximum
1842 * size possible under XFS. This wastes a little bit of memory,
1843 * but it is much faster.
1845 xfs_buf_item_zone = kmem_zone_init(sizeof(struct xfs_buf_log_item),
1847 if (!xfs_buf_item_zone)
1848 goto out_destroy_trans_zone;
1850 xfs_efd_zone = kmem_zone_init((sizeof(xfs_efd_log_item_t) +
1851 ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
1852 sizeof(xfs_extent_t))), "xfs_efd_item");
1854 goto out_destroy_buf_item_zone;
1856 xfs_efi_zone = kmem_zone_init((sizeof(xfs_efi_log_item_t) +
1857 ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
1858 sizeof(xfs_extent_t))), "xfs_efi_item");
1860 goto out_destroy_efd_zone;
1863 kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
1864 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM | KM_ZONE_SPREAD |
1865 KM_ZONE_ACCOUNT, xfs_fs_inode_init_once);
1866 if (!xfs_inode_zone)
1867 goto out_destroy_efi_zone;
1870 kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
1871 KM_ZONE_SPREAD, NULL);
1873 goto out_destroy_inode_zone;
1874 xfs_icreate_zone = kmem_zone_init(sizeof(struct xfs_icreate_item),
1876 if (!xfs_icreate_zone)
1877 goto out_destroy_ili_zone;
1879 xfs_rud_zone = kmem_zone_init(sizeof(struct xfs_rud_log_item),
1882 goto out_destroy_icreate_zone;
1884 xfs_rui_zone = kmem_zone_init(
1885 xfs_rui_log_item_sizeof(XFS_RUI_MAX_FAST_EXTENTS),
1888 goto out_destroy_rud_zone;
1890 xfs_cud_zone = kmem_zone_init(sizeof(struct xfs_cud_log_item),
1893 goto out_destroy_rui_zone;
1895 xfs_cui_zone = kmem_zone_init(
1896 xfs_cui_log_item_sizeof(XFS_CUI_MAX_FAST_EXTENTS),
1899 goto out_destroy_cud_zone;
1901 xfs_bud_zone = kmem_zone_init(sizeof(struct xfs_bud_log_item),
1904 goto out_destroy_cui_zone;
1906 xfs_bui_zone = kmem_zone_init(
1907 xfs_bui_log_item_sizeof(XFS_BUI_MAX_FAST_EXTENTS),
1910 goto out_destroy_bud_zone;
1914 out_destroy_bud_zone:
1915 kmem_zone_destroy(xfs_bud_zone);
1916 out_destroy_cui_zone:
1917 kmem_zone_destroy(xfs_cui_zone);
1918 out_destroy_cud_zone:
1919 kmem_zone_destroy(xfs_cud_zone);
1920 out_destroy_rui_zone:
1921 kmem_zone_destroy(xfs_rui_zone);
1922 out_destroy_rud_zone:
1923 kmem_zone_destroy(xfs_rud_zone);
1924 out_destroy_icreate_zone:
1925 kmem_zone_destroy(xfs_icreate_zone);
1926 out_destroy_ili_zone:
1927 kmem_zone_destroy(xfs_ili_zone);
1928 out_destroy_inode_zone:
1929 kmem_zone_destroy(xfs_inode_zone);
1930 out_destroy_efi_zone:
1931 kmem_zone_destroy(xfs_efi_zone);
1932 out_destroy_efd_zone:
1933 kmem_zone_destroy(xfs_efd_zone);
1934 out_destroy_buf_item_zone:
1935 kmem_zone_destroy(xfs_buf_item_zone);
1936 out_destroy_trans_zone:
1937 kmem_zone_destroy(xfs_trans_zone);
1938 out_destroy_ifork_zone:
1939 kmem_zone_destroy(xfs_ifork_zone);
1940 out_destroy_da_state_zone:
1941 kmem_zone_destroy(xfs_da_state_zone);
1942 out_destroy_btree_cur_zone:
1943 kmem_zone_destroy(xfs_btree_cur_zone);
1944 out_destroy_bmap_free_item_zone:
1945 kmem_zone_destroy(xfs_bmap_free_item_zone);
1946 out_destroy_log_ticket_zone:
1947 kmem_zone_destroy(xfs_log_ticket_zone);
1953 xfs_destroy_zones(void)
1956 * Make sure all delayed rcu free are flushed before we
1960 kmem_zone_destroy(xfs_bui_zone);
1961 kmem_zone_destroy(xfs_bud_zone);
1962 kmem_zone_destroy(xfs_cui_zone);
1963 kmem_zone_destroy(xfs_cud_zone);
1964 kmem_zone_destroy(xfs_rui_zone);
1965 kmem_zone_destroy(xfs_rud_zone);
1966 kmem_zone_destroy(xfs_icreate_zone);
1967 kmem_zone_destroy(xfs_ili_zone);
1968 kmem_zone_destroy(xfs_inode_zone);
1969 kmem_zone_destroy(xfs_efi_zone);
1970 kmem_zone_destroy(xfs_efd_zone);
1971 kmem_zone_destroy(xfs_buf_item_zone);
1972 kmem_zone_destroy(xfs_trans_zone);
1973 kmem_zone_destroy(xfs_ifork_zone);
1974 kmem_zone_destroy(xfs_da_state_zone);
1975 kmem_zone_destroy(xfs_btree_cur_zone);
1976 kmem_zone_destroy(xfs_bmap_free_item_zone);
1977 kmem_zone_destroy(xfs_log_ticket_zone);
1981 xfs_init_workqueues(void)
1984 * The allocation workqueue can be used in memory reclaim situations
1985 * (writepage path), and parallelism is only limited by the number of
1986 * AGs in all the filesystems mounted. Hence use the default large
1987 * max_active value for this workqueue.
1989 xfs_alloc_wq = alloc_workqueue("xfsalloc",
1990 WQ_MEM_RECLAIM|WQ_FREEZABLE, 0);
1994 xfs_discard_wq = alloc_workqueue("xfsdiscard", WQ_UNBOUND, 0);
1995 if (!xfs_discard_wq)
1996 goto out_free_alloc_wq;
2000 destroy_workqueue(xfs_alloc_wq);
2005 xfs_destroy_workqueues(void)
2007 destroy_workqueue(xfs_discard_wq);
2008 destroy_workqueue(xfs_alloc_wq);
2016 xfs_check_ondisk_structs();
2018 printk(KERN_INFO XFS_VERSION_STRING " with "
2019 XFS_BUILD_OPTIONS " enabled\n");
2023 error = xfs_init_zones();
2027 error = xfs_init_workqueues();
2029 goto out_destroy_zones;
2031 error = xfs_mru_cache_init();
2033 goto out_destroy_wq;
2035 error = xfs_buf_init();
2037 goto out_mru_cache_uninit;
2039 error = xfs_init_procfs();
2041 goto out_buf_terminate;
2043 error = xfs_sysctl_register();
2045 goto out_cleanup_procfs;
2047 xfs_kset = kset_create_and_add("xfs", NULL, fs_kobj);
2050 goto out_sysctl_unregister;
2053 xfsstats.xs_kobj.kobject.kset = xfs_kset;
2055 xfsstats.xs_stats = alloc_percpu(struct xfsstats);
2056 if (!xfsstats.xs_stats) {
2058 goto out_kset_unregister;
2061 error = xfs_sysfs_init(&xfsstats.xs_kobj, &xfs_stats_ktype, NULL,
2064 goto out_free_stats;
2067 xfs_dbg_kobj.kobject.kset = xfs_kset;
2068 error = xfs_sysfs_init(&xfs_dbg_kobj, &xfs_dbg_ktype, NULL, "debug");
2070 goto out_remove_stats_kobj;
2073 error = xfs_qm_init();
2075 goto out_remove_dbg_kobj;
2077 error = register_filesystem(&xfs_fs_type);
2084 out_remove_dbg_kobj:
2086 xfs_sysfs_del(&xfs_dbg_kobj);
2087 out_remove_stats_kobj:
2089 xfs_sysfs_del(&xfsstats.xs_kobj);
2091 free_percpu(xfsstats.xs_stats);
2092 out_kset_unregister:
2093 kset_unregister(xfs_kset);
2094 out_sysctl_unregister:
2095 xfs_sysctl_unregister();
2097 xfs_cleanup_procfs();
2099 xfs_buf_terminate();
2100 out_mru_cache_uninit:
2101 xfs_mru_cache_uninit();
2103 xfs_destroy_workqueues();
2105 xfs_destroy_zones();
2114 unregister_filesystem(&xfs_fs_type);
2116 xfs_sysfs_del(&xfs_dbg_kobj);
2118 xfs_sysfs_del(&xfsstats.xs_kobj);
2119 free_percpu(xfsstats.xs_stats);
2120 kset_unregister(xfs_kset);
2121 xfs_sysctl_unregister();
2122 xfs_cleanup_procfs();
2123 xfs_buf_terminate();
2124 xfs_mru_cache_uninit();
2125 xfs_destroy_workqueues();
2126 xfs_destroy_zones();
2127 xfs_uuid_table_free();
2130 module_init(init_xfs_fs);
2131 module_exit(exit_xfs_fs);
2133 MODULE_AUTHOR("Silicon Graphics, Inc.");
2134 MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
2135 MODULE_LICENSE("GPL");