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