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/parser.h>
42 static const struct super_operations xfs_super_operations;
44 static struct kset *xfs_kset; /* top-level xfs sysfs dir */
46 static struct xfs_kobj xfs_dbg_kobj; /* global debug sysfs attrs */
50 * Table driven mount option parser.
53 Opt_logbufs, Opt_logbsize, Opt_logdev, Opt_rtdev,
54 Opt_wsync, Opt_noalign, Opt_swalloc, Opt_sunit, Opt_swidth, Opt_nouuid,
55 Opt_grpid, Opt_nogrpid, Opt_bsdgroups, Opt_sysvgroups,
56 Opt_allocsize, Opt_norecovery, Opt_inode64, Opt_inode32, Opt_ikeep,
57 Opt_noikeep, Opt_largeio, Opt_nolargeio, Opt_attr2, Opt_noattr2,
58 Opt_filestreams, Opt_quota, Opt_noquota, Opt_usrquota, Opt_grpquota,
59 Opt_prjquota, Opt_uquota, Opt_gquota, Opt_pquota,
60 Opt_uqnoenforce, Opt_gqnoenforce, Opt_pqnoenforce, Opt_qnoenforce,
61 Opt_discard, Opt_nodiscard, Opt_dax, Opt_err,
64 static const match_table_t tokens = {
65 {Opt_logbufs, "logbufs=%u"}, /* number of XFS log buffers */
66 {Opt_logbsize, "logbsize=%s"}, /* size of XFS log buffers */
67 {Opt_logdev, "logdev=%s"}, /* log device */
68 {Opt_rtdev, "rtdev=%s"}, /* realtime I/O device */
69 {Opt_wsync, "wsync"}, /* safe-mode nfs compatible mount */
70 {Opt_noalign, "noalign"}, /* turn off stripe alignment */
71 {Opt_swalloc, "swalloc"}, /* turn on stripe width allocation */
72 {Opt_sunit, "sunit=%u"}, /* data volume stripe unit */
73 {Opt_swidth, "swidth=%u"}, /* data volume stripe width */
74 {Opt_nouuid, "nouuid"}, /* ignore filesystem UUID */
75 {Opt_grpid, "grpid"}, /* group-ID from parent directory */
76 {Opt_nogrpid, "nogrpid"}, /* group-ID from current process */
77 {Opt_bsdgroups, "bsdgroups"}, /* group-ID from parent directory */
78 {Opt_sysvgroups,"sysvgroups"}, /* group-ID from current process */
79 {Opt_allocsize, "allocsize=%s"},/* preferred allocation size */
80 {Opt_norecovery,"norecovery"}, /* don't run XFS recovery */
81 {Opt_inode64, "inode64"}, /* inodes can be allocated anywhere */
82 {Opt_inode32, "inode32"}, /* inode allocation limited to
83 * XFS_MAXINUMBER_32 */
84 {Opt_ikeep, "ikeep"}, /* do not free empty inode clusters */
85 {Opt_noikeep, "noikeep"}, /* free empty inode clusters */
86 {Opt_largeio, "largeio"}, /* report large I/O sizes in stat() */
87 {Opt_nolargeio, "nolargeio"}, /* do not report large I/O sizes
89 {Opt_attr2, "attr2"}, /* do use attr2 attribute format */
90 {Opt_noattr2, "noattr2"}, /* do not use attr2 attribute format */
91 {Opt_filestreams,"filestreams"},/* use filestreams allocator */
92 {Opt_quota, "quota"}, /* disk quotas (user) */
93 {Opt_noquota, "noquota"}, /* no quotas */
94 {Opt_usrquota, "usrquota"}, /* user quota enabled */
95 {Opt_grpquota, "grpquota"}, /* group quota enabled */
96 {Opt_prjquota, "prjquota"}, /* project quota enabled */
97 {Opt_uquota, "uquota"}, /* user quota (IRIX variant) */
98 {Opt_gquota, "gquota"}, /* group quota (IRIX variant) */
99 {Opt_pquota, "pquota"}, /* project quota (IRIX variant) */
100 {Opt_uqnoenforce,"uqnoenforce"},/* user quota limit enforcement */
101 {Opt_gqnoenforce,"gqnoenforce"},/* group quota limit enforcement */
102 {Opt_pqnoenforce,"pqnoenforce"},/* project quota limit enforcement */
103 {Opt_qnoenforce, "qnoenforce"}, /* same as uqnoenforce */
104 {Opt_discard, "discard"}, /* Discard unused blocks */
105 {Opt_nodiscard, "nodiscard"}, /* Do not discard unused blocks */
106 {Opt_dax, "dax"}, /* Enable direct access to bdev pages */
112 suffix_kstrtoint(const substring_t *s, unsigned int base, int *res)
114 int last, shift_left_factor = 0, _res;
118 value = match_strdup(s);
122 last = strlen(value) - 1;
123 if (value[last] == 'K' || value[last] == 'k') {
124 shift_left_factor = 10;
127 if (value[last] == 'M' || value[last] == 'm') {
128 shift_left_factor = 20;
131 if (value[last] == 'G' || value[last] == 'g') {
132 shift_left_factor = 30;
136 if (kstrtoint(value, base, &_res))
139 *res = _res << shift_left_factor;
144 * This function fills in xfs_mount_t fields based on mount args.
145 * Note: the superblock has _not_ yet been read in.
147 * Note that this function leaks the various device name allocations on
148 * failure. The caller takes care of them.
150 * *sb is const because this is also used to test options on the remount
151 * path, and we don't want this to have any side effects at remount time.
152 * Today this function does not change *sb, but just to future-proof...
156 struct xfs_mount *mp,
159 const struct super_block *sb = mp->m_super;
161 substring_t args[MAX_OPT_ARGS];
165 * Copy binary VFS mount flags we are interested in.
168 mp->m_flags |= XFS_MOUNT_RDONLY;
169 if (sb->s_flags & SB_DIRSYNC)
170 mp->m_flags |= XFS_MOUNT_DIRSYNC;
171 if (sb->s_flags & SB_SYNCHRONOUS)
172 mp->m_flags |= XFS_MOUNT_WSYNC;
175 * These can be overridden by the mount option parsing.
179 mp->m_allocsize_log = 16; /* 64k */
184 while ((p = strsep(&options, ",")) != NULL) {
190 token = match_token(p, tokens, args);
193 if (match_int(args, &mp->m_logbufs))
197 if (suffix_kstrtoint(args, 10, &mp->m_logbsize))
201 kfree(mp->m_logname);
202 mp->m_logname = match_strdup(args);
208 mp->m_rtname = match_strdup(args);
213 if (suffix_kstrtoint(args, 10, &size))
215 mp->m_allocsize_log = ffs(size) - 1;
216 mp->m_flags |= XFS_MOUNT_ALLOCSIZE;
220 mp->m_flags |= XFS_MOUNT_GRPID;
224 mp->m_flags &= ~XFS_MOUNT_GRPID;
227 mp->m_flags |= XFS_MOUNT_WSYNC;
230 mp->m_flags |= XFS_MOUNT_NORECOVERY;
233 mp->m_flags |= XFS_MOUNT_NOALIGN;
236 mp->m_flags |= XFS_MOUNT_SWALLOC;
239 if (match_int(args, &mp->m_dalign))
243 if (match_int(args, &mp->m_swidth))
247 mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
250 mp->m_flags &= ~XFS_MOUNT_SMALL_INUMS;
253 mp->m_flags |= XFS_MOUNT_NOUUID;
256 mp->m_flags |= XFS_MOUNT_IKEEP;
259 mp->m_flags &= ~XFS_MOUNT_IKEEP;
262 mp->m_flags |= XFS_MOUNT_LARGEIO;
265 mp->m_flags &= ~XFS_MOUNT_LARGEIO;
268 mp->m_flags |= XFS_MOUNT_ATTR2;
271 mp->m_flags &= ~XFS_MOUNT_ATTR2;
272 mp->m_flags |= XFS_MOUNT_NOATTR2;
274 case Opt_filestreams:
275 mp->m_flags |= XFS_MOUNT_FILESTREAMS;
278 mp->m_qflags &= ~XFS_ALL_QUOTA_ACCT;
279 mp->m_qflags &= ~XFS_ALL_QUOTA_ENFD;
280 mp->m_qflags &= ~XFS_ALL_QUOTA_ACTIVE;
285 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE |
289 case Opt_uqnoenforce:
290 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
291 mp->m_qflags &= ~XFS_UQUOTA_ENFD;
295 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE |
298 case Opt_pqnoenforce:
299 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
300 mp->m_qflags &= ~XFS_PQUOTA_ENFD;
304 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE |
307 case Opt_gqnoenforce:
308 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
309 mp->m_qflags &= ~XFS_GQUOTA_ENFD;
312 mp->m_flags |= XFS_MOUNT_DISCARD;
315 mp->m_flags &= ~XFS_MOUNT_DISCARD;
319 mp->m_flags |= XFS_MOUNT_DAX;
323 xfs_warn(mp, "unknown mount option [%s].", p);
329 * no recovery flag requires a read-only mount
331 if ((mp->m_flags & XFS_MOUNT_NORECOVERY) &&
332 !(mp->m_flags & XFS_MOUNT_RDONLY)) {
333 xfs_warn(mp, "no-recovery mounts must be read-only.");
337 if ((mp->m_flags & XFS_MOUNT_NOALIGN) &&
338 (mp->m_dalign || mp->m_swidth)) {
340 "sunit and swidth options incompatible with the noalign option");
344 if (!IS_ENABLED(CONFIG_XFS_QUOTA) && mp->m_qflags != 0) {
345 xfs_warn(mp, "quota support not available in this kernel.");
349 if ((mp->m_dalign && !mp->m_swidth) ||
350 (!mp->m_dalign && mp->m_swidth)) {
351 xfs_warn(mp, "sunit and swidth must be specified together");
355 if (mp->m_dalign && (mp->m_swidth % mp->m_dalign != 0)) {
357 "stripe width (%d) must be a multiple of the stripe unit (%d)",
358 mp->m_swidth, mp->m_dalign);
363 if (mp->m_logbufs != -1 &&
364 mp->m_logbufs != 0 &&
365 (mp->m_logbufs < XLOG_MIN_ICLOGS ||
366 mp->m_logbufs > XLOG_MAX_ICLOGS)) {
367 xfs_warn(mp, "invalid logbufs value: %d [not %d-%d]",
368 mp->m_logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
371 if (mp->m_logbsize != -1 &&
372 mp->m_logbsize != 0 &&
373 (mp->m_logbsize < XLOG_MIN_RECORD_BSIZE ||
374 mp->m_logbsize > XLOG_MAX_RECORD_BSIZE ||
375 !is_power_of_2(mp->m_logbsize))) {
377 "invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
382 if ((mp->m_flags & XFS_MOUNT_ALLOCSIZE) &&
383 (mp->m_allocsize_log > XFS_MAX_IO_LOG ||
384 mp->m_allocsize_log < XFS_MIN_IO_LOG)) {
385 xfs_warn(mp, "invalid log iosize: %d [not %d-%d]",
386 mp->m_allocsize_log, XFS_MIN_IO_LOG, XFS_MAX_IO_LOG);
393 struct proc_xfs_info {
403 static struct proc_xfs_info xfs_info_set[] = {
404 /* the few simple ones we can get from the mount struct */
405 { XFS_MOUNT_IKEEP, ",ikeep" },
406 { XFS_MOUNT_WSYNC, ",wsync" },
407 { XFS_MOUNT_NOALIGN, ",noalign" },
408 { XFS_MOUNT_SWALLOC, ",swalloc" },
409 { XFS_MOUNT_NOUUID, ",nouuid" },
410 { XFS_MOUNT_NORECOVERY, ",norecovery" },
411 { XFS_MOUNT_ATTR2, ",attr2" },
412 { XFS_MOUNT_FILESTREAMS, ",filestreams" },
413 { XFS_MOUNT_GRPID, ",grpid" },
414 { XFS_MOUNT_DISCARD, ",discard" },
415 { XFS_MOUNT_LARGEIO, ",largeio" },
416 { XFS_MOUNT_DAX, ",dax" },
419 struct xfs_mount *mp = XFS_M(root->d_sb);
420 struct proc_xfs_info *xfs_infop;
422 for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
423 if (mp->m_flags & xfs_infop->flag)
424 seq_puts(m, xfs_infop->str);
427 seq_printf(m, ",inode%d",
428 (mp->m_flags & XFS_MOUNT_SMALL_INUMS) ? 32 : 64);
430 if (mp->m_flags & XFS_MOUNT_ALLOCSIZE)
431 seq_printf(m, ",allocsize=%dk",
432 (1 << mp->m_allocsize_log) >> 10);
434 if (mp->m_logbufs > 0)
435 seq_printf(m, ",logbufs=%d", mp->m_logbufs);
436 if (mp->m_logbsize > 0)
437 seq_printf(m, ",logbsize=%dk", mp->m_logbsize >> 10);
440 seq_show_option(m, "logdev", mp->m_logname);
442 seq_show_option(m, "rtdev", mp->m_rtname);
444 if (mp->m_dalign > 0)
445 seq_printf(m, ",sunit=%d",
446 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
447 if (mp->m_swidth > 0)
448 seq_printf(m, ",swidth=%d",
449 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
451 if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD))
452 seq_puts(m, ",usrquota");
453 else if (mp->m_qflags & XFS_UQUOTA_ACCT)
454 seq_puts(m, ",uqnoenforce");
456 if (mp->m_qflags & XFS_PQUOTA_ACCT) {
457 if (mp->m_qflags & XFS_PQUOTA_ENFD)
458 seq_puts(m, ",prjquota");
460 seq_puts(m, ",pqnoenforce");
462 if (mp->m_qflags & XFS_GQUOTA_ACCT) {
463 if (mp->m_qflags & XFS_GQUOTA_ENFD)
464 seq_puts(m, ",grpquota");
466 seq_puts(m, ",gqnoenforce");
469 if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
470 seq_puts(m, ",noquota");
477 unsigned int blockshift)
479 unsigned int pagefactor = 1;
480 unsigned int bitshift = BITS_PER_LONG - 1;
482 /* Figure out maximum filesize, on Linux this can depend on
483 * the filesystem blocksize (on 32 bit platforms).
484 * __block_write_begin does this in an [unsigned] long long...
485 * page->index << (PAGE_SHIFT - bbits)
486 * So, for page sized blocks (4K on 32 bit platforms),
487 * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
488 * (((u64)PAGE_SIZE << (BITS_PER_LONG-1))-1)
489 * but for smaller blocksizes it is less (bbits = log2 bsize).
492 #if BITS_PER_LONG == 32
493 ASSERT(sizeof(sector_t) == 8);
494 pagefactor = PAGE_SIZE;
495 bitshift = BITS_PER_LONG;
498 return (((uint64_t)pagefactor) << bitshift) - 1;
502 * Set parameters for inode allocation heuristics, taking into account
503 * filesystem size and inode32/inode64 mount options; i.e. specifically
504 * whether or not XFS_MOUNT_SMALL_INUMS is set.
506 * Inode allocation patterns are altered only if inode32 is requested
507 * (XFS_MOUNT_SMALL_INUMS), and the filesystem is sufficiently large.
508 * If altered, XFS_MOUNT_32BITINODES is set as well.
510 * An agcount independent of that in the mount structure is provided
511 * because in the growfs case, mp->m_sb.sb_agcount is not yet updated
512 * to the potentially higher ag count.
514 * Returns the maximum AG index which may contain inodes.
518 struct xfs_mount *mp,
519 xfs_agnumber_t agcount)
521 xfs_agnumber_t index;
522 xfs_agnumber_t maxagi = 0;
523 xfs_sb_t *sbp = &mp->m_sb;
524 xfs_agnumber_t max_metadata;
529 * Calculate how much should be reserved for inodes to meet
530 * the max inode percentage. Used only for inode32.
532 if (M_IGEO(mp)->maxicount) {
535 icount = sbp->sb_dblocks * sbp->sb_imax_pct;
537 icount += sbp->sb_agblocks - 1;
538 do_div(icount, sbp->sb_agblocks);
539 max_metadata = icount;
541 max_metadata = agcount;
544 /* Get the last possible inode in the filesystem */
545 agino = XFS_AGB_TO_AGINO(mp, sbp->sb_agblocks - 1);
546 ino = XFS_AGINO_TO_INO(mp, agcount - 1, agino);
549 * If user asked for no more than 32-bit inodes, and the fs is
550 * sufficiently large, set XFS_MOUNT_32BITINODES if we must alter
551 * the allocator to accommodate the request.
553 if ((mp->m_flags & XFS_MOUNT_SMALL_INUMS) && ino > XFS_MAXINUMBER_32)
554 mp->m_flags |= XFS_MOUNT_32BITINODES;
556 mp->m_flags &= ~XFS_MOUNT_32BITINODES;
558 for (index = 0; index < agcount; index++) {
559 struct xfs_perag *pag;
561 ino = XFS_AGINO_TO_INO(mp, index, agino);
563 pag = xfs_perag_get(mp, index);
565 if (mp->m_flags & XFS_MOUNT_32BITINODES) {
566 if (ino > XFS_MAXINUMBER_32) {
567 pag->pagi_inodeok = 0;
568 pag->pagf_metadata = 0;
570 pag->pagi_inodeok = 1;
572 if (index < max_metadata)
573 pag->pagf_metadata = 1;
575 pag->pagf_metadata = 0;
578 pag->pagi_inodeok = 1;
579 pag->pagf_metadata = 0;
585 return (mp->m_flags & XFS_MOUNT_32BITINODES) ? maxagi : agcount;
592 struct block_device **bdevp)
596 *bdevp = blkdev_get_by_path(name, FMODE_READ|FMODE_WRITE|FMODE_EXCL,
598 if (IS_ERR(*bdevp)) {
599 error = PTR_ERR(*bdevp);
600 xfs_warn(mp, "Invalid device [%s], error=%d", name, error);
608 struct block_device *bdev)
611 blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
615 xfs_blkdev_issue_flush(
616 xfs_buftarg_t *buftarg)
618 blkdev_issue_flush(buftarg->bt_bdev, GFP_NOFS, NULL);
623 struct xfs_mount *mp)
625 struct dax_device *dax_ddev = mp->m_ddev_targp->bt_daxdev;
627 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
628 struct block_device *logdev = mp->m_logdev_targp->bt_bdev;
629 struct dax_device *dax_logdev = mp->m_logdev_targp->bt_daxdev;
631 xfs_free_buftarg(mp->m_logdev_targp);
632 xfs_blkdev_put(logdev);
633 fs_put_dax(dax_logdev);
635 if (mp->m_rtdev_targp) {
636 struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev;
637 struct dax_device *dax_rtdev = mp->m_rtdev_targp->bt_daxdev;
639 xfs_free_buftarg(mp->m_rtdev_targp);
640 xfs_blkdev_put(rtdev);
641 fs_put_dax(dax_rtdev);
643 xfs_free_buftarg(mp->m_ddev_targp);
644 fs_put_dax(dax_ddev);
648 * The file system configurations are:
649 * (1) device (partition) with data and internal log
650 * (2) logical volume with data and log subvolumes.
651 * (3) logical volume with data, log, and realtime subvolumes.
653 * We only have to handle opening the log and realtime volumes here if
654 * they are present. The data subvolume has already been opened by
655 * get_sb_bdev() and is stored in sb->s_bdev.
659 struct xfs_mount *mp)
661 struct block_device *ddev = mp->m_super->s_bdev;
662 struct dax_device *dax_ddev = fs_dax_get_by_bdev(ddev);
663 struct dax_device *dax_logdev = NULL, *dax_rtdev = NULL;
664 struct block_device *logdev = NULL, *rtdev = NULL;
668 * Open real time and log devices - order is important.
671 error = xfs_blkdev_get(mp, mp->m_logname, &logdev);
674 dax_logdev = fs_dax_get_by_bdev(logdev);
678 error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev);
680 goto out_close_logdev;
682 if (rtdev == ddev || rtdev == logdev) {
684 "Cannot mount filesystem with identical rtdev and ddev/logdev.");
686 goto out_close_rtdev;
688 dax_rtdev = fs_dax_get_by_bdev(rtdev);
692 * Setup xfs_mount buffer target pointers
695 mp->m_ddev_targp = xfs_alloc_buftarg(mp, ddev, dax_ddev);
696 if (!mp->m_ddev_targp)
697 goto out_close_rtdev;
700 mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev, dax_rtdev);
701 if (!mp->m_rtdev_targp)
702 goto out_free_ddev_targ;
705 if (logdev && logdev != ddev) {
706 mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev, dax_logdev);
707 if (!mp->m_logdev_targp)
708 goto out_free_rtdev_targ;
710 mp->m_logdev_targp = mp->m_ddev_targp;
716 if (mp->m_rtdev_targp)
717 xfs_free_buftarg(mp->m_rtdev_targp);
719 xfs_free_buftarg(mp->m_ddev_targp);
721 xfs_blkdev_put(rtdev);
722 fs_put_dax(dax_rtdev);
724 if (logdev && logdev != ddev) {
725 xfs_blkdev_put(logdev);
726 fs_put_dax(dax_logdev);
729 fs_put_dax(dax_ddev);
734 * Setup xfs_mount buffer target pointers based on superblock
738 struct xfs_mount *mp)
742 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_sectsize);
746 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
747 unsigned int log_sector_size = BBSIZE;
749 if (xfs_sb_version_hassector(&mp->m_sb))
750 log_sector_size = mp->m_sb.sb_logsectsize;
751 error = xfs_setsize_buftarg(mp->m_logdev_targp,
756 if (mp->m_rtdev_targp) {
757 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
758 mp->m_sb.sb_sectsize);
767 xfs_init_mount_workqueues(
768 struct xfs_mount *mp)
770 mp->m_buf_workqueue = alloc_workqueue("xfs-buf/%s",
771 WQ_MEM_RECLAIM|WQ_FREEZABLE, 1, mp->m_super->s_id);
772 if (!mp->m_buf_workqueue)
775 mp->m_unwritten_workqueue = alloc_workqueue("xfs-conv/%s",
776 WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_super->s_id);
777 if (!mp->m_unwritten_workqueue)
778 goto out_destroy_buf;
780 mp->m_cil_workqueue = alloc_workqueue("xfs-cil/%s",
781 WQ_MEM_RECLAIM | WQ_FREEZABLE | WQ_UNBOUND,
782 0, mp->m_super->s_id);
783 if (!mp->m_cil_workqueue)
784 goto out_destroy_unwritten;
786 mp->m_reclaim_workqueue = alloc_workqueue("xfs-reclaim/%s",
787 WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_super->s_id);
788 if (!mp->m_reclaim_workqueue)
789 goto out_destroy_cil;
791 mp->m_eofblocks_workqueue = alloc_workqueue("xfs-eofblocks/%s",
792 WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_super->s_id);
793 if (!mp->m_eofblocks_workqueue)
794 goto out_destroy_reclaim;
796 mp->m_sync_workqueue = alloc_workqueue("xfs-sync/%s", WQ_FREEZABLE, 0,
798 if (!mp->m_sync_workqueue)
799 goto out_destroy_eofb;
804 destroy_workqueue(mp->m_eofblocks_workqueue);
806 destroy_workqueue(mp->m_reclaim_workqueue);
808 destroy_workqueue(mp->m_cil_workqueue);
809 out_destroy_unwritten:
810 destroy_workqueue(mp->m_unwritten_workqueue);
812 destroy_workqueue(mp->m_buf_workqueue);
818 xfs_destroy_mount_workqueues(
819 struct xfs_mount *mp)
821 destroy_workqueue(mp->m_sync_workqueue);
822 destroy_workqueue(mp->m_eofblocks_workqueue);
823 destroy_workqueue(mp->m_reclaim_workqueue);
824 destroy_workqueue(mp->m_cil_workqueue);
825 destroy_workqueue(mp->m_unwritten_workqueue);
826 destroy_workqueue(mp->m_buf_workqueue);
830 * Flush all dirty data to disk. Must not be called while holding an XFS_ILOCK
831 * or a page lock. We use sync_inodes_sb() here to ensure we block while waiting
832 * for IO to complete so that we effectively throttle multiple callers to the
833 * rate at which IO is completing.
837 struct xfs_mount *mp)
839 struct super_block *sb = mp->m_super;
841 if (down_read_trylock(&sb->s_umount)) {
843 up_read(&sb->s_umount);
847 /* Catch misguided souls that try to use this interface on XFS */
848 STATIC struct inode *
850 struct super_block *sb)
859 struct xfs_inode *ip,
862 struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, whichfork);
863 struct xfs_bmbt_irec got;
864 struct xfs_iext_cursor icur;
866 if (!ifp || !xfs_iext_lookup_extent(ip, ifp, 0, &icur, &got))
869 if (isnullstartblock(got.br_startblock)) {
870 xfs_warn(ip->i_mount,
871 "ino %llx %s fork has delalloc extent at [0x%llx:0x%llx]",
873 whichfork == XFS_DATA_FORK ? "data" : "cow",
874 got.br_startoff, got.br_blockcount);
876 } while (xfs_iext_next_extent(ifp, &icur, &got));
879 #define xfs_check_delalloc(ip, whichfork) do { } while (0)
883 * Now that the generic code is guaranteed not to be accessing
884 * the linux inode, we can inactivate and reclaim the inode.
887 xfs_fs_destroy_inode(
890 struct xfs_inode *ip = XFS_I(inode);
892 trace_xfs_destroy_inode(ip);
894 ASSERT(!rwsem_is_locked(&inode->i_rwsem));
895 XFS_STATS_INC(ip->i_mount, vn_rele);
896 XFS_STATS_INC(ip->i_mount, vn_remove);
900 if (!XFS_FORCED_SHUTDOWN(ip->i_mount) && ip->i_delayed_blks) {
901 xfs_check_delalloc(ip, XFS_DATA_FORK);
902 xfs_check_delalloc(ip, XFS_COW_FORK);
906 XFS_STATS_INC(ip->i_mount, vn_reclaim);
909 * We should never get here with one of the reclaim flags already set.
911 ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIMABLE));
912 ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIM));
915 * We always use background reclaim here because even if the
916 * inode is clean, it still may be under IO and hence we have
917 * to take the flush lock. The background reclaim path handles
918 * this more efficiently than we can here, so simply let background
919 * reclaim tear down all inodes.
921 xfs_inode_set_reclaim_tag(ip);
929 struct xfs_inode *ip = XFS_I(inode);
930 struct xfs_mount *mp = ip->i_mount;
931 struct xfs_trans *tp;
933 if (!(inode->i_sb->s_flags & SB_LAZYTIME))
935 if (flag != I_DIRTY_SYNC || !(inode->i_state & I_DIRTY_TIME))
938 if (xfs_trans_alloc(mp, &M_RES(mp)->tr_fsyncts, 0, 0, 0, &tp))
940 xfs_ilock(ip, XFS_ILOCK_EXCL);
941 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
942 xfs_trans_log_inode(tp, ip, XFS_ILOG_TIMESTAMP);
943 xfs_trans_commit(tp);
947 * Slab object creation initialisation for the XFS inode.
948 * This covers only the idempotent fields in the XFS inode;
949 * all other fields need to be initialised on allocation
950 * from the slab. This avoids the need to repeatedly initialise
951 * fields in the xfs inode that left in the initialise state
952 * when freeing the inode.
955 xfs_fs_inode_init_once(
958 struct xfs_inode *ip = inode;
960 memset(ip, 0, sizeof(struct xfs_inode));
963 inode_init_once(VFS_I(ip));
966 atomic_set(&ip->i_pincount, 0);
967 spin_lock_init(&ip->i_flags_lock);
969 mrlock_init(&ip->i_mmaplock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
970 "xfsino", ip->i_ino);
971 mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
972 "xfsino", ip->i_ino);
976 * We do an unlocked check for XFS_IDONTCACHE here because we are already
977 * serialised against cache hits here via the inode->i_lock and igrab() in
978 * xfs_iget_cache_hit(). Hence a lookup that might clear this flag will not be
979 * racing with us, and it avoids needing to grab a spinlock here for every inode
980 * we drop the final reference on.
986 struct xfs_inode *ip = XFS_I(inode);
989 * If this unlinked inode is in the middle of recovery, don't
990 * drop the inode just yet; log recovery will take care of
991 * that. See the comment for this inode flag.
993 if (ip->i_flags & XFS_IRECOVERY) {
994 ASSERT(ip->i_mount->m_log->l_flags & XLOG_RECOVERY_NEEDED);
998 return generic_drop_inode(inode) || (ip->i_flags & XFS_IDONTCACHE);
1003 struct xfs_mount *mp)
1005 kfree(mp->m_rtname);
1006 kfree(mp->m_logname);
1011 struct super_block *sb,
1014 struct xfs_mount *mp = XFS_M(sb);
1017 * Doing anything during the async pass would be counterproductive.
1022 xfs_log_force(mp, XFS_LOG_SYNC);
1025 * The disk must be active because we're syncing.
1026 * We schedule log work now (now that the disk is
1027 * active) instead of later (when it might not be).
1029 flush_delayed_work(&mp->m_log->l_work);
1037 struct dentry *dentry,
1038 struct kstatfs *statp)
1040 struct xfs_mount *mp = XFS_M(dentry->d_sb);
1041 xfs_sb_t *sbp = &mp->m_sb;
1042 struct xfs_inode *ip = XFS_I(d_inode(dentry));
1043 uint64_t fakeinos, id;
1050 statp->f_type = XFS_SUPER_MAGIC;
1051 statp->f_namelen = MAXNAMELEN - 1;
1053 id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
1054 statp->f_fsid.val[0] = (u32)id;
1055 statp->f_fsid.val[1] = (u32)(id >> 32);
1057 icount = percpu_counter_sum(&mp->m_icount);
1058 ifree = percpu_counter_sum(&mp->m_ifree);
1059 fdblocks = percpu_counter_sum(&mp->m_fdblocks);
1061 spin_lock(&mp->m_sb_lock);
1062 statp->f_bsize = sbp->sb_blocksize;
1063 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
1064 statp->f_blocks = sbp->sb_dblocks - lsize;
1065 spin_unlock(&mp->m_sb_lock);
1067 statp->f_bfree = fdblocks - mp->m_alloc_set_aside;
1068 statp->f_bavail = statp->f_bfree;
1070 fakeinos = XFS_FSB_TO_INO(mp, statp->f_bfree);
1071 statp->f_files = min(icount + fakeinos, (uint64_t)XFS_MAXINUMBER);
1072 if (M_IGEO(mp)->maxicount)
1073 statp->f_files = min_t(typeof(statp->f_files),
1075 M_IGEO(mp)->maxicount);
1077 /* If sb_icount overshot maxicount, report actual allocation */
1078 statp->f_files = max_t(typeof(statp->f_files),
1082 /* make sure statp->f_ffree does not underflow */
1083 ffree = statp->f_files - (icount - ifree);
1084 statp->f_ffree = max_t(int64_t, ffree, 0);
1087 if ((ip->i_d.di_flags & XFS_DIFLAG_PROJINHERIT) &&
1088 ((mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))) ==
1089 (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))
1090 xfs_qm_statvfs(ip, statp);
1092 if (XFS_IS_REALTIME_MOUNT(mp) &&
1093 (ip->i_d.di_flags & (XFS_DIFLAG_RTINHERIT | XFS_DIFLAG_REALTIME))) {
1094 statp->f_blocks = sbp->sb_rblocks;
1095 statp->f_bavail = statp->f_bfree =
1096 sbp->sb_frextents * sbp->sb_rextsize;
1103 xfs_save_resvblks(struct xfs_mount *mp)
1105 uint64_t resblks = 0;
1107 mp->m_resblks_save = mp->m_resblks;
1108 xfs_reserve_blocks(mp, &resblks, NULL);
1112 xfs_restore_resvblks(struct xfs_mount *mp)
1116 if (mp->m_resblks_save) {
1117 resblks = mp->m_resblks_save;
1118 mp->m_resblks_save = 0;
1120 resblks = xfs_default_resblks(mp);
1122 xfs_reserve_blocks(mp, &resblks, NULL);
1126 * Trigger writeback of all the dirty metadata in the file system.
1128 * This ensures that the metadata is written to their location on disk rather
1129 * than just existing in transactions in the log. This means after a quiesce
1130 * there is no log replay required to write the inodes to disk - this is the
1131 * primary difference between a sync and a quiesce.
1133 * Note: xfs_log_quiesce() stops background log work - the callers must ensure
1134 * it is started again when appropriate.
1138 struct xfs_mount *mp)
1142 /* wait for all modifications to complete */
1143 while (atomic_read(&mp->m_active_trans) > 0)
1146 /* force the log to unpin objects from the now complete transactions */
1147 xfs_log_force(mp, XFS_LOG_SYNC);
1149 /* reclaim inodes to do any IO before the freeze completes */
1150 xfs_reclaim_inodes(mp, 0);
1151 xfs_reclaim_inodes(mp, SYNC_WAIT);
1153 /* Push the superblock and write an unmount record */
1154 error = xfs_log_sbcount(mp);
1156 xfs_warn(mp, "xfs_attr_quiesce: failed to log sb changes. "
1157 "Frozen image may not be consistent.");
1159 * Just warn here till VFS can correctly support
1160 * read-only remount without racing.
1162 WARN_ON(atomic_read(&mp->m_active_trans) != 0);
1164 xfs_log_quiesce(mp);
1168 xfs_test_remount_options(
1169 struct super_block *sb,
1173 struct xfs_mount *tmp_mp;
1175 tmp_mp = kmem_zalloc(sizeof(*tmp_mp), KM_MAYFAIL);
1179 tmp_mp->m_super = sb;
1180 error = xfs_parseargs(tmp_mp, options);
1181 xfs_free_names(tmp_mp);
1189 struct super_block *sb,
1193 struct xfs_mount *mp = XFS_M(sb);
1194 xfs_sb_t *sbp = &mp->m_sb;
1195 substring_t args[MAX_OPT_ARGS];
1199 /* First, check for complete junk; i.e. invalid options */
1200 error = xfs_test_remount_options(sb, options);
1204 sync_filesystem(sb);
1205 while ((p = strsep(&options, ",")) != NULL) {
1211 token = match_token(p, tokens, args);
1214 mp->m_flags &= ~XFS_MOUNT_SMALL_INUMS;
1215 mp->m_maxagi = xfs_set_inode_alloc(mp, sbp->sb_agcount);
1218 mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
1219 mp->m_maxagi = xfs_set_inode_alloc(mp, sbp->sb_agcount);
1223 * Logically we would return an error here to prevent
1224 * users from believing they might have changed
1225 * mount options using remount which can't be changed.
1227 * But unfortunately mount(8) adds all options from
1228 * mtab and fstab to the mount arguments in some cases
1229 * so we can't blindly reject options, but have to
1230 * check for each specified option if it actually
1231 * differs from the currently set option and only
1232 * reject it if that's the case.
1234 * Until that is implemented we return success for
1235 * every remount request, and silently ignore all
1236 * options that we can't actually change.
1240 "mount option \"%s\" not supported for remount", p);
1249 if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(*flags & SB_RDONLY)) {
1250 if (mp->m_flags & XFS_MOUNT_NORECOVERY) {
1252 "ro->rw transition prohibited on norecovery mount");
1256 if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 &&
1257 xfs_sb_has_ro_compat_feature(sbp,
1258 XFS_SB_FEAT_RO_COMPAT_UNKNOWN)) {
1260 "ro->rw transition prohibited on unknown (0x%x) ro-compat filesystem",
1261 (sbp->sb_features_ro_compat &
1262 XFS_SB_FEAT_RO_COMPAT_UNKNOWN));
1266 mp->m_flags &= ~XFS_MOUNT_RDONLY;
1269 * If this is the first remount to writeable state we
1270 * might have some superblock changes to update.
1272 if (mp->m_update_sb) {
1273 error = xfs_sync_sb(mp, false);
1275 xfs_warn(mp, "failed to write sb changes");
1278 mp->m_update_sb = false;
1282 * Fill out the reserve pool if it is empty. Use the stashed
1283 * value if it is non-zero, otherwise go with the default.
1285 xfs_restore_resvblks(mp);
1286 xfs_log_work_queue(mp);
1288 /* Recover any CoW blocks that never got remapped. */
1289 error = xfs_reflink_recover_cow(mp);
1292 "Error %d recovering leftover CoW allocations.", error);
1293 xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
1296 xfs_start_block_reaping(mp);
1298 /* Create the per-AG metadata reservation pool .*/
1299 error = xfs_fs_reserve_ag_blocks(mp);
1300 if (error && error != -ENOSPC)
1305 if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (*flags & SB_RDONLY)) {
1307 * Cancel background eofb scanning so it cannot race with the
1308 * final log force+buftarg wait and deadlock the remount.
1310 xfs_stop_block_reaping(mp);
1312 /* Get rid of any leftover CoW reservations... */
1313 error = xfs_icache_free_cowblocks(mp, NULL);
1315 xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
1319 /* Free the per-AG metadata reservation pool. */
1320 error = xfs_fs_unreserve_ag_blocks(mp);
1322 xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
1327 * Before we sync the metadata, we need to free up the reserve
1328 * block pool so that the used block count in the superblock on
1329 * disk is correct at the end of the remount. Stash the current
1330 * reserve pool size so that if we get remounted rw, we can
1331 * return it to the same size.
1333 xfs_save_resvblks(mp);
1335 xfs_quiesce_attr(mp);
1336 mp->m_flags |= XFS_MOUNT_RDONLY;
1343 * Second stage of a freeze. The data is already frozen so we only
1344 * need to take care of the metadata. Once that's done sync the superblock
1345 * to the log to dirty it in case of a crash while frozen. This ensures that we
1346 * will recover the unlinked inode lists on the next mount.
1350 struct super_block *sb)
1352 struct xfs_mount *mp = XFS_M(sb);
1354 xfs_stop_block_reaping(mp);
1355 xfs_save_resvblks(mp);
1356 xfs_quiesce_attr(mp);
1357 return xfs_sync_sb(mp, true);
1362 struct super_block *sb)
1364 struct xfs_mount *mp = XFS_M(sb);
1366 xfs_restore_resvblks(mp);
1367 xfs_log_work_queue(mp);
1368 xfs_start_block_reaping(mp);
1373 * This function fills in xfs_mount_t fields based on mount args.
1374 * Note: the superblock _has_ now been read in.
1378 struct xfs_mount *mp)
1380 int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
1382 /* Fail a mount where the logbuf is smaller than the log stripe */
1383 if (xfs_sb_version_haslogv2(&mp->m_sb)) {
1384 if (mp->m_logbsize <= 0 &&
1385 mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE) {
1386 mp->m_logbsize = mp->m_sb.sb_logsunit;
1387 } else if (mp->m_logbsize > 0 &&
1388 mp->m_logbsize < mp->m_sb.sb_logsunit) {
1390 "logbuf size must be greater than or equal to log stripe size");
1394 /* Fail a mount if the logbuf is larger than 32K */
1395 if (mp->m_logbsize > XLOG_BIG_RECORD_BSIZE) {
1397 "logbuf size for version 1 logs must be 16K or 32K");
1403 * V5 filesystems always use attr2 format for attributes.
1405 if (xfs_sb_version_hascrc(&mp->m_sb) &&
1406 (mp->m_flags & XFS_MOUNT_NOATTR2)) {
1407 xfs_warn(mp, "Cannot mount a V5 filesystem as noattr2. "
1408 "attr2 is always enabled for V5 filesystems.");
1413 * mkfs'ed attr2 will turn on attr2 mount unless explicitly
1414 * told by noattr2 to turn it off
1416 if (xfs_sb_version_hasattr2(&mp->m_sb) &&
1417 !(mp->m_flags & XFS_MOUNT_NOATTR2))
1418 mp->m_flags |= XFS_MOUNT_ATTR2;
1421 * prohibit r/w mounts of read-only filesystems
1423 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
1425 "cannot mount a read-only filesystem as read-write");
1429 if ((mp->m_qflags & (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE)) &&
1430 (mp->m_qflags & (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE)) &&
1431 !xfs_sb_version_has_pquotino(&mp->m_sb)) {
1433 "Super block does not support project and group quota together");
1441 xfs_init_percpu_counters(
1442 struct xfs_mount *mp)
1446 error = percpu_counter_init(&mp->m_icount, 0, GFP_KERNEL);
1450 error = percpu_counter_init(&mp->m_ifree, 0, GFP_KERNEL);
1454 error = percpu_counter_init(&mp->m_fdblocks, 0, GFP_KERNEL);
1458 error = percpu_counter_init(&mp->m_delalloc_blks, 0, GFP_KERNEL);
1465 percpu_counter_destroy(&mp->m_fdblocks);
1467 percpu_counter_destroy(&mp->m_ifree);
1469 percpu_counter_destroy(&mp->m_icount);
1474 xfs_reinit_percpu_counters(
1475 struct xfs_mount *mp)
1477 percpu_counter_set(&mp->m_icount, mp->m_sb.sb_icount);
1478 percpu_counter_set(&mp->m_ifree, mp->m_sb.sb_ifree);
1479 percpu_counter_set(&mp->m_fdblocks, mp->m_sb.sb_fdblocks);
1483 xfs_destroy_percpu_counters(
1484 struct xfs_mount *mp)
1486 percpu_counter_destroy(&mp->m_icount);
1487 percpu_counter_destroy(&mp->m_ifree);
1488 percpu_counter_destroy(&mp->m_fdblocks);
1489 ASSERT(XFS_FORCED_SHUTDOWN(mp) ||
1490 percpu_counter_sum(&mp->m_delalloc_blks) == 0);
1491 percpu_counter_destroy(&mp->m_delalloc_blks);
1494 static struct xfs_mount *
1496 struct super_block *sb)
1498 struct xfs_mount *mp;
1500 mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
1505 spin_lock_init(&mp->m_sb_lock);
1506 spin_lock_init(&mp->m_agirotor_lock);
1507 INIT_RADIX_TREE(&mp->m_perag_tree, GFP_ATOMIC);
1508 spin_lock_init(&mp->m_perag_lock);
1509 mutex_init(&mp->m_growlock);
1510 atomic_set(&mp->m_active_trans, 0);
1511 INIT_DELAYED_WORK(&mp->m_reclaim_work, xfs_reclaim_worker);
1512 INIT_DELAYED_WORK(&mp->m_eofblocks_work, xfs_eofblocks_worker);
1513 INIT_DELAYED_WORK(&mp->m_cowblocks_work, xfs_cowblocks_worker);
1514 mp->m_kobj.kobject.kset = xfs_kset;
1516 * We don't create the finobt per-ag space reservation until after log
1517 * recovery, so we must set this to true so that an ifree transaction
1518 * started during log recovery will not depend on space reservations
1519 * for finobt expansion.
1521 mp->m_finobt_nores = true;
1528 struct super_block *sb,
1533 struct xfs_mount *mp = NULL;
1534 int flags = 0, error = -ENOMEM;
1537 * allocate mp and do all low-level struct initializations before we
1538 * attach it to the super
1540 mp = xfs_mount_alloc(sb);
1545 error = xfs_parseargs(mp, (char *)data);
1547 goto out_free_names;
1549 sb_min_blocksize(sb, BBSIZE);
1550 sb->s_xattr = xfs_xattr_handlers;
1551 sb->s_export_op = &xfs_export_operations;
1552 #ifdef CONFIG_XFS_QUOTA
1553 sb->s_qcop = &xfs_quotactl_operations;
1554 sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ;
1556 sb->s_op = &xfs_super_operations;
1559 * Delay mount work if the debug hook is set. This is debug
1560 * instrumention to coordinate simulation of xfs mount failures with
1561 * VFS superblock operations
1563 if (xfs_globals.mount_delay) {
1564 xfs_notice(mp, "Delaying mount for %d seconds.",
1565 xfs_globals.mount_delay);
1566 msleep(xfs_globals.mount_delay * 1000);
1570 flags |= XFS_MFSI_QUIET;
1572 error = xfs_open_devices(mp);
1574 goto out_free_names;
1576 error = xfs_init_mount_workqueues(mp);
1578 goto out_close_devices;
1580 error = xfs_init_percpu_counters(mp);
1582 goto out_destroy_workqueues;
1584 /* Allocate stats memory before we do operations that might use it */
1585 mp->m_stats.xs_stats = alloc_percpu(struct xfsstats);
1586 if (!mp->m_stats.xs_stats) {
1588 goto out_destroy_counters;
1591 error = xfs_readsb(mp, flags);
1593 goto out_free_stats;
1595 error = xfs_finish_flags(mp);
1599 error = xfs_setup_devices(mp);
1603 error = xfs_filestream_mount(mp);
1608 * we must configure the block size in the superblock before we run the
1609 * full mount process as the mount process can lookup and cache inodes.
1611 sb->s_magic = XFS_SUPER_MAGIC;
1612 sb->s_blocksize = mp->m_sb.sb_blocksize;
1613 sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
1614 sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
1615 sb->s_max_links = XFS_MAXLINK;
1616 sb->s_time_gran = 1;
1617 sb->s_time_min = S32_MIN;
1618 sb->s_time_max = S32_MAX;
1619 sb->s_iflags |= SB_I_CGROUPWB;
1621 set_posix_acl_flag(sb);
1623 /* version 5 superblocks support inode version counters. */
1624 if (XFS_SB_VERSION_NUM(&mp->m_sb) == XFS_SB_VERSION_5)
1625 sb->s_flags |= SB_I_VERSION;
1627 if (mp->m_flags & XFS_MOUNT_DAX) {
1628 bool rtdev_is_dax = false, datadev_is_dax;
1631 "DAX enabled. Warning: EXPERIMENTAL, use at your own risk");
1633 datadev_is_dax = bdev_dax_supported(mp->m_ddev_targp->bt_bdev,
1635 if (mp->m_rtdev_targp)
1636 rtdev_is_dax = bdev_dax_supported(
1637 mp->m_rtdev_targp->bt_bdev, sb->s_blocksize);
1638 if (!rtdev_is_dax && !datadev_is_dax) {
1640 "DAX unsupported by block device. Turning off DAX.");
1641 mp->m_flags &= ~XFS_MOUNT_DAX;
1643 if (xfs_sb_version_hasreflink(&mp->m_sb)) {
1645 "DAX and reflink cannot be used together!");
1647 goto out_filestream_unmount;
1651 if (mp->m_flags & XFS_MOUNT_DISCARD) {
1652 struct request_queue *q = bdev_get_queue(sb->s_bdev);
1654 if (!blk_queue_discard(q)) {
1655 xfs_warn(mp, "mounting with \"discard\" option, but "
1656 "the device does not support discard");
1657 mp->m_flags &= ~XFS_MOUNT_DISCARD;
1661 if (xfs_sb_version_hasreflink(&mp->m_sb)) {
1662 if (mp->m_sb.sb_rblocks) {
1664 "reflink not compatible with realtime device!");
1666 goto out_filestream_unmount;
1669 if (xfs_globals.always_cow) {
1670 xfs_info(mp, "using DEBUG-only always_cow mode.");
1671 mp->m_always_cow = true;
1675 if (xfs_sb_version_hasrmapbt(&mp->m_sb) && mp->m_sb.sb_rblocks) {
1677 "reverse mapping btree not compatible with realtime device!");
1679 goto out_filestream_unmount;
1682 error = xfs_mountfs(mp);
1684 goto out_filestream_unmount;
1686 root = igrab(VFS_I(mp->m_rootip));
1691 sb->s_root = d_make_root(root);
1699 out_filestream_unmount:
1700 xfs_filestream_unmount(mp);
1704 free_percpu(mp->m_stats.xs_stats);
1705 out_destroy_counters:
1706 xfs_destroy_percpu_counters(mp);
1707 out_destroy_workqueues:
1708 xfs_destroy_mount_workqueues(mp);
1710 xfs_close_devices(mp);
1712 sb->s_fs_info = NULL;
1719 xfs_filestream_unmount(mp);
1726 struct super_block *sb)
1728 struct xfs_mount *mp = XFS_M(sb);
1730 /* if ->fill_super failed, we have no mount to tear down */
1734 xfs_notice(mp, "Unmounting Filesystem");
1735 xfs_filestream_unmount(mp);
1739 free_percpu(mp->m_stats.xs_stats);
1740 xfs_destroy_percpu_counters(mp);
1741 xfs_destroy_mount_workqueues(mp);
1742 xfs_close_devices(mp);
1744 sb->s_fs_info = NULL;
1749 STATIC struct dentry *
1751 struct file_system_type *fs_type,
1753 const char *dev_name,
1756 return mount_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super);
1760 xfs_fs_nr_cached_objects(
1761 struct super_block *sb,
1762 struct shrink_control *sc)
1764 /* Paranoia: catch incorrect calls during mount setup or teardown */
1765 if (WARN_ON_ONCE(!sb->s_fs_info))
1767 return xfs_reclaim_inodes_count(XFS_M(sb));
1771 xfs_fs_free_cached_objects(
1772 struct super_block *sb,
1773 struct shrink_control *sc)
1775 return xfs_reclaim_inodes_nr(XFS_M(sb), sc->nr_to_scan);
1778 static const struct super_operations xfs_super_operations = {
1779 .alloc_inode = xfs_fs_alloc_inode,
1780 .destroy_inode = xfs_fs_destroy_inode,
1781 .dirty_inode = xfs_fs_dirty_inode,
1782 .drop_inode = xfs_fs_drop_inode,
1783 .put_super = xfs_fs_put_super,
1784 .sync_fs = xfs_fs_sync_fs,
1785 .freeze_fs = xfs_fs_freeze,
1786 .unfreeze_fs = xfs_fs_unfreeze,
1787 .statfs = xfs_fs_statfs,
1788 .remount_fs = xfs_fs_remount,
1789 .show_options = xfs_fs_show_options,
1790 .nr_cached_objects = xfs_fs_nr_cached_objects,
1791 .free_cached_objects = xfs_fs_free_cached_objects,
1794 static struct file_system_type xfs_fs_type = {
1795 .owner = THIS_MODULE,
1797 .mount = xfs_fs_mount,
1798 .kill_sb = kill_block_super,
1799 .fs_flags = FS_REQUIRES_DEV,
1801 MODULE_ALIAS_FS("xfs");
1804 xfs_init_zones(void)
1806 xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t),
1808 if (!xfs_log_ticket_zone)
1811 xfs_bmap_free_item_zone = kmem_zone_init(
1812 sizeof(struct xfs_extent_free_item),
1813 "xfs_bmap_free_item");
1814 if (!xfs_bmap_free_item_zone)
1815 goto out_destroy_log_ticket_zone;
1817 xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
1819 if (!xfs_btree_cur_zone)
1820 goto out_destroy_bmap_free_item_zone;
1822 xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t),
1824 if (!xfs_da_state_zone)
1825 goto out_destroy_btree_cur_zone;
1827 xfs_ifork_zone = kmem_zone_init(sizeof(struct xfs_ifork), "xfs_ifork");
1828 if (!xfs_ifork_zone)
1829 goto out_destroy_da_state_zone;
1831 xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "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_zone_init(sizeof(struct xfs_buf_log_item),
1843 if (!xfs_buf_item_zone)
1844 goto out_destroy_trans_zone;
1846 xfs_efd_zone = kmem_zone_init((sizeof(xfs_efd_log_item_t) +
1847 ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
1848 sizeof(xfs_extent_t))), "xfs_efd_item");
1850 goto out_destroy_buf_item_zone;
1852 xfs_efi_zone = kmem_zone_init((sizeof(xfs_efi_log_item_t) +
1853 ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
1854 sizeof(xfs_extent_t))), "xfs_efi_item");
1856 goto out_destroy_efd_zone;
1859 kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
1860 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM | KM_ZONE_SPREAD |
1861 KM_ZONE_ACCOUNT, xfs_fs_inode_init_once);
1862 if (!xfs_inode_zone)
1863 goto out_destroy_efi_zone;
1866 kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
1867 KM_ZONE_SPREAD, NULL);
1869 goto out_destroy_inode_zone;
1870 xfs_icreate_zone = kmem_zone_init(sizeof(struct xfs_icreate_item),
1872 if (!xfs_icreate_zone)
1873 goto out_destroy_ili_zone;
1875 xfs_rud_zone = kmem_zone_init(sizeof(struct xfs_rud_log_item),
1878 goto out_destroy_icreate_zone;
1880 xfs_rui_zone = kmem_zone_init(
1881 xfs_rui_log_item_sizeof(XFS_RUI_MAX_FAST_EXTENTS),
1884 goto out_destroy_rud_zone;
1886 xfs_cud_zone = kmem_zone_init(sizeof(struct xfs_cud_log_item),
1889 goto out_destroy_rui_zone;
1891 xfs_cui_zone = kmem_zone_init(
1892 xfs_cui_log_item_sizeof(XFS_CUI_MAX_FAST_EXTENTS),
1895 goto out_destroy_cud_zone;
1897 xfs_bud_zone = kmem_zone_init(sizeof(struct xfs_bud_log_item),
1900 goto out_destroy_cui_zone;
1902 xfs_bui_zone = kmem_zone_init(
1903 xfs_bui_log_item_sizeof(XFS_BUI_MAX_FAST_EXTENTS),
1906 goto out_destroy_bud_zone;
1910 out_destroy_bud_zone:
1911 kmem_zone_destroy(xfs_bud_zone);
1912 out_destroy_cui_zone:
1913 kmem_zone_destroy(xfs_cui_zone);
1914 out_destroy_cud_zone:
1915 kmem_zone_destroy(xfs_cud_zone);
1916 out_destroy_rui_zone:
1917 kmem_zone_destroy(xfs_rui_zone);
1918 out_destroy_rud_zone:
1919 kmem_zone_destroy(xfs_rud_zone);
1920 out_destroy_icreate_zone:
1921 kmem_zone_destroy(xfs_icreate_zone);
1922 out_destroy_ili_zone:
1923 kmem_zone_destroy(xfs_ili_zone);
1924 out_destroy_inode_zone:
1925 kmem_zone_destroy(xfs_inode_zone);
1926 out_destroy_efi_zone:
1927 kmem_zone_destroy(xfs_efi_zone);
1928 out_destroy_efd_zone:
1929 kmem_zone_destroy(xfs_efd_zone);
1930 out_destroy_buf_item_zone:
1931 kmem_zone_destroy(xfs_buf_item_zone);
1932 out_destroy_trans_zone:
1933 kmem_zone_destroy(xfs_trans_zone);
1934 out_destroy_ifork_zone:
1935 kmem_zone_destroy(xfs_ifork_zone);
1936 out_destroy_da_state_zone:
1937 kmem_zone_destroy(xfs_da_state_zone);
1938 out_destroy_btree_cur_zone:
1939 kmem_zone_destroy(xfs_btree_cur_zone);
1940 out_destroy_bmap_free_item_zone:
1941 kmem_zone_destroy(xfs_bmap_free_item_zone);
1942 out_destroy_log_ticket_zone:
1943 kmem_zone_destroy(xfs_log_ticket_zone);
1949 xfs_destroy_zones(void)
1952 * Make sure all delayed rcu free are flushed before we
1956 kmem_zone_destroy(xfs_bui_zone);
1957 kmem_zone_destroy(xfs_bud_zone);
1958 kmem_zone_destroy(xfs_cui_zone);
1959 kmem_zone_destroy(xfs_cud_zone);
1960 kmem_zone_destroy(xfs_rui_zone);
1961 kmem_zone_destroy(xfs_rud_zone);
1962 kmem_zone_destroy(xfs_icreate_zone);
1963 kmem_zone_destroy(xfs_ili_zone);
1964 kmem_zone_destroy(xfs_inode_zone);
1965 kmem_zone_destroy(xfs_efi_zone);
1966 kmem_zone_destroy(xfs_efd_zone);
1967 kmem_zone_destroy(xfs_buf_item_zone);
1968 kmem_zone_destroy(xfs_trans_zone);
1969 kmem_zone_destroy(xfs_ifork_zone);
1970 kmem_zone_destroy(xfs_da_state_zone);
1971 kmem_zone_destroy(xfs_btree_cur_zone);
1972 kmem_zone_destroy(xfs_bmap_free_item_zone);
1973 kmem_zone_destroy(xfs_log_ticket_zone);
1977 xfs_init_workqueues(void)
1980 * The allocation workqueue can be used in memory reclaim situations
1981 * (writepage path), and parallelism is only limited by the number of
1982 * AGs in all the filesystems mounted. Hence use the default large
1983 * max_active value for this workqueue.
1985 xfs_alloc_wq = alloc_workqueue("xfsalloc",
1986 WQ_MEM_RECLAIM|WQ_FREEZABLE, 0);
1990 xfs_discard_wq = alloc_workqueue("xfsdiscard", WQ_UNBOUND, 0);
1991 if (!xfs_discard_wq)
1992 goto out_free_alloc_wq;
1996 destroy_workqueue(xfs_alloc_wq);
2001 xfs_destroy_workqueues(void)
2003 destroy_workqueue(xfs_discard_wq);
2004 destroy_workqueue(xfs_alloc_wq);
2012 xfs_check_ondisk_structs();
2014 printk(KERN_INFO XFS_VERSION_STRING " with "
2015 XFS_BUILD_OPTIONS " enabled\n");
2019 error = xfs_init_zones();
2023 error = xfs_init_workqueues();
2025 goto out_destroy_zones;
2027 error = xfs_mru_cache_init();
2029 goto out_destroy_wq;
2031 error = xfs_buf_init();
2033 goto out_mru_cache_uninit;
2035 error = xfs_init_procfs();
2037 goto out_buf_terminate;
2039 error = xfs_sysctl_register();
2041 goto out_cleanup_procfs;
2043 xfs_kset = kset_create_and_add("xfs", NULL, fs_kobj);
2046 goto out_sysctl_unregister;
2049 xfsstats.xs_kobj.kobject.kset = xfs_kset;
2051 xfsstats.xs_stats = alloc_percpu(struct xfsstats);
2052 if (!xfsstats.xs_stats) {
2054 goto out_kset_unregister;
2057 error = xfs_sysfs_init(&xfsstats.xs_kobj, &xfs_stats_ktype, NULL,
2060 goto out_free_stats;
2063 xfs_dbg_kobj.kobject.kset = xfs_kset;
2064 error = xfs_sysfs_init(&xfs_dbg_kobj, &xfs_dbg_ktype, NULL, "debug");
2066 goto out_remove_stats_kobj;
2069 error = xfs_qm_init();
2071 goto out_remove_dbg_kobj;
2073 error = register_filesystem(&xfs_fs_type);
2080 out_remove_dbg_kobj:
2082 xfs_sysfs_del(&xfs_dbg_kobj);
2083 out_remove_stats_kobj:
2085 xfs_sysfs_del(&xfsstats.xs_kobj);
2087 free_percpu(xfsstats.xs_stats);
2088 out_kset_unregister:
2089 kset_unregister(xfs_kset);
2090 out_sysctl_unregister:
2091 xfs_sysctl_unregister();
2093 xfs_cleanup_procfs();
2095 xfs_buf_terminate();
2096 out_mru_cache_uninit:
2097 xfs_mru_cache_uninit();
2099 xfs_destroy_workqueues();
2101 xfs_destroy_zones();
2110 unregister_filesystem(&xfs_fs_type);
2112 xfs_sysfs_del(&xfs_dbg_kobj);
2114 xfs_sysfs_del(&xfsstats.xs_kobj);
2115 free_percpu(xfsstats.xs_stats);
2116 kset_unregister(xfs_kset);
2117 xfs_sysctl_unregister();
2118 xfs_cleanup_procfs();
2119 xfs_buf_terminate();
2120 xfs_mru_cache_uninit();
2121 xfs_destroy_workqueues();
2122 xfs_destroy_zones();
2123 xfs_uuid_table_free();
2126 module_init(init_xfs_fs);
2127 module_exit(exit_xfs_fs);
2129 MODULE_AUTHOR("Silicon Graphics, Inc.");
2130 MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
2131 MODULE_LICENSE("GPL");