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