blob: 9f8090951f09124ae5dda27a97055ffbff0bd7d6 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scotta805bad2006-06-19 08:40:27 +10002 * Copyright (c) 2000-2006 Silicon Graphics, Inc.
Nathan Scott7b718762005-11-02 14:58:39 +11003 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Nathan Scott7b718762005-11-02 14:58:39 +11005 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * published by the Free Software Foundation.
8 *
Nathan Scott7b718762005-11-02 14:58:39 +11009 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 *
Nathan Scott7b718762005-11-02 14:58:39 +110014 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
Christoph Hellwig0b1b2132009-12-14 23:14:59 +000018
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include "xfs.h"
Dave Chinner70a9883c2013-10-23 10:36:05 +110020#include "xfs_shared.h"
Dave Chinner6ca1c902013-08-12 20:49:26 +100021#include "xfs_format.h"
Dave Chinner239880e2013-10-23 10:50:10 +110022#include "xfs_log_format.h"
23#include "xfs_trans_resv.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include "xfs_sb.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include "xfs_mount.h"
Dave Chinner57062782013-10-15 09:17:51 +110026#include "xfs_da_format.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include "xfs_inode.h"
Nathan Scotta844f452005-11-02 14:38:42 +110028#include "xfs_btree.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include "xfs_bmap.h"
Dave Chinnera4fbe6a2013-10-23 10:51:50 +110030#include "xfs_alloc.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include "xfs_error.h"
Christoph Hellwig9909c4a2007-10-11 18:11:14 +100032#include "xfs_fsops.h"
Dave Chinner239880e2013-10-23 10:50:10 +110033#include "xfs_trans.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include "xfs_buf_item.h"
Dave Chinner239880e2013-10-23 10:50:10 +110035#include "xfs_log.h"
David Chinnera67d7c52007-11-23 16:29:32 +110036#include "xfs_log_priv.h"
Christoph Hellwig9f8868f2008-07-18 17:11:46 +100037#include "xfs_da_btree.h"
Dave Chinner2b9ab5a2013-08-12 20:49:37 +100038#include "xfs_dir2.h"
Christoph Hellwig9f8868f2008-07-18 17:11:46 +100039#include "xfs_extfree_item.h"
40#include "xfs_mru_cache.h"
41#include "xfs_inode_item.h"
Dave Chinner6d8b79c2012-10-08 21:56:09 +110042#include "xfs_icache.h"
Christoph Hellwig0b1b2132009-12-14 23:14:59 +000043#include "xfs_trace.h"
Dave Chinner3ebe7d22013-06-27 16:04:53 +100044#include "xfs_icreate_item.h"
Dave Chinnera4fbe6a2013-10-23 10:51:50 +110045#include "xfs_filestream.h"
46#include "xfs_quota.h"
Brian Foster65b65732014-09-09 11:52:42 +100047#include "xfs_sysfs.h"
Darrick J. Wong30cbc592016-03-09 08:15:14 +110048#include "xfs_ondisk.h"
Darrick J. Wong5880f2d72016-08-03 12:04:45 +100049#include "xfs_rmap_item.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51#include <linux/namei.h>
52#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090053#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070054#include <linux/mount.h>
Christoph Hellwig0829c362005-09-02 16:58:49 +100055#include <linux/mempool.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070056#include <linux/writeback.h>
Christoph Hellwig4df08c52005-09-05 08:34:18 +100057#include <linux/kthread.h>
Nigel Cunningham7dfb7102006-12-06 20:34:23 -080058#include <linux/freezer.h>
Christoph Hellwig62a877e2008-07-18 17:12:36 +100059#include <linux/parser.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Alexey Dobriyanb87221d2009-09-21 17:01:09 -070061static const struct super_operations xfs_super_operations;
Christoph Hellwig0e51a8e2016-04-06 08:34:30 +100062struct bio_set *xfs_ioend_bioset;
Brian Foster65b65732014-09-09 11:52:42 +100063
Dave Chinnere3aed1a2014-09-29 10:46:08 +100064static struct kset *xfs_kset; /* top-level xfs sysfs dir */
Brian Foster65b65732014-09-09 11:52:42 +100065#ifdef DEBUG
66static struct xfs_kobj xfs_dbg_kobj; /* global debug sysfs attrs */
67#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Christoph Hellwig62a877e2008-07-18 17:12:36 +100069/*
70 * Table driven mount option parser.
Christoph Hellwig62a877e2008-07-18 17:12:36 +100071 */
72enum {
Eric Sandeen2e74af02016-03-02 09:55:38 +110073 Opt_logbufs, Opt_logbsize, Opt_logdev, Opt_rtdev, Opt_biosize,
74 Opt_wsync, Opt_noalign, Opt_swalloc, Opt_sunit, Opt_swidth, Opt_nouuid,
75 Opt_mtpt, Opt_grpid, Opt_nogrpid, Opt_bsdgroups, Opt_sysvgroups,
76 Opt_allocsize, Opt_norecovery, Opt_barrier, Opt_nobarrier,
77 Opt_inode64, Opt_inode32, Opt_ikeep, Opt_noikeep,
78 Opt_largeio, Opt_nolargeio, Opt_attr2, Opt_noattr2, Opt_filestreams,
79 Opt_quota, Opt_noquota, Opt_usrquota, Opt_grpquota, Opt_prjquota,
80 Opt_uquota, Opt_gquota, Opt_pquota,
81 Opt_uqnoenforce, Opt_gqnoenforce, Opt_pqnoenforce, Opt_qnoenforce,
82 Opt_discard, Opt_nodiscard, Opt_dax, Opt_err,
Christoph Hellwig62a877e2008-07-18 17:12:36 +100083};
84
Steven Whitehousea447c092008-10-13 10:46:57 +010085static const match_table_t tokens = {
Eric Sandeen2e74af02016-03-02 09:55:38 +110086 {Opt_logbufs, "logbufs=%u"}, /* number of XFS log buffers */
87 {Opt_logbsize, "logbsize=%s"}, /* size of XFS log buffers */
88 {Opt_logdev, "logdev=%s"}, /* log device */
89 {Opt_rtdev, "rtdev=%s"}, /* realtime I/O device */
90 {Opt_biosize, "biosize=%u"}, /* log2 of preferred buffered io size */
91 {Opt_wsync, "wsync"}, /* safe-mode nfs compatible mount */
92 {Opt_noalign, "noalign"}, /* turn off stripe alignment */
93 {Opt_swalloc, "swalloc"}, /* turn on stripe width allocation */
94 {Opt_sunit, "sunit=%u"}, /* data volume stripe unit */
95 {Opt_swidth, "swidth=%u"}, /* data volume stripe width */
96 {Opt_nouuid, "nouuid"}, /* ignore filesystem UUID */
97 {Opt_mtpt, "mtpt"}, /* filesystem mount point */
98 {Opt_grpid, "grpid"}, /* group-ID from parent directory */
99 {Opt_nogrpid, "nogrpid"}, /* group-ID from current process */
100 {Opt_bsdgroups, "bsdgroups"}, /* group-ID from parent directory */
101 {Opt_sysvgroups,"sysvgroups"}, /* group-ID from current process */
102 {Opt_allocsize, "allocsize=%s"},/* preferred allocation size */
103 {Opt_norecovery,"norecovery"}, /* don't run XFS recovery */
104 {Opt_barrier, "barrier"}, /* use writer barriers for log write and
105 * unwritten extent conversion */
106 {Opt_nobarrier, "nobarrier"}, /* .. disable */
107 {Opt_inode64, "inode64"}, /* inodes can be allocated anywhere */
108 {Opt_inode32, "inode32"}, /* inode allocation limited to
109 * XFS_MAXINUMBER_32 */
110 {Opt_ikeep, "ikeep"}, /* do not free empty inode clusters */
111 {Opt_noikeep, "noikeep"}, /* free empty inode clusters */
112 {Opt_largeio, "largeio"}, /* report large I/O sizes in stat() */
113 {Opt_nolargeio, "nolargeio"}, /* do not report large I/O sizes
114 * in stat(). */
115 {Opt_attr2, "attr2"}, /* do use attr2 attribute format */
116 {Opt_noattr2, "noattr2"}, /* do not use attr2 attribute format */
117 {Opt_filestreams,"filestreams"},/* use filestreams allocator */
118 {Opt_quota, "quota"}, /* disk quotas (user) */
119 {Opt_noquota, "noquota"}, /* no quotas */
120 {Opt_usrquota, "usrquota"}, /* user quota enabled */
121 {Opt_grpquota, "grpquota"}, /* group quota enabled */
122 {Opt_prjquota, "prjquota"}, /* project quota enabled */
123 {Opt_uquota, "uquota"}, /* user quota (IRIX variant) */
124 {Opt_gquota, "gquota"}, /* group quota (IRIX variant) */
125 {Opt_pquota, "pquota"}, /* project quota (IRIX variant) */
126 {Opt_uqnoenforce,"uqnoenforce"},/* user quota limit enforcement */
127 {Opt_gqnoenforce,"gqnoenforce"},/* group quota limit enforcement */
128 {Opt_pqnoenforce,"pqnoenforce"},/* project quota limit enforcement */
129 {Opt_qnoenforce, "qnoenforce"}, /* same as uqnoenforce */
130 {Opt_discard, "discard"}, /* Discard unused blocks */
131 {Opt_nodiscard, "nodiscard"}, /* Do not discard unused blocks */
132
133 {Opt_dax, "dax"}, /* Enable direct access to bdev pages */
134 {Opt_err, NULL},
Christoph Hellwig62a877e2008-07-18 17:12:36 +1000135};
136
137
Markus Elfringa841b642016-01-04 16:13:21 +1100138STATIC int
Eric Sandeen2e74af02016-03-02 09:55:38 +1100139suffix_kstrtoint(const substring_t *s, unsigned int base, int *res)
David Chinnera67d7c52007-11-23 16:29:32 +1100140{
Abhijit Pawara17164e2013-01-09 19:34:42 +0530141 int last, shift_left_factor = 0, _res;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100142 char *value;
143 int ret = 0;
144
145 value = match_strdup(s);
146 if (!value)
147 return -ENOMEM;
David Chinnera67d7c52007-11-23 16:29:32 +1100148
149 last = strlen(value) - 1;
150 if (value[last] == 'K' || value[last] == 'k') {
151 shift_left_factor = 10;
152 value[last] = '\0';
153 }
154 if (value[last] == 'M' || value[last] == 'm') {
155 shift_left_factor = 20;
156 value[last] = '\0';
157 }
158 if (value[last] == 'G' || value[last] == 'g') {
159 shift_left_factor = 30;
160 value[last] = '\0';
161 }
162
Eric Sandeen2e74af02016-03-02 09:55:38 +1100163 if (kstrtoint(value, base, &_res))
164 ret = -EINVAL;
165 kfree(value);
Abhijit Pawara17164e2013-01-09 19:34:42 +0530166 *res = _res << shift_left_factor;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100167 return ret;
David Chinnera67d7c52007-11-23 16:29:32 +1100168}
169
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100170/*
171 * This function fills in xfs_mount_t fields based on mount args.
172 * Note: the superblock has _not_ yet been read in.
173 *
174 * Note that this function leaks the various device name allocations on
175 * failure. The caller takes care of them.
Eric Sandeena08ee402016-03-02 09:56:31 +1100176 *
177 * *sb is const because this is also used to test options on the remount
178 * path, and we don't want this to have any side effects at remount time.
179 * Today this function does not change *sb, but just to future-proof...
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100180 */
David Chinnera67d7c52007-11-23 16:29:32 +1100181STATIC int
182xfs_parseargs(
183 struct xfs_mount *mp,
Christoph Hellwig288699f2010-06-23 18:11:15 +1000184 char *options)
David Chinnera67d7c52007-11-23 16:29:32 +1100185{
Eric Sandeena08ee402016-03-02 09:56:31 +1100186 const struct super_block *sb = mp->m_super;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100187 char *p;
188 substring_t args[MAX_OPT_ARGS];
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100189 int dsunit = 0;
190 int dswidth = 0;
191 int iosize = 0;
Christoph Hellwiga5687782009-02-09 08:37:39 +0100192 __uint8_t iosizelog = 0;
David Chinnera67d7c52007-11-23 16:29:32 +1100193
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100194 /*
Dave Chinner4f107002011-03-07 10:00:35 +1100195 * set up the mount name first so all the errors will refer to the
196 * correct device.
197 */
198 mp->m_fsname = kstrndup(sb->s_id, MAXNAMELEN, GFP_KERNEL);
199 if (!mp->m_fsname)
Dave Chinner24513372014-06-25 14:58:08 +1000200 return -ENOMEM;
Dave Chinner4f107002011-03-07 10:00:35 +1100201 mp->m_fsname_len = strlen(mp->m_fsname) + 1;
202
203 /*
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100204 * Copy binary VFS mount flags we are interested in.
205 */
206 if (sb->s_flags & MS_RDONLY)
207 mp->m_flags |= XFS_MOUNT_RDONLY;
208 if (sb->s_flags & MS_DIRSYNC)
209 mp->m_flags |= XFS_MOUNT_DIRSYNC;
210 if (sb->s_flags & MS_SYNCHRONOUS)
211 mp->m_flags |= XFS_MOUNT_WSYNC;
212
213 /*
214 * Set some default flags that could be cleared by the mount option
215 * parsing.
216 */
217 mp->m_flags |= XFS_MOUNT_BARRIER;
218 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100219
220 /*
221 * These can be overridden by the mount option parsing.
222 */
223 mp->m_logbufs = -1;
224 mp->m_logbsize = -1;
David Chinnera67d7c52007-11-23 16:29:32 +1100225
226 if (!options)
227 goto done;
228
Eric Sandeen2e74af02016-03-02 09:55:38 +1100229 while ((p = strsep(&options, ",")) != NULL) {
230 int token;
David Chinnera67d7c52007-11-23 16:29:32 +1100231
Eric Sandeen2e74af02016-03-02 09:55:38 +1100232 if (!*p)
233 continue;
234
235 token = match_token(p, tokens, args);
236 switch (token) {
237 case Opt_logbufs:
238 if (match_int(args, &mp->m_logbufs))
Dave Chinner24513372014-06-25 14:58:08 +1000239 return -EINVAL;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100240 break;
241 case Opt_logbsize:
242 if (suffix_kstrtoint(args, 10, &mp->m_logbsize))
Dave Chinner24513372014-06-25 14:58:08 +1000243 return -EINVAL;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100244 break;
245 case Opt_logdev:
246 mp->m_logname = match_strdup(args);
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100247 if (!mp->m_logname)
Dave Chinner24513372014-06-25 14:58:08 +1000248 return -ENOMEM;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100249 break;
250 case Opt_mtpt:
251 xfs_warn(mp, "%s option not allowed on this system", p);
Dave Chinner24513372014-06-25 14:58:08 +1000252 return -EINVAL;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100253 case Opt_rtdev:
254 mp->m_rtname = match_strdup(args);
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100255 if (!mp->m_rtname)
Dave Chinner24513372014-06-25 14:58:08 +1000256 return -ENOMEM;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100257 break;
258 case Opt_allocsize:
259 case Opt_biosize:
260 if (suffix_kstrtoint(args, 10, &iosize))
Dave Chinner24513372014-06-25 14:58:08 +1000261 return -EINVAL;
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100262 iosizelog = ffs(iosize) - 1;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100263 break;
264 case Opt_grpid:
265 case Opt_bsdgroups:
David Chinnera67d7c52007-11-23 16:29:32 +1100266 mp->m_flags |= XFS_MOUNT_GRPID;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100267 break;
268 case Opt_nogrpid:
269 case Opt_sysvgroups:
David Chinnera67d7c52007-11-23 16:29:32 +1100270 mp->m_flags &= ~XFS_MOUNT_GRPID;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100271 break;
272 case Opt_wsync:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100273 mp->m_flags |= XFS_MOUNT_WSYNC;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100274 break;
275 case Opt_norecovery:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100276 mp->m_flags |= XFS_MOUNT_NORECOVERY;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100277 break;
278 case Opt_noalign:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100279 mp->m_flags |= XFS_MOUNT_NOALIGN;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100280 break;
281 case Opt_swalloc:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100282 mp->m_flags |= XFS_MOUNT_SWALLOC;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100283 break;
284 case Opt_sunit:
285 if (match_int(args, &dsunit))
Dave Chinner24513372014-06-25 14:58:08 +1000286 return -EINVAL;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100287 break;
288 case Opt_swidth:
289 if (match_int(args, &dswidth))
Dave Chinner24513372014-06-25 14:58:08 +1000290 return -EINVAL;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100291 break;
292 case Opt_inode32:
Carlos Maiolino08bf5402012-09-20 10:32:37 -0300293 mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100294 break;
295 case Opt_inode64:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100296 mp->m_flags &= ~XFS_MOUNT_SMALL_INUMS;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100297 break;
298 case Opt_nouuid:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100299 mp->m_flags |= XFS_MOUNT_NOUUID;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100300 break;
301 case Opt_barrier:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100302 mp->m_flags |= XFS_MOUNT_BARRIER;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100303 break;
304 case Opt_nobarrier:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100305 mp->m_flags &= ~XFS_MOUNT_BARRIER;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100306 break;
307 case Opt_ikeep:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100308 mp->m_flags |= XFS_MOUNT_IKEEP;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100309 break;
310 case Opt_noikeep:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100311 mp->m_flags &= ~XFS_MOUNT_IKEEP;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100312 break;
313 case Opt_largeio:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100314 mp->m_flags &= ~XFS_MOUNT_COMPAT_IOSIZE;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100315 break;
316 case Opt_nolargeio:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100317 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100318 break;
319 case Opt_attr2:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100320 mp->m_flags |= XFS_MOUNT_ATTR2;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100321 break;
322 case Opt_noattr2:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100323 mp->m_flags &= ~XFS_MOUNT_ATTR2;
324 mp->m_flags |= XFS_MOUNT_NOATTR2;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100325 break;
326 case Opt_filestreams:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100327 mp->m_flags |= XFS_MOUNT_FILESTREAMS;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100328 break;
329 case Opt_noquota:
Chandra Seetharaman4177af32012-01-23 17:31:43 +0000330 mp->m_qflags &= ~XFS_ALL_QUOTA_ACCT;
331 mp->m_qflags &= ~XFS_ALL_QUOTA_ENFD;
332 mp->m_qflags &= ~XFS_ALL_QUOTA_ACTIVE;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100333 break;
334 case Opt_quota:
335 case Opt_uquota:
336 case Opt_usrquota:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100337 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE |
338 XFS_UQUOTA_ENFD);
Eric Sandeen2e74af02016-03-02 09:55:38 +1100339 break;
340 case Opt_qnoenforce:
341 case Opt_uqnoenforce:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100342 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
343 mp->m_qflags &= ~XFS_UQUOTA_ENFD;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100344 break;
345 case Opt_pquota:
346 case Opt_prjquota:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100347 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE |
Chandra Seetharaman83e782e2013-06-27 17:25:10 -0500348 XFS_PQUOTA_ENFD);
Eric Sandeen2e74af02016-03-02 09:55:38 +1100349 break;
350 case Opt_pqnoenforce:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100351 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
Chandra Seetharaman83e782e2013-06-27 17:25:10 -0500352 mp->m_qflags &= ~XFS_PQUOTA_ENFD;
Eryu Guance5c7672016-04-06 07:19:40 +1000353 break;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100354 case Opt_gquota:
355 case Opt_grpquota:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100356 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE |
Chandra Seetharaman83e782e2013-06-27 17:25:10 -0500357 XFS_GQUOTA_ENFD);
Eric Sandeen2e74af02016-03-02 09:55:38 +1100358 break;
359 case Opt_gqnoenforce:
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100360 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
Chandra Seetharaman83e782e2013-06-27 17:25:10 -0500361 mp->m_qflags &= ~XFS_GQUOTA_ENFD;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100362 break;
363 case Opt_discard:
Christoph Hellwige84661a2011-05-20 13:45:32 +0000364 mp->m_flags |= XFS_MOUNT_DISCARD;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100365 break;
366 case Opt_nodiscard:
Christoph Hellwige84661a2011-05-20 13:45:32 +0000367 mp->m_flags &= ~XFS_MOUNT_DISCARD;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100368 break;
Dave Chinnercbe4dab2015-06-04 09:19:18 +1000369#ifdef CONFIG_FS_DAX
Eric Sandeen2e74af02016-03-02 09:55:38 +1100370 case Opt_dax:
Dave Chinnercbe4dab2015-06-04 09:19:18 +1000371 mp->m_flags |= XFS_MOUNT_DAX;
Eric Sandeen2e74af02016-03-02 09:55:38 +1100372 break;
Dave Chinnercbe4dab2015-06-04 09:19:18 +1000373#endif
Eric Sandeen2e74af02016-03-02 09:55:38 +1100374 default:
375 xfs_warn(mp, "unknown mount option [%s].", p);
Dave Chinner24513372014-06-25 14:58:08 +1000376 return -EINVAL;
David Chinnera67d7c52007-11-23 16:29:32 +1100377 }
378 }
379
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100380 /*
381 * no recovery flag requires a read-only mount
382 */
383 if ((mp->m_flags & XFS_MOUNT_NORECOVERY) &&
384 !(mp->m_flags & XFS_MOUNT_RDONLY)) {
Dave Chinner4f107002011-03-07 10:00:35 +1100385 xfs_warn(mp, "no-recovery mounts must be read-only.");
Dave Chinner24513372014-06-25 14:58:08 +1000386 return -EINVAL;
David Chinnera67d7c52007-11-23 16:29:32 +1100387 }
388
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100389 if ((mp->m_flags & XFS_MOUNT_NOALIGN) && (dsunit || dswidth)) {
Dave Chinner4f107002011-03-07 10:00:35 +1100390 xfs_warn(mp,
391 "sunit and swidth options incompatible with the noalign option");
Dave Chinner24513372014-06-25 14:58:08 +1000392 return -EINVAL;
David Chinnera67d7c52007-11-23 16:29:32 +1100393 }
394
Christoph Hellwig7d095252009-06-08 15:33:32 +0200395#ifndef CONFIG_XFS_QUOTA
396 if (XFS_IS_QUOTA_RUNNING(mp)) {
Dave Chinner4f107002011-03-07 10:00:35 +1100397 xfs_warn(mp, "quota support not available in this kernel.");
Dave Chinner24513372014-06-25 14:58:08 +1000398 return -EINVAL;
Christoph Hellwig7d095252009-06-08 15:33:32 +0200399 }
400#endif
401
David Chinnera67d7c52007-11-23 16:29:32 +1100402 if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
Dave Chinner4f107002011-03-07 10:00:35 +1100403 xfs_warn(mp, "sunit and swidth must be specified together");
Dave Chinner24513372014-06-25 14:58:08 +1000404 return -EINVAL;
David Chinnera67d7c52007-11-23 16:29:32 +1100405 }
406
407 if (dsunit && (dswidth % dsunit != 0)) {
Dave Chinner4f107002011-03-07 10:00:35 +1100408 xfs_warn(mp,
409 "stripe width (%d) must be a multiple of the stripe unit (%d)",
David Chinnera67d7c52007-11-23 16:29:32 +1100410 dswidth, dsunit);
Dave Chinner24513372014-06-25 14:58:08 +1000411 return -EINVAL;
David Chinnera67d7c52007-11-23 16:29:32 +1100412 }
413
David Chinnera67d7c52007-11-23 16:29:32 +1100414done:
Jie Liu39a45d82013-05-02 19:27:47 +0800415 if (dsunit && !(mp->m_flags & XFS_MOUNT_NOALIGN)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100416 /*
417 * At this point the superblock has not been read
418 * in, therefore we do not know the block size.
419 * Before the mount call ends we will convert
420 * these to FSBs.
421 */
Jie Liu39a45d82013-05-02 19:27:47 +0800422 mp->m_dalign = dsunit;
423 mp->m_swidth = dswidth;
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100424 }
425
426 if (mp->m_logbufs != -1 &&
427 mp->m_logbufs != 0 &&
428 (mp->m_logbufs < XLOG_MIN_ICLOGS ||
429 mp->m_logbufs > XLOG_MAX_ICLOGS)) {
Dave Chinner4f107002011-03-07 10:00:35 +1100430 xfs_warn(mp, "invalid logbufs value: %d [not %d-%d]",
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100431 mp->m_logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
Dave Chinner24513372014-06-25 14:58:08 +1000432 return -EINVAL;
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100433 }
434 if (mp->m_logbsize != -1 &&
435 mp->m_logbsize != 0 &&
436 (mp->m_logbsize < XLOG_MIN_RECORD_BSIZE ||
437 mp->m_logbsize > XLOG_MAX_RECORD_BSIZE ||
438 !is_power_of_2(mp->m_logbsize))) {
Dave Chinner4f107002011-03-07 10:00:35 +1100439 xfs_warn(mp,
440 "invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100441 mp->m_logbsize);
Dave Chinner24513372014-06-25 14:58:08 +1000442 return -EINVAL;
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100443 }
444
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100445 if (iosizelog) {
446 if (iosizelog > XFS_MAX_IO_LOG ||
447 iosizelog < XFS_MIN_IO_LOG) {
Dave Chinner4f107002011-03-07 10:00:35 +1100448 xfs_warn(mp, "invalid log iosize: %d [not %d-%d]",
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100449 iosizelog, XFS_MIN_IO_LOG,
450 XFS_MAX_IO_LOG);
Dave Chinner24513372014-06-25 14:58:08 +1000451 return -EINVAL;
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100452 }
453
454 mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
455 mp->m_readio_log = iosizelog;
456 mp->m_writeio_log = iosizelog;
457 }
458
David Chinnera67d7c52007-11-23 16:29:32 +1100459 return 0;
460}
461
462struct proc_xfs_info {
Dave Chinnercbe4dab2015-06-04 09:19:18 +1000463 uint64_t flag;
464 char *str;
David Chinnera67d7c52007-11-23 16:29:32 +1100465};
466
467STATIC int
468xfs_showargs(
469 struct xfs_mount *mp,
470 struct seq_file *m)
471{
472 static struct proc_xfs_info xfs_info_set[] = {
473 /* the few simple ones we can get from the mount struct */
Eric Sandeen2e74af02016-03-02 09:55:38 +1100474 { XFS_MOUNT_IKEEP, ",ikeep" },
475 { XFS_MOUNT_WSYNC, ",wsync" },
476 { XFS_MOUNT_NOALIGN, ",noalign" },
477 { XFS_MOUNT_SWALLOC, ",swalloc" },
478 { XFS_MOUNT_NOUUID, ",nouuid" },
479 { XFS_MOUNT_NORECOVERY, ",norecovery" },
480 { XFS_MOUNT_ATTR2, ",attr2" },
481 { XFS_MOUNT_FILESTREAMS, ",filestreams" },
482 { XFS_MOUNT_GRPID, ",grpid" },
483 { XFS_MOUNT_DISCARD, ",discard" },
484 { XFS_MOUNT_SMALL_INUMS, ",inode32" },
485 { XFS_MOUNT_DAX, ",dax" },
David Chinnera67d7c52007-11-23 16:29:32 +1100486 { 0, NULL }
487 };
488 static struct proc_xfs_info xfs_info_unset[] = {
489 /* the few simple ones we can get from the mount struct */
Eric Sandeen2e74af02016-03-02 09:55:38 +1100490 { XFS_MOUNT_COMPAT_IOSIZE, ",largeio" },
491 { XFS_MOUNT_BARRIER, ",nobarrier" },
492 { XFS_MOUNT_SMALL_INUMS, ",inode64" },
David Chinnera67d7c52007-11-23 16:29:32 +1100493 { 0, NULL }
494 };
495 struct proc_xfs_info *xfs_infop;
496
497 for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
498 if (mp->m_flags & xfs_infop->flag)
499 seq_puts(m, xfs_infop->str);
500 }
501 for (xfs_infop = xfs_info_unset; xfs_infop->flag; xfs_infop++) {
502 if (!(mp->m_flags & xfs_infop->flag))
503 seq_puts(m, xfs_infop->str);
504 }
505
506 if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
Eric Sandeen2e74af02016-03-02 09:55:38 +1100507 seq_printf(m, ",allocsize=%dk",
David Chinnera67d7c52007-11-23 16:29:32 +1100508 (int)(1 << mp->m_writeio_log) >> 10);
509
510 if (mp->m_logbufs > 0)
Eric Sandeen2e74af02016-03-02 09:55:38 +1100511 seq_printf(m, ",logbufs=%d", mp->m_logbufs);
David Chinnera67d7c52007-11-23 16:29:32 +1100512 if (mp->m_logbsize > 0)
Eric Sandeen2e74af02016-03-02 09:55:38 +1100513 seq_printf(m, ",logbsize=%dk", mp->m_logbsize >> 10);
David Chinnera67d7c52007-11-23 16:29:32 +1100514
515 if (mp->m_logname)
Eric Sandeen2e74af02016-03-02 09:55:38 +1100516 seq_show_option(m, "logdev", mp->m_logname);
David Chinnera67d7c52007-11-23 16:29:32 +1100517 if (mp->m_rtname)
Eric Sandeen2e74af02016-03-02 09:55:38 +1100518 seq_show_option(m, "rtdev", mp->m_rtname);
David Chinnera67d7c52007-11-23 16:29:32 +1100519
520 if (mp->m_dalign > 0)
Eric Sandeen2e74af02016-03-02 09:55:38 +1100521 seq_printf(m, ",sunit=%d",
David Chinnera67d7c52007-11-23 16:29:32 +1100522 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
523 if (mp->m_swidth > 0)
Eric Sandeen2e74af02016-03-02 09:55:38 +1100524 seq_printf(m, ",swidth=%d",
David Chinnera67d7c52007-11-23 16:29:32 +1100525 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
526
527 if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD))
Eric Sandeen2e74af02016-03-02 09:55:38 +1100528 seq_puts(m, ",usrquota");
David Chinnera67d7c52007-11-23 16:29:32 +1100529 else if (mp->m_qflags & XFS_UQUOTA_ACCT)
Eric Sandeen2e74af02016-03-02 09:55:38 +1100530 seq_puts(m, ",uqnoenforce");
David Chinnera67d7c52007-11-23 16:29:32 +1100531
Alex Elder988abe42009-09-02 17:02:24 -0500532 if (mp->m_qflags & XFS_PQUOTA_ACCT) {
Chandra Seetharaman83e782e2013-06-27 17:25:10 -0500533 if (mp->m_qflags & XFS_PQUOTA_ENFD)
Eric Sandeen2e74af02016-03-02 09:55:38 +1100534 seq_puts(m, ",prjquota");
Alex Elder988abe42009-09-02 17:02:24 -0500535 else
Eric Sandeen2e74af02016-03-02 09:55:38 +1100536 seq_puts(m, ",pqnoenforce");
Chandra Seetharamand892d582013-07-19 17:36:02 -0500537 }
538 if (mp->m_qflags & XFS_GQUOTA_ACCT) {
Chandra Seetharaman83e782e2013-06-27 17:25:10 -0500539 if (mp->m_qflags & XFS_GQUOTA_ENFD)
Eric Sandeen2e74af02016-03-02 09:55:38 +1100540 seq_puts(m, ",grpquota");
Alex Elder988abe42009-09-02 17:02:24 -0500541 else
Eric Sandeen2e74af02016-03-02 09:55:38 +1100542 seq_puts(m, ",gqnoenforce");
Alex Elder988abe42009-09-02 17:02:24 -0500543 }
David Chinnera67d7c52007-11-23 16:29:32 +1100544
545 if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
Eric Sandeen2e74af02016-03-02 09:55:38 +1100546 seq_puts(m, ",noquota");
David Chinnera67d7c52007-11-23 16:29:32 +1100547
548 return 0;
549}
Eric Sandeen0d5a75e2016-06-01 17:38:15 +1000550static __uint64_t
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551xfs_max_file_offset(
552 unsigned int blockshift)
553{
554 unsigned int pagefactor = 1;
555 unsigned int bitshift = BITS_PER_LONG - 1;
556
557 /* Figure out maximum filesize, on Linux this can depend on
558 * the filesystem blocksize (on 32 bit platforms).
Christoph Hellwigebdec242010-10-06 10:47:23 +0200559 * __block_write_begin does this in an [unsigned] long...
Kirill A. Shutemovea1754a2016-04-01 15:29:48 +0300560 * page->index << (PAGE_SHIFT - bbits)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 * So, for page sized blocks (4K on 32 bit platforms),
562 * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
Kirill A. Shutemovea1754a2016-04-01 15:29:48 +0300563 * (((u64)PAGE_SIZE << (BITS_PER_LONG-1))-1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 * but for smaller blocksizes it is less (bbits = log2 bsize).
565 * Note1: get_block_t takes a long (implicit cast from above)
566 * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch
567 * can optionally convert the [unsigned] long from above into
568 * an [unsigned] long long.
569 */
570
571#if BITS_PER_LONG == 32
Bartlomiej Zolnierkiewicz90c699a2009-06-19 08:08:50 +0200572# if defined(CONFIG_LBDAF)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 ASSERT(sizeof(sector_t) == 8);
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +0300574 pagefactor = PAGE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 bitshift = BITS_PER_LONG;
576# else
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +0300577 pagefactor = PAGE_SIZE >> (PAGE_SHIFT - blockshift);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578# endif
579#endif
580
581 return (((__uint64_t)pagefactor) << bitshift) - 1;
582}
583
Eric Sandeen9de67c32014-07-24 20:51:54 +1000584/*
Eric Sandeen12c3f052016-03-02 09:58:09 +1100585 * Set parameters for inode allocation heuristics, taking into account
586 * filesystem size and inode32/inode64 mount options; i.e. specifically
587 * whether or not XFS_MOUNT_SMALL_INUMS is set.
588 *
589 * Inode allocation patterns are altered only if inode32 is requested
590 * (XFS_MOUNT_SMALL_INUMS), and the filesystem is sufficiently large.
591 * If altered, XFS_MOUNT_32BITINODES is set as well.
592 *
593 * An agcount independent of that in the mount structure is provided
594 * because in the growfs case, mp->m_sb.sb_agcount is not yet updated
595 * to the potentially higher ag count.
596 *
597 * Returns the maximum AG index which may contain inodes.
Eric Sandeen9de67c32014-07-24 20:51:54 +1000598 */
Carlos Maiolino2d2194f2012-09-20 10:32:38 -0300599xfs_agnumber_t
Eric Sandeen12c3f052016-03-02 09:58:09 +1100600xfs_set_inode_alloc(
601 struct xfs_mount *mp,
602 xfs_agnumber_t agcount)
Carlos Maiolino2d2194f2012-09-20 10:32:38 -0300603{
Eric Sandeen12c3f052016-03-02 09:58:09 +1100604 xfs_agnumber_t index;
Carlos Maiolino4056c1d2012-09-20 10:32:40 -0300605 xfs_agnumber_t maxagi = 0;
Carlos Maiolino2d2194f2012-09-20 10:32:38 -0300606 xfs_sb_t *sbp = &mp->m_sb;
607 xfs_agnumber_t max_metadata;
Eric Sandeen54aa61f2014-07-24 20:53:10 +1000608 xfs_agino_t agino;
609 xfs_ino_t ino;
Carlos Maiolino2d2194f2012-09-20 10:32:38 -0300610
Eric Sandeen12c3f052016-03-02 09:58:09 +1100611 /*
612 * Calculate how much should be reserved for inodes to meet
613 * the max inode percentage. Used only for inode32.
Carlos Maiolino2d2194f2012-09-20 10:32:38 -0300614 */
615 if (mp->m_maxicount) {
616 __uint64_t icount;
617
618 icount = sbp->sb_dblocks * sbp->sb_imax_pct;
619 do_div(icount, 100);
620 icount += sbp->sb_agblocks - 1;
621 do_div(icount, sbp->sb_agblocks);
622 max_metadata = icount;
623 } else {
Eric Sandeen9de67c32014-07-24 20:51:54 +1000624 max_metadata = agcount;
Carlos Maiolino2d2194f2012-09-20 10:32:38 -0300625 }
626
Eric Sandeen12c3f052016-03-02 09:58:09 +1100627 /* Get the last possible inode in the filesystem */
Eric Sandeen54aa61f2014-07-24 20:53:10 +1000628 agino = XFS_OFFBNO_TO_AGINO(mp, sbp->sb_agblocks - 1, 0);
Eric Sandeen12c3f052016-03-02 09:58:09 +1100629 ino = XFS_AGINO_TO_INO(mp, agcount - 1, agino);
Eric Sandeen54aa61f2014-07-24 20:53:10 +1000630
Eric Sandeen12c3f052016-03-02 09:58:09 +1100631 /*
632 * If user asked for no more than 32-bit inodes, and the fs is
633 * sufficiently large, set XFS_MOUNT_32BITINODES if we must alter
634 * the allocator to accommodate the request.
635 */
636 if ((mp->m_flags & XFS_MOUNT_SMALL_INUMS) && ino > XFS_MAXINUMBER_32)
637 mp->m_flags |= XFS_MOUNT_32BITINODES;
638 else
639 mp->m_flags &= ~XFS_MOUNT_32BITINODES;
Carlos Maiolino2d2194f2012-09-20 10:32:38 -0300640
Eric Sandeen9de67c32014-07-24 20:51:54 +1000641 for (index = 0; index < agcount; index++) {
Carlos Maiolino2d2194f2012-09-20 10:32:38 -0300642 struct xfs_perag *pag;
643
Eric Sandeen12c3f052016-03-02 09:58:09 +1100644 ino = XFS_AGINO_TO_INO(mp, index, agino);
645
Carlos Maiolino2d2194f2012-09-20 10:32:38 -0300646 pag = xfs_perag_get(mp, index);
Eric Sandeen12c3f052016-03-02 09:58:09 +1100647
648 if (mp->m_flags & XFS_MOUNT_32BITINODES) {
649 if (ino > XFS_MAXINUMBER_32) {
650 pag->pagi_inodeok = 0;
651 pag->pagf_metadata = 0;
652 } else {
653 pag->pagi_inodeok = 1;
654 maxagi++;
655 if (index < max_metadata)
656 pag->pagf_metadata = 1;
657 else
658 pag->pagf_metadata = 0;
659 }
660 } else {
661 pag->pagi_inodeok = 1;
662 pag->pagf_metadata = 0;
663 }
664
Carlos Maiolino2d2194f2012-09-20 10:32:38 -0300665 xfs_perag_put(pag);
666 }
667
Eric Sandeen12c3f052016-03-02 09:58:09 +1100668 return (mp->m_flags & XFS_MOUNT_32BITINODES) ? maxagi : agcount;
Carlos Maiolino2d2194f2012-09-20 10:32:38 -0300669}
670
Hannes Eder3180e662009-03-04 19:34:10 +0100671STATIC int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672xfs_blkdev_get(
673 xfs_mount_t *mp,
674 const char *name,
675 struct block_device **bdevp)
676{
677 int error = 0;
678
Tejun Heod4d77622010-11-13 11:55:18 +0100679 *bdevp = blkdev_get_by_path(name, FMODE_READ|FMODE_WRITE|FMODE_EXCL,
680 mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 if (IS_ERR(*bdevp)) {
682 error = PTR_ERR(*bdevp);
Eric Sandeen77af5742014-12-24 09:47:27 +1100683 xfs_warn(mp, "Invalid device [%s], error=%d", name, error);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 }
685
Dave Chinner24513372014-06-25 14:58:08 +1000686 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687}
688
Hannes Eder3180e662009-03-04 19:34:10 +0100689STATIC void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690xfs_blkdev_put(
691 struct block_device *bdev)
692{
693 if (bdev)
Tejun Heoe525fd82010-11-13 11:55:17 +0100694 blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695}
696
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100697void
698xfs_blkdev_issue_flush(
699 xfs_buftarg_t *buftarg)
700{
Shaohua Li7582df52012-04-24 21:23:46 +0800701 blkdev_issue_flush(buftarg->bt_bdev, GFP_NOFS, NULL);
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100702}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000704STATIC void
705xfs_close_devices(
706 struct xfs_mount *mp)
707{
708 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
Lachlan McIlroyc032bfc2008-07-18 17:13:12 +1000709 struct block_device *logdev = mp->m_logdev_targp->bt_bdev;
Christoph Hellwigb7963132009-03-03 14:48:37 -0500710 xfs_free_buftarg(mp, mp->m_logdev_targp);
Lachlan McIlroyc032bfc2008-07-18 17:13:12 +1000711 xfs_blkdev_put(logdev);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000712 }
713 if (mp->m_rtdev_targp) {
Lachlan McIlroyc032bfc2008-07-18 17:13:12 +1000714 struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev;
Christoph Hellwigb7963132009-03-03 14:48:37 -0500715 xfs_free_buftarg(mp, mp->m_rtdev_targp);
Lachlan McIlroyc032bfc2008-07-18 17:13:12 +1000716 xfs_blkdev_put(rtdev);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000717 }
Christoph Hellwigb7963132009-03-03 14:48:37 -0500718 xfs_free_buftarg(mp, mp->m_ddev_targp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000719}
720
721/*
722 * The file system configurations are:
723 * (1) device (partition) with data and internal log
724 * (2) logical volume with data and log subvolumes.
725 * (3) logical volume with data, log, and realtime subvolumes.
726 *
727 * We only have to handle opening the log and realtime volumes here if
728 * they are present. The data subvolume has already been opened by
729 * get_sb_bdev() and is stored in sb->s_bdev.
730 */
731STATIC int
732xfs_open_devices(
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100733 struct xfs_mount *mp)
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000734{
735 struct block_device *ddev = mp->m_super->s_bdev;
736 struct block_device *logdev = NULL, *rtdev = NULL;
737 int error;
738
739 /*
740 * Open real time and log devices - order is important.
741 */
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100742 if (mp->m_logname) {
743 error = xfs_blkdev_get(mp, mp->m_logname, &logdev);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000744 if (error)
745 goto out;
746 }
747
Christoph Hellwig9d565ff2008-10-30 17:53:24 +1100748 if (mp->m_rtname) {
749 error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000750 if (error)
751 goto out_close_logdev;
752
753 if (rtdev == ddev || rtdev == logdev) {
Dave Chinner4f107002011-03-07 10:00:35 +1100754 xfs_warn(mp,
755 "Cannot mount filesystem with identical rtdev and ddev/logdev.");
Dave Chinner24513372014-06-25 14:58:08 +1000756 error = -EINVAL;
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000757 goto out_close_rtdev;
758 }
759 }
760
761 /*
762 * Setup xfs_mount buffer target pointers
763 */
Dave Chinner24513372014-06-25 14:58:08 +1000764 error = -ENOMEM;
Eric Sandeen34dcefd2014-04-14 19:01:00 +1000765 mp->m_ddev_targp = xfs_alloc_buftarg(mp, ddev);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000766 if (!mp->m_ddev_targp)
767 goto out_close_rtdev;
768
769 if (rtdev) {
Eric Sandeen34dcefd2014-04-14 19:01:00 +1000770 mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000771 if (!mp->m_rtdev_targp)
772 goto out_free_ddev_targ;
773 }
774
775 if (logdev && logdev != ddev) {
Eric Sandeen34dcefd2014-04-14 19:01:00 +1000776 mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000777 if (!mp->m_logdev_targp)
778 goto out_free_rtdev_targ;
779 } else {
780 mp->m_logdev_targp = mp->m_ddev_targp;
781 }
782
783 return 0;
784
785 out_free_rtdev_targ:
786 if (mp->m_rtdev_targp)
Christoph Hellwigb7963132009-03-03 14:48:37 -0500787 xfs_free_buftarg(mp, mp->m_rtdev_targp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000788 out_free_ddev_targ:
Christoph Hellwigb7963132009-03-03 14:48:37 -0500789 xfs_free_buftarg(mp, mp->m_ddev_targp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000790 out_close_rtdev:
Markus Elfringd2a5e3c2014-12-01 08:24:20 +1100791 xfs_blkdev_put(rtdev);
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000792 out_close_logdev:
793 if (logdev && logdev != ddev)
794 xfs_blkdev_put(logdev);
795 out:
796 return error;
797}
798
Christoph Hellwige34b5622008-05-20 15:10:36 +1000799/*
800 * Setup xfs_mount buffer target pointers based on superblock
801 */
802STATIC int
803xfs_setup_devices(
804 struct xfs_mount *mp)
805{
806 int error;
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000807
Eric Sandeena96c4152014-04-14 19:00:29 +1000808 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_sectsize);
Christoph Hellwige34b5622008-05-20 15:10:36 +1000809 if (error)
810 return error;
811
812 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
813 unsigned int log_sector_size = BBSIZE;
814
815 if (xfs_sb_version_hassector(&mp->m_sb))
816 log_sector_size = mp->m_sb.sb_logsectsize;
817 error = xfs_setsize_buftarg(mp->m_logdev_targp,
Christoph Hellwige34b5622008-05-20 15:10:36 +1000818 log_sector_size);
819 if (error)
820 return error;
821 }
822 if (mp->m_rtdev_targp) {
823 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
Christoph Hellwige34b5622008-05-20 15:10:36 +1000824 mp->m_sb.sb_sectsize);
825 if (error)
826 return error;
827 }
828
829 return 0;
830}
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000831
Christoph Hellwigaa6bf012012-02-29 09:53:48 +0000832STATIC int
833xfs_init_mount_workqueues(
834 struct xfs_mount *mp)
835{
Brian Foster78c931b2014-11-28 13:59:58 +1100836 mp->m_buf_workqueue = alloc_workqueue("xfs-buf/%s",
Brian Fosterb29c70f2014-12-04 09:43:17 +1100837 WQ_MEM_RECLAIM|WQ_FREEZABLE, 1, mp->m_fsname);
Brian Foster78c931b2014-11-28 13:59:58 +1100838 if (!mp->m_buf_workqueue)
839 goto out;
840
Christoph Hellwigaa6bf012012-02-29 09:53:48 +0000841 mp->m_data_workqueue = alloc_workqueue("xfs-data/%s",
Brian Foster8018ec02014-09-09 11:44:46 +1000842 WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_fsname);
Christoph Hellwigaa6bf012012-02-29 09:53:48 +0000843 if (!mp->m_data_workqueue)
Brian Foster78c931b2014-11-28 13:59:58 +1100844 goto out_destroy_buf;
Christoph Hellwigaa6bf012012-02-29 09:53:48 +0000845
846 mp->m_unwritten_workqueue = alloc_workqueue("xfs-conv/%s",
Brian Foster8018ec02014-09-09 11:44:46 +1000847 WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_fsname);
Christoph Hellwigaa6bf012012-02-29 09:53:48 +0000848 if (!mp->m_unwritten_workqueue)
849 goto out_destroy_data_iodone_queue;
850
Dave Chinner4c2d5422012-04-23 17:54:32 +1000851 mp->m_cil_workqueue = alloc_workqueue("xfs-cil/%s",
Brian Foster8018ec02014-09-09 11:44:46 +1000852 WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_fsname);
Dave Chinner4c2d5422012-04-23 17:54:32 +1000853 if (!mp->m_cil_workqueue)
854 goto out_destroy_unwritten;
Dave Chinner58896082012-10-08 21:56:05 +1100855
856 mp->m_reclaim_workqueue = alloc_workqueue("xfs-reclaim/%s",
Chris Mason7a29ac42015-11-10 10:10:34 +1100857 WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_fsname);
Dave Chinner58896082012-10-08 21:56:05 +1100858 if (!mp->m_reclaim_workqueue)
859 goto out_destroy_cil;
860
861 mp->m_log_workqueue = alloc_workqueue("xfs-log/%s",
Chris Mason7a29ac42015-11-10 10:10:34 +1100862 WQ_MEM_RECLAIM|WQ_FREEZABLE|WQ_HIGHPRI, 0,
863 mp->m_fsname);
Dave Chinner58896082012-10-08 21:56:05 +1100864 if (!mp->m_log_workqueue)
865 goto out_destroy_reclaim;
866
Brian Foster579b62f2012-11-06 09:50:47 -0500867 mp->m_eofblocks_workqueue = alloc_workqueue("xfs-eofblocks/%s",
Chris Mason7a29ac42015-11-10 10:10:34 +1100868 WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_fsname);
Brian Foster579b62f2012-11-06 09:50:47 -0500869 if (!mp->m_eofblocks_workqueue)
870 goto out_destroy_log;
871
Christoph Hellwigaa6bf012012-02-29 09:53:48 +0000872 return 0;
873
Brian Foster579b62f2012-11-06 09:50:47 -0500874out_destroy_log:
875 destroy_workqueue(mp->m_log_workqueue);
Dave Chinner58896082012-10-08 21:56:05 +1100876out_destroy_reclaim:
877 destroy_workqueue(mp->m_reclaim_workqueue);
878out_destroy_cil:
879 destroy_workqueue(mp->m_cil_workqueue);
Dave Chinner4c2d5422012-04-23 17:54:32 +1000880out_destroy_unwritten:
881 destroy_workqueue(mp->m_unwritten_workqueue);
Christoph Hellwigaa6bf012012-02-29 09:53:48 +0000882out_destroy_data_iodone_queue:
883 destroy_workqueue(mp->m_data_workqueue);
Brian Foster78c931b2014-11-28 13:59:58 +1100884out_destroy_buf:
885 destroy_workqueue(mp->m_buf_workqueue);
Christoph Hellwigaa6bf012012-02-29 09:53:48 +0000886out:
887 return -ENOMEM;
888}
889
890STATIC void
891xfs_destroy_mount_workqueues(
892 struct xfs_mount *mp)
893{
Brian Foster579b62f2012-11-06 09:50:47 -0500894 destroy_workqueue(mp->m_eofblocks_workqueue);
Dave Chinner58896082012-10-08 21:56:05 +1100895 destroy_workqueue(mp->m_log_workqueue);
896 destroy_workqueue(mp->m_reclaim_workqueue);
Dave Chinner4c2d5422012-04-23 17:54:32 +1000897 destroy_workqueue(mp->m_cil_workqueue);
Christoph Hellwigaa6bf012012-02-29 09:53:48 +0000898 destroy_workqueue(mp->m_data_workqueue);
899 destroy_workqueue(mp->m_unwritten_workqueue);
Brian Foster78c931b2014-11-28 13:59:58 +1100900 destroy_workqueue(mp->m_buf_workqueue);
Christoph Hellwigaa6bf012012-02-29 09:53:48 +0000901}
902
Dave Chinner9aa05002012-10-08 21:56:04 +1100903/*
904 * Flush all dirty data to disk. Must not be called while holding an XFS_ILOCK
905 * or a page lock. We use sync_inodes_sb() here to ensure we block while waiting
906 * for IO to complete so that we effectively throttle multiple callers to the
907 * rate at which IO is completing.
908 */
909void
910xfs_flush_inodes(
911 struct xfs_mount *mp)
912{
913 struct super_block *sb = mp->m_super;
914
915 if (down_read_trylock(&sb->s_umount)) {
Jan Kara0dc83bd2014-02-21 11:19:04 +0100916 sync_inodes_sb(sb);
Dave Chinner9aa05002012-10-08 21:56:04 +1100917 up_read(&sb->s_umount);
918 }
919}
920
David Chinnerbf904242008-10-30 17:36:14 +1100921/* Catch misguided souls that try to use this interface on XFS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922STATIC struct inode *
Nathan Scotta50cd262006-03-14 14:06:18 +1100923xfs_fs_alloc_inode(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 struct super_block *sb)
925{
David Chinnerbf904242008-10-30 17:36:14 +1100926 BUG();
Lachlan McIlroy493dca62008-10-30 17:36:52 +1100927 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928}
929
David Chinnerbf904242008-10-30 17:36:14 +1100930/*
David Chinner99fa8cb2008-10-30 17:36:40 +1100931 * Now that the generic code is guaranteed not to be accessing
Dave Chinner8179c032016-05-18 13:52:42 +1000932 * the linux inode, we can inactivate and reclaim the inode.
David Chinnerbf904242008-10-30 17:36:14 +1100933 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +1100935xfs_fs_destroy_inode(
Christoph Hellwig848ce8f2009-09-29 13:48:56 +0000936 struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937{
Christoph Hellwig848ce8f2009-09-29 13:48:56 +0000938 struct xfs_inode *ip = XFS_I(inode);
939
Christoph Hellwigcca28fb2010-06-24 11:57:09 +1000940 trace_xfs_destroy_inode(ip);
David Chinner99fa8cb2008-10-30 17:36:40 +1100941
Dave Chinner8179c032016-05-18 13:52:42 +1000942 ASSERT(!rwsem_is_locked(&ip->i_iolock.mr_lock));
943 XFS_STATS_INC(ip->i_mount, vn_rele);
944 XFS_STATS_INC(ip->i_mount, vn_remove);
945
946 xfs_inactive(ip);
Christoph Hellwig848ce8f2009-09-29 13:48:56 +0000947
Christoph Hellwig848ce8f2009-09-29 13:48:56 +0000948 ASSERT(XFS_FORCED_SHUTDOWN(ip->i_mount) || ip->i_delayed_blks == 0);
Dave Chinner8179c032016-05-18 13:52:42 +1000949 XFS_STATS_INC(ip->i_mount, vn_reclaim);
Christoph Hellwig848ce8f2009-09-29 13:48:56 +0000950
951 /*
952 * We should never get here with one of the reclaim flags already set.
953 */
954 ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIMABLE));
955 ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIM));
956
957 /*
Dave Chinner57817c62010-01-10 23:51:47 +0000958 * We always use background reclaim here because even if the
959 * inode is clean, it still may be under IO and hence we have
960 * to take the flush lock. The background reclaim path handles
961 * this more efficiently than we can here, so simply let background
962 * reclaim tear down all inodes.
Christoph Hellwig848ce8f2009-09-29 13:48:56 +0000963 */
Dave Chinner57817c62010-01-10 23:51:47 +0000964 xfs_inode_set_reclaim_tag(ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965}
966
David Chinner07c8f672008-10-30 16:11:59 +1100967/*
968 * Slab object creation initialisation for the XFS inode.
969 * This covers only the idempotent fields in the XFS inode;
970 * all other fields need to be initialised on allocation
Uwe Kleine-Königb5950762010-11-01 15:38:34 -0400971 * from the slab. This avoids the need to repeatedly initialise
David Chinner07c8f672008-10-30 16:11:59 +1100972 * fields in the xfs inode that left in the initialise state
973 * when freeing the inode.
974 */
David Chinnerbf904242008-10-30 17:36:14 +1100975STATIC void
976xfs_fs_inode_init_once(
David Chinner07c8f672008-10-30 16:11:59 +1100977 void *inode)
978{
979 struct xfs_inode *ip = inode;
980
981 memset(ip, 0, sizeof(struct xfs_inode));
David Chinnerbf904242008-10-30 17:36:14 +1100982
983 /* vfs inode */
984 inode_init_once(VFS_I(ip));
985
986 /* xfs inode */
David Chinner07c8f672008-10-30 16:11:59 +1100987 atomic_set(&ip->i_pincount, 0);
988 spin_lock_init(&ip->i_flags_lock);
David Chinner07c8f672008-10-30 16:11:59 +1100989
Dave Chinner653c60b2015-02-23 21:43:37 +1100990 mrlock_init(&ip->i_mmaplock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
991 "xfsino", ip->i_ino);
David Chinner07c8f672008-10-30 16:11:59 +1100992 mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
993 "xfsino", ip->i_ino);
David Chinner07c8f672008-10-30 16:11:59 +1100994}
995
Dave Chinner5132ba82012-03-22 05:15:10 +0000996/*
997 * We do an unlocked check for XFS_IDONTCACHE here because we are already
998 * serialised against cache hits here via the inode->i_lock and igrab() in
999 * xfs_iget_cache_hit(). Hence a lookup that might clear this flag will not be
1000 * racing with us, and it avoids needing to grab a spinlock here for every inode
1001 * we drop the final reference on.
1002 */
1003STATIC int
1004xfs_fs_drop_inode(
1005 struct inode *inode)
1006{
1007 struct xfs_inode *ip = XFS_I(inode);
1008
1009 return generic_drop_inode(inode) || (ip->i_flags & XFS_IDONTCACHE);
1010}
1011
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012STATIC void
Christoph Hellwiga7381592008-08-13 16:04:05 +10001013xfs_free_fsname(
1014 struct xfs_mount *mp)
1015{
1016 kfree(mp->m_fsname);
1017 kfree(mp->m_rtname);
1018 kfree(mp->m_logname);
1019}
1020
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021STATIC int
Christoph Hellwig69961a22009-10-06 20:29:28 +00001022xfs_fs_sync_fs(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 struct super_block *sb,
1024 int wait)
1025{
Christoph Hellwig745f6912007-08-30 17:20:39 +10001026 struct xfs_mount *mp = XFS_M(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027
Lachlan McIlroye893bff2007-10-12 11:13:35 +10001028 /*
Christoph Hellwig34625c62011-12-06 21:58:12 +00001029 * Doing anything during the async pass would be counterproductive.
Lachlan McIlroye893bff2007-10-12 11:13:35 +10001030 */
Christoph Hellwig34625c62011-12-06 21:58:12 +00001031 if (!wait)
Christoph Hellwig69961a22009-10-06 20:29:28 +00001032 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033
Dave Chinner34061f52012-10-08 21:56:06 +11001034 xfs_log_force(mp, XFS_LOG_SYNC);
Christoph Hellwig69961a22009-10-06 20:29:28 +00001035 if (laptop_mode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 /*
1037 * The disk must be active because we're syncing.
Dave Chinnerf661f1e2012-10-08 21:56:02 +11001038 * We schedule log work now (now that the disk is
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 * active) instead of later (when it might not be).
1040 */
Dave Chinnerf661f1e2012-10-08 21:56:02 +11001041 flush_delayed_work(&mp->m_log->l_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 }
1043
Christoph Hellwig69961a22009-10-06 20:29:28 +00001044 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045}
1046
1047STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001048xfs_fs_statfs(
David Howells726c3342006-06-23 02:02:58 -07001049 struct dentry *dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 struct kstatfs *statp)
1051{
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001052 struct xfs_mount *mp = XFS_M(dentry->d_sb);
1053 xfs_sb_t *sbp = &mp->m_sb;
David Howells2b0143b2015-03-17 22:25:59 +00001054 struct xfs_inode *ip = XFS_I(d_inode(dentry));
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001055 __uint64_t fakeinos, id;
Dave Chinner501ab322015-02-23 21:19:28 +11001056 __uint64_t icount;
Dave Chinnere88b64e2015-02-23 21:19:53 +11001057 __uint64_t ifree;
Dave Chinner0d485ad2015-02-23 21:22:03 +11001058 __uint64_t fdblocks;
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001059 xfs_extlen_t lsize;
Stuart Brodsky2fe33662010-08-24 11:46:05 +10001060 __int64_t ffree;
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001061
1062 statp->f_type = XFS_SB_MAGIC;
1063 statp->f_namelen = MAXNAMELEN - 1;
1064
1065 id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
1066 statp->f_fsid.val[0] = (u32)id;
1067 statp->f_fsid.val[1] = (u32)(id >> 32);
1068
Dave Chinner501ab322015-02-23 21:19:28 +11001069 icount = percpu_counter_sum(&mp->m_icount);
Dave Chinnere88b64e2015-02-23 21:19:53 +11001070 ifree = percpu_counter_sum(&mp->m_ifree);
Dave Chinner0d485ad2015-02-23 21:22:03 +11001071 fdblocks = percpu_counter_sum(&mp->m_fdblocks);
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001072
1073 spin_lock(&mp->m_sb_lock);
1074 statp->f_bsize = sbp->sb_blocksize;
1075 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
1076 statp->f_blocks = sbp->sb_dblocks - lsize;
Dave Chinner0d485ad2015-02-23 21:22:03 +11001077 spin_unlock(&mp->m_sb_lock);
1078
Darrick J. Wong52548852016-08-03 11:38:24 +10001079 statp->f_bfree = fdblocks - mp->m_alloc_set_aside;
Dave Chinner0d485ad2015-02-23 21:22:03 +11001080 statp->f_bavail = statp->f_bfree;
1081
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001082 fakeinos = statp->f_bfree << sbp->sb_inopblog;
Dave Chinner501ab322015-02-23 21:19:28 +11001083 statp->f_files = MIN(icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001084 if (mp->m_maxicount)
Christoph Hellwiga19d9f82009-03-29 09:51:08 +02001085 statp->f_files = min_t(typeof(statp->f_files),
1086 statp->f_files,
1087 mp->m_maxicount);
Stuart Brodsky2fe33662010-08-24 11:46:05 +10001088
Eric Sandeen01f98822015-02-06 09:53:02 +11001089 /* If sb_icount overshot maxicount, report actual allocation */
1090 statp->f_files = max_t(typeof(statp->f_files),
1091 statp->f_files,
1092 sbp->sb_icount);
1093
Stuart Brodsky2fe33662010-08-24 11:46:05 +10001094 /* make sure statp->f_ffree does not underflow */
Dave Chinnere88b64e2015-02-23 21:19:53 +11001095 ffree = statp->f_files - (icount - ifree);
Stuart Brodsky2fe33662010-08-24 11:46:05 +10001096 statp->f_ffree = max_t(__int64_t, ffree, 0);
1097
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001098
Jie Liuda5bf952012-04-12 03:59:57 +00001099 if ((ip->i_d.di_flags & XFS_DIFLAG_PROJINHERIT) &&
Chandra Seetharaman83e782e2013-06-27 17:25:10 -05001100 ((mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))) ==
1101 (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))
Christoph Hellwig7d095252009-06-08 15:33:32 +02001102 xfs_qm_statvfs(ip, statp);
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001103 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104}
1105
Eric Sandeend5db0f92010-02-05 22:59:53 +00001106STATIC void
1107xfs_save_resvblks(struct xfs_mount *mp)
1108{
1109 __uint64_t resblks = 0;
1110
1111 mp->m_resblks_save = mp->m_resblks;
1112 xfs_reserve_blocks(mp, &resblks, NULL);
1113}
1114
1115STATIC void
1116xfs_restore_resvblks(struct xfs_mount *mp)
1117{
1118 __uint64_t resblks;
1119
1120 if (mp->m_resblks_save) {
1121 resblks = mp->m_resblks_save;
1122 mp->m_resblks_save = 0;
1123 } else
1124 resblks = xfs_default_resblks(mp);
1125
1126 xfs_reserve_blocks(mp, &resblks, NULL);
1127}
1128
Dave Chinnerc7eea6f2012-10-08 21:56:07 +11001129/*
1130 * Trigger writeback of all the dirty metadata in the file system.
1131 *
1132 * This ensures that the metadata is written to their location on disk rather
1133 * than just existing in transactions in the log. This means after a quiesce
Dave Chinnerc75921a2012-10-08 21:56:08 +11001134 * there is no log replay required to write the inodes to disk - this is the
1135 * primary difference between a sync and a quiesce.
Dave Chinnerc7eea6f2012-10-08 21:56:07 +11001136 *
Dave Chinnerc75921a2012-10-08 21:56:08 +11001137 * Note: xfs_log_quiesce() stops background log work - the callers must ensure
1138 * it is started again when appropriate.
Dave Chinnerc7eea6f2012-10-08 21:56:07 +11001139 */
Dave Chinner632b89e2013-10-29 22:11:58 +11001140static void
Dave Chinnerc7eea6f2012-10-08 21:56:07 +11001141xfs_quiesce_attr(
1142 struct xfs_mount *mp)
1143{
1144 int error = 0;
1145
1146 /* wait for all modifications to complete */
1147 while (atomic_read(&mp->m_active_trans) > 0)
1148 delay(100);
1149
1150 /* force the log to unpin objects from the now complete transactions */
1151 xfs_log_force(mp, XFS_LOG_SYNC);
1152
1153 /* reclaim inodes to do any IO before the freeze completes */
1154 xfs_reclaim_inodes(mp, 0);
1155 xfs_reclaim_inodes(mp, SYNC_WAIT);
1156
Dave Chinnerc75921a2012-10-08 21:56:08 +11001157 /* Push the superblock and write an unmount record */
1158 error = xfs_log_sbcount(mp);
1159 if (error)
1160 xfs_warn(mp, "xfs_attr_quiesce: failed to log sb changes. "
1161 "Frozen image may not be consistent.");
Dave Chinnerc7eea6f2012-10-08 21:56:07 +11001162 /*
1163 * Just warn here till VFS can correctly support
1164 * read-only remount without racing.
1165 */
1166 WARN_ON(atomic_read(&mp->m_active_trans) != 0);
1167
Dave Chinnerc75921a2012-10-08 21:56:08 +11001168 xfs_log_quiesce(mp);
Dave Chinnerc7eea6f2012-10-08 21:56:07 +11001169}
1170
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171STATIC int
Eric Sandeena08ee402016-03-02 09:56:31 +11001172xfs_test_remount_options(
1173 struct super_block *sb,
1174 struct xfs_mount *mp,
1175 char *options)
1176{
1177 int error = 0;
1178 struct xfs_mount *tmp_mp;
1179
1180 tmp_mp = kmem_zalloc(sizeof(*tmp_mp), KM_MAYFAIL);
1181 if (!tmp_mp)
1182 return -ENOMEM;
1183
1184 tmp_mp->m_super = sb;
1185 error = xfs_parseargs(tmp_mp, options);
1186 xfs_free_fsname(tmp_mp);
1187 kfree(tmp_mp);
1188
1189 return error;
1190}
1191
1192STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001193xfs_fs_remount(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 struct super_block *sb,
1195 int *flags,
1196 char *options)
1197{
Christoph Hellwig745f6912007-08-30 17:20:39 +10001198 struct xfs_mount *mp = XFS_M(sb);
Eric Sandeen9de67c32014-07-24 20:51:54 +10001199 xfs_sb_t *sbp = &mp->m_sb;
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001200 substring_t args[MAX_OPT_ARGS];
1201 char *p;
Christoph Hellwig7884bc82009-01-19 02:04:07 +01001202 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203
Eric Sandeena08ee402016-03-02 09:56:31 +11001204 /* First, check for complete junk; i.e. invalid options */
1205 error = xfs_test_remount_options(sb, mp, options);
1206 if (error)
1207 return error;
1208
Theodore Ts'o02b99842014-03-13 10:14:33 -04001209 sync_filesystem(sb);
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001210 while ((p = strsep(&options, ",")) != NULL) {
1211 int token;
Christoph Hellwigbdd907b2008-05-20 15:10:44 +10001212
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001213 if (!*p)
1214 continue;
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001215
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001216 token = match_token(p, tokens, args);
1217 switch (token) {
1218 case Opt_barrier:
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001219 mp->m_flags |= XFS_MOUNT_BARRIER;
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001220 break;
1221 case Opt_nobarrier:
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001222 mp->m_flags &= ~XFS_MOUNT_BARRIER;
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001223 break;
Carlos Maiolinoc3a58fe2012-08-17 18:19:38 -03001224 case Opt_inode64:
Eric Sandeen12c3f052016-03-02 09:58:09 +11001225 mp->m_flags &= ~XFS_MOUNT_SMALL_INUMS;
1226 mp->m_maxagi = xfs_set_inode_alloc(mp, sbp->sb_agcount);
Carlos Maiolinoc3a58fe2012-08-17 18:19:38 -03001227 break;
Carlos Maiolino2ea03922012-09-20 10:32:41 -03001228 case Opt_inode32:
Eric Sandeen12c3f052016-03-02 09:58:09 +11001229 mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
1230 mp->m_maxagi = xfs_set_inode_alloc(mp, sbp->sb_agcount);
Carlos Maiolino2ea03922012-09-20 10:32:41 -03001231 break;
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001232 default:
Christoph Hellwig6efdf282008-09-17 16:49:33 +10001233 /*
1234 * Logically we would return an error here to prevent
1235 * users from believing they might have changed
1236 * mount options using remount which can't be changed.
1237 *
1238 * But unfortunately mount(8) adds all options from
1239 * mtab and fstab to the mount arguments in some cases
1240 * so we can't blindly reject options, but have to
1241 * check for each specified option if it actually
1242 * differs from the currently set option and only
1243 * reject it if that's the case.
1244 *
1245 * Until that is implemented we return success for
1246 * every remount request, and silently ignore all
1247 * options that we can't actually change.
1248 */
1249#if 0
Dave Chinner4f107002011-03-07 10:00:35 +11001250 xfs_info(mp,
Eric Sandeen08e96e12013-10-11 20:59:05 -05001251 "mount option \"%s\" not supported for remount", p);
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001252 return -EINVAL;
Christoph Hellwig6efdf282008-09-17 16:49:33 +10001253#else
Christoph Hellwig6c5e51d2008-10-12 14:30:44 +02001254 break;
Christoph Hellwig6efdf282008-09-17 16:49:33 +10001255#endif
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001256 }
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001257 }
1258
Christoph Hellwig7884bc82009-01-19 02:04:07 +01001259 /* ro -> rw */
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001260 if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(*flags & MS_RDONLY)) {
Eric Sandeenbbe051c2015-04-13 11:25:41 +10001261 if (mp->m_flags & XFS_MOUNT_NORECOVERY) {
1262 xfs_warn(mp,
1263 "ro->rw transition prohibited on norecovery mount");
1264 return -EINVAL;
1265 }
1266
Eric Sandeend0a58e82016-04-06 07:05:41 +10001267 if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 &&
1268 xfs_sb_has_ro_compat_feature(sbp,
1269 XFS_SB_FEAT_RO_COMPAT_UNKNOWN)) {
1270 xfs_warn(mp,
1271"ro->rw transition prohibited on unknown (0x%x) ro-compat filesystem",
1272 (sbp->sb_features_ro_compat &
1273 XFS_SB_FEAT_RO_COMPAT_UNKNOWN));
1274 return -EINVAL;
1275 }
1276
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001277 mp->m_flags &= ~XFS_MOUNT_RDONLY;
Christoph Hellwig7884bc82009-01-19 02:04:07 +01001278
1279 /*
1280 * If this is the first remount to writeable state we
1281 * might have some superblock changes to update.
1282 */
Dave Chinner61e63ec2015-01-22 09:10:31 +11001283 if (mp->m_update_sb) {
1284 error = xfs_sync_sb(mp, false);
Christoph Hellwig7884bc82009-01-19 02:04:07 +01001285 if (error) {
Dave Chinner4f107002011-03-07 10:00:35 +11001286 xfs_warn(mp, "failed to write sb changes");
Christoph Hellwig7884bc82009-01-19 02:04:07 +01001287 return error;
1288 }
Dave Chinner61e63ec2015-01-22 09:10:31 +11001289 mp->m_update_sb = false;
Christoph Hellwig7884bc82009-01-19 02:04:07 +01001290 }
Dave Chinnercbe132a2010-01-26 15:08:49 +11001291
1292 /*
1293 * Fill out the reserve pool if it is empty. Use the stashed
1294 * value if it is non-zero, otherwise go with the default.
1295 */
Eric Sandeend5db0f92010-02-05 22:59:53 +00001296 xfs_restore_resvblks(mp);
Dave Chinnerf661f1e2012-10-08 21:56:02 +11001297 xfs_log_work_queue(mp);
Brian Fosterfa5a4f52016-06-21 11:53:28 +10001298 xfs_queue_eofblocks(mp);
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001299 }
1300
1301 /* rw -> ro */
1302 if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (*flags & MS_RDONLY)) {
Dave Chinnercbe132a2010-01-26 15:08:49 +11001303 /*
Dave Chinner34061f52012-10-08 21:56:06 +11001304 * Before we sync the metadata, we need to free up the reserve
1305 * block pool so that the used block count in the superblock on
1306 * disk is correct at the end of the remount. Stash the current
1307 * reserve pool size so that if we get remounted rw, we can
1308 * return it to the same size.
Dave Chinnercbe132a2010-01-26 15:08:49 +11001309 */
Eric Sandeend5db0f92010-02-05 22:59:53 +00001310 xfs_save_resvblks(mp);
Brian Fosterfa5a4f52016-06-21 11:53:28 +10001311
1312 /*
1313 * Cancel background eofb scanning so it cannot race with the
1314 * final log force+buftarg wait and deadlock the remount.
1315 */
1316 cancel_delayed_work_sync(&mp->m_eofblocks_work);
1317
David Chinner76bf1052008-10-30 17:16:21 +11001318 xfs_quiesce_attr(mp);
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001319 mp->m_flags |= XFS_MOUNT_RDONLY;
1320 }
1321
Christoph Hellwig62a877e2008-07-18 17:12:36 +10001322 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323}
1324
Christoph Hellwig9909c4a2007-10-11 18:11:14 +10001325/*
1326 * Second stage of a freeze. The data is already frozen so we only
Dave Chinner61e63ec2015-01-22 09:10:31 +11001327 * need to take care of the metadata. Once that's done sync the superblock
1328 * to the log to dirty it in case of a crash while frozen. This ensures that we
1329 * will recover the unlinked inode lists on the next mount.
Christoph Hellwig9909c4a2007-10-11 18:11:14 +10001330 */
Takashi Satoc4be0c12009-01-09 16:40:58 -08001331STATIC int
1332xfs_fs_freeze(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 struct super_block *sb)
1334{
Christoph Hellwig9909c4a2007-10-11 18:11:14 +10001335 struct xfs_mount *mp = XFS_M(sb);
1336
Eric Sandeend5db0f92010-02-05 22:59:53 +00001337 xfs_save_resvblks(mp);
David Chinner76bf1052008-10-30 17:16:21 +11001338 xfs_quiesce_attr(mp);
Dave Chinner61e63ec2015-01-22 09:10:31 +11001339 return xfs_sync_sb(mp, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340}
1341
1342STATIC int
Eric Sandeend5db0f92010-02-05 22:59:53 +00001343xfs_fs_unfreeze(
1344 struct super_block *sb)
1345{
1346 struct xfs_mount *mp = XFS_M(sb);
1347
1348 xfs_restore_resvblks(mp);
Dave Chinnerf661f1e2012-10-08 21:56:02 +11001349 xfs_log_work_queue(mp);
Eric Sandeend5db0f92010-02-05 22:59:53 +00001350 return 0;
1351}
1352
1353STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001354xfs_fs_show_options(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 struct seq_file *m,
Al Viro34c80b12011-12-08 21:32:45 -05001356 struct dentry *root)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357{
Dave Chinner24513372014-06-25 14:58:08 +10001358 return xfs_showargs(XFS_M(root->d_sb), m);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359}
1360
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001361/*
1362 * This function fills in xfs_mount_t fields based on mount args.
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001363 * Note: the superblock _has_ now been read in.
1364 */
1365STATIC int
1366xfs_finish_flags(
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001367 struct xfs_mount *mp)
1368{
1369 int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
1370
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02001371 /* Fail a mount where the logbuf is smaller than the log stripe */
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001372 if (xfs_sb_version_haslogv2(&mp->m_sb)) {
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001373 if (mp->m_logbsize <= 0 &&
1374 mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE) {
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001375 mp->m_logbsize = mp->m_sb.sb_logsunit;
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001376 } else if (mp->m_logbsize > 0 &&
1377 mp->m_logbsize < mp->m_sb.sb_logsunit) {
Dave Chinner4f107002011-03-07 10:00:35 +11001378 xfs_warn(mp,
1379 "logbuf size must be greater than or equal to log stripe size");
Dave Chinner24513372014-06-25 14:58:08 +10001380 return -EINVAL;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001381 }
1382 } else {
1383 /* Fail a mount if the logbuf is larger than 32K */
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001384 if (mp->m_logbsize > XLOG_BIG_RECORD_BSIZE) {
Dave Chinner4f107002011-03-07 10:00:35 +11001385 xfs_warn(mp,
1386 "logbuf size for version 1 logs must be 16K or 32K");
Dave Chinner24513372014-06-25 14:58:08 +10001387 return -EINVAL;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001388 }
1389 }
1390
1391 /*
Dave Chinnerd3eaace2013-06-05 12:09:09 +10001392 * V5 filesystems always use attr2 format for attributes.
1393 */
1394 if (xfs_sb_version_hascrc(&mp->m_sb) &&
1395 (mp->m_flags & XFS_MOUNT_NOATTR2)) {
Eric Sandeen2e74af02016-03-02 09:55:38 +11001396 xfs_warn(mp, "Cannot mount a V5 filesystem as noattr2. "
1397 "attr2 is always enabled for V5 filesystems.");
Dave Chinner24513372014-06-25 14:58:08 +10001398 return -EINVAL;
Dave Chinnerd3eaace2013-06-05 12:09:09 +10001399 }
1400
1401 /*
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001402 * mkfs'ed attr2 will turn on attr2 mount unless explicitly
1403 * told by noattr2 to turn it off
1404 */
1405 if (xfs_sb_version_hasattr2(&mp->m_sb) &&
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001406 !(mp->m_flags & XFS_MOUNT_NOATTR2))
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001407 mp->m_flags |= XFS_MOUNT_ATTR2;
1408
1409 /*
1410 * prohibit r/w mounts of read-only filesystems
1411 */
1412 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
Dave Chinner4f107002011-03-07 10:00:35 +11001413 xfs_warn(mp,
1414 "cannot mount a read-only filesystem as read-write");
Dave Chinner24513372014-06-25 14:58:08 +10001415 return -EROFS;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001416 }
1417
Chandra Seetharamand892d582013-07-19 17:36:02 -05001418 if ((mp->m_qflags & (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE)) &&
1419 (mp->m_qflags & (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE)) &&
1420 !xfs_sb_version_has_pquotino(&mp->m_sb)) {
1421 xfs_warn(mp,
1422 "Super block does not support project and group quota together");
Dave Chinner24513372014-06-25 14:58:08 +10001423 return -EINVAL;
Chandra Seetharamand892d582013-07-19 17:36:02 -05001424 }
1425
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001426 return 0;
1427}
1428
Dave Chinner5681ca42015-02-23 21:22:31 +11001429static int
1430xfs_init_percpu_counters(
1431 struct xfs_mount *mp)
1432{
1433 int error;
1434
1435 error = percpu_counter_init(&mp->m_icount, 0, GFP_KERNEL);
1436 if (error)
Joe Perches5e9383f2015-03-25 15:00:24 +11001437 return -ENOMEM;
Dave Chinner5681ca42015-02-23 21:22:31 +11001438
1439 error = percpu_counter_init(&mp->m_ifree, 0, GFP_KERNEL);
1440 if (error)
1441 goto free_icount;
1442
1443 error = percpu_counter_init(&mp->m_fdblocks, 0, GFP_KERNEL);
1444 if (error)
1445 goto free_ifree;
1446
1447 return 0;
1448
1449free_ifree:
1450 percpu_counter_destroy(&mp->m_ifree);
1451free_icount:
1452 percpu_counter_destroy(&mp->m_icount);
1453 return -ENOMEM;
1454}
1455
1456void
1457xfs_reinit_percpu_counters(
1458 struct xfs_mount *mp)
1459{
1460 percpu_counter_set(&mp->m_icount, mp->m_sb.sb_icount);
1461 percpu_counter_set(&mp->m_ifree, mp->m_sb.sb_ifree);
1462 percpu_counter_set(&mp->m_fdblocks, mp->m_sb.sb_fdblocks);
1463}
1464
1465static void
1466xfs_destroy_percpu_counters(
1467 struct xfs_mount *mp)
1468{
1469 percpu_counter_destroy(&mp->m_icount);
1470 percpu_counter_destroy(&mp->m_ifree);
1471 percpu_counter_destroy(&mp->m_fdblocks);
1472}
1473
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001475xfs_fs_fill_super(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 struct super_block *sb,
1477 void *data,
1478 int silent)
1479{
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001480 struct inode *root;
Christoph Hellwig745f6912007-08-30 17:20:39 +10001481 struct xfs_mount *mp = NULL;
Dave Chinner24513372014-06-25 14:58:08 +10001482 int flags = 0, error = -ENOMEM;
Christoph Hellwigbdd907b2008-05-20 15:10:44 +10001483
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001484 mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
1485 if (!mp)
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001486 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001488 spin_lock_init(&mp->m_sb_lock);
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001489 mutex_init(&mp->m_growlock);
1490 atomic_set(&mp->m_active_trans, 0);
Dave Chinner7e185302012-10-08 21:56:00 +11001491 INIT_DELAYED_WORK(&mp->m_reclaim_work, xfs_reclaim_worker);
Brian Foster579b62f2012-11-06 09:50:47 -05001492 INIT_DELAYED_WORK(&mp->m_eofblocks_work, xfs_eofblocks_worker);
Dave Chinnere3aed1a2014-09-29 10:46:08 +10001493 mp->m_kobj.kobject.kset = xfs_kset;
Christoph Hellwig74394492007-08-30 17:21:22 +10001494
Christoph Hellwigb267ce92007-08-30 17:21:30 +10001495 mp->m_super = sb;
1496 sb->s_fs_info = mp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497
Christoph Hellwig288699f2010-06-23 18:11:15 +10001498 error = xfs_parseargs(mp, (char *)data);
Christoph Hellwig745f6912007-08-30 17:20:39 +10001499 if (error)
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001500 goto out_free_fsname;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501
1502 sb_min_blocksize(sb, BBSIZE);
Lachlan McIlroy0ec58512008-06-23 13:23:01 +10001503 sb->s_xattr = xfs_xattr_handlers;
Nathan Scotta50cd262006-03-14 14:06:18 +11001504 sb->s_export_op = &xfs_export_operations;
Christoph Hellwigfcafb712009-02-09 08:47:34 +01001505#ifdef CONFIG_XFS_QUOTA
Nathan Scotta50cd262006-03-14 14:06:18 +11001506 sb->s_qcop = &xfs_quotactl_operations;
Jan Kara17ef4fd2014-09-30 22:35:33 +02001507 sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ;
Christoph Hellwigfcafb712009-02-09 08:47:34 +01001508#endif
Nathan Scotta50cd262006-03-14 14:06:18 +11001509 sb->s_op = &xfs_super_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001511 if (silent)
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001512 flags |= XFS_MFSI_QUIET;
1513
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001514 error = xfs_open_devices(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001515 if (error)
Christoph Hellwig288699f2010-06-23 18:11:15 +10001516 goto out_free_fsname;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001517
Dave Chinner24513372014-06-25 14:58:08 +10001518 error = xfs_init_mount_workqueues(mp);
Christoph Hellwig61ba35d2010-09-30 02:25:54 +00001519 if (error)
1520 goto out_close_devices;
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001521
Dave Chinner5681ca42015-02-23 21:22:31 +11001522 error = xfs_init_percpu_counters(mp);
Christoph Hellwigaa6bf012012-02-29 09:53:48 +00001523 if (error)
1524 goto out_destroy_workqueues;
1525
Bill O'Donnell225e4632015-10-12 18:21:19 +11001526 /* Allocate stats memory before we do operations that might use it */
1527 mp->m_stats.xs_stats = alloc_percpu(struct xfsstats);
1528 if (!mp->m_stats.xs_stats) {
Dan Carpenterf9d460b2015-10-19 08:42:47 +11001529 error = -ENOMEM;
Bill O'Donnell225e4632015-10-12 18:21:19 +11001530 goto out_destroy_counters;
1531 }
1532
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001533 error = xfs_readsb(mp, flags);
1534 if (error)
Bill O'Donnell225e4632015-10-12 18:21:19 +11001535 goto out_free_stats;
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001536
1537 error = xfs_finish_flags(mp);
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001538 if (error)
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001539 goto out_free_sb;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001540
Christoph Hellwige34b5622008-05-20 15:10:36 +10001541 error = xfs_setup_devices(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001542 if (error)
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001543 goto out_free_sb;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001544
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001545 error = xfs_filestream_mount(mp);
1546 if (error)
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001547 goto out_free_sb;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001548
Dave Chinner704b2902011-03-26 09:14:57 +11001549 /*
1550 * we must configure the block size in the superblock before we run the
1551 * full mount process as the mount process can lookup and cache inodes.
Dave Chinner704b2902011-03-26 09:14:57 +11001552 */
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001553 sb->s_magic = XFS_SB_MAGIC;
1554 sb->s_blocksize = mp->m_sb.sb_blocksize;
1555 sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
Al Viro8de52772012-02-06 12:45:27 -05001557 sb->s_max_links = XFS_MAXLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 sb->s_time_gran = 1;
1559 set_posix_acl_flag(sb);
1560
Dave Chinnerdc037ad2013-06-27 16:04:59 +10001561 /* version 5 superblocks support inode version counters. */
1562 if (XFS_SB_VERSION_NUM(&mp->m_sb) == XFS_SB_VERSION_5)
1563 sb->s_flags |= MS_I_VERSION;
1564
Dave Chinnercbe4dab2015-06-04 09:19:18 +10001565 if (mp->m_flags & XFS_MOUNT_DAX) {
1566 xfs_warn(mp,
Toshi Kani1e937cd2016-05-10 10:23:56 -06001567 "DAX enabled. Warning: EXPERIMENTAL, use at your own risk");
1568
1569 error = bdev_dax_supported(sb, sb->s_blocksize);
1570 if (error) {
Dave Chinnercbe4dab2015-06-04 09:19:18 +10001571 xfs_alert(mp,
Toshi Kani1e937cd2016-05-10 10:23:56 -06001572 "DAX unsupported by block device. Turning off DAX.");
Dave Chinnercbe4dab2015-06-04 09:19:18 +10001573 mp->m_flags &= ~XFS_MOUNT_DAX;
1574 }
1575 }
1576
Dave Chinner8a00ebe2012-04-13 12:10:44 +00001577 error = xfs_mountfs(mp);
Christoph Hellwig2bcf6e92011-07-13 13:43:48 +02001578 if (error)
Dave Chinner7e185302012-10-08 21:56:00 +11001579 goto out_filestream_unmount;
Dave Chinner704b2902011-03-26 09:14:57 +11001580
David Chinner01651642008-08-13 15:45:15 +10001581 root = igrab(VFS_I(mp->m_rootip));
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001582 if (!root) {
Dave Chinner24513372014-06-25 14:58:08 +10001583 error = -ENOENT;
Dave Chinner8a00ebe2012-04-13 12:10:44 +00001584 goto out_unmount;
Christoph Hellwigcbc89dc2008-02-05 12:14:01 +11001585 }
Al Viro48fde702012-01-08 22:15:13 -05001586 sb->s_root = d_make_root(root);
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001587 if (!sb->s_root) {
Dave Chinner24513372014-06-25 14:58:08 +10001588 error = -ENOMEM;
Dave Chinner8a00ebe2012-04-13 12:10:44 +00001589 goto out_unmount;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 }
Christoph Hellwig74394492007-08-30 17:21:22 +10001591
Dave Chinner7e185302012-10-08 21:56:00 +11001592 return 0;
1593
1594 out_filestream_unmount:
Christoph Hellwig120226c2008-05-20 15:11:11 +10001595 xfs_filestream_unmount(mp);
Christoph Hellwigeffa2ed2008-05-20 15:11:05 +10001596 out_free_sb:
1597 xfs_freesb(mp);
Bill O'Donnell225e4632015-10-12 18:21:19 +11001598 out_free_stats:
1599 free_percpu(mp->m_stats.xs_stats);
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001600 out_destroy_counters:
Dave Chinner5681ca42015-02-23 21:22:31 +11001601 xfs_destroy_percpu_counters(mp);
Bill O'Donnell225e4632015-10-12 18:21:19 +11001602 out_destroy_workqueues:
Christoph Hellwigaa6bf012012-02-29 09:53:48 +00001603 xfs_destroy_mount_workqueues(mp);
Christoph Hellwig61ba35d2010-09-30 02:25:54 +00001604 out_close_devices:
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001605 xfs_close_devices(mp);
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001606 out_free_fsname:
1607 xfs_free_fsname(mp);
Christoph Hellwigc962fb72008-05-20 15:10:52 +10001608 kfree(mp);
Christoph Hellwig9d565ff2008-10-30 17:53:24 +11001609 out:
Dave Chinner24513372014-06-25 14:58:08 +10001610 return error;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001611
Christoph Hellwig2bcf6e92011-07-13 13:43:48 +02001612 out_unmount:
Christoph Hellwige48ad312008-05-20 11:30:52 +10001613 xfs_filestream_unmount(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001614 xfs_unmountfs(mp);
Christoph Hellwig62033002008-08-13 16:50:21 +10001615 goto out_free_sb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616}
1617
Dave Chinner5681ca42015-02-23 21:22:31 +11001618STATIC void
1619xfs_fs_put_super(
1620 struct super_block *sb)
1621{
1622 struct xfs_mount *mp = XFS_M(sb);
1623
Dave Chinner42254412015-02-24 10:27:28 +11001624 xfs_notice(mp, "Unmounting Filesystem");
Dave Chinner5681ca42015-02-23 21:22:31 +11001625 xfs_filestream_unmount(mp);
1626 xfs_unmountfs(mp);
1627
1628 xfs_freesb(mp);
Bill O'Donnell225e4632015-10-12 18:21:19 +11001629 free_percpu(mp->m_stats.xs_stats);
Dave Chinner5681ca42015-02-23 21:22:31 +11001630 xfs_destroy_percpu_counters(mp);
1631 xfs_destroy_mount_workqueues(mp);
1632 xfs_close_devices(mp);
1633 xfs_free_fsname(mp);
1634 kfree(mp);
1635}
1636
Al Viro152a0832010-07-25 00:46:55 +04001637STATIC struct dentry *
1638xfs_fs_mount(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 struct file_system_type *fs_type,
1640 int flags,
1641 const char *dev_name,
Al Viro152a0832010-07-25 00:46:55 +04001642 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643{
Al Viro152a0832010-07-25 00:46:55 +04001644 return mount_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645}
1646
Dave Chinner0a234c62013-08-28 10:17:57 +10001647static long
Dave Chinner8daaa832011-07-08 14:14:46 +10001648xfs_fs_nr_cached_objects(
Dave Chinner9b17c622013-08-28 10:18:05 +10001649 struct super_block *sb,
Vladimir Davydov4101b622015-02-12 14:58:51 -08001650 struct shrink_control *sc)
Dave Chinner8daaa832011-07-08 14:14:46 +10001651{
1652 return xfs_reclaim_inodes_count(XFS_M(sb));
1653}
1654
Dave Chinner0a234c62013-08-28 10:17:57 +10001655static long
Dave Chinner8daaa832011-07-08 14:14:46 +10001656xfs_fs_free_cached_objects(
1657 struct super_block *sb,
Vladimir Davydov4101b622015-02-12 14:58:51 -08001658 struct shrink_control *sc)
Dave Chinner8daaa832011-07-08 14:14:46 +10001659{
Vladimir Davydov4101b622015-02-12 14:58:51 -08001660 return xfs_reclaim_inodes_nr(XFS_M(sb), sc->nr_to_scan);
Dave Chinner8daaa832011-07-08 14:14:46 +10001661}
1662
Alexey Dobriyanb87221d2009-09-21 17:01:09 -07001663static const struct super_operations xfs_super_operations = {
Nathan Scotta50cd262006-03-14 14:06:18 +11001664 .alloc_inode = xfs_fs_alloc_inode,
1665 .destroy_inode = xfs_fs_destroy_inode,
Dave Chinner5132ba82012-03-22 05:15:10 +00001666 .drop_inode = xfs_fs_drop_inode,
Nathan Scotta50cd262006-03-14 14:06:18 +11001667 .put_super = xfs_fs_put_super,
Christoph Hellwig69961a22009-10-06 20:29:28 +00001668 .sync_fs = xfs_fs_sync_fs,
Takashi Satoc4be0c12009-01-09 16:40:58 -08001669 .freeze_fs = xfs_fs_freeze,
Eric Sandeend5db0f92010-02-05 22:59:53 +00001670 .unfreeze_fs = xfs_fs_unfreeze,
Nathan Scotta50cd262006-03-14 14:06:18 +11001671 .statfs = xfs_fs_statfs,
1672 .remount_fs = xfs_fs_remount,
1673 .show_options = xfs_fs_show_options,
Dave Chinner8daaa832011-07-08 14:14:46 +10001674 .nr_cached_objects = xfs_fs_nr_cached_objects,
1675 .free_cached_objects = xfs_fs_free_cached_objects,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676};
1677
Andrew Morton5085b602007-02-20 13:57:47 -08001678static struct file_system_type xfs_fs_type = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 .owner = THIS_MODULE,
1680 .name = "xfs",
Al Viro152a0832010-07-25 00:46:55 +04001681 .mount = xfs_fs_mount,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 .kill_sb = kill_block_super,
1683 .fs_flags = FS_REQUIRES_DEV,
1684};
Eric W. Biederman7f78e032013-03-02 19:39:14 -08001685MODULE_ALIAS_FS("xfs");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001687STATIC int __init
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001688xfs_init_zones(void)
1689{
Christoph Hellwig0e51a8e2016-04-06 08:34:30 +10001690 xfs_ioend_bioset = bioset_create(4 * MAX_BUF_PER_PAGE,
1691 offsetof(struct xfs_ioend, io_inline_bio));
1692 if (!xfs_ioend_bioset)
David Chinnerbf904242008-10-30 17:36:14 +11001693 goto out;
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001694
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001695 xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t),
1696 "xfs_log_ticket");
1697 if (!xfs_log_ticket_zone)
Christoph Hellwig0e51a8e2016-04-06 08:34:30 +10001698 goto out_free_ioend_bioset;
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001699
Darrick J. Wonge66a4c62016-06-21 11:53:28 +10001700 xfs_bmap_free_item_zone = kmem_zone_init(
Darrick J. Wong310a75a2016-08-03 11:18:10 +10001701 sizeof(struct xfs_extent_free_item),
Darrick J. Wonge66a4c62016-06-21 11:53:28 +10001702 "xfs_bmap_free_item");
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001703 if (!xfs_bmap_free_item_zone)
1704 goto out_destroy_log_ticket_zone;
David Chinnerbf904242008-10-30 17:36:14 +11001705
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001706 xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
1707 "xfs_btree_cur");
1708 if (!xfs_btree_cur_zone)
1709 goto out_destroy_bmap_free_item_zone;
1710
1711 xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t),
1712 "xfs_da_state");
1713 if (!xfs_da_state_zone)
1714 goto out_destroy_btree_cur_zone;
1715
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001716 xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
1717 if (!xfs_ifork_zone)
Dave Chinner1d9025e2012-06-22 18:50:14 +10001718 goto out_destroy_da_state_zone;
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001719
1720 xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
1721 if (!xfs_trans_zone)
1722 goto out_destroy_ifork_zone;
1723
Christoph Hellwige98c4142010-06-23 18:11:15 +10001724 xfs_log_item_desc_zone =
1725 kmem_zone_init(sizeof(struct xfs_log_item_desc),
1726 "xfs_log_item_desc");
1727 if (!xfs_log_item_desc_zone)
1728 goto out_destroy_trans_zone;
1729
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001730 /*
1731 * The size of the zone allocated buf log item is the maximum
1732 * size possible under XFS. This wastes a little bit of memory,
1733 * but it is much faster.
1734 */
Dave Chinner77c1a082012-06-22 18:50:07 +10001735 xfs_buf_item_zone = kmem_zone_init(sizeof(struct xfs_buf_log_item),
1736 "xfs_buf_item");
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001737 if (!xfs_buf_item_zone)
Christoph Hellwige98c4142010-06-23 18:11:15 +10001738 goto out_destroy_log_item_desc_zone;
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001739
1740 xfs_efd_zone = kmem_zone_init((sizeof(xfs_efd_log_item_t) +
1741 ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
1742 sizeof(xfs_extent_t))), "xfs_efd_item");
1743 if (!xfs_efd_zone)
1744 goto out_destroy_buf_item_zone;
1745
1746 xfs_efi_zone = kmem_zone_init((sizeof(xfs_efi_log_item_t) +
1747 ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
1748 sizeof(xfs_extent_t))), "xfs_efi_item");
1749 if (!xfs_efi_zone)
1750 goto out_destroy_efd_zone;
1751
1752 xfs_inode_zone =
1753 kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
Vladimir Davydov5d097052016-01-14 15:18:21 -08001754 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM | KM_ZONE_SPREAD |
1755 KM_ZONE_ACCOUNT, xfs_fs_inode_init_once);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001756 if (!xfs_inode_zone)
1757 goto out_destroy_efi_zone;
1758
1759 xfs_ili_zone =
1760 kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
1761 KM_ZONE_SPREAD, NULL);
1762 if (!xfs_ili_zone)
1763 goto out_destroy_inode_zone;
Dave Chinner3ebe7d22013-06-27 16:04:53 +10001764 xfs_icreate_zone = kmem_zone_init(sizeof(struct xfs_icreate_item),
1765 "xfs_icr");
1766 if (!xfs_icreate_zone)
1767 goto out_destroy_ili_zone;
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001768
Darrick J. Wong5880f2d72016-08-03 12:04:45 +10001769 xfs_rud_zone = kmem_zone_init((sizeof(struct xfs_rud_log_item) +
1770 ((XFS_RUD_MAX_FAST_EXTENTS - 1) *
1771 sizeof(struct xfs_map_extent))),
1772 "xfs_rud_item");
1773 if (!xfs_rud_zone)
1774 goto out_destroy_icreate_zone;
1775
1776 xfs_rui_zone = kmem_zone_init((sizeof(struct xfs_rui_log_item) +
1777 ((XFS_RUI_MAX_FAST_EXTENTS - 1) *
1778 sizeof(struct xfs_map_extent))),
1779 "xfs_rui_item");
1780 if (!xfs_rui_zone)
1781 goto out_destroy_rud_zone;
1782
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001783 return 0;
1784
Darrick J. Wong5880f2d72016-08-03 12:04:45 +10001785 out_destroy_rud_zone:
1786 kmem_zone_destroy(xfs_rud_zone);
1787 out_destroy_icreate_zone:
1788 kmem_zone_destroy(xfs_icreate_zone);
Dave Chinner3ebe7d22013-06-27 16:04:53 +10001789 out_destroy_ili_zone:
1790 kmem_zone_destroy(xfs_ili_zone);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001791 out_destroy_inode_zone:
1792 kmem_zone_destroy(xfs_inode_zone);
1793 out_destroy_efi_zone:
1794 kmem_zone_destroy(xfs_efi_zone);
1795 out_destroy_efd_zone:
1796 kmem_zone_destroy(xfs_efd_zone);
1797 out_destroy_buf_item_zone:
1798 kmem_zone_destroy(xfs_buf_item_zone);
Christoph Hellwige98c4142010-06-23 18:11:15 +10001799 out_destroy_log_item_desc_zone:
1800 kmem_zone_destroy(xfs_log_item_desc_zone);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001801 out_destroy_trans_zone:
1802 kmem_zone_destroy(xfs_trans_zone);
1803 out_destroy_ifork_zone:
1804 kmem_zone_destroy(xfs_ifork_zone);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001805 out_destroy_da_state_zone:
1806 kmem_zone_destroy(xfs_da_state_zone);
1807 out_destroy_btree_cur_zone:
1808 kmem_zone_destroy(xfs_btree_cur_zone);
1809 out_destroy_bmap_free_item_zone:
1810 kmem_zone_destroy(xfs_bmap_free_item_zone);
1811 out_destroy_log_ticket_zone:
1812 kmem_zone_destroy(xfs_log_ticket_zone);
Christoph Hellwig0e51a8e2016-04-06 08:34:30 +10001813 out_free_ioend_bioset:
1814 bioset_free(xfs_ioend_bioset);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001815 out:
1816 return -ENOMEM;
1817}
1818
1819STATIC void
1820xfs_destroy_zones(void)
1821{
Kirill A. Shutemov8c0a8532012-09-26 11:33:07 +10001822 /*
1823 * Make sure all delayed rcu free are flushed before we
1824 * destroy caches.
1825 */
1826 rcu_barrier();
Darrick J. Wong5880f2d72016-08-03 12:04:45 +10001827 kmem_zone_destroy(xfs_rui_zone);
1828 kmem_zone_destroy(xfs_rud_zone);
Dave Chinner3ebe7d22013-06-27 16:04:53 +10001829 kmem_zone_destroy(xfs_icreate_zone);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001830 kmem_zone_destroy(xfs_ili_zone);
1831 kmem_zone_destroy(xfs_inode_zone);
1832 kmem_zone_destroy(xfs_efi_zone);
1833 kmem_zone_destroy(xfs_efd_zone);
1834 kmem_zone_destroy(xfs_buf_item_zone);
Christoph Hellwige98c4142010-06-23 18:11:15 +10001835 kmem_zone_destroy(xfs_log_item_desc_zone);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001836 kmem_zone_destroy(xfs_trans_zone);
1837 kmem_zone_destroy(xfs_ifork_zone);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001838 kmem_zone_destroy(xfs_da_state_zone);
1839 kmem_zone_destroy(xfs_btree_cur_zone);
1840 kmem_zone_destroy(xfs_bmap_free_item_zone);
1841 kmem_zone_destroy(xfs_log_ticket_zone);
Christoph Hellwig0e51a8e2016-04-06 08:34:30 +10001842 bioset_free(xfs_ioend_bioset);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001843}
1844
1845STATIC int __init
Dave Chinner0bf6a5b2011-04-08 12:45:07 +10001846xfs_init_workqueues(void)
1847{
1848 /*
Dave Chinnerc999a222012-03-22 05:15:07 +00001849 * The allocation workqueue can be used in memory reclaim situations
1850 * (writepage path), and parallelism is only limited by the number of
1851 * AGs in all the filesystems mounted. Hence use the default large
1852 * max_active value for this workqueue.
1853 */
Brian Foster8018ec02014-09-09 11:44:46 +10001854 xfs_alloc_wq = alloc_workqueue("xfsalloc",
1855 WQ_MEM_RECLAIM|WQ_FREEZABLE, 0);
Dave Chinnerc999a222012-03-22 05:15:07 +00001856 if (!xfs_alloc_wq)
Dave Chinner58896082012-10-08 21:56:05 +11001857 return -ENOMEM;
Dave Chinnerc999a222012-03-22 05:15:07 +00001858
Dave Chinner0bf6a5b2011-04-08 12:45:07 +10001859 return 0;
Dave Chinner0bf6a5b2011-04-08 12:45:07 +10001860}
1861
Luck, Tony39411f82011-04-11 12:06:12 -07001862STATIC void
Dave Chinner0bf6a5b2011-04-08 12:45:07 +10001863xfs_destroy_workqueues(void)
1864{
Dave Chinnerc999a222012-03-22 05:15:07 +00001865 destroy_workqueue(xfs_alloc_wq);
Dave Chinner0bf6a5b2011-04-08 12:45:07 +10001866}
1867
1868STATIC int __init
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001869init_xfs_fs(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870{
1871 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872
Darrick J. Wong30cbc592016-03-09 08:15:14 +11001873 xfs_check_ondisk_structs();
1874
Christoph Hellwig65795912008-11-28 14:23:33 +11001875 printk(KERN_INFO XFS_VERSION_STRING " with "
1876 XFS_BUILD_OPTIONS " enabled\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877
Darrick J. Wong9749fee2016-08-03 11:14:35 +10001878 xfs_extent_free_init_defer_op();
Darrick J. Wongf8dbebe2016-08-03 12:11:01 +10001879 xfs_rmap_update_init_defer_op();
Darrick J. Wong9749fee2016-08-03 11:14:35 +10001880
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001881 xfs_dir_startup();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882
Nathan Scott87582802006-03-14 13:18:19 +11001883 error = xfs_init_zones();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001884 if (error)
1885 goto out;
1886
Dave Chinner0bf6a5b2011-04-08 12:45:07 +10001887 error = xfs_init_workqueues();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001888 if (error)
Christoph Hellwig0b1b2132009-12-14 23:14:59 +00001889 goto out_destroy_zones;
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001890
Dave Chinner0bf6a5b2011-04-08 12:45:07 +10001891 error = xfs_mru_cache_init();
1892 if (error)
1893 goto out_destroy_wq;
1894
Nathan Scottce8e9222006-01-11 15:39:08 +11001895 error = xfs_buf_init();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001896 if (error)
Christoph Hellwig1919add2014-04-23 07:11:51 +10001897 goto out_mru_cache_uninit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001899 error = xfs_init_procfs();
1900 if (error)
1901 goto out_buf_terminate;
1902
1903 error = xfs_sysctl_register();
1904 if (error)
1905 goto out_cleanup_procfs;
1906
Brian Foster3d871222014-07-15 07:41:37 +10001907 xfs_kset = kset_create_and_add("xfs", NULL, fs_kobj);
1908 if (!xfs_kset) {
1909 error = -ENOMEM;
Bill O'Donnellbb230c12015-10-12 05:15:45 +11001910 goto out_sysctl_unregister;
Brian Foster3d871222014-07-15 07:41:37 +10001911 }
1912
Bill O'Donnell80529c42015-10-12 05:19:45 +11001913 xfsstats.xs_kobj.kobject.kset = xfs_kset;
1914
1915 xfsstats.xs_stats = alloc_percpu(struct xfsstats);
1916 if (!xfsstats.xs_stats) {
1917 error = -ENOMEM;
1918 goto out_kset_unregister;
1919 }
1920
1921 error = xfs_sysfs_init(&xfsstats.xs_kobj, &xfs_stats_ktype, NULL,
Bill O'Donnellbb230c12015-10-12 05:15:45 +11001922 "stats");
1923 if (error)
Bill O'Donnell80529c42015-10-12 05:19:45 +11001924 goto out_free_stats;
Bill O'Donnellbb230c12015-10-12 05:15:45 +11001925
Brian Foster65b65732014-09-09 11:52:42 +10001926#ifdef DEBUG
1927 xfs_dbg_kobj.kobject.kset = xfs_kset;
1928 error = xfs_sysfs_init(&xfs_dbg_kobj, &xfs_dbg_ktype, NULL, "debug");
Christoph Hellwiga05931c2012-03-13 08:52:37 +00001929 if (error)
Bill O'Donnellbb230c12015-10-12 05:15:45 +11001930 goto out_remove_stats_kobj;
Brian Foster65b65732014-09-09 11:52:42 +10001931#endif
1932
1933 error = xfs_qm_init();
1934 if (error)
Bill O'Donnellbb230c12015-10-12 05:15:45 +11001935 goto out_remove_dbg_kobj;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936
1937 error = register_filesystem(&xfs_fs_type);
1938 if (error)
Christoph Hellwiga05931c2012-03-13 08:52:37 +00001939 goto out_qm_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940 return 0;
1941
Christoph Hellwiga05931c2012-03-13 08:52:37 +00001942 out_qm_exit:
1943 xfs_qm_exit();
Bill O'Donnellbb230c12015-10-12 05:15:45 +11001944 out_remove_dbg_kobj:
Brian Foster65b65732014-09-09 11:52:42 +10001945#ifdef DEBUG
1946 xfs_sysfs_del(&xfs_dbg_kobj);
Bill O'Donnellbb230c12015-10-12 05:15:45 +11001947 out_remove_stats_kobj:
Brian Foster65b65732014-09-09 11:52:42 +10001948#endif
Bill O'Donnell80529c42015-10-12 05:19:45 +11001949 xfs_sysfs_del(&xfsstats.xs_kobj);
1950 out_free_stats:
1951 free_percpu(xfsstats.xs_stats);
Bill O'Donnellbb230c12015-10-12 05:15:45 +11001952 out_kset_unregister:
Brian Foster3d871222014-07-15 07:41:37 +10001953 kset_unregister(xfs_kset);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001954 out_sysctl_unregister:
1955 xfs_sysctl_unregister();
1956 out_cleanup_procfs:
1957 xfs_cleanup_procfs();
1958 out_buf_terminate:
Nathan Scottce8e9222006-01-11 15:39:08 +11001959 xfs_buf_terminate();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001960 out_mru_cache_uninit:
1961 xfs_mru_cache_uninit();
Dave Chinner0bf6a5b2011-04-08 12:45:07 +10001962 out_destroy_wq:
1963 xfs_destroy_workqueues();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001964 out_destroy_zones:
Nathan Scott87582802006-03-14 13:18:19 +11001965 xfs_destroy_zones();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001966 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967 return error;
1968}
1969
1970STATIC void __exit
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001971exit_xfs_fs(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972{
Christoph Hellwiga05931c2012-03-13 08:52:37 +00001973 xfs_qm_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974 unregister_filesystem(&xfs_fs_type);
Brian Foster65b65732014-09-09 11:52:42 +10001975#ifdef DEBUG
1976 xfs_sysfs_del(&xfs_dbg_kobj);
1977#endif
Bill O'Donnell80529c42015-10-12 05:19:45 +11001978 xfs_sysfs_del(&xfsstats.xs_kobj);
1979 free_percpu(xfsstats.xs_stats);
Brian Foster3d871222014-07-15 07:41:37 +10001980 kset_unregister(xfs_kset);
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001981 xfs_sysctl_unregister();
1982 xfs_cleanup_procfs();
Nathan Scottce8e9222006-01-11 15:39:08 +11001983 xfs_buf_terminate();
Christoph Hellwig9f8868f2008-07-18 17:11:46 +10001984 xfs_mru_cache_uninit();
Dave Chinner0bf6a5b2011-04-08 12:45:07 +10001985 xfs_destroy_workqueues();
Nathan Scott87582802006-03-14 13:18:19 +11001986 xfs_destroy_zones();
Darrick J. Wongaf3b6382015-11-03 13:06:34 +11001987 xfs_uuid_table_free();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988}
1989
1990module_init(init_xfs_fs);
1991module_exit(exit_xfs_fs);
1992
1993MODULE_AUTHOR("Silicon Graphics, Inc.");
1994MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
1995MODULE_LICENSE("GPL");