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