blob: 5c28fb22b44b6d60b2064fb3b986b85d6d2669dc [file] [log] [blame]
Dave Chinner0b61f8a2018-06-05 19:42:14 -07001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Nathan Scotta805bad2006-06-19 08:40:27 +10003 * Copyright (c) 2000-2006 Silicon Graphics, Inc.
Nathan Scott7b718762005-11-02 14:58:39 +11004 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
Christoph Hellwig0b1b2132009-12-14 23:14:59 +00006
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include "xfs.h"
Dave Chinner70a98832013-10-23 10:36:05 +11008#include "xfs_shared.h"
Dave Chinner6ca1c902013-08-12 20:49:26 +10009#include "xfs_format.h"
Dave Chinner239880e2013-10-23 10:50:10 +110010#include "xfs_log_format.h"
11#include "xfs_trans_resv.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include "xfs_sb.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include "xfs_mount.h"
Dave Chinner57062782013-10-15 09:17:51 +110014#include "xfs_da_format.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include "xfs_inode.h"
Nathan Scotta844f452005-11-02 14:38:42 +110016#include "xfs_btree.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include "xfs_bmap.h"
Dave Chinnera4fbe6a2013-10-23 10:51:50 +110018#include "xfs_alloc.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include "xfs_error.h"
Christoph Hellwig9909c4a2007-10-11 18:11:14 +100020#include "xfs_fsops.h"
Dave Chinner239880e2013-10-23 10:50:10 +110021#include "xfs_trans.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include "xfs_buf_item.h"
Dave Chinner239880e2013-10-23 10:50:10 +110023#include "xfs_log.h"
David Chinnera67d7c52007-11-23 16:29:32 +110024#include "xfs_log_priv.h"
Christoph Hellwig9f8868f2008-07-18 17:11:46 +100025#include "xfs_da_btree.h"
Dave Chinner2b9ab5a2013-08-12 20:49:37 +100026#include "xfs_dir2.h"
Christoph Hellwig9f8868f2008-07-18 17:11:46 +100027#include "xfs_extfree_item.h"
28#include "xfs_mru_cache.h"
29#include "xfs_inode_item.h"
Dave Chinner6d8b79c2012-10-08 21:56:09 +110030#include "xfs_icache.h"
Christoph Hellwig0b1b2132009-12-14 23:14:59 +000031#include "xfs_trace.h"
Dave Chinner3ebe7d22013-06-27 16:04:53 +100032#include "xfs_icreate_item.h"
Dave Chinnera4fbe6a2013-10-23 10:51:50 +110033#include "xfs_filestream.h"
34#include "xfs_quota.h"
Brian Foster65b65732014-09-09 11:52:42 +100035#include "xfs_sysfs.h"
Darrick J. Wong30cbc592016-03-09 08:15:14 +110036#include "xfs_ondisk.h"
Darrick J. Wong5880f2d72016-08-03 12:04:45 +100037#include "xfs_rmap_item.h"
Darrick J. Wongbaf4bcac2016-10-03 09:11:20 -070038#include "xfs_refcount_item.h"
Darrick J. Wong6413a012016-10-03 09:11:25 -070039#include "xfs_bmap_item.h"
Darrick J. Wong5e7e6052016-10-03 09:11:38 -070040#include "xfs_reflink.h"
Darrick J. Wongbc9f2b72018-12-12 08:46:22 -080041#include "xfs_defer.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43#include <linux/namei.h>
Dan Williamsef510422017-05-08 10:55:27 -070044#include <linux/dax.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090046#include <linux/slab.h>
Adam Borowskidddde682018-10-18 17:20:19 +110047#include <linux/magic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include <linux/mount.h>
Christoph Hellwig0829c362005-09-02 16:58:49 +100049#include <linux/mempool.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#include <linux/writeback.h>
Christoph Hellwig4df08c52005-09-05 08:34:18 +100051#include <linux/kthread.h>
Nigel Cunningham7dfb7102006-12-06 20:34:23 -080052#include <linux/freezer.h>
Christoph Hellwig62a877e2008-07-18 17:12:36 +100053#include <linux/parser.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
Alexey Dobriyanb87221d2009-09-21 17:01:09 -070055static const struct super_operations xfs_super_operations;
Kent Overstreete292d7b2018-05-20 18:25:57 -040056struct bio_set xfs_ioend_bioset;
Brian Foster65b65732014-09-09 11:52:42 +100057
Dave Chinnere3aed1a2014-09-29 10:46:08 +100058static struct kset *xfs_kset; /* top-level xfs sysfs dir */
Brian Foster65b65732014-09-09 11:52:42 +100059#ifdef DEBUG
60static struct xfs_kobj xfs_dbg_kobj; /* global debug sysfs attrs */
61#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Christoph Hellwig62a877e2008-07-18 17:12:36 +100063/*
64 * Table driven mount option parser.
Christoph Hellwig62a877e2008-07-18 17:12:36 +100065 */
66enum {
Eric Sandeen2e74af02016-03-02 09:55:38 +110067 Opt_logbufs, Opt_logbsize, Opt_logdev, Opt_rtdev, Opt_biosize,
68 Opt_wsync, Opt_noalign, Opt_swalloc, Opt_sunit, Opt_swidth, Opt_nouuid,
Christoph Hellwig94079282019-04-28 08:32:52 -070069 Opt_grpid, Opt_nogrpid, Opt_bsdgroups, Opt_sysvgroups,
Eric Sandeen1c02d502018-07-26 09:11:27 -070070 Opt_allocsize, Opt_norecovery, Opt_inode64, Opt_inode32, Opt_ikeep,
71 Opt_noikeep, Opt_largeio, Opt_nolargeio, Opt_attr2, Opt_noattr2,
72 Opt_filestreams, Opt_quota, Opt_noquota, Opt_usrquota, Opt_grpquota,
73 Opt_prjquota, Opt_uquota, Opt_gquota, Opt_pquota,
Eric Sandeen2e74af02016-03-02 09:55:38 +110074 Opt_uqnoenforce, Opt_gqnoenforce, Opt_pqnoenforce, Opt_qnoenforce,
75 Opt_discard, Opt_nodiscard, Opt_dax, Opt_err,
Christoph Hellwig62a877e2008-07-18 17:12:36 +100076};
77
Steven Whitehousea447c092008-10-13 10:46:57 +010078static const match_table_t tokens = {
Eric Sandeen2e74af02016-03-02 09:55:38 +110079 {Opt_logbufs, "logbufs=%u"}, /* number of XFS log buffers */
80 {Opt_logbsize, "logbsize=%s"}, /* size of XFS log buffers */
81 {Opt_logdev, "logdev=%s"}, /* log device */
82 {Opt_rtdev, "rtdev=%s"}, /* realtime I/O device */
83 {Opt_biosize, "biosize=%u"}, /* log2 of preferred buffered io size */
84 {Opt_wsync, "wsync"}, /* safe-mode nfs compatible mount */
85 {Opt_noalign, "noalign"}, /* turn off stripe alignment */
86 {Opt_swalloc, "swalloc"}, /* turn on stripe width allocation */
87 {Opt_sunit, "sunit=%u"}, /* data volume stripe unit */
88 {Opt_swidth, "swidth=%u"}, /* data volume stripe width */
89 {Opt_nouuid, "nouuid"}, /* ignore filesystem UUID */
Eric Sandeen2e74af02016-03-02 09:55:38 +110090 {Opt_grpid, "grpid"}, /* group-ID from parent directory */
91 {Opt_nogrpid, "nogrpid"}, /* group-ID from current process */
92 {Opt_bsdgroups, "bsdgroups"}, /* group-ID from parent directory */
93 {Opt_sysvgroups,"sysvgroups"}, /* group-ID from current process */
94 {Opt_allocsize, "allocsize=%s"},/* preferred allocation size */
95 {Opt_norecovery,"norecovery"}, /* don't run XFS recovery */
Eric Sandeen2e74af02016-03-02 09:55:38 +110096 {Opt_inode64, "inode64"}, /* inodes can be allocated anywhere */
97 {Opt_inode32, "inode32"}, /* inode allocation limited to
98 * XFS_MAXINUMBER_32 */
99 {Opt_ikeep, "ikeep"}, /* do not free empty inode clusters */
100 {Opt_noikeep, "noikeep"}, /* free empty inode clusters */
101 {Opt_largeio, "largeio"}, /* report large I/O sizes in stat() */
102 {Opt_nolargeio, "nolargeio"}, /* do not report large I/O sizes
103 * in stat(). */
104 {Opt_attr2, "attr2"}, /* do use attr2 attribute format */
105 {Opt_noattr2, "noattr2"}, /* do not use attr2 attribute format */
106 {Opt_filestreams,"filestreams"},/* use filestreams allocator */
107 {Opt_quota, "quota"}, /* disk quotas (user) */
108 {Opt_noquota, "noquota"}, /* no quotas */
109 {Opt_usrquota, "usrquota"}, /* user quota enabled */
110 {Opt_grpquota, "grpquota"}, /* group quota enabled */
111 {Opt_prjquota, "prjquota"}, /* project quota enabled */
112 {Opt_uquota, "uquota"}, /* user quota (IRIX variant) */
113 {Opt_gquota, "gquota"}, /* group quota (IRIX variant) */
114 {Opt_pquota, "pquota"}, /* project quota (IRIX variant) */
115 {Opt_uqnoenforce,"uqnoenforce"},/* user quota limit enforcement */
116 {Opt_gqnoenforce,"gqnoenforce"},/* group quota limit enforcement */
117 {Opt_pqnoenforce,"pqnoenforce"},/* project quota limit enforcement */
118 {Opt_qnoenforce, "qnoenforce"}, /* same as uqnoenforce */
119 {Opt_discard, "discard"}, /* Discard unused blocks */
120 {Opt_nodiscard, "nodiscard"}, /* Do not discard unused blocks */
Eric Sandeen2e74af02016-03-02 09:55:38 +1100121 {Opt_dax, "dax"}, /* Enable direct access to bdev pages */
122 {Opt_err, NULL},
Christoph Hellwig62a877e2008-07-18 17:12:36 +1000123};
124
125
Markus Elfringa841b642016-01-04 16:13:21 +1100126STATIC int
Eric Sandeen2e74af02016-03-02 09:55:38 +1100127suffix_kstrtoint(const substring_t *s, unsigned int base, int *res)
David Chinnera67d7c52007-11-23 16:29:32 +1100128{
Abhijit Pawara17164e2013-01-09 19:34:42 +0530129 int last, shift_left_factor = 0, _res;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100130 char *value;
131 int ret = 0;
132
133 value = match_strdup(s);
134 if (!value)
135 return -ENOMEM;
David Chinnera67d7c52007-11-23 16:29:32 +1100136
137 last = strlen(value) - 1;
138 if (value[last] == 'K' || value[last] == 'k') {
139 shift_left_factor = 10;
140 value[last] = '\0';
141 }
142 if (value[last] == 'M' || value[last] == 'm') {
143 shift_left_factor = 20;
144 value[last] = '\0';
145 }
146 if (value[last] == 'G' || value[last] == 'g') {
147 shift_left_factor = 30;
148 value[last] = '\0';
149 }
150
Eric Sandeen2e74af02016-03-02 09:55:38 +1100151 if (kstrtoint(value, base, &_res))
152 ret = -EINVAL;
153 kfree(value);
Abhijit Pawara17164e2013-01-09 19:34:42 +0530154 *res = _res << shift_left_factor;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100155 return ret;
David Chinnera67d7c52007-11-23 16:29:32 +1100156}
157
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100158/*
159 * This function fills in xfs_mount_t fields based on mount args.
160 * Note: the superblock has _not_ yet been read in.
161 *
162 * Note that this function leaks the various device name allocations on
163 * failure. The caller takes care of them.
Eric Sandeena08ee402016-03-02 09:56:31 +1100164 *
165 * *sb is const because this is also used to test options on the remount
166 * path, and we don't want this to have any side effects at remount time.
167 * Today this function does not change *sb, but just to future-proof...
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100168 */
David Chinnera67d7c52007-11-23 16:29:32 +1100169STATIC int
170xfs_parseargs(
171 struct xfs_mount *mp,
Christoph Hellwig288699f2010-06-23 18:11:15 +1000172 char *options)
David Chinnera67d7c52007-11-23 16:29:32 +1100173{
Eric Sandeena08ee402016-03-02 09:56:31 +1100174 const struct super_block *sb = mp->m_super;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100175 char *p;
176 substring_t args[MAX_OPT_ARGS];
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100177 int dsunit = 0;
178 int dswidth = 0;
179 int iosize = 0;
Darrick J. Wongc8ce5402017-06-16 11:00:05 -0700180 uint8_t iosizelog = 0;
David Chinnera67d7c52007-11-23 16:29:32 +1100181
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100182 /*
Dave Chinner4f107002011-03-07 10:00:35 +1100183 * set up the mount name first so all the errors will refer to the
184 * correct device.
185 */
186 mp->m_fsname = kstrndup(sb->s_id, MAXNAMELEN, GFP_KERNEL);
187 if (!mp->m_fsname)
Dave Chinner24513372014-06-25 14:58:08 +1000188 return -ENOMEM;
Dave Chinner4f107002011-03-07 10:00:35 +1100189 mp->m_fsname_len = strlen(mp->m_fsname) + 1;
190
191 /*
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100192 * Copy binary VFS mount flags we are interested in.
193 */
David Howellsbc98a422017-07-17 08:45:34 +0100194 if (sb_rdonly(sb))
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100195 mp->m_flags |= XFS_MOUNT_RDONLY;
Linus Torvalds1751e8a2017-11-27 13:05:09 -0800196 if (sb->s_flags & SB_DIRSYNC)
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100197 mp->m_flags |= XFS_MOUNT_DIRSYNC;
Linus Torvalds1751e8a2017-11-27 13:05:09 -0800198 if (sb->s_flags & SB_SYNCHRONOUS)
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100199 mp->m_flags |= XFS_MOUNT_WSYNC;
200
201 /*
202 * Set some default flags that could be cleared by the mount option
203 * parsing.
204 */
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100205 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100206
207 /*
208 * These can be overridden by the mount option parsing.
209 */
210 mp->m_logbufs = -1;
211 mp->m_logbsize = -1;
David Chinnera67d7c52007-11-23 16:29:32 +1100212
213 if (!options)
214 goto done;
215
Eric Sandeen2e74af02016-03-02 09:55:38 +1100216 while ((p = strsep(&options, ",")) != NULL) {
217 int token;
David Chinnera67d7c52007-11-23 16:29:32 +1100218
Eric Sandeen2e74af02016-03-02 09:55:38 +1100219 if (!*p)
220 continue;
221
222 token = match_token(p, tokens, args);
223 switch (token) {
224 case Opt_logbufs:
225 if (match_int(args, &mp->m_logbufs))
Dave Chinner24513372014-06-25 14:58:08 +1000226 return -EINVAL;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100227 break;
228 case Opt_logbsize:
229 if (suffix_kstrtoint(args, 10, &mp->m_logbsize))
Dave Chinner24513372014-06-25 14:58:08 +1000230 return -EINVAL;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100231 break;
232 case Opt_logdev:
Chengguang Xu5b4c8452018-02-25 12:17:31 -0800233 kfree(mp->m_logname);
Eric Sandeen2e74af02016-03-02 09:55:38 +1100234 mp->m_logname = match_strdup(args);
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100235 if (!mp->m_logname)
Dave Chinner24513372014-06-25 14:58:08 +1000236 return -ENOMEM;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100237 break;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100238 case Opt_rtdev:
Chengguang Xu5b4c8452018-02-25 12:17:31 -0800239 kfree(mp->m_rtname);
Eric Sandeen2e74af02016-03-02 09:55:38 +1100240 mp->m_rtname = match_strdup(args);
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100241 if (!mp->m_rtname)
Dave Chinner24513372014-06-25 14:58:08 +1000242 return -ENOMEM;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100243 break;
244 case Opt_allocsize:
245 case Opt_biosize:
246 if (suffix_kstrtoint(args, 10, &iosize))
Dave Chinner24513372014-06-25 14:58:08 +1000247 return -EINVAL;
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100248 iosizelog = ffs(iosize) - 1;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100249 break;
250 case Opt_grpid:
251 case Opt_bsdgroups:
David Chinnera67d7c52007-11-23 16:29:32 +1100252 mp->m_flags |= XFS_MOUNT_GRPID;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100253 break;
254 case Opt_nogrpid:
255 case Opt_sysvgroups:
David Chinnera67d7c52007-11-23 16:29:32 +1100256 mp->m_flags &= ~XFS_MOUNT_GRPID;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100257 break;
258 case Opt_wsync:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100259 mp->m_flags |= XFS_MOUNT_WSYNC;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100260 break;
261 case Opt_norecovery:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100262 mp->m_flags |= XFS_MOUNT_NORECOVERY;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100263 break;
264 case Opt_noalign:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100265 mp->m_flags |= XFS_MOUNT_NOALIGN;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100266 break;
267 case Opt_swalloc:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100268 mp->m_flags |= XFS_MOUNT_SWALLOC;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100269 break;
270 case Opt_sunit:
271 if (match_int(args, &dsunit))
Dave Chinner24513372014-06-25 14:58:08 +1000272 return -EINVAL;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100273 break;
274 case Opt_swidth:
275 if (match_int(args, &dswidth))
Dave Chinner24513372014-06-25 14:58:08 +1000276 return -EINVAL;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100277 break;
278 case Opt_inode32:
Carlos Maiolino08bf5402012-09-20 10:32:37 -0300279 mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100280 break;
281 case Opt_inode64:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100282 mp->m_flags &= ~XFS_MOUNT_SMALL_INUMS;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100283 break;
284 case Opt_nouuid:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100285 mp->m_flags |= XFS_MOUNT_NOUUID;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100286 break;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100287 case Opt_ikeep:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100288 mp->m_flags |= XFS_MOUNT_IKEEP;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100289 break;
290 case Opt_noikeep:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100291 mp->m_flags &= ~XFS_MOUNT_IKEEP;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100292 break;
293 case Opt_largeio:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100294 mp->m_flags &= ~XFS_MOUNT_COMPAT_IOSIZE;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100295 break;
296 case Opt_nolargeio:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100297 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100298 break;
299 case Opt_attr2:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100300 mp->m_flags |= XFS_MOUNT_ATTR2;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100301 break;
302 case Opt_noattr2:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100303 mp->m_flags &= ~XFS_MOUNT_ATTR2;
304 mp->m_flags |= XFS_MOUNT_NOATTR2;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100305 break;
306 case Opt_filestreams:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100307 mp->m_flags |= XFS_MOUNT_FILESTREAMS;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100308 break;
309 case Opt_noquota:
Chandra Seetharaman4177af32012-01-23 17:31:43 +0000310 mp->m_qflags &= ~XFS_ALL_QUOTA_ACCT;
311 mp->m_qflags &= ~XFS_ALL_QUOTA_ENFD;
312 mp->m_qflags &= ~XFS_ALL_QUOTA_ACTIVE;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100313 break;
314 case Opt_quota:
315 case Opt_uquota:
316 case Opt_usrquota:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100317 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE |
318 XFS_UQUOTA_ENFD);
Eric Sandeen2e74af02016-03-02 09:55:38 +1100319 break;
320 case Opt_qnoenforce:
321 case Opt_uqnoenforce:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100322 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
323 mp->m_qflags &= ~XFS_UQUOTA_ENFD;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100324 break;
325 case Opt_pquota:
326 case Opt_prjquota:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100327 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE |
Chandra Seetharaman83e782e2013-06-27 17:25:10 -0500328 XFS_PQUOTA_ENFD);
Eric Sandeen2e74af02016-03-02 09:55:38 +1100329 break;
330 case Opt_pqnoenforce:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100331 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
Chandra Seetharaman83e782e2013-06-27 17:25:10 -0500332 mp->m_qflags &= ~XFS_PQUOTA_ENFD;
Eryu Guance5c7672016-04-06 07:19:40 +1000333 break;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100334 case Opt_gquota:
335 case Opt_grpquota:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100336 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE |
Chandra Seetharaman83e782e2013-06-27 17:25:10 -0500337 XFS_GQUOTA_ENFD);
Eric Sandeen2e74af02016-03-02 09:55:38 +1100338 break;
339 case Opt_gqnoenforce:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100340 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
Chandra Seetharaman83e782e2013-06-27 17:25:10 -0500341 mp->m_qflags &= ~XFS_GQUOTA_ENFD;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100342 break;
343 case Opt_discard:
Christoph Hellwige84661a2011-05-20 13:45:32 +0000344 mp->m_flags |= XFS_MOUNT_DISCARD;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100345 break;
346 case Opt_nodiscard:
Christoph Hellwige84661a2011-05-20 13:45:32 +0000347 mp->m_flags &= ~XFS_MOUNT_DISCARD;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100348 break;
Dave Chinnercbe4dab2015-06-04 09:19:18 +1000349#ifdef CONFIG_FS_DAX
Eric Sandeen2e74af02016-03-02 09:55:38 +1100350 case Opt_dax:
Dave Chinnercbe4dab2015-06-04 09:19:18 +1000351 mp->m_flags |= XFS_MOUNT_DAX;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100352 break;
Dave Chinnercbe4dab2015-06-04 09:19:18 +1000353#endif
Eric Sandeen2e74af02016-03-02 09:55:38 +1100354 default:
355 xfs_warn(mp, "unknown mount option [%s].", p);
Dave Chinner24513372014-06-25 14:58:08 +1000356 return -EINVAL;
David Chinnera67d7c52007-11-23 16:29:32 +1100357 }
358 }
359
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100360 /*
361 * no recovery flag requires a read-only mount
362 */
363 if ((mp->m_flags & XFS_MOUNT_NORECOVERY) &&
364 !(mp->m_flags & XFS_MOUNT_RDONLY)) {
Dave Chinner4f107002011-03-07 10:00:35 +1100365 xfs_warn(mp, "no-recovery mounts must be read-only.");
Dave Chinner24513372014-06-25 14:58:08 +1000366 return -EINVAL;
David Chinnera67d7c52007-11-23 16:29:32 +1100367 }
368
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100369 if ((mp->m_flags & XFS_MOUNT_NOALIGN) && (dsunit || dswidth)) {
Dave Chinner4f107002011-03-07 10:00:35 +1100370 xfs_warn(mp,
371 "sunit and swidth options incompatible with the noalign option");
Dave Chinner24513372014-06-25 14:58:08 +1000372 return -EINVAL;
David Chinnera67d7c52007-11-23 16:29:32 +1100373 }
374
Christoph Hellwig7d095252009-06-08 15:33:32 +0200375#ifndef CONFIG_XFS_QUOTA
376 if (XFS_IS_QUOTA_RUNNING(mp)) {
Dave Chinner4f107002011-03-07 10:00:35 +1100377 xfs_warn(mp, "quota support not available in this kernel.");
Dave Chinner24513372014-06-25 14:58:08 +1000378 return -EINVAL;
Christoph Hellwig7d095252009-06-08 15:33:32 +0200379 }
380#endif
381
David Chinnera67d7c52007-11-23 16:29:32 +1100382 if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
Dave Chinner4f107002011-03-07 10:00:35 +1100383 xfs_warn(mp, "sunit and swidth must be specified together");
Dave Chinner24513372014-06-25 14:58:08 +1000384 return -EINVAL;
David Chinnera67d7c52007-11-23 16:29:32 +1100385 }
386
387 if (dsunit && (dswidth % dsunit != 0)) {
Dave Chinner4f107002011-03-07 10:00:35 +1100388 xfs_warn(mp,
389 "stripe width (%d) must be a multiple of the stripe unit (%d)",
David Chinnera67d7c52007-11-23 16:29:32 +1100390 dswidth, dsunit);
Dave Chinner24513372014-06-25 14:58:08 +1000391 return -EINVAL;
David Chinnera67d7c52007-11-23 16:29:32 +1100392 }
393
David Chinnera67d7c52007-11-23 16:29:32 +1100394done:
Jie Liu39a45d82013-05-02 19:27:47 +0800395 if (dsunit && !(mp->m_flags & XFS_MOUNT_NOALIGN)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100396 /*
397 * At this point the superblock has not been read
398 * in, therefore we do not know the block size.
399 * Before the mount call ends we will convert
400 * these to FSBs.
401 */
Jie Liu39a45d82013-05-02 19:27:47 +0800402 mp->m_dalign = dsunit;
403 mp->m_swidth = dswidth;
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100404 }
405
406 if (mp->m_logbufs != -1 &&
407 mp->m_logbufs != 0 &&
408 (mp->m_logbufs < XLOG_MIN_ICLOGS ||
409 mp->m_logbufs > XLOG_MAX_ICLOGS)) {
Dave Chinner4f107002011-03-07 10:00:35 +1100410 xfs_warn(mp, "invalid logbufs value: %d [not %d-%d]",
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100411 mp->m_logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
Dave Chinner24513372014-06-25 14:58:08 +1000412 return -EINVAL;
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100413 }
414 if (mp->m_logbsize != -1 &&
415 mp->m_logbsize != 0 &&
416 (mp->m_logbsize < XLOG_MIN_RECORD_BSIZE ||
417 mp->m_logbsize > XLOG_MAX_RECORD_BSIZE ||
418 !is_power_of_2(mp->m_logbsize))) {
Dave Chinner4f107002011-03-07 10:00:35 +1100419 xfs_warn(mp,
420 "invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100421 mp->m_logbsize);
Dave Chinner24513372014-06-25 14:58:08 +1000422 return -EINVAL;
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100423 }
424
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100425 if (iosizelog) {
426 if (iosizelog > XFS_MAX_IO_LOG ||
427 iosizelog < XFS_MIN_IO_LOG) {
Dave Chinner4f107002011-03-07 10:00:35 +1100428 xfs_warn(mp, "invalid log iosize: %d [not %d-%d]",
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100429 iosizelog, XFS_MIN_IO_LOG,
430 XFS_MAX_IO_LOG);
Dave Chinner24513372014-06-25 14:58:08 +1000431 return -EINVAL;
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100432 }
433
434 mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
435 mp->m_readio_log = iosizelog;
436 mp->m_writeio_log = iosizelog;
437 }
438
David Chinnera67d7c52007-11-23 16:29:32 +1100439 return 0;
440}
441
442struct proc_xfs_info {
Dave Chinnercbe4dab2015-06-04 09:19:18 +1000443 uint64_t flag;
444 char *str;
David Chinnera67d7c52007-11-23 16:29:32 +1100445};
446
Eric Sandeen91083262019-05-01 20:26:30 -0700447STATIC void
David Chinnera67d7c52007-11-23 16:29:32 +1100448xfs_showargs(
449 struct xfs_mount *mp,
450 struct seq_file *m)
451{
452 static struct proc_xfs_info xfs_info_set[] = {
453 /* the few simple ones we can get from the mount struct */
Eric Sandeen2e74af02016-03-02 09:55:38 +1100454 { XFS_MOUNT_IKEEP, ",ikeep" },
455 { XFS_MOUNT_WSYNC, ",wsync" },
456 { XFS_MOUNT_NOALIGN, ",noalign" },
457 { XFS_MOUNT_SWALLOC, ",swalloc" },
458 { XFS_MOUNT_NOUUID, ",nouuid" },
459 { XFS_MOUNT_NORECOVERY, ",norecovery" },
460 { XFS_MOUNT_ATTR2, ",attr2" },
461 { XFS_MOUNT_FILESTREAMS, ",filestreams" },
462 { XFS_MOUNT_GRPID, ",grpid" },
463 { XFS_MOUNT_DISCARD, ",discard" },
464 { XFS_MOUNT_SMALL_INUMS, ",inode32" },
465 { XFS_MOUNT_DAX, ",dax" },
David Chinnera67d7c52007-11-23 16:29:32 +1100466 { 0, NULL }
467 };
468 static struct proc_xfs_info xfs_info_unset[] = {
469 /* the few simple ones we can get from the mount struct */
Eric Sandeen2e74af02016-03-02 09:55:38 +1100470 { XFS_MOUNT_COMPAT_IOSIZE, ",largeio" },
Eric Sandeen2e74af02016-03-02 09:55:38 +1100471 { XFS_MOUNT_SMALL_INUMS, ",inode64" },
David Chinnera67d7c52007-11-23 16:29:32 +1100472 { 0, NULL }
473 };
474 struct proc_xfs_info *xfs_infop;
475
476 for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
477 if (mp->m_flags & xfs_infop->flag)
478 seq_puts(m, xfs_infop->str);
479 }
480 for (xfs_infop = xfs_info_unset; xfs_infop->flag; xfs_infop++) {
481 if (!(mp->m_flags & xfs_infop->flag))
482 seq_puts(m, xfs_infop->str);
483 }
484
485 if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
Eric Sandeen2e74af02016-03-02 09:55:38 +1100486 seq_printf(m, ",allocsize=%dk",
David Chinnera67d7c52007-11-23 16:29:32 +1100487 (int)(1 << mp->m_writeio_log) >> 10);
488
489 if (mp->m_logbufs > 0)
Eric Sandeen2e74af02016-03-02 09:55:38 +1100490 seq_printf(m, ",logbufs=%d", mp->m_logbufs);
David Chinnera67d7c52007-11-23 16:29:32 +1100491 if (mp->m_logbsize > 0)
Eric Sandeen2e74af02016-03-02 09:55:38 +1100492 seq_printf(m, ",logbsize=%dk", mp->m_logbsize >> 10);
David Chinnera67d7c52007-11-23 16:29:32 +1100493
494 if (mp->m_logname)
Eric Sandeen2e74af02016-03-02 09:55:38 +1100495 seq_show_option(m, "logdev", mp->m_logname);
David Chinnera67d7c52007-11-23 16:29:32 +1100496 if (mp->m_rtname)
Eric Sandeen2e74af02016-03-02 09:55:38 +1100497 seq_show_option(m, "rtdev", mp->m_rtname);
David Chinnera67d7c52007-11-23 16:29:32 +1100498
499 if (mp->m_dalign > 0)
Eric Sandeen2e74af02016-03-02 09:55:38 +1100500 seq_printf(m, ",sunit=%d",
David Chinnera67d7c52007-11-23 16:29:32 +1100501 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
502 if (mp->m_swidth > 0)
Eric Sandeen2e74af02016-03-02 09:55:38 +1100503 seq_printf(m, ",swidth=%d",
David Chinnera67d7c52007-11-23 16:29:32 +1100504 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
505
506 if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD))
Eric Sandeen2e74af02016-03-02 09:55:38 +1100507 seq_puts(m, ",usrquota");
David Chinnera67d7c52007-11-23 16:29:32 +1100508 else if (mp->m_qflags & XFS_UQUOTA_ACCT)
Eric Sandeen2e74af02016-03-02 09:55:38 +1100509 seq_puts(m, ",uqnoenforce");
David Chinnera67d7c52007-11-23 16:29:32 +1100510
Alex Elder988abe42009-09-02 17:02:24 -0500511 if (mp->m_qflags & XFS_PQUOTA_ACCT) {
Chandra Seetharaman83e782e2013-06-27 17:25:10 -0500512 if (mp->m_qflags & XFS_PQUOTA_ENFD)
Eric Sandeen2e74af02016-03-02 09:55:38 +1100513 seq_puts(m, ",prjquota");
Alex Elder988abe42009-09-02 17:02:24 -0500514 else
Eric Sandeen2e74af02016-03-02 09:55:38 +1100515 seq_puts(m, ",pqnoenforce");
Chandra Seetharamand892d582013-07-19 17:36:02 -0500516 }
517 if (mp->m_qflags & XFS_GQUOTA_ACCT) {
Chandra Seetharaman83e782e2013-06-27 17:25:10 -0500518 if (mp->m_qflags & XFS_GQUOTA_ENFD)
Eric Sandeen2e74af02016-03-02 09:55:38 +1100519 seq_puts(m, ",grpquota");
Alex Elder988abe42009-09-02 17:02:24 -0500520 else
Eric Sandeen2e74af02016-03-02 09:55:38 +1100521 seq_puts(m, ",gqnoenforce");
Alex Elder988abe42009-09-02 17:02:24 -0500522 }
David Chinnera67d7c52007-11-23 16:29:32 +1100523
524 if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
Eric Sandeen2e74af02016-03-02 09:55:38 +1100525 seq_puts(m, ",noquota");
David Chinnera67d7c52007-11-23 16:29:32 +1100526}
Eric Sandeen91083262019-05-01 20:26:30 -0700527
Darrick J. Wongc8ce5402017-06-16 11:00:05 -0700528static uint64_t
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529xfs_max_file_offset(
530 unsigned int blockshift)
531{
532 unsigned int pagefactor = 1;
533 unsigned int bitshift = BITS_PER_LONG - 1;
534
535 /* Figure out maximum filesize, on Linux this can depend on
536 * the filesystem blocksize (on 32 bit platforms).
Christoph Hellwig72deb452019-04-05 18:08:59 +0200537 * __block_write_begin does this in an [unsigned] long long...
Kirill A. Shutemovea1754a2016-04-01 15:29:48 +0300538 * page->index << (PAGE_SHIFT - bbits)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 * So, for page sized blocks (4K on 32 bit platforms),
540 * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
Kirill A. Shutemovea1754a2016-04-01 15:29:48 +0300541 * (((u64)PAGE_SIZE << (BITS_PER_LONG-1))-1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 * but for smaller blocksizes it is less (bbits = log2 bsize).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 */
544
545#if BITS_PER_LONG == 32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 ASSERT(sizeof(sector_t) == 8);
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +0300547 pagefactor = PAGE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 bitshift = BITS_PER_LONG;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549#endif
550
Darrick J. Wongc8ce5402017-06-16 11:00:05 -0700551 return (((uint64_t)pagefactor) << bitshift) - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552}
553
Eric Sandeen9de67c32014-07-24 20:51:54 +1000554/*
Eric Sandeen12c3f052016-03-02 09:58:09 +1100555 * Set parameters for inode allocation heuristics, taking into account
556 * filesystem size and inode32/inode64 mount options; i.e. specifically
557 * whether or not XFS_MOUNT_SMALL_INUMS is set.
558 *
559 * Inode allocation patterns are altered only if inode32 is requested
560 * (XFS_MOUNT_SMALL_INUMS), and the filesystem is sufficiently large.
561 * If altered, XFS_MOUNT_32BITINODES is set as well.
562 *
563 * An agcount independent of that in the mount structure is provided
564 * because in the growfs case, mp->m_sb.sb_agcount is not yet updated
565 * to the potentially higher ag count.
566 *
567 * Returns the maximum AG index which may contain inodes.
Eric Sandeen9de67c32014-07-24 20:51:54 +1000568 */
Carlos Maiolino2d2194f2012-09-20 10:32:38 -0300569xfs_agnumber_t
Eric Sandeen12c3f052016-03-02 09:58:09 +1100570xfs_set_inode_alloc(
571 struct xfs_mount *mp,
572 xfs_agnumber_t agcount)
Carlos Maiolino2d2194f2012-09-20 10:32:38 -0300573{
Eric Sandeen12c3f052016-03-02 09:58:09 +1100574 xfs_agnumber_t index;
Carlos Maiolino4056c1d2012-09-20 10:32:40 -0300575 xfs_agnumber_t maxagi = 0;
Carlos Maiolino2d2194f2012-09-20 10:32:38 -0300576 xfs_sb_t *sbp = &mp->m_sb;
577 xfs_agnumber_t max_metadata;
Eric Sandeen54aa61f2014-07-24 20:53:10 +1000578 xfs_agino_t agino;
579 xfs_ino_t ino;
Carlos Maiolino2d2194f2012-09-20 10:32:38 -0300580
Eric Sandeen12c3f052016-03-02 09:58:09 +1100581 /*
582 * Calculate how much should be reserved for inodes to meet
583 * the max inode percentage. Used only for inode32.
Carlos Maiolino2d2194f2012-09-20 10:32:38 -0300584 */
Darrick J. Wongef325952019-06-05 11:19:34 -0700585 if (M_IGEO(mp)->maxicount) {
Darrick J. Wongc8ce5402017-06-16 11:00:05 -0700586 uint64_t icount;
Carlos Maiolino2d2194f2012-09-20 10:32:38 -0300587
588 icount = sbp->sb_dblocks * sbp->sb_imax_pct;
589 do_div(icount, 100);
590 icount += sbp->sb_agblocks - 1;
591 do_div(icount, sbp->sb_agblocks);
592 max_metadata = icount;
593 } else {
Eric Sandeen9de67c32014-07-24 20:51:54 +1000594 max_metadata = agcount;
Carlos Maiolino2d2194f2012-09-20 10:32:38 -0300595 }
596
Eric Sandeen12c3f052016-03-02 09:58:09 +1100597 /* Get the last possible inode in the filesystem */
Darrick J. Wong43004b22018-12-12 08:46:24 -0800598 agino = XFS_AGB_TO_AGINO(mp, sbp->sb_agblocks - 1);
Eric Sandeen12c3f052016-03-02 09:58:09 +1100599 ino = XFS_AGINO_TO_INO(mp, agcount - 1, agino);
Eric Sandeen54aa61f2014-07-24 20:53:10 +1000600
Eric Sandeen12c3f052016-03-02 09:58:09 +1100601 /*
602 * If user asked for no more than 32-bit inodes, and the fs is
603 * sufficiently large, set XFS_MOUNT_32BITINODES if we must alter
604 * the allocator to accommodate the request.
605 */
606 if ((mp->m_flags & XFS_MOUNT_SMALL_INUMS) && ino > XFS_MAXINUMBER_32)
607 mp->m_flags |= XFS_MOUNT_32BITINODES;
608 else
609 mp->m_flags &= ~XFS_MOUNT_32BITINODES;
Carlos Maiolino2d2194f2012-09-20 10:32:38 -0300610
Eric Sandeen9de67c32014-07-24 20:51:54 +1000611 for (index = 0; index < agcount; index++) {
Carlos Maiolino2d2194f2012-09-20 10:32:38 -0300612 struct xfs_perag *pag;
613
Eric Sandeen12c3f052016-03-02 09:58:09 +1100614 ino = XFS_AGINO_TO_INO(mp, index, agino);
615
Carlos Maiolino2d2194f2012-09-20 10:32:38 -0300616 pag = xfs_perag_get(mp, index);
Eric Sandeen12c3f052016-03-02 09:58:09 +1100617
618 if (mp->m_flags & XFS_MOUNT_32BITINODES) {
619 if (ino > XFS_MAXINUMBER_32) {
620 pag->pagi_inodeok = 0;
621 pag->pagf_metadata = 0;
622 } else {
623 pag->pagi_inodeok = 1;
624 maxagi++;
625 if (index < max_metadata)
626 pag->pagf_metadata = 1;
627 else
628 pag->pagf_metadata = 0;
629 }
630 } else {
631 pag->pagi_inodeok = 1;
632 pag->pagf_metadata = 0;
633 }
634
Carlos Maiolino2d2194f2012-09-20 10:32:38 -0300635 xfs_perag_put(pag);
636 }
637
Eric Sandeen12c3f052016-03-02 09:58:09 +1100638 return (mp->m_flags & XFS_MOUNT_32BITINODES) ? maxagi : agcount;
Carlos Maiolino2d2194f2012-09-20 10:32:38 -0300639}
640
Hannes Eder3180e662009-03-04 19:34:10 +0100641STATIC int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642xfs_blkdev_get(
643 xfs_mount_t *mp,
644 const char *name,
645 struct block_device **bdevp)
646{
647 int error = 0;
648
Tejun Heod4d77622010-11-13 11:55:18 +0100649 *bdevp = blkdev_get_by_path(name, FMODE_READ|FMODE_WRITE|FMODE_EXCL,
650 mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 if (IS_ERR(*bdevp)) {
652 error = PTR_ERR(*bdevp);
Eric Sandeen77af5742014-12-24 09:47:27 +1100653 xfs_warn(mp, "Invalid device [%s], error=%d", name, error);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 }
655
Dave Chinner24513372014-06-25 14:58:08 +1000656 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657}
658
Hannes Eder3180e662009-03-04 19:34:10 +0100659STATIC void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660xfs_blkdev_put(
661 struct block_device *bdev)
662{
663 if (bdev)
Tejun Heoe525fd82010-11-13 11:55:17 +0100664 blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665}
666
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100667void
668xfs_blkdev_issue_flush(
669 xfs_buftarg_t *buftarg)
670{
Shaohua Li7582df52012-04-24 21:23:46 +0800671 blkdev_issue_flush(buftarg->bt_bdev, GFP_NOFS, NULL);
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100672}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000674STATIC void
675xfs_close_devices(
676 struct xfs_mount *mp)
677{
Dan Williams486aff52017-08-24 15:12:50 -0700678 struct dax_device *dax_ddev = mp->m_ddev_targp->bt_daxdev;
679
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000680 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
Lachlan McIlroyc032bfc2008-07-18 17:13:12 +1000681 struct block_device *logdev = mp->m_logdev_targp->bt_bdev;
Dan Williams486aff52017-08-24 15:12:50 -0700682 struct dax_device *dax_logdev = mp->m_logdev_targp->bt_daxdev;
683
Eric Sandeena1f69412018-04-06 10:09:42 -0700684 xfs_free_buftarg(mp->m_logdev_targp);
Lachlan McIlroyc032bfc2008-07-18 17:13:12 +1000685 xfs_blkdev_put(logdev);
Dan Williams486aff52017-08-24 15:12:50 -0700686 fs_put_dax(dax_logdev);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000687 }
688 if (mp->m_rtdev_targp) {
Lachlan McIlroyc032bfc2008-07-18 17:13:12 +1000689 struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev;
Dan Williams486aff52017-08-24 15:12:50 -0700690 struct dax_device *dax_rtdev = mp->m_rtdev_targp->bt_daxdev;
691
Eric Sandeena1f69412018-04-06 10:09:42 -0700692 xfs_free_buftarg(mp->m_rtdev_targp);
Lachlan McIlroyc032bfc2008-07-18 17:13:12 +1000693 xfs_blkdev_put(rtdev);
Dan Williams486aff52017-08-24 15:12:50 -0700694 fs_put_dax(dax_rtdev);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000695 }
Eric Sandeena1f69412018-04-06 10:09:42 -0700696 xfs_free_buftarg(mp->m_ddev_targp);
Dan Williams486aff52017-08-24 15:12:50 -0700697 fs_put_dax(dax_ddev);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000698}
699
700/*
701 * The file system configurations are:
702 * (1) device (partition) with data and internal log
703 * (2) logical volume with data and log subvolumes.
704 * (3) logical volume with data, log, and realtime subvolumes.
705 *
706 * We only have to handle opening the log and realtime volumes here if
707 * they are present. The data subvolume has already been opened by
708 * get_sb_bdev() and is stored in sb->s_bdev.
709 */
710STATIC int
711xfs_open_devices(
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100712 struct xfs_mount *mp)
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000713{
714 struct block_device *ddev = mp->m_super->s_bdev;
Dan Williams486aff52017-08-24 15:12:50 -0700715 struct dax_device *dax_ddev = fs_dax_get_by_bdev(ddev);
716 struct dax_device *dax_logdev = NULL, *dax_rtdev = NULL;
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000717 struct block_device *logdev = NULL, *rtdev = NULL;
718 int error;
719
720 /*
721 * Open real time and log devices - order is important.
722 */
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100723 if (mp->m_logname) {
724 error = xfs_blkdev_get(mp, mp->m_logname, &logdev);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000725 if (error)
726 goto out;
Dan Williams486aff52017-08-24 15:12:50 -0700727 dax_logdev = fs_dax_get_by_bdev(logdev);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000728 }
729
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100730 if (mp->m_rtname) {
731 error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000732 if (error)
733 goto out_close_logdev;
734
735 if (rtdev == ddev || rtdev == logdev) {
Dave Chinner4f107002011-03-07 10:00:35 +1100736 xfs_warn(mp,
737 "Cannot mount filesystem with identical rtdev and ddev/logdev.");
Dave Chinner24513372014-06-25 14:58:08 +1000738 error = -EINVAL;
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000739 goto out_close_rtdev;
740 }
Dan Williams486aff52017-08-24 15:12:50 -0700741 dax_rtdev = fs_dax_get_by_bdev(rtdev);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000742 }
743
744 /*
745 * Setup xfs_mount buffer target pointers
746 */
Dave Chinner24513372014-06-25 14:58:08 +1000747 error = -ENOMEM;
Dan Williams486aff52017-08-24 15:12:50 -0700748 mp->m_ddev_targp = xfs_alloc_buftarg(mp, ddev, dax_ddev);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000749 if (!mp->m_ddev_targp)
750 goto out_close_rtdev;
751
752 if (rtdev) {
Dan Williams486aff52017-08-24 15:12:50 -0700753 mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev, dax_rtdev);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000754 if (!mp->m_rtdev_targp)
755 goto out_free_ddev_targ;
756 }
757
758 if (logdev && logdev != ddev) {
Dan Williams486aff52017-08-24 15:12:50 -0700759 mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev, dax_logdev);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000760 if (!mp->m_logdev_targp)
761 goto out_free_rtdev_targ;
762 } else {
763 mp->m_logdev_targp = mp->m_ddev_targp;
764 }
765
766 return 0;
767
768 out_free_rtdev_targ:
769 if (mp->m_rtdev_targp)
Eric Sandeena1f69412018-04-06 10:09:42 -0700770 xfs_free_buftarg(mp->m_rtdev_targp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000771 out_free_ddev_targ:
Eric Sandeena1f69412018-04-06 10:09:42 -0700772 xfs_free_buftarg(mp->m_ddev_targp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000773 out_close_rtdev:
Markus Elfringd2a5e3c2014-12-01 08:24:20 +1100774 xfs_blkdev_put(rtdev);
Dan Williams486aff52017-08-24 15:12:50 -0700775 fs_put_dax(dax_rtdev);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000776 out_close_logdev:
Dan Williams486aff52017-08-24 15:12:50 -0700777 if (logdev && logdev != ddev) {
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000778 xfs_blkdev_put(logdev);
Dan Williams486aff52017-08-24 15:12:50 -0700779 fs_put_dax(dax_logdev);
780 }
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000781 out:
Dan Williams486aff52017-08-24 15:12:50 -0700782 fs_put_dax(dax_ddev);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000783 return error;
784}
785
Christoph Hellwige34b5622008-05-20 15:10:36 +1000786/*
787 * Setup xfs_mount buffer target pointers based on superblock
788 */
789STATIC int
790xfs_setup_devices(
791 struct xfs_mount *mp)
792{
793 int error;
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000794
Eric Sandeena96c4152014-04-14 19:00:29 +1000795 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_sectsize);
Christoph Hellwige34b5622008-05-20 15:10:36 +1000796 if (error)
797 return error;
798
799 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
800 unsigned int log_sector_size = BBSIZE;
801
802 if (xfs_sb_version_hassector(&mp->m_sb))
803 log_sector_size = mp->m_sb.sb_logsectsize;
804 error = xfs_setsize_buftarg(mp->m_logdev_targp,
Christoph Hellwige34b5622008-05-20 15:10:36 +1000805 log_sector_size);
806 if (error)
807 return error;
808 }
809 if (mp->m_rtdev_targp) {
810 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
Christoph Hellwige34b5622008-05-20 15:10:36 +1000811 mp->m_sb.sb_sectsize);
812 if (error)
813 return error;
814 }
815
816 return 0;
817}
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000818
Christoph Hellwigaa6bf012012-02-29 09:53:48 +0000819STATIC int
820xfs_init_mount_workqueues(
821 struct xfs_mount *mp)
822{
Brian Foster78c931b2014-11-28 13:59:58 +1100823 mp->m_buf_workqueue = alloc_workqueue("xfs-buf/%s",
Brian Fosterb29c70f2014-12-04 09:43:17 +1100824 WQ_MEM_RECLAIM|WQ_FREEZABLE, 1, mp->m_fsname);
Brian Foster78c931b2014-11-28 13:59:58 +1100825 if (!mp->m_buf_workqueue)
826 goto out;
827
Christoph Hellwigaa6bf012012-02-29 09:53:48 +0000828 mp->m_unwritten_workqueue = alloc_workqueue("xfs-conv/%s",
Brian Foster8018ec02014-09-09 11:44:46 +1000829 WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_fsname);
Christoph Hellwigaa6bf012012-02-29 09:53:48 +0000830 if (!mp->m_unwritten_workqueue)
Darrick J. Wong28408242019-04-15 13:13:21 -0700831 goto out_destroy_buf;
Christoph Hellwigaa6bf012012-02-29 09:53:48 +0000832
Dave Chinner4c2d5422012-04-23 17:54:32 +1000833 mp->m_cil_workqueue = alloc_workqueue("xfs-cil/%s",
Brian Foster8018ec02014-09-09 11:44:46 +1000834 WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_fsname);
Dave Chinner4c2d5422012-04-23 17:54:32 +1000835 if (!mp->m_cil_workqueue)
836 goto out_destroy_unwritten;
Dave Chinner58896082012-10-08 21:56:05 +1100837
838 mp->m_reclaim_workqueue = alloc_workqueue("xfs-reclaim/%s",
Chris Mason7a29ac42015-11-10 10:10:34 +1100839 WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_fsname);
Dave Chinner58896082012-10-08 21:56:05 +1100840 if (!mp->m_reclaim_workqueue)
841 goto out_destroy_cil;
842
Brian Foster579b62f2012-11-06 09:50:47 -0500843 mp->m_eofblocks_workqueue = alloc_workqueue("xfs-eofblocks/%s",
Chris Mason7a29ac42015-11-10 10:10:34 +1100844 WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_fsname);
Brian Foster579b62f2012-11-06 09:50:47 -0500845 if (!mp->m_eofblocks_workqueue)
Christoph Hellwig1058d0f2019-06-28 19:27:25 -0700846 goto out_destroy_reclaim;
Brian Foster579b62f2012-11-06 09:50:47 -0500847
Brian Foster696a5622017-03-28 14:51:44 -0700848 mp->m_sync_workqueue = alloc_workqueue("xfs-sync/%s", WQ_FREEZABLE, 0,
849 mp->m_fsname);
850 if (!mp->m_sync_workqueue)
851 goto out_destroy_eofb;
852
Christoph Hellwigaa6bf012012-02-29 09:53:48 +0000853 return 0;
854
Brian Foster696a5622017-03-28 14:51:44 -0700855out_destroy_eofb:
856 destroy_workqueue(mp->m_eofblocks_workqueue);
Dave Chinner58896082012-10-08 21:56:05 +1100857out_destroy_reclaim:
858 destroy_workqueue(mp->m_reclaim_workqueue);
859out_destroy_cil:
860 destroy_workqueue(mp->m_cil_workqueue);
Dave Chinner4c2d5422012-04-23 17:54:32 +1000861out_destroy_unwritten:
862 destroy_workqueue(mp->m_unwritten_workqueue);
Brian Foster78c931b2014-11-28 13:59:58 +1100863out_destroy_buf:
864 destroy_workqueue(mp->m_buf_workqueue);
Christoph Hellwigaa6bf012012-02-29 09:53:48 +0000865out:
866 return -ENOMEM;
867}
868
869STATIC void
870xfs_destroy_mount_workqueues(
871 struct xfs_mount *mp)
872{
Brian Foster696a5622017-03-28 14:51:44 -0700873 destroy_workqueue(mp->m_sync_workqueue);
Brian Foster579b62f2012-11-06 09:50:47 -0500874 destroy_workqueue(mp->m_eofblocks_workqueue);
Dave Chinner58896082012-10-08 21:56:05 +1100875 destroy_workqueue(mp->m_reclaim_workqueue);
Dave Chinner4c2d5422012-04-23 17:54:32 +1000876 destroy_workqueue(mp->m_cil_workqueue);
Christoph Hellwigaa6bf012012-02-29 09:53:48 +0000877 destroy_workqueue(mp->m_unwritten_workqueue);
Brian Foster78c931b2014-11-28 13:59:58 +1100878 destroy_workqueue(mp->m_buf_workqueue);
Christoph Hellwigaa6bf012012-02-29 09:53:48 +0000879}
880
Dave Chinner9aa05002012-10-08 21:56:04 +1100881/*
882 * Flush all dirty data to disk. Must not be called while holding an XFS_ILOCK
883 * or a page lock. We use sync_inodes_sb() here to ensure we block while waiting
884 * for IO to complete so that we effectively throttle multiple callers to the
885 * rate at which IO is completing.
886 */
887void
888xfs_flush_inodes(
889 struct xfs_mount *mp)
890{
891 struct super_block *sb = mp->m_super;
892
893 if (down_read_trylock(&sb->s_umount)) {
Jan Kara0dc83bd2014-02-21 11:19:04 +0100894 sync_inodes_sb(sb);
Dave Chinner9aa05002012-10-08 21:56:04 +1100895 up_read(&sb->s_umount);
896 }
897}
898
David Chinnerbf904242008-10-30 17:36:14 +1100899/* Catch misguided souls that try to use this interface on XFS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900STATIC struct inode *
Nathan Scotta50cd262006-03-14 14:06:18 +1100901xfs_fs_alloc_inode(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 struct super_block *sb)
903{
David Chinnerbf904242008-10-30 17:36:14 +1100904 BUG();
Lachlan McIlroy493dca62008-10-30 17:36:52 +1100905 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906}
907
Christoph Hellwig48318222018-10-18 17:20:11 +1100908#ifdef DEBUG
909static void
910xfs_check_delalloc(
911 struct xfs_inode *ip,
912 int whichfork)
913{
914 struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, whichfork);
915 struct xfs_bmbt_irec got;
916 struct xfs_iext_cursor icur;
917
918 if (!ifp || !xfs_iext_lookup_extent(ip, ifp, 0, &icur, &got))
919 return;
920 do {
921 if (isnullstartblock(got.br_startblock)) {
922 xfs_warn(ip->i_mount,
923 "ino %llx %s fork has delalloc extent at [0x%llx:0x%llx]",
924 ip->i_ino,
925 whichfork == XFS_DATA_FORK ? "data" : "cow",
926 got.br_startoff, got.br_blockcount);
927 }
928 } while (xfs_iext_next_extent(ifp, &icur, &got));
929}
930#else
931#define xfs_check_delalloc(ip, whichfork) do { } while (0)
932#endif
933
David Chinnerbf904242008-10-30 17:36:14 +1100934/*
David Chinner99fa8cb2008-10-30 17:36:40 +1100935 * Now that the generic code is guaranteed not to be accessing
Dave Chinner8179c032016-05-18 13:52:42 +1000936 * the linux inode, we can inactivate and reclaim the inode.
David Chinnerbf904242008-10-30 17:36:14 +1100937 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +1100939xfs_fs_destroy_inode(
Christoph Hellwig848ce8f2009-09-29 13:48:56 +0000940 struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941{
Christoph Hellwig848ce8f2009-09-29 13:48:56 +0000942 struct xfs_inode *ip = XFS_I(inode);
943
Christoph Hellwigcca28fb2010-06-24 11:57:09 +1000944 trace_xfs_destroy_inode(ip);
David Chinner99fa8cb2008-10-30 17:36:40 +1100945
Christoph Hellwig65523212016-11-30 14:33:25 +1100946 ASSERT(!rwsem_is_locked(&inode->i_rwsem));
Dave Chinner8179c032016-05-18 13:52:42 +1000947 XFS_STATS_INC(ip->i_mount, vn_rele);
948 XFS_STATS_INC(ip->i_mount, vn_remove);
949
950 xfs_inactive(ip);
Christoph Hellwig848ce8f2009-09-29 13:48:56 +0000951
Christoph Hellwig48318222018-10-18 17:20:11 +1100952 if (!XFS_FORCED_SHUTDOWN(ip->i_mount) && ip->i_delayed_blks) {
953 xfs_check_delalloc(ip, XFS_DATA_FORK);
954 xfs_check_delalloc(ip, XFS_COW_FORK);
955 ASSERT(0);
956 }
957
Dave Chinner8179c032016-05-18 13:52:42 +1000958 XFS_STATS_INC(ip->i_mount, vn_reclaim);
Christoph Hellwig848ce8f2009-09-29 13:48:56 +0000959
960 /*
961 * We should never get here with one of the reclaim flags already set.
962 */
963 ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIMABLE));
964 ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIM));
965
966 /*
Dave Chinner57817c62010-01-10 23:51:47 +0000967 * We always use background reclaim here because even if the
968 * inode is clean, it still may be under IO and hence we have
969 * to take the flush lock. The background reclaim path handles
970 * this more efficiently than we can here, so simply let background
971 * reclaim tear down all inodes.
Christoph Hellwig848ce8f2009-09-29 13:48:56 +0000972 */
Dave Chinner57817c62010-01-10 23:51:47 +0000973 xfs_inode_set_reclaim_tag(ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974}
975
Christoph Hellwigc3b1b132018-03-06 17:04:00 -0800976static void
977xfs_fs_dirty_inode(
978 struct inode *inode,
979 int flag)
980{
981 struct xfs_inode *ip = XFS_I(inode);
982 struct xfs_mount *mp = ip->i_mount;
983 struct xfs_trans *tp;
984
985 if (!(inode->i_sb->s_flags & SB_LAZYTIME))
986 return;
987 if (flag != I_DIRTY_SYNC || !(inode->i_state & I_DIRTY_TIME))
988 return;
989
990 if (xfs_trans_alloc(mp, &M_RES(mp)->tr_fsyncts, 0, 0, 0, &tp))
991 return;
992 xfs_ilock(ip, XFS_ILOCK_EXCL);
993 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
994 xfs_trans_log_inode(tp, ip, XFS_ILOG_TIMESTAMP);
995 xfs_trans_commit(tp);
996}
997
David Chinner07c8f672008-10-30 16:11:59 +1100998/*
999 * Slab object creation initialisation for the XFS inode.
1000 * This covers only the idempotent fields in the XFS inode;
1001 * all other fields need to be initialised on allocation
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04001002 * from the slab. This avoids the need to repeatedly initialise
David Chinner07c8f672008-10-30 16:11:59 +11001003 * fields in the xfs inode that left in the initialise state
1004 * when freeing the inode.
1005 */
David Chinnerbf904242008-10-30 17:36:14 +11001006STATIC void
1007xfs_fs_inode_init_once(
David Chinner07c8f672008-10-30 16:11:59 +11001008 void *inode)
1009{
1010 struct xfs_inode *ip = inode;
1011
1012 memset(ip, 0, sizeof(struct xfs_inode));
David Chinnerbf904242008-10-30 17:36:14 +11001013
1014 /* vfs inode */
1015 inode_init_once(VFS_I(ip));
1016
1017 /* xfs inode */
David Chinner07c8f672008-10-30 16:11:59 +11001018 atomic_set(&ip->i_pincount, 0);
1019 spin_lock_init(&ip->i_flags_lock);
David Chinner07c8f672008-10-30 16:11:59 +11001020
Dave Chinner653c60b2015-02-23 21:43:37 +11001021 mrlock_init(&ip->i_mmaplock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
1022 "xfsino", ip->i_ino);
David Chinner07c8f672008-10-30 16:11:59 +11001023 mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
1024 "xfsino", ip->i_ino);
David Chinner07c8f672008-10-30 16:11:59 +11001025}
1026
Dave Chinner5132ba82012-03-22 05:15:10 +00001027/*
1028 * We do an unlocked check for XFS_IDONTCACHE here because we are already
1029 * serialised against cache hits here via the inode->i_lock and igrab() in
1030 * xfs_iget_cache_hit(). Hence a lookup that might clear this flag will not be
1031 * racing with us, and it avoids needing to grab a spinlock here for every inode
1032 * we drop the final reference on.
1033 */
1034STATIC int
1035xfs_fs_drop_inode(
1036 struct inode *inode)
1037{
1038 struct xfs_inode *ip = XFS_I(inode);
1039
Darrick J. Wong17c12bc2016-10-03 09:11:29 -07001040 /*
1041 * If this unlinked inode is in the middle of recovery, don't
1042 * drop the inode just yet; log recovery will take care of
1043 * that. See the comment for this inode flag.
1044 */
1045 if (ip->i_flags & XFS_IRECOVERY) {
1046 ASSERT(ip->i_mount->m_log->l_flags & XLOG_RECOVERY_NEEDED);
1047 return 0;
1048 }
1049
Dave Chinner5132ba82012-03-22 05:15:10 +00001050 return generic_drop_inode(inode) || (ip->i_flags & XFS_IDONTCACHE);
1051}
1052
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053STATIC void
Christoph Hellwiga7381592008-08-13 16:04:05 +10001054xfs_free_fsname(
1055 struct xfs_mount *mp)
1056{
1057 kfree(mp->m_fsname);
1058 kfree(mp->m_rtname);
1059 kfree(mp->m_logname);
1060}
1061
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062STATIC int
Christoph Hellwig69961a22009-10-06 20:29:28 +00001063xfs_fs_sync_fs(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 struct super_block *sb,
1065 int wait)
1066{
Christoph Hellwig745f6912007-08-30 17:20:39 +10001067 struct xfs_mount *mp = XFS_M(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068
Lachlan McIlroye893bff2007-10-12 11:13:35 +10001069 /*
Christoph Hellwig34625c62011-12-06 21:58:12 +00001070 * Doing anything during the async pass would be counterproductive.
Lachlan McIlroye893bff2007-10-12 11:13:35 +10001071 */
Christoph Hellwig34625c62011-12-06 21:58:12 +00001072 if (!wait)
Christoph Hellwig69961a22009-10-06 20:29:28 +00001073 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074
Dave Chinner34061f52012-10-08 21:56:06 +11001075 xfs_log_force(mp, XFS_LOG_SYNC);
Christoph Hellwig69961a22009-10-06 20:29:28 +00001076 if (laptop_mode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 /*
1078 * The disk must be active because we're syncing.
Dave Chinnerf661f1e2012-10-08 21:56:02 +11001079 * We schedule log work now (now that the disk is
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 * active) instead of later (when it might not be).
1081 */
Dave Chinnerf661f1e2012-10-08 21:56:02 +11001082 flush_delayed_work(&mp->m_log->l_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 }
1084
Christoph Hellwig69961a22009-10-06 20:29:28 +00001085 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086}
1087
1088STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001089xfs_fs_statfs(
David Howells726c3342006-06-23 02:02:58 -07001090 struct dentry *dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 struct kstatfs *statp)
1092{
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001093 struct xfs_mount *mp = XFS_M(dentry->d_sb);
1094 xfs_sb_t *sbp = &mp->m_sb;
David Howells2b0143b2015-03-17 22:25:59 +00001095 struct xfs_inode *ip = XFS_I(d_inode(dentry));
Darrick J. Wongc8ce5402017-06-16 11:00:05 -07001096 uint64_t fakeinos, id;
1097 uint64_t icount;
1098 uint64_t ifree;
1099 uint64_t fdblocks;
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001100 xfs_extlen_t lsize;
Darrick J. Wongc8ce5402017-06-16 11:00:05 -07001101 int64_t ffree;
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001102
Adam Borowskidddde682018-10-18 17:20:19 +11001103 statp->f_type = XFS_SUPER_MAGIC;
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001104 statp->f_namelen = MAXNAMELEN - 1;
1105
1106 id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
1107 statp->f_fsid.val[0] = (u32)id;
1108 statp->f_fsid.val[1] = (u32)(id >> 32);
1109
Dave Chinner501ab322015-02-23 21:19:28 +11001110 icount = percpu_counter_sum(&mp->m_icount);
Dave Chinnere88b64e2015-02-23 21:19:53 +11001111 ifree = percpu_counter_sum(&mp->m_ifree);
Dave Chinner0d485ad2015-02-23 21:22:03 +11001112 fdblocks = percpu_counter_sum(&mp->m_fdblocks);
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001113
1114 spin_lock(&mp->m_sb_lock);
1115 statp->f_bsize = sbp->sb_blocksize;
1116 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
1117 statp->f_blocks = sbp->sb_dblocks - lsize;
Dave Chinner0d485ad2015-02-23 21:22:03 +11001118 spin_unlock(&mp->m_sb_lock);
1119
Darrick J. Wong52548852016-08-03 11:38:24 +10001120 statp->f_bfree = fdblocks - mp->m_alloc_set_aside;
Dave Chinner0d485ad2015-02-23 21:22:03 +11001121 statp->f_bavail = statp->f_bfree;
1122
Darrick J. Wong43004b22018-12-12 08:46:24 -08001123 fakeinos = XFS_FSB_TO_INO(mp, statp->f_bfree);
Dave Chinner9bb54cb2018-06-07 07:54:02 -07001124 statp->f_files = min(icount + fakeinos, (uint64_t)XFS_MAXINUMBER);
Darrick J. Wongef325952019-06-05 11:19:34 -07001125 if (M_IGEO(mp)->maxicount)
Christoph Hellwiga19d9f82009-03-29 09:51:08 +02001126 statp->f_files = min_t(typeof(statp->f_files),
1127 statp->f_files,
Darrick J. Wongef325952019-06-05 11:19:34 -07001128 M_IGEO(mp)->maxicount);
Stuart Brodsky2fe33662010-08-24 11:46:05 +10001129
Eric Sandeen01f98822015-02-06 09:53:02 +11001130 /* If sb_icount overshot maxicount, report actual allocation */
1131 statp->f_files = max_t(typeof(statp->f_files),
1132 statp->f_files,
1133 sbp->sb_icount);
1134
Stuart Brodsky2fe33662010-08-24 11:46:05 +10001135 /* make sure statp->f_ffree does not underflow */
Dave Chinnere88b64e2015-02-23 21:19:53 +11001136 ffree = statp->f_files - (icount - ifree);
Darrick J. Wongc8ce5402017-06-16 11:00:05 -07001137 statp->f_ffree = max_t(int64_t, ffree, 0);
Stuart Brodsky2fe33662010-08-24 11:46:05 +10001138
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001139
Jie Liuda5bf952012-04-12 03:59:57 +00001140 if ((ip->i_d.di_flags & XFS_DIFLAG_PROJINHERIT) &&
Chandra Seetharaman83e782e2013-06-27 17:25:10 -05001141 ((mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))) ==
1142 (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))
Christoph Hellwig7d095252009-06-08 15:33:32 +02001143 xfs_qm_statvfs(ip, statp);
Richard Wareinga0158312018-01-08 10:41:33 -08001144
1145 if (XFS_IS_REALTIME_MOUNT(mp) &&
1146 (ip->i_d.di_flags & (XFS_DIFLAG_RTINHERIT | XFS_DIFLAG_REALTIME))) {
1147 statp->f_blocks = sbp->sb_rblocks;
1148 statp->f_bavail = statp->f_bfree =
1149 sbp->sb_frextents * sbp->sb_rextsize;
1150 }
1151
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001152 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153}
1154
Eric Sandeend5db0f92010-02-05 22:59:53 +00001155STATIC void
1156xfs_save_resvblks(struct xfs_mount *mp)
1157{
Darrick J. Wongc8ce5402017-06-16 11:00:05 -07001158 uint64_t resblks = 0;
Eric Sandeend5db0f92010-02-05 22:59:53 +00001159
1160 mp->m_resblks_save = mp->m_resblks;
1161 xfs_reserve_blocks(mp, &resblks, NULL);
1162}
1163
1164STATIC void
1165xfs_restore_resvblks(struct xfs_mount *mp)
1166{
Darrick J. Wongc8ce5402017-06-16 11:00:05 -07001167 uint64_t resblks;
Eric Sandeend5db0f92010-02-05 22:59:53 +00001168
1169 if (mp->m_resblks_save) {
1170 resblks = mp->m_resblks_save;
1171 mp->m_resblks_save = 0;
1172 } else
1173 resblks = xfs_default_resblks(mp);
1174
1175 xfs_reserve_blocks(mp, &resblks, NULL);
1176}
1177
Dave Chinnerc7eea6f2012-10-08 21:56:07 +11001178/*
1179 * Trigger writeback of all the dirty metadata in the file system.
1180 *
1181 * This ensures that the metadata is written to their location on disk rather
1182 * than just existing in transactions in the log. This means after a quiesce
Dave Chinnerc75921a2012-10-08 21:56:08 +11001183 * there is no log replay required to write the inodes to disk - this is the
1184 * primary difference between a sync and a quiesce.
Dave Chinnerc7eea6f2012-10-08 21:56:07 +11001185 *
Dave Chinnerc75921a2012-10-08 21:56:08 +11001186 * Note: xfs_log_quiesce() stops background log work - the callers must ensure
1187 * it is started again when appropriate.
Dave Chinnerc7eea6f2012-10-08 21:56:07 +11001188 */
Dave Chinnerddeb14f2016-09-26 08:21:44 +10001189void
Dave Chinnerc7eea6f2012-10-08 21:56:07 +11001190xfs_quiesce_attr(
1191 struct xfs_mount *mp)
1192{
1193 int error = 0;
1194
1195 /* wait for all modifications to complete */
1196 while (atomic_read(&mp->m_active_trans) > 0)
1197 delay(100);
1198
1199 /* force the log to unpin objects from the now complete transactions */
1200 xfs_log_force(mp, XFS_LOG_SYNC);
1201
1202 /* reclaim inodes to do any IO before the freeze completes */
1203 xfs_reclaim_inodes(mp, 0);
1204 xfs_reclaim_inodes(mp, SYNC_WAIT);
1205
Dave Chinnerc75921a2012-10-08 21:56:08 +11001206 /* Push the superblock and write an unmount record */
1207 error = xfs_log_sbcount(mp);
1208 if (error)
1209 xfs_warn(mp, "xfs_attr_quiesce: failed to log sb changes. "
1210 "Frozen image may not be consistent.");
Dave Chinnerc7eea6f2012-10-08 21:56:07 +11001211 /*
1212 * Just warn here till VFS can correctly support
1213 * read-only remount without racing.
1214 */
1215 WARN_ON(atomic_read(&mp->m_active_trans) != 0);
1216
Dave Chinnerc75921a2012-10-08 21:56:08 +11001217 xfs_log_quiesce(mp);
Dave Chinnerc7eea6f2012-10-08 21:56:07 +11001218}
1219
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220STATIC int
Eric Sandeena08ee402016-03-02 09:56:31 +11001221xfs_test_remount_options(
1222 struct super_block *sb,
Eric Sandeena08ee402016-03-02 09:56:31 +11001223 char *options)
1224{
1225 int error = 0;
1226 struct xfs_mount *tmp_mp;
1227
1228 tmp_mp = kmem_zalloc(sizeof(*tmp_mp), KM_MAYFAIL);
1229 if (!tmp_mp)
1230 return -ENOMEM;
1231
1232 tmp_mp->m_super = sb;
1233 error = xfs_parseargs(tmp_mp, options);
1234 xfs_free_fsname(tmp_mp);
Pan Bian6c370592017-09-02 09:54:23 -07001235 kmem_free(tmp_mp);
Eric Sandeena08ee402016-03-02 09:56:31 +11001236
1237 return error;
1238}
1239
1240STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001241xfs_fs_remount(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 struct super_block *sb,
1243 int *flags,
1244 char *options)
1245{
Christoph Hellwig745f6912007-08-30 17:20:39 +10001246 struct xfs_mount *mp = XFS_M(sb);
Eric Sandeen9de67c32014-07-24 20:51:54 +10001247 xfs_sb_t *sbp = &mp->m_sb;
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001248 substring_t args[MAX_OPT_ARGS];
1249 char *p;
Christoph Hellwig7884bc82009-01-19 02:04:07 +01001250 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251
Eric Sandeena08ee402016-03-02 09:56:31 +11001252 /* First, check for complete junk; i.e. invalid options */
Eric Sandeena1f69412018-04-06 10:09:42 -07001253 error = xfs_test_remount_options(sb, options);
Eric Sandeena08ee402016-03-02 09:56:31 +11001254 if (error)
1255 return error;
1256
Theodore Ts'o02b99842014-03-13 10:14:33 -04001257 sync_filesystem(sb);
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001258 while ((p = strsep(&options, ",")) != NULL) {
1259 int token;
Christoph Hellwigbdd907b2008-05-20 15:10:44 +10001260
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001261 if (!*p)
1262 continue;
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001263
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001264 token = match_token(p, tokens, args);
1265 switch (token) {
Carlos Maiolinoc3a58fe2012-08-17 18:19:38 -03001266 case Opt_inode64:
Eric Sandeen12c3f052016-03-02 09:58:09 +11001267 mp->m_flags &= ~XFS_MOUNT_SMALL_INUMS;
1268 mp->m_maxagi = xfs_set_inode_alloc(mp, sbp->sb_agcount);
Carlos Maiolinoc3a58fe2012-08-17 18:19:38 -03001269 break;
Carlos Maiolino2ea03922012-09-20 10:32:41 -03001270 case Opt_inode32:
Eric Sandeen12c3f052016-03-02 09:58:09 +11001271 mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
1272 mp->m_maxagi = xfs_set_inode_alloc(mp, sbp->sb_agcount);
Carlos Maiolino2ea03922012-09-20 10:32:41 -03001273 break;
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001274 default:
Christoph Hellwig6efdf282008-09-17 16:49:33 +10001275 /*
1276 * Logically we would return an error here to prevent
1277 * users from believing they might have changed
1278 * mount options using remount which can't be changed.
1279 *
1280 * But unfortunately mount(8) adds all options from
1281 * mtab and fstab to the mount arguments in some cases
1282 * so we can't blindly reject options, but have to
1283 * check for each specified option if it actually
1284 * differs from the currently set option and only
1285 * reject it if that's the case.
1286 *
1287 * Until that is implemented we return success for
1288 * every remount request, and silently ignore all
1289 * options that we can't actually change.
1290 */
1291#if 0
Dave Chinner4f107002011-03-07 10:00:35 +11001292 xfs_info(mp,
Eric Sandeen08e96e12013-10-11 20:59:05 -05001293 "mount option \"%s\" not supported for remount", p);
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001294 return -EINVAL;
Christoph Hellwig6efdf282008-09-17 16:49:33 +10001295#else
Christoph Hellwig6c5e51d2008-10-12 14:30:44 +02001296 break;
Christoph Hellwig6efdf282008-09-17 16:49:33 +10001297#endif
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001298 }
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001299 }
1300
Christoph Hellwig7884bc82009-01-19 02:04:07 +01001301 /* ro -> rw */
Linus Torvalds1751e8a2017-11-27 13:05:09 -08001302 if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(*flags & SB_RDONLY)) {
Eric Sandeenbbe051c2015-04-13 11:25:41 +10001303 if (mp->m_flags & XFS_MOUNT_NORECOVERY) {
1304 xfs_warn(mp,
1305 "ro->rw transition prohibited on norecovery mount");
1306 return -EINVAL;
1307 }
1308
Eric Sandeend0a58e82016-04-06 07:05:41 +10001309 if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 &&
1310 xfs_sb_has_ro_compat_feature(sbp,
1311 XFS_SB_FEAT_RO_COMPAT_UNKNOWN)) {
1312 xfs_warn(mp,
1313"ro->rw transition prohibited on unknown (0x%x) ro-compat filesystem",
1314 (sbp->sb_features_ro_compat &
1315 XFS_SB_FEAT_RO_COMPAT_UNKNOWN));
1316 return -EINVAL;
1317 }
1318
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001319 mp->m_flags &= ~XFS_MOUNT_RDONLY;
Christoph Hellwig7884bc82009-01-19 02:04:07 +01001320
1321 /*
1322 * If this is the first remount to writeable state we
1323 * might have some superblock changes to update.
1324 */
Dave Chinner61e63ec2015-01-22 09:10:31 +11001325 if (mp->m_update_sb) {
1326 error = xfs_sync_sb(mp, false);
Christoph Hellwig7884bc82009-01-19 02:04:07 +01001327 if (error) {
Dave Chinner4f107002011-03-07 10:00:35 +11001328 xfs_warn(mp, "failed to write sb changes");
Christoph Hellwig7884bc82009-01-19 02:04:07 +01001329 return error;
1330 }
Dave Chinner61e63ec2015-01-22 09:10:31 +11001331 mp->m_update_sb = false;
Christoph Hellwig7884bc82009-01-19 02:04:07 +01001332 }
Dave Chinnercbe132a2010-01-26 15:08:49 +11001333
1334 /*
1335 * Fill out the reserve pool if it is empty. Use the stashed
1336 * value if it is non-zero, otherwise go with the default.
1337 */
Eric Sandeend5db0f92010-02-05 22:59:53 +00001338 xfs_restore_resvblks(mp);
Dave Chinnerf661f1e2012-10-08 21:56:02 +11001339 xfs_log_work_queue(mp);
Darrick J. Wong174edb02016-10-03 09:11:39 -07001340
1341 /* Recover any CoW blocks that never got remapped. */
1342 error = xfs_reflink_recover_cow(mp);
1343 if (error) {
1344 xfs_err(mp,
1345 "Error %d recovering leftover CoW allocations.", error);
1346 xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
1347 return error;
1348 }
Darrick J. Wonged30dcb2019-04-25 18:26:22 -07001349 xfs_start_block_reaping(mp);
Darrick J. Wong84d69612016-10-03 09:11:44 -07001350
1351 /* Create the per-AG metadata reservation pool .*/
1352 error = xfs_fs_reserve_ag_blocks(mp);
1353 if (error && error != -ENOSPC)
1354 return error;
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001355 }
1356
1357 /* rw -> ro */
Linus Torvalds1751e8a2017-11-27 13:05:09 -08001358 if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (*flags & SB_RDONLY)) {
Darrick J. Wongd6b636e2018-05-09 10:03:56 -07001359 /*
1360 * Cancel background eofb scanning so it cannot race with the
1361 * final log force+buftarg wait and deadlock the remount.
1362 */
Darrick J. Wonged30dcb2019-04-25 18:26:22 -07001363 xfs_stop_block_reaping(mp);
Darrick J. Wongd6b636e2018-05-09 10:03:56 -07001364
Darrick J. Wong10ddf642017-12-14 15:46:05 -08001365 /* Get rid of any leftover CoW reservations... */
Darrick J. Wong10ddf642017-12-14 15:46:05 -08001366 error = xfs_icache_free_cowblocks(mp, NULL);
1367 if (error) {
1368 xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
1369 return error;
1370 }
1371
Darrick J. Wong84d69612016-10-03 09:11:44 -07001372 /* Free the per-AG metadata reservation pool. */
1373 error = xfs_fs_unreserve_ag_blocks(mp);
1374 if (error) {
1375 xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
1376 return error;
1377 }
1378
Dave Chinnercbe132a2010-01-26 15:08:49 +11001379 /*
Dave Chinner34061f52012-10-08 21:56:06 +11001380 * Before we sync the metadata, we need to free up the reserve
1381 * block pool so that the used block count in the superblock on
1382 * disk is correct at the end of the remount. Stash the current
1383 * reserve pool size so that if we get remounted rw, we can
1384 * return it to the same size.
Dave Chinnercbe132a2010-01-26 15:08:49 +11001385 */
Eric Sandeend5db0f92010-02-05 22:59:53 +00001386 xfs_save_resvblks(mp);
Brian Fosterfa5a4f52016-06-21 11:53:28 +10001387
David Chinner76bf1052008-10-30 17:16:21 +11001388 xfs_quiesce_attr(mp);
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001389 mp->m_flags |= XFS_MOUNT_RDONLY;
1390 }
1391
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001392 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393}
1394
Christoph Hellwig9909c4a2007-10-11 18:11:14 +10001395/*
1396 * Second stage of a freeze. The data is already frozen so we only
Dave Chinner61e63ec2015-01-22 09:10:31 +11001397 * need to take care of the metadata. Once that's done sync the superblock
1398 * to the log to dirty it in case of a crash while frozen. This ensures that we
1399 * will recover the unlinked inode lists on the next mount.
Christoph Hellwig9909c4a2007-10-11 18:11:14 +10001400 */
Takashi Satoc4be0c12009-01-09 16:40:58 -08001401STATIC int
1402xfs_fs_freeze(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 struct super_block *sb)
1404{
Christoph Hellwig9909c4a2007-10-11 18:11:14 +10001405 struct xfs_mount *mp = XFS_M(sb);
1406
Darrick J. Wonged30dcb2019-04-25 18:26:22 -07001407 xfs_stop_block_reaping(mp);
Eric Sandeend5db0f92010-02-05 22:59:53 +00001408 xfs_save_resvblks(mp);
David Chinner76bf1052008-10-30 17:16:21 +11001409 xfs_quiesce_attr(mp);
Dave Chinner61e63ec2015-01-22 09:10:31 +11001410 return xfs_sync_sb(mp, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411}
1412
1413STATIC int
Eric Sandeend5db0f92010-02-05 22:59:53 +00001414xfs_fs_unfreeze(
1415 struct super_block *sb)
1416{
1417 struct xfs_mount *mp = XFS_M(sb);
1418
1419 xfs_restore_resvblks(mp);
Dave Chinnerf661f1e2012-10-08 21:56:02 +11001420 xfs_log_work_queue(mp);
Darrick J. Wonged30dcb2019-04-25 18:26:22 -07001421 xfs_start_block_reaping(mp);
Eric Sandeend5db0f92010-02-05 22:59:53 +00001422 return 0;
1423}
1424
1425STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001426xfs_fs_show_options(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 struct seq_file *m,
Al Viro34c80b12011-12-08 21:32:45 -05001428 struct dentry *root)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429{
Eric Sandeen91083262019-05-01 20:26:30 -07001430 xfs_showargs(XFS_M(root->d_sb), m);
1431 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432}
1433
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001434/*
1435 * This function fills in xfs_mount_t fields based on mount args.
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001436 * Note: the superblock _has_ now been read in.
1437 */
1438STATIC int
1439xfs_finish_flags(
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001440 struct xfs_mount *mp)
1441{
1442 int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
1443
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02001444 /* Fail a mount where the logbuf is smaller than the log stripe */
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001445 if (xfs_sb_version_haslogv2(&mp->m_sb)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001446 if (mp->m_logbsize <= 0 &&
1447 mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE) {
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001448 mp->m_logbsize = mp->m_sb.sb_logsunit;
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001449 } else if (mp->m_logbsize > 0 &&
1450 mp->m_logbsize < mp->m_sb.sb_logsunit) {
Dave Chinner4f107002011-03-07 10:00:35 +11001451 xfs_warn(mp,
1452 "logbuf size must be greater than or equal to log stripe size");
Dave Chinner24513372014-06-25 14:58:08 +10001453 return -EINVAL;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001454 }
1455 } else {
1456 /* Fail a mount if the logbuf is larger than 32K */
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001457 if (mp->m_logbsize > XLOG_BIG_RECORD_BSIZE) {
Dave Chinner4f107002011-03-07 10:00:35 +11001458 xfs_warn(mp,
1459 "logbuf size for version 1 logs must be 16K or 32K");
Dave Chinner24513372014-06-25 14:58:08 +10001460 return -EINVAL;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001461 }
1462 }
1463
1464 /*
Dave Chinnerd3eaace2013-06-05 12:09:09 +10001465 * V5 filesystems always use attr2 format for attributes.
1466 */
1467 if (xfs_sb_version_hascrc(&mp->m_sb) &&
1468 (mp->m_flags & XFS_MOUNT_NOATTR2)) {
Eric Sandeen2e74af02016-03-02 09:55:38 +11001469 xfs_warn(mp, "Cannot mount a V5 filesystem as noattr2. "
1470 "attr2 is always enabled for V5 filesystems.");
Dave Chinner24513372014-06-25 14:58:08 +10001471 return -EINVAL;
Dave Chinnerd3eaace2013-06-05 12:09:09 +10001472 }
1473
1474 /*
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001475 * mkfs'ed attr2 will turn on attr2 mount unless explicitly
1476 * told by noattr2 to turn it off
1477 */
1478 if (xfs_sb_version_hasattr2(&mp->m_sb) &&
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001479 !(mp->m_flags & XFS_MOUNT_NOATTR2))
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001480 mp->m_flags |= XFS_MOUNT_ATTR2;
1481
1482 /*
1483 * prohibit r/w mounts of read-only filesystems
1484 */
1485 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
Dave Chinner4f107002011-03-07 10:00:35 +11001486 xfs_warn(mp,
1487 "cannot mount a read-only filesystem as read-write");
Dave Chinner24513372014-06-25 14:58:08 +10001488 return -EROFS;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001489 }
1490
Chandra Seetharamand892d582013-07-19 17:36:02 -05001491 if ((mp->m_qflags & (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE)) &&
1492 (mp->m_qflags & (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE)) &&
1493 !xfs_sb_version_has_pquotino(&mp->m_sb)) {
1494 xfs_warn(mp,
1495 "Super block does not support project and group quota together");
Dave Chinner24513372014-06-25 14:58:08 +10001496 return -EINVAL;
Chandra Seetharamand892d582013-07-19 17:36:02 -05001497 }
1498
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001499 return 0;
1500}
1501
Dave Chinner5681ca42015-02-23 21:22:31 +11001502static int
1503xfs_init_percpu_counters(
1504 struct xfs_mount *mp)
1505{
1506 int error;
1507
1508 error = percpu_counter_init(&mp->m_icount, 0, GFP_KERNEL);
1509 if (error)
Joe Perches5e9383f2015-03-25 15:00:24 +11001510 return -ENOMEM;
Dave Chinner5681ca42015-02-23 21:22:31 +11001511
1512 error = percpu_counter_init(&mp->m_ifree, 0, GFP_KERNEL);
1513 if (error)
1514 goto free_icount;
1515
1516 error = percpu_counter_init(&mp->m_fdblocks, 0, GFP_KERNEL);
1517 if (error)
1518 goto free_ifree;
1519
Darrick J. Wong9fe82b82019-04-25 18:26:22 -07001520 error = percpu_counter_init(&mp->m_delalloc_blks, 0, GFP_KERNEL);
1521 if (error)
1522 goto free_fdblocks;
1523
Dave Chinner5681ca42015-02-23 21:22:31 +11001524 return 0;
1525
Darrick J. Wong9fe82b82019-04-25 18:26:22 -07001526free_fdblocks:
1527 percpu_counter_destroy(&mp->m_fdblocks);
Dave Chinner5681ca42015-02-23 21:22:31 +11001528free_ifree:
1529 percpu_counter_destroy(&mp->m_ifree);
1530free_icount:
1531 percpu_counter_destroy(&mp->m_icount);
1532 return -ENOMEM;
1533}
1534
1535void
1536xfs_reinit_percpu_counters(
1537 struct xfs_mount *mp)
1538{
1539 percpu_counter_set(&mp->m_icount, mp->m_sb.sb_icount);
1540 percpu_counter_set(&mp->m_ifree, mp->m_sb.sb_ifree);
1541 percpu_counter_set(&mp->m_fdblocks, mp->m_sb.sb_fdblocks);
1542}
1543
1544static void
1545xfs_destroy_percpu_counters(
1546 struct xfs_mount *mp)
1547{
1548 percpu_counter_destroy(&mp->m_icount);
1549 percpu_counter_destroy(&mp->m_ifree);
1550 percpu_counter_destroy(&mp->m_fdblocks);
Darrick J. Wong9fe82b82019-04-25 18:26:22 -07001551 ASSERT(XFS_FORCED_SHUTDOWN(mp) ||
1552 percpu_counter_sum(&mp->m_delalloc_blks) == 0);
1553 percpu_counter_destroy(&mp->m_delalloc_blks);
Dave Chinner5681ca42015-02-23 21:22:31 +11001554}
1555
Brian Foster72c44e32018-03-23 17:54:32 -07001556static struct xfs_mount *
1557xfs_mount_alloc(
1558 struct super_block *sb)
1559{
1560 struct xfs_mount *mp;
1561
1562 mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
1563 if (!mp)
1564 return NULL;
1565
1566 mp->m_super = sb;
1567 spin_lock_init(&mp->m_sb_lock);
1568 spin_lock_init(&mp->m_agirotor_lock);
1569 INIT_RADIX_TREE(&mp->m_perag_tree, GFP_ATOMIC);
1570 spin_lock_init(&mp->m_perag_lock);
1571 mutex_init(&mp->m_growlock);
1572 atomic_set(&mp->m_active_trans, 0);
1573 INIT_DELAYED_WORK(&mp->m_reclaim_work, xfs_reclaim_worker);
1574 INIT_DELAYED_WORK(&mp->m_eofblocks_work, xfs_eofblocks_worker);
1575 INIT_DELAYED_WORK(&mp->m_cowblocks_work, xfs_cowblocks_worker);
1576 mp->m_kobj.kobject.kset = xfs_kset;
Darrick J. Wong15a268d2019-02-13 11:46:16 -08001577 /*
1578 * We don't create the finobt per-ag space reservation until after log
1579 * recovery, so we must set this to true so that an ifree transaction
1580 * started during log recovery will not depend on space reservations
1581 * for finobt expansion.
1582 */
1583 mp->m_finobt_nores = true;
Brian Foster72c44e32018-03-23 17:54:32 -07001584 return mp;
1585}
1586
1587
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001589xfs_fs_fill_super(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 struct super_block *sb,
1591 void *data,
1592 int silent)
1593{
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001594 struct inode *root;
Christoph Hellwig745f6912007-08-30 17:20:39 +10001595 struct xfs_mount *mp = NULL;
Dave Chinner24513372014-06-25 14:58:08 +10001596 int flags = 0, error = -ENOMEM;
Christoph Hellwigbdd907b2008-05-20 15:10:44 +10001597
Brian Foster72c44e32018-03-23 17:54:32 -07001598 /*
1599 * allocate mp and do all low-level struct initializations before we
1600 * attach it to the super
1601 */
1602 mp = xfs_mount_alloc(sb);
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001603 if (!mp)
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001604 goto out;
Christoph Hellwigb267ce92007-08-30 17:21:30 +10001605 sb->s_fs_info = mp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606
Christoph Hellwig288699f2010-06-23 18:11:15 +10001607 error = xfs_parseargs(mp, (char *)data);
Christoph Hellwig745f6912007-08-30 17:20:39 +10001608 if (error)
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001609 goto out_free_fsname;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610
1611 sb_min_blocksize(sb, BBSIZE);
Lachlan McIlroy0ec58512008-06-23 13:23:01 +10001612 sb->s_xattr = xfs_xattr_handlers;
Nathan Scotta50cd262006-03-14 14:06:18 +11001613 sb->s_export_op = &xfs_export_operations;
Christoph Hellwigfcafb712009-02-09 08:47:34 +01001614#ifdef CONFIG_XFS_QUOTA
Nathan Scotta50cd262006-03-14 14:06:18 +11001615 sb->s_qcop = &xfs_quotactl_operations;
Jan Kara17ef4fd2014-09-30 22:35:33 +02001616 sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ;
Christoph Hellwigfcafb712009-02-09 08:47:34 +01001617#endif
Nathan Scotta50cd262006-03-14 14:06:18 +11001618 sb->s_op = &xfs_super_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619
Dave Chinnerdae5cd82018-05-10 21:50:23 -07001620 /*
1621 * Delay mount work if the debug hook is set. This is debug
1622 * instrumention to coordinate simulation of xfs mount failures with
1623 * VFS superblock operations
1624 */
1625 if (xfs_globals.mount_delay) {
1626 xfs_notice(mp, "Delaying mount for %d seconds.",
1627 xfs_globals.mount_delay);
1628 msleep(xfs_globals.mount_delay * 1000);
1629 }
1630
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001631 if (silent)
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001632 flags |= XFS_MFSI_QUIET;
1633
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001634 error = xfs_open_devices(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001635 if (error)
Christoph Hellwig288699f2010-06-23 18:11:15 +10001636 goto out_free_fsname;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001637
Dave Chinner24513372014-06-25 14:58:08 +10001638 error = xfs_init_mount_workqueues(mp);
Christoph Hellwig61ba35d2010-09-30 02:25:54 +00001639 if (error)
1640 goto out_close_devices;
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001641
Dave Chinner5681ca42015-02-23 21:22:31 +11001642 error = xfs_init_percpu_counters(mp);
Christoph Hellwigaa6bf012012-02-29 09:53:48 +00001643 if (error)
1644 goto out_destroy_workqueues;
1645
Bill O'Donnell225e4632015-10-12 18:21:19 +11001646 /* Allocate stats memory before we do operations that might use it */
1647 mp->m_stats.xs_stats = alloc_percpu(struct xfsstats);
1648 if (!mp->m_stats.xs_stats) {
Dan Carpenterf9d460b2015-10-19 08:42:47 +11001649 error = -ENOMEM;
Bill O'Donnell225e4632015-10-12 18:21:19 +11001650 goto out_destroy_counters;
1651 }
1652
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001653 error = xfs_readsb(mp, flags);
1654 if (error)
Bill O'Donnell225e4632015-10-12 18:21:19 +11001655 goto out_free_stats;
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001656
1657 error = xfs_finish_flags(mp);
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001658 if (error)
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001659 goto out_free_sb;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001660
Christoph Hellwige34b5622008-05-20 15:10:36 +10001661 error = xfs_setup_devices(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001662 if (error)
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001663 goto out_free_sb;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001664
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001665 error = xfs_filestream_mount(mp);
1666 if (error)
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001667 goto out_free_sb;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001668
Dave Chinner704b2902011-03-26 09:14:57 +11001669 /*
1670 * we must configure the block size in the superblock before we run the
1671 * full mount process as the mount process can lookup and cache inodes.
Dave Chinner704b2902011-03-26 09:14:57 +11001672 */
Adam Borowskidddde682018-10-18 17:20:19 +11001673 sb->s_magic = XFS_SUPER_MAGIC;
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001674 sb->s_blocksize = mp->m_sb.sb_blocksize;
1675 sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
Al Viro8de52772012-02-06 12:45:27 -05001677 sb->s_max_links = XFS_MAXLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678 sb->s_time_gran = 1;
1679 set_posix_acl_flag(sb);
1680
Dave Chinnerdc037ad2013-06-27 16:04:59 +10001681 /* version 5 superblocks support inode version counters. */
1682 if (XFS_SB_VERSION_NUM(&mp->m_sb) == XFS_SB_VERSION_5)
Matthew Garrett357fdad2017-10-18 13:56:26 -07001683 sb->s_flags |= SB_I_VERSION;
Dave Chinnerdc037ad2013-06-27 16:04:59 +10001684
Dave Chinnercbe4dab2015-06-04 09:19:18 +10001685 if (mp->m_flags & XFS_MOUNT_DAX) {
Dave Jiang80660f22018-05-30 13:03:46 -07001686 bool rtdev_is_dax = false, datadev_is_dax;
Darrick J. Wongba23cba2018-05-30 13:03:45 -07001687
Dave Chinnercbe4dab2015-06-04 09:19:18 +10001688 xfs_warn(mp,
Toshi Kani1e937cd2016-05-10 10:23:56 -06001689 "DAX enabled. Warning: EXPERIMENTAL, use at your own risk");
1690
Dave Jiang80660f22018-05-30 13:03:46 -07001691 datadev_is_dax = bdev_dax_supported(mp->m_ddev_targp->bt_bdev,
1692 sb->s_blocksize);
Darrick J. Wongba23cba2018-05-30 13:03:45 -07001693 if (mp->m_rtdev_targp)
Dave Jiang80660f22018-05-30 13:03:46 -07001694 rtdev_is_dax = bdev_dax_supported(
1695 mp->m_rtdev_targp->bt_bdev, sb->s_blocksize);
1696 if (!rtdev_is_dax && !datadev_is_dax) {
Dave Chinnercbe4dab2015-06-04 09:19:18 +10001697 xfs_alert(mp,
Toshi Kani1e937cd2016-05-10 10:23:56 -06001698 "DAX unsupported by block device. Turning off DAX.");
Dave Chinnercbe4dab2015-06-04 09:19:18 +10001699 mp->m_flags &= ~XFS_MOUNT_DAX;
1700 }
Darrick J. Wongb6e03c12018-01-31 14:21:56 -08001701 if (xfs_sb_version_hasreflink(&mp->m_sb)) {
Darrick J. Wonge54b5bf2016-10-03 09:11:52 -07001702 xfs_alert(mp,
Christoph Hellwig1e369b02018-01-08 13:30:08 -08001703 "DAX and reflink cannot be used together!");
Darrick J. Wongb6e03c12018-01-31 14:21:56 -08001704 error = -EINVAL;
1705 goto out_filestream_unmount;
1706 }
Dave Chinnercbe4dab2015-06-04 09:19:18 +10001707 }
1708
Kenjiro Nakayama1e6fa682017-09-18 12:03:56 -07001709 if (mp->m_flags & XFS_MOUNT_DISCARD) {
1710 struct request_queue *q = bdev_get_queue(sb->s_bdev);
1711
1712 if (!blk_queue_discard(q)) {
1713 xfs_warn(mp, "mounting with \"discard\" option, but "
1714 "the device does not support discard");
1715 mp->m_flags &= ~XFS_MOUNT_DISCARD;
1716 }
1717 }
1718
Christoph Hellwig66ae56a2019-02-18 09:38:49 -08001719 if (xfs_sb_version_hasreflink(&mp->m_sb)) {
1720 if (mp->m_sb.sb_rblocks) {
1721 xfs_alert(mp,
Darrick J. Wongc14632d2018-01-31 16:38:18 -08001722 "reflink not compatible with realtime device!");
Christoph Hellwig66ae56a2019-02-18 09:38:49 -08001723 error = -EINVAL;
1724 goto out_filestream_unmount;
1725 }
1726
1727 if (xfs_globals.always_cow) {
1728 xfs_info(mp, "using DEBUG-only always_cow mode.");
1729 mp->m_always_cow = true;
1730 }
Darrick J. Wongc14632d2018-01-31 16:38:18 -08001731 }
1732
Darrick J. Wong76883f72018-01-31 09:47:25 -08001733 if (xfs_sb_version_hasrmapbt(&mp->m_sb) && mp->m_sb.sb_rblocks) {
Darrick J. Wong1c0607a2016-08-03 12:20:57 +10001734 xfs_alert(mp,
Darrick J. Wong76883f72018-01-31 09:47:25 -08001735 "reverse mapping btree not compatible with realtime device!");
1736 error = -EINVAL;
1737 goto out_filestream_unmount;
Darrick J. Wong738f57c2016-08-26 15:59:19 +10001738 }
Darrick J. Wong1c0607a2016-08-03 12:20:57 +10001739
Dave Chinner8a00ebe2012-04-13 12:10:44 +00001740 error = xfs_mountfs(mp);
Christoph Hellwig2bcf6e92011-07-13 13:43:48 +02001741 if (error)
Dave Chinner7e185302012-10-08 21:56:00 +11001742 goto out_filestream_unmount;
Dave Chinner704b2902011-03-26 09:14:57 +11001743
David Chinner01651642008-08-13 15:45:15 +10001744 root = igrab(VFS_I(mp->m_rootip));
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001745 if (!root) {
Dave Chinner24513372014-06-25 14:58:08 +10001746 error = -ENOENT;
Dave Chinner8a00ebe2012-04-13 12:10:44 +00001747 goto out_unmount;
Christoph Hellwigcbc89dc2008-02-05 12:14:01 +11001748 }
Al Viro48fde702012-01-08 22:15:13 -05001749 sb->s_root = d_make_root(root);
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001750 if (!sb->s_root) {
Dave Chinner24513372014-06-25 14:58:08 +10001751 error = -ENOMEM;
Dave Chinner8a00ebe2012-04-13 12:10:44 +00001752 goto out_unmount;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 }
Christoph Hellwig74394492007-08-30 17:21:22 +10001754
Dave Chinner7e185302012-10-08 21:56:00 +11001755 return 0;
1756
1757 out_filestream_unmount:
Christoph Hellwig120226c2008-05-20 15:11:11 +10001758 xfs_filestream_unmount(mp);
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001759 out_free_sb:
1760 xfs_freesb(mp);
Bill O'Donnell225e4632015-10-12 18:21:19 +11001761 out_free_stats:
1762 free_percpu(mp->m_stats.xs_stats);
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001763 out_destroy_counters:
Dave Chinner5681ca42015-02-23 21:22:31 +11001764 xfs_destroy_percpu_counters(mp);
Bill O'Donnell225e4632015-10-12 18:21:19 +11001765 out_destroy_workqueues:
Christoph Hellwigaa6bf012012-02-29 09:53:48 +00001766 xfs_destroy_mount_workqueues(mp);
Christoph Hellwig61ba35d2010-09-30 02:25:54 +00001767 out_close_devices:
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001768 xfs_close_devices(mp);
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001769 out_free_fsname:
Dave Chinnerc9fbd7b2018-05-10 21:50:23 -07001770 sb->s_fs_info = NULL;
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001771 xfs_free_fsname(mp);
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001772 kfree(mp);
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001773 out:
Dave Chinner24513372014-06-25 14:58:08 +10001774 return error;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001775
Christoph Hellwig2bcf6e92011-07-13 13:43:48 +02001776 out_unmount:
Christoph Hellwige48ad3162008-05-20 11:30:52 +10001777 xfs_filestream_unmount(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001778 xfs_unmountfs(mp);
Christoph Hellwig62033002008-08-13 16:50:21 +10001779 goto out_free_sb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780}
1781
Dave Chinner5681ca42015-02-23 21:22:31 +11001782STATIC void
1783xfs_fs_put_super(
1784 struct super_block *sb)
1785{
1786 struct xfs_mount *mp = XFS_M(sb);
1787
Dave Chinnerc9fbd7b2018-05-10 21:50:23 -07001788 /* if ->fill_super failed, we have no mount to tear down */
1789 if (!sb->s_fs_info)
1790 return;
1791
Dave Chinner42254412015-02-24 10:27:28 +11001792 xfs_notice(mp, "Unmounting Filesystem");
Dave Chinner5681ca42015-02-23 21:22:31 +11001793 xfs_filestream_unmount(mp);
1794 xfs_unmountfs(mp);
1795
1796 xfs_freesb(mp);
Bill O'Donnell225e4632015-10-12 18:21:19 +11001797 free_percpu(mp->m_stats.xs_stats);
Dave Chinner5681ca42015-02-23 21:22:31 +11001798 xfs_destroy_percpu_counters(mp);
1799 xfs_destroy_mount_workqueues(mp);
1800 xfs_close_devices(mp);
Dave Chinnerc9fbd7b2018-05-10 21:50:23 -07001801
1802 sb->s_fs_info = NULL;
Dave Chinner5681ca42015-02-23 21:22:31 +11001803 xfs_free_fsname(mp);
1804 kfree(mp);
1805}
1806
Al Viro152a0832010-07-25 00:46:55 +04001807STATIC struct dentry *
1808xfs_fs_mount(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 struct file_system_type *fs_type,
1810 int flags,
1811 const char *dev_name,
Al Viro152a0832010-07-25 00:46:55 +04001812 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813{
Al Viro152a0832010-07-25 00:46:55 +04001814 return mount_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815}
1816
Dave Chinner0a234c62013-08-28 10:17:57 +10001817static long
Dave Chinner8daaa832011-07-08 14:14:46 +10001818xfs_fs_nr_cached_objects(
Dave Chinner9b17c622013-08-28 10:18:05 +10001819 struct super_block *sb,
Vladimir Davydov4101b622015-02-12 14:58:51 -08001820 struct shrink_control *sc)
Dave Chinner8daaa832011-07-08 14:14:46 +10001821{
Dave Chinnerc9fbd7b2018-05-10 21:50:23 -07001822 /* Paranoia: catch incorrect calls during mount setup or teardown */
1823 if (WARN_ON_ONCE(!sb->s_fs_info))
1824 return 0;
Dave Chinner8daaa832011-07-08 14:14:46 +10001825 return xfs_reclaim_inodes_count(XFS_M(sb));
1826}
1827
Dave Chinner0a234c62013-08-28 10:17:57 +10001828static long
Dave Chinner8daaa832011-07-08 14:14:46 +10001829xfs_fs_free_cached_objects(
1830 struct super_block *sb,
Vladimir Davydov4101b622015-02-12 14:58:51 -08001831 struct shrink_control *sc)
Dave Chinner8daaa832011-07-08 14:14:46 +10001832{
Vladimir Davydov4101b622015-02-12 14:58:51 -08001833 return xfs_reclaim_inodes_nr(XFS_M(sb), sc->nr_to_scan);
Dave Chinner8daaa832011-07-08 14:14:46 +10001834}
1835
Alexey Dobriyanb87221d2009-09-21 17:01:09 -07001836static const struct super_operations xfs_super_operations = {
Nathan Scotta50cd262006-03-14 14:06:18 +11001837 .alloc_inode = xfs_fs_alloc_inode,
1838 .destroy_inode = xfs_fs_destroy_inode,
Christoph Hellwigc3b1b132018-03-06 17:04:00 -08001839 .dirty_inode = xfs_fs_dirty_inode,
Dave Chinner5132ba82012-03-22 05:15:10 +00001840 .drop_inode = xfs_fs_drop_inode,
Nathan Scotta50cd262006-03-14 14:06:18 +11001841 .put_super = xfs_fs_put_super,
Christoph Hellwig69961a22009-10-06 20:29:28 +00001842 .sync_fs = xfs_fs_sync_fs,
Takashi Satoc4be0c12009-01-09 16:40:58 -08001843 .freeze_fs = xfs_fs_freeze,
Eric Sandeend5db0f92010-02-05 22:59:53 +00001844 .unfreeze_fs = xfs_fs_unfreeze,
Nathan Scotta50cd262006-03-14 14:06:18 +11001845 .statfs = xfs_fs_statfs,
1846 .remount_fs = xfs_fs_remount,
1847 .show_options = xfs_fs_show_options,
Dave Chinner8daaa832011-07-08 14:14:46 +10001848 .nr_cached_objects = xfs_fs_nr_cached_objects,
1849 .free_cached_objects = xfs_fs_free_cached_objects,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850};
1851
Andrew Morton5085b602007-02-20 13:57:47 -08001852static struct file_system_type xfs_fs_type = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 .owner = THIS_MODULE,
1854 .name = "xfs",
Al Viro152a0832010-07-25 00:46:55 +04001855 .mount = xfs_fs_mount,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 .kill_sb = kill_block_super,
1857 .fs_flags = FS_REQUIRES_DEV,
1858};
Eric W. Biederman7f78e032013-03-02 19:39:14 -08001859MODULE_ALIAS_FS("xfs");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001861STATIC int __init
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001862xfs_init_zones(void)
1863{
Christoph Hellwig82cb1412018-07-11 22:26:05 -07001864 if (bioset_init(&xfs_ioend_bioset, 4 * (PAGE_SIZE / SECTOR_SIZE),
NeilBrown011067b2017-06-18 14:38:57 +10001865 offsetof(struct xfs_ioend, io_inline_bio),
Kent Overstreete292d7b2018-05-20 18:25:57 -04001866 BIOSET_NEED_BVECS))
David Chinnerbf904242008-10-30 17:36:14 +11001867 goto out;
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001868
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001869 xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t),
1870 "xfs_log_ticket");
1871 if (!xfs_log_ticket_zone)
Christoph Hellwig0e51a8e2016-04-06 08:34:30 +10001872 goto out_free_ioend_bioset;
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001873
Darrick J. Wonge66a4c62016-06-21 11:53:28 +10001874 xfs_bmap_free_item_zone = kmem_zone_init(
Darrick J. Wong310a75a2016-08-03 11:18:10 +10001875 sizeof(struct xfs_extent_free_item),
Darrick J. Wonge66a4c62016-06-21 11:53:28 +10001876 "xfs_bmap_free_item");
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001877 if (!xfs_bmap_free_item_zone)
1878 goto out_destroy_log_ticket_zone;
David Chinnerbf904242008-10-30 17:36:14 +11001879
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001880 xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
1881 "xfs_btree_cur");
1882 if (!xfs_btree_cur_zone)
1883 goto out_destroy_bmap_free_item_zone;
1884
1885 xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t),
1886 "xfs_da_state");
1887 if (!xfs_da_state_zone)
1888 goto out_destroy_btree_cur_zone;
1889
Christoph Hellwig3ba738d2018-07-17 16:51:50 -07001890 xfs_ifork_zone = kmem_zone_init(sizeof(struct xfs_ifork), "xfs_ifork");
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001891 if (!xfs_ifork_zone)
Dave Chinner1d9025e2012-06-22 18:50:14 +10001892 goto out_destroy_da_state_zone;
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001893
1894 xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
1895 if (!xfs_trans_zone)
1896 goto out_destroy_ifork_zone;
1897
Christoph Hellwige98c4142010-06-23 18:11:15 +10001898
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001899 /*
1900 * The size of the zone allocated buf log item is the maximum
1901 * size possible under XFS. This wastes a little bit of memory,
1902 * but it is much faster.
1903 */
Dave Chinner77c1a082012-06-22 18:50:07 +10001904 xfs_buf_item_zone = kmem_zone_init(sizeof(struct xfs_buf_log_item),
1905 "xfs_buf_item");
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001906 if (!xfs_buf_item_zone)
Dave Chinnere6631f82018-05-09 07:49:37 -07001907 goto out_destroy_trans_zone;
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001908
1909 xfs_efd_zone = kmem_zone_init((sizeof(xfs_efd_log_item_t) +
1910 ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
1911 sizeof(xfs_extent_t))), "xfs_efd_item");
1912 if (!xfs_efd_zone)
1913 goto out_destroy_buf_item_zone;
1914
1915 xfs_efi_zone = kmem_zone_init((sizeof(xfs_efi_log_item_t) +
1916 ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
1917 sizeof(xfs_extent_t))), "xfs_efi_item");
1918 if (!xfs_efi_zone)
1919 goto out_destroy_efd_zone;
1920
1921 xfs_inode_zone =
1922 kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
Vladimir Davydov5d097052016-01-14 15:18:21 -08001923 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM | KM_ZONE_SPREAD |
1924 KM_ZONE_ACCOUNT, xfs_fs_inode_init_once);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001925 if (!xfs_inode_zone)
1926 goto out_destroy_efi_zone;
1927
1928 xfs_ili_zone =
1929 kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
1930 KM_ZONE_SPREAD, NULL);
1931 if (!xfs_ili_zone)
1932 goto out_destroy_inode_zone;
Dave Chinner3ebe7d22013-06-27 16:04:53 +10001933 xfs_icreate_zone = kmem_zone_init(sizeof(struct xfs_icreate_item),
1934 "xfs_icr");
1935 if (!xfs_icreate_zone)
1936 goto out_destroy_ili_zone;
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001937
Darrick J. Wong722e2512016-08-03 12:28:43 +10001938 xfs_rud_zone = kmem_zone_init(sizeof(struct xfs_rud_log_item),
Darrick J. Wong5880f2d72016-08-03 12:04:45 +10001939 "xfs_rud_item");
1940 if (!xfs_rud_zone)
1941 goto out_destroy_icreate_zone;
1942
Darrick J. Wongcd001582016-09-19 10:24:27 +10001943 xfs_rui_zone = kmem_zone_init(
1944 xfs_rui_log_item_sizeof(XFS_RUI_MAX_FAST_EXTENTS),
Darrick J. Wong5880f2d72016-08-03 12:04:45 +10001945 "xfs_rui_item");
1946 if (!xfs_rui_zone)
1947 goto out_destroy_rud_zone;
1948
Darrick J. Wongbaf4bcac2016-10-03 09:11:20 -07001949 xfs_cud_zone = kmem_zone_init(sizeof(struct xfs_cud_log_item),
1950 "xfs_cud_item");
1951 if (!xfs_cud_zone)
1952 goto out_destroy_rui_zone;
1953
1954 xfs_cui_zone = kmem_zone_init(
1955 xfs_cui_log_item_sizeof(XFS_CUI_MAX_FAST_EXTENTS),
1956 "xfs_cui_item");
1957 if (!xfs_cui_zone)
1958 goto out_destroy_cud_zone;
1959
Darrick J. Wong6413a012016-10-03 09:11:25 -07001960 xfs_bud_zone = kmem_zone_init(sizeof(struct xfs_bud_log_item),
1961 "xfs_bud_item");
1962 if (!xfs_bud_zone)
1963 goto out_destroy_cui_zone;
1964
1965 xfs_bui_zone = kmem_zone_init(
1966 xfs_bui_log_item_sizeof(XFS_BUI_MAX_FAST_EXTENTS),
1967 "xfs_bui_item");
1968 if (!xfs_bui_zone)
1969 goto out_destroy_bud_zone;
1970
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001971 return 0;
1972
Darrick J. Wong6413a012016-10-03 09:11:25 -07001973 out_destroy_bud_zone:
1974 kmem_zone_destroy(xfs_bud_zone);
1975 out_destroy_cui_zone:
1976 kmem_zone_destroy(xfs_cui_zone);
Darrick J. Wongbaf4bcac2016-10-03 09:11:20 -07001977 out_destroy_cud_zone:
1978 kmem_zone_destroy(xfs_cud_zone);
1979 out_destroy_rui_zone:
1980 kmem_zone_destroy(xfs_rui_zone);
Darrick J. Wong5880f2d72016-08-03 12:04:45 +10001981 out_destroy_rud_zone:
1982 kmem_zone_destroy(xfs_rud_zone);
1983 out_destroy_icreate_zone:
1984 kmem_zone_destroy(xfs_icreate_zone);
Dave Chinner3ebe7d22013-06-27 16:04:53 +10001985 out_destroy_ili_zone:
1986 kmem_zone_destroy(xfs_ili_zone);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001987 out_destroy_inode_zone:
1988 kmem_zone_destroy(xfs_inode_zone);
1989 out_destroy_efi_zone:
1990 kmem_zone_destroy(xfs_efi_zone);
1991 out_destroy_efd_zone:
1992 kmem_zone_destroy(xfs_efd_zone);
1993 out_destroy_buf_item_zone:
1994 kmem_zone_destroy(xfs_buf_item_zone);
1995 out_destroy_trans_zone:
1996 kmem_zone_destroy(xfs_trans_zone);
1997 out_destroy_ifork_zone:
1998 kmem_zone_destroy(xfs_ifork_zone);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001999 out_destroy_da_state_zone:
2000 kmem_zone_destroy(xfs_da_state_zone);
2001 out_destroy_btree_cur_zone:
2002 kmem_zone_destroy(xfs_btree_cur_zone);
2003 out_destroy_bmap_free_item_zone:
2004 kmem_zone_destroy(xfs_bmap_free_item_zone);
2005 out_destroy_log_ticket_zone:
2006 kmem_zone_destroy(xfs_log_ticket_zone);
Christoph Hellwig0e51a8e2016-04-06 08:34:30 +10002007 out_free_ioend_bioset:
Kent Overstreete292d7b2018-05-20 18:25:57 -04002008 bioset_exit(&xfs_ioend_bioset);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002009 out:
2010 return -ENOMEM;
2011}
2012
2013STATIC void
2014xfs_destroy_zones(void)
2015{
Kirill A. Shutemov8c0a8532012-09-26 11:33:07 +10002016 /*
2017 * Make sure all delayed rcu free are flushed before we
2018 * destroy caches.
2019 */
2020 rcu_barrier();
Darrick J. Wong6413a012016-10-03 09:11:25 -07002021 kmem_zone_destroy(xfs_bui_zone);
2022 kmem_zone_destroy(xfs_bud_zone);
Darrick J. Wongbaf4bcac2016-10-03 09:11:20 -07002023 kmem_zone_destroy(xfs_cui_zone);
2024 kmem_zone_destroy(xfs_cud_zone);
Darrick J. Wong5880f2d72016-08-03 12:04:45 +10002025 kmem_zone_destroy(xfs_rui_zone);
2026 kmem_zone_destroy(xfs_rud_zone);
Dave Chinner3ebe7d22013-06-27 16:04:53 +10002027 kmem_zone_destroy(xfs_icreate_zone);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002028 kmem_zone_destroy(xfs_ili_zone);
2029 kmem_zone_destroy(xfs_inode_zone);
2030 kmem_zone_destroy(xfs_efi_zone);
2031 kmem_zone_destroy(xfs_efd_zone);
2032 kmem_zone_destroy(xfs_buf_item_zone);
2033 kmem_zone_destroy(xfs_trans_zone);
2034 kmem_zone_destroy(xfs_ifork_zone);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002035 kmem_zone_destroy(xfs_da_state_zone);
2036 kmem_zone_destroy(xfs_btree_cur_zone);
2037 kmem_zone_destroy(xfs_bmap_free_item_zone);
2038 kmem_zone_destroy(xfs_log_ticket_zone);
Kent Overstreete292d7b2018-05-20 18:25:57 -04002039 bioset_exit(&xfs_ioend_bioset);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002040}
2041
2042STATIC int __init
Dave Chinner0bf6a5b2011-04-08 12:45:07 +10002043xfs_init_workqueues(void)
2044{
2045 /*
Dave Chinnerc999a222012-03-22 05:15:07 +00002046 * The allocation workqueue can be used in memory reclaim situations
2047 * (writepage path), and parallelism is only limited by the number of
2048 * AGs in all the filesystems mounted. Hence use the default large
2049 * max_active value for this workqueue.
2050 */
Brian Foster8018ec02014-09-09 11:44:46 +10002051 xfs_alloc_wq = alloc_workqueue("xfsalloc",
2052 WQ_MEM_RECLAIM|WQ_FREEZABLE, 0);
Dave Chinnerc999a222012-03-22 05:15:07 +00002053 if (!xfs_alloc_wq)
Dave Chinner58896082012-10-08 21:56:05 +11002054 return -ENOMEM;
Dave Chinnerc999a222012-03-22 05:15:07 +00002055
Christoph Hellwig4560e782017-02-07 14:07:58 -08002056 xfs_discard_wq = alloc_workqueue("xfsdiscard", WQ_UNBOUND, 0);
2057 if (!xfs_discard_wq)
2058 goto out_free_alloc_wq;
2059
Dave Chinner0bf6a5b2011-04-08 12:45:07 +10002060 return 0;
Christoph Hellwig4560e782017-02-07 14:07:58 -08002061out_free_alloc_wq:
2062 destroy_workqueue(xfs_alloc_wq);
2063 return -ENOMEM;
Dave Chinner0bf6a5b2011-04-08 12:45:07 +10002064}
2065
Luck, Tony39411f82011-04-11 12:06:12 -07002066STATIC void
Dave Chinner0bf6a5b2011-04-08 12:45:07 +10002067xfs_destroy_workqueues(void)
2068{
Christoph Hellwig4560e782017-02-07 14:07:58 -08002069 destroy_workqueue(xfs_discard_wq);
Dave Chinnerc999a222012-03-22 05:15:07 +00002070 destroy_workqueue(xfs_alloc_wq);
Dave Chinner0bf6a5b2011-04-08 12:45:07 +10002071}
2072
2073STATIC int __init
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002074init_xfs_fs(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075{
2076 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077
Darrick J. Wong30cbc592016-03-09 08:15:14 +11002078 xfs_check_ondisk_structs();
2079
Christoph Hellwig65795912008-11-28 14:23:33 +11002080 printk(KERN_INFO XFS_VERSION_STRING " with "
2081 XFS_BUILD_OPTIONS " enabled\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002083 xfs_dir_startup();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084
Nathan Scott87582802006-03-14 13:18:19 +11002085 error = xfs_init_zones();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002086 if (error)
2087 goto out;
2088
Dave Chinner0bf6a5b2011-04-08 12:45:07 +10002089 error = xfs_init_workqueues();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002090 if (error)
Christoph Hellwig0b1b2132009-12-14 23:14:59 +00002091 goto out_destroy_zones;
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002092
Dave Chinner0bf6a5b2011-04-08 12:45:07 +10002093 error = xfs_mru_cache_init();
2094 if (error)
2095 goto out_destroy_wq;
2096
Nathan Scottce8e9222006-01-11 15:39:08 +11002097 error = xfs_buf_init();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002098 if (error)
Christoph Hellwig1919add2014-04-23 07:11:51 +10002099 goto out_mru_cache_uninit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002101 error = xfs_init_procfs();
2102 if (error)
2103 goto out_buf_terminate;
2104
2105 error = xfs_sysctl_register();
2106 if (error)
2107 goto out_cleanup_procfs;
2108
Brian Foster3d871222014-07-15 07:41:37 +10002109 xfs_kset = kset_create_and_add("xfs", NULL, fs_kobj);
2110 if (!xfs_kset) {
2111 error = -ENOMEM;
Bill O'Donnellbb230c12015-10-12 05:15:45 +11002112 goto out_sysctl_unregister;
Brian Foster3d871222014-07-15 07:41:37 +10002113 }
2114
Bill O'Donnell80529c42015-10-12 05:19:45 +11002115 xfsstats.xs_kobj.kobject.kset = xfs_kset;
2116
2117 xfsstats.xs_stats = alloc_percpu(struct xfsstats);
2118 if (!xfsstats.xs_stats) {
2119 error = -ENOMEM;
2120 goto out_kset_unregister;
2121 }
2122
2123 error = xfs_sysfs_init(&xfsstats.xs_kobj, &xfs_stats_ktype, NULL,
Bill O'Donnellbb230c12015-10-12 05:15:45 +11002124 "stats");
2125 if (error)
Bill O'Donnell80529c42015-10-12 05:19:45 +11002126 goto out_free_stats;
Bill O'Donnellbb230c12015-10-12 05:15:45 +11002127
Brian Foster65b65732014-09-09 11:52:42 +10002128#ifdef DEBUG
2129 xfs_dbg_kobj.kobject.kset = xfs_kset;
2130 error = xfs_sysfs_init(&xfs_dbg_kobj, &xfs_dbg_ktype, NULL, "debug");
Christoph Hellwiga05931c2012-03-13 08:52:37 +00002131 if (error)
Bill O'Donnellbb230c12015-10-12 05:15:45 +11002132 goto out_remove_stats_kobj;
Brian Foster65b65732014-09-09 11:52:42 +10002133#endif
2134
2135 error = xfs_qm_init();
2136 if (error)
Bill O'Donnellbb230c12015-10-12 05:15:45 +11002137 goto out_remove_dbg_kobj;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138
2139 error = register_filesystem(&xfs_fs_type);
2140 if (error)
Christoph Hellwiga05931c2012-03-13 08:52:37 +00002141 goto out_qm_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142 return 0;
2143
Christoph Hellwiga05931c2012-03-13 08:52:37 +00002144 out_qm_exit:
2145 xfs_qm_exit();
Bill O'Donnellbb230c12015-10-12 05:15:45 +11002146 out_remove_dbg_kobj:
Brian Foster65b65732014-09-09 11:52:42 +10002147#ifdef DEBUG
2148 xfs_sysfs_del(&xfs_dbg_kobj);
Bill O'Donnellbb230c12015-10-12 05:15:45 +11002149 out_remove_stats_kobj:
Brian Foster65b65732014-09-09 11:52:42 +10002150#endif
Bill O'Donnell80529c42015-10-12 05:19:45 +11002151 xfs_sysfs_del(&xfsstats.xs_kobj);
2152 out_free_stats:
2153 free_percpu(xfsstats.xs_stats);
Bill O'Donnellbb230c12015-10-12 05:15:45 +11002154 out_kset_unregister:
Brian Foster3d871222014-07-15 07:41:37 +10002155 kset_unregister(xfs_kset);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002156 out_sysctl_unregister:
2157 xfs_sysctl_unregister();
2158 out_cleanup_procfs:
2159 xfs_cleanup_procfs();
2160 out_buf_terminate:
Nathan Scottce8e9222006-01-11 15:39:08 +11002161 xfs_buf_terminate();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002162 out_mru_cache_uninit:
2163 xfs_mru_cache_uninit();
Dave Chinner0bf6a5b2011-04-08 12:45:07 +10002164 out_destroy_wq:
2165 xfs_destroy_workqueues();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002166 out_destroy_zones:
Nathan Scott87582802006-03-14 13:18:19 +11002167 xfs_destroy_zones();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002168 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169 return error;
2170}
2171
2172STATIC void __exit
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002173exit_xfs_fs(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174{
Christoph Hellwiga05931c2012-03-13 08:52:37 +00002175 xfs_qm_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176 unregister_filesystem(&xfs_fs_type);
Brian Foster65b65732014-09-09 11:52:42 +10002177#ifdef DEBUG
2178 xfs_sysfs_del(&xfs_dbg_kobj);
2179#endif
Bill O'Donnell80529c42015-10-12 05:19:45 +11002180 xfs_sysfs_del(&xfsstats.xs_kobj);
2181 free_percpu(xfsstats.xs_stats);
Brian Foster3d871222014-07-15 07:41:37 +10002182 kset_unregister(xfs_kset);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002183 xfs_sysctl_unregister();
2184 xfs_cleanup_procfs();
Nathan Scottce8e9222006-01-11 15:39:08 +11002185 xfs_buf_terminate();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10002186 xfs_mru_cache_uninit();
Dave Chinner0bf6a5b2011-04-08 12:45:07 +10002187 xfs_destroy_workqueues();
Nathan Scott87582802006-03-14 13:18:19 +11002188 xfs_destroy_zones();
Darrick J. Wongaf3b6382015-11-03 13:06:34 +11002189 xfs_uuid_table_free();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190}
2191
2192module_init(init_xfs_fs);
2193module_exit(exit_xfs_fs);
2194
2195MODULE_AUTHOR("Silicon Graphics, Inc.");
2196MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
2197MODULE_LICENSE("GPL");