2 * Copyright (c) 2000-2006 Silicon Graphics, Inc.
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.
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.
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
23 #include "xfs_trans.h"
27 #include "xfs_alloc.h"
28 #include "xfs_dmapi.h"
29 #include "xfs_quota.h"
30 #include "xfs_mount.h"
31 #include "xfs_bmap_btree.h"
32 #include "xfs_alloc_btree.h"
33 #include "xfs_ialloc_btree.h"
34 #include "xfs_dir2_sf.h"
35 #include "xfs_attr_sf.h"
36 #include "xfs_dinode.h"
37 #include "xfs_inode.h"
38 #include "xfs_btree.h"
39 #include "xfs_ialloc.h"
41 #include "xfs_rtalloc.h"
42 #include "xfs_error.h"
43 #include "xfs_itable.h"
44 #include "xfs_fsops.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"
62 #include <linux/namei.h>
63 #include <linux/init.h>
64 #include <linux/mount.h>
65 #include <linux/mempool.h>
66 #include <linux/writeback.h>
67 #include <linux/kthread.h>
68 #include <linux/freezer.h>
70 static struct quotactl_ops xfs_quotactl_operations;
71 static struct super_operations xfs_super_operations;
72 static kmem_zone_t *xfs_vnode_zone;
73 static kmem_zone_t *xfs_ioend_zone;
74 mempool_t *xfs_ioend_pool;
76 STATIC struct xfs_mount_args *
78 struct super_block *sb,
81 struct xfs_mount_args *args;
83 args = kzalloc(sizeof(struct xfs_mount_args), GFP_KERNEL);
87 args->logbufs = args->logbufsize = -1;
88 strncpy(args->fsname, sb->s_id, MAXNAMELEN);
90 /* Copy the already-parsed mount(2) flags we're interested in */
91 if (sb->s_flags & MS_DIRSYNC)
92 args->flags |= XFSMNT_DIRSYNC;
93 if (sb->s_flags & MS_SYNCHRONOUS)
94 args->flags |= XFSMNT_WSYNC;
96 args->flags |= XFSMNT_QUIET;
97 args->flags |= XFSMNT_32BITINODES;
102 #define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
103 #define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
104 #define MNTOPT_LOGDEV "logdev" /* log device */
105 #define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
106 #define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
107 #define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
108 #define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
109 #define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
110 #define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
111 #define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
112 #define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
113 #define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
114 #define MNTOPT_MTPT "mtpt" /* filesystem mount point */
115 #define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
116 #define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
117 #define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
118 #define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
119 #define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
120 #define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
121 #define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
122 * unwritten extent conversion */
123 #define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
124 #define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
125 #define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
126 #define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
127 #define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
128 #define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
129 #define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
131 #define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
132 #define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
133 #define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
134 #define MNTOPT_QUOTA "quota" /* disk quotas (user) */
135 #define MNTOPT_NOQUOTA "noquota" /* no quotas */
136 #define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */
137 #define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */
138 #define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */
139 #define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */
140 #define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */
141 #define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */
142 #define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
143 #define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
144 #define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
145 #define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */
146 #define MNTOPT_DMAPI "dmapi" /* DMI enabled (DMAPI / XDSM) */
147 #define MNTOPT_XDSM "xdsm" /* DMI enabled (DMAPI / XDSM) */
148 #define MNTOPT_DMI "dmi" /* DMI enabled (DMAPI / XDSM) */
151 suffix_strtoul(char *s, char **endp, unsigned int base)
153 int last, shift_left_factor = 0;
156 last = strlen(value) - 1;
157 if (value[last] == 'K' || value[last] == 'k') {
158 shift_left_factor = 10;
161 if (value[last] == 'M' || value[last] == 'm') {
162 shift_left_factor = 20;
165 if (value[last] == 'G' || value[last] == 'g') {
166 shift_left_factor = 30;
170 return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
175 struct xfs_mount *mp,
177 struct xfs_mount_args *args,
180 char *this_char, *value, *eov;
181 int dsunit, dswidth, vol_dsunit, vol_dswidth;
183 int dmapi_implies_ikeep = 1;
185 args->flags |= XFSMNT_BARRIER;
186 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
191 iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0;
193 while ((this_char = strsep(&options, ",")) != NULL) {
196 if ((value = strchr(this_char, '=')) != NULL)
199 if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
200 if (!value || !*value) {
202 "XFS: %s option requires an argument",
206 args->logbufs = simple_strtoul(value, &eov, 10);
207 } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
208 if (!value || !*value) {
210 "XFS: %s option requires an argument",
214 args->logbufsize = suffix_strtoul(value, &eov, 10);
215 } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
216 if (!value || !*value) {
218 "XFS: %s option requires an argument",
222 strncpy(args->logname, value, MAXNAMELEN);
223 } else if (!strcmp(this_char, MNTOPT_MTPT)) {
224 if (!value || !*value) {
226 "XFS: %s option requires an argument",
230 strncpy(args->mtpt, value, MAXNAMELEN);
231 } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
232 if (!value || !*value) {
234 "XFS: %s option requires an argument",
238 strncpy(args->rtname, value, MAXNAMELEN);
239 } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
240 if (!value || !*value) {
242 "XFS: %s option requires an argument",
246 iosize = simple_strtoul(value, &eov, 10);
247 args->flags |= XFSMNT_IOSIZE;
248 args->iosizelog = (uint8_t) iosize;
249 } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
250 if (!value || !*value) {
252 "XFS: %s option requires an argument",
256 iosize = suffix_strtoul(value, &eov, 10);
257 args->flags |= XFSMNT_IOSIZE;
258 args->iosizelog = ffs(iosize) - 1;
259 } else if (!strcmp(this_char, MNTOPT_GRPID) ||
260 !strcmp(this_char, MNTOPT_BSDGROUPS)) {
261 mp->m_flags |= XFS_MOUNT_GRPID;
262 } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
263 !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
264 mp->m_flags &= ~XFS_MOUNT_GRPID;
265 } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
266 args->flags |= XFSMNT_WSYNC;
267 } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
268 args->flags |= XFSMNT_OSYNCISOSYNC;
269 } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
270 args->flags |= XFSMNT_NORECOVERY;
271 } else if (!strcmp(this_char, MNTOPT_INO64)) {
272 args->flags |= XFSMNT_INO64;
275 "XFS: %s option not allowed on this system",
279 } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
280 args->flags |= XFSMNT_NOALIGN;
281 } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
282 args->flags |= XFSMNT_SWALLOC;
283 } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
284 if (!value || !*value) {
286 "XFS: %s option requires an argument",
290 dsunit = simple_strtoul(value, &eov, 10);
291 } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
292 if (!value || !*value) {
294 "XFS: %s option requires an argument",
298 dswidth = simple_strtoul(value, &eov, 10);
299 } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
300 args->flags &= ~XFSMNT_32BITINODES;
303 "XFS: %s option not allowed on this system",
307 } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
308 args->flags |= XFSMNT_NOUUID;
309 } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
310 args->flags |= XFSMNT_BARRIER;
311 } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
312 args->flags &= ~XFSMNT_BARRIER;
313 } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
314 args->flags |= XFSMNT_IKEEP;
315 } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
316 dmapi_implies_ikeep = 0;
317 args->flags &= ~XFSMNT_IKEEP;
318 } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
319 args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE;
320 } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
321 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
322 } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
323 args->flags |= XFSMNT_ATTR2;
324 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
325 args->flags &= ~XFSMNT_ATTR2;
326 args->flags |= XFSMNT_NOATTR2;
327 } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
328 args->flags2 |= XFSMNT2_FILESTREAMS;
329 } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
330 args->flags &= ~(XFSMNT_UQUOTAENF|XFSMNT_UQUOTA);
331 args->flags &= ~(XFSMNT_GQUOTAENF|XFSMNT_GQUOTA);
332 } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
333 !strcmp(this_char, MNTOPT_UQUOTA) ||
334 !strcmp(this_char, MNTOPT_USRQUOTA)) {
335 args->flags |= XFSMNT_UQUOTA | XFSMNT_UQUOTAENF;
336 } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
337 !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
338 args->flags |= XFSMNT_UQUOTA;
339 args->flags &= ~XFSMNT_UQUOTAENF;
340 } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
341 !strcmp(this_char, MNTOPT_PRJQUOTA)) {
342 args->flags |= XFSMNT_PQUOTA | XFSMNT_PQUOTAENF;
343 } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
344 args->flags |= XFSMNT_PQUOTA;
345 args->flags &= ~XFSMNT_PQUOTAENF;
346 } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
347 !strcmp(this_char, MNTOPT_GRPQUOTA)) {
348 args->flags |= XFSMNT_GQUOTA | XFSMNT_GQUOTAENF;
349 } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
350 args->flags |= XFSMNT_GQUOTA;
351 args->flags &= ~XFSMNT_GQUOTAENF;
352 } else if (!strcmp(this_char, MNTOPT_DMAPI)) {
353 args->flags |= XFSMNT_DMAPI;
354 } else if (!strcmp(this_char, MNTOPT_XDSM)) {
355 args->flags |= XFSMNT_DMAPI;
356 } else if (!strcmp(this_char, MNTOPT_DMI)) {
357 args->flags |= XFSMNT_DMAPI;
358 } else if (!strcmp(this_char, "ihashsize")) {
360 "XFS: ihashsize no longer used, option is deprecated.");
361 } else if (!strcmp(this_char, "osyncisdsync")) {
362 /* no-op, this is now the default */
364 "XFS: osyncisdsync is now the default, option is deprecated.");
365 } else if (!strcmp(this_char, "irixsgid")) {
367 "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
370 "XFS: unknown mount option [%s].", this_char);
375 if (args->flags & XFSMNT_NORECOVERY) {
376 if ((mp->m_flags & XFS_MOUNT_RDONLY) == 0) {
378 "XFS: no-recovery mounts must be read-only.");
383 if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) {
385 "XFS: sunit and swidth options incompatible with the noalign option");
389 if ((args->flags & XFSMNT_GQUOTA) && (args->flags & XFSMNT_PQUOTA)) {
391 "XFS: cannot mount with both project and group quota");
395 if ((args->flags & XFSMNT_DMAPI) && *args->mtpt == '\0') {
396 printk("XFS: %s option needs the mount point option as well\n",
401 if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
403 "XFS: sunit and swidth must be specified together");
407 if (dsunit && (dswidth % dsunit != 0)) {
409 "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
415 * Applications using DMI filesystems often expect the
416 * inode generation number to be monotonically increasing.
417 * If we delete inode chunks we break this assumption, so
418 * keep unused inode chunks on disk for DMI filesystems
419 * until we come up with a better solution.
420 * Note that if "ikeep" or "noikeep" mount options are
421 * supplied, then they are honored.
423 if ((args->flags & XFSMNT_DMAPI) && dmapi_implies_ikeep)
424 args->flags |= XFSMNT_IKEEP;
426 if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
428 args->sunit = dsunit;
429 args->flags |= XFSMNT_RETERR;
431 args->sunit = vol_dsunit;
433 dswidth ? (args->swidth = dswidth) :
434 (args->swidth = vol_dswidth);
436 args->sunit = args->swidth = 0;
440 if (args->flags & XFSMNT_32BITINODES)
441 mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
443 args->flags |= XFSMNT_FLAGS2;
447 struct proc_xfs_info {
454 struct xfs_mount *mp,
457 static struct proc_xfs_info xfs_info_set[] = {
458 /* the few simple ones we can get from the mount struct */
459 { XFS_MOUNT_IKEEP, "," MNTOPT_IKEEP },
460 { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
461 { XFS_MOUNT_INO64, "," MNTOPT_INO64 },
462 { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
463 { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
464 { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
465 { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
466 { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
467 { XFS_MOUNT_ATTR2, "," MNTOPT_ATTR2 },
468 { XFS_MOUNT_FILESTREAMS, "," MNTOPT_FILESTREAM },
469 { XFS_MOUNT_DMAPI, "," MNTOPT_DMAPI },
470 { XFS_MOUNT_GRPID, "," MNTOPT_GRPID },
473 static struct proc_xfs_info xfs_info_unset[] = {
474 /* the few simple ones we can get from the mount struct */
475 { XFS_MOUNT_COMPAT_IOSIZE, "," MNTOPT_LARGEIO },
476 { XFS_MOUNT_BARRIER, "," MNTOPT_NOBARRIER },
477 { XFS_MOUNT_SMALL_INUMS, "," MNTOPT_64BITINODE },
480 struct proc_xfs_info *xfs_infop;
482 for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
483 if (mp->m_flags & xfs_infop->flag)
484 seq_puts(m, xfs_infop->str);
486 for (xfs_infop = xfs_info_unset; xfs_infop->flag; xfs_infop++) {
487 if (!(mp->m_flags & xfs_infop->flag))
488 seq_puts(m, xfs_infop->str);
491 if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
492 seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
493 (int)(1 << mp->m_writeio_log) >> 10);
495 if (mp->m_logbufs > 0)
496 seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
497 if (mp->m_logbsize > 0)
498 seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
501 seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
503 seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
505 if (mp->m_dalign > 0)
506 seq_printf(m, "," MNTOPT_SUNIT "=%d",
507 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
508 if (mp->m_swidth > 0)
509 seq_printf(m, "," MNTOPT_SWIDTH "=%d",
510 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
512 if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD))
513 seq_puts(m, "," MNTOPT_USRQUOTA);
514 else if (mp->m_qflags & XFS_UQUOTA_ACCT)
515 seq_puts(m, "," MNTOPT_UQUOTANOENF);
517 if (mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_OQUOTA_ENFD))
518 seq_puts(m, "," MNTOPT_PRJQUOTA);
519 else if (mp->m_qflags & XFS_PQUOTA_ACCT)
520 seq_puts(m, "," MNTOPT_PQUOTANOENF);
522 if (mp->m_qflags & (XFS_GQUOTA_ACCT|XFS_OQUOTA_ENFD))
523 seq_puts(m, "," MNTOPT_GRPQUOTA);
524 else if (mp->m_qflags & XFS_GQUOTA_ACCT)
525 seq_puts(m, "," MNTOPT_GQUOTANOENF);
527 if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
528 seq_puts(m, "," MNTOPT_NOQUOTA);
534 unsigned int blockshift)
536 unsigned int pagefactor = 1;
537 unsigned int bitshift = BITS_PER_LONG - 1;
539 /* Figure out maximum filesize, on Linux this can depend on
540 * the filesystem blocksize (on 32 bit platforms).
541 * __block_prepare_write does this in an [unsigned] long...
542 * page->index << (PAGE_CACHE_SHIFT - bbits)
543 * So, for page sized blocks (4K on 32 bit platforms),
544 * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
545 * (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
546 * but for smaller blocksizes it is less (bbits = log2 bsize).
547 * Note1: get_block_t takes a long (implicit cast from above)
548 * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch
549 * can optionally convert the [unsigned] long from above into
550 * an [unsigned] long long.
553 #if BITS_PER_LONG == 32
554 # if defined(CONFIG_LBD)
555 ASSERT(sizeof(sector_t) == 8);
556 pagefactor = PAGE_CACHE_SIZE;
557 bitshift = BITS_PER_LONG;
559 pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift);
563 return (((__uint64_t)pagefactor) << bitshift) - 1;
570 switch (inode->i_mode & S_IFMT) {
572 inode->i_op = &xfs_inode_operations;
573 inode->i_fop = &xfs_file_operations;
574 inode->i_mapping->a_ops = &xfs_address_space_operations;
577 if (xfs_sb_version_hasasciici(&XFS_M(inode->i_sb)->m_sb))
578 inode->i_op = &xfs_dir_ci_inode_operations;
580 inode->i_op = &xfs_dir_inode_operations;
581 inode->i_fop = &xfs_dir_file_operations;
584 inode->i_op = &xfs_symlink_inode_operations;
585 if (!(XFS_I(inode)->i_df.if_flags & XFS_IFINLINE))
586 inode->i_mapping->a_ops = &xfs_address_space_operations;
589 inode->i_op = &xfs_inode_operations;
590 init_special_inode(inode, inode->i_mode, inode->i_rdev);
596 xfs_revalidate_inode(
601 struct inode *inode = vn_to_inode(vp);
603 inode->i_mode = ip->i_d.di_mode;
604 inode->i_nlink = ip->i_d.di_nlink;
605 inode->i_uid = ip->i_d.di_uid;
606 inode->i_gid = ip->i_d.di_gid;
608 switch (inode->i_mode & S_IFMT) {
612 MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff,
613 sysv_minor(ip->i_df.if_u2.if_rdev));
620 inode->i_generation = ip->i_d.di_gen;
621 i_size_write(inode, ip->i_d.di_size);
622 inode->i_atime.tv_sec = ip->i_d.di_atime.t_sec;
623 inode->i_atime.tv_nsec = ip->i_d.di_atime.t_nsec;
624 inode->i_mtime.tv_sec = ip->i_d.di_mtime.t_sec;
625 inode->i_mtime.tv_nsec = ip->i_d.di_mtime.t_nsec;
626 inode->i_ctime.tv_sec = ip->i_d.di_ctime.t_sec;
627 inode->i_ctime.tv_nsec = ip->i_d.di_ctime.t_nsec;
628 if (ip->i_d.di_flags & XFS_DIFLAG_IMMUTABLE)
629 inode->i_flags |= S_IMMUTABLE;
631 inode->i_flags &= ~S_IMMUTABLE;
632 if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
633 inode->i_flags |= S_APPEND;
635 inode->i_flags &= ~S_APPEND;
636 if (ip->i_d.di_flags & XFS_DIFLAG_SYNC)
637 inode->i_flags |= S_SYNC;
639 inode->i_flags &= ~S_SYNC;
640 if (ip->i_d.di_flags & XFS_DIFLAG_NOATIME)
641 inode->i_flags |= S_NOATIME;
643 inode->i_flags &= ~S_NOATIME;
644 xfs_iflags_clear(ip, XFS_IMODIFIED);
648 xfs_initialize_vnode(
649 struct xfs_mount *mp,
651 struct xfs_inode *ip)
653 struct inode *inode = vn_to_inode(vp);
657 inode->i_private = ip;
661 * We need to set the ops vectors, and unlock the inode, but if
662 * we have been called during the new inode create process, it is
663 * too early to fill in the Linux inode. We will get called a
664 * second time once the inode is properly set up, and then we can
667 if (ip->i_d.di_mode != 0 && (inode->i_state & I_NEW)) {
668 xfs_revalidate_inode(mp, vp, ip);
669 xfs_set_inodeops(inode);
671 xfs_iflags_clear(ip, XFS_INEW);
674 unlock_new_inode(inode);
682 struct block_device **bdevp)
686 *bdevp = open_bdev_excl(name, 0, mp);
687 if (IS_ERR(*bdevp)) {
688 error = PTR_ERR(*bdevp);
689 printk("XFS: Invalid device [%s], error=%d\n", name, error);
697 struct block_device *bdev)
700 close_bdev_excl(bdev);
704 * Try to write out the superblock using barriers.
710 xfs_buf_t *sbp = xfs_getsb(mp, 0);
715 XFS_BUF_UNDELAYWRITE(sbp);
717 XFS_BUF_UNASYNC(sbp);
718 XFS_BUF_ORDERED(sbp);
721 error = xfs_iowait(sbp);
724 * Clear all the flags we set and possible error state in the
725 * buffer. We only did the write to try out whether barriers
726 * worked and shouldn't leave any traces in the superblock
730 XFS_BUF_ERROR(sbp, 0);
731 XFS_BUF_UNORDERED(sbp);
738 xfs_mountfs_check_barriers(xfs_mount_t *mp)
742 if (mp->m_logdev_targp != mp->m_ddev_targp) {
743 xfs_fs_cmn_err(CE_NOTE, mp,
744 "Disabling barriers, not supported with external log device");
745 mp->m_flags &= ~XFS_MOUNT_BARRIER;
749 if (mp->m_ddev_targp->bt_bdev->bd_disk->queue->ordered ==
750 QUEUE_ORDERED_NONE) {
751 xfs_fs_cmn_err(CE_NOTE, mp,
752 "Disabling barriers, not supported by the underlying device");
753 mp->m_flags &= ~XFS_MOUNT_BARRIER;
757 if (xfs_readonly_buftarg(mp->m_ddev_targp)) {
758 xfs_fs_cmn_err(CE_NOTE, mp,
759 "Disabling barriers, underlying device is readonly");
760 mp->m_flags &= ~XFS_MOUNT_BARRIER;
764 error = xfs_barrier_test(mp);
766 xfs_fs_cmn_err(CE_NOTE, mp,
767 "Disabling barriers, trial barrier write failed");
768 mp->m_flags &= ~XFS_MOUNT_BARRIER;
774 xfs_blkdev_issue_flush(
775 xfs_buftarg_t *buftarg)
777 blkdev_issue_flush(buftarg->bt_bdev, NULL);
782 struct xfs_mount *mp)
784 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
785 xfs_free_buftarg(mp->m_logdev_targp);
786 xfs_blkdev_put(mp->m_logdev_targp->bt_bdev);
788 if (mp->m_rtdev_targp) {
789 xfs_free_buftarg(mp->m_rtdev_targp);
790 xfs_blkdev_put(mp->m_rtdev_targp->bt_bdev);
792 xfs_free_buftarg(mp->m_ddev_targp);
796 * The file system configurations are:
797 * (1) device (partition) with data and internal log
798 * (2) logical volume with data and log subvolumes.
799 * (3) logical volume with data, log, and realtime subvolumes.
801 * We only have to handle opening the log and realtime volumes here if
802 * they are present. The data subvolume has already been opened by
803 * get_sb_bdev() and is stored in sb->s_bdev.
807 struct xfs_mount *mp,
808 struct xfs_mount_args *args)
810 struct block_device *ddev = mp->m_super->s_bdev;
811 struct block_device *logdev = NULL, *rtdev = NULL;
815 * Open real time and log devices - order is important.
817 if (args->logname[0]) {
818 error = xfs_blkdev_get(mp, args->logname, &logdev);
823 if (args->rtname[0]) {
824 error = xfs_blkdev_get(mp, args->rtname, &rtdev);
826 goto out_close_logdev;
828 if (rtdev == ddev || rtdev == logdev) {
830 "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
832 goto out_close_rtdev;
837 * Setup xfs_mount buffer target pointers
840 mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
841 if (!mp->m_ddev_targp)
842 goto out_close_rtdev;
845 mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
846 if (!mp->m_rtdev_targp)
847 goto out_free_ddev_targ;
850 if (logdev && logdev != ddev) {
851 mp->m_logdev_targp = xfs_alloc_buftarg(logdev, 1);
852 if (!mp->m_logdev_targp)
853 goto out_free_rtdev_targ;
855 mp->m_logdev_targp = mp->m_ddev_targp;
861 if (mp->m_rtdev_targp)
862 xfs_free_buftarg(mp->m_rtdev_targp);
864 xfs_free_buftarg(mp->m_ddev_targp);
867 xfs_blkdev_put(rtdev);
869 if (logdev && logdev != ddev)
870 xfs_blkdev_put(logdev);
876 * Setup xfs_mount buffer target pointers based on superblock
880 struct xfs_mount *mp)
884 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
885 mp->m_sb.sb_sectsize);
889 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
890 unsigned int log_sector_size = BBSIZE;
892 if (xfs_sb_version_hassector(&mp->m_sb))
893 log_sector_size = mp->m_sb.sb_logsectsize;
894 error = xfs_setsize_buftarg(mp->m_logdev_targp,
895 mp->m_sb.sb_blocksize,
900 if (mp->m_rtdev_targp) {
901 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
902 mp->m_sb.sb_blocksize,
903 mp->m_sb.sb_sectsize);
912 * XFS AIL push thread support
917 xfs_lsn_t threshold_lsn)
919 mp->m_ail.xa_target = threshold_lsn;
920 wake_up_process(mp->m_ail.xa_task);
927 xfs_mount_t *mp = (xfs_mount_t *)data;
928 xfs_lsn_t last_pushed_lsn = 0;
931 while (!kthread_should_stop()) {
933 schedule_timeout_interruptible(msecs_to_jiffies(tout));
940 if (XFS_FORCED_SHUTDOWN(mp))
943 tout = xfsaild_push(mp, &last_pushed_lsn);
953 mp->m_ail.xa_target = 0;
954 mp->m_ail.xa_task = kthread_run(xfsaild, mp, "xfsaild");
955 if (IS_ERR(mp->m_ail.xa_task))
956 return -PTR_ERR(mp->m_ail.xa_task);
964 kthread_stop(mp->m_ail.xa_task);
969 STATIC struct inode *
971 struct super_block *sb)
975 vp = kmem_zone_alloc(xfs_vnode_zone, KM_SLEEP);
978 return vn_to_inode(vp);
982 xfs_fs_destroy_inode(
985 kmem_zone_free(xfs_vnode_zone, vn_from_inode(inode));
989 xfs_fs_inode_init_once(
992 inode_init_once(vn_to_inode((bhv_vnode_t *)vnode));
996 * Attempt to flush the inode, this will actually fail
997 * if the inode is pinned, but we dirty the inode again
998 * at the point when it is unpinned after a log write,
999 * since this is when the inode itself becomes flushable.
1003 struct inode *inode,
1009 xfs_itrace_entry(XFS_I(inode));
1011 filemap_fdatawait(inode->i_mapping);
1012 flags |= FLUSH_SYNC;
1014 error = xfs_inode_flush(XFS_I(inode), flags);
1016 * if we failed to write out the inode then mark
1017 * it dirty again so we'll try again later.
1020 mark_inode_dirty_sync(inode);
1027 struct inode *inode)
1029 xfs_inode_t *ip = XFS_I(inode);
1032 * ip can be null when xfs_iget_core calls xfs_idestroy if we
1033 * find an inode with di_mode == 0 but without IGET_CREATE set.
1036 xfs_itrace_entry(ip);
1037 XFS_STATS_INC(vn_rele);
1038 XFS_STATS_INC(vn_remove);
1039 XFS_STATS_INC(vn_reclaim);
1040 XFS_STATS_DEC(vn_active);
1043 xfs_iflags_clear(ip, XFS_IMODIFIED);
1044 if (xfs_reclaim(ip))
1045 panic("%s: cannot reclaim 0x%p\n", __func__, inode);
1048 ASSERT(XFS_I(inode) == NULL);
1052 * Enqueue a work item to be picked up by the vfs xfssyncd thread.
1053 * Doing this has two advantages:
1054 * - It saves on stack space, which is tight in certain situations
1055 * - It can be used (with care) as a mechanism to avoid deadlocks.
1056 * Flushing while allocating in a full filesystem requires both.
1059 xfs_syncd_queue_work(
1060 struct xfs_mount *mp,
1062 void (*syncer)(struct xfs_mount *, void *))
1064 struct bhv_vfs_sync_work *work;
1066 work = kmem_alloc(sizeof(struct bhv_vfs_sync_work), KM_SLEEP);
1067 INIT_LIST_HEAD(&work->w_list);
1068 work->w_syncer = syncer;
1069 work->w_data = data;
1071 spin_lock(&mp->m_sync_lock);
1072 list_add_tail(&work->w_list, &mp->m_sync_list);
1073 spin_unlock(&mp->m_sync_lock);
1074 wake_up_process(mp->m_sync_task);
1078 * Flush delayed allocate data, attempting to free up reserved space
1079 * from existing allocations. At this point a new allocation attempt
1080 * has failed with ENOSPC and we are in the process of scratching our
1081 * heads, looking about for more room...
1084 xfs_flush_inode_work(
1085 struct xfs_mount *mp,
1088 struct inode *inode = arg;
1089 filemap_flush(inode->i_mapping);
1097 struct inode *inode = ip->i_vnode;
1100 xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_inode_work);
1101 delay(msecs_to_jiffies(500));
1105 * This is the "bigger hammer" version of xfs_flush_inode_work...
1106 * (IOW, "If at first you don't succeed, use a Bigger Hammer").
1109 xfs_flush_device_work(
1110 struct xfs_mount *mp,
1113 struct inode *inode = arg;
1114 sync_blockdev(mp->m_super->s_bdev);
1122 struct inode *inode = vn_to_inode(XFS_ITOV(ip));
1125 xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_device_work);
1126 delay(msecs_to_jiffies(500));
1127 xfs_log_force(ip->i_mount, (xfs_lsn_t)0, XFS_LOG_FORCE|XFS_LOG_SYNC);
1132 struct xfs_mount *mp,
1137 if (!(mp->m_flags & XFS_MOUNT_RDONLY))
1138 error = xfs_sync(mp, SYNC_FSDATA | SYNC_BDFLUSH | SYNC_ATTR);
1140 wake_up(&mp->m_wait_single_sync_task);
1147 struct xfs_mount *mp = arg;
1149 bhv_vfs_sync_work_t *work, *n;
1153 timeleft = xfs_syncd_centisecs * msecs_to_jiffies(10);
1155 timeleft = schedule_timeout_interruptible(timeleft);
1158 if (kthread_should_stop() && list_empty(&mp->m_sync_list))
1161 spin_lock(&mp->m_sync_lock);
1163 * We can get woken by laptop mode, to do a sync -
1164 * that's the (only!) case where the list would be
1165 * empty with time remaining.
1167 if (!timeleft || list_empty(&mp->m_sync_list)) {
1169 timeleft = xfs_syncd_centisecs *
1170 msecs_to_jiffies(10);
1171 INIT_LIST_HEAD(&mp->m_sync_work.w_list);
1172 list_add_tail(&mp->m_sync_work.w_list,
1175 list_for_each_entry_safe(work, n, &mp->m_sync_list, w_list)
1176 list_move(&work->w_list, &tmp);
1177 spin_unlock(&mp->m_sync_lock);
1179 list_for_each_entry_safe(work, n, &tmp, w_list) {
1180 (*work->w_syncer)(mp, work->w_data);
1181 list_del(&work->w_list);
1182 if (work == &mp->m_sync_work)
1193 struct super_block *sb)
1195 struct xfs_mount *mp = XFS_M(sb);
1196 struct xfs_inode *rip = mp->m_rootip;
1197 int unmount_event_flags = 0;
1200 kthread_stop(mp->m_sync_task);
1202 xfs_sync(mp, SYNC_ATTR | SYNC_DELWRI);
1205 if (mp->m_flags & XFS_MOUNT_DMAPI) {
1206 unmount_event_flags =
1207 (mp->m_dmevmask & (1 << DM_EVENT_UNMOUNT)) ?
1208 0 : DM_FLAGS_UNWANTED;
1210 * Ignore error from dmapi here, first unmount is not allowed
1211 * to fail anyway, and second we wouldn't want to fail a
1212 * unmount because of dmapi.
1214 XFS_SEND_PREUNMOUNT(mp, rip, DM_RIGHT_NULL, rip, DM_RIGHT_NULL,
1215 NULL, NULL, 0, 0, unmount_event_flags);
1220 * Blow away any referenced inode in the filestreams cache.
1221 * This can and will cause log traffic as inodes go inactive
1224 xfs_filestream_unmount(mp);
1226 XFS_bflush(mp->m_ddev_targp);
1227 error = xfs_unmount_flush(mp, 0);
1233 * If we're forcing a shutdown, typically because of a media error,
1234 * we want to make sure we invalidate dirty pages that belong to
1235 * referenced vnodes as well.
1237 if (XFS_FORCED_SHUTDOWN(mp)) {
1238 error = xfs_sync(mp, SYNC_WAIT | SYNC_CLOSE);
1239 ASSERT(error != EFSCORRUPTED);
1242 if (mp->m_flags & XFS_MOUNT_DMAPI) {
1243 XFS_SEND_UNMOUNT(mp, rip, DM_RIGHT_NULL, 0, 0,
1244 unmount_event_flags);
1248 xfs_icsb_destroy_counters(mp);
1249 xfs_close_devices(mp);
1257 struct super_block *sb)
1259 if (!(sb->s_flags & MS_RDONLY))
1260 xfs_sync(XFS_M(sb), SYNC_FSDATA);
1266 struct super_block *sb,
1269 struct xfs_mount *mp = XFS_M(sb);
1274 * Treat a sync operation like a freeze. This is to work
1275 * around a race in sync_inodes() which works in two phases
1276 * - an asynchronous flush, which can write out an inode
1277 * without waiting for file size updates to complete, and a
1278 * synchronous flush, which wont do anything because the
1279 * async flush removed the inode's dirty flag. Also
1280 * sync_inodes() will not see any files that just have
1281 * outstanding transactions to be flushed because we don't
1282 * dirty the Linux inode until after the transaction I/O
1285 if (wait || unlikely(sb->s_frozen == SB_FREEZE_WRITE)) {
1287 * First stage of freeze - no more writers will make progress
1288 * now we are here, so we flush delwri and delalloc buffers
1289 * here, then wait for all I/O to complete. Data is frozen at
1290 * that point. Metadata is not frozen, transactions can still
1291 * occur here so don't bother flushing the buftarg (i.e
1292 * SYNC_QUIESCE) because it'll just get dirty again.
1294 flags = SYNC_DATA_QUIESCE;
1296 flags = SYNC_FSDATA;
1298 error = xfs_sync(mp, flags);
1301 if (unlikely(laptop_mode)) {
1302 int prev_sync_seq = mp->m_sync_seq;
1305 * The disk must be active because we're syncing.
1306 * We schedule xfssyncd now (now that the disk is
1307 * active) instead of later (when it might not be).
1309 wake_up_process(mp->m_sync_task);
1311 * We have to wait for the sync iteration to complete.
1312 * If we don't, the disk activity caused by the sync
1313 * will come after the sync is completed, and that
1314 * triggers another sync from laptop mode.
1316 wait_event(mp->m_wait_single_sync_task,
1317 mp->m_sync_seq != prev_sync_seq);
1325 struct dentry *dentry,
1326 struct kstatfs *statp)
1328 struct xfs_mount *mp = XFS_M(dentry->d_sb);
1329 xfs_sb_t *sbp = &mp->m_sb;
1330 __uint64_t fakeinos, id;
1333 statp->f_type = XFS_SB_MAGIC;
1334 statp->f_namelen = MAXNAMELEN - 1;
1336 id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
1337 statp->f_fsid.val[0] = (u32)id;
1338 statp->f_fsid.val[1] = (u32)(id >> 32);
1340 xfs_icsb_sync_counters(mp, XFS_ICSB_LAZY_COUNT);
1342 spin_lock(&mp->m_sb_lock);
1343 statp->f_bsize = sbp->sb_blocksize;
1344 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
1345 statp->f_blocks = sbp->sb_dblocks - lsize;
1346 statp->f_bfree = statp->f_bavail =
1347 sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
1348 fakeinos = statp->f_bfree << sbp->sb_inopblog;
1350 fakeinos += mp->m_inoadd;
1353 MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
1354 if (mp->m_maxicount)
1358 statp->f_files = min_t(typeof(statp->f_files),
1361 statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
1362 spin_unlock(&mp->m_sb_lock);
1364 XFS_QM_DQSTATVFS(XFS_I(dentry->d_inode), statp);
1370 struct super_block *sb,
1374 struct xfs_mount *mp = XFS_M(sb);
1375 struct xfs_mount_args *args;
1378 args = xfs_args_allocate(sb, 0);
1382 error = xfs_parseargs(mp, options, args, 1);
1386 if (!(*flags & MS_RDONLY)) { /* rw/ro -> rw */
1387 if (mp->m_flags & XFS_MOUNT_RDONLY)
1388 mp->m_flags &= ~XFS_MOUNT_RDONLY;
1389 if (args->flags & XFSMNT_BARRIER) {
1390 mp->m_flags |= XFS_MOUNT_BARRIER;
1391 xfs_mountfs_check_barriers(mp);
1393 mp->m_flags &= ~XFS_MOUNT_BARRIER;
1395 } else if (!(mp->m_flags & XFS_MOUNT_RDONLY)) { /* rw -> ro */
1396 xfs_filestream_flush(mp);
1397 xfs_sync(mp, SYNC_DATA_QUIESCE);
1398 xfs_attr_quiesce(mp);
1399 mp->m_flags |= XFS_MOUNT_RDONLY;
1408 * Second stage of a freeze. The data is already frozen so we only
1409 * need to take care of themetadata. Once that's done write a dummy
1410 * record to dirty the log in case of a crash while frozen.
1414 struct super_block *sb)
1416 struct xfs_mount *mp = XFS_M(sb);
1418 xfs_attr_quiesce(mp);
1419 xfs_fs_log_dummy(mp);
1423 xfs_fs_show_options(
1425 struct vfsmount *mnt)
1427 return -xfs_showargs(XFS_M(mnt->mnt_sb), m);
1432 struct super_block *sb,
1435 return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XQUOTASYNC, 0, NULL);
1440 struct super_block *sb,
1441 struct fs_quota_stat *fqs)
1443 return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XGETQSTAT, 0, (caddr_t)fqs);
1448 struct super_block *sb,
1452 return -XFS_QM_QUOTACTL(XFS_M(sb), op, 0, (caddr_t)&flags);
1457 struct super_block *sb,
1460 struct fs_disk_quota *fdq)
1462 return -XFS_QM_QUOTACTL(XFS_M(sb),
1463 (type == USRQUOTA) ? Q_XGETQUOTA :
1464 ((type == GRPQUOTA) ? Q_XGETGQUOTA :
1465 Q_XGETPQUOTA), id, (caddr_t)fdq);
1470 struct super_block *sb,
1473 struct fs_disk_quota *fdq)
1475 return -XFS_QM_QUOTACTL(XFS_M(sb),
1476 (type == USRQUOTA) ? Q_XSETQLIM :
1477 ((type == GRPQUOTA) ? Q_XSETGQLIM :
1478 Q_XSETPQLIM), id, (caddr_t)fdq);
1482 * This function fills in xfs_mount_t fields based on mount args.
1483 * Note: the superblock has _not_ yet been read in.
1487 struct xfs_mount_args *ap,
1488 struct xfs_mount *mp)
1490 /* Values are in BBs */
1491 if ((ap->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
1493 * At this point the superblock has not been read
1494 * in, therefore we do not know the block size.
1495 * Before the mount call ends we will convert
1498 mp->m_dalign = ap->sunit;
1499 mp->m_swidth = ap->swidth;
1502 if (ap->logbufs != -1 &&
1504 (ap->logbufs < XLOG_MIN_ICLOGS ||
1505 ap->logbufs > XLOG_MAX_ICLOGS)) {
1507 "XFS: invalid logbufs value: %d [not %d-%d]",
1508 ap->logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
1509 return XFS_ERROR(EINVAL);
1511 mp->m_logbufs = ap->logbufs;
1512 if (ap->logbufsize != -1 &&
1513 ap->logbufsize != 0 &&
1514 (ap->logbufsize < XLOG_MIN_RECORD_BSIZE ||
1515 ap->logbufsize > XLOG_MAX_RECORD_BSIZE ||
1516 !is_power_of_2(ap->logbufsize))) {
1518 "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
1520 return XFS_ERROR(EINVAL);
1522 mp->m_logbsize = ap->logbufsize;
1523 mp->m_fsname_len = strlen(ap->fsname) + 1;
1524 mp->m_fsname = kmem_alloc(mp->m_fsname_len, KM_SLEEP);
1525 strcpy(mp->m_fsname, ap->fsname);
1526 if (ap->rtname[0]) {
1527 mp->m_rtname = kmem_alloc(strlen(ap->rtname) + 1, KM_SLEEP);
1528 strcpy(mp->m_rtname, ap->rtname);
1530 if (ap->logname[0]) {
1531 mp->m_logname = kmem_alloc(strlen(ap->logname) + 1, KM_SLEEP);
1532 strcpy(mp->m_logname, ap->logname);
1535 if (ap->flags & XFSMNT_WSYNC)
1536 mp->m_flags |= XFS_MOUNT_WSYNC;
1538 if (ap->flags & XFSMNT_INO64) {
1539 mp->m_flags |= XFS_MOUNT_INO64;
1540 mp->m_inoadd = XFS_INO64_OFFSET;
1543 if (ap->flags & XFSMNT_RETERR)
1544 mp->m_flags |= XFS_MOUNT_RETERR;
1545 if (ap->flags & XFSMNT_NOALIGN)
1546 mp->m_flags |= XFS_MOUNT_NOALIGN;
1547 if (ap->flags & XFSMNT_SWALLOC)
1548 mp->m_flags |= XFS_MOUNT_SWALLOC;
1549 if (ap->flags & XFSMNT_OSYNCISOSYNC)
1550 mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
1551 if (ap->flags & XFSMNT_32BITINODES)
1552 mp->m_flags |= XFS_MOUNT_32BITINODES;
1554 if (ap->flags & XFSMNT_IOSIZE) {
1555 if (ap->iosizelog > XFS_MAX_IO_LOG ||
1556 ap->iosizelog < XFS_MIN_IO_LOG) {
1558 "XFS: invalid log iosize: %d [not %d-%d]",
1559 ap->iosizelog, XFS_MIN_IO_LOG,
1561 return XFS_ERROR(EINVAL);
1564 mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
1565 mp->m_readio_log = mp->m_writeio_log = ap->iosizelog;
1568 if (ap->flags & XFSMNT_IKEEP)
1569 mp->m_flags |= XFS_MOUNT_IKEEP;
1570 if (ap->flags & XFSMNT_DIRSYNC)
1571 mp->m_flags |= XFS_MOUNT_DIRSYNC;
1572 if (ap->flags & XFSMNT_ATTR2)
1573 mp->m_flags |= XFS_MOUNT_ATTR2;
1574 if (ap->flags & XFSMNT_NOATTR2)
1575 mp->m_flags |= XFS_MOUNT_NOATTR2;
1577 if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
1578 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
1581 * no recovery flag requires a read-only mount
1583 if (ap->flags & XFSMNT_NORECOVERY) {
1584 if (!(mp->m_flags & XFS_MOUNT_RDONLY)) {
1586 "XFS: tried to mount a FS read-write without recovery!");
1587 return XFS_ERROR(EINVAL);
1589 mp->m_flags |= XFS_MOUNT_NORECOVERY;
1592 if (ap->flags & XFSMNT_NOUUID)
1593 mp->m_flags |= XFS_MOUNT_NOUUID;
1594 if (ap->flags & XFSMNT_BARRIER)
1595 mp->m_flags |= XFS_MOUNT_BARRIER;
1597 mp->m_flags &= ~XFS_MOUNT_BARRIER;
1599 if (ap->flags2 & XFSMNT2_FILESTREAMS)
1600 mp->m_flags |= XFS_MOUNT_FILESTREAMS;
1602 if (ap->flags & XFSMNT_DMAPI)
1603 mp->m_flags |= XFS_MOUNT_DMAPI;
1608 * This function fills in xfs_mount_t fields based on mount args.
1609 * Note: the superblock _has_ now been read in.
1613 struct xfs_mount_args *ap,
1614 struct xfs_mount *mp)
1616 int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
1618 /* Fail a mount where the logbuf is smaller then the log stripe */
1619 if (xfs_sb_version_haslogv2(&mp->m_sb)) {
1620 if ((ap->logbufsize <= 0) &&
1621 (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) {
1622 mp->m_logbsize = mp->m_sb.sb_logsunit;
1623 } else if (ap->logbufsize > 0 &&
1624 ap->logbufsize < mp->m_sb.sb_logsunit) {
1626 "XFS: logbuf size must be greater than or equal to log stripe size");
1627 return XFS_ERROR(EINVAL);
1630 /* Fail a mount if the logbuf is larger than 32K */
1631 if (ap->logbufsize > XLOG_BIG_RECORD_BSIZE) {
1633 "XFS: logbuf size for version 1 logs must be 16K or 32K");
1634 return XFS_ERROR(EINVAL);
1639 * mkfs'ed attr2 will turn on attr2 mount unless explicitly
1640 * told by noattr2 to turn it off
1642 if (xfs_sb_version_hasattr2(&mp->m_sb) &&
1643 !(ap->flags & XFSMNT_NOATTR2))
1644 mp->m_flags |= XFS_MOUNT_ATTR2;
1647 * prohibit r/w mounts of read-only filesystems
1649 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
1651 "XFS: cannot mount a read-only filesystem as read-write");
1652 return XFS_ERROR(EROFS);
1656 * check for shared mount.
1658 if (ap->flags & XFSMNT_SHARED) {
1659 if (!xfs_sb_version_hasshared(&mp->m_sb))
1660 return XFS_ERROR(EINVAL);
1663 * For IRIX 6.5, shared mounts must have the shared
1664 * version bit set, have the persistent readonly
1665 * field set, must be version 0 and can only be mounted
1668 if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) ||
1669 (mp->m_sb.sb_shared_vn != 0))
1670 return XFS_ERROR(EINVAL);
1672 mp->m_flags |= XFS_MOUNT_SHARED;
1675 * Shared XFS V0 can't deal with DMI. Return EINVAL.
1677 if (mp->m_sb.sb_shared_vn == 0 && (ap->flags & XFSMNT_DMAPI))
1678 return XFS_ERROR(EINVAL);
1681 if (ap->flags & XFSMNT_UQUOTA) {
1682 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
1683 if (ap->flags & XFSMNT_UQUOTAENF)
1684 mp->m_qflags |= XFS_UQUOTA_ENFD;
1687 if (ap->flags & XFSMNT_GQUOTA) {
1688 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
1689 if (ap->flags & XFSMNT_GQUOTAENF)
1690 mp->m_qflags |= XFS_OQUOTA_ENFD;
1691 } else if (ap->flags & XFSMNT_PQUOTA) {
1692 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
1693 if (ap->flags & XFSMNT_PQUOTAENF)
1694 mp->m_qflags |= XFS_OQUOTA_ENFD;
1702 struct super_block *sb,
1707 struct xfs_mount *mp = NULL;
1708 struct xfs_mount_args *args;
1709 int flags = 0, error = ENOMEM;
1711 args = xfs_args_allocate(sb, silent);
1715 mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
1719 spin_lock_init(&mp->m_sb_lock);
1720 mutex_init(&mp->m_ilock);
1721 mutex_init(&mp->m_growlock);
1722 atomic_set(&mp->m_active_trans, 0);
1723 INIT_LIST_HEAD(&mp->m_sync_list);
1724 spin_lock_init(&mp->m_sync_lock);
1725 init_waitqueue_head(&mp->m_wait_single_sync_task);
1730 if (sb->s_flags & MS_RDONLY)
1731 mp->m_flags |= XFS_MOUNT_RDONLY;
1733 error = xfs_parseargs(mp, (char *)data, args, 0);
1737 sb_min_blocksize(sb, BBSIZE);
1738 sb->s_xattr = xfs_xattr_handlers;
1739 sb->s_export_op = &xfs_export_operations;
1740 sb->s_qcop = &xfs_quotactl_operations;
1741 sb->s_op = &xfs_super_operations;
1743 error = xfs_dmops_get(mp, args);
1746 error = xfs_qmops_get(mp, args);
1750 if (args->flags & XFSMNT_QUIET)
1751 flags |= XFS_MFSI_QUIET;
1753 error = xfs_open_devices(mp, args);
1757 if (xfs_icsb_init_counters(mp))
1758 mp->m_flags |= XFS_MOUNT_NO_PERCPU_SB;
1761 * Setup flags based on mount(2) options and then the superblock
1763 error = xfs_start_flags(args, mp);
1765 goto out_destroy_counters;
1766 error = xfs_readsb(mp, flags);
1768 goto out_destroy_counters;
1769 error = xfs_finish_flags(args, mp);
1773 error = xfs_setup_devices(mp);
1777 if (mp->m_flags & XFS_MOUNT_BARRIER)
1778 xfs_mountfs_check_barriers(mp);
1780 error = xfs_filestream_mount(mp);
1784 error = xfs_mountfs(mp, flags);
1786 goto out_filestream_unmount;
1788 XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, args->mtpt, args->fsname);
1791 sb->s_magic = XFS_SB_MAGIC;
1792 sb->s_blocksize = mp->m_sb.sb_blocksize;
1793 sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
1794 sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
1795 sb->s_time_gran = 1;
1796 set_posix_acl_flag(sb);
1798 root = igrab(mp->m_rootip->i_vnode);
1803 if (is_bad_inode(root)) {
1807 sb->s_root = d_alloc_root(root);
1813 mp->m_sync_work.w_syncer = xfs_sync_worker;
1814 mp->m_sync_work.w_mount = mp;
1815 mp->m_sync_task = kthread_run(xfssyncd, mp, "xfssyncd");
1816 if (IS_ERR(mp->m_sync_task)) {
1817 error = -PTR_ERR(mp->m_sync_task);
1821 xfs_itrace_exit(XFS_I(sb->s_root->d_inode));
1826 out_filestream_unmount:
1827 xfs_filestream_unmount(mp);
1830 out_destroy_counters:
1831 xfs_icsb_destroy_counters(mp);
1832 xfs_close_devices(mp);
1853 * Blow away any referenced inode in the filestreams cache.
1854 * This can and will cause log traffic as inodes go inactive
1857 xfs_filestream_unmount(mp);
1859 XFS_bflush(mp->m_ddev_targp);
1860 error = xfs_unmount_flush(mp, 0);
1863 IRELE(mp->m_rootip);
1866 goto out_destroy_counters;
1871 struct file_system_type *fs_type,
1873 const char *dev_name,
1875 struct vfsmount *mnt)
1877 return get_sb_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super,
1881 static struct super_operations xfs_super_operations = {
1882 .alloc_inode = xfs_fs_alloc_inode,
1883 .destroy_inode = xfs_fs_destroy_inode,
1884 .write_inode = xfs_fs_write_inode,
1885 .clear_inode = xfs_fs_clear_inode,
1886 .put_super = xfs_fs_put_super,
1887 .write_super = xfs_fs_write_super,
1888 .sync_fs = xfs_fs_sync_super,
1889 .write_super_lockfs = xfs_fs_lockfs,
1890 .statfs = xfs_fs_statfs,
1891 .remount_fs = xfs_fs_remount,
1892 .show_options = xfs_fs_show_options,
1895 static struct quotactl_ops xfs_quotactl_operations = {
1896 .quota_sync = xfs_fs_quotasync,
1897 .get_xstate = xfs_fs_getxstate,
1898 .set_xstate = xfs_fs_setxstate,
1899 .get_xquota = xfs_fs_getxquota,
1900 .set_xquota = xfs_fs_setxquota,
1903 static struct file_system_type xfs_fs_type = {
1904 .owner = THIS_MODULE,
1906 .get_sb = xfs_fs_get_sb,
1907 .kill_sb = kill_block_super,
1908 .fs_flags = FS_REQUIRES_DEV,
1912 xfs_alloc_trace_bufs(void)
1914 #ifdef XFS_ALLOC_TRACE
1915 xfs_alloc_trace_buf = ktrace_alloc(XFS_ALLOC_TRACE_SIZE, KM_MAYFAIL);
1916 if (!xfs_alloc_trace_buf)
1919 #ifdef XFS_BMAP_TRACE
1920 xfs_bmap_trace_buf = ktrace_alloc(XFS_BMAP_TRACE_SIZE, KM_MAYFAIL);
1921 if (!xfs_bmap_trace_buf)
1922 goto out_free_alloc_trace;
1924 #ifdef XFS_BMBT_TRACE
1925 xfs_bmbt_trace_buf = ktrace_alloc(XFS_BMBT_TRACE_SIZE, KM_MAYFAIL);
1926 if (!xfs_bmbt_trace_buf)
1927 goto out_free_bmap_trace;
1929 #ifdef XFS_ATTR_TRACE
1930 xfs_attr_trace_buf = ktrace_alloc(XFS_ATTR_TRACE_SIZE, KM_MAYFAIL);
1931 if (!xfs_attr_trace_buf)
1932 goto out_free_bmbt_trace;
1934 #ifdef XFS_DIR2_TRACE
1935 xfs_dir2_trace_buf = ktrace_alloc(XFS_DIR2_GTRACE_SIZE, KM_MAYFAIL);
1936 if (!xfs_dir2_trace_buf)
1937 goto out_free_attr_trace;
1942 #ifdef XFS_DIR2_TRACE
1943 out_free_attr_trace:
1945 #ifdef XFS_ATTR_TRACE
1946 ktrace_free(xfs_attr_trace_buf);
1947 out_free_bmbt_trace:
1949 #ifdef XFS_BMBT_TRACE
1950 ktrace_free(xfs_bmbt_trace_buf);
1951 out_free_bmap_trace:
1953 #ifdef XFS_BMAP_TRACE
1954 ktrace_free(xfs_bmap_trace_buf);
1955 out_free_alloc_trace:
1957 #ifdef XFS_ALLOC_TRACE
1958 ktrace_free(xfs_alloc_trace_buf);
1965 xfs_free_trace_bufs(void)
1967 #ifdef XFS_DIR2_TRACE
1968 ktrace_free(xfs_dir2_trace_buf);
1970 #ifdef XFS_ATTR_TRACE
1971 ktrace_free(xfs_attr_trace_buf);
1973 #ifdef XFS_BMBT_TRACE
1974 ktrace_free(xfs_bmbt_trace_buf);
1976 #ifdef XFS_BMAP_TRACE
1977 ktrace_free(xfs_bmap_trace_buf);
1979 #ifdef XFS_ALLOC_TRACE
1980 ktrace_free(xfs_alloc_trace_buf);
1985 xfs_init_zones(void)
1987 xfs_vnode_zone = kmem_zone_init_flags(sizeof(bhv_vnode_t), "xfs_vnode",
1988 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM |
1990 xfs_fs_inode_init_once);
1991 if (!xfs_vnode_zone)
1994 xfs_ioend_zone = kmem_zone_init(sizeof(xfs_ioend_t), "xfs_ioend");
1995 if (!xfs_ioend_zone)
1996 goto out_destroy_vnode_zone;
1998 xfs_ioend_pool = mempool_create_slab_pool(4 * MAX_BUF_PER_PAGE,
2000 if (!xfs_ioend_pool)
2001 goto out_destroy_ioend_zone;
2003 xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t),
2005 if (!xfs_log_ticket_zone)
2006 goto out_destroy_ioend_pool;
2008 xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
2009 "xfs_bmap_free_item");
2010 if (!xfs_bmap_free_item_zone)
2011 goto out_destroy_log_ticket_zone;
2012 xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
2014 if (!xfs_btree_cur_zone)
2015 goto out_destroy_bmap_free_item_zone;
2017 xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t),
2019 if (!xfs_da_state_zone)
2020 goto out_destroy_btree_cur_zone;
2022 xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf");
2023 if (!xfs_dabuf_zone)
2024 goto out_destroy_da_state_zone;
2026 xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
2027 if (!xfs_ifork_zone)
2028 goto out_destroy_dabuf_zone;
2030 xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
2031 if (!xfs_trans_zone)
2032 goto out_destroy_ifork_zone;
2035 * The size of the zone allocated buf log item is the maximum
2036 * size possible under XFS. This wastes a little bit of memory,
2037 * but it is much faster.
2039 xfs_buf_item_zone = kmem_zone_init((sizeof(xfs_buf_log_item_t) +
2040 (((XFS_MAX_BLOCKSIZE / XFS_BLI_CHUNK) /
2041 NBWORD) * sizeof(int))), "xfs_buf_item");
2042 if (!xfs_buf_item_zone)
2043 goto out_destroy_trans_zone;
2045 xfs_efd_zone = kmem_zone_init((sizeof(xfs_efd_log_item_t) +
2046 ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
2047 sizeof(xfs_extent_t))), "xfs_efd_item");
2049 goto out_destroy_buf_item_zone;
2051 xfs_efi_zone = kmem_zone_init((sizeof(xfs_efi_log_item_t) +
2052 ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
2053 sizeof(xfs_extent_t))), "xfs_efi_item");
2055 goto out_destroy_efd_zone;
2058 kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
2059 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM |
2060 KM_ZONE_SPREAD, NULL);
2061 if (!xfs_inode_zone)
2062 goto out_destroy_efi_zone;
2065 kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
2066 KM_ZONE_SPREAD, NULL);
2068 goto out_destroy_inode_zone;
2070 #ifdef CONFIG_XFS_POSIX_ACL
2071 xfs_acl_zone = kmem_zone_init(sizeof(xfs_acl_t), "xfs_acl");
2073 goto out_destroy_ili_zone;
2078 #ifdef CONFIG_XFS_POSIX_ACL
2079 out_destroy_ili_zone:
2081 kmem_zone_destroy(xfs_ili_zone);
2082 out_destroy_inode_zone:
2083 kmem_zone_destroy(xfs_inode_zone);
2084 out_destroy_efi_zone:
2085 kmem_zone_destroy(xfs_efi_zone);
2086 out_destroy_efd_zone:
2087 kmem_zone_destroy(xfs_efd_zone);
2088 out_destroy_buf_item_zone:
2089 kmem_zone_destroy(xfs_buf_item_zone);
2090 out_destroy_trans_zone:
2091 kmem_zone_destroy(xfs_trans_zone);
2092 out_destroy_ifork_zone:
2093 kmem_zone_destroy(xfs_ifork_zone);
2094 out_destroy_dabuf_zone:
2095 kmem_zone_destroy(xfs_dabuf_zone);
2096 out_destroy_da_state_zone:
2097 kmem_zone_destroy(xfs_da_state_zone);
2098 out_destroy_btree_cur_zone:
2099 kmem_zone_destroy(xfs_btree_cur_zone);
2100 out_destroy_bmap_free_item_zone:
2101 kmem_zone_destroy(xfs_bmap_free_item_zone);
2102 out_destroy_log_ticket_zone:
2103 kmem_zone_destroy(xfs_log_ticket_zone);
2104 out_destroy_ioend_pool:
2105 mempool_destroy(xfs_ioend_pool);
2106 out_destroy_ioend_zone:
2107 kmem_zone_destroy(xfs_ioend_zone);
2108 out_destroy_vnode_zone:
2109 kmem_zone_destroy(xfs_vnode_zone);
2115 xfs_destroy_zones(void)
2117 #ifdef CONFIG_XFS_POSIX_ACL
2118 kmem_zone_destroy(xfs_acl_zone);
2120 kmem_zone_destroy(xfs_ili_zone);
2121 kmem_zone_destroy(xfs_inode_zone);
2122 kmem_zone_destroy(xfs_efi_zone);
2123 kmem_zone_destroy(xfs_efd_zone);
2124 kmem_zone_destroy(xfs_buf_item_zone);
2125 kmem_zone_destroy(xfs_trans_zone);
2126 kmem_zone_destroy(xfs_ifork_zone);
2127 kmem_zone_destroy(xfs_dabuf_zone);
2128 kmem_zone_destroy(xfs_da_state_zone);
2129 kmem_zone_destroy(xfs_btree_cur_zone);
2130 kmem_zone_destroy(xfs_bmap_free_item_zone);
2131 kmem_zone_destroy(xfs_log_ticket_zone);
2132 mempool_destroy(xfs_ioend_pool);
2133 kmem_zone_destroy(xfs_ioend_zone);
2134 kmem_zone_destroy(xfs_vnode_zone);
2142 static char message[] __initdata = KERN_INFO \
2143 XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled\n";
2151 error = xfs_init_zones();
2155 error = xfs_alloc_trace_bufs();
2157 goto out_destroy_zones;
2159 error = xfs_mru_cache_init();
2161 goto out_free_trace_buffers;
2163 error = xfs_filestream_init();
2165 goto out_mru_cache_uninit;
2167 error = xfs_buf_init();
2169 goto out_filestream_uninit;
2171 error = xfs_init_procfs();
2173 goto out_buf_terminate;
2175 error = xfs_sysctl_register();
2177 goto out_cleanup_procfs;
2181 error = register_filesystem(&xfs_fs_type);
2183 goto out_sysctl_unregister;
2186 out_sysctl_unregister:
2187 xfs_sysctl_unregister();
2189 xfs_cleanup_procfs();
2191 xfs_buf_terminate();
2192 out_filestream_uninit:
2193 xfs_filestream_uninit();
2194 out_mru_cache_uninit:
2195 xfs_mru_cache_uninit();
2196 out_free_trace_buffers:
2197 xfs_free_trace_bufs();
2199 xfs_destroy_zones();
2208 unregister_filesystem(&xfs_fs_type);
2209 xfs_sysctl_unregister();
2210 xfs_cleanup_procfs();
2211 xfs_buf_terminate();
2212 xfs_filestream_uninit();
2213 xfs_mru_cache_uninit();
2214 xfs_free_trace_bufs();
2215 xfs_destroy_zones();
2219 module_init(init_xfs_fs);
2220 module_exit(exit_xfs_fs);
2222 MODULE_AUTHOR("Silicon Graphics, Inc.");
2223 MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
2224 MODULE_LICENSE("GPL");