Dave Chinner | 0b61f8a | 2018-06-05 19:42:14 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Nathan Scott | a805bad | 2006-06-19 08:40:27 +1000 | [diff] [blame] | 3 | * Copyright (c) 2000-2006 Silicon Graphics, Inc. |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 4 | * All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | */ |
Christoph Hellwig | 0b1b213 | 2009-12-14 23:14:59 +0000 | [diff] [blame] | 6 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include "xfs.h" |
Dave Chinner | 70a9883 | 2013-10-23 10:36:05 +1100 | [diff] [blame] | 8 | #include "xfs_shared.h" |
Dave Chinner | 6ca1c90 | 2013-08-12 20:49:26 +1000 | [diff] [blame] | 9 | #include "xfs_format.h" |
Dave Chinner | 239880e | 2013-10-23 10:50:10 +1100 | [diff] [blame] | 10 | #include "xfs_log_format.h" |
| 11 | #include "xfs_trans_resv.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include "xfs_sb.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include "xfs_mount.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include "xfs_inode.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 15 | #include "xfs_btree.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include "xfs_bmap.h" |
Dave Chinner | a4fbe6a | 2013-10-23 10:51:50 +1100 | [diff] [blame] | 17 | #include "xfs_alloc.h" |
Christoph Hellwig | 9909c4a | 2007-10-11 18:11:14 +1000 | [diff] [blame] | 18 | #include "xfs_fsops.h" |
Dave Chinner | 239880e | 2013-10-23 10:50:10 +1100 | [diff] [blame] | 19 | #include "xfs_trans.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include "xfs_buf_item.h" |
Dave Chinner | 239880e | 2013-10-23 10:50:10 +1100 | [diff] [blame] | 21 | #include "xfs_log.h" |
David Chinner | a67d7c5 | 2007-11-23 16:29:32 +1100 | [diff] [blame] | 22 | #include "xfs_log_priv.h" |
Dave Chinner | 2b9ab5a | 2013-08-12 20:49:37 +1000 | [diff] [blame] | 23 | #include "xfs_dir2.h" |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 24 | #include "xfs_extfree_item.h" |
| 25 | #include "xfs_mru_cache.h" |
| 26 | #include "xfs_inode_item.h" |
Dave Chinner | 6d8b79c | 2012-10-08 21:56:09 +1100 | [diff] [blame] | 27 | #include "xfs_icache.h" |
Christoph Hellwig | 0b1b213 | 2009-12-14 23:14:59 +0000 | [diff] [blame] | 28 | #include "xfs_trace.h" |
Dave Chinner | 3ebe7d2 | 2013-06-27 16:04:53 +1000 | [diff] [blame] | 29 | #include "xfs_icreate_item.h" |
Dave Chinner | a4fbe6a | 2013-10-23 10:51:50 +1100 | [diff] [blame] | 30 | #include "xfs_filestream.h" |
| 31 | #include "xfs_quota.h" |
Brian Foster | 65b6573 | 2014-09-09 11:52:42 +1000 | [diff] [blame] | 32 | #include "xfs_sysfs.h" |
Darrick J. Wong | 30cbc59 | 2016-03-09 08:15:14 +1100 | [diff] [blame] | 33 | #include "xfs_ondisk.h" |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 34 | #include "xfs_rmap_item.h" |
Darrick J. Wong | baf4bcac | 2016-10-03 09:11:20 -0700 | [diff] [blame] | 35 | #include "xfs_refcount_item.h" |
Darrick J. Wong | 6413a01 | 2016-10-03 09:11:25 -0700 | [diff] [blame] | 36 | #include "xfs_bmap_item.h" |
Darrick J. Wong | 5e7e605 | 2016-10-03 09:11:38 -0700 | [diff] [blame] | 37 | #include "xfs_reflink.h" |
Darrick J. Wong | 894ecac | 2021-01-22 16:48:44 -0800 | [diff] [blame] | 38 | #include "xfs_pwork.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Adam Borowski | dddde68 | 2018-10-18 17:20:19 +1100 | [diff] [blame] | 40 | #include <linux/magic.h> |
Ian Kent | 73e5fff | 2019-11-04 13:58:46 -0800 | [diff] [blame] | 41 | #include <linux/fs_context.h> |
| 42 | #include <linux/fs_parser.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
Alexey Dobriyan | b87221d | 2009-09-21 17:01:09 -0700 | [diff] [blame] | 44 | static const struct super_operations xfs_super_operations; |
Brian Foster | 65b6573 | 2014-09-09 11:52:42 +1000 | [diff] [blame] | 45 | |
Dave Chinner | e3aed1a | 2014-09-29 10:46:08 +1000 | [diff] [blame] | 46 | static struct kset *xfs_kset; /* top-level xfs sysfs dir */ |
Brian Foster | 65b6573 | 2014-09-09 11:52:42 +1000 | [diff] [blame] | 47 | #ifdef DEBUG |
| 48 | static struct xfs_kobj xfs_dbg_kobj; /* global debug sysfs attrs */ |
| 49 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
Ira Weiny | 8d6c344 | 2020-05-04 09:02:42 -0700 | [diff] [blame] | 51 | enum xfs_dax_mode { |
| 52 | XFS_DAX_INODE = 0, |
| 53 | XFS_DAX_ALWAYS = 1, |
| 54 | XFS_DAX_NEVER = 2, |
| 55 | }; |
| 56 | |
| 57 | static void |
| 58 | xfs_mount_set_dax_mode( |
| 59 | struct xfs_mount *mp, |
| 60 | enum xfs_dax_mode mode) |
| 61 | { |
| 62 | switch (mode) { |
| 63 | case XFS_DAX_INODE: |
| 64 | mp->m_flags &= ~(XFS_MOUNT_DAX_ALWAYS | XFS_MOUNT_DAX_NEVER); |
| 65 | break; |
| 66 | case XFS_DAX_ALWAYS: |
| 67 | mp->m_flags |= XFS_MOUNT_DAX_ALWAYS; |
| 68 | mp->m_flags &= ~XFS_MOUNT_DAX_NEVER; |
| 69 | break; |
| 70 | case XFS_DAX_NEVER: |
| 71 | mp->m_flags |= XFS_MOUNT_DAX_NEVER; |
| 72 | mp->m_flags &= ~XFS_MOUNT_DAX_ALWAYS; |
| 73 | break; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | static const struct constant_table dax_param_enums[] = { |
| 78 | {"inode", XFS_DAX_INODE }, |
| 79 | {"always", XFS_DAX_ALWAYS }, |
| 80 | {"never", XFS_DAX_NEVER }, |
| 81 | {} |
| 82 | }; |
| 83 | |
Christoph Hellwig | 62a877e | 2008-07-18 17:12:36 +1000 | [diff] [blame] | 84 | /* |
| 85 | * Table driven mount option parser. |
Christoph Hellwig | 62a877e | 2008-07-18 17:12:36 +1000 | [diff] [blame] | 86 | */ |
| 87 | enum { |
Ian Kent | 8da57c5 | 2019-10-28 08:41:42 -0700 | [diff] [blame] | 88 | Opt_logbufs, Opt_logbsize, Opt_logdev, Opt_rtdev, |
Eric Sandeen | 2e74af0 | 2016-03-02 09:55:38 +1100 | [diff] [blame] | 89 | Opt_wsync, Opt_noalign, Opt_swalloc, Opt_sunit, Opt_swidth, Opt_nouuid, |
Christoph Hellwig | 9407928 | 2019-04-28 08:32:52 -0700 | [diff] [blame] | 90 | Opt_grpid, Opt_nogrpid, Opt_bsdgroups, Opt_sysvgroups, |
Eric Sandeen | 1c02d50 | 2018-07-26 09:11:27 -0700 | [diff] [blame] | 91 | Opt_allocsize, Opt_norecovery, Opt_inode64, Opt_inode32, Opt_ikeep, |
| 92 | Opt_noikeep, Opt_largeio, Opt_nolargeio, Opt_attr2, Opt_noattr2, |
| 93 | Opt_filestreams, Opt_quota, Opt_noquota, Opt_usrquota, Opt_grpquota, |
| 94 | Opt_prjquota, Opt_uquota, Opt_gquota, Opt_pquota, |
Eric Sandeen | 2e74af0 | 2016-03-02 09:55:38 +1100 | [diff] [blame] | 95 | Opt_uqnoenforce, Opt_gqnoenforce, Opt_pqnoenforce, Opt_qnoenforce, |
Ira Weiny | 8d6c344 | 2020-05-04 09:02:42 -0700 | [diff] [blame] | 96 | Opt_discard, Opt_nodiscard, Opt_dax, Opt_dax_enum, |
Christoph Hellwig | 62a877e | 2008-07-18 17:12:36 +1000 | [diff] [blame] | 97 | }; |
| 98 | |
Al Viro | d7167b1 | 2019-09-07 07:23:15 -0400 | [diff] [blame] | 99 | static const struct fs_parameter_spec xfs_fs_parameters[] = { |
Ian Kent | 73e5fff | 2019-11-04 13:58:46 -0800 | [diff] [blame] | 100 | fsparam_u32("logbufs", Opt_logbufs), |
| 101 | fsparam_string("logbsize", Opt_logbsize), |
| 102 | fsparam_string("logdev", Opt_logdev), |
| 103 | fsparam_string("rtdev", Opt_rtdev), |
| 104 | fsparam_flag("wsync", Opt_wsync), |
| 105 | fsparam_flag("noalign", Opt_noalign), |
| 106 | fsparam_flag("swalloc", Opt_swalloc), |
| 107 | fsparam_u32("sunit", Opt_sunit), |
| 108 | fsparam_u32("swidth", Opt_swidth), |
| 109 | fsparam_flag("nouuid", Opt_nouuid), |
| 110 | fsparam_flag("grpid", Opt_grpid), |
| 111 | fsparam_flag("nogrpid", Opt_nogrpid), |
| 112 | fsparam_flag("bsdgroups", Opt_bsdgroups), |
| 113 | fsparam_flag("sysvgroups", Opt_sysvgroups), |
| 114 | fsparam_string("allocsize", Opt_allocsize), |
| 115 | fsparam_flag("norecovery", Opt_norecovery), |
| 116 | fsparam_flag("inode64", Opt_inode64), |
| 117 | fsparam_flag("inode32", Opt_inode32), |
| 118 | fsparam_flag("ikeep", Opt_ikeep), |
| 119 | fsparam_flag("noikeep", Opt_noikeep), |
| 120 | fsparam_flag("largeio", Opt_largeio), |
| 121 | fsparam_flag("nolargeio", Opt_nolargeio), |
| 122 | fsparam_flag("attr2", Opt_attr2), |
| 123 | fsparam_flag("noattr2", Opt_noattr2), |
| 124 | fsparam_flag("filestreams", Opt_filestreams), |
| 125 | fsparam_flag("quota", Opt_quota), |
| 126 | fsparam_flag("noquota", Opt_noquota), |
| 127 | fsparam_flag("usrquota", Opt_usrquota), |
| 128 | fsparam_flag("grpquota", Opt_grpquota), |
| 129 | fsparam_flag("prjquota", Opt_prjquota), |
| 130 | fsparam_flag("uquota", Opt_uquota), |
| 131 | fsparam_flag("gquota", Opt_gquota), |
| 132 | fsparam_flag("pquota", Opt_pquota), |
| 133 | fsparam_flag("uqnoenforce", Opt_uqnoenforce), |
| 134 | fsparam_flag("gqnoenforce", Opt_gqnoenforce), |
| 135 | fsparam_flag("pqnoenforce", Opt_pqnoenforce), |
| 136 | fsparam_flag("qnoenforce", Opt_qnoenforce), |
| 137 | fsparam_flag("discard", Opt_discard), |
| 138 | fsparam_flag("nodiscard", Opt_nodiscard), |
| 139 | fsparam_flag("dax", Opt_dax), |
Ira Weiny | 8d6c344 | 2020-05-04 09:02:42 -0700 | [diff] [blame] | 140 | fsparam_enum("dax", Opt_dax_enum, dax_param_enums), |
Ian Kent | 73e5fff | 2019-11-04 13:58:46 -0800 | [diff] [blame] | 141 | {} |
Christoph Hellwig | 62a877e | 2008-07-18 17:12:36 +1000 | [diff] [blame] | 142 | }; |
| 143 | |
David Chinner | a67d7c5 | 2007-11-23 16:29:32 +1100 | [diff] [blame] | 144 | struct proc_xfs_info { |
Dave Chinner | cbe4dab | 2015-06-04 09:19:18 +1000 | [diff] [blame] | 145 | uint64_t flag; |
| 146 | char *str; |
David Chinner | a67d7c5 | 2007-11-23 16:29:32 +1100 | [diff] [blame] | 147 | }; |
| 148 | |
Christoph Hellwig | 21f5599 | 2019-10-28 08:41:47 -0700 | [diff] [blame] | 149 | static int |
| 150 | xfs_fs_show_options( |
| 151 | struct seq_file *m, |
| 152 | struct dentry *root) |
David Chinner | a67d7c5 | 2007-11-23 16:29:32 +1100 | [diff] [blame] | 153 | { |
| 154 | static struct proc_xfs_info xfs_info_set[] = { |
| 155 | /* the few simple ones we can get from the mount struct */ |
Eric Sandeen | 2e74af0 | 2016-03-02 09:55:38 +1100 | [diff] [blame] | 156 | { XFS_MOUNT_IKEEP, ",ikeep" }, |
| 157 | { XFS_MOUNT_WSYNC, ",wsync" }, |
| 158 | { XFS_MOUNT_NOALIGN, ",noalign" }, |
| 159 | { XFS_MOUNT_SWALLOC, ",swalloc" }, |
| 160 | { XFS_MOUNT_NOUUID, ",nouuid" }, |
| 161 | { XFS_MOUNT_NORECOVERY, ",norecovery" }, |
| 162 | { XFS_MOUNT_ATTR2, ",attr2" }, |
| 163 | { XFS_MOUNT_FILESTREAMS, ",filestreams" }, |
| 164 | { XFS_MOUNT_GRPID, ",grpid" }, |
| 165 | { XFS_MOUNT_DISCARD, ",discard" }, |
Christoph Hellwig | 7c6b94b | 2019-10-28 08:41:46 -0700 | [diff] [blame] | 166 | { XFS_MOUNT_LARGEIO, ",largeio" }, |
Ira Weiny | 8d6c344 | 2020-05-04 09:02:42 -0700 | [diff] [blame] | 167 | { XFS_MOUNT_DAX_ALWAYS, ",dax=always" }, |
| 168 | { XFS_MOUNT_DAX_NEVER, ",dax=never" }, |
David Chinner | a67d7c5 | 2007-11-23 16:29:32 +1100 | [diff] [blame] | 169 | { 0, NULL } |
| 170 | }; |
Christoph Hellwig | 21f5599 | 2019-10-28 08:41:47 -0700 | [diff] [blame] | 171 | struct xfs_mount *mp = XFS_M(root->d_sb); |
David Chinner | a67d7c5 | 2007-11-23 16:29:32 +1100 | [diff] [blame] | 172 | struct proc_xfs_info *xfs_infop; |
| 173 | |
| 174 | for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) { |
| 175 | if (mp->m_flags & xfs_infop->flag) |
| 176 | seq_puts(m, xfs_infop->str); |
| 177 | } |
Christoph Hellwig | 1775c50 | 2019-10-28 08:41:47 -0700 | [diff] [blame] | 178 | |
| 179 | seq_printf(m, ",inode%d", |
| 180 | (mp->m_flags & XFS_MOUNT_SMALL_INUMS) ? 32 : 64); |
David Chinner | a67d7c5 | 2007-11-23 16:29:32 +1100 | [diff] [blame] | 181 | |
Christoph Hellwig | 3274d00 | 2019-10-28 08:41:45 -0700 | [diff] [blame] | 182 | if (mp->m_flags & XFS_MOUNT_ALLOCSIZE) |
Eric Sandeen | 2e74af0 | 2016-03-02 09:55:38 +1100 | [diff] [blame] | 183 | seq_printf(m, ",allocsize=%dk", |
Christoph Hellwig | aa58d44 | 2019-10-28 08:41:46 -0700 | [diff] [blame] | 184 | (1 << mp->m_allocsize_log) >> 10); |
David Chinner | a67d7c5 | 2007-11-23 16:29:32 +1100 | [diff] [blame] | 185 | |
| 186 | if (mp->m_logbufs > 0) |
Eric Sandeen | 2e74af0 | 2016-03-02 09:55:38 +1100 | [diff] [blame] | 187 | seq_printf(m, ",logbufs=%d", mp->m_logbufs); |
David Chinner | a67d7c5 | 2007-11-23 16:29:32 +1100 | [diff] [blame] | 188 | if (mp->m_logbsize > 0) |
Eric Sandeen | 2e74af0 | 2016-03-02 09:55:38 +1100 | [diff] [blame] | 189 | seq_printf(m, ",logbsize=%dk", mp->m_logbsize >> 10); |
David Chinner | a67d7c5 | 2007-11-23 16:29:32 +1100 | [diff] [blame] | 190 | |
| 191 | if (mp->m_logname) |
Eric Sandeen | 2e74af0 | 2016-03-02 09:55:38 +1100 | [diff] [blame] | 192 | seq_show_option(m, "logdev", mp->m_logname); |
David Chinner | a67d7c5 | 2007-11-23 16:29:32 +1100 | [diff] [blame] | 193 | if (mp->m_rtname) |
Eric Sandeen | 2e74af0 | 2016-03-02 09:55:38 +1100 | [diff] [blame] | 194 | seq_show_option(m, "rtdev", mp->m_rtname); |
David Chinner | a67d7c5 | 2007-11-23 16:29:32 +1100 | [diff] [blame] | 195 | |
| 196 | if (mp->m_dalign > 0) |
Eric Sandeen | 2e74af0 | 2016-03-02 09:55:38 +1100 | [diff] [blame] | 197 | seq_printf(m, ",sunit=%d", |
David Chinner | a67d7c5 | 2007-11-23 16:29:32 +1100 | [diff] [blame] | 198 | (int)XFS_FSB_TO_BB(mp, mp->m_dalign)); |
| 199 | if (mp->m_swidth > 0) |
Eric Sandeen | 2e74af0 | 2016-03-02 09:55:38 +1100 | [diff] [blame] | 200 | seq_printf(m, ",swidth=%d", |
David Chinner | a67d7c5 | 2007-11-23 16:29:32 +1100 | [diff] [blame] | 201 | (int)XFS_FSB_TO_BB(mp, mp->m_swidth)); |
| 202 | |
Kaixu Xia | 237d788 | 2020-12-03 16:46:50 -0800 | [diff] [blame] | 203 | if (mp->m_qflags & XFS_UQUOTA_ACCT) { |
| 204 | if (mp->m_qflags & XFS_UQUOTA_ENFD) |
| 205 | seq_puts(m, ",usrquota"); |
| 206 | else |
| 207 | seq_puts(m, ",uqnoenforce"); |
| 208 | } |
David Chinner | a67d7c5 | 2007-11-23 16:29:32 +1100 | [diff] [blame] | 209 | |
Alex Elder | 988abe4 | 2009-09-02 17:02:24 -0500 | [diff] [blame] | 210 | if (mp->m_qflags & XFS_PQUOTA_ACCT) { |
Chandra Seetharaman | 83e782e | 2013-06-27 17:25:10 -0500 | [diff] [blame] | 211 | if (mp->m_qflags & XFS_PQUOTA_ENFD) |
Eric Sandeen | 2e74af0 | 2016-03-02 09:55:38 +1100 | [diff] [blame] | 212 | seq_puts(m, ",prjquota"); |
Alex Elder | 988abe4 | 2009-09-02 17:02:24 -0500 | [diff] [blame] | 213 | else |
Eric Sandeen | 2e74af0 | 2016-03-02 09:55:38 +1100 | [diff] [blame] | 214 | seq_puts(m, ",pqnoenforce"); |
Chandra Seetharaman | d892d58 | 2013-07-19 17:36:02 -0500 | [diff] [blame] | 215 | } |
| 216 | if (mp->m_qflags & XFS_GQUOTA_ACCT) { |
Chandra Seetharaman | 83e782e | 2013-06-27 17:25:10 -0500 | [diff] [blame] | 217 | if (mp->m_qflags & XFS_GQUOTA_ENFD) |
Eric Sandeen | 2e74af0 | 2016-03-02 09:55:38 +1100 | [diff] [blame] | 218 | seq_puts(m, ",grpquota"); |
Alex Elder | 988abe4 | 2009-09-02 17:02:24 -0500 | [diff] [blame] | 219 | else |
Eric Sandeen | 2e74af0 | 2016-03-02 09:55:38 +1100 | [diff] [blame] | 220 | seq_puts(m, ",gqnoenforce"); |
Alex Elder | 988abe4 | 2009-09-02 17:02:24 -0500 | [diff] [blame] | 221 | } |
David Chinner | a67d7c5 | 2007-11-23 16:29:32 +1100 | [diff] [blame] | 222 | |
| 223 | if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT)) |
Eric Sandeen | 2e74af0 | 2016-03-02 09:55:38 +1100 | [diff] [blame] | 224 | seq_puts(m, ",noquota"); |
Christoph Hellwig | 21f5599 | 2019-10-28 08:41:47 -0700 | [diff] [blame] | 225 | |
| 226 | return 0; |
David Chinner | a67d7c5 | 2007-11-23 16:29:32 +1100 | [diff] [blame] | 227 | } |
Eric Sandeen | 9108326 | 2019-05-01 20:26:30 -0700 | [diff] [blame] | 228 | |
Eric Sandeen | 9de67c3 | 2014-07-24 20:51:54 +1000 | [diff] [blame] | 229 | /* |
Eric Sandeen | 12c3f05 | 2016-03-02 09:58:09 +1100 | [diff] [blame] | 230 | * Set parameters for inode allocation heuristics, taking into account |
| 231 | * filesystem size and inode32/inode64 mount options; i.e. specifically |
| 232 | * whether or not XFS_MOUNT_SMALL_INUMS is set. |
| 233 | * |
| 234 | * Inode allocation patterns are altered only if inode32 is requested |
| 235 | * (XFS_MOUNT_SMALL_INUMS), and the filesystem is sufficiently large. |
| 236 | * If altered, XFS_MOUNT_32BITINODES is set as well. |
| 237 | * |
| 238 | * An agcount independent of that in the mount structure is provided |
| 239 | * because in the growfs case, mp->m_sb.sb_agcount is not yet updated |
| 240 | * to the potentially higher ag count. |
| 241 | * |
| 242 | * Returns the maximum AG index which may contain inodes. |
Eric Sandeen | 9de67c3 | 2014-07-24 20:51:54 +1000 | [diff] [blame] | 243 | */ |
Carlos Maiolino | 2d2194f | 2012-09-20 10:32:38 -0300 | [diff] [blame] | 244 | xfs_agnumber_t |
Eric Sandeen | 12c3f05 | 2016-03-02 09:58:09 +1100 | [diff] [blame] | 245 | xfs_set_inode_alloc( |
| 246 | struct xfs_mount *mp, |
| 247 | xfs_agnumber_t agcount) |
Carlos Maiolino | 2d2194f | 2012-09-20 10:32:38 -0300 | [diff] [blame] | 248 | { |
Eric Sandeen | 12c3f05 | 2016-03-02 09:58:09 +1100 | [diff] [blame] | 249 | xfs_agnumber_t index; |
Carlos Maiolino | 4056c1d | 2012-09-20 10:32:40 -0300 | [diff] [blame] | 250 | xfs_agnumber_t maxagi = 0; |
Carlos Maiolino | 2d2194f | 2012-09-20 10:32:38 -0300 | [diff] [blame] | 251 | xfs_sb_t *sbp = &mp->m_sb; |
| 252 | xfs_agnumber_t max_metadata; |
Eric Sandeen | 54aa61f | 2014-07-24 20:53:10 +1000 | [diff] [blame] | 253 | xfs_agino_t agino; |
| 254 | xfs_ino_t ino; |
Carlos Maiolino | 2d2194f | 2012-09-20 10:32:38 -0300 | [diff] [blame] | 255 | |
Eric Sandeen | 12c3f05 | 2016-03-02 09:58:09 +1100 | [diff] [blame] | 256 | /* |
| 257 | * Calculate how much should be reserved for inodes to meet |
| 258 | * the max inode percentage. Used only for inode32. |
Carlos Maiolino | 2d2194f | 2012-09-20 10:32:38 -0300 | [diff] [blame] | 259 | */ |
Darrick J. Wong | ef32595 | 2019-06-05 11:19:34 -0700 | [diff] [blame] | 260 | if (M_IGEO(mp)->maxicount) { |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 261 | uint64_t icount; |
Carlos Maiolino | 2d2194f | 2012-09-20 10:32:38 -0300 | [diff] [blame] | 262 | |
| 263 | icount = sbp->sb_dblocks * sbp->sb_imax_pct; |
| 264 | do_div(icount, 100); |
| 265 | icount += sbp->sb_agblocks - 1; |
| 266 | do_div(icount, sbp->sb_agblocks); |
| 267 | max_metadata = icount; |
| 268 | } else { |
Eric Sandeen | 9de67c3 | 2014-07-24 20:51:54 +1000 | [diff] [blame] | 269 | max_metadata = agcount; |
Carlos Maiolino | 2d2194f | 2012-09-20 10:32:38 -0300 | [diff] [blame] | 270 | } |
| 271 | |
Eric Sandeen | 12c3f05 | 2016-03-02 09:58:09 +1100 | [diff] [blame] | 272 | /* Get the last possible inode in the filesystem */ |
Darrick J. Wong | 43004b2 | 2018-12-12 08:46:24 -0800 | [diff] [blame] | 273 | agino = XFS_AGB_TO_AGINO(mp, sbp->sb_agblocks - 1); |
Eric Sandeen | 12c3f05 | 2016-03-02 09:58:09 +1100 | [diff] [blame] | 274 | ino = XFS_AGINO_TO_INO(mp, agcount - 1, agino); |
Eric Sandeen | 54aa61f | 2014-07-24 20:53:10 +1000 | [diff] [blame] | 275 | |
Eric Sandeen | 12c3f05 | 2016-03-02 09:58:09 +1100 | [diff] [blame] | 276 | /* |
| 277 | * If user asked for no more than 32-bit inodes, and the fs is |
| 278 | * sufficiently large, set XFS_MOUNT_32BITINODES if we must alter |
| 279 | * the allocator to accommodate the request. |
| 280 | */ |
| 281 | if ((mp->m_flags & XFS_MOUNT_SMALL_INUMS) && ino > XFS_MAXINUMBER_32) |
| 282 | mp->m_flags |= XFS_MOUNT_32BITINODES; |
| 283 | else |
| 284 | mp->m_flags &= ~XFS_MOUNT_32BITINODES; |
Carlos Maiolino | 2d2194f | 2012-09-20 10:32:38 -0300 | [diff] [blame] | 285 | |
Eric Sandeen | 9de67c3 | 2014-07-24 20:51:54 +1000 | [diff] [blame] | 286 | for (index = 0; index < agcount; index++) { |
Carlos Maiolino | 2d2194f | 2012-09-20 10:32:38 -0300 | [diff] [blame] | 287 | struct xfs_perag *pag; |
| 288 | |
Eric Sandeen | 12c3f05 | 2016-03-02 09:58:09 +1100 | [diff] [blame] | 289 | ino = XFS_AGINO_TO_INO(mp, index, agino); |
| 290 | |
Carlos Maiolino | 2d2194f | 2012-09-20 10:32:38 -0300 | [diff] [blame] | 291 | pag = xfs_perag_get(mp, index); |
Eric Sandeen | 12c3f05 | 2016-03-02 09:58:09 +1100 | [diff] [blame] | 292 | |
| 293 | if (mp->m_flags & XFS_MOUNT_32BITINODES) { |
| 294 | if (ino > XFS_MAXINUMBER_32) { |
| 295 | pag->pagi_inodeok = 0; |
| 296 | pag->pagf_metadata = 0; |
| 297 | } else { |
| 298 | pag->pagi_inodeok = 1; |
| 299 | maxagi++; |
| 300 | if (index < max_metadata) |
| 301 | pag->pagf_metadata = 1; |
| 302 | else |
| 303 | pag->pagf_metadata = 0; |
| 304 | } |
| 305 | } else { |
| 306 | pag->pagi_inodeok = 1; |
| 307 | pag->pagf_metadata = 0; |
| 308 | } |
| 309 | |
Carlos Maiolino | 2d2194f | 2012-09-20 10:32:38 -0300 | [diff] [blame] | 310 | xfs_perag_put(pag); |
| 311 | } |
| 312 | |
Eric Sandeen | 12c3f05 | 2016-03-02 09:58:09 +1100 | [diff] [blame] | 313 | return (mp->m_flags & XFS_MOUNT_32BITINODES) ? maxagi : agcount; |
Carlos Maiolino | 2d2194f | 2012-09-20 10:32:38 -0300 | [diff] [blame] | 314 | } |
| 315 | |
Hannes Eder | 3180e66 | 2009-03-04 19:34:10 +0100 | [diff] [blame] | 316 | STATIC int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | xfs_blkdev_get( |
| 318 | xfs_mount_t *mp, |
| 319 | const char *name, |
| 320 | struct block_device **bdevp) |
| 321 | { |
| 322 | int error = 0; |
| 323 | |
Tejun Heo | d4d7762 | 2010-11-13 11:55:18 +0100 | [diff] [blame] | 324 | *bdevp = blkdev_get_by_path(name, FMODE_READ|FMODE_WRITE|FMODE_EXCL, |
| 325 | mp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | if (IS_ERR(*bdevp)) { |
| 327 | error = PTR_ERR(*bdevp); |
Eric Sandeen | 77af574 | 2014-12-24 09:47:27 +1100 | [diff] [blame] | 328 | xfs_warn(mp, "Invalid device [%s], error=%d", name, error); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 331 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | } |
| 333 | |
Hannes Eder | 3180e66 | 2009-03-04 19:34:10 +0100 | [diff] [blame] | 334 | STATIC void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | xfs_blkdev_put( |
| 336 | struct block_device *bdev) |
| 337 | { |
| 338 | if (bdev) |
Tejun Heo | e525fd8 | 2010-11-13 11:55:17 +0100 | [diff] [blame] | 339 | blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | } |
| 341 | |
Christoph Hellwig | f538d4d | 2005-11-02 10:26:59 +1100 | [diff] [blame] | 342 | void |
| 343 | xfs_blkdev_issue_flush( |
| 344 | xfs_buftarg_t *buftarg) |
| 345 | { |
Christoph Hellwig | c6bf3f0 | 2021-01-26 15:52:35 +0100 | [diff] [blame] | 346 | blkdev_issue_flush(buftarg->bt_bdev); |
Christoph Hellwig | f538d4d | 2005-11-02 10:26:59 +1100 | [diff] [blame] | 347 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 349 | STATIC void |
| 350 | xfs_close_devices( |
| 351 | struct xfs_mount *mp) |
| 352 | { |
Dan Williams | 486aff5 | 2017-08-24 15:12:50 -0700 | [diff] [blame] | 353 | struct dax_device *dax_ddev = mp->m_ddev_targp->bt_daxdev; |
| 354 | |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 355 | if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) { |
Lachlan McIlroy | c032bfc | 2008-07-18 17:13:12 +1000 | [diff] [blame] | 356 | struct block_device *logdev = mp->m_logdev_targp->bt_bdev; |
Dan Williams | 486aff5 | 2017-08-24 15:12:50 -0700 | [diff] [blame] | 357 | struct dax_device *dax_logdev = mp->m_logdev_targp->bt_daxdev; |
| 358 | |
Eric Sandeen | a1f6941 | 2018-04-06 10:09:42 -0700 | [diff] [blame] | 359 | xfs_free_buftarg(mp->m_logdev_targp); |
Lachlan McIlroy | c032bfc | 2008-07-18 17:13:12 +1000 | [diff] [blame] | 360 | xfs_blkdev_put(logdev); |
Dan Williams | 486aff5 | 2017-08-24 15:12:50 -0700 | [diff] [blame] | 361 | fs_put_dax(dax_logdev); |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 362 | } |
| 363 | if (mp->m_rtdev_targp) { |
Lachlan McIlroy | c032bfc | 2008-07-18 17:13:12 +1000 | [diff] [blame] | 364 | struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev; |
Dan Williams | 486aff5 | 2017-08-24 15:12:50 -0700 | [diff] [blame] | 365 | struct dax_device *dax_rtdev = mp->m_rtdev_targp->bt_daxdev; |
| 366 | |
Eric Sandeen | a1f6941 | 2018-04-06 10:09:42 -0700 | [diff] [blame] | 367 | xfs_free_buftarg(mp->m_rtdev_targp); |
Lachlan McIlroy | c032bfc | 2008-07-18 17:13:12 +1000 | [diff] [blame] | 368 | xfs_blkdev_put(rtdev); |
Dan Williams | 486aff5 | 2017-08-24 15:12:50 -0700 | [diff] [blame] | 369 | fs_put_dax(dax_rtdev); |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 370 | } |
Eric Sandeen | a1f6941 | 2018-04-06 10:09:42 -0700 | [diff] [blame] | 371 | xfs_free_buftarg(mp->m_ddev_targp); |
Dan Williams | 486aff5 | 2017-08-24 15:12:50 -0700 | [diff] [blame] | 372 | fs_put_dax(dax_ddev); |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | /* |
| 376 | * The file system configurations are: |
| 377 | * (1) device (partition) with data and internal log |
| 378 | * (2) logical volume with data and log subvolumes. |
| 379 | * (3) logical volume with data, log, and realtime subvolumes. |
| 380 | * |
| 381 | * We only have to handle opening the log and realtime volumes here if |
| 382 | * they are present. The data subvolume has already been opened by |
| 383 | * get_sb_bdev() and is stored in sb->s_bdev. |
| 384 | */ |
| 385 | STATIC int |
| 386 | xfs_open_devices( |
Christoph Hellwig | 9d565ff | 2008-10-30 17:53:24 +1100 | [diff] [blame] | 387 | struct xfs_mount *mp) |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 388 | { |
| 389 | struct block_device *ddev = mp->m_super->s_bdev; |
Dan Williams | 486aff5 | 2017-08-24 15:12:50 -0700 | [diff] [blame] | 390 | struct dax_device *dax_ddev = fs_dax_get_by_bdev(ddev); |
| 391 | struct dax_device *dax_logdev = NULL, *dax_rtdev = NULL; |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 392 | struct block_device *logdev = NULL, *rtdev = NULL; |
| 393 | int error; |
| 394 | |
| 395 | /* |
| 396 | * Open real time and log devices - order is important. |
| 397 | */ |
Christoph Hellwig | 9d565ff | 2008-10-30 17:53:24 +1100 | [diff] [blame] | 398 | if (mp->m_logname) { |
| 399 | error = xfs_blkdev_get(mp, mp->m_logname, &logdev); |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 400 | if (error) |
| 401 | goto out; |
Dan Williams | 486aff5 | 2017-08-24 15:12:50 -0700 | [diff] [blame] | 402 | dax_logdev = fs_dax_get_by_bdev(logdev); |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 403 | } |
| 404 | |
Christoph Hellwig | 9d565ff | 2008-10-30 17:53:24 +1100 | [diff] [blame] | 405 | if (mp->m_rtname) { |
| 406 | error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev); |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 407 | if (error) |
| 408 | goto out_close_logdev; |
| 409 | |
| 410 | if (rtdev == ddev || rtdev == logdev) { |
Dave Chinner | 4f10700 | 2011-03-07 10:00:35 +1100 | [diff] [blame] | 411 | xfs_warn(mp, |
| 412 | "Cannot mount filesystem with identical rtdev and ddev/logdev."); |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 413 | error = -EINVAL; |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 414 | goto out_close_rtdev; |
| 415 | } |
Dan Williams | 486aff5 | 2017-08-24 15:12:50 -0700 | [diff] [blame] | 416 | dax_rtdev = fs_dax_get_by_bdev(rtdev); |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | /* |
| 420 | * Setup xfs_mount buffer target pointers |
| 421 | */ |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 422 | error = -ENOMEM; |
Dan Williams | 486aff5 | 2017-08-24 15:12:50 -0700 | [diff] [blame] | 423 | mp->m_ddev_targp = xfs_alloc_buftarg(mp, ddev, dax_ddev); |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 424 | if (!mp->m_ddev_targp) |
| 425 | goto out_close_rtdev; |
| 426 | |
| 427 | if (rtdev) { |
Dan Williams | 486aff5 | 2017-08-24 15:12:50 -0700 | [diff] [blame] | 428 | mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev, dax_rtdev); |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 429 | if (!mp->m_rtdev_targp) |
| 430 | goto out_free_ddev_targ; |
| 431 | } |
| 432 | |
| 433 | if (logdev && logdev != ddev) { |
Dan Williams | 486aff5 | 2017-08-24 15:12:50 -0700 | [diff] [blame] | 434 | mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev, dax_logdev); |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 435 | if (!mp->m_logdev_targp) |
| 436 | goto out_free_rtdev_targ; |
| 437 | } else { |
| 438 | mp->m_logdev_targp = mp->m_ddev_targp; |
| 439 | } |
| 440 | |
| 441 | return 0; |
| 442 | |
| 443 | out_free_rtdev_targ: |
| 444 | if (mp->m_rtdev_targp) |
Eric Sandeen | a1f6941 | 2018-04-06 10:09:42 -0700 | [diff] [blame] | 445 | xfs_free_buftarg(mp->m_rtdev_targp); |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 446 | out_free_ddev_targ: |
Eric Sandeen | a1f6941 | 2018-04-06 10:09:42 -0700 | [diff] [blame] | 447 | xfs_free_buftarg(mp->m_ddev_targp); |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 448 | out_close_rtdev: |
Markus Elfring | d2a5e3c | 2014-12-01 08:24:20 +1100 | [diff] [blame] | 449 | xfs_blkdev_put(rtdev); |
Dan Williams | 486aff5 | 2017-08-24 15:12:50 -0700 | [diff] [blame] | 450 | fs_put_dax(dax_rtdev); |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 451 | out_close_logdev: |
Dan Williams | 486aff5 | 2017-08-24 15:12:50 -0700 | [diff] [blame] | 452 | if (logdev && logdev != ddev) { |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 453 | xfs_blkdev_put(logdev); |
Dan Williams | 486aff5 | 2017-08-24 15:12:50 -0700 | [diff] [blame] | 454 | fs_put_dax(dax_logdev); |
| 455 | } |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 456 | out: |
Dan Williams | 486aff5 | 2017-08-24 15:12:50 -0700 | [diff] [blame] | 457 | fs_put_dax(dax_ddev); |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 458 | return error; |
| 459 | } |
| 460 | |
Christoph Hellwig | e34b562 | 2008-05-20 15:10:36 +1000 | [diff] [blame] | 461 | /* |
| 462 | * Setup xfs_mount buffer target pointers based on superblock |
| 463 | */ |
| 464 | STATIC int |
| 465 | xfs_setup_devices( |
| 466 | struct xfs_mount *mp) |
| 467 | { |
| 468 | int error; |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 469 | |
Eric Sandeen | a96c415 | 2014-04-14 19:00:29 +1000 | [diff] [blame] | 470 | error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_sectsize); |
Christoph Hellwig | e34b562 | 2008-05-20 15:10:36 +1000 | [diff] [blame] | 471 | if (error) |
| 472 | return error; |
| 473 | |
| 474 | if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) { |
| 475 | unsigned int log_sector_size = BBSIZE; |
| 476 | |
| 477 | if (xfs_sb_version_hassector(&mp->m_sb)) |
| 478 | log_sector_size = mp->m_sb.sb_logsectsize; |
| 479 | error = xfs_setsize_buftarg(mp->m_logdev_targp, |
Christoph Hellwig | e34b562 | 2008-05-20 15:10:36 +1000 | [diff] [blame] | 480 | log_sector_size); |
| 481 | if (error) |
| 482 | return error; |
| 483 | } |
| 484 | if (mp->m_rtdev_targp) { |
| 485 | error = xfs_setsize_buftarg(mp->m_rtdev_targp, |
Christoph Hellwig | e34b562 | 2008-05-20 15:10:36 +1000 | [diff] [blame] | 486 | mp->m_sb.sb_sectsize); |
| 487 | if (error) |
| 488 | return error; |
| 489 | } |
| 490 | |
| 491 | return 0; |
| 492 | } |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 493 | |
Christoph Hellwig | aa6bf01 | 2012-02-29 09:53:48 +0000 | [diff] [blame] | 494 | STATIC int |
| 495 | xfs_init_mount_workqueues( |
| 496 | struct xfs_mount *mp) |
| 497 | { |
Brian Foster | 78c931b | 2014-11-28 13:59:58 +1100 | [diff] [blame] | 498 | mp->m_buf_workqueue = alloc_workqueue("xfs-buf/%s", |
Darrick J. Wong | 05a302a | 2021-01-22 16:48:42 -0800 | [diff] [blame] | 499 | XFS_WQFLAGS(WQ_FREEZABLE | WQ_MEM_RECLAIM), |
| 500 | 1, mp->m_super->s_id); |
Brian Foster | 78c931b | 2014-11-28 13:59:58 +1100 | [diff] [blame] | 501 | if (!mp->m_buf_workqueue) |
| 502 | goto out; |
| 503 | |
Christoph Hellwig | aa6bf01 | 2012-02-29 09:53:48 +0000 | [diff] [blame] | 504 | mp->m_unwritten_workqueue = alloc_workqueue("xfs-conv/%s", |
Darrick J. Wong | 05a302a | 2021-01-22 16:48:42 -0800 | [diff] [blame] | 505 | XFS_WQFLAGS(WQ_FREEZABLE | WQ_MEM_RECLAIM), |
| 506 | 0, mp->m_super->s_id); |
Christoph Hellwig | aa6bf01 | 2012-02-29 09:53:48 +0000 | [diff] [blame] | 507 | if (!mp->m_unwritten_workqueue) |
Darrick J. Wong | 2840824 | 2019-04-15 13:13:21 -0700 | [diff] [blame] | 508 | goto out_destroy_buf; |
Christoph Hellwig | aa6bf01 | 2012-02-29 09:53:48 +0000 | [diff] [blame] | 509 | |
Dave Chinner | 4c2d542 | 2012-04-23 17:54:32 +1000 | [diff] [blame] | 510 | mp->m_cil_workqueue = alloc_workqueue("xfs-cil/%s", |
Darrick J. Wong | 05a302a | 2021-01-22 16:48:42 -0800 | [diff] [blame] | 511 | XFS_WQFLAGS(WQ_FREEZABLE | WQ_MEM_RECLAIM | WQ_UNBOUND), |
Ian Kent | e1d3d21 | 2019-11-04 13:58:40 -0800 | [diff] [blame] | 512 | 0, mp->m_super->s_id); |
Dave Chinner | 4c2d542 | 2012-04-23 17:54:32 +1000 | [diff] [blame] | 513 | if (!mp->m_cil_workqueue) |
| 514 | goto out_destroy_unwritten; |
Dave Chinner | 5889608 | 2012-10-08 21:56:05 +1100 | [diff] [blame] | 515 | |
| 516 | mp->m_reclaim_workqueue = alloc_workqueue("xfs-reclaim/%s", |
Darrick J. Wong | 05a302a | 2021-01-22 16:48:42 -0800 | [diff] [blame] | 517 | XFS_WQFLAGS(WQ_FREEZABLE | WQ_MEM_RECLAIM), |
| 518 | 0, mp->m_super->s_id); |
Dave Chinner | 5889608 | 2012-10-08 21:56:05 +1100 | [diff] [blame] | 519 | if (!mp->m_reclaim_workqueue) |
| 520 | goto out_destroy_cil; |
| 521 | |
Darrick J. Wong | 9669f51 | 2021-01-22 16:48:43 -0800 | [diff] [blame] | 522 | mp->m_blockgc_workqueue = alloc_workqueue("xfs-blockgc/%s", |
Darrick J. Wong | 47bd6d3 | 2021-01-25 16:39:01 -0800 | [diff] [blame] | 523 | WQ_SYSFS | WQ_UNBOUND | WQ_FREEZABLE | WQ_MEM_RECLAIM, |
Darrick J. Wong | 05a302a | 2021-01-22 16:48:42 -0800 | [diff] [blame] | 524 | 0, mp->m_super->s_id); |
Darrick J. Wong | 9669f51 | 2021-01-22 16:48:43 -0800 | [diff] [blame] | 525 | if (!mp->m_blockgc_workqueue) |
Christoph Hellwig | 1058d0f | 2019-06-28 19:27:25 -0700 | [diff] [blame] | 526 | goto out_destroy_reclaim; |
Brian Foster | 579b62f | 2012-11-06 09:50:47 -0500 | [diff] [blame] | 527 | |
Darrick J. Wong | 05a302a | 2021-01-22 16:48:42 -0800 | [diff] [blame] | 528 | mp->m_sync_workqueue = alloc_workqueue("xfs-sync/%s", |
| 529 | XFS_WQFLAGS(WQ_FREEZABLE), 0, mp->m_super->s_id); |
Brian Foster | 696a562 | 2017-03-28 14:51:44 -0700 | [diff] [blame] | 530 | if (!mp->m_sync_workqueue) |
| 531 | goto out_destroy_eofb; |
| 532 | |
Christoph Hellwig | aa6bf01 | 2012-02-29 09:53:48 +0000 | [diff] [blame] | 533 | return 0; |
| 534 | |
Brian Foster | 696a562 | 2017-03-28 14:51:44 -0700 | [diff] [blame] | 535 | out_destroy_eofb: |
Darrick J. Wong | 9669f51 | 2021-01-22 16:48:43 -0800 | [diff] [blame] | 536 | destroy_workqueue(mp->m_blockgc_workqueue); |
Dave Chinner | 5889608 | 2012-10-08 21:56:05 +1100 | [diff] [blame] | 537 | out_destroy_reclaim: |
| 538 | destroy_workqueue(mp->m_reclaim_workqueue); |
| 539 | out_destroy_cil: |
| 540 | destroy_workqueue(mp->m_cil_workqueue); |
Dave Chinner | 4c2d542 | 2012-04-23 17:54:32 +1000 | [diff] [blame] | 541 | out_destroy_unwritten: |
| 542 | destroy_workqueue(mp->m_unwritten_workqueue); |
Brian Foster | 78c931b | 2014-11-28 13:59:58 +1100 | [diff] [blame] | 543 | out_destroy_buf: |
| 544 | destroy_workqueue(mp->m_buf_workqueue); |
Christoph Hellwig | aa6bf01 | 2012-02-29 09:53:48 +0000 | [diff] [blame] | 545 | out: |
| 546 | return -ENOMEM; |
| 547 | } |
| 548 | |
| 549 | STATIC void |
| 550 | xfs_destroy_mount_workqueues( |
| 551 | struct xfs_mount *mp) |
| 552 | { |
Brian Foster | 696a562 | 2017-03-28 14:51:44 -0700 | [diff] [blame] | 553 | destroy_workqueue(mp->m_sync_workqueue); |
Darrick J. Wong | 9669f51 | 2021-01-22 16:48:43 -0800 | [diff] [blame] | 554 | destroy_workqueue(mp->m_blockgc_workqueue); |
Dave Chinner | 5889608 | 2012-10-08 21:56:05 +1100 | [diff] [blame] | 555 | destroy_workqueue(mp->m_reclaim_workqueue); |
Dave Chinner | 4c2d542 | 2012-04-23 17:54:32 +1000 | [diff] [blame] | 556 | destroy_workqueue(mp->m_cil_workqueue); |
Christoph Hellwig | aa6bf01 | 2012-02-29 09:53:48 +0000 | [diff] [blame] | 557 | destroy_workqueue(mp->m_unwritten_workqueue); |
Brian Foster | 78c931b | 2014-11-28 13:59:58 +1100 | [diff] [blame] | 558 | destroy_workqueue(mp->m_buf_workqueue); |
Christoph Hellwig | aa6bf01 | 2012-02-29 09:53:48 +0000 | [diff] [blame] | 559 | } |
| 560 | |
Darrick J. Wong | f0f7a67 | 2020-04-12 13:11:10 -0700 | [diff] [blame] | 561 | static void |
| 562 | xfs_flush_inodes_worker( |
| 563 | struct work_struct *work) |
| 564 | { |
| 565 | struct xfs_mount *mp = container_of(work, struct xfs_mount, |
| 566 | m_flush_inodes_work); |
| 567 | struct super_block *sb = mp->m_super; |
| 568 | |
| 569 | if (down_read_trylock(&sb->s_umount)) { |
| 570 | sync_inodes_sb(sb); |
| 571 | up_read(&sb->s_umount); |
| 572 | } |
| 573 | } |
| 574 | |
Dave Chinner | 9aa0500 | 2012-10-08 21:56:04 +1100 | [diff] [blame] | 575 | /* |
| 576 | * Flush all dirty data to disk. Must not be called while holding an XFS_ILOCK |
| 577 | * or a page lock. We use sync_inodes_sb() here to ensure we block while waiting |
| 578 | * for IO to complete so that we effectively throttle multiple callers to the |
| 579 | * rate at which IO is completing. |
| 580 | */ |
| 581 | void |
| 582 | xfs_flush_inodes( |
| 583 | struct xfs_mount *mp) |
| 584 | { |
Darrick J. Wong | f0f7a67 | 2020-04-12 13:11:10 -0700 | [diff] [blame] | 585 | /* |
| 586 | * If flush_work() returns true then that means we waited for a flush |
| 587 | * which was already in progress. Don't bother running another scan. |
| 588 | */ |
| 589 | if (flush_work(&mp->m_flush_inodes_work)) |
Darrick J. Wong | c642570 | 2020-03-27 08:49:44 -0700 | [diff] [blame] | 590 | return; |
| 591 | |
Darrick J. Wong | f0f7a67 | 2020-04-12 13:11:10 -0700 | [diff] [blame] | 592 | queue_work(mp->m_sync_workqueue, &mp->m_flush_inodes_work); |
| 593 | flush_work(&mp->m_flush_inodes_work); |
Dave Chinner | 9aa0500 | 2012-10-08 21:56:04 +1100 | [diff] [blame] | 594 | } |
| 595 | |
David Chinner | bf90424 | 2008-10-30 17:36:14 +1100 | [diff] [blame] | 596 | /* Catch misguided souls that try to use this interface on XFS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | STATIC struct inode * |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 598 | xfs_fs_alloc_inode( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | struct super_block *sb) |
| 600 | { |
David Chinner | bf90424 | 2008-10-30 17:36:14 +1100 | [diff] [blame] | 601 | BUG(); |
Lachlan McIlroy | 493dca6 | 2008-10-30 17:36:52 +1100 | [diff] [blame] | 602 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | } |
| 604 | |
Christoph Hellwig | 4831822 | 2018-10-18 17:20:11 +1100 | [diff] [blame] | 605 | #ifdef DEBUG |
| 606 | static void |
| 607 | xfs_check_delalloc( |
| 608 | struct xfs_inode *ip, |
| 609 | int whichfork) |
| 610 | { |
| 611 | struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, whichfork); |
| 612 | struct xfs_bmbt_irec got; |
| 613 | struct xfs_iext_cursor icur; |
| 614 | |
| 615 | if (!ifp || !xfs_iext_lookup_extent(ip, ifp, 0, &icur, &got)) |
| 616 | return; |
| 617 | do { |
| 618 | if (isnullstartblock(got.br_startblock)) { |
| 619 | xfs_warn(ip->i_mount, |
| 620 | "ino %llx %s fork has delalloc extent at [0x%llx:0x%llx]", |
| 621 | ip->i_ino, |
| 622 | whichfork == XFS_DATA_FORK ? "data" : "cow", |
| 623 | got.br_startoff, got.br_blockcount); |
| 624 | } |
| 625 | } while (xfs_iext_next_extent(ifp, &icur, &got)); |
| 626 | } |
| 627 | #else |
| 628 | #define xfs_check_delalloc(ip, whichfork) do { } while (0) |
| 629 | #endif |
| 630 | |
David Chinner | bf90424 | 2008-10-30 17:36:14 +1100 | [diff] [blame] | 631 | /* |
David Chinner | 99fa8cb | 2008-10-30 17:36:40 +1100 | [diff] [blame] | 632 | * Now that the generic code is guaranteed not to be accessing |
Dave Chinner | 8179c03 | 2016-05-18 13:52:42 +1000 | [diff] [blame] | 633 | * the linux inode, we can inactivate and reclaim the inode. |
David Chinner | bf90424 | 2008-10-30 17:36:14 +1100 | [diff] [blame] | 634 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | STATIC void |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 636 | xfs_fs_destroy_inode( |
Christoph Hellwig | 848ce8f | 2009-09-29 13:48:56 +0000 | [diff] [blame] | 637 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | { |
Christoph Hellwig | 848ce8f | 2009-09-29 13:48:56 +0000 | [diff] [blame] | 639 | struct xfs_inode *ip = XFS_I(inode); |
| 640 | |
Christoph Hellwig | cca28fb | 2010-06-24 11:57:09 +1000 | [diff] [blame] | 641 | trace_xfs_destroy_inode(ip); |
David Chinner | 99fa8cb | 2008-10-30 17:36:40 +1100 | [diff] [blame] | 642 | |
Christoph Hellwig | 6552321 | 2016-11-30 14:33:25 +1100 | [diff] [blame] | 643 | ASSERT(!rwsem_is_locked(&inode->i_rwsem)); |
Dave Chinner | 8179c03 | 2016-05-18 13:52:42 +1000 | [diff] [blame] | 644 | XFS_STATS_INC(ip->i_mount, vn_rele); |
| 645 | XFS_STATS_INC(ip->i_mount, vn_remove); |
| 646 | |
| 647 | xfs_inactive(ip); |
Christoph Hellwig | 848ce8f | 2009-09-29 13:48:56 +0000 | [diff] [blame] | 648 | |
Christoph Hellwig | 4831822 | 2018-10-18 17:20:11 +1100 | [diff] [blame] | 649 | if (!XFS_FORCED_SHUTDOWN(ip->i_mount) && ip->i_delayed_blks) { |
| 650 | xfs_check_delalloc(ip, XFS_DATA_FORK); |
| 651 | xfs_check_delalloc(ip, XFS_COW_FORK); |
| 652 | ASSERT(0); |
| 653 | } |
| 654 | |
Dave Chinner | 8179c03 | 2016-05-18 13:52:42 +1000 | [diff] [blame] | 655 | XFS_STATS_INC(ip->i_mount, vn_reclaim); |
Christoph Hellwig | 848ce8f | 2009-09-29 13:48:56 +0000 | [diff] [blame] | 656 | |
| 657 | /* |
| 658 | * We should never get here with one of the reclaim flags already set. |
| 659 | */ |
| 660 | ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIMABLE)); |
| 661 | ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIM)); |
| 662 | |
| 663 | /* |
Dave Chinner | 718ecc5 | 2020-08-17 16:41:01 -0700 | [diff] [blame] | 664 | * We always use background reclaim here because even if the inode is |
| 665 | * clean, it still may be under IO and hence we have wait for IO |
| 666 | * completion to occur before we can reclaim the inode. The background |
| 667 | * reclaim path handles this more efficiently than we can here, so |
| 668 | * simply let background reclaim tear down all inodes. |
Christoph Hellwig | 848ce8f | 2009-09-29 13:48:56 +0000 | [diff] [blame] | 669 | */ |
Dave Chinner | 57817c6 | 2010-01-10 23:51:47 +0000 | [diff] [blame] | 670 | xfs_inode_set_reclaim_tag(ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | } |
| 672 | |
Christoph Hellwig | c3b1b13 | 2018-03-06 17:04:00 -0800 | [diff] [blame] | 673 | static void |
| 674 | xfs_fs_dirty_inode( |
| 675 | struct inode *inode, |
| 676 | int flag) |
| 677 | { |
| 678 | struct xfs_inode *ip = XFS_I(inode); |
| 679 | struct xfs_mount *mp = ip->i_mount; |
| 680 | struct xfs_trans *tp; |
| 681 | |
| 682 | if (!(inode->i_sb->s_flags & SB_LAZYTIME)) |
| 683 | return; |
| 684 | if (flag != I_DIRTY_SYNC || !(inode->i_state & I_DIRTY_TIME)) |
| 685 | return; |
| 686 | |
| 687 | if (xfs_trans_alloc(mp, &M_RES(mp)->tr_fsyncts, 0, 0, 0, &tp)) |
| 688 | return; |
| 689 | xfs_ilock(ip, XFS_ILOCK_EXCL); |
| 690 | xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); |
| 691 | xfs_trans_log_inode(tp, ip, XFS_ILOG_TIMESTAMP); |
| 692 | xfs_trans_commit(tp); |
| 693 | } |
| 694 | |
David Chinner | 07c8f67 | 2008-10-30 16:11:59 +1100 | [diff] [blame] | 695 | /* |
| 696 | * Slab object creation initialisation for the XFS inode. |
| 697 | * This covers only the idempotent fields in the XFS inode; |
| 698 | * all other fields need to be initialised on allocation |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 699 | * from the slab. This avoids the need to repeatedly initialise |
David Chinner | 07c8f67 | 2008-10-30 16:11:59 +1100 | [diff] [blame] | 700 | * fields in the xfs inode that left in the initialise state |
| 701 | * when freeing the inode. |
| 702 | */ |
David Chinner | bf90424 | 2008-10-30 17:36:14 +1100 | [diff] [blame] | 703 | STATIC void |
| 704 | xfs_fs_inode_init_once( |
David Chinner | 07c8f67 | 2008-10-30 16:11:59 +1100 | [diff] [blame] | 705 | void *inode) |
| 706 | { |
| 707 | struct xfs_inode *ip = inode; |
| 708 | |
| 709 | memset(ip, 0, sizeof(struct xfs_inode)); |
David Chinner | bf90424 | 2008-10-30 17:36:14 +1100 | [diff] [blame] | 710 | |
| 711 | /* vfs inode */ |
| 712 | inode_init_once(VFS_I(ip)); |
| 713 | |
| 714 | /* xfs inode */ |
David Chinner | 07c8f67 | 2008-10-30 16:11:59 +1100 | [diff] [blame] | 715 | atomic_set(&ip->i_pincount, 0); |
| 716 | spin_lock_init(&ip->i_flags_lock); |
David Chinner | 07c8f67 | 2008-10-30 16:11:59 +1100 | [diff] [blame] | 717 | |
Dave Chinner | 653c60b | 2015-02-23 21:43:37 +1100 | [diff] [blame] | 718 | mrlock_init(&ip->i_mmaplock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER, |
| 719 | "xfsino", ip->i_ino); |
David Chinner | 07c8f67 | 2008-10-30 16:11:59 +1100 | [diff] [blame] | 720 | mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER, |
| 721 | "xfsino", ip->i_ino); |
David Chinner | 07c8f67 | 2008-10-30 16:11:59 +1100 | [diff] [blame] | 722 | } |
| 723 | |
Dave Chinner | 5132ba8 | 2012-03-22 05:15:10 +0000 | [diff] [blame] | 724 | /* |
| 725 | * We do an unlocked check for XFS_IDONTCACHE here because we are already |
| 726 | * serialised against cache hits here via the inode->i_lock and igrab() in |
| 727 | * xfs_iget_cache_hit(). Hence a lookup that might clear this flag will not be |
| 728 | * racing with us, and it avoids needing to grab a spinlock here for every inode |
| 729 | * we drop the final reference on. |
| 730 | */ |
| 731 | STATIC int |
| 732 | xfs_fs_drop_inode( |
| 733 | struct inode *inode) |
| 734 | { |
| 735 | struct xfs_inode *ip = XFS_I(inode); |
| 736 | |
Darrick J. Wong | 17c12bc | 2016-10-03 09:11:29 -0700 | [diff] [blame] | 737 | /* |
| 738 | * If this unlinked inode is in the middle of recovery, don't |
| 739 | * drop the inode just yet; log recovery will take care of |
| 740 | * that. See the comment for this inode flag. |
| 741 | */ |
| 742 | if (ip->i_flags & XFS_IRECOVERY) { |
| 743 | ASSERT(ip->i_mount->m_log->l_flags & XLOG_RECOVERY_NEEDED); |
| 744 | return 0; |
| 745 | } |
| 746 | |
Ira Weiny | dae2f8e | 2020-04-30 07:41:37 -0700 | [diff] [blame] | 747 | return generic_drop_inode(inode); |
Dave Chinner | 5132ba8 | 2012-03-22 05:15:10 +0000 | [diff] [blame] | 748 | } |
| 749 | |
Ian Kent | a943f37 | 2019-11-04 13:58:42 -0800 | [diff] [blame] | 750 | static void |
| 751 | xfs_mount_free( |
Christoph Hellwig | a738159 | 2008-08-13 16:04:05 +1000 | [diff] [blame] | 752 | struct xfs_mount *mp) |
| 753 | { |
Christoph Hellwig | a738159 | 2008-08-13 16:04:05 +1000 | [diff] [blame] | 754 | kfree(mp->m_rtname); |
| 755 | kfree(mp->m_logname); |
Ian Kent | a943f37 | 2019-11-04 13:58:42 -0800 | [diff] [blame] | 756 | kmem_free(mp); |
Christoph Hellwig | a738159 | 2008-08-13 16:04:05 +1000 | [diff] [blame] | 757 | } |
| 758 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | STATIC int |
Christoph Hellwig | 69961a2 | 2009-10-06 20:29:28 +0000 | [diff] [blame] | 760 | xfs_fs_sync_fs( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | struct super_block *sb, |
| 762 | int wait) |
| 763 | { |
Christoph Hellwig | 745f691 | 2007-08-30 17:20:39 +1000 | [diff] [blame] | 764 | struct xfs_mount *mp = XFS_M(sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | |
Lachlan McIlroy | e893bff | 2007-10-12 11:13:35 +1000 | [diff] [blame] | 766 | /* |
Christoph Hellwig | 34625c6 | 2011-12-06 21:58:12 +0000 | [diff] [blame] | 767 | * Doing anything during the async pass would be counterproductive. |
Lachlan McIlroy | e893bff | 2007-10-12 11:13:35 +1000 | [diff] [blame] | 768 | */ |
Christoph Hellwig | 34625c6 | 2011-12-06 21:58:12 +0000 | [diff] [blame] | 769 | if (!wait) |
Christoph Hellwig | 69961a2 | 2009-10-06 20:29:28 +0000 | [diff] [blame] | 770 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | |
Dave Chinner | 34061f5 | 2012-10-08 21:56:06 +1100 | [diff] [blame] | 772 | xfs_log_force(mp, XFS_LOG_SYNC); |
Christoph Hellwig | 69961a2 | 2009-10-06 20:29:28 +0000 | [diff] [blame] | 773 | if (laptop_mode) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | /* |
| 775 | * The disk must be active because we're syncing. |
Dave Chinner | f661f1e | 2012-10-08 21:56:02 +1100 | [diff] [blame] | 776 | * We schedule log work now (now that the disk is |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | * active) instead of later (when it might not be). |
| 778 | */ |
Dave Chinner | f661f1e | 2012-10-08 21:56:02 +1100 | [diff] [blame] | 779 | flush_delayed_work(&mp->m_log->l_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | } |
| 781 | |
Christoph Hellwig | 69961a2 | 2009-10-06 20:29:28 +0000 | [diff] [blame] | 782 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | STATIC int |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 786 | xfs_fs_statfs( |
David Howells | 726c334 | 2006-06-23 02:02:58 -0700 | [diff] [blame] | 787 | struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | struct kstatfs *statp) |
| 789 | { |
Christoph Hellwig | 4ca488e | 2007-10-11 18:09:40 +1000 | [diff] [blame] | 790 | struct xfs_mount *mp = XFS_M(dentry->d_sb); |
| 791 | xfs_sb_t *sbp = &mp->m_sb; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 792 | struct xfs_inode *ip = XFS_I(d_inode(dentry)); |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 793 | uint64_t fakeinos, id; |
| 794 | uint64_t icount; |
| 795 | uint64_t ifree; |
| 796 | uint64_t fdblocks; |
Christoph Hellwig | 4ca488e | 2007-10-11 18:09:40 +1000 | [diff] [blame] | 797 | xfs_extlen_t lsize; |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 798 | int64_t ffree; |
Christoph Hellwig | 4ca488e | 2007-10-11 18:09:40 +1000 | [diff] [blame] | 799 | |
Adam Borowski | dddde68 | 2018-10-18 17:20:19 +1100 | [diff] [blame] | 800 | statp->f_type = XFS_SUPER_MAGIC; |
Christoph Hellwig | 4ca488e | 2007-10-11 18:09:40 +1000 | [diff] [blame] | 801 | statp->f_namelen = MAXNAMELEN - 1; |
| 802 | |
| 803 | id = huge_encode_dev(mp->m_ddev_targp->bt_dev); |
Al Viro | 6d1349c | 2020-09-18 16:45:50 -0400 | [diff] [blame] | 804 | statp->f_fsid = u64_to_fsid(id); |
Christoph Hellwig | 4ca488e | 2007-10-11 18:09:40 +1000 | [diff] [blame] | 805 | |
Dave Chinner | 501ab32 | 2015-02-23 21:19:28 +1100 | [diff] [blame] | 806 | icount = percpu_counter_sum(&mp->m_icount); |
Dave Chinner | e88b64e | 2015-02-23 21:19:53 +1100 | [diff] [blame] | 807 | ifree = percpu_counter_sum(&mp->m_ifree); |
Dave Chinner | 0d485ad | 2015-02-23 21:22:03 +1100 | [diff] [blame] | 808 | fdblocks = percpu_counter_sum(&mp->m_fdblocks); |
Christoph Hellwig | 4ca488e | 2007-10-11 18:09:40 +1000 | [diff] [blame] | 809 | |
| 810 | spin_lock(&mp->m_sb_lock); |
| 811 | statp->f_bsize = sbp->sb_blocksize; |
| 812 | lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0; |
| 813 | statp->f_blocks = sbp->sb_dblocks - lsize; |
Dave Chinner | 0d485ad | 2015-02-23 21:22:03 +1100 | [diff] [blame] | 814 | spin_unlock(&mp->m_sb_lock); |
| 815 | |
Zheng Bin | 237aac4 | 2020-05-12 11:48:35 -0700 | [diff] [blame] | 816 | /* make sure statp->f_bfree does not underflow */ |
| 817 | statp->f_bfree = max_t(int64_t, fdblocks - mp->m_alloc_set_aside, 0); |
Dave Chinner | 0d485ad | 2015-02-23 21:22:03 +1100 | [diff] [blame] | 818 | statp->f_bavail = statp->f_bfree; |
| 819 | |
Darrick J. Wong | 43004b2 | 2018-12-12 08:46:24 -0800 | [diff] [blame] | 820 | fakeinos = XFS_FSB_TO_INO(mp, statp->f_bfree); |
Dave Chinner | 9bb54cb | 2018-06-07 07:54:02 -0700 | [diff] [blame] | 821 | statp->f_files = min(icount + fakeinos, (uint64_t)XFS_MAXINUMBER); |
Darrick J. Wong | ef32595 | 2019-06-05 11:19:34 -0700 | [diff] [blame] | 822 | if (M_IGEO(mp)->maxicount) |
Christoph Hellwig | a19d9f8 | 2009-03-29 09:51:08 +0200 | [diff] [blame] | 823 | statp->f_files = min_t(typeof(statp->f_files), |
| 824 | statp->f_files, |
Darrick J. Wong | ef32595 | 2019-06-05 11:19:34 -0700 | [diff] [blame] | 825 | M_IGEO(mp)->maxicount); |
Stuart Brodsky | 2fe3366 | 2010-08-24 11:46:05 +1000 | [diff] [blame] | 826 | |
Eric Sandeen | 01f9882 | 2015-02-06 09:53:02 +1100 | [diff] [blame] | 827 | /* If sb_icount overshot maxicount, report actual allocation */ |
| 828 | statp->f_files = max_t(typeof(statp->f_files), |
| 829 | statp->f_files, |
| 830 | sbp->sb_icount); |
| 831 | |
Stuart Brodsky | 2fe3366 | 2010-08-24 11:46:05 +1000 | [diff] [blame] | 832 | /* make sure statp->f_ffree does not underflow */ |
Dave Chinner | e88b64e | 2015-02-23 21:19:53 +1100 | [diff] [blame] | 833 | ffree = statp->f_files - (icount - ifree); |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 834 | statp->f_ffree = max_t(int64_t, ffree, 0); |
Stuart Brodsky | 2fe3366 | 2010-08-24 11:46:05 +1000 | [diff] [blame] | 835 | |
Christoph Hellwig | 4ca488e | 2007-10-11 18:09:40 +1000 | [diff] [blame] | 836 | |
Jie Liu | da5bf95 | 2012-04-12 03:59:57 +0000 | [diff] [blame] | 837 | if ((ip->i_d.di_flags & XFS_DIFLAG_PROJINHERIT) && |
Chandra Seetharaman | 83e782e | 2013-06-27 17:25:10 -0500 | [diff] [blame] | 838 | ((mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))) == |
| 839 | (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD)) |
Christoph Hellwig | 7d09525 | 2009-06-08 15:33:32 +0200 | [diff] [blame] | 840 | xfs_qm_statvfs(ip, statp); |
Richard Wareing | a015831 | 2018-01-08 10:41:33 -0800 | [diff] [blame] | 841 | |
| 842 | if (XFS_IS_REALTIME_MOUNT(mp) && |
| 843 | (ip->i_d.di_flags & (XFS_DIFLAG_RTINHERIT | XFS_DIFLAG_REALTIME))) { |
| 844 | statp->f_blocks = sbp->sb_rblocks; |
| 845 | statp->f_bavail = statp->f_bfree = |
| 846 | sbp->sb_frextents * sbp->sb_rextsize; |
| 847 | } |
| 848 | |
Christoph Hellwig | 4ca488e | 2007-10-11 18:09:40 +1000 | [diff] [blame] | 849 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | } |
| 851 | |
Eric Sandeen | d5db0f9 | 2010-02-05 22:59:53 +0000 | [diff] [blame] | 852 | STATIC void |
| 853 | xfs_save_resvblks(struct xfs_mount *mp) |
| 854 | { |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 855 | uint64_t resblks = 0; |
Eric Sandeen | d5db0f9 | 2010-02-05 22:59:53 +0000 | [diff] [blame] | 856 | |
| 857 | mp->m_resblks_save = mp->m_resblks; |
| 858 | xfs_reserve_blocks(mp, &resblks, NULL); |
| 859 | } |
| 860 | |
| 861 | STATIC void |
| 862 | xfs_restore_resvblks(struct xfs_mount *mp) |
| 863 | { |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 864 | uint64_t resblks; |
Eric Sandeen | d5db0f9 | 2010-02-05 22:59:53 +0000 | [diff] [blame] | 865 | |
| 866 | if (mp->m_resblks_save) { |
| 867 | resblks = mp->m_resblks_save; |
| 868 | mp->m_resblks_save = 0; |
| 869 | } else |
| 870 | resblks = xfs_default_resblks(mp); |
| 871 | |
| 872 | xfs_reserve_blocks(mp, &resblks, NULL); |
| 873 | } |
| 874 | |
Dave Chinner | c7eea6f | 2012-10-08 21:56:07 +1100 | [diff] [blame] | 875 | /* |
Christoph Hellwig | 9909c4a | 2007-10-11 18:11:14 +1000 | [diff] [blame] | 876 | * Second stage of a freeze. The data is already frozen so we only |
Dave Chinner | 61e63ec | 2015-01-22 09:10:31 +1100 | [diff] [blame] | 877 | * need to take care of the metadata. Once that's done sync the superblock |
| 878 | * to the log to dirty it in case of a crash while frozen. This ensures that we |
| 879 | * will recover the unlinked inode lists on the next mount. |
Christoph Hellwig | 9909c4a | 2007-10-11 18:11:14 +1000 | [diff] [blame] | 880 | */ |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 881 | STATIC int |
| 882 | xfs_fs_freeze( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | struct super_block *sb) |
| 884 | { |
Christoph Hellwig | 9909c4a | 2007-10-11 18:11:14 +1000 | [diff] [blame] | 885 | struct xfs_mount *mp = XFS_M(sb); |
Waiman Long | c3f2375 | 2020-07-08 10:21:44 -0700 | [diff] [blame] | 886 | unsigned int flags; |
| 887 | int ret; |
Christoph Hellwig | 9909c4a | 2007-10-11 18:11:14 +1000 | [diff] [blame] | 888 | |
Waiman Long | c3f2375 | 2020-07-08 10:21:44 -0700 | [diff] [blame] | 889 | /* |
| 890 | * The filesystem is now frozen far enough that memory reclaim |
| 891 | * cannot safely operate on the filesystem. Hence we need to |
| 892 | * set a GFP_NOFS context here to avoid recursion deadlocks. |
| 893 | */ |
| 894 | flags = memalloc_nofs_save(); |
Darrick J. Wong | c9a6526 | 2021-01-22 16:48:44 -0800 | [diff] [blame] | 895 | xfs_blockgc_stop(mp); |
Eric Sandeen | d5db0f9 | 2010-02-05 22:59:53 +0000 | [diff] [blame] | 896 | xfs_save_resvblks(mp); |
Brian Foster | 5b0ad7c | 2021-01-22 16:48:24 -0800 | [diff] [blame] | 897 | ret = xfs_log_quiesce(mp); |
Waiman Long | c3f2375 | 2020-07-08 10:21:44 -0700 | [diff] [blame] | 898 | memalloc_nofs_restore(flags); |
| 899 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | STATIC int |
Eric Sandeen | d5db0f9 | 2010-02-05 22:59:53 +0000 | [diff] [blame] | 903 | xfs_fs_unfreeze( |
| 904 | struct super_block *sb) |
| 905 | { |
| 906 | struct xfs_mount *mp = XFS_M(sb); |
| 907 | |
| 908 | xfs_restore_resvblks(mp); |
Dave Chinner | f661f1e | 2012-10-08 21:56:02 +1100 | [diff] [blame] | 909 | xfs_log_work_queue(mp); |
Darrick J. Wong | c9a6526 | 2021-01-22 16:48:44 -0800 | [diff] [blame] | 910 | xfs_blockgc_start(mp); |
Eric Sandeen | d5db0f9 | 2010-02-05 22:59:53 +0000 | [diff] [blame] | 911 | return 0; |
| 912 | } |
| 913 | |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 914 | /* |
| 915 | * This function fills in xfs_mount_t fields based on mount args. |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 916 | * Note: the superblock _has_ now been read in. |
| 917 | */ |
| 918 | STATIC int |
| 919 | xfs_finish_flags( |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 920 | struct xfs_mount *mp) |
| 921 | { |
| 922 | int ronly = (mp->m_flags & XFS_MOUNT_RDONLY); |
| 923 | |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 924 | /* Fail a mount where the logbuf is smaller than the log stripe */ |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 925 | if (xfs_sb_version_haslogv2(&mp->m_sb)) { |
Christoph Hellwig | 9d565ff | 2008-10-30 17:53:24 +1100 | [diff] [blame] | 926 | if (mp->m_logbsize <= 0 && |
| 927 | mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE) { |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 928 | mp->m_logbsize = mp->m_sb.sb_logsunit; |
Christoph Hellwig | 9d565ff | 2008-10-30 17:53:24 +1100 | [diff] [blame] | 929 | } else if (mp->m_logbsize > 0 && |
| 930 | mp->m_logbsize < mp->m_sb.sb_logsunit) { |
Dave Chinner | 4f10700 | 2011-03-07 10:00:35 +1100 | [diff] [blame] | 931 | xfs_warn(mp, |
| 932 | "logbuf size must be greater than or equal to log stripe size"); |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 933 | return -EINVAL; |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 934 | } |
| 935 | } else { |
| 936 | /* Fail a mount if the logbuf is larger than 32K */ |
Christoph Hellwig | 9d565ff | 2008-10-30 17:53:24 +1100 | [diff] [blame] | 937 | if (mp->m_logbsize > XLOG_BIG_RECORD_BSIZE) { |
Dave Chinner | 4f10700 | 2011-03-07 10:00:35 +1100 | [diff] [blame] | 938 | xfs_warn(mp, |
| 939 | "logbuf size for version 1 logs must be 16K or 32K"); |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 940 | return -EINVAL; |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 941 | } |
| 942 | } |
| 943 | |
| 944 | /* |
Dave Chinner | d3eaace | 2013-06-05 12:09:09 +1000 | [diff] [blame] | 945 | * V5 filesystems always use attr2 format for attributes. |
| 946 | */ |
| 947 | if (xfs_sb_version_hascrc(&mp->m_sb) && |
| 948 | (mp->m_flags & XFS_MOUNT_NOATTR2)) { |
Eric Sandeen | 2e74af0 | 2016-03-02 09:55:38 +1100 | [diff] [blame] | 949 | xfs_warn(mp, "Cannot mount a V5 filesystem as noattr2. " |
| 950 | "attr2 is always enabled for V5 filesystems."); |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 951 | return -EINVAL; |
Dave Chinner | d3eaace | 2013-06-05 12:09:09 +1000 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | /* |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 955 | * mkfs'ed attr2 will turn on attr2 mount unless explicitly |
| 956 | * told by noattr2 to turn it off |
| 957 | */ |
| 958 | if (xfs_sb_version_hasattr2(&mp->m_sb) && |
Christoph Hellwig | 9d565ff | 2008-10-30 17:53:24 +1100 | [diff] [blame] | 959 | !(mp->m_flags & XFS_MOUNT_NOATTR2)) |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 960 | mp->m_flags |= XFS_MOUNT_ATTR2; |
| 961 | |
| 962 | /* |
| 963 | * prohibit r/w mounts of read-only filesystems |
| 964 | */ |
| 965 | if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) { |
Dave Chinner | 4f10700 | 2011-03-07 10:00:35 +1100 | [diff] [blame] | 966 | xfs_warn(mp, |
| 967 | "cannot mount a read-only filesystem as read-write"); |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 968 | return -EROFS; |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 969 | } |
| 970 | |
Chandra Seetharaman | d892d58 | 2013-07-19 17:36:02 -0500 | [diff] [blame] | 971 | if ((mp->m_qflags & (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE)) && |
| 972 | (mp->m_qflags & (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE)) && |
| 973 | !xfs_sb_version_has_pquotino(&mp->m_sb)) { |
| 974 | xfs_warn(mp, |
| 975 | "Super block does not support project and group quota together"); |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 976 | return -EINVAL; |
Chandra Seetharaman | d892d58 | 2013-07-19 17:36:02 -0500 | [diff] [blame] | 977 | } |
| 978 | |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 979 | return 0; |
| 980 | } |
| 981 | |
Dave Chinner | 5681ca4 | 2015-02-23 21:22:31 +1100 | [diff] [blame] | 982 | static int |
| 983 | xfs_init_percpu_counters( |
| 984 | struct xfs_mount *mp) |
| 985 | { |
| 986 | int error; |
| 987 | |
| 988 | error = percpu_counter_init(&mp->m_icount, 0, GFP_KERNEL); |
| 989 | if (error) |
Joe Perches | 5e9383f | 2015-03-25 15:00:24 +1100 | [diff] [blame] | 990 | return -ENOMEM; |
Dave Chinner | 5681ca4 | 2015-02-23 21:22:31 +1100 | [diff] [blame] | 991 | |
| 992 | error = percpu_counter_init(&mp->m_ifree, 0, GFP_KERNEL); |
| 993 | if (error) |
| 994 | goto free_icount; |
| 995 | |
| 996 | error = percpu_counter_init(&mp->m_fdblocks, 0, GFP_KERNEL); |
| 997 | if (error) |
| 998 | goto free_ifree; |
| 999 | |
Darrick J. Wong | 9fe82b8 | 2019-04-25 18:26:22 -0700 | [diff] [blame] | 1000 | error = percpu_counter_init(&mp->m_delalloc_blks, 0, GFP_KERNEL); |
| 1001 | if (error) |
| 1002 | goto free_fdblocks; |
| 1003 | |
Dave Chinner | 5681ca4 | 2015-02-23 21:22:31 +1100 | [diff] [blame] | 1004 | return 0; |
| 1005 | |
Darrick J. Wong | 9fe82b8 | 2019-04-25 18:26:22 -0700 | [diff] [blame] | 1006 | free_fdblocks: |
| 1007 | percpu_counter_destroy(&mp->m_fdblocks); |
Dave Chinner | 5681ca4 | 2015-02-23 21:22:31 +1100 | [diff] [blame] | 1008 | free_ifree: |
| 1009 | percpu_counter_destroy(&mp->m_ifree); |
| 1010 | free_icount: |
| 1011 | percpu_counter_destroy(&mp->m_icount); |
| 1012 | return -ENOMEM; |
| 1013 | } |
| 1014 | |
| 1015 | void |
| 1016 | xfs_reinit_percpu_counters( |
| 1017 | struct xfs_mount *mp) |
| 1018 | { |
| 1019 | percpu_counter_set(&mp->m_icount, mp->m_sb.sb_icount); |
| 1020 | percpu_counter_set(&mp->m_ifree, mp->m_sb.sb_ifree); |
| 1021 | percpu_counter_set(&mp->m_fdblocks, mp->m_sb.sb_fdblocks); |
| 1022 | } |
| 1023 | |
| 1024 | static void |
| 1025 | xfs_destroy_percpu_counters( |
| 1026 | struct xfs_mount *mp) |
| 1027 | { |
| 1028 | percpu_counter_destroy(&mp->m_icount); |
| 1029 | percpu_counter_destroy(&mp->m_ifree); |
| 1030 | percpu_counter_destroy(&mp->m_fdblocks); |
Darrick J. Wong | 9fe82b8 | 2019-04-25 18:26:22 -0700 | [diff] [blame] | 1031 | ASSERT(XFS_FORCED_SHUTDOWN(mp) || |
| 1032 | percpu_counter_sum(&mp->m_delalloc_blks) == 0); |
| 1033 | percpu_counter_destroy(&mp->m_delalloc_blks); |
Dave Chinner | 5681ca4 | 2015-02-23 21:22:31 +1100 | [diff] [blame] | 1034 | } |
| 1035 | |
Ian Kent | 2f8d66b | 2019-11-04 13:58:47 -0800 | [diff] [blame] | 1036 | static void |
| 1037 | xfs_fs_put_super( |
| 1038 | struct super_block *sb) |
| 1039 | { |
| 1040 | struct xfs_mount *mp = XFS_M(sb); |
| 1041 | |
| 1042 | /* if ->fill_super failed, we have no mount to tear down */ |
| 1043 | if (!sb->s_fs_info) |
| 1044 | return; |
| 1045 | |
| 1046 | xfs_notice(mp, "Unmounting Filesystem"); |
| 1047 | xfs_filestream_unmount(mp); |
| 1048 | xfs_unmountfs(mp); |
| 1049 | |
| 1050 | xfs_freesb(mp); |
| 1051 | free_percpu(mp->m_stats.xs_stats); |
| 1052 | xfs_destroy_percpu_counters(mp); |
| 1053 | xfs_destroy_mount_workqueues(mp); |
| 1054 | xfs_close_devices(mp); |
| 1055 | |
| 1056 | sb->s_fs_info = NULL; |
| 1057 | xfs_mount_free(mp); |
| 1058 | } |
| 1059 | |
| 1060 | static long |
| 1061 | xfs_fs_nr_cached_objects( |
| 1062 | struct super_block *sb, |
| 1063 | struct shrink_control *sc) |
| 1064 | { |
| 1065 | /* Paranoia: catch incorrect calls during mount setup or teardown */ |
| 1066 | if (WARN_ON_ONCE(!sb->s_fs_info)) |
| 1067 | return 0; |
| 1068 | return xfs_reclaim_inodes_count(XFS_M(sb)); |
| 1069 | } |
| 1070 | |
| 1071 | static long |
| 1072 | xfs_fs_free_cached_objects( |
| 1073 | struct super_block *sb, |
| 1074 | struct shrink_control *sc) |
| 1075 | { |
| 1076 | return xfs_reclaim_inodes_nr(XFS_M(sb), sc->nr_to_scan); |
| 1077 | } |
| 1078 | |
| 1079 | static const struct super_operations xfs_super_operations = { |
| 1080 | .alloc_inode = xfs_fs_alloc_inode, |
| 1081 | .destroy_inode = xfs_fs_destroy_inode, |
| 1082 | .dirty_inode = xfs_fs_dirty_inode, |
| 1083 | .drop_inode = xfs_fs_drop_inode, |
| 1084 | .put_super = xfs_fs_put_super, |
| 1085 | .sync_fs = xfs_fs_sync_fs, |
| 1086 | .freeze_fs = xfs_fs_freeze, |
| 1087 | .unfreeze_fs = xfs_fs_unfreeze, |
| 1088 | .statfs = xfs_fs_statfs, |
| 1089 | .show_options = xfs_fs_show_options, |
| 1090 | .nr_cached_objects = xfs_fs_nr_cached_objects, |
| 1091 | .free_cached_objects = xfs_fs_free_cached_objects, |
| 1092 | }; |
| 1093 | |
Ian Kent | 73e5fff | 2019-11-04 13:58:46 -0800 | [diff] [blame] | 1094 | static int |
Ian Kent | 8757c38 | 2019-11-04 13:58:48 -0800 | [diff] [blame] | 1095 | suffix_kstrtoint( |
| 1096 | const char *s, |
| 1097 | unsigned int base, |
| 1098 | int *res) |
| 1099 | { |
| 1100 | int last, shift_left_factor = 0, _res; |
| 1101 | char *value; |
| 1102 | int ret = 0; |
| 1103 | |
| 1104 | value = kstrdup(s, GFP_KERNEL); |
| 1105 | if (!value) |
| 1106 | return -ENOMEM; |
| 1107 | |
| 1108 | last = strlen(value) - 1; |
| 1109 | if (value[last] == 'K' || value[last] == 'k') { |
| 1110 | shift_left_factor = 10; |
| 1111 | value[last] = '\0'; |
| 1112 | } |
| 1113 | if (value[last] == 'M' || value[last] == 'm') { |
| 1114 | shift_left_factor = 20; |
| 1115 | value[last] = '\0'; |
| 1116 | } |
| 1117 | if (value[last] == 'G' || value[last] == 'g') { |
| 1118 | shift_left_factor = 30; |
| 1119 | value[last] = '\0'; |
| 1120 | } |
| 1121 | |
| 1122 | if (kstrtoint(value, base, &_res)) |
| 1123 | ret = -EINVAL; |
| 1124 | kfree(value); |
| 1125 | *res = _res << shift_left_factor; |
| 1126 | return ret; |
| 1127 | } |
| 1128 | |
| 1129 | /* |
| 1130 | * Set mount state from a mount option. |
| 1131 | * |
| 1132 | * NOTE: mp->m_super is NULL here! |
| 1133 | */ |
| 1134 | static int |
Darrick J. Wong | 1e5c39d | 2020-12-04 15:59:39 -0800 | [diff] [blame] | 1135 | xfs_fs_parse_param( |
Ian Kent | 8757c38 | 2019-11-04 13:58:48 -0800 | [diff] [blame] | 1136 | struct fs_context *fc, |
| 1137 | struct fs_parameter *param) |
| 1138 | { |
| 1139 | struct xfs_mount *mp = fc->s_fs_info; |
| 1140 | struct fs_parse_result result; |
| 1141 | int size = 0; |
| 1142 | int opt; |
| 1143 | |
Al Viro | d7167b1 | 2019-09-07 07:23:15 -0400 | [diff] [blame] | 1144 | opt = fs_parse(fc, xfs_fs_parameters, param, &result); |
Ian Kent | 8757c38 | 2019-11-04 13:58:48 -0800 | [diff] [blame] | 1145 | if (opt < 0) |
| 1146 | return opt; |
| 1147 | |
| 1148 | switch (opt) { |
| 1149 | case Opt_logbufs: |
| 1150 | mp->m_logbufs = result.uint_32; |
| 1151 | return 0; |
| 1152 | case Opt_logbsize: |
| 1153 | if (suffix_kstrtoint(param->string, 10, &mp->m_logbsize)) |
| 1154 | return -EINVAL; |
| 1155 | return 0; |
| 1156 | case Opt_logdev: |
| 1157 | kfree(mp->m_logname); |
| 1158 | mp->m_logname = kstrdup(param->string, GFP_KERNEL); |
| 1159 | if (!mp->m_logname) |
| 1160 | return -ENOMEM; |
| 1161 | return 0; |
| 1162 | case Opt_rtdev: |
| 1163 | kfree(mp->m_rtname); |
| 1164 | mp->m_rtname = kstrdup(param->string, GFP_KERNEL); |
| 1165 | if (!mp->m_rtname) |
| 1166 | return -ENOMEM; |
| 1167 | return 0; |
| 1168 | case Opt_allocsize: |
| 1169 | if (suffix_kstrtoint(param->string, 10, &size)) |
| 1170 | return -EINVAL; |
| 1171 | mp->m_allocsize_log = ffs(size) - 1; |
| 1172 | mp->m_flags |= XFS_MOUNT_ALLOCSIZE; |
| 1173 | return 0; |
| 1174 | case Opt_grpid: |
| 1175 | case Opt_bsdgroups: |
| 1176 | mp->m_flags |= XFS_MOUNT_GRPID; |
| 1177 | return 0; |
| 1178 | case Opt_nogrpid: |
| 1179 | case Opt_sysvgroups: |
| 1180 | mp->m_flags &= ~XFS_MOUNT_GRPID; |
| 1181 | return 0; |
| 1182 | case Opt_wsync: |
| 1183 | mp->m_flags |= XFS_MOUNT_WSYNC; |
| 1184 | return 0; |
| 1185 | case Opt_norecovery: |
| 1186 | mp->m_flags |= XFS_MOUNT_NORECOVERY; |
| 1187 | return 0; |
| 1188 | case Opt_noalign: |
| 1189 | mp->m_flags |= XFS_MOUNT_NOALIGN; |
| 1190 | return 0; |
| 1191 | case Opt_swalloc: |
| 1192 | mp->m_flags |= XFS_MOUNT_SWALLOC; |
| 1193 | return 0; |
| 1194 | case Opt_sunit: |
| 1195 | mp->m_dalign = result.uint_32; |
| 1196 | return 0; |
| 1197 | case Opt_swidth: |
| 1198 | mp->m_swidth = result.uint_32; |
| 1199 | return 0; |
| 1200 | case Opt_inode32: |
| 1201 | mp->m_flags |= XFS_MOUNT_SMALL_INUMS; |
| 1202 | return 0; |
| 1203 | case Opt_inode64: |
| 1204 | mp->m_flags &= ~XFS_MOUNT_SMALL_INUMS; |
| 1205 | return 0; |
| 1206 | case Opt_nouuid: |
| 1207 | mp->m_flags |= XFS_MOUNT_NOUUID; |
| 1208 | return 0; |
Ian Kent | 8757c38 | 2019-11-04 13:58:48 -0800 | [diff] [blame] | 1209 | case Opt_largeio: |
| 1210 | mp->m_flags |= XFS_MOUNT_LARGEIO; |
| 1211 | return 0; |
| 1212 | case Opt_nolargeio: |
| 1213 | mp->m_flags &= ~XFS_MOUNT_LARGEIO; |
| 1214 | return 0; |
Ian Kent | 8757c38 | 2019-11-04 13:58:48 -0800 | [diff] [blame] | 1215 | case Opt_filestreams: |
| 1216 | mp->m_flags |= XFS_MOUNT_FILESTREAMS; |
| 1217 | return 0; |
| 1218 | case Opt_noquota: |
| 1219 | mp->m_qflags &= ~XFS_ALL_QUOTA_ACCT; |
| 1220 | mp->m_qflags &= ~XFS_ALL_QUOTA_ENFD; |
| 1221 | mp->m_qflags &= ~XFS_ALL_QUOTA_ACTIVE; |
| 1222 | return 0; |
| 1223 | case Opt_quota: |
| 1224 | case Opt_uquota: |
| 1225 | case Opt_usrquota: |
| 1226 | mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE | |
| 1227 | XFS_UQUOTA_ENFD); |
| 1228 | return 0; |
| 1229 | case Opt_qnoenforce: |
| 1230 | case Opt_uqnoenforce: |
| 1231 | mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE); |
| 1232 | mp->m_qflags &= ~XFS_UQUOTA_ENFD; |
| 1233 | return 0; |
| 1234 | case Opt_pquota: |
| 1235 | case Opt_prjquota: |
| 1236 | mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE | |
| 1237 | XFS_PQUOTA_ENFD); |
| 1238 | return 0; |
| 1239 | case Opt_pqnoenforce: |
| 1240 | mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE); |
| 1241 | mp->m_qflags &= ~XFS_PQUOTA_ENFD; |
| 1242 | return 0; |
| 1243 | case Opt_gquota: |
| 1244 | case Opt_grpquota: |
| 1245 | mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE | |
| 1246 | XFS_GQUOTA_ENFD); |
| 1247 | return 0; |
| 1248 | case Opt_gqnoenforce: |
| 1249 | mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE); |
| 1250 | mp->m_qflags &= ~XFS_GQUOTA_ENFD; |
| 1251 | return 0; |
| 1252 | case Opt_discard: |
| 1253 | mp->m_flags |= XFS_MOUNT_DISCARD; |
| 1254 | return 0; |
| 1255 | case Opt_nodiscard: |
| 1256 | mp->m_flags &= ~XFS_MOUNT_DISCARD; |
| 1257 | return 0; |
| 1258 | #ifdef CONFIG_FS_DAX |
| 1259 | case Opt_dax: |
Ira Weiny | 8d6c344 | 2020-05-04 09:02:42 -0700 | [diff] [blame] | 1260 | xfs_mount_set_dax_mode(mp, XFS_DAX_ALWAYS); |
| 1261 | return 0; |
| 1262 | case Opt_dax_enum: |
| 1263 | xfs_mount_set_dax_mode(mp, result.uint_32); |
Ian Kent | 8757c38 | 2019-11-04 13:58:48 -0800 | [diff] [blame] | 1264 | return 0; |
| 1265 | #endif |
Pavel Reichl | c23c393 | 2020-09-25 11:10:29 -0700 | [diff] [blame] | 1266 | /* Following mount options will be removed in September 2025 */ |
| 1267 | case Opt_ikeep: |
| 1268 | xfs_warn(mp, "%s mount option is deprecated.", param->key); |
| 1269 | mp->m_flags |= XFS_MOUNT_IKEEP; |
| 1270 | return 0; |
| 1271 | case Opt_noikeep: |
| 1272 | xfs_warn(mp, "%s mount option is deprecated.", param->key); |
| 1273 | mp->m_flags &= ~XFS_MOUNT_IKEEP; |
| 1274 | return 0; |
| 1275 | case Opt_attr2: |
| 1276 | xfs_warn(mp, "%s mount option is deprecated.", param->key); |
| 1277 | mp->m_flags |= XFS_MOUNT_ATTR2; |
| 1278 | return 0; |
| 1279 | case Opt_noattr2: |
| 1280 | xfs_warn(mp, "%s mount option is deprecated.", param->key); |
| 1281 | mp->m_flags &= ~XFS_MOUNT_ATTR2; |
| 1282 | mp->m_flags |= XFS_MOUNT_NOATTR2; |
| 1283 | return 0; |
Ian Kent | 8757c38 | 2019-11-04 13:58:48 -0800 | [diff] [blame] | 1284 | default: |
| 1285 | xfs_warn(mp, "unknown mount option [%s].", param->key); |
| 1286 | return -EINVAL; |
| 1287 | } |
| 1288 | |
| 1289 | return 0; |
| 1290 | } |
| 1291 | |
| 1292 | static int |
Darrick J. Wong | 1e5c39d | 2020-12-04 15:59:39 -0800 | [diff] [blame] | 1293 | xfs_fs_validate_params( |
Ian Kent | 8757c38 | 2019-11-04 13:58:48 -0800 | [diff] [blame] | 1294 | struct xfs_mount *mp) |
| 1295 | { |
| 1296 | /* |
| 1297 | * no recovery flag requires a read-only mount |
| 1298 | */ |
| 1299 | if ((mp->m_flags & XFS_MOUNT_NORECOVERY) && |
| 1300 | !(mp->m_flags & XFS_MOUNT_RDONLY)) { |
| 1301 | xfs_warn(mp, "no-recovery mounts must be read-only."); |
| 1302 | return -EINVAL; |
| 1303 | } |
| 1304 | |
| 1305 | if ((mp->m_flags & XFS_MOUNT_NOALIGN) && |
| 1306 | (mp->m_dalign || mp->m_swidth)) { |
| 1307 | xfs_warn(mp, |
| 1308 | "sunit and swidth options incompatible with the noalign option"); |
| 1309 | return -EINVAL; |
| 1310 | } |
| 1311 | |
| 1312 | if (!IS_ENABLED(CONFIG_XFS_QUOTA) && mp->m_qflags != 0) { |
| 1313 | xfs_warn(mp, "quota support not available in this kernel."); |
| 1314 | return -EINVAL; |
| 1315 | } |
| 1316 | |
| 1317 | if ((mp->m_dalign && !mp->m_swidth) || |
| 1318 | (!mp->m_dalign && mp->m_swidth)) { |
| 1319 | xfs_warn(mp, "sunit and swidth must be specified together"); |
| 1320 | return -EINVAL; |
| 1321 | } |
| 1322 | |
| 1323 | if (mp->m_dalign && (mp->m_swidth % mp->m_dalign != 0)) { |
| 1324 | xfs_warn(mp, |
| 1325 | "stripe width (%d) must be a multiple of the stripe unit (%d)", |
| 1326 | mp->m_swidth, mp->m_dalign); |
| 1327 | return -EINVAL; |
| 1328 | } |
| 1329 | |
| 1330 | if (mp->m_logbufs != -1 && |
| 1331 | mp->m_logbufs != 0 && |
| 1332 | (mp->m_logbufs < XLOG_MIN_ICLOGS || |
| 1333 | mp->m_logbufs > XLOG_MAX_ICLOGS)) { |
| 1334 | xfs_warn(mp, "invalid logbufs value: %d [not %d-%d]", |
| 1335 | mp->m_logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS); |
| 1336 | return -EINVAL; |
| 1337 | } |
| 1338 | |
| 1339 | if (mp->m_logbsize != -1 && |
| 1340 | mp->m_logbsize != 0 && |
| 1341 | (mp->m_logbsize < XLOG_MIN_RECORD_BSIZE || |
| 1342 | mp->m_logbsize > XLOG_MAX_RECORD_BSIZE || |
| 1343 | !is_power_of_2(mp->m_logbsize))) { |
| 1344 | xfs_warn(mp, |
| 1345 | "invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]", |
| 1346 | mp->m_logbsize); |
| 1347 | return -EINVAL; |
| 1348 | } |
| 1349 | |
| 1350 | if ((mp->m_flags & XFS_MOUNT_ALLOCSIZE) && |
| 1351 | (mp->m_allocsize_log > XFS_MAX_IO_LOG || |
| 1352 | mp->m_allocsize_log < XFS_MIN_IO_LOG)) { |
| 1353 | xfs_warn(mp, "invalid log iosize: %d [not %d-%d]", |
| 1354 | mp->m_allocsize_log, XFS_MIN_IO_LOG, XFS_MAX_IO_LOG); |
| 1355 | return -EINVAL; |
| 1356 | } |
| 1357 | |
| 1358 | return 0; |
| 1359 | } |
| 1360 | |
| 1361 | static int |
Darrick J. Wong | 1e5c39d | 2020-12-04 15:59:39 -0800 | [diff] [blame] | 1362 | xfs_fs_fill_super( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1363 | struct super_block *sb, |
Ian Kent | 73e5fff | 2019-11-04 13:58:46 -0800 | [diff] [blame] | 1364 | struct fs_context *fc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | { |
Ian Kent | 73e5fff | 2019-11-04 13:58:46 -0800 | [diff] [blame] | 1366 | struct xfs_mount *mp = sb->s_fs_info; |
Christoph Hellwig | f3dcc13 | 2008-03-27 18:00:54 +1100 | [diff] [blame] | 1367 | struct inode *root; |
Colin Ian King | 0279c71 | 2019-11-06 08:07:46 -0800 | [diff] [blame] | 1368 | int flags = 0, error; |
Christoph Hellwig | bdd907b | 2008-05-20 15:10:44 +1000 | [diff] [blame] | 1369 | |
Ian Kent | 7c89fcb | 2019-11-04 13:58:46 -0800 | [diff] [blame] | 1370 | mp->m_super = sb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 | |
Darrick J. Wong | 1e5c39d | 2020-12-04 15:59:39 -0800 | [diff] [blame] | 1372 | error = xfs_fs_validate_params(mp); |
Christoph Hellwig | 745f691 | 2007-08-30 17:20:39 +1000 | [diff] [blame] | 1373 | if (error) |
Ian Kent | e1d3d21 | 2019-11-04 13:58:40 -0800 | [diff] [blame] | 1374 | goto out_free_names; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1375 | |
| 1376 | sb_min_blocksize(sb, BBSIZE); |
Lachlan McIlroy | 0ec5851 | 2008-06-23 13:23:01 +1000 | [diff] [blame] | 1377 | sb->s_xattr = xfs_xattr_handlers; |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1378 | sb->s_export_op = &xfs_export_operations; |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 1379 | #ifdef CONFIG_XFS_QUOTA |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1380 | sb->s_qcop = &xfs_quotactl_operations; |
Jan Kara | 17ef4fd | 2014-09-30 22:35:33 +0200 | [diff] [blame] | 1381 | sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ; |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 1382 | #endif |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1383 | sb->s_op = &xfs_super_operations; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1384 | |
Dave Chinner | dae5cd8 | 2018-05-10 21:50:23 -0700 | [diff] [blame] | 1385 | /* |
| 1386 | * Delay mount work if the debug hook is set. This is debug |
| 1387 | * instrumention to coordinate simulation of xfs mount failures with |
| 1388 | * VFS superblock operations |
| 1389 | */ |
| 1390 | if (xfs_globals.mount_delay) { |
| 1391 | xfs_notice(mp, "Delaying mount for %d seconds.", |
| 1392 | xfs_globals.mount_delay); |
| 1393 | msleep(xfs_globals.mount_delay * 1000); |
| 1394 | } |
| 1395 | |
Ian Kent | 73e5fff | 2019-11-04 13:58:46 -0800 | [diff] [blame] | 1396 | if (fc->sb_flags & SB_SILENT) |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 1397 | flags |= XFS_MFSI_QUIET; |
| 1398 | |
Christoph Hellwig | 9d565ff | 2008-10-30 17:53:24 +1100 | [diff] [blame] | 1399 | error = xfs_open_devices(mp); |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 1400 | if (error) |
Ian Kent | e1d3d21 | 2019-11-04 13:58:40 -0800 | [diff] [blame] | 1401 | goto out_free_names; |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 1402 | |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 1403 | error = xfs_init_mount_workqueues(mp); |
Christoph Hellwig | 61ba35d | 2010-09-30 02:25:54 +0000 | [diff] [blame] | 1404 | if (error) |
| 1405 | goto out_close_devices; |
Christoph Hellwig | c962fb7 | 2008-05-20 15:10:52 +1000 | [diff] [blame] | 1406 | |
Dave Chinner | 5681ca4 | 2015-02-23 21:22:31 +1100 | [diff] [blame] | 1407 | error = xfs_init_percpu_counters(mp); |
Christoph Hellwig | aa6bf01 | 2012-02-29 09:53:48 +0000 | [diff] [blame] | 1408 | if (error) |
| 1409 | goto out_destroy_workqueues; |
| 1410 | |
Bill O'Donnell | 225e463 | 2015-10-12 18:21:19 +1100 | [diff] [blame] | 1411 | /* Allocate stats memory before we do operations that might use it */ |
| 1412 | mp->m_stats.xs_stats = alloc_percpu(struct xfsstats); |
| 1413 | if (!mp->m_stats.xs_stats) { |
Dan Carpenter | f9d460b | 2015-10-19 08:42:47 +1100 | [diff] [blame] | 1414 | error = -ENOMEM; |
Bill O'Donnell | 225e463 | 2015-10-12 18:21:19 +1100 | [diff] [blame] | 1415 | goto out_destroy_counters; |
| 1416 | } |
| 1417 | |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 1418 | error = xfs_readsb(mp, flags); |
| 1419 | if (error) |
Bill O'Donnell | 225e463 | 2015-10-12 18:21:19 +1100 | [diff] [blame] | 1420 | goto out_free_stats; |
Christoph Hellwig | 9d565ff | 2008-10-30 17:53:24 +1100 | [diff] [blame] | 1421 | |
| 1422 | error = xfs_finish_flags(mp); |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 1423 | if (error) |
Christoph Hellwig | effa2ed | 2008-05-20 15:11:05 +1000 | [diff] [blame] | 1424 | goto out_free_sb; |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 1425 | |
Christoph Hellwig | e34b562 | 2008-05-20 15:10:36 +1000 | [diff] [blame] | 1426 | error = xfs_setup_devices(mp); |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 1427 | if (error) |
Christoph Hellwig | effa2ed | 2008-05-20 15:11:05 +1000 | [diff] [blame] | 1428 | goto out_free_sb; |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 1429 | |
Darrick J. Wong | b96cb83 | 2020-09-10 10:57:17 -0700 | [diff] [blame] | 1430 | /* V4 support is undergoing deprecation. */ |
| 1431 | if (!xfs_sb_version_hascrc(&mp->m_sb)) { |
| 1432 | #ifdef CONFIG_XFS_SUPPORT_V4 |
| 1433 | xfs_warn_once(mp, |
| 1434 | "Deprecated V4 format (crc=0) will not be supported after September 2030."); |
| 1435 | #else |
| 1436 | xfs_warn(mp, |
| 1437 | "Deprecated V4 format (crc=0) not supported by kernel."); |
| 1438 | error = -EINVAL; |
| 1439 | goto out_free_sb; |
| 1440 | #endif |
| 1441 | } |
| 1442 | |
Darrick J. Wong | 80c720b | 2020-11-24 11:45:55 -0800 | [diff] [blame] | 1443 | /* Filesystem claims it needs repair, so refuse the mount. */ |
| 1444 | if (xfs_sb_version_needsrepair(&mp->m_sb)) { |
| 1445 | xfs_warn(mp, "Filesystem needs repair. Please run xfs_repair."); |
| 1446 | error = -EFSCORRUPTED; |
| 1447 | goto out_free_sb; |
| 1448 | } |
| 1449 | |
Darrick J. Wong | 932befe | 2020-01-02 13:20:13 -0800 | [diff] [blame] | 1450 | /* |
Darrick J. Wong | 3945ae0 | 2020-11-24 11:45:54 -0800 | [diff] [blame] | 1451 | * Don't touch the filesystem if a user tool thinks it owns the primary |
| 1452 | * superblock. mkfs doesn't clear the flag from secondary supers, so |
| 1453 | * we don't check them at all. |
| 1454 | */ |
| 1455 | if (mp->m_sb.sb_inprogress) { |
| 1456 | xfs_warn(mp, "Offline file system operation in progress!"); |
| 1457 | error = -EFSCORRUPTED; |
| 1458 | goto out_free_sb; |
| 1459 | } |
| 1460 | |
| 1461 | /* |
| 1462 | * Until this is fixed only page-sized or smaller data blocks work. |
| 1463 | */ |
| 1464 | if (mp->m_sb.sb_blocksize > PAGE_SIZE) { |
| 1465 | xfs_warn(mp, |
| 1466 | "File system with blocksize %d bytes. " |
| 1467 | "Only pagesize (%ld) or less will currently work.", |
| 1468 | mp->m_sb.sb_blocksize, PAGE_SIZE); |
| 1469 | error = -ENOSYS; |
| 1470 | goto out_free_sb; |
| 1471 | } |
| 1472 | |
| 1473 | /* Ensure this filesystem fits in the page cache limits */ |
| 1474 | if (xfs_sb_validate_fsb_count(&mp->m_sb, mp->m_sb.sb_dblocks) || |
| 1475 | xfs_sb_validate_fsb_count(&mp->m_sb, mp->m_sb.sb_rblocks)) { |
| 1476 | xfs_warn(mp, |
| 1477 | "file system too large to be mounted on this system."); |
| 1478 | error = -EFBIG; |
| 1479 | goto out_free_sb; |
| 1480 | } |
| 1481 | |
| 1482 | /* |
Darrick J. Wong | 932befe | 2020-01-02 13:20:13 -0800 | [diff] [blame] | 1483 | * XFS block mappings use 54 bits to store the logical block offset. |
| 1484 | * This should suffice to handle the maximum file size that the VFS |
| 1485 | * supports (currently 2^63 bytes on 64-bit and ULONG_MAX << PAGE_SHIFT |
| 1486 | * bytes on 32-bit), but as XFS and VFS have gotten the s_maxbytes |
| 1487 | * calculation wrong on 32-bit kernels in the past, we'll add a WARN_ON |
| 1488 | * to check this assertion. |
| 1489 | * |
| 1490 | * Avoid integer overflow by comparing the maximum bmbt offset to the |
| 1491 | * maximum pagecache offset in units of fs blocks. |
| 1492 | */ |
Darrick J. Wong | 33005fd | 2020-12-04 13:28:35 -0800 | [diff] [blame] | 1493 | if (!xfs_verify_fileoff(mp, XFS_B_TO_FSBT(mp, MAX_LFS_FILESIZE))) { |
Darrick J. Wong | 932befe | 2020-01-02 13:20:13 -0800 | [diff] [blame] | 1494 | xfs_warn(mp, |
| 1495 | "MAX_LFS_FILESIZE block offset (%llu) exceeds extent map maximum (%llu)!", |
| 1496 | XFS_B_TO_FSBT(mp, MAX_LFS_FILESIZE), |
| 1497 | XFS_MAX_FILEOFF); |
| 1498 | error = -EINVAL; |
| 1499 | goto out_free_sb; |
| 1500 | } |
| 1501 | |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 1502 | error = xfs_filestream_mount(mp); |
| 1503 | if (error) |
Christoph Hellwig | effa2ed | 2008-05-20 15:11:05 +1000 | [diff] [blame] | 1504 | goto out_free_sb; |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 1505 | |
Dave Chinner | 704b290 | 2011-03-26 09:14:57 +1100 | [diff] [blame] | 1506 | /* |
| 1507 | * we must configure the block size in the superblock before we run the |
| 1508 | * full mount process as the mount process can lookup and cache inodes. |
Dave Chinner | 704b290 | 2011-03-26 09:14:57 +1100 | [diff] [blame] | 1509 | */ |
Adam Borowski | dddde68 | 2018-10-18 17:20:19 +1100 | [diff] [blame] | 1510 | sb->s_magic = XFS_SUPER_MAGIC; |
Christoph Hellwig | 4ca488e | 2007-10-11 18:09:40 +1000 | [diff] [blame] | 1511 | sb->s_blocksize = mp->m_sb.sb_blocksize; |
| 1512 | sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1; |
Darrick J. Wong | 932befe | 2020-01-02 13:20:13 -0800 | [diff] [blame] | 1513 | sb->s_maxbytes = MAX_LFS_FILESIZE; |
Al Viro | 8de5277 | 2012-02-06 12:45:27 -0500 | [diff] [blame] | 1514 | sb->s_max_links = XFS_MAXLINK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1515 | sb->s_time_gran = 1; |
Darrick J. Wong | f93e5436 | 2020-08-17 09:59:07 -0700 | [diff] [blame] | 1516 | if (xfs_sb_version_hasbigtime(&mp->m_sb)) { |
| 1517 | sb->s_time_min = xfs_bigtime_to_unix(XFS_BIGTIME_TIME_MIN); |
| 1518 | sb->s_time_max = xfs_bigtime_to_unix(XFS_BIGTIME_TIME_MAX); |
| 1519 | } else { |
| 1520 | sb->s_time_min = XFS_LEGACY_TIME_MIN; |
| 1521 | sb->s_time_max = XFS_LEGACY_TIME_MAX; |
| 1522 | } |
Darrick J. Wong | 06dbf82 | 2020-08-24 11:58:01 -0700 | [diff] [blame] | 1523 | trace_xfs_inode_timestamp_range(mp, sb->s_time_min, sb->s_time_max); |
Christoph Hellwig | adfb5fb | 2019-06-28 19:30:22 -0700 | [diff] [blame] | 1524 | sb->s_iflags |= SB_I_CGROUPWB; |
| 1525 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | set_posix_acl_flag(sb); |
| 1527 | |
Dave Chinner | dc037ad | 2013-06-27 16:04:59 +1000 | [diff] [blame] | 1528 | /* version 5 superblocks support inode version counters. */ |
| 1529 | if (XFS_SB_VERSION_NUM(&mp->m_sb) == XFS_SB_VERSION_5) |
Matthew Garrett | 357fdad | 2017-10-18 13:56:26 -0700 | [diff] [blame] | 1530 | sb->s_flags |= SB_I_VERSION; |
Dave Chinner | dc037ad | 2013-06-27 16:04:59 +1000 | [diff] [blame] | 1531 | |
Darrick J. Wong | f93e5436 | 2020-08-17 09:59:07 -0700 | [diff] [blame] | 1532 | if (xfs_sb_version_hasbigtime(&mp->m_sb)) |
| 1533 | xfs_warn(mp, |
| 1534 | "EXPERIMENTAL big timestamp feature in use. Use at your own risk!"); |
| 1535 | |
Ira Weiny | 606723d | 2020-05-04 09:02:41 -0700 | [diff] [blame] | 1536 | if (mp->m_flags & XFS_MOUNT_DAX_ALWAYS) { |
Dave Jiang | 80660f2 | 2018-05-30 13:03:46 -0700 | [diff] [blame] | 1537 | bool rtdev_is_dax = false, datadev_is_dax; |
Darrick J. Wong | ba23cba | 2018-05-30 13:03:45 -0700 | [diff] [blame] | 1538 | |
Dave Chinner | cbe4dab | 2015-06-04 09:19:18 +1000 | [diff] [blame] | 1539 | xfs_warn(mp, |
Toshi Kani | 1e937cd | 2016-05-10 10:23:56 -0600 | [diff] [blame] | 1540 | "DAX enabled. Warning: EXPERIMENTAL, use at your own risk"); |
| 1541 | |
Dave Jiang | 80660f2 | 2018-05-30 13:03:46 -0700 | [diff] [blame] | 1542 | datadev_is_dax = bdev_dax_supported(mp->m_ddev_targp->bt_bdev, |
| 1543 | sb->s_blocksize); |
Darrick J. Wong | ba23cba | 2018-05-30 13:03:45 -0700 | [diff] [blame] | 1544 | if (mp->m_rtdev_targp) |
Dave Jiang | 80660f2 | 2018-05-30 13:03:46 -0700 | [diff] [blame] | 1545 | rtdev_is_dax = bdev_dax_supported( |
| 1546 | mp->m_rtdev_targp->bt_bdev, sb->s_blocksize); |
| 1547 | if (!rtdev_is_dax && !datadev_is_dax) { |
Dave Chinner | cbe4dab | 2015-06-04 09:19:18 +1000 | [diff] [blame] | 1548 | xfs_alert(mp, |
Toshi Kani | 1e937cd | 2016-05-10 10:23:56 -0600 | [diff] [blame] | 1549 | "DAX unsupported by block device. Turning off DAX."); |
Ira Weiny | 8d6c344 | 2020-05-04 09:02:42 -0700 | [diff] [blame] | 1550 | xfs_mount_set_dax_mode(mp, XFS_DAX_NEVER); |
Dave Chinner | cbe4dab | 2015-06-04 09:19:18 +1000 | [diff] [blame] | 1551 | } |
Darrick J. Wong | b6e03c1 | 2018-01-31 14:21:56 -0800 | [diff] [blame] | 1552 | if (xfs_sb_version_hasreflink(&mp->m_sb)) { |
Darrick J. Wong | e54b5bf | 2016-10-03 09:11:52 -0700 | [diff] [blame] | 1553 | xfs_alert(mp, |
Christoph Hellwig | 1e369b0 | 2018-01-08 13:30:08 -0800 | [diff] [blame] | 1554 | "DAX and reflink cannot be used together!"); |
Darrick J. Wong | b6e03c1 | 2018-01-31 14:21:56 -0800 | [diff] [blame] | 1555 | error = -EINVAL; |
| 1556 | goto out_filestream_unmount; |
| 1557 | } |
Dave Chinner | cbe4dab | 2015-06-04 09:19:18 +1000 | [diff] [blame] | 1558 | } |
| 1559 | |
Kenjiro Nakayama | 1e6fa68 | 2017-09-18 12:03:56 -0700 | [diff] [blame] | 1560 | if (mp->m_flags & XFS_MOUNT_DISCARD) { |
| 1561 | struct request_queue *q = bdev_get_queue(sb->s_bdev); |
| 1562 | |
| 1563 | if (!blk_queue_discard(q)) { |
| 1564 | xfs_warn(mp, "mounting with \"discard\" option, but " |
| 1565 | "the device does not support discard"); |
| 1566 | mp->m_flags &= ~XFS_MOUNT_DISCARD; |
| 1567 | } |
| 1568 | } |
| 1569 | |
Christoph Hellwig | 66ae56a | 2019-02-18 09:38:49 -0800 | [diff] [blame] | 1570 | if (xfs_sb_version_hasreflink(&mp->m_sb)) { |
| 1571 | if (mp->m_sb.sb_rblocks) { |
| 1572 | xfs_alert(mp, |
Darrick J. Wong | c14632d | 2018-01-31 16:38:18 -0800 | [diff] [blame] | 1573 | "reflink not compatible with realtime device!"); |
Christoph Hellwig | 66ae56a | 2019-02-18 09:38:49 -0800 | [diff] [blame] | 1574 | error = -EINVAL; |
| 1575 | goto out_filestream_unmount; |
| 1576 | } |
| 1577 | |
| 1578 | if (xfs_globals.always_cow) { |
| 1579 | xfs_info(mp, "using DEBUG-only always_cow mode."); |
| 1580 | mp->m_always_cow = true; |
| 1581 | } |
Darrick J. Wong | c14632d | 2018-01-31 16:38:18 -0800 | [diff] [blame] | 1582 | } |
| 1583 | |
Darrick J. Wong | 76883f7 | 2018-01-31 09:47:25 -0800 | [diff] [blame] | 1584 | if (xfs_sb_version_hasrmapbt(&mp->m_sb) && mp->m_sb.sb_rblocks) { |
Darrick J. Wong | 1c0607a | 2016-08-03 12:20:57 +1000 | [diff] [blame] | 1585 | xfs_alert(mp, |
Darrick J. Wong | 76883f7 | 2018-01-31 09:47:25 -0800 | [diff] [blame] | 1586 | "reverse mapping btree not compatible with realtime device!"); |
| 1587 | error = -EINVAL; |
| 1588 | goto out_filestream_unmount; |
Darrick J. Wong | 738f57c | 2016-08-26 15:59:19 +1000 | [diff] [blame] | 1589 | } |
Darrick J. Wong | 1c0607a | 2016-08-03 12:20:57 +1000 | [diff] [blame] | 1590 | |
Darrick J. Wong | 2a39946 | 2020-08-17 09:58:01 -0700 | [diff] [blame] | 1591 | if (xfs_sb_version_hasinobtcounts(&mp->m_sb)) |
| 1592 | xfs_warn(mp, |
| 1593 | "EXPERIMENTAL inode btree counters feature in use. Use at your own risk!"); |
| 1594 | |
Dave Chinner | 8a00ebe | 2012-04-13 12:10:44 +0000 | [diff] [blame] | 1595 | error = xfs_mountfs(mp); |
Christoph Hellwig | 2bcf6e9 | 2011-07-13 13:43:48 +0200 | [diff] [blame] | 1596 | if (error) |
Dave Chinner | 7e18530 | 2012-10-08 21:56:00 +1100 | [diff] [blame] | 1597 | goto out_filestream_unmount; |
Dave Chinner | 704b290 | 2011-03-26 09:14:57 +1100 | [diff] [blame] | 1598 | |
David Chinner | 0165164 | 2008-08-13 15:45:15 +1000 | [diff] [blame] | 1599 | root = igrab(VFS_I(mp->m_rootip)); |
Christoph Hellwig | f3dcc13 | 2008-03-27 18:00:54 +1100 | [diff] [blame] | 1600 | if (!root) { |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 1601 | error = -ENOENT; |
Dave Chinner | 8a00ebe | 2012-04-13 12:10:44 +0000 | [diff] [blame] | 1602 | goto out_unmount; |
Christoph Hellwig | cbc89dc | 2008-02-05 12:14:01 +1100 | [diff] [blame] | 1603 | } |
Al Viro | 48fde70 | 2012-01-08 22:15:13 -0500 | [diff] [blame] | 1604 | sb->s_root = d_make_root(root); |
Christoph Hellwig | f3dcc13 | 2008-03-27 18:00:54 +1100 | [diff] [blame] | 1605 | if (!sb->s_root) { |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 1606 | error = -ENOMEM; |
Dave Chinner | 8a00ebe | 2012-04-13 12:10:44 +0000 | [diff] [blame] | 1607 | goto out_unmount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1608 | } |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1609 | |
Dave Chinner | 7e18530 | 2012-10-08 21:56:00 +1100 | [diff] [blame] | 1610 | return 0; |
| 1611 | |
| 1612 | out_filestream_unmount: |
Christoph Hellwig | 120226c | 2008-05-20 15:11:11 +1000 | [diff] [blame] | 1613 | xfs_filestream_unmount(mp); |
Christoph Hellwig | effa2ed | 2008-05-20 15:11:05 +1000 | [diff] [blame] | 1614 | out_free_sb: |
| 1615 | xfs_freesb(mp); |
Bill O'Donnell | 225e463 | 2015-10-12 18:21:19 +1100 | [diff] [blame] | 1616 | out_free_stats: |
| 1617 | free_percpu(mp->m_stats.xs_stats); |
Christoph Hellwig | 9d565ff | 2008-10-30 17:53:24 +1100 | [diff] [blame] | 1618 | out_destroy_counters: |
Dave Chinner | 5681ca4 | 2015-02-23 21:22:31 +1100 | [diff] [blame] | 1619 | xfs_destroy_percpu_counters(mp); |
Bill O'Donnell | 225e463 | 2015-10-12 18:21:19 +1100 | [diff] [blame] | 1620 | out_destroy_workqueues: |
Christoph Hellwig | aa6bf01 | 2012-02-29 09:53:48 +0000 | [diff] [blame] | 1621 | xfs_destroy_mount_workqueues(mp); |
Christoph Hellwig | 61ba35d | 2010-09-30 02:25:54 +0000 | [diff] [blame] | 1622 | out_close_devices: |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 1623 | xfs_close_devices(mp); |
Ian Kent | e1d3d21 | 2019-11-04 13:58:40 -0800 | [diff] [blame] | 1624 | out_free_names: |
Dave Chinner | c9fbd7b | 2018-05-10 21:50:23 -0700 | [diff] [blame] | 1625 | sb->s_fs_info = NULL; |
Ian Kent | a943f37 | 2019-11-04 13:58:42 -0800 | [diff] [blame] | 1626 | xfs_mount_free(mp); |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 1627 | return error; |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 1628 | |
Christoph Hellwig | 2bcf6e9 | 2011-07-13 13:43:48 +0200 | [diff] [blame] | 1629 | out_unmount: |
Christoph Hellwig | e48ad316 | 2008-05-20 11:30:52 +1000 | [diff] [blame] | 1630 | xfs_filestream_unmount(mp); |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 1631 | xfs_unmountfs(mp); |
Christoph Hellwig | 6203300 | 2008-08-13 16:50:21 +1000 | [diff] [blame] | 1632 | goto out_free_sb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1633 | } |
| 1634 | |
Ian Kent | 73e5fff | 2019-11-04 13:58:46 -0800 | [diff] [blame] | 1635 | static int |
Darrick J. Wong | 1e5c39d | 2020-12-04 15:59:39 -0800 | [diff] [blame] | 1636 | xfs_fs_get_tree( |
Ian Kent | 73e5fff | 2019-11-04 13:58:46 -0800 | [diff] [blame] | 1637 | struct fs_context *fc) |
| 1638 | { |
Darrick J. Wong | 1e5c39d | 2020-12-04 15:59:39 -0800 | [diff] [blame] | 1639 | return get_tree_bdev(fc, xfs_fs_fill_super); |
Ian Kent | 73e5fff | 2019-11-04 13:58:46 -0800 | [diff] [blame] | 1640 | } |
| 1641 | |
Ian Kent | 63cd1e9 | 2019-11-04 13:58:47 -0800 | [diff] [blame] | 1642 | static int |
| 1643 | xfs_remount_rw( |
| 1644 | struct xfs_mount *mp) |
| 1645 | { |
| 1646 | struct xfs_sb *sbp = &mp->m_sb; |
| 1647 | int error; |
| 1648 | |
| 1649 | if (mp->m_flags & XFS_MOUNT_NORECOVERY) { |
| 1650 | xfs_warn(mp, |
| 1651 | "ro->rw transition prohibited on norecovery mount"); |
| 1652 | return -EINVAL; |
| 1653 | } |
| 1654 | |
| 1655 | if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 && |
| 1656 | xfs_sb_has_ro_compat_feature(sbp, XFS_SB_FEAT_RO_COMPAT_UNKNOWN)) { |
| 1657 | xfs_warn(mp, |
| 1658 | "ro->rw transition prohibited on unknown (0x%x) ro-compat filesystem", |
| 1659 | (sbp->sb_features_ro_compat & |
| 1660 | XFS_SB_FEAT_RO_COMPAT_UNKNOWN)); |
| 1661 | return -EINVAL; |
| 1662 | } |
| 1663 | |
| 1664 | mp->m_flags &= ~XFS_MOUNT_RDONLY; |
| 1665 | |
| 1666 | /* |
| 1667 | * If this is the first remount to writeable state we might have some |
| 1668 | * superblock changes to update. |
| 1669 | */ |
| 1670 | if (mp->m_update_sb) { |
| 1671 | error = xfs_sync_sb(mp, false); |
| 1672 | if (error) { |
| 1673 | xfs_warn(mp, "failed to write sb changes"); |
| 1674 | return error; |
| 1675 | } |
| 1676 | mp->m_update_sb = false; |
| 1677 | } |
| 1678 | |
| 1679 | /* |
| 1680 | * Fill out the reserve pool if it is empty. Use the stashed value if |
| 1681 | * it is non-zero, otherwise go with the default. |
| 1682 | */ |
| 1683 | xfs_restore_resvblks(mp); |
| 1684 | xfs_log_work_queue(mp); |
| 1685 | |
| 1686 | /* Recover any CoW blocks that never got remapped. */ |
| 1687 | error = xfs_reflink_recover_cow(mp); |
| 1688 | if (error) { |
| 1689 | xfs_err(mp, |
| 1690 | "Error %d recovering leftover CoW allocations.", error); |
Dan Carpenter | 7f6bcf7 | 2019-11-08 08:06:36 -0800 | [diff] [blame] | 1691 | xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE); |
Ian Kent | 63cd1e9 | 2019-11-04 13:58:47 -0800 | [diff] [blame] | 1692 | return error; |
| 1693 | } |
Darrick J. Wong | c9a6526 | 2021-01-22 16:48:44 -0800 | [diff] [blame] | 1694 | xfs_blockgc_start(mp); |
Ian Kent | 63cd1e9 | 2019-11-04 13:58:47 -0800 | [diff] [blame] | 1695 | |
| 1696 | /* Create the per-AG metadata reservation pool .*/ |
| 1697 | error = xfs_fs_reserve_ag_blocks(mp); |
| 1698 | if (error && error != -ENOSPC) |
| 1699 | return error; |
| 1700 | |
| 1701 | return 0; |
| 1702 | } |
| 1703 | |
| 1704 | static int |
| 1705 | xfs_remount_ro( |
| 1706 | struct xfs_mount *mp) |
| 1707 | { |
| 1708 | int error; |
| 1709 | |
| 1710 | /* |
| 1711 | * Cancel background eofb scanning so it cannot race with the final |
| 1712 | * log force+buftarg wait and deadlock the remount. |
| 1713 | */ |
Darrick J. Wong | c9a6526 | 2021-01-22 16:48:44 -0800 | [diff] [blame] | 1714 | xfs_blockgc_stop(mp); |
Ian Kent | 63cd1e9 | 2019-11-04 13:58:47 -0800 | [diff] [blame] | 1715 | |
| 1716 | /* Get rid of any leftover CoW reservations... */ |
Darrick J. Wong | b943c0c | 2021-01-22 16:48:40 -0800 | [diff] [blame] | 1717 | error = xfs_blockgc_free_space(mp, NULL); |
Ian Kent | 63cd1e9 | 2019-11-04 13:58:47 -0800 | [diff] [blame] | 1718 | if (error) { |
| 1719 | xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE); |
| 1720 | return error; |
| 1721 | } |
| 1722 | |
| 1723 | /* Free the per-AG metadata reservation pool. */ |
| 1724 | error = xfs_fs_unreserve_ag_blocks(mp); |
| 1725 | if (error) { |
| 1726 | xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE); |
| 1727 | return error; |
| 1728 | } |
| 1729 | |
| 1730 | /* |
| 1731 | * Before we sync the metadata, we need to free up the reserve block |
| 1732 | * pool so that the used block count in the superblock on disk is |
| 1733 | * correct at the end of the remount. Stash the current* reserve pool |
| 1734 | * size so that if we get remounted rw, we can return it to the same |
| 1735 | * size. |
| 1736 | */ |
| 1737 | xfs_save_resvblks(mp); |
| 1738 | |
Brian Foster | ea2064d | 2021-01-22 16:48:24 -0800 | [diff] [blame] | 1739 | xfs_log_clean(mp); |
Ian Kent | 63cd1e9 | 2019-11-04 13:58:47 -0800 | [diff] [blame] | 1740 | mp->m_flags |= XFS_MOUNT_RDONLY; |
| 1741 | |
| 1742 | return 0; |
| 1743 | } |
| 1744 | |
| 1745 | /* |
| 1746 | * Logically we would return an error here to prevent users from believing |
| 1747 | * they might have changed mount options using remount which can't be changed. |
| 1748 | * |
| 1749 | * But unfortunately mount(8) adds all options from mtab and fstab to the mount |
| 1750 | * arguments in some cases so we can't blindly reject options, but have to |
| 1751 | * check for each specified option if it actually differs from the currently |
| 1752 | * set option and only reject it if that's the case. |
| 1753 | * |
| 1754 | * Until that is implemented we return success for every remount request, and |
| 1755 | * silently ignore all options that we can't actually change. |
| 1756 | */ |
| 1757 | static int |
Darrick J. Wong | 1e5c39d | 2020-12-04 15:59:39 -0800 | [diff] [blame] | 1758 | xfs_fs_reconfigure( |
Ian Kent | 63cd1e9 | 2019-11-04 13:58:47 -0800 | [diff] [blame] | 1759 | struct fs_context *fc) |
| 1760 | { |
| 1761 | struct xfs_mount *mp = XFS_M(fc->root->d_sb); |
| 1762 | struct xfs_mount *new_mp = fc->s_fs_info; |
| 1763 | xfs_sb_t *sbp = &mp->m_sb; |
| 1764 | int flags = fc->sb_flags; |
| 1765 | int error; |
| 1766 | |
Eric Sandeen | 4750a17 | 2020-07-15 08:30:37 -0700 | [diff] [blame] | 1767 | /* version 5 superblocks always support version counters. */ |
| 1768 | if (XFS_SB_VERSION_NUM(&mp->m_sb) == XFS_SB_VERSION_5) |
| 1769 | fc->sb_flags |= SB_I_VERSION; |
| 1770 | |
Darrick J. Wong | 1e5c39d | 2020-12-04 15:59:39 -0800 | [diff] [blame] | 1771 | error = xfs_fs_validate_params(new_mp); |
Ian Kent | 63cd1e9 | 2019-11-04 13:58:47 -0800 | [diff] [blame] | 1772 | if (error) |
| 1773 | return error; |
| 1774 | |
| 1775 | sync_filesystem(mp->m_super); |
| 1776 | |
| 1777 | /* inode32 -> inode64 */ |
| 1778 | if ((mp->m_flags & XFS_MOUNT_SMALL_INUMS) && |
| 1779 | !(new_mp->m_flags & XFS_MOUNT_SMALL_INUMS)) { |
| 1780 | mp->m_flags &= ~XFS_MOUNT_SMALL_INUMS; |
| 1781 | mp->m_maxagi = xfs_set_inode_alloc(mp, sbp->sb_agcount); |
| 1782 | } |
| 1783 | |
| 1784 | /* inode64 -> inode32 */ |
| 1785 | if (!(mp->m_flags & XFS_MOUNT_SMALL_INUMS) && |
| 1786 | (new_mp->m_flags & XFS_MOUNT_SMALL_INUMS)) { |
| 1787 | mp->m_flags |= XFS_MOUNT_SMALL_INUMS; |
| 1788 | mp->m_maxagi = xfs_set_inode_alloc(mp, sbp->sb_agcount); |
| 1789 | } |
| 1790 | |
| 1791 | /* ro -> rw */ |
| 1792 | if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(flags & SB_RDONLY)) { |
| 1793 | error = xfs_remount_rw(mp); |
| 1794 | if (error) |
| 1795 | return error; |
| 1796 | } |
| 1797 | |
| 1798 | /* rw -> ro */ |
| 1799 | if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (flags & SB_RDONLY)) { |
| 1800 | error = xfs_remount_ro(mp); |
| 1801 | if (error) |
| 1802 | return error; |
| 1803 | } |
| 1804 | |
| 1805 | return 0; |
| 1806 | } |
| 1807 | |
Darrick J. Wong | 1e5c39d | 2020-12-04 15:59:39 -0800 | [diff] [blame] | 1808 | static void xfs_fs_free( |
Ian Kent | 73e5fff | 2019-11-04 13:58:46 -0800 | [diff] [blame] | 1809 | struct fs_context *fc) |
| 1810 | { |
| 1811 | struct xfs_mount *mp = fc->s_fs_info; |
| 1812 | |
| 1813 | /* |
| 1814 | * mp is stored in the fs_context when it is initialized. |
| 1815 | * mp is transferred to the superblock on a successful mount, |
| 1816 | * but if an error occurs before the transfer we have to free |
| 1817 | * it here. |
| 1818 | */ |
| 1819 | if (mp) |
| 1820 | xfs_mount_free(mp); |
| 1821 | } |
| 1822 | |
| 1823 | static const struct fs_context_operations xfs_context_ops = { |
Darrick J. Wong | 1e5c39d | 2020-12-04 15:59:39 -0800 | [diff] [blame] | 1824 | .parse_param = xfs_fs_parse_param, |
| 1825 | .get_tree = xfs_fs_get_tree, |
| 1826 | .reconfigure = xfs_fs_reconfigure, |
| 1827 | .free = xfs_fs_free, |
Ian Kent | 73e5fff | 2019-11-04 13:58:46 -0800 | [diff] [blame] | 1828 | }; |
| 1829 | |
| 1830 | static int xfs_init_fs_context( |
| 1831 | struct fs_context *fc) |
| 1832 | { |
| 1833 | struct xfs_mount *mp; |
| 1834 | |
Ian Kent | 50f8300 | 2019-11-04 13:58:48 -0800 | [diff] [blame] | 1835 | mp = kmem_alloc(sizeof(struct xfs_mount), KM_ZERO); |
Ian Kent | 73e5fff | 2019-11-04 13:58:46 -0800 | [diff] [blame] | 1836 | if (!mp) |
| 1837 | return -ENOMEM; |
| 1838 | |
Ian Kent | 50f8300 | 2019-11-04 13:58:48 -0800 | [diff] [blame] | 1839 | spin_lock_init(&mp->m_sb_lock); |
| 1840 | spin_lock_init(&mp->m_agirotor_lock); |
| 1841 | INIT_RADIX_TREE(&mp->m_perag_tree, GFP_ATOMIC); |
| 1842 | spin_lock_init(&mp->m_perag_lock); |
| 1843 | mutex_init(&mp->m_growlock); |
Darrick J. Wong | f0f7a67 | 2020-04-12 13:11:10 -0700 | [diff] [blame] | 1844 | INIT_WORK(&mp->m_flush_inodes_work, xfs_flush_inodes_worker); |
Ian Kent | 50f8300 | 2019-11-04 13:58:48 -0800 | [diff] [blame] | 1845 | INIT_DELAYED_WORK(&mp->m_reclaim_work, xfs_reclaim_worker); |
Ian Kent | 50f8300 | 2019-11-04 13:58:48 -0800 | [diff] [blame] | 1846 | mp->m_kobj.kobject.kset = xfs_kset; |
| 1847 | /* |
| 1848 | * We don't create the finobt per-ag space reservation until after log |
| 1849 | * recovery, so we must set this to true so that an ifree transaction |
| 1850 | * started during log recovery will not depend on space reservations |
| 1851 | * for finobt expansion. |
| 1852 | */ |
| 1853 | mp->m_finobt_nores = true; |
| 1854 | |
Ian Kent | 73e5fff | 2019-11-04 13:58:46 -0800 | [diff] [blame] | 1855 | /* |
| 1856 | * These can be overridden by the mount option parsing. |
| 1857 | */ |
| 1858 | mp->m_logbufs = -1; |
| 1859 | mp->m_logbsize = -1; |
| 1860 | mp->m_allocsize_log = 16; /* 64k */ |
| 1861 | |
| 1862 | /* |
| 1863 | * Copy binary VFS mount flags we are interested in. |
| 1864 | */ |
| 1865 | if (fc->sb_flags & SB_RDONLY) |
| 1866 | mp->m_flags |= XFS_MOUNT_RDONLY; |
| 1867 | if (fc->sb_flags & SB_DIRSYNC) |
| 1868 | mp->m_flags |= XFS_MOUNT_DIRSYNC; |
| 1869 | if (fc->sb_flags & SB_SYNCHRONOUS) |
| 1870 | mp->m_flags |= XFS_MOUNT_WSYNC; |
| 1871 | |
| 1872 | fc->s_fs_info = mp; |
| 1873 | fc->ops = &xfs_context_ops; |
| 1874 | |
| 1875 | return 0; |
| 1876 | } |
| 1877 | |
Andrew Morton | 5085b60 | 2007-02-20 13:57:47 -0800 | [diff] [blame] | 1878 | static struct file_system_type xfs_fs_type = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | .owner = THIS_MODULE, |
| 1880 | .name = "xfs", |
Ian Kent | 73e5fff | 2019-11-04 13:58:46 -0800 | [diff] [blame] | 1881 | .init_fs_context = xfs_init_fs_context, |
Al Viro | d7167b1 | 2019-09-07 07:23:15 -0400 | [diff] [blame] | 1882 | .parameters = xfs_fs_parameters, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1883 | .kill_sb = kill_block_super, |
Christoph Hellwig | f736d93 | 2021-01-21 14:19:58 +0100 | [diff] [blame] | 1884 | .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1885 | }; |
Eric W. Biederman | 7f78e03 | 2013-03-02 19:39:14 -0800 | [diff] [blame] | 1886 | MODULE_ALIAS_FS("xfs"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1887 | |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 1888 | STATIC int __init |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 1889 | xfs_init_zones(void) |
| 1890 | { |
Carlos Maiolino | b123176 | 2019-11-14 12:43:03 -0800 | [diff] [blame] | 1891 | xfs_log_ticket_zone = kmem_cache_create("xfs_log_ticket", |
| 1892 | sizeof(struct xlog_ticket), |
| 1893 | 0, 0, NULL); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 1894 | if (!xfs_log_ticket_zone) |
Christoph Hellwig | 598ecfb | 2019-10-17 13:12:15 -0700 | [diff] [blame] | 1895 | goto out; |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 1896 | |
Carlos Maiolino | b123176 | 2019-11-14 12:43:03 -0800 | [diff] [blame] | 1897 | xfs_bmap_free_item_zone = kmem_cache_create("xfs_bmap_free_item", |
| 1898 | sizeof(struct xfs_extent_free_item), |
| 1899 | 0, 0, NULL); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 1900 | if (!xfs_bmap_free_item_zone) |
| 1901 | goto out_destroy_log_ticket_zone; |
David Chinner | bf90424 | 2008-10-30 17:36:14 +1100 | [diff] [blame] | 1902 | |
Carlos Maiolino | b123176 | 2019-11-14 12:43:03 -0800 | [diff] [blame] | 1903 | xfs_btree_cur_zone = kmem_cache_create("xfs_btree_cur", |
| 1904 | sizeof(struct xfs_btree_cur), |
| 1905 | 0, 0, NULL); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 1906 | if (!xfs_btree_cur_zone) |
| 1907 | goto out_destroy_bmap_free_item_zone; |
| 1908 | |
Carlos Maiolino | b123176 | 2019-11-14 12:43:03 -0800 | [diff] [blame] | 1909 | xfs_da_state_zone = kmem_cache_create("xfs_da_state", |
| 1910 | sizeof(struct xfs_da_state), |
| 1911 | 0, 0, NULL); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 1912 | if (!xfs_da_state_zone) |
| 1913 | goto out_destroy_btree_cur_zone; |
| 1914 | |
Carlos Maiolino | b123176 | 2019-11-14 12:43:03 -0800 | [diff] [blame] | 1915 | xfs_ifork_zone = kmem_cache_create("xfs_ifork", |
| 1916 | sizeof(struct xfs_ifork), |
| 1917 | 0, 0, NULL); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 1918 | if (!xfs_ifork_zone) |
Dave Chinner | 1d9025e | 2012-06-22 18:50:14 +1000 | [diff] [blame] | 1919 | goto out_destroy_da_state_zone; |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 1920 | |
Carlos Maiolino | b123176 | 2019-11-14 12:43:03 -0800 | [diff] [blame] | 1921 | xfs_trans_zone = kmem_cache_create("xf_trans", |
| 1922 | sizeof(struct xfs_trans), |
| 1923 | 0, 0, NULL); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 1924 | if (!xfs_trans_zone) |
| 1925 | goto out_destroy_ifork_zone; |
| 1926 | |
Christoph Hellwig | e98c414 | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 1927 | |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 1928 | /* |
| 1929 | * The size of the zone allocated buf log item is the maximum |
| 1930 | * size possible under XFS. This wastes a little bit of memory, |
| 1931 | * but it is much faster. |
| 1932 | */ |
Carlos Maiolino | b123176 | 2019-11-14 12:43:03 -0800 | [diff] [blame] | 1933 | xfs_buf_item_zone = kmem_cache_create("xfs_buf_item", |
| 1934 | sizeof(struct xfs_buf_log_item), |
| 1935 | 0, 0, NULL); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 1936 | if (!xfs_buf_item_zone) |
Dave Chinner | e6631f8 | 2018-05-09 07:49:37 -0700 | [diff] [blame] | 1937 | goto out_destroy_trans_zone; |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 1938 | |
Carlos Maiolino | b123176 | 2019-11-14 12:43:03 -0800 | [diff] [blame] | 1939 | xfs_efd_zone = kmem_cache_create("xfs_efd_item", |
| 1940 | (sizeof(struct xfs_efd_log_item) + |
| 1941 | (XFS_EFD_MAX_FAST_EXTENTS - 1) * |
| 1942 | sizeof(struct xfs_extent)), |
| 1943 | 0, 0, NULL); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 1944 | if (!xfs_efd_zone) |
| 1945 | goto out_destroy_buf_item_zone; |
| 1946 | |
Carlos Maiolino | b123176 | 2019-11-14 12:43:03 -0800 | [diff] [blame] | 1947 | xfs_efi_zone = kmem_cache_create("xfs_efi_item", |
| 1948 | (sizeof(struct xfs_efi_log_item) + |
| 1949 | (XFS_EFI_MAX_FAST_EXTENTS - 1) * |
| 1950 | sizeof(struct xfs_extent)), |
| 1951 | 0, 0, NULL); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 1952 | if (!xfs_efi_zone) |
| 1953 | goto out_destroy_efd_zone; |
| 1954 | |
Carlos Maiolino | b123176 | 2019-11-14 12:43:03 -0800 | [diff] [blame] | 1955 | xfs_inode_zone = kmem_cache_create("xfs_inode", |
| 1956 | sizeof(struct xfs_inode), 0, |
| 1957 | (SLAB_HWCACHE_ALIGN | |
| 1958 | SLAB_RECLAIM_ACCOUNT | |
| 1959 | SLAB_MEM_SPREAD | SLAB_ACCOUNT), |
| 1960 | xfs_fs_inode_init_once); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 1961 | if (!xfs_inode_zone) |
| 1962 | goto out_destroy_efi_zone; |
| 1963 | |
Carlos Maiolino | b123176 | 2019-11-14 12:43:03 -0800 | [diff] [blame] | 1964 | xfs_ili_zone = kmem_cache_create("xfs_ili", |
| 1965 | sizeof(struct xfs_inode_log_item), 0, |
Dave Chinner | d59eada | 2020-03-24 20:10:28 -0700 | [diff] [blame] | 1966 | SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, |
| 1967 | NULL); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 1968 | if (!xfs_ili_zone) |
| 1969 | goto out_destroy_inode_zone; |
Carlos Maiolino | b123176 | 2019-11-14 12:43:03 -0800 | [diff] [blame] | 1970 | |
| 1971 | xfs_icreate_zone = kmem_cache_create("xfs_icr", |
| 1972 | sizeof(struct xfs_icreate_item), |
| 1973 | 0, 0, NULL); |
Dave Chinner | 3ebe7d2 | 2013-06-27 16:04:53 +1000 | [diff] [blame] | 1974 | if (!xfs_icreate_zone) |
| 1975 | goto out_destroy_ili_zone; |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 1976 | |
Carlos Maiolino | b123176 | 2019-11-14 12:43:03 -0800 | [diff] [blame] | 1977 | xfs_rud_zone = kmem_cache_create("xfs_rud_item", |
| 1978 | sizeof(struct xfs_rud_log_item), |
| 1979 | 0, 0, NULL); |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 1980 | if (!xfs_rud_zone) |
| 1981 | goto out_destroy_icreate_zone; |
| 1982 | |
Carlos Maiolino | b123176 | 2019-11-14 12:43:03 -0800 | [diff] [blame] | 1983 | xfs_rui_zone = kmem_cache_create("xfs_rui_item", |
Darrick J. Wong | cd00158 | 2016-09-19 10:24:27 +1000 | [diff] [blame] | 1984 | xfs_rui_log_item_sizeof(XFS_RUI_MAX_FAST_EXTENTS), |
Carlos Maiolino | b123176 | 2019-11-14 12:43:03 -0800 | [diff] [blame] | 1985 | 0, 0, NULL); |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 1986 | if (!xfs_rui_zone) |
| 1987 | goto out_destroy_rud_zone; |
| 1988 | |
Carlos Maiolino | b123176 | 2019-11-14 12:43:03 -0800 | [diff] [blame] | 1989 | xfs_cud_zone = kmem_cache_create("xfs_cud_item", |
| 1990 | sizeof(struct xfs_cud_log_item), |
| 1991 | 0, 0, NULL); |
Darrick J. Wong | baf4bcac | 2016-10-03 09:11:20 -0700 | [diff] [blame] | 1992 | if (!xfs_cud_zone) |
| 1993 | goto out_destroy_rui_zone; |
| 1994 | |
Carlos Maiolino | b123176 | 2019-11-14 12:43:03 -0800 | [diff] [blame] | 1995 | xfs_cui_zone = kmem_cache_create("xfs_cui_item", |
Darrick J. Wong | baf4bcac | 2016-10-03 09:11:20 -0700 | [diff] [blame] | 1996 | xfs_cui_log_item_sizeof(XFS_CUI_MAX_FAST_EXTENTS), |
Carlos Maiolino | b123176 | 2019-11-14 12:43:03 -0800 | [diff] [blame] | 1997 | 0, 0, NULL); |
Darrick J. Wong | baf4bcac | 2016-10-03 09:11:20 -0700 | [diff] [blame] | 1998 | if (!xfs_cui_zone) |
| 1999 | goto out_destroy_cud_zone; |
| 2000 | |
Carlos Maiolino | b123176 | 2019-11-14 12:43:03 -0800 | [diff] [blame] | 2001 | xfs_bud_zone = kmem_cache_create("xfs_bud_item", |
| 2002 | sizeof(struct xfs_bud_log_item), |
| 2003 | 0, 0, NULL); |
Darrick J. Wong | 6413a01 | 2016-10-03 09:11:25 -0700 | [diff] [blame] | 2004 | if (!xfs_bud_zone) |
| 2005 | goto out_destroy_cui_zone; |
| 2006 | |
Carlos Maiolino | b123176 | 2019-11-14 12:43:03 -0800 | [diff] [blame] | 2007 | xfs_bui_zone = kmem_cache_create("xfs_bui_item", |
Darrick J. Wong | 6413a01 | 2016-10-03 09:11:25 -0700 | [diff] [blame] | 2008 | xfs_bui_log_item_sizeof(XFS_BUI_MAX_FAST_EXTENTS), |
Carlos Maiolino | b123176 | 2019-11-14 12:43:03 -0800 | [diff] [blame] | 2009 | 0, 0, NULL); |
Darrick J. Wong | 6413a01 | 2016-10-03 09:11:25 -0700 | [diff] [blame] | 2010 | if (!xfs_bui_zone) |
| 2011 | goto out_destroy_bud_zone; |
| 2012 | |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 2013 | return 0; |
| 2014 | |
Darrick J. Wong | 6413a01 | 2016-10-03 09:11:25 -0700 | [diff] [blame] | 2015 | out_destroy_bud_zone: |
Carlos Maiolino | aaf54eb | 2019-11-14 12:43:04 -0800 | [diff] [blame] | 2016 | kmem_cache_destroy(xfs_bud_zone); |
Darrick J. Wong | 6413a01 | 2016-10-03 09:11:25 -0700 | [diff] [blame] | 2017 | out_destroy_cui_zone: |
Carlos Maiolino | aaf54eb | 2019-11-14 12:43:04 -0800 | [diff] [blame] | 2018 | kmem_cache_destroy(xfs_cui_zone); |
Darrick J. Wong | baf4bcac | 2016-10-03 09:11:20 -0700 | [diff] [blame] | 2019 | out_destroy_cud_zone: |
Carlos Maiolino | aaf54eb | 2019-11-14 12:43:04 -0800 | [diff] [blame] | 2020 | kmem_cache_destroy(xfs_cud_zone); |
Darrick J. Wong | baf4bcac | 2016-10-03 09:11:20 -0700 | [diff] [blame] | 2021 | out_destroy_rui_zone: |
Carlos Maiolino | aaf54eb | 2019-11-14 12:43:04 -0800 | [diff] [blame] | 2022 | kmem_cache_destroy(xfs_rui_zone); |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 2023 | out_destroy_rud_zone: |
Carlos Maiolino | aaf54eb | 2019-11-14 12:43:04 -0800 | [diff] [blame] | 2024 | kmem_cache_destroy(xfs_rud_zone); |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 2025 | out_destroy_icreate_zone: |
Carlos Maiolino | aaf54eb | 2019-11-14 12:43:04 -0800 | [diff] [blame] | 2026 | kmem_cache_destroy(xfs_icreate_zone); |
Dave Chinner | 3ebe7d2 | 2013-06-27 16:04:53 +1000 | [diff] [blame] | 2027 | out_destroy_ili_zone: |
Carlos Maiolino | aaf54eb | 2019-11-14 12:43:04 -0800 | [diff] [blame] | 2028 | kmem_cache_destroy(xfs_ili_zone); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 2029 | out_destroy_inode_zone: |
Carlos Maiolino | aaf54eb | 2019-11-14 12:43:04 -0800 | [diff] [blame] | 2030 | kmem_cache_destroy(xfs_inode_zone); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 2031 | out_destroy_efi_zone: |
Carlos Maiolino | aaf54eb | 2019-11-14 12:43:04 -0800 | [diff] [blame] | 2032 | kmem_cache_destroy(xfs_efi_zone); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 2033 | out_destroy_efd_zone: |
Carlos Maiolino | aaf54eb | 2019-11-14 12:43:04 -0800 | [diff] [blame] | 2034 | kmem_cache_destroy(xfs_efd_zone); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 2035 | out_destroy_buf_item_zone: |
Carlos Maiolino | aaf54eb | 2019-11-14 12:43:04 -0800 | [diff] [blame] | 2036 | kmem_cache_destroy(xfs_buf_item_zone); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 2037 | out_destroy_trans_zone: |
Carlos Maiolino | aaf54eb | 2019-11-14 12:43:04 -0800 | [diff] [blame] | 2038 | kmem_cache_destroy(xfs_trans_zone); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 2039 | out_destroy_ifork_zone: |
Carlos Maiolino | aaf54eb | 2019-11-14 12:43:04 -0800 | [diff] [blame] | 2040 | kmem_cache_destroy(xfs_ifork_zone); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 2041 | out_destroy_da_state_zone: |
Carlos Maiolino | aaf54eb | 2019-11-14 12:43:04 -0800 | [diff] [blame] | 2042 | kmem_cache_destroy(xfs_da_state_zone); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 2043 | out_destroy_btree_cur_zone: |
Carlos Maiolino | aaf54eb | 2019-11-14 12:43:04 -0800 | [diff] [blame] | 2044 | kmem_cache_destroy(xfs_btree_cur_zone); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 2045 | out_destroy_bmap_free_item_zone: |
Carlos Maiolino | aaf54eb | 2019-11-14 12:43:04 -0800 | [diff] [blame] | 2046 | kmem_cache_destroy(xfs_bmap_free_item_zone); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 2047 | out_destroy_log_ticket_zone: |
Carlos Maiolino | aaf54eb | 2019-11-14 12:43:04 -0800 | [diff] [blame] | 2048 | kmem_cache_destroy(xfs_log_ticket_zone); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 2049 | out: |
| 2050 | return -ENOMEM; |
| 2051 | } |
| 2052 | |
| 2053 | STATIC void |
| 2054 | xfs_destroy_zones(void) |
| 2055 | { |
Kirill A. Shutemov | 8c0a853 | 2012-09-26 11:33:07 +1000 | [diff] [blame] | 2056 | /* |
| 2057 | * Make sure all delayed rcu free are flushed before we |
| 2058 | * destroy caches. |
| 2059 | */ |
| 2060 | rcu_barrier(); |
Carlos Maiolino | aaf54eb | 2019-11-14 12:43:04 -0800 | [diff] [blame] | 2061 | kmem_cache_destroy(xfs_bui_zone); |
| 2062 | kmem_cache_destroy(xfs_bud_zone); |
| 2063 | kmem_cache_destroy(xfs_cui_zone); |
| 2064 | kmem_cache_destroy(xfs_cud_zone); |
| 2065 | kmem_cache_destroy(xfs_rui_zone); |
| 2066 | kmem_cache_destroy(xfs_rud_zone); |
| 2067 | kmem_cache_destroy(xfs_icreate_zone); |
| 2068 | kmem_cache_destroy(xfs_ili_zone); |
| 2069 | kmem_cache_destroy(xfs_inode_zone); |
| 2070 | kmem_cache_destroy(xfs_efi_zone); |
| 2071 | kmem_cache_destroy(xfs_efd_zone); |
| 2072 | kmem_cache_destroy(xfs_buf_item_zone); |
| 2073 | kmem_cache_destroy(xfs_trans_zone); |
| 2074 | kmem_cache_destroy(xfs_ifork_zone); |
| 2075 | kmem_cache_destroy(xfs_da_state_zone); |
| 2076 | kmem_cache_destroy(xfs_btree_cur_zone); |
| 2077 | kmem_cache_destroy(xfs_bmap_free_item_zone); |
| 2078 | kmem_cache_destroy(xfs_log_ticket_zone); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 2079 | } |
| 2080 | |
| 2081 | STATIC int __init |
Dave Chinner | 0bf6a5b | 2011-04-08 12:45:07 +1000 | [diff] [blame] | 2082 | xfs_init_workqueues(void) |
| 2083 | { |
| 2084 | /* |
Dave Chinner | c999a22 | 2012-03-22 05:15:07 +0000 | [diff] [blame] | 2085 | * The allocation workqueue can be used in memory reclaim situations |
| 2086 | * (writepage path), and parallelism is only limited by the number of |
| 2087 | * AGs in all the filesystems mounted. Hence use the default large |
| 2088 | * max_active value for this workqueue. |
| 2089 | */ |
Brian Foster | 8018ec0 | 2014-09-09 11:44:46 +1000 | [diff] [blame] | 2090 | xfs_alloc_wq = alloc_workqueue("xfsalloc", |
Darrick J. Wong | 05a302a | 2021-01-22 16:48:42 -0800 | [diff] [blame] | 2091 | XFS_WQFLAGS(WQ_MEM_RECLAIM | WQ_FREEZABLE), 0); |
Dave Chinner | c999a22 | 2012-03-22 05:15:07 +0000 | [diff] [blame] | 2092 | if (!xfs_alloc_wq) |
Dave Chinner | 5889608 | 2012-10-08 21:56:05 +1100 | [diff] [blame] | 2093 | return -ENOMEM; |
Dave Chinner | c999a22 | 2012-03-22 05:15:07 +0000 | [diff] [blame] | 2094 | |
Darrick J. Wong | 05a302a | 2021-01-22 16:48:42 -0800 | [diff] [blame] | 2095 | xfs_discard_wq = alloc_workqueue("xfsdiscard", XFS_WQFLAGS(WQ_UNBOUND), |
| 2096 | 0); |
Christoph Hellwig | 4560e78 | 2017-02-07 14:07:58 -0800 | [diff] [blame] | 2097 | if (!xfs_discard_wq) |
| 2098 | goto out_free_alloc_wq; |
| 2099 | |
Dave Chinner | 0bf6a5b | 2011-04-08 12:45:07 +1000 | [diff] [blame] | 2100 | return 0; |
Christoph Hellwig | 4560e78 | 2017-02-07 14:07:58 -0800 | [diff] [blame] | 2101 | out_free_alloc_wq: |
| 2102 | destroy_workqueue(xfs_alloc_wq); |
| 2103 | return -ENOMEM; |
Dave Chinner | 0bf6a5b | 2011-04-08 12:45:07 +1000 | [diff] [blame] | 2104 | } |
| 2105 | |
Luck, Tony | 39411f8 | 2011-04-11 12:06:12 -0700 | [diff] [blame] | 2106 | STATIC void |
Dave Chinner | 0bf6a5b | 2011-04-08 12:45:07 +1000 | [diff] [blame] | 2107 | xfs_destroy_workqueues(void) |
| 2108 | { |
Christoph Hellwig | 4560e78 | 2017-02-07 14:07:58 -0800 | [diff] [blame] | 2109 | destroy_workqueue(xfs_discard_wq); |
Dave Chinner | c999a22 | 2012-03-22 05:15:07 +0000 | [diff] [blame] | 2110 | destroy_workqueue(xfs_alloc_wq); |
Dave Chinner | 0bf6a5b | 2011-04-08 12:45:07 +1000 | [diff] [blame] | 2111 | } |
| 2112 | |
| 2113 | STATIC int __init |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 2114 | init_xfs_fs(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | { |
| 2116 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2117 | |
Darrick J. Wong | 30cbc59 | 2016-03-09 08:15:14 +1100 | [diff] [blame] | 2118 | xfs_check_ondisk_structs(); |
| 2119 | |
Christoph Hellwig | 6579591 | 2008-11-28 14:23:33 +1100 | [diff] [blame] | 2120 | printk(KERN_INFO XFS_VERSION_STRING " with " |
| 2121 | XFS_BUILD_OPTIONS " enabled\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2122 | |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 2123 | xfs_dir_startup(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2124 | |
Nathan Scott | 8758280 | 2006-03-14 13:18:19 +1100 | [diff] [blame] | 2125 | error = xfs_init_zones(); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 2126 | if (error) |
| 2127 | goto out; |
| 2128 | |
Dave Chinner | 0bf6a5b | 2011-04-08 12:45:07 +1000 | [diff] [blame] | 2129 | error = xfs_init_workqueues(); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 2130 | if (error) |
Christoph Hellwig | 0b1b213 | 2009-12-14 23:14:59 +0000 | [diff] [blame] | 2131 | goto out_destroy_zones; |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 2132 | |
Dave Chinner | 0bf6a5b | 2011-04-08 12:45:07 +1000 | [diff] [blame] | 2133 | error = xfs_mru_cache_init(); |
| 2134 | if (error) |
| 2135 | goto out_destroy_wq; |
| 2136 | |
Nathan Scott | ce8e922 | 2006-01-11 15:39:08 +1100 | [diff] [blame] | 2137 | error = xfs_buf_init(); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 2138 | if (error) |
Christoph Hellwig | 1919add | 2014-04-23 07:11:51 +1000 | [diff] [blame] | 2139 | goto out_mru_cache_uninit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2140 | |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 2141 | error = xfs_init_procfs(); |
| 2142 | if (error) |
| 2143 | goto out_buf_terminate; |
| 2144 | |
| 2145 | error = xfs_sysctl_register(); |
| 2146 | if (error) |
| 2147 | goto out_cleanup_procfs; |
| 2148 | |
Brian Foster | 3d87122 | 2014-07-15 07:41:37 +1000 | [diff] [blame] | 2149 | xfs_kset = kset_create_and_add("xfs", NULL, fs_kobj); |
| 2150 | if (!xfs_kset) { |
| 2151 | error = -ENOMEM; |
Bill O'Donnell | bb230c1 | 2015-10-12 05:15:45 +1100 | [diff] [blame] | 2152 | goto out_sysctl_unregister; |
Brian Foster | 3d87122 | 2014-07-15 07:41:37 +1000 | [diff] [blame] | 2153 | } |
| 2154 | |
Bill O'Donnell | 80529c4 | 2015-10-12 05:19:45 +1100 | [diff] [blame] | 2155 | xfsstats.xs_kobj.kobject.kset = xfs_kset; |
| 2156 | |
| 2157 | xfsstats.xs_stats = alloc_percpu(struct xfsstats); |
| 2158 | if (!xfsstats.xs_stats) { |
| 2159 | error = -ENOMEM; |
| 2160 | goto out_kset_unregister; |
| 2161 | } |
| 2162 | |
| 2163 | error = xfs_sysfs_init(&xfsstats.xs_kobj, &xfs_stats_ktype, NULL, |
Bill O'Donnell | bb230c1 | 2015-10-12 05:15:45 +1100 | [diff] [blame] | 2164 | "stats"); |
| 2165 | if (error) |
Bill O'Donnell | 80529c4 | 2015-10-12 05:19:45 +1100 | [diff] [blame] | 2166 | goto out_free_stats; |
Bill O'Donnell | bb230c1 | 2015-10-12 05:15:45 +1100 | [diff] [blame] | 2167 | |
Brian Foster | 65b6573 | 2014-09-09 11:52:42 +1000 | [diff] [blame] | 2168 | #ifdef DEBUG |
| 2169 | xfs_dbg_kobj.kobject.kset = xfs_kset; |
| 2170 | error = xfs_sysfs_init(&xfs_dbg_kobj, &xfs_dbg_ktype, NULL, "debug"); |
Christoph Hellwig | a05931c | 2012-03-13 08:52:37 +0000 | [diff] [blame] | 2171 | if (error) |
Bill O'Donnell | bb230c1 | 2015-10-12 05:15:45 +1100 | [diff] [blame] | 2172 | goto out_remove_stats_kobj; |
Brian Foster | 65b6573 | 2014-09-09 11:52:42 +1000 | [diff] [blame] | 2173 | #endif |
| 2174 | |
| 2175 | error = xfs_qm_init(); |
| 2176 | if (error) |
Bill O'Donnell | bb230c1 | 2015-10-12 05:15:45 +1100 | [diff] [blame] | 2177 | goto out_remove_dbg_kobj; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2178 | |
| 2179 | error = register_filesystem(&xfs_fs_type); |
| 2180 | if (error) |
Christoph Hellwig | a05931c | 2012-03-13 08:52:37 +0000 | [diff] [blame] | 2181 | goto out_qm_exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2182 | return 0; |
| 2183 | |
Christoph Hellwig | a05931c | 2012-03-13 08:52:37 +0000 | [diff] [blame] | 2184 | out_qm_exit: |
| 2185 | xfs_qm_exit(); |
Bill O'Donnell | bb230c1 | 2015-10-12 05:15:45 +1100 | [diff] [blame] | 2186 | out_remove_dbg_kobj: |
Brian Foster | 65b6573 | 2014-09-09 11:52:42 +1000 | [diff] [blame] | 2187 | #ifdef DEBUG |
| 2188 | xfs_sysfs_del(&xfs_dbg_kobj); |
Bill O'Donnell | bb230c1 | 2015-10-12 05:15:45 +1100 | [diff] [blame] | 2189 | out_remove_stats_kobj: |
Brian Foster | 65b6573 | 2014-09-09 11:52:42 +1000 | [diff] [blame] | 2190 | #endif |
Bill O'Donnell | 80529c4 | 2015-10-12 05:19:45 +1100 | [diff] [blame] | 2191 | xfs_sysfs_del(&xfsstats.xs_kobj); |
| 2192 | out_free_stats: |
| 2193 | free_percpu(xfsstats.xs_stats); |
Bill O'Donnell | bb230c1 | 2015-10-12 05:15:45 +1100 | [diff] [blame] | 2194 | out_kset_unregister: |
Brian Foster | 3d87122 | 2014-07-15 07:41:37 +1000 | [diff] [blame] | 2195 | kset_unregister(xfs_kset); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 2196 | out_sysctl_unregister: |
| 2197 | xfs_sysctl_unregister(); |
| 2198 | out_cleanup_procfs: |
| 2199 | xfs_cleanup_procfs(); |
| 2200 | out_buf_terminate: |
Nathan Scott | ce8e922 | 2006-01-11 15:39:08 +1100 | [diff] [blame] | 2201 | xfs_buf_terminate(); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 2202 | out_mru_cache_uninit: |
| 2203 | xfs_mru_cache_uninit(); |
Dave Chinner | 0bf6a5b | 2011-04-08 12:45:07 +1000 | [diff] [blame] | 2204 | out_destroy_wq: |
| 2205 | xfs_destroy_workqueues(); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 2206 | out_destroy_zones: |
Nathan Scott | 8758280 | 2006-03-14 13:18:19 +1100 | [diff] [blame] | 2207 | xfs_destroy_zones(); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 2208 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2209 | return error; |
| 2210 | } |
| 2211 | |
| 2212 | STATIC void __exit |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 2213 | exit_xfs_fs(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2214 | { |
Christoph Hellwig | a05931c | 2012-03-13 08:52:37 +0000 | [diff] [blame] | 2215 | xfs_qm_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2216 | unregister_filesystem(&xfs_fs_type); |
Brian Foster | 65b6573 | 2014-09-09 11:52:42 +1000 | [diff] [blame] | 2217 | #ifdef DEBUG |
| 2218 | xfs_sysfs_del(&xfs_dbg_kobj); |
| 2219 | #endif |
Bill O'Donnell | 80529c4 | 2015-10-12 05:19:45 +1100 | [diff] [blame] | 2220 | xfs_sysfs_del(&xfsstats.xs_kobj); |
| 2221 | free_percpu(xfsstats.xs_stats); |
Brian Foster | 3d87122 | 2014-07-15 07:41:37 +1000 | [diff] [blame] | 2222 | kset_unregister(xfs_kset); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 2223 | xfs_sysctl_unregister(); |
| 2224 | xfs_cleanup_procfs(); |
Nathan Scott | ce8e922 | 2006-01-11 15:39:08 +1100 | [diff] [blame] | 2225 | xfs_buf_terminate(); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 2226 | xfs_mru_cache_uninit(); |
Dave Chinner | 0bf6a5b | 2011-04-08 12:45:07 +1000 | [diff] [blame] | 2227 | xfs_destroy_workqueues(); |
Nathan Scott | 8758280 | 2006-03-14 13:18:19 +1100 | [diff] [blame] | 2228 | xfs_destroy_zones(); |
Darrick J. Wong | af3b638 | 2015-11-03 13:06:34 +1100 | [diff] [blame] | 2229 | xfs_uuid_table_free(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2230 | } |
| 2231 | |
| 2232 | module_init(init_xfs_fs); |
| 2233 | module_exit(exit_xfs_fs); |
| 2234 | |
| 2235 | MODULE_AUTHOR("Silicon Graphics, Inc."); |
| 2236 | MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled"); |
| 2237 | MODULE_LICENSE("GPL"); |