[XFS] fix uninitialised variable bug in dquot release.
[deliverable/linux.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 struct xfs_inode *ip = XFS_I(inode);
994 int error = 0;
995 int flags = 0;
996
997 xfs_itrace_entry(ip);
998 if (sync) {
999 error = xfs_wait_on_pages(ip, 0, -1);
1000 if (error)
1001 goto out_error;
1002 flags |= FLUSH_SYNC;
1003 }
1004 error = xfs_inode_flush(ip, flags);
1005
1006 out_error:
1007 /*
1008 * if we failed to write out the inode then mark
1009 * it dirty again so we'll try again later.
1010 */
1011 if (error)
1012 xfs_mark_inode_dirty_sync(ip);
1013
1014 return -error;
1015 }
1016
1017 STATIC void
1018 xfs_fs_clear_inode(
1019 struct inode *inode)
1020 {
1021 xfs_inode_t *ip = XFS_I(inode);
1022
1023 xfs_itrace_entry(ip);
1024 XFS_STATS_INC(vn_rele);
1025 XFS_STATS_INC(vn_remove);
1026 XFS_STATS_DEC(vn_active);
1027
1028 xfs_inactive(ip);
1029 xfs_iflags_clear(ip, XFS_IMODIFIED);
1030 }
1031
1032 STATIC void
1033 xfs_free_fsname(
1034 struct xfs_mount *mp)
1035 {
1036 kfree(mp->m_fsname);
1037 kfree(mp->m_rtname);
1038 kfree(mp->m_logname);
1039 }
1040
1041 STATIC void
1042 xfs_fs_put_super(
1043 struct super_block *sb)
1044 {
1045 struct xfs_mount *mp = XFS_M(sb);
1046 struct xfs_inode *rip = mp->m_rootip;
1047 int unmount_event_flags = 0;
1048 int error;
1049
1050 xfs_syncd_stop(mp);
1051 xfs_sync_inodes(mp, SYNC_ATTR|SYNC_DELWRI);
1052
1053 #ifdef HAVE_DMAPI
1054 if (mp->m_flags & XFS_MOUNT_DMAPI) {
1055 unmount_event_flags =
1056 (mp->m_dmevmask & (1 << DM_EVENT_UNMOUNT)) ?
1057 0 : DM_FLAGS_UNWANTED;
1058 /*
1059 * Ignore error from dmapi here, first unmount is not allowed
1060 * to fail anyway, and second we wouldn't want to fail a
1061 * unmount because of dmapi.
1062 */
1063 XFS_SEND_PREUNMOUNT(mp, rip, DM_RIGHT_NULL, rip, DM_RIGHT_NULL,
1064 NULL, NULL, 0, 0, unmount_event_flags);
1065 }
1066 #endif
1067
1068 /*
1069 * Blow away any referenced inode in the filestreams cache.
1070 * This can and will cause log traffic as inodes go inactive
1071 * here.
1072 */
1073 xfs_filestream_unmount(mp);
1074
1075 XFS_bflush(mp->m_ddev_targp);
1076 error = xfs_unmount_flush(mp, 0);
1077 WARN_ON(error);
1078
1079 if (mp->m_flags & XFS_MOUNT_DMAPI) {
1080 XFS_SEND_UNMOUNT(mp, rip, DM_RIGHT_NULL, 0, 0,
1081 unmount_event_flags);
1082 }
1083
1084 xfs_unmountfs(mp);
1085 xfs_freesb(mp);
1086 xfs_icsb_destroy_counters(mp);
1087 xfs_close_devices(mp);
1088 xfs_qmops_put(mp);
1089 xfs_dmops_put(mp);
1090 xfs_free_fsname(mp);
1091 kfree(mp);
1092 }
1093
1094 STATIC void
1095 xfs_fs_write_super(
1096 struct super_block *sb)
1097 {
1098 if (!(sb->s_flags & MS_RDONLY))
1099 xfs_sync_fsdata(XFS_M(sb), 0);
1100 sb->s_dirt = 0;
1101 }
1102
1103 STATIC int
1104 xfs_fs_sync_super(
1105 struct super_block *sb,
1106 int wait)
1107 {
1108 struct xfs_mount *mp = XFS_M(sb);
1109 int error;
1110
1111 /*
1112 * Treat a sync operation like a freeze. This is to work
1113 * around a race in sync_inodes() which works in two phases
1114 * - an asynchronous flush, which can write out an inode
1115 * without waiting for file size updates to complete, and a
1116 * synchronous flush, which wont do anything because the
1117 * async flush removed the inode's dirty flag. Also
1118 * sync_inodes() will not see any files that just have
1119 * outstanding transactions to be flushed because we don't
1120 * dirty the Linux inode until after the transaction I/O
1121 * completes.
1122 */
1123 if (wait || unlikely(sb->s_frozen == SB_FREEZE_WRITE))
1124 error = xfs_quiesce_data(mp);
1125 else
1126 error = xfs_sync_fsdata(mp, 0);
1127 sb->s_dirt = 0;
1128
1129 if (unlikely(laptop_mode)) {
1130 int prev_sync_seq = mp->m_sync_seq;
1131
1132 /*
1133 * The disk must be active because we're syncing.
1134 * We schedule xfssyncd now (now that the disk is
1135 * active) instead of later (when it might not be).
1136 */
1137 wake_up_process(mp->m_sync_task);
1138 /*
1139 * We have to wait for the sync iteration to complete.
1140 * If we don't, the disk activity caused by the sync
1141 * will come after the sync is completed, and that
1142 * triggers another sync from laptop mode.
1143 */
1144 wait_event(mp->m_wait_single_sync_task,
1145 mp->m_sync_seq != prev_sync_seq);
1146 }
1147
1148 return -error;
1149 }
1150
1151 STATIC int
1152 xfs_fs_statfs(
1153 struct dentry *dentry,
1154 struct kstatfs *statp)
1155 {
1156 struct xfs_mount *mp = XFS_M(dentry->d_sb);
1157 xfs_sb_t *sbp = &mp->m_sb;
1158 __uint64_t fakeinos, id;
1159 xfs_extlen_t lsize;
1160
1161 statp->f_type = XFS_SB_MAGIC;
1162 statp->f_namelen = MAXNAMELEN - 1;
1163
1164 id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
1165 statp->f_fsid.val[0] = (u32)id;
1166 statp->f_fsid.val[1] = (u32)(id >> 32);
1167
1168 xfs_icsb_sync_counters(mp, XFS_ICSB_LAZY_COUNT);
1169
1170 spin_lock(&mp->m_sb_lock);
1171 statp->f_bsize = sbp->sb_blocksize;
1172 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
1173 statp->f_blocks = sbp->sb_dblocks - lsize;
1174 statp->f_bfree = statp->f_bavail =
1175 sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
1176 fakeinos = statp->f_bfree << sbp->sb_inopblog;
1177 #if XFS_BIG_INUMS
1178 fakeinos += mp->m_inoadd;
1179 #endif
1180 statp->f_files =
1181 MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
1182 if (mp->m_maxicount)
1183 #if XFS_BIG_INUMS
1184 if (!mp->m_inoadd)
1185 #endif
1186 statp->f_files = min_t(typeof(statp->f_files),
1187 statp->f_files,
1188 mp->m_maxicount);
1189 statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
1190 spin_unlock(&mp->m_sb_lock);
1191
1192 XFS_QM_DQSTATVFS(XFS_I(dentry->d_inode), statp);
1193 return 0;
1194 }
1195
1196 STATIC int
1197 xfs_fs_remount(
1198 struct super_block *sb,
1199 int *flags,
1200 char *options)
1201 {
1202 struct xfs_mount *mp = XFS_M(sb);
1203 substring_t args[MAX_OPT_ARGS];
1204 char *p;
1205
1206 while ((p = strsep(&options, ",")) != NULL) {
1207 int token;
1208
1209 if (!*p)
1210 continue;
1211
1212 token = match_token(p, tokens, args);
1213 switch (token) {
1214 case Opt_barrier:
1215 mp->m_flags |= XFS_MOUNT_BARRIER;
1216
1217 /*
1218 * Test if barriers are actually working if we can,
1219 * else delay this check until the filesystem is
1220 * marked writeable.
1221 */
1222 if (!(mp->m_flags & XFS_MOUNT_RDONLY))
1223 xfs_mountfs_check_barriers(mp);
1224 break;
1225 case Opt_nobarrier:
1226 mp->m_flags &= ~XFS_MOUNT_BARRIER;
1227 break;
1228 default:
1229 /*
1230 * Logically we would return an error here to prevent
1231 * users from believing they might have changed
1232 * mount options using remount which can't be changed.
1233 *
1234 * But unfortunately mount(8) adds all options from
1235 * mtab and fstab to the mount arguments in some cases
1236 * so we can't blindly reject options, but have to
1237 * check for each specified option if it actually
1238 * differs from the currently set option and only
1239 * reject it if that's the case.
1240 *
1241 * Until that is implemented we return success for
1242 * every remount request, and silently ignore all
1243 * options that we can't actually change.
1244 */
1245 #if 0
1246 printk(KERN_INFO
1247 "XFS: mount option \"%s\" not supported for remount\n", p);
1248 return -EINVAL;
1249 #else
1250 break;
1251 #endif
1252 }
1253 }
1254
1255 /* rw/ro -> rw */
1256 if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(*flags & MS_RDONLY)) {
1257 mp->m_flags &= ~XFS_MOUNT_RDONLY;
1258 if (mp->m_flags & XFS_MOUNT_BARRIER)
1259 xfs_mountfs_check_barriers(mp);
1260 }
1261
1262 /* rw -> ro */
1263 if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (*flags & MS_RDONLY)) {
1264 xfs_quiesce_data(mp);
1265 xfs_quiesce_attr(mp);
1266 mp->m_flags |= XFS_MOUNT_RDONLY;
1267 }
1268
1269 return 0;
1270 }
1271
1272 /*
1273 * Second stage of a freeze. The data is already frozen so we only
1274 * need to take care of the metadata. Once that's done write a dummy
1275 * record to dirty the log in case of a crash while frozen.
1276 */
1277 STATIC void
1278 xfs_fs_lockfs(
1279 struct super_block *sb)
1280 {
1281 struct xfs_mount *mp = XFS_M(sb);
1282
1283 xfs_quiesce_attr(mp);
1284 xfs_fs_log_dummy(mp);
1285 }
1286
1287 STATIC int
1288 xfs_fs_show_options(
1289 struct seq_file *m,
1290 struct vfsmount *mnt)
1291 {
1292 return -xfs_showargs(XFS_M(mnt->mnt_sb), m);
1293 }
1294
1295 STATIC int
1296 xfs_fs_quotasync(
1297 struct super_block *sb,
1298 int type)
1299 {
1300 return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XQUOTASYNC, 0, NULL);
1301 }
1302
1303 STATIC int
1304 xfs_fs_getxstate(
1305 struct super_block *sb,
1306 struct fs_quota_stat *fqs)
1307 {
1308 return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XGETQSTAT, 0, (caddr_t)fqs);
1309 }
1310
1311 STATIC int
1312 xfs_fs_setxstate(
1313 struct super_block *sb,
1314 unsigned int flags,
1315 int op)
1316 {
1317 return -XFS_QM_QUOTACTL(XFS_M(sb), op, 0, (caddr_t)&flags);
1318 }
1319
1320 STATIC int
1321 xfs_fs_getxquota(
1322 struct super_block *sb,
1323 int type,
1324 qid_t id,
1325 struct fs_disk_quota *fdq)
1326 {
1327 return -XFS_QM_QUOTACTL(XFS_M(sb),
1328 (type == USRQUOTA) ? Q_XGETQUOTA :
1329 ((type == GRPQUOTA) ? Q_XGETGQUOTA :
1330 Q_XGETPQUOTA), id, (caddr_t)fdq);
1331 }
1332
1333 STATIC int
1334 xfs_fs_setxquota(
1335 struct super_block *sb,
1336 int type,
1337 qid_t id,
1338 struct fs_disk_quota *fdq)
1339 {
1340 return -XFS_QM_QUOTACTL(XFS_M(sb),
1341 (type == USRQUOTA) ? Q_XSETQLIM :
1342 ((type == GRPQUOTA) ? Q_XSETGQLIM :
1343 Q_XSETPQLIM), id, (caddr_t)fdq);
1344 }
1345
1346 /*
1347 * This function fills in xfs_mount_t fields based on mount args.
1348 * Note: the superblock _has_ now been read in.
1349 */
1350 STATIC int
1351 xfs_finish_flags(
1352 struct xfs_mount *mp)
1353 {
1354 int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
1355
1356 /* Fail a mount where the logbuf is smaller then the log stripe */
1357 if (xfs_sb_version_haslogv2(&mp->m_sb)) {
1358 if (mp->m_logbsize <= 0 &&
1359 mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE) {
1360 mp->m_logbsize = mp->m_sb.sb_logsunit;
1361 } else if (mp->m_logbsize > 0 &&
1362 mp->m_logbsize < mp->m_sb.sb_logsunit) {
1363 cmn_err(CE_WARN,
1364 "XFS: logbuf size must be greater than or equal to log stripe size");
1365 return XFS_ERROR(EINVAL);
1366 }
1367 } else {
1368 /* Fail a mount if the logbuf is larger than 32K */
1369 if (mp->m_logbsize > XLOG_BIG_RECORD_BSIZE) {
1370 cmn_err(CE_WARN,
1371 "XFS: logbuf size for version 1 logs must be 16K or 32K");
1372 return XFS_ERROR(EINVAL);
1373 }
1374 }
1375
1376 /*
1377 * mkfs'ed attr2 will turn on attr2 mount unless explicitly
1378 * told by noattr2 to turn it off
1379 */
1380 if (xfs_sb_version_hasattr2(&mp->m_sb) &&
1381 !(mp->m_flags & XFS_MOUNT_NOATTR2))
1382 mp->m_flags |= XFS_MOUNT_ATTR2;
1383
1384 /*
1385 * prohibit r/w mounts of read-only filesystems
1386 */
1387 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
1388 cmn_err(CE_WARN,
1389 "XFS: cannot mount a read-only filesystem as read-write");
1390 return XFS_ERROR(EROFS);
1391 }
1392
1393 #if 0 /* shared mounts were never supported on Linux */
1394 /*
1395 * check for shared mount.
1396 */
1397 if (ap->flags & XFSMNT_SHARED) {
1398 if (!xfs_sb_version_hasshared(&mp->m_sb))
1399 return XFS_ERROR(EINVAL);
1400
1401 /*
1402 * For IRIX 6.5, shared mounts must have the shared
1403 * version bit set, have the persistent readonly
1404 * field set, must be version 0 and can only be mounted
1405 * read-only.
1406 */
1407 if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) ||
1408 (mp->m_sb.sb_shared_vn != 0))
1409 return XFS_ERROR(EINVAL);
1410
1411 mp->m_flags |= XFS_MOUNT_SHARED;
1412
1413 /*
1414 * Shared XFS V0 can't deal with DMI. Return EINVAL.
1415 */
1416 if (mp->m_sb.sb_shared_vn == 0 &&
1417 (mp->m_flags & XFS_MOUNT_DMAPI))
1418 return XFS_ERROR(EINVAL);
1419 }
1420 #endif
1421
1422 return 0;
1423 }
1424
1425 STATIC int
1426 xfs_fs_fill_super(
1427 struct super_block *sb,
1428 void *data,
1429 int silent)
1430 {
1431 struct inode *root;
1432 struct xfs_mount *mp = NULL;
1433 int flags = 0, error = ENOMEM;
1434 char *mtpt = NULL;
1435
1436 mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
1437 if (!mp)
1438 goto out;
1439
1440 spin_lock_init(&mp->m_sb_lock);
1441 mutex_init(&mp->m_growlock);
1442 atomic_set(&mp->m_active_trans, 0);
1443 INIT_LIST_HEAD(&mp->m_sync_list);
1444 spin_lock_init(&mp->m_sync_lock);
1445 init_waitqueue_head(&mp->m_wait_single_sync_task);
1446
1447 mp->m_super = sb;
1448 sb->s_fs_info = mp;
1449
1450 error = xfs_parseargs(mp, (char *)data, &mtpt);
1451 if (error)
1452 goto out_free_fsname;
1453
1454 sb_min_blocksize(sb, BBSIZE);
1455 sb->s_xattr = xfs_xattr_handlers;
1456 sb->s_export_op = &xfs_export_operations;
1457 sb->s_qcop = &xfs_quotactl_operations;
1458 sb->s_op = &xfs_super_operations;
1459
1460 error = xfs_dmops_get(mp);
1461 if (error)
1462 goto out_free_fsname;
1463 error = xfs_qmops_get(mp);
1464 if (error)
1465 goto out_put_dmops;
1466
1467 if (silent)
1468 flags |= XFS_MFSI_QUIET;
1469
1470 error = xfs_open_devices(mp);
1471 if (error)
1472 goto out_put_qmops;
1473
1474 if (xfs_icsb_init_counters(mp))
1475 mp->m_flags |= XFS_MOUNT_NO_PERCPU_SB;
1476
1477 error = xfs_readsb(mp, flags);
1478 if (error)
1479 goto out_destroy_counters;
1480
1481 error = xfs_finish_flags(mp);
1482 if (error)
1483 goto out_free_sb;
1484
1485 error = xfs_setup_devices(mp);
1486 if (error)
1487 goto out_free_sb;
1488
1489 if (mp->m_flags & XFS_MOUNT_BARRIER)
1490 xfs_mountfs_check_barriers(mp);
1491
1492 error = xfs_filestream_mount(mp);
1493 if (error)
1494 goto out_free_sb;
1495
1496 error = xfs_mountfs(mp);
1497 if (error)
1498 goto out_filestream_unmount;
1499
1500 XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, mtpt, mp->m_fsname);
1501
1502 sb->s_dirt = 1;
1503 sb->s_magic = XFS_SB_MAGIC;
1504 sb->s_blocksize = mp->m_sb.sb_blocksize;
1505 sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
1506 sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
1507 sb->s_time_gran = 1;
1508 set_posix_acl_flag(sb);
1509
1510 root = igrab(VFS_I(mp->m_rootip));
1511 if (!root) {
1512 error = ENOENT;
1513 goto fail_unmount;
1514 }
1515 if (is_bad_inode(root)) {
1516 error = EINVAL;
1517 goto fail_vnrele;
1518 }
1519 sb->s_root = d_alloc_root(root);
1520 if (!sb->s_root) {
1521 error = ENOMEM;
1522 goto fail_vnrele;
1523 }
1524
1525 error = xfs_syncd_init(mp);
1526 if (error)
1527 goto fail_vnrele;
1528
1529 kfree(mtpt);
1530
1531 xfs_itrace_exit(XFS_I(sb->s_root->d_inode));
1532 return 0;
1533
1534 out_filestream_unmount:
1535 xfs_filestream_unmount(mp);
1536 out_free_sb:
1537 xfs_freesb(mp);
1538 out_destroy_counters:
1539 xfs_icsb_destroy_counters(mp);
1540 xfs_close_devices(mp);
1541 out_put_qmops:
1542 xfs_qmops_put(mp);
1543 out_put_dmops:
1544 xfs_dmops_put(mp);
1545 out_free_fsname:
1546 xfs_free_fsname(mp);
1547 kfree(mtpt);
1548 kfree(mp);
1549 out:
1550 return -error;
1551
1552 fail_vnrele:
1553 if (sb->s_root) {
1554 dput(sb->s_root);
1555 sb->s_root = NULL;
1556 } else {
1557 iput(root);
1558 }
1559
1560 fail_unmount:
1561 /*
1562 * Blow away any referenced inode in the filestreams cache.
1563 * This can and will cause log traffic as inodes go inactive
1564 * here.
1565 */
1566 xfs_filestream_unmount(mp);
1567
1568 XFS_bflush(mp->m_ddev_targp);
1569 error = xfs_unmount_flush(mp, 0);
1570 WARN_ON(error);
1571
1572 xfs_unmountfs(mp);
1573 goto out_free_sb;
1574 }
1575
1576 STATIC int
1577 xfs_fs_get_sb(
1578 struct file_system_type *fs_type,
1579 int flags,
1580 const char *dev_name,
1581 void *data,
1582 struct vfsmount *mnt)
1583 {
1584 return get_sb_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super,
1585 mnt);
1586 }
1587
1588 static struct super_operations xfs_super_operations = {
1589 .alloc_inode = xfs_fs_alloc_inode,
1590 .destroy_inode = xfs_fs_destroy_inode,
1591 .write_inode = xfs_fs_write_inode,
1592 .clear_inode = xfs_fs_clear_inode,
1593 .put_super = xfs_fs_put_super,
1594 .write_super = xfs_fs_write_super,
1595 .sync_fs = xfs_fs_sync_super,
1596 .write_super_lockfs = xfs_fs_lockfs,
1597 .statfs = xfs_fs_statfs,
1598 .remount_fs = xfs_fs_remount,
1599 .show_options = xfs_fs_show_options,
1600 };
1601
1602 static struct quotactl_ops xfs_quotactl_operations = {
1603 .quota_sync = xfs_fs_quotasync,
1604 .get_xstate = xfs_fs_getxstate,
1605 .set_xstate = xfs_fs_setxstate,
1606 .get_xquota = xfs_fs_getxquota,
1607 .set_xquota = xfs_fs_setxquota,
1608 };
1609
1610 static struct file_system_type xfs_fs_type = {
1611 .owner = THIS_MODULE,
1612 .name = "xfs",
1613 .get_sb = xfs_fs_get_sb,
1614 .kill_sb = kill_block_super,
1615 .fs_flags = FS_REQUIRES_DEV,
1616 };
1617
1618 STATIC int __init
1619 xfs_alloc_trace_bufs(void)
1620 {
1621 #ifdef XFS_ALLOC_TRACE
1622 xfs_alloc_trace_buf = ktrace_alloc(XFS_ALLOC_TRACE_SIZE, KM_MAYFAIL);
1623 if (!xfs_alloc_trace_buf)
1624 goto out;
1625 #endif
1626 #ifdef XFS_BMAP_TRACE
1627 xfs_bmap_trace_buf = ktrace_alloc(XFS_BMAP_TRACE_SIZE, KM_MAYFAIL);
1628 if (!xfs_bmap_trace_buf)
1629 goto out_free_alloc_trace;
1630 #endif
1631 #ifdef XFS_BTREE_TRACE
1632 xfs_allocbt_trace_buf = ktrace_alloc(XFS_ALLOCBT_TRACE_SIZE,
1633 KM_MAYFAIL);
1634 if (!xfs_allocbt_trace_buf)
1635 goto out_free_bmap_trace;
1636
1637 xfs_inobt_trace_buf = ktrace_alloc(XFS_INOBT_TRACE_SIZE, KM_MAYFAIL);
1638 if (!xfs_inobt_trace_buf)
1639 goto out_free_allocbt_trace;
1640
1641 xfs_bmbt_trace_buf = ktrace_alloc(XFS_BMBT_TRACE_SIZE, KM_MAYFAIL);
1642 if (!xfs_bmbt_trace_buf)
1643 goto out_free_inobt_trace;
1644 #endif
1645 #ifdef XFS_ATTR_TRACE
1646 xfs_attr_trace_buf = ktrace_alloc(XFS_ATTR_TRACE_SIZE, KM_MAYFAIL);
1647 if (!xfs_attr_trace_buf)
1648 goto out_free_bmbt_trace;
1649 #endif
1650 #ifdef XFS_DIR2_TRACE
1651 xfs_dir2_trace_buf = ktrace_alloc(XFS_DIR2_GTRACE_SIZE, KM_MAYFAIL);
1652 if (!xfs_dir2_trace_buf)
1653 goto out_free_attr_trace;
1654 #endif
1655
1656 return 0;
1657
1658 #ifdef XFS_DIR2_TRACE
1659 out_free_attr_trace:
1660 #endif
1661 #ifdef XFS_ATTR_TRACE
1662 ktrace_free(xfs_attr_trace_buf);
1663 out_free_bmbt_trace:
1664 #endif
1665 #ifdef XFS_BTREE_TRACE
1666 ktrace_free(xfs_bmbt_trace_buf);
1667 out_free_inobt_trace:
1668 ktrace_free(xfs_inobt_trace_buf);
1669 out_free_allocbt_trace:
1670 ktrace_free(xfs_allocbt_trace_buf);
1671 out_free_bmap_trace:
1672 #endif
1673 #ifdef XFS_BMAP_TRACE
1674 ktrace_free(xfs_bmap_trace_buf);
1675 out_free_alloc_trace:
1676 #endif
1677 #ifdef XFS_ALLOC_TRACE
1678 ktrace_free(xfs_alloc_trace_buf);
1679 out:
1680 #endif
1681 return -ENOMEM;
1682 }
1683
1684 STATIC void
1685 xfs_free_trace_bufs(void)
1686 {
1687 #ifdef XFS_DIR2_TRACE
1688 ktrace_free(xfs_dir2_trace_buf);
1689 #endif
1690 #ifdef XFS_ATTR_TRACE
1691 ktrace_free(xfs_attr_trace_buf);
1692 #endif
1693 #ifdef XFS_BTREE_TRACE
1694 ktrace_free(xfs_bmbt_trace_buf);
1695 ktrace_free(xfs_inobt_trace_buf);
1696 ktrace_free(xfs_allocbt_trace_buf);
1697 #endif
1698 #ifdef XFS_BMAP_TRACE
1699 ktrace_free(xfs_bmap_trace_buf);
1700 #endif
1701 #ifdef XFS_ALLOC_TRACE
1702 ktrace_free(xfs_alloc_trace_buf);
1703 #endif
1704 }
1705
1706 STATIC int __init
1707 xfs_init_zones(void)
1708 {
1709
1710 xfs_ioend_zone = kmem_zone_init(sizeof(xfs_ioend_t), "xfs_ioend");
1711 if (!xfs_ioend_zone)
1712 goto out;
1713
1714 xfs_ioend_pool = mempool_create_slab_pool(4 * MAX_BUF_PER_PAGE,
1715 xfs_ioend_zone);
1716 if (!xfs_ioend_pool)
1717 goto out_destroy_ioend_zone;
1718
1719 xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t),
1720 "xfs_log_ticket");
1721 if (!xfs_log_ticket_zone)
1722 goto out_destroy_ioend_pool;
1723
1724 xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
1725 "xfs_bmap_free_item");
1726 if (!xfs_bmap_free_item_zone)
1727 goto out_destroy_log_ticket_zone;
1728
1729 xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
1730 "xfs_btree_cur");
1731 if (!xfs_btree_cur_zone)
1732 goto out_destroy_bmap_free_item_zone;
1733
1734 xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t),
1735 "xfs_da_state");
1736 if (!xfs_da_state_zone)
1737 goto out_destroy_btree_cur_zone;
1738
1739 xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf");
1740 if (!xfs_dabuf_zone)
1741 goto out_destroy_da_state_zone;
1742
1743 xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
1744 if (!xfs_ifork_zone)
1745 goto out_destroy_dabuf_zone;
1746
1747 xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
1748 if (!xfs_trans_zone)
1749 goto out_destroy_ifork_zone;
1750
1751 /*
1752 * The size of the zone allocated buf log item is the maximum
1753 * size possible under XFS. This wastes a little bit of memory,
1754 * but it is much faster.
1755 */
1756 xfs_buf_item_zone = kmem_zone_init((sizeof(xfs_buf_log_item_t) +
1757 (((XFS_MAX_BLOCKSIZE / XFS_BLI_CHUNK) /
1758 NBWORD) * sizeof(int))), "xfs_buf_item");
1759 if (!xfs_buf_item_zone)
1760 goto out_destroy_trans_zone;
1761
1762 xfs_efd_zone = kmem_zone_init((sizeof(xfs_efd_log_item_t) +
1763 ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
1764 sizeof(xfs_extent_t))), "xfs_efd_item");
1765 if (!xfs_efd_zone)
1766 goto out_destroy_buf_item_zone;
1767
1768 xfs_efi_zone = kmem_zone_init((sizeof(xfs_efi_log_item_t) +
1769 ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
1770 sizeof(xfs_extent_t))), "xfs_efi_item");
1771 if (!xfs_efi_zone)
1772 goto out_destroy_efd_zone;
1773
1774 xfs_inode_zone =
1775 kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
1776 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM | KM_ZONE_SPREAD,
1777 xfs_fs_inode_init_once);
1778 if (!xfs_inode_zone)
1779 goto out_destroy_efi_zone;
1780
1781 xfs_ili_zone =
1782 kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
1783 KM_ZONE_SPREAD, NULL);
1784 if (!xfs_ili_zone)
1785 goto out_destroy_inode_zone;
1786
1787 #ifdef CONFIG_XFS_POSIX_ACL
1788 xfs_acl_zone = kmem_zone_init(sizeof(xfs_acl_t), "xfs_acl");
1789 if (!xfs_acl_zone)
1790 goto out_destroy_ili_zone;
1791 #endif
1792
1793 return 0;
1794
1795 #ifdef CONFIG_XFS_POSIX_ACL
1796 out_destroy_ili_zone:
1797 #endif
1798 kmem_zone_destroy(xfs_ili_zone);
1799 out_destroy_inode_zone:
1800 kmem_zone_destroy(xfs_inode_zone);
1801 out_destroy_efi_zone:
1802 kmem_zone_destroy(xfs_efi_zone);
1803 out_destroy_efd_zone:
1804 kmem_zone_destroy(xfs_efd_zone);
1805 out_destroy_buf_item_zone:
1806 kmem_zone_destroy(xfs_buf_item_zone);
1807 out_destroy_trans_zone:
1808 kmem_zone_destroy(xfs_trans_zone);
1809 out_destroy_ifork_zone:
1810 kmem_zone_destroy(xfs_ifork_zone);
1811 out_destroy_dabuf_zone:
1812 kmem_zone_destroy(xfs_dabuf_zone);
1813 out_destroy_da_state_zone:
1814 kmem_zone_destroy(xfs_da_state_zone);
1815 out_destroy_btree_cur_zone:
1816 kmem_zone_destroy(xfs_btree_cur_zone);
1817 out_destroy_bmap_free_item_zone:
1818 kmem_zone_destroy(xfs_bmap_free_item_zone);
1819 out_destroy_log_ticket_zone:
1820 kmem_zone_destroy(xfs_log_ticket_zone);
1821 out_destroy_ioend_pool:
1822 mempool_destroy(xfs_ioend_pool);
1823 out_destroy_ioend_zone:
1824 kmem_zone_destroy(xfs_ioend_zone);
1825 out:
1826 return -ENOMEM;
1827 }
1828
1829 STATIC void
1830 xfs_destroy_zones(void)
1831 {
1832 #ifdef CONFIG_XFS_POSIX_ACL
1833 kmem_zone_destroy(xfs_acl_zone);
1834 #endif
1835 kmem_zone_destroy(xfs_ili_zone);
1836 kmem_zone_destroy(xfs_inode_zone);
1837 kmem_zone_destroy(xfs_efi_zone);
1838 kmem_zone_destroy(xfs_efd_zone);
1839 kmem_zone_destroy(xfs_buf_item_zone);
1840 kmem_zone_destroy(xfs_trans_zone);
1841 kmem_zone_destroy(xfs_ifork_zone);
1842 kmem_zone_destroy(xfs_dabuf_zone);
1843 kmem_zone_destroy(xfs_da_state_zone);
1844 kmem_zone_destroy(xfs_btree_cur_zone);
1845 kmem_zone_destroy(xfs_bmap_free_item_zone);
1846 kmem_zone_destroy(xfs_log_ticket_zone);
1847 mempool_destroy(xfs_ioend_pool);
1848 kmem_zone_destroy(xfs_ioend_zone);
1849
1850 }
1851
1852 STATIC int __init
1853 init_xfs_fs(void)
1854 {
1855 int error;
1856
1857 printk(KERN_INFO XFS_VERSION_STRING " with "
1858 XFS_BUILD_OPTIONS " enabled\n");
1859
1860 ktrace_init(64);
1861 vn_init();
1862 xfs_dir_startup();
1863
1864 error = xfs_init_zones();
1865 if (error)
1866 goto out;
1867
1868 error = xfs_alloc_trace_bufs();
1869 if (error)
1870 goto out_destroy_zones;
1871
1872 error = xfs_mru_cache_init();
1873 if (error)
1874 goto out_free_trace_buffers;
1875
1876 error = xfs_filestream_init();
1877 if (error)
1878 goto out_mru_cache_uninit;
1879
1880 error = xfs_buf_init();
1881 if (error)
1882 goto out_filestream_uninit;
1883
1884 error = xfs_init_procfs();
1885 if (error)
1886 goto out_buf_terminate;
1887
1888 error = xfs_sysctl_register();
1889 if (error)
1890 goto out_cleanup_procfs;
1891
1892 vfs_initquota();
1893
1894 error = register_filesystem(&xfs_fs_type);
1895 if (error)
1896 goto out_sysctl_unregister;
1897 return 0;
1898
1899 out_sysctl_unregister:
1900 xfs_sysctl_unregister();
1901 out_cleanup_procfs:
1902 xfs_cleanup_procfs();
1903 out_buf_terminate:
1904 xfs_buf_terminate();
1905 out_filestream_uninit:
1906 xfs_filestream_uninit();
1907 out_mru_cache_uninit:
1908 xfs_mru_cache_uninit();
1909 out_free_trace_buffers:
1910 xfs_free_trace_bufs();
1911 out_destroy_zones:
1912 xfs_destroy_zones();
1913 out:
1914 return error;
1915 }
1916
1917 STATIC void __exit
1918 exit_xfs_fs(void)
1919 {
1920 vfs_exitquota();
1921 unregister_filesystem(&xfs_fs_type);
1922 xfs_sysctl_unregister();
1923 xfs_cleanup_procfs();
1924 xfs_buf_terminate();
1925 xfs_filestream_uninit();
1926 xfs_mru_cache_uninit();
1927 xfs_free_trace_bufs();
1928 xfs_destroy_zones();
1929 ktrace_uninit();
1930 }
1931
1932 module_init(init_xfs_fs);
1933 module_exit(exit_xfs_fs);
1934
1935 MODULE_AUTHOR("Silicon Graphics, Inc.");
1936 MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
1937 MODULE_LICENSE("GPL");
This page took 0.111229 seconds and 5 git commands to generate.