]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - fs/xfs/linux-2.6/xfs_super.c
4b6ddf88d44e2bae88b9e93aab9513e820ef0aa4
[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
57 #include <linux/namei.h>
58 #include <linux/init.h>
59 #include <linux/mount.h>
60 #include <linux/mempool.h>
61 #include <linux/writeback.h>
62 #include <linux/kthread.h>
63 #include <linux/freezer.h>
64
65 static struct quotactl_ops xfs_quotactl_operations;
66 static struct super_operations xfs_super_operations;
67 static kmem_zone_t *xfs_vnode_zone;
68 static kmem_zone_t *xfs_ioend_zone;
69 mempool_t *xfs_ioend_pool;
70
71 STATIC struct xfs_mount_args *
72 xfs_args_allocate(
73         struct super_block      *sb,
74         int                     silent)
75 {
76         struct xfs_mount_args   *args;
77
78         args = kmem_zalloc(sizeof(struct xfs_mount_args), KM_SLEEP);
79         args->logbufs = args->logbufsize = -1;
80         strncpy(args->fsname, sb->s_id, MAXNAMELEN);
81
82         /* Copy the already-parsed mount(2) flags we're interested in */
83         if (sb->s_flags & MS_DIRSYNC)
84                 args->flags |= XFSMNT_DIRSYNC;
85         if (sb->s_flags & MS_SYNCHRONOUS)
86                 args->flags |= XFSMNT_WSYNC;
87         if (silent)
88                 args->flags |= XFSMNT_QUIET;
89         args->flags |= XFSMNT_32BITINODES;
90
91         return args;
92 }
93
94 #define MNTOPT_LOGBUFS  "logbufs"       /* number of XFS log buffers */
95 #define MNTOPT_LOGBSIZE "logbsize"      /* size of XFS log buffers */
96 #define MNTOPT_LOGDEV   "logdev"        /* log device */
97 #define MNTOPT_RTDEV    "rtdev"         /* realtime I/O device */
98 #define MNTOPT_BIOSIZE  "biosize"       /* log2 of preferred buffered io size */
99 #define MNTOPT_WSYNC    "wsync"         /* safe-mode nfs compatible mount */
100 #define MNTOPT_INO64    "ino64"         /* force inodes into 64-bit range */
101 #define MNTOPT_NOALIGN  "noalign"       /* turn off stripe alignment */
102 #define MNTOPT_SWALLOC  "swalloc"       /* turn on stripe width allocation */
103 #define MNTOPT_SUNIT    "sunit"         /* data volume stripe unit */
104 #define MNTOPT_SWIDTH   "swidth"        /* data volume stripe width */
105 #define MNTOPT_NOUUID   "nouuid"        /* ignore filesystem UUID */
106 #define MNTOPT_MTPT     "mtpt"          /* filesystem mount point */
107 #define MNTOPT_GRPID    "grpid"         /* group-ID from parent directory */
108 #define MNTOPT_NOGRPID  "nogrpid"       /* group-ID from current process */
109 #define MNTOPT_BSDGROUPS    "bsdgroups"    /* group-ID from parent directory */
110 #define MNTOPT_SYSVGROUPS   "sysvgroups"   /* group-ID from current process */
111 #define MNTOPT_ALLOCSIZE    "allocsize"    /* preferred allocation size */
112 #define MNTOPT_NORECOVERY   "norecovery"   /* don't run XFS recovery */
113 #define MNTOPT_BARRIER  "barrier"       /* use writer barriers for log write and
114                                          * unwritten extent conversion */
115 #define MNTOPT_NOBARRIER "nobarrier"    /* .. disable */
116 #define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
117 #define MNTOPT_64BITINODE   "inode64"   /* inodes can be allocated anywhere */
118 #define MNTOPT_IKEEP    "ikeep"         /* do not free empty inode clusters */
119 #define MNTOPT_NOIKEEP  "noikeep"       /* free empty inode clusters */
120 #define MNTOPT_LARGEIO     "largeio"    /* report large I/O sizes in stat() */
121 #define MNTOPT_NOLARGEIO   "nolargeio"  /* do not report large I/O sizes
122                                          * in stat(). */
123 #define MNTOPT_ATTR2    "attr2"         /* do use attr2 attribute format */
124 #define MNTOPT_NOATTR2  "noattr2"       /* do not use attr2 attribute format */
125 #define MNTOPT_FILESTREAM  "filestreams" /* use filestreams allocator */
126 #define MNTOPT_QUOTA    "quota"         /* disk quotas (user) */
127 #define MNTOPT_NOQUOTA  "noquota"       /* no quotas */
128 #define MNTOPT_USRQUOTA "usrquota"      /* user quota enabled */
129 #define MNTOPT_GRPQUOTA "grpquota"      /* group quota enabled */
130 #define MNTOPT_PRJQUOTA "prjquota"      /* project quota enabled */
131 #define MNTOPT_UQUOTA   "uquota"        /* user quota (IRIX variant) */
132 #define MNTOPT_GQUOTA   "gquota"        /* group quota (IRIX variant) */
133 #define MNTOPT_PQUOTA   "pquota"        /* project quota (IRIX variant) */
134 #define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
135 #define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
136 #define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
137 #define MNTOPT_QUOTANOENF  "qnoenforce" /* same as uqnoenforce */
138 #define MNTOPT_DMAPI    "dmapi"         /* DMI enabled (DMAPI / XDSM) */
139 #define MNTOPT_XDSM     "xdsm"          /* DMI enabled (DMAPI / XDSM) */
140 #define MNTOPT_DMI      "dmi"           /* DMI enabled (DMAPI / XDSM) */
141
142 STATIC unsigned long
143 suffix_strtoul(char *s, char **endp, unsigned int base)
144 {
145         int     last, shift_left_factor = 0;
146         char    *value = s;
147
148         last = strlen(value) - 1;
149         if (value[last] == 'K' || value[last] == 'k') {
150                 shift_left_factor = 10;
151                 value[last] = '\0';
152         }
153         if (value[last] == 'M' || value[last] == 'm') {
154                 shift_left_factor = 20;
155                 value[last] = '\0';
156         }
157         if (value[last] == 'G' || value[last] == 'g') {
158                 shift_left_factor = 30;
159                 value[last] = '\0';
160         }
161
162         return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
163 }
164
165 STATIC int
166 xfs_parseargs(
167         struct xfs_mount        *mp,
168         char                    *options,
169         struct xfs_mount_args   *args,
170         int                     update)
171 {
172         char                    *this_char, *value, *eov;
173         int                     dsunit, dswidth, vol_dsunit, vol_dswidth;
174         int                     iosize;
175         int                     dmapi_implies_ikeep = 1;
176
177         args->flags |= XFSMNT_BARRIER;
178         args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
179
180         if (!options)
181                 goto done;
182
183         iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0;
184
185         while ((this_char = strsep(&options, ",")) != NULL) {
186                 if (!*this_char)
187                         continue;
188                 if ((value = strchr(this_char, '=')) != NULL)
189                         *value++ = 0;
190
191                 if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
192                         if (!value || !*value) {
193                                 cmn_err(CE_WARN,
194                                         "XFS: %s option requires an argument",
195                                         this_char);
196                                 return EINVAL;
197                         }
198                         args->logbufs = simple_strtoul(value, &eov, 10);
199                 } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
200                         if (!value || !*value) {
201                                 cmn_err(CE_WARN,
202                                         "XFS: %s option requires an argument",
203                                         this_char);
204                                 return EINVAL;
205                         }
206                         args->logbufsize = suffix_strtoul(value, &eov, 10);
207                 } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
208                         if (!value || !*value) {
209                                 cmn_err(CE_WARN,
210                                         "XFS: %s option requires an argument",
211                                         this_char);
212                                 return EINVAL;
213                         }
214                         strncpy(args->logname, value, MAXNAMELEN);
215                 } else if (!strcmp(this_char, MNTOPT_MTPT)) {
216                         if (!value || !*value) {
217                                 cmn_err(CE_WARN,
218                                         "XFS: %s option requires an argument",
219                                         this_char);
220                                 return EINVAL;
221                         }
222                         strncpy(args->mtpt, value, MAXNAMELEN);
223                 } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
224                         if (!value || !*value) {
225                                 cmn_err(CE_WARN,
226                                         "XFS: %s option requires an argument",
227                                         this_char);
228                                 return EINVAL;
229                         }
230                         strncpy(args->rtname, value, MAXNAMELEN);
231                 } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
232                         if (!value || !*value) {
233                                 cmn_err(CE_WARN,
234                                         "XFS: %s option requires an argument",
235                                         this_char);
236                                 return EINVAL;
237                         }
238                         iosize = simple_strtoul(value, &eov, 10);
239                         args->flags |= XFSMNT_IOSIZE;
240                         args->iosizelog = (uint8_t) iosize;
241                 } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
242                         if (!value || !*value) {
243                                 cmn_err(CE_WARN,
244                                         "XFS: %s option requires an argument",
245                                         this_char);
246                                 return EINVAL;
247                         }
248                         iosize = suffix_strtoul(value, &eov, 10);
249                         args->flags |= XFSMNT_IOSIZE;
250                         args->iosizelog = ffs(iosize) - 1;
251                 } else if (!strcmp(this_char, MNTOPT_GRPID) ||
252                            !strcmp(this_char, MNTOPT_BSDGROUPS)) {
253                         mp->m_flags |= XFS_MOUNT_GRPID;
254                 } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
255                            !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
256                         mp->m_flags &= ~XFS_MOUNT_GRPID;
257                 } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
258                         args->flags |= XFSMNT_WSYNC;
259                 } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
260                         args->flags |= XFSMNT_OSYNCISOSYNC;
261                 } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
262                         args->flags |= XFSMNT_NORECOVERY;
263                 } else if (!strcmp(this_char, MNTOPT_INO64)) {
264                         args->flags |= XFSMNT_INO64;
265 #if !XFS_BIG_INUMS
266                         cmn_err(CE_WARN,
267                                 "XFS: %s option not allowed on this system",
268                                 this_char);
269                         return EINVAL;
270 #endif
271                 } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
272                         args->flags |= XFSMNT_NOALIGN;
273                 } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
274                         args->flags |= XFSMNT_SWALLOC;
275                 } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
276                         if (!value || !*value) {
277                                 cmn_err(CE_WARN,
278                                         "XFS: %s option requires an argument",
279                                         this_char);
280                                 return EINVAL;
281                         }
282                         dsunit = simple_strtoul(value, &eov, 10);
283                 } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
284                         if (!value || !*value) {
285                                 cmn_err(CE_WARN,
286                                         "XFS: %s option requires an argument",
287                                         this_char);
288                                 return EINVAL;
289                         }
290                         dswidth = simple_strtoul(value, &eov, 10);
291                 } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
292                         args->flags &= ~XFSMNT_32BITINODES;
293 #if !XFS_BIG_INUMS
294                         cmn_err(CE_WARN,
295                                 "XFS: %s option not allowed on this system",
296                                 this_char);
297                         return EINVAL;
298 #endif
299                 } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
300                         args->flags |= XFSMNT_NOUUID;
301                 } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
302                         args->flags |= XFSMNT_BARRIER;
303                 } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
304                         args->flags &= ~XFSMNT_BARRIER;
305                 } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
306                         args->flags |= XFSMNT_IKEEP;
307                 } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
308                         dmapi_implies_ikeep = 0;
309                         args->flags &= ~XFSMNT_IKEEP;
310                 } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
311                         args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE;
312                 } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
313                         args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
314                 } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
315                         args->flags |= XFSMNT_ATTR2;
316                 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
317                         args->flags &= ~XFSMNT_ATTR2;
318                         args->flags |= XFSMNT_NOATTR2;
319                 } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
320                         args->flags2 |= XFSMNT2_FILESTREAMS;
321                 } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
322                         args->flags &= ~(XFSMNT_UQUOTAENF|XFSMNT_UQUOTA);
323                         args->flags &= ~(XFSMNT_GQUOTAENF|XFSMNT_GQUOTA);
324                 } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
325                            !strcmp(this_char, MNTOPT_UQUOTA) ||
326                            !strcmp(this_char, MNTOPT_USRQUOTA)) {
327                         args->flags |= XFSMNT_UQUOTA | XFSMNT_UQUOTAENF;
328                 } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
329                            !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
330                         args->flags |= XFSMNT_UQUOTA;
331                         args->flags &= ~XFSMNT_UQUOTAENF;
332                 } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
333                            !strcmp(this_char, MNTOPT_PRJQUOTA)) {
334                         args->flags |= XFSMNT_PQUOTA | XFSMNT_PQUOTAENF;
335                 } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
336                         args->flags |= XFSMNT_PQUOTA;
337                         args->flags &= ~XFSMNT_PQUOTAENF;
338                 } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
339                            !strcmp(this_char, MNTOPT_GRPQUOTA)) {
340                         args->flags |= XFSMNT_GQUOTA | XFSMNT_GQUOTAENF;
341                 } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
342                         args->flags |= XFSMNT_GQUOTA;
343                         args->flags &= ~XFSMNT_GQUOTAENF;
344                 } else if (!strcmp(this_char, MNTOPT_DMAPI)) {
345                         args->flags |= XFSMNT_DMAPI;
346                 } else if (!strcmp(this_char, MNTOPT_XDSM)) {
347                         args->flags |= XFSMNT_DMAPI;
348                 } else if (!strcmp(this_char, MNTOPT_DMI)) {
349                         args->flags |= XFSMNT_DMAPI;
350                 } else if (!strcmp(this_char, "ihashsize")) {
351                         cmn_err(CE_WARN,
352         "XFS: ihashsize no longer used, option is deprecated.");
353                 } else if (!strcmp(this_char, "osyncisdsync")) {
354                         /* no-op, this is now the default */
355                         cmn_err(CE_WARN,
356         "XFS: osyncisdsync is now the default, option is deprecated.");
357                 } else if (!strcmp(this_char, "irixsgid")) {
358                         cmn_err(CE_WARN,
359         "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
360                 } else {
361                         cmn_err(CE_WARN,
362                                 "XFS: unknown mount option [%s].", this_char);
363                         return EINVAL;
364                 }
365         }
366
367         if (args->flags & XFSMNT_NORECOVERY) {
368                 if ((mp->m_flags & XFS_MOUNT_RDONLY) == 0) {
369                         cmn_err(CE_WARN,
370                                 "XFS: no-recovery mounts must be read-only.");
371                         return EINVAL;
372                 }
373         }
374
375         if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) {
376                 cmn_err(CE_WARN,
377         "XFS: sunit and swidth options incompatible with the noalign option");
378                 return EINVAL;
379         }
380
381         if ((args->flags & XFSMNT_GQUOTA) && (args->flags & XFSMNT_PQUOTA)) {
382                 cmn_err(CE_WARN,
383                         "XFS: cannot mount with both project and group quota");
384                 return EINVAL;
385         }
386
387         if ((args->flags & XFSMNT_DMAPI) && *args->mtpt == '\0') {
388                 printk("XFS: %s option needs the mount point option as well\n",
389                         MNTOPT_DMAPI);
390                 return EINVAL;
391         }
392
393         if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
394                 cmn_err(CE_WARN,
395                         "XFS: sunit and swidth must be specified together");
396                 return EINVAL;
397         }
398
399         if (dsunit && (dswidth % dsunit != 0)) {
400                 cmn_err(CE_WARN,
401         "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
402                         dswidth, dsunit);
403                 return EINVAL;
404         }
405
406         /*
407          * Applications using DMI filesystems often expect the
408          * inode generation number to be monotonically increasing.
409          * If we delete inode chunks we break this assumption, so
410          * keep unused inode chunks on disk for DMI filesystems
411          * until we come up with a better solution.
412          * Note that if "ikeep" or "noikeep" mount options are
413          * supplied, then they are honored.
414          */
415         if ((args->flags & XFSMNT_DMAPI) && dmapi_implies_ikeep)
416                 args->flags |= XFSMNT_IKEEP;
417
418         if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
419                 if (dsunit) {
420                         args->sunit = dsunit;
421                         args->flags |= XFSMNT_RETERR;
422                 } else {
423                         args->sunit = vol_dsunit;
424                 }
425                 dswidth ? (args->swidth = dswidth) :
426                           (args->swidth = vol_dswidth);
427         } else {
428                 args->sunit = args->swidth = 0;
429         }
430
431 done:
432         if (args->flags & XFSMNT_32BITINODES)
433                 mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
434         if (args->flags2)
435                 args->flags |= XFSMNT_FLAGS2;
436         return 0;
437 }
438
439 struct proc_xfs_info {
440         int     flag;
441         char    *str;
442 };
443
444 STATIC int
445 xfs_showargs(
446         struct xfs_mount        *mp,
447         struct seq_file         *m)
448 {
449         static struct proc_xfs_info xfs_info_set[] = {
450                 /* the few simple ones we can get from the mount struct */
451                 { XFS_MOUNT_IKEEP,              "," MNTOPT_IKEEP },
452                 { XFS_MOUNT_WSYNC,              "," MNTOPT_WSYNC },
453                 { XFS_MOUNT_INO64,              "," MNTOPT_INO64 },
454                 { XFS_MOUNT_NOALIGN,            "," MNTOPT_NOALIGN },
455                 { XFS_MOUNT_SWALLOC,            "," MNTOPT_SWALLOC },
456                 { XFS_MOUNT_NOUUID,             "," MNTOPT_NOUUID },
457                 { XFS_MOUNT_NORECOVERY,         "," MNTOPT_NORECOVERY },
458                 { XFS_MOUNT_OSYNCISOSYNC,       "," MNTOPT_OSYNCISOSYNC },
459                 { XFS_MOUNT_ATTR2,              "," MNTOPT_ATTR2 },
460                 { XFS_MOUNT_FILESTREAMS,        "," MNTOPT_FILESTREAM },
461                 { XFS_MOUNT_DMAPI,              "," MNTOPT_DMAPI },
462                 { XFS_MOUNT_GRPID,              "," MNTOPT_GRPID },
463                 { 0, NULL }
464         };
465         static struct proc_xfs_info xfs_info_unset[] = {
466                 /* the few simple ones we can get from the mount struct */
467                 { XFS_MOUNT_COMPAT_IOSIZE,      "," MNTOPT_LARGEIO },
468                 { XFS_MOUNT_BARRIER,            "," MNTOPT_NOBARRIER },
469                 { XFS_MOUNT_SMALL_INUMS,        "," MNTOPT_64BITINODE },
470                 { 0, NULL }
471         };
472         struct proc_xfs_info    *xfs_infop;
473
474         for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
475                 if (mp->m_flags & xfs_infop->flag)
476                         seq_puts(m, xfs_infop->str);
477         }
478         for (xfs_infop = xfs_info_unset; xfs_infop->flag; xfs_infop++) {
479                 if (!(mp->m_flags & xfs_infop->flag))
480                         seq_puts(m, xfs_infop->str);
481         }
482
483         if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
484                 seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
485                                 (int)(1 << mp->m_writeio_log) >> 10);
486
487         if (mp->m_logbufs > 0)
488                 seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
489         if (mp->m_logbsize > 0)
490                 seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
491
492         if (mp->m_logname)
493                 seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
494         if (mp->m_rtname)
495                 seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
496
497         if (mp->m_dalign > 0)
498                 seq_printf(m, "," MNTOPT_SUNIT "=%d",
499                                 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
500         if (mp->m_swidth > 0)
501                 seq_printf(m, "," MNTOPT_SWIDTH "=%d",
502                                 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
503
504         if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD))
505                 seq_puts(m, "," MNTOPT_USRQUOTA);
506         else if (mp->m_qflags & XFS_UQUOTA_ACCT)
507                 seq_puts(m, "," MNTOPT_UQUOTANOENF);
508
509         if (mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_OQUOTA_ENFD))
510                 seq_puts(m, "," MNTOPT_PRJQUOTA);
511         else if (mp->m_qflags & XFS_PQUOTA_ACCT)
512                 seq_puts(m, "," MNTOPT_PQUOTANOENF);
513
514         if (mp->m_qflags & (XFS_GQUOTA_ACCT|XFS_OQUOTA_ENFD))
515                 seq_puts(m, "," MNTOPT_GRPQUOTA);
516         else if (mp->m_qflags & XFS_GQUOTA_ACCT)
517                 seq_puts(m, "," MNTOPT_GQUOTANOENF);
518
519         if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
520                 seq_puts(m, "," MNTOPT_NOQUOTA);
521
522         return 0;
523 }
524 __uint64_t
525 xfs_max_file_offset(
526         unsigned int            blockshift)
527 {
528         unsigned int            pagefactor = 1;
529         unsigned int            bitshift = BITS_PER_LONG - 1;
530
531         /* Figure out maximum filesize, on Linux this can depend on
532          * the filesystem blocksize (on 32 bit platforms).
533          * __block_prepare_write does this in an [unsigned] long...
534          *      page->index << (PAGE_CACHE_SHIFT - bbits)
535          * So, for page sized blocks (4K on 32 bit platforms),
536          * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
537          *      (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
538          * but for smaller blocksizes it is less (bbits = log2 bsize).
539          * Note1: get_block_t takes a long (implicit cast from above)
540          * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch
541          * can optionally convert the [unsigned] long from above into
542          * an [unsigned] long long.
543          */
544
545 #if BITS_PER_LONG == 32
546 # if defined(CONFIG_LBD)
547         ASSERT(sizeof(sector_t) == 8);
548         pagefactor = PAGE_CACHE_SIZE;
549         bitshift = BITS_PER_LONG;
550 # else
551         pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift);
552 # endif
553 #endif
554
555         return (((__uint64_t)pagefactor) << bitshift) - 1;
556 }
557
558 STATIC_INLINE void
559 xfs_set_inodeops(
560         struct inode            *inode)
561 {
562         switch (inode->i_mode & S_IFMT) {
563         case S_IFREG:
564                 inode->i_op = &xfs_inode_operations;
565                 inode->i_fop = &xfs_file_operations;
566                 inode->i_mapping->a_ops = &xfs_address_space_operations;
567                 break;
568         case S_IFDIR:
569                 inode->i_op = &xfs_dir_inode_operations;
570                 inode->i_fop = &xfs_dir_file_operations;
571                 break;
572         case S_IFLNK:
573                 inode->i_op = &xfs_symlink_inode_operations;
574                 if (!(XFS_I(inode)->i_df.if_flags & XFS_IFINLINE))
575                         inode->i_mapping->a_ops = &xfs_address_space_operations;
576                 break;
577         default:
578                 inode->i_op = &xfs_inode_operations;
579                 init_special_inode(inode, inode->i_mode, inode->i_rdev);
580                 break;
581         }
582 }
583
584 STATIC_INLINE void
585 xfs_revalidate_inode(
586         xfs_mount_t             *mp,
587         bhv_vnode_t             *vp,
588         xfs_inode_t             *ip)
589 {
590         struct inode            *inode = vn_to_inode(vp);
591
592         inode->i_mode   = ip->i_d.di_mode;
593         inode->i_nlink  = ip->i_d.di_nlink;
594         inode->i_uid    = ip->i_d.di_uid;
595         inode->i_gid    = ip->i_d.di_gid;
596
597         switch (inode->i_mode & S_IFMT) {
598         case S_IFBLK:
599         case S_IFCHR:
600                 inode->i_rdev =
601                         MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff,
602                               sysv_minor(ip->i_df.if_u2.if_rdev));
603                 break;
604         default:
605                 inode->i_rdev = 0;
606                 break;
607         }
608
609         inode->i_generation = ip->i_d.di_gen;
610         i_size_write(inode, ip->i_d.di_size);
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;
633         xfs_iflags_clear(ip, XFS_IMODIFIED);
634 }
635
636 void
637 xfs_initialize_vnode(
638         struct xfs_mount        *mp,
639         bhv_vnode_t             *vp,
640         struct xfs_inode        *ip)
641 {
642         struct inode            *inode = vn_to_inode(vp);
643
644         if (!ip->i_vnode) {
645                 ip->i_vnode = vp;
646                 inode->i_private = ip;
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          */
656         if (ip->i_d.di_mode != 0 && (inode->i_state & I_NEW)) {
657                 xfs_revalidate_inode(mp, vp, ip);
658                 xfs_set_inodeops(inode);
659
660                 xfs_iflags_clear(ip, XFS_INEW);
661                 barrier();
662
663                 unlock_new_inode(inode);
664         }
665 }
666
667 int
668 xfs_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
684 void
685 xfs_blkdev_put(
686         struct block_device     *bdev)
687 {
688         if (bdev)
689                 close_bdev_excl(bdev);
690 }
691
692 /*
693  * Try to write out the superblock using barriers.
694  */
695 STATIC int
696 xfs_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
726 void
727 xfs_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;
735                 return;
736         }
737
738         if (mp->m_ddev_targp->bt_bdev->bd_disk->queue->ordered ==
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;
743                 return;
744         }
745
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
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;
758                 return;
759         }
760 }
761
762 void
763 xfs_blkdev_issue_flush(
764         xfs_buftarg_t           *buftarg)
765 {
766         blkdev_issue_flush(buftarg->bt_bdev, NULL);
767 }
768
769 /*
770  * XFS AIL push thread support
771  */
772 void
773 xfsaild_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
781 int
782 xfsaild(
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
807 int
808 xfsaild_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
818 void
819 xfsaild_stop(
820         xfs_mount_t     *mp)
821 {
822         kthread_stop(mp->m_ail.xa_task);
823 }
824
825
826
827 STATIC struct inode *
828 xfs_fs_alloc_inode(
829         struct super_block      *sb)
830 {
831         bhv_vnode_t             *vp;
832
833         vp = kmem_zone_alloc(xfs_vnode_zone, KM_SLEEP);
834         if (unlikely(!vp))
835                 return NULL;
836         return vn_to_inode(vp);
837 }
838
839 STATIC void
840 xfs_fs_destroy_inode(
841         struct inode            *inode)
842 {
843         kmem_zone_free(xfs_vnode_zone, vn_from_inode(inode));
844 }
845
846 STATIC void
847 xfs_fs_inode_init_once(
848         void                    *vnode)
849 {
850         inode_init_once(vn_to_inode((bhv_vnode_t *)vnode));
851 }
852
853 STATIC int __init
854 xfs_init_zones(void)
855 {
856         xfs_vnode_zone = kmem_zone_init_flags(sizeof(bhv_vnode_t), "xfs_vnode",
857                                         KM_ZONE_HWALIGN | KM_ZONE_RECLAIM |
858                                         KM_ZONE_SPREAD,
859                                         xfs_fs_inode_init_once);
860         if (!xfs_vnode_zone)
861                 goto out;
862
863         xfs_ioend_zone = kmem_zone_init(sizeof(xfs_ioend_t), "xfs_ioend");
864         if (!xfs_ioend_zone)
865                 goto out_destroy_vnode_zone;
866
867         xfs_ioend_pool = mempool_create_slab_pool(4 * MAX_BUF_PER_PAGE,
868                                                   xfs_ioend_zone);
869         if (!xfs_ioend_pool)
870                 goto out_free_ioend_zone;
871         return 0;
872
873  out_free_ioend_zone:
874         kmem_zone_destroy(xfs_ioend_zone);
875  out_destroy_vnode_zone:
876         kmem_zone_destroy(xfs_vnode_zone);
877  out:
878         return -ENOMEM;
879 }
880
881 STATIC void
882 xfs_destroy_zones(void)
883 {
884         mempool_destroy(xfs_ioend_pool);
885         kmem_zone_destroy(xfs_vnode_zone);
886         kmem_zone_destroy(xfs_ioend_zone);
887 }
888
889 /*
890  * Attempt to flush the inode, this will actually fail
891  * if the inode is pinned, but we dirty the inode again
892  * at the point when it is unpinned after a log write,
893  * since this is when the inode itself becomes flushable.
894  */
895 STATIC int
896 xfs_fs_write_inode(
897         struct inode            *inode,
898         int                     sync)
899 {
900         int                     error = 0;
901         int                     flags = 0;
902
903         xfs_itrace_entry(XFS_I(inode));
904         if (sync) {
905                 filemap_fdatawait(inode->i_mapping);
906                 flags |= FLUSH_SYNC;
907         }
908         error = xfs_inode_flush(XFS_I(inode), flags);
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);
915
916         return -error;
917 }
918
919 STATIC void
920 xfs_fs_clear_inode(
921         struct inode            *inode)
922 {
923         xfs_inode_t             *ip = XFS_I(inode);
924
925         /*
926          * ip can be null when xfs_iget_core calls xfs_idestroy if we
927          * find an inode with di_mode == 0 but without IGET_CREATE set.
928          */
929         if (ip) {
930                 xfs_itrace_entry(ip);
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", __func__, inode);
940         }
941
942         ASSERT(XFS_I(inode) == NULL);
943 }
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  */
952 STATIC void
953 xfs_syncd_queue_work(
954         struct xfs_mount *mp,
955         void            *data,
956         void            (*syncer)(struct xfs_mount *, void *))
957 {
958         struct bhv_vfs_sync_work *work;
959
960         work = kmem_alloc(sizeof(struct bhv_vfs_sync_work), KM_SLEEP);
961         INIT_LIST_HEAD(&work->w_list);
962         work->w_syncer = syncer;
963         work->w_data = data;
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);
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  */
977 STATIC void
978 xfs_flush_inode_work(
979         struct xfs_mount *mp,
980         void            *arg)
981 {
982         struct inode    *inode = arg;
983         filemap_flush(inode->i_mapping);
984         iput(inode);
985 }
986
987 void
988 xfs_flush_inode(
989         xfs_inode_t     *ip)
990 {
991         struct inode    *inode = ip->i_vnode;
992
993         igrab(inode);
994         xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_inode_work);
995         delay(msecs_to_jiffies(500));
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  */
1002 STATIC void
1003 xfs_flush_device_work(
1004         struct xfs_mount *mp,
1005         void            *arg)
1006 {
1007         struct inode    *inode = arg;
1008         sync_blockdev(mp->m_super->s_bdev);
1009         iput(inode);
1010 }
1011
1012 void
1013 xfs_flush_device(
1014         xfs_inode_t     *ip)
1015 {
1016         struct inode    *inode = vn_to_inode(XFS_ITOV(ip));
1017
1018         igrab(inode);
1019         xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_device_work);
1020         delay(msecs_to_jiffies(500));
1021         xfs_log_force(ip->i_mount, (xfs_lsn_t)0, XFS_LOG_FORCE|XFS_LOG_SYNC);
1022 }
1023
1024 STATIC void
1025 xfs_sync_worker(
1026         struct xfs_mount *mp,
1027         void            *unused)
1028 {
1029         int             error;
1030
1031         if (!(mp->m_flags & XFS_MOUNT_RDONLY))
1032                 error = xfs_sync(mp, SYNC_FSDATA | SYNC_BDFLUSH | SYNC_ATTR);
1033         mp->m_sync_seq++;
1034         wake_up(&mp->m_wait_single_sync_task);
1035 }
1036
1037 STATIC int
1038 xfssyncd(
1039         void                    *arg)
1040 {
1041         struct xfs_mount        *mp = arg;
1042         long                    timeleft;
1043         bhv_vfs_sync_work_t     *work, *n;
1044         LIST_HEAD               (tmp);
1045
1046         set_freezable();
1047         timeleft = xfs_syncd_centisecs * msecs_to_jiffies(10);
1048         for (;;) {
1049                 timeleft = schedule_timeout_interruptible(timeleft);
1050                 /* swsusp */
1051                 try_to_freeze();
1052                 if (kthread_should_stop() && list_empty(&mp->m_sync_list))
1053                         break;
1054
1055                 spin_lock(&mp->m_sync_lock);
1056                 /*
1057                  * We can get woken by laptop mode, to do a sync -
1058                  * that's the (only!) case where the list would be
1059                  * empty with time remaining.
1060                  */
1061                 if (!timeleft || list_empty(&mp->m_sync_list)) {
1062                         if (!timeleft)
1063                                 timeleft = xfs_syncd_centisecs *
1064                                                         msecs_to_jiffies(10);
1065                         INIT_LIST_HEAD(&mp->m_sync_work.w_list);
1066                         list_add_tail(&mp->m_sync_work.w_list,
1067                                         &mp->m_sync_list);
1068                 }
1069                 list_for_each_entry_safe(work, n, &mp->m_sync_list, w_list)
1070                         list_move(&work->w_list, &tmp);
1071                 spin_unlock(&mp->m_sync_lock);
1072
1073                 list_for_each_entry_safe(work, n, &tmp, w_list) {
1074                         (*work->w_syncer)(mp, work->w_data);
1075                         list_del(&work->w_list);
1076                         if (work == &mp->m_sync_work)
1077                                 continue;
1078                         kmem_free(work);
1079                 }
1080         }
1081
1082         return 0;
1083 }
1084
1085 STATIC void
1086 xfs_fs_put_super(
1087         struct super_block      *sb)
1088 {
1089         struct xfs_mount        *mp = XFS_M(sb);
1090         struct xfs_inode        *rip = mp->m_rootip;
1091         int                     unmount_event_flags = 0;
1092         int                     error;
1093
1094         kthread_stop(mp->m_sync_task);
1095
1096         xfs_sync(mp, SYNC_ATTR | SYNC_DELWRI);
1097
1098 #ifdef HAVE_DMAPI
1099         if (mp->m_flags & XFS_MOUNT_DMAPI) {
1100                 unmount_event_flags =
1101                         (mp->m_dmevmask & (1 << DM_EVENT_UNMOUNT)) ?
1102                                 0 : DM_FLAGS_UNWANTED;
1103                 /*
1104                  * Ignore error from dmapi here, first unmount is not allowed
1105                  * to fail anyway, and second we wouldn't want to fail a
1106                  * unmount because of dmapi.
1107                  */
1108                 XFS_SEND_PREUNMOUNT(mp, rip, DM_RIGHT_NULL, rip, DM_RIGHT_NULL,
1109                                 NULL, NULL, 0, 0, unmount_event_flags);
1110         }
1111 #endif
1112
1113         /*
1114          * Blow away any referenced inode in the filestreams cache.
1115          * This can and will cause log traffic as inodes go inactive
1116          * here.
1117          */
1118         xfs_filestream_unmount(mp);
1119
1120         XFS_bflush(mp->m_ddev_targp);
1121         error = xfs_unmount_flush(mp, 0);
1122         WARN_ON(error);
1123
1124         IRELE(rip);
1125
1126         /*
1127          * If we're forcing a shutdown, typically because of a media error,
1128          * we want to make sure we invalidate dirty pages that belong to
1129          * referenced vnodes as well.
1130          */
1131         if (XFS_FORCED_SHUTDOWN(mp)) {
1132                 error = xfs_sync(mp, SYNC_WAIT | SYNC_CLOSE);
1133                 ASSERT(error != EFSCORRUPTED);
1134         }
1135
1136         if (mp->m_flags & XFS_MOUNT_DMAPI) {
1137                 XFS_SEND_UNMOUNT(mp, rip, DM_RIGHT_NULL, 0, 0,
1138                                 unmount_event_flags);
1139         }
1140
1141         xfs_unmountfs(mp, NULL);
1142         xfs_qmops_put(mp);
1143         xfs_dmops_put(mp);
1144         kmem_free(mp);
1145 }
1146
1147 STATIC void
1148 xfs_fs_write_super(
1149         struct super_block      *sb)
1150 {
1151         if (!(sb->s_flags & MS_RDONLY))
1152                 xfs_sync(XFS_M(sb), SYNC_FSDATA);
1153         sb->s_dirt = 0;
1154 }
1155
1156 STATIC int
1157 xfs_fs_sync_super(
1158         struct super_block      *sb,
1159         int                     wait)
1160 {
1161         struct xfs_mount        *mp = XFS_M(sb);
1162         int                     error;
1163         int                     flags;
1164
1165         /*
1166          * Treat a sync operation like a freeze.  This is to work
1167          * around a race in sync_inodes() which works in two phases
1168          * - an asynchronous flush, which can write out an inode
1169          * without waiting for file size updates to complete, and a
1170          * synchronous flush, which wont do anything because the
1171          * async flush removed the inode's dirty flag.  Also
1172          * sync_inodes() will not see any files that just have
1173          * outstanding transactions to be flushed because we don't
1174          * dirty the Linux inode until after the transaction I/O
1175          * completes.
1176          */
1177         if (wait || unlikely(sb->s_frozen == SB_FREEZE_WRITE)) {
1178                 /*
1179                  * First stage of freeze - no more writers will make progress
1180                  * now we are here, so we flush delwri and delalloc buffers
1181                  * here, then wait for all I/O to complete.  Data is frozen at
1182                  * that point. Metadata is not frozen, transactions can still
1183                  * occur here so don't bother flushing the buftarg (i.e
1184                  * SYNC_QUIESCE) because it'll just get dirty again.
1185                  */
1186                 flags = SYNC_DATA_QUIESCE;
1187         } else
1188                 flags = SYNC_FSDATA;
1189
1190         error = xfs_sync(mp, flags);
1191         sb->s_dirt = 0;
1192
1193         if (unlikely(laptop_mode)) {
1194                 int     prev_sync_seq = mp->m_sync_seq;
1195
1196                 /*
1197                  * The disk must be active because we're syncing.
1198                  * We schedule xfssyncd now (now that the disk is
1199                  * active) instead of later (when it might not be).
1200                  */
1201                 wake_up_process(mp->m_sync_task);
1202                 /*
1203                  * We have to wait for the sync iteration to complete.
1204                  * If we don't, the disk activity caused by the sync
1205                  * will come after the sync is completed, and that
1206                  * triggers another sync from laptop mode.
1207                  */
1208                 wait_event(mp->m_wait_single_sync_task,
1209                                 mp->m_sync_seq != prev_sync_seq);
1210         }
1211
1212         return -error;
1213 }
1214
1215 STATIC int
1216 xfs_fs_statfs(
1217         struct dentry           *dentry,
1218         struct kstatfs          *statp)
1219 {
1220         struct xfs_mount        *mp = XFS_M(dentry->d_sb);
1221         xfs_sb_t                *sbp = &mp->m_sb;
1222         __uint64_t              fakeinos, id;
1223         xfs_extlen_t            lsize;
1224
1225         statp->f_type = XFS_SB_MAGIC;
1226         statp->f_namelen = MAXNAMELEN - 1;
1227
1228         id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
1229         statp->f_fsid.val[0] = (u32)id;
1230         statp->f_fsid.val[1] = (u32)(id >> 32);
1231
1232         xfs_icsb_sync_counters(mp, XFS_ICSB_LAZY_COUNT);
1233
1234         spin_lock(&mp->m_sb_lock);
1235         statp->f_bsize = sbp->sb_blocksize;
1236         lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
1237         statp->f_blocks = sbp->sb_dblocks - lsize;
1238         statp->f_bfree = statp->f_bavail =
1239                                 sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
1240         fakeinos = statp->f_bfree << sbp->sb_inopblog;
1241 #if XFS_BIG_INUMS
1242         fakeinos += mp->m_inoadd;
1243 #endif
1244         statp->f_files =
1245             MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
1246         if (mp->m_maxicount)
1247 #if XFS_BIG_INUMS
1248                 if (!mp->m_inoadd)
1249 #endif
1250                         statp->f_files = min_t(typeof(statp->f_files),
1251                                                 statp->f_files,
1252                                                 mp->m_maxicount);
1253         statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
1254         spin_unlock(&mp->m_sb_lock);
1255
1256         XFS_QM_DQSTATVFS(XFS_I(dentry->d_inode), statp);
1257         return 0;
1258 }
1259
1260 STATIC int
1261 xfs_fs_remount(
1262         struct super_block      *sb,
1263         int                     *flags,
1264         char                    *options)
1265 {
1266         struct xfs_mount        *mp = XFS_M(sb);
1267         struct xfs_mount_args   *args = xfs_args_allocate(sb, 0);
1268         int                     error;
1269
1270         error = xfs_parseargs(mp, options, args, 1);
1271         if (error)
1272                 goto out_free_args;
1273
1274         if (!(*flags & MS_RDONLY)) {                    /* rw/ro -> rw */
1275                 if (mp->m_flags & XFS_MOUNT_RDONLY)
1276                 mp->m_flags &= ~XFS_MOUNT_RDONLY;
1277                 if (args->flags & XFSMNT_BARRIER) {
1278                         mp->m_flags |= XFS_MOUNT_BARRIER;
1279                         xfs_mountfs_check_barriers(mp);
1280                 } else {
1281                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
1282                 }
1283         } else if (!(mp->m_flags & XFS_MOUNT_RDONLY)) { /* rw -> ro */
1284                 xfs_filestream_flush(mp);
1285                 xfs_sync(mp, SYNC_DATA_QUIESCE);
1286                 xfs_attr_quiesce(mp);
1287                 mp->m_flags |= XFS_MOUNT_RDONLY;
1288         }
1289
1290  out_free_args:
1291         kmem_free(args);
1292         return -error;
1293 }
1294
1295 /*
1296  * Second stage of a freeze. The data is already frozen so we only
1297  * need to take care of themetadata. Once that's done write a dummy
1298  * record to dirty the log in case of a crash while frozen.
1299  */
1300 STATIC void
1301 xfs_fs_lockfs(
1302         struct super_block      *sb)
1303 {
1304         struct xfs_mount        *mp = XFS_M(sb);
1305
1306         xfs_attr_quiesce(mp);
1307         xfs_fs_log_dummy(mp);
1308 }
1309
1310 STATIC int
1311 xfs_fs_show_options(
1312         struct seq_file         *m,
1313         struct vfsmount         *mnt)
1314 {
1315         return -xfs_showargs(XFS_M(mnt->mnt_sb), m);
1316 }
1317
1318 STATIC int
1319 xfs_fs_quotasync(
1320         struct super_block      *sb,
1321         int                     type)
1322 {
1323         return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XQUOTASYNC, 0, NULL);
1324 }
1325
1326 STATIC int
1327 xfs_fs_getxstate(
1328         struct super_block      *sb,
1329         struct fs_quota_stat    *fqs)
1330 {
1331         return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XGETQSTAT, 0, (caddr_t)fqs);
1332 }
1333
1334 STATIC int
1335 xfs_fs_setxstate(
1336         struct super_block      *sb,
1337         unsigned int            flags,
1338         int                     op)
1339 {
1340         return -XFS_QM_QUOTACTL(XFS_M(sb), op, 0, (caddr_t)&flags);
1341 }
1342
1343 STATIC int
1344 xfs_fs_getxquota(
1345         struct super_block      *sb,
1346         int                     type,
1347         qid_t                   id,
1348         struct fs_disk_quota    *fdq)
1349 {
1350         return -XFS_QM_QUOTACTL(XFS_M(sb),
1351                                  (type == USRQUOTA) ? Q_XGETQUOTA :
1352                                   ((type == GRPQUOTA) ? Q_XGETGQUOTA :
1353                                    Q_XGETPQUOTA), id, (caddr_t)fdq);
1354 }
1355
1356 STATIC int
1357 xfs_fs_setxquota(
1358         struct super_block      *sb,
1359         int                     type,
1360         qid_t                   id,
1361         struct fs_disk_quota    *fdq)
1362 {
1363         return -XFS_QM_QUOTACTL(XFS_M(sb),
1364                                  (type == USRQUOTA) ? Q_XSETQLIM :
1365                                   ((type == GRPQUOTA) ? Q_XSETGQLIM :
1366                                    Q_XSETPQLIM), id, (caddr_t)fdq);
1367 }
1368
1369 /*
1370  * This function fills in xfs_mount_t fields based on mount args.
1371  * Note: the superblock has _not_ yet been read in.
1372  */
1373 STATIC int
1374 xfs_start_flags(
1375         struct xfs_mount_args   *ap,
1376         struct xfs_mount        *mp)
1377 {
1378         /* Values are in BBs */
1379         if ((ap->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
1380                 /*
1381                  * At this point the superblock has not been read
1382                  * in, therefore we do not know the block size.
1383                  * Before the mount call ends we will convert
1384                  * these to FSBs.
1385                  */
1386                 mp->m_dalign = ap->sunit;
1387                 mp->m_swidth = ap->swidth;
1388         }
1389
1390         if (ap->logbufs != -1 &&
1391             ap->logbufs != 0 &&
1392             (ap->logbufs < XLOG_MIN_ICLOGS ||
1393              ap->logbufs > XLOG_MAX_ICLOGS)) {
1394                 cmn_err(CE_WARN,
1395                         "XFS: invalid logbufs value: %d [not %d-%d]",
1396                         ap->logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
1397                 return XFS_ERROR(EINVAL);
1398         }
1399         mp->m_logbufs = ap->logbufs;
1400         if (ap->logbufsize != -1 &&
1401             ap->logbufsize !=  0 &&
1402             (ap->logbufsize < XLOG_MIN_RECORD_BSIZE ||
1403              ap->logbufsize > XLOG_MAX_RECORD_BSIZE ||
1404              !is_power_of_2(ap->logbufsize))) {
1405                 cmn_err(CE_WARN,
1406         "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
1407                         ap->logbufsize);
1408                 return XFS_ERROR(EINVAL);
1409         }
1410         mp->m_logbsize = ap->logbufsize;
1411         mp->m_fsname_len = strlen(ap->fsname) + 1;
1412         mp->m_fsname = kmem_alloc(mp->m_fsname_len, KM_SLEEP);
1413         strcpy(mp->m_fsname, ap->fsname);
1414         if (ap->rtname[0]) {
1415                 mp->m_rtname = kmem_alloc(strlen(ap->rtname) + 1, KM_SLEEP);
1416                 strcpy(mp->m_rtname, ap->rtname);
1417         }
1418         if (ap->logname[0]) {
1419                 mp->m_logname = kmem_alloc(strlen(ap->logname) + 1, KM_SLEEP);
1420                 strcpy(mp->m_logname, ap->logname);
1421         }
1422
1423         if (ap->flags & XFSMNT_WSYNC)
1424                 mp->m_flags |= XFS_MOUNT_WSYNC;
1425 #if XFS_BIG_INUMS
1426         if (ap->flags & XFSMNT_INO64) {
1427                 mp->m_flags |= XFS_MOUNT_INO64;
1428                 mp->m_inoadd = XFS_INO64_OFFSET;
1429         }
1430 #endif
1431         if (ap->flags & XFSMNT_RETERR)
1432                 mp->m_flags |= XFS_MOUNT_RETERR;
1433         if (ap->flags & XFSMNT_NOALIGN)
1434                 mp->m_flags |= XFS_MOUNT_NOALIGN;
1435         if (ap->flags & XFSMNT_SWALLOC)
1436                 mp->m_flags |= XFS_MOUNT_SWALLOC;
1437         if (ap->flags & XFSMNT_OSYNCISOSYNC)
1438                 mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
1439         if (ap->flags & XFSMNT_32BITINODES)
1440                 mp->m_flags |= XFS_MOUNT_32BITINODES;
1441
1442         if (ap->flags & XFSMNT_IOSIZE) {
1443                 if (ap->iosizelog > XFS_MAX_IO_LOG ||
1444                     ap->iosizelog < XFS_MIN_IO_LOG) {
1445                         cmn_err(CE_WARN,
1446                 "XFS: invalid log iosize: %d [not %d-%d]",
1447                                 ap->iosizelog, XFS_MIN_IO_LOG,
1448                                 XFS_MAX_IO_LOG);
1449                         return XFS_ERROR(EINVAL);
1450                 }
1451
1452                 mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
1453                 mp->m_readio_log = mp->m_writeio_log = ap->iosizelog;
1454         }
1455
1456         if (ap->flags & XFSMNT_IKEEP)
1457                 mp->m_flags |= XFS_MOUNT_IKEEP;
1458         if (ap->flags & XFSMNT_DIRSYNC)
1459                 mp->m_flags |= XFS_MOUNT_DIRSYNC;
1460         if (ap->flags & XFSMNT_ATTR2)
1461                 mp->m_flags |= XFS_MOUNT_ATTR2;
1462         if (ap->flags & XFSMNT_NOATTR2)
1463                 mp->m_flags |= XFS_MOUNT_NOATTR2;
1464
1465         if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
1466                 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
1467
1468         /*
1469          * no recovery flag requires a read-only mount
1470          */
1471         if (ap->flags & XFSMNT_NORECOVERY) {
1472                 if (!(mp->m_flags & XFS_MOUNT_RDONLY)) {
1473                         cmn_err(CE_WARN,
1474         "XFS: tried to mount a FS read-write without recovery!");
1475                         return XFS_ERROR(EINVAL);
1476                 }
1477                 mp->m_flags |= XFS_MOUNT_NORECOVERY;
1478         }
1479
1480         if (ap->flags & XFSMNT_NOUUID)
1481                 mp->m_flags |= XFS_MOUNT_NOUUID;
1482         if (ap->flags & XFSMNT_BARRIER)
1483                 mp->m_flags |= XFS_MOUNT_BARRIER;
1484         else
1485                 mp->m_flags &= ~XFS_MOUNT_BARRIER;
1486
1487         if (ap->flags2 & XFSMNT2_FILESTREAMS)
1488                 mp->m_flags |= XFS_MOUNT_FILESTREAMS;
1489
1490         if (ap->flags & XFSMNT_DMAPI)
1491                 mp->m_flags |= XFS_MOUNT_DMAPI;
1492         return 0;
1493 }
1494
1495 /*
1496  * This function fills in xfs_mount_t fields based on mount args.
1497  * Note: the superblock _has_ now been read in.
1498  */
1499 STATIC int
1500 xfs_finish_flags(
1501         struct xfs_mount_args   *ap,
1502         struct xfs_mount        *mp)
1503 {
1504         int                     ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
1505
1506         /* Fail a mount where the logbuf is smaller then the log stripe */
1507         if (xfs_sb_version_haslogv2(&mp->m_sb)) {
1508                 if ((ap->logbufsize <= 0) &&
1509                     (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) {
1510                         mp->m_logbsize = mp->m_sb.sb_logsunit;
1511                 } else if (ap->logbufsize > 0 &&
1512                            ap->logbufsize < mp->m_sb.sb_logsunit) {
1513                         cmn_err(CE_WARN,
1514         "XFS: logbuf size must be greater than or equal to log stripe size");
1515                         return XFS_ERROR(EINVAL);
1516                 }
1517         } else {
1518                 /* Fail a mount if the logbuf is larger than 32K */
1519                 if (ap->logbufsize > XLOG_BIG_RECORD_BSIZE) {
1520                         cmn_err(CE_WARN,
1521         "XFS: logbuf size for version 1 logs must be 16K or 32K");
1522                         return XFS_ERROR(EINVAL);
1523                 }
1524         }
1525
1526         /*
1527          * mkfs'ed attr2 will turn on attr2 mount unless explicitly
1528          * told by noattr2 to turn it off
1529          */
1530         if (xfs_sb_version_hasattr2(&mp->m_sb) &&
1531             !(ap->flags & XFSMNT_NOATTR2))
1532                 mp->m_flags |= XFS_MOUNT_ATTR2;
1533
1534         /*
1535          * prohibit r/w mounts of read-only filesystems
1536          */
1537         if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
1538                 cmn_err(CE_WARN,
1539         "XFS: cannot mount a read-only filesystem as read-write");
1540                 return XFS_ERROR(EROFS);
1541         }
1542
1543         /*
1544          * check for shared mount.
1545          */
1546         if (ap->flags & XFSMNT_SHARED) {
1547                 if (!xfs_sb_version_hasshared(&mp->m_sb))
1548                         return XFS_ERROR(EINVAL);
1549
1550                 /*
1551                  * For IRIX 6.5, shared mounts must have the shared
1552                  * version bit set, have the persistent readonly
1553                  * field set, must be version 0 and can only be mounted
1554                  * read-only.
1555                  */
1556                 if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) ||
1557                      (mp->m_sb.sb_shared_vn != 0))
1558                         return XFS_ERROR(EINVAL);
1559
1560                 mp->m_flags |= XFS_MOUNT_SHARED;
1561
1562                 /*
1563                  * Shared XFS V0 can't deal with DMI.  Return EINVAL.
1564                  */
1565                 if (mp->m_sb.sb_shared_vn == 0 && (ap->flags & XFSMNT_DMAPI))
1566                         return XFS_ERROR(EINVAL);
1567         }
1568
1569         if (ap->flags & XFSMNT_UQUOTA) {
1570                 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
1571                 if (ap->flags & XFSMNT_UQUOTAENF)
1572                         mp->m_qflags |= XFS_UQUOTA_ENFD;
1573         }
1574
1575         if (ap->flags & XFSMNT_GQUOTA) {
1576                 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
1577                 if (ap->flags & XFSMNT_GQUOTAENF)
1578                         mp->m_qflags |= XFS_OQUOTA_ENFD;
1579         } else if (ap->flags & XFSMNT_PQUOTA) {
1580                 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
1581                 if (ap->flags & XFSMNT_PQUOTAENF)
1582                         mp->m_qflags |= XFS_OQUOTA_ENFD;
1583         }
1584
1585         return 0;
1586 }
1587
1588 /*
1589  * The file system configurations are:
1590  *      (1) device (partition) with data and internal log
1591  *      (2) logical volume with data and log subvolumes.
1592  *      (3) logical volume with data, log, and realtime subvolumes.
1593  *
1594  * We only have to handle opening the log and realtime volumes here if
1595  * they are present.  The data subvolume has already been opened by
1596  * get_sb_bdev() and is stored in vfsp->vfs_super->s_bdev.
1597  */
1598 STATIC int
1599 xfs_fs_fill_super(
1600         struct super_block      *sb,
1601         void                    *data,
1602         int                     silent)
1603 {
1604         struct inode            *root;
1605         struct xfs_mount        *mp = NULL;
1606         struct xfs_mount_args   *args = xfs_args_allocate(sb, silent);
1607         struct block_device     *ddev = sb->s_bdev;
1608         struct block_device     *logdev = NULL, *rtdev = NULL;
1609         int                     flags = 0, error;
1610
1611         mp = xfs_mount_init();
1612
1613         INIT_LIST_HEAD(&mp->m_sync_list);
1614         spin_lock_init(&mp->m_sync_lock);
1615         init_waitqueue_head(&mp->m_wait_single_sync_task);
1616
1617         mp->m_super = sb;
1618         sb->s_fs_info = mp;
1619
1620         if (sb->s_flags & MS_RDONLY)
1621                 mp->m_flags |= XFS_MOUNT_RDONLY;
1622
1623         error = xfs_parseargs(mp, (char *)data, args, 0);
1624         if (error)
1625                 goto fail_vfsop;
1626
1627         sb_min_blocksize(sb, BBSIZE);
1628         sb->s_export_op = &xfs_export_operations;
1629         sb->s_qcop = &xfs_quotactl_operations;
1630         sb->s_op = &xfs_super_operations;
1631
1632         error = xfs_dmops_get(mp, args);
1633         if (error)
1634                 goto fail_vfsop;
1635         error = xfs_qmops_get(mp, args);
1636         if (error)
1637                 goto fail_vfsop;
1638
1639         if (args->flags & XFSMNT_QUIET)
1640                 flags |= XFS_MFSI_QUIET;
1641
1642         /*
1643          * Open real time and log devices - order is important.
1644          */
1645         if (args->logname[0]) {
1646                 error = xfs_blkdev_get(mp, args->logname, &logdev);
1647                 if (error)
1648                         goto fail_vfsop;
1649         }
1650         if (args->rtname[0]) {
1651                 error = xfs_blkdev_get(mp, args->rtname, &rtdev);
1652                 if (error) {
1653                         xfs_blkdev_put(logdev);
1654                         goto fail_vfsop;
1655                 }
1656
1657                 if (rtdev == ddev || rtdev == logdev) {
1658                         cmn_err(CE_WARN,
1659         "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
1660                         xfs_blkdev_put(logdev);
1661                         xfs_blkdev_put(rtdev);
1662                         error = EINVAL;
1663                         goto fail_vfsop;
1664                 }
1665         }
1666
1667         /*
1668          * Setup xfs_mount buffer target pointers
1669          */
1670         error = ENOMEM;
1671         mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
1672         if (!mp->m_ddev_targp) {
1673                 xfs_blkdev_put(logdev);
1674                 xfs_blkdev_put(rtdev);
1675                 goto fail_vfsop;
1676         }
1677         if (rtdev) {
1678                 mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
1679                 if (!mp->m_rtdev_targp) {
1680                         xfs_blkdev_put(logdev);
1681                         xfs_blkdev_put(rtdev);
1682                         goto error0;
1683                 }
1684         }
1685         mp->m_logdev_targp = (logdev && logdev != ddev) ?
1686                                 xfs_alloc_buftarg(logdev, 1) : mp->m_ddev_targp;
1687         if (!mp->m_logdev_targp) {
1688                 xfs_blkdev_put(logdev);
1689                 xfs_blkdev_put(rtdev);
1690                 goto error0;
1691         }
1692
1693         /*
1694          * Setup flags based on mount(2) options and then the superblock
1695          */
1696         error = xfs_start_flags(args, mp);
1697         if (error)
1698                 goto error1;
1699         error = xfs_readsb(mp, flags);
1700         if (error)
1701                 goto error1;
1702         error = xfs_finish_flags(args, mp);
1703         if (error)
1704                 goto error2;
1705
1706         /*
1707          * Setup xfs_mount buffer target pointers based on superblock
1708          */
1709         error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
1710                                     mp->m_sb.sb_sectsize);
1711         if (!error && logdev && logdev != ddev) {
1712                 unsigned int    log_sector_size = BBSIZE;
1713
1714                 if (xfs_sb_version_hassector(&mp->m_sb))
1715                         log_sector_size = mp->m_sb.sb_logsectsize;
1716                 error = xfs_setsize_buftarg(mp->m_logdev_targp,
1717                                             mp->m_sb.sb_blocksize,
1718                                             log_sector_size);
1719         }
1720         if (!error && rtdev)
1721                 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
1722                                             mp->m_sb.sb_blocksize,
1723                                             mp->m_sb.sb_sectsize);
1724         if (error)
1725                 goto error2;
1726
1727         if (mp->m_flags & XFS_MOUNT_BARRIER)
1728                 xfs_mountfs_check_barriers(mp);
1729
1730         error = xfs_filestream_mount(mp);
1731         if (error)
1732                 goto error2;
1733
1734         error = xfs_mountfs(mp, flags);
1735         if (error)
1736                 goto error2;
1737
1738         XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, args->mtpt, args->fsname);
1739
1740         sb->s_dirt = 1;
1741         sb->s_magic = XFS_SB_MAGIC;
1742         sb->s_blocksize = mp->m_sb.sb_blocksize;
1743         sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
1744         sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
1745         sb->s_time_gran = 1;
1746         set_posix_acl_flag(sb);
1747
1748         root = igrab(mp->m_rootip->i_vnode);
1749         if (!root) {
1750                 error = ENOENT;
1751                 goto fail_unmount;
1752         }
1753         if (is_bad_inode(root)) {
1754                 error = EINVAL;
1755                 goto fail_vnrele;
1756         }
1757         sb->s_root = d_alloc_root(root);
1758         if (!sb->s_root) {
1759                 error = ENOMEM;
1760                 goto fail_vnrele;
1761         }
1762
1763         mp->m_sync_work.w_syncer = xfs_sync_worker;
1764         mp->m_sync_work.w_mount = mp;
1765         mp->m_sync_task = kthread_run(xfssyncd, mp, "xfssyncd");
1766         if (IS_ERR(mp->m_sync_task)) {
1767                 error = -PTR_ERR(mp->m_sync_task);
1768                 goto fail_vnrele;
1769         }
1770
1771         xfs_itrace_exit(XFS_I(sb->s_root->d_inode));
1772
1773         kmem_free(args);
1774         return 0;
1775
1776  error2:
1777         if (mp->m_sb_bp)
1778                 xfs_freesb(mp);
1779  error1:
1780         xfs_binval(mp->m_ddev_targp);
1781         if (logdev && logdev != ddev)
1782                 xfs_binval(mp->m_logdev_targp);
1783         if (rtdev)
1784                 xfs_binval(mp->m_rtdev_targp);
1785  error0:
1786         xfs_unmountfs_close(mp, NULL);
1787         xfs_qmops_put(mp);
1788         xfs_dmops_put(mp);
1789         goto fail_vfsop;
1790
1791  fail_vnrele:
1792         if (sb->s_root) {
1793                 dput(sb->s_root);
1794                 sb->s_root = NULL;
1795         } else {
1796                 iput(root);
1797         }
1798
1799  fail_unmount:
1800         /*
1801          * Blow away any referenced inode in the filestreams cache.
1802          * This can and will cause log traffic as inodes go inactive
1803          * here.
1804          */
1805         xfs_filestream_unmount(mp);
1806
1807         XFS_bflush(mp->m_ddev_targp);
1808         error = xfs_unmount_flush(mp, 0);
1809         WARN_ON(error);
1810
1811         IRELE(mp->m_rootip);
1812
1813         xfs_unmountfs(mp, NULL);
1814         xfs_qmops_put(mp);
1815         xfs_dmops_put(mp);
1816         kmem_free(mp);
1817
1818  fail_vfsop:
1819         kmem_free(args);
1820         return -error;
1821 }
1822
1823 STATIC int
1824 xfs_fs_get_sb(
1825         struct file_system_type *fs_type,
1826         int                     flags,
1827         const char              *dev_name,
1828         void                    *data,
1829         struct vfsmount         *mnt)
1830 {
1831         return get_sb_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super,
1832                            mnt);
1833 }
1834
1835 static struct super_operations xfs_super_operations = {
1836         .alloc_inode            = xfs_fs_alloc_inode,
1837         .destroy_inode          = xfs_fs_destroy_inode,
1838         .write_inode            = xfs_fs_write_inode,
1839         .clear_inode            = xfs_fs_clear_inode,
1840         .put_super              = xfs_fs_put_super,
1841         .write_super            = xfs_fs_write_super,
1842         .sync_fs                = xfs_fs_sync_super,
1843         .write_super_lockfs     = xfs_fs_lockfs,
1844         .statfs                 = xfs_fs_statfs,
1845         .remount_fs             = xfs_fs_remount,
1846         .show_options           = xfs_fs_show_options,
1847 };
1848
1849 static struct quotactl_ops xfs_quotactl_operations = {
1850         .quota_sync             = xfs_fs_quotasync,
1851         .get_xstate             = xfs_fs_getxstate,
1852         .set_xstate             = xfs_fs_setxstate,
1853         .get_xquota             = xfs_fs_getxquota,
1854         .set_xquota             = xfs_fs_setxquota,
1855 };
1856
1857 static struct file_system_type xfs_fs_type = {
1858         .owner                  = THIS_MODULE,
1859         .name                   = "xfs",
1860         .get_sb                 = xfs_fs_get_sb,
1861         .kill_sb                = kill_block_super,
1862         .fs_flags               = FS_REQUIRES_DEV,
1863 };
1864
1865
1866 STATIC int __init
1867 init_xfs_fs( void )
1868 {
1869         int                     error;
1870         static char             message[] __initdata = KERN_INFO \
1871                 XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled\n";
1872
1873         printk(message);
1874
1875         ktrace_init(64);
1876
1877         error = xfs_init_zones();
1878         if (error < 0)
1879                 goto undo_zones;
1880
1881         error = xfs_buf_init();
1882         if (error < 0)
1883                 goto undo_buffers;
1884
1885         vn_init();
1886         xfs_init();
1887         uuid_init();
1888         vfs_initquota();
1889
1890         error = register_filesystem(&xfs_fs_type);
1891         if (error)
1892                 goto undo_register;
1893         return 0;
1894
1895 undo_register:
1896         xfs_buf_terminate();
1897
1898 undo_buffers:
1899         xfs_destroy_zones();
1900
1901 undo_zones:
1902         return error;
1903 }
1904
1905 STATIC void __exit
1906 exit_xfs_fs( void )
1907 {
1908         vfs_exitquota();
1909         unregister_filesystem(&xfs_fs_type);
1910         xfs_cleanup();
1911         xfs_buf_terminate();
1912         xfs_destroy_zones();
1913         ktrace_uninit();
1914 }
1915
1916 module_init(init_xfs_fs);
1917 module_exit(exit_xfs_fs);
1918
1919 MODULE_AUTHOR("Silicon Graphics, Inc.");
1920 MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
1921 MODULE_LICENSE("GPL");