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

Generated by: LCOV version 1.14