[XFS] kill struct xfs_mount_args
[linux-2.6-block.git] / fs / xfs / linux-2.6 / 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 */
1da177e4 18#include "xfs.h"
a844f451 19#include "xfs_bit.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"
27#include "xfs_dmapi.h"
28#include "xfs_quota.h"
29#include "xfs_mount.h"
1da177e4 30#include "xfs_bmap_btree.h"
a844f451 31#include "xfs_alloc_btree.h"
1da177e4 32#include "xfs_ialloc_btree.h"
1da177e4 33#include "xfs_dir2_sf.h"
a844f451 34#include "xfs_attr_sf.h"
1da177e4
LT
35#include "xfs_dinode.h"
36#include "xfs_inode.h"
a844f451 37#include "xfs_btree.h"
8c4ed633 38#include "xfs_btree_trace.h"
a844f451 39#include "xfs_ialloc.h"
1da177e4 40#include "xfs_bmap.h"
1da177e4
LT
41#include "xfs_rtalloc.h"
42#include "xfs_error.h"
43#include "xfs_itable.h"
9909c4aa 44#include "xfs_fsops.h"
1da177e4
LT
45#include "xfs_rw.h"
46#include "xfs_acl.h"
1da177e4
LT
47#include "xfs_attr.h"
48#include "xfs_buf_item.h"
49#include "xfs_utils.h"
739bfb2a 50#include "xfs_vnodeops.h"
745f6919 51#include "xfs_vfsops.h"
1da177e4 52#include "xfs_version.h"
a67d7c5f 53#include "xfs_log_priv.h"
249a8c11 54#include "xfs_trans_priv.h"
48b62a1a 55#include "xfs_filestream.h"
9f8868ff
CH
56#include "xfs_da_btree.h"
57#include "xfs_dir2_trace.h"
58#include "xfs_extfree_item.h"
59#include "xfs_mru_cache.h"
60#include "xfs_inode_item.h"
fe4fa4b8 61#include "xfs_sync.h"
1da177e4
LT
62
63#include <linux/namei.h>
64#include <linux/init.h>
65#include <linux/mount.h>
0829c360 66#include <linux/mempool.h>
1da177e4 67#include <linux/writeback.h>
4df08c52 68#include <linux/kthread.h>
7dfb7103 69#include <linux/freezer.h>
62a877e3 70#include <linux/parser.h>
1da177e4 71
7989cb8e
DC
72static struct quotactl_ops xfs_quotactl_operations;
73static struct super_operations xfs_super_operations;
7989cb8e 74static kmem_zone_t *xfs_ioend_zone;
0829c360 75mempool_t *xfs_ioend_pool;
1da177e4 76
a67d7c5f
DC
77#define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
78#define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
79#define MNTOPT_LOGDEV "logdev" /* log device */
80#define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
81#define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
82#define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
83#define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
84#define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
85#define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
86#define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
87#define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
88#define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
89#define MNTOPT_MTPT "mtpt" /* filesystem mount point */
90#define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
91#define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
92#define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
93#define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
94#define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
95#define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
96#define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
97 * unwritten extent conversion */
98#define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
99#define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
100#define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
101#define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
102#define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
103#define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
104#define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
105 * in stat(). */
106#define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
107#define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
108#define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
109#define MNTOPT_QUOTA "quota" /* disk quotas (user) */
110#define MNTOPT_NOQUOTA "noquota" /* no quotas */
111#define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */
112#define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */
113#define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */
114#define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */
115#define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */
116#define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */
117#define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
118#define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
119#define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
120#define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */
121#define MNTOPT_DMAPI "dmapi" /* DMI enabled (DMAPI / XDSM) */
122#define MNTOPT_XDSM "xdsm" /* DMI enabled (DMAPI / XDSM) */
123#define MNTOPT_DMI "dmi" /* DMI enabled (DMAPI / XDSM) */
124
62a877e3
CH
125/*
126 * Table driven mount option parser.
127 *
128 * Currently only used for remount, but it will be used for mount
129 * in the future, too.
130 */
131enum {
132 Opt_barrier, Opt_nobarrier, Opt_err
133};
134
a447c093 135static const match_table_t tokens = {
62a877e3
CH
136 {Opt_barrier, "barrier"},
137 {Opt_nobarrier, "nobarrier"},
138 {Opt_err, NULL}
139};
140
141
a67d7c5f
DC
142STATIC unsigned long
143suffix_strtoul(char *s, char **endp, unsigned int base)
144{
145 int last, shift_left_factor = 0;
146 char *value = s;
147
148 last = strlen(value) - 1;
149 if (value[last] == 'K' || value[last] == 'k') {
150 shift_left_factor = 10;
151 value[last] = '\0';
152 }
153 if (value[last] == 'M' || value[last] == 'm') {
154 shift_left_factor = 20;
155 value[last] = '\0';
156 }
157 if (value[last] == 'G' || value[last] == 'g') {
158 shift_left_factor = 30;
159 value[last] = '\0';
160 }
161
162 return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
163}
164
9d565ffa
CH
165/*
166 * This function fills in xfs_mount_t fields based on mount args.
167 * Note: the superblock has _not_ yet been read in.
168 *
169 * Note that this function leaks the various device name allocations on
170 * failure. The caller takes care of them.
171 */
a67d7c5f
DC
172STATIC int
173xfs_parseargs(
174 struct xfs_mount *mp,
175 char *options,
9d565ffa 176 char **mtpt)
a67d7c5f 177{
9d565ffa 178 struct super_block *sb = mp->m_super;
a67d7c5f 179 char *this_char, *value, *eov;
9d565ffa
CH
180 int dsunit = 0;
181 int dswidth = 0;
182 int iosize = 0;
1bd960ee 183 int dmapi_implies_ikeep = 1;
9d565ffa
CH
184 uchar_t iosizelog = 0;
185
186 /*
187 * Copy binary VFS mount flags we are interested in.
188 */
189 if (sb->s_flags & MS_RDONLY)
190 mp->m_flags |= XFS_MOUNT_RDONLY;
191 if (sb->s_flags & MS_DIRSYNC)
192 mp->m_flags |= XFS_MOUNT_DIRSYNC;
193 if (sb->s_flags & MS_SYNCHRONOUS)
194 mp->m_flags |= XFS_MOUNT_WSYNC;
195
196 /*
197 * Set some default flags that could be cleared by the mount option
198 * parsing.
199 */
200 mp->m_flags |= XFS_MOUNT_BARRIER;
201 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
202 mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
a67d7c5f 203
9d565ffa
CH
204 /*
205 * These can be overridden by the mount option parsing.
206 */
207 mp->m_logbufs = -1;
208 mp->m_logbsize = -1;
a67d7c5f
DC
209
210 if (!options)
211 goto done;
212
a67d7c5f
DC
213 while ((this_char = strsep(&options, ",")) != NULL) {
214 if (!*this_char)
215 continue;
216 if ((value = strchr(this_char, '=')) != NULL)
217 *value++ = 0;
218
219 if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
220 if (!value || !*value) {
221 cmn_err(CE_WARN,
222 "XFS: %s option requires an argument",
223 this_char);
224 return EINVAL;
225 }
9d565ffa 226 mp->m_logbufs = simple_strtoul(value, &eov, 10);
a67d7c5f
DC
227 } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
228 if (!value || !*value) {
229 cmn_err(CE_WARN,
230 "XFS: %s option requires an argument",
231 this_char);
232 return EINVAL;
233 }
9d565ffa 234 mp->m_logbsize = suffix_strtoul(value, &eov, 10);
a67d7c5f
DC
235 } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
236 if (!value || !*value) {
237 cmn_err(CE_WARN,
238 "XFS: %s option requires an argument",
239 this_char);
240 return EINVAL;
241 }
9d565ffa
CH
242 mp->m_logname = kstrndup(value, MAXNAMELEN, GFP_KERNEL);
243 if (!mp->m_logname)
244 return ENOMEM;
a67d7c5f
DC
245 } else if (!strcmp(this_char, MNTOPT_MTPT)) {
246 if (!value || !*value) {
247 cmn_err(CE_WARN,
248 "XFS: %s option requires an argument",
249 this_char);
250 return EINVAL;
251 }
9d565ffa
CH
252 *mtpt = kstrndup(value, MAXNAMELEN, GFP_KERNEL);
253 if (!*mtpt)
254 return ENOMEM;
a67d7c5f
DC
255 } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
256 if (!value || !*value) {
257 cmn_err(CE_WARN,
258 "XFS: %s option requires an argument",
259 this_char);
260 return EINVAL;
261 }
9d565ffa
CH
262 mp->m_rtname = kstrndup(value, MAXNAMELEN, GFP_KERNEL);
263 if (!mp->m_rtname)
264 return ENOMEM;
a67d7c5f
DC
265 } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
266 if (!value || !*value) {
267 cmn_err(CE_WARN,
268 "XFS: %s option requires an argument",
269 this_char);
270 return EINVAL;
271 }
272 iosize = simple_strtoul(value, &eov, 10);
9d565ffa 273 iosizelog = (uint8_t) iosize;
a67d7c5f
DC
274 } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
275 if (!value || !*value) {
276 cmn_err(CE_WARN,
277 "XFS: %s option requires an argument",
278 this_char);
279 return EINVAL;
280 }
281 iosize = suffix_strtoul(value, &eov, 10);
9d565ffa 282 iosizelog = ffs(iosize) - 1;
a67d7c5f
DC
283 } else if (!strcmp(this_char, MNTOPT_GRPID) ||
284 !strcmp(this_char, MNTOPT_BSDGROUPS)) {
285 mp->m_flags |= XFS_MOUNT_GRPID;
286 } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
287 !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
288 mp->m_flags &= ~XFS_MOUNT_GRPID;
289 } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
9d565ffa 290 mp->m_flags |= XFS_MOUNT_WSYNC;
a67d7c5f 291 } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
9d565ffa 292 mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
a67d7c5f 293 } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
9d565ffa 294 mp->m_flags |= XFS_MOUNT_NORECOVERY;
a67d7c5f 295 } else if (!strcmp(this_char, MNTOPT_INO64)) {
9d565ffa
CH
296#if XFS_BIG_INUMS
297 mp->m_flags |= XFS_MOUNT_INO64;
298 mp->m_inoadd = XFS_INO64_OFFSET;
299#else
a67d7c5f
DC
300 cmn_err(CE_WARN,
301 "XFS: %s option not allowed on this system",
302 this_char);
303 return EINVAL;
304#endif
305 } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
9d565ffa 306 mp->m_flags |= XFS_MOUNT_NOALIGN;
a67d7c5f 307 } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
9d565ffa 308 mp->m_flags |= XFS_MOUNT_SWALLOC;
a67d7c5f
DC
309 } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
310 if (!value || !*value) {
311 cmn_err(CE_WARN,
312 "XFS: %s option requires an argument",
313 this_char);
314 return EINVAL;
315 }
316 dsunit = simple_strtoul(value, &eov, 10);
317 } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
318 if (!value || !*value) {
319 cmn_err(CE_WARN,
320 "XFS: %s option requires an argument",
321 this_char);
322 return EINVAL;
323 }
324 dswidth = simple_strtoul(value, &eov, 10);
325 } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
9d565ffa 326 mp->m_flags &= ~XFS_MOUNT_SMALL_INUMS;
a67d7c5f
DC
327#if !XFS_BIG_INUMS
328 cmn_err(CE_WARN,
329 "XFS: %s option not allowed on this system",
330 this_char);
331 return EINVAL;
332#endif
333 } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
9d565ffa 334 mp->m_flags |= XFS_MOUNT_NOUUID;
a67d7c5f 335 } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
9d565ffa 336 mp->m_flags |= XFS_MOUNT_BARRIER;
a67d7c5f 337 } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
9d565ffa 338 mp->m_flags &= ~XFS_MOUNT_BARRIER;
a67d7c5f 339 } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
9d565ffa 340 mp->m_flags |= XFS_MOUNT_IKEEP;
a67d7c5f 341 } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
1bd960ee 342 dmapi_implies_ikeep = 0;
9d565ffa 343 mp->m_flags &= ~XFS_MOUNT_IKEEP;
a67d7c5f 344 } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
9d565ffa 345 mp->m_flags &= ~XFS_MOUNT_COMPAT_IOSIZE;
a67d7c5f 346 } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
9d565ffa 347 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
a67d7c5f 348 } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
9d565ffa 349 mp->m_flags |= XFS_MOUNT_ATTR2;
a67d7c5f 350 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
9d565ffa
CH
351 mp->m_flags &= ~XFS_MOUNT_ATTR2;
352 mp->m_flags |= XFS_MOUNT_NOATTR2;
a67d7c5f 353 } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
9d565ffa 354 mp->m_flags |= XFS_MOUNT_FILESTREAMS;
a67d7c5f 355 } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
9d565ffa
CH
356 mp->m_qflags &= ~(XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE |
357 XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE |
358 XFS_UQUOTA_ENFD | XFS_OQUOTA_ENFD);
a67d7c5f
DC
359 } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
360 !strcmp(this_char, MNTOPT_UQUOTA) ||
361 !strcmp(this_char, MNTOPT_USRQUOTA)) {
9d565ffa
CH
362 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE |
363 XFS_UQUOTA_ENFD);
a67d7c5f
DC
364 } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
365 !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
9d565ffa
CH
366 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
367 mp->m_qflags &= ~XFS_UQUOTA_ENFD;
a67d7c5f
DC
368 } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
369 !strcmp(this_char, MNTOPT_PRJQUOTA)) {
9d565ffa
CH
370 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE |
371 XFS_OQUOTA_ENFD);
a67d7c5f 372 } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
9d565ffa
CH
373 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
374 mp->m_qflags &= ~XFS_OQUOTA_ENFD;
a67d7c5f
DC
375 } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
376 !strcmp(this_char, MNTOPT_GRPQUOTA)) {
9d565ffa
CH
377 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE |
378 XFS_OQUOTA_ENFD);
a67d7c5f 379 } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
9d565ffa
CH
380 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
381 mp->m_qflags &= ~XFS_OQUOTA_ENFD;
a67d7c5f 382 } else if (!strcmp(this_char, MNTOPT_DMAPI)) {
9d565ffa 383 mp->m_flags |= XFS_MOUNT_DMAPI;
a67d7c5f 384 } else if (!strcmp(this_char, MNTOPT_XDSM)) {
9d565ffa 385 mp->m_flags |= XFS_MOUNT_DMAPI;
a67d7c5f 386 } else if (!strcmp(this_char, MNTOPT_DMI)) {
9d565ffa 387 mp->m_flags |= XFS_MOUNT_DMAPI;
a67d7c5f
DC
388 } else if (!strcmp(this_char, "ihashsize")) {
389 cmn_err(CE_WARN,
390 "XFS: ihashsize no longer used, option is deprecated.");
391 } else if (!strcmp(this_char, "osyncisdsync")) {
392 /* no-op, this is now the default */
393 cmn_err(CE_WARN,
394 "XFS: osyncisdsync is now the default, option is deprecated.");
395 } else if (!strcmp(this_char, "irixsgid")) {
396 cmn_err(CE_WARN,
397 "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
398 } else {
399 cmn_err(CE_WARN,
400 "XFS: unknown mount option [%s].", this_char);
401 return EINVAL;
402 }
403 }
404
9d565ffa
CH
405 /*
406 * no recovery flag requires a read-only mount
407 */
408 if ((mp->m_flags & XFS_MOUNT_NORECOVERY) &&
409 !(mp->m_flags & XFS_MOUNT_RDONLY)) {
410 cmn_err(CE_WARN, "XFS: no-recovery mounts must be read-only.");
411 return EINVAL;
a67d7c5f
DC
412 }
413
9d565ffa 414 if ((mp->m_flags & XFS_MOUNT_NOALIGN) && (dsunit || dswidth)) {
a67d7c5f
DC
415 cmn_err(CE_WARN,
416 "XFS: sunit and swidth options incompatible with the noalign option");
417 return EINVAL;
418 }
419
9d565ffa
CH
420 if ((mp->m_qflags & (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE)) &&
421 (mp->m_qflags & (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE))) {
a67d7c5f
DC
422 cmn_err(CE_WARN,
423 "XFS: cannot mount with both project and group quota");
424 return EINVAL;
425 }
426
9d565ffa 427 if ((mp->m_flags & XFS_MOUNT_DMAPI) && (!*mtpt || *mtpt[0] == '\0')) {
a67d7c5f
DC
428 printk("XFS: %s option needs the mount point option as well\n",
429 MNTOPT_DMAPI);
430 return EINVAL;
431 }
432
433 if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
434 cmn_err(CE_WARN,
435 "XFS: sunit and swidth must be specified together");
436 return EINVAL;
437 }
438
439 if (dsunit && (dswidth % dsunit != 0)) {
440 cmn_err(CE_WARN,
441 "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
442 dswidth, dsunit);
443 return EINVAL;
444 }
445
446 /*
447 * Applications using DMI filesystems often expect the
448 * inode generation number to be monotonically increasing.
449 * If we delete inode chunks we break this assumption, so
450 * keep unused inode chunks on disk for DMI filesystems
451 * until we come up with a better solution.
452 * Note that if "ikeep" or "noikeep" mount options are
453 * supplied, then they are honored.
454 */
9d565ffa
CH
455 if ((mp->m_flags & XFS_MOUNT_DMAPI) && dmapi_implies_ikeep)
456 mp->m_flags |= XFS_MOUNT_IKEEP;
a67d7c5f 457
9d565ffa
CH
458done:
459 if (!(mp->m_flags & XFS_MOUNT_NOALIGN)) {
460 /*
461 * At this point the superblock has not been read
462 * in, therefore we do not know the block size.
463 * Before the mount call ends we will convert
464 * these to FSBs.
465 */
a67d7c5f 466 if (dsunit) {
9d565ffa
CH
467 mp->m_dalign = dsunit;
468 mp->m_flags |= XFS_MOUNT_RETERR;
a67d7c5f 469 }
9d565ffa
CH
470
471 if (dswidth)
472 mp->m_swidth = dswidth;
473 }
474
475 if (mp->m_logbufs != -1 &&
476 mp->m_logbufs != 0 &&
477 (mp->m_logbufs < XLOG_MIN_ICLOGS ||
478 mp->m_logbufs > XLOG_MAX_ICLOGS)) {
479 cmn_err(CE_WARN,
480 "XFS: invalid logbufs value: %d [not %d-%d]",
481 mp->m_logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
482 return XFS_ERROR(EINVAL);
483 }
484 if (mp->m_logbsize != -1 &&
485 mp->m_logbsize != 0 &&
486 (mp->m_logbsize < XLOG_MIN_RECORD_BSIZE ||
487 mp->m_logbsize > XLOG_MAX_RECORD_BSIZE ||
488 !is_power_of_2(mp->m_logbsize))) {
489 cmn_err(CE_WARN,
490 "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
491 mp->m_logbsize);
492 return XFS_ERROR(EINVAL);
493 }
494
495 mp->m_fsname = kstrndup(sb->s_id, MAXNAMELEN, GFP_KERNEL);
496 if (!mp->m_fsname)
497 return ENOMEM;
498 mp->m_fsname_len = strlen(mp->m_fsname) + 1;
499
500 if (iosizelog) {
501 if (iosizelog > XFS_MAX_IO_LOG ||
502 iosizelog < XFS_MIN_IO_LOG) {
503 cmn_err(CE_WARN,
504 "XFS: invalid log iosize: %d [not %d-%d]",
505 iosizelog, XFS_MIN_IO_LOG,
506 XFS_MAX_IO_LOG);
507 return XFS_ERROR(EINVAL);
508 }
509
510 mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
511 mp->m_readio_log = iosizelog;
512 mp->m_writeio_log = iosizelog;
a67d7c5f
DC
513 }
514
a67d7c5f
DC
515 return 0;
516}
517
518struct proc_xfs_info {
519 int flag;
520 char *str;
521};
522
523STATIC int
524xfs_showargs(
525 struct xfs_mount *mp,
526 struct seq_file *m)
527{
528 static struct proc_xfs_info xfs_info_set[] = {
529 /* the few simple ones we can get from the mount struct */
1bd960ee 530 { XFS_MOUNT_IKEEP, "," MNTOPT_IKEEP },
a67d7c5f
DC
531 { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
532 { XFS_MOUNT_INO64, "," MNTOPT_INO64 },
533 { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
534 { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
535 { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
536 { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
537 { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
538 { XFS_MOUNT_ATTR2, "," MNTOPT_ATTR2 },
539 { XFS_MOUNT_FILESTREAMS, "," MNTOPT_FILESTREAM },
540 { XFS_MOUNT_DMAPI, "," MNTOPT_DMAPI },
541 { XFS_MOUNT_GRPID, "," MNTOPT_GRPID },
542 { 0, NULL }
543 };
544 static struct proc_xfs_info xfs_info_unset[] = {
545 /* the few simple ones we can get from the mount struct */
a67d7c5f
DC
546 { XFS_MOUNT_COMPAT_IOSIZE, "," MNTOPT_LARGEIO },
547 { XFS_MOUNT_BARRIER, "," MNTOPT_NOBARRIER },
548 { XFS_MOUNT_SMALL_INUMS, "," MNTOPT_64BITINODE },
549 { 0, NULL }
550 };
551 struct proc_xfs_info *xfs_infop;
552
553 for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
554 if (mp->m_flags & xfs_infop->flag)
555 seq_puts(m, xfs_infop->str);
556 }
557 for (xfs_infop = xfs_info_unset; xfs_infop->flag; xfs_infop++) {
558 if (!(mp->m_flags & xfs_infop->flag))
559 seq_puts(m, xfs_infop->str);
560 }
561
562 if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
563 seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
564 (int)(1 << mp->m_writeio_log) >> 10);
565
566 if (mp->m_logbufs > 0)
567 seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
568 if (mp->m_logbsize > 0)
569 seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
570
571 if (mp->m_logname)
572 seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
573 if (mp->m_rtname)
574 seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
575
576 if (mp->m_dalign > 0)
577 seq_printf(m, "," MNTOPT_SUNIT "=%d",
578 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
579 if (mp->m_swidth > 0)
580 seq_printf(m, "," MNTOPT_SWIDTH "=%d",
581 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
582
583 if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD))
584 seq_puts(m, "," MNTOPT_USRQUOTA);
585 else if (mp->m_qflags & XFS_UQUOTA_ACCT)
586 seq_puts(m, "," MNTOPT_UQUOTANOENF);
587
588 if (mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_OQUOTA_ENFD))
589 seq_puts(m, "," MNTOPT_PRJQUOTA);
590 else if (mp->m_qflags & XFS_PQUOTA_ACCT)
591 seq_puts(m, "," MNTOPT_PQUOTANOENF);
592
593 if (mp->m_qflags & (XFS_GQUOTA_ACCT|XFS_OQUOTA_ENFD))
594 seq_puts(m, "," MNTOPT_GRPQUOTA);
595 else if (mp->m_qflags & XFS_GQUOTA_ACCT)
596 seq_puts(m, "," MNTOPT_GQUOTANOENF);
597
598 if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
599 seq_puts(m, "," MNTOPT_NOQUOTA);
600
601 return 0;
602}
1da177e4
LT
603__uint64_t
604xfs_max_file_offset(
605 unsigned int blockshift)
606{
607 unsigned int pagefactor = 1;
608 unsigned int bitshift = BITS_PER_LONG - 1;
609
610 /* Figure out maximum filesize, on Linux this can depend on
611 * the filesystem blocksize (on 32 bit platforms).
612 * __block_prepare_write does this in an [unsigned] long...
613 * page->index << (PAGE_CACHE_SHIFT - bbits)
614 * So, for page sized blocks (4K on 32 bit platforms),
615 * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
616 * (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
617 * but for smaller blocksizes it is less (bbits = log2 bsize).
618 * Note1: get_block_t takes a long (implicit cast from above)
619 * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch
620 * can optionally convert the [unsigned] long from above into
621 * an [unsigned] long long.
622 */
623
624#if BITS_PER_LONG == 32
625# if defined(CONFIG_LBD)
626 ASSERT(sizeof(sector_t) == 8);
627 pagefactor = PAGE_CACHE_SIZE;
628 bitshift = BITS_PER_LONG;
629# else
630 pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift);
631# endif
632#endif
633
634 return (((__uint64_t)pagefactor) << bitshift) - 1;
635}
636
1da177e4
LT
637int
638xfs_blkdev_get(
639 xfs_mount_t *mp,
640 const char *name,
641 struct block_device **bdevp)
642{
643 int error = 0;
644
30c40d2c 645 *bdevp = open_bdev_exclusive(name, FMODE_READ|FMODE_WRITE, mp);
1da177e4
LT
646 if (IS_ERR(*bdevp)) {
647 error = PTR_ERR(*bdevp);
648 printk("XFS: Invalid device [%s], error=%d\n", name, error);
649 }
650
651 return -error;
652}
653
654void
655xfs_blkdev_put(
656 struct block_device *bdev)
657{
658 if (bdev)
30c40d2c 659 close_bdev_exclusive(bdev, FMODE_READ|FMODE_WRITE);
1da177e4
LT
660}
661
f538d4da
CH
662/*
663 * Try to write out the superblock using barriers.
664 */
665STATIC int
666xfs_barrier_test(
667 xfs_mount_t *mp)
668{
669 xfs_buf_t *sbp = xfs_getsb(mp, 0);
670 int error;
671
672 XFS_BUF_UNDONE(sbp);
673 XFS_BUF_UNREAD(sbp);
674 XFS_BUF_UNDELAYWRITE(sbp);
675 XFS_BUF_WRITE(sbp);
676 XFS_BUF_UNASYNC(sbp);
677 XFS_BUF_ORDERED(sbp);
678
679 xfsbdstrat(mp, sbp);
680 error = xfs_iowait(sbp);
681
682 /*
683 * Clear all the flags we set and possible error state in the
684 * buffer. We only did the write to try out whether barriers
685 * worked and shouldn't leave any traces in the superblock
686 * buffer.
687 */
688 XFS_BUF_DONE(sbp);
689 XFS_BUF_ERROR(sbp, 0);
690 XFS_BUF_UNORDERED(sbp);
691
692 xfs_buf_relse(sbp);
693 return error;
694}
695
696void
697xfs_mountfs_check_barriers(xfs_mount_t *mp)
698{
699 int error;
700
701 if (mp->m_logdev_targp != mp->m_ddev_targp) {
702 xfs_fs_cmn_err(CE_NOTE, mp,
703 "Disabling barriers, not supported with external log device");
704 mp->m_flags &= ~XFS_MOUNT_BARRIER;
4ef19ddd 705 return;
f538d4da
CH
706 }
707
b2ea401b
NS
708 if (xfs_readonly_buftarg(mp->m_ddev_targp)) {
709 xfs_fs_cmn_err(CE_NOTE, mp,
710 "Disabling barriers, underlying device is readonly");
711 mp->m_flags &= ~XFS_MOUNT_BARRIER;
712 return;
713 }
714
f538d4da
CH
715 error = xfs_barrier_test(mp);
716 if (error) {
717 xfs_fs_cmn_err(CE_NOTE, mp,
718 "Disabling barriers, trial barrier write failed");
719 mp->m_flags &= ~XFS_MOUNT_BARRIER;
4ef19ddd 720 return;
f538d4da
CH
721 }
722}
723
724void
725xfs_blkdev_issue_flush(
726 xfs_buftarg_t *buftarg)
727{
ce8e922c 728 blkdev_issue_flush(buftarg->bt_bdev, NULL);
f538d4da 729}
1da177e4 730
19f354d4
CH
731STATIC void
732xfs_close_devices(
733 struct xfs_mount *mp)
734{
735 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
c032bfcf 736 struct block_device *logdev = mp->m_logdev_targp->bt_bdev;
19f354d4 737 xfs_free_buftarg(mp->m_logdev_targp);
c032bfcf 738 xfs_blkdev_put(logdev);
19f354d4
CH
739 }
740 if (mp->m_rtdev_targp) {
c032bfcf 741 struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev;
19f354d4 742 xfs_free_buftarg(mp->m_rtdev_targp);
c032bfcf 743 xfs_blkdev_put(rtdev);
19f354d4
CH
744 }
745 xfs_free_buftarg(mp->m_ddev_targp);
746}
747
748/*
749 * The file system configurations are:
750 * (1) device (partition) with data and internal log
751 * (2) logical volume with data and log subvolumes.
752 * (3) logical volume with data, log, and realtime subvolumes.
753 *
754 * We only have to handle opening the log and realtime volumes here if
755 * they are present. The data subvolume has already been opened by
756 * get_sb_bdev() and is stored in sb->s_bdev.
757 */
758STATIC int
759xfs_open_devices(
9d565ffa 760 struct xfs_mount *mp)
19f354d4
CH
761{
762 struct block_device *ddev = mp->m_super->s_bdev;
763 struct block_device *logdev = NULL, *rtdev = NULL;
764 int error;
765
766 /*
767 * Open real time and log devices - order is important.
768 */
9d565ffa
CH
769 if (mp->m_logname) {
770 error = xfs_blkdev_get(mp, mp->m_logname, &logdev);
19f354d4
CH
771 if (error)
772 goto out;
773 }
774
9d565ffa
CH
775 if (mp->m_rtname) {
776 error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev);
19f354d4
CH
777 if (error)
778 goto out_close_logdev;
779
780 if (rtdev == ddev || rtdev == logdev) {
781 cmn_err(CE_WARN,
782 "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
783 error = EINVAL;
784 goto out_close_rtdev;
785 }
786 }
787
788 /*
789 * Setup xfs_mount buffer target pointers
790 */
791 error = ENOMEM;
792 mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
793 if (!mp->m_ddev_targp)
794 goto out_close_rtdev;
795
796 if (rtdev) {
797 mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
798 if (!mp->m_rtdev_targp)
799 goto out_free_ddev_targ;
800 }
801
802 if (logdev && logdev != ddev) {
803 mp->m_logdev_targp = xfs_alloc_buftarg(logdev, 1);
804 if (!mp->m_logdev_targp)
805 goto out_free_rtdev_targ;
806 } else {
807 mp->m_logdev_targp = mp->m_ddev_targp;
808 }
809
810 return 0;
811
812 out_free_rtdev_targ:
813 if (mp->m_rtdev_targp)
814 xfs_free_buftarg(mp->m_rtdev_targp);
815 out_free_ddev_targ:
816 xfs_free_buftarg(mp->m_ddev_targp);
817 out_close_rtdev:
818 if (rtdev)
819 xfs_blkdev_put(rtdev);
820 out_close_logdev:
821 if (logdev && logdev != ddev)
822 xfs_blkdev_put(logdev);
823 out:
824 return error;
825}
826
e34b562c
CH
827/*
828 * Setup xfs_mount buffer target pointers based on superblock
829 */
830STATIC int
831xfs_setup_devices(
832 struct xfs_mount *mp)
833{
834 int error;
19f354d4 835
e34b562c
CH
836 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
837 mp->m_sb.sb_sectsize);
838 if (error)
839 return error;
840
841 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
842 unsigned int log_sector_size = BBSIZE;
843
844 if (xfs_sb_version_hassector(&mp->m_sb))
845 log_sector_size = mp->m_sb.sb_logsectsize;
846 error = xfs_setsize_buftarg(mp->m_logdev_targp,
847 mp->m_sb.sb_blocksize,
848 log_sector_size);
849 if (error)
850 return error;
851 }
852 if (mp->m_rtdev_targp) {
853 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
854 mp->m_sb.sb_blocksize,
855 mp->m_sb.sb_sectsize);
856 if (error)
857 return error;
858 }
859
860 return 0;
861}
19f354d4 862
249a8c11
DC
863/*
864 * XFS AIL push thread support
865 */
866void
867xfsaild_wakeup(
82fa9012 868 struct xfs_ail *ailp,
249a8c11
DC
869 xfs_lsn_t threshold_lsn)
870{
82fa9012
DC
871 ailp->xa_target = threshold_lsn;
872 wake_up_process(ailp->xa_task);
249a8c11
DC
873}
874
875int
876xfsaild(
877 void *data)
878{
82fa9012 879 struct xfs_ail *ailp = data;
249a8c11
DC
880 xfs_lsn_t last_pushed_lsn = 0;
881 long tout = 0;
882
883 while (!kthread_should_stop()) {
884 if (tout)
885 schedule_timeout_interruptible(msecs_to_jiffies(tout));
886 tout = 1000;
887
888 /* swsusp */
889 try_to_freeze();
890
82fa9012
DC
891 ASSERT(ailp->xa_mount->m_log);
892 if (XFS_FORCED_SHUTDOWN(ailp->xa_mount))
249a8c11
DC
893 continue;
894
82fa9012 895 tout = xfsaild_push(ailp, &last_pushed_lsn);
249a8c11
DC
896 }
897
898 return 0;
899} /* xfsaild */
900
901int
902xfsaild_start(
82fa9012 903 struct xfs_ail *ailp)
249a8c11 904{
82fa9012
DC
905 ailp->xa_target = 0;
906 ailp->xa_task = kthread_run(xfsaild, ailp, "xfsaild");
907 if (IS_ERR(ailp->xa_task))
908 return -PTR_ERR(ailp->xa_task);
249a8c11
DC
909 return 0;
910}
911
912void
913xfsaild_stop(
82fa9012 914 struct xfs_ail *ailp)
249a8c11 915{
82fa9012 916 kthread_stop(ailp->xa_task);
249a8c11
DC
917}
918
919
bf904248 920/* Catch misguided souls that try to use this interface on XFS */
1da177e4 921STATIC struct inode *
a50cd269 922xfs_fs_alloc_inode(
1da177e4
LT
923 struct super_block *sb)
924{
bf904248 925 BUG();
493dca61 926 return NULL;
1da177e4
LT
927}
928
bf904248 929/*
99fa8cb3
DC
930 * Now that the generic code is guaranteed not to be accessing
931 * the linux inode, we can reclaim the inode.
bf904248 932 */
1da177e4 933STATIC void
a50cd269 934xfs_fs_destroy_inode(
bf904248 935 struct inode *inode)
1da177e4 936{
99fa8cb3
DC
937 xfs_inode_t *ip = XFS_I(inode);
938
939 XFS_STATS_INC(vn_reclaim);
940 if (xfs_reclaim(ip))
941 panic("%s: cannot reclaim 0x%p\n", __func__, inode);
1da177e4
LT
942}
943
07c8f675
DC
944/*
945 * Slab object creation initialisation for the XFS inode.
946 * This covers only the idempotent fields in the XFS inode;
947 * all other fields need to be initialised on allocation
948 * from the slab. This avoids the need to repeatedly intialise
949 * fields in the xfs inode that left in the initialise state
950 * when freeing the inode.
951 */
bf904248
DC
952STATIC void
953xfs_fs_inode_init_once(
07c8f675
DC
954 void *inode)
955{
956 struct xfs_inode *ip = inode;
957
958 memset(ip, 0, sizeof(struct xfs_inode));
bf904248
DC
959
960 /* vfs inode */
961 inode_init_once(VFS_I(ip));
962
963 /* xfs inode */
07c8f675
DC
964 atomic_set(&ip->i_iocount, 0);
965 atomic_set(&ip->i_pincount, 0);
966 spin_lock_init(&ip->i_flags_lock);
07c8f675
DC
967 init_waitqueue_head(&ip->i_ipin_wait);
968 /*
969 * Because we want to use a counting completion, complete
970 * the flush completion once to allow a single access to
971 * the flush completion without blocking.
972 */
973 init_completion(&ip->i_flush);
974 complete(&ip->i_flush);
975
976 mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
977 "xfsino", ip->i_ino);
978 mrlock_init(&ip->i_iolock, MRLOCK_BARRIER, "xfsio", ip->i_ino);
979}
980
1da177e4
LT
981/*
982 * Attempt to flush the inode, this will actually fail
983 * if the inode is pinned, but we dirty the inode again
984 * at the point when it is unpinned after a log write,
8758280f 985 * since this is when the inode itself becomes flushable.
1da177e4
LT
986 */
987STATIC int
a50cd269 988xfs_fs_write_inode(
1da177e4
LT
989 struct inode *inode,
990 int sync)
991{
a3f74ffb
DC
992 int error = 0;
993 int flags = 0;
1da177e4 994
cf441eeb 995 xfs_itrace_entry(XFS_I(inode));
739bfb2a
CH
996 if (sync) {
997 filemap_fdatawait(inode->i_mapping);
998 flags |= FLUSH_SYNC;
1da177e4 999 }
739bfb2a 1000 error = xfs_inode_flush(XFS_I(inode), flags);
e893bffd
LM
1001 /*
1002 * if we failed to write out the inode then mark
1003 * it dirty again so we'll try again later.
1004 */
1005 if (error)
94b97e39 1006 xfs_mark_inode_dirty_sync(XFS_I(inode));
739bfb2a 1007
1da177e4
LT
1008 return -error;
1009}
1010
1011STATIC void
a50cd269 1012xfs_fs_clear_inode(
1da177e4
LT
1013 struct inode *inode)
1014{
1543d79c 1015 xfs_inode_t *ip = XFS_I(inode);
56d433e4 1016
99fa8cb3
DC
1017 xfs_itrace_entry(ip);
1018 XFS_STATS_INC(vn_rele);
1019 XFS_STATS_INC(vn_remove);
1020 XFS_STATS_DEC(vn_active);
1021
1022 xfs_inactive(ip);
1023 xfs_iflags_clear(ip, XFS_IMODIFIED);
56d433e4 1024}
1da177e4 1025
a738159d
CH
1026STATIC void
1027xfs_free_fsname(
1028 struct xfs_mount *mp)
1029{
1030 kfree(mp->m_fsname);
1031 kfree(mp->m_rtname);
1032 kfree(mp->m_logname);
1033}
1034
1da177e4 1035STATIC void
a50cd269 1036xfs_fs_put_super(
1da177e4
LT
1037 struct super_block *sb)
1038{
745f6919 1039 struct xfs_mount *mp = XFS_M(sb);
e48ad316
CH
1040 struct xfs_inode *rip = mp->m_rootip;
1041 int unmount_event_flags = 0;
1da177e4
LT
1042 int error;
1043
a167b17e 1044 xfs_syncd_stop(mp);
be97d9d5 1045 xfs_sync_inodes(mp, SYNC_ATTR|SYNC_DELWRI);
e48ad316
CH
1046
1047#ifdef HAVE_DMAPI
1048 if (mp->m_flags & XFS_MOUNT_DMAPI) {
1049 unmount_event_flags =
1050 (mp->m_dmevmask & (1 << DM_EVENT_UNMOUNT)) ?
1051 0 : DM_FLAGS_UNWANTED;
1052 /*
1053 * Ignore error from dmapi here, first unmount is not allowed
1054 * to fail anyway, and second we wouldn't want to fail a
1055 * unmount because of dmapi.
1056 */
1057 XFS_SEND_PREUNMOUNT(mp, rip, DM_RIGHT_NULL, rip, DM_RIGHT_NULL,
1058 NULL, NULL, 0, 0, unmount_event_flags);
1059 }
1060#endif
1061
1062 /*
1063 * Blow away any referenced inode in the filestreams cache.
1064 * This can and will cause log traffic as inodes go inactive
1065 * here.
1066 */
1067 xfs_filestream_unmount(mp);
1068
1069 XFS_bflush(mp->m_ddev_targp);
1070 error = xfs_unmount_flush(mp, 0);
1071 WARN_ON(error);
1072
e48ad316
CH
1073 if (mp->m_flags & XFS_MOUNT_DMAPI) {
1074 XFS_SEND_UNMOUNT(mp, rip, DM_RIGHT_NULL, 0, 0,
1075 unmount_event_flags);
1076 }
1077
19f354d4 1078 xfs_unmountfs(mp);
6203300e 1079 xfs_freesb(mp);
c962fb79 1080 xfs_icsb_destroy_counters(mp);
19f354d4 1081 xfs_close_devices(mp);
e48ad316
CH
1082 xfs_qmops_put(mp);
1083 xfs_dmops_put(mp);
a738159d 1084 xfs_free_fsname(mp);
c962fb79 1085 kfree(mp);
1da177e4
LT
1086}
1087
1088STATIC void
a50cd269 1089xfs_fs_write_super(
1da177e4
LT
1090 struct super_block *sb)
1091{
b83bd138 1092 if (!(sb->s_flags & MS_RDONLY))
e9f1c6ee 1093 xfs_sync_fsdata(XFS_M(sb), 0);
1da177e4
LT
1094 sb->s_dirt = 0;
1095}
1096
1097STATIC int
a50cd269 1098xfs_fs_sync_super(
1da177e4
LT
1099 struct super_block *sb,
1100 int wait)
1101{
745f6919 1102 struct xfs_mount *mp = XFS_M(sb);
b83bd138 1103 int error;
1da177e4 1104
e893bffd
LM
1105 /*
1106 * Treat a sync operation like a freeze. This is to work
1107 * around a race in sync_inodes() which works in two phases
1108 * - an asynchronous flush, which can write out an inode
1109 * without waiting for file size updates to complete, and a
1110 * synchronous flush, which wont do anything because the
1111 * async flush removed the inode's dirty flag. Also
1112 * sync_inodes() will not see any files that just have
1113 * outstanding transactions to be flushed because we don't
1114 * dirty the Linux inode until after the transaction I/O
1115 * completes.
1116 */
e9f1c6ee
DC
1117 if (wait || unlikely(sb->s_frozen == SB_FREEZE_WRITE))
1118 error = xfs_quiesce_data(mp);
1119 else
1120 error = xfs_sync_fsdata(mp, 0);
1da177e4
LT
1121 sb->s_dirt = 0;
1122
1123 if (unlikely(laptop_mode)) {
74394496 1124 int prev_sync_seq = mp->m_sync_seq;
1da177e4
LT
1125
1126 /*
1127 * The disk must be active because we're syncing.
1128 * We schedule xfssyncd now (now that the disk is
1129 * active) instead of later (when it might not be).
1130 */
74394496 1131 wake_up_process(mp->m_sync_task);
1da177e4
LT
1132 /*
1133 * We have to wait for the sync iteration to complete.
1134 * If we don't, the disk activity caused by the sync
1135 * will come after the sync is completed, and that
1136 * triggers another sync from laptop mode.
1137 */
74394496
CH
1138 wait_event(mp->m_wait_single_sync_task,
1139 mp->m_sync_seq != prev_sync_seq);
1da177e4
LT
1140 }
1141
1142 return -error;
1143}
1144
1145STATIC int
a50cd269 1146xfs_fs_statfs(
726c3342 1147 struct dentry *dentry,
1da177e4
LT
1148 struct kstatfs *statp)
1149{
4ca488eb
CH
1150 struct xfs_mount *mp = XFS_M(dentry->d_sb);
1151 xfs_sb_t *sbp = &mp->m_sb;
1152 __uint64_t fakeinos, id;
1153 xfs_extlen_t lsize;
1154
1155 statp->f_type = XFS_SB_MAGIC;
1156 statp->f_namelen = MAXNAMELEN - 1;
1157
1158 id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
1159 statp->f_fsid.val[0] = (u32)id;
1160 statp->f_fsid.val[1] = (u32)(id >> 32);
1161
d4d90b57 1162 xfs_icsb_sync_counters(mp, XFS_ICSB_LAZY_COUNT);
4ca488eb
CH
1163
1164 spin_lock(&mp->m_sb_lock);
1165 statp->f_bsize = sbp->sb_blocksize;
1166 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
1167 statp->f_blocks = sbp->sb_dblocks - lsize;
1168 statp->f_bfree = statp->f_bavail =
1169 sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
1170 fakeinos = statp->f_bfree << sbp->sb_inopblog;
1171#if XFS_BIG_INUMS
1172 fakeinos += mp->m_inoadd;
1173#endif
1174 statp->f_files =
1175 MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
1176 if (mp->m_maxicount)
1177#if XFS_BIG_INUMS
1178 if (!mp->m_inoadd)
1179#endif
1180 statp->f_files = min_t(typeof(statp->f_files),
1181 statp->f_files,
1182 mp->m_maxicount);
1183 statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
1184 spin_unlock(&mp->m_sb_lock);
1185
1186 XFS_QM_DQSTATVFS(XFS_I(dentry->d_inode), statp);
1187 return 0;
1da177e4
LT
1188}
1189
1190STATIC int
a50cd269 1191xfs_fs_remount(
1da177e4
LT
1192 struct super_block *sb,
1193 int *flags,
1194 char *options)
1195{
745f6919 1196 struct xfs_mount *mp = XFS_M(sb);
62a877e3
CH
1197 substring_t args[MAX_OPT_ARGS];
1198 char *p;
1da177e4 1199
62a877e3
CH
1200 while ((p = strsep(&options, ",")) != NULL) {
1201 int token;
bdd907ba 1202
62a877e3
CH
1203 if (!*p)
1204 continue;
48b62a1a 1205
62a877e3
CH
1206 token = match_token(p, tokens, args);
1207 switch (token) {
1208 case Opt_barrier:
48b62a1a 1209 mp->m_flags |= XFS_MOUNT_BARRIER;
62a877e3
CH
1210
1211 /*
1212 * Test if barriers are actually working if we can,
1213 * else delay this check until the filesystem is
1214 * marked writeable.
1215 */
1216 if (!(mp->m_flags & XFS_MOUNT_RDONLY))
1217 xfs_mountfs_check_barriers(mp);
1218 break;
1219 case Opt_nobarrier:
48b62a1a 1220 mp->m_flags &= ~XFS_MOUNT_BARRIER;
62a877e3
CH
1221 break;
1222 default:
6efdf281
CH
1223 /*
1224 * Logically we would return an error here to prevent
1225 * users from believing they might have changed
1226 * mount options using remount which can't be changed.
1227 *
1228 * But unfortunately mount(8) adds all options from
1229 * mtab and fstab to the mount arguments in some cases
1230 * so we can't blindly reject options, but have to
1231 * check for each specified option if it actually
1232 * differs from the currently set option and only
1233 * reject it if that's the case.
1234 *
1235 * Until that is implemented we return success for
1236 * every remount request, and silently ignore all
1237 * options that we can't actually change.
1238 */
1239#if 0
62a877e3
CH
1240 printk(KERN_INFO
1241 "XFS: mount option \"%s\" not supported for remount\n", p);
1242 return -EINVAL;
6efdf281 1243#else
6c5e51da 1244 break;
6efdf281 1245#endif
48b62a1a 1246 }
62a877e3
CH
1247 }
1248
1249 /* rw/ro -> rw */
1250 if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(*flags & MS_RDONLY)) {
1251 mp->m_flags &= ~XFS_MOUNT_RDONLY;
1252 if (mp->m_flags & XFS_MOUNT_BARRIER)
1253 xfs_mountfs_check_barriers(mp);
1254 }
1255
1256 /* rw -> ro */
1257 if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (*flags & MS_RDONLY)) {
e9f1c6ee 1258 xfs_quiesce_data(mp);
76bf105c 1259 xfs_quiesce_attr(mp);
48b62a1a
CH
1260 mp->m_flags |= XFS_MOUNT_RDONLY;
1261 }
1262
62a877e3 1263 return 0;
1da177e4
LT
1264}
1265
9909c4aa
CH
1266/*
1267 * Second stage of a freeze. The data is already frozen so we only
76bf105c 1268 * need to take care of the metadata. Once that's done write a dummy
9909c4aa
CH
1269 * record to dirty the log in case of a crash while frozen.
1270 */
1da177e4 1271STATIC void
a50cd269 1272xfs_fs_lockfs(
1da177e4
LT
1273 struct super_block *sb)
1274{
9909c4aa
CH
1275 struct xfs_mount *mp = XFS_M(sb);
1276
76bf105c 1277 xfs_quiesce_attr(mp);
9909c4aa 1278 xfs_fs_log_dummy(mp);
1da177e4
LT
1279}
1280
1281STATIC int
a50cd269 1282xfs_fs_show_options(
1da177e4
LT
1283 struct seq_file *m,
1284 struct vfsmount *mnt)
1285{
745f6919 1286 return -xfs_showargs(XFS_M(mnt->mnt_sb), m);
1da177e4
LT
1287}
1288
ee34807a 1289STATIC int
a50cd269 1290xfs_fs_quotasync(
ee34807a
NS
1291 struct super_block *sb,
1292 int type)
1293{
b09cc771 1294 return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XQUOTASYNC, 0, NULL);
ee34807a
NS
1295}
1296
1da177e4 1297STATIC int
a50cd269 1298xfs_fs_getxstate(
1da177e4
LT
1299 struct super_block *sb,
1300 struct fs_quota_stat *fqs)
1301{
b09cc771 1302 return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XGETQSTAT, 0, (caddr_t)fqs);
1da177e4
LT
1303}
1304
1305STATIC int
a50cd269 1306xfs_fs_setxstate(
1da177e4
LT
1307 struct super_block *sb,
1308 unsigned int flags,
1309 int op)
1310{
b09cc771 1311 return -XFS_QM_QUOTACTL(XFS_M(sb), op, 0, (caddr_t)&flags);
1da177e4
LT
1312}
1313
1314STATIC int
a50cd269 1315xfs_fs_getxquota(
1da177e4
LT
1316 struct super_block *sb,
1317 int type,
1318 qid_t id,
1319 struct fs_disk_quota *fdq)
1320{
b09cc771 1321 return -XFS_QM_QUOTACTL(XFS_M(sb),
b83bd138
NS
1322 (type == USRQUOTA) ? Q_XGETQUOTA :
1323 ((type == GRPQUOTA) ? Q_XGETGQUOTA :
1324 Q_XGETPQUOTA), id, (caddr_t)fdq);
1da177e4
LT
1325}
1326
1327STATIC int
a50cd269 1328xfs_fs_setxquota(
1da177e4
LT
1329 struct super_block *sb,
1330 int type,
1331 qid_t id,
1332 struct fs_disk_quota *fdq)
1333{
b09cc771 1334 return -XFS_QM_QUOTACTL(XFS_M(sb),
b83bd138
NS
1335 (type == USRQUOTA) ? Q_XSETQLIM :
1336 ((type == GRPQUOTA) ? Q_XSETGQLIM :
1337 Q_XSETPQLIM), id, (caddr_t)fdq);
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
1350 /* Fail a mount where the logbuf is smaller then the log stripe */
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) {
f8f15e42
CH
1357 cmn_err(CE_WARN,
1358 "XFS: logbuf size must be greater than or equal to log stripe size");
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) {
f8f15e42
CH
1364 cmn_err(CE_WARN,
1365 "XFS: logbuf size for version 1 logs must be 16K or 32K");
1366 return XFS_ERROR(EINVAL);
1367 }
1368 }
1369
1370 /*
1371 * mkfs'ed attr2 will turn on attr2 mount unless explicitly
1372 * told by noattr2 to turn it off
1373 */
1374 if (xfs_sb_version_hasattr2(&mp->m_sb) &&
9d565ffa 1375 !(mp->m_flags & XFS_MOUNT_NOATTR2))
f8f15e42
CH
1376 mp->m_flags |= XFS_MOUNT_ATTR2;
1377
1378 /*
1379 * prohibit r/w mounts of read-only filesystems
1380 */
1381 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
1382 cmn_err(CE_WARN,
1383 "XFS: cannot mount a read-only filesystem as read-write");
1384 return XFS_ERROR(EROFS);
1385 }
1386
9d565ffa 1387#if 0 /* shared mounts were never supported on Linux */
f8f15e42
CH
1388 /*
1389 * check for shared mount.
1390 */
1391 if (ap->flags & XFSMNT_SHARED) {
1392 if (!xfs_sb_version_hasshared(&mp->m_sb))
1393 return XFS_ERROR(EINVAL);
1394
1395 /*
1396 * For IRIX 6.5, shared mounts must have the shared
1397 * version bit set, have the persistent readonly
1398 * field set, must be version 0 and can only be mounted
1399 * read-only.
1400 */
1401 if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) ||
1402 (mp->m_sb.sb_shared_vn != 0))
1403 return XFS_ERROR(EINVAL);
1404
1405 mp->m_flags |= XFS_MOUNT_SHARED;
1406
1407 /*
1408 * Shared XFS V0 can't deal with DMI. Return EINVAL.
1409 */
9d565ffa
CH
1410 if (mp->m_sb.sb_shared_vn == 0 &&
1411 (mp->m_flags & XFS_MOUNT_DMAPI))
f8f15e42
CH
1412 return XFS_ERROR(EINVAL);
1413 }
9d565ffa 1414#endif
f8f15e42
CH
1415
1416 return 0;
1417}
1418
1da177e4 1419STATIC int
a50cd269 1420xfs_fs_fill_super(
1da177e4
LT
1421 struct super_block *sb,
1422 void *data,
1423 int silent)
1424{
f3dcc13f 1425 struct inode *root;
745f6919 1426 struct xfs_mount *mp = NULL;
c962fb79 1427 int flags = 0, error = ENOMEM;
9d565ffa 1428 char *mtpt = NULL;
bdd907ba 1429
c962fb79
CH
1430 mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
1431 if (!mp)
9d565ffa 1432 goto out;
1da177e4 1433
c962fb79 1434 spin_lock_init(&mp->m_sb_lock);
c962fb79
CH
1435 mutex_init(&mp->m_growlock);
1436 atomic_set(&mp->m_active_trans, 0);
74394496
CH
1437 INIT_LIST_HEAD(&mp->m_sync_list);
1438 spin_lock_init(&mp->m_sync_lock);
1439 init_waitqueue_head(&mp->m_wait_single_sync_task);
1440
b267ce99
CH
1441 mp->m_super = sb;
1442 sb->s_fs_info = mp;
1da177e4 1443
9d565ffa 1444 error = xfs_parseargs(mp, (char *)data, &mtpt);
745f6919 1445 if (error)
9d565ffa 1446 goto out_free_fsname;
1da177e4
LT
1447
1448 sb_min_blocksize(sb, BBSIZE);
0ec58516 1449 sb->s_xattr = xfs_xattr_handlers;
a50cd269 1450 sb->s_export_op = &xfs_export_operations;
a50cd269
NS
1451 sb->s_qcop = &xfs_quotactl_operations;
1452 sb->s_op = &xfs_super_operations;
1da177e4 1453
9d565ffa 1454 error = xfs_dmops_get(mp);
f8f15e42 1455 if (error)
9d565ffa
CH
1456 goto out_free_fsname;
1457 error = xfs_qmops_get(mp);
745f6919 1458 if (error)
19f354d4 1459 goto out_put_dmops;
1da177e4 1460
9d565ffa 1461 if (silent)
f8f15e42
CH
1462 flags |= XFS_MFSI_QUIET;
1463
9d565ffa 1464 error = xfs_open_devices(mp);
19f354d4
CH
1465 if (error)
1466 goto out_put_qmops;
f8f15e42 1467
c962fb79
CH
1468 if (xfs_icsb_init_counters(mp))
1469 mp->m_flags |= XFS_MOUNT_NO_PERCPU_SB;
1470
f8f15e42
CH
1471 error = xfs_readsb(mp, flags);
1472 if (error)
9d565ffa
CH
1473 goto out_destroy_counters;
1474
1475 error = xfs_finish_flags(mp);
f8f15e42 1476 if (error)
effa2eda 1477 goto out_free_sb;
f8f15e42 1478
e34b562c 1479 error = xfs_setup_devices(mp);
19f354d4 1480 if (error)
effa2eda 1481 goto out_free_sb;
f8f15e42
CH
1482
1483 if (mp->m_flags & XFS_MOUNT_BARRIER)
1484 xfs_mountfs_check_barriers(mp);
1485
1486 error = xfs_filestream_mount(mp);
1487 if (error)
effa2eda 1488 goto out_free_sb;
f8f15e42 1489
4249023a 1490 error = xfs_mountfs(mp);
f8f15e42 1491 if (error)
120226c1 1492 goto out_filestream_unmount;
f8f15e42 1493
9d565ffa 1494 XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, mtpt, mp->m_fsname);
f8f15e42 1495
1da177e4 1496 sb->s_dirt = 1;
4ca488eb
CH
1497 sb->s_magic = XFS_SB_MAGIC;
1498 sb->s_blocksize = mp->m_sb.sb_blocksize;
1499 sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
1da177e4
LT
1500 sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
1501 sb->s_time_gran = 1;
1502 set_posix_acl_flag(sb);
1503
01651646 1504 root = igrab(VFS_I(mp->m_rootip));
f3dcc13f 1505 if (!root) {
cbc89dcf 1506 error = ENOENT;
1da177e4 1507 goto fail_unmount;
cbc89dcf 1508 }
f3dcc13f
CH
1509 if (is_bad_inode(root)) {
1510 error = EINVAL;
1da177e4
LT
1511 goto fail_vnrele;
1512 }
f3dcc13f
CH
1513 sb->s_root = d_alloc_root(root);
1514 if (!sb->s_root) {
1515 error = ENOMEM;
1da177e4
LT
1516 goto fail_vnrele;
1517 }
74394496 1518
a167b17e
DC
1519 error = xfs_syncd_init(mp);
1520 if (error)
1da177e4 1521 goto fail_vnrele;
74394496 1522
9d565ffa 1523 kfree(mtpt);
1da177e4 1524
9d565ffa 1525 xfs_itrace_exit(XFS_I(sb->s_root->d_inode));
1da177e4
LT
1526 return 0;
1527
120226c1
CH
1528 out_filestream_unmount:
1529 xfs_filestream_unmount(mp);
effa2eda
CH
1530 out_free_sb:
1531 xfs_freesb(mp);
9d565ffa 1532 out_destroy_counters:
c962fb79 1533 xfs_icsb_destroy_counters(mp);
19f354d4
CH
1534 xfs_close_devices(mp);
1535 out_put_qmops:
f8f15e42 1536 xfs_qmops_put(mp);
19f354d4 1537 out_put_dmops:
f8f15e42 1538 xfs_dmops_put(mp);
9d565ffa
CH
1539 out_free_fsname:
1540 xfs_free_fsname(mp);
1541 kfree(mtpt);
c962fb79 1542 kfree(mp);
9d565ffa 1543 out:
c962fb79 1544 return -error;
f8f15e42
CH
1545
1546 fail_vnrele:
1da177e4
LT
1547 if (sb->s_root) {
1548 dput(sb->s_root);
1549 sb->s_root = NULL;
1550 } else {
f3dcc13f 1551 iput(root);
1da177e4
LT
1552 }
1553
f8f15e42 1554 fail_unmount:
e48ad316
CH
1555 /*
1556 * Blow away any referenced inode in the filestreams cache.
1557 * This can and will cause log traffic as inodes go inactive
1558 * here.
1559 */
1560 xfs_filestream_unmount(mp);
1561
1562 XFS_bflush(mp->m_ddev_targp);
1563 error = xfs_unmount_flush(mp, 0);
1564 WARN_ON(error);
1565
19f354d4 1566 xfs_unmountfs(mp);
6203300e 1567 goto out_free_sb;
1da177e4
LT
1568}
1569
454e2398 1570STATIC int
a50cd269 1571xfs_fs_get_sb(
1da177e4
LT
1572 struct file_system_type *fs_type,
1573 int flags,
1574 const char *dev_name,
454e2398
DH
1575 void *data,
1576 struct vfsmount *mnt)
1da177e4 1577{
454e2398
DH
1578 return get_sb_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super,
1579 mnt);
a50cd269
NS
1580}
1581
7989cb8e 1582static struct super_operations xfs_super_operations = {
a50cd269
NS
1583 .alloc_inode = xfs_fs_alloc_inode,
1584 .destroy_inode = xfs_fs_destroy_inode,
1585 .write_inode = xfs_fs_write_inode,
1586 .clear_inode = xfs_fs_clear_inode,
1587 .put_super = xfs_fs_put_super,
1588 .write_super = xfs_fs_write_super,
1589 .sync_fs = xfs_fs_sync_super,
1590 .write_super_lockfs = xfs_fs_lockfs,
1591 .statfs = xfs_fs_statfs,
1592 .remount_fs = xfs_fs_remount,
1593 .show_options = xfs_fs_show_options,
1da177e4
LT
1594};
1595
7989cb8e 1596static struct quotactl_ops xfs_quotactl_operations = {
a50cd269
NS
1597 .quota_sync = xfs_fs_quotasync,
1598 .get_xstate = xfs_fs_getxstate,
1599 .set_xstate = xfs_fs_setxstate,
1600 .get_xquota = xfs_fs_getxquota,
1601 .set_xquota = xfs_fs_setxquota,
1da177e4
LT
1602};
1603
5085b607 1604static struct file_system_type xfs_fs_type = {
1da177e4
LT
1605 .owner = THIS_MODULE,
1606 .name = "xfs",
a50cd269 1607 .get_sb = xfs_fs_get_sb,
1da177e4
LT
1608 .kill_sb = kill_block_super,
1609 .fs_flags = FS_REQUIRES_DEV,
1610};
1611
9f8868ff
CH
1612STATIC int __init
1613xfs_alloc_trace_bufs(void)
1614{
1615#ifdef XFS_ALLOC_TRACE
1616 xfs_alloc_trace_buf = ktrace_alloc(XFS_ALLOC_TRACE_SIZE, KM_MAYFAIL);
1617 if (!xfs_alloc_trace_buf)
1618 goto out;
1619#endif
1620#ifdef XFS_BMAP_TRACE
1621 xfs_bmap_trace_buf = ktrace_alloc(XFS_BMAP_TRACE_SIZE, KM_MAYFAIL);
1622 if (!xfs_bmap_trace_buf)
1623 goto out_free_alloc_trace;
1624#endif
8c4ed633
CH
1625#ifdef XFS_BTREE_TRACE
1626 xfs_allocbt_trace_buf = ktrace_alloc(XFS_ALLOCBT_TRACE_SIZE,
1627 KM_MAYFAIL);
1628 if (!xfs_allocbt_trace_buf)
1629 goto out_free_bmap_trace;
1630
1631 xfs_inobt_trace_buf = ktrace_alloc(XFS_INOBT_TRACE_SIZE, KM_MAYFAIL);
1632 if (!xfs_inobt_trace_buf)
1633 goto out_free_allocbt_trace;
1634
9f8868ff
CH
1635 xfs_bmbt_trace_buf = ktrace_alloc(XFS_BMBT_TRACE_SIZE, KM_MAYFAIL);
1636 if (!xfs_bmbt_trace_buf)
8c4ed633 1637 goto out_free_inobt_trace;
9f8868ff
CH
1638#endif
1639#ifdef XFS_ATTR_TRACE
1640 xfs_attr_trace_buf = ktrace_alloc(XFS_ATTR_TRACE_SIZE, KM_MAYFAIL);
1641 if (!xfs_attr_trace_buf)
1642 goto out_free_bmbt_trace;
1643#endif
1644#ifdef XFS_DIR2_TRACE
1645 xfs_dir2_trace_buf = ktrace_alloc(XFS_DIR2_GTRACE_SIZE, KM_MAYFAIL);
1646 if (!xfs_dir2_trace_buf)
1647 goto out_free_attr_trace;
1648#endif
1649
1650 return 0;
1651
1652#ifdef XFS_DIR2_TRACE
1653 out_free_attr_trace:
1654#endif
1655#ifdef XFS_ATTR_TRACE
1656 ktrace_free(xfs_attr_trace_buf);
1657 out_free_bmbt_trace:
1658#endif
8c4ed633 1659#ifdef XFS_BTREE_TRACE
9f8868ff 1660 ktrace_free(xfs_bmbt_trace_buf);
8c4ed633
CH
1661 out_free_inobt_trace:
1662 ktrace_free(xfs_inobt_trace_buf);
1663 out_free_allocbt_trace:
1664 ktrace_free(xfs_allocbt_trace_buf);
9f8868ff
CH
1665 out_free_bmap_trace:
1666#endif
1667#ifdef XFS_BMAP_TRACE
1668 ktrace_free(xfs_bmap_trace_buf);
1669 out_free_alloc_trace:
1670#endif
1671#ifdef XFS_ALLOC_TRACE
1672 ktrace_free(xfs_alloc_trace_buf);
1673 out:
1674#endif
1675 return -ENOMEM;
1676}
1677
1678STATIC void
1679xfs_free_trace_bufs(void)
1680{
1681#ifdef XFS_DIR2_TRACE
1682 ktrace_free(xfs_dir2_trace_buf);
1683#endif
1684#ifdef XFS_ATTR_TRACE
1685 ktrace_free(xfs_attr_trace_buf);
1686#endif
8c4ed633 1687#ifdef XFS_BTREE_TRACE
9f8868ff 1688 ktrace_free(xfs_bmbt_trace_buf);
8c4ed633
CH
1689 ktrace_free(xfs_inobt_trace_buf);
1690 ktrace_free(xfs_allocbt_trace_buf);
9f8868ff
CH
1691#endif
1692#ifdef XFS_BMAP_TRACE
1693 ktrace_free(xfs_bmap_trace_buf);
1694#endif
1695#ifdef XFS_ALLOC_TRACE
1696 ktrace_free(xfs_alloc_trace_buf);
1697#endif
1698}
1699
1700STATIC int __init
1701xfs_init_zones(void)
1702{
9f8868ff
CH
1703
1704 xfs_ioend_zone = kmem_zone_init(sizeof(xfs_ioend_t), "xfs_ioend");
1705 if (!xfs_ioend_zone)
bf904248 1706 goto out;
9f8868ff
CH
1707
1708 xfs_ioend_pool = mempool_create_slab_pool(4 * MAX_BUF_PER_PAGE,
1709 xfs_ioend_zone);
1710 if (!xfs_ioend_pool)
1711 goto out_destroy_ioend_zone;
1712
1713 xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t),
1714 "xfs_log_ticket");
1715 if (!xfs_log_ticket_zone)
1716 goto out_destroy_ioend_pool;
1717
1718 xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
1719 "xfs_bmap_free_item");
1720 if (!xfs_bmap_free_item_zone)
1721 goto out_destroy_log_ticket_zone;
bf904248 1722
9f8868ff
CH
1723 xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
1724 "xfs_btree_cur");
1725 if (!xfs_btree_cur_zone)
1726 goto out_destroy_bmap_free_item_zone;
1727
1728 xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t),
1729 "xfs_da_state");
1730 if (!xfs_da_state_zone)
1731 goto out_destroy_btree_cur_zone;
1732
1733 xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf");
1734 if (!xfs_dabuf_zone)
1735 goto out_destroy_da_state_zone;
1736
1737 xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
1738 if (!xfs_ifork_zone)
1739 goto out_destroy_dabuf_zone;
1740
1741 xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
1742 if (!xfs_trans_zone)
1743 goto out_destroy_ifork_zone;
1744
1745 /*
1746 * The size of the zone allocated buf log item is the maximum
1747 * size possible under XFS. This wastes a little bit of memory,
1748 * but it is much faster.
1749 */
1750 xfs_buf_item_zone = kmem_zone_init((sizeof(xfs_buf_log_item_t) +
1751 (((XFS_MAX_BLOCKSIZE / XFS_BLI_CHUNK) /
1752 NBWORD) * sizeof(int))), "xfs_buf_item");
1753 if (!xfs_buf_item_zone)
1754 goto out_destroy_trans_zone;
1755
1756 xfs_efd_zone = kmem_zone_init((sizeof(xfs_efd_log_item_t) +
1757 ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
1758 sizeof(xfs_extent_t))), "xfs_efd_item");
1759 if (!xfs_efd_zone)
1760 goto out_destroy_buf_item_zone;
1761
1762 xfs_efi_zone = kmem_zone_init((sizeof(xfs_efi_log_item_t) +
1763 ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
1764 sizeof(xfs_extent_t))), "xfs_efi_item");
1765 if (!xfs_efi_zone)
1766 goto out_destroy_efd_zone;
1767
1768 xfs_inode_zone =
1769 kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
bf904248
DC
1770 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM | KM_ZONE_SPREAD,
1771 xfs_fs_inode_init_once);
9f8868ff
CH
1772 if (!xfs_inode_zone)
1773 goto out_destroy_efi_zone;
1774
1775 xfs_ili_zone =
1776 kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
1777 KM_ZONE_SPREAD, NULL);
1778 if (!xfs_ili_zone)
1779 goto out_destroy_inode_zone;
1780
1781#ifdef CONFIG_XFS_POSIX_ACL
1782 xfs_acl_zone = kmem_zone_init(sizeof(xfs_acl_t), "xfs_acl");
1783 if (!xfs_acl_zone)
1784 goto out_destroy_ili_zone;
1785#endif
1786
1787 return 0;
1788
1789#ifdef CONFIG_XFS_POSIX_ACL
1790 out_destroy_ili_zone:
1791#endif
1792 kmem_zone_destroy(xfs_ili_zone);
1793 out_destroy_inode_zone:
1794 kmem_zone_destroy(xfs_inode_zone);
1795 out_destroy_efi_zone:
1796 kmem_zone_destroy(xfs_efi_zone);
1797 out_destroy_efd_zone:
1798 kmem_zone_destroy(xfs_efd_zone);
1799 out_destroy_buf_item_zone:
1800 kmem_zone_destroy(xfs_buf_item_zone);
1801 out_destroy_trans_zone:
1802 kmem_zone_destroy(xfs_trans_zone);
1803 out_destroy_ifork_zone:
1804 kmem_zone_destroy(xfs_ifork_zone);
1805 out_destroy_dabuf_zone:
1806 kmem_zone_destroy(xfs_dabuf_zone);
1807 out_destroy_da_state_zone:
1808 kmem_zone_destroy(xfs_da_state_zone);
1809 out_destroy_btree_cur_zone:
1810 kmem_zone_destroy(xfs_btree_cur_zone);
1811 out_destroy_bmap_free_item_zone:
1812 kmem_zone_destroy(xfs_bmap_free_item_zone);
1813 out_destroy_log_ticket_zone:
1814 kmem_zone_destroy(xfs_log_ticket_zone);
1815 out_destroy_ioend_pool:
1816 mempool_destroy(xfs_ioend_pool);
1817 out_destroy_ioend_zone:
1818 kmem_zone_destroy(xfs_ioend_zone);
9f8868ff
CH
1819 out:
1820 return -ENOMEM;
1821}
1822
1823STATIC void
1824xfs_destroy_zones(void)
1825{
1826#ifdef CONFIG_XFS_POSIX_ACL
1827 kmem_zone_destroy(xfs_acl_zone);
1828#endif
1829 kmem_zone_destroy(xfs_ili_zone);
1830 kmem_zone_destroy(xfs_inode_zone);
1831 kmem_zone_destroy(xfs_efi_zone);
1832 kmem_zone_destroy(xfs_efd_zone);
1833 kmem_zone_destroy(xfs_buf_item_zone);
1834 kmem_zone_destroy(xfs_trans_zone);
1835 kmem_zone_destroy(xfs_ifork_zone);
1836 kmem_zone_destroy(xfs_dabuf_zone);
1837 kmem_zone_destroy(xfs_da_state_zone);
1838 kmem_zone_destroy(xfs_btree_cur_zone);
1839 kmem_zone_destroy(xfs_bmap_free_item_zone);
1840 kmem_zone_destroy(xfs_log_ticket_zone);
1841 mempool_destroy(xfs_ioend_pool);
1842 kmem_zone_destroy(xfs_ioend_zone);
9f8868ff
CH
1843
1844}
1da177e4
LT
1845
1846STATIC int __init
9f8868ff 1847init_xfs_fs(void)
1da177e4
LT
1848{
1849 int error;
1da177e4
LT
1850 static char message[] __initdata = KERN_INFO \
1851 XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled\n";
1852
1853 printk(message);
1854
1da177e4 1855 ktrace_init(64);
9f8868ff
CH
1856 vn_init();
1857 xfs_dir_startup();
1da177e4 1858
8758280f 1859 error = xfs_init_zones();
9f8868ff
CH
1860 if (error)
1861 goto out;
1862
1863 error = xfs_alloc_trace_bufs();
1864 if (error)
1865 goto out_destroy_zones;
1866
1867 error = xfs_mru_cache_init();
1868 if (error)
1869 goto out_free_trace_buffers;
1870
1871 error = xfs_filestream_init();
1872 if (error)
1873 goto out_mru_cache_uninit;
1da177e4 1874
ce8e922c 1875 error = xfs_buf_init();
9f8868ff
CH
1876 if (error)
1877 goto out_filestream_uninit;
1878
1879 error = xfs_init_procfs();
1880 if (error)
1881 goto out_buf_terminate;
1882
1883 error = xfs_sysctl_register();
1884 if (error)
1885 goto out_cleanup_procfs;
1da177e4 1886
1da177e4
LT
1887 vfs_initquota();
1888
1889 error = register_filesystem(&xfs_fs_type);
1890 if (error)
9f8868ff 1891 goto out_sysctl_unregister;
1da177e4
LT
1892 return 0;
1893
9f8868ff
CH
1894 out_sysctl_unregister:
1895 xfs_sysctl_unregister();
1896 out_cleanup_procfs:
1897 xfs_cleanup_procfs();
1898 out_buf_terminate:
ce8e922c 1899 xfs_buf_terminate();
9f8868ff
CH
1900 out_filestream_uninit:
1901 xfs_filestream_uninit();
1902 out_mru_cache_uninit:
1903 xfs_mru_cache_uninit();
1904 out_free_trace_buffers:
1905 xfs_free_trace_bufs();
1906 out_destroy_zones:
8758280f 1907 xfs_destroy_zones();
9f8868ff 1908 out:
1da177e4
LT
1909 return error;
1910}
1911
1912STATIC void __exit
9f8868ff 1913exit_xfs_fs(void)
1da177e4
LT
1914{
1915 vfs_exitquota();
1da177e4 1916 unregister_filesystem(&xfs_fs_type);
9f8868ff
CH
1917 xfs_sysctl_unregister();
1918 xfs_cleanup_procfs();
ce8e922c 1919 xfs_buf_terminate();
9f8868ff
CH
1920 xfs_filestream_uninit();
1921 xfs_mru_cache_uninit();
1922 xfs_free_trace_bufs();
8758280f 1923 xfs_destroy_zones();
1da177e4
LT
1924 ktrace_uninit();
1925}
1926
1927module_init(init_xfs_fs);
1928module_exit(exit_xfs_fs);
1929
1930MODULE_AUTHOR("Silicon Graphics, Inc.");
1931MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
1932MODULE_LICENSE("GPL");