LCOV - code coverage report
Current view: top level - fs/xfs - xfs_super.c (source / functions) Hit Total Coverage
Test: fstests of 6.5.0-rc3-acha @ Mon Jul 31 20:08:06 PDT 2023 Lines: 897 1180 76.0 %
Date: 2023-07-31 20:08:07 Functions: 53 57 93.0 %

          Line data    Source code
       1             : // SPDX-License-Identifier: GPL-2.0
       2             : /*
       3             :  * Copyright (c) 2000-2006 Silicon Graphics, Inc.
       4             :  * All Rights Reserved.
       5             :  */
       6             : 
       7             : #include "xfs.h"
       8             : #include "xfs_shared.h"
       9             : #include "xfs_format.h"
      10             : #include "xfs_log_format.h"
      11             : #include "xfs_trans_resv.h"
      12             : #include "xfs_sb.h"
      13             : #include "xfs_mount.h"
      14             : #include "xfs_inode.h"
      15             : #include "xfs_btree.h"
      16             : #include "xfs_bmap.h"
      17             : #include "xfs_alloc.h"
      18             : #include "xfs_fsops.h"
      19             : #include "xfs_trans.h"
      20             : #include "xfs_buf_item.h"
      21             : #include "xfs_log.h"
      22             : #include "xfs_log_priv.h"
      23             : #include "xfs_dir2.h"
      24             : #include "xfs_extfree_item.h"
      25             : #include "xfs_mru_cache.h"
      26             : #include "xfs_inode_item.h"
      27             : #include "xfs_icache.h"
      28             : #include "xfs_trace.h"
      29             : #include "xfs_icreate_item.h"
      30             : #include "xfs_filestream.h"
      31             : #include "xfs_quota.h"
      32             : #include "xfs_sysfs.h"
      33             : #include "xfs_ondisk.h"
      34             : #include "xfs_rmap_item.h"
      35             : #include "xfs_refcount_item.h"
      36             : #include "xfs_bmap_item.h"
      37             : #include "xfs_reflink.h"
      38             : #include "xfs_pwork.h"
      39             : #include "xfs_ag.h"
      40             : #include "xfs_defer.h"
      41             : #include "xfs_attr_item.h"
      42             : #include "xfs_xattr.h"
      43             : #include "xfs_iunlink_item.h"
      44             : #include "xfs_dahash_test.h"
      45             : #include "xfs_swapext_item.h"
      46             : #include "xfs_parent.h"
      47             : #include "scrub/stats.h"
      48             : #include "scrub/rcbag_btree.h"
      49             : 
      50             : #include <linux/magic.h>
      51             : #include <linux/fs_context.h>
      52             : #include <linux/fs_parser.h>
      53             : 
      54             : static const struct super_operations xfs_super_operations;
      55             : 
      56             : static struct dentry *xfs_debugfs;      /* top-level xfs debugfs dir */
      57             : static struct kset *xfs_kset;           /* top-level xfs sysfs dir */
      58             : #ifdef DEBUG
      59             : static struct xfs_kobj xfs_dbg_kobj;    /* global debug sysfs attrs */
      60             : #endif
      61             : 
      62             : #ifdef CONFIG_HOTPLUG_CPU
      63             : static LIST_HEAD(xfs_mount_list);
      64             : static DEFINE_SPINLOCK(xfs_mount_list_lock);
      65             : 
      66       24157 : static inline void xfs_mount_list_add(struct xfs_mount *mp)
      67             : {
      68       24157 :         spin_lock(&xfs_mount_list_lock);
      69       24157 :         list_add(&mp->m_mount_list, &xfs_mount_list);
      70       24157 :         spin_unlock(&xfs_mount_list_lock);
      71       24157 : }
      72             : 
      73       24164 : static inline void xfs_mount_list_del(struct xfs_mount *mp)
      74             : {
      75       24164 :         spin_lock(&xfs_mount_list_lock);
      76       24164 :         list_del(&mp->m_mount_list);
      77       24164 :         spin_unlock(&xfs_mount_list_lock);
      78       24164 : }
      79             : #else /* !CONFIG_HOTPLUG_CPU */
      80             : static inline void xfs_mount_list_add(struct xfs_mount *mp) {}
      81             : static inline void xfs_mount_list_del(struct xfs_mount *mp) {}
      82             : #endif
      83             : 
      84             : enum xfs_dax_mode {
      85             :         XFS_DAX_INODE = 0,
      86             :         XFS_DAX_ALWAYS = 1,
      87             :         XFS_DAX_NEVER = 2,
      88             : };
      89             : 
      90             : static void
      91             : xfs_mount_set_dax_mode(
      92             :         struct xfs_mount        *mp,
      93             :         enum xfs_dax_mode       mode)
      94             : {
      95           0 :         switch (mode) {
      96             :         case XFS_DAX_INODE:
      97             :                 mp->m_features &= ~(XFS_FEAT_DAX_ALWAYS | XFS_FEAT_DAX_NEVER);
      98             :                 break;
      99             :         case XFS_DAX_ALWAYS:
     100             :                 mp->m_features |= XFS_FEAT_DAX_ALWAYS;
     101             :                 mp->m_features &= ~XFS_FEAT_DAX_NEVER;
     102             :                 break;
     103             :         case XFS_DAX_NEVER:
     104           0 :                 mp->m_features |= XFS_FEAT_DAX_NEVER;
     105           0 :                 mp->m_features &= ~XFS_FEAT_DAX_ALWAYS;
     106           0 :                 break;
     107             :         }
     108             : }
     109             : 
     110             : static const struct constant_table dax_param_enums[] = {
     111             :         {"inode",     XFS_DAX_INODE },
     112             :         {"always",    XFS_DAX_ALWAYS },
     113             :         {"never",     XFS_DAX_NEVER },
     114             :         {}
     115             : };
     116             : 
     117             : /*
     118             :  * Table driven mount option parser.
     119             :  */
     120             : enum {
     121             :         Opt_logbufs, Opt_logbsize, Opt_logdev, Opt_rtdev,
     122             :         Opt_wsync, Opt_noalign, Opt_swalloc, Opt_sunit, Opt_swidth, Opt_nouuid,
     123             :         Opt_grpid, Opt_nogrpid, Opt_bsdgroups, Opt_sysvgroups,
     124             :         Opt_allocsize, Opt_norecovery, Opt_inode64, Opt_inode32, Opt_ikeep,
     125             :         Opt_noikeep, Opt_largeio, Opt_nolargeio, Opt_attr2, Opt_noattr2,
     126             :         Opt_filestreams, Opt_quota, Opt_noquota, Opt_usrquota, Opt_grpquota,
     127             :         Opt_prjquota, Opt_uquota, Opt_gquota, Opt_pquota,
     128             :         Opt_uqnoenforce, Opt_gqnoenforce, Opt_pqnoenforce, Opt_qnoenforce,
     129             :         Opt_discard, Opt_nodiscard, Opt_dax, Opt_dax_enum,
     130             : };
     131             : 
     132             : static const struct fs_parameter_spec xfs_fs_parameters[] = {
     133             :         fsparam_u32("logbufs",                Opt_logbufs),
     134             :         fsparam_string("logbsize",    Opt_logbsize),
     135             :         fsparam_string("logdev",      Opt_logdev),
     136             :         fsparam_string("rtdev",               Opt_rtdev),
     137             :         fsparam_flag("wsync",         Opt_wsync),
     138             :         fsparam_flag("noalign",               Opt_noalign),
     139             :         fsparam_flag("swalloc",               Opt_swalloc),
     140             :         fsparam_u32("sunit",          Opt_sunit),
     141             :         fsparam_u32("swidth",         Opt_swidth),
     142             :         fsparam_flag("nouuid",                Opt_nouuid),
     143             :         fsparam_flag("grpid",         Opt_grpid),
     144             :         fsparam_flag("nogrpid",               Opt_nogrpid),
     145             :         fsparam_flag("bsdgroups",     Opt_bsdgroups),
     146             :         fsparam_flag("sysvgroups",    Opt_sysvgroups),
     147             :         fsparam_string("allocsize",   Opt_allocsize),
     148             :         fsparam_flag("norecovery",    Opt_norecovery),
     149             :         fsparam_flag("inode64",               Opt_inode64),
     150             :         fsparam_flag("inode32",               Opt_inode32),
     151             :         fsparam_flag("ikeep",         Opt_ikeep),
     152             :         fsparam_flag("noikeep",               Opt_noikeep),
     153             :         fsparam_flag("largeio",               Opt_largeio),
     154             :         fsparam_flag("nolargeio",     Opt_nolargeio),
     155             :         fsparam_flag("attr2",         Opt_attr2),
     156             :         fsparam_flag("noattr2",               Opt_noattr2),
     157             :         fsparam_flag("filestreams",   Opt_filestreams),
     158             :         fsparam_flag("quota",         Opt_quota),
     159             :         fsparam_flag("noquota",               Opt_noquota),
     160             :         fsparam_flag("usrquota",      Opt_usrquota),
     161             :         fsparam_flag("grpquota",      Opt_grpquota),
     162             :         fsparam_flag("prjquota",      Opt_prjquota),
     163             :         fsparam_flag("uquota",                Opt_uquota),
     164             :         fsparam_flag("gquota",                Opt_gquota),
     165             :         fsparam_flag("pquota",                Opt_pquota),
     166             :         fsparam_flag("uqnoenforce",   Opt_uqnoenforce),
     167             :         fsparam_flag("gqnoenforce",   Opt_gqnoenforce),
     168             :         fsparam_flag("pqnoenforce",   Opt_pqnoenforce),
     169             :         fsparam_flag("qnoenforce",    Opt_qnoenforce),
     170             :         fsparam_flag("discard",               Opt_discard),
     171             :         fsparam_flag("nodiscard",     Opt_nodiscard),
     172             :         fsparam_flag("dax",           Opt_dax),
     173             :         fsparam_enum("dax",           Opt_dax_enum, dax_param_enums),
     174             :         {}
     175             : };
     176             : 
     177             : struct proc_xfs_info {
     178             :         uint64_t        flag;
     179             :         char            *str;
     180             : };
     181             : 
     182             : static int
     183     5194422 : xfs_fs_show_options(
     184             :         struct seq_file         *m,
     185             :         struct dentry           *root)
     186             : {
     187     5194422 :         static struct proc_xfs_info xfs_info_set[] = {
     188             :                 /* the few simple ones we can get from the mount struct */
     189             :                 { XFS_FEAT_IKEEP,               ",ikeep" },
     190             :                 { XFS_FEAT_WSYNC,               ",wsync" },
     191             :                 { XFS_FEAT_NOALIGN,             ",noalign" },
     192             :                 { XFS_FEAT_SWALLOC,             ",swalloc" },
     193             :                 { XFS_FEAT_NOUUID,              ",nouuid" },
     194             :                 { XFS_FEAT_NORECOVERY,          ",norecovery" },
     195             :                 { XFS_FEAT_ATTR2,               ",attr2" },
     196             :                 { XFS_FEAT_FILESTREAMS,         ",filestreams" },
     197             :                 { XFS_FEAT_GRPID,               ",grpid" },
     198             :                 { XFS_FEAT_DISCARD,             ",discard" },
     199             :                 { XFS_FEAT_LARGE_IOSIZE,        ",largeio" },
     200             :                 { XFS_FEAT_DAX_ALWAYS,          ",dax=always" },
     201             :                 { XFS_FEAT_DAX_NEVER,           ",dax=never" },
     202             :                 { 0, NULL }
     203             :         };
     204     5194422 :         struct xfs_mount        *mp = XFS_M(root->d_sb);
     205     5194422 :         struct proc_xfs_info    *xfs_infop;
     206             : 
     207    72648751 :         for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
     208    67420209 :                 if (mp->m_features & xfs_infop->flag)
     209     5211938 :                         seq_puts(m, xfs_infop->str);
     210             :         }
     211             : 
     212    10459079 :         seq_printf(m, ",inode%d", xfs_has_small_inums(mp) ? 32 : 64);
     213             : 
     214     5199347 :         if (xfs_has_allocsize(mp))
     215          38 :                 seq_printf(m, ",allocsize=%dk",
     216          38 :                            (1 << mp->m_allocsize_log) >> 10);
     217             : 
     218     5199348 :         if (mp->m_logbufs > 0)
     219     5202642 :                 seq_printf(m, ",logbufs=%d", mp->m_logbufs);
     220     5191518 :         if (mp->m_logbsize > 0)
     221     5195073 :                 seq_printf(m, ",logbsize=%dk", mp->m_logbsize >> 10);
     222             : 
     223     5188003 :         if (mp->m_logname)
     224           5 :                 seq_show_option(m, "logdev", mp->m_logname);
     225     5194403 :         if (mp->m_rtname)
     226     1116270 :                 seq_show_option(m, "rtdev", mp->m_rtname);
     227             : 
     228     5194083 :         if (mp->m_dalign > 0)
     229        1101 :                 seq_printf(m, ",sunit=%d",
     230        1101 :                                 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
     231     5194078 :         if (mp->m_swidth > 0)
     232        1096 :                 seq_printf(m, ",swidth=%d",
     233        1096 :                                 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
     234             : 
     235     5194079 :         if (mp->m_qflags & XFS_UQUOTA_ENFD)
     236     4052988 :                 seq_puts(m, ",usrquota");
     237     1141091 :         else if (mp->m_qflags & XFS_UQUOTA_ACCT)
     238         397 :                 seq_puts(m, ",uqnoenforce");
     239             : 
     240     5194729 :         if (mp->m_qflags & XFS_PQUOTA_ENFD)
     241     4061199 :                 seq_puts(m, ",prjquota");
     242     1133551 :         else if (mp->m_qflags & XFS_PQUOTA_ACCT)
     243         365 :                 seq_puts(m, ",pqnoenforce");
     244             : 
     245     5231864 :         if (mp->m_qflags & XFS_GQUOTA_ENFD)
     246     4099758 :                 seq_puts(m, ",grpquota");
     247     1132120 :         else if (mp->m_qflags & XFS_GQUOTA_ACCT)
     248         406 :                 seq_puts(m, ",gqnoenforce");
     249             : 
     250     5226097 :         if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
     251     1138538 :                 seq_puts(m, ",noquota");
     252             : 
     253     5226113 :         return 0;
     254             : }
     255             : 
     256             : static bool
     257      179096 : xfs_set_inode_alloc_perag(
     258             :         struct xfs_perag        *pag,
     259             :         xfs_ino_t               ino,
     260             :         xfs_agnumber_t          max_metadata)
     261             : {
     262      358192 :         if (!xfs_is_inode32(pag->pag_mount)) {
     263      179096 :                 set_bit(XFS_AGSTATE_ALLOWS_INODES, &pag->pag_opstate);
     264      179096 :                 clear_bit(XFS_AGSTATE_PREFERS_METADATA, &pag->pag_opstate);
     265      179096 :                 return false;
     266             :         }
     267             : 
     268           0 :         if (ino > XFS_MAXINUMBER_32) {
     269           0 :                 clear_bit(XFS_AGSTATE_ALLOWS_INODES, &pag->pag_opstate);
     270           0 :                 clear_bit(XFS_AGSTATE_PREFERS_METADATA, &pag->pag_opstate);
     271           0 :                 return false;
     272             :         }
     273             : 
     274           0 :         set_bit(XFS_AGSTATE_ALLOWS_INODES, &pag->pag_opstate);
     275           0 :         if (pag->pag_agno < max_metadata)
     276           0 :                 set_bit(XFS_AGSTATE_PREFERS_METADATA, &pag->pag_opstate);
     277             :         else
     278           0 :                 clear_bit(XFS_AGSTATE_PREFERS_METADATA, &pag->pag_opstate);
     279             :         return true;
     280             : }
     281             : 
     282             : /*
     283             :  * Set parameters for inode allocation heuristics, taking into account
     284             :  * filesystem size and inode32/inode64 mount options; i.e. specifically
     285             :  * whether or not XFS_FEAT_SMALL_INUMS is set.
     286             :  *
     287             :  * Inode allocation patterns are altered only if inode32 is requested
     288             :  * (XFS_FEAT_SMALL_INUMS), and the filesystem is sufficiently large.
     289             :  * If altered, XFS_OPSTATE_INODE32 is set as well.
     290             :  *
     291             :  * An agcount independent of that in the mount structure is provided
     292             :  * because in the growfs case, mp->m_sb.sb_agcount is not yet updated
     293             :  * to the potentially higher ag count.
     294             :  *
     295             :  * Returns the maximum AG index which may contain inodes.
     296             :  */
     297             : xfs_agnumber_t
     298       35484 : xfs_set_inode_alloc(
     299             :         struct xfs_mount *mp,
     300             :         xfs_agnumber_t  agcount)
     301             : {
     302       35484 :         xfs_agnumber_t  index;
     303       35484 :         xfs_agnumber_t  maxagi = 0;
     304       35484 :         xfs_sb_t        *sbp = &mp->m_sb;
     305       35484 :         xfs_agnumber_t  max_metadata;
     306       35484 :         xfs_agino_t     agino;
     307       35484 :         xfs_ino_t       ino;
     308             : 
     309             :         /*
     310             :          * Calculate how much should be reserved for inodes to meet
     311             :          * the max inode percentage.  Used only for inode32.
     312             :          */
     313       35484 :         if (M_IGEO(mp)->maxicount) {
     314       35484 :                 uint64_t        icount;
     315             : 
     316       35484 :                 icount = sbp->sb_dblocks * sbp->sb_imax_pct;
     317       35484 :                 do_div(icount, 100);
     318       35484 :                 icount += sbp->sb_agblocks - 1;
     319       35484 :                 do_div(icount, sbp->sb_agblocks);
     320       35484 :                 max_metadata = icount;
     321             :         } else {
     322             :                 max_metadata = agcount;
     323             :         }
     324             : 
     325             :         /* Get the last possible inode in the filesystem */
     326       35484 :         agino = XFS_AGB_TO_AGINO(mp, sbp->sb_agblocks - 1);
     327       35484 :         ino = XFS_AGINO_TO_INO(mp, agcount - 1, agino);
     328             : 
     329             :         /*
     330             :          * If user asked for no more than 32-bit inodes, and the fs is
     331             :          * sufficiently large, set XFS_OPSTATE_INODE32 if we must alter
     332             :          * the allocator to accommodate the request.
     333             :          */
     334       35484 :         if (xfs_has_small_inums(mp) && ino > XFS_MAXINUMBER_32)
     335           0 :                 set_bit(XFS_OPSTATE_INODE32, &mp->m_opstate);
     336             :         else
     337       35484 :                 clear_bit(XFS_OPSTATE_INODE32, &mp->m_opstate);
     338             : 
     339      214580 :         for (index = 0; index < agcount; index++) {
     340      179096 :                 struct xfs_perag        *pag;
     341             : 
     342      179096 :                 ino = XFS_AGINO_TO_INO(mp, index, agino);
     343             : 
     344      179096 :                 pag = xfs_perag_get(mp, index);
     345      179096 :                 if (xfs_set_inode_alloc_perag(pag, ino, max_metadata))
     346           0 :                         maxagi++;
     347      179096 :                 xfs_perag_put(pag);
     348             :         }
     349             : 
     350       70968 :         return xfs_is_inode32(mp) ? maxagi : agcount;
     351             : }
     352             : 
     353             : static int
     354           0 : xfs_setup_dax_always(
     355             :         struct xfs_mount        *mp)
     356             : {
     357           0 :         if (!mp->m_ddev_targp->bt_daxdev &&
     358           0 :             (!mp->m_rtdev_targp || !mp->m_rtdev_targp->bt_daxdev)) {
     359           0 :                 xfs_alert(mp,
     360             :                         "DAX unsupported by block device. Turning off DAX.");
     361           0 :                 goto disable_dax;
     362             :         }
     363             : 
     364           0 :         if (mp->m_super->s_blocksize != PAGE_SIZE) {
     365           0 :                 xfs_alert(mp,
     366             :                         "DAX not supported for blocksize. Turning off DAX.");
     367           0 :                 goto disable_dax;
     368             :         }
     369             : 
     370           0 :         if (xfs_has_reflink(mp) &&
     371           0 :             bdev_is_partition(mp->m_ddev_targp->bt_bdev)) {
     372           0 :                 xfs_alert(mp,
     373             :                         "DAX and reflink cannot work with multi-partitions!");
     374           0 :                 return -EINVAL;
     375             :         }
     376             : 
     377           0 :         xfs_warn(mp, "DAX enabled. Warning: EXPERIMENTAL, use at your own risk");
     378           0 :         return 0;
     379             : 
     380           0 : disable_dax:
     381           0 :         xfs_mount_set_dax_mode(mp, XFS_DAX_NEVER);
     382           0 :         return 0;
     383             : }
     384             : 
     385             : static void
     386           0 : xfs_bdev_mark_dead(
     387             :         struct block_device     *bdev)
     388             : {
     389           0 :         xfs_force_shutdown(bdev->bd_holder, SHUTDOWN_DEVICE_REMOVED);
     390           0 : }
     391             : 
     392             : static const struct blk_holder_ops xfs_holder_ops = {
     393             :         .mark_dead              = xfs_bdev_mark_dead,
     394             : };
     395             : 
     396             : STATIC int
     397         185 : xfs_blkdev_get(
     398             :         xfs_mount_t             *mp,
     399             :         const char              *name,
     400             :         struct block_device     **bdevp)
     401             : {
     402         185 :         int                     error = 0;
     403             : 
     404         185 :         *bdevp = blkdev_get_by_path(name, BLK_OPEN_READ | BLK_OPEN_WRITE, mp,
     405             :                                     &xfs_holder_ops);
     406         185 :         if (IS_ERR(*bdevp)) {
     407           0 :                 error = PTR_ERR(*bdevp);
     408           0 :                 xfs_warn(mp, "Invalid device [%s], error=%d", name, error);
     409             :         }
     410             : 
     411         185 :         return error;
     412             : }
     413             : 
     414             : STATIC void
     415         187 : xfs_blkdev_put(
     416             :         struct xfs_mount        *mp,
     417             :         struct block_device     *bdev)
     418             : {
     419         187 :         if (bdev)
     420         187 :                 blkdev_put(bdev, mp);
     421         187 : }
     422             : 
     423             : STATIC void
     424       24164 : xfs_close_devices(
     425             :         struct xfs_mount        *mp)
     426             : {
     427       24164 :         if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
     428           4 :                 struct block_device *logdev = xfs_buftarg_bdev(mp->m_logdev_targp);
     429             : 
     430           4 :                 xfs_free_buftarg(mp->m_logdev_targp);
     431           4 :                 xfs_blkdev_put(mp, logdev);
     432             :         }
     433       24164 :         if (mp->m_rtdev_targp) {
     434         183 :                 struct block_device *rtdev = xfs_buftarg_bdev(mp->m_rtdev_targp);
     435             : 
     436         183 :                 xfs_free_buftarg(mp->m_rtdev_targp);
     437         183 :                 xfs_blkdev_put(mp, rtdev);
     438             :         }
     439       24164 :         xfs_free_buftarg(mp->m_ddev_targp);
     440       24164 : }
     441             : 
     442             : /*
     443             :  * The file system configurations are:
     444             :  *      (1) device (partition) with data and internal log
     445             :  *      (2) logical volume with data and log subvolumes.
     446             :  *      (3) logical volume with data, log, and realtime subvolumes.
     447             :  *
     448             :  * We only have to handle opening the log and realtime volumes here if
     449             :  * they are present.  The data subvolume has already been opened by
     450             :  * get_sb_bdev() and is stored in sb->s_bdev.
     451             :  */
     452             : STATIC int
     453       24157 : xfs_open_devices(
     454             :         struct xfs_mount        *mp)
     455             : {
     456       24157 :         struct block_device     *ddev = mp->m_super->s_bdev;
     457       24157 :         struct block_device     *logdev = NULL, *rtdev = NULL;
     458       24157 :         int                     error;
     459             : 
     460             :         /*
     461             :          * Open real time and log devices - order is important.
     462             :          */
     463       24157 :         if (mp->m_logname) {
     464           4 :                 error = xfs_blkdev_get(mp, mp->m_logname, &logdev);
     465           4 :                 if (error)
     466             :                         return error;
     467             :         }
     468             : 
     469       24157 :         if (mp->m_rtname) {
     470         181 :                 error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev);
     471         181 :                 if (error)
     472           0 :                         goto out_close_logdev;
     473             : 
     474         181 :                 if (rtdev == ddev || rtdev == logdev) {
     475           0 :                         xfs_warn(mp,
     476             :         "Cannot mount filesystem with identical rtdev and ddev/logdev.");
     477           0 :                         error = -EINVAL;
     478           0 :                         goto out_close_rtdev;
     479             :                 }
     480             :         }
     481             : 
     482             :         /*
     483             :          * Setup xfs_mount buffer target pointers
     484             :          */
     485       24157 :         error = -ENOMEM;
     486       24157 :         mp->m_ddev_targp = xfs_alloc_buftarg(mp, ddev);
     487       24157 :         if (!mp->m_ddev_targp)
     488           0 :                 goto out_close_rtdev;
     489             : 
     490       24157 :         if (rtdev) {
     491         181 :                 mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev);
     492         181 :                 if (!mp->m_rtdev_targp)
     493           0 :                         goto out_free_ddev_targ;
     494             :         }
     495             : 
     496       24157 :         if (logdev && logdev != ddev) {
     497           4 :                 mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev);
     498           4 :                 if (!mp->m_logdev_targp)
     499           0 :                         goto out_free_rtdev_targ;
     500             :         } else {
     501       24153 :                 mp->m_logdev_targp = mp->m_ddev_targp;
     502             :         }
     503             : 
     504             :         return 0;
     505             : 
     506             :  out_free_rtdev_targ:
     507           0 :         if (mp->m_rtdev_targp)
     508           0 :                 xfs_free_buftarg(mp->m_rtdev_targp);
     509           0 :  out_free_ddev_targ:
     510           0 :         xfs_free_buftarg(mp->m_ddev_targp);
     511           0 :  out_close_rtdev:
     512           0 :         xfs_blkdev_put(mp, rtdev);
     513           0 :  out_close_logdev:
     514           0 :         if (logdev && logdev != ddev)
     515           0 :                 xfs_blkdev_put(mp, logdev);
     516             :         return error;
     517             : }
     518             : 
     519             : /*
     520             :  * Setup xfs_mount buffer target pointers based on superblock
     521             :  */
     522             : STATIC int
     523       24129 : xfs_setup_devices(
     524             :         struct xfs_mount        *mp)
     525             : {
     526       24129 :         int                     error;
     527             : 
     528       24129 :         error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_sectsize);
     529       24129 :         if (error)
     530             :                 return error;
     531             : 
     532       24129 :         if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
     533           2 :                 unsigned int    log_sector_size = BBSIZE;
     534             : 
     535           2 :                 if (xfs_has_sector(mp))
     536           0 :                         log_sector_size = mp->m_sb.sb_logsectsize;
     537           2 :                 error = xfs_setsize_buftarg(mp->m_logdev_targp,
     538             :                                             log_sector_size);
     539           2 :                 if (error)
     540             :                         return error;
     541             :         }
     542       24129 :         if (mp->m_rtdev_targp) {
     543         181 :                 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
     544         181 :                                             mp->m_sb.sb_sectsize);
     545         181 :                 if (error)
     546           0 :                         return error;
     547             :         }
     548             : 
     549             :         return 0;
     550             : }
     551             : 
     552             : STATIC int
     553       24157 : xfs_init_mount_workqueues(
     554             :         struct xfs_mount        *mp)
     555             : {
     556       48314 :         mp->m_buf_workqueue = alloc_workqueue("xfs-buf/%s",
     557             :                         XFS_WQFLAGS(WQ_FREEZABLE | WQ_MEM_RECLAIM),
     558       24157 :                         1, mp->m_super->s_id);
     559       24157 :         if (!mp->m_buf_workqueue)
     560           0 :                 goto out;
     561             : 
     562       48314 :         mp->m_unwritten_workqueue = alloc_workqueue("xfs-conv/%s",
     563             :                         XFS_WQFLAGS(WQ_FREEZABLE | WQ_MEM_RECLAIM),
     564       24157 :                         0, mp->m_super->s_id);
     565       24157 :         if (!mp->m_unwritten_workqueue)
     566           0 :                 goto out_destroy_buf;
     567             : 
     568       48314 :         mp->m_reclaim_workqueue = alloc_workqueue("xfs-reclaim/%s",
     569             :                         XFS_WQFLAGS(WQ_FREEZABLE | WQ_MEM_RECLAIM),
     570       24157 :                         0, mp->m_super->s_id);
     571       24157 :         if (!mp->m_reclaim_workqueue)
     572           0 :                 goto out_destroy_unwritten;
     573             : 
     574       48314 :         mp->m_blockgc_wq = alloc_workqueue("xfs-blockgc/%s",
     575             :                         XFS_WQFLAGS(WQ_UNBOUND | WQ_FREEZABLE | WQ_MEM_RECLAIM),
     576       24157 :                         0, mp->m_super->s_id);
     577       24157 :         if (!mp->m_blockgc_wq)
     578           0 :                 goto out_destroy_reclaim;
     579             : 
     580       48314 :         mp->m_inodegc_wq = alloc_workqueue("xfs-inodegc/%s",
     581             :                         XFS_WQFLAGS(WQ_FREEZABLE | WQ_MEM_RECLAIM),
     582       24157 :                         1, mp->m_super->s_id);
     583       24157 :         if (!mp->m_inodegc_wq)
     584           0 :                 goto out_destroy_blockgc;
     585             : 
     586       48314 :         mp->m_sync_workqueue = alloc_workqueue("xfs-sync/%s",
     587       24157 :                         XFS_WQFLAGS(WQ_FREEZABLE), 0, mp->m_super->s_id);
     588       24157 :         if (!mp->m_sync_workqueue)
     589           0 :                 goto out_destroy_inodegc;
     590             : 
     591             :         return 0;
     592             : 
     593             : out_destroy_inodegc:
     594           0 :         destroy_workqueue(mp->m_inodegc_wq);
     595           0 : out_destroy_blockgc:
     596           0 :         destroy_workqueue(mp->m_blockgc_wq);
     597           0 : out_destroy_reclaim:
     598           0 :         destroy_workqueue(mp->m_reclaim_workqueue);
     599           0 : out_destroy_unwritten:
     600           0 :         destroy_workqueue(mp->m_unwritten_workqueue);
     601           0 : out_destroy_buf:
     602           0 :         destroy_workqueue(mp->m_buf_workqueue);
     603             : out:
     604             :         return -ENOMEM;
     605             : }
     606             : 
     607             : STATIC void
     608       24164 : xfs_destroy_mount_workqueues(
     609             :         struct xfs_mount        *mp)
     610             : {
     611       24164 :         destroy_workqueue(mp->m_sync_workqueue);
     612       24164 :         destroy_workqueue(mp->m_blockgc_wq);
     613       24164 :         destroy_workqueue(mp->m_inodegc_wq);
     614       24164 :         destroy_workqueue(mp->m_reclaim_workqueue);
     615       24164 :         destroy_workqueue(mp->m_unwritten_workqueue);
     616       24164 :         destroy_workqueue(mp->m_buf_workqueue);
     617       24164 : }
     618             : 
     619             : static void
     620      325985 : xfs_flush_inodes_worker(
     621             :         struct work_struct      *work)
     622             : {
     623      325985 :         struct xfs_mount        *mp = container_of(work, struct xfs_mount,
     624             :                                                    m_flush_inodes_work);
     625      325985 :         struct super_block      *sb = mp->m_super;
     626             : 
     627      325985 :         if (down_read_trylock(&sb->s_umount)) {
     628      325985 :                 sync_inodes_sb(sb);
     629      325985 :                 up_read(&sb->s_umount);
     630             :         }
     631      325985 : }
     632             : 
     633             : /*
     634             :  * Flush all dirty data to disk. Must not be called while holding an XFS_ILOCK
     635             :  * or a page lock. We use sync_inodes_sb() here to ensure we block while waiting
     636             :  * for IO to complete so that we effectively throttle multiple callers to the
     637             :  * rate at which IO is completing.
     638             :  */
     639             : void
     640      543959 : xfs_flush_inodes(
     641             :         struct xfs_mount        *mp)
     642             : {
     643             :         /*
     644             :          * If flush_work() returns true then that means we waited for a flush
     645             :          * which was already in progress.  Don't bother running another scan.
     646             :          */
     647      543959 :         if (flush_work(&mp->m_flush_inodes_work))
     648             :                 return;
     649             : 
     650      326420 :         queue_work(mp->m_sync_workqueue, &mp->m_flush_inodes_work);
     651      326433 :         flush_work(&mp->m_flush_inodes_work);
     652             : }
     653             : 
     654             : /* Catch misguided souls that try to use this interface on XFS */
     655             : STATIC struct inode *
     656           0 : xfs_fs_alloc_inode(
     657             :         struct super_block      *sb)
     658             : {
     659           0 :         BUG();
     660             :         return NULL;
     661             : }
     662             : 
     663             : /*
     664             :  * Now that the generic code is guaranteed not to be accessing
     665             :  * the linux inode, we can inactivate and reclaim the inode.
     666             :  */
     667             : STATIC void
     668  1055824206 : xfs_fs_destroy_inode(
     669             :         struct inode            *inode)
     670             : {
     671  1055824206 :         struct xfs_inode        *ip = XFS_I(inode);
     672             : 
     673  1055824206 :         trace_xfs_destroy_inode(ip);
     674             : 
     675  1055892304 :         ASSERT(!rwsem_is_locked(&inode->i_rwsem));
     676  1055892304 :         XFS_STATS_INC(ip->i_mount, vn_rele);
     677  1055892304 :         XFS_STATS_INC(ip->i_mount, vn_remove);
     678  1055892304 :         xfs_inode_mark_reclaimable(ip);
     679  1055863626 : }
     680             : 
     681             : static void
     682      977065 : xfs_fs_dirty_inode(
     683             :         struct inode                    *inode,
     684             :         int                             flags)
     685             : {
     686      977065 :         struct xfs_inode                *ip = XFS_I(inode);
     687      977065 :         struct xfs_mount                *mp = ip->i_mount;
     688      977065 :         struct xfs_trans                *tp;
     689             : 
     690      977065 :         if (!(inode->i_sb->s_flags & SB_LAZYTIME))
     691      977045 :                 return;
     692             : 
     693             :         /*
     694             :          * Only do the timestamp update if the inode is dirty (I_DIRTY_SYNC)
     695             :          * and has dirty timestamp (I_DIRTY_TIME). I_DIRTY_TIME can be passed
     696             :          * in flags possibly together with I_DIRTY_SYNC.
     697             :          */
     698          20 :         if ((flags & ~I_DIRTY_TIME) != I_DIRTY_SYNC || !(flags & I_DIRTY_TIME))
     699             :                 return;
     700             : 
     701          20 :         if (xfs_trans_alloc(mp, &M_RES(mp)->tr_fsyncts, 0, 0, 0, &tp))
     702             :                 return;
     703          20 :         xfs_ilock(ip, XFS_ILOCK_EXCL);
     704          20 :         xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
     705          20 :         xfs_trans_log_inode(tp, ip, XFS_ILOG_TIMESTAMP);
     706          20 :         xfs_trans_commit(tp);
     707             : }
     708             : 
     709             : /*
     710             :  * Slab object creation initialisation for the XFS inode.
     711             :  * This covers only the idempotent fields in the XFS inode;
     712             :  * all other fields need to be initialised on allocation
     713             :  * from the slab. This avoids the need to repeatedly initialise
     714             :  * fields in the xfs inode that left in the initialise state
     715             :  * when freeing the inode.
     716             :  */
     717             : STATIC void
     718   322656649 : xfs_fs_inode_init_once(
     719             :         void                    *inode)
     720             : {
     721   322656649 :         struct xfs_inode        *ip = inode;
     722             : 
     723   322656649 :         memset(ip, 0, sizeof(struct xfs_inode));
     724             : 
     725             :         /* vfs inode */
     726   322656649 :         inode_init_once(VFS_I(ip));
     727             : 
     728             :         /* xfs inode */
     729   322655288 :         atomic_set(&ip->i_pincount, 0);
     730   322655288 :         spin_lock_init(&ip->i_flags_lock);
     731             : 
     732   322652553 :         mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
     733             :                      "xfsino", ip->i_ino);
     734   322658236 : }
     735             : 
     736             : /*
     737             :  * We do an unlocked check for XFS_IDONTCACHE here because we are already
     738             :  * serialised against cache hits here via the inode->i_lock and igrab() in
     739             :  * xfs_iget_cache_hit(). Hence a lookup that might clear this flag will not be
     740             :  * racing with us, and it avoids needing to grab a spinlock here for every inode
     741             :  * we drop the final reference on.
     742             :  */
     743             : STATIC int
     744 42752877601 : xfs_fs_drop_inode(
     745             :         struct inode            *inode)
     746             : {
     747 42752877601 :         struct xfs_inode        *ip = XFS_I(inode);
     748             : 
     749             :         /*
     750             :          * If this unlinked inode is in the middle of recovery, don't
     751             :          * drop the inode just yet; log recovery will take care of
     752             :          * that.  See the comment for this inode flag.
     753             :          */
     754 42752877601 :         if (ip->i_flags & XFS_IRECOVERY) {
     755          34 :                 ASSERT(xlog_recovery_needed(ip->i_mount->m_log));
     756          17 :                 return 0;
     757             :         }
     758             : 
     759 42752877584 :         return generic_drop_inode(inode);
     760             : }
     761             : 
     762             : static void
     763       31926 : xfs_mount_free(
     764             :         struct xfs_mount        *mp)
     765             : {
     766       31926 :         debugfs_remove(mp->m_debugfs);
     767       31926 :         kfree(mp->m_rtname);
     768       31926 :         kfree(mp->m_logname);
     769       31926 :         kmem_free(mp);
     770       31926 : }
     771             : 
     772             : STATIC int
     773     4251243 : xfs_fs_sync_fs(
     774             :         struct super_block      *sb,
     775             :         int                     wait)
     776             : {
     777     4251243 :         struct xfs_mount        *mp = XFS_M(sb);
     778     4251243 :         int                     error;
     779             : 
     780     4251243 :         trace_xfs_fs_sync_fs(mp, __return_address);
     781             : 
     782             :         /*
     783             :          * Doing anything during the async pass would be counterproductive.
     784             :          */
     785     4251308 :         if (!wait)
     786             :                 return 0;
     787             : 
     788     2125599 :         error = xfs_log_force(mp, XFS_LOG_SYNC);
     789     2125166 :         if (error)
     790             :                 return error;
     791             : 
     792     2105884 :         if (laptop_mode) {
     793             :                 /*
     794             :                  * The disk must be active because we're syncing.
     795             :                  * We schedule log work now (now that the disk is
     796             :                  * active) instead of later (when it might not be).
     797             :                  */
     798           0 :                 flush_delayed_work(&mp->m_log->l_work);
     799             :         }
     800             : 
     801             :         /*
     802             :          * If we are called with page faults frozen out, it means we are about
     803             :          * to freeze the transaction subsystem. Take the opportunity to shut
     804             :          * down inodegc because once SB_FREEZE_FS is set it's too late to
     805             :          * prevent inactivation races with freeze. The fs doesn't get called
     806             :          * again by the freezing process until after SB_FREEZE_FS has been set,
     807             :          * so it's now or never.  Same logic applies to speculative allocation
     808             :          * garbage collection.
     809             :          *
     810             :          * We don't care if this is a normal syncfs call that does this or
     811             :          * freeze that does this - we can run this multiple times without issue
     812             :          * and we won't race with a restart because a restart can only occur
     813             :          * when the state is either SB_FREEZE_FS or SB_FREEZE_COMPLETE.
     814             :          */
     815     2105884 :         if (sb->s_writers.frozen == SB_FREEZE_PAGEFAULT) {
     816       36469 :                 xfs_inodegc_stop(mp);
     817       36469 :                 xfs_blockgc_stop(mp);
     818             :         }
     819             : 
     820             :         return 0;
     821             : }
     822             : 
     823             : STATIC int
     824     8927857 : xfs_fs_statfs(
     825             :         struct dentry           *dentry,
     826             :         struct kstatfs          *statp)
     827             : {
     828     8927857 :         struct xfs_mount        *mp = XFS_M(dentry->d_sb);
     829     8927857 :         xfs_sb_t                *sbp = &mp->m_sb;
     830     8927857 :         struct xfs_inode        *ip = XFS_I(d_inode(dentry));
     831     8927857 :         uint64_t                fakeinos, id;
     832     8927857 :         uint64_t                icount;
     833     8927857 :         uint64_t                ifree;
     834     8927857 :         uint64_t                fdblocks;
     835     8927857 :         xfs_extlen_t            lsize;
     836     8927857 :         int64_t                 ffree;
     837             : 
     838             :         /*
     839             :          * Expedite background inodegc but don't wait. We do not want to block
     840             :          * here waiting hours for a billion extent file to be truncated.
     841             :          */
     842     8927857 :         xfs_inodegc_push(mp);
     843             : 
     844     8899899 :         statp->f_type = XFS_SUPER_MAGIC;
     845     8899899 :         statp->f_namelen = MAXNAMELEN - 1;
     846             : 
     847     8899899 :         id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
     848     8899899 :         statp->f_fsid = u64_to_fsid(id);
     849             : 
     850     8899899 :         icount = percpu_counter_sum(&mp->m_icount);
     851     8981634 :         ifree = percpu_counter_sum(&mp->m_ifree);
     852     8981826 :         fdblocks = percpu_counter_sum(&mp->m_fdblocks);
     853             : 
     854     8981698 :         spin_lock(&mp->m_sb_lock);
     855     8981882 :         statp->f_bsize = sbp->sb_blocksize;
     856     8981882 :         lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
     857     8981882 :         statp->f_blocks = sbp->sb_dblocks - lsize;
     858     8981882 :         spin_unlock(&mp->m_sb_lock);
     859             : 
     860             :         /* make sure statp->f_bfree does not underflow */
     861     8976511 :         statp->f_bfree = max_t(int64_t, 0,
     862             :                                 fdblocks - xfs_fdblocks_unavailable(mp));
     863     8976511 :         statp->f_bavail = statp->f_bfree;
     864             : 
     865     8976511 :         fakeinos = XFS_FSB_TO_INO(mp, statp->f_bfree);
     866     8976511 :         statp->f_files = min(icount + fakeinos, (uint64_t)XFS_MAXINUMBER);
     867     8976511 :         if (M_IGEO(mp)->maxicount)
     868     8975348 :                 statp->f_files = min_t(typeof(statp->f_files),
     869             :                                         statp->f_files,
     870             :                                         M_IGEO(mp)->maxicount);
     871             : 
     872             :         /* If sb_icount overshot maxicount, report actual allocation */
     873     8976511 :         statp->f_files = max_t(typeof(statp->f_files),
     874             :                                         statp->f_files,
     875             :                                         sbp->sb_icount);
     876             : 
     877             :         /* make sure statp->f_ffree does not underflow */
     878     8976511 :         ffree = statp->f_files - (icount - ifree);
     879     8976511 :         statp->f_ffree = max_t(int64_t, ffree, 0);
     880             : 
     881             : 
     882     8976511 :         if ((ip->i_diflags & XFS_DIFLAG_PROJINHERIT) &&
     883         836 :             ((mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))) ==
     884             :                               (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))
     885         608 :                 xfs_qm_statvfs(ip, statp);
     886             : 
     887     8976511 :         if (XFS_IS_REALTIME_MOUNT(mp) &&
     888     1855860 :             (ip->i_diflags & (XFS_DIFLAG_RTINHERIT | XFS_DIFLAG_REALTIME))) {
     889     1855556 :                 s64     freertx;
     890             : 
     891     1855556 :                 statp->f_blocks = sbp->sb_rblocks;
     892     1855556 :                 freertx = percpu_counter_sum_positive(&mp->m_frextents);
     893     1855556 :                 statp->f_bavail = statp->f_bfree = freertx * sbp->sb_rextsize;
     894             :         }
     895             : 
     896     8976511 :         return 0;
     897             : }
     898             : 
     899             : STATIC void
     900       36820 : xfs_save_resvblks(struct xfs_mount *mp)
     901             : {
     902       36820 :         uint64_t resblks = 0;
     903             : 
     904       36820 :         mp->m_resblks_save = mp->m_resblks;
     905       36820 :         xfs_reserve_blocks(mp, &resblks, NULL);
     906       36820 : }
     907             : 
     908             : STATIC void
     909       36810 : xfs_restore_resvblks(struct xfs_mount *mp)
     910             : {
     911       36810 :         uint64_t resblks;
     912             : 
     913       36810 :         if (mp->m_resblks_save) {
     914       36806 :                 resblks = mp->m_resblks_save;
     915       36806 :                 mp->m_resblks_save = 0;
     916             :         } else
     917           4 :                 resblks = xfs_default_resblks(mp);
     918             : 
     919       36810 :         xfs_reserve_blocks(mp, &resblks, NULL);
     920       36810 : }
     921             : 
     922             : /*
     923             :  * Second stage of a freeze. The data is already frozen so we only
     924             :  * need to take care of the metadata. Once that's done sync the superblock
     925             :  * to the log to dirty it in case of a crash while frozen. This ensures that we
     926             :  * will recover the unlinked inode lists on the next mount.
     927             :  */
     928             : STATIC int
     929       36469 : xfs_fs_freeze(
     930             :         struct super_block      *sb)
     931             : {
     932       36469 :         struct xfs_mount        *mp = XFS_M(sb);
     933       36469 :         unsigned int            flags;
     934       36469 :         int                     ret;
     935             : 
     936             :         /*
     937             :          * The filesystem is now frozen far enough that memory reclaim
     938             :          * cannot safely operate on the filesystem. Hence we need to
     939             :          * set a GFP_NOFS context here to avoid recursion deadlocks.
     940             :          */
     941       36469 :         flags = memalloc_nofs_save();
     942       36469 :         xfs_save_resvblks(mp);
     943       36469 :         ret = xfs_log_quiesce(mp);
     944       36469 :         memalloc_nofs_restore(flags);
     945             : 
     946             :         /*
     947             :          * For read-write filesystems, we need to restart the inodegc on error
     948             :          * because we stopped it at SB_FREEZE_PAGEFAULT level and a thaw is not
     949             :          * going to be run to restart it now.  We are at SB_FREEZE_FS level
     950             :          * here, so we can restart safely without racing with a stop in
     951             :          * xfs_fs_sync_fs().
     952             :          */
     953       36469 :         if (ret && !xfs_is_readonly(mp)) {
     954           0 :                 xfs_blockgc_start(mp);
     955           0 :                 xfs_inodegc_start(mp);
     956             :         }
     957             : 
     958       36469 :         return ret;
     959             : }
     960             : 
     961             : STATIC int
     962       36469 : xfs_fs_unfreeze(
     963             :         struct super_block      *sb)
     964             : {
     965       36469 :         struct xfs_mount        *mp = XFS_M(sb);
     966             : 
     967       36469 :         xfs_restore_resvblks(mp);
     968       36469 :         xfs_log_work_queue(mp);
     969             : 
     970             :         /*
     971             :          * Don't reactivate the inodegc worker on a readonly filesystem because
     972             :          * inodes are sent directly to reclaim.  Don't reactivate the blockgc
     973             :          * worker because there are no speculative preallocations on a readonly
     974             :          * filesystem.
     975             :          */
     976       72938 :         if (!xfs_is_readonly(mp)) {
     977       36469 :                 xfs_blockgc_start(mp);
     978       36469 :                 xfs_inodegc_start(mp);
     979             :         }
     980             : 
     981       36469 :         return 0;
     982             : }
     983             : 
     984             : /*
     985             :  * This function fills in xfs_mount_t fields based on mount args.
     986             :  * Note: the superblock _has_ now been read in.
     987             :  */
     988             : STATIC int
     989       24141 : xfs_finish_flags(
     990             :         struct xfs_mount        *mp)
     991             : {
     992             :         /* Fail a mount where the logbuf is smaller than the log stripe */
     993       24141 :         if (xfs_has_logv2(mp)) {
     994       24131 :                 if (mp->m_logbsize <= 0 &&
     995       23983 :                     mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE) {
     996          58 :                         mp->m_logbsize = mp->m_sb.sb_logsunit;
     997       24073 :                 } else if (mp->m_logbsize > 0 &&
     998         148 :                            mp->m_logbsize < mp->m_sb.sb_logsunit) {
     999           0 :                         xfs_warn(mp,
    1000             :                 "logbuf size must be greater than or equal to log stripe size");
    1001           0 :                         return -EINVAL;
    1002             :                 }
    1003             :         } else {
    1004             :                 /* Fail a mount if the logbuf is larger than 32K */
    1005          10 :                 if (mp->m_logbsize > XLOG_BIG_RECORD_BSIZE) {
    1006           4 :                         xfs_warn(mp,
    1007             :                 "logbuf size for version 1 logs must be 16K or 32K");
    1008           4 :                         return -EINVAL;
    1009             :                 }
    1010             :         }
    1011             : 
    1012             :         /*
    1013             :          * V5 filesystems always use attr2 format for attributes.
    1014             :          */
    1015       24137 :         if (xfs_has_crc(mp) && xfs_has_noattr2(mp)) {
    1016           4 :                 xfs_warn(mp, "Cannot mount a V5 filesystem as noattr2. "
    1017             :                              "attr2 is always enabled for V5 filesystems.");
    1018           4 :                 return -EINVAL;
    1019             :         }
    1020             : 
    1021             :         /*
    1022             :          * prohibit r/w mounts of read-only filesystems
    1023             :          */
    1024       24133 :         if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !xfs_is_readonly(mp)) {
    1025           0 :                 xfs_warn(mp,
    1026             :                         "cannot mount a read-only filesystem as read-write");
    1027           0 :                 return -EROFS;
    1028             :         }
    1029             : 
    1030       24133 :         if ((mp->m_qflags & XFS_GQUOTA_ACCT) &&
    1031       21685 :             (mp->m_qflags & XFS_PQUOTA_ACCT) &&
    1032             :             !xfs_has_pquotino(mp)) {
    1033           4 :                 xfs_warn(mp,
    1034             :                   "Super block does not support project and group quota together");
    1035           4 :                 return -EINVAL;
    1036             :         }
    1037             : 
    1038             :         return 0;
    1039             : }
    1040             : 
    1041             : static int
    1042       24157 : xfs_init_percpu_counters(
    1043             :         struct xfs_mount        *mp)
    1044             : {
    1045       24157 :         int             error;
    1046             : 
    1047       24157 :         error = percpu_counter_init(&mp->m_icount, 0, GFP_KERNEL);
    1048       24157 :         if (error)
    1049             :                 return -ENOMEM;
    1050             : 
    1051       24157 :         error = percpu_counter_init(&mp->m_ifree, 0, GFP_KERNEL);
    1052       24157 :         if (error)
    1053           0 :                 goto free_icount;
    1054             : 
    1055       24157 :         error = percpu_counter_init(&mp->m_fdblocks, 0, GFP_KERNEL);
    1056       24157 :         if (error)
    1057           0 :                 goto free_ifree;
    1058             : 
    1059       24157 :         error = percpu_counter_init(&mp->m_delalloc_blks, 0, GFP_KERNEL);
    1060       24157 :         if (error)
    1061           0 :                 goto free_fdblocks;
    1062             : 
    1063       24157 :         error = percpu_counter_init(&mp->m_frextents, 0, GFP_KERNEL);
    1064       24157 :         if (error)
    1065           0 :                 goto free_delalloc;
    1066             : 
    1067             :         return 0;
    1068             : 
    1069             : free_delalloc:
    1070           0 :         percpu_counter_destroy(&mp->m_delalloc_blks);
    1071           0 : free_fdblocks:
    1072           0 :         percpu_counter_destroy(&mp->m_fdblocks);
    1073           0 : free_ifree:
    1074           0 :         percpu_counter_destroy(&mp->m_ifree);
    1075           0 : free_icount:
    1076           0 :         percpu_counter_destroy(&mp->m_icount);
    1077           0 :         return -ENOMEM;
    1078             : }
    1079             : 
    1080             : void
    1081       46721 : xfs_reinit_percpu_counters(
    1082             :         struct xfs_mount        *mp)
    1083             : {
    1084       46721 :         percpu_counter_set(&mp->m_icount, mp->m_sb.sb_icount);
    1085       46721 :         percpu_counter_set(&mp->m_ifree, mp->m_sb.sb_ifree);
    1086       46721 :         percpu_counter_set(&mp->m_fdblocks, mp->m_sb.sb_fdblocks);
    1087       46721 :         percpu_counter_set(&mp->m_frextents, mp->m_sb.sb_frextents);
    1088       46721 : }
    1089             : 
    1090             : static void
    1091       24164 : xfs_destroy_percpu_counters(
    1092             :         struct xfs_mount        *mp)
    1093             : {
    1094       24164 :         percpu_counter_destroy(&mp->m_icount);
    1095       24164 :         percpu_counter_destroy(&mp->m_ifree);
    1096       24164 :         percpu_counter_destroy(&mp->m_fdblocks);
    1097       48328 :         ASSERT(xfs_is_shutdown(mp) ||
    1098             :                percpu_counter_sum(&mp->m_delalloc_blks) == 0);
    1099       24164 :         percpu_counter_destroy(&mp->m_delalloc_blks);
    1100       24164 :         percpu_counter_destroy(&mp->m_frextents);
    1101       24164 : }
    1102             : 
    1103             : static int
    1104       24157 : xfs_inodegc_init_percpu(
    1105             :         struct xfs_mount        *mp)
    1106             : {
    1107       24157 :         struct xfs_inodegc      *gc;
    1108       24157 :         int                     cpu;
    1109             : 
    1110       24157 :         mp->m_inodegc = alloc_percpu(struct xfs_inodegc);
    1111       24157 :         if (!mp->m_inodegc)
    1112             :                 return -ENOMEM;
    1113             : 
    1114       72471 :         for_each_possible_cpu(cpu) {
    1115       48314 :                 gc = per_cpu_ptr(mp->m_inodegc, cpu);
    1116             : #if defined(DEBUG) || defined(XFS_WARN)
    1117       48314 :                 gc->cpu = cpu;
    1118             : #endif
    1119       48314 :                 init_llist_head(&gc->list);
    1120       48314 :                 gc->items = 0;
    1121       48314 :                 gc->error = 0;
    1122       48314 :                 INIT_DELAYED_WORK(&gc->work, xfs_inodegc_worker);
    1123             :         }
    1124             :         return 0;
    1125             : }
    1126             : 
    1127             : static void
    1128             : xfs_inodegc_free_percpu(
    1129             :         struct xfs_mount        *mp)
    1130             : {
    1131       24164 :         if (!mp->m_inodegc)
    1132             :                 return;
    1133       24164 :         free_percpu(mp->m_inodegc);
    1134             : }
    1135             : 
    1136             : static void
    1137       24082 : xfs_fs_put_super(
    1138             :         struct super_block      *sb)
    1139             : {
    1140       24082 :         struct xfs_mount        *mp = XFS_M(sb);
    1141             : 
    1142             :         /* if ->fill_super failed, we have no mount to tear down */
    1143       24082 :         if (!sb->s_fs_info)
    1144             :                 return;
    1145             : 
    1146       24082 :         xfs_notice(mp, "Unmounting Filesystem %pU", &mp->m_sb.sb_uuid);
    1147       24082 :         xfs_filestream_unmount(mp);
    1148       24082 :         xfs_unmountfs(mp);
    1149             : 
    1150       24082 :         xfs_freesb(mp);
    1151       24082 :         xchk_mount_stats_free(mp);
    1152       24082 :         free_percpu(mp->m_stats.xs_stats);
    1153       24082 :         xfs_mount_list_del(mp);
    1154       24082 :         xfs_inodegc_free_percpu(mp);
    1155       24082 :         xfs_destroy_percpu_counters(mp);
    1156       24082 :         xfs_destroy_mount_workqueues(mp);
    1157       24082 :         xfs_close_devices(mp);
    1158             : 
    1159       24082 :         sb->s_fs_info = NULL;
    1160       24082 :         xfs_mount_free(mp);
    1161             : }
    1162             : 
    1163             : static long
    1164      792836 : xfs_fs_nr_cached_objects(
    1165             :         struct super_block      *sb,
    1166             :         struct shrink_control   *sc)
    1167             : {
    1168             :         /* Paranoia: catch incorrect calls during mount setup or teardown */
    1169      792836 :         if (WARN_ON_ONCE(!sb->s_fs_info))
    1170             :                 return 0;
    1171      792836 :         return xfs_reclaim_inodes_count(XFS_M(sb));
    1172             : }
    1173             : 
    1174             : static long
    1175      409272 : xfs_fs_free_cached_objects(
    1176             :         struct super_block      *sb,
    1177             :         struct shrink_control   *sc)
    1178             : {
    1179      409272 :         return xfs_reclaim_inodes_nr(XFS_M(sb), sc->nr_to_scan);
    1180             : }
    1181             : 
    1182             : static void
    1183           0 : xfs_fs_shutdown(
    1184             :         struct super_block      *sb)
    1185             : {
    1186           0 :         xfs_force_shutdown(XFS_M(sb), SHUTDOWN_DEVICE_REMOVED);
    1187           0 : }
    1188             : 
    1189             : static const struct super_operations xfs_super_operations = {
    1190             :         .alloc_inode            = xfs_fs_alloc_inode,
    1191             :         .destroy_inode          = xfs_fs_destroy_inode,
    1192             :         .dirty_inode            = xfs_fs_dirty_inode,
    1193             :         .drop_inode             = xfs_fs_drop_inode,
    1194             :         .put_super              = xfs_fs_put_super,
    1195             :         .sync_fs                = xfs_fs_sync_fs,
    1196             :         .freeze_fs              = xfs_fs_freeze,
    1197             :         .unfreeze_fs            = xfs_fs_unfreeze,
    1198             :         .statfs                 = xfs_fs_statfs,
    1199             :         .show_options           = xfs_fs_show_options,
    1200             :         .nr_cached_objects      = xfs_fs_nr_cached_objects,
    1201             :         .free_cached_objects    = xfs_fs_free_cached_objects,
    1202             :         .shutdown               = xfs_fs_shutdown,
    1203             : };
    1204             : 
    1205             : static int
    1206         178 : suffix_kstrtoint(
    1207             :         const char      *s,
    1208             :         unsigned int    base,
    1209             :         int             *res)
    1210             : {
    1211         178 :         int             last, shift_left_factor = 0, _res;
    1212         178 :         char            *value;
    1213         178 :         int             ret = 0;
    1214             : 
    1215         178 :         value = kstrdup(s, GFP_KERNEL);
    1216         178 :         if (!value)
    1217             :                 return -ENOMEM;
    1218             : 
    1219         178 :         last = strlen(value) - 1;
    1220         178 :         if (value[last] == 'K' || value[last] == 'k') {
    1221         170 :                 shift_left_factor = 10;
    1222         170 :                 value[last] = '\0';
    1223             :         }
    1224         178 :         if (value[last] == 'M' || value[last] == 'm') {
    1225           0 :                 shift_left_factor = 20;
    1226           0 :                 value[last] = '\0';
    1227             :         }
    1228         178 :         if (value[last] == 'G' || value[last] == 'g') {
    1229           2 :                 shift_left_factor = 30;
    1230           2 :                 value[last] = '\0';
    1231             :         }
    1232             : 
    1233         178 :         if (kstrtoint(value, base, &_res))
    1234           0 :                 ret = -EINVAL;
    1235         178 :         kfree(value);
    1236         178 :         *res = _res << shift_left_factor;
    1237         178 :         return ret;
    1238             : }
    1239             : 
    1240             : static inline void
    1241          26 : xfs_fs_warn_deprecated(
    1242             :         struct fs_context       *fc,
    1243             :         struct fs_parameter     *param,
    1244             :         uint64_t                flag,
    1245             :         bool                    value)
    1246             : {
    1247             :         /* Don't print the warning if reconfiguring and current mount point
    1248             :          * already had the flag set
    1249             :          */
    1250          26 :         if ((fc->purpose & FS_CONTEXT_FOR_RECONFIGURE) &&
    1251          10 :             !!(XFS_M(fc->root->d_sb)->m_features & flag) == value)
    1252             :                 return;
    1253          20 :         xfs_warn(fc->s_fs_info, "%s mount option is deprecated.", param->key);
    1254             : }
    1255             : 
    1256             : /*
    1257             :  * Set mount state from a mount option.
    1258             :  *
    1259             :  * NOTE: mp->m_super is NULL here!
    1260             :  */
    1261             : static int
    1262      116729 : xfs_fs_parse_param(
    1263             :         struct fs_context       *fc,
    1264             :         struct fs_parameter     *param)
    1265             : {
    1266      116729 :         struct xfs_mount        *parsing_mp = fc->s_fs_info;
    1267      116729 :         struct fs_parse_result  result;
    1268      116729 :         int                     size = 0;
    1269      116729 :         int                     opt;
    1270             : 
    1271      116729 :         opt = fs_parse(fc, xfs_fs_parameters, param, &result);
    1272      116729 :         if (opt < 0)
    1273             :                 return opt;
    1274             : 
    1275       91901 :         switch (opt) {
    1276          10 :         case Opt_logbufs:
    1277          10 :                 parsing_mp->m_logbufs = result.uint_32;
    1278          10 :                 return 0;
    1279         168 :         case Opt_logbsize:
    1280         168 :                 if (suffix_kstrtoint(param->string, 10, &parsing_mp->m_logbsize))
    1281           0 :                         return -EINVAL;
    1282             :                 return 0;
    1283           4 :         case Opt_logdev:
    1284           4 :                 kfree(parsing_mp->m_logname);
    1285           4 :                 parsing_mp->m_logname = kstrdup(param->string, GFP_KERNEL);
    1286           4 :                 if (!parsing_mp->m_logname)
    1287           0 :                         return -ENOMEM;
    1288             :                 return 0;
    1289         788 :         case Opt_rtdev:
    1290         788 :                 kfree(parsing_mp->m_rtname);
    1291         788 :                 parsing_mp->m_rtname = kstrdup(param->string, GFP_KERNEL);
    1292         788 :                 if (!parsing_mp->m_rtname)
    1293           0 :                         return -ENOMEM;
    1294             :                 return 0;
    1295          10 :         case Opt_allocsize:
    1296          10 :                 if (suffix_kstrtoint(param->string, 10, &size))
    1297             :                         return -EINVAL;
    1298          10 :                 parsing_mp->m_allocsize_log = ffs(size) - 1;
    1299          10 :                 parsing_mp->m_features |= XFS_FEAT_ALLOCSIZE;
    1300          10 :                 return 0;
    1301           4 :         case Opt_grpid:
    1302             :         case Opt_bsdgroups:
    1303           4 :                 parsing_mp->m_features |= XFS_FEAT_GRPID;
    1304           4 :                 return 0;
    1305           4 :         case Opt_nogrpid:
    1306             :         case Opt_sysvgroups:
    1307           4 :                 parsing_mp->m_features &= ~XFS_FEAT_GRPID;
    1308           4 :                 return 0;
    1309           8 :         case Opt_wsync:
    1310           8 :                 parsing_mp->m_features |= XFS_FEAT_WSYNC;
    1311           8 :                 return 0;
    1312          14 :         case Opt_norecovery:
    1313          14 :                 parsing_mp->m_features |= XFS_FEAT_NORECOVERY;
    1314          14 :                 return 0;
    1315           2 :         case Opt_noalign:
    1316           2 :                 parsing_mp->m_features |= XFS_FEAT_NOALIGN;
    1317           2 :                 return 0;
    1318           2 :         case Opt_swalloc:
    1319           2 :                 parsing_mp->m_features |= XFS_FEAT_SWALLOC;
    1320           2 :                 return 0;
    1321          30 :         case Opt_sunit:
    1322          30 :                 parsing_mp->m_dalign = result.uint_32;
    1323          30 :                 return 0;
    1324          30 :         case Opt_swidth:
    1325          30 :                 parsing_mp->m_swidth = result.uint_32;
    1326          30 :                 return 0;
    1327           2 :         case Opt_inode32:
    1328           2 :                 parsing_mp->m_features |= XFS_FEAT_SMALL_INUMS;
    1329           2 :                 return 0;
    1330           6 :         case Opt_inode64:
    1331           6 :                 parsing_mp->m_features &= ~XFS_FEAT_SMALL_INUMS;
    1332           6 :                 return 0;
    1333           4 :         case Opt_nouuid:
    1334           4 :                 parsing_mp->m_features |= XFS_FEAT_NOUUID;
    1335           4 :                 return 0;
    1336           2 :         case Opt_largeio:
    1337           2 :                 parsing_mp->m_features |= XFS_FEAT_LARGE_IOSIZE;
    1338           2 :                 return 0;
    1339           2 :         case Opt_nolargeio:
    1340           2 :                 parsing_mp->m_features &= ~XFS_FEAT_LARGE_IOSIZE;
    1341           2 :                 return 0;
    1342          18 :         case Opt_filestreams:
    1343          18 :                 parsing_mp->m_features |= XFS_FEAT_FILESTREAMS;
    1344          18 :                 return 0;
    1345         450 :         case Opt_noquota:
    1346         450 :                 parsing_mp->m_qflags &= ~XFS_ALL_QUOTA_ACCT;
    1347         450 :                 parsing_mp->m_qflags &= ~XFS_ALL_QUOTA_ENFD;
    1348         450 :                 return 0;
    1349       29811 :         case Opt_quota:
    1350             :         case Opt_uquota:
    1351             :         case Opt_usrquota:
    1352       29811 :                 parsing_mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ENFD);
    1353       29811 :                 return 0;
    1354         462 :         case Opt_qnoenforce:
    1355             :         case Opt_uqnoenforce:
    1356         462 :                 parsing_mp->m_qflags |= XFS_UQUOTA_ACCT;
    1357         462 :                 parsing_mp->m_qflags &= ~XFS_UQUOTA_ENFD;
    1358         462 :                 return 0;
    1359       29497 :         case Opt_pquota:
    1360             :         case Opt_prjquota:
    1361       29497 :                 parsing_mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ENFD);
    1362       29497 :                 return 0;
    1363         430 :         case Opt_pqnoenforce:
    1364         430 :                 parsing_mp->m_qflags |= XFS_PQUOTA_ACCT;
    1365         430 :                 parsing_mp->m_qflags &= ~XFS_PQUOTA_ENFD;
    1366         430 :                 return 0;
    1367       29609 :         case Opt_gquota:
    1368             :         case Opt_grpquota:
    1369       29609 :                 parsing_mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ENFD);
    1370       29609 :                 return 0;
    1371         480 :         case Opt_gqnoenforce:
    1372         480 :                 parsing_mp->m_qflags |= XFS_GQUOTA_ACCT;
    1373         480 :                 parsing_mp->m_qflags &= ~XFS_GQUOTA_ENFD;
    1374         480 :                 return 0;
    1375           4 :         case Opt_discard:
    1376           4 :                 parsing_mp->m_features |= XFS_FEAT_DISCARD;
    1377           4 :                 return 0;
    1378           2 :         case Opt_nodiscard:
    1379           2 :                 parsing_mp->m_features &= ~XFS_FEAT_DISCARD;
    1380           2 :                 return 0;
    1381             : #ifdef CONFIG_FS_DAX
    1382             :         case Opt_dax:
    1383             :                 xfs_mount_set_dax_mode(parsing_mp, XFS_DAX_ALWAYS);
    1384             :                 return 0;
    1385             :         case Opt_dax_enum:
    1386             :                 xfs_mount_set_dax_mode(parsing_mp, result.uint_32);
    1387             :                 return 0;
    1388             : #endif
    1389             :         /* Following mount options will be removed in September 2025 */
    1390           4 :         case Opt_ikeep:
    1391           4 :                 xfs_fs_warn_deprecated(fc, param, XFS_FEAT_IKEEP, true);
    1392           4 :                 parsing_mp->m_features |= XFS_FEAT_IKEEP;
    1393           4 :                 return 0;
    1394           4 :         case Opt_noikeep:
    1395           4 :                 xfs_fs_warn_deprecated(fc, param, XFS_FEAT_IKEEP, false);
    1396           4 :                 parsing_mp->m_features &= ~XFS_FEAT_IKEEP;
    1397           4 :                 return 0;
    1398          10 :         case Opt_attr2:
    1399          10 :                 xfs_fs_warn_deprecated(fc, param, XFS_FEAT_ATTR2, true);
    1400          10 :                 parsing_mp->m_features |= XFS_FEAT_ATTR2;
    1401          10 :                 return 0;
    1402           8 :         case Opt_noattr2:
    1403           8 :                 xfs_fs_warn_deprecated(fc, param, XFS_FEAT_NOATTR2, true);
    1404           8 :                 parsing_mp->m_features |= XFS_FEAT_NOATTR2;
    1405           8 :                 return 0;
    1406          22 :         default:
    1407          22 :                 xfs_warn(parsing_mp, "unknown mount option [%s].", param->key);
    1408          22 :                 return -EINVAL;
    1409             :         }
    1410             : 
    1411             :         return 0;
    1412             : }
    1413             : 
    1414             : static int
    1415       24896 : xfs_fs_validate_params(
    1416             :         struct xfs_mount        *mp)
    1417             : {
    1418             :         /* No recovery flag requires a read-only mount */
    1419       24908 :         if (xfs_has_norecovery(mp) && !xfs_is_readonly(mp)) {
    1420           2 :                 xfs_warn(mp, "no-recovery mounts must be read-only.");
    1421           2 :                 return -EINVAL;
    1422             :         }
    1423             : 
    1424             :         /*
    1425             :          * We have not read the superblock at this point, so only the attr2
    1426             :          * mount option can set the attr2 feature by this stage.
    1427             :          */
    1428       24894 :         if (xfs_has_attr2(mp) && xfs_has_noattr2(mp)) {
    1429           0 :                 xfs_warn(mp, "attr2 and noattr2 cannot both be specified.");
    1430           0 :                 return -EINVAL;
    1431             :         }
    1432             : 
    1433             : 
    1434       24894 :         if (xfs_has_noalign(mp) && (mp->m_dalign || mp->m_swidth)) {
    1435           0 :                 xfs_warn(mp,
    1436             :         "sunit and swidth options incompatible with the noalign option");
    1437           0 :                 return -EINVAL;
    1438             :         }
    1439             : 
    1440       24894 :         if (!IS_ENABLED(CONFIG_XFS_QUOTA) && mp->m_qflags != 0) {
    1441             :                 xfs_warn(mp, "quota support not available in this kernel.");
    1442             :                 return -EINVAL;
    1443             :         }
    1444             : 
    1445       24894 :         if ((mp->m_dalign && !mp->m_swidth) ||
    1446       24872 :             (!mp->m_dalign && mp->m_swidth)) {
    1447           0 :                 xfs_warn(mp, "sunit and swidth must be specified together");
    1448           0 :                 return -EINVAL;
    1449             :         }
    1450             : 
    1451       24894 :         if (mp->m_dalign && (mp->m_swidth % mp->m_dalign != 0)) {
    1452           0 :                 xfs_warn(mp,
    1453             :         "stripe width (%d) must be a multiple of the stripe unit (%d)",
    1454             :                         mp->m_swidth, mp->m_dalign);
    1455           0 :                 return -EINVAL;
    1456             :         }
    1457             : 
    1458       24894 :         if (mp->m_logbufs != -1 &&
    1459          10 :             mp->m_logbufs != 0 &&
    1460          10 :             (mp->m_logbufs < XLOG_MIN_ICLOGS ||
    1461             :              mp->m_logbufs > XLOG_MAX_ICLOGS)) {
    1462           4 :                 xfs_warn(mp, "invalid logbufs value: %d [not %d-%d]",
    1463             :                         mp->m_logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
    1464           4 :                 return -EINVAL;
    1465             :         }
    1466             : 
    1467       24890 :         if (mp->m_logbsize != -1 &&
    1468         164 :             mp->m_logbsize !=  0 &&
    1469         164 :             (mp->m_logbsize < XLOG_MIN_RECORD_BSIZE ||
    1470         160 :              mp->m_logbsize > XLOG_MAX_RECORD_BSIZE ||
    1471         160 :              !is_power_of_2(mp->m_logbsize))) {
    1472           4 :                 xfs_warn(mp,
    1473             :                         "invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
    1474             :                         mp->m_logbsize);
    1475           4 :                 return -EINVAL;
    1476             :         }
    1477             : 
    1478       24886 :         if (xfs_has_allocsize(mp) &&
    1479          10 :             (mp->m_allocsize_log > XFS_MAX_IO_LOG ||
    1480             :              mp->m_allocsize_log < XFS_MIN_IO_LOG)) {
    1481           4 :                 xfs_warn(mp, "invalid log iosize: %d [not %d-%d]",
    1482             :                         mp->m_allocsize_log, XFS_MIN_IO_LOG, XFS_MAX_IO_LOG);
    1483           4 :                 return -EINVAL;
    1484             :         }
    1485             : 
    1486             :         return 0;
    1487             : }
    1488             : 
    1489             : struct dentry *
    1490       24131 : xfs_debugfs_mkdir(
    1491             :         const char      *name,
    1492             :         struct dentry   *parent)
    1493             : {
    1494       48300 :         struct dentry   *child;
    1495             : 
    1496             :         /* Apparently we're expected to ignore error returns?? */
    1497       24131 :         child = debugfs_create_dir(name, parent);
    1498       48300 :         if (IS_ERR(child))
    1499           0 :                 return NULL;
    1500             : 
    1501             :         return child;
    1502             : }
    1503             : 
    1504             : static int
    1505       24171 : xfs_fs_fill_super(
    1506             :         struct super_block      *sb,
    1507             :         struct fs_context       *fc)
    1508             : {
    1509       24171 :         struct xfs_mount        *mp = sb->s_fs_info;
    1510       24171 :         struct inode            *root;
    1511       24171 :         int                     flags = 0, error;
    1512             : 
    1513       24171 :         mp->m_super = sb;
    1514             : 
    1515       24171 :         error = xfs_fs_validate_params(mp);
    1516       24171 :         if (error)
    1517          14 :                 goto out_free_names;
    1518             : 
    1519       24157 :         sb_min_blocksize(sb, BBSIZE);
    1520       24157 :         sb->s_xattr = xfs_xattr_handlers;
    1521       24157 :         sb->s_export_op = &xfs_export_operations;
    1522             : #ifdef CONFIG_XFS_QUOTA
    1523       24157 :         sb->s_qcop = &xfs_quotactl_operations;
    1524       24157 :         sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ;
    1525             : #endif
    1526       24157 :         sb->s_op = &xfs_super_operations;
    1527             : 
    1528             :         /*
    1529             :          * Delay mount work if the debug hook is set. This is debug
    1530             :          * instrumention to coordinate simulation of xfs mount failures with
    1531             :          * VFS superblock operations
    1532             :          */
    1533       24157 :         if (xfs_globals.mount_delay) {
    1534           2 :                 xfs_notice(mp, "Delaying mount for %d seconds.",
    1535             :                         xfs_globals.mount_delay);
    1536           2 :                 msleep(xfs_globals.mount_delay * 1000);
    1537             :         }
    1538             : 
    1539       24157 :         if (fc->sb_flags & SB_SILENT)
    1540           0 :                 flags |= XFS_MFSI_QUIET;
    1541             : 
    1542       24157 :         error = xfs_open_devices(mp);
    1543       24157 :         if (error)
    1544           0 :                 goto out_free_names;
    1545             : 
    1546       24157 :         if (xfs_debugfs) {
    1547       48314 :                 mp->m_debugfs = xfs_debugfs_mkdir(mp->m_super->s_id,
    1548             :                                                   xfs_debugfs);
    1549             :         } else {
    1550           0 :                 mp->m_debugfs = NULL;
    1551             :         }
    1552             : 
    1553       24157 :         error = xfs_init_mount_workqueues(mp);
    1554       24157 :         if (error)
    1555           0 :                 goto out_close_devices;
    1556             : 
    1557       24157 :         error = xfs_init_percpu_counters(mp);
    1558       24157 :         if (error)
    1559           0 :                 goto out_destroy_workqueues;
    1560             : 
    1561       24157 :         error = xfs_inodegc_init_percpu(mp);
    1562       24157 :         if (error)
    1563           0 :                 goto out_destroy_counters;
    1564             : 
    1565             :         /*
    1566             :          * All percpu data structures requiring cleanup when a cpu goes offline
    1567             :          * must be allocated before adding this @mp to the cpu-dead handler's
    1568             :          * mount list.
    1569             :          */
    1570       24157 :         xfs_mount_list_add(mp);
    1571             : 
    1572             :         /* Allocate stats memory before we do operations that might use it */
    1573       24157 :         mp->m_stats.xs_stats = alloc_percpu(struct xfsstats);
    1574       24157 :         if (!mp->m_stats.xs_stats) {
    1575           0 :                 error = -ENOMEM;
    1576           0 :                 goto out_destroy_inodegc;
    1577             :         }
    1578             : 
    1579       24157 :         error = xchk_mount_stats_alloc(mp);
    1580       24157 :         if (error)
    1581           0 :                 goto out_free_stats;
    1582             : 
    1583       24157 :         error = xfs_readsb(mp, flags);
    1584       24157 :         if (error)
    1585          16 :                 goto out_free_scrub_stats;
    1586             : 
    1587       24141 :         error = xfs_finish_flags(mp);
    1588       24141 :         if (error)
    1589          12 :                 goto out_free_sb;
    1590             : 
    1591       24129 :         error = xfs_setup_devices(mp);
    1592       24129 :         if (error)
    1593           0 :                 goto out_free_sb;
    1594             : 
    1595             :         /* V4 support is undergoing deprecation. */
    1596       24129 :         if (!xfs_has_crc(mp)) {
    1597             : #ifdef CONFIG_XFS_SUPPORT_V4
    1598          44 :                 xfs_warn_once(mp,
    1599             :         "Deprecated V4 format (crc=0) will not be supported after September 2030.");
    1600             : #else
    1601             :                 xfs_warn(mp,
    1602             :         "Deprecated V4 format (crc=0) not supported by kernel.");
    1603             :                 error = -EINVAL;
    1604             :                 goto out_free_sb;
    1605             : #endif
    1606             :         }
    1607             : 
    1608             :         /* ASCII case insensitivity is undergoing deprecation. */
    1609       24129 :         if (xfs_has_asciici(mp)) {
    1610             : #ifdef CONFIG_XFS_SUPPORT_ASCII_CI
    1611          26 :                 xfs_warn_once(mp,
    1612             :         "Deprecated ASCII case-insensitivity feature (ascii-ci=1) will not be supported after September 2030.");
    1613             : #else
    1614             :                 xfs_warn(mp,
    1615             :         "Deprecated ASCII case-insensitivity feature (ascii-ci=1) not supported by kernel.");
    1616             :                 error = -EINVAL;
    1617             :                 goto out_free_sb;
    1618             : #endif
    1619             :         }
    1620             : 
    1621             :         /* Filesystem claims it needs repair, so refuse the mount. */
    1622       24129 :         if (xfs_has_needsrepair(mp)) {
    1623           4 :                 xfs_warn(mp, "Filesystem needs repair.  Please run xfs_repair.");
    1624           4 :                 error = -EFSCORRUPTED;
    1625           4 :                 goto out_free_sb;
    1626             :         }
    1627             : 
    1628             :         /*
    1629             :          * Don't touch the filesystem if a user tool thinks it owns the primary
    1630             :          * superblock.  mkfs doesn't clear the flag from secondary supers, so
    1631             :          * we don't check them at all.
    1632             :          */
    1633       24125 :         if (mp->m_sb.sb_inprogress) {
    1634           0 :                 xfs_warn(mp, "Offline file system operation in progress!");
    1635           0 :                 error = -EFSCORRUPTED;
    1636           0 :                 goto out_free_sb;
    1637             :         }
    1638             : 
    1639             :         /*
    1640             :          * Until this is fixed only page-sized or smaller data blocks work.
    1641             :          */
    1642       24125 :         if (mp->m_sb.sb_blocksize > PAGE_SIZE) {
    1643           0 :                 xfs_warn(mp,
    1644             :                 "File system with blocksize %d bytes. "
    1645             :                 "Only pagesize (%ld) or less will currently work.",
    1646             :                                 mp->m_sb.sb_blocksize, PAGE_SIZE);
    1647           0 :                 error = -ENOSYS;
    1648           0 :                 goto out_free_sb;
    1649             :         }
    1650             : 
    1651             :         /* Ensure this filesystem fits in the page cache limits */
    1652       48250 :         if (xfs_sb_validate_fsb_count(&mp->m_sb, mp->m_sb.sb_dblocks) ||
    1653       24125 :             xfs_sb_validate_fsb_count(&mp->m_sb, mp->m_sb.sb_rblocks)) {
    1654           0 :                 xfs_warn(mp,
    1655             :                 "file system too large to be mounted on this system.");
    1656           0 :                 error = -EFBIG;
    1657           0 :                 goto out_free_sb;
    1658             :         }
    1659             : 
    1660             :         /*
    1661             :          * XFS block mappings use 54 bits to store the logical block offset.
    1662             :          * This should suffice to handle the maximum file size that the VFS
    1663             :          * supports (currently 2^63 bytes on 64-bit and ULONG_MAX << PAGE_SHIFT
    1664             :          * bytes on 32-bit), but as XFS and VFS have gotten the s_maxbytes
    1665             :          * calculation wrong on 32-bit kernels in the past, we'll add a WARN_ON
    1666             :          * to check this assertion.
    1667             :          *
    1668             :          * Avoid integer overflow by comparing the maximum bmbt offset to the
    1669             :          * maximum pagecache offset in units of fs blocks.
    1670             :          */
    1671       24125 :         if (!xfs_verify_fileoff(mp, XFS_B_TO_FSBT(mp, MAX_LFS_FILESIZE))) {
    1672           0 :                 xfs_warn(mp,
    1673             : "MAX_LFS_FILESIZE block offset (%llu) exceeds extent map maximum (%llu)!",
    1674             :                          XFS_B_TO_FSBT(mp, MAX_LFS_FILESIZE),
    1675             :                          XFS_MAX_FILEOFF);
    1676           0 :                 error = -EINVAL;
    1677           0 :                 goto out_free_sb;
    1678             :         }
    1679             : 
    1680       24125 :         error = xfs_filestream_mount(mp);
    1681       24125 :         if (error)
    1682           0 :                 goto out_free_sb;
    1683             : 
    1684             :         /*
    1685             :          * we must configure the block size in the superblock before we run the
    1686             :          * full mount process as the mount process can lookup and cache inodes.
    1687             :          */
    1688       24125 :         sb->s_magic = XFS_SUPER_MAGIC;
    1689       24125 :         sb->s_blocksize = mp->m_sb.sb_blocksize;
    1690       24125 :         sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
    1691       24125 :         sb->s_maxbytes = MAX_LFS_FILESIZE;
    1692       24125 :         sb->s_max_links = XFS_MAXLINK;
    1693       24125 :         sb->s_time_gran = 1;
    1694       24125 :         if (xfs_has_bigtime(mp)) {
    1695       24046 :                 sb->s_time_min = xfs_bigtime_to_unix(XFS_BIGTIME_TIME_MIN);
    1696       24046 :                 sb->s_time_max = xfs_bigtime_to_unix(XFS_BIGTIME_TIME_MAX);
    1697             :         } else {
    1698          79 :                 sb->s_time_min = XFS_LEGACY_TIME_MIN;
    1699          79 :                 sb->s_time_max = XFS_LEGACY_TIME_MAX;
    1700             :         }
    1701       24125 :         trace_xfs_inode_timestamp_range(mp, sb->s_time_min, sb->s_time_max);
    1702       24125 :         sb->s_iflags |= SB_I_CGROUPWB;
    1703             : 
    1704       24125 :         set_posix_acl_flag(sb);
    1705             : 
    1706             :         /* version 5 superblocks support inode version counters. */
    1707       24125 :         if (xfs_has_crc(mp))
    1708       24081 :                 sb->s_flags |= SB_I_VERSION;
    1709             : 
    1710       24125 :         if (xfs_has_dax_always(mp)) {
    1711           0 :                 error = xfs_setup_dax_always(mp);
    1712           0 :                 if (error)
    1713           0 :                         goto out_filestream_unmount;
    1714             :         }
    1715             : 
    1716       24125 :         if (xfs_has_discard(mp) && !bdev_max_discard_sectors(sb->s_bdev)) {
    1717           0 :                 xfs_warn(mp,
    1718             :         "mounting with \"discard\" option, but the device does not support discard");
    1719           0 :                 mp->m_features &= ~XFS_FEAT_DISCARD;
    1720             :         }
    1721             : 
    1722       24125 :         if (xfs_has_reflink(mp)) {
    1723       23867 :                 if (mp->m_sb.sb_rblocks) {
    1724           0 :                         xfs_alert(mp,
    1725             :         "reflink not compatible with realtime device!");
    1726           0 :                         error = -EINVAL;
    1727           0 :                         goto out_filestream_unmount;
    1728             :                 }
    1729             : 
    1730       23867 :                 if (xfs_globals.always_cow) {
    1731           0 :                         xfs_info(mp, "using DEBUG-only always_cow mode.");
    1732           0 :                         mp->m_always_cow = true;
    1733             :                 }
    1734             :         }
    1735             : 
    1736       24125 :         if (xfs_has_rmapbt(mp) && mp->m_sb.sb_rblocks) {
    1737           0 :                 xfs_alert(mp,
    1738             :         "reverse mapping btree not compatible with realtime device!");
    1739           0 :                 error = -EINVAL;
    1740           0 :                 goto out_filestream_unmount;
    1741             :         }
    1742             : 
    1743       24125 :         if (xfs_has_parent(mp))
    1744       23567 :                 xfs_warn(mp,
    1745             :         "EXPERIMENTAL parent pointer feature enabled. Use at your own risk!");
    1746             : 
    1747       24125 :         error = xfs_mountfs(mp);
    1748       24125 :         if (error)
    1749          50 :                 goto out_filestream_unmount;
    1750             : 
    1751       24075 :         root = igrab(VFS_I(mp->m_rootip));
    1752       24075 :         if (!root) {
    1753           0 :                 error = -ENOENT;
    1754           0 :                 goto out_unmount;
    1755             :         }
    1756       24075 :         sb->s_root = d_make_root(root);
    1757       24075 :         if (!sb->s_root) {
    1758           0 :                 error = -ENOMEM;
    1759           0 :                 goto out_unmount;
    1760             :         }
    1761             : 
    1762             :         return 0;
    1763             : 
    1764          50 :  out_filestream_unmount:
    1765          50 :         xfs_filestream_unmount(mp);
    1766          66 :  out_free_sb:
    1767          66 :         xfs_freesb(mp);
    1768          82 :  out_free_scrub_stats:
    1769          82 :         xchk_mount_stats_free(mp);
    1770          82 :  out_free_stats:
    1771          82 :         free_percpu(mp->m_stats.xs_stats);
    1772          82 :  out_destroy_inodegc:
    1773          82 :         xfs_mount_list_del(mp);
    1774          82 :         xfs_inodegc_free_percpu(mp);
    1775          82 :  out_destroy_counters:
    1776          82 :         xfs_destroy_percpu_counters(mp);
    1777          82 :  out_destroy_workqueues:
    1778          82 :         xfs_destroy_mount_workqueues(mp);
    1779          82 :  out_close_devices:
    1780          82 :         xfs_close_devices(mp);
    1781          96 :  out_free_names:
    1782          96 :         sb->s_fs_info = NULL;
    1783          96 :         xfs_mount_free(mp);
    1784          96 :         return error;
    1785             : 
    1786           0 :  out_unmount:
    1787           0 :         xfs_filestream_unmount(mp);
    1788           0 :         xfs_unmountfs(mp);
    1789           0 :         goto out_free_sb;
    1790             : }
    1791             : 
    1792             : static int
    1793       24792 : xfs_fs_get_tree(
    1794             :         struct fs_context       *fc)
    1795             : {
    1796       24792 :         return get_tree_bdev(fc, xfs_fs_fill_super);
    1797             : }
    1798             : 
    1799             : static int
    1800         345 : xfs_remount_rw(
    1801             :         struct xfs_mount        *mp)
    1802             : {
    1803         345 :         struct xfs_sb           *sbp = &mp->m_sb;
    1804         345 :         int error;
    1805             : 
    1806         345 :         if (xfs_has_norecovery(mp)) {
    1807           2 :                 xfs_warn(mp,
    1808             :                         "ro->rw transition prohibited on norecovery mount");
    1809           2 :                 return -EINVAL;
    1810             :         }
    1811             : 
    1812         343 :         if (xfs_sb_is_v5(sbp) &&
    1813             :             xfs_sb_has_ro_compat_feature(sbp, XFS_SB_FEAT_RO_COMPAT_UNKNOWN)) {
    1814           2 :                 xfs_warn(mp,
    1815             :         "ro->rw transition prohibited on unknown (0x%x) ro-compat filesystem",
    1816             :                         (sbp->sb_features_ro_compat &
    1817             :                                 XFS_SB_FEAT_RO_COMPAT_UNKNOWN));
    1818           2 :                 return -EINVAL;
    1819             :         }
    1820             : 
    1821         341 :         clear_bit(XFS_OPSTATE_READONLY, &mp->m_opstate);
    1822             : 
    1823             :         /*
    1824             :          * If this is the first remount to writeable state we might have some
    1825             :          * superblock changes to update.
    1826             :          */
    1827         341 :         if (mp->m_update_sb) {
    1828           2 :                 error = xfs_sync_sb(mp, false);
    1829           2 :                 if (error) {
    1830           0 :                         xfs_warn(mp, "failed to write sb changes");
    1831           0 :                         return error;
    1832             :                 }
    1833           2 :                 mp->m_update_sb = false;
    1834             :         }
    1835             : 
    1836             :         /*
    1837             :          * Fill out the reserve pool if it is empty. Use the stashed value if
    1838             :          * it is non-zero, otherwise go with the default.
    1839             :          */
    1840         341 :         xfs_restore_resvblks(mp);
    1841         341 :         xfs_log_work_queue(mp);
    1842         341 :         xfs_blockgc_start(mp);
    1843             : 
    1844             :         /* Create the per-AG metadata reservation pool .*/
    1845         341 :         error = xfs_fs_reserve_ag_blocks(mp);
    1846         341 :         if (error && error != -ENOSPC)
    1847             :                 return error;
    1848             : 
    1849             :         /* Re-enable the background inode inactivation worker. */
    1850         341 :         xfs_inodegc_start(mp);
    1851             : 
    1852         341 :         return 0;
    1853             : }
    1854             : 
    1855             : static int
    1856         351 : xfs_remount_ro(
    1857             :         struct xfs_mount        *mp)
    1858             : {
    1859         351 :         struct xfs_icwalk       icw = {
    1860             :                 .icw_flags      = XFS_ICWALK_FLAG_SYNC,
    1861             :         };
    1862         351 :         int                     error;
    1863             : 
    1864             :         /* Flush all the dirty data to disk. */
    1865         351 :         error = sync_filesystem(mp->m_super);
    1866         351 :         if (error)
    1867             :                 return error;
    1868             : 
    1869             :         /*
    1870             :          * Cancel background eofb scanning so it cannot race with the final
    1871             :          * log force+buftarg wait and deadlock the remount.
    1872             :          */
    1873         351 :         xfs_blockgc_stop(mp);
    1874             : 
    1875             :         /*
    1876             :          * Clear out all remaining COW staging extents and speculative post-EOF
    1877             :          * preallocations so that we don't leave inodes requiring inactivation
    1878             :          * cleanups during reclaim on a read-only mount.  We must process every
    1879             :          * cached inode, so this requires a synchronous cache scan.
    1880             :          */
    1881         351 :         error = xfs_blockgc_free_space(mp, &icw);
    1882         351 :         if (error) {
    1883           0 :                 xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
    1884           0 :                 return error;
    1885             :         }
    1886             : 
    1887             :         /*
    1888             :          * Stop the inodegc background worker.  xfs_fs_reconfigure already
    1889             :          * flushed all pending inodegc work when it sync'd the filesystem.
    1890             :          * The VFS holds s_umount, so we know that inodes cannot enter
    1891             :          * xfs_fs_destroy_inode during a remount operation.  In readonly mode
    1892             :          * we send inodes straight to reclaim, so no inodes will be queued.
    1893             :          */
    1894         351 :         xfs_inodegc_stop(mp);
    1895             : 
    1896             :         /* Free the per-AG metadata reservation pool. */
    1897         351 :         error = xfs_fs_unreserve_ag_blocks(mp);
    1898         351 :         if (error) {
    1899           0 :                 xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
    1900           0 :                 return error;
    1901             :         }
    1902             : 
    1903             :         /*
    1904             :          * Before we sync the metadata, we need to free up the reserve block
    1905             :          * pool so that the used block count in the superblock on disk is
    1906             :          * correct at the end of the remount. Stash the current* reserve pool
    1907             :          * size so that if we get remounted rw, we can return it to the same
    1908             :          * size.
    1909             :          */
    1910         351 :         xfs_save_resvblks(mp);
    1911             : 
    1912         351 :         xfs_log_clean(mp);
    1913         351 :         set_bit(XFS_OPSTATE_READONLY, &mp->m_opstate);
    1914             : 
    1915             :         return 0;
    1916             : }
    1917             : 
    1918             : /*
    1919             :  * Logically we would return an error here to prevent users from believing
    1920             :  * they might have changed mount options using remount which can't be changed.
    1921             :  *
    1922             :  * But unfortunately mount(8) adds all options from mtab and fstab to the mount
    1923             :  * arguments in some cases so we can't blindly reject options, but have to
    1924             :  * check for each specified option if it actually differs from the currently
    1925             :  * set option and only reject it if that's the case.
    1926             :  *
    1927             :  * Until that is implemented we return success for every remount request, and
    1928             :  * silently ignore all options that we can't actually change.
    1929             :  */
    1930             : static int
    1931         725 : xfs_fs_reconfigure(
    1932             :         struct fs_context *fc)
    1933             : {
    1934         725 :         struct xfs_mount        *mp = XFS_M(fc->root->d_sb);
    1935         725 :         struct xfs_mount        *new_mp = fc->s_fs_info;
    1936         725 :         int                     flags = fc->sb_flags;
    1937         725 :         int                     error;
    1938             : 
    1939             :         /* version 5 superblocks always support version counters. */
    1940         725 :         if (xfs_has_crc(mp))
    1941         723 :                 fc->sb_flags |= SB_I_VERSION;
    1942             : 
    1943         725 :         error = xfs_fs_validate_params(new_mp);
    1944         725 :         if (error)
    1945             :                 return error;
    1946             : 
    1947             :         /* inode32 -> inode64 */
    1948         725 :         if (xfs_has_small_inums(mp) && !xfs_has_small_inums(new_mp)) {
    1949           0 :                 mp->m_features &= ~XFS_FEAT_SMALL_INUMS;
    1950           0 :                 mp->m_maxagi = xfs_set_inode_alloc(mp, mp->m_sb.sb_agcount);
    1951             :         }
    1952             : 
    1953             :         /* inode64 -> inode32 */
    1954         725 :         if (!xfs_has_small_inums(mp) && xfs_has_small_inums(new_mp)) {
    1955           0 :                 mp->m_features |= XFS_FEAT_SMALL_INUMS;
    1956           0 :                 mp->m_maxagi = xfs_set_inode_alloc(mp, mp->m_sb.sb_agcount);
    1957             :         }
    1958             : 
    1959             :         /* ro -> rw */
    1960        1450 :         if (xfs_is_readonly(mp) && !(flags & SB_RDONLY)) {
    1961         345 :                 error = xfs_remount_rw(mp);
    1962         345 :                 if (error)
    1963             :                         return error;
    1964             :         }
    1965             : 
    1966             :         /* rw -> ro */
    1967        1442 :         if (!xfs_is_readonly(mp) && (flags & SB_RDONLY)) {
    1968         351 :                 error = xfs_remount_ro(mp);
    1969         351 :                 if (error)
    1970           0 :                         return error;
    1971             :         }
    1972             : 
    1973             :         return 0;
    1974             : }
    1975             : 
    1976       31919 : static void xfs_fs_free(
    1977             :         struct fs_context       *fc)
    1978             : {
    1979       31919 :         struct xfs_mount        *mp = fc->s_fs_info;
    1980             : 
    1981             :         /*
    1982             :          * mp is stored in the fs_context when it is initialized.
    1983             :          * mp is transferred to the superblock on a successful mount,
    1984             :          * but if an error occurs before the transfer we have to free
    1985             :          * it here.
    1986             :          */
    1987       31919 :         if (mp)
    1988        7748 :                 xfs_mount_free(mp);
    1989       31919 : }
    1990             : 
    1991             : static const struct fs_context_operations xfs_context_ops = {
    1992             :         .parse_param = xfs_fs_parse_param,
    1993             :         .get_tree    = xfs_fs_get_tree,
    1994             :         .reconfigure = xfs_fs_reconfigure,
    1995             :         .free        = xfs_fs_free,
    1996             : };
    1997             : 
    1998       31919 : static int xfs_init_fs_context(
    1999             :         struct fs_context       *fc)
    2000             : {
    2001       31919 :         struct xfs_mount        *mp;
    2002             : 
    2003       31919 :         mp = kmem_alloc(sizeof(struct xfs_mount), KM_ZERO);
    2004       31919 :         if (!mp)
    2005             :                 return -ENOMEM;
    2006             : 
    2007       31919 :         spin_lock_init(&mp->m_sb_lock);
    2008       31919 :         INIT_RADIX_TREE(&mp->m_perag_tree, GFP_ATOMIC);
    2009       31919 :         spin_lock_init(&mp->m_perag_lock);
    2010       31919 :         mutex_init(&mp->m_growlock);
    2011       31919 :         INIT_WORK(&mp->m_flush_inodes_work, xfs_flush_inodes_worker);
    2012       31919 :         INIT_DELAYED_WORK(&mp->m_reclaim_work, xfs_reclaim_worker);
    2013       31919 :         mp->m_kobj.kobject.kset = xfs_kset;
    2014             :         /*
    2015             :          * We don't create the finobt per-ag space reservation until after log
    2016             :          * recovery, so we must set this to true so that an ifree transaction
    2017             :          * started during log recovery will not depend on space reservations
    2018             :          * for finobt expansion.
    2019             :          */
    2020       31919 :         mp->m_finobt_nores = true;
    2021             : 
    2022             :         /*
    2023             :          * These can be overridden by the mount option parsing.
    2024             :          */
    2025       31919 :         mp->m_logbufs = -1;
    2026       31919 :         mp->m_logbsize = -1;
    2027       31919 :         mp->m_allocsize_log = 16; /* 64k */
    2028             : 
    2029       31919 :         xfs_hooks_init(&mp->m_dir_update_hooks);
    2030             : 
    2031             :         /*
    2032             :          * Copy binary VFS mount flags we are interested in.
    2033             :          */
    2034       31919 :         if (fc->sb_flags & SB_RDONLY)
    2035        8910 :                 set_bit(XFS_OPSTATE_READONLY, &mp->m_opstate);
    2036       31919 :         if (fc->sb_flags & SB_DIRSYNC)
    2037           0 :                 mp->m_features |= XFS_FEAT_DIRSYNC;
    2038       31919 :         if (fc->sb_flags & SB_SYNCHRONOUS)
    2039          64 :                 mp->m_features |= XFS_FEAT_WSYNC;
    2040             : 
    2041       31919 :         fc->s_fs_info = mp;
    2042       31919 :         fc->ops = &xfs_context_ops;
    2043             : 
    2044       31919 :         return 0;
    2045             : }
    2046             : 
    2047             : static struct file_system_type xfs_fs_type = {
    2048             :         .owner                  = THIS_MODULE,
    2049             :         .name                   = "xfs",
    2050             :         .init_fs_context        = xfs_init_fs_context,
    2051             :         .parameters             = xfs_fs_parameters,
    2052             :         .kill_sb                = kill_block_super,
    2053             :         .fs_flags               = FS_REQUIRES_DEV | FS_ALLOW_IDMAP,
    2054             : };
    2055             : MODULE_ALIAS_FS("xfs");
    2056             : 
    2057             : STATIC int __init
    2058          12 : xfs_init_caches(void)
    2059             : {
    2060          12 :         int             error;
    2061             : 
    2062          12 :         xfs_buf_cache = kmem_cache_create("xfs_buf", sizeof(struct xfs_buf), 0,
    2063             :                                          SLAB_HWCACHE_ALIGN |
    2064             :                                          SLAB_RECLAIM_ACCOUNT |
    2065             :                                          SLAB_MEM_SPREAD,
    2066             :                                          NULL);
    2067          12 :         if (!xfs_buf_cache)
    2068           0 :                 goto out;
    2069             : 
    2070          12 :         xfs_log_ticket_cache = kmem_cache_create("xfs_log_ticket",
    2071             :                                                 sizeof(struct xlog_ticket),
    2072             :                                                 0, 0, NULL);
    2073          12 :         if (!xfs_log_ticket_cache)
    2074           0 :                 goto out_destroy_buf_cache;
    2075             : 
    2076          12 :         error = xfs_btree_init_cur_caches();
    2077          12 :         if (error)
    2078           0 :                 goto out_destroy_log_ticket_cache;
    2079             : 
    2080          12 :         error = rcbagbt_init_cur_cache();
    2081          12 :         if (error)
    2082           0 :                 goto out_destroy_btree_cur_cache;
    2083             : 
    2084          12 :         error = xfs_defer_init_item_caches();
    2085          12 :         if (error)
    2086           0 :                 goto out_destroy_rcbagbt_cur_cache;
    2087             : 
    2088          12 :         xfs_da_state_cache = kmem_cache_create("xfs_da_state",
    2089             :                                               sizeof(struct xfs_da_state),
    2090             :                                               0, 0, NULL);
    2091          12 :         if (!xfs_da_state_cache)
    2092           0 :                 goto out_destroy_defer_item_cache;
    2093             : 
    2094          12 :         xfs_ifork_cache = kmem_cache_create("xfs_ifork",
    2095             :                                            sizeof(struct xfs_ifork),
    2096             :                                            0, 0, NULL);
    2097          12 :         if (!xfs_ifork_cache)
    2098           0 :                 goto out_destroy_da_state_cache;
    2099             : 
    2100          12 :         xfs_trans_cache = kmem_cache_create("xfs_trans",
    2101             :                                            sizeof(struct xfs_trans),
    2102             :                                            0, 0, NULL);
    2103          12 :         if (!xfs_trans_cache)
    2104           0 :                 goto out_destroy_ifork_cache;
    2105             : 
    2106             : 
    2107             :         /*
    2108             :          * The size of the cache-allocated buf log item is the maximum
    2109             :          * size possible under XFS.  This wastes a little bit of memory,
    2110             :          * but it is much faster.
    2111             :          */
    2112          12 :         xfs_buf_item_cache = kmem_cache_create("xfs_buf_item",
    2113             :                                               sizeof(struct xfs_buf_log_item),
    2114             :                                               0, 0, NULL);
    2115          12 :         if (!xfs_buf_item_cache)
    2116           0 :                 goto out_destroy_trans_cache;
    2117             : 
    2118          12 :         xfs_efd_cache = kmem_cache_create("xfs_efd_item",
    2119             :                         xfs_efd_log_item_sizeof(XFS_EFD_MAX_FAST_EXTENTS),
    2120             :                         0, 0, NULL);
    2121          12 :         if (!xfs_efd_cache)
    2122           0 :                 goto out_destroy_buf_item_cache;
    2123             : 
    2124          12 :         xfs_efi_cache = kmem_cache_create("xfs_efi_item",
    2125             :                         xfs_efi_log_item_sizeof(XFS_EFI_MAX_FAST_EXTENTS),
    2126             :                         0, 0, NULL);
    2127          12 :         if (!xfs_efi_cache)
    2128           0 :                 goto out_destroy_efd_cache;
    2129             : 
    2130          12 :         xfs_inode_cache = kmem_cache_create("xfs_inode",
    2131             :                                            sizeof(struct xfs_inode), 0,
    2132             :                                            (SLAB_HWCACHE_ALIGN |
    2133             :                                             SLAB_RECLAIM_ACCOUNT |
    2134             :                                             SLAB_MEM_SPREAD | SLAB_ACCOUNT),
    2135             :                                            xfs_fs_inode_init_once);
    2136          12 :         if (!xfs_inode_cache)
    2137           0 :                 goto out_destroy_efi_cache;
    2138             : 
    2139          12 :         xfs_ili_cache = kmem_cache_create("xfs_ili",
    2140             :                                          sizeof(struct xfs_inode_log_item), 0,
    2141             :                                          SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD,
    2142             :                                          NULL);
    2143          12 :         if (!xfs_ili_cache)
    2144           0 :                 goto out_destroy_inode_cache;
    2145             : 
    2146          12 :         xfs_icreate_cache = kmem_cache_create("xfs_icr",
    2147             :                                              sizeof(struct xfs_icreate_item),
    2148             :                                              0, 0, NULL);
    2149          12 :         if (!xfs_icreate_cache)
    2150           0 :                 goto out_destroy_ili_cache;
    2151             : 
    2152          12 :         xfs_rud_cache = kmem_cache_create("xfs_rud_item",
    2153             :                                          sizeof(struct xfs_rud_log_item),
    2154             :                                          0, 0, NULL);
    2155          12 :         if (!xfs_rud_cache)
    2156           0 :                 goto out_destroy_icreate_cache;
    2157             : 
    2158          12 :         xfs_rui_cache = kmem_cache_create("xfs_rui_item",
    2159             :                         xfs_rui_log_item_sizeof(XFS_RUI_MAX_FAST_EXTENTS),
    2160             :                         0, 0, NULL);
    2161          12 :         if (!xfs_rui_cache)
    2162           0 :                 goto out_destroy_rud_cache;
    2163             : 
    2164          12 :         xfs_cud_cache = kmem_cache_create("xfs_cud_item",
    2165             :                                          sizeof(struct xfs_cud_log_item),
    2166             :                                          0, 0, NULL);
    2167          12 :         if (!xfs_cud_cache)
    2168           0 :                 goto out_destroy_rui_cache;
    2169             : 
    2170          12 :         xfs_cui_cache = kmem_cache_create("xfs_cui_item",
    2171             :                         xfs_cui_log_item_sizeof(XFS_CUI_MAX_FAST_EXTENTS),
    2172             :                         0, 0, NULL);
    2173          12 :         if (!xfs_cui_cache)
    2174           0 :                 goto out_destroy_cud_cache;
    2175             : 
    2176          12 :         xfs_bud_cache = kmem_cache_create("xfs_bud_item",
    2177             :                                          sizeof(struct xfs_bud_log_item),
    2178             :                                          0, 0, NULL);
    2179          12 :         if (!xfs_bud_cache)
    2180           0 :                 goto out_destroy_cui_cache;
    2181             : 
    2182          12 :         xfs_bui_cache = kmem_cache_create("xfs_bui_item",
    2183             :                         xfs_bui_log_item_sizeof(XFS_BUI_MAX_FAST_EXTENTS),
    2184             :                         0, 0, NULL);
    2185          12 :         if (!xfs_bui_cache)
    2186           0 :                 goto out_destroy_bud_cache;
    2187             : 
    2188          12 :         xfs_attrd_cache = kmem_cache_create("xfs_attrd_item",
    2189             :                                             sizeof(struct xfs_attrd_log_item),
    2190             :                                             0, 0, NULL);
    2191          12 :         if (!xfs_attrd_cache)
    2192           0 :                 goto out_destroy_bui_cache;
    2193             : 
    2194          12 :         xfs_attri_cache = kmem_cache_create("xfs_attri_item",
    2195             :                                             sizeof(struct xfs_attri_log_item),
    2196             :                                             0, 0, NULL);
    2197          12 :         if (!xfs_attri_cache)
    2198           0 :                 goto out_destroy_attrd_cache;
    2199             : 
    2200          12 :         xfs_iunlink_cache = kmem_cache_create("xfs_iul_item",
    2201             :                                              sizeof(struct xfs_iunlink_item),
    2202             :                                              0, 0, NULL);
    2203          12 :         if (!xfs_iunlink_cache)
    2204           0 :                 goto out_destroy_attri_cache;
    2205             : 
    2206          12 :         xfs_sxd_cache = kmem_cache_create("xfs_sxd_item",
    2207             :                                          sizeof(struct xfs_sxd_log_item),
    2208             :                                          0, 0, NULL);
    2209          12 :         if (!xfs_sxd_cache)
    2210           0 :                 goto out_destroy_iul_cache;
    2211             : 
    2212          12 :         xfs_sxi_cache = kmem_cache_create("xfs_sxi_item",
    2213             :                                          sizeof(struct xfs_sxi_log_item),
    2214             :                                          0, 0, NULL);
    2215          12 :         if (!xfs_sxi_cache)
    2216           0 :                 goto out_destroy_sxd_cache;
    2217             : 
    2218          12 :         xfs_parent_intent_cache = kmem_cache_create("xfs_parent_intent",
    2219             :                                              sizeof(struct xfs_parent_defer),
    2220             :                                              0, 0, NULL);
    2221          12 :         if (!xfs_parent_intent_cache)
    2222           0 :                 goto out_destroy_sxi_cache;
    2223             : 
    2224             :         return 0;
    2225             : 
    2226             :  out_destroy_sxi_cache:
    2227           0 :         kmem_cache_destroy(xfs_sxi_cache);
    2228           0 :  out_destroy_sxd_cache:
    2229           0 :         kmem_cache_destroy(xfs_sxd_cache);
    2230           0 :  out_destroy_iul_cache:
    2231           0 :         kmem_cache_destroy(xfs_iunlink_cache);
    2232           0 :  out_destroy_attri_cache:
    2233           0 :         kmem_cache_destroy(xfs_attri_cache);
    2234           0 :  out_destroy_attrd_cache:
    2235           0 :         kmem_cache_destroy(xfs_attrd_cache);
    2236           0 :  out_destroy_bui_cache:
    2237           0 :         kmem_cache_destroy(xfs_bui_cache);
    2238           0 :  out_destroy_bud_cache:
    2239           0 :         kmem_cache_destroy(xfs_bud_cache);
    2240           0 :  out_destroy_cui_cache:
    2241           0 :         kmem_cache_destroy(xfs_cui_cache);
    2242           0 :  out_destroy_cud_cache:
    2243           0 :         kmem_cache_destroy(xfs_cud_cache);
    2244           0 :  out_destroy_rui_cache:
    2245           0 :         kmem_cache_destroy(xfs_rui_cache);
    2246           0 :  out_destroy_rud_cache:
    2247           0 :         kmem_cache_destroy(xfs_rud_cache);
    2248           0 :  out_destroy_icreate_cache:
    2249           0 :         kmem_cache_destroy(xfs_icreate_cache);
    2250           0 :  out_destroy_ili_cache:
    2251           0 :         kmem_cache_destroy(xfs_ili_cache);
    2252           0 :  out_destroy_inode_cache:
    2253           0 :         kmem_cache_destroy(xfs_inode_cache);
    2254           0 :  out_destroy_efi_cache:
    2255           0 :         kmem_cache_destroy(xfs_efi_cache);
    2256           0 :  out_destroy_efd_cache:
    2257           0 :         kmem_cache_destroy(xfs_efd_cache);
    2258           0 :  out_destroy_buf_item_cache:
    2259           0 :         kmem_cache_destroy(xfs_buf_item_cache);
    2260           0 :  out_destroy_trans_cache:
    2261           0 :         kmem_cache_destroy(xfs_trans_cache);
    2262           0 :  out_destroy_ifork_cache:
    2263           0 :         kmem_cache_destroy(xfs_ifork_cache);
    2264           0 :  out_destroy_da_state_cache:
    2265           0 :         kmem_cache_destroy(xfs_da_state_cache);
    2266           0 :  out_destroy_defer_item_cache:
    2267           0 :         xfs_defer_destroy_item_caches();
    2268           0 :  out_destroy_rcbagbt_cur_cache:
    2269           0 :         rcbagbt_destroy_cur_cache();
    2270           0 :  out_destroy_btree_cur_cache:
    2271           0 :         xfs_btree_destroy_cur_caches();
    2272           0 :  out_destroy_log_ticket_cache:
    2273           0 :         kmem_cache_destroy(xfs_log_ticket_cache);
    2274           0 :  out_destroy_buf_cache:
    2275           0 :         kmem_cache_destroy(xfs_buf_cache);
    2276             :  out:
    2277             :         return -ENOMEM;
    2278             : }
    2279             : 
    2280             : STATIC void
    2281          12 : xfs_destroy_caches(void)
    2282             : {
    2283             :         /*
    2284             :          * Make sure all delayed rcu free are flushed before we
    2285             :          * destroy caches.
    2286             :          */
    2287          12 :         rcu_barrier();
    2288          12 :         kmem_cache_destroy(xfs_parent_intent_cache);
    2289          12 :         kmem_cache_destroy(xfs_sxd_cache);
    2290          12 :         kmem_cache_destroy(xfs_sxi_cache);
    2291          12 :         kmem_cache_destroy(xfs_iunlink_cache);
    2292          12 :         kmem_cache_destroy(xfs_attri_cache);
    2293          12 :         kmem_cache_destroy(xfs_attrd_cache);
    2294          12 :         kmem_cache_destroy(xfs_bui_cache);
    2295          12 :         kmem_cache_destroy(xfs_bud_cache);
    2296          12 :         kmem_cache_destroy(xfs_cui_cache);
    2297          12 :         kmem_cache_destroy(xfs_cud_cache);
    2298          12 :         kmem_cache_destroy(xfs_rui_cache);
    2299          12 :         kmem_cache_destroy(xfs_rud_cache);
    2300          12 :         kmem_cache_destroy(xfs_icreate_cache);
    2301          12 :         kmem_cache_destroy(xfs_ili_cache);
    2302          12 :         kmem_cache_destroy(xfs_inode_cache);
    2303          12 :         kmem_cache_destroy(xfs_efi_cache);
    2304          12 :         kmem_cache_destroy(xfs_efd_cache);
    2305          12 :         kmem_cache_destroy(xfs_buf_item_cache);
    2306          12 :         kmem_cache_destroy(xfs_trans_cache);
    2307          12 :         kmem_cache_destroy(xfs_ifork_cache);
    2308          12 :         kmem_cache_destroy(xfs_da_state_cache);
    2309          12 :         xfs_defer_destroy_item_caches();
    2310          12 :         rcbagbt_destroy_cur_cache();
    2311          12 :         xfs_btree_destroy_cur_caches();
    2312          12 :         kmem_cache_destroy(xfs_log_ticket_cache);
    2313          12 :         kmem_cache_destroy(xfs_buf_cache);
    2314          12 : }
    2315             : 
    2316             : STATIC int __init
    2317          12 : xfs_init_workqueues(void)
    2318             : {
    2319             :         /*
    2320             :          * The allocation workqueue can be used in memory reclaim situations
    2321             :          * (writepage path), and parallelism is only limited by the number of
    2322             :          * AGs in all the filesystems mounted. Hence use the default large
    2323             :          * max_active value for this workqueue.
    2324             :          */
    2325          12 :         xfs_alloc_wq = alloc_workqueue("xfsalloc",
    2326             :                         XFS_WQFLAGS(WQ_MEM_RECLAIM | WQ_FREEZABLE), 0);
    2327          12 :         if (!xfs_alloc_wq)
    2328             :                 return -ENOMEM;
    2329             : 
    2330          12 :         xfs_discard_wq = alloc_workqueue("xfsdiscard", XFS_WQFLAGS(WQ_UNBOUND),
    2331             :                         0);
    2332          12 :         if (!xfs_discard_wq)
    2333           0 :                 goto out_free_alloc_wq;
    2334             : 
    2335             :         return 0;
    2336             : out_free_alloc_wq:
    2337           0 :         destroy_workqueue(xfs_alloc_wq);
    2338           0 :         return -ENOMEM;
    2339             : }
    2340             : 
    2341             : STATIC void
    2342          12 : xfs_destroy_workqueues(void)
    2343             : {
    2344          12 :         destroy_workqueue(xfs_discard_wq);
    2345          12 :         destroy_workqueue(xfs_alloc_wq);
    2346          12 : }
    2347             : 
    2348             : #ifdef CONFIG_HOTPLUG_CPU
    2349             : static int
    2350          15 : xfs_cpu_dead(
    2351             :         unsigned int            cpu)
    2352             : {
    2353          15 :         struct xfs_mount        *mp, *n;
    2354             : 
    2355          15 :         spin_lock(&xfs_mount_list_lock);
    2356          30 :         list_for_each_entry_safe(mp, n, &xfs_mount_list, m_mount_list) {
    2357          15 :                 spin_unlock(&xfs_mount_list_lock);
    2358          15 :                 xfs_inodegc_cpu_dead(mp, cpu);
    2359          15 :                 xlog_cil_pcp_dead(mp->m_log, cpu);
    2360          15 :                 spin_lock(&xfs_mount_list_lock);
    2361             :         }
    2362          15 :         spin_unlock(&xfs_mount_list_lock);
    2363          15 :         return 0;
    2364             : }
    2365             : 
    2366             : static int __init
    2367          12 : xfs_cpu_hotplug_init(void)
    2368             : {
    2369          12 :         int     error;
    2370             : 
    2371          12 :         error = cpuhp_setup_state_nocalls(CPUHP_XFS_DEAD, "xfs:dead", NULL,
    2372             :                         xfs_cpu_dead);
    2373          12 :         if (error < 0)
    2374           0 :                 xfs_alert(NULL,
    2375             : "Failed to initialise CPU hotplug, error %d. XFS is non-functional.",
    2376             :                         error);
    2377          12 :         return error;
    2378             : }
    2379             : 
    2380             : static void
    2381             : xfs_cpu_hotplug_destroy(void)
    2382             : {
    2383          12 :         cpuhp_remove_state_nocalls(CPUHP_XFS_DEAD);
    2384           0 : }
    2385             : 
    2386             : #else /* !CONFIG_HOTPLUG_CPU */
    2387             : static inline int xfs_cpu_hotplug_init(void) { return 0; }
    2388             : static inline void xfs_cpu_hotplug_destroy(void) {}
    2389             : #endif
    2390             : 
    2391             : STATIC int __init
    2392          12 : init_xfs_fs(void)
    2393             : {
    2394          12 :         int                     error;
    2395             : 
    2396          12 :         xfs_check_ondisk_structs();
    2397             : 
    2398          12 :         error = xfs_dahash_test();
    2399          12 :         if (error)
    2400             :                 return error;
    2401             : 
    2402          12 :         printk(KERN_INFO XFS_VERSION_STRING " with "
    2403             :                          XFS_BUILD_OPTIONS " enabled\n");
    2404             : 
    2405          12 :         xfs_dir_startup();
    2406             : 
    2407          12 :         error = xfs_cpu_hotplug_init();
    2408          12 :         if (error)
    2409           0 :                 goto out;
    2410             : 
    2411          12 :         error = xfs_init_caches();
    2412          12 :         if (error)
    2413           0 :                 goto out_destroy_hp;
    2414             : 
    2415          12 :         error = xfs_init_workqueues();
    2416          12 :         if (error)
    2417           0 :                 goto out_destroy_caches;
    2418             : 
    2419          12 :         error = xfs_mru_cache_init();
    2420          12 :         if (error)
    2421           0 :                 goto out_destroy_wq;
    2422             : 
    2423          12 :         error = xfs_init_procfs();
    2424          12 :         if (error)
    2425           0 :                 goto out_mru_cache_uninit;
    2426             : 
    2427          12 :         error = xfs_sysctl_register();
    2428          12 :         if (error)
    2429           0 :                 goto out_cleanup_procfs;
    2430             : 
    2431          12 :         xfs_debugfs = xfs_debugfs_mkdir("xfs", NULL);
    2432             : 
    2433          12 :         xfs_kset = kset_create_and_add("xfs", NULL, fs_kobj);
    2434          12 :         if (!xfs_kset) {
    2435           0 :                 error = -ENOMEM;
    2436           0 :                 goto out_debugfs_unregister;
    2437             :         }
    2438             : 
    2439          12 :         xfsstats.xs_kobj.kobject.kset = xfs_kset;
    2440             : 
    2441          12 :         xfsstats.xs_stats = alloc_percpu(struct xfsstats);
    2442          12 :         if (!xfsstats.xs_stats) {
    2443           0 :                 error = -ENOMEM;
    2444           0 :                 goto out_kset_unregister;
    2445             :         }
    2446             : 
    2447          12 :         error = xfs_sysfs_init(&xfsstats.xs_kobj, &xfs_stats_ktype, NULL,
    2448             :                                "stats");
    2449          12 :         if (error)
    2450           0 :                 goto out_free_stats;
    2451             : 
    2452          12 :         error = xchk_global_stats_setup(xfs_debugfs);
    2453          12 :         if (error)
    2454           0 :                 goto out_remove_stats_kobj;
    2455             : 
    2456             : #ifdef DEBUG
    2457          12 :         xfs_dbg_kobj.kobject.kset = xfs_kset;
    2458          12 :         error = xfs_sysfs_init(&xfs_dbg_kobj, &xfs_dbg_ktype, NULL, "debug");
    2459          12 :         if (error)
    2460           0 :                 goto out_remove_scrub_stats;
    2461             : #endif
    2462             : 
    2463          12 :         error = xfs_qm_init();
    2464          12 :         if (error)
    2465           0 :                 goto out_remove_dbg_kobj;
    2466             : 
    2467          12 :         error = register_filesystem(&xfs_fs_type);
    2468          12 :         if (error)
    2469           0 :                 goto out_qm_exit;
    2470             :         return 0;
    2471             : 
    2472             :  out_qm_exit:
    2473           0 :         xfs_qm_exit();
    2474           0 :  out_remove_dbg_kobj:
    2475             : #ifdef DEBUG
    2476           0 :         xfs_sysfs_del(&xfs_dbg_kobj);
    2477           0 :  out_remove_scrub_stats:
    2478             : #endif
    2479           0 :         xchk_global_stats_teardown();
    2480           0 :  out_remove_stats_kobj:
    2481           0 :         xfs_sysfs_del(&xfsstats.xs_kobj);
    2482           0 :  out_free_stats:
    2483           0 :         free_percpu(xfsstats.xs_stats);
    2484           0 :  out_kset_unregister:
    2485           0 :         kset_unregister(xfs_kset);
    2486           0 :  out_debugfs_unregister:
    2487           0 :         debugfs_remove(xfs_debugfs);
    2488           0 :         xfs_sysctl_unregister();
    2489           0 :  out_cleanup_procfs:
    2490           0 :         xfs_cleanup_procfs();
    2491           0 :  out_mru_cache_uninit:
    2492           0 :         xfs_mru_cache_uninit();
    2493           0 :  out_destroy_wq:
    2494           0 :         xfs_destroy_workqueues();
    2495           0 :  out_destroy_caches:
    2496           0 :         xfs_destroy_caches();
    2497           0 :  out_destroy_hp:
    2498           0 :         xfs_cpu_hotplug_destroy();
    2499             :  out:
    2500             :         return error;
    2501             : }
    2502             : 
    2503             : STATIC void __exit
    2504          12 : exit_xfs_fs(void)
    2505             : {
    2506          12 :         xfs_qm_exit();
    2507          12 :         unregister_filesystem(&xfs_fs_type);
    2508             : #ifdef DEBUG
    2509          12 :         xfs_sysfs_del(&xfs_dbg_kobj);
    2510             : #endif
    2511          12 :         xchk_global_stats_teardown();
    2512          12 :         xfs_sysfs_del(&xfsstats.xs_kobj);
    2513          12 :         free_percpu(xfsstats.xs_stats);
    2514          12 :         kset_unregister(xfs_kset);
    2515          12 :         debugfs_remove(xfs_debugfs);
    2516          12 :         xfs_sysctl_unregister();
    2517          12 :         xfs_cleanup_procfs();
    2518          12 :         xfs_mru_cache_uninit();
    2519          12 :         xfs_destroy_workqueues();
    2520          12 :         xfs_destroy_caches();
    2521          12 :         xfs_uuid_table_free();
    2522          12 :         xfs_cpu_hotplug_destroy();
    2523          12 : }
    2524             : 
    2525             : module_init(init_xfs_fs);
    2526             : module_exit(exit_xfs_fs);
    2527             : 
    2528             : MODULE_AUTHOR("Silicon Graphics, Inc.");
    2529             : MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
    2530             : MODULE_LICENSE("GPL");

Generated by: LCOV version 1.14