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