]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - fs/xfs/linux-2.6/xfs_super.c
[XFS] Move AIL pushing into it's own thread
[mirror_ubuntu-bionic-kernel.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"
1da177e4
LT
55
56#include <linux/namei.h>
57#include <linux/init.h>
58#include <linux/mount.h>
0829c360 59#include <linux/mempool.h>
1da177e4 60#include <linux/writeback.h>
4df08c52 61#include <linux/kthread.h>
7dfb7103 62#include <linux/freezer.h>
1da177e4 63
7989cb8e
DC
64static struct quotactl_ops xfs_quotactl_operations;
65static struct super_operations xfs_super_operations;
66static kmem_zone_t *xfs_vnode_zone;
67static kmem_zone_t *xfs_ioend_zone;
0829c360 68mempool_t *xfs_ioend_pool;
1da177e4
LT
69
70STATIC struct xfs_mount_args *
71xfs_args_allocate(
764d1f89
NS
72 struct super_block *sb,
73 int silent)
1da177e4
LT
74{
75 struct xfs_mount_args *args;
76
77 args = kmem_zalloc(sizeof(struct xfs_mount_args), KM_SLEEP);
78 args->logbufs = args->logbufsize = -1;
79 strncpy(args->fsname, sb->s_id, MAXNAMELEN);
80
81 /* Copy the already-parsed mount(2) flags we're interested in */
1da177e4
LT
82 if (sb->s_flags & MS_DIRSYNC)
83 args->flags |= XFSMNT_DIRSYNC;
84 if (sb->s_flags & MS_SYNCHRONOUS)
85 args->flags |= XFSMNT_WSYNC;
764d1f89
NS
86 if (silent)
87 args->flags |= XFSMNT_QUIET;
1da177e4
LT
88 args->flags |= XFSMNT_32BITINODES;
89
90 return args;
91}
92
a67d7c5f
DC
93#define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
94#define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
95#define MNTOPT_LOGDEV "logdev" /* log device */
96#define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
97#define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
98#define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
99#define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
100#define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
101#define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
102#define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
103#define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
104#define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
105#define MNTOPT_MTPT "mtpt" /* filesystem mount point */
106#define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
107#define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
108#define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
109#define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
110#define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
111#define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
112#define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
113 * unwritten extent conversion */
114#define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
115#define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
116#define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
117#define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
118#define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
119#define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
120#define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
121 * in stat(). */
122#define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
123#define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
124#define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
125#define MNTOPT_QUOTA "quota" /* disk quotas (user) */
126#define MNTOPT_NOQUOTA "noquota" /* no quotas */
127#define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */
128#define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */
129#define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */
130#define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */
131#define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */
132#define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */
133#define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
134#define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
135#define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
136#define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */
137#define MNTOPT_DMAPI "dmapi" /* DMI enabled (DMAPI / XDSM) */
138#define MNTOPT_XDSM "xdsm" /* DMI enabled (DMAPI / XDSM) */
139#define MNTOPT_DMI "dmi" /* DMI enabled (DMAPI / XDSM) */
140
141STATIC unsigned long
142suffix_strtoul(char *s, char **endp, unsigned int base)
143{
144 int last, shift_left_factor = 0;
145 char *value = s;
146
147 last = strlen(value) - 1;
148 if (value[last] == 'K' || value[last] == 'k') {
149 shift_left_factor = 10;
150 value[last] = '\0';
151 }
152 if (value[last] == 'M' || value[last] == 'm') {
153 shift_left_factor = 20;
154 value[last] = '\0';
155 }
156 if (value[last] == 'G' || value[last] == 'g') {
157 shift_left_factor = 30;
158 value[last] = '\0';
159 }
160
161 return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
162}
163
164STATIC int
165xfs_parseargs(
166 struct xfs_mount *mp,
167 char *options,
168 struct xfs_mount_args *args,
169 int update)
170{
171 char *this_char, *value, *eov;
172 int dsunit, dswidth, vol_dsunit, vol_dswidth;
173 int iosize;
174 int ikeep = 0;
175
176 args->flags |= XFSMNT_BARRIER;
177 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
178
179 if (!options)
180 goto done;
181
182 iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0;
183
184 while ((this_char = strsep(&options, ",")) != NULL) {
185 if (!*this_char)
186 continue;
187 if ((value = strchr(this_char, '=')) != NULL)
188 *value++ = 0;
189
190 if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
191 if (!value || !*value) {
192 cmn_err(CE_WARN,
193 "XFS: %s option requires an argument",
194 this_char);
195 return EINVAL;
196 }
197 args->logbufs = simple_strtoul(value, &eov, 10);
198 } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
199 if (!value || !*value) {
200 cmn_err(CE_WARN,
201 "XFS: %s option requires an argument",
202 this_char);
203 return EINVAL;
204 }
205 args->logbufsize = suffix_strtoul(value, &eov, 10);
206 } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
207 if (!value || !*value) {
208 cmn_err(CE_WARN,
209 "XFS: %s option requires an argument",
210 this_char);
211 return EINVAL;
212 }
213 strncpy(args->logname, value, MAXNAMELEN);
214 } else if (!strcmp(this_char, MNTOPT_MTPT)) {
215 if (!value || !*value) {
216 cmn_err(CE_WARN,
217 "XFS: %s option requires an argument",
218 this_char);
219 return EINVAL;
220 }
221 strncpy(args->mtpt, value, MAXNAMELEN);
222 } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
223 if (!value || !*value) {
224 cmn_err(CE_WARN,
225 "XFS: %s option requires an argument",
226 this_char);
227 return EINVAL;
228 }
229 strncpy(args->rtname, value, MAXNAMELEN);
230 } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
231 if (!value || !*value) {
232 cmn_err(CE_WARN,
233 "XFS: %s option requires an argument",
234 this_char);
235 return EINVAL;
236 }
237 iosize = simple_strtoul(value, &eov, 10);
238 args->flags |= XFSMNT_IOSIZE;
239 args->iosizelog = (uint8_t) iosize;
240 } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
241 if (!value || !*value) {
242 cmn_err(CE_WARN,
243 "XFS: %s option requires an argument",
244 this_char);
245 return EINVAL;
246 }
247 iosize = suffix_strtoul(value, &eov, 10);
248 args->flags |= XFSMNT_IOSIZE;
249 args->iosizelog = ffs(iosize) - 1;
250 } else if (!strcmp(this_char, MNTOPT_GRPID) ||
251 !strcmp(this_char, MNTOPT_BSDGROUPS)) {
252 mp->m_flags |= XFS_MOUNT_GRPID;
253 } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
254 !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
255 mp->m_flags &= ~XFS_MOUNT_GRPID;
256 } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
257 args->flags |= XFSMNT_WSYNC;
258 } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
259 args->flags |= XFSMNT_OSYNCISOSYNC;
260 } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
261 args->flags |= XFSMNT_NORECOVERY;
262 } else if (!strcmp(this_char, MNTOPT_INO64)) {
263 args->flags |= XFSMNT_INO64;
264#if !XFS_BIG_INUMS
265 cmn_err(CE_WARN,
266 "XFS: %s option not allowed on this system",
267 this_char);
268 return EINVAL;
269#endif
270 } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
271 args->flags |= XFSMNT_NOALIGN;
272 } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
273 args->flags |= XFSMNT_SWALLOC;
274 } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
275 if (!value || !*value) {
276 cmn_err(CE_WARN,
277 "XFS: %s option requires an argument",
278 this_char);
279 return EINVAL;
280 }
281 dsunit = simple_strtoul(value, &eov, 10);
282 } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
283 if (!value || !*value) {
284 cmn_err(CE_WARN,
285 "XFS: %s option requires an argument",
286 this_char);
287 return EINVAL;
288 }
289 dswidth = simple_strtoul(value, &eov, 10);
290 } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
291 args->flags &= ~XFSMNT_32BITINODES;
292#if !XFS_BIG_INUMS
293 cmn_err(CE_WARN,
294 "XFS: %s option not allowed on this system",
295 this_char);
296 return EINVAL;
297#endif
298 } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
299 args->flags |= XFSMNT_NOUUID;
300 } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
301 args->flags |= XFSMNT_BARRIER;
302 } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
303 args->flags &= ~XFSMNT_BARRIER;
304 } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
305 ikeep = 1;
306 args->flags &= ~XFSMNT_IDELETE;
307 } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
308 args->flags |= XFSMNT_IDELETE;
309 } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
310 args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE;
311 } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
312 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
313 } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
314 args->flags |= XFSMNT_ATTR2;
315 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
316 args->flags &= ~XFSMNT_ATTR2;
317 } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
318 args->flags2 |= XFSMNT2_FILESTREAMS;
319 } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
320 args->flags &= ~(XFSMNT_UQUOTAENF|XFSMNT_UQUOTA);
321 args->flags &= ~(XFSMNT_GQUOTAENF|XFSMNT_GQUOTA);
322 } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
323 !strcmp(this_char, MNTOPT_UQUOTA) ||
324 !strcmp(this_char, MNTOPT_USRQUOTA)) {
325 args->flags |= XFSMNT_UQUOTA | XFSMNT_UQUOTAENF;
326 } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
327 !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
328 args->flags |= XFSMNT_UQUOTA;
329 args->flags &= ~XFSMNT_UQUOTAENF;
330 } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
331 !strcmp(this_char, MNTOPT_PRJQUOTA)) {
332 args->flags |= XFSMNT_PQUOTA | XFSMNT_PQUOTAENF;
333 } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
334 args->flags |= XFSMNT_PQUOTA;
335 args->flags &= ~XFSMNT_PQUOTAENF;
336 } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
337 !strcmp(this_char, MNTOPT_GRPQUOTA)) {
338 args->flags |= XFSMNT_GQUOTA | XFSMNT_GQUOTAENF;
339 } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
340 args->flags |= XFSMNT_GQUOTA;
341 args->flags &= ~XFSMNT_GQUOTAENF;
342 } else if (!strcmp(this_char, MNTOPT_DMAPI)) {
343 args->flags |= XFSMNT_DMAPI;
344 } else if (!strcmp(this_char, MNTOPT_XDSM)) {
345 args->flags |= XFSMNT_DMAPI;
346 } else if (!strcmp(this_char, MNTOPT_DMI)) {
347 args->flags |= XFSMNT_DMAPI;
348 } else if (!strcmp(this_char, "ihashsize")) {
349 cmn_err(CE_WARN,
350 "XFS: ihashsize no longer used, option is deprecated.");
351 } else if (!strcmp(this_char, "osyncisdsync")) {
352 /* no-op, this is now the default */
353 cmn_err(CE_WARN,
354 "XFS: osyncisdsync is now the default, option is deprecated.");
355 } else if (!strcmp(this_char, "irixsgid")) {
356 cmn_err(CE_WARN,
357 "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
358 } else {
359 cmn_err(CE_WARN,
360 "XFS: unknown mount option [%s].", this_char);
361 return EINVAL;
362 }
363 }
364
365 if (args->flags & XFSMNT_NORECOVERY) {
366 if ((mp->m_flags & XFS_MOUNT_RDONLY) == 0) {
367 cmn_err(CE_WARN,
368 "XFS: no-recovery mounts must be read-only.");
369 return EINVAL;
370 }
371 }
372
373 if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) {
374 cmn_err(CE_WARN,
375 "XFS: sunit and swidth options incompatible with the noalign option");
376 return EINVAL;
377 }
378
379 if ((args->flags & XFSMNT_GQUOTA) && (args->flags & XFSMNT_PQUOTA)) {
380 cmn_err(CE_WARN,
381 "XFS: cannot mount with both project and group quota");
382 return EINVAL;
383 }
384
385 if ((args->flags & XFSMNT_DMAPI) && *args->mtpt == '\0') {
386 printk("XFS: %s option needs the mount point option as well\n",
387 MNTOPT_DMAPI);
388 return EINVAL;
389 }
390
391 if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
392 cmn_err(CE_WARN,
393 "XFS: sunit and swidth must be specified together");
394 return EINVAL;
395 }
396
397 if (dsunit && (dswidth % dsunit != 0)) {
398 cmn_err(CE_WARN,
399 "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
400 dswidth, dsunit);
401 return EINVAL;
402 }
403
404 /*
405 * Applications using DMI filesystems often expect the
406 * inode generation number to be monotonically increasing.
407 * If we delete inode chunks we break this assumption, so
408 * keep unused inode chunks on disk for DMI filesystems
409 * until we come up with a better solution.
410 * Note that if "ikeep" or "noikeep" mount options are
411 * supplied, then they are honored.
412 */
413 if (!(args->flags & XFSMNT_DMAPI) && !ikeep)
414 args->flags |= XFSMNT_IDELETE;
415
416 if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
417 if (dsunit) {
418 args->sunit = dsunit;
419 args->flags |= XFSMNT_RETERR;
420 } else {
421 args->sunit = vol_dsunit;
422 }
423 dswidth ? (args->swidth = dswidth) :
424 (args->swidth = vol_dswidth);
425 } else {
426 args->sunit = args->swidth = 0;
427 }
428
429done:
430 if (args->flags & XFSMNT_32BITINODES)
431 mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
432 if (args->flags2)
433 args->flags |= XFSMNT_FLAGS2;
434 return 0;
435}
436
437struct proc_xfs_info {
438 int flag;
439 char *str;
440};
441
442STATIC int
443xfs_showargs(
444 struct xfs_mount *mp,
445 struct seq_file *m)
446{
447 static struct proc_xfs_info xfs_info_set[] = {
448 /* the few simple ones we can get from the mount struct */
449 { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
450 { XFS_MOUNT_INO64, "," MNTOPT_INO64 },
451 { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
452 { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
453 { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
454 { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
455 { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
456 { XFS_MOUNT_ATTR2, "," MNTOPT_ATTR2 },
457 { XFS_MOUNT_FILESTREAMS, "," MNTOPT_FILESTREAM },
458 { XFS_MOUNT_DMAPI, "," MNTOPT_DMAPI },
459 { XFS_MOUNT_GRPID, "," MNTOPT_GRPID },
460 { 0, NULL }
461 };
462 static struct proc_xfs_info xfs_info_unset[] = {
463 /* the few simple ones we can get from the mount struct */
464 { XFS_MOUNT_IDELETE, "," MNTOPT_IKEEP },
465 { XFS_MOUNT_COMPAT_IOSIZE, "," MNTOPT_LARGEIO },
466 { XFS_MOUNT_BARRIER, "," MNTOPT_NOBARRIER },
467 { XFS_MOUNT_SMALL_INUMS, "," MNTOPT_64BITINODE },
468 { 0, NULL }
469 };
470 struct proc_xfs_info *xfs_infop;
471
472 for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
473 if (mp->m_flags & xfs_infop->flag)
474 seq_puts(m, xfs_infop->str);
475 }
476 for (xfs_infop = xfs_info_unset; xfs_infop->flag; xfs_infop++) {
477 if (!(mp->m_flags & xfs_infop->flag))
478 seq_puts(m, xfs_infop->str);
479 }
480
481 if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
482 seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
483 (int)(1 << mp->m_writeio_log) >> 10);
484
485 if (mp->m_logbufs > 0)
486 seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
487 if (mp->m_logbsize > 0)
488 seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
489
490 if (mp->m_logname)
491 seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
492 if (mp->m_rtname)
493 seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
494
495 if (mp->m_dalign > 0)
496 seq_printf(m, "," MNTOPT_SUNIT "=%d",
497 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
498 if (mp->m_swidth > 0)
499 seq_printf(m, "," MNTOPT_SWIDTH "=%d",
500 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
501
502 if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD))
503 seq_puts(m, "," MNTOPT_USRQUOTA);
504 else if (mp->m_qflags & XFS_UQUOTA_ACCT)
505 seq_puts(m, "," MNTOPT_UQUOTANOENF);
506
507 if (mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_OQUOTA_ENFD))
508 seq_puts(m, "," MNTOPT_PRJQUOTA);
509 else if (mp->m_qflags & XFS_PQUOTA_ACCT)
510 seq_puts(m, "," MNTOPT_PQUOTANOENF);
511
512 if (mp->m_qflags & (XFS_GQUOTA_ACCT|XFS_OQUOTA_ENFD))
513 seq_puts(m, "," MNTOPT_GRPQUOTA);
514 else if (mp->m_qflags & XFS_GQUOTA_ACCT)
515 seq_puts(m, "," MNTOPT_GQUOTANOENF);
516
517 if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
518 seq_puts(m, "," MNTOPT_NOQUOTA);
519
520 return 0;
521}
1da177e4
LT
522__uint64_t
523xfs_max_file_offset(
524 unsigned int blockshift)
525{
526 unsigned int pagefactor = 1;
527 unsigned int bitshift = BITS_PER_LONG - 1;
528
529 /* Figure out maximum filesize, on Linux this can depend on
530 * the filesystem blocksize (on 32 bit platforms).
531 * __block_prepare_write does this in an [unsigned] long...
532 * page->index << (PAGE_CACHE_SHIFT - bbits)
533 * So, for page sized blocks (4K on 32 bit platforms),
534 * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
535 * (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
536 * but for smaller blocksizes it is less (bbits = log2 bsize).
537 * Note1: get_block_t takes a long (implicit cast from above)
538 * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch
539 * can optionally convert the [unsigned] long from above into
540 * an [unsigned] long long.
541 */
542
543#if BITS_PER_LONG == 32
544# if defined(CONFIG_LBD)
545 ASSERT(sizeof(sector_t) == 8);
546 pagefactor = PAGE_CACHE_SIZE;
547 bitshift = BITS_PER_LONG;
548# else
549 pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift);
550# endif
551#endif
552
553 return (((__uint64_t)pagefactor) << bitshift) - 1;
554}
555
7989cb8e 556STATIC_INLINE void
1da177e4
LT
557xfs_set_inodeops(
558 struct inode *inode)
559{
0432dab2
CH
560 switch (inode->i_mode & S_IFMT) {
561 case S_IFREG:
416c6d5b 562 inode->i_op = &xfs_inode_operations;
3562fd45 563 inode->i_fop = &xfs_file_operations;
e4c573bb 564 inode->i_mapping->a_ops = &xfs_address_space_operations;
0432dab2
CH
565 break;
566 case S_IFDIR:
416c6d5b 567 inode->i_op = &xfs_dir_inode_operations;
3562fd45 568 inode->i_fop = &xfs_dir_file_operations;
0432dab2
CH
569 break;
570 case S_IFLNK:
416c6d5b 571 inode->i_op = &xfs_symlink_inode_operations;
1da177e4 572 if (inode->i_blocks)
e4c573bb 573 inode->i_mapping->a_ops = &xfs_address_space_operations;
0432dab2
CH
574 break;
575 default:
416c6d5b 576 inode->i_op = &xfs_inode_operations;
1da177e4 577 init_special_inode(inode, inode->i_mode, inode->i_rdev);
0432dab2 578 break;
1da177e4
LT
579 }
580}
581
7989cb8e 582STATIC_INLINE void
1da177e4
LT
583xfs_revalidate_inode(
584 xfs_mount_t *mp,
67fcaa73 585 bhv_vnode_t *vp,
1da177e4
LT
586 xfs_inode_t *ip)
587{
ec86dc02 588 struct inode *inode = vn_to_inode(vp);
1da177e4 589
0432dab2 590 inode->i_mode = ip->i_d.di_mode;
1da177e4
LT
591 inode->i_nlink = ip->i_d.di_nlink;
592 inode->i_uid = ip->i_d.di_uid;
593 inode->i_gid = ip->i_d.di_gid;
0432dab2
CH
594
595 switch (inode->i_mode & S_IFMT) {
596 case S_IFBLK:
597 case S_IFCHR:
598 inode->i_rdev =
599 MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff,
600 sysv_minor(ip->i_df.if_u2.if_rdev));
601 break;
602 default:
1da177e4 603 inode->i_rdev = 0;
0432dab2 604 break;
1da177e4 605 }
0432dab2 606
1da177e4
LT
607 inode->i_generation = ip->i_d.di_gen;
608 i_size_write(inode, ip->i_d.di_size);
609 inode->i_blocks =
610 XFS_FSB_TO_BB(mp, ip->i_d.di_nblocks + ip->i_delayed_blks);
611 inode->i_atime.tv_sec = ip->i_d.di_atime.t_sec;
612 inode->i_atime.tv_nsec = ip->i_d.di_atime.t_nsec;
613 inode->i_mtime.tv_sec = ip->i_d.di_mtime.t_sec;
614 inode->i_mtime.tv_nsec = ip->i_d.di_mtime.t_nsec;
615 inode->i_ctime.tv_sec = ip->i_d.di_ctime.t_sec;
616 inode->i_ctime.tv_nsec = ip->i_d.di_ctime.t_nsec;
617 if (ip->i_d.di_flags & XFS_DIFLAG_IMMUTABLE)
618 inode->i_flags |= S_IMMUTABLE;
619 else
620 inode->i_flags &= ~S_IMMUTABLE;
621 if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
622 inode->i_flags |= S_APPEND;
623 else
624 inode->i_flags &= ~S_APPEND;
625 if (ip->i_d.di_flags & XFS_DIFLAG_SYNC)
626 inode->i_flags |= S_SYNC;
627 else
628 inode->i_flags &= ~S_SYNC;
629 if (ip->i_d.di_flags & XFS_DIFLAG_NOATIME)
630 inode->i_flags |= S_NOATIME;
631 else
632 inode->i_flags &= ~S_NOATIME;
b3aea4ed 633 xfs_iflags_clear(ip, XFS_IMODIFIED);
1da177e4
LT
634}
635
636void
637xfs_initialize_vnode(
48c872a9 638 struct xfs_mount *mp,
67fcaa73 639 bhv_vnode_t *vp,
745f6919 640 struct xfs_inode *ip)
1da177e4 641{
ec86dc02 642 struct inode *inode = vn_to_inode(vp);
1da177e4 643
739bfb2a 644 if (!ip->i_vnode) {
739bfb2a
CH
645 ip->i_vnode = vp;
646 inode->i_private = ip;
1da177e4
LT
647 }
648
649 /*
650 * We need to set the ops vectors, and unlock the inode, but if
651 * we have been called during the new inode create process, it is
652 * too early to fill in the Linux inode. We will get called a
653 * second time once the inode is properly set up, and then we can
654 * finish our work.
655 */
745f6919 656 if (ip->i_d.di_mode != 0 && (inode->i_state & I_NEW)) {
48c872a9 657 xfs_revalidate_inode(mp, vp, ip);
1da177e4 658 xfs_set_inodeops(inode);
ec86dc02 659
7a18c386 660 xfs_iflags_clear(ip, XFS_INEW);
1da177e4
LT
661 barrier();
662
663 unlock_new_inode(inode);
664 }
665}
666
667int
668xfs_blkdev_get(
669 xfs_mount_t *mp,
670 const char *name,
671 struct block_device **bdevp)
672{
673 int error = 0;
674
675 *bdevp = open_bdev_excl(name, 0, mp);
676 if (IS_ERR(*bdevp)) {
677 error = PTR_ERR(*bdevp);
678 printk("XFS: Invalid device [%s], error=%d\n", name, error);
679 }
680
681 return -error;
682}
683
684void
685xfs_blkdev_put(
686 struct block_device *bdev)
687{
688 if (bdev)
689 close_bdev_excl(bdev);
690}
691
f538d4da
CH
692/*
693 * Try to write out the superblock using barriers.
694 */
695STATIC int
696xfs_barrier_test(
697 xfs_mount_t *mp)
698{
699 xfs_buf_t *sbp = xfs_getsb(mp, 0);
700 int error;
701
702 XFS_BUF_UNDONE(sbp);
703 XFS_BUF_UNREAD(sbp);
704 XFS_BUF_UNDELAYWRITE(sbp);
705 XFS_BUF_WRITE(sbp);
706 XFS_BUF_UNASYNC(sbp);
707 XFS_BUF_ORDERED(sbp);
708
709 xfsbdstrat(mp, sbp);
710 error = xfs_iowait(sbp);
711
712 /*
713 * Clear all the flags we set and possible error state in the
714 * buffer. We only did the write to try out whether barriers
715 * worked and shouldn't leave any traces in the superblock
716 * buffer.
717 */
718 XFS_BUF_DONE(sbp);
719 XFS_BUF_ERROR(sbp, 0);
720 XFS_BUF_UNORDERED(sbp);
721
722 xfs_buf_relse(sbp);
723 return error;
724}
725
726void
727xfs_mountfs_check_barriers(xfs_mount_t *mp)
728{
729 int error;
730
731 if (mp->m_logdev_targp != mp->m_ddev_targp) {
732 xfs_fs_cmn_err(CE_NOTE, mp,
733 "Disabling barriers, not supported with external log device");
734 mp->m_flags &= ~XFS_MOUNT_BARRIER;
4ef19ddd 735 return;
f538d4da
CH
736 }
737
ce8e922c 738 if (mp->m_ddev_targp->bt_bdev->bd_disk->queue->ordered ==
f538d4da
CH
739 QUEUE_ORDERED_NONE) {
740 xfs_fs_cmn_err(CE_NOTE, mp,
741 "Disabling barriers, not supported by the underlying device");
742 mp->m_flags &= ~XFS_MOUNT_BARRIER;
4ef19ddd 743 return;
f538d4da
CH
744 }
745
b2ea401b
NS
746 if (xfs_readonly_buftarg(mp->m_ddev_targp)) {
747 xfs_fs_cmn_err(CE_NOTE, mp,
748 "Disabling barriers, underlying device is readonly");
749 mp->m_flags &= ~XFS_MOUNT_BARRIER;
750 return;
751 }
752
f538d4da
CH
753 error = xfs_barrier_test(mp);
754 if (error) {
755 xfs_fs_cmn_err(CE_NOTE, mp,
756 "Disabling barriers, trial barrier write failed");
757 mp->m_flags &= ~XFS_MOUNT_BARRIER;
4ef19ddd 758 return;
f538d4da
CH
759 }
760}
761
762void
763xfs_blkdev_issue_flush(
764 xfs_buftarg_t *buftarg)
765{
ce8e922c 766 blkdev_issue_flush(buftarg->bt_bdev, NULL);
f538d4da 767}
1da177e4 768
249a8c11
DC
769/*
770 * XFS AIL push thread support
771 */
772void
773xfsaild_wakeup(
774 xfs_mount_t *mp,
775 xfs_lsn_t threshold_lsn)
776{
777 mp->m_ail.xa_target = threshold_lsn;
778 wake_up_process(mp->m_ail.xa_task);
779}
780
781int
782xfsaild(
783 void *data)
784{
785 xfs_mount_t *mp = (xfs_mount_t *)data;
786 xfs_lsn_t last_pushed_lsn = 0;
787 long tout = 0;
788
789 while (!kthread_should_stop()) {
790 if (tout)
791 schedule_timeout_interruptible(msecs_to_jiffies(tout));
792 tout = 1000;
793
794 /* swsusp */
795 try_to_freeze();
796
797 ASSERT(mp->m_log);
798 if (XFS_FORCED_SHUTDOWN(mp))
799 continue;
800
801 tout = xfsaild_push(mp, &last_pushed_lsn);
802 }
803
804 return 0;
805} /* xfsaild */
806
807int
808xfsaild_start(
809 xfs_mount_t *mp)
810{
811 mp->m_ail.xa_target = 0;
812 mp->m_ail.xa_task = kthread_run(xfsaild, mp, "xfsaild");
813 if (IS_ERR(mp->m_ail.xa_task))
814 return -PTR_ERR(mp->m_ail.xa_task);
815 return 0;
816}
817
818void
819xfsaild_stop(
820 xfs_mount_t *mp)
821{
822 kthread_stop(mp->m_ail.xa_task);
823}
824
825
826
1da177e4 827STATIC struct inode *
a50cd269 828xfs_fs_alloc_inode(
1da177e4
LT
829 struct super_block *sb)
830{
67fcaa73 831 bhv_vnode_t *vp;
1da177e4 832
8758280f
NS
833 vp = kmem_zone_alloc(xfs_vnode_zone, KM_SLEEP);
834 if (unlikely(!vp))
1da177e4 835 return NULL;
ec86dc02 836 return vn_to_inode(vp);
1da177e4
LT
837}
838
839STATIC void
a50cd269 840xfs_fs_destroy_inode(
1da177e4
LT
841 struct inode *inode)
842{
ec86dc02 843 kmem_zone_free(xfs_vnode_zone, vn_from_inode(inode));
1da177e4
LT
844}
845
846STATIC void
a50cd269 847xfs_fs_inode_init_once(
8758280f 848 kmem_zone_t *zonep,
4ba9b9d0 849 void *vnode)
1da177e4 850{
a35afb83 851 inode_init_once(vn_to_inode((bhv_vnode_t *)vnode));
1da177e4
LT
852}
853
854STATIC int
8758280f 855xfs_init_zones(void)
1da177e4 856{
67fcaa73 857 xfs_vnode_zone = kmem_zone_init_flags(sizeof(bhv_vnode_t), "xfs_vnode",
e0cc2325
NS
858 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM |
859 KM_ZONE_SPREAD,
a50cd269 860 xfs_fs_inode_init_once);
0829c360
CH
861 if (!xfs_vnode_zone)
862 goto out;
863
864 xfs_ioend_zone = kmem_zone_init(sizeof(xfs_ioend_t), "xfs_ioend");
865 if (!xfs_ioend_zone)
866 goto out_destroy_vnode_zone;
867
93d2341c
MD
868 xfs_ioend_pool = mempool_create_slab_pool(4 * MAX_BUF_PER_PAGE,
869 xfs_ioend_zone);
0829c360
CH
870 if (!xfs_ioend_pool)
871 goto out_free_ioend_zone;
1da177e4 872 return 0;
0829c360 873
0829c360
CH
874 out_free_ioend_zone:
875 kmem_zone_destroy(xfs_ioend_zone);
876 out_destroy_vnode_zone:
877 kmem_zone_destroy(xfs_vnode_zone);
878 out:
879 return -ENOMEM;
1da177e4
LT
880}
881
882STATIC void
8758280f 883xfs_destroy_zones(void)
1da177e4 884{
0829c360
CH
885 mempool_destroy(xfs_ioend_pool);
886 kmem_zone_destroy(xfs_vnode_zone);
887 kmem_zone_destroy(xfs_ioend_zone);
1da177e4
LT
888}
889
890/*
891 * Attempt to flush the inode, this will actually fail
892 * if the inode is pinned, but we dirty the inode again
893 * at the point when it is unpinned after a log write,
8758280f 894 * since this is when the inode itself becomes flushable.
1da177e4
LT
895 */
896STATIC int
a50cd269 897xfs_fs_write_inode(
1da177e4
LT
898 struct inode *inode,
899 int sync)
900{
1da177e4
LT
901 int error = 0, flags = FLUSH_INODE;
902
cf441eeb 903 xfs_itrace_entry(XFS_I(inode));
739bfb2a
CH
904 if (sync) {
905 filemap_fdatawait(inode->i_mapping);
906 flags |= FLUSH_SYNC;
1da177e4 907 }
739bfb2a 908 error = xfs_inode_flush(XFS_I(inode), flags);
e893bffd
LM
909 /*
910 * if we failed to write out the inode then mark
911 * it dirty again so we'll try again later.
912 */
913 if (error)
914 mark_inode_dirty_sync(inode);
739bfb2a 915
1da177e4
LT
916 return -error;
917}
918
919STATIC void
a50cd269 920xfs_fs_clear_inode(
1da177e4
LT
921 struct inode *inode)
922{
1543d79c 923 xfs_inode_t *ip = XFS_I(inode);
56d433e4 924
02ba71de 925 /*
1543d79c 926 * ip can be null when xfs_iget_core calls xfs_idestroy if we
02ba71de
CH
927 * find an inode with di_mode == 0 but without IGET_CREATE set.
928 */
1543d79c 929 if (ip) {
cf441eeb 930 xfs_itrace_entry(ip);
1543d79c
CH
931 XFS_STATS_INC(vn_rele);
932 XFS_STATS_INC(vn_remove);
933 XFS_STATS_INC(vn_reclaim);
934 XFS_STATS_DEC(vn_active);
935
936 xfs_inactive(ip);
937 xfs_iflags_clear(ip, XFS_IMODIFIED);
938 if (xfs_reclaim(ip))
939 panic("%s: cannot reclaim 0x%p\n", __FUNCTION__, inode);
b3aea4ed 940 }
56d433e4 941
739bfb2a 942 ASSERT(XFS_I(inode) == NULL);
56d433e4 943}
1da177e4
LT
944
945/*
946 * Enqueue a work item to be picked up by the vfs xfssyncd thread.
947 * Doing this has two advantages:
948 * - It saves on stack space, which is tight in certain situations
949 * - It can be used (with care) as a mechanism to avoid deadlocks.
950 * Flushing while allocating in a full filesystem requires both.
951 */
952STATIC void
953xfs_syncd_queue_work(
74394496 954 struct xfs_mount *mp,
1da177e4 955 void *data,
74394496 956 void (*syncer)(struct xfs_mount *, void *))
1da177e4 957{
b83bd138 958 struct bhv_vfs_sync_work *work;
1da177e4 959
b83bd138 960 work = kmem_alloc(sizeof(struct bhv_vfs_sync_work), KM_SLEEP);
1da177e4
LT
961 INIT_LIST_HEAD(&work->w_list);
962 work->w_syncer = syncer;
963 work->w_data = data;
74394496
CH
964 work->w_mount = mp;
965 spin_lock(&mp->m_sync_lock);
966 list_add_tail(&work->w_list, &mp->m_sync_list);
967 spin_unlock(&mp->m_sync_lock);
968 wake_up_process(mp->m_sync_task);
1da177e4
LT
969}
970
971/*
972 * Flush delayed allocate data, attempting to free up reserved space
973 * from existing allocations. At this point a new allocation attempt
974 * has failed with ENOSPC and we are in the process of scratching our
975 * heads, looking about for more room...
976 */
977STATIC void
978xfs_flush_inode_work(
74394496
CH
979 struct xfs_mount *mp,
980 void *arg)
1da177e4 981{
74394496
CH
982 struct inode *inode = arg;
983 filemap_flush(inode->i_mapping);
984 iput(inode);
1da177e4
LT
985}
986
987void
988xfs_flush_inode(
989 xfs_inode_t *ip)
990{
74394496 991 struct inode *inode = ip->i_vnode;
1da177e4
LT
992
993 igrab(inode);
74394496 994 xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_inode_work);
041e0e3b 995 delay(msecs_to_jiffies(500));
1da177e4
LT
996}
997
998/*
999 * This is the "bigger hammer" version of xfs_flush_inode_work...
1000 * (IOW, "If at first you don't succeed, use a Bigger Hammer").
1001 */
1002STATIC void
1003xfs_flush_device_work(
74394496
CH
1004 struct xfs_mount *mp,
1005 void *arg)
1da177e4 1006{
74394496 1007 struct inode *inode = arg;
b267ce99 1008 sync_blockdev(mp->m_super->s_bdev);
74394496 1009 iput(inode);
1da177e4
LT
1010}
1011
1012void
1013xfs_flush_device(
1014 xfs_inode_t *ip)
1015{
ec86dc02 1016 struct inode *inode = vn_to_inode(XFS_ITOV(ip));
1da177e4
LT
1017
1018 igrab(inode);
74394496 1019 xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_device_work);
041e0e3b 1020 delay(msecs_to_jiffies(500));
1da177e4
LT
1021 xfs_log_force(ip->i_mount, (xfs_lsn_t)0, XFS_LOG_FORCE|XFS_LOG_SYNC);
1022}
1023
1da177e4 1024STATIC void
74394496
CH
1025xfs_sync_worker(
1026 struct xfs_mount *mp,
1da177e4
LT
1027 void *unused)
1028{
1029 int error;
1030
74394496
CH
1031 if (!(mp->m_flags & XFS_MOUNT_RDONLY))
1032 error = xfs_sync(mp, SYNC_FSDATA | SYNC_BDFLUSH | SYNC_ATTR |
1033 SYNC_REFCACHE | SYNC_SUPER);
1034 mp->m_sync_seq++;
1035 wake_up(&mp->m_wait_single_sync_task);
1da177e4
LT
1036}
1037
1038STATIC int
1039xfssyncd(
1040 void *arg)
1041{
74394496 1042 struct xfs_mount *mp = arg;
1da177e4 1043 long timeleft;
b83bd138 1044 bhv_vfs_sync_work_t *work, *n;
4df08c52 1045 LIST_HEAD (tmp);
1da177e4 1046
83144186 1047 set_freezable();
041e0e3b 1048 timeleft = xfs_syncd_centisecs * msecs_to_jiffies(10);
1da177e4 1049 for (;;) {
041e0e3b 1050 timeleft = schedule_timeout_interruptible(timeleft);
1da177e4 1051 /* swsusp */
3e1d1d28 1052 try_to_freeze();
74394496 1053 if (kthread_should_stop() && list_empty(&mp->m_sync_list))
1da177e4
LT
1054 break;
1055
74394496 1056 spin_lock(&mp->m_sync_lock);
1da177e4
LT
1057 /*
1058 * We can get woken by laptop mode, to do a sync -
1059 * that's the (only!) case where the list would be
1060 * empty with time remaining.
1061 */
74394496 1062 if (!timeleft || list_empty(&mp->m_sync_list)) {
1da177e4 1063 if (!timeleft)
041e0e3b
NA
1064 timeleft = xfs_syncd_centisecs *
1065 msecs_to_jiffies(10);
74394496
CH
1066 INIT_LIST_HEAD(&mp->m_sync_work.w_list);
1067 list_add_tail(&mp->m_sync_work.w_list,
1068 &mp->m_sync_list);
1da177e4 1069 }
74394496 1070 list_for_each_entry_safe(work, n, &mp->m_sync_list, w_list)
1da177e4 1071 list_move(&work->w_list, &tmp);
74394496 1072 spin_unlock(&mp->m_sync_lock);
1da177e4
LT
1073
1074 list_for_each_entry_safe(work, n, &tmp, w_list) {
74394496 1075 (*work->w_syncer)(mp, work->w_data);
1da177e4 1076 list_del(&work->w_list);
74394496 1077 if (work == &mp->m_sync_work)
1da177e4 1078 continue;
b83bd138 1079 kmem_free(work, sizeof(struct bhv_vfs_sync_work));
1da177e4
LT
1080 }
1081 }
1082
1da177e4
LT
1083 return 0;
1084}
1085
1da177e4 1086STATIC void
a50cd269 1087xfs_fs_put_super(
1da177e4
LT
1088 struct super_block *sb)
1089{
745f6919 1090 struct xfs_mount *mp = XFS_M(sb);
1da177e4
LT
1091 int error;
1092
74394496
CH
1093 kthread_stop(mp->m_sync_task);
1094
745f6919
CH
1095 xfs_sync(mp, SYNC_ATTR | SYNC_DELWRI);
1096 error = xfs_unmount(mp, 0, NULL);
b267ce99 1097 if (error)
b83bd138 1098 printk("XFS: unmount got error=%d\n", error);
1da177e4
LT
1099}
1100
1101STATIC void
a50cd269 1102xfs_fs_write_super(
1da177e4
LT
1103 struct super_block *sb)
1104{
b83bd138 1105 if (!(sb->s_flags & MS_RDONLY))
745f6919 1106 xfs_sync(XFS_M(sb), SYNC_FSDATA);
1da177e4
LT
1107 sb->s_dirt = 0;
1108}
1109
1110STATIC int
a50cd269 1111xfs_fs_sync_super(
1da177e4
LT
1112 struct super_block *sb,
1113 int wait)
1114{
745f6919 1115 struct xfs_mount *mp = XFS_M(sb);
b83bd138
NS
1116 int error;
1117 int flags;
1da177e4 1118
e893bffd
LM
1119 /*
1120 * Treat a sync operation like a freeze. This is to work
1121 * around a race in sync_inodes() which works in two phases
1122 * - an asynchronous flush, which can write out an inode
1123 * without waiting for file size updates to complete, and a
1124 * synchronous flush, which wont do anything because the
1125 * async flush removed the inode's dirty flag. Also
1126 * sync_inodes() will not see any files that just have
1127 * outstanding transactions to be flushed because we don't
1128 * dirty the Linux inode until after the transaction I/O
1129 * completes.
1130 */
1131 if (wait || unlikely(sb->s_frozen == SB_FREEZE_WRITE)) {
2823945f
DC
1132 /*
1133 * First stage of freeze - no more writers will make progress
1134 * now we are here, so we flush delwri and delalloc buffers
1135 * here, then wait for all I/O to complete. Data is frozen at
1136 * that point. Metadata is not frozen, transactions can still
1137 * occur here so don't bother flushing the buftarg (i.e
1138 * SYNC_QUIESCE) because it'll just get dirty again.
1139 */
516b2e7c 1140 flags = SYNC_DATA_QUIESCE;
2823945f 1141 } else
e893bffd 1142 flags = SYNC_FSDATA;
1da177e4 1143
745f6919 1144 error = xfs_sync(mp, flags);
1da177e4
LT
1145 sb->s_dirt = 0;
1146
1147 if (unlikely(laptop_mode)) {
74394496 1148 int prev_sync_seq = mp->m_sync_seq;
1da177e4
LT
1149
1150 /*
1151 * The disk must be active because we're syncing.
1152 * We schedule xfssyncd now (now that the disk is
1153 * active) instead of later (when it might not be).
1154 */
74394496 1155 wake_up_process(mp->m_sync_task);
1da177e4
LT
1156 /*
1157 * We have to wait for the sync iteration to complete.
1158 * If we don't, the disk activity caused by the sync
1159 * will come after the sync is completed, and that
1160 * triggers another sync from laptop mode.
1161 */
74394496
CH
1162 wait_event(mp->m_wait_single_sync_task,
1163 mp->m_sync_seq != prev_sync_seq);
1da177e4
LT
1164 }
1165
1166 return -error;
1167}
1168
1169STATIC int
a50cd269 1170xfs_fs_statfs(
726c3342 1171 struct dentry *dentry,
1da177e4
LT
1172 struct kstatfs *statp)
1173{
4ca488eb
CH
1174 struct xfs_mount *mp = XFS_M(dentry->d_sb);
1175 xfs_sb_t *sbp = &mp->m_sb;
1176 __uint64_t fakeinos, id;
1177 xfs_extlen_t lsize;
1178
1179 statp->f_type = XFS_SB_MAGIC;
1180 statp->f_namelen = MAXNAMELEN - 1;
1181
1182 id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
1183 statp->f_fsid.val[0] = (u32)id;
1184 statp->f_fsid.val[1] = (u32)(id >> 32);
1185
1186 xfs_icsb_sync_counters_flags(mp, XFS_ICSB_LAZY_COUNT);
1187
1188 spin_lock(&mp->m_sb_lock);
1189 statp->f_bsize = sbp->sb_blocksize;
1190 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
1191 statp->f_blocks = sbp->sb_dblocks - lsize;
1192 statp->f_bfree = statp->f_bavail =
1193 sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
1194 fakeinos = statp->f_bfree << sbp->sb_inopblog;
1195#if XFS_BIG_INUMS
1196 fakeinos += mp->m_inoadd;
1197#endif
1198 statp->f_files =
1199 MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
1200 if (mp->m_maxicount)
1201#if XFS_BIG_INUMS
1202 if (!mp->m_inoadd)
1203#endif
1204 statp->f_files = min_t(typeof(statp->f_files),
1205 statp->f_files,
1206 mp->m_maxicount);
1207 statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
1208 spin_unlock(&mp->m_sb_lock);
1209
1210 XFS_QM_DQSTATVFS(XFS_I(dentry->d_inode), statp);
1211 return 0;
1da177e4
LT
1212}
1213
1214STATIC int
a50cd269 1215xfs_fs_remount(
1da177e4
LT
1216 struct super_block *sb,
1217 int *flags,
1218 char *options)
1219{
745f6919 1220 struct xfs_mount *mp = XFS_M(sb);
764d1f89 1221 struct xfs_mount_args *args = xfs_args_allocate(sb, 0);
1da177e4
LT
1222 int error;
1223
745f6919 1224 error = xfs_parseargs(mp, options, args, 1);
1da177e4 1225 if (!error)
745f6919 1226 error = xfs_mntupdate(mp, flags, args);
1da177e4
LT
1227 kmem_free(args, sizeof(*args));
1228 return -error;
1229}
1230
9909c4aa
CH
1231/*
1232 * Second stage of a freeze. The data is already frozen so we only
1233 * need to take care of themetadata. Once that's done write a dummy
1234 * record to dirty the log in case of a crash while frozen.
1235 */
1da177e4 1236STATIC void
a50cd269 1237xfs_fs_lockfs(
1da177e4
LT
1238 struct super_block *sb)
1239{
9909c4aa
CH
1240 struct xfs_mount *mp = XFS_M(sb);
1241
1242 xfs_attr_quiesce(mp);
1243 xfs_fs_log_dummy(mp);
1da177e4
LT
1244}
1245
1246STATIC int
a50cd269 1247xfs_fs_show_options(
1da177e4
LT
1248 struct seq_file *m,
1249 struct vfsmount *mnt)
1250{
745f6919 1251 return -xfs_showargs(XFS_M(mnt->mnt_sb), m);
1da177e4
LT
1252}
1253
ee34807a 1254STATIC int
a50cd269 1255xfs_fs_quotasync(
ee34807a
NS
1256 struct super_block *sb,
1257 int type)
1258{
b09cc771 1259 return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XQUOTASYNC, 0, NULL);
ee34807a
NS
1260}
1261
1da177e4 1262STATIC int
a50cd269 1263xfs_fs_getxstate(
1da177e4
LT
1264 struct super_block *sb,
1265 struct fs_quota_stat *fqs)
1266{
b09cc771 1267 return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XGETQSTAT, 0, (caddr_t)fqs);
1da177e4
LT
1268}
1269
1270STATIC int
a50cd269 1271xfs_fs_setxstate(
1da177e4
LT
1272 struct super_block *sb,
1273 unsigned int flags,
1274 int op)
1275{
b09cc771 1276 return -XFS_QM_QUOTACTL(XFS_M(sb), op, 0, (caddr_t)&flags);
1da177e4
LT
1277}
1278
1279STATIC int
a50cd269 1280xfs_fs_getxquota(
1da177e4
LT
1281 struct super_block *sb,
1282 int type,
1283 qid_t id,
1284 struct fs_disk_quota *fdq)
1285{
b09cc771 1286 return -XFS_QM_QUOTACTL(XFS_M(sb),
b83bd138
NS
1287 (type == USRQUOTA) ? Q_XGETQUOTA :
1288 ((type == GRPQUOTA) ? Q_XGETGQUOTA :
1289 Q_XGETPQUOTA), id, (caddr_t)fdq);
1da177e4
LT
1290}
1291
1292STATIC int
a50cd269 1293xfs_fs_setxquota(
1da177e4
LT
1294 struct super_block *sb,
1295 int type,
1296 qid_t id,
1297 struct fs_disk_quota *fdq)
1298{
b09cc771 1299 return -XFS_QM_QUOTACTL(XFS_M(sb),
b83bd138
NS
1300 (type == USRQUOTA) ? Q_XSETQLIM :
1301 ((type == GRPQUOTA) ? Q_XSETGQLIM :
1302 Q_XSETPQLIM), id, (caddr_t)fdq);
1da177e4
LT
1303}
1304
1305STATIC int
a50cd269 1306xfs_fs_fill_super(
1da177e4
LT
1307 struct super_block *sb,
1308 void *data,
1309 int silent)
1310{
0a74cd19 1311 struct inode *rootvp;
745f6919 1312 struct xfs_mount *mp = NULL;
764d1f89 1313 struct xfs_mount_args *args = xfs_args_allocate(sb, silent);
b83bd138 1314 int error;
1da177e4 1315
745f6919 1316 mp = xfs_mount_init();
1da177e4 1317
74394496
CH
1318 INIT_LIST_HEAD(&mp->m_sync_list);
1319 spin_lock_init(&mp->m_sync_lock);
1320 init_waitqueue_head(&mp->m_wait_single_sync_task);
1321
b267ce99
CH
1322 mp->m_super = sb;
1323 sb->s_fs_info = mp;
1da177e4 1324
bd186aa9
CH
1325 if (sb->s_flags & MS_RDONLY)
1326 mp->m_flags |= XFS_MOUNT_RDONLY;
1327
745f6919
CH
1328 error = xfs_parseargs(mp, (char *)data, args, 0);
1329 if (error)
1da177e4 1330 goto fail_vfsop;
1da177e4
LT
1331
1332 sb_min_blocksize(sb, BBSIZE);
a50cd269 1333 sb->s_export_op = &xfs_export_operations;
a50cd269
NS
1334 sb->s_qcop = &xfs_quotactl_operations;
1335 sb->s_op = &xfs_super_operations;
1da177e4 1336
745f6919
CH
1337 error = xfs_mount(mp, args, NULL);
1338 if (error)
1da177e4 1339 goto fail_vfsop;
1da177e4 1340
1da177e4 1341 sb->s_dirt = 1;
4ca488eb
CH
1342 sb->s_magic = XFS_SB_MAGIC;
1343 sb->s_blocksize = mp->m_sb.sb_blocksize;
1344 sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
1da177e4
LT
1345 sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
1346 sb->s_time_gran = 1;
1347 set_posix_acl_flag(sb);
1348
745f6919 1349 error = xfs_root(mp, &rootvp);
1da177e4
LT
1350 if (error)
1351 goto fail_unmount;
1352
ec86dc02 1353 sb->s_root = d_alloc_root(vn_to_inode(rootvp));
1da177e4
LT
1354 if (!sb->s_root) {
1355 error = ENOMEM;
1356 goto fail_vnrele;
1357 }
1358 if (is_bad_inode(sb->s_root->d_inode)) {
1359 error = EINVAL;
1360 goto fail_vnrele;
1361 }
74394496
CH
1362
1363 mp->m_sync_work.w_syncer = xfs_sync_worker;
1364 mp->m_sync_work.w_mount = mp;
1365 mp->m_sync_task = kthread_run(xfssyncd, mp, "xfssyncd");
1366 if (IS_ERR(mp->m_sync_task)) {
1367 error = -PTR_ERR(mp->m_sync_task);
1da177e4 1368 goto fail_vnrele;
74394496
CH
1369 }
1370
cf441eeb 1371 xfs_itrace_exit(XFS_I(sb->s_root->d_inode));
1da177e4
LT
1372
1373 kmem_free(args, sizeof(*args));
1374 return 0;
1375
1376fail_vnrele:
1377 if (sb->s_root) {
1378 dput(sb->s_root);
1379 sb->s_root = NULL;
1380 } else {
1381 VN_RELE(rootvp);
1382 }
1383
1384fail_unmount:
745f6919 1385 xfs_unmount(mp, 0, NULL);
1da177e4
LT
1386
1387fail_vfsop:
1da177e4
LT
1388 kmem_free(args, sizeof(*args));
1389 return -error;
1390}
1391
454e2398 1392STATIC int
a50cd269 1393xfs_fs_get_sb(
1da177e4
LT
1394 struct file_system_type *fs_type,
1395 int flags,
1396 const char *dev_name,
454e2398
DH
1397 void *data,
1398 struct vfsmount *mnt)
1da177e4 1399{
454e2398
DH
1400 return get_sb_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super,
1401 mnt);
a50cd269
NS
1402}
1403
7989cb8e 1404static struct super_operations xfs_super_operations = {
a50cd269
NS
1405 .alloc_inode = xfs_fs_alloc_inode,
1406 .destroy_inode = xfs_fs_destroy_inode,
1407 .write_inode = xfs_fs_write_inode,
1408 .clear_inode = xfs_fs_clear_inode,
1409 .put_super = xfs_fs_put_super,
1410 .write_super = xfs_fs_write_super,
1411 .sync_fs = xfs_fs_sync_super,
1412 .write_super_lockfs = xfs_fs_lockfs,
1413 .statfs = xfs_fs_statfs,
1414 .remount_fs = xfs_fs_remount,
1415 .show_options = xfs_fs_show_options,
1da177e4
LT
1416};
1417
7989cb8e 1418static struct quotactl_ops xfs_quotactl_operations = {
a50cd269
NS
1419 .quota_sync = xfs_fs_quotasync,
1420 .get_xstate = xfs_fs_getxstate,
1421 .set_xstate = xfs_fs_setxstate,
1422 .get_xquota = xfs_fs_getxquota,
1423 .set_xquota = xfs_fs_setxquota,
1da177e4
LT
1424};
1425
5085b607 1426static struct file_system_type xfs_fs_type = {
1da177e4
LT
1427 .owner = THIS_MODULE,
1428 .name = "xfs",
a50cd269 1429 .get_sb = xfs_fs_get_sb,
1da177e4
LT
1430 .kill_sb = kill_block_super,
1431 .fs_flags = FS_REQUIRES_DEV,
1432};
1433
1434
1435STATIC int __init
1436init_xfs_fs( void )
1437{
1438 int error;
1da177e4
LT
1439 static char message[] __initdata = KERN_INFO \
1440 XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled\n";
1441
1442 printk(message);
1443
1da177e4
LT
1444 ktrace_init(64);
1445
8758280f 1446 error = xfs_init_zones();
1da177e4 1447 if (error < 0)
0829c360 1448 goto undo_zones;
1da177e4 1449
ce8e922c 1450 error = xfs_buf_init();
1da177e4 1451 if (error < 0)
ce8e922c 1452 goto undo_buffers;
1da177e4
LT
1453
1454 vn_init();
1455 xfs_init();
1456 uuid_init();
1457 vfs_initquota();
1458
1459 error = register_filesystem(&xfs_fs_type);
1460 if (error)
1461 goto undo_register;
1da177e4
LT
1462 return 0;
1463
1464undo_register:
ce8e922c 1465 xfs_buf_terminate();
1da177e4 1466
ce8e922c 1467undo_buffers:
8758280f 1468 xfs_destroy_zones();
1da177e4 1469
0829c360 1470undo_zones:
1da177e4
LT
1471 return error;
1472}
1473
1474STATIC void __exit
1475exit_xfs_fs( void )
1476{
1477 vfs_exitquota();
1da177e4
LT
1478 unregister_filesystem(&xfs_fs_type);
1479 xfs_cleanup();
ce8e922c 1480 xfs_buf_terminate();
8758280f 1481 xfs_destroy_zones();
1da177e4
LT
1482 ktrace_uninit();
1483}
1484
1485module_init(init_xfs_fs);
1486module_exit(exit_xfs_fs);
1487
1488MODULE_AUTHOR("Silicon Graphics, Inc.");
1489MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
1490MODULE_LICENSE("GPL");