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