2 * XFS filesystem operations.
4 * Copyright (c) 2000-2004 Silicon Graphics, Inc. All Rights Reserved.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of version 2 of the GNU General Public License as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it would be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * Further, this software is distributed without any warranty that it is
15 * free of the rightful claim of any third person regarding infringement
16 * or the like. Any license provided herein, whether implied or
17 * otherwise, applies only to this software file. Patent licenses, if
18 * any, provided herein do not apply to combinations of this program with
19 * other software, or any other product whatsoever.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write the Free Software Foundation, Inc., 59
23 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
25 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
26 * Mountain View, CA 94043, or:
30 * For further information regarding this notice, see:
32 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
36 #include "xfs_macros.h"
37 #include "xfs_types.h"
40 #include "xfs_trans.h"
44 #include "xfs_dmapi.h"
45 #include "xfs_mount.h"
46 #include "xfs_bmap_btree.h"
47 #include "xfs_ialloc_btree.h"
48 #include "xfs_alloc_btree.h"
49 #include "xfs_btree.h"
50 #include "xfs_alloc.h"
51 #include "xfs_ialloc.h"
52 #include "xfs_attr_sf.h"
53 #include "xfs_dir_sf.h"
54 #include "xfs_dir2_sf.h"
55 #include "xfs_dinode.h"
56 #include "xfs_inode_item.h"
57 #include "xfs_inode.h"
59 #include "xfs_error.h"
61 #include "xfs_da_btree.h"
63 #include "xfs_refcache.h"
64 #include "xfs_buf_item.h"
65 #include "xfs_extfree_item.h"
66 #include "xfs_quota.h"
67 #include "xfs_dir2_trace.h"
71 #include "xfs_log_priv.h"
73 STATIC int xfs_sync(bhv_desc_t *, int, cred_t *);
78 extern kmem_zone_t *xfs_bmap_free_item_zone;
79 extern kmem_zone_t *xfs_btree_cur_zone;
80 extern kmem_zone_t *xfs_trans_zone;
81 extern kmem_zone_t *xfs_buf_item_zone;
82 extern kmem_zone_t *xfs_dabuf_zone;
83 #ifdef XFS_DABUF_DEBUG
84 extern lock_t xfs_dabuf_global_lock;
85 spinlock_init(&xfs_dabuf_global_lock, "xfsda");
89 * Initialize all of the zone allocators we use.
91 xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
92 "xfs_bmap_free_item");
93 xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
95 xfs_inode_zone = kmem_zone_init(sizeof(xfs_inode_t), "xfs_inode");
96 xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
98 kmem_zone_init(sizeof(xfs_da_state_t), "xfs_da_state");
99 xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf");
102 * The size of the zone allocated buf log item is the maximum
103 * size possible under XFS. This wastes a little bit of memory,
104 * but it is much faster.
107 kmem_zone_init((sizeof(xfs_buf_log_item_t) +
108 (((XFS_MAX_BLOCKSIZE / XFS_BLI_CHUNK) /
109 NBWORD) * sizeof(int))),
111 xfs_efd_zone = kmem_zone_init((sizeof(xfs_efd_log_item_t) +
112 ((XFS_EFD_MAX_FAST_EXTENTS - 1) * sizeof(xfs_extent_t))),
114 xfs_efi_zone = kmem_zone_init((sizeof(xfs_efi_log_item_t) +
115 ((XFS_EFI_MAX_FAST_EXTENTS - 1) * sizeof(xfs_extent_t))),
117 xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
118 xfs_ili_zone = kmem_zone_init(sizeof(xfs_inode_log_item_t), "xfs_ili");
119 xfs_chashlist_zone = kmem_zone_init(sizeof(xfs_chashlist_t),
121 _ACL_ZONE_INIT(xfs_acl_zone, "xfs_acl");
124 * Allocate global trace buffers.
126 #ifdef XFS_ALLOC_TRACE
127 xfs_alloc_trace_buf = ktrace_alloc(XFS_ALLOC_TRACE_SIZE, KM_SLEEP);
129 #ifdef XFS_BMAP_TRACE
130 xfs_bmap_trace_buf = ktrace_alloc(XFS_BMAP_TRACE_SIZE, KM_SLEEP);
132 #ifdef XFS_BMBT_TRACE
133 xfs_bmbt_trace_buf = ktrace_alloc(XFS_BMBT_TRACE_SIZE, KM_SLEEP);
136 xfs_dir_trace_buf = ktrace_alloc(XFS_DIR_TRACE_SIZE, KM_SLEEP);
138 #ifdef XFS_ATTR_TRACE
139 xfs_attr_trace_buf = ktrace_alloc(XFS_ATTR_TRACE_SIZE, KM_SLEEP);
141 #ifdef XFS_DIR2_TRACE
142 xfs_dir2_trace_buf = ktrace_alloc(XFS_DIR2_GTRACE_SIZE, KM_SLEEP);
147 #if (defined(DEBUG) || defined(INDUCE_IO_ERROR))
148 xfs_error_test_init();
149 #endif /* DEBUG || INDUCE_IO_ERROR */
152 xfs_sysctl_register();
159 extern kmem_zone_t *xfs_bmap_free_item_zone;
160 extern kmem_zone_t *xfs_btree_cur_zone;
161 extern kmem_zone_t *xfs_inode_zone;
162 extern kmem_zone_t *xfs_trans_zone;
163 extern kmem_zone_t *xfs_da_state_zone;
164 extern kmem_zone_t *xfs_dabuf_zone;
165 extern kmem_zone_t *xfs_efd_zone;
166 extern kmem_zone_t *xfs_efi_zone;
167 extern kmem_zone_t *xfs_buf_item_zone;
168 extern kmem_zone_t *xfs_chashlist_zone;
170 xfs_cleanup_procfs();
171 xfs_sysctl_unregister();
172 xfs_refcache_destroy();
174 #ifdef XFS_DIR2_TRACE
175 ktrace_free(xfs_dir2_trace_buf);
177 #ifdef XFS_ATTR_TRACE
178 ktrace_free(xfs_attr_trace_buf);
181 ktrace_free(xfs_dir_trace_buf);
183 #ifdef XFS_BMBT_TRACE
184 ktrace_free(xfs_bmbt_trace_buf);
186 #ifdef XFS_BMAP_TRACE
187 ktrace_free(xfs_bmap_trace_buf);
189 #ifdef XFS_ALLOC_TRACE
190 ktrace_free(xfs_alloc_trace_buf);
193 kmem_cache_destroy(xfs_bmap_free_item_zone);
194 kmem_cache_destroy(xfs_btree_cur_zone);
195 kmem_cache_destroy(xfs_inode_zone);
196 kmem_cache_destroy(xfs_trans_zone);
197 kmem_cache_destroy(xfs_da_state_zone);
198 kmem_cache_destroy(xfs_dabuf_zone);
199 kmem_cache_destroy(xfs_buf_item_zone);
200 kmem_cache_destroy(xfs_efd_zone);
201 kmem_cache_destroy(xfs_efi_zone);
202 kmem_cache_destroy(xfs_ifork_zone);
203 kmem_cache_destroy(xfs_ili_zone);
204 kmem_cache_destroy(xfs_chashlist_zone);
205 _ACL_ZONE_DESTROY(xfs_acl_zone);
211 * This function fills in xfs_mount_t fields based on mount args.
212 * Note: the superblock has _not_ yet been read in.
217 struct xfs_mount_args *ap,
218 struct xfs_mount *mp)
220 /* Values are in BBs */
221 if ((ap->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
223 * At this point the superblock has not been read
224 * in, therefore we do not know the block size.
225 * Before the mount call ends we will convert
228 mp->m_dalign = ap->sunit;
229 mp->m_swidth = ap->swidth;
232 if (ap->logbufs != -1 &&
233 #if defined(DEBUG) || defined(XLOG_NOLOG)
236 (ap->logbufs < XLOG_MIN_ICLOGS ||
237 ap->logbufs > XLOG_MAX_ICLOGS)) {
239 "XFS: invalid logbufs value: %d [not %d-%d]",
240 ap->logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
241 return XFS_ERROR(EINVAL);
243 mp->m_logbufs = ap->logbufs;
244 if (ap->logbufsize != -1 &&
245 ap->logbufsize != 16 * 1024 &&
246 ap->logbufsize != 32 * 1024 &&
247 ap->logbufsize != 64 * 1024 &&
248 ap->logbufsize != 128 * 1024 &&
249 ap->logbufsize != 256 * 1024) {
251 "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
253 return XFS_ERROR(EINVAL);
255 mp->m_logbsize = ap->logbufsize;
256 mp->m_fsname_len = strlen(ap->fsname) + 1;
257 mp->m_fsname = kmem_alloc(mp->m_fsname_len, KM_SLEEP);
258 strcpy(mp->m_fsname, ap->fsname);
261 * Pull in the 'wsync' and 'ino64' mount options before we do the real
262 * work of mounting and recovery. The arg pointer will
263 * be NULL when we are being called from the root mount code.
265 if (ap->flags & XFSMNT_WSYNC)
266 mp->m_flags |= XFS_MOUNT_WSYNC;
268 if (ap->flags & XFSMNT_INO64) {
269 mp->m_flags |= XFS_MOUNT_INO64;
270 mp->m_inoadd = XFS_INO64_OFFSET;
273 if (ap->flags & XFSMNT_NOATIME)
274 mp->m_flags |= XFS_MOUNT_NOATIME;
276 if (ap->flags & XFSMNT_RETERR)
277 mp->m_flags |= XFS_MOUNT_RETERR;
279 if (ap->flags & XFSMNT_NOALIGN)
280 mp->m_flags |= XFS_MOUNT_NOALIGN;
282 if (ap->flags & XFSMNT_OSYNCISOSYNC)
283 mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
285 if (ap->flags & XFSMNT_32BITINODES)
286 mp->m_flags |= (XFS_MOUNT_32BITINODES | XFS_MOUNT_32BITINOOPT);
288 if (ap->flags & XFSMNT_IOSIZE) {
289 if (ap->iosizelog > XFS_MAX_IO_LOG ||
290 ap->iosizelog < XFS_MIN_IO_LOG) {
292 "XFS: invalid log iosize: %d [not %d-%d]",
293 ap->iosizelog, XFS_MIN_IO_LOG,
295 return XFS_ERROR(EINVAL);
298 mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
299 mp->m_readio_log = mp->m_writeio_log = ap->iosizelog;
301 if (ap->flags & XFSMNT_IDELETE)
302 mp->m_flags |= XFS_MOUNT_IDELETE;
305 * no recovery flag requires a read-only mount
307 if (ap->flags & XFSMNT_NORECOVERY) {
308 if (!(vfs->vfs_flag & VFS_RDONLY)) {
310 "XFS: tried to mount a FS read-write without recovery!");
311 return XFS_ERROR(EINVAL);
313 mp->m_flags |= XFS_MOUNT_NORECOVERY;
316 if (ap->flags & XFSMNT_NOUUID)
317 mp->m_flags |= XFS_MOUNT_NOUUID;
318 if (ap->flags & XFSMNT_NOLOGFLUSH)
319 mp->m_flags |= XFS_MOUNT_NOLOGFLUSH;
325 * This function fills in xfs_mount_t fields based on mount args.
326 * Note: the superblock _has_ now been read in.
331 struct xfs_mount_args *ap,
332 struct xfs_mount *mp)
334 int ronly = (vfs->vfs_flag & VFS_RDONLY);
336 /* Fail a mount where the logbuf is smaller then the log stripe */
337 if (XFS_SB_VERSION_HASLOGV2(&mp->m_sb)) {
338 if ((ap->logbufsize == -1) &&
339 (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) {
340 mp->m_logbsize = mp->m_sb.sb_logsunit;
341 } else if (ap->logbufsize < mp->m_sb.sb_logsunit) {
343 "XFS: logbuf size must be greater than or equal to log stripe size");
344 return XFS_ERROR(EINVAL);
347 /* Fail a mount if the logbuf is larger than 32K */
348 if (ap->logbufsize > XLOG_BIG_RECORD_BSIZE) {
350 "XFS: logbuf size for version 1 logs must be 16K or 32K");
351 return XFS_ERROR(EINVAL);
356 * prohibit r/w mounts of read-only filesystems
358 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
360 "XFS: cannot mount a read-only filesystem as read-write");
361 return XFS_ERROR(EROFS);
365 * disallow mount attempts with (IRIX) project quota enabled
367 if (XFS_SB_VERSION_HASQUOTA(&mp->m_sb) &&
368 (mp->m_sb.sb_qflags & XFS_PQUOTA_ACCT)) {
370 "XFS: cannot mount a filesystem with IRIX project quota enabled");
371 return XFS_ERROR(ENOSYS);
375 * check for shared mount.
377 if (ap->flags & XFSMNT_SHARED) {
378 if (!XFS_SB_VERSION_HASSHARED(&mp->m_sb))
379 return XFS_ERROR(EINVAL);
382 * For IRIX 6.5, shared mounts must have the shared
383 * version bit set, have the persistent readonly
384 * field set, must be version 0 and can only be mounted
387 if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) ||
388 (mp->m_sb.sb_shared_vn != 0))
389 return XFS_ERROR(EINVAL);
391 mp->m_flags |= XFS_MOUNT_SHARED;
394 * Shared XFS V0 can't deal with DMI. Return EINVAL.
396 if (mp->m_sb.sb_shared_vn == 0 && (ap->flags & XFSMNT_DMAPI))
397 return XFS_ERROR(EINVAL);
406 * The file system configurations are:
407 * (1) device (partition) with data and internal log
408 * (2) logical volume with data and log subvolumes.
409 * (3) logical volume with data, log, and realtime subvolumes.
411 * We only have to handle opening the log and realtime volumes here if
412 * they are present. The data subvolume has already been opened by
413 * get_sb_bdev() and is stored in vfsp->vfs_super->s_bdev.
417 struct bhv_desc *bhvp,
418 struct xfs_mount_args *args,
421 struct vfs *vfsp = bhvtovfs(bhvp);
423 struct xfs_mount *mp = XFS_BHVTOM(bhvp);
424 struct block_device *ddev, *logdev, *rtdev;
425 int flags = 0, error;
427 ddev = vfsp->vfs_super->s_bdev;
428 logdev = rtdev = NULL;
431 * Open real time and log devices - order is important.
433 if (args->logname[0]) {
434 error = xfs_blkdev_get(mp, args->logname, &logdev);
438 if (args->rtname[0]) {
439 error = xfs_blkdev_get(mp, args->rtname, &rtdev);
441 xfs_blkdev_put(logdev);
445 if (rtdev == ddev || rtdev == logdev) {
447 "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
448 xfs_blkdev_put(logdev);
449 xfs_blkdev_put(rtdev);
455 * Setup xfs_mount function vectors from available behaviors
457 p = vfs_bhv_lookup(vfsp, VFS_POSITION_DM);
458 mp->m_dm_ops = p ? *(xfs_dmops_t *) vfs_bhv_custom(p) : xfs_dmcore_stub;
459 p = vfs_bhv_lookup(vfsp, VFS_POSITION_QM);
460 mp->m_qm_ops = p ? *(xfs_qmops_t *) vfs_bhv_custom(p) : xfs_qmcore_stub;
461 p = vfs_bhv_lookup(vfsp, VFS_POSITION_IO);
462 mp->m_io_ops = p ? *(xfs_ioops_t *) vfs_bhv_custom(p) : xfs_iocore_xfs;
465 * Setup xfs_mount buffer target pointers
467 mp->m_ddev_targp = xfs_alloc_buftarg(ddev);
469 mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev);
470 mp->m_logdev_targp = (logdev && logdev != ddev) ?
471 xfs_alloc_buftarg(logdev) : mp->m_ddev_targp;
474 * Setup flags based on mount(2) options and then the superblock
476 error = xfs_start_flags(vfsp, args, mp);
479 error = xfs_readsb(mp);
482 error = xfs_finish_flags(vfsp, args, mp);
489 * Setup xfs_mount buffer target pointers based on superblock
491 xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
492 mp->m_sb.sb_sectsize);
493 if (logdev && logdev != ddev) {
494 unsigned int log_sector_size = BBSIZE;
496 if (XFS_SB_VERSION_HASSECTOR(&mp->m_sb))
497 log_sector_size = mp->m_sb.sb_logsectsize;
498 xfs_setsize_buftarg(mp->m_logdev_targp, mp->m_sb.sb_blocksize,
502 xfs_setsize_buftarg(mp->m_rtdev_targp, mp->m_sb.sb_blocksize,
503 mp->m_sb.sb_blocksize);
505 if (!(error = XFS_IOINIT(vfsp, args, flags)))
509 xfs_binval(mp->m_ddev_targp);
510 if (logdev != NULL && logdev != ddev) {
511 xfs_binval(mp->m_logdev_targp);
514 xfs_binval(mp->m_rtdev_targp);
516 xfs_unmountfs_close(mp, NULL);
526 struct vfs *vfsp = bhvtovfs(bdp);
527 xfs_mount_t *mp = XFS_BHVTOM(bdp);
530 int unmount_event_wanted = 0;
531 int unmount_event_flags = 0;
532 int xfs_unmountfs_needed = 0;
538 if (vfsp->vfs_flag & VFS_DMI) {
539 error = XFS_SEND_NAMESP(mp, DM_EVENT_PREUNMOUNT,
540 rvp, DM_RIGHT_NULL, rvp, DM_RIGHT_NULL,
542 (mp->m_dmevmask & (1<<DM_EVENT_PREUNMOUNT))?
543 0:DM_FLAGS_UNWANTED);
545 return XFS_ERROR(error);
546 unmount_event_wanted = 1;
547 unmount_event_flags = (mp->m_dmevmask & (1<<DM_EVENT_UNMOUNT))?
548 0 : DM_FLAGS_UNWANTED;
552 * First blow any referenced inode from this file system
553 * out of the reference cache, and delete the timer.
555 xfs_refcache_purge_mp(mp);
557 XFS_bflush(mp->m_ddev_targp);
558 error = xfs_unmount_flush(mp, 0);
562 ASSERT(vn_count(rvp) == 1);
565 * Drop the reference count
570 * If we're forcing a shutdown, typically because of a media error,
571 * we want to make sure we invalidate dirty pages that belong to
572 * referenced vnodes as well.
574 if (XFS_FORCED_SHUTDOWN(mp)) {
575 error = xfs_sync(&mp->m_bhv,
576 (SYNC_WAIT | SYNC_CLOSE), credp);
577 ASSERT(error != EFSCORRUPTED);
579 xfs_unmountfs_needed = 1;
582 /* Send DMAPI event, if required.
583 * Then do xfs_unmountfs() if needed.
584 * Then return error (or zero).
586 if (unmount_event_wanted) {
587 /* Note: mp structure must still exist for
588 * XFS_SEND_UNMOUNT() call.
590 XFS_SEND_UNMOUNT(mp, vfsp, error == 0 ? rvp : NULL,
591 DM_RIGHT_NULL, 0, error, unmount_event_flags);
593 if (xfs_unmountfs_needed) {
595 * Call common unmount function to flush to disk
596 * and free the super block buffer & mount structures.
598 xfs_unmountfs(mp, credp);
601 return XFS_ERROR(error);
604 #define REMOUNT_READONLY_FLAGS (SYNC_REMOUNT|SYNC_ATTR|SYNC_WAIT)
610 struct xfs_mount_args *args)
612 struct vfs *vfsp = bhvtovfs(bdp);
613 xfs_mount_t *mp = XFS_BHVTOM(bdp);
617 if (args->flags & XFSMNT_NOATIME)
618 mp->m_flags |= XFS_MOUNT_NOATIME;
620 mp->m_flags &= ~XFS_MOUNT_NOATIME;
622 if (!(vfsp->vfs_flag & VFS_RDONLY)) {
623 VFS_SYNC(vfsp, SYNC_FSDATA|SYNC_BDFLUSH|SYNC_ATTR, NULL, error);
626 if (*flags & MS_RDONLY) {
627 xfs_refcache_purge_mp(mp);
628 xfs_flush_buftarg(mp->m_ddev_targp, 0);
629 xfs_finish_reclaim_all(mp, 0);
631 /* This loop must run at least twice.
632 * The first instance of the loop will flush
633 * most meta data but that will generate more
634 * meta data (typically directory updates).
635 * Which then must be flushed and logged before
636 * we can write the unmount record.
639 VFS_SYNC(vfsp, REMOUNT_READONLY_FLAGS, NULL, error);
640 pincount = xfs_flush_buftarg(mp->m_ddev_targp, 1);
647 /* Ok now write out an unmount record */
648 xfs_log_unmount_write(mp);
649 xfs_unmountfs_writesb(mp);
650 vfsp->vfs_flag |= VFS_RDONLY;
652 vfsp->vfs_flag &= ~VFS_RDONLY;
659 * xfs_unmount_flush implements a set of flush operation on special
660 * inodes, which are needed as a separate set of operations so that
661 * they can be called as part of relocation process.
665 xfs_mount_t *mp, /* Mount structure we are getting
667 int relocation) /* Called from vfs relocation. */
669 xfs_inode_t *rip = mp->m_rootip;
671 xfs_inode_t *rsumip = NULL;
672 vnode_t *rvp = XFS_ITOV(rip);
675 xfs_ilock(rip, XFS_ILOCK_EXCL);
679 * Flush out the real time inodes.
681 if ((rbmip = mp->m_rbmip) != NULL) {
682 xfs_ilock(rbmip, XFS_ILOCK_EXCL);
684 error = xfs_iflush(rbmip, XFS_IFLUSH_SYNC);
685 xfs_iunlock(rbmip, XFS_ILOCK_EXCL);
687 if (error == EFSCORRUPTED)
690 ASSERT(vn_count(XFS_ITOV(rbmip)) == 1);
692 rsumip = mp->m_rsumip;
693 xfs_ilock(rsumip, XFS_ILOCK_EXCL);
695 error = xfs_iflush(rsumip, XFS_IFLUSH_SYNC);
696 xfs_iunlock(rsumip, XFS_ILOCK_EXCL);
698 if (error == EFSCORRUPTED)
701 ASSERT(vn_count(XFS_ITOV(rsumip)) == 1);
705 * Synchronously flush root inode to disk
707 error = xfs_iflush(rip, XFS_IFLUSH_SYNC);
708 if (error == EFSCORRUPTED)
711 if (vn_count(rvp) != 1 && !relocation) {
712 xfs_iunlock(rip, XFS_ILOCK_EXCL);
713 return XFS_ERROR(EBUSY);
717 * Release dquot that rootinode, rbmino and rsumino might be holding,
718 * flush and purge the quota inodes.
720 error = XFS_QM_UNMOUNT(mp);
721 if (error == EFSCORRUPTED)
725 VN_RELE(XFS_ITOV(rbmip));
726 VN_RELE(XFS_ITOV(rsumip));
729 xfs_iunlock(rip, XFS_ILOCK_EXCL);
736 xfs_iunlock(rip, XFS_ILOCK_EXCL);
738 return XFS_ERROR(EFSCORRUPTED);
742 * xfs_root extracts the root vnode from a vfs.
744 * vfsp -- the vfs struct for the desired file system
745 * vpp -- address of the caller's vnode pointer which should be
746 * set to the desired fs root vnode
755 vp = XFS_ITOV((XFS_BHVTOM(bdp))->m_rootip);
764 * Fill in the statvfs structure for the given file system. We use
765 * the superblock lock in the mount structure to ensure a consistent
766 * snapshot of the counters returned.
781 mp = XFS_BHVTOM(bdp);
784 statp->f_type = XFS_SB_MAGIC;
787 statp->f_bsize = sbp->sb_blocksize;
788 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
789 statp->f_blocks = sbp->sb_dblocks - lsize;
790 statp->f_bfree = statp->f_bavail = sbp->sb_fdblocks;
791 fakeinos = statp->f_bfree << sbp->sb_inopblog;
793 fakeinos += mp->m_inoadd;
796 MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
801 statp->f_files = min_t(typeof(statp->f_files),
804 statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
805 XFS_SB_UNLOCK(mp, s);
807 id = huge_encode_dev(mp->m_dev);
808 statp->f_fsid.val[0] = (u32)id;
809 statp->f_fsid.val[1] = (u32)(id >> 32);
810 statp->f_namelen = MAXNAMELEN - 1;
817 * xfs_sync flushes any pending I/O to file system vfsp.
819 * This routine is called by vfs_sync() to make sure that things make it
820 * out to disk eventually, on sync() system calls to flush out everything,
821 * and when the file system is unmounted. For the vfs_sync() case, all
822 * we really need to do is sync out the log to make all of our meta-data
823 * updates permanent (except for timestamps). For calls from pflushd(),
824 * dirty pages are kept moving by calling pdflush() on the inodes
825 * containing them. We also flush the inodes that we can lock without
826 * sleeping and the superblock if we can lock it without sleeping from
827 * vfs_sync() so that items at the tail of the log are always moving out.
830 * SYNC_BDFLUSH - We're being called from vfs_sync() so we don't want
831 * to sleep if we can help it. All we really need
832 * to do is ensure that the log is synced at least
833 * periodically. We also push the inodes and
834 * superblock if we can lock them without sleeping
835 * and they are not pinned.
836 * SYNC_ATTR - We need to flush the inodes. If SYNC_BDFLUSH is not
837 * set, then we really want to lock each inode and flush
839 * SYNC_WAIT - All the flushes that take place in this call should
841 * SYNC_DELWRI - This tells us to push dirty pages associated with
842 * inodes. SYNC_WAIT and SYNC_BDFLUSH are used to
843 * determine if they should be flushed sync, async, or
845 * SYNC_CLOSE - This flag is passed when the system is being
846 * unmounted. We should sync and invalidate everthing.
847 * SYNC_FSDATA - This indicates that the caller would like to make
848 * sure the superblock is safe on disk. We can ensure
849 * this by simply makeing sure the log gets flushed
850 * if SYNC_BDFLUSH is set, and by actually writing it
863 mp = XFS_BHVTOM(bdp);
864 return (xfs_syncsub(mp, flags, 0, NULL));
868 * xfs sync routine for internal use
870 * This routine supports all of the flags defined for the generic VFS_SYNC
871 * interface as explained above under xfs_sync. In the interests of not
872 * changing interfaces within the 6.5 family, additional internallly-
873 * required functions are specified within a separate xflags parameter,
874 * only available by calling this routine.
884 xfs_inode_t *ip = NULL;
885 xfs_inode_t *ip_next;
893 uint base_lock_flags;
894 boolean_t mount_locked;
895 boolean_t vnode_refed;
898 xfs_iptr_t *ipointer;
900 boolean_t ipointer_in = B_FALSE;
902 #define IPOINTER_SET ipointer_in = B_TRUE
903 #define IPOINTER_CLR ipointer_in = B_FALSE
910 /* Insert a marker record into the inode list after inode ip. The list
911 * must be locked when this is called. After the call the list will no
914 #define IPOINTER_INSERT(ip, mp) { \
915 ASSERT(ipointer_in == B_FALSE); \
916 ipointer->ip_mnext = ip->i_mnext; \
917 ipointer->ip_mprev = ip; \
918 ip->i_mnext = (xfs_inode_t *)ipointer; \
919 ipointer->ip_mnext->i_mprev = (xfs_inode_t *)ipointer; \
921 XFS_MOUNT_IUNLOCK(mp); \
922 mount_locked = B_FALSE; \
926 /* Remove the marker from the inode list. If the marker was the only item
927 * in the list then there are no remaining inodes and we should zero out
928 * the whole list. If we are the current head of the list then move the head
931 #define IPOINTER_REMOVE(ip, mp) { \
932 ASSERT(ipointer_in == B_TRUE); \
933 if (ipointer->ip_mnext != (xfs_inode_t *)ipointer) { \
934 ip = ipointer->ip_mnext; \
935 ip->i_mprev = ipointer->ip_mprev; \
936 ipointer->ip_mprev->i_mnext = ip; \
937 if (mp->m_inodes == (xfs_inode_t *)ipointer) { \
941 ASSERT(mp->m_inodes == (xfs_inode_t *)ipointer); \
942 mp->m_inodes = NULL; \
948 #define XFS_PREEMPT_MASK 0x7f
952 if (XFS_MTOVFS(mp)->vfs_flag & VFS_RDONLY)
958 /* Allocate a reference marker */
959 ipointer = (xfs_iptr_t *)kmem_zalloc(sizeof(xfs_iptr_t), KM_SLEEP);
961 fflag = XFS_B_ASYNC; /* default is don't wait */
962 if (flags & SYNC_BDFLUSH)
963 fflag = XFS_B_DELWRI;
964 if (flags & SYNC_WAIT)
965 fflag = 0; /* synchronous overrides all */
967 base_lock_flags = XFS_ILOCK_SHARED;
968 if (flags & (SYNC_DELWRI | SYNC_CLOSE)) {
970 * We need the I/O lock if we're going to call any of
971 * the flush/inval routines.
973 base_lock_flags |= XFS_IOLOCK_SHARED;
980 mount_locked = B_TRUE;
981 vnode_refed = B_FALSE;
986 ASSERT(ipointer_in == B_FALSE);
987 ASSERT(vnode_refed == B_FALSE);
989 lock_flags = base_lock_flags;
992 * There were no inodes in the list, just break out
1000 * We found another sync thread marker - skip it
1002 if (ip->i_mount == NULL) {
1007 vp = XFS_ITOV_NULL(ip);
1010 * If the vnode is gone then this is being torn down,
1011 * call reclaim if it is flushed, else let regular flush
1012 * code deal with it later in the loop.
1016 /* Skip ones already in reclaim */
1017 if (ip->i_flags & XFS_IRECLAIM) {
1021 if (xfs_ilock_nowait(ip, XFS_ILOCK_EXCL) == 0) {
1023 } else if ((xfs_ipincount(ip) == 0) &&
1024 xfs_iflock_nowait(ip)) {
1025 IPOINTER_INSERT(ip, mp);
1027 xfs_finish_reclaim(ip, 1,
1028 XFS_IFLUSH_DELWRI_ELSE_ASYNC);
1030 XFS_MOUNT_ILOCK(mp);
1031 mount_locked = B_TRUE;
1032 IPOINTER_REMOVE(ip, mp);
1034 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1040 if (XFS_FORCED_SHUTDOWN(mp) && !(flags & SYNC_CLOSE)) {
1041 XFS_MOUNT_IUNLOCK(mp);
1042 kmem_free(ipointer, sizeof(xfs_iptr_t));
1047 * If this is just vfs_sync() or pflushd() calling
1048 * then we can skip inodes for which it looks like
1049 * there is nothing to do. Since we don't have the
1050 * inode locked this is racey, but these are periodic
1051 * calls so it doesn't matter. For the others we want
1052 * to know for sure, so we at least try to lock them.
1054 if (flags & SYNC_BDFLUSH) {
1055 if (((ip->i_itemp == NULL) ||
1056 !(ip->i_itemp->ili_format.ilf_fields &
1058 (ip->i_update_core == 0)) {
1065 * Try to lock without sleeping. We're out of order with
1066 * the inode list lock here, so if we fail we need to drop
1067 * the mount lock and try again. If we're called from
1068 * bdflush() here, then don't bother.
1070 * The inode lock here actually coordinates with the
1071 * almost spurious inode lock in xfs_ireclaim() to prevent
1072 * the vnode we handle here without a reference from
1073 * being freed while we reference it. If we lock the inode
1074 * while it's on the mount list here, then the spurious inode
1075 * lock in xfs_ireclaim() after the inode is pulled from
1076 * the mount list will sleep until we release it here.
1077 * This keeps the vnode from being freed while we reference
1078 * it. It is also cheaper and simpler than actually doing
1079 * a vn_get() for every inode we touch here.
1081 if (xfs_ilock_nowait(ip, lock_flags) == 0) {
1083 if ((flags & SYNC_BDFLUSH) || (vp == NULL)) {
1089 * We need to unlock the inode list lock in order
1090 * to lock the inode. Insert a marker record into
1091 * the inode list to remember our position, dropping
1092 * the lock is now done inside the IPOINTER_INSERT
1095 * We also use the inode list lock to protect us
1096 * in taking a snapshot of the vnode version number
1097 * for use in calling vn_get().
1100 IPOINTER_INSERT(ip, mp);
1102 vp = vn_get(vp, &vmap);
1105 * The vnode was reclaimed once we let go
1106 * of the inode list lock. Skip to the
1107 * next list entry. Remove the marker.
1110 XFS_MOUNT_ILOCK(mp);
1112 mount_locked = B_TRUE;
1113 vnode_refed = B_FALSE;
1115 IPOINTER_REMOVE(ip, mp);
1120 xfs_ilock(ip, lock_flags);
1122 ASSERT(vp == XFS_ITOV(ip));
1123 ASSERT(ip->i_mount == mp);
1125 vnode_refed = B_TRUE;
1128 /* From here on in the loop we may have a marker record
1129 * in the inode list.
1132 if ((flags & SYNC_CLOSE) && (vp != NULL)) {
1134 * This is the shutdown case. We just need to
1135 * flush and invalidate all the pages associated
1136 * with the inode. Drop the inode lock since
1137 * we can't hold it across calls to the buffer
1140 * We don't set the VREMAPPING bit in the vnode
1141 * here, because we don't hold the vnode lock
1142 * exclusively. It doesn't really matter, though,
1143 * because we only come here when we're shutting
1146 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1148 if (XFS_FORCED_SHUTDOWN(mp)) {
1149 VOP_TOSS_PAGES(vp, 0, -1, FI_REMAPF);
1151 VOP_FLUSHINVAL_PAGES(vp, 0, -1, FI_REMAPF);
1154 xfs_ilock(ip, XFS_ILOCK_SHARED);
1156 } else if ((flags & SYNC_DELWRI) && (vp != NULL)) {
1158 /* We need to have dropped the lock here,
1159 * so insert a marker if we have not already
1163 IPOINTER_INSERT(ip, mp);
1167 * Drop the inode lock since we can't hold it
1168 * across calls to the buffer cache.
1170 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1171 VOP_FLUSH_PAGES(vp, (xfs_off_t)0, -1,
1172 fflag, FI_NONE, error);
1173 xfs_ilock(ip, XFS_ILOCK_SHARED);
1178 if (flags & SYNC_BDFLUSH) {
1179 if ((flags & SYNC_ATTR) &&
1180 ((ip->i_update_core) ||
1181 ((ip->i_itemp != NULL) &&
1182 (ip->i_itemp->ili_format.ilf_fields != 0)))) {
1184 /* Insert marker and drop lock if not already
1188 IPOINTER_INSERT(ip, mp);
1192 * We don't want the periodic flushing of the
1193 * inodes by vfs_sync() to interfere with
1194 * I/O to the file, especially read I/O
1195 * where it is only the access time stamp
1196 * that is being flushed out. To prevent
1197 * long periods where we have both inode
1198 * locks held shared here while reading the
1199 * inode's buffer in from disk, we drop the
1200 * inode lock while reading in the inode
1201 * buffer. We have to release the buffer
1202 * and reacquire the inode lock so that they
1203 * are acquired in the proper order (inode
1204 * locks first). The buffer will go at the
1205 * end of the lru chain, though, so we can
1206 * expect it to still be there when we go
1207 * for it again in xfs_iflush().
1209 if ((xfs_ipincount(ip) == 0) &&
1210 xfs_iflock_nowait(ip)) {
1213 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1215 error = xfs_itobp(mp, NULL, ip,
1220 /* Bailing out, remove the
1221 * marker and free it.
1223 XFS_MOUNT_ILOCK(mp);
1225 IPOINTER_REMOVE(ip, mp);
1227 XFS_MOUNT_IUNLOCK(mp);
1229 ASSERT(!(lock_flags &
1230 XFS_IOLOCK_SHARED));
1233 sizeof(xfs_iptr_t));
1238 * Since we dropped the inode lock,
1239 * the inode may have been reclaimed.
1240 * Therefore, we reacquire the mount
1241 * lock and check to see if we were the
1242 * inode reclaimed. If this happened
1243 * then the ipointer marker will no
1244 * longer point back at us. In this
1245 * case, move ip along to the inode
1246 * after the marker, remove the marker
1249 XFS_MOUNT_ILOCK(mp);
1250 mount_locked = B_TRUE;
1252 if (ip != ipointer->ip_mprev) {
1253 IPOINTER_REMOVE(ip, mp);
1255 ASSERT(!vnode_refed);
1256 ASSERT(!(lock_flags &
1257 XFS_IOLOCK_SHARED));
1261 ASSERT(ip->i_mount == mp);
1263 if (xfs_ilock_nowait(ip,
1264 XFS_ILOCK_SHARED) == 0) {
1265 ASSERT(ip->i_mount == mp);
1267 * We failed to reacquire
1268 * the inode lock without
1269 * sleeping, so just skip
1270 * the inode for now. We
1271 * clear the ILOCK bit from
1272 * the lock_flags so that we
1273 * won't try to drop a lock
1274 * we don't hold below.
1276 lock_flags &= ~XFS_ILOCK_SHARED;
1277 IPOINTER_REMOVE(ip_next, mp);
1278 } else if ((xfs_ipincount(ip) == 0) &&
1279 xfs_iflock_nowait(ip)) {
1280 ASSERT(ip->i_mount == mp);
1282 * Since this is vfs_sync()
1283 * calling we only flush the
1284 * inode out if we can lock
1285 * it without sleeping and
1286 * it is not pinned. Drop
1287 * the mount lock here so
1288 * that we don't hold it for
1289 * too long. We already have
1290 * a marker in the list here.
1292 XFS_MOUNT_IUNLOCK(mp);
1293 mount_locked = B_FALSE;
1294 error = xfs_iflush(ip,
1297 ASSERT(ip->i_mount == mp);
1298 IPOINTER_REMOVE(ip_next, mp);
1305 if ((flags & SYNC_ATTR) &&
1306 ((ip->i_update_core) ||
1307 ((ip->i_itemp != NULL) &&
1308 (ip->i_itemp->ili_format.ilf_fields != 0)))) {
1310 IPOINTER_INSERT(ip, mp);
1313 if (flags & SYNC_WAIT) {
1315 error = xfs_iflush(ip,
1319 * If we can't acquire the flush
1320 * lock, then the inode is already
1321 * being flushed so don't bother
1322 * waiting. If we can lock it then
1323 * do a delwri flush so we can
1324 * combine multiple inode flushes
1325 * in each disk write.
1327 if (xfs_iflock_nowait(ip)) {
1328 error = xfs_iflush(ip,
1337 if (lock_flags != 0) {
1338 xfs_iunlock(ip, lock_flags);
1343 * If we had to take a reference on the vnode
1344 * above, then wait until after we've unlocked
1345 * the inode to release the reference. This is
1346 * because we can be already holding the inode
1347 * lock when VN_RELE() calls xfs_inactive().
1349 * Make sure to drop the mount lock before calling
1350 * VN_RELE() so that we don't trip over ourselves if
1351 * we have to go for the mount lock again in the
1355 IPOINTER_INSERT(ip, mp);
1360 vnode_refed = B_FALSE;
1368 * bail out if the filesystem is corrupted.
1370 if (error == EFSCORRUPTED) {
1371 if (!mount_locked) {
1372 XFS_MOUNT_ILOCK(mp);
1373 IPOINTER_REMOVE(ip, mp);
1375 XFS_MOUNT_IUNLOCK(mp);
1376 ASSERT(ipointer_in == B_FALSE);
1377 kmem_free(ipointer, sizeof(xfs_iptr_t));
1378 return XFS_ERROR(error);
1381 /* Let other threads have a chance at the mount lock
1382 * if we have looped many times without dropping the
1385 if ((++preempt & XFS_PREEMPT_MASK) == 0) {
1387 IPOINTER_INSERT(ip, mp);
1391 if (mount_locked == B_FALSE) {
1392 XFS_MOUNT_ILOCK(mp);
1393 mount_locked = B_TRUE;
1394 IPOINTER_REMOVE(ip, mp);
1398 ASSERT(ipointer_in == B_FALSE);
1401 } while (ip != mp->m_inodes);
1403 XFS_MOUNT_IUNLOCK(mp);
1405 ASSERT(ipointer_in == B_FALSE);
1407 kmem_free(ipointer, sizeof(xfs_iptr_t));
1408 return XFS_ERROR(last_error);
1412 * xfs sync routine for internal use
1414 * This routine supports all of the flags defined for the generic VFS_SYNC
1415 * interface as explained above under xfs_sync. In the interests of not
1416 * changing interfaces within the 6.5 family, additional internallly-
1417 * required functions are specified within a separate xflags parameter,
1418 * only available by calling this routine.
1430 uint log_flags = XFS_LOG_FORCE;
1432 xfs_buf_log_item_t *bip;
1435 * Sync out the log. This ensures that the log is periodically
1436 * flushed even if there is not enough activity to fill it up.
1438 if (flags & SYNC_WAIT)
1439 log_flags |= XFS_LOG_SYNC;
1441 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1443 if (flags & (SYNC_ATTR|SYNC_DELWRI)) {
1444 if (flags & SYNC_BDFLUSH)
1445 xfs_finish_reclaim_all(mp, 1);
1447 error = xfs_sync_inodes(mp, flags, xflags, bypassed);
1451 * Flushing out dirty data above probably generated more
1452 * log activity, so if this isn't vfs_sync() then flush
1455 if (flags & SYNC_DELWRI) {
1456 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1459 if (flags & SYNC_FSDATA) {
1461 * If this is vfs_sync() then only sync the superblock
1462 * if we can lock it without sleeping and it is not pinned.
1464 if (flags & SYNC_BDFLUSH) {
1465 bp = xfs_getsb(mp, XFS_BUF_TRYLOCK);
1467 bip = XFS_BUF_FSPRIVATE(bp,xfs_buf_log_item_t*);
1468 if ((bip != NULL) &&
1469 xfs_buf_item_dirty(bip)) {
1470 if (!(XFS_BUF_ISPINNED(bp))) {
1472 error = xfs_bwrite(mp, bp);
1481 bp = xfs_getsb(mp, 0);
1483 * If the buffer is pinned then push on the log so
1484 * we won't get stuck waiting in the write for
1485 * someone, maybe ourselves, to flush the log.
1486 * Even though we just pushed the log above, we
1487 * did not have the superblock buffer locked at
1488 * that point so it can become pinned in between
1491 if (XFS_BUF_ISPINNED(bp))
1492 xfs_log_force(mp, (xfs_lsn_t)0, XFS_LOG_FORCE);
1493 if (flags & SYNC_WAIT)
1494 XFS_BUF_UNASYNC(bp);
1497 error = xfs_bwrite(mp, bp);
1505 * If this is the periodic sync, then kick some entries out of
1506 * the reference cache. This ensures that idle entries are
1507 * eventually kicked out of the cache.
1509 if (flags & SYNC_REFCACHE) {
1510 xfs_refcache_purge_some(mp);
1514 * Now check to see if the log needs a "dummy" transaction.
1517 if (!(flags & SYNC_REMOUNT) && xfs_log_need_covered(mp)) {
1522 * Put a dummy transaction in the log to tell
1523 * recovery that all others are OK.
1525 tp = xfs_trans_alloc(mp, XFS_TRANS_DUMMY1);
1526 if ((error = xfs_trans_reserve(tp, 0,
1527 XFS_ICHANGE_LOG_RES(mp),
1529 xfs_trans_cancel(tp, 0);
1534 xfs_ilock(ip, XFS_ILOCK_EXCL);
1536 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
1537 xfs_trans_ihold(tp, ip);
1538 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
1539 error = xfs_trans_commit(tp, 0, NULL);
1540 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1541 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1545 * When shutting down, we need to insure that the AIL is pushed
1546 * to disk or the filesystem can appear corrupt from the PROM.
1548 if ((flags & (SYNC_CLOSE|SYNC_WAIT)) == (SYNC_CLOSE|SYNC_WAIT)) {
1549 XFS_bflush(mp->m_ddev_targp);
1550 if (mp->m_rtdev_targp) {
1551 XFS_bflush(mp->m_rtdev_targp);
1555 return XFS_ERROR(last_error);
1559 * xfs_vget - called by DMAPI to get vnode from file handle
1574 xfid = (struct xfs_fid *)fidp;
1575 if (xfid->xfs_fid_len == sizeof(*xfid) - sizeof(xfid->xfs_fid_len)) {
1576 ino = xfid->xfs_fid_ino;
1577 igen = xfid->xfs_fid_gen;
1580 * Invalid. Since handles can be created in user space
1581 * and passed in via gethandle(), this is not cause for
1584 return XFS_ERROR(EINVAL);
1586 mp = XFS_BHVTOM(bdp);
1587 error = xfs_iget(mp, NULL, ino, XFS_ILOCK_SHARED, &ip, 0);
1594 return XFS_ERROR(EIO);
1597 if (ip->i_d.di_mode == 0 || (igen && (ip->i_d.di_gen != igen))) {
1598 xfs_iput_new(ip, XFS_ILOCK_SHARED);
1600 return XFS_ERROR(ENOENT);
1603 *vpp = XFS_ITOV(ip);
1604 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1609 #define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
1610 #define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
1611 #define MNTOPT_LOGDEV "logdev" /* log device */
1612 #define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
1613 #define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
1614 #define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
1615 #define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
1616 #define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
1617 #define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
1618 #define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
1619 #define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
1620 #define MNTOPT_MTPT "mtpt" /* filesystem mount point */
1621 #define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
1622 #define MNTOPT_NOLOGFLUSH "nologflush" /* don't hard flush on log writes */
1623 #define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
1624 #define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
1625 #define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
1626 #define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
1631 struct bhv_desc *bhv,
1633 struct xfs_mount_args *args,
1636 struct vfs *vfsp = bhvtovfs(bhv);
1637 char *this_char, *value, *eov;
1638 int dsunit, dswidth, vol_dsunit, vol_dswidth;
1641 #if 0 /* XXX: off by default, until some remaining issues ironed out */
1642 args->flags |= XFSMNT_IDELETE; /* default to on */
1648 iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0;
1650 while ((this_char = strsep(&options, ",")) != NULL) {
1653 if ((value = strchr(this_char, '=')) != NULL)
1656 if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
1657 if (!value || !*value) {
1658 printk("XFS: %s option requires an argument\n",
1662 args->logbufs = simple_strtoul(value, &eov, 10);
1663 } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
1664 int last, in_kilobytes = 0;
1666 if (!value || !*value) {
1667 printk("XFS: %s option requires an argument\n",
1671 last = strlen(value) - 1;
1672 if (value[last] == 'K' || value[last] == 'k') {
1676 args->logbufsize = simple_strtoul(value, &eov, 10);
1678 args->logbufsize <<= 10;
1679 } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
1680 if (!value || !*value) {
1681 printk("XFS: %s option requires an argument\n",
1685 strncpy(args->logname, value, MAXNAMELEN);
1686 } else if (!strcmp(this_char, MNTOPT_MTPT)) {
1687 if (!value || !*value) {
1688 printk("XFS: %s option requires an argument\n",
1692 strncpy(args->mtpt, value, MAXNAMELEN);
1693 } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
1694 if (!value || !*value) {
1695 printk("XFS: %s option requires an argument\n",
1699 strncpy(args->rtname, value, MAXNAMELEN);
1700 } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
1701 if (!value || !*value) {
1702 printk("XFS: %s option requires an argument\n",
1706 iosize = simple_strtoul(value, &eov, 10);
1707 args->flags |= XFSMNT_IOSIZE;
1708 args->iosizelog = (uint8_t) iosize;
1709 } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
1710 args->flags |= XFSMNT_WSYNC;
1711 } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
1712 args->flags |= XFSMNT_OSYNCISOSYNC;
1713 } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
1714 args->flags |= XFSMNT_NORECOVERY;
1715 } else if (!strcmp(this_char, MNTOPT_INO64)) {
1716 args->flags |= XFSMNT_INO64;
1718 printk("XFS: %s option not allowed on this system\n",
1722 } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
1723 args->flags |= XFSMNT_NOALIGN;
1724 } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
1725 if (!value || !*value) {
1726 printk("XFS: %s option requires an argument\n",
1730 dsunit = simple_strtoul(value, &eov, 10);
1731 } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
1732 if (!value || !*value) {
1733 printk("XFS: %s option requires an argument\n",
1737 dswidth = simple_strtoul(value, &eov, 10);
1738 } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
1739 args->flags &= ~XFSMNT_32BITINODES;
1741 printk("XFS: %s option not allowed on this system\n",
1745 } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
1746 args->flags |= XFSMNT_NOUUID;
1747 } else if (!strcmp(this_char, MNTOPT_NOLOGFLUSH)) {
1748 args->flags |= XFSMNT_NOLOGFLUSH;
1749 } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
1750 args->flags &= ~XFSMNT_IDELETE;
1751 } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
1752 args->flags |= XFSMNT_IDELETE;
1753 } else if (!strcmp(this_char, "osyncisdsync")) {
1754 /* no-op, this is now the default */
1755 printk("XFS: osyncisdsync is now the default, option is deprecated.\n");
1756 } else if (!strcmp(this_char, "irixsgid")) {
1757 printk("XFS: irixsgid is now a sysctl(2) variable, option is deprecated.\n");
1759 printk("XFS: unknown mount option [%s].\n", this_char);
1764 if (args->flags & XFSMNT_NORECOVERY) {
1765 if ((vfsp->vfs_flag & VFS_RDONLY) == 0) {
1766 printk("XFS: no-recovery mounts must be read-only.\n");
1771 if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) {
1773 "XFS: sunit and swidth options incompatible with the noalign option\n");
1777 if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
1778 printk("XFS: sunit and swidth must be specified together\n");
1782 if (dsunit && (dswidth % dsunit != 0)) {
1784 "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)\n",
1789 if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
1791 args->sunit = dsunit;
1792 args->flags |= XFSMNT_RETERR;
1794 args->sunit = vol_dsunit;
1796 dswidth ? (args->swidth = dswidth) :
1797 (args->swidth = vol_dswidth);
1799 args->sunit = args->swidth = 0;
1807 struct bhv_desc *bhv,
1810 static struct proc_xfs_info {
1814 /* the few simple ones we can get from the mount struct */
1815 { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
1816 { XFS_MOUNT_INO64, "," MNTOPT_INO64 },
1817 { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
1818 { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
1819 { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
1820 { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
1821 { XFS_MOUNT_NOLOGFLUSH, "," MNTOPT_NOLOGFLUSH },
1822 { XFS_MOUNT_IDELETE, "," MNTOPT_NOIKEEP },
1825 struct proc_xfs_info *xfs_infop;
1826 struct xfs_mount *mp = XFS_BHVTOM(bhv);
1828 for (xfs_infop = xfs_info; xfs_infop->flag; xfs_infop++) {
1829 if (mp->m_flags & xfs_infop->flag)
1830 seq_puts(m, xfs_infop->str);
1833 if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
1834 seq_printf(m, "," MNTOPT_BIOSIZE "=%d", mp->m_writeio_log);
1836 if (mp->m_logbufs > 0)
1837 seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
1839 if (mp->m_logbsize > 0)
1840 seq_printf(m, "," MNTOPT_LOGBSIZE "=%d", mp->m_logbsize);
1842 if (mp->m_ddev_targp != mp->m_logdev_targp)
1843 seq_printf(m, "," MNTOPT_LOGDEV "=%s",
1844 XFS_BUFTARG_NAME(mp->m_logdev_targp));
1846 if (mp->m_rtdev_targp && mp->m_ddev_targp != mp->m_rtdev_targp)
1847 seq_printf(m, "," MNTOPT_RTDEV "=%s",
1848 XFS_BUFTARG_NAME(mp->m_rtdev_targp));
1850 if (mp->m_dalign > 0)
1851 seq_printf(m, "," MNTOPT_SUNIT "=%d",
1852 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
1854 if (mp->m_swidth > 0)
1855 seq_printf(m, "," MNTOPT_SWIDTH "=%d",
1856 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
1858 if (!(mp->m_flags & XFS_MOUNT_32BITINOOPT))
1859 seq_printf(m, "," MNTOPT_64BITINODE);
1868 xfs_mount_t *mp = XFS_BHVTOM(bdp);
1870 while (atomic_read(&mp->m_active_trans) > 0)
1873 /* Push the superblock and write an unmount record */
1874 xfs_log_unmount_write(mp);
1875 xfs_unmountfs_writesb(mp);
1879 vfsops_t xfs_vfsops = {
1880 BHV_IDENTITY_INIT(VFS_BHV_XFS,VFS_POSITION_XFS),
1881 .vfs_parseargs = xfs_parseargs,
1882 .vfs_showargs = xfs_showargs,
1883 .vfs_mount = xfs_mount,
1884 .vfs_unmount = xfs_unmount,
1885 .vfs_mntupdate = xfs_mntupdate,
1886 .vfs_root = xfs_root,
1887 .vfs_statvfs = xfs_statvfs,
1888 .vfs_sync = xfs_sync,
1889 .vfs_vget = xfs_vget,
1890 .vfs_dmapiops = (vfs_dmapiops_t)fs_nosys,
1891 .vfs_quotactl = (vfs_quotactl_t)fs_nosys,
1892 .vfs_init_vnode = xfs_initialize_vnode,
1893 .vfs_force_shutdown = xfs_do_force_shutdown,
1894 .vfs_freeze = xfs_freeze,