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"
57 #include <linux/namei.h>
58 #include <linux/init.h>
59 #include <linux/mount.h>
60 #include <linux/mempool.h>
61 #include <linux/writeback.h>
62 #include <linux/kthread.h>
63 #include <linux/freezer.h>
65 static struct quotactl_ops xfs_quotactl_operations;
66 static struct super_operations xfs_super_operations;
67 static kmem_zone_t *xfs_vnode_zone;
68 static kmem_zone_t *xfs_ioend_zone;
69 mempool_t *xfs_ioend_pool;
71 STATIC struct xfs_mount_args *
73 struct super_block *sb,
76 struct xfs_mount_args *args;
78 args = kzalloc(sizeof(struct xfs_mount_args), GFP_KERNEL);
82 args->logbufs = args->logbufsize = -1;
83 strncpy(args->fsname, sb->s_id, MAXNAMELEN);
85 /* Copy the already-parsed mount(2) flags we're interested in */
86 if (sb->s_flags & MS_DIRSYNC)
87 args->flags |= XFSMNT_DIRSYNC;
88 if (sb->s_flags & MS_SYNCHRONOUS)
89 args->flags |= XFSMNT_WSYNC;
91 args->flags |= XFSMNT_QUIET;
92 args->flags |= XFSMNT_32BITINODES;
97 #define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
98 #define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
99 #define MNTOPT_LOGDEV "logdev" /* log device */
100 #define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
101 #define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
102 #define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
103 #define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
104 #define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
105 #define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
106 #define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
107 #define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
108 #define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
109 #define MNTOPT_MTPT "mtpt" /* filesystem mount point */
110 #define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
111 #define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
112 #define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
113 #define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
114 #define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
115 #define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
116 #define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
117 * unwritten extent conversion */
118 #define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
119 #define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
120 #define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
121 #define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
122 #define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
123 #define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
124 #define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
126 #define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
127 #define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
128 #define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
129 #define MNTOPT_QUOTA "quota" /* disk quotas (user) */
130 #define MNTOPT_NOQUOTA "noquota" /* no quotas */
131 #define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */
132 #define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */
133 #define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */
134 #define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */
135 #define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */
136 #define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */
137 #define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
138 #define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
139 #define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
140 #define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */
141 #define MNTOPT_DMAPI "dmapi" /* DMI enabled (DMAPI / XDSM) */
142 #define MNTOPT_XDSM "xdsm" /* DMI enabled (DMAPI / XDSM) */
143 #define MNTOPT_DMI "dmi" /* DMI enabled (DMAPI / XDSM) */
146 suffix_strtoul(char *s, char **endp, unsigned int base)
148 int last, shift_left_factor = 0;
151 last = strlen(value) - 1;
152 if (value[last] == 'K' || value[last] == 'k') {
153 shift_left_factor = 10;
156 if (value[last] == 'M' || value[last] == 'm') {
157 shift_left_factor = 20;
160 if (value[last] == 'G' || value[last] == 'g') {
161 shift_left_factor = 30;
165 return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
170 struct xfs_mount *mp,
172 struct xfs_mount_args *args,
175 char *this_char, *value, *eov;
176 int dsunit, dswidth, vol_dsunit, vol_dswidth;
178 int dmapi_implies_ikeep = 1;
180 args->flags |= XFSMNT_BARRIER;
181 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
186 iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0;
188 while ((this_char = strsep(&options, ",")) != NULL) {
191 if ((value = strchr(this_char, '=')) != NULL)
194 if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
195 if (!value || !*value) {
197 "XFS: %s option requires an argument",
201 args->logbufs = simple_strtoul(value, &eov, 10);
202 } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
203 if (!value || !*value) {
205 "XFS: %s option requires an argument",
209 args->logbufsize = suffix_strtoul(value, &eov, 10);
210 } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
211 if (!value || !*value) {
213 "XFS: %s option requires an argument",
217 strncpy(args->logname, value, MAXNAMELEN);
218 } else if (!strcmp(this_char, MNTOPT_MTPT)) {
219 if (!value || !*value) {
221 "XFS: %s option requires an argument",
225 strncpy(args->mtpt, value, MAXNAMELEN);
226 } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
227 if (!value || !*value) {
229 "XFS: %s option requires an argument",
233 strncpy(args->rtname, value, MAXNAMELEN);
234 } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
235 if (!value || !*value) {
237 "XFS: %s option requires an argument",
241 iosize = simple_strtoul(value, &eov, 10);
242 args->flags |= XFSMNT_IOSIZE;
243 args->iosizelog = (uint8_t) iosize;
244 } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
245 if (!value || !*value) {
247 "XFS: %s option requires an argument",
251 iosize = suffix_strtoul(value, &eov, 10);
252 args->flags |= XFSMNT_IOSIZE;
253 args->iosizelog = ffs(iosize) - 1;
254 } else if (!strcmp(this_char, MNTOPT_GRPID) ||
255 !strcmp(this_char, MNTOPT_BSDGROUPS)) {
256 mp->m_flags |= XFS_MOUNT_GRPID;
257 } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
258 !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
259 mp->m_flags &= ~XFS_MOUNT_GRPID;
260 } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
261 args->flags |= XFSMNT_WSYNC;
262 } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
263 args->flags |= XFSMNT_OSYNCISOSYNC;
264 } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
265 args->flags |= XFSMNT_NORECOVERY;
266 } else if (!strcmp(this_char, MNTOPT_INO64)) {
267 args->flags |= XFSMNT_INO64;
270 "XFS: %s option not allowed on this system",
274 } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
275 args->flags |= XFSMNT_NOALIGN;
276 } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
277 args->flags |= XFSMNT_SWALLOC;
278 } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
279 if (!value || !*value) {
281 "XFS: %s option requires an argument",
285 dsunit = simple_strtoul(value, &eov, 10);
286 } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
287 if (!value || !*value) {
289 "XFS: %s option requires an argument",
293 dswidth = simple_strtoul(value, &eov, 10);
294 } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
295 args->flags &= ~XFSMNT_32BITINODES;
298 "XFS: %s option not allowed on this system",
302 } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
303 args->flags |= XFSMNT_NOUUID;
304 } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
305 args->flags |= XFSMNT_BARRIER;
306 } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
307 args->flags &= ~XFSMNT_BARRIER;
308 } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
309 args->flags |= XFSMNT_IKEEP;
310 } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
311 dmapi_implies_ikeep = 0;
312 args->flags &= ~XFSMNT_IKEEP;
313 } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
314 args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE;
315 } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
316 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
317 } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
318 args->flags |= XFSMNT_ATTR2;
319 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
320 args->flags &= ~XFSMNT_ATTR2;
321 args->flags |= XFSMNT_NOATTR2;
322 } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
323 args->flags2 |= XFSMNT2_FILESTREAMS;
324 } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
325 args->flags &= ~(XFSMNT_UQUOTAENF|XFSMNT_UQUOTA);
326 args->flags &= ~(XFSMNT_GQUOTAENF|XFSMNT_GQUOTA);
327 } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
328 !strcmp(this_char, MNTOPT_UQUOTA) ||
329 !strcmp(this_char, MNTOPT_USRQUOTA)) {
330 args->flags |= XFSMNT_UQUOTA | XFSMNT_UQUOTAENF;
331 } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
332 !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
333 args->flags |= XFSMNT_UQUOTA;
334 args->flags &= ~XFSMNT_UQUOTAENF;
335 } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
336 !strcmp(this_char, MNTOPT_PRJQUOTA)) {
337 args->flags |= XFSMNT_PQUOTA | XFSMNT_PQUOTAENF;
338 } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
339 args->flags |= XFSMNT_PQUOTA;
340 args->flags &= ~XFSMNT_PQUOTAENF;
341 } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
342 !strcmp(this_char, MNTOPT_GRPQUOTA)) {
343 args->flags |= XFSMNT_GQUOTA | XFSMNT_GQUOTAENF;
344 } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
345 args->flags |= XFSMNT_GQUOTA;
346 args->flags &= ~XFSMNT_GQUOTAENF;
347 } else if (!strcmp(this_char, MNTOPT_DMAPI)) {
348 args->flags |= XFSMNT_DMAPI;
349 } else if (!strcmp(this_char, MNTOPT_XDSM)) {
350 args->flags |= XFSMNT_DMAPI;
351 } else if (!strcmp(this_char, MNTOPT_DMI)) {
352 args->flags |= XFSMNT_DMAPI;
353 } else if (!strcmp(this_char, "ihashsize")) {
355 "XFS: ihashsize no longer used, option is deprecated.");
356 } else if (!strcmp(this_char, "osyncisdsync")) {
357 /* no-op, this is now the default */
359 "XFS: osyncisdsync is now the default, option is deprecated.");
360 } else if (!strcmp(this_char, "irixsgid")) {
362 "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
365 "XFS: unknown mount option [%s].", this_char);
370 if (args->flags & XFSMNT_NORECOVERY) {
371 if ((mp->m_flags & XFS_MOUNT_RDONLY) == 0) {
373 "XFS: no-recovery mounts must be read-only.");
378 if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) {
380 "XFS: sunit and swidth options incompatible with the noalign option");
384 if ((args->flags & XFSMNT_GQUOTA) && (args->flags & XFSMNT_PQUOTA)) {
386 "XFS: cannot mount with both project and group quota");
390 if ((args->flags & XFSMNT_DMAPI) && *args->mtpt == '\0') {
391 printk("XFS: %s option needs the mount point option as well\n",
396 if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
398 "XFS: sunit and swidth must be specified together");
402 if (dsunit && (dswidth % dsunit != 0)) {
404 "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
410 * Applications using DMI filesystems often expect the
411 * inode generation number to be monotonically increasing.
412 * If we delete inode chunks we break this assumption, so
413 * keep unused inode chunks on disk for DMI filesystems
414 * until we come up with a better solution.
415 * Note that if "ikeep" or "noikeep" mount options are
416 * supplied, then they are honored.
418 if ((args->flags & XFSMNT_DMAPI) && dmapi_implies_ikeep)
419 args->flags |= XFSMNT_IKEEP;
421 if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
423 args->sunit = dsunit;
424 args->flags |= XFSMNT_RETERR;
426 args->sunit = vol_dsunit;
428 dswidth ? (args->swidth = dswidth) :
429 (args->swidth = vol_dswidth);
431 args->sunit = args->swidth = 0;
435 if (args->flags & XFSMNT_32BITINODES)
436 mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
438 args->flags |= XFSMNT_FLAGS2;
442 struct proc_xfs_info {
449 struct xfs_mount *mp,
452 static struct proc_xfs_info xfs_info_set[] = {
453 /* the few simple ones we can get from the mount struct */
454 { XFS_MOUNT_IKEEP, "," MNTOPT_IKEEP },
455 { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
456 { XFS_MOUNT_INO64, "," MNTOPT_INO64 },
457 { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
458 { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
459 { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
460 { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
461 { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
462 { XFS_MOUNT_ATTR2, "," MNTOPT_ATTR2 },
463 { XFS_MOUNT_FILESTREAMS, "," MNTOPT_FILESTREAM },
464 { XFS_MOUNT_DMAPI, "," MNTOPT_DMAPI },
465 { XFS_MOUNT_GRPID, "," MNTOPT_GRPID },
468 static struct proc_xfs_info xfs_info_unset[] = {
469 /* the few simple ones we can get from the mount struct */
470 { XFS_MOUNT_COMPAT_IOSIZE, "," MNTOPT_LARGEIO },
471 { XFS_MOUNT_BARRIER, "," MNTOPT_NOBARRIER },
472 { XFS_MOUNT_SMALL_INUMS, "," MNTOPT_64BITINODE },
475 struct proc_xfs_info *xfs_infop;
477 for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
478 if (mp->m_flags & xfs_infop->flag)
479 seq_puts(m, xfs_infop->str);
481 for (xfs_infop = xfs_info_unset; xfs_infop->flag; xfs_infop++) {
482 if (!(mp->m_flags & xfs_infop->flag))
483 seq_puts(m, xfs_infop->str);
486 if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
487 seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
488 (int)(1 << mp->m_writeio_log) >> 10);
490 if (mp->m_logbufs > 0)
491 seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
492 if (mp->m_logbsize > 0)
493 seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
496 seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
498 seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
500 if (mp->m_dalign > 0)
501 seq_printf(m, "," MNTOPT_SUNIT "=%d",
502 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
503 if (mp->m_swidth > 0)
504 seq_printf(m, "," MNTOPT_SWIDTH "=%d",
505 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
507 if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD))
508 seq_puts(m, "," MNTOPT_USRQUOTA);
509 else if (mp->m_qflags & XFS_UQUOTA_ACCT)
510 seq_puts(m, "," MNTOPT_UQUOTANOENF);
512 if (mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_OQUOTA_ENFD))
513 seq_puts(m, "," MNTOPT_PRJQUOTA);
514 else if (mp->m_qflags & XFS_PQUOTA_ACCT)
515 seq_puts(m, "," MNTOPT_PQUOTANOENF);
517 if (mp->m_qflags & (XFS_GQUOTA_ACCT|XFS_OQUOTA_ENFD))
518 seq_puts(m, "," MNTOPT_GRPQUOTA);
519 else if (mp->m_qflags & XFS_GQUOTA_ACCT)
520 seq_puts(m, "," MNTOPT_GQUOTANOENF);
522 if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
523 seq_puts(m, "," MNTOPT_NOQUOTA);
529 unsigned int blockshift)
531 unsigned int pagefactor = 1;
532 unsigned int bitshift = BITS_PER_LONG - 1;
534 /* Figure out maximum filesize, on Linux this can depend on
535 * the filesystem blocksize (on 32 bit platforms).
536 * __block_prepare_write does this in an [unsigned] long...
537 * page->index << (PAGE_CACHE_SHIFT - bbits)
538 * So, for page sized blocks (4K on 32 bit platforms),
539 * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
540 * (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
541 * but for smaller blocksizes it is less (bbits = log2 bsize).
542 * Note1: get_block_t takes a long (implicit cast from above)
543 * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch
544 * can optionally convert the [unsigned] long from above into
545 * an [unsigned] long long.
548 #if BITS_PER_LONG == 32
549 # if defined(CONFIG_LBD)
550 ASSERT(sizeof(sector_t) == 8);
551 pagefactor = PAGE_CACHE_SIZE;
552 bitshift = BITS_PER_LONG;
554 pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift);
558 return (((__uint64_t)pagefactor) << bitshift) - 1;
565 switch (inode->i_mode & S_IFMT) {
567 inode->i_op = &xfs_inode_operations;
568 inode->i_fop = &xfs_file_operations;
569 inode->i_mapping->a_ops = &xfs_address_space_operations;
572 if (xfs_sb_version_hasasciici(&XFS_M(inode->i_sb)->m_sb))
573 inode->i_op = &xfs_dir_ci_inode_operations;
575 inode->i_op = &xfs_dir_inode_operations;
576 inode->i_fop = &xfs_dir_file_operations;
579 inode->i_op = &xfs_symlink_inode_operations;
580 if (!(XFS_I(inode)->i_df.if_flags & XFS_IFINLINE))
581 inode->i_mapping->a_ops = &xfs_address_space_operations;
584 inode->i_op = &xfs_inode_operations;
585 init_special_inode(inode, inode->i_mode, inode->i_rdev);
591 xfs_revalidate_inode(
596 struct inode *inode = vn_to_inode(vp);
598 inode->i_mode = ip->i_d.di_mode;
599 inode->i_nlink = ip->i_d.di_nlink;
600 inode->i_uid = ip->i_d.di_uid;
601 inode->i_gid = ip->i_d.di_gid;
603 switch (inode->i_mode & S_IFMT) {
607 MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff,
608 sysv_minor(ip->i_df.if_u2.if_rdev));
615 inode->i_generation = ip->i_d.di_gen;
616 i_size_write(inode, ip->i_d.di_size);
617 inode->i_atime.tv_sec = ip->i_d.di_atime.t_sec;
618 inode->i_atime.tv_nsec = ip->i_d.di_atime.t_nsec;
619 inode->i_mtime.tv_sec = ip->i_d.di_mtime.t_sec;
620 inode->i_mtime.tv_nsec = ip->i_d.di_mtime.t_nsec;
621 inode->i_ctime.tv_sec = ip->i_d.di_ctime.t_sec;
622 inode->i_ctime.tv_nsec = ip->i_d.di_ctime.t_nsec;
623 if (ip->i_d.di_flags & XFS_DIFLAG_IMMUTABLE)
624 inode->i_flags |= S_IMMUTABLE;
626 inode->i_flags &= ~S_IMMUTABLE;
627 if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
628 inode->i_flags |= S_APPEND;
630 inode->i_flags &= ~S_APPEND;
631 if (ip->i_d.di_flags & XFS_DIFLAG_SYNC)
632 inode->i_flags |= S_SYNC;
634 inode->i_flags &= ~S_SYNC;
635 if (ip->i_d.di_flags & XFS_DIFLAG_NOATIME)
636 inode->i_flags |= S_NOATIME;
638 inode->i_flags &= ~S_NOATIME;
639 xfs_iflags_clear(ip, XFS_IMODIFIED);
643 xfs_initialize_vnode(
644 struct xfs_mount *mp,
646 struct xfs_inode *ip)
648 struct inode *inode = vn_to_inode(vp);
652 inode->i_private = ip;
656 * We need to set the ops vectors, and unlock the inode, but if
657 * we have been called during the new inode create process, it is
658 * too early to fill in the Linux inode. We will get called a
659 * second time once the inode is properly set up, and then we can
662 if (ip->i_d.di_mode != 0 && (inode->i_state & I_NEW)) {
663 xfs_revalidate_inode(mp, vp, ip);
664 xfs_set_inodeops(inode);
666 xfs_iflags_clear(ip, XFS_INEW);
669 unlock_new_inode(inode);
677 struct block_device **bdevp)
681 *bdevp = open_bdev_excl(name, 0, mp);
682 if (IS_ERR(*bdevp)) {
683 error = PTR_ERR(*bdevp);
684 printk("XFS: Invalid device [%s], error=%d\n", name, error);
692 struct block_device *bdev)
695 close_bdev_excl(bdev);
699 * Try to write out the superblock using barriers.
705 xfs_buf_t *sbp = xfs_getsb(mp, 0);
710 XFS_BUF_UNDELAYWRITE(sbp);
712 XFS_BUF_UNASYNC(sbp);
713 XFS_BUF_ORDERED(sbp);
716 error = xfs_iowait(sbp);
719 * Clear all the flags we set and possible error state in the
720 * buffer. We only did the write to try out whether barriers
721 * worked and shouldn't leave any traces in the superblock
725 XFS_BUF_ERROR(sbp, 0);
726 XFS_BUF_UNORDERED(sbp);
733 xfs_mountfs_check_barriers(xfs_mount_t *mp)
737 if (mp->m_logdev_targp != mp->m_ddev_targp) {
738 xfs_fs_cmn_err(CE_NOTE, mp,
739 "Disabling barriers, not supported with external log device");
740 mp->m_flags &= ~XFS_MOUNT_BARRIER;
744 if (mp->m_ddev_targp->bt_bdev->bd_disk->queue->ordered ==
745 QUEUE_ORDERED_NONE) {
746 xfs_fs_cmn_err(CE_NOTE, mp,
747 "Disabling barriers, not supported by the underlying device");
748 mp->m_flags &= ~XFS_MOUNT_BARRIER;
752 if (xfs_readonly_buftarg(mp->m_ddev_targp)) {
753 xfs_fs_cmn_err(CE_NOTE, mp,
754 "Disabling barriers, underlying device is readonly");
755 mp->m_flags &= ~XFS_MOUNT_BARRIER;
759 error = xfs_barrier_test(mp);
761 xfs_fs_cmn_err(CE_NOTE, mp,
762 "Disabling barriers, trial barrier write failed");
763 mp->m_flags &= ~XFS_MOUNT_BARRIER;
769 xfs_blkdev_issue_flush(
770 xfs_buftarg_t *buftarg)
772 blkdev_issue_flush(buftarg->bt_bdev, NULL);
777 struct xfs_mount *mp)
779 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
780 xfs_free_buftarg(mp->m_logdev_targp);
781 xfs_blkdev_put(mp->m_logdev_targp->bt_bdev);
783 if (mp->m_rtdev_targp) {
784 xfs_free_buftarg(mp->m_rtdev_targp);
785 xfs_blkdev_put(mp->m_rtdev_targp->bt_bdev);
787 xfs_free_buftarg(mp->m_ddev_targp);
791 * The file system configurations are:
792 * (1) device (partition) with data and internal log
793 * (2) logical volume with data and log subvolumes.
794 * (3) logical volume with data, log, and realtime subvolumes.
796 * We only have to handle opening the log and realtime volumes here if
797 * they are present. The data subvolume has already been opened by
798 * get_sb_bdev() and is stored in sb->s_bdev.
802 struct xfs_mount *mp,
803 struct xfs_mount_args *args)
805 struct block_device *ddev = mp->m_super->s_bdev;
806 struct block_device *logdev = NULL, *rtdev = NULL;
810 * Open real time and log devices - order is important.
812 if (args->logname[0]) {
813 error = xfs_blkdev_get(mp, args->logname, &logdev);
818 if (args->rtname[0]) {
819 error = xfs_blkdev_get(mp, args->rtname, &rtdev);
821 goto out_close_logdev;
823 if (rtdev == ddev || rtdev == logdev) {
825 "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
827 goto out_close_rtdev;
832 * Setup xfs_mount buffer target pointers
835 mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
836 if (!mp->m_ddev_targp)
837 goto out_close_rtdev;
840 mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
841 if (!mp->m_rtdev_targp)
842 goto out_free_ddev_targ;
845 if (logdev && logdev != ddev) {
846 mp->m_logdev_targp = xfs_alloc_buftarg(logdev, 1);
847 if (!mp->m_logdev_targp)
848 goto out_free_rtdev_targ;
850 mp->m_logdev_targp = mp->m_ddev_targp;
856 if (mp->m_rtdev_targp)
857 xfs_free_buftarg(mp->m_rtdev_targp);
859 xfs_free_buftarg(mp->m_ddev_targp);
862 xfs_blkdev_put(rtdev);
864 if (logdev && logdev != ddev)
865 xfs_blkdev_put(logdev);
871 * Setup xfs_mount buffer target pointers based on superblock
875 struct xfs_mount *mp)
879 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
880 mp->m_sb.sb_sectsize);
884 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
885 unsigned int log_sector_size = BBSIZE;
887 if (xfs_sb_version_hassector(&mp->m_sb))
888 log_sector_size = mp->m_sb.sb_logsectsize;
889 error = xfs_setsize_buftarg(mp->m_logdev_targp,
890 mp->m_sb.sb_blocksize,
895 if (mp->m_rtdev_targp) {
896 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
897 mp->m_sb.sb_blocksize,
898 mp->m_sb.sb_sectsize);
907 * XFS AIL push thread support
912 xfs_lsn_t threshold_lsn)
914 mp->m_ail.xa_target = threshold_lsn;
915 wake_up_process(mp->m_ail.xa_task);
922 xfs_mount_t *mp = (xfs_mount_t *)data;
923 xfs_lsn_t last_pushed_lsn = 0;
926 while (!kthread_should_stop()) {
928 schedule_timeout_interruptible(msecs_to_jiffies(tout));
935 if (XFS_FORCED_SHUTDOWN(mp))
938 tout = xfsaild_push(mp, &last_pushed_lsn);
948 mp->m_ail.xa_target = 0;
949 mp->m_ail.xa_task = kthread_run(xfsaild, mp, "xfsaild");
950 if (IS_ERR(mp->m_ail.xa_task))
951 return -PTR_ERR(mp->m_ail.xa_task);
959 kthread_stop(mp->m_ail.xa_task);
964 STATIC struct inode *
966 struct super_block *sb)
970 vp = kmem_zone_alloc(xfs_vnode_zone, KM_SLEEP);
973 return vn_to_inode(vp);
977 xfs_fs_destroy_inode(
980 kmem_zone_free(xfs_vnode_zone, vn_from_inode(inode));
984 xfs_fs_inode_init_once(
987 inode_init_once(vn_to_inode((bhv_vnode_t *)vnode));
993 xfs_vnode_zone = kmem_zone_init_flags(sizeof(bhv_vnode_t), "xfs_vnode",
994 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM |
996 xfs_fs_inode_init_once);
1000 xfs_ioend_zone = kmem_zone_init(sizeof(xfs_ioend_t), "xfs_ioend");
1001 if (!xfs_ioend_zone)
1002 goto out_destroy_vnode_zone;
1004 xfs_ioend_pool = mempool_create_slab_pool(4 * MAX_BUF_PER_PAGE,
1006 if (!xfs_ioend_pool)
1007 goto out_free_ioend_zone;
1010 out_free_ioend_zone:
1011 kmem_zone_destroy(xfs_ioend_zone);
1012 out_destroy_vnode_zone:
1013 kmem_zone_destroy(xfs_vnode_zone);
1019 xfs_destroy_zones(void)
1021 mempool_destroy(xfs_ioend_pool);
1022 kmem_zone_destroy(xfs_vnode_zone);
1023 kmem_zone_destroy(xfs_ioend_zone);
1027 * Attempt to flush the inode, this will actually fail
1028 * if the inode is pinned, but we dirty the inode again
1029 * at the point when it is unpinned after a log write,
1030 * since this is when the inode itself becomes flushable.
1034 struct inode *inode,
1040 xfs_itrace_entry(XFS_I(inode));
1042 filemap_fdatawait(inode->i_mapping);
1043 flags |= FLUSH_SYNC;
1045 error = xfs_inode_flush(XFS_I(inode), flags);
1047 * if we failed to write out the inode then mark
1048 * it dirty again so we'll try again later.
1051 mark_inode_dirty_sync(inode);
1058 struct inode *inode)
1060 xfs_inode_t *ip = XFS_I(inode);
1063 * ip can be null when xfs_iget_core calls xfs_idestroy if we
1064 * find an inode with di_mode == 0 but without IGET_CREATE set.
1067 xfs_itrace_entry(ip);
1068 XFS_STATS_INC(vn_rele);
1069 XFS_STATS_INC(vn_remove);
1070 XFS_STATS_INC(vn_reclaim);
1071 XFS_STATS_DEC(vn_active);
1074 xfs_iflags_clear(ip, XFS_IMODIFIED);
1075 if (xfs_reclaim(ip))
1076 panic("%s: cannot reclaim 0x%p\n", __func__, inode);
1079 ASSERT(XFS_I(inode) == NULL);
1083 * Enqueue a work item to be picked up by the vfs xfssyncd thread.
1084 * Doing this has two advantages:
1085 * - It saves on stack space, which is tight in certain situations
1086 * - It can be used (with care) as a mechanism to avoid deadlocks.
1087 * Flushing while allocating in a full filesystem requires both.
1090 xfs_syncd_queue_work(
1091 struct xfs_mount *mp,
1093 void (*syncer)(struct xfs_mount *, void *))
1095 struct bhv_vfs_sync_work *work;
1097 work = kmem_alloc(sizeof(struct bhv_vfs_sync_work), KM_SLEEP);
1098 INIT_LIST_HEAD(&work->w_list);
1099 work->w_syncer = syncer;
1100 work->w_data = data;
1102 spin_lock(&mp->m_sync_lock);
1103 list_add_tail(&work->w_list, &mp->m_sync_list);
1104 spin_unlock(&mp->m_sync_lock);
1105 wake_up_process(mp->m_sync_task);
1109 * Flush delayed allocate data, attempting to free up reserved space
1110 * from existing allocations. At this point a new allocation attempt
1111 * has failed with ENOSPC and we are in the process of scratching our
1112 * heads, looking about for more room...
1115 xfs_flush_inode_work(
1116 struct xfs_mount *mp,
1119 struct inode *inode = arg;
1120 filemap_flush(inode->i_mapping);
1128 struct inode *inode = ip->i_vnode;
1131 xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_inode_work);
1132 delay(msecs_to_jiffies(500));
1136 * This is the "bigger hammer" version of xfs_flush_inode_work...
1137 * (IOW, "If at first you don't succeed, use a Bigger Hammer").
1140 xfs_flush_device_work(
1141 struct xfs_mount *mp,
1144 struct inode *inode = arg;
1145 sync_blockdev(mp->m_super->s_bdev);
1153 struct inode *inode = vn_to_inode(XFS_ITOV(ip));
1156 xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_device_work);
1157 delay(msecs_to_jiffies(500));
1158 xfs_log_force(ip->i_mount, (xfs_lsn_t)0, XFS_LOG_FORCE|XFS_LOG_SYNC);
1163 struct xfs_mount *mp,
1168 if (!(mp->m_flags & XFS_MOUNT_RDONLY))
1169 error = xfs_sync(mp, SYNC_FSDATA | SYNC_BDFLUSH | SYNC_ATTR);
1171 wake_up(&mp->m_wait_single_sync_task);
1178 struct xfs_mount *mp = arg;
1180 bhv_vfs_sync_work_t *work, *n;
1184 timeleft = xfs_syncd_centisecs * msecs_to_jiffies(10);
1186 timeleft = schedule_timeout_interruptible(timeleft);
1189 if (kthread_should_stop() && list_empty(&mp->m_sync_list))
1192 spin_lock(&mp->m_sync_lock);
1194 * We can get woken by laptop mode, to do a sync -
1195 * that's the (only!) case where the list would be
1196 * empty with time remaining.
1198 if (!timeleft || list_empty(&mp->m_sync_list)) {
1200 timeleft = xfs_syncd_centisecs *
1201 msecs_to_jiffies(10);
1202 INIT_LIST_HEAD(&mp->m_sync_work.w_list);
1203 list_add_tail(&mp->m_sync_work.w_list,
1206 list_for_each_entry_safe(work, n, &mp->m_sync_list, w_list)
1207 list_move(&work->w_list, &tmp);
1208 spin_unlock(&mp->m_sync_lock);
1210 list_for_each_entry_safe(work, n, &tmp, w_list) {
1211 (*work->w_syncer)(mp, work->w_data);
1212 list_del(&work->w_list);
1213 if (work == &mp->m_sync_work)
1224 struct super_block *sb)
1226 struct xfs_mount *mp = XFS_M(sb);
1227 struct xfs_inode *rip = mp->m_rootip;
1228 int unmount_event_flags = 0;
1231 kthread_stop(mp->m_sync_task);
1233 xfs_sync(mp, SYNC_ATTR | SYNC_DELWRI);
1236 if (mp->m_flags & XFS_MOUNT_DMAPI) {
1237 unmount_event_flags =
1238 (mp->m_dmevmask & (1 << DM_EVENT_UNMOUNT)) ?
1239 0 : DM_FLAGS_UNWANTED;
1241 * Ignore error from dmapi here, first unmount is not allowed
1242 * to fail anyway, and second we wouldn't want to fail a
1243 * unmount because of dmapi.
1245 XFS_SEND_PREUNMOUNT(mp, rip, DM_RIGHT_NULL, rip, DM_RIGHT_NULL,
1246 NULL, NULL, 0, 0, unmount_event_flags);
1251 * Blow away any referenced inode in the filestreams cache.
1252 * This can and will cause log traffic as inodes go inactive
1255 xfs_filestream_unmount(mp);
1257 XFS_bflush(mp->m_ddev_targp);
1258 error = xfs_unmount_flush(mp, 0);
1264 * If we're forcing a shutdown, typically because of a media error,
1265 * we want to make sure we invalidate dirty pages that belong to
1266 * referenced vnodes as well.
1268 if (XFS_FORCED_SHUTDOWN(mp)) {
1269 error = xfs_sync(mp, SYNC_WAIT | SYNC_CLOSE);
1270 ASSERT(error != EFSCORRUPTED);
1273 if (mp->m_flags & XFS_MOUNT_DMAPI) {
1274 XFS_SEND_UNMOUNT(mp, rip, DM_RIGHT_NULL, 0, 0,
1275 unmount_event_flags);
1279 xfs_icsb_destroy_counters(mp);
1280 xfs_close_devices(mp);
1288 struct super_block *sb)
1290 if (!(sb->s_flags & MS_RDONLY))
1291 xfs_sync(XFS_M(sb), SYNC_FSDATA);
1297 struct super_block *sb,
1300 struct xfs_mount *mp = XFS_M(sb);
1305 * Treat a sync operation like a freeze. This is to work
1306 * around a race in sync_inodes() which works in two phases
1307 * - an asynchronous flush, which can write out an inode
1308 * without waiting for file size updates to complete, and a
1309 * synchronous flush, which wont do anything because the
1310 * async flush removed the inode's dirty flag. Also
1311 * sync_inodes() will not see any files that just have
1312 * outstanding transactions to be flushed because we don't
1313 * dirty the Linux inode until after the transaction I/O
1316 if (wait || unlikely(sb->s_frozen == SB_FREEZE_WRITE)) {
1318 * First stage of freeze - no more writers will make progress
1319 * now we are here, so we flush delwri and delalloc buffers
1320 * here, then wait for all I/O to complete. Data is frozen at
1321 * that point. Metadata is not frozen, transactions can still
1322 * occur here so don't bother flushing the buftarg (i.e
1323 * SYNC_QUIESCE) because it'll just get dirty again.
1325 flags = SYNC_DATA_QUIESCE;
1327 flags = SYNC_FSDATA;
1329 error = xfs_sync(mp, flags);
1332 if (unlikely(laptop_mode)) {
1333 int prev_sync_seq = mp->m_sync_seq;
1336 * The disk must be active because we're syncing.
1337 * We schedule xfssyncd now (now that the disk is
1338 * active) instead of later (when it might not be).
1340 wake_up_process(mp->m_sync_task);
1342 * We have to wait for the sync iteration to complete.
1343 * If we don't, the disk activity caused by the sync
1344 * will come after the sync is completed, and that
1345 * triggers another sync from laptop mode.
1347 wait_event(mp->m_wait_single_sync_task,
1348 mp->m_sync_seq != prev_sync_seq);
1356 struct dentry *dentry,
1357 struct kstatfs *statp)
1359 struct xfs_mount *mp = XFS_M(dentry->d_sb);
1360 xfs_sb_t *sbp = &mp->m_sb;
1361 __uint64_t fakeinos, id;
1364 statp->f_type = XFS_SB_MAGIC;
1365 statp->f_namelen = MAXNAMELEN - 1;
1367 id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
1368 statp->f_fsid.val[0] = (u32)id;
1369 statp->f_fsid.val[1] = (u32)(id >> 32);
1371 xfs_icsb_sync_counters(mp, XFS_ICSB_LAZY_COUNT);
1373 spin_lock(&mp->m_sb_lock);
1374 statp->f_bsize = sbp->sb_blocksize;
1375 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
1376 statp->f_blocks = sbp->sb_dblocks - lsize;
1377 statp->f_bfree = statp->f_bavail =
1378 sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
1379 fakeinos = statp->f_bfree << sbp->sb_inopblog;
1381 fakeinos += mp->m_inoadd;
1384 MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
1385 if (mp->m_maxicount)
1389 statp->f_files = min_t(typeof(statp->f_files),
1392 statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
1393 spin_unlock(&mp->m_sb_lock);
1395 XFS_QM_DQSTATVFS(XFS_I(dentry->d_inode), statp);
1401 struct super_block *sb,
1405 struct xfs_mount *mp = XFS_M(sb);
1406 struct xfs_mount_args *args;
1409 args = xfs_args_allocate(sb, 0);
1413 error = xfs_parseargs(mp, options, args, 1);
1417 if (!(*flags & MS_RDONLY)) { /* rw/ro -> rw */
1418 if (mp->m_flags & XFS_MOUNT_RDONLY)
1419 mp->m_flags &= ~XFS_MOUNT_RDONLY;
1420 if (args->flags & XFSMNT_BARRIER) {
1421 mp->m_flags |= XFS_MOUNT_BARRIER;
1422 xfs_mountfs_check_barriers(mp);
1424 mp->m_flags &= ~XFS_MOUNT_BARRIER;
1426 } else if (!(mp->m_flags & XFS_MOUNT_RDONLY)) { /* rw -> ro */
1427 xfs_filestream_flush(mp);
1428 xfs_sync(mp, SYNC_DATA_QUIESCE);
1429 xfs_attr_quiesce(mp);
1430 mp->m_flags |= XFS_MOUNT_RDONLY;
1439 * Second stage of a freeze. The data is already frozen so we only
1440 * need to take care of themetadata. Once that's done write a dummy
1441 * record to dirty the log in case of a crash while frozen.
1445 struct super_block *sb)
1447 struct xfs_mount *mp = XFS_M(sb);
1449 xfs_attr_quiesce(mp);
1450 xfs_fs_log_dummy(mp);
1454 xfs_fs_show_options(
1456 struct vfsmount *mnt)
1458 return -xfs_showargs(XFS_M(mnt->mnt_sb), m);
1463 struct super_block *sb,
1466 return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XQUOTASYNC, 0, NULL);
1471 struct super_block *sb,
1472 struct fs_quota_stat *fqs)
1474 return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XGETQSTAT, 0, (caddr_t)fqs);
1479 struct super_block *sb,
1483 return -XFS_QM_QUOTACTL(XFS_M(sb), op, 0, (caddr_t)&flags);
1488 struct super_block *sb,
1491 struct fs_disk_quota *fdq)
1493 return -XFS_QM_QUOTACTL(XFS_M(sb),
1494 (type == USRQUOTA) ? Q_XGETQUOTA :
1495 ((type == GRPQUOTA) ? Q_XGETGQUOTA :
1496 Q_XGETPQUOTA), id, (caddr_t)fdq);
1501 struct super_block *sb,
1504 struct fs_disk_quota *fdq)
1506 return -XFS_QM_QUOTACTL(XFS_M(sb),
1507 (type == USRQUOTA) ? Q_XSETQLIM :
1508 ((type == GRPQUOTA) ? Q_XSETGQLIM :
1509 Q_XSETPQLIM), id, (caddr_t)fdq);
1513 * This function fills in xfs_mount_t fields based on mount args.
1514 * Note: the superblock has _not_ yet been read in.
1518 struct xfs_mount_args *ap,
1519 struct xfs_mount *mp)
1521 /* Values are in BBs */
1522 if ((ap->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
1524 * At this point the superblock has not been read
1525 * in, therefore we do not know the block size.
1526 * Before the mount call ends we will convert
1529 mp->m_dalign = ap->sunit;
1530 mp->m_swidth = ap->swidth;
1533 if (ap->logbufs != -1 &&
1535 (ap->logbufs < XLOG_MIN_ICLOGS ||
1536 ap->logbufs > XLOG_MAX_ICLOGS)) {
1538 "XFS: invalid logbufs value: %d [not %d-%d]",
1539 ap->logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
1540 return XFS_ERROR(EINVAL);
1542 mp->m_logbufs = ap->logbufs;
1543 if (ap->logbufsize != -1 &&
1544 ap->logbufsize != 0 &&
1545 (ap->logbufsize < XLOG_MIN_RECORD_BSIZE ||
1546 ap->logbufsize > XLOG_MAX_RECORD_BSIZE ||
1547 !is_power_of_2(ap->logbufsize))) {
1549 "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
1551 return XFS_ERROR(EINVAL);
1553 mp->m_logbsize = ap->logbufsize;
1554 mp->m_fsname_len = strlen(ap->fsname) + 1;
1555 mp->m_fsname = kmem_alloc(mp->m_fsname_len, KM_SLEEP);
1556 strcpy(mp->m_fsname, ap->fsname);
1557 if (ap->rtname[0]) {
1558 mp->m_rtname = kmem_alloc(strlen(ap->rtname) + 1, KM_SLEEP);
1559 strcpy(mp->m_rtname, ap->rtname);
1561 if (ap->logname[0]) {
1562 mp->m_logname = kmem_alloc(strlen(ap->logname) + 1, KM_SLEEP);
1563 strcpy(mp->m_logname, ap->logname);
1566 if (ap->flags & XFSMNT_WSYNC)
1567 mp->m_flags |= XFS_MOUNT_WSYNC;
1569 if (ap->flags & XFSMNT_INO64) {
1570 mp->m_flags |= XFS_MOUNT_INO64;
1571 mp->m_inoadd = XFS_INO64_OFFSET;
1574 if (ap->flags & XFSMNT_RETERR)
1575 mp->m_flags |= XFS_MOUNT_RETERR;
1576 if (ap->flags & XFSMNT_NOALIGN)
1577 mp->m_flags |= XFS_MOUNT_NOALIGN;
1578 if (ap->flags & XFSMNT_SWALLOC)
1579 mp->m_flags |= XFS_MOUNT_SWALLOC;
1580 if (ap->flags & XFSMNT_OSYNCISOSYNC)
1581 mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
1582 if (ap->flags & XFSMNT_32BITINODES)
1583 mp->m_flags |= XFS_MOUNT_32BITINODES;
1585 if (ap->flags & XFSMNT_IOSIZE) {
1586 if (ap->iosizelog > XFS_MAX_IO_LOG ||
1587 ap->iosizelog < XFS_MIN_IO_LOG) {
1589 "XFS: invalid log iosize: %d [not %d-%d]",
1590 ap->iosizelog, XFS_MIN_IO_LOG,
1592 return XFS_ERROR(EINVAL);
1595 mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
1596 mp->m_readio_log = mp->m_writeio_log = ap->iosizelog;
1599 if (ap->flags & XFSMNT_IKEEP)
1600 mp->m_flags |= XFS_MOUNT_IKEEP;
1601 if (ap->flags & XFSMNT_DIRSYNC)
1602 mp->m_flags |= XFS_MOUNT_DIRSYNC;
1603 if (ap->flags & XFSMNT_ATTR2)
1604 mp->m_flags |= XFS_MOUNT_ATTR2;
1605 if (ap->flags & XFSMNT_NOATTR2)
1606 mp->m_flags |= XFS_MOUNT_NOATTR2;
1608 if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
1609 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
1612 * no recovery flag requires a read-only mount
1614 if (ap->flags & XFSMNT_NORECOVERY) {
1615 if (!(mp->m_flags & XFS_MOUNT_RDONLY)) {
1617 "XFS: tried to mount a FS read-write without recovery!");
1618 return XFS_ERROR(EINVAL);
1620 mp->m_flags |= XFS_MOUNT_NORECOVERY;
1623 if (ap->flags & XFSMNT_NOUUID)
1624 mp->m_flags |= XFS_MOUNT_NOUUID;
1625 if (ap->flags & XFSMNT_BARRIER)
1626 mp->m_flags |= XFS_MOUNT_BARRIER;
1628 mp->m_flags &= ~XFS_MOUNT_BARRIER;
1630 if (ap->flags2 & XFSMNT2_FILESTREAMS)
1631 mp->m_flags |= XFS_MOUNT_FILESTREAMS;
1633 if (ap->flags & XFSMNT_DMAPI)
1634 mp->m_flags |= XFS_MOUNT_DMAPI;
1639 * This function fills in xfs_mount_t fields based on mount args.
1640 * Note: the superblock _has_ now been read in.
1644 struct xfs_mount_args *ap,
1645 struct xfs_mount *mp)
1647 int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
1649 /* Fail a mount where the logbuf is smaller then the log stripe */
1650 if (xfs_sb_version_haslogv2(&mp->m_sb)) {
1651 if ((ap->logbufsize <= 0) &&
1652 (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) {
1653 mp->m_logbsize = mp->m_sb.sb_logsunit;
1654 } else if (ap->logbufsize > 0 &&
1655 ap->logbufsize < mp->m_sb.sb_logsunit) {
1657 "XFS: logbuf size must be greater than or equal to log stripe size");
1658 return XFS_ERROR(EINVAL);
1661 /* Fail a mount if the logbuf is larger than 32K */
1662 if (ap->logbufsize > XLOG_BIG_RECORD_BSIZE) {
1664 "XFS: logbuf size for version 1 logs must be 16K or 32K");
1665 return XFS_ERROR(EINVAL);
1670 * mkfs'ed attr2 will turn on attr2 mount unless explicitly
1671 * told by noattr2 to turn it off
1673 if (xfs_sb_version_hasattr2(&mp->m_sb) &&
1674 !(ap->flags & XFSMNT_NOATTR2))
1675 mp->m_flags |= XFS_MOUNT_ATTR2;
1678 * prohibit r/w mounts of read-only filesystems
1680 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
1682 "XFS: cannot mount a read-only filesystem as read-write");
1683 return XFS_ERROR(EROFS);
1687 * check for shared mount.
1689 if (ap->flags & XFSMNT_SHARED) {
1690 if (!xfs_sb_version_hasshared(&mp->m_sb))
1691 return XFS_ERROR(EINVAL);
1694 * For IRIX 6.5, shared mounts must have the shared
1695 * version bit set, have the persistent readonly
1696 * field set, must be version 0 and can only be mounted
1699 if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) ||
1700 (mp->m_sb.sb_shared_vn != 0))
1701 return XFS_ERROR(EINVAL);
1703 mp->m_flags |= XFS_MOUNT_SHARED;
1706 * Shared XFS V0 can't deal with DMI. Return EINVAL.
1708 if (mp->m_sb.sb_shared_vn == 0 && (ap->flags & XFSMNT_DMAPI))
1709 return XFS_ERROR(EINVAL);
1712 if (ap->flags & XFSMNT_UQUOTA) {
1713 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
1714 if (ap->flags & XFSMNT_UQUOTAENF)
1715 mp->m_qflags |= XFS_UQUOTA_ENFD;
1718 if (ap->flags & XFSMNT_GQUOTA) {
1719 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
1720 if (ap->flags & XFSMNT_GQUOTAENF)
1721 mp->m_qflags |= XFS_OQUOTA_ENFD;
1722 } else if (ap->flags & XFSMNT_PQUOTA) {
1723 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
1724 if (ap->flags & XFSMNT_PQUOTAENF)
1725 mp->m_qflags |= XFS_OQUOTA_ENFD;
1733 struct super_block *sb,
1738 struct xfs_mount *mp = NULL;
1739 struct xfs_mount_args *args;
1740 int flags = 0, error = ENOMEM;
1742 args = xfs_args_allocate(sb, silent);
1746 mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
1750 spin_lock_init(&mp->m_sb_lock);
1751 mutex_init(&mp->m_ilock);
1752 mutex_init(&mp->m_growlock);
1753 atomic_set(&mp->m_active_trans, 0);
1754 INIT_LIST_HEAD(&mp->m_sync_list);
1755 spin_lock_init(&mp->m_sync_lock);
1756 init_waitqueue_head(&mp->m_wait_single_sync_task);
1761 if (sb->s_flags & MS_RDONLY)
1762 mp->m_flags |= XFS_MOUNT_RDONLY;
1764 error = xfs_parseargs(mp, (char *)data, args, 0);
1768 sb_min_blocksize(sb, BBSIZE);
1769 sb->s_export_op = &xfs_export_operations;
1770 sb->s_qcop = &xfs_quotactl_operations;
1771 sb->s_op = &xfs_super_operations;
1773 error = xfs_dmops_get(mp, args);
1776 error = xfs_qmops_get(mp, args);
1780 if (args->flags & XFSMNT_QUIET)
1781 flags |= XFS_MFSI_QUIET;
1783 error = xfs_open_devices(mp, args);
1787 if (xfs_icsb_init_counters(mp))
1788 mp->m_flags |= XFS_MOUNT_NO_PERCPU_SB;
1791 * Setup flags based on mount(2) options and then the superblock
1793 error = xfs_start_flags(args, mp);
1795 goto out_destroy_counters;
1796 error = xfs_readsb(mp, flags);
1798 goto out_destroy_counters;
1799 error = xfs_finish_flags(args, mp);
1803 error = xfs_setup_devices(mp);
1807 if (mp->m_flags & XFS_MOUNT_BARRIER)
1808 xfs_mountfs_check_barriers(mp);
1810 error = xfs_filestream_mount(mp);
1814 error = xfs_mountfs(mp, flags);
1816 goto out_filestream_unmount;
1818 XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, args->mtpt, args->fsname);
1821 sb->s_magic = XFS_SB_MAGIC;
1822 sb->s_blocksize = mp->m_sb.sb_blocksize;
1823 sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
1824 sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
1825 sb->s_time_gran = 1;
1826 set_posix_acl_flag(sb);
1828 root = igrab(mp->m_rootip->i_vnode);
1833 if (is_bad_inode(root)) {
1837 sb->s_root = d_alloc_root(root);
1843 mp->m_sync_work.w_syncer = xfs_sync_worker;
1844 mp->m_sync_work.w_mount = mp;
1845 mp->m_sync_task = kthread_run(xfssyncd, mp, "xfssyncd");
1846 if (IS_ERR(mp->m_sync_task)) {
1847 error = -PTR_ERR(mp->m_sync_task);
1851 xfs_itrace_exit(XFS_I(sb->s_root->d_inode));
1856 out_filestream_unmount:
1857 xfs_filestream_unmount(mp);
1860 out_destroy_counters:
1861 xfs_icsb_destroy_counters(mp);
1862 xfs_close_devices(mp);
1883 * Blow away any referenced inode in the filestreams cache.
1884 * This can and will cause log traffic as inodes go inactive
1887 xfs_filestream_unmount(mp);
1889 XFS_bflush(mp->m_ddev_targp);
1890 error = xfs_unmount_flush(mp, 0);
1893 IRELE(mp->m_rootip);
1896 goto out_destroy_counters;
1901 struct file_system_type *fs_type,
1903 const char *dev_name,
1905 struct vfsmount *mnt)
1907 return get_sb_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super,
1911 static struct super_operations xfs_super_operations = {
1912 .alloc_inode = xfs_fs_alloc_inode,
1913 .destroy_inode = xfs_fs_destroy_inode,
1914 .write_inode = xfs_fs_write_inode,
1915 .clear_inode = xfs_fs_clear_inode,
1916 .put_super = xfs_fs_put_super,
1917 .write_super = xfs_fs_write_super,
1918 .sync_fs = xfs_fs_sync_super,
1919 .write_super_lockfs = xfs_fs_lockfs,
1920 .statfs = xfs_fs_statfs,
1921 .remount_fs = xfs_fs_remount,
1922 .show_options = xfs_fs_show_options,
1925 static struct quotactl_ops xfs_quotactl_operations = {
1926 .quota_sync = xfs_fs_quotasync,
1927 .get_xstate = xfs_fs_getxstate,
1928 .set_xstate = xfs_fs_setxstate,
1929 .get_xquota = xfs_fs_getxquota,
1930 .set_xquota = xfs_fs_setxquota,
1933 static struct file_system_type xfs_fs_type = {
1934 .owner = THIS_MODULE,
1936 .get_sb = xfs_fs_get_sb,
1937 .kill_sb = kill_block_super,
1938 .fs_flags = FS_REQUIRES_DEV,
1946 static char message[] __initdata = KERN_INFO \
1947 XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled\n";
1953 error = xfs_init_zones();
1957 error = xfs_buf_init();
1966 error = register_filesystem(&xfs_fs_type);
1972 xfs_buf_terminate();
1975 xfs_destroy_zones();
1985 unregister_filesystem(&xfs_fs_type);
1987 xfs_buf_terminate();
1988 xfs_destroy_zones();
1992 module_init(init_xfs_fs);
1993 module_exit(exit_xfs_fs);
1995 MODULE_AUTHOR("Silicon Graphics, Inc.");
1996 MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
1997 MODULE_LICENSE("GPL");