[XFS] fix spurious gcc warnings
[pandora-kernel.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_inum.h"
22 #include "xfs_trans.h"
23 #include "xfs_sb.h"
24 #include "xfs_ag.h"
25 #include "xfs_dir2.h"
26 #include "xfs_alloc.h"
27 #include "xfs_dmapi.h"
28 #include "xfs_quota.h"
29 #include "xfs_mount.h"
30 #include "xfs_bmap_btree.h"
31 #include "xfs_alloc_btree.h"
32 #include "xfs_ialloc_btree.h"
33 #include "xfs_dir2_sf.h"
34 #include "xfs_attr_sf.h"
35 #include "xfs_dinode.h"
36 #include "xfs_inode.h"
37 #include "xfs_btree.h"
38 #include "xfs_btree_trace.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 #include "xfs_sync.h"
62
63 #include <linux/namei.h>
64 #include <linux/init.h>
65 #include <linux/mount.h>
66 #include <linux/mempool.h>
67 #include <linux/writeback.h>
68 #include <linux/kthread.h>
69 #include <linux/freezer.h>
70 #include <linux/parser.h>
71
72 static struct quotactl_ops xfs_quotactl_operations;
73 static struct super_operations xfs_super_operations;
74 static kmem_zone_t *xfs_ioend_zone;
75 mempool_t *xfs_ioend_pool;
76
77 #define MNTOPT_LOGBUFS  "logbufs"       /* number of XFS log buffers */
78 #define MNTOPT_LOGBSIZE "logbsize"      /* size of XFS log buffers */
79 #define MNTOPT_LOGDEV   "logdev"        /* log device */
80 #define MNTOPT_RTDEV    "rtdev"         /* realtime I/O device */
81 #define MNTOPT_BIOSIZE  "biosize"       /* log2 of preferred buffered io size */
82 #define MNTOPT_WSYNC    "wsync"         /* safe-mode nfs compatible mount */
83 #define MNTOPT_INO64    "ino64"         /* force inodes into 64-bit range */
84 #define MNTOPT_NOALIGN  "noalign"       /* turn off stripe alignment */
85 #define MNTOPT_SWALLOC  "swalloc"       /* turn on stripe width allocation */
86 #define MNTOPT_SUNIT    "sunit"         /* data volume stripe unit */
87 #define MNTOPT_SWIDTH   "swidth"        /* data volume stripe width */
88 #define MNTOPT_NOUUID   "nouuid"        /* ignore filesystem UUID */
89 #define MNTOPT_MTPT     "mtpt"          /* filesystem mount point */
90 #define MNTOPT_GRPID    "grpid"         /* group-ID from parent directory */
91 #define MNTOPT_NOGRPID  "nogrpid"       /* group-ID from current process */
92 #define MNTOPT_BSDGROUPS    "bsdgroups"    /* group-ID from parent directory */
93 #define MNTOPT_SYSVGROUPS   "sysvgroups"   /* group-ID from current process */
94 #define MNTOPT_ALLOCSIZE    "allocsize"    /* preferred allocation size */
95 #define MNTOPT_NORECOVERY   "norecovery"   /* don't run XFS recovery */
96 #define MNTOPT_BARRIER  "barrier"       /* use writer barriers for log write and
97                                          * unwritten extent conversion */
98 #define MNTOPT_NOBARRIER "nobarrier"    /* .. disable */
99 #define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
100 #define MNTOPT_64BITINODE   "inode64"   /* inodes can be allocated anywhere */
101 #define MNTOPT_IKEEP    "ikeep"         /* do not free empty inode clusters */
102 #define MNTOPT_NOIKEEP  "noikeep"       /* free empty inode clusters */
103 #define MNTOPT_LARGEIO     "largeio"    /* report large I/O sizes in stat() */
104 #define MNTOPT_NOLARGEIO   "nolargeio"  /* do not report large I/O sizes
105                                          * in stat(). */
106 #define MNTOPT_ATTR2    "attr2"         /* do use attr2 attribute format */
107 #define MNTOPT_NOATTR2  "noattr2"       /* do not use attr2 attribute format */
108 #define MNTOPT_FILESTREAM  "filestreams" /* use filestreams allocator */
109 #define MNTOPT_QUOTA    "quota"         /* disk quotas (user) */
110 #define MNTOPT_NOQUOTA  "noquota"       /* no quotas */
111 #define MNTOPT_USRQUOTA "usrquota"      /* user quota enabled */
112 #define MNTOPT_GRPQUOTA "grpquota"      /* group quota enabled */
113 #define MNTOPT_PRJQUOTA "prjquota"      /* project quota enabled */
114 #define MNTOPT_UQUOTA   "uquota"        /* user quota (IRIX variant) */
115 #define MNTOPT_GQUOTA   "gquota"        /* group quota (IRIX variant) */
116 #define MNTOPT_PQUOTA   "pquota"        /* project quota (IRIX variant) */
117 #define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
118 #define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
119 #define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
120 #define MNTOPT_QUOTANOENF  "qnoenforce" /* same as uqnoenforce */
121 #define MNTOPT_DMAPI    "dmapi"         /* DMI enabled (DMAPI / XDSM) */
122 #define MNTOPT_XDSM     "xdsm"          /* DMI enabled (DMAPI / XDSM) */
123 #define MNTOPT_DMI      "dmi"           /* DMI enabled (DMAPI / XDSM) */
124
125 /*
126  * Table driven mount option parser.
127  *
128  * Currently only used for remount, but it will be used for mount
129  * in the future, too.
130  */
131 enum {
132         Opt_barrier, Opt_nobarrier, Opt_err
133 };
134
135 static const match_table_t tokens = {
136         {Opt_barrier, "barrier"},
137         {Opt_nobarrier, "nobarrier"},
138         {Opt_err, NULL}
139 };
140
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 /*
166  * This function fills in xfs_mount_t fields based on mount args.
167  * Note: the superblock has _not_ yet been read in.
168  *
169  * Note that this function leaks the various device name allocations on
170  * failure.  The caller takes care of them.
171  */
172 STATIC int
173 xfs_parseargs(
174         struct xfs_mount        *mp,
175         char                    *options,
176         char                    **mtpt)
177 {
178         struct super_block      *sb = mp->m_super;
179         char                    *this_char, *value, *eov;
180         int                     dsunit = 0;
181         int                     dswidth = 0;
182         int                     iosize = 0;
183         int                     dmapi_implies_ikeep = 1;
184         uchar_t                 iosizelog = 0;
185
186         /*
187          * Copy binary VFS mount flags we are interested in.
188          */
189         if (sb->s_flags & MS_RDONLY)
190                 mp->m_flags |= XFS_MOUNT_RDONLY;
191         if (sb->s_flags & MS_DIRSYNC)
192                 mp->m_flags |= XFS_MOUNT_DIRSYNC;
193         if (sb->s_flags & MS_SYNCHRONOUS)
194                 mp->m_flags |= XFS_MOUNT_WSYNC;
195
196         /*
197          * Set some default flags that could be cleared by the mount option
198          * parsing.
199          */
200         mp->m_flags |= XFS_MOUNT_BARRIER;
201         mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
202         mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
203
204         /*
205          * These can be overridden by the mount option parsing.
206          */
207         mp->m_logbufs = -1;
208         mp->m_logbsize = -1;
209
210         if (!options)
211                 goto done;
212
213         while ((this_char = strsep(&options, ",")) != NULL) {
214                 if (!*this_char)
215                         continue;
216                 if ((value = strchr(this_char, '=')) != NULL)
217                         *value++ = 0;
218
219                 if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
220                         if (!value || !*value) {
221                                 cmn_err(CE_WARN,
222                                         "XFS: %s option requires an argument",
223                                         this_char);
224                                 return EINVAL;
225                         }
226                         mp->m_logbufs = simple_strtoul(value, &eov, 10);
227                 } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
228                         if (!value || !*value) {
229                                 cmn_err(CE_WARN,
230                                         "XFS: %s option requires an argument",
231                                         this_char);
232                                 return EINVAL;
233                         }
234                         mp->m_logbsize = suffix_strtoul(value, &eov, 10);
235                 } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
236                         if (!value || !*value) {
237                                 cmn_err(CE_WARN,
238                                         "XFS: %s option requires an argument",
239                                         this_char);
240                                 return EINVAL;
241                         }
242                         mp->m_logname = kstrndup(value, MAXNAMELEN, GFP_KERNEL);
243                         if (!mp->m_logname)
244                                 return ENOMEM;
245                 } else if (!strcmp(this_char, MNTOPT_MTPT)) {
246                         if (!value || !*value) {
247                                 cmn_err(CE_WARN,
248                                         "XFS: %s option requires an argument",
249                                         this_char);
250                                 return EINVAL;
251                         }
252                         *mtpt = kstrndup(value, MAXNAMELEN, GFP_KERNEL);
253                         if (!*mtpt)
254                                 return ENOMEM;
255                 } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
256                         if (!value || !*value) {
257                                 cmn_err(CE_WARN,
258                                         "XFS: %s option requires an argument",
259                                         this_char);
260                                 return EINVAL;
261                         }
262                         mp->m_rtname = kstrndup(value, MAXNAMELEN, GFP_KERNEL);
263                         if (!mp->m_rtname)
264                                 return ENOMEM;
265                 } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
266                         if (!value || !*value) {
267                                 cmn_err(CE_WARN,
268                                         "XFS: %s option requires an argument",
269                                         this_char);
270                                 return EINVAL;
271                         }
272                         iosize = simple_strtoul(value, &eov, 10);
273                         iosizelog = ffs(iosize) - 1;
274                 } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
275                         if (!value || !*value) {
276                                 cmn_err(CE_WARN,
277                                         "XFS: %s option requires an argument",
278                                         this_char);
279                                 return EINVAL;
280                         }
281                         iosize = suffix_strtoul(value, &eov, 10);
282                         iosizelog = ffs(iosize) - 1;
283                 } else if (!strcmp(this_char, MNTOPT_GRPID) ||
284                            !strcmp(this_char, MNTOPT_BSDGROUPS)) {
285                         mp->m_flags |= XFS_MOUNT_GRPID;
286                 } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
287                            !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
288                         mp->m_flags &= ~XFS_MOUNT_GRPID;
289                 } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
290                         mp->m_flags |= XFS_MOUNT_WSYNC;
291                 } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
292                         mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
293                 } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
294                         mp->m_flags |= XFS_MOUNT_NORECOVERY;
295                 } else if (!strcmp(this_char, MNTOPT_INO64)) {
296 #if XFS_BIG_INUMS
297                         mp->m_flags |= XFS_MOUNT_INO64;
298                         mp->m_inoadd = XFS_INO64_OFFSET;
299 #else
300                         cmn_err(CE_WARN,
301                                 "XFS: %s option not allowed on this system",
302                                 this_char);
303                         return EINVAL;
304 #endif
305                 } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
306                         mp->m_flags |= XFS_MOUNT_NOALIGN;
307                 } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
308                         mp->m_flags |= XFS_MOUNT_SWALLOC;
309                 } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
310                         if (!value || !*value) {
311                                 cmn_err(CE_WARN,
312                                         "XFS: %s option requires an argument",
313                                         this_char);
314                                 return EINVAL;
315                         }
316                         dsunit = simple_strtoul(value, &eov, 10);
317                 } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
318                         if (!value || !*value) {
319                                 cmn_err(CE_WARN,
320                                         "XFS: %s option requires an argument",
321                                         this_char);
322                                 return EINVAL;
323                         }
324                         dswidth = simple_strtoul(value, &eov, 10);
325                 } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
326                         mp->m_flags &= ~XFS_MOUNT_SMALL_INUMS;
327 #if !XFS_BIG_INUMS
328                         cmn_err(CE_WARN,
329                                 "XFS: %s option not allowed on this system",
330                                 this_char);
331                         return EINVAL;
332 #endif
333                 } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
334                         mp->m_flags |= XFS_MOUNT_NOUUID;
335                 } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
336                         mp->m_flags |= XFS_MOUNT_BARRIER;
337                 } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
338                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
339                 } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
340                         mp->m_flags |= XFS_MOUNT_IKEEP;
341                 } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
342                         dmapi_implies_ikeep = 0;
343                         mp->m_flags &= ~XFS_MOUNT_IKEEP;
344                 } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
345                         mp->m_flags &= ~XFS_MOUNT_COMPAT_IOSIZE;
346                 } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
347                         mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
348                 } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
349                         mp->m_flags |= XFS_MOUNT_ATTR2;
350                 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
351                         mp->m_flags &= ~XFS_MOUNT_ATTR2;
352                         mp->m_flags |= XFS_MOUNT_NOATTR2;
353                 } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
354                         mp->m_flags |= XFS_MOUNT_FILESTREAMS;
355                 } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
356                         mp->m_qflags &= ~(XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE |
357                                           XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE |
358                                           XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE |
359                                           XFS_UQUOTA_ENFD | XFS_OQUOTA_ENFD);
360                 } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
361                            !strcmp(this_char, MNTOPT_UQUOTA) ||
362                            !strcmp(this_char, MNTOPT_USRQUOTA)) {
363                         mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE |
364                                          XFS_UQUOTA_ENFD);
365                 } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
366                            !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
367                         mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
368                         mp->m_qflags &= ~XFS_UQUOTA_ENFD;
369                 } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
370                            !strcmp(this_char, MNTOPT_PRJQUOTA)) {
371                         mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE |
372                                          XFS_OQUOTA_ENFD);
373                 } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
374                         mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
375                         mp->m_qflags &= ~XFS_OQUOTA_ENFD;
376                 } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
377                            !strcmp(this_char, MNTOPT_GRPQUOTA)) {
378                         mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE |
379                                          XFS_OQUOTA_ENFD);
380                 } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
381                         mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
382                         mp->m_qflags &= ~XFS_OQUOTA_ENFD;
383                 } else if (!strcmp(this_char, MNTOPT_DMAPI)) {
384                         mp->m_flags |= XFS_MOUNT_DMAPI;
385                 } else if (!strcmp(this_char, MNTOPT_XDSM)) {
386                         mp->m_flags |= XFS_MOUNT_DMAPI;
387                 } else if (!strcmp(this_char, MNTOPT_DMI)) {
388                         mp->m_flags |= XFS_MOUNT_DMAPI;
389                 } else if (!strcmp(this_char, "ihashsize")) {
390                         cmn_err(CE_WARN,
391         "XFS: ihashsize no longer used, option is deprecated.");
392                 } else if (!strcmp(this_char, "osyncisdsync")) {
393                         /* no-op, this is now the default */
394                         cmn_err(CE_WARN,
395         "XFS: osyncisdsync is now the default, option is deprecated.");
396                 } else if (!strcmp(this_char, "irixsgid")) {
397                         cmn_err(CE_WARN,
398         "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
399                 } else {
400                         cmn_err(CE_WARN,
401                                 "XFS: unknown mount option [%s].", this_char);
402                         return EINVAL;
403                 }
404         }
405
406         /*
407          * no recovery flag requires a read-only mount
408          */
409         if ((mp->m_flags & XFS_MOUNT_NORECOVERY) &&
410             !(mp->m_flags & XFS_MOUNT_RDONLY)) {
411                 cmn_err(CE_WARN, "XFS: no-recovery mounts must be read-only.");
412                 return EINVAL;
413         }
414
415         if ((mp->m_flags & XFS_MOUNT_NOALIGN) && (dsunit || dswidth)) {
416                 cmn_err(CE_WARN,
417         "XFS: sunit and swidth options incompatible with the noalign option");
418                 return EINVAL;
419         }
420
421         if ((mp->m_qflags & (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE)) &&
422             (mp->m_qflags & (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE))) {
423                 cmn_err(CE_WARN,
424                         "XFS: cannot mount with both project and group quota");
425                 return EINVAL;
426         }
427
428         if ((mp->m_flags & XFS_MOUNT_DMAPI) && (!*mtpt || *mtpt[0] == '\0')) {
429                 printk("XFS: %s option needs the mount point option as well\n",
430                         MNTOPT_DMAPI);
431                 return EINVAL;
432         }
433
434         if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
435                 cmn_err(CE_WARN,
436                         "XFS: sunit and swidth must be specified together");
437                 return EINVAL;
438         }
439
440         if (dsunit && (dswidth % dsunit != 0)) {
441                 cmn_err(CE_WARN,
442         "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
443                         dswidth, dsunit);
444                 return EINVAL;
445         }
446
447         /*
448          * Applications using DMI filesystems often expect the
449          * inode generation number to be monotonically increasing.
450          * If we delete inode chunks we break this assumption, so
451          * keep unused inode chunks on disk for DMI filesystems
452          * until we come up with a better solution.
453          * Note that if "ikeep" or "noikeep" mount options are
454          * supplied, then they are honored.
455          */
456         if ((mp->m_flags & XFS_MOUNT_DMAPI) && dmapi_implies_ikeep)
457                 mp->m_flags |= XFS_MOUNT_IKEEP;
458
459 done:
460         if (!(mp->m_flags & XFS_MOUNT_NOALIGN)) {
461                 /*
462                  * At this point the superblock has not been read
463                  * in, therefore we do not know the block size.
464                  * Before the mount call ends we will convert
465                  * these to FSBs.
466                  */
467                 if (dsunit) {
468                         mp->m_dalign = dsunit;
469                         mp->m_flags |= XFS_MOUNT_RETERR;
470                 }
471
472                 if (dswidth)
473                         mp->m_swidth = dswidth;
474         }
475
476         if (mp->m_logbufs != -1 &&
477             mp->m_logbufs != 0 &&
478             (mp->m_logbufs < XLOG_MIN_ICLOGS ||
479              mp->m_logbufs > XLOG_MAX_ICLOGS)) {
480                 cmn_err(CE_WARN,
481                         "XFS: invalid logbufs value: %d [not %d-%d]",
482                         mp->m_logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
483                 return XFS_ERROR(EINVAL);
484         }
485         if (mp->m_logbsize != -1 &&
486             mp->m_logbsize !=  0 &&
487             (mp->m_logbsize < XLOG_MIN_RECORD_BSIZE ||
488              mp->m_logbsize > XLOG_MAX_RECORD_BSIZE ||
489              !is_power_of_2(mp->m_logbsize))) {
490                 cmn_err(CE_WARN,
491         "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
492                         mp->m_logbsize);
493                 return XFS_ERROR(EINVAL);
494         }
495
496         mp->m_fsname = kstrndup(sb->s_id, MAXNAMELEN, GFP_KERNEL);
497         if (!mp->m_fsname)
498                 return ENOMEM;
499         mp->m_fsname_len = strlen(mp->m_fsname) + 1;
500
501         if (iosizelog) {
502                 if (iosizelog > XFS_MAX_IO_LOG ||
503                     iosizelog < XFS_MIN_IO_LOG) {
504                         cmn_err(CE_WARN,
505                 "XFS: invalid log iosize: %d [not %d-%d]",
506                                 iosizelog, XFS_MIN_IO_LOG,
507                                 XFS_MAX_IO_LOG);
508                         return XFS_ERROR(EINVAL);
509                 }
510
511                 mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
512                 mp->m_readio_log = iosizelog;
513                 mp->m_writeio_log = iosizelog;
514         }
515
516         return 0;
517 }
518
519 struct proc_xfs_info {
520         int     flag;
521         char    *str;
522 };
523
524 STATIC int
525 xfs_showargs(
526         struct xfs_mount        *mp,
527         struct seq_file         *m)
528 {
529         static struct proc_xfs_info xfs_info_set[] = {
530                 /* the few simple ones we can get from the mount struct */
531                 { XFS_MOUNT_IKEEP,              "," MNTOPT_IKEEP },
532                 { XFS_MOUNT_WSYNC,              "," MNTOPT_WSYNC },
533                 { XFS_MOUNT_INO64,              "," MNTOPT_INO64 },
534                 { XFS_MOUNT_NOALIGN,            "," MNTOPT_NOALIGN },
535                 { XFS_MOUNT_SWALLOC,            "," MNTOPT_SWALLOC },
536                 { XFS_MOUNT_NOUUID,             "," MNTOPT_NOUUID },
537                 { XFS_MOUNT_NORECOVERY,         "," MNTOPT_NORECOVERY },
538                 { XFS_MOUNT_OSYNCISOSYNC,       "," MNTOPT_OSYNCISOSYNC },
539                 { XFS_MOUNT_ATTR2,              "," MNTOPT_ATTR2 },
540                 { XFS_MOUNT_FILESTREAMS,        "," MNTOPT_FILESTREAM },
541                 { XFS_MOUNT_DMAPI,              "," MNTOPT_DMAPI },
542                 { XFS_MOUNT_GRPID,              "," MNTOPT_GRPID },
543                 { 0, NULL }
544         };
545         static struct proc_xfs_info xfs_info_unset[] = {
546                 /* the few simple ones we can get from the mount struct */
547                 { XFS_MOUNT_COMPAT_IOSIZE,      "," MNTOPT_LARGEIO },
548                 { XFS_MOUNT_BARRIER,            "," MNTOPT_NOBARRIER },
549                 { XFS_MOUNT_SMALL_INUMS,        "," MNTOPT_64BITINODE },
550                 { 0, NULL }
551         };
552         struct proc_xfs_info    *xfs_infop;
553
554         for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
555                 if (mp->m_flags & xfs_infop->flag)
556                         seq_puts(m, xfs_infop->str);
557         }
558         for (xfs_infop = xfs_info_unset; xfs_infop->flag; xfs_infop++) {
559                 if (!(mp->m_flags & xfs_infop->flag))
560                         seq_puts(m, xfs_infop->str);
561         }
562
563         if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
564                 seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
565                                 (int)(1 << mp->m_writeio_log) >> 10);
566
567         if (mp->m_logbufs > 0)
568                 seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
569         if (mp->m_logbsize > 0)
570                 seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
571
572         if (mp->m_logname)
573                 seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
574         if (mp->m_rtname)
575                 seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
576
577         if (mp->m_dalign > 0)
578                 seq_printf(m, "," MNTOPT_SUNIT "=%d",
579                                 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
580         if (mp->m_swidth > 0)
581                 seq_printf(m, "," MNTOPT_SWIDTH "=%d",
582                                 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
583
584         if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD))
585                 seq_puts(m, "," MNTOPT_USRQUOTA);
586         else if (mp->m_qflags & XFS_UQUOTA_ACCT)
587                 seq_puts(m, "," MNTOPT_UQUOTANOENF);
588
589         if (mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_OQUOTA_ENFD))
590                 seq_puts(m, "," MNTOPT_PRJQUOTA);
591         else if (mp->m_qflags & XFS_PQUOTA_ACCT)
592                 seq_puts(m, "," MNTOPT_PQUOTANOENF);
593
594         if (mp->m_qflags & (XFS_GQUOTA_ACCT|XFS_OQUOTA_ENFD))
595                 seq_puts(m, "," MNTOPT_GRPQUOTA);
596         else if (mp->m_qflags & XFS_GQUOTA_ACCT)
597                 seq_puts(m, "," MNTOPT_GQUOTANOENF);
598
599         if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
600                 seq_puts(m, "," MNTOPT_NOQUOTA);
601
602         return 0;
603 }
604 __uint64_t
605 xfs_max_file_offset(
606         unsigned int            blockshift)
607 {
608         unsigned int            pagefactor = 1;
609         unsigned int            bitshift = BITS_PER_LONG - 1;
610
611         /* Figure out maximum filesize, on Linux this can depend on
612          * the filesystem blocksize (on 32 bit platforms).
613          * __block_prepare_write does this in an [unsigned] long...
614          *      page->index << (PAGE_CACHE_SHIFT - bbits)
615          * So, for page sized blocks (4K on 32 bit platforms),
616          * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
617          *      (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
618          * but for smaller blocksizes it is less (bbits = log2 bsize).
619          * Note1: get_block_t takes a long (implicit cast from above)
620          * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch
621          * can optionally convert the [unsigned] long from above into
622          * an [unsigned] long long.
623          */
624
625 #if BITS_PER_LONG == 32
626 # if defined(CONFIG_LBD)
627         ASSERT(sizeof(sector_t) == 8);
628         pagefactor = PAGE_CACHE_SIZE;
629         bitshift = BITS_PER_LONG;
630 # else
631         pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift);
632 # endif
633 #endif
634
635         return (((__uint64_t)pagefactor) << bitshift) - 1;
636 }
637
638 int
639 xfs_blkdev_get(
640         xfs_mount_t             *mp,
641         const char              *name,
642         struct block_device     **bdevp)
643 {
644         int                     error = 0;
645
646         *bdevp = open_bdev_exclusive(name, FMODE_READ|FMODE_WRITE, mp);
647         if (IS_ERR(*bdevp)) {
648                 error = PTR_ERR(*bdevp);
649                 printk("XFS: Invalid device [%s], error=%d\n", name, error);
650         }
651
652         return -error;
653 }
654
655 void
656 xfs_blkdev_put(
657         struct block_device     *bdev)
658 {
659         if (bdev)
660                 close_bdev_exclusive(bdev, FMODE_READ|FMODE_WRITE);
661 }
662
663 /*
664  * Try to write out the superblock using barriers.
665  */
666 STATIC int
667 xfs_barrier_test(
668         xfs_mount_t     *mp)
669 {
670         xfs_buf_t       *sbp = xfs_getsb(mp, 0);
671         int             error;
672
673         XFS_BUF_UNDONE(sbp);
674         XFS_BUF_UNREAD(sbp);
675         XFS_BUF_UNDELAYWRITE(sbp);
676         XFS_BUF_WRITE(sbp);
677         XFS_BUF_UNASYNC(sbp);
678         XFS_BUF_ORDERED(sbp);
679
680         xfsbdstrat(mp, sbp);
681         error = xfs_iowait(sbp);
682
683         /*
684          * Clear all the flags we set and possible error state in the
685          * buffer.  We only did the write to try out whether barriers
686          * worked and shouldn't leave any traces in the superblock
687          * buffer.
688          */
689         XFS_BUF_DONE(sbp);
690         XFS_BUF_ERROR(sbp, 0);
691         XFS_BUF_UNORDERED(sbp);
692
693         xfs_buf_relse(sbp);
694         return error;
695 }
696
697 void
698 xfs_mountfs_check_barriers(xfs_mount_t *mp)
699 {
700         int error;
701
702         if (mp->m_logdev_targp != mp->m_ddev_targp) {
703                 xfs_fs_cmn_err(CE_NOTE, mp,
704                   "Disabling barriers, not supported with external log device");
705                 mp->m_flags &= ~XFS_MOUNT_BARRIER;
706                 return;
707         }
708
709         if (xfs_readonly_buftarg(mp->m_ddev_targp)) {
710                 xfs_fs_cmn_err(CE_NOTE, mp,
711                   "Disabling barriers, underlying device is readonly");
712                 mp->m_flags &= ~XFS_MOUNT_BARRIER;
713                 return;
714         }
715
716         error = xfs_barrier_test(mp);
717         if (error) {
718                 xfs_fs_cmn_err(CE_NOTE, mp,
719                   "Disabling barriers, trial barrier write failed");
720                 mp->m_flags &= ~XFS_MOUNT_BARRIER;
721                 return;
722         }
723 }
724
725 void
726 xfs_blkdev_issue_flush(
727         xfs_buftarg_t           *buftarg)
728 {
729         blkdev_issue_flush(buftarg->bt_bdev, NULL);
730 }
731
732 STATIC void
733 xfs_close_devices(
734         struct xfs_mount        *mp)
735 {
736         if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
737                 struct block_device *logdev = mp->m_logdev_targp->bt_bdev;
738                 xfs_free_buftarg(mp->m_logdev_targp);
739                 xfs_blkdev_put(logdev);
740         }
741         if (mp->m_rtdev_targp) {
742                 struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev;
743                 xfs_free_buftarg(mp->m_rtdev_targp);
744                 xfs_blkdev_put(rtdev);
745         }
746         xfs_free_buftarg(mp->m_ddev_targp);
747 }
748
749 /*
750  * The file system configurations are:
751  *      (1) device (partition) with data and internal log
752  *      (2) logical volume with data and log subvolumes.
753  *      (3) logical volume with data, log, and realtime subvolumes.
754  *
755  * We only have to handle opening the log and realtime volumes here if
756  * they are present.  The data subvolume has already been opened by
757  * get_sb_bdev() and is stored in sb->s_bdev.
758  */
759 STATIC int
760 xfs_open_devices(
761         struct xfs_mount        *mp)
762 {
763         struct block_device     *ddev = mp->m_super->s_bdev;
764         struct block_device     *logdev = NULL, *rtdev = NULL;
765         int                     error;
766
767         /*
768          * Open real time and log devices - order is important.
769          */
770         if (mp->m_logname) {
771                 error = xfs_blkdev_get(mp, mp->m_logname, &logdev);
772                 if (error)
773                         goto out;
774         }
775
776         if (mp->m_rtname) {
777                 error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev);
778                 if (error)
779                         goto out_close_logdev;
780
781                 if (rtdev == ddev || rtdev == logdev) {
782                         cmn_err(CE_WARN,
783         "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
784                         error = EINVAL;
785                         goto out_close_rtdev;
786                 }
787         }
788
789         /*
790          * Setup xfs_mount buffer target pointers
791          */
792         error = ENOMEM;
793         mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
794         if (!mp->m_ddev_targp)
795                 goto out_close_rtdev;
796
797         if (rtdev) {
798                 mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
799                 if (!mp->m_rtdev_targp)
800                         goto out_free_ddev_targ;
801         }
802
803         if (logdev && logdev != ddev) {
804                 mp->m_logdev_targp = xfs_alloc_buftarg(logdev, 1);
805                 if (!mp->m_logdev_targp)
806                         goto out_free_rtdev_targ;
807         } else {
808                 mp->m_logdev_targp = mp->m_ddev_targp;
809         }
810
811         return 0;
812
813  out_free_rtdev_targ:
814         if (mp->m_rtdev_targp)
815                 xfs_free_buftarg(mp->m_rtdev_targp);
816  out_free_ddev_targ:
817         xfs_free_buftarg(mp->m_ddev_targp);
818  out_close_rtdev:
819         if (rtdev)
820                 xfs_blkdev_put(rtdev);
821  out_close_logdev:
822         if (logdev && logdev != ddev)
823                 xfs_blkdev_put(logdev);
824  out:
825         return error;
826 }
827
828 /*
829  * Setup xfs_mount buffer target pointers based on superblock
830  */
831 STATIC int
832 xfs_setup_devices(
833         struct xfs_mount        *mp)
834 {
835         int                     error;
836
837         error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
838                                     mp->m_sb.sb_sectsize);
839         if (error)
840                 return error;
841
842         if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
843                 unsigned int    log_sector_size = BBSIZE;
844
845                 if (xfs_sb_version_hassector(&mp->m_sb))
846                         log_sector_size = mp->m_sb.sb_logsectsize;
847                 error = xfs_setsize_buftarg(mp->m_logdev_targp,
848                                             mp->m_sb.sb_blocksize,
849                                             log_sector_size);
850                 if (error)
851                         return error;
852         }
853         if (mp->m_rtdev_targp) {
854                 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
855                                             mp->m_sb.sb_blocksize,
856                                             mp->m_sb.sb_sectsize);
857                 if (error)
858                         return error;
859         }
860
861         return 0;
862 }
863
864 /*
865  * XFS AIL push thread support
866  */
867 void
868 xfsaild_wakeup(
869         struct xfs_ail          *ailp,
870         xfs_lsn_t               threshold_lsn)
871 {
872         ailp->xa_target = threshold_lsn;
873         wake_up_process(ailp->xa_task);
874 }
875
876 int
877 xfsaild(
878         void    *data)
879 {
880         struct xfs_ail  *ailp = data;
881         xfs_lsn_t       last_pushed_lsn = 0;
882         long            tout = 0;
883
884         while (!kthread_should_stop()) {
885                 if (tout)
886                         schedule_timeout_interruptible(msecs_to_jiffies(tout));
887                 tout = 1000;
888
889                 /* swsusp */
890                 try_to_freeze();
891
892                 ASSERT(ailp->xa_mount->m_log);
893                 if (XFS_FORCED_SHUTDOWN(ailp->xa_mount))
894                         continue;
895
896                 tout = xfsaild_push(ailp, &last_pushed_lsn);
897         }
898
899         return 0;
900 }       /* xfsaild */
901
902 int
903 xfsaild_start(
904         struct xfs_ail  *ailp)
905 {
906         ailp->xa_target = 0;
907         ailp->xa_task = kthread_run(xfsaild, ailp, "xfsaild");
908         if (IS_ERR(ailp->xa_task))
909                 return -PTR_ERR(ailp->xa_task);
910         return 0;
911 }
912
913 void
914 xfsaild_stop(
915         struct xfs_ail  *ailp)
916 {
917         kthread_stop(ailp->xa_task);
918 }
919
920
921 /* Catch misguided souls that try to use this interface on XFS */
922 STATIC struct inode *
923 xfs_fs_alloc_inode(
924         struct super_block      *sb)
925 {
926         BUG();
927         return NULL;
928 }
929
930 /*
931  * Now that the generic code is guaranteed not to be accessing
932  * the linux inode, we can reclaim the inode.
933  */
934 STATIC void
935 xfs_fs_destroy_inode(
936         struct inode    *inode)
937 {
938         xfs_inode_t             *ip = XFS_I(inode);
939
940         XFS_STATS_INC(vn_reclaim);
941         if (xfs_reclaim(ip))
942                 panic("%s: cannot reclaim 0x%p\n", __func__, inode);
943 }
944
945 /*
946  * Slab object creation initialisation for the XFS inode.
947  * This covers only the idempotent fields in the XFS inode;
948  * all other fields need to be initialised on allocation
949  * from the slab. This avoids the need to repeatedly intialise
950  * fields in the xfs inode that left in the initialise state
951  * when freeing the inode.
952  */
953 STATIC void
954 xfs_fs_inode_init_once(
955         void                    *inode)
956 {
957         struct xfs_inode        *ip = inode;
958
959         memset(ip, 0, sizeof(struct xfs_inode));
960
961         /* vfs inode */
962         inode_init_once(VFS_I(ip));
963
964         /* xfs inode */
965         atomic_set(&ip->i_iocount, 0);
966         atomic_set(&ip->i_pincount, 0);
967         spin_lock_init(&ip->i_flags_lock);
968         init_waitqueue_head(&ip->i_ipin_wait);
969         /*
970          * Because we want to use a counting completion, complete
971          * the flush completion once to allow a single access to
972          * the flush completion without blocking.
973          */
974         init_completion(&ip->i_flush);
975         complete(&ip->i_flush);
976
977         mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
978                      "xfsino", ip->i_ino);
979         mrlock_init(&ip->i_iolock, MRLOCK_BARRIER, "xfsio", ip->i_ino);
980 }
981
982 /*
983  * Attempt to flush the inode, this will actually fail
984  * if the inode is pinned, but we dirty the inode again
985  * at the point when it is unpinned after a log write,
986  * since this is when the inode itself becomes flushable.
987  */
988 STATIC int
989 xfs_fs_write_inode(
990         struct inode            *inode,
991         int                     sync)
992 {
993         int                     error = 0;
994         int                     flags = 0;
995
996         xfs_itrace_entry(XFS_I(inode));
997         if (sync) {
998                 filemap_fdatawait(inode->i_mapping);
999                 flags |= FLUSH_SYNC;
1000         }
1001         error = xfs_inode_flush(XFS_I(inode), flags);
1002         /*
1003          * if we failed to write out the inode then mark
1004          * it dirty again so we'll try again later.
1005          */
1006         if (error)
1007                 xfs_mark_inode_dirty_sync(XFS_I(inode));
1008
1009         return -error;
1010 }
1011
1012 STATIC void
1013 xfs_fs_clear_inode(
1014         struct inode            *inode)
1015 {
1016         xfs_inode_t             *ip = XFS_I(inode);
1017
1018         xfs_itrace_entry(ip);
1019         XFS_STATS_INC(vn_rele);
1020         XFS_STATS_INC(vn_remove);
1021         XFS_STATS_DEC(vn_active);
1022
1023         xfs_inactive(ip);
1024         xfs_iflags_clear(ip, XFS_IMODIFIED);
1025 }
1026
1027 STATIC void
1028 xfs_free_fsname(
1029         struct xfs_mount        *mp)
1030 {
1031         kfree(mp->m_fsname);
1032         kfree(mp->m_rtname);
1033         kfree(mp->m_logname);
1034 }
1035
1036 STATIC void
1037 xfs_fs_put_super(
1038         struct super_block      *sb)
1039 {
1040         struct xfs_mount        *mp = XFS_M(sb);
1041         struct xfs_inode        *rip = mp->m_rootip;
1042         int                     unmount_event_flags = 0;
1043         int                     error;
1044
1045         xfs_syncd_stop(mp);
1046         xfs_sync_inodes(mp, SYNC_ATTR|SYNC_DELWRI);
1047
1048 #ifdef HAVE_DMAPI
1049         if (mp->m_flags & XFS_MOUNT_DMAPI) {
1050                 unmount_event_flags =
1051                         (mp->m_dmevmask & (1 << DM_EVENT_UNMOUNT)) ?
1052                                 0 : DM_FLAGS_UNWANTED;
1053                 /*
1054                  * Ignore error from dmapi here, first unmount is not allowed
1055                  * to fail anyway, and second we wouldn't want to fail a
1056                  * unmount because of dmapi.
1057                  */
1058                 XFS_SEND_PREUNMOUNT(mp, rip, DM_RIGHT_NULL, rip, DM_RIGHT_NULL,
1059                                 NULL, NULL, 0, 0, unmount_event_flags);
1060         }
1061 #endif
1062
1063         /*
1064          * Blow away any referenced inode in the filestreams cache.
1065          * This can and will cause log traffic as inodes go inactive
1066          * here.
1067          */
1068         xfs_filestream_unmount(mp);
1069
1070         XFS_bflush(mp->m_ddev_targp);
1071         error = xfs_unmount_flush(mp, 0);
1072         WARN_ON(error);
1073
1074         if (mp->m_flags & XFS_MOUNT_DMAPI) {
1075                 XFS_SEND_UNMOUNT(mp, rip, DM_RIGHT_NULL, 0, 0,
1076                                 unmount_event_flags);
1077         }
1078
1079         xfs_unmountfs(mp);
1080         xfs_freesb(mp);
1081         xfs_icsb_destroy_counters(mp);
1082         xfs_close_devices(mp);
1083         xfs_qmops_put(mp);
1084         xfs_dmops_put(mp);
1085         xfs_free_fsname(mp);
1086         kfree(mp);
1087 }
1088
1089 STATIC void
1090 xfs_fs_write_super(
1091         struct super_block      *sb)
1092 {
1093         if (!(sb->s_flags & MS_RDONLY))
1094                 xfs_sync_fsdata(XFS_M(sb), 0);
1095         sb->s_dirt = 0;
1096 }
1097
1098 STATIC int
1099 xfs_fs_sync_super(
1100         struct super_block      *sb,
1101         int                     wait)
1102 {
1103         struct xfs_mount        *mp = XFS_M(sb);
1104         int                     error;
1105
1106         /*
1107          * Treat a sync operation like a freeze.  This is to work
1108          * around a race in sync_inodes() which works in two phases
1109          * - an asynchronous flush, which can write out an inode
1110          * without waiting for file size updates to complete, and a
1111          * synchronous flush, which wont do anything because the
1112          * async flush removed the inode's dirty flag.  Also
1113          * sync_inodes() will not see any files that just have
1114          * outstanding transactions to be flushed because we don't
1115          * dirty the Linux inode until after the transaction I/O
1116          * completes.
1117          */
1118         if (wait || unlikely(sb->s_frozen == SB_FREEZE_WRITE))
1119                 error = xfs_quiesce_data(mp);
1120         else
1121                 error = xfs_sync_fsdata(mp, 0);
1122         sb->s_dirt = 0;
1123
1124         if (unlikely(laptop_mode)) {
1125                 int     prev_sync_seq = mp->m_sync_seq;
1126
1127                 /*
1128                  * The disk must be active because we're syncing.
1129                  * We schedule xfssyncd now (now that the disk is
1130                  * active) instead of later (when it might not be).
1131                  */
1132                 wake_up_process(mp->m_sync_task);
1133                 /*
1134                  * We have to wait for the sync iteration to complete.
1135                  * If we don't, the disk activity caused by the sync
1136                  * will come after the sync is completed, and that
1137                  * triggers another sync from laptop mode.
1138                  */
1139                 wait_event(mp->m_wait_single_sync_task,
1140                                 mp->m_sync_seq != prev_sync_seq);
1141         }
1142
1143         return -error;
1144 }
1145
1146 STATIC int
1147 xfs_fs_statfs(
1148         struct dentry           *dentry,
1149         struct kstatfs          *statp)
1150 {
1151         struct xfs_mount        *mp = XFS_M(dentry->d_sb);
1152         xfs_sb_t                *sbp = &mp->m_sb;
1153         __uint64_t              fakeinos, id;
1154         xfs_extlen_t            lsize;
1155
1156         statp->f_type = XFS_SB_MAGIC;
1157         statp->f_namelen = MAXNAMELEN - 1;
1158
1159         id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
1160         statp->f_fsid.val[0] = (u32)id;
1161         statp->f_fsid.val[1] = (u32)(id >> 32);
1162
1163         xfs_icsb_sync_counters(mp, XFS_ICSB_LAZY_COUNT);
1164
1165         spin_lock(&mp->m_sb_lock);
1166         statp->f_bsize = sbp->sb_blocksize;
1167         lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
1168         statp->f_blocks = sbp->sb_dblocks - lsize;
1169         statp->f_bfree = statp->f_bavail =
1170                                 sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
1171         fakeinos = statp->f_bfree << sbp->sb_inopblog;
1172 #if XFS_BIG_INUMS
1173         fakeinos += mp->m_inoadd;
1174 #endif
1175         statp->f_files =
1176             MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
1177         if (mp->m_maxicount)
1178 #if XFS_BIG_INUMS
1179                 if (!mp->m_inoadd)
1180 #endif
1181                         statp->f_files = min_t(typeof(statp->f_files),
1182                                                 statp->f_files,
1183                                                 mp->m_maxicount);
1184         statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
1185         spin_unlock(&mp->m_sb_lock);
1186
1187         XFS_QM_DQSTATVFS(XFS_I(dentry->d_inode), statp);
1188         return 0;
1189 }
1190
1191 STATIC int
1192 xfs_fs_remount(
1193         struct super_block      *sb,
1194         int                     *flags,
1195         char                    *options)
1196 {
1197         struct xfs_mount        *mp = XFS_M(sb);
1198         substring_t             args[MAX_OPT_ARGS];
1199         char                    *p;
1200
1201         while ((p = strsep(&options, ",")) != NULL) {
1202                 int token;
1203
1204                 if (!*p)
1205                         continue;
1206
1207                 token = match_token(p, tokens, args);
1208                 switch (token) {
1209                 case Opt_barrier:
1210                         mp->m_flags |= XFS_MOUNT_BARRIER;
1211
1212                         /*
1213                          * Test if barriers are actually working if we can,
1214                          * else delay this check until the filesystem is
1215                          * marked writeable.
1216                          */
1217                         if (!(mp->m_flags & XFS_MOUNT_RDONLY))
1218                                 xfs_mountfs_check_barriers(mp);
1219                         break;
1220                 case Opt_nobarrier:
1221                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
1222                         break;
1223                 default:
1224                         /*
1225                          * Logically we would return an error here to prevent
1226                          * users from believing they might have changed
1227                          * mount options using remount which can't be changed.
1228                          *
1229                          * But unfortunately mount(8) adds all options from
1230                          * mtab and fstab to the mount arguments in some cases
1231                          * so we can't blindly reject options, but have to
1232                          * check for each specified option if it actually
1233                          * differs from the currently set option and only
1234                          * reject it if that's the case.
1235                          *
1236                          * Until that is implemented we return success for
1237                          * every remount request, and silently ignore all
1238                          * options that we can't actually change.
1239                          */
1240 #if 0
1241                         printk(KERN_INFO
1242         "XFS: mount option \"%s\" not supported for remount\n", p);
1243                         return -EINVAL;
1244 #else
1245                         break;
1246 #endif
1247                 }
1248         }
1249
1250         /* rw/ro -> rw */
1251         if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(*flags & MS_RDONLY)) {
1252                 mp->m_flags &= ~XFS_MOUNT_RDONLY;
1253                 if (mp->m_flags & XFS_MOUNT_BARRIER)
1254                         xfs_mountfs_check_barriers(mp);
1255         }
1256
1257         /* rw -> ro */
1258         if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (*flags & MS_RDONLY)) {
1259                 xfs_quiesce_data(mp);
1260                 xfs_quiesce_attr(mp);
1261                 mp->m_flags |= XFS_MOUNT_RDONLY;
1262         }
1263
1264         return 0;
1265 }
1266
1267 /*
1268  * Second stage of a freeze. The data is already frozen so we only
1269  * need to take care of the metadata. Once that's done write a dummy
1270  * record to dirty the log in case of a crash while frozen.
1271  */
1272 STATIC void
1273 xfs_fs_lockfs(
1274         struct super_block      *sb)
1275 {
1276         struct xfs_mount        *mp = XFS_M(sb);
1277
1278         xfs_quiesce_attr(mp);
1279         xfs_fs_log_dummy(mp);
1280 }
1281
1282 STATIC int
1283 xfs_fs_show_options(
1284         struct seq_file         *m,
1285         struct vfsmount         *mnt)
1286 {
1287         return -xfs_showargs(XFS_M(mnt->mnt_sb), m);
1288 }
1289
1290 STATIC int
1291 xfs_fs_quotasync(
1292         struct super_block      *sb,
1293         int                     type)
1294 {
1295         return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XQUOTASYNC, 0, NULL);
1296 }
1297
1298 STATIC int
1299 xfs_fs_getxstate(
1300         struct super_block      *sb,
1301         struct fs_quota_stat    *fqs)
1302 {
1303         return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XGETQSTAT, 0, (caddr_t)fqs);
1304 }
1305
1306 STATIC int
1307 xfs_fs_setxstate(
1308         struct super_block      *sb,
1309         unsigned int            flags,
1310         int                     op)
1311 {
1312         return -XFS_QM_QUOTACTL(XFS_M(sb), op, 0, (caddr_t)&flags);
1313 }
1314
1315 STATIC int
1316 xfs_fs_getxquota(
1317         struct super_block      *sb,
1318         int                     type,
1319         qid_t                   id,
1320         struct fs_disk_quota    *fdq)
1321 {
1322         return -XFS_QM_QUOTACTL(XFS_M(sb),
1323                                  (type == USRQUOTA) ? Q_XGETQUOTA :
1324                                   ((type == GRPQUOTA) ? Q_XGETGQUOTA :
1325                                    Q_XGETPQUOTA), id, (caddr_t)fdq);
1326 }
1327
1328 STATIC int
1329 xfs_fs_setxquota(
1330         struct super_block      *sb,
1331         int                     type,
1332         qid_t                   id,
1333         struct fs_disk_quota    *fdq)
1334 {
1335         return -XFS_QM_QUOTACTL(XFS_M(sb),
1336                                  (type == USRQUOTA) ? Q_XSETQLIM :
1337                                   ((type == GRPQUOTA) ? Q_XSETGQLIM :
1338                                    Q_XSETPQLIM), id, (caddr_t)fdq);
1339 }
1340
1341 /*
1342  * This function fills in xfs_mount_t fields based on mount args.
1343  * Note: the superblock _has_ now been read in.
1344  */
1345 STATIC int
1346 xfs_finish_flags(
1347         struct xfs_mount        *mp)
1348 {
1349         int                     ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
1350
1351         /* Fail a mount where the logbuf is smaller then the log stripe */
1352         if (xfs_sb_version_haslogv2(&mp->m_sb)) {
1353                 if (mp->m_logbsize <= 0 &&
1354                     mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE) {
1355                         mp->m_logbsize = mp->m_sb.sb_logsunit;
1356                 } else if (mp->m_logbsize > 0 &&
1357                            mp->m_logbsize < mp->m_sb.sb_logsunit) {
1358                         cmn_err(CE_WARN,
1359         "XFS: logbuf size must be greater than or equal to log stripe size");
1360                         return XFS_ERROR(EINVAL);
1361                 }
1362         } else {
1363                 /* Fail a mount if the logbuf is larger than 32K */
1364                 if (mp->m_logbsize > XLOG_BIG_RECORD_BSIZE) {
1365                         cmn_err(CE_WARN,
1366         "XFS: logbuf size for version 1 logs must be 16K or 32K");
1367                         return XFS_ERROR(EINVAL);
1368                 }
1369         }
1370
1371         /*
1372          * mkfs'ed attr2 will turn on attr2 mount unless explicitly
1373          * told by noattr2 to turn it off
1374          */
1375         if (xfs_sb_version_hasattr2(&mp->m_sb) &&
1376             !(mp->m_flags & XFS_MOUNT_NOATTR2))
1377                 mp->m_flags |= XFS_MOUNT_ATTR2;
1378
1379         /*
1380          * prohibit r/w mounts of read-only filesystems
1381          */
1382         if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
1383                 cmn_err(CE_WARN,
1384         "XFS: cannot mount a read-only filesystem as read-write");
1385                 return XFS_ERROR(EROFS);
1386         }
1387
1388 #if 0 /* shared mounts were never supported on Linux */
1389         /*
1390          * check for shared mount.
1391          */
1392         if (ap->flags & XFSMNT_SHARED) {
1393                 if (!xfs_sb_version_hasshared(&mp->m_sb))
1394                         return XFS_ERROR(EINVAL);
1395
1396                 /*
1397                  * For IRIX 6.5, shared mounts must have the shared
1398                  * version bit set, have the persistent readonly
1399                  * field set, must be version 0 and can only be mounted
1400                  * read-only.
1401                  */
1402                 if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) ||
1403                      (mp->m_sb.sb_shared_vn != 0))
1404                         return XFS_ERROR(EINVAL);
1405
1406                 mp->m_flags |= XFS_MOUNT_SHARED;
1407
1408                 /*
1409                  * Shared XFS V0 can't deal with DMI.  Return EINVAL.
1410                  */
1411                 if (mp->m_sb.sb_shared_vn == 0 &&
1412                     (mp->m_flags & XFS_MOUNT_DMAPI))
1413                         return XFS_ERROR(EINVAL);
1414         }
1415 #endif
1416
1417         return 0;
1418 }
1419
1420 STATIC int
1421 xfs_fs_fill_super(
1422         struct super_block      *sb,
1423         void                    *data,
1424         int                     silent)
1425 {
1426         struct inode            *root;
1427         struct xfs_mount        *mp = NULL;
1428         int                     flags = 0, error = ENOMEM;
1429         char                    *mtpt = NULL;
1430
1431         mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
1432         if (!mp)
1433                 goto out;
1434
1435         spin_lock_init(&mp->m_sb_lock);
1436         mutex_init(&mp->m_growlock);
1437         atomic_set(&mp->m_active_trans, 0);
1438         INIT_LIST_HEAD(&mp->m_sync_list);
1439         spin_lock_init(&mp->m_sync_lock);
1440         init_waitqueue_head(&mp->m_wait_single_sync_task);
1441
1442         mp->m_super = sb;
1443         sb->s_fs_info = mp;
1444
1445         error = xfs_parseargs(mp, (char *)data, &mtpt);
1446         if (error)
1447                 goto out_free_fsname;
1448
1449         sb_min_blocksize(sb, BBSIZE);
1450         sb->s_xattr = xfs_xattr_handlers;
1451         sb->s_export_op = &xfs_export_operations;
1452         sb->s_qcop = &xfs_quotactl_operations;
1453         sb->s_op = &xfs_super_operations;
1454
1455         error = xfs_dmops_get(mp);
1456         if (error)
1457                 goto out_free_fsname;
1458         error = xfs_qmops_get(mp);
1459         if (error)
1460                 goto out_put_dmops;
1461
1462         if (silent)
1463                 flags |= XFS_MFSI_QUIET;
1464
1465         error = xfs_open_devices(mp);
1466         if (error)
1467                 goto out_put_qmops;
1468
1469         if (xfs_icsb_init_counters(mp))
1470                 mp->m_flags |= XFS_MOUNT_NO_PERCPU_SB;
1471
1472         error = xfs_readsb(mp, flags);
1473         if (error)
1474                 goto out_destroy_counters;
1475
1476         error = xfs_finish_flags(mp);
1477         if (error)
1478                 goto out_free_sb;
1479
1480         error = xfs_setup_devices(mp);
1481         if (error)
1482                 goto out_free_sb;
1483
1484         if (mp->m_flags & XFS_MOUNT_BARRIER)
1485                 xfs_mountfs_check_barriers(mp);
1486
1487         error = xfs_filestream_mount(mp);
1488         if (error)
1489                 goto out_free_sb;
1490
1491         error = xfs_mountfs(mp);
1492         if (error)
1493                 goto out_filestream_unmount;
1494
1495         XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, mtpt, mp->m_fsname);
1496
1497         sb->s_dirt = 1;
1498         sb->s_magic = XFS_SB_MAGIC;
1499         sb->s_blocksize = mp->m_sb.sb_blocksize;
1500         sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
1501         sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
1502         sb->s_time_gran = 1;
1503         set_posix_acl_flag(sb);
1504
1505         root = igrab(VFS_I(mp->m_rootip));
1506         if (!root) {
1507                 error = ENOENT;
1508                 goto fail_unmount;
1509         }
1510         if (is_bad_inode(root)) {
1511                 error = EINVAL;
1512                 goto fail_vnrele;
1513         }
1514         sb->s_root = d_alloc_root(root);
1515         if (!sb->s_root) {
1516                 error = ENOMEM;
1517                 goto fail_vnrele;
1518         }
1519
1520         error = xfs_syncd_init(mp);
1521         if (error)
1522                 goto fail_vnrele;
1523
1524         kfree(mtpt);
1525
1526         xfs_itrace_exit(XFS_I(sb->s_root->d_inode));
1527         return 0;
1528
1529  out_filestream_unmount:
1530         xfs_filestream_unmount(mp);
1531  out_free_sb:
1532         xfs_freesb(mp);
1533  out_destroy_counters:
1534         xfs_icsb_destroy_counters(mp);
1535         xfs_close_devices(mp);
1536  out_put_qmops:
1537         xfs_qmops_put(mp);
1538  out_put_dmops:
1539         xfs_dmops_put(mp);
1540  out_free_fsname:
1541         xfs_free_fsname(mp);
1542         kfree(mtpt);
1543         kfree(mp);
1544  out:
1545         return -error;
1546
1547  fail_vnrele:
1548         if (sb->s_root) {
1549                 dput(sb->s_root);
1550                 sb->s_root = NULL;
1551         } else {
1552                 iput(root);
1553         }
1554
1555  fail_unmount:
1556         /*
1557          * Blow away any referenced inode in the filestreams cache.
1558          * This can and will cause log traffic as inodes go inactive
1559          * here.
1560          */
1561         xfs_filestream_unmount(mp);
1562
1563         XFS_bflush(mp->m_ddev_targp);
1564         error = xfs_unmount_flush(mp, 0);
1565         WARN_ON(error);
1566
1567         xfs_unmountfs(mp);
1568         goto out_free_sb;
1569 }
1570
1571 STATIC int
1572 xfs_fs_get_sb(
1573         struct file_system_type *fs_type,
1574         int                     flags,
1575         const char              *dev_name,
1576         void                    *data,
1577         struct vfsmount         *mnt)
1578 {
1579         return get_sb_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super,
1580                            mnt);
1581 }
1582
1583 static struct super_operations xfs_super_operations = {
1584         .alloc_inode            = xfs_fs_alloc_inode,
1585         .destroy_inode          = xfs_fs_destroy_inode,
1586         .write_inode            = xfs_fs_write_inode,
1587         .clear_inode            = xfs_fs_clear_inode,
1588         .put_super              = xfs_fs_put_super,
1589         .write_super            = xfs_fs_write_super,
1590         .sync_fs                = xfs_fs_sync_super,
1591         .write_super_lockfs     = xfs_fs_lockfs,
1592         .statfs                 = xfs_fs_statfs,
1593         .remount_fs             = xfs_fs_remount,
1594         .show_options           = xfs_fs_show_options,
1595 };
1596
1597 static struct quotactl_ops xfs_quotactl_operations = {
1598         .quota_sync             = xfs_fs_quotasync,
1599         .get_xstate             = xfs_fs_getxstate,
1600         .set_xstate             = xfs_fs_setxstate,
1601         .get_xquota             = xfs_fs_getxquota,
1602         .set_xquota             = xfs_fs_setxquota,
1603 };
1604
1605 static struct file_system_type xfs_fs_type = {
1606         .owner                  = THIS_MODULE,
1607         .name                   = "xfs",
1608         .get_sb                 = xfs_fs_get_sb,
1609         .kill_sb                = kill_block_super,
1610         .fs_flags               = FS_REQUIRES_DEV,
1611 };
1612
1613 STATIC int __init
1614 xfs_alloc_trace_bufs(void)
1615 {
1616 #ifdef XFS_ALLOC_TRACE
1617         xfs_alloc_trace_buf = ktrace_alloc(XFS_ALLOC_TRACE_SIZE, KM_MAYFAIL);
1618         if (!xfs_alloc_trace_buf)
1619                 goto out;
1620 #endif
1621 #ifdef XFS_BMAP_TRACE
1622         xfs_bmap_trace_buf = ktrace_alloc(XFS_BMAP_TRACE_SIZE, KM_MAYFAIL);
1623         if (!xfs_bmap_trace_buf)
1624                 goto out_free_alloc_trace;
1625 #endif
1626 #ifdef XFS_BTREE_TRACE
1627         xfs_allocbt_trace_buf = ktrace_alloc(XFS_ALLOCBT_TRACE_SIZE,
1628                                              KM_MAYFAIL);
1629         if (!xfs_allocbt_trace_buf)
1630                 goto out_free_bmap_trace;
1631
1632         xfs_inobt_trace_buf = ktrace_alloc(XFS_INOBT_TRACE_SIZE, KM_MAYFAIL);
1633         if (!xfs_inobt_trace_buf)
1634                 goto out_free_allocbt_trace;
1635
1636         xfs_bmbt_trace_buf = ktrace_alloc(XFS_BMBT_TRACE_SIZE, KM_MAYFAIL);
1637         if (!xfs_bmbt_trace_buf)
1638                 goto out_free_inobt_trace;
1639 #endif
1640 #ifdef XFS_ATTR_TRACE
1641         xfs_attr_trace_buf = ktrace_alloc(XFS_ATTR_TRACE_SIZE, KM_MAYFAIL);
1642         if (!xfs_attr_trace_buf)
1643                 goto out_free_bmbt_trace;
1644 #endif
1645 #ifdef XFS_DIR2_TRACE
1646         xfs_dir2_trace_buf = ktrace_alloc(XFS_DIR2_GTRACE_SIZE, KM_MAYFAIL);
1647         if (!xfs_dir2_trace_buf)
1648                 goto out_free_attr_trace;
1649 #endif
1650
1651         return 0;
1652
1653 #ifdef XFS_DIR2_TRACE
1654  out_free_attr_trace:
1655 #endif
1656 #ifdef XFS_ATTR_TRACE
1657         ktrace_free(xfs_attr_trace_buf);
1658  out_free_bmbt_trace:
1659 #endif
1660 #ifdef XFS_BTREE_TRACE
1661         ktrace_free(xfs_bmbt_trace_buf);
1662  out_free_inobt_trace:
1663         ktrace_free(xfs_inobt_trace_buf);
1664  out_free_allocbt_trace:
1665         ktrace_free(xfs_allocbt_trace_buf);
1666  out_free_bmap_trace:
1667 #endif
1668 #ifdef XFS_BMAP_TRACE
1669         ktrace_free(xfs_bmap_trace_buf);
1670  out_free_alloc_trace:
1671 #endif
1672 #ifdef XFS_ALLOC_TRACE
1673         ktrace_free(xfs_alloc_trace_buf);
1674  out:
1675 #endif
1676         return -ENOMEM;
1677 }
1678
1679 STATIC void
1680 xfs_free_trace_bufs(void)
1681 {
1682 #ifdef XFS_DIR2_TRACE
1683         ktrace_free(xfs_dir2_trace_buf);
1684 #endif
1685 #ifdef XFS_ATTR_TRACE
1686         ktrace_free(xfs_attr_trace_buf);
1687 #endif
1688 #ifdef XFS_BTREE_TRACE
1689         ktrace_free(xfs_bmbt_trace_buf);
1690         ktrace_free(xfs_inobt_trace_buf);
1691         ktrace_free(xfs_allocbt_trace_buf);
1692 #endif
1693 #ifdef XFS_BMAP_TRACE
1694         ktrace_free(xfs_bmap_trace_buf);
1695 #endif
1696 #ifdef XFS_ALLOC_TRACE
1697         ktrace_free(xfs_alloc_trace_buf);
1698 #endif
1699 }
1700
1701 STATIC int __init
1702 xfs_init_zones(void)
1703 {
1704
1705         xfs_ioend_zone = kmem_zone_init(sizeof(xfs_ioend_t), "xfs_ioend");
1706         if (!xfs_ioend_zone)
1707                 goto out;
1708
1709         xfs_ioend_pool = mempool_create_slab_pool(4 * MAX_BUF_PER_PAGE,
1710                                                   xfs_ioend_zone);
1711         if (!xfs_ioend_pool)
1712                 goto out_destroy_ioend_zone;
1713
1714         xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t),
1715                                                 "xfs_log_ticket");
1716         if (!xfs_log_ticket_zone)
1717                 goto out_destroy_ioend_pool;
1718
1719         xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
1720                                                 "xfs_bmap_free_item");
1721         if (!xfs_bmap_free_item_zone)
1722                 goto out_destroy_log_ticket_zone;
1723
1724         xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
1725                                                 "xfs_btree_cur");
1726         if (!xfs_btree_cur_zone)
1727                 goto out_destroy_bmap_free_item_zone;
1728
1729         xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t),
1730                                                 "xfs_da_state");
1731         if (!xfs_da_state_zone)
1732                 goto out_destroy_btree_cur_zone;
1733
1734         xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf");
1735         if (!xfs_dabuf_zone)
1736                 goto out_destroy_da_state_zone;
1737
1738         xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
1739         if (!xfs_ifork_zone)
1740                 goto out_destroy_dabuf_zone;
1741
1742         xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
1743         if (!xfs_trans_zone)
1744                 goto out_destroy_ifork_zone;
1745
1746         /*
1747          * The size of the zone allocated buf log item is the maximum
1748          * size possible under XFS.  This wastes a little bit of memory,
1749          * but it is much faster.
1750          */
1751         xfs_buf_item_zone = kmem_zone_init((sizeof(xfs_buf_log_item_t) +
1752                                 (((XFS_MAX_BLOCKSIZE / XFS_BLI_CHUNK) /
1753                                   NBWORD) * sizeof(int))), "xfs_buf_item");
1754         if (!xfs_buf_item_zone)
1755                 goto out_destroy_trans_zone;
1756
1757         xfs_efd_zone = kmem_zone_init((sizeof(xfs_efd_log_item_t) +
1758                         ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
1759                                  sizeof(xfs_extent_t))), "xfs_efd_item");
1760         if (!xfs_efd_zone)
1761                 goto out_destroy_buf_item_zone;
1762
1763         xfs_efi_zone = kmem_zone_init((sizeof(xfs_efi_log_item_t) +
1764                         ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
1765                                 sizeof(xfs_extent_t))), "xfs_efi_item");
1766         if (!xfs_efi_zone)
1767                 goto out_destroy_efd_zone;
1768
1769         xfs_inode_zone =
1770                 kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
1771                         KM_ZONE_HWALIGN | KM_ZONE_RECLAIM | KM_ZONE_SPREAD,
1772                         xfs_fs_inode_init_once);
1773         if (!xfs_inode_zone)
1774                 goto out_destroy_efi_zone;
1775
1776         xfs_ili_zone =
1777                 kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
1778                                         KM_ZONE_SPREAD, NULL);
1779         if (!xfs_ili_zone)
1780                 goto out_destroy_inode_zone;
1781
1782 #ifdef CONFIG_XFS_POSIX_ACL
1783         xfs_acl_zone = kmem_zone_init(sizeof(xfs_acl_t), "xfs_acl");
1784         if (!xfs_acl_zone)
1785                 goto out_destroy_ili_zone;
1786 #endif
1787
1788         return 0;
1789
1790 #ifdef CONFIG_XFS_POSIX_ACL
1791  out_destroy_ili_zone:
1792 #endif
1793         kmem_zone_destroy(xfs_ili_zone);
1794  out_destroy_inode_zone:
1795         kmem_zone_destroy(xfs_inode_zone);
1796  out_destroy_efi_zone:
1797         kmem_zone_destroy(xfs_efi_zone);
1798  out_destroy_efd_zone:
1799         kmem_zone_destroy(xfs_efd_zone);
1800  out_destroy_buf_item_zone:
1801         kmem_zone_destroy(xfs_buf_item_zone);
1802  out_destroy_trans_zone:
1803         kmem_zone_destroy(xfs_trans_zone);
1804  out_destroy_ifork_zone:
1805         kmem_zone_destroy(xfs_ifork_zone);
1806  out_destroy_dabuf_zone:
1807         kmem_zone_destroy(xfs_dabuf_zone);
1808  out_destroy_da_state_zone:
1809         kmem_zone_destroy(xfs_da_state_zone);
1810  out_destroy_btree_cur_zone:
1811         kmem_zone_destroy(xfs_btree_cur_zone);
1812  out_destroy_bmap_free_item_zone:
1813         kmem_zone_destroy(xfs_bmap_free_item_zone);
1814  out_destroy_log_ticket_zone:
1815         kmem_zone_destroy(xfs_log_ticket_zone);
1816  out_destroy_ioend_pool:
1817         mempool_destroy(xfs_ioend_pool);
1818  out_destroy_ioend_zone:
1819         kmem_zone_destroy(xfs_ioend_zone);
1820  out:
1821         return -ENOMEM;
1822 }
1823
1824 STATIC void
1825 xfs_destroy_zones(void)
1826 {
1827 #ifdef CONFIG_XFS_POSIX_ACL
1828         kmem_zone_destroy(xfs_acl_zone);
1829 #endif
1830         kmem_zone_destroy(xfs_ili_zone);
1831         kmem_zone_destroy(xfs_inode_zone);
1832         kmem_zone_destroy(xfs_efi_zone);
1833         kmem_zone_destroy(xfs_efd_zone);
1834         kmem_zone_destroy(xfs_buf_item_zone);
1835         kmem_zone_destroy(xfs_trans_zone);
1836         kmem_zone_destroy(xfs_ifork_zone);
1837         kmem_zone_destroy(xfs_dabuf_zone);
1838         kmem_zone_destroy(xfs_da_state_zone);
1839         kmem_zone_destroy(xfs_btree_cur_zone);
1840         kmem_zone_destroy(xfs_bmap_free_item_zone);
1841         kmem_zone_destroy(xfs_log_ticket_zone);
1842         mempool_destroy(xfs_ioend_pool);
1843         kmem_zone_destroy(xfs_ioend_zone);
1844
1845 }
1846
1847 STATIC int __init
1848 init_xfs_fs(void)
1849 {
1850         int                     error;
1851
1852         printk(KERN_INFO XFS_VERSION_STRING " with "
1853                          XFS_BUILD_OPTIONS " enabled\n");
1854
1855         ktrace_init(64);
1856         vn_init();
1857         xfs_dir_startup();
1858
1859         error = xfs_init_zones();
1860         if (error)
1861                 goto out;
1862
1863         error = xfs_alloc_trace_bufs();
1864         if (error)
1865                 goto out_destroy_zones;
1866
1867         error = xfs_mru_cache_init();
1868         if (error)
1869                 goto out_free_trace_buffers;
1870
1871         error = xfs_filestream_init();
1872         if (error)
1873                 goto out_mru_cache_uninit;
1874
1875         error = xfs_buf_init();
1876         if (error)
1877                 goto out_filestream_uninit;
1878
1879         error = xfs_init_procfs();
1880         if (error)
1881                 goto out_buf_terminate;
1882
1883         error = xfs_sysctl_register();
1884         if (error)
1885                 goto out_cleanup_procfs;
1886
1887         vfs_initquota();
1888
1889         error = register_filesystem(&xfs_fs_type);
1890         if (error)
1891                 goto out_sysctl_unregister;
1892         return 0;
1893
1894  out_sysctl_unregister:
1895         xfs_sysctl_unregister();
1896  out_cleanup_procfs:
1897         xfs_cleanup_procfs();
1898  out_buf_terminate:
1899         xfs_buf_terminate();
1900  out_filestream_uninit:
1901         xfs_filestream_uninit();
1902  out_mru_cache_uninit:
1903         xfs_mru_cache_uninit();
1904  out_free_trace_buffers:
1905         xfs_free_trace_bufs();
1906  out_destroy_zones:
1907         xfs_destroy_zones();
1908  out:
1909         return error;
1910 }
1911
1912 STATIC void __exit
1913 exit_xfs_fs(void)
1914 {
1915         vfs_exitquota();
1916         unregister_filesystem(&xfs_fs_type);
1917         xfs_sysctl_unregister();
1918         xfs_cleanup_procfs();
1919         xfs_buf_terminate();
1920         xfs_filestream_uninit();
1921         xfs_mru_cache_uninit();
1922         xfs_free_trace_bufs();
1923         xfs_destroy_zones();
1924         ktrace_uninit();
1925 }
1926
1927 module_init(init_xfs_fs);
1928 module_exit(exit_xfs_fs);
1929
1930 MODULE_AUTHOR("Silicon Graphics, Inc.");
1931 MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
1932 MODULE_LICENSE("GPL");