]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - fs/xfs/xfs_super.c
xfs: Introduce an ordered buffer item
[mirror_ubuntu-jammy-kernel.git] / fs / xfs / xfs_super.c
CommitLineData
1da177e4 1/*
a805bad5 2 * Copyright (c) 2000-2006 Silicon Graphics, Inc.
7b718769 3 * All Rights Reserved.
1da177e4 4 *
7b718769
NS
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
1da177e4
LT
7 * published by the Free Software Foundation.
8 *
7b718769
NS
9 * 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.
1da177e4 13 *
7b718769
NS
14 * 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
1da177e4 17 */
0b1b213f 18
1da177e4 19#include "xfs.h"
1da177e4 20#include "xfs_log.h"
a844f451 21#include "xfs_inum.h"
1da177e4
LT
22#include "xfs_trans.h"
23#include "xfs_sb.h"
a844f451 24#include "xfs_ag.h"
1da177e4
LT
25#include "xfs_dir2.h"
26#include "xfs_alloc.h"
1da177e4
LT
27#include "xfs_quota.h"
28#include "xfs_mount.h"
1da177e4 29#include "xfs_bmap_btree.h"
a844f451 30#include "xfs_alloc_btree.h"
1da177e4 31#include "xfs_ialloc_btree.h"
1da177e4
LT
32#include "xfs_dinode.h"
33#include "xfs_inode.h"
a844f451
NS
34#include "xfs_btree.h"
35#include "xfs_ialloc.h"
1da177e4 36#include "xfs_bmap.h"
1da177e4
LT
37#include "xfs_rtalloc.h"
38#include "xfs_error.h"
39#include "xfs_itable.h"
9909c4aa 40#include "xfs_fsops.h"
1da177e4
LT
41#include "xfs_attr.h"
42#include "xfs_buf_item.h"
43#include "xfs_utils.h"
739bfb2a 44#include "xfs_vnodeops.h"
a67d7c5f 45#include "xfs_log_priv.h"
249a8c11 46#include "xfs_trans_priv.h"
48b62a1a 47#include "xfs_filestream.h"
9f8868ff 48#include "xfs_da_btree.h"
9f8868ff
CH
49#include "xfs_extfree_item.h"
50#include "xfs_mru_cache.h"
51#include "xfs_inode_item.h"
6d8b79cf 52#include "xfs_icache.h"
0b1b213f 53#include "xfs_trace.h"
1da177e4
LT
54
55#include <linux/namei.h>
56#include <linux/init.h>
5a0e3ad6 57#include <linux/slab.h>
1da177e4 58#include <linux/mount.h>
0829c360 59#include <linux/mempool.h>
1da177e4 60#include <linux/writeback.h>
4df08c52 61#include <linux/kthread.h>
7dfb7103 62#include <linux/freezer.h>
62a877e3 63#include <linux/parser.h>
1da177e4 64
b87221de 65static const struct super_operations xfs_super_operations;
7989cb8e 66static kmem_zone_t *xfs_ioend_zone;
0829c360 67mempool_t *xfs_ioend_pool;
1da177e4 68
a67d7c5f
DC
69#define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
70#define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
71#define MNTOPT_LOGDEV "logdev" /* log device */
72#define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
73#define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
74#define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
a67d7c5f
DC
75#define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
76#define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
77#define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
78#define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
79#define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
80#define MNTOPT_MTPT "mtpt" /* filesystem mount point */
81#define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
82#define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
83#define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
84#define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
85#define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
86#define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
87#define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
88 * unwritten extent conversion */
89#define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
a67d7c5f 90#define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
08bf5404
CM
91#define MNTOPT_32BITINODE "inode32" /* inode allocation limited to
92 * XFS_MAXINUMBER_32 */
a67d7c5f
DC
93#define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
94#define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
95#define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
96#define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
97 * in stat(). */
98#define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
99#define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
100#define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
101#define MNTOPT_QUOTA "quota" /* disk quotas (user) */
102#define MNTOPT_NOQUOTA "noquota" /* no quotas */
103#define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */
104#define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */
105#define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */
106#define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */
107#define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */
108#define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */
109#define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
110#define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
111#define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
112#define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */
e84661aa
CH
113#define MNTOPT_DELAYLOG "delaylog" /* Delayed logging enabled */
114#define MNTOPT_NODELAYLOG "nodelaylog" /* Delayed logging disabled */
115#define MNTOPT_DISCARD "discard" /* Discard unused blocks */
116#define MNTOPT_NODISCARD "nodiscard" /* Do not discard unused blocks */
a67d7c5f 117
62a877e3
CH
118/*
119 * Table driven mount option parser.
120 *
121 * Currently only used for remount, but it will be used for mount
122 * in the future, too.
123 */
124enum {
2ea03929
CM
125 Opt_barrier,
126 Opt_nobarrier,
127 Opt_inode64,
128 Opt_inode32,
129 Opt_err
62a877e3
CH
130};
131
a447c093 132static const match_table_t tokens = {
62a877e3
CH
133 {Opt_barrier, "barrier"},
134 {Opt_nobarrier, "nobarrier"},
c3a58fec 135 {Opt_inode64, "inode64"},
2ea03929 136 {Opt_inode32, "inode32"},
62a877e3
CH
137 {Opt_err, NULL}
138};
139
140
a67d7c5f 141STATIC unsigned long
a17164e5 142suffix_kstrtoint(char *s, unsigned int base, int *res)
a67d7c5f 143{
a17164e5 144 int last, shift_left_factor = 0, _res;
a67d7c5f
DC
145 char *value = s;
146
147 last = strlen(value) - 1;
148 if (value[last] == 'K' || value[last] == 'k') {
149 shift_left_factor = 10;
150 value[last] = '\0';
151 }
152 if (value[last] == 'M' || value[last] == 'm') {
153 shift_left_factor = 20;
154 value[last] = '\0';
155 }
156 if (value[last] == 'G' || value[last] == 'g') {
157 shift_left_factor = 30;
158 value[last] = '\0';
159 }
160
a17164e5
AP
161 if (kstrtoint(s, base, &_res))
162 return -EINVAL;
163 *res = _res << shift_left_factor;
164 return 0;
a67d7c5f
DC
165}
166
9d565ffa
CH
167/*
168 * This function fills in xfs_mount_t fields based on mount args.
169 * Note: the superblock has _not_ yet been read in.
170 *
171 * Note that this function leaks the various device name allocations on
172 * failure. The caller takes care of them.
173 */
a67d7c5f
DC
174STATIC int
175xfs_parseargs(
176 struct xfs_mount *mp,
288699fe 177 char *options)
a67d7c5f 178{
9d565ffa 179 struct super_block *sb = mp->m_super;
a17164e5 180 char *this_char, *value;
9d565ffa
CH
181 int dsunit = 0;
182 int dswidth = 0;
183 int iosize = 0;
a5687787 184 __uint8_t iosizelog = 0;
9d565ffa 185
4f10700a
DC
186 /*
187 * set up the mount name first so all the errors will refer to the
188 * correct device.
189 */
190 mp->m_fsname = kstrndup(sb->s_id, MAXNAMELEN, GFP_KERNEL);
191 if (!mp->m_fsname)
192 return ENOMEM;
193 mp->m_fsname_len = strlen(mp->m_fsname) + 1;
194
9d565ffa
CH
195 /*
196 * Copy binary VFS mount flags we are interested in.
197 */
198 if (sb->s_flags & MS_RDONLY)
199 mp->m_flags |= XFS_MOUNT_RDONLY;
200 if (sb->s_flags & MS_DIRSYNC)
201 mp->m_flags |= XFS_MOUNT_DIRSYNC;
202 if (sb->s_flags & MS_SYNCHRONOUS)
203 mp->m_flags |= XFS_MOUNT_WSYNC;
204
205 /*
206 * Set some default flags that could be cleared by the mount option
207 * parsing.
208 */
209 mp->m_flags |= XFS_MOUNT_BARRIER;
210 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
08bf5404 211#if !XFS_BIG_INUMS
9d565ffa 212 mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
08bf5404 213#endif
a67d7c5f 214
9d565ffa
CH
215 /*
216 * These can be overridden by the mount option parsing.
217 */
218 mp->m_logbufs = -1;
219 mp->m_logbsize = -1;
a67d7c5f
DC
220
221 if (!options)
222 goto done;
223
a67d7c5f
DC
224 while ((this_char = strsep(&options, ",")) != NULL) {
225 if (!*this_char)
226 continue;
227 if ((value = strchr(this_char, '=')) != NULL)
228 *value++ = 0;
229
230 if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
231 if (!value || !*value) {
4f10700a 232 xfs_warn(mp, "%s option requires an argument",
a67d7c5f
DC
233 this_char);
234 return EINVAL;
235 }
a17164e5
AP
236 if (kstrtoint(value, 10, &mp->m_logbufs))
237 return EINVAL;
a67d7c5f
DC
238 } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
239 if (!value || !*value) {
4f10700a 240 xfs_warn(mp, "%s option requires an argument",
a67d7c5f
DC
241 this_char);
242 return EINVAL;
243 }
a17164e5
AP
244 if (suffix_kstrtoint(value, 10, &mp->m_logbsize))
245 return EINVAL;
a67d7c5f
DC
246 } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
247 if (!value || !*value) {
4f10700a 248 xfs_warn(mp, "%s option requires an argument",
a67d7c5f
DC
249 this_char);
250 return EINVAL;
251 }
9d565ffa
CH
252 mp->m_logname = kstrndup(value, MAXNAMELEN, GFP_KERNEL);
253 if (!mp->m_logname)
254 return ENOMEM;
a67d7c5f 255 } else if (!strcmp(this_char, MNTOPT_MTPT)) {
4f10700a 256 xfs_warn(mp, "%s option not allowed on this system",
288699fe
CH
257 this_char);
258 return EINVAL;
a67d7c5f
DC
259 } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
260 if (!value || !*value) {
4f10700a 261 xfs_warn(mp, "%s option requires an argument",
a67d7c5f
DC
262 this_char);
263 return EINVAL;
264 }
9d565ffa
CH
265 mp->m_rtname = kstrndup(value, MAXNAMELEN, GFP_KERNEL);
266 if (!mp->m_rtname)
267 return ENOMEM;
a67d7c5f
DC
268 } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
269 if (!value || !*value) {
4f10700a 270 xfs_warn(mp, "%s option requires an argument",
a67d7c5f
DC
271 this_char);
272 return EINVAL;
273 }
a17164e5
AP
274 if (kstrtoint(value, 10, &iosize))
275 return EINVAL;
1ec7944b 276 iosizelog = ffs(iosize) - 1;
a67d7c5f
DC
277 } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
278 if (!value || !*value) {
4f10700a 279 xfs_warn(mp, "%s option requires an argument",
a67d7c5f
DC
280 this_char);
281 return EINVAL;
282 }
a17164e5
AP
283 if (suffix_kstrtoint(value, 10, &iosize))
284 return EINVAL;
9d565ffa 285 iosizelog = ffs(iosize) - 1;
a67d7c5f
DC
286 } else if (!strcmp(this_char, MNTOPT_GRPID) ||
287 !strcmp(this_char, MNTOPT_BSDGROUPS)) {
288 mp->m_flags |= XFS_MOUNT_GRPID;
289 } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
290 !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
291 mp->m_flags &= ~XFS_MOUNT_GRPID;
292 } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
9d565ffa 293 mp->m_flags |= XFS_MOUNT_WSYNC;
a67d7c5f 294 } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
9d565ffa 295 mp->m_flags |= XFS_MOUNT_NORECOVERY;
a67d7c5f 296 } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
9d565ffa 297 mp->m_flags |= XFS_MOUNT_NOALIGN;
a67d7c5f 298 } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
9d565ffa 299 mp->m_flags |= XFS_MOUNT_SWALLOC;
a67d7c5f
DC
300 } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
301 if (!value || !*value) {
4f10700a 302 xfs_warn(mp, "%s option requires an argument",
a67d7c5f
DC
303 this_char);
304 return EINVAL;
305 }
a17164e5
AP
306 if (kstrtoint(value, 10, &dsunit))
307 return EINVAL;
a67d7c5f
DC
308 } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
309 if (!value || !*value) {
4f10700a 310 xfs_warn(mp, "%s option requires an argument",
a67d7c5f
DC
311 this_char);
312 return EINVAL;
313 }
a17164e5
AP
314 if (kstrtoint(value, 10, &dswidth))
315 return EINVAL;
08bf5404
CM
316 } else if (!strcmp(this_char, MNTOPT_32BITINODE)) {
317 mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
a67d7c5f 318 } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
9d565ffa 319 mp->m_flags &= ~XFS_MOUNT_SMALL_INUMS;
a67d7c5f 320#if !XFS_BIG_INUMS
4f10700a 321 xfs_warn(mp, "%s option not allowed on this system",
a67d7c5f
DC
322 this_char);
323 return EINVAL;
324#endif
325 } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
9d565ffa 326 mp->m_flags |= XFS_MOUNT_NOUUID;
a67d7c5f 327 } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
9d565ffa 328 mp->m_flags |= XFS_MOUNT_BARRIER;
a67d7c5f 329 } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
9d565ffa 330 mp->m_flags &= ~XFS_MOUNT_BARRIER;
a67d7c5f 331 } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
9d565ffa 332 mp->m_flags |= XFS_MOUNT_IKEEP;
a67d7c5f 333 } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
9d565ffa 334 mp->m_flags &= ~XFS_MOUNT_IKEEP;
a67d7c5f 335 } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
9d565ffa 336 mp->m_flags &= ~XFS_MOUNT_COMPAT_IOSIZE;
a67d7c5f 337 } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
9d565ffa 338 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
a67d7c5f 339 } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
9d565ffa 340 mp->m_flags |= XFS_MOUNT_ATTR2;
a67d7c5f 341 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
9d565ffa
CH
342 mp->m_flags &= ~XFS_MOUNT_ATTR2;
343 mp->m_flags |= XFS_MOUNT_NOATTR2;
a67d7c5f 344 } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
9d565ffa 345 mp->m_flags |= XFS_MOUNT_FILESTREAMS;
a67d7c5f 346 } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
4177af3a
CS
347 mp->m_qflags &= ~XFS_ALL_QUOTA_ACCT;
348 mp->m_qflags &= ~XFS_ALL_QUOTA_ENFD;
349 mp->m_qflags &= ~XFS_ALL_QUOTA_ACTIVE;
a67d7c5f
DC
350 } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
351 !strcmp(this_char, MNTOPT_UQUOTA) ||
352 !strcmp(this_char, MNTOPT_USRQUOTA)) {
9d565ffa
CH
353 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE |
354 XFS_UQUOTA_ENFD);
a67d7c5f
DC
355 } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
356 !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
9d565ffa
CH
357 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
358 mp->m_qflags &= ~XFS_UQUOTA_ENFD;
a67d7c5f
DC
359 } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
360 !strcmp(this_char, MNTOPT_PRJQUOTA)) {
9d565ffa
CH
361 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE |
362 XFS_OQUOTA_ENFD);
a67d7c5f 363 } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
9d565ffa
CH
364 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
365 mp->m_qflags &= ~XFS_OQUOTA_ENFD;
a67d7c5f
DC
366 } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
367 !strcmp(this_char, MNTOPT_GRPQUOTA)) {
9d565ffa
CH
368 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE |
369 XFS_OQUOTA_ENFD);
a67d7c5f 370 } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
9d565ffa
CH
371 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
372 mp->m_qflags &= ~XFS_OQUOTA_ENFD;
71e330b5 373 } else if (!strcmp(this_char, MNTOPT_DELAYLOG)) {
93b8a585
CH
374 xfs_warn(mp,
375 "delaylog is the default now, option is deprecated.");
71e330b5 376 } else if (!strcmp(this_char, MNTOPT_NODELAYLOG)) {
242d6219 377 xfs_warn(mp,
93b8a585 378 "nodelaylog support has been removed, option is deprecated.");
e84661aa
CH
379 } else if (!strcmp(this_char, MNTOPT_DISCARD)) {
380 mp->m_flags |= XFS_MOUNT_DISCARD;
381 } else if (!strcmp(this_char, MNTOPT_NODISCARD)) {
382 mp->m_flags &= ~XFS_MOUNT_DISCARD;
a67d7c5f 383 } else if (!strcmp(this_char, "ihashsize")) {
4f10700a
DC
384 xfs_warn(mp,
385 "ihashsize no longer used, option is deprecated.");
a67d7c5f 386 } else if (!strcmp(this_char, "osyncisdsync")) {
4f10700a
DC
387 xfs_warn(mp,
388 "osyncisdsync has no effect, option is deprecated.");
a64afb05 389 } else if (!strcmp(this_char, "osyncisosync")) {
4f10700a
DC
390 xfs_warn(mp,
391 "osyncisosync has no effect, option is deprecated.");
a67d7c5f 392 } else if (!strcmp(this_char, "irixsgid")) {
4f10700a
DC
393 xfs_warn(mp,
394 "irixsgid is now a sysctl(2) variable, option is deprecated.");
a67d7c5f 395 } else {
4f10700a 396 xfs_warn(mp, "unknown mount option [%s].", this_char);
a67d7c5f
DC
397 return EINVAL;
398 }
399 }
400
9d565ffa
CH
401 /*
402 * no recovery flag requires a read-only mount
403 */
404 if ((mp->m_flags & XFS_MOUNT_NORECOVERY) &&
405 !(mp->m_flags & XFS_MOUNT_RDONLY)) {
4f10700a 406 xfs_warn(mp, "no-recovery mounts must be read-only.");
9d565ffa 407 return EINVAL;
a67d7c5f
DC
408 }
409
9d565ffa 410 if ((mp->m_flags & XFS_MOUNT_NOALIGN) && (dsunit || dswidth)) {
4f10700a
DC
411 xfs_warn(mp,
412 "sunit and swidth options incompatible with the noalign option");
a67d7c5f
DC
413 return EINVAL;
414 }
415
7d095257
CH
416#ifndef CONFIG_XFS_QUOTA
417 if (XFS_IS_QUOTA_RUNNING(mp)) {
4f10700a 418 xfs_warn(mp, "quota support not available in this kernel.");
7d095257
CH
419 return EINVAL;
420 }
421#endif
422
9d565ffa
CH
423 if ((mp->m_qflags & (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE)) &&
424 (mp->m_qflags & (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE))) {
4f10700a 425 xfs_warn(mp, "cannot mount with both project and group quota");
a67d7c5f
DC
426 return EINVAL;
427 }
428
a67d7c5f 429 if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
4f10700a 430 xfs_warn(mp, "sunit and swidth must be specified together");
a67d7c5f
DC
431 return EINVAL;
432 }
433
434 if (dsunit && (dswidth % dsunit != 0)) {
4f10700a
DC
435 xfs_warn(mp,
436 "stripe width (%d) must be a multiple of the stripe unit (%d)",
a67d7c5f
DC
437 dswidth, dsunit);
438 return EINVAL;
439 }
440
9d565ffa 441done:
39a45d84 442 if (dsunit && !(mp->m_flags & XFS_MOUNT_NOALIGN)) {
9d565ffa
CH
443 /*
444 * At this point the superblock has not been read
445 * in, therefore we do not know the block size.
446 * Before the mount call ends we will convert
447 * these to FSBs.
448 */
39a45d84
JL
449 mp->m_dalign = dsunit;
450 mp->m_swidth = dswidth;
9d565ffa
CH
451 }
452
453 if (mp->m_logbufs != -1 &&
454 mp->m_logbufs != 0 &&
455 (mp->m_logbufs < XLOG_MIN_ICLOGS ||
456 mp->m_logbufs > XLOG_MAX_ICLOGS)) {
4f10700a 457 xfs_warn(mp, "invalid logbufs value: %d [not %d-%d]",
9d565ffa
CH
458 mp->m_logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
459 return XFS_ERROR(EINVAL);
460 }
461 if (mp->m_logbsize != -1 &&
462 mp->m_logbsize != 0 &&
463 (mp->m_logbsize < XLOG_MIN_RECORD_BSIZE ||
464 mp->m_logbsize > XLOG_MAX_RECORD_BSIZE ||
465 !is_power_of_2(mp->m_logbsize))) {
4f10700a
DC
466 xfs_warn(mp,
467 "invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
9d565ffa
CH
468 mp->m_logbsize);
469 return XFS_ERROR(EINVAL);
470 }
471
9d565ffa
CH
472 if (iosizelog) {
473 if (iosizelog > XFS_MAX_IO_LOG ||
474 iosizelog < XFS_MIN_IO_LOG) {
4f10700a 475 xfs_warn(mp, "invalid log iosize: %d [not %d-%d]",
9d565ffa
CH
476 iosizelog, XFS_MIN_IO_LOG,
477 XFS_MAX_IO_LOG);
478 return XFS_ERROR(EINVAL);
479 }
480
481 mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
482 mp->m_readio_log = iosizelog;
483 mp->m_writeio_log = iosizelog;
a67d7c5f
DC
484 }
485
a67d7c5f
DC
486 return 0;
487}
488
489struct proc_xfs_info {
490 int flag;
491 char *str;
492};
493
494STATIC int
495xfs_showargs(
496 struct xfs_mount *mp,
497 struct seq_file *m)
498{
499 static struct proc_xfs_info xfs_info_set[] = {
500 /* the few simple ones we can get from the mount struct */
1bd960ee 501 { XFS_MOUNT_IKEEP, "," MNTOPT_IKEEP },
a67d7c5f 502 { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
a67d7c5f
DC
503 { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
504 { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
505 { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
506 { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
a67d7c5f
DC
507 { XFS_MOUNT_ATTR2, "," MNTOPT_ATTR2 },
508 { XFS_MOUNT_FILESTREAMS, "," MNTOPT_FILESTREAM },
a67d7c5f 509 { XFS_MOUNT_GRPID, "," MNTOPT_GRPID },
e84661aa 510 { XFS_MOUNT_DISCARD, "," MNTOPT_DISCARD },
08bf5404 511 { XFS_MOUNT_SMALL_INUMS, "," MNTOPT_32BITINODE },
a67d7c5f
DC
512 { 0, NULL }
513 };
514 static struct proc_xfs_info xfs_info_unset[] = {
515 /* the few simple ones we can get from the mount struct */
a67d7c5f
DC
516 { XFS_MOUNT_COMPAT_IOSIZE, "," MNTOPT_LARGEIO },
517 { XFS_MOUNT_BARRIER, "," MNTOPT_NOBARRIER },
518 { XFS_MOUNT_SMALL_INUMS, "," MNTOPT_64BITINODE },
519 { 0, NULL }
520 };
521 struct proc_xfs_info *xfs_infop;
522
523 for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
524 if (mp->m_flags & xfs_infop->flag)
525 seq_puts(m, xfs_infop->str);
526 }
527 for (xfs_infop = xfs_info_unset; xfs_infop->flag; xfs_infop++) {
528 if (!(mp->m_flags & xfs_infop->flag))
529 seq_puts(m, xfs_infop->str);
530 }
531
532 if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
533 seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
534 (int)(1 << mp->m_writeio_log) >> 10);
535
536 if (mp->m_logbufs > 0)
537 seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
538 if (mp->m_logbsize > 0)
539 seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
540
541 if (mp->m_logname)
542 seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
543 if (mp->m_rtname)
544 seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
545
546 if (mp->m_dalign > 0)
547 seq_printf(m, "," MNTOPT_SUNIT "=%d",
548 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
549 if (mp->m_swidth > 0)
550 seq_printf(m, "," MNTOPT_SWIDTH "=%d",
551 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
552
553 if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD))
554 seq_puts(m, "," MNTOPT_USRQUOTA);
555 else if (mp->m_qflags & XFS_UQUOTA_ACCT)
556 seq_puts(m, "," MNTOPT_UQUOTANOENF);
557
988abe40
AE
558 /* Either project or group quotas can be active, not both */
559
560 if (mp->m_qflags & XFS_PQUOTA_ACCT) {
561 if (mp->m_qflags & XFS_OQUOTA_ENFD)
562 seq_puts(m, "," MNTOPT_PRJQUOTA);
563 else
564 seq_puts(m, "," MNTOPT_PQUOTANOENF);
565 } else if (mp->m_qflags & XFS_GQUOTA_ACCT) {
566 if (mp->m_qflags & XFS_OQUOTA_ENFD)
567 seq_puts(m, "," MNTOPT_GRPQUOTA);
568 else
569 seq_puts(m, "," MNTOPT_GQUOTANOENF);
570 }
a67d7c5f
DC
571
572 if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
573 seq_puts(m, "," MNTOPT_NOQUOTA);
574
575 return 0;
576}
1da177e4
LT
577__uint64_t
578xfs_max_file_offset(
579 unsigned int blockshift)
580{
581 unsigned int pagefactor = 1;
582 unsigned int bitshift = BITS_PER_LONG - 1;
583
584 /* Figure out maximum filesize, on Linux this can depend on
585 * the filesystem blocksize (on 32 bit platforms).
ebdec241 586 * __block_write_begin does this in an [unsigned] long...
1da177e4
LT
587 * page->index << (PAGE_CACHE_SHIFT - bbits)
588 * So, for page sized blocks (4K on 32 bit platforms),
589 * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
590 * (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
591 * but for smaller blocksizes it is less (bbits = log2 bsize).
592 * Note1: get_block_t takes a long (implicit cast from above)
593 * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch
594 * can optionally convert the [unsigned] long from above into
595 * an [unsigned] long long.
596 */
597
598#if BITS_PER_LONG == 32
90c699a9 599# if defined(CONFIG_LBDAF)
1da177e4
LT
600 ASSERT(sizeof(sector_t) == 8);
601 pagefactor = PAGE_CACHE_SIZE;
602 bitshift = BITS_PER_LONG;
603# else
604 pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift);
605# endif
606#endif
607
608 return (((__uint64_t)pagefactor) << bitshift) - 1;
609}
610
2d2194f6
CM
611xfs_agnumber_t
612xfs_set_inode32(struct xfs_mount *mp)
613{
614 xfs_agnumber_t index = 0;
4056c1d0 615 xfs_agnumber_t maxagi = 0;
2d2194f6
CM
616 xfs_sb_t *sbp = &mp->m_sb;
617 xfs_agnumber_t max_metadata;
618 xfs_agino_t agino = XFS_OFFBNO_TO_AGINO(mp, sbp->sb_agblocks -1, 0);
619 xfs_ino_t ino = XFS_AGINO_TO_INO(mp, sbp->sb_agcount -1, agino);
620 xfs_perag_t *pag;
621
622 /* Calculate how much should be reserved for inodes to meet
623 * the max inode percentage.
624 */
625 if (mp->m_maxicount) {
626 __uint64_t icount;
627
628 icount = sbp->sb_dblocks * sbp->sb_imax_pct;
629 do_div(icount, 100);
630 icount += sbp->sb_agblocks - 1;
631 do_div(icount, sbp->sb_agblocks);
632 max_metadata = icount;
633 } else {
634 max_metadata = sbp->sb_agcount;
635 }
636
637 for (index = 0; index < sbp->sb_agcount; index++) {
638 ino = XFS_AGINO_TO_INO(mp, index, agino);
4056c1d0 639
2d2194f6 640 if (ino > XFS_MAXINUMBER_32) {
4056c1d0
CM
641 pag = xfs_perag_get(mp, index);
642 pag->pagi_inodeok = 0;
643 pag->pagf_metadata = 0;
644 xfs_perag_put(pag);
645 continue;
2d2194f6
CM
646 }
647
648 pag = xfs_perag_get(mp, index);
649 pag->pagi_inodeok = 1;
4056c1d0 650 maxagi++;
2d2194f6
CM
651 if (index < max_metadata)
652 pag->pagf_metadata = 1;
653 xfs_perag_put(pag);
654 }
4056c1d0
CM
655 mp->m_flags |= (XFS_MOUNT_32BITINODES |
656 XFS_MOUNT_SMALL_INUMS);
657
658 return maxagi;
2d2194f6
CM
659}
660
661xfs_agnumber_t
662xfs_set_inode64(struct xfs_mount *mp)
663{
664 xfs_agnumber_t index = 0;
665
666 for (index = 0; index < mp->m_sb.sb_agcount; index++) {
667 struct xfs_perag *pag;
668
669 pag = xfs_perag_get(mp, index);
670 pag->pagi_inodeok = 1;
671 pag->pagf_metadata = 0;
672 xfs_perag_put(pag);
673 }
674
675 /* There is no need for lock protection on m_flags,
676 * the rw_semaphore of the VFS superblock is locked
677 * during mount/umount/remount operations, so this is
678 * enough to avoid concurency on the m_flags field
679 */
680 mp->m_flags &= ~(XFS_MOUNT_32BITINODES |
681 XFS_MOUNT_SMALL_INUMS);
682 return index;
683}
684
3180e66d 685STATIC int
1da177e4
LT
686xfs_blkdev_get(
687 xfs_mount_t *mp,
688 const char *name,
689 struct block_device **bdevp)
690{
691 int error = 0;
692
d4d77629
TH
693 *bdevp = blkdev_get_by_path(name, FMODE_READ|FMODE_WRITE|FMODE_EXCL,
694 mp);
1da177e4
LT
695 if (IS_ERR(*bdevp)) {
696 error = PTR_ERR(*bdevp);
4f10700a 697 xfs_warn(mp, "Invalid device [%s], error=%d\n", name, error);
1da177e4
LT
698 }
699
700 return -error;
701}
702
3180e66d 703STATIC void
1da177e4
LT
704xfs_blkdev_put(
705 struct block_device *bdev)
706{
707 if (bdev)
e525fd89 708 blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
1da177e4
LT
709}
710
f538d4da
CH
711void
712xfs_blkdev_issue_flush(
713 xfs_buftarg_t *buftarg)
714{
7582df51 715 blkdev_issue_flush(buftarg->bt_bdev, GFP_NOFS, NULL);
f538d4da 716}
1da177e4 717
19f354d4
CH
718STATIC void
719xfs_close_devices(
720 struct xfs_mount *mp)
721{
722 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
c032bfcf 723 struct block_device *logdev = mp->m_logdev_targp->bt_bdev;
b7963133 724 xfs_free_buftarg(mp, mp->m_logdev_targp);
c032bfcf 725 xfs_blkdev_put(logdev);
19f354d4
CH
726 }
727 if (mp->m_rtdev_targp) {
c032bfcf 728 struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev;
b7963133 729 xfs_free_buftarg(mp, mp->m_rtdev_targp);
c032bfcf 730 xfs_blkdev_put(rtdev);
19f354d4 731 }
b7963133 732 xfs_free_buftarg(mp, mp->m_ddev_targp);
19f354d4
CH
733}
734
735/*
736 * The file system configurations are:
737 * (1) device (partition) with data and internal log
738 * (2) logical volume with data and log subvolumes.
739 * (3) logical volume with data, log, and realtime subvolumes.
740 *
741 * We only have to handle opening the log and realtime volumes here if
742 * they are present. The data subvolume has already been opened by
743 * get_sb_bdev() and is stored in sb->s_bdev.
744 */
745STATIC int
746xfs_open_devices(
9d565ffa 747 struct xfs_mount *mp)
19f354d4
CH
748{
749 struct block_device *ddev = mp->m_super->s_bdev;
750 struct block_device *logdev = NULL, *rtdev = NULL;
751 int error;
752
753 /*
754 * Open real time and log devices - order is important.
755 */
9d565ffa
CH
756 if (mp->m_logname) {
757 error = xfs_blkdev_get(mp, mp->m_logname, &logdev);
19f354d4
CH
758 if (error)
759 goto out;
760 }
761
9d565ffa
CH
762 if (mp->m_rtname) {
763 error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev);
19f354d4
CH
764 if (error)
765 goto out_close_logdev;
766
767 if (rtdev == ddev || rtdev == logdev) {
4f10700a
DC
768 xfs_warn(mp,
769 "Cannot mount filesystem with identical rtdev and ddev/logdev.");
19f354d4
CH
770 error = EINVAL;
771 goto out_close_rtdev;
772 }
773 }
774
775 /*
776 * Setup xfs_mount buffer target pointers
777 */
778 error = ENOMEM;
ebad861b 779 mp->m_ddev_targp = xfs_alloc_buftarg(mp, ddev, 0, mp->m_fsname);
19f354d4
CH
780 if (!mp->m_ddev_targp)
781 goto out_close_rtdev;
782
783 if (rtdev) {
ebad861b
DC
784 mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev, 1,
785 mp->m_fsname);
19f354d4
CH
786 if (!mp->m_rtdev_targp)
787 goto out_free_ddev_targ;
788 }
789
790 if (logdev && logdev != ddev) {
ebad861b
DC
791 mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev, 1,
792 mp->m_fsname);
19f354d4
CH
793 if (!mp->m_logdev_targp)
794 goto out_free_rtdev_targ;
795 } else {
796 mp->m_logdev_targp = mp->m_ddev_targp;
797 }
798
799 return 0;
800
801 out_free_rtdev_targ:
802 if (mp->m_rtdev_targp)
b7963133 803 xfs_free_buftarg(mp, mp->m_rtdev_targp);
19f354d4 804 out_free_ddev_targ:
b7963133 805 xfs_free_buftarg(mp, mp->m_ddev_targp);
19f354d4
CH
806 out_close_rtdev:
807 if (rtdev)
808 xfs_blkdev_put(rtdev);
809 out_close_logdev:
810 if (logdev && logdev != ddev)
811 xfs_blkdev_put(logdev);
812 out:
813 return error;
814}
815
e34b562c
CH
816/*
817 * Setup xfs_mount buffer target pointers based on superblock
818 */
819STATIC int
820xfs_setup_devices(
821 struct xfs_mount *mp)
822{
823 int error;
19f354d4 824
e34b562c
CH
825 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
826 mp->m_sb.sb_sectsize);
827 if (error)
828 return error;
829
830 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
831 unsigned int log_sector_size = BBSIZE;
832
833 if (xfs_sb_version_hassector(&mp->m_sb))
834 log_sector_size = mp->m_sb.sb_logsectsize;
835 error = xfs_setsize_buftarg(mp->m_logdev_targp,
836 mp->m_sb.sb_blocksize,
837 log_sector_size);
838 if (error)
839 return error;
840 }
841 if (mp->m_rtdev_targp) {
842 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
843 mp->m_sb.sb_blocksize,
844 mp->m_sb.sb_sectsize);
845 if (error)
846 return error;
847 }
848
849 return 0;
850}
19f354d4 851
aa6bf01d
CH
852STATIC int
853xfs_init_mount_workqueues(
854 struct xfs_mount *mp)
855{
856 mp->m_data_workqueue = alloc_workqueue("xfs-data/%s",
857 WQ_MEM_RECLAIM, 0, mp->m_fsname);
858 if (!mp->m_data_workqueue)
859 goto out;
860
861 mp->m_unwritten_workqueue = alloc_workqueue("xfs-conv/%s",
862 WQ_MEM_RECLAIM, 0, mp->m_fsname);
863 if (!mp->m_unwritten_workqueue)
864 goto out_destroy_data_iodone_queue;
865
4c2d542f
DC
866 mp->m_cil_workqueue = alloc_workqueue("xfs-cil/%s",
867 WQ_MEM_RECLAIM, 0, mp->m_fsname);
868 if (!mp->m_cil_workqueue)
869 goto out_destroy_unwritten;
5889608d
DC
870
871 mp->m_reclaim_workqueue = alloc_workqueue("xfs-reclaim/%s",
872 WQ_NON_REENTRANT, 0, mp->m_fsname);
873 if (!mp->m_reclaim_workqueue)
874 goto out_destroy_cil;
875
876 mp->m_log_workqueue = alloc_workqueue("xfs-log/%s",
877 WQ_NON_REENTRANT, 0, mp->m_fsname);
878 if (!mp->m_log_workqueue)
879 goto out_destroy_reclaim;
880
579b62fa
BF
881 mp->m_eofblocks_workqueue = alloc_workqueue("xfs-eofblocks/%s",
882 WQ_NON_REENTRANT, 0, mp->m_fsname);
883 if (!mp->m_eofblocks_workqueue)
884 goto out_destroy_log;
885
aa6bf01d
CH
886 return 0;
887
579b62fa
BF
888out_destroy_log:
889 destroy_workqueue(mp->m_log_workqueue);
5889608d
DC
890out_destroy_reclaim:
891 destroy_workqueue(mp->m_reclaim_workqueue);
892out_destroy_cil:
893 destroy_workqueue(mp->m_cil_workqueue);
4c2d542f
DC
894out_destroy_unwritten:
895 destroy_workqueue(mp->m_unwritten_workqueue);
aa6bf01d
CH
896out_destroy_data_iodone_queue:
897 destroy_workqueue(mp->m_data_workqueue);
898out:
899 return -ENOMEM;
900}
901
902STATIC void
903xfs_destroy_mount_workqueues(
904 struct xfs_mount *mp)
905{
579b62fa 906 destroy_workqueue(mp->m_eofblocks_workqueue);
5889608d
DC
907 destroy_workqueue(mp->m_log_workqueue);
908 destroy_workqueue(mp->m_reclaim_workqueue);
4c2d542f 909 destroy_workqueue(mp->m_cil_workqueue);
aa6bf01d
CH
910 destroy_workqueue(mp->m_data_workqueue);
911 destroy_workqueue(mp->m_unwritten_workqueue);
912}
913
9aa05000
DC
914/*
915 * Flush all dirty data to disk. Must not be called while holding an XFS_ILOCK
916 * or a page lock. We use sync_inodes_sb() here to ensure we block while waiting
917 * for IO to complete so that we effectively throttle multiple callers to the
918 * rate at which IO is completing.
919 */
920void
921xfs_flush_inodes(
922 struct xfs_mount *mp)
923{
924 struct super_block *sb = mp->m_super;
925
926 if (down_read_trylock(&sb->s_umount)) {
927 sync_inodes_sb(sb);
928 up_read(&sb->s_umount);
929 }
930}
931
bf904248 932/* Catch misguided souls that try to use this interface on XFS */
1da177e4 933STATIC struct inode *
a50cd269 934xfs_fs_alloc_inode(
1da177e4
LT
935 struct super_block *sb)
936{
bf904248 937 BUG();
493dca61 938 return NULL;
1da177e4
LT
939}
940
bf904248 941/*
99fa8cb3
DC
942 * Now that the generic code is guaranteed not to be accessing
943 * the linux inode, we can reclaim the inode.
bf904248 944 */
1da177e4 945STATIC void
a50cd269 946xfs_fs_destroy_inode(
848ce8f7 947 struct inode *inode)
1da177e4 948{
848ce8f7
CH
949 struct xfs_inode *ip = XFS_I(inode);
950
cca28fb8 951 trace_xfs_destroy_inode(ip);
99fa8cb3
DC
952
953 XFS_STATS_INC(vn_reclaim);
848ce8f7
CH
954
955 /* bad inode, get out here ASAP */
956 if (is_bad_inode(inode))
957 goto out_reclaim;
958
848ce8f7
CH
959 ASSERT(XFS_FORCED_SHUTDOWN(ip->i_mount) || ip->i_delayed_blks == 0);
960
961 /*
962 * We should never get here with one of the reclaim flags already set.
963 */
964 ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIMABLE));
965 ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIM));
966
967 /*
57817c68
DC
968 * We always use background reclaim here because even if the
969 * inode is clean, it still may be under IO and hence we have
970 * to take the flush lock. The background reclaim path handles
971 * this more efficiently than we can here, so simply let background
972 * reclaim tear down all inodes.
848ce8f7 973 */
848ce8f7 974out_reclaim:
57817c68 975 xfs_inode_set_reclaim_tag(ip);
1da177e4
LT
976}
977
07c8f675
DC
978/*
979 * Slab object creation initialisation for the XFS inode.
980 * This covers only the idempotent fields in the XFS inode;
981 * all other fields need to be initialised on allocation
b595076a 982 * from the slab. This avoids the need to repeatedly initialise
07c8f675
DC
983 * fields in the xfs inode that left in the initialise state
984 * when freeing the inode.
985 */
bf904248
DC
986STATIC void
987xfs_fs_inode_init_once(
07c8f675
DC
988 void *inode)
989{
990 struct xfs_inode *ip = inode;
991
992 memset(ip, 0, sizeof(struct xfs_inode));
bf904248
DC
993
994 /* vfs inode */
995 inode_init_once(VFS_I(ip));
996
997 /* xfs inode */
07c8f675
DC
998 atomic_set(&ip->i_pincount, 0);
999 spin_lock_init(&ip->i_flags_lock);
07c8f675
DC
1000
1001 mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
1002 "xfsino", ip->i_ino);
07c8f675
DC
1003}
1004
1da177e4 1005STATIC void
b57922d9 1006xfs_fs_evict_inode(
1da177e4
LT
1007 struct inode *inode)
1008{
1543d79c 1009 xfs_inode_t *ip = XFS_I(inode);
56d433e4 1010
4f59af75
CH
1011 ASSERT(!rwsem_is_locked(&ip->i_iolock.mr_lock));
1012
b57922d9 1013 trace_xfs_evict_inode(ip);
cca28fb8 1014
b57922d9 1015 truncate_inode_pages(&inode->i_data, 0);
dbd5768f 1016 clear_inode(inode);
99fa8cb3
DC
1017 XFS_STATS_INC(vn_rele);
1018 XFS_STATS_INC(vn_remove);
1019 XFS_STATS_DEC(vn_active);
1020
1021 xfs_inactive(ip);
56d433e4 1022}
1da177e4 1023
5132ba8f
DC
1024/*
1025 * We do an unlocked check for XFS_IDONTCACHE here because we are already
1026 * serialised against cache hits here via the inode->i_lock and igrab() in
1027 * xfs_iget_cache_hit(). Hence a lookup that might clear this flag will not be
1028 * racing with us, and it avoids needing to grab a spinlock here for every inode
1029 * we drop the final reference on.
1030 */
1031STATIC int
1032xfs_fs_drop_inode(
1033 struct inode *inode)
1034{
1035 struct xfs_inode *ip = XFS_I(inode);
1036
1037 return generic_drop_inode(inode) || (ip->i_flags & XFS_IDONTCACHE);
1038}
1039
a738159d
CH
1040STATIC void
1041xfs_free_fsname(
1042 struct xfs_mount *mp)
1043{
1044 kfree(mp->m_fsname);
1045 kfree(mp->m_rtname);
1046 kfree(mp->m_logname);
1047}
1048
1da177e4 1049STATIC void
a50cd269 1050xfs_fs_put_super(
1da177e4
LT
1051 struct super_block *sb)
1052{
745f6919 1053 struct xfs_mount *mp = XFS_M(sb);
1da177e4 1054
7e18530b
DC
1055 xfs_filestream_unmount(mp);
1056 xfs_unmountfs(mp);
1057
6203300e 1058 xfs_freesb(mp);
c962fb79 1059 xfs_icsb_destroy_counters(mp);
aa6bf01d 1060 xfs_destroy_mount_workqueues(mp);
19f354d4 1061 xfs_close_devices(mp);
a738159d 1062 xfs_free_fsname(mp);
c962fb79 1063 kfree(mp);
1da177e4
LT
1064}
1065
1da177e4 1066STATIC int
69961a26 1067xfs_fs_sync_fs(
1da177e4
LT
1068 struct super_block *sb,
1069 int wait)
1070{
745f6919 1071 struct xfs_mount *mp = XFS_M(sb);
1da177e4 1072
e893bffd 1073 /*
34625c66 1074 * Doing anything during the async pass would be counterproductive.
e893bffd 1075 */
34625c66 1076 if (!wait)
69961a26 1077 return 0;
69961a26 1078
34061f5c 1079 xfs_log_force(mp, XFS_LOG_SYNC);
69961a26 1080 if (laptop_mode) {
1da177e4
LT
1081 /*
1082 * The disk must be active because we're syncing.
f661f1e0 1083 * We schedule log work now (now that the disk is
1da177e4
LT
1084 * active) instead of later (when it might not be).
1085 */
f661f1e0 1086 flush_delayed_work(&mp->m_log->l_work);
1da177e4
LT
1087 }
1088
69961a26 1089 return 0;
1da177e4
LT
1090}
1091
1092STATIC int
a50cd269 1093xfs_fs_statfs(
726c3342 1094 struct dentry *dentry,
1da177e4
LT
1095 struct kstatfs *statp)
1096{
4ca488eb
CH
1097 struct xfs_mount *mp = XFS_M(dentry->d_sb);
1098 xfs_sb_t *sbp = &mp->m_sb;
7d095257 1099 struct xfs_inode *ip = XFS_I(dentry->d_inode);
4ca488eb
CH
1100 __uint64_t fakeinos, id;
1101 xfs_extlen_t lsize;
2fe33661 1102 __int64_t ffree;
4ca488eb
CH
1103
1104 statp->f_type = XFS_SB_MAGIC;
1105 statp->f_namelen = MAXNAMELEN - 1;
1106
1107 id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
1108 statp->f_fsid.val[0] = (u32)id;
1109 statp->f_fsid.val[1] = (u32)(id >> 32);
1110
d4d90b57 1111 xfs_icsb_sync_counters(mp, XFS_ICSB_LAZY_COUNT);
4ca488eb
CH
1112
1113 spin_lock(&mp->m_sb_lock);
1114 statp->f_bsize = sbp->sb_blocksize;
1115 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
1116 statp->f_blocks = sbp->sb_dblocks - lsize;
1117 statp->f_bfree = statp->f_bavail =
1118 sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
1119 fakeinos = statp->f_bfree << sbp->sb_inopblog;
4ca488eb
CH
1120 statp->f_files =
1121 MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
1122 if (mp->m_maxicount)
a19d9f88
CH
1123 statp->f_files = min_t(typeof(statp->f_files),
1124 statp->f_files,
1125 mp->m_maxicount);
2fe33661
SB
1126
1127 /* make sure statp->f_ffree does not underflow */
1128 ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
1129 statp->f_ffree = max_t(__int64_t, ffree, 0);
1130
4ca488eb
CH
1131 spin_unlock(&mp->m_sb_lock);
1132
da5bf95e 1133 if ((ip->i_d.di_flags & XFS_DIFLAG_PROJINHERIT) &&
7d095257
CH
1134 ((mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_OQUOTA_ENFD))) ==
1135 (XFS_PQUOTA_ACCT|XFS_OQUOTA_ENFD))
1136 xfs_qm_statvfs(ip, statp);
4ca488eb 1137 return 0;
1da177e4
LT
1138}
1139
d5db0f97
ES
1140STATIC void
1141xfs_save_resvblks(struct xfs_mount *mp)
1142{
1143 __uint64_t resblks = 0;
1144
1145 mp->m_resblks_save = mp->m_resblks;
1146 xfs_reserve_blocks(mp, &resblks, NULL);
1147}
1148
1149STATIC void
1150xfs_restore_resvblks(struct xfs_mount *mp)
1151{
1152 __uint64_t resblks;
1153
1154 if (mp->m_resblks_save) {
1155 resblks = mp->m_resblks_save;
1156 mp->m_resblks_save = 0;
1157 } else
1158 resblks = xfs_default_resblks(mp);
1159
1160 xfs_reserve_blocks(mp, &resblks, NULL);
1161}
1162
c7eea6f7
DC
1163/*
1164 * Trigger writeback of all the dirty metadata in the file system.
1165 *
1166 * This ensures that the metadata is written to their location on disk rather
1167 * than just existing in transactions in the log. This means after a quiesce
c75921a7
DC
1168 * there is no log replay required to write the inodes to disk - this is the
1169 * primary difference between a sync and a quiesce.
c7eea6f7 1170 *
c75921a7
DC
1171 * Note: xfs_log_quiesce() stops background log work - the callers must ensure
1172 * it is started again when appropriate.
c7eea6f7
DC
1173 */
1174void
1175xfs_quiesce_attr(
1176 struct xfs_mount *mp)
1177{
1178 int error = 0;
1179
1180 /* wait for all modifications to complete */
1181 while (atomic_read(&mp->m_active_trans) > 0)
1182 delay(100);
1183
1184 /* force the log to unpin objects from the now complete transactions */
1185 xfs_log_force(mp, XFS_LOG_SYNC);
1186
1187 /* reclaim inodes to do any IO before the freeze completes */
1188 xfs_reclaim_inodes(mp, 0);
1189 xfs_reclaim_inodes(mp, SYNC_WAIT);
1190
c7eea6f7
DC
1191 /* Push the superblock and write an unmount record */
1192 error = xfs_log_sbcount(mp);
1193 if (error)
1194 xfs_warn(mp, "xfs_attr_quiesce: failed to log sb changes. "
1195 "Frozen image may not be consistent.");
c7eea6f7 1196 /*
c75921a7
DC
1197 * Just warn here till VFS can correctly support
1198 * read-only remount without racing.
c7eea6f7 1199 */
c75921a7 1200 WARN_ON(atomic_read(&mp->m_active_trans) != 0);
c7eea6f7 1201
c75921a7 1202 xfs_log_quiesce(mp);
c7eea6f7
DC
1203}
1204
1da177e4 1205STATIC int
a50cd269 1206xfs_fs_remount(
1da177e4
LT
1207 struct super_block *sb,
1208 int *flags,
1209 char *options)
1210{
745f6919 1211 struct xfs_mount *mp = XFS_M(sb);
62a877e3
CH
1212 substring_t args[MAX_OPT_ARGS];
1213 char *p;
7884bc86 1214 int error;
1da177e4 1215
62a877e3
CH
1216 while ((p = strsep(&options, ",")) != NULL) {
1217 int token;
bdd907ba 1218
62a877e3
CH
1219 if (!*p)
1220 continue;
48b62a1a 1221
62a877e3
CH
1222 token = match_token(p, tokens, args);
1223 switch (token) {
1224 case Opt_barrier:
48b62a1a 1225 mp->m_flags |= XFS_MOUNT_BARRIER;
62a877e3
CH
1226 break;
1227 case Opt_nobarrier:
48b62a1a 1228 mp->m_flags &= ~XFS_MOUNT_BARRIER;
62a877e3 1229 break;
c3a58fec 1230 case Opt_inode64:
4c083722 1231 mp->m_maxagi = xfs_set_inode64(mp);
c3a58fec 1232 break;
2ea03929
CM
1233 case Opt_inode32:
1234 mp->m_maxagi = xfs_set_inode32(mp);
1235 break;
62a877e3 1236 default:
6efdf281
CH
1237 /*
1238 * Logically we would return an error here to prevent
1239 * users from believing they might have changed
1240 * mount options using remount which can't be changed.
1241 *
1242 * But unfortunately mount(8) adds all options from
1243 * mtab and fstab to the mount arguments in some cases
1244 * so we can't blindly reject options, but have to
1245 * check for each specified option if it actually
1246 * differs from the currently set option and only
1247 * reject it if that's the case.
1248 *
1249 * Until that is implemented we return success for
1250 * every remount request, and silently ignore all
1251 * options that we can't actually change.
1252 */
1253#if 0
4f10700a
DC
1254 xfs_info(mp,
1255 "mount option \"%s\" not supported for remount\n", p);
62a877e3 1256 return -EINVAL;
6efdf281 1257#else
6c5e51da 1258 break;
6efdf281 1259#endif
48b62a1a 1260 }
62a877e3
CH
1261 }
1262
7884bc86 1263 /* ro -> rw */
62a877e3
CH
1264 if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(*flags & MS_RDONLY)) {
1265 mp->m_flags &= ~XFS_MOUNT_RDONLY;
7884bc86
CH
1266
1267 /*
1268 * If this is the first remount to writeable state we
1269 * might have some superblock changes to update.
1270 */
1271 if (mp->m_update_flags) {
1272 error = xfs_mount_log_sb(mp, mp->m_update_flags);
1273 if (error) {
4f10700a 1274 xfs_warn(mp, "failed to write sb changes");
7884bc86
CH
1275 return error;
1276 }
1277 mp->m_update_flags = 0;
1278 }
cbe132a8
DC
1279
1280 /*
1281 * Fill out the reserve pool if it is empty. Use the stashed
1282 * value if it is non-zero, otherwise go with the default.
1283 */
d5db0f97 1284 xfs_restore_resvblks(mp);
f661f1e0 1285 xfs_log_work_queue(mp);
62a877e3
CH
1286 }
1287
1288 /* rw -> ro */
1289 if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (*flags & MS_RDONLY)) {
cbe132a8 1290 /*
34061f5c
DC
1291 * Before we sync the metadata, we need to free up the reserve
1292 * block pool so that the used block count in the superblock on
1293 * disk is correct at the end of the remount. Stash the current
1294 * reserve pool size so that if we get remounted rw, we can
1295 * return it to the same size.
cbe132a8 1296 */
d5db0f97 1297 xfs_save_resvblks(mp);
76bf105c 1298 xfs_quiesce_attr(mp);
48b62a1a
CH
1299 mp->m_flags |= XFS_MOUNT_RDONLY;
1300 }
1301
62a877e3 1302 return 0;
1da177e4
LT
1303}
1304
9909c4aa
CH
1305/*
1306 * Second stage of a freeze. The data is already frozen so we only
76bf105c 1307 * need to take care of the metadata. Once that's done write a dummy
9909c4aa
CH
1308 * record to dirty the log in case of a crash while frozen.
1309 */
c4be0c1d
TS
1310STATIC int
1311xfs_fs_freeze(
1da177e4
LT
1312 struct super_block *sb)
1313{
9909c4aa
CH
1314 struct xfs_mount *mp = XFS_M(sb);
1315
d5db0f97 1316 xfs_save_resvblks(mp);
76bf105c 1317 xfs_quiesce_attr(mp);
c58efdb4 1318 return -xfs_fs_log_dummy(mp);
1da177e4
LT
1319}
1320
d5db0f97
ES
1321STATIC int
1322xfs_fs_unfreeze(
1323 struct super_block *sb)
1324{
1325 struct xfs_mount *mp = XFS_M(sb);
1326
1327 xfs_restore_resvblks(mp);
f661f1e0 1328 xfs_log_work_queue(mp);
d5db0f97
ES
1329 return 0;
1330}
1331
1da177e4 1332STATIC int
a50cd269 1333xfs_fs_show_options(
1da177e4 1334 struct seq_file *m,
34c80b1d 1335 struct dentry *root)
1da177e4 1336{
34c80b1d 1337 return -xfs_showargs(XFS_M(root->d_sb), m);
1da177e4
LT
1338}
1339
f8f15e42
CH
1340/*
1341 * This function fills in xfs_mount_t fields based on mount args.
1342 * Note: the superblock _has_ now been read in.
1343 */
1344STATIC int
1345xfs_finish_flags(
f8f15e42
CH
1346 struct xfs_mount *mp)
1347{
1348 int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
1349
025dfdaf 1350 /* Fail a mount where the logbuf is smaller than the log stripe */
f8f15e42 1351 if (xfs_sb_version_haslogv2(&mp->m_sb)) {
9d565ffa
CH
1352 if (mp->m_logbsize <= 0 &&
1353 mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE) {
f8f15e42 1354 mp->m_logbsize = mp->m_sb.sb_logsunit;
9d565ffa
CH
1355 } else if (mp->m_logbsize > 0 &&
1356 mp->m_logbsize < mp->m_sb.sb_logsunit) {
4f10700a
DC
1357 xfs_warn(mp,
1358 "logbuf size must be greater than or equal to log stripe size");
f8f15e42
CH
1359 return XFS_ERROR(EINVAL);
1360 }
1361 } else {
1362 /* Fail a mount if the logbuf is larger than 32K */
9d565ffa 1363 if (mp->m_logbsize > XLOG_BIG_RECORD_BSIZE) {
4f10700a
DC
1364 xfs_warn(mp,
1365 "logbuf size for version 1 logs must be 16K or 32K");
f8f15e42
CH
1366 return XFS_ERROR(EINVAL);
1367 }
1368 }
1369
d3eaace8
DC
1370 /*
1371 * V5 filesystems always use attr2 format for attributes.
1372 */
1373 if (xfs_sb_version_hascrc(&mp->m_sb) &&
1374 (mp->m_flags & XFS_MOUNT_NOATTR2)) {
1375 xfs_warn(mp,
1376"Cannot mount a V5 filesystem as %s. %s is always enabled for V5 filesystems.",
1377 MNTOPT_NOATTR2, MNTOPT_ATTR2);
1378 return XFS_ERROR(EINVAL);
1379 }
1380
f8f15e42
CH
1381 /*
1382 * mkfs'ed attr2 will turn on attr2 mount unless explicitly
1383 * told by noattr2 to turn it off
1384 */
1385 if (xfs_sb_version_hasattr2(&mp->m_sb) &&
9d565ffa 1386 !(mp->m_flags & XFS_MOUNT_NOATTR2))
f8f15e42
CH
1387 mp->m_flags |= XFS_MOUNT_ATTR2;
1388
1389 /*
1390 * prohibit r/w mounts of read-only filesystems
1391 */
1392 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
4f10700a
DC
1393 xfs_warn(mp,
1394 "cannot mount a read-only filesystem as read-write");
f8f15e42
CH
1395 return XFS_ERROR(EROFS);
1396 }
1397
f8f15e42
CH
1398 return 0;
1399}
1400
1da177e4 1401STATIC int
a50cd269 1402xfs_fs_fill_super(
1da177e4
LT
1403 struct super_block *sb,
1404 void *data,
1405 int silent)
1406{
f3dcc13f 1407 struct inode *root;
745f6919 1408 struct xfs_mount *mp = NULL;
c962fb79 1409 int flags = 0, error = ENOMEM;
bdd907ba 1410
c962fb79
CH
1411 mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
1412 if (!mp)
9d565ffa 1413 goto out;
1da177e4 1414
c962fb79 1415 spin_lock_init(&mp->m_sb_lock);
c962fb79
CH
1416 mutex_init(&mp->m_growlock);
1417 atomic_set(&mp->m_active_trans, 0);
7e18530b 1418 INIT_DELAYED_WORK(&mp->m_reclaim_work, xfs_reclaim_worker);
579b62fa 1419 INIT_DELAYED_WORK(&mp->m_eofblocks_work, xfs_eofblocks_worker);
74394496 1420
b267ce99
CH
1421 mp->m_super = sb;
1422 sb->s_fs_info = mp;
1da177e4 1423
288699fe 1424 error = xfs_parseargs(mp, (char *)data);
745f6919 1425 if (error)
9d565ffa 1426 goto out_free_fsname;
1da177e4
LT
1427
1428 sb_min_blocksize(sb, BBSIZE);
0ec58516 1429 sb->s_xattr = xfs_xattr_handlers;
a50cd269 1430 sb->s_export_op = &xfs_export_operations;
fcafb71b 1431#ifdef CONFIG_XFS_QUOTA
a50cd269 1432 sb->s_qcop = &xfs_quotactl_operations;
fcafb71b 1433#endif
a50cd269 1434 sb->s_op = &xfs_super_operations;
1da177e4 1435
9d565ffa 1436 if (silent)
f8f15e42
CH
1437 flags |= XFS_MFSI_QUIET;
1438
9d565ffa 1439 error = xfs_open_devices(mp);
19f354d4 1440 if (error)
288699fe 1441 goto out_free_fsname;
f8f15e42 1442
aa6bf01d 1443 error = xfs_init_mount_workqueues(mp);
61ba35de
CH
1444 if (error)
1445 goto out_close_devices;
c962fb79 1446
aa6bf01d
CH
1447 error = xfs_icsb_init_counters(mp);
1448 if (error)
1449 goto out_destroy_workqueues;
1450
f8f15e42
CH
1451 error = xfs_readsb(mp, flags);
1452 if (error)
9d565ffa
CH
1453 goto out_destroy_counters;
1454
1455 error = xfs_finish_flags(mp);
f8f15e42 1456 if (error)
effa2eda 1457 goto out_free_sb;
f8f15e42 1458
e34b562c 1459 error = xfs_setup_devices(mp);
19f354d4 1460 if (error)
effa2eda 1461 goto out_free_sb;
f8f15e42 1462
f8f15e42
CH
1463 error = xfs_filestream_mount(mp);
1464 if (error)
effa2eda 1465 goto out_free_sb;
f8f15e42 1466
704b2907
DC
1467 /*
1468 * we must configure the block size in the superblock before we run the
1469 * full mount process as the mount process can lookup and cache inodes.
704b2907 1470 */
4ca488eb
CH
1471 sb->s_magic = XFS_SB_MAGIC;
1472 sb->s_blocksize = mp->m_sb.sb_blocksize;
1473 sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
1da177e4 1474 sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
8de52778 1475 sb->s_max_links = XFS_MAXLINK;
1da177e4
LT
1476 sb->s_time_gran = 1;
1477 set_posix_acl_flag(sb);
1478
8a00ebe4 1479 error = xfs_mountfs(mp);
2bcf6e97 1480 if (error)
7e18530b 1481 goto out_filestream_unmount;
704b2907 1482
01651646 1483 root = igrab(VFS_I(mp->m_rootip));
f3dcc13f 1484 if (!root) {
cbc89dcf 1485 error = ENOENT;
8a00ebe4 1486 goto out_unmount;
cbc89dcf 1487 }
f3dcc13f
CH
1488 if (is_bad_inode(root)) {
1489 error = EINVAL;
8a00ebe4 1490 goto out_unmount;
1da177e4 1491 }
48fde701 1492 sb->s_root = d_make_root(root);
f3dcc13f
CH
1493 if (!sb->s_root) {
1494 error = ENOMEM;
8a00ebe4 1495 goto out_unmount;
1da177e4 1496 }
74394496 1497
1da177e4 1498 return 0;
33c7a2bc 1499
7e18530b 1500 out_filestream_unmount:
120226c1 1501 xfs_filestream_unmount(mp);
effa2eda
CH
1502 out_free_sb:
1503 xfs_freesb(mp);
9d565ffa 1504 out_destroy_counters:
c962fb79 1505 xfs_icsb_destroy_counters(mp);
aa6bf01d
CH
1506out_destroy_workqueues:
1507 xfs_destroy_mount_workqueues(mp);
61ba35de 1508 out_close_devices:
19f354d4 1509 xfs_close_devices(mp);
9d565ffa
CH
1510 out_free_fsname:
1511 xfs_free_fsname(mp);
c962fb79 1512 kfree(mp);
9d565ffa 1513 out:
c962fb79 1514 return -error;
f8f15e42 1515
2bcf6e97 1516 out_unmount:
e48ad316 1517 xfs_filestream_unmount(mp);
19f354d4 1518 xfs_unmountfs(mp);
6203300e 1519 goto out_free_sb;
1da177e4
LT
1520}
1521
152a0836
AV
1522STATIC struct dentry *
1523xfs_fs_mount(
1da177e4
LT
1524 struct file_system_type *fs_type,
1525 int flags,
1526 const char *dev_name,
152a0836 1527 void *data)
1da177e4 1528{
152a0836 1529 return mount_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super);
a50cd269
NS
1530}
1531
8daaa831
DC
1532static int
1533xfs_fs_nr_cached_objects(
1534 struct super_block *sb)
1535{
1536 return xfs_reclaim_inodes_count(XFS_M(sb));
1537}
1538
1539static void
1540xfs_fs_free_cached_objects(
1541 struct super_block *sb,
1542 int nr_to_scan)
1543{
1544 xfs_reclaim_inodes_nr(XFS_M(sb), nr_to_scan);
1545}
1546
b87221de 1547static const struct super_operations xfs_super_operations = {
a50cd269
NS
1548 .alloc_inode = xfs_fs_alloc_inode,
1549 .destroy_inode = xfs_fs_destroy_inode,
b57922d9 1550 .evict_inode = xfs_fs_evict_inode,
5132ba8f 1551 .drop_inode = xfs_fs_drop_inode,
a50cd269 1552 .put_super = xfs_fs_put_super,
69961a26 1553 .sync_fs = xfs_fs_sync_fs,
c4be0c1d 1554 .freeze_fs = xfs_fs_freeze,
d5db0f97 1555 .unfreeze_fs = xfs_fs_unfreeze,
a50cd269
NS
1556 .statfs = xfs_fs_statfs,
1557 .remount_fs = xfs_fs_remount,
1558 .show_options = xfs_fs_show_options,
8daaa831
DC
1559 .nr_cached_objects = xfs_fs_nr_cached_objects,
1560 .free_cached_objects = xfs_fs_free_cached_objects,
1da177e4
LT
1561};
1562
5085b607 1563static struct file_system_type xfs_fs_type = {
1da177e4
LT
1564 .owner = THIS_MODULE,
1565 .name = "xfs",
152a0836 1566 .mount = xfs_fs_mount,
1da177e4
LT
1567 .kill_sb = kill_block_super,
1568 .fs_flags = FS_REQUIRES_DEV,
1569};
7f78e035 1570MODULE_ALIAS_FS("xfs");
1da177e4 1571
9f8868ff
CH
1572STATIC int __init
1573xfs_init_zones(void)
1574{
9f8868ff
CH
1575
1576 xfs_ioend_zone = kmem_zone_init(sizeof(xfs_ioend_t), "xfs_ioend");
1577 if (!xfs_ioend_zone)
bf904248 1578 goto out;
9f8868ff
CH
1579
1580 xfs_ioend_pool = mempool_create_slab_pool(4 * MAX_BUF_PER_PAGE,
1581 xfs_ioend_zone);
1582 if (!xfs_ioend_pool)
1583 goto out_destroy_ioend_zone;
1584
1585 xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t),
1586 "xfs_log_ticket");
1587 if (!xfs_log_ticket_zone)
1588 goto out_destroy_ioend_pool;
1589
1590 xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
1591 "xfs_bmap_free_item");
1592 if (!xfs_bmap_free_item_zone)
1593 goto out_destroy_log_ticket_zone;
bf904248 1594
9f8868ff
CH
1595 xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
1596 "xfs_btree_cur");
1597 if (!xfs_btree_cur_zone)
1598 goto out_destroy_bmap_free_item_zone;
1599
1600 xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t),
1601 "xfs_da_state");
1602 if (!xfs_da_state_zone)
1603 goto out_destroy_btree_cur_zone;
1604
9f8868ff
CH
1605 xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
1606 if (!xfs_ifork_zone)
1d9025e5 1607 goto out_destroy_da_state_zone;
9f8868ff
CH
1608
1609 xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
1610 if (!xfs_trans_zone)
1611 goto out_destroy_ifork_zone;
1612
e98c414f
CH
1613 xfs_log_item_desc_zone =
1614 kmem_zone_init(sizeof(struct xfs_log_item_desc),
1615 "xfs_log_item_desc");
1616 if (!xfs_log_item_desc_zone)
1617 goto out_destroy_trans_zone;
1618
9f8868ff
CH
1619 /*
1620 * The size of the zone allocated buf log item is the maximum
1621 * size possible under XFS. This wastes a little bit of memory,
1622 * but it is much faster.
1623 */
77c1a08f
DC
1624 xfs_buf_item_zone = kmem_zone_init(sizeof(struct xfs_buf_log_item),
1625 "xfs_buf_item");
9f8868ff 1626 if (!xfs_buf_item_zone)
e98c414f 1627 goto out_destroy_log_item_desc_zone;
9f8868ff
CH
1628
1629 xfs_efd_zone = kmem_zone_init((sizeof(xfs_efd_log_item_t) +
1630 ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
1631 sizeof(xfs_extent_t))), "xfs_efd_item");
1632 if (!xfs_efd_zone)
1633 goto out_destroy_buf_item_zone;
1634
1635 xfs_efi_zone = kmem_zone_init((sizeof(xfs_efi_log_item_t) +
1636 ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
1637 sizeof(xfs_extent_t))), "xfs_efi_item");
1638 if (!xfs_efi_zone)
1639 goto out_destroy_efd_zone;
1640
1641 xfs_inode_zone =
1642 kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
bf904248
DC
1643 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM | KM_ZONE_SPREAD,
1644 xfs_fs_inode_init_once);
9f8868ff
CH
1645 if (!xfs_inode_zone)
1646 goto out_destroy_efi_zone;
1647
1648 xfs_ili_zone =
1649 kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
1650 KM_ZONE_SPREAD, NULL);
1651 if (!xfs_ili_zone)
1652 goto out_destroy_inode_zone;
1653
9f8868ff
CH
1654 return 0;
1655
9f8868ff
CH
1656 out_destroy_inode_zone:
1657 kmem_zone_destroy(xfs_inode_zone);
1658 out_destroy_efi_zone:
1659 kmem_zone_destroy(xfs_efi_zone);
1660 out_destroy_efd_zone:
1661 kmem_zone_destroy(xfs_efd_zone);
1662 out_destroy_buf_item_zone:
1663 kmem_zone_destroy(xfs_buf_item_zone);
e98c414f
CH
1664 out_destroy_log_item_desc_zone:
1665 kmem_zone_destroy(xfs_log_item_desc_zone);
9f8868ff
CH
1666 out_destroy_trans_zone:
1667 kmem_zone_destroy(xfs_trans_zone);
1668 out_destroy_ifork_zone:
1669 kmem_zone_destroy(xfs_ifork_zone);
9f8868ff
CH
1670 out_destroy_da_state_zone:
1671 kmem_zone_destroy(xfs_da_state_zone);
1672 out_destroy_btree_cur_zone:
1673 kmem_zone_destroy(xfs_btree_cur_zone);
1674 out_destroy_bmap_free_item_zone:
1675 kmem_zone_destroy(xfs_bmap_free_item_zone);
1676 out_destroy_log_ticket_zone:
1677 kmem_zone_destroy(xfs_log_ticket_zone);
1678 out_destroy_ioend_pool:
1679 mempool_destroy(xfs_ioend_pool);
1680 out_destroy_ioend_zone:
1681 kmem_zone_destroy(xfs_ioend_zone);
9f8868ff
CH
1682 out:
1683 return -ENOMEM;
1684}
1685
1686STATIC void
1687xfs_destroy_zones(void)
1688{
8c0a8537
KS
1689 /*
1690 * Make sure all delayed rcu free are flushed before we
1691 * destroy caches.
1692 */
1693 rcu_barrier();
9f8868ff
CH
1694 kmem_zone_destroy(xfs_ili_zone);
1695 kmem_zone_destroy(xfs_inode_zone);
1696 kmem_zone_destroy(xfs_efi_zone);
1697 kmem_zone_destroy(xfs_efd_zone);
1698 kmem_zone_destroy(xfs_buf_item_zone);
e98c414f 1699 kmem_zone_destroy(xfs_log_item_desc_zone);
9f8868ff
CH
1700 kmem_zone_destroy(xfs_trans_zone);
1701 kmem_zone_destroy(xfs_ifork_zone);
9f8868ff
CH
1702 kmem_zone_destroy(xfs_da_state_zone);
1703 kmem_zone_destroy(xfs_btree_cur_zone);
1704 kmem_zone_destroy(xfs_bmap_free_item_zone);
1705 kmem_zone_destroy(xfs_log_ticket_zone);
1706 mempool_destroy(xfs_ioend_pool);
1707 kmem_zone_destroy(xfs_ioend_zone);
9f8868ff
CH
1708
1709}
1da177e4 1710
0bf6a5bd
DC
1711STATIC int __init
1712xfs_init_workqueues(void)
1713{
c999a223
DC
1714 /*
1715 * The allocation workqueue can be used in memory reclaim situations
1716 * (writepage path), and parallelism is only limited by the number of
1717 * AGs in all the filesystems mounted. Hence use the default large
1718 * max_active value for this workqueue.
1719 */
1720 xfs_alloc_wq = alloc_workqueue("xfsalloc", WQ_MEM_RECLAIM, 0);
1721 if (!xfs_alloc_wq)
5889608d 1722 return -ENOMEM;
c999a223 1723
0bf6a5bd 1724 return 0;
0bf6a5bd
DC
1725}
1726
39411f81 1727STATIC void
0bf6a5bd
DC
1728xfs_destroy_workqueues(void)
1729{
c999a223 1730 destroy_workqueue(xfs_alloc_wq);
0bf6a5bd
DC
1731}
1732
1da177e4 1733STATIC int __init
9f8868ff 1734init_xfs_fs(void)
1da177e4
LT
1735{
1736 int error;
1da177e4 1737
65795910
CH
1738 printk(KERN_INFO XFS_VERSION_STRING " with "
1739 XFS_BUILD_OPTIONS " enabled\n");
1da177e4 1740
9f8868ff 1741 xfs_dir_startup();
1da177e4 1742
8758280f 1743 error = xfs_init_zones();
9f8868ff
CH
1744 if (error)
1745 goto out;
1746
0bf6a5bd 1747 error = xfs_init_workqueues();
9f8868ff 1748 if (error)
0b1b213f 1749 goto out_destroy_zones;
9f8868ff 1750
0bf6a5bd
DC
1751 error = xfs_mru_cache_init();
1752 if (error)
1753 goto out_destroy_wq;
1754
9f8868ff
CH
1755 error = xfs_filestream_init();
1756 if (error)
1757 goto out_mru_cache_uninit;
1da177e4 1758
ce8e922c 1759 error = xfs_buf_init();
9f8868ff
CH
1760 if (error)
1761 goto out_filestream_uninit;
1762
1763 error = xfs_init_procfs();
1764 if (error)
1765 goto out_buf_terminate;
1766
1767 error = xfs_sysctl_register();
1768 if (error)
1769 goto out_cleanup_procfs;
1da177e4 1770
a05931ce
CH
1771 error = xfs_qm_init();
1772 if (error)
1773 goto out_sysctl_unregister;
1da177e4
LT
1774
1775 error = register_filesystem(&xfs_fs_type);
1776 if (error)
a05931ce 1777 goto out_qm_exit;
1da177e4
LT
1778 return 0;
1779
a05931ce
CH
1780 out_qm_exit:
1781 xfs_qm_exit();
9f8868ff
CH
1782 out_sysctl_unregister:
1783 xfs_sysctl_unregister();
1784 out_cleanup_procfs:
1785 xfs_cleanup_procfs();
1786 out_buf_terminate:
ce8e922c 1787 xfs_buf_terminate();
9f8868ff
CH
1788 out_filestream_uninit:
1789 xfs_filestream_uninit();
1790 out_mru_cache_uninit:
1791 xfs_mru_cache_uninit();
0bf6a5bd
DC
1792 out_destroy_wq:
1793 xfs_destroy_workqueues();
9f8868ff 1794 out_destroy_zones:
8758280f 1795 xfs_destroy_zones();
9f8868ff 1796 out:
1da177e4
LT
1797 return error;
1798}
1799
1800STATIC void __exit
9f8868ff 1801exit_xfs_fs(void)
1da177e4 1802{
a05931ce 1803 xfs_qm_exit();
1da177e4 1804 unregister_filesystem(&xfs_fs_type);
9f8868ff
CH
1805 xfs_sysctl_unregister();
1806 xfs_cleanup_procfs();
ce8e922c 1807 xfs_buf_terminate();
9f8868ff
CH
1808 xfs_filestream_uninit();
1809 xfs_mru_cache_uninit();
0bf6a5bd 1810 xfs_destroy_workqueues();
8758280f 1811 xfs_destroy_zones();
1da177e4
LT
1812}
1813
1814module_init(init_xfs_fs);
1815module_exit(exit_xfs_fs);
1816
1817MODULE_AUTHOR("Silicon Graphics, Inc.");
1818MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
1819MODULE_LICENSE("GPL");