[XFS] Remove vn_from_inode()
[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
LT
20#include "xfs_log.h"
21#include "xfs_clnt.h"
a844f451 22#include "xfs_inum.h"
1da177e4
LT
23#include "xfs_trans.h"
24#include "xfs_sb.h"
a844f451 25#include "xfs_ag.h"
1da177e4
LT
26#include "xfs_dir2.h"
27#include "xfs_alloc.h"
28#include "xfs_dmapi.h"
29#include "xfs_quota.h"
30#include "xfs_mount.h"
1da177e4 31#include "xfs_bmap_btree.h"
a844f451 32#include "xfs_alloc_btree.h"
1da177e4 33#include "xfs_ialloc_btree.h"
1da177e4 34#include "xfs_dir2_sf.h"
a844f451 35#include "xfs_attr_sf.h"
1da177e4
LT
36#include "xfs_dinode.h"
37#include "xfs_inode.h"
a844f451
NS
38#include "xfs_btree.h"
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"
1da177e4
LT
61
62#include <linux/namei.h>
63#include <linux/init.h>
64#include <linux/mount.h>
0829c360 65#include <linux/mempool.h>
1da177e4 66#include <linux/writeback.h>
4df08c52 67#include <linux/kthread.h>
7dfb7103 68#include <linux/freezer.h>
62a877e3 69#include <linux/parser.h>
1da177e4 70
7989cb8e
DC
71static struct quotactl_ops xfs_quotactl_operations;
72static struct super_operations xfs_super_operations;
73static kmem_zone_t *xfs_vnode_zone;
74static kmem_zone_t *xfs_ioend_zone;
0829c360 75mempool_t *xfs_ioend_pool;
1da177e4
LT
76
77STATIC struct xfs_mount_args *
78xfs_args_allocate(
764d1f89
NS
79 struct super_block *sb,
80 int silent)
1da177e4
LT
81{
82 struct xfs_mount_args *args;
83
bdd907ba
CH
84 args = kzalloc(sizeof(struct xfs_mount_args), GFP_KERNEL);
85 if (!args)
86 return NULL;
87
1da177e4
LT
88 args->logbufs = args->logbufsize = -1;
89 strncpy(args->fsname, sb->s_id, MAXNAMELEN);
90
91 /* Copy the already-parsed mount(2) flags we're interested in */
1da177e4
LT
92 if (sb->s_flags & MS_DIRSYNC)
93 args->flags |= XFSMNT_DIRSYNC;
94 if (sb->s_flags & MS_SYNCHRONOUS)
95 args->flags |= XFSMNT_WSYNC;
764d1f89
NS
96 if (silent)
97 args->flags |= XFSMNT_QUIET;
1da177e4
LT
98 args->flags |= XFSMNT_32BITINODES;
99
100 return args;
101}
102
a67d7c5f
DC
103#define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
104#define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
105#define MNTOPT_LOGDEV "logdev" /* log device */
106#define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
107#define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
108#define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
109#define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
110#define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
111#define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
112#define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
113#define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
114#define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
115#define MNTOPT_MTPT "mtpt" /* filesystem mount point */
116#define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
117#define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
118#define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
119#define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
120#define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
121#define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
122#define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
123 * unwritten extent conversion */
124#define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
125#define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
126#define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
127#define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
128#define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
129#define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
130#define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
131 * in stat(). */
132#define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
133#define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
134#define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
135#define MNTOPT_QUOTA "quota" /* disk quotas (user) */
136#define MNTOPT_NOQUOTA "noquota" /* no quotas */
137#define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */
138#define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */
139#define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */
140#define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */
141#define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */
142#define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */
143#define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
144#define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
145#define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
146#define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */
147#define MNTOPT_DMAPI "dmapi" /* DMI enabled (DMAPI / XDSM) */
148#define MNTOPT_XDSM "xdsm" /* DMI enabled (DMAPI / XDSM) */
149#define MNTOPT_DMI "dmi" /* DMI enabled (DMAPI / XDSM) */
150
62a877e3
CH
151/*
152 * Table driven mount option parser.
153 *
154 * Currently only used for remount, but it will be used for mount
155 * in the future, too.
156 */
157enum {
158 Opt_barrier, Opt_nobarrier, Opt_err
159};
160
161static match_table_t tokens = {
162 {Opt_barrier, "barrier"},
163 {Opt_nobarrier, "nobarrier"},
164 {Opt_err, NULL}
165};
166
167
a67d7c5f
DC
168STATIC unsigned long
169suffix_strtoul(char *s, char **endp, unsigned int base)
170{
171 int last, shift_left_factor = 0;
172 char *value = s;
173
174 last = strlen(value) - 1;
175 if (value[last] == 'K' || value[last] == 'k') {
176 shift_left_factor = 10;
177 value[last] = '\0';
178 }
179 if (value[last] == 'M' || value[last] == 'm') {
180 shift_left_factor = 20;
181 value[last] = '\0';
182 }
183 if (value[last] == 'G' || value[last] == 'g') {
184 shift_left_factor = 30;
185 value[last] = '\0';
186 }
187
188 return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
189}
190
191STATIC int
192xfs_parseargs(
193 struct xfs_mount *mp,
194 char *options,
195 struct xfs_mount_args *args,
196 int update)
197{
198 char *this_char, *value, *eov;
199 int dsunit, dswidth, vol_dsunit, vol_dswidth;
200 int iosize;
1bd960ee 201 int dmapi_implies_ikeep = 1;
a67d7c5f
DC
202
203 args->flags |= XFSMNT_BARRIER;
204 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
205
206 if (!options)
207 goto done;
208
209 iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0;
210
211 while ((this_char = strsep(&options, ",")) != NULL) {
212 if (!*this_char)
213 continue;
214 if ((value = strchr(this_char, '=')) != NULL)
215 *value++ = 0;
216
217 if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
218 if (!value || !*value) {
219 cmn_err(CE_WARN,
220 "XFS: %s option requires an argument",
221 this_char);
222 return EINVAL;
223 }
224 args->logbufs = simple_strtoul(value, &eov, 10);
225 } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
226 if (!value || !*value) {
227 cmn_err(CE_WARN,
228 "XFS: %s option requires an argument",
229 this_char);
230 return EINVAL;
231 }
232 args->logbufsize = suffix_strtoul(value, &eov, 10);
233 } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
234 if (!value || !*value) {
235 cmn_err(CE_WARN,
236 "XFS: %s option requires an argument",
237 this_char);
238 return EINVAL;
239 }
240 strncpy(args->logname, value, MAXNAMELEN);
241 } else if (!strcmp(this_char, MNTOPT_MTPT)) {
242 if (!value || !*value) {
243 cmn_err(CE_WARN,
244 "XFS: %s option requires an argument",
245 this_char);
246 return EINVAL;
247 }
248 strncpy(args->mtpt, value, MAXNAMELEN);
249 } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
250 if (!value || !*value) {
251 cmn_err(CE_WARN,
252 "XFS: %s option requires an argument",
253 this_char);
254 return EINVAL;
255 }
256 strncpy(args->rtname, value, MAXNAMELEN);
257 } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
258 if (!value || !*value) {
259 cmn_err(CE_WARN,
260 "XFS: %s option requires an argument",
261 this_char);
262 return EINVAL;
263 }
264 iosize = simple_strtoul(value, &eov, 10);
265 args->flags |= XFSMNT_IOSIZE;
266 args->iosizelog = (uint8_t) iosize;
267 } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
268 if (!value || !*value) {
269 cmn_err(CE_WARN,
270 "XFS: %s option requires an argument",
271 this_char);
272 return EINVAL;
273 }
274 iosize = suffix_strtoul(value, &eov, 10);
275 args->flags |= XFSMNT_IOSIZE;
276 args->iosizelog = ffs(iosize) - 1;
277 } else if (!strcmp(this_char, MNTOPT_GRPID) ||
278 !strcmp(this_char, MNTOPT_BSDGROUPS)) {
279 mp->m_flags |= XFS_MOUNT_GRPID;
280 } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
281 !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
282 mp->m_flags &= ~XFS_MOUNT_GRPID;
283 } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
284 args->flags |= XFSMNT_WSYNC;
285 } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
286 args->flags |= XFSMNT_OSYNCISOSYNC;
287 } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
288 args->flags |= XFSMNT_NORECOVERY;
289 } else if (!strcmp(this_char, MNTOPT_INO64)) {
290 args->flags |= XFSMNT_INO64;
291#if !XFS_BIG_INUMS
292 cmn_err(CE_WARN,
293 "XFS: %s option not allowed on this system",
294 this_char);
295 return EINVAL;
296#endif
297 } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
298 args->flags |= XFSMNT_NOALIGN;
299 } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
300 args->flags |= XFSMNT_SWALLOC;
301 } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
302 if (!value || !*value) {
303 cmn_err(CE_WARN,
304 "XFS: %s option requires an argument",
305 this_char);
306 return EINVAL;
307 }
308 dsunit = simple_strtoul(value, &eov, 10);
309 } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
310 if (!value || !*value) {
311 cmn_err(CE_WARN,
312 "XFS: %s option requires an argument",
313 this_char);
314 return EINVAL;
315 }
316 dswidth = simple_strtoul(value, &eov, 10);
317 } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
318 args->flags &= ~XFSMNT_32BITINODES;
319#if !XFS_BIG_INUMS
320 cmn_err(CE_WARN,
321 "XFS: %s option not allowed on this system",
322 this_char);
323 return EINVAL;
324#endif
325 } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
326 args->flags |= XFSMNT_NOUUID;
327 } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
328 args->flags |= XFSMNT_BARRIER;
329 } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
330 args->flags &= ~XFSMNT_BARRIER;
331 } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
1bd960ee 332 args->flags |= XFSMNT_IKEEP;
a67d7c5f 333 } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
1bd960ee
JJS
334 dmapi_implies_ikeep = 0;
335 args->flags &= ~XFSMNT_IKEEP;
a67d7c5f
DC
336 } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
337 args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE;
338 } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
339 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
340 } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
341 args->flags |= XFSMNT_ATTR2;
342 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
343 args->flags &= ~XFSMNT_ATTR2;
7c12f296 344 args->flags |= XFSMNT_NOATTR2;
a67d7c5f
DC
345 } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
346 args->flags2 |= XFSMNT2_FILESTREAMS;
347 } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
348 args->flags &= ~(XFSMNT_UQUOTAENF|XFSMNT_UQUOTA);
349 args->flags &= ~(XFSMNT_GQUOTAENF|XFSMNT_GQUOTA);
350 } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
351 !strcmp(this_char, MNTOPT_UQUOTA) ||
352 !strcmp(this_char, MNTOPT_USRQUOTA)) {
353 args->flags |= XFSMNT_UQUOTA | XFSMNT_UQUOTAENF;
354 } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
355 !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
356 args->flags |= XFSMNT_UQUOTA;
357 args->flags &= ~XFSMNT_UQUOTAENF;
358 } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
359 !strcmp(this_char, MNTOPT_PRJQUOTA)) {
360 args->flags |= XFSMNT_PQUOTA | XFSMNT_PQUOTAENF;
361 } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
362 args->flags |= XFSMNT_PQUOTA;
363 args->flags &= ~XFSMNT_PQUOTAENF;
364 } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
365 !strcmp(this_char, MNTOPT_GRPQUOTA)) {
366 args->flags |= XFSMNT_GQUOTA | XFSMNT_GQUOTAENF;
367 } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
368 args->flags |= XFSMNT_GQUOTA;
369 args->flags &= ~XFSMNT_GQUOTAENF;
370 } else if (!strcmp(this_char, MNTOPT_DMAPI)) {
371 args->flags |= XFSMNT_DMAPI;
372 } else if (!strcmp(this_char, MNTOPT_XDSM)) {
373 args->flags |= XFSMNT_DMAPI;
374 } else if (!strcmp(this_char, MNTOPT_DMI)) {
375 args->flags |= XFSMNT_DMAPI;
376 } else if (!strcmp(this_char, "ihashsize")) {
377 cmn_err(CE_WARN,
378 "XFS: ihashsize no longer used, option is deprecated.");
379 } else if (!strcmp(this_char, "osyncisdsync")) {
380 /* no-op, this is now the default */
381 cmn_err(CE_WARN,
382 "XFS: osyncisdsync is now the default, option is deprecated.");
383 } else if (!strcmp(this_char, "irixsgid")) {
384 cmn_err(CE_WARN,
385 "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
386 } else {
387 cmn_err(CE_WARN,
388 "XFS: unknown mount option [%s].", this_char);
389 return EINVAL;
390 }
391 }
392
393 if (args->flags & XFSMNT_NORECOVERY) {
394 if ((mp->m_flags & XFS_MOUNT_RDONLY) == 0) {
395 cmn_err(CE_WARN,
396 "XFS: no-recovery mounts must be read-only.");
397 return EINVAL;
398 }
399 }
400
401 if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) {
402 cmn_err(CE_WARN,
403 "XFS: sunit and swidth options incompatible with the noalign option");
404 return EINVAL;
405 }
406
407 if ((args->flags & XFSMNT_GQUOTA) && (args->flags & XFSMNT_PQUOTA)) {
408 cmn_err(CE_WARN,
409 "XFS: cannot mount with both project and group quota");
410 return EINVAL;
411 }
412
413 if ((args->flags & XFSMNT_DMAPI) && *args->mtpt == '\0') {
414 printk("XFS: %s option needs the mount point option as well\n",
415 MNTOPT_DMAPI);
416 return EINVAL;
417 }
418
419 if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
420 cmn_err(CE_WARN,
421 "XFS: sunit and swidth must be specified together");
422 return EINVAL;
423 }
424
425 if (dsunit && (dswidth % dsunit != 0)) {
426 cmn_err(CE_WARN,
427 "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
428 dswidth, dsunit);
429 return EINVAL;
430 }
431
432 /*
433 * Applications using DMI filesystems often expect the
434 * inode generation number to be monotonically increasing.
435 * If we delete inode chunks we break this assumption, so
436 * keep unused inode chunks on disk for DMI filesystems
437 * until we come up with a better solution.
438 * Note that if "ikeep" or "noikeep" mount options are
439 * supplied, then they are honored.
440 */
1bd960ee
JJS
441 if ((args->flags & XFSMNT_DMAPI) && dmapi_implies_ikeep)
442 args->flags |= XFSMNT_IKEEP;
a67d7c5f
DC
443
444 if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
445 if (dsunit) {
446 args->sunit = dsunit;
447 args->flags |= XFSMNT_RETERR;
448 } else {
449 args->sunit = vol_dsunit;
450 }
451 dswidth ? (args->swidth = dswidth) :
452 (args->swidth = vol_dswidth);
453 } else {
454 args->sunit = args->swidth = 0;
455 }
456
457done:
458 if (args->flags & XFSMNT_32BITINODES)
459 mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
460 if (args->flags2)
461 args->flags |= XFSMNT_FLAGS2;
462 return 0;
463}
464
465struct proc_xfs_info {
466 int flag;
467 char *str;
468};
469
470STATIC int
471xfs_showargs(
472 struct xfs_mount *mp,
473 struct seq_file *m)
474{
475 static struct proc_xfs_info xfs_info_set[] = {
476 /* the few simple ones we can get from the mount struct */
1bd960ee 477 { XFS_MOUNT_IKEEP, "," MNTOPT_IKEEP },
a67d7c5f
DC
478 { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
479 { XFS_MOUNT_INO64, "," MNTOPT_INO64 },
480 { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
481 { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
482 { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
483 { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
484 { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
485 { XFS_MOUNT_ATTR2, "," MNTOPT_ATTR2 },
486 { XFS_MOUNT_FILESTREAMS, "," MNTOPT_FILESTREAM },
487 { XFS_MOUNT_DMAPI, "," MNTOPT_DMAPI },
488 { XFS_MOUNT_GRPID, "," MNTOPT_GRPID },
489 { 0, NULL }
490 };
491 static struct proc_xfs_info xfs_info_unset[] = {
492 /* the few simple ones we can get from the mount struct */
a67d7c5f
DC
493 { XFS_MOUNT_COMPAT_IOSIZE, "," MNTOPT_LARGEIO },
494 { XFS_MOUNT_BARRIER, "," MNTOPT_NOBARRIER },
495 { XFS_MOUNT_SMALL_INUMS, "," MNTOPT_64BITINODE },
496 { 0, NULL }
497 };
498 struct proc_xfs_info *xfs_infop;
499
500 for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
501 if (mp->m_flags & xfs_infop->flag)
502 seq_puts(m, xfs_infop->str);
503 }
504 for (xfs_infop = xfs_info_unset; xfs_infop->flag; xfs_infop++) {
505 if (!(mp->m_flags & xfs_infop->flag))
506 seq_puts(m, xfs_infop->str);
507 }
508
509 if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
510 seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
511 (int)(1 << mp->m_writeio_log) >> 10);
512
513 if (mp->m_logbufs > 0)
514 seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
515 if (mp->m_logbsize > 0)
516 seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
517
518 if (mp->m_logname)
519 seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
520 if (mp->m_rtname)
521 seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
522
523 if (mp->m_dalign > 0)
524 seq_printf(m, "," MNTOPT_SUNIT "=%d",
525 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
526 if (mp->m_swidth > 0)
527 seq_printf(m, "," MNTOPT_SWIDTH "=%d",
528 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
529
530 if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD))
531 seq_puts(m, "," MNTOPT_USRQUOTA);
532 else if (mp->m_qflags & XFS_UQUOTA_ACCT)
533 seq_puts(m, "," MNTOPT_UQUOTANOENF);
534
535 if (mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_OQUOTA_ENFD))
536 seq_puts(m, "," MNTOPT_PRJQUOTA);
537 else if (mp->m_qflags & XFS_PQUOTA_ACCT)
538 seq_puts(m, "," MNTOPT_PQUOTANOENF);
539
540 if (mp->m_qflags & (XFS_GQUOTA_ACCT|XFS_OQUOTA_ENFD))
541 seq_puts(m, "," MNTOPT_GRPQUOTA);
542 else if (mp->m_qflags & XFS_GQUOTA_ACCT)
543 seq_puts(m, "," MNTOPT_GQUOTANOENF);
544
545 if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
546 seq_puts(m, "," MNTOPT_NOQUOTA);
547
548 return 0;
549}
1da177e4
LT
550__uint64_t
551xfs_max_file_offset(
552 unsigned int blockshift)
553{
554 unsigned int pagefactor = 1;
555 unsigned int bitshift = BITS_PER_LONG - 1;
556
557 /* Figure out maximum filesize, on Linux this can depend on
558 * the filesystem blocksize (on 32 bit platforms).
559 * __block_prepare_write does this in an [unsigned] long...
560 * page->index << (PAGE_CACHE_SHIFT - bbits)
561 * So, for page sized blocks (4K on 32 bit platforms),
562 * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
563 * (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
564 * but for smaller blocksizes it is less (bbits = log2 bsize).
565 * Note1: get_block_t takes a long (implicit cast from above)
566 * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch
567 * can optionally convert the [unsigned] long from above into
568 * an [unsigned] long long.
569 */
570
571#if BITS_PER_LONG == 32
572# if defined(CONFIG_LBD)
573 ASSERT(sizeof(sector_t) == 8);
574 pagefactor = PAGE_CACHE_SIZE;
575 bitshift = BITS_PER_LONG;
576# else
577 pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift);
578# endif
579#endif
580
581 return (((__uint64_t)pagefactor) << bitshift) - 1;
582}
583
7989cb8e 584STATIC_INLINE void
1da177e4
LT
585xfs_set_inodeops(
586 struct inode *inode)
587{
0432dab2
CH
588 switch (inode->i_mode & S_IFMT) {
589 case S_IFREG:
416c6d5b 590 inode->i_op = &xfs_inode_operations;
3562fd45 591 inode->i_fop = &xfs_file_operations;
e4c573bb 592 inode->i_mapping->a_ops = &xfs_address_space_operations;
0432dab2
CH
593 break;
594 case S_IFDIR:
189f4bf2
BN
595 if (xfs_sb_version_hasasciici(&XFS_M(inode->i_sb)->m_sb))
596 inode->i_op = &xfs_dir_ci_inode_operations;
597 else
598 inode->i_op = &xfs_dir_inode_operations;
3562fd45 599 inode->i_fop = &xfs_dir_file_operations;
0432dab2
CH
600 break;
601 case S_IFLNK:
416c6d5b 602 inode->i_op = &xfs_symlink_inode_operations;
222096ae 603 if (!(XFS_I(inode)->i_df.if_flags & XFS_IFINLINE))
e4c573bb 604 inode->i_mapping->a_ops = &xfs_address_space_operations;
0432dab2
CH
605 break;
606 default:
416c6d5b 607 inode->i_op = &xfs_inode_operations;
1da177e4 608 init_special_inode(inode, inode->i_mode, inode->i_rdev);
0432dab2 609 break;
1da177e4
LT
610 }
611}
612
7989cb8e 613STATIC_INLINE void
1da177e4
LT
614xfs_revalidate_inode(
615 xfs_mount_t *mp,
67fcaa73 616 bhv_vnode_t *vp,
1da177e4
LT
617 xfs_inode_t *ip)
618{
ec86dc02 619 struct inode *inode = vn_to_inode(vp);
1da177e4 620
0432dab2 621 inode->i_mode = ip->i_d.di_mode;
1da177e4
LT
622 inode->i_nlink = ip->i_d.di_nlink;
623 inode->i_uid = ip->i_d.di_uid;
624 inode->i_gid = ip->i_d.di_gid;
0432dab2
CH
625
626 switch (inode->i_mode & S_IFMT) {
627 case S_IFBLK:
628 case S_IFCHR:
629 inode->i_rdev =
630 MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff,
631 sysv_minor(ip->i_df.if_u2.if_rdev));
632 break;
633 default:
1da177e4 634 inode->i_rdev = 0;
0432dab2 635 break;
1da177e4 636 }
0432dab2 637
1da177e4
LT
638 inode->i_generation = ip->i_d.di_gen;
639 i_size_write(inode, ip->i_d.di_size);
1da177e4
LT
640 inode->i_atime.tv_sec = ip->i_d.di_atime.t_sec;
641 inode->i_atime.tv_nsec = ip->i_d.di_atime.t_nsec;
642 inode->i_mtime.tv_sec = ip->i_d.di_mtime.t_sec;
643 inode->i_mtime.tv_nsec = ip->i_d.di_mtime.t_nsec;
644 inode->i_ctime.tv_sec = ip->i_d.di_ctime.t_sec;
645 inode->i_ctime.tv_nsec = ip->i_d.di_ctime.t_nsec;
646 if (ip->i_d.di_flags & XFS_DIFLAG_IMMUTABLE)
647 inode->i_flags |= S_IMMUTABLE;
648 else
649 inode->i_flags &= ~S_IMMUTABLE;
650 if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
651 inode->i_flags |= S_APPEND;
652 else
653 inode->i_flags &= ~S_APPEND;
654 if (ip->i_d.di_flags & XFS_DIFLAG_SYNC)
655 inode->i_flags |= S_SYNC;
656 else
657 inode->i_flags &= ~S_SYNC;
658 if (ip->i_d.di_flags & XFS_DIFLAG_NOATIME)
659 inode->i_flags |= S_NOATIME;
660 else
661 inode->i_flags &= ~S_NOATIME;
b3aea4ed 662 xfs_iflags_clear(ip, XFS_IMODIFIED);
1da177e4
LT
663}
664
665void
666xfs_initialize_vnode(
48c872a9 667 struct xfs_mount *mp,
67fcaa73 668 bhv_vnode_t *vp,
745f6919 669 struct xfs_inode *ip)
1da177e4 670{
ec86dc02 671 struct inode *inode = vn_to_inode(vp);
1da177e4 672
739bfb2a 673 if (!ip->i_vnode) {
739bfb2a
CH
674 ip->i_vnode = vp;
675 inode->i_private = ip;
1da177e4
LT
676 }
677
678 /*
679 * We need to set the ops vectors, and unlock the inode, but if
680 * we have been called during the new inode create process, it is
681 * too early to fill in the Linux inode. We will get called a
682 * second time once the inode is properly set up, and then we can
683 * finish our work.
684 */
745f6919 685 if (ip->i_d.di_mode != 0 && (inode->i_state & I_NEW)) {
48c872a9 686 xfs_revalidate_inode(mp, vp, ip);
1da177e4 687 xfs_set_inodeops(inode);
ec86dc02 688
7a18c386 689 xfs_iflags_clear(ip, XFS_INEW);
1da177e4
LT
690 barrier();
691
692 unlock_new_inode(inode);
693 }
694}
695
696int
697xfs_blkdev_get(
698 xfs_mount_t *mp,
699 const char *name,
700 struct block_device **bdevp)
701{
702 int error = 0;
703
704 *bdevp = open_bdev_excl(name, 0, mp);
705 if (IS_ERR(*bdevp)) {
706 error = PTR_ERR(*bdevp);
707 printk("XFS: Invalid device [%s], error=%d\n", name, error);
708 }
709
710 return -error;
711}
712
713void
714xfs_blkdev_put(
715 struct block_device *bdev)
716{
717 if (bdev)
718 close_bdev_excl(bdev);
719}
720
f538d4da
CH
721/*
722 * Try to write out the superblock using barriers.
723 */
724STATIC int
725xfs_barrier_test(
726 xfs_mount_t *mp)
727{
728 xfs_buf_t *sbp = xfs_getsb(mp, 0);
729 int error;
730
731 XFS_BUF_UNDONE(sbp);
732 XFS_BUF_UNREAD(sbp);
733 XFS_BUF_UNDELAYWRITE(sbp);
734 XFS_BUF_WRITE(sbp);
735 XFS_BUF_UNASYNC(sbp);
736 XFS_BUF_ORDERED(sbp);
737
738 xfsbdstrat(mp, sbp);
739 error = xfs_iowait(sbp);
740
741 /*
742 * Clear all the flags we set and possible error state in the
743 * buffer. We only did the write to try out whether barriers
744 * worked and shouldn't leave any traces in the superblock
745 * buffer.
746 */
747 XFS_BUF_DONE(sbp);
748 XFS_BUF_ERROR(sbp, 0);
749 XFS_BUF_UNORDERED(sbp);
750
751 xfs_buf_relse(sbp);
752 return error;
753}
754
755void
756xfs_mountfs_check_barriers(xfs_mount_t *mp)
757{
758 int error;
759
760 if (mp->m_logdev_targp != mp->m_ddev_targp) {
761 xfs_fs_cmn_err(CE_NOTE, mp,
762 "Disabling barriers, not supported with external log device");
763 mp->m_flags &= ~XFS_MOUNT_BARRIER;
4ef19ddd 764 return;
f538d4da
CH
765 }
766
b2ea401b
NS
767 if (xfs_readonly_buftarg(mp->m_ddev_targp)) {
768 xfs_fs_cmn_err(CE_NOTE, mp,
769 "Disabling barriers, underlying device is readonly");
770 mp->m_flags &= ~XFS_MOUNT_BARRIER;
771 return;
772 }
773
f538d4da
CH
774 error = xfs_barrier_test(mp);
775 if (error) {
776 xfs_fs_cmn_err(CE_NOTE, mp,
777 "Disabling barriers, trial barrier write failed");
778 mp->m_flags &= ~XFS_MOUNT_BARRIER;
4ef19ddd 779 return;
f538d4da
CH
780 }
781}
782
783void
784xfs_blkdev_issue_flush(
785 xfs_buftarg_t *buftarg)
786{
ce8e922c 787 blkdev_issue_flush(buftarg->bt_bdev, NULL);
f538d4da 788}
1da177e4 789
19f354d4
CH
790STATIC void
791xfs_close_devices(
792 struct xfs_mount *mp)
793{
794 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
c032bfcf 795 struct block_device *logdev = mp->m_logdev_targp->bt_bdev;
19f354d4 796 xfs_free_buftarg(mp->m_logdev_targp);
c032bfcf 797 xfs_blkdev_put(logdev);
19f354d4
CH
798 }
799 if (mp->m_rtdev_targp) {
c032bfcf 800 struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev;
19f354d4 801 xfs_free_buftarg(mp->m_rtdev_targp);
c032bfcf 802 xfs_blkdev_put(rtdev);
19f354d4
CH
803 }
804 xfs_free_buftarg(mp->m_ddev_targp);
805}
806
807/*
808 * The file system configurations are:
809 * (1) device (partition) with data and internal log
810 * (2) logical volume with data and log subvolumes.
811 * (3) logical volume with data, log, and realtime subvolumes.
812 *
813 * We only have to handle opening the log and realtime volumes here if
814 * they are present. The data subvolume has already been opened by
815 * get_sb_bdev() and is stored in sb->s_bdev.
816 */
817STATIC int
818xfs_open_devices(
819 struct xfs_mount *mp,
820 struct xfs_mount_args *args)
821{
822 struct block_device *ddev = mp->m_super->s_bdev;
823 struct block_device *logdev = NULL, *rtdev = NULL;
824 int error;
825
826 /*
827 * Open real time and log devices - order is important.
828 */
829 if (args->logname[0]) {
830 error = xfs_blkdev_get(mp, args->logname, &logdev);
831 if (error)
832 goto out;
833 }
834
835 if (args->rtname[0]) {
836 error = xfs_blkdev_get(mp, args->rtname, &rtdev);
837 if (error)
838 goto out_close_logdev;
839
840 if (rtdev == ddev || rtdev == logdev) {
841 cmn_err(CE_WARN,
842 "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
843 error = EINVAL;
844 goto out_close_rtdev;
845 }
846 }
847
848 /*
849 * Setup xfs_mount buffer target pointers
850 */
851 error = ENOMEM;
852 mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
853 if (!mp->m_ddev_targp)
854 goto out_close_rtdev;
855
856 if (rtdev) {
857 mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
858 if (!mp->m_rtdev_targp)
859 goto out_free_ddev_targ;
860 }
861
862 if (logdev && logdev != ddev) {
863 mp->m_logdev_targp = xfs_alloc_buftarg(logdev, 1);
864 if (!mp->m_logdev_targp)
865 goto out_free_rtdev_targ;
866 } else {
867 mp->m_logdev_targp = mp->m_ddev_targp;
868 }
869
870 return 0;
871
872 out_free_rtdev_targ:
873 if (mp->m_rtdev_targp)
874 xfs_free_buftarg(mp->m_rtdev_targp);
875 out_free_ddev_targ:
876 xfs_free_buftarg(mp->m_ddev_targp);
877 out_close_rtdev:
878 if (rtdev)
879 xfs_blkdev_put(rtdev);
880 out_close_logdev:
881 if (logdev && logdev != ddev)
882 xfs_blkdev_put(logdev);
883 out:
884 return error;
885}
886
e34b562c
CH
887/*
888 * Setup xfs_mount buffer target pointers based on superblock
889 */
890STATIC int
891xfs_setup_devices(
892 struct xfs_mount *mp)
893{
894 int error;
19f354d4 895
e34b562c
CH
896 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
897 mp->m_sb.sb_sectsize);
898 if (error)
899 return error;
900
901 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
902 unsigned int log_sector_size = BBSIZE;
903
904 if (xfs_sb_version_hassector(&mp->m_sb))
905 log_sector_size = mp->m_sb.sb_logsectsize;
906 error = xfs_setsize_buftarg(mp->m_logdev_targp,
907 mp->m_sb.sb_blocksize,
908 log_sector_size);
909 if (error)
910 return error;
911 }
912 if (mp->m_rtdev_targp) {
913 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
914 mp->m_sb.sb_blocksize,
915 mp->m_sb.sb_sectsize);
916 if (error)
917 return error;
918 }
919
920 return 0;
921}
19f354d4 922
249a8c11
DC
923/*
924 * XFS AIL push thread support
925 */
926void
927xfsaild_wakeup(
928 xfs_mount_t *mp,
929 xfs_lsn_t threshold_lsn)
930{
931 mp->m_ail.xa_target = threshold_lsn;
932 wake_up_process(mp->m_ail.xa_task);
933}
934
935int
936xfsaild(
937 void *data)
938{
939 xfs_mount_t *mp = (xfs_mount_t *)data;
940 xfs_lsn_t last_pushed_lsn = 0;
941 long tout = 0;
942
943 while (!kthread_should_stop()) {
944 if (tout)
945 schedule_timeout_interruptible(msecs_to_jiffies(tout));
946 tout = 1000;
947
948 /* swsusp */
949 try_to_freeze();
950
951 ASSERT(mp->m_log);
952 if (XFS_FORCED_SHUTDOWN(mp))
953 continue;
954
955 tout = xfsaild_push(mp, &last_pushed_lsn);
956 }
957
958 return 0;
959} /* xfsaild */
960
961int
962xfsaild_start(
963 xfs_mount_t *mp)
964{
965 mp->m_ail.xa_target = 0;
966 mp->m_ail.xa_task = kthread_run(xfsaild, mp, "xfsaild");
967 if (IS_ERR(mp->m_ail.xa_task))
968 return -PTR_ERR(mp->m_ail.xa_task);
969 return 0;
970}
971
972void
973xfsaild_stop(
974 xfs_mount_t *mp)
975{
976 kthread_stop(mp->m_ail.xa_task);
977}
978
979
980
1da177e4 981STATIC struct inode *
a50cd269 982xfs_fs_alloc_inode(
1da177e4
LT
983 struct super_block *sb)
984{
67fcaa73 985 bhv_vnode_t *vp;
1da177e4 986
8758280f
NS
987 vp = kmem_zone_alloc(xfs_vnode_zone, KM_SLEEP);
988 if (unlikely(!vp))
1da177e4 989 return NULL;
ec86dc02 990 return vn_to_inode(vp);
1da177e4
LT
991}
992
993STATIC void
a50cd269 994xfs_fs_destroy_inode(
1da177e4
LT
995 struct inode *inode)
996{
a19d033c 997 kmem_zone_free(xfs_vnode_zone, inode);
1da177e4
LT
998}
999
1000STATIC void
a50cd269 1001xfs_fs_inode_init_once(
4ba9b9d0 1002 void *vnode)
1da177e4 1003{
a35afb83 1004 inode_init_once(vn_to_inode((bhv_vnode_t *)vnode));
1da177e4
LT
1005}
1006
1da177e4
LT
1007/*
1008 * Attempt to flush the inode, this will actually fail
1009 * if the inode is pinned, but we dirty the inode again
1010 * at the point when it is unpinned after a log write,
8758280f 1011 * since this is when the inode itself becomes flushable.
1da177e4
LT
1012 */
1013STATIC int
a50cd269 1014xfs_fs_write_inode(
1da177e4
LT
1015 struct inode *inode,
1016 int sync)
1017{
a3f74ffb
DC
1018 int error = 0;
1019 int flags = 0;
1da177e4 1020
cf441eeb 1021 xfs_itrace_entry(XFS_I(inode));
739bfb2a
CH
1022 if (sync) {
1023 filemap_fdatawait(inode->i_mapping);
1024 flags |= FLUSH_SYNC;
1da177e4 1025 }
739bfb2a 1026 error = xfs_inode_flush(XFS_I(inode), flags);
e893bffd
LM
1027 /*
1028 * if we failed to write out the inode then mark
1029 * it dirty again so we'll try again later.
1030 */
1031 if (error)
1032 mark_inode_dirty_sync(inode);
739bfb2a 1033
1da177e4
LT
1034 return -error;
1035}
1036
1037STATIC void
a50cd269 1038xfs_fs_clear_inode(
1da177e4
LT
1039 struct inode *inode)
1040{
1543d79c 1041 xfs_inode_t *ip = XFS_I(inode);
56d433e4 1042
02ba71de 1043 /*
1543d79c 1044 * ip can be null when xfs_iget_core calls xfs_idestroy if we
02ba71de
CH
1045 * find an inode with di_mode == 0 but without IGET_CREATE set.
1046 */
1543d79c 1047 if (ip) {
cf441eeb 1048 xfs_itrace_entry(ip);
1543d79c
CH
1049 XFS_STATS_INC(vn_rele);
1050 XFS_STATS_INC(vn_remove);
1051 XFS_STATS_INC(vn_reclaim);
1052 XFS_STATS_DEC(vn_active);
1053
1054 xfs_inactive(ip);
1055 xfs_iflags_clear(ip, XFS_IMODIFIED);
1056 if (xfs_reclaim(ip))
34a622b2 1057 panic("%s: cannot reclaim 0x%p\n", __func__, inode);
b3aea4ed 1058 }
56d433e4 1059
739bfb2a 1060 ASSERT(XFS_I(inode) == NULL);
56d433e4 1061}
1da177e4
LT
1062
1063/*
1064 * Enqueue a work item to be picked up by the vfs xfssyncd thread.
1065 * Doing this has two advantages:
1066 * - It saves on stack space, which is tight in certain situations
1067 * - It can be used (with care) as a mechanism to avoid deadlocks.
1068 * Flushing while allocating in a full filesystem requires both.
1069 */
1070STATIC void
1071xfs_syncd_queue_work(
74394496 1072 struct xfs_mount *mp,
1da177e4 1073 void *data,
74394496 1074 void (*syncer)(struct xfs_mount *, void *))
1da177e4 1075{
b83bd138 1076 struct bhv_vfs_sync_work *work;
1da177e4 1077
b83bd138 1078 work = kmem_alloc(sizeof(struct bhv_vfs_sync_work), KM_SLEEP);
1da177e4
LT
1079 INIT_LIST_HEAD(&work->w_list);
1080 work->w_syncer = syncer;
1081 work->w_data = data;
74394496
CH
1082 work->w_mount = mp;
1083 spin_lock(&mp->m_sync_lock);
1084 list_add_tail(&work->w_list, &mp->m_sync_list);
1085 spin_unlock(&mp->m_sync_lock);
1086 wake_up_process(mp->m_sync_task);
1da177e4
LT
1087}
1088
1089/*
1090 * Flush delayed allocate data, attempting to free up reserved space
1091 * from existing allocations. At this point a new allocation attempt
1092 * has failed with ENOSPC and we are in the process of scratching our
1093 * heads, looking about for more room...
1094 */
1095STATIC void
1096xfs_flush_inode_work(
74394496
CH
1097 struct xfs_mount *mp,
1098 void *arg)
1da177e4 1099{
74394496
CH
1100 struct inode *inode = arg;
1101 filemap_flush(inode->i_mapping);
1102 iput(inode);
1da177e4
LT
1103}
1104
1105void
1106xfs_flush_inode(
1107 xfs_inode_t *ip)
1108{
01651646 1109 struct inode *inode = VFS_I(ip);
1da177e4
LT
1110
1111 igrab(inode);
74394496 1112 xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_inode_work);
041e0e3b 1113 delay(msecs_to_jiffies(500));
1da177e4
LT
1114}
1115
1116/*
1117 * This is the "bigger hammer" version of xfs_flush_inode_work...
1118 * (IOW, "If at first you don't succeed, use a Bigger Hammer").
1119 */
1120STATIC void
1121xfs_flush_device_work(
74394496
CH
1122 struct xfs_mount *mp,
1123 void *arg)
1da177e4 1124{
74394496 1125 struct inode *inode = arg;
b267ce99 1126 sync_blockdev(mp->m_super->s_bdev);
74394496 1127 iput(inode);
1da177e4
LT
1128}
1129
1130void
1131xfs_flush_device(
1132 xfs_inode_t *ip)
1133{
e4f75291 1134 struct inode *inode = VFS_I(ip);
1da177e4
LT
1135
1136 igrab(inode);
74394496 1137 xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_device_work);
041e0e3b 1138 delay(msecs_to_jiffies(500));
1da177e4
LT
1139 xfs_log_force(ip->i_mount, (xfs_lsn_t)0, XFS_LOG_FORCE|XFS_LOG_SYNC);
1140}
1141
1da177e4 1142STATIC void
74394496
CH
1143xfs_sync_worker(
1144 struct xfs_mount *mp,
1da177e4
LT
1145 void *unused)
1146{
1147 int error;
1148
74394496 1149 if (!(mp->m_flags & XFS_MOUNT_RDONLY))
7e20694d 1150 error = xfs_sync(mp, SYNC_FSDATA | SYNC_BDFLUSH | SYNC_ATTR);
74394496
CH
1151 mp->m_sync_seq++;
1152 wake_up(&mp->m_wait_single_sync_task);
1da177e4
LT
1153}
1154
1155STATIC int
1156xfssyncd(
1157 void *arg)
1158{
74394496 1159 struct xfs_mount *mp = arg;
1da177e4 1160 long timeleft;
b83bd138 1161 bhv_vfs_sync_work_t *work, *n;
4df08c52 1162 LIST_HEAD (tmp);
1da177e4 1163
83144186 1164 set_freezable();
041e0e3b 1165 timeleft = xfs_syncd_centisecs * msecs_to_jiffies(10);
1da177e4 1166 for (;;) {
041e0e3b 1167 timeleft = schedule_timeout_interruptible(timeleft);
1da177e4 1168 /* swsusp */
3e1d1d28 1169 try_to_freeze();
74394496 1170 if (kthread_should_stop() && list_empty(&mp->m_sync_list))
1da177e4
LT
1171 break;
1172
74394496 1173 spin_lock(&mp->m_sync_lock);
1da177e4
LT
1174 /*
1175 * We can get woken by laptop mode, to do a sync -
1176 * that's the (only!) case where the list would be
1177 * empty with time remaining.
1178 */
74394496 1179 if (!timeleft || list_empty(&mp->m_sync_list)) {
1da177e4 1180 if (!timeleft)
041e0e3b
NA
1181 timeleft = xfs_syncd_centisecs *
1182 msecs_to_jiffies(10);
74394496
CH
1183 INIT_LIST_HEAD(&mp->m_sync_work.w_list);
1184 list_add_tail(&mp->m_sync_work.w_list,
1185 &mp->m_sync_list);
1da177e4 1186 }
74394496 1187 list_for_each_entry_safe(work, n, &mp->m_sync_list, w_list)
1da177e4 1188 list_move(&work->w_list, &tmp);
74394496 1189 spin_unlock(&mp->m_sync_lock);
1da177e4
LT
1190
1191 list_for_each_entry_safe(work, n, &tmp, w_list) {
74394496 1192 (*work->w_syncer)(mp, work->w_data);
1da177e4 1193 list_del(&work->w_list);
74394496 1194 if (work == &mp->m_sync_work)
1da177e4 1195 continue;
f0e2d93c 1196 kmem_free(work);
1da177e4
LT
1197 }
1198 }
1199
1da177e4
LT
1200 return 0;
1201}
1202
a738159d
CH
1203STATIC void
1204xfs_free_fsname(
1205 struct xfs_mount *mp)
1206{
1207 kfree(mp->m_fsname);
1208 kfree(mp->m_rtname);
1209 kfree(mp->m_logname);
1210}
1211
1da177e4 1212STATIC void
a50cd269 1213xfs_fs_put_super(
1da177e4
LT
1214 struct super_block *sb)
1215{
745f6919 1216 struct xfs_mount *mp = XFS_M(sb);
e48ad316
CH
1217 struct xfs_inode *rip = mp->m_rootip;
1218 int unmount_event_flags = 0;
1da177e4
LT
1219 int error;
1220
74394496
CH
1221 kthread_stop(mp->m_sync_task);
1222
745f6919 1223 xfs_sync(mp, SYNC_ATTR | SYNC_DELWRI);
e48ad316
CH
1224
1225#ifdef HAVE_DMAPI
1226 if (mp->m_flags & XFS_MOUNT_DMAPI) {
1227 unmount_event_flags =
1228 (mp->m_dmevmask & (1 << DM_EVENT_UNMOUNT)) ?
1229 0 : DM_FLAGS_UNWANTED;
1230 /*
1231 * Ignore error from dmapi here, first unmount is not allowed
1232 * to fail anyway, and second we wouldn't want to fail a
1233 * unmount because of dmapi.
1234 */
1235 XFS_SEND_PREUNMOUNT(mp, rip, DM_RIGHT_NULL, rip, DM_RIGHT_NULL,
1236 NULL, NULL, 0, 0, unmount_event_flags);
1237 }
1238#endif
1239
1240 /*
1241 * Blow away any referenced inode in the filestreams cache.
1242 * This can and will cause log traffic as inodes go inactive
1243 * here.
1244 */
1245 xfs_filestream_unmount(mp);
1246
1247 XFS_bflush(mp->m_ddev_targp);
1248 error = xfs_unmount_flush(mp, 0);
1249 WARN_ON(error);
1250
1251 IRELE(rip);
1252
1253 /*
1254 * If we're forcing a shutdown, typically because of a media error,
1255 * we want to make sure we invalidate dirty pages that belong to
1256 * referenced vnodes as well.
1257 */
1258 if (XFS_FORCED_SHUTDOWN(mp)) {
1259 error = xfs_sync(mp, SYNC_WAIT | SYNC_CLOSE);
1260 ASSERT(error != EFSCORRUPTED);
1261 }
1262
1263 if (mp->m_flags & XFS_MOUNT_DMAPI) {
1264 XFS_SEND_UNMOUNT(mp, rip, DM_RIGHT_NULL, 0, 0,
1265 unmount_event_flags);
1266 }
1267
19f354d4 1268 xfs_unmountfs(mp);
c962fb79 1269 xfs_icsb_destroy_counters(mp);
19f354d4 1270 xfs_close_devices(mp);
e48ad316
CH
1271 xfs_qmops_put(mp);
1272 xfs_dmops_put(mp);
a738159d 1273 xfs_free_fsname(mp);
c962fb79 1274 kfree(mp);
1da177e4
LT
1275}
1276
1277STATIC void
a50cd269 1278xfs_fs_write_super(
1da177e4
LT
1279 struct super_block *sb)
1280{
b83bd138 1281 if (!(sb->s_flags & MS_RDONLY))
745f6919 1282 xfs_sync(XFS_M(sb), SYNC_FSDATA);
1da177e4
LT
1283 sb->s_dirt = 0;
1284}
1285
1286STATIC int
a50cd269 1287xfs_fs_sync_super(
1da177e4
LT
1288 struct super_block *sb,
1289 int wait)
1290{
745f6919 1291 struct xfs_mount *mp = XFS_M(sb);
b83bd138
NS
1292 int error;
1293 int flags;
1da177e4 1294
e893bffd
LM
1295 /*
1296 * Treat a sync operation like a freeze. This is to work
1297 * around a race in sync_inodes() which works in two phases
1298 * - an asynchronous flush, which can write out an inode
1299 * without waiting for file size updates to complete, and a
1300 * synchronous flush, which wont do anything because the
1301 * async flush removed the inode's dirty flag. Also
1302 * sync_inodes() will not see any files that just have
1303 * outstanding transactions to be flushed because we don't
1304 * dirty the Linux inode until after the transaction I/O
1305 * completes.
1306 */
1307 if (wait || unlikely(sb->s_frozen == SB_FREEZE_WRITE)) {
2823945f
DC
1308 /*
1309 * First stage of freeze - no more writers will make progress
1310 * now we are here, so we flush delwri and delalloc buffers
1311 * here, then wait for all I/O to complete. Data is frozen at
1312 * that point. Metadata is not frozen, transactions can still
1313 * occur here so don't bother flushing the buftarg (i.e
1314 * SYNC_QUIESCE) because it'll just get dirty again.
1315 */
516b2e7c 1316 flags = SYNC_DATA_QUIESCE;
2823945f 1317 } else
e893bffd 1318 flags = SYNC_FSDATA;
1da177e4 1319
745f6919 1320 error = xfs_sync(mp, flags);
1da177e4
LT
1321 sb->s_dirt = 0;
1322
1323 if (unlikely(laptop_mode)) {
74394496 1324 int prev_sync_seq = mp->m_sync_seq;
1da177e4
LT
1325
1326 /*
1327 * The disk must be active because we're syncing.
1328 * We schedule xfssyncd now (now that the disk is
1329 * active) instead of later (when it might not be).
1330 */
74394496 1331 wake_up_process(mp->m_sync_task);
1da177e4
LT
1332 /*
1333 * We have to wait for the sync iteration to complete.
1334 * If we don't, the disk activity caused by the sync
1335 * will come after the sync is completed, and that
1336 * triggers another sync from laptop mode.
1337 */
74394496
CH
1338 wait_event(mp->m_wait_single_sync_task,
1339 mp->m_sync_seq != prev_sync_seq);
1da177e4
LT
1340 }
1341
1342 return -error;
1343}
1344
1345STATIC int
a50cd269 1346xfs_fs_statfs(
726c3342 1347 struct dentry *dentry,
1da177e4
LT
1348 struct kstatfs *statp)
1349{
4ca488eb
CH
1350 struct xfs_mount *mp = XFS_M(dentry->d_sb);
1351 xfs_sb_t *sbp = &mp->m_sb;
1352 __uint64_t fakeinos, id;
1353 xfs_extlen_t lsize;
1354
1355 statp->f_type = XFS_SB_MAGIC;
1356 statp->f_namelen = MAXNAMELEN - 1;
1357
1358 id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
1359 statp->f_fsid.val[0] = (u32)id;
1360 statp->f_fsid.val[1] = (u32)(id >> 32);
1361
d4d90b57 1362 xfs_icsb_sync_counters(mp, XFS_ICSB_LAZY_COUNT);
4ca488eb
CH
1363
1364 spin_lock(&mp->m_sb_lock);
1365 statp->f_bsize = sbp->sb_blocksize;
1366 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
1367 statp->f_blocks = sbp->sb_dblocks - lsize;
1368 statp->f_bfree = statp->f_bavail =
1369 sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
1370 fakeinos = statp->f_bfree << sbp->sb_inopblog;
1371#if XFS_BIG_INUMS
1372 fakeinos += mp->m_inoadd;
1373#endif
1374 statp->f_files =
1375 MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
1376 if (mp->m_maxicount)
1377#if XFS_BIG_INUMS
1378 if (!mp->m_inoadd)
1379#endif
1380 statp->f_files = min_t(typeof(statp->f_files),
1381 statp->f_files,
1382 mp->m_maxicount);
1383 statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
1384 spin_unlock(&mp->m_sb_lock);
1385
1386 XFS_QM_DQSTATVFS(XFS_I(dentry->d_inode), statp);
1387 return 0;
1da177e4
LT
1388}
1389
1390STATIC int
a50cd269 1391xfs_fs_remount(
1da177e4
LT
1392 struct super_block *sb,
1393 int *flags,
1394 char *options)
1395{
745f6919 1396 struct xfs_mount *mp = XFS_M(sb);
62a877e3
CH
1397 substring_t args[MAX_OPT_ARGS];
1398 char *p;
1da177e4 1399
62a877e3
CH
1400 while ((p = strsep(&options, ",")) != NULL) {
1401 int token;
bdd907ba 1402
62a877e3
CH
1403 if (!*p)
1404 continue;
48b62a1a 1405
62a877e3
CH
1406 token = match_token(p, tokens, args);
1407 switch (token) {
1408 case Opt_barrier:
48b62a1a 1409 mp->m_flags |= XFS_MOUNT_BARRIER;
62a877e3
CH
1410
1411 /*
1412 * Test if barriers are actually working if we can,
1413 * else delay this check until the filesystem is
1414 * marked writeable.
1415 */
1416 if (!(mp->m_flags & XFS_MOUNT_RDONLY))
1417 xfs_mountfs_check_barriers(mp);
1418 break;
1419 case Opt_nobarrier:
48b62a1a 1420 mp->m_flags &= ~XFS_MOUNT_BARRIER;
62a877e3
CH
1421 break;
1422 default:
1423 printk(KERN_INFO
1424 "XFS: mount option \"%s\" not supported for remount\n", p);
1425 return -EINVAL;
48b62a1a 1426 }
62a877e3
CH
1427 }
1428
1429 /* rw/ro -> rw */
1430 if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(*flags & MS_RDONLY)) {
1431 mp->m_flags &= ~XFS_MOUNT_RDONLY;
1432 if (mp->m_flags & XFS_MOUNT_BARRIER)
1433 xfs_mountfs_check_barriers(mp);
1434 }
1435
1436 /* rw -> ro */
1437 if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (*flags & MS_RDONLY)) {
48b62a1a
CH
1438 xfs_filestream_flush(mp);
1439 xfs_sync(mp, SYNC_DATA_QUIESCE);
1440 xfs_attr_quiesce(mp);
1441 mp->m_flags |= XFS_MOUNT_RDONLY;
1442 }
1443
62a877e3 1444 return 0;
1da177e4
LT
1445}
1446
9909c4aa
CH
1447/*
1448 * Second stage of a freeze. The data is already frozen so we only
1449 * need to take care of themetadata. Once that's done write a dummy
1450 * record to dirty the log in case of a crash while frozen.
1451 */
1da177e4 1452STATIC void
a50cd269 1453xfs_fs_lockfs(
1da177e4
LT
1454 struct super_block *sb)
1455{
9909c4aa
CH
1456 struct xfs_mount *mp = XFS_M(sb);
1457
1458 xfs_attr_quiesce(mp);
1459 xfs_fs_log_dummy(mp);
1da177e4
LT
1460}
1461
1462STATIC int
a50cd269 1463xfs_fs_show_options(
1da177e4
LT
1464 struct seq_file *m,
1465 struct vfsmount *mnt)
1466{
745f6919 1467 return -xfs_showargs(XFS_M(mnt->mnt_sb), m);
1da177e4
LT
1468}
1469
ee34807a 1470STATIC int
a50cd269 1471xfs_fs_quotasync(
ee34807a
NS
1472 struct super_block *sb,
1473 int type)
1474{
b09cc771 1475 return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XQUOTASYNC, 0, NULL);
ee34807a
NS
1476}
1477
1da177e4 1478STATIC int
a50cd269 1479xfs_fs_getxstate(
1da177e4
LT
1480 struct super_block *sb,
1481 struct fs_quota_stat *fqs)
1482{
b09cc771 1483 return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XGETQSTAT, 0, (caddr_t)fqs);
1da177e4
LT
1484}
1485
1486STATIC int
a50cd269 1487xfs_fs_setxstate(
1da177e4
LT
1488 struct super_block *sb,
1489 unsigned int flags,
1490 int op)
1491{
b09cc771 1492 return -XFS_QM_QUOTACTL(XFS_M(sb), op, 0, (caddr_t)&flags);
1da177e4
LT
1493}
1494
1495STATIC int
a50cd269 1496xfs_fs_getxquota(
1da177e4
LT
1497 struct super_block *sb,
1498 int type,
1499 qid_t id,
1500 struct fs_disk_quota *fdq)
1501{
b09cc771 1502 return -XFS_QM_QUOTACTL(XFS_M(sb),
b83bd138
NS
1503 (type == USRQUOTA) ? Q_XGETQUOTA :
1504 ((type == GRPQUOTA) ? Q_XGETGQUOTA :
1505 Q_XGETPQUOTA), id, (caddr_t)fdq);
1da177e4
LT
1506}
1507
1508STATIC int
a50cd269 1509xfs_fs_setxquota(
1da177e4
LT
1510 struct super_block *sb,
1511 int type,
1512 qid_t id,
1513 struct fs_disk_quota *fdq)
1514{
b09cc771 1515 return -XFS_QM_QUOTACTL(XFS_M(sb),
b83bd138
NS
1516 (type == USRQUOTA) ? Q_XSETQLIM :
1517 ((type == GRPQUOTA) ? Q_XSETGQLIM :
1518 Q_XSETPQLIM), id, (caddr_t)fdq);
1da177e4
LT
1519}
1520
f8f15e42
CH
1521/*
1522 * This function fills in xfs_mount_t fields based on mount args.
1523 * Note: the superblock has _not_ yet been read in.
1524 */
1525STATIC int
1526xfs_start_flags(
1527 struct xfs_mount_args *ap,
1528 struct xfs_mount *mp)
1529{
a738159d
CH
1530 int error;
1531
f8f15e42
CH
1532 /* Values are in BBs */
1533 if ((ap->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
1534 /*
1535 * At this point the superblock has not been read
1536 * in, therefore we do not know the block size.
1537 * Before the mount call ends we will convert
1538 * these to FSBs.
1539 */
1540 mp->m_dalign = ap->sunit;
1541 mp->m_swidth = ap->swidth;
1542 }
1543
1544 if (ap->logbufs != -1 &&
1545 ap->logbufs != 0 &&
1546 (ap->logbufs < XLOG_MIN_ICLOGS ||
1547 ap->logbufs > XLOG_MAX_ICLOGS)) {
1548 cmn_err(CE_WARN,
1549 "XFS: invalid logbufs value: %d [not %d-%d]",
1550 ap->logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
1551 return XFS_ERROR(EINVAL);
1552 }
1553 mp->m_logbufs = ap->logbufs;
1554 if (ap->logbufsize != -1 &&
1555 ap->logbufsize != 0 &&
1556 (ap->logbufsize < XLOG_MIN_RECORD_BSIZE ||
1557 ap->logbufsize > XLOG_MAX_RECORD_BSIZE ||
1558 !is_power_of_2(ap->logbufsize))) {
1559 cmn_err(CE_WARN,
1560 "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
1561 ap->logbufsize);
1562 return XFS_ERROR(EINVAL);
1563 }
a738159d
CH
1564
1565 error = ENOMEM;
1566
f8f15e42
CH
1567 mp->m_logbsize = ap->logbufsize;
1568 mp->m_fsname_len = strlen(ap->fsname) + 1;
a738159d
CH
1569
1570 mp->m_fsname = kstrdup(ap->fsname, GFP_KERNEL);
1571 if (!mp->m_fsname)
1572 goto out;
1573
f8f15e42 1574 if (ap->rtname[0]) {
a738159d
CH
1575 mp->m_rtname = kstrdup(ap->rtname, GFP_KERNEL);
1576 if (!mp->m_rtname)
1577 goto out_free_fsname;
1578
f8f15e42 1579 }
a738159d 1580
f8f15e42 1581 if (ap->logname[0]) {
a738159d
CH
1582 mp->m_logname = kstrdup(ap->logname, GFP_KERNEL);
1583 if (!mp->m_logname)
1584 goto out_free_rtname;
f8f15e42
CH
1585 }
1586
1587 if (ap->flags & XFSMNT_WSYNC)
1588 mp->m_flags |= XFS_MOUNT_WSYNC;
1589#if XFS_BIG_INUMS
1590 if (ap->flags & XFSMNT_INO64) {
1591 mp->m_flags |= XFS_MOUNT_INO64;
1592 mp->m_inoadd = XFS_INO64_OFFSET;
1593 }
1594#endif
1595 if (ap->flags & XFSMNT_RETERR)
1596 mp->m_flags |= XFS_MOUNT_RETERR;
1597 if (ap->flags & XFSMNT_NOALIGN)
1598 mp->m_flags |= XFS_MOUNT_NOALIGN;
1599 if (ap->flags & XFSMNT_SWALLOC)
1600 mp->m_flags |= XFS_MOUNT_SWALLOC;
1601 if (ap->flags & XFSMNT_OSYNCISOSYNC)
1602 mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
1603 if (ap->flags & XFSMNT_32BITINODES)
1604 mp->m_flags |= XFS_MOUNT_32BITINODES;
1605
1606 if (ap->flags & XFSMNT_IOSIZE) {
1607 if (ap->iosizelog > XFS_MAX_IO_LOG ||
1608 ap->iosizelog < XFS_MIN_IO_LOG) {
1609 cmn_err(CE_WARN,
1610 "XFS: invalid log iosize: %d [not %d-%d]",
1611 ap->iosizelog, XFS_MIN_IO_LOG,
1612 XFS_MAX_IO_LOG);
1613 return XFS_ERROR(EINVAL);
1614 }
1615
1616 mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
1617 mp->m_readio_log = mp->m_writeio_log = ap->iosizelog;
1618 }
1619
1620 if (ap->flags & XFSMNT_IKEEP)
1621 mp->m_flags |= XFS_MOUNT_IKEEP;
1622 if (ap->flags & XFSMNT_DIRSYNC)
1623 mp->m_flags |= XFS_MOUNT_DIRSYNC;
1624 if (ap->flags & XFSMNT_ATTR2)
1625 mp->m_flags |= XFS_MOUNT_ATTR2;
1626 if (ap->flags & XFSMNT_NOATTR2)
1627 mp->m_flags |= XFS_MOUNT_NOATTR2;
1628
1629 if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
1630 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
1631
1632 /*
1633 * no recovery flag requires a read-only mount
1634 */
1635 if (ap->flags & XFSMNT_NORECOVERY) {
1636 if (!(mp->m_flags & XFS_MOUNT_RDONLY)) {
1637 cmn_err(CE_WARN,
1638 "XFS: tried to mount a FS read-write without recovery!");
1639 return XFS_ERROR(EINVAL);
1640 }
1641 mp->m_flags |= XFS_MOUNT_NORECOVERY;
1642 }
1643
1644 if (ap->flags & XFSMNT_NOUUID)
1645 mp->m_flags |= XFS_MOUNT_NOUUID;
1646 if (ap->flags & XFSMNT_BARRIER)
1647 mp->m_flags |= XFS_MOUNT_BARRIER;
1648 else
1649 mp->m_flags &= ~XFS_MOUNT_BARRIER;
1650
1651 if (ap->flags2 & XFSMNT2_FILESTREAMS)
1652 mp->m_flags |= XFS_MOUNT_FILESTREAMS;
1653
1654 if (ap->flags & XFSMNT_DMAPI)
1655 mp->m_flags |= XFS_MOUNT_DMAPI;
1656 return 0;
a738159d
CH
1657
1658
1659 out_free_rtname:
1660 kfree(mp->m_rtname);
1661 out_free_fsname:
1662 kfree(mp->m_fsname);
1663 out:
1664 return error;
f8f15e42
CH
1665}
1666
1667/*
1668 * This function fills in xfs_mount_t fields based on mount args.
1669 * Note: the superblock _has_ now been read in.
1670 */
1671STATIC int
1672xfs_finish_flags(
1673 struct xfs_mount_args *ap,
1674 struct xfs_mount *mp)
1675{
1676 int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
1677
1678 /* Fail a mount where the logbuf is smaller then the log stripe */
1679 if (xfs_sb_version_haslogv2(&mp->m_sb)) {
1680 if ((ap->logbufsize <= 0) &&
1681 (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) {
1682 mp->m_logbsize = mp->m_sb.sb_logsunit;
1683 } else if (ap->logbufsize > 0 &&
1684 ap->logbufsize < mp->m_sb.sb_logsunit) {
1685 cmn_err(CE_WARN,
1686 "XFS: logbuf size must be greater than or equal to log stripe size");
1687 return XFS_ERROR(EINVAL);
1688 }
1689 } else {
1690 /* Fail a mount if the logbuf is larger than 32K */
1691 if (ap->logbufsize > XLOG_BIG_RECORD_BSIZE) {
1692 cmn_err(CE_WARN,
1693 "XFS: logbuf size for version 1 logs must be 16K or 32K");
1694 return XFS_ERROR(EINVAL);
1695 }
1696 }
1697
1698 /*
1699 * mkfs'ed attr2 will turn on attr2 mount unless explicitly
1700 * told by noattr2 to turn it off
1701 */
1702 if (xfs_sb_version_hasattr2(&mp->m_sb) &&
1703 !(ap->flags & XFSMNT_NOATTR2))
1704 mp->m_flags |= XFS_MOUNT_ATTR2;
1705
1706 /*
1707 * prohibit r/w mounts of read-only filesystems
1708 */
1709 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
1710 cmn_err(CE_WARN,
1711 "XFS: cannot mount a read-only filesystem as read-write");
1712 return XFS_ERROR(EROFS);
1713 }
1714
1715 /*
1716 * check for shared mount.
1717 */
1718 if (ap->flags & XFSMNT_SHARED) {
1719 if (!xfs_sb_version_hasshared(&mp->m_sb))
1720 return XFS_ERROR(EINVAL);
1721
1722 /*
1723 * For IRIX 6.5, shared mounts must have the shared
1724 * version bit set, have the persistent readonly
1725 * field set, must be version 0 and can only be mounted
1726 * read-only.
1727 */
1728 if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) ||
1729 (mp->m_sb.sb_shared_vn != 0))
1730 return XFS_ERROR(EINVAL);
1731
1732 mp->m_flags |= XFS_MOUNT_SHARED;
1733
1734 /*
1735 * Shared XFS V0 can't deal with DMI. Return EINVAL.
1736 */
1737 if (mp->m_sb.sb_shared_vn == 0 && (ap->flags & XFSMNT_DMAPI))
1738 return XFS_ERROR(EINVAL);
1739 }
1740
1741 if (ap->flags & XFSMNT_UQUOTA) {
1742 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
1743 if (ap->flags & XFSMNT_UQUOTAENF)
1744 mp->m_qflags |= XFS_UQUOTA_ENFD;
1745 }
1746
1747 if (ap->flags & XFSMNT_GQUOTA) {
1748 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
1749 if (ap->flags & XFSMNT_GQUOTAENF)
1750 mp->m_qflags |= XFS_OQUOTA_ENFD;
1751 } else if (ap->flags & XFSMNT_PQUOTA) {
1752 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
1753 if (ap->flags & XFSMNT_PQUOTAENF)
1754 mp->m_qflags |= XFS_OQUOTA_ENFD;
1755 }
1756
1757 return 0;
1758}
1759
1da177e4 1760STATIC int
a50cd269 1761xfs_fs_fill_super(
1da177e4
LT
1762 struct super_block *sb,
1763 void *data,
1764 int silent)
1765{
f3dcc13f 1766 struct inode *root;
745f6919 1767 struct xfs_mount *mp = NULL;
bdd907ba 1768 struct xfs_mount_args *args;
c962fb79 1769 int flags = 0, error = ENOMEM;
1da177e4 1770
bdd907ba
CH
1771 args = xfs_args_allocate(sb, silent);
1772 if (!args)
1773 return -ENOMEM;
1774
c962fb79
CH
1775 mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
1776 if (!mp)
1777 goto out_free_args;
1da177e4 1778
c962fb79
CH
1779 spin_lock_init(&mp->m_sb_lock);
1780 mutex_init(&mp->m_ilock);
1781 mutex_init(&mp->m_growlock);
1782 atomic_set(&mp->m_active_trans, 0);
74394496
CH
1783 INIT_LIST_HEAD(&mp->m_sync_list);
1784 spin_lock_init(&mp->m_sync_lock);
1785 init_waitqueue_head(&mp->m_wait_single_sync_task);
1786
b267ce99
CH
1787 mp->m_super = sb;
1788 sb->s_fs_info = mp;
1da177e4 1789
bd186aa9
CH
1790 if (sb->s_flags & MS_RDONLY)
1791 mp->m_flags |= XFS_MOUNT_RDONLY;
1792
745f6919
CH
1793 error = xfs_parseargs(mp, (char *)data, args, 0);
1794 if (error)
c962fb79 1795 goto out_free_mp;
1da177e4
LT
1796
1797 sb_min_blocksize(sb, BBSIZE);
0ec58516 1798 sb->s_xattr = xfs_xattr_handlers;
a50cd269 1799 sb->s_export_op = &xfs_export_operations;
a50cd269
NS
1800 sb->s_qcop = &xfs_quotactl_operations;
1801 sb->s_op = &xfs_super_operations;
1da177e4 1802
f8f15e42
CH
1803 error = xfs_dmops_get(mp, args);
1804 if (error)
c962fb79 1805 goto out_free_mp;
f8f15e42 1806 error = xfs_qmops_get(mp, args);
745f6919 1807 if (error)
19f354d4 1808 goto out_put_dmops;
1da177e4 1809
f8f15e42
CH
1810 if (args->flags & XFSMNT_QUIET)
1811 flags |= XFS_MFSI_QUIET;
1812
19f354d4
CH
1813 error = xfs_open_devices(mp, args);
1814 if (error)
1815 goto out_put_qmops;
f8f15e42 1816
c962fb79
CH
1817 if (xfs_icsb_init_counters(mp))
1818 mp->m_flags |= XFS_MOUNT_NO_PERCPU_SB;
1819
f8f15e42
CH
1820 /*
1821 * Setup flags based on mount(2) options and then the superblock
1822 */
1823 error = xfs_start_flags(args, mp);
1824 if (error)
a738159d 1825 goto out_free_fsname;
f8f15e42
CH
1826 error = xfs_readsb(mp, flags);
1827 if (error)
a738159d 1828 goto out_free_fsname;
f8f15e42
CH
1829 error = xfs_finish_flags(args, mp);
1830 if (error)
effa2eda 1831 goto out_free_sb;
f8f15e42 1832
e34b562c 1833 error = xfs_setup_devices(mp);
19f354d4 1834 if (error)
effa2eda 1835 goto out_free_sb;
f8f15e42
CH
1836
1837 if (mp->m_flags & XFS_MOUNT_BARRIER)
1838 xfs_mountfs_check_barriers(mp);
1839
1840 error = xfs_filestream_mount(mp);
1841 if (error)
effa2eda 1842 goto out_free_sb;
f8f15e42
CH
1843
1844 error = xfs_mountfs(mp, flags);
1845 if (error)
120226c1 1846 goto out_filestream_unmount;
f8f15e42
CH
1847
1848 XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, args->mtpt, args->fsname);
1849
1da177e4 1850 sb->s_dirt = 1;
4ca488eb
CH
1851 sb->s_magic = XFS_SB_MAGIC;
1852 sb->s_blocksize = mp->m_sb.sb_blocksize;
1853 sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
1da177e4
LT
1854 sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
1855 sb->s_time_gran = 1;
1856 set_posix_acl_flag(sb);
1857
01651646 1858 root = igrab(VFS_I(mp->m_rootip));
f3dcc13f 1859 if (!root) {
cbc89dcf 1860 error = ENOENT;
1da177e4 1861 goto fail_unmount;
cbc89dcf 1862 }
f3dcc13f
CH
1863 if (is_bad_inode(root)) {
1864 error = EINVAL;
1da177e4
LT
1865 goto fail_vnrele;
1866 }
f3dcc13f
CH
1867 sb->s_root = d_alloc_root(root);
1868 if (!sb->s_root) {
1869 error = ENOMEM;
1da177e4
LT
1870 goto fail_vnrele;
1871 }
74394496
CH
1872
1873 mp->m_sync_work.w_syncer = xfs_sync_worker;
1874 mp->m_sync_work.w_mount = mp;
1875 mp->m_sync_task = kthread_run(xfssyncd, mp, "xfssyncd");
1876 if (IS_ERR(mp->m_sync_task)) {
1877 error = -PTR_ERR(mp->m_sync_task);
1da177e4 1878 goto fail_vnrele;
74394496
CH
1879 }
1880
cf441eeb 1881 xfs_itrace_exit(XFS_I(sb->s_root->d_inode));
1da177e4 1882
bdd907ba 1883 kfree(args);
1da177e4
LT
1884 return 0;
1885
120226c1
CH
1886 out_filestream_unmount:
1887 xfs_filestream_unmount(mp);
effa2eda
CH
1888 out_free_sb:
1889 xfs_freesb(mp);
a738159d
CH
1890 out_free_fsname:
1891 xfs_free_fsname(mp);
c962fb79 1892 xfs_icsb_destroy_counters(mp);
19f354d4
CH
1893 xfs_close_devices(mp);
1894 out_put_qmops:
f8f15e42 1895 xfs_qmops_put(mp);
19f354d4 1896 out_put_dmops:
f8f15e42 1897 xfs_dmops_put(mp);
c962fb79
CH
1898 out_free_mp:
1899 kfree(mp);
1900 out_free_args:
1901 kfree(args);
1902 return -error;
f8f15e42
CH
1903
1904 fail_vnrele:
1da177e4
LT
1905 if (sb->s_root) {
1906 dput(sb->s_root);
1907 sb->s_root = NULL;
1908 } else {
f3dcc13f 1909 iput(root);
1da177e4
LT
1910 }
1911
f8f15e42 1912 fail_unmount:
e48ad316
CH
1913 /*
1914 * Blow away any referenced inode in the filestreams cache.
1915 * This can and will cause log traffic as inodes go inactive
1916 * here.
1917 */
1918 xfs_filestream_unmount(mp);
1919
1920 XFS_bflush(mp->m_ddev_targp);
1921 error = xfs_unmount_flush(mp, 0);
1922 WARN_ON(error);
1923
1924 IRELE(mp->m_rootip);
1925
19f354d4 1926 xfs_unmountfs(mp);
a738159d 1927 goto out_free_fsname;
1da177e4
LT
1928}
1929
454e2398 1930STATIC int
a50cd269 1931xfs_fs_get_sb(
1da177e4
LT
1932 struct file_system_type *fs_type,
1933 int flags,
1934 const char *dev_name,
454e2398
DH
1935 void *data,
1936 struct vfsmount *mnt)
1da177e4 1937{
454e2398
DH
1938 return get_sb_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super,
1939 mnt);
a50cd269
NS
1940}
1941
7989cb8e 1942static struct super_operations xfs_super_operations = {
a50cd269
NS
1943 .alloc_inode = xfs_fs_alloc_inode,
1944 .destroy_inode = xfs_fs_destroy_inode,
1945 .write_inode = xfs_fs_write_inode,
1946 .clear_inode = xfs_fs_clear_inode,
1947 .put_super = xfs_fs_put_super,
1948 .write_super = xfs_fs_write_super,
1949 .sync_fs = xfs_fs_sync_super,
1950 .write_super_lockfs = xfs_fs_lockfs,
1951 .statfs = xfs_fs_statfs,
1952 .remount_fs = xfs_fs_remount,
1953 .show_options = xfs_fs_show_options,
1da177e4
LT
1954};
1955
7989cb8e 1956static struct quotactl_ops xfs_quotactl_operations = {
a50cd269
NS
1957 .quota_sync = xfs_fs_quotasync,
1958 .get_xstate = xfs_fs_getxstate,
1959 .set_xstate = xfs_fs_setxstate,
1960 .get_xquota = xfs_fs_getxquota,
1961 .set_xquota = xfs_fs_setxquota,
1da177e4
LT
1962};
1963
5085b607 1964static struct file_system_type xfs_fs_type = {
1da177e4
LT
1965 .owner = THIS_MODULE,
1966 .name = "xfs",
a50cd269 1967 .get_sb = xfs_fs_get_sb,
1da177e4
LT
1968 .kill_sb = kill_block_super,
1969 .fs_flags = FS_REQUIRES_DEV,
1970};
1971
9f8868ff
CH
1972STATIC int __init
1973xfs_alloc_trace_bufs(void)
1974{
1975#ifdef XFS_ALLOC_TRACE
1976 xfs_alloc_trace_buf = ktrace_alloc(XFS_ALLOC_TRACE_SIZE, KM_MAYFAIL);
1977 if (!xfs_alloc_trace_buf)
1978 goto out;
1979#endif
1980#ifdef XFS_BMAP_TRACE
1981 xfs_bmap_trace_buf = ktrace_alloc(XFS_BMAP_TRACE_SIZE, KM_MAYFAIL);
1982 if (!xfs_bmap_trace_buf)
1983 goto out_free_alloc_trace;
1984#endif
1985#ifdef XFS_BMBT_TRACE
1986 xfs_bmbt_trace_buf = ktrace_alloc(XFS_BMBT_TRACE_SIZE, KM_MAYFAIL);
1987 if (!xfs_bmbt_trace_buf)
1988 goto out_free_bmap_trace;
1989#endif
1990#ifdef XFS_ATTR_TRACE
1991 xfs_attr_trace_buf = ktrace_alloc(XFS_ATTR_TRACE_SIZE, KM_MAYFAIL);
1992 if (!xfs_attr_trace_buf)
1993 goto out_free_bmbt_trace;
1994#endif
1995#ifdef XFS_DIR2_TRACE
1996 xfs_dir2_trace_buf = ktrace_alloc(XFS_DIR2_GTRACE_SIZE, KM_MAYFAIL);
1997 if (!xfs_dir2_trace_buf)
1998 goto out_free_attr_trace;
1999#endif
2000
2001 return 0;
2002
2003#ifdef XFS_DIR2_TRACE
2004 out_free_attr_trace:
2005#endif
2006#ifdef XFS_ATTR_TRACE
2007 ktrace_free(xfs_attr_trace_buf);
2008 out_free_bmbt_trace:
2009#endif
2010#ifdef XFS_BMBT_TRACE
2011 ktrace_free(xfs_bmbt_trace_buf);
2012 out_free_bmap_trace:
2013#endif
2014#ifdef XFS_BMAP_TRACE
2015 ktrace_free(xfs_bmap_trace_buf);
2016 out_free_alloc_trace:
2017#endif
2018#ifdef XFS_ALLOC_TRACE
2019 ktrace_free(xfs_alloc_trace_buf);
2020 out:
2021#endif
2022 return -ENOMEM;
2023}
2024
2025STATIC void
2026xfs_free_trace_bufs(void)
2027{
2028#ifdef XFS_DIR2_TRACE
2029 ktrace_free(xfs_dir2_trace_buf);
2030#endif
2031#ifdef XFS_ATTR_TRACE
2032 ktrace_free(xfs_attr_trace_buf);
2033#endif
2034#ifdef XFS_BMBT_TRACE
2035 ktrace_free(xfs_bmbt_trace_buf);
2036#endif
2037#ifdef XFS_BMAP_TRACE
2038 ktrace_free(xfs_bmap_trace_buf);
2039#endif
2040#ifdef XFS_ALLOC_TRACE
2041 ktrace_free(xfs_alloc_trace_buf);
2042#endif
2043}
2044
2045STATIC int __init
2046xfs_init_zones(void)
2047{
2048 xfs_vnode_zone = kmem_zone_init_flags(sizeof(bhv_vnode_t), "xfs_vnode",
2049 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM |
2050 KM_ZONE_SPREAD,
2051 xfs_fs_inode_init_once);
2052 if (!xfs_vnode_zone)
2053 goto out;
2054
2055 xfs_ioend_zone = kmem_zone_init(sizeof(xfs_ioend_t), "xfs_ioend");
2056 if (!xfs_ioend_zone)
2057 goto out_destroy_vnode_zone;
2058
2059 xfs_ioend_pool = mempool_create_slab_pool(4 * MAX_BUF_PER_PAGE,
2060 xfs_ioend_zone);
2061 if (!xfs_ioend_pool)
2062 goto out_destroy_ioend_zone;
2063
2064 xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t),
2065 "xfs_log_ticket");
2066 if (!xfs_log_ticket_zone)
2067 goto out_destroy_ioend_pool;
2068
2069 xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
2070 "xfs_bmap_free_item");
2071 if (!xfs_bmap_free_item_zone)
2072 goto out_destroy_log_ticket_zone;
2073 xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
2074 "xfs_btree_cur");
2075 if (!xfs_btree_cur_zone)
2076 goto out_destroy_bmap_free_item_zone;
2077
2078 xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t),
2079 "xfs_da_state");
2080 if (!xfs_da_state_zone)
2081 goto out_destroy_btree_cur_zone;
2082
2083 xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf");
2084 if (!xfs_dabuf_zone)
2085 goto out_destroy_da_state_zone;
2086
2087 xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
2088 if (!xfs_ifork_zone)
2089 goto out_destroy_dabuf_zone;
2090
2091 xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
2092 if (!xfs_trans_zone)
2093 goto out_destroy_ifork_zone;
2094
2095 /*
2096 * The size of the zone allocated buf log item is the maximum
2097 * size possible under XFS. This wastes a little bit of memory,
2098 * but it is much faster.
2099 */
2100 xfs_buf_item_zone = kmem_zone_init((sizeof(xfs_buf_log_item_t) +
2101 (((XFS_MAX_BLOCKSIZE / XFS_BLI_CHUNK) /
2102 NBWORD) * sizeof(int))), "xfs_buf_item");
2103 if (!xfs_buf_item_zone)
2104 goto out_destroy_trans_zone;
2105
2106 xfs_efd_zone = kmem_zone_init((sizeof(xfs_efd_log_item_t) +
2107 ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
2108 sizeof(xfs_extent_t))), "xfs_efd_item");
2109 if (!xfs_efd_zone)
2110 goto out_destroy_buf_item_zone;
2111
2112 xfs_efi_zone = kmem_zone_init((sizeof(xfs_efi_log_item_t) +
2113 ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
2114 sizeof(xfs_extent_t))), "xfs_efi_item");
2115 if (!xfs_efi_zone)
2116 goto out_destroy_efd_zone;
2117
2118 xfs_inode_zone =
2119 kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
2120 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM |
2121 KM_ZONE_SPREAD, NULL);
2122 if (!xfs_inode_zone)
2123 goto out_destroy_efi_zone;
2124
2125 xfs_ili_zone =
2126 kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
2127 KM_ZONE_SPREAD, NULL);
2128 if (!xfs_ili_zone)
2129 goto out_destroy_inode_zone;
2130
2131#ifdef CONFIG_XFS_POSIX_ACL
2132 xfs_acl_zone = kmem_zone_init(sizeof(xfs_acl_t), "xfs_acl");
2133 if (!xfs_acl_zone)
2134 goto out_destroy_ili_zone;
2135#endif
2136
2137 return 0;
2138
2139#ifdef CONFIG_XFS_POSIX_ACL
2140 out_destroy_ili_zone:
2141#endif
2142 kmem_zone_destroy(xfs_ili_zone);
2143 out_destroy_inode_zone:
2144 kmem_zone_destroy(xfs_inode_zone);
2145 out_destroy_efi_zone:
2146 kmem_zone_destroy(xfs_efi_zone);
2147 out_destroy_efd_zone:
2148 kmem_zone_destroy(xfs_efd_zone);
2149 out_destroy_buf_item_zone:
2150 kmem_zone_destroy(xfs_buf_item_zone);
2151 out_destroy_trans_zone:
2152 kmem_zone_destroy(xfs_trans_zone);
2153 out_destroy_ifork_zone:
2154 kmem_zone_destroy(xfs_ifork_zone);
2155 out_destroy_dabuf_zone:
2156 kmem_zone_destroy(xfs_dabuf_zone);
2157 out_destroy_da_state_zone:
2158 kmem_zone_destroy(xfs_da_state_zone);
2159 out_destroy_btree_cur_zone:
2160 kmem_zone_destroy(xfs_btree_cur_zone);
2161 out_destroy_bmap_free_item_zone:
2162 kmem_zone_destroy(xfs_bmap_free_item_zone);
2163 out_destroy_log_ticket_zone:
2164 kmem_zone_destroy(xfs_log_ticket_zone);
2165 out_destroy_ioend_pool:
2166 mempool_destroy(xfs_ioend_pool);
2167 out_destroy_ioend_zone:
2168 kmem_zone_destroy(xfs_ioend_zone);
2169 out_destroy_vnode_zone:
2170 kmem_zone_destroy(xfs_vnode_zone);
2171 out:
2172 return -ENOMEM;
2173}
2174
2175STATIC void
2176xfs_destroy_zones(void)
2177{
2178#ifdef CONFIG_XFS_POSIX_ACL
2179 kmem_zone_destroy(xfs_acl_zone);
2180#endif
2181 kmem_zone_destroy(xfs_ili_zone);
2182 kmem_zone_destroy(xfs_inode_zone);
2183 kmem_zone_destroy(xfs_efi_zone);
2184 kmem_zone_destroy(xfs_efd_zone);
2185 kmem_zone_destroy(xfs_buf_item_zone);
2186 kmem_zone_destroy(xfs_trans_zone);
2187 kmem_zone_destroy(xfs_ifork_zone);
2188 kmem_zone_destroy(xfs_dabuf_zone);
2189 kmem_zone_destroy(xfs_da_state_zone);
2190 kmem_zone_destroy(xfs_btree_cur_zone);
2191 kmem_zone_destroy(xfs_bmap_free_item_zone);
2192 kmem_zone_destroy(xfs_log_ticket_zone);
2193 mempool_destroy(xfs_ioend_pool);
2194 kmem_zone_destroy(xfs_ioend_zone);
2195 kmem_zone_destroy(xfs_vnode_zone);
2196
2197}
1da177e4
LT
2198
2199STATIC int __init
9f8868ff 2200init_xfs_fs(void)
1da177e4
LT
2201{
2202 int error;
1da177e4
LT
2203 static char message[] __initdata = KERN_INFO \
2204 XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled\n";
2205
2206 printk(message);
2207
1da177e4 2208 ktrace_init(64);
9f8868ff
CH
2209 vn_init();
2210 xfs_dir_startup();
1da177e4 2211
8758280f 2212 error = xfs_init_zones();
9f8868ff
CH
2213 if (error)
2214 goto out;
2215
2216 error = xfs_alloc_trace_bufs();
2217 if (error)
2218 goto out_destroy_zones;
2219
2220 error = xfs_mru_cache_init();
2221 if (error)
2222 goto out_free_trace_buffers;
2223
2224 error = xfs_filestream_init();
2225 if (error)
2226 goto out_mru_cache_uninit;
1da177e4 2227
ce8e922c 2228 error = xfs_buf_init();
9f8868ff
CH
2229 if (error)
2230 goto out_filestream_uninit;
2231
2232 error = xfs_init_procfs();
2233 if (error)
2234 goto out_buf_terminate;
2235
2236 error = xfs_sysctl_register();
2237 if (error)
2238 goto out_cleanup_procfs;
1da177e4 2239
1da177e4
LT
2240 vfs_initquota();
2241
2242 error = register_filesystem(&xfs_fs_type);
2243 if (error)
9f8868ff 2244 goto out_sysctl_unregister;
1da177e4
LT
2245 return 0;
2246
9f8868ff
CH
2247 out_sysctl_unregister:
2248 xfs_sysctl_unregister();
2249 out_cleanup_procfs:
2250 xfs_cleanup_procfs();
2251 out_buf_terminate:
ce8e922c 2252 xfs_buf_terminate();
9f8868ff
CH
2253 out_filestream_uninit:
2254 xfs_filestream_uninit();
2255 out_mru_cache_uninit:
2256 xfs_mru_cache_uninit();
2257 out_free_trace_buffers:
2258 xfs_free_trace_bufs();
2259 out_destroy_zones:
8758280f 2260 xfs_destroy_zones();
9f8868ff 2261 out:
1da177e4
LT
2262 return error;
2263}
2264
2265STATIC void __exit
9f8868ff 2266exit_xfs_fs(void)
1da177e4
LT
2267{
2268 vfs_exitquota();
1da177e4 2269 unregister_filesystem(&xfs_fs_type);
9f8868ff
CH
2270 xfs_sysctl_unregister();
2271 xfs_cleanup_procfs();
ce8e922c 2272 xfs_buf_terminate();
9f8868ff
CH
2273 xfs_filestream_uninit();
2274 xfs_mru_cache_uninit();
2275 xfs_free_trace_bufs();
8758280f 2276 xfs_destroy_zones();
1da177e4
LT
2277 ktrace_uninit();
2278}
2279
2280module_init(init_xfs_fs);
2281module_exit(exit_xfs_fs);
2282
2283MODULE_AUTHOR("Silicon Graphics, Inc.");
2284MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
2285MODULE_LICENSE("GPL");
This page took 0.522669 seconds and 5 git commands to generate.