2 * Copyright (c) 2000-2005 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
20 #include "xfs_types.h"
24 #include "xfs_trans.h"
28 #include "xfs_dmapi.h"
29 #include "xfs_mount.h"
30 #include "xfs_da_btree.h"
31 #include "xfs_bmap_btree.h"
32 #include "xfs_ialloc_btree.h"
33 #include "xfs_alloc_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_inode_item.h"
39 #include "xfs_btree.h"
40 #include "xfs_alloc.h"
41 #include "xfs_ialloc.h"
42 #include "xfs_quota.h"
43 #include "xfs_error.h"
46 #include "xfs_refcache.h"
47 #include "xfs_buf_item.h"
48 #include "xfs_log_priv.h"
49 #include "xfs_dir2_trace.h"
50 #include "xfs_extfree_item.h"
54 #include "xfs_fsops.h"
56 STATIC int xfs_sync(bhv_desc_t *, int, cred_t *);
61 extern kmem_zone_t *xfs_bmap_free_item_zone;
62 extern kmem_zone_t *xfs_btree_cur_zone;
63 extern kmem_zone_t *xfs_trans_zone;
64 extern kmem_zone_t *xfs_buf_item_zone;
65 extern kmem_zone_t *xfs_dabuf_zone;
66 #ifdef XFS_DABUF_DEBUG
67 extern lock_t xfs_dabuf_global_lock;
68 spinlock_init(&xfs_dabuf_global_lock, "xfsda");
72 * Initialize all of the zone allocators we use.
74 xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
75 "xfs_bmap_free_item");
76 xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
78 xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
80 kmem_zone_init(sizeof(xfs_da_state_t), "xfs_da_state");
81 xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf");
82 xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
83 xfs_acl_zone_init(xfs_acl_zone, "xfs_acl");
86 * The size of the zone allocated buf log item is the maximum
87 * size possible under XFS. This wastes a little bit of memory,
88 * but it is much faster.
91 kmem_zone_init((sizeof(xfs_buf_log_item_t) +
92 (((XFS_MAX_BLOCKSIZE / XFS_BLI_CHUNK) /
93 NBWORD) * sizeof(int))),
96 kmem_zone_init((sizeof(xfs_efd_log_item_t) +
97 ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
98 sizeof(xfs_extent_t))),
101 kmem_zone_init((sizeof(xfs_efi_log_item_t) +
102 ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
103 sizeof(xfs_extent_t))),
107 * These zones warrant special memory allocator hints
110 kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
111 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM |
112 KM_ZONE_SPREAD, NULL);
114 kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
115 KM_ZONE_SPREAD, NULL);
117 kmem_zone_init_flags(sizeof(xfs_chashlist_t), "xfs_chashlist",
118 KM_ZONE_SPREAD, NULL);
121 * Allocate global trace buffers.
123 #ifdef XFS_ALLOC_TRACE
124 xfs_alloc_trace_buf = ktrace_alloc(XFS_ALLOC_TRACE_SIZE, KM_SLEEP);
126 #ifdef XFS_BMAP_TRACE
127 xfs_bmap_trace_buf = ktrace_alloc(XFS_BMAP_TRACE_SIZE, KM_SLEEP);
129 #ifdef XFS_BMBT_TRACE
130 xfs_bmbt_trace_buf = ktrace_alloc(XFS_BMBT_TRACE_SIZE, KM_SLEEP);
132 #ifdef XFS_ATTR_TRACE
133 xfs_attr_trace_buf = ktrace_alloc(XFS_ATTR_TRACE_SIZE, KM_SLEEP);
135 #ifdef XFS_DIR2_TRACE
136 xfs_dir2_trace_buf = ktrace_alloc(XFS_DIR2_GTRACE_SIZE, KM_SLEEP);
141 #if (defined(DEBUG) || defined(INDUCE_IO_ERROR))
142 xfs_error_test_init();
143 #endif /* DEBUG || INDUCE_IO_ERROR */
146 xfs_sysctl_register();
153 extern kmem_zone_t *xfs_bmap_free_item_zone;
154 extern kmem_zone_t *xfs_btree_cur_zone;
155 extern kmem_zone_t *xfs_inode_zone;
156 extern kmem_zone_t *xfs_trans_zone;
157 extern kmem_zone_t *xfs_da_state_zone;
158 extern kmem_zone_t *xfs_dabuf_zone;
159 extern kmem_zone_t *xfs_efd_zone;
160 extern kmem_zone_t *xfs_efi_zone;
161 extern kmem_zone_t *xfs_buf_item_zone;
162 extern kmem_zone_t *xfs_chashlist_zone;
164 xfs_cleanup_procfs();
165 xfs_sysctl_unregister();
166 xfs_refcache_destroy();
167 xfs_acl_zone_destroy(xfs_acl_zone);
169 #ifdef XFS_DIR2_TRACE
170 ktrace_free(xfs_dir2_trace_buf);
172 #ifdef XFS_ATTR_TRACE
173 ktrace_free(xfs_attr_trace_buf);
175 #ifdef XFS_BMBT_TRACE
176 ktrace_free(xfs_bmbt_trace_buf);
178 #ifdef XFS_BMAP_TRACE
179 ktrace_free(xfs_bmap_trace_buf);
181 #ifdef XFS_ALLOC_TRACE
182 ktrace_free(xfs_alloc_trace_buf);
185 kmem_zone_destroy(xfs_bmap_free_item_zone);
186 kmem_zone_destroy(xfs_btree_cur_zone);
187 kmem_zone_destroy(xfs_inode_zone);
188 kmem_zone_destroy(xfs_trans_zone);
189 kmem_zone_destroy(xfs_da_state_zone);
190 kmem_zone_destroy(xfs_dabuf_zone);
191 kmem_zone_destroy(xfs_buf_item_zone);
192 kmem_zone_destroy(xfs_efd_zone);
193 kmem_zone_destroy(xfs_efi_zone);
194 kmem_zone_destroy(xfs_ifork_zone);
195 kmem_zone_destroy(xfs_ili_zone);
196 kmem_zone_destroy(xfs_chashlist_zone);
202 * This function fills in xfs_mount_t fields based on mount args.
203 * Note: the superblock has _not_ yet been read in.
208 struct xfs_mount_args *ap,
209 struct xfs_mount *mp)
211 /* Values are in BBs */
212 if ((ap->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
214 * At this point the superblock has not been read
215 * in, therefore we do not know the block size.
216 * Before the mount call ends we will convert
219 mp->m_dalign = ap->sunit;
220 mp->m_swidth = ap->swidth;
223 if (ap->logbufs != -1 &&
225 (ap->logbufs < XLOG_MIN_ICLOGS ||
226 ap->logbufs > XLOG_MAX_ICLOGS)) {
228 "XFS: invalid logbufs value: %d [not %d-%d]",
229 ap->logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
230 return XFS_ERROR(EINVAL);
232 mp->m_logbufs = ap->logbufs;
233 if (ap->logbufsize != -1 &&
234 ap->logbufsize != 0 &&
235 ap->logbufsize != 16 * 1024 &&
236 ap->logbufsize != 32 * 1024 &&
237 ap->logbufsize != 64 * 1024 &&
238 ap->logbufsize != 128 * 1024 &&
239 ap->logbufsize != 256 * 1024) {
241 "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
243 return XFS_ERROR(EINVAL);
245 mp->m_ihsize = ap->ihashsize;
246 mp->m_logbsize = ap->logbufsize;
247 mp->m_fsname_len = strlen(ap->fsname) + 1;
248 mp->m_fsname = kmem_alloc(mp->m_fsname_len, KM_SLEEP);
249 strcpy(mp->m_fsname, ap->fsname);
251 mp->m_rtname = kmem_alloc(strlen(ap->rtname) + 1, KM_SLEEP);
252 strcpy(mp->m_rtname, ap->rtname);
254 if (ap->logname[0]) {
255 mp->m_logname = kmem_alloc(strlen(ap->logname) + 1, KM_SLEEP);
256 strcpy(mp->m_logname, ap->logname);
259 if (ap->flags & XFSMNT_WSYNC)
260 mp->m_flags |= XFS_MOUNT_WSYNC;
262 if (ap->flags & XFSMNT_INO64) {
263 mp->m_flags |= XFS_MOUNT_INO64;
264 mp->m_inoadd = XFS_INO64_OFFSET;
267 if (ap->flags & XFSMNT_RETERR)
268 mp->m_flags |= XFS_MOUNT_RETERR;
269 if (ap->flags & XFSMNT_NOALIGN)
270 mp->m_flags |= XFS_MOUNT_NOALIGN;
271 if (ap->flags & XFSMNT_SWALLOC)
272 mp->m_flags |= XFS_MOUNT_SWALLOC;
273 if (ap->flags & XFSMNT_OSYNCISOSYNC)
274 mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
275 if (ap->flags & XFSMNT_32BITINODES)
276 mp->m_flags |= XFS_MOUNT_32BITINODES;
278 if (ap->flags & XFSMNT_IOSIZE) {
279 if (ap->iosizelog > XFS_MAX_IO_LOG ||
280 ap->iosizelog < XFS_MIN_IO_LOG) {
282 "XFS: invalid log iosize: %d [not %d-%d]",
283 ap->iosizelog, XFS_MIN_IO_LOG,
285 return XFS_ERROR(EINVAL);
288 mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
289 mp->m_readio_log = mp->m_writeio_log = ap->iosizelog;
292 if (ap->flags & XFSMNT_IHASHSIZE)
293 mp->m_flags |= XFS_MOUNT_IHASHSIZE;
294 if (ap->flags & XFSMNT_IDELETE)
295 mp->m_flags |= XFS_MOUNT_IDELETE;
296 if (ap->flags & XFSMNT_DIRSYNC)
297 mp->m_flags |= XFS_MOUNT_DIRSYNC;
298 if (ap->flags & XFSMNT_ATTR2)
299 mp->m_flags |= XFS_MOUNT_ATTR2;
301 if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
302 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
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_BARRIER)
319 mp->m_flags |= XFS_MOUNT_BARRIER;
321 mp->m_flags &= ~XFS_MOUNT_BARRIER;
327 * This function fills in xfs_mount_t fields based on mount args.
328 * Note: the superblock _has_ now been read in.
333 struct xfs_mount_args *ap,
334 struct xfs_mount *mp)
336 int ronly = (vfs->vfs_flag & VFS_RDONLY);
338 /* Fail a mount where the logbuf is smaller then the log stripe */
339 if (XFS_SB_VERSION_HASLOGV2(&mp->m_sb)) {
340 if ((ap->logbufsize <= 0) &&
341 (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) {
342 mp->m_logbsize = mp->m_sb.sb_logsunit;
343 } else if (ap->logbufsize > 0 &&
344 ap->logbufsize < mp->m_sb.sb_logsunit) {
346 "XFS: logbuf size must be greater than or equal to log stripe size");
347 return XFS_ERROR(EINVAL);
350 /* Fail a mount if the logbuf is larger than 32K */
351 if (ap->logbufsize > XLOG_BIG_RECORD_BSIZE) {
353 "XFS: logbuf size for version 1 logs must be 16K or 32K");
354 return XFS_ERROR(EINVAL);
358 if (XFS_SB_VERSION_HASATTR2(&mp->m_sb)) {
359 mp->m_flags |= XFS_MOUNT_ATTR2;
363 * prohibit r/w mounts of read-only filesystems
365 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
367 "XFS: cannot mount a read-only filesystem as read-write");
368 return XFS_ERROR(EROFS);
372 * check for shared mount.
374 if (ap->flags & XFSMNT_SHARED) {
375 if (!XFS_SB_VERSION_HASSHARED(&mp->m_sb))
376 return XFS_ERROR(EINVAL);
379 * For IRIX 6.5, shared mounts must have the shared
380 * version bit set, have the persistent readonly
381 * field set, must be version 0 and can only be mounted
384 if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) ||
385 (mp->m_sb.sb_shared_vn != 0))
386 return XFS_ERROR(EINVAL);
388 mp->m_flags |= XFS_MOUNT_SHARED;
391 * Shared XFS V0 can't deal with DMI. Return EINVAL.
393 if (mp->m_sb.sb_shared_vn == 0 && (ap->flags & XFSMNT_DMAPI))
394 return XFS_ERROR(EINVAL);
403 * The file system configurations are:
404 * (1) device (partition) with data and internal log
405 * (2) logical volume with data and log subvolumes.
406 * (3) logical volume with data, log, and realtime subvolumes.
408 * We only have to handle opening the log and realtime volumes here if
409 * they are present. The data subvolume has already been opened by
410 * get_sb_bdev() and is stored in vfsp->vfs_super->s_bdev.
414 struct bhv_desc *bhvp,
415 struct xfs_mount_args *args,
418 struct bhv_vfs *vfsp = bhvtovfs(bhvp);
420 struct xfs_mount *mp = XFS_BHVTOM(bhvp);
421 struct block_device *ddev, *logdev, *rtdev;
422 int flags = 0, error;
424 ddev = vfsp->vfs_super->s_bdev;
425 logdev = rtdev = NULL;
428 * Setup xfs_mount function vectors from available behaviors
430 p = vfs_bhv_lookup(vfsp, VFS_POSITION_DM);
431 mp->m_dm_ops = p ? *(xfs_dmops_t *) vfs_bhv_custom(p) : xfs_dmcore_stub;
432 p = vfs_bhv_lookup(vfsp, VFS_POSITION_QM);
433 mp->m_qm_ops = p ? *(xfs_qmops_t *) vfs_bhv_custom(p) : xfs_qmcore_stub;
434 p = vfs_bhv_lookup(vfsp, VFS_POSITION_IO);
435 mp->m_io_ops = p ? *(xfs_ioops_t *) vfs_bhv_custom(p) : xfs_iocore_xfs;
437 if (args->flags & XFSMNT_QUIET)
438 flags |= XFS_MFSI_QUIET;
441 * Open real time and log devices - order is important.
443 if (args->logname[0]) {
444 error = xfs_blkdev_get(mp, args->logname, &logdev);
448 if (args->rtname[0]) {
449 error = xfs_blkdev_get(mp, args->rtname, &rtdev);
451 xfs_blkdev_put(logdev);
455 if (rtdev == ddev || rtdev == logdev) {
457 "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
458 xfs_blkdev_put(logdev);
459 xfs_blkdev_put(rtdev);
465 * Setup xfs_mount buffer target pointers
468 mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
469 if (!mp->m_ddev_targp) {
470 xfs_blkdev_put(logdev);
471 xfs_blkdev_put(rtdev);
475 mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
476 if (!mp->m_rtdev_targp)
479 mp->m_logdev_targp = (logdev && logdev != ddev) ?
480 xfs_alloc_buftarg(logdev, 1) : mp->m_ddev_targp;
481 if (!mp->m_logdev_targp)
485 * Setup flags based on mount(2) options and then the superblock
487 error = xfs_start_flags(vfsp, args, mp);
490 error = xfs_readsb(mp, flags);
493 error = xfs_finish_flags(vfsp, args, mp);
498 * Setup xfs_mount buffer target pointers based on superblock
500 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
501 mp->m_sb.sb_sectsize);
502 if (!error && logdev && logdev != ddev) {
503 unsigned int log_sector_size = BBSIZE;
505 if (XFS_SB_VERSION_HASSECTOR(&mp->m_sb))
506 log_sector_size = mp->m_sb.sb_logsectsize;
507 error = xfs_setsize_buftarg(mp->m_logdev_targp,
508 mp->m_sb.sb_blocksize,
512 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
513 mp->m_sb.sb_blocksize,
514 mp->m_sb.sb_sectsize);
518 if (mp->m_flags & XFS_MOUNT_BARRIER)
519 xfs_mountfs_check_barriers(mp);
521 error = XFS_IOINIT(vfsp, args, flags);
531 xfs_binval(mp->m_ddev_targp);
532 if (logdev && logdev != ddev)
533 xfs_binval(mp->m_logdev_targp);
535 xfs_binval(mp->m_rtdev_targp);
537 xfs_unmountfs_close(mp, credp);
547 bhv_vfs_t *vfsp = bhvtovfs(bdp);
548 xfs_mount_t *mp = XFS_BHVTOM(bdp);
551 int unmount_event_wanted = 0;
552 int unmount_event_flags = 0;
553 int xfs_unmountfs_needed = 0;
559 if (vfsp->vfs_flag & VFS_DMI) {
560 error = XFS_SEND_PREUNMOUNT(mp, vfsp,
561 rvp, DM_RIGHT_NULL, rvp, DM_RIGHT_NULL,
563 (mp->m_dmevmask & (1<<DM_EVENT_PREUNMOUNT))?
564 0:DM_FLAGS_UNWANTED);
566 return XFS_ERROR(error);
567 unmount_event_wanted = 1;
568 unmount_event_flags = (mp->m_dmevmask & (1<<DM_EVENT_UNMOUNT))?
569 0 : DM_FLAGS_UNWANTED;
573 * First blow any referenced inode from this file system
574 * out of the reference cache, and delete the timer.
576 xfs_refcache_purge_mp(mp);
578 XFS_bflush(mp->m_ddev_targp);
579 error = xfs_unmount_flush(mp, 0);
583 ASSERT(vn_count(rvp) == 1);
586 * Drop the reference count
591 * If we're forcing a shutdown, typically because of a media error,
592 * we want to make sure we invalidate dirty pages that belong to
593 * referenced vnodes as well.
595 if (XFS_FORCED_SHUTDOWN(mp)) {
596 error = xfs_sync(&mp->m_bhv,
597 (SYNC_WAIT | SYNC_CLOSE), credp);
598 ASSERT(error != EFSCORRUPTED);
600 xfs_unmountfs_needed = 1;
603 /* Send DMAPI event, if required.
604 * Then do xfs_unmountfs() if needed.
605 * Then return error (or zero).
607 if (unmount_event_wanted) {
608 /* Note: mp structure must still exist for
609 * XFS_SEND_UNMOUNT() call.
611 XFS_SEND_UNMOUNT(mp, vfsp, error == 0 ? rvp : NULL,
612 DM_RIGHT_NULL, 0, error, unmount_event_flags);
614 if (xfs_unmountfs_needed) {
616 * Call common unmount function to flush to disk
617 * and free the super block buffer & mount structures.
619 xfs_unmountfs(mp, credp);
622 return XFS_ERROR(error);
629 int count = 0, pincount;
631 xfs_refcache_purge_mp(mp);
632 xfs_flush_buftarg(mp->m_ddev_targp, 0);
633 xfs_finish_reclaim_all(mp, 0);
635 /* This loop must run at least twice.
636 * The first instance of the loop will flush
637 * most meta data but that will generate more
638 * meta data (typically directory updates).
639 * Which then must be flushed and logged before
640 * we can write the unmount record.
643 xfs_syncsub(mp, SYNC_REMOUNT|SYNC_ATTR|SYNC_WAIT, NULL);
644 pincount = xfs_flush_buftarg(mp->m_ddev_targp, 1);
658 struct xfs_mount_args *args)
660 bhv_vfs_t *vfsp = bhvtovfs(bdp);
661 xfs_mount_t *mp = XFS_BHVTOM(bdp);
663 if (!(*flags & MS_RDONLY)) { /* rw/ro -> rw */
664 if (vfsp->vfs_flag & VFS_RDONLY)
665 vfsp->vfs_flag &= ~VFS_RDONLY;
666 if (args->flags & XFSMNT_BARRIER) {
667 mp->m_flags |= XFS_MOUNT_BARRIER;
668 xfs_mountfs_check_barriers(mp);
670 mp->m_flags &= ~XFS_MOUNT_BARRIER;
672 } else if (!(vfsp->vfs_flag & VFS_RDONLY)) { /* rw -> ro */
673 bhv_vfs_sync(vfsp, SYNC_FSDATA|SYNC_BDFLUSH|SYNC_ATTR, NULL);
675 xfs_log_sbcount(mp, 1);
676 xfs_log_unmount_write(mp);
677 xfs_unmountfs_writesb(mp);
678 vfsp->vfs_flag |= VFS_RDONLY;
684 * xfs_unmount_flush implements a set of flush operation on special
685 * inodes, which are needed as a separate set of operations so that
686 * they can be called as part of relocation process.
690 xfs_mount_t *mp, /* Mount structure we are getting
692 int relocation) /* Called from vfs relocation. */
694 xfs_inode_t *rip = mp->m_rootip;
696 xfs_inode_t *rsumip = NULL;
697 bhv_vnode_t *rvp = XFS_ITOV(rip);
700 xfs_ilock(rip, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT);
704 * Flush out the real time inodes.
706 if ((rbmip = mp->m_rbmip) != NULL) {
707 xfs_ilock(rbmip, XFS_ILOCK_EXCL);
709 error = xfs_iflush(rbmip, XFS_IFLUSH_SYNC);
710 xfs_iunlock(rbmip, XFS_ILOCK_EXCL);
712 if (error == EFSCORRUPTED)
715 ASSERT(vn_count(XFS_ITOV(rbmip)) == 1);
717 rsumip = mp->m_rsumip;
718 xfs_ilock(rsumip, XFS_ILOCK_EXCL);
720 error = xfs_iflush(rsumip, XFS_IFLUSH_SYNC);
721 xfs_iunlock(rsumip, XFS_ILOCK_EXCL);
723 if (error == EFSCORRUPTED)
726 ASSERT(vn_count(XFS_ITOV(rsumip)) == 1);
730 * Synchronously flush root inode to disk
732 error = xfs_iflush(rip, XFS_IFLUSH_SYNC);
733 if (error == EFSCORRUPTED)
736 if (vn_count(rvp) != 1 && !relocation) {
737 xfs_iunlock(rip, XFS_ILOCK_EXCL);
738 return XFS_ERROR(EBUSY);
742 * Release dquot that rootinode, rbmino and rsumino might be holding,
743 * flush and purge the quota inodes.
745 error = XFS_QM_UNMOUNT(mp);
746 if (error == EFSCORRUPTED)
750 VN_RELE(XFS_ITOV(rbmip));
751 VN_RELE(XFS_ITOV(rsumip));
754 xfs_iunlock(rip, XFS_ILOCK_EXCL);
761 xfs_iunlock(rip, XFS_ILOCK_EXCL);
763 return XFS_ERROR(EFSCORRUPTED);
767 * xfs_root extracts the root vnode from a vfs.
769 * vfsp -- the vfs struct for the desired file system
770 * vpp -- address of the caller's vnode pointer which should be
771 * set to the desired fs root vnode
780 vp = XFS_ITOV((XFS_BHVTOM(bdp))->m_rootip);
789 * Fill in the statvfs structure for the given file system. We use
790 * the superblock lock in the mount structure to ensure a consistent
791 * snapshot of the counters returned.
796 bhv_statvfs_t *statp,
805 mp = XFS_BHVTOM(bdp);
808 statp->f_type = XFS_SB_MAGIC;
810 xfs_icsb_sync_counters_flags(mp, XFS_ICSB_LAZY_COUNT);
812 statp->f_bsize = sbp->sb_blocksize;
813 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
814 statp->f_blocks = sbp->sb_dblocks - lsize;
815 statp->f_bfree = statp->f_bavail =
816 sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
817 fakeinos = statp->f_bfree << sbp->sb_inopblog;
819 fakeinos += mp->m_inoadd;
822 MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
827 statp->f_files = min_t(typeof(statp->f_files),
830 statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
831 XFS_SB_UNLOCK(mp, s);
833 xfs_statvfs_fsid(statp, mp);
834 statp->f_namelen = MAXNAMELEN - 1;
841 * xfs_sync flushes any pending I/O to file system vfsp.
843 * This routine is called by vfs_sync() to make sure that things make it
844 * out to disk eventually, on sync() system calls to flush out everything,
845 * and when the file system is unmounted. For the vfs_sync() case, all
846 * we really need to do is sync out the log to make all of our meta-data
847 * updates permanent (except for timestamps). For calls from pflushd(),
848 * dirty pages are kept moving by calling pdflush() on the inodes
849 * containing them. We also flush the inodes that we can lock without
850 * sleeping and the superblock if we can lock it without sleeping from
851 * vfs_sync() so that items at the tail of the log are always moving out.
854 * SYNC_BDFLUSH - We're being called from vfs_sync() so we don't want
855 * to sleep if we can help it. All we really need
856 * to do is ensure that the log is synced at least
857 * periodically. We also push the inodes and
858 * superblock if we can lock them without sleeping
859 * and they are not pinned.
860 * SYNC_ATTR - We need to flush the inodes. If SYNC_BDFLUSH is not
861 * set, then we really want to lock each inode and flush
863 * SYNC_WAIT - All the flushes that take place in this call should
865 * SYNC_DELWRI - This tells us to push dirty pages associated with
866 * inodes. SYNC_WAIT and SYNC_BDFLUSH are used to
867 * determine if they should be flushed sync, async, or
869 * SYNC_CLOSE - This flag is passed when the system is being
870 * unmounted. We should sync and invalidate everything.
871 * SYNC_FSDATA - This indicates that the caller would like to make
872 * sure the superblock is safe on disk. We can ensure
873 * this by simply making sure the log gets flushed
874 * if SYNC_BDFLUSH is set, and by actually writing it
876 * SYNC_IOWAIT - The caller wants us to wait for all data I/O to complete
877 * before we return (including direct I/O). Forms the drain
878 * side of the write barrier needed to safely quiesce the
889 xfs_mount_t *mp = XFS_BHVTOM(bdp);
891 return xfs_syncsub(mp, flags, NULL);
895 * xfs sync routine for internal use
897 * This routine supports all of the flags defined for the generic vfs_sync
898 * interface as explained above under xfs_sync.
907 xfs_inode_t *ip = NULL;
908 xfs_inode_t *ip_next;
910 bhv_vnode_t *vp = NULL;
915 uint base_lock_flags;
916 boolean_t mount_locked;
917 boolean_t vnode_refed;
920 xfs_iptr_t *ipointer;
922 boolean_t ipointer_in = B_FALSE;
924 #define IPOINTER_SET ipointer_in = B_TRUE
925 #define IPOINTER_CLR ipointer_in = B_FALSE
932 /* Insert a marker record into the inode list after inode ip. The list
933 * must be locked when this is called. After the call the list will no
936 #define IPOINTER_INSERT(ip, mp) { \
937 ASSERT(ipointer_in == B_FALSE); \
938 ipointer->ip_mnext = ip->i_mnext; \
939 ipointer->ip_mprev = ip; \
940 ip->i_mnext = (xfs_inode_t *)ipointer; \
941 ipointer->ip_mnext->i_mprev = (xfs_inode_t *)ipointer; \
943 XFS_MOUNT_IUNLOCK(mp); \
944 mount_locked = B_FALSE; \
948 /* Remove the marker from the inode list. If the marker was the only item
949 * in the list then there are no remaining inodes and we should zero out
950 * the whole list. If we are the current head of the list then move the head
953 #define IPOINTER_REMOVE(ip, mp) { \
954 ASSERT(ipointer_in == B_TRUE); \
955 if (ipointer->ip_mnext != (xfs_inode_t *)ipointer) { \
956 ip = ipointer->ip_mnext; \
957 ip->i_mprev = ipointer->ip_mprev; \
958 ipointer->ip_mprev->i_mnext = ip; \
959 if (mp->m_inodes == (xfs_inode_t *)ipointer) { \
963 ASSERT(mp->m_inodes == (xfs_inode_t *)ipointer); \
964 mp->m_inodes = NULL; \
970 #define XFS_PREEMPT_MASK 0x7f
974 if (XFS_MTOVFS(mp)->vfs_flag & VFS_RDONLY)
980 /* Allocate a reference marker */
981 ipointer = (xfs_iptr_t *)kmem_zalloc(sizeof(xfs_iptr_t), KM_SLEEP);
983 fflag = XFS_B_ASYNC; /* default is don't wait */
984 if (flags & (SYNC_BDFLUSH | SYNC_DELWRI))
985 fflag = XFS_B_DELWRI;
986 if (flags & SYNC_WAIT)
987 fflag = 0; /* synchronous overrides all */
989 base_lock_flags = XFS_ILOCK_SHARED;
990 if (flags & (SYNC_DELWRI | SYNC_CLOSE)) {
992 * We need the I/O lock if we're going to call any of
993 * the flush/inval routines.
995 base_lock_flags |= XFS_IOLOCK_SHARED;
1002 mount_locked = B_TRUE;
1003 vnode_refed = B_FALSE;
1008 ASSERT(ipointer_in == B_FALSE);
1009 ASSERT(vnode_refed == B_FALSE);
1011 lock_flags = base_lock_flags;
1014 * There were no inodes in the list, just break out
1022 * We found another sync thread marker - skip it
1024 if (ip->i_mount == NULL) {
1029 vp = XFS_ITOV_NULL(ip);
1032 * If the vnode is gone then this is being torn down,
1033 * call reclaim if it is flushed, else let regular flush
1034 * code deal with it later in the loop.
1038 /* Skip ones already in reclaim */
1039 if (ip->i_flags & XFS_IRECLAIM) {
1043 if (xfs_ilock_nowait(ip, XFS_ILOCK_EXCL) == 0) {
1045 } else if ((xfs_ipincount(ip) == 0) &&
1046 xfs_iflock_nowait(ip)) {
1047 IPOINTER_INSERT(ip, mp);
1049 xfs_finish_reclaim(ip, 1,
1050 XFS_IFLUSH_DELWRI_ELSE_ASYNC);
1052 XFS_MOUNT_ILOCK(mp);
1053 mount_locked = B_TRUE;
1054 IPOINTER_REMOVE(ip, mp);
1056 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1067 if (XFS_FORCED_SHUTDOWN(mp) && !(flags & SYNC_CLOSE)) {
1068 XFS_MOUNT_IUNLOCK(mp);
1069 kmem_free(ipointer, sizeof(xfs_iptr_t));
1074 * If this is just vfs_sync() or pflushd() calling
1075 * then we can skip inodes for which it looks like
1076 * there is nothing to do. Since we don't have the
1077 * inode locked this is racy, but these are periodic
1078 * calls so it doesn't matter. For the others we want
1079 * to know for sure, so we at least try to lock them.
1081 if (flags & SYNC_BDFLUSH) {
1082 if (((ip->i_itemp == NULL) ||
1083 !(ip->i_itemp->ili_format.ilf_fields &
1085 (ip->i_update_core == 0)) {
1092 * Try to lock without sleeping. We're out of order with
1093 * the inode list lock here, so if we fail we need to drop
1094 * the mount lock and try again. If we're called from
1095 * bdflush() here, then don't bother.
1097 * The inode lock here actually coordinates with the
1098 * almost spurious inode lock in xfs_ireclaim() to prevent
1099 * the vnode we handle here without a reference from
1100 * being freed while we reference it. If we lock the inode
1101 * while it's on the mount list here, then the spurious inode
1102 * lock in xfs_ireclaim() after the inode is pulled from
1103 * the mount list will sleep until we release it here.
1104 * This keeps the vnode from being freed while we reference
1107 if (xfs_ilock_nowait(ip, lock_flags) == 0) {
1108 if ((flags & SYNC_BDFLUSH) || (vp == NULL)) {
1119 IPOINTER_INSERT(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.
1133 * If we have to flush data or wait for I/O completion
1134 * we need to drop the ilock that we currently hold.
1135 * If we need to drop the lock, insert a marker if we
1136 * have not already done so.
1138 if ((flags & (SYNC_CLOSE|SYNC_IOWAIT)) ||
1139 ((flags & SYNC_DELWRI) && VN_DIRTY(vp))) {
1141 IPOINTER_INSERT(ip, mp);
1143 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1145 if (flags & SYNC_CLOSE) {
1146 /* Shutdown case. Flush and invalidate. */
1147 if (XFS_FORCED_SHUTDOWN(mp))
1148 bhv_vop_toss_pages(vp, 0, -1, FI_REMAPF);
1150 error = bhv_vop_flushinval_pages(vp, 0,
1152 } else if ((flags & SYNC_DELWRI) && VN_DIRTY(vp)) {
1153 error = bhv_vop_flush_pages(vp, (xfs_off_t)0,
1154 -1, fflag, FI_NONE);
1158 * When freezing, we need to wait ensure all I/O (including direct
1159 * I/O) is complete to ensure no further data modification can take
1160 * place after this point
1162 if (flags & SYNC_IOWAIT)
1165 xfs_ilock(ip, XFS_ILOCK_SHARED);
1168 if (flags & SYNC_BDFLUSH) {
1169 if ((flags & SYNC_ATTR) &&
1170 ((ip->i_update_core) ||
1171 ((ip->i_itemp != NULL) &&
1172 (ip->i_itemp->ili_format.ilf_fields != 0)))) {
1174 /* Insert marker and drop lock if not already
1178 IPOINTER_INSERT(ip, mp);
1182 * We don't want the periodic flushing of the
1183 * inodes by vfs_sync() to interfere with
1184 * I/O to the file, especially read I/O
1185 * where it is only the access time stamp
1186 * that is being flushed out. To prevent
1187 * long periods where we have both inode
1188 * locks held shared here while reading the
1189 * inode's buffer in from disk, we drop the
1190 * inode lock while reading in the inode
1191 * buffer. We have to release the buffer
1192 * and reacquire the inode lock so that they
1193 * are acquired in the proper order (inode
1194 * locks first). The buffer will go at the
1195 * end of the lru chain, though, so we can
1196 * expect it to still be there when we go
1197 * for it again in xfs_iflush().
1199 if ((xfs_ipincount(ip) == 0) &&
1200 xfs_iflock_nowait(ip)) {
1203 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1205 error = xfs_itobp(mp, NULL, ip,
1210 /* Bailing out, remove the
1211 * marker and free it.
1213 XFS_MOUNT_ILOCK(mp);
1214 IPOINTER_REMOVE(ip, mp);
1215 XFS_MOUNT_IUNLOCK(mp);
1217 ASSERT(!(lock_flags &
1218 XFS_IOLOCK_SHARED));
1221 sizeof(xfs_iptr_t));
1226 * Since we dropped the inode lock,
1227 * the inode may have been reclaimed.
1228 * Therefore, we reacquire the mount
1229 * lock and check to see if we were the
1230 * inode reclaimed. If this happened
1231 * then the ipointer marker will no
1232 * longer point back at us. In this
1233 * case, move ip along to the inode
1234 * after the marker, remove the marker
1237 XFS_MOUNT_ILOCK(mp);
1238 mount_locked = B_TRUE;
1240 if (ip != ipointer->ip_mprev) {
1241 IPOINTER_REMOVE(ip, mp);
1243 ASSERT(!vnode_refed);
1244 ASSERT(!(lock_flags &
1245 XFS_IOLOCK_SHARED));
1249 ASSERT(ip->i_mount == mp);
1251 if (xfs_ilock_nowait(ip,
1252 XFS_ILOCK_SHARED) == 0) {
1253 ASSERT(ip->i_mount == mp);
1255 * We failed to reacquire
1256 * the inode lock without
1257 * sleeping, so just skip
1258 * the inode for now. We
1259 * clear the ILOCK bit from
1260 * the lock_flags so that we
1261 * won't try to drop a lock
1262 * we don't hold below.
1264 lock_flags &= ~XFS_ILOCK_SHARED;
1265 IPOINTER_REMOVE(ip_next, mp);
1266 } else if ((xfs_ipincount(ip) == 0) &&
1267 xfs_iflock_nowait(ip)) {
1268 ASSERT(ip->i_mount == mp);
1270 * Since this is vfs_sync()
1271 * calling we only flush the
1272 * inode out if we can lock
1273 * it without sleeping and
1274 * it is not pinned. Drop
1275 * the mount lock here so
1276 * that we don't hold it for
1277 * too long. We already have
1278 * a marker in the list here.
1280 XFS_MOUNT_IUNLOCK(mp);
1281 mount_locked = B_FALSE;
1282 error = xfs_iflush(ip,
1285 ASSERT(ip->i_mount == mp);
1286 IPOINTER_REMOVE(ip_next, mp);
1293 if ((flags & SYNC_ATTR) &&
1294 ((ip->i_update_core) ||
1295 ((ip->i_itemp != NULL) &&
1296 (ip->i_itemp->ili_format.ilf_fields != 0)))) {
1298 IPOINTER_INSERT(ip, mp);
1301 if (flags & SYNC_WAIT) {
1303 error = xfs_iflush(ip,
1307 * If we can't acquire the flush
1308 * lock, then the inode is already
1309 * being flushed so don't bother
1310 * waiting. If we can lock it then
1311 * do a delwri flush so we can
1312 * combine multiple inode flushes
1313 * in each disk write.
1315 if (xfs_iflock_nowait(ip)) {
1316 error = xfs_iflush(ip,
1325 if (lock_flags != 0) {
1326 xfs_iunlock(ip, lock_flags);
1331 * If we had to take a reference on the vnode
1332 * above, then wait until after we've unlocked
1333 * the inode to release the reference. This is
1334 * because we can be already holding the inode
1335 * lock when VN_RELE() calls xfs_inactive().
1337 * Make sure to drop the mount lock before calling
1338 * VN_RELE() so that we don't trip over ourselves if
1339 * we have to go for the mount lock again in the
1343 IPOINTER_INSERT(ip, mp);
1348 vnode_refed = B_FALSE;
1356 * bail out if the filesystem is corrupted.
1358 if (error == EFSCORRUPTED) {
1359 if (!mount_locked) {
1360 XFS_MOUNT_ILOCK(mp);
1361 IPOINTER_REMOVE(ip, mp);
1363 XFS_MOUNT_IUNLOCK(mp);
1364 ASSERT(ipointer_in == B_FALSE);
1365 kmem_free(ipointer, sizeof(xfs_iptr_t));
1366 return XFS_ERROR(error);
1369 /* Let other threads have a chance at the mount lock
1370 * if we have looped many times without dropping the
1373 if ((++preempt & XFS_PREEMPT_MASK) == 0) {
1375 IPOINTER_INSERT(ip, mp);
1379 if (mount_locked == B_FALSE) {
1380 XFS_MOUNT_ILOCK(mp);
1381 mount_locked = B_TRUE;
1382 IPOINTER_REMOVE(ip, mp);
1386 ASSERT(ipointer_in == B_FALSE);
1389 } while (ip != mp->m_inodes);
1391 XFS_MOUNT_IUNLOCK(mp);
1393 ASSERT(ipointer_in == B_FALSE);
1395 kmem_free(ipointer, sizeof(xfs_iptr_t));
1396 return XFS_ERROR(last_error);
1400 * xfs sync routine for internal use
1402 * This routine supports all of the flags defined for the generic vfs_sync
1403 * interface as explained above under xfs_sync.
1414 uint log_flags = XFS_LOG_FORCE;
1416 xfs_buf_log_item_t *bip;
1419 * Sync out the log. This ensures that the log is periodically
1420 * flushed even if there is not enough activity to fill it up.
1422 if (flags & SYNC_WAIT)
1423 log_flags |= XFS_LOG_SYNC;
1425 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1427 if (flags & (SYNC_ATTR|SYNC_DELWRI)) {
1428 if (flags & SYNC_BDFLUSH)
1429 xfs_finish_reclaim_all(mp, 1);
1431 error = xfs_sync_inodes(mp, flags, bypassed);
1435 * Flushing out dirty data above probably generated more
1436 * log activity, so if this isn't vfs_sync() then flush
1439 if (flags & SYNC_DELWRI) {
1440 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1443 if (flags & SYNC_FSDATA) {
1445 * If this is vfs_sync() then only sync the superblock
1446 * if we can lock it without sleeping and it is not pinned.
1448 if (flags & SYNC_BDFLUSH) {
1449 bp = xfs_getsb(mp, XFS_BUF_TRYLOCK);
1451 bip = XFS_BUF_FSPRIVATE(bp,xfs_buf_log_item_t*);
1452 if ((bip != NULL) &&
1453 xfs_buf_item_dirty(bip)) {
1454 if (!(XFS_BUF_ISPINNED(bp))) {
1456 error = xfs_bwrite(mp, bp);
1465 bp = xfs_getsb(mp, 0);
1467 * If the buffer is pinned then push on the log so
1468 * we won't get stuck waiting in the write for
1469 * someone, maybe ourselves, to flush the log.
1470 * Even though we just pushed the log above, we
1471 * did not have the superblock buffer locked at
1472 * that point so it can become pinned in between
1475 if (XFS_BUF_ISPINNED(bp))
1476 xfs_log_force(mp, (xfs_lsn_t)0, XFS_LOG_FORCE);
1477 if (flags & SYNC_WAIT)
1478 XFS_BUF_UNASYNC(bp);
1481 error = xfs_bwrite(mp, bp);
1489 * If this is the periodic sync, then kick some entries out of
1490 * the reference cache. This ensures that idle entries are
1491 * eventually kicked out of the cache.
1493 if (flags & SYNC_REFCACHE) {
1494 if (flags & SYNC_WAIT)
1495 xfs_refcache_purge_mp(mp);
1497 xfs_refcache_purge_some(mp);
1501 * If asked, update the disk superblock with incore counter values if we
1502 * are using non-persistent counters so that they don't get too far out
1503 * of sync if we crash or get a forced shutdown. We don't want to force
1504 * this to disk, just get a transaction into the iclogs....
1506 if (flags & SYNC_SUPER)
1507 xfs_log_sbcount(mp, 0);
1510 * Now check to see if the log needs a "dummy" transaction.
1513 if (!(flags & SYNC_REMOUNT) && xfs_log_need_covered(mp)) {
1518 * Put a dummy transaction in the log to tell
1519 * recovery that all others are OK.
1521 tp = xfs_trans_alloc(mp, XFS_TRANS_DUMMY1);
1522 if ((error = xfs_trans_reserve(tp, 0,
1523 XFS_ICHANGE_LOG_RES(mp),
1525 xfs_trans_cancel(tp, 0);
1530 xfs_ilock(ip, XFS_ILOCK_EXCL);
1532 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
1533 xfs_trans_ihold(tp, ip);
1534 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
1535 error = xfs_trans_commit(tp, 0);
1536 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1537 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1541 * When shutting down, we need to insure that the AIL is pushed
1542 * to disk or the filesystem can appear corrupt from the PROM.
1544 if ((flags & (SYNC_CLOSE|SYNC_WAIT)) == (SYNC_CLOSE|SYNC_WAIT)) {
1545 XFS_bflush(mp->m_ddev_targp);
1546 if (mp->m_rtdev_targp) {
1547 XFS_bflush(mp->m_rtdev_targp);
1551 return XFS_ERROR(last_error);
1555 * xfs_vget - called by DMAPI and NFSD to get vnode from file handle
1563 xfs_mount_t *mp = XFS_BHVTOM(bdp);
1564 xfs_fid_t *xfid = (struct xfs_fid *)fidp;
1571 * Invalid. Since handles can be created in user space and passed in
1572 * via gethandle(), this is not cause for a panic.
1574 if (xfid->xfs_fid_len != sizeof(*xfid) - sizeof(xfid->xfs_fid_len))
1575 return XFS_ERROR(EINVAL);
1577 ino = xfid->xfs_fid_ino;
1578 igen = xfid->xfs_fid_gen;
1581 * NFS can sometimes send requests for ino 0. Fail them gracefully.
1584 return XFS_ERROR(ESTALE);
1586 error = xfs_iget(mp, NULL, ino, 0, XFS_ILOCK_SHARED, &ip, 0);
1594 return XFS_ERROR(EIO);
1597 if (ip->i_d.di_mode == 0 || 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_SWALLOC "swalloc" /* turn on stripe width allocation */
1618 #define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
1619 #define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
1620 #define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
1621 #define MNTOPT_MTPT "mtpt" /* filesystem mount point */
1622 #define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
1623 #define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
1624 #define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
1625 #define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
1626 #define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
1627 #define MNTOPT_IHASHSIZE "ihashsize" /* size of inode hash table */
1628 #define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
1629 #define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
1630 * unwritten extent conversion */
1631 #define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
1632 #define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
1633 #define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
1634 #define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
1635 #define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
1636 #define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
1637 #define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
1639 #define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
1640 #define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
1642 STATIC unsigned long
1643 suffix_strtoul(char *s, char **endp, unsigned int base)
1645 int last, shift_left_factor = 0;
1648 last = strlen(value) - 1;
1649 if (value[last] == 'K' || value[last] == 'k') {
1650 shift_left_factor = 10;
1653 if (value[last] == 'M' || value[last] == 'm') {
1654 shift_left_factor = 20;
1657 if (value[last] == 'G' || value[last] == 'g') {
1658 shift_left_factor = 30;
1662 return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
1667 struct bhv_desc *bhv,
1669 struct xfs_mount_args *args,
1672 bhv_vfs_t *vfsp = bhvtovfs(bhv);
1673 char *this_char, *value, *eov;
1674 int dsunit, dswidth, vol_dsunit, vol_dswidth;
1677 args->flags |= XFSMNT_IDELETE;
1678 args->flags |= XFSMNT_BARRIER;
1679 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
1684 iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0;
1686 while ((this_char = strsep(&options, ",")) != NULL) {
1689 if ((value = strchr(this_char, '=')) != NULL)
1692 if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
1693 if (!value || !*value) {
1695 "XFS: %s option requires an argument",
1699 args->logbufs = simple_strtoul(value, &eov, 10);
1700 } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
1701 if (!value || !*value) {
1703 "XFS: %s option requires an argument",
1707 args->logbufsize = suffix_strtoul(value, &eov, 10);
1708 } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
1709 if (!value || !*value) {
1711 "XFS: %s option requires an argument",
1715 strncpy(args->logname, value, MAXNAMELEN);
1716 } else if (!strcmp(this_char, MNTOPT_MTPT)) {
1717 if (!value || !*value) {
1719 "XFS: %s option requires an argument",
1723 strncpy(args->mtpt, value, MAXNAMELEN);
1724 } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
1725 if (!value || !*value) {
1727 "XFS: %s option requires an argument",
1731 strncpy(args->rtname, value, MAXNAMELEN);
1732 } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
1733 if (!value || !*value) {
1735 "XFS: %s option requires an argument",
1739 iosize = simple_strtoul(value, &eov, 10);
1740 args->flags |= XFSMNT_IOSIZE;
1741 args->iosizelog = (uint8_t) iosize;
1742 } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
1743 if (!value || !*value) {
1745 "XFS: %s option requires an argument",
1749 iosize = suffix_strtoul(value, &eov, 10);
1750 args->flags |= XFSMNT_IOSIZE;
1751 args->iosizelog = ffs(iosize) - 1;
1752 } else if (!strcmp(this_char, MNTOPT_IHASHSIZE)) {
1753 if (!value || !*value) {
1755 "XFS: %s option requires an argument",
1759 args->flags |= XFSMNT_IHASHSIZE;
1760 args->ihashsize = simple_strtoul(value, &eov, 10);
1761 } else if (!strcmp(this_char, MNTOPT_GRPID) ||
1762 !strcmp(this_char, MNTOPT_BSDGROUPS)) {
1763 vfsp->vfs_flag |= VFS_GRPID;
1764 } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
1765 !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
1766 vfsp->vfs_flag &= ~VFS_GRPID;
1767 } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
1768 args->flags |= XFSMNT_WSYNC;
1769 } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
1770 args->flags |= XFSMNT_OSYNCISOSYNC;
1771 } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
1772 args->flags |= XFSMNT_NORECOVERY;
1773 } else if (!strcmp(this_char, MNTOPT_INO64)) {
1774 args->flags |= XFSMNT_INO64;
1777 "XFS: %s option not allowed on this system",
1781 } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
1782 args->flags |= XFSMNT_NOALIGN;
1783 } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
1784 args->flags |= XFSMNT_SWALLOC;
1785 } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
1786 if (!value || !*value) {
1788 "XFS: %s option requires an argument",
1792 dsunit = simple_strtoul(value, &eov, 10);
1793 } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
1794 if (!value || !*value) {
1796 "XFS: %s option requires an argument",
1800 dswidth = simple_strtoul(value, &eov, 10);
1801 } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
1802 args->flags &= ~XFSMNT_32BITINODES;
1805 "XFS: %s option not allowed on this system",
1809 } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
1810 args->flags |= XFSMNT_NOUUID;
1811 } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
1812 args->flags |= XFSMNT_BARRIER;
1813 } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
1814 args->flags &= ~XFSMNT_BARRIER;
1815 } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
1816 args->flags &= ~XFSMNT_IDELETE;
1817 } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
1818 args->flags |= XFSMNT_IDELETE;
1819 } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
1820 args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE;
1821 } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
1822 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
1823 } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
1824 args->flags |= XFSMNT_ATTR2;
1825 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
1826 args->flags &= ~XFSMNT_ATTR2;
1827 } else if (!strcmp(this_char, "osyncisdsync")) {
1828 /* no-op, this is now the default */
1830 "XFS: osyncisdsync is now the default, option is deprecated.");
1831 } else if (!strcmp(this_char, "irixsgid")) {
1833 "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
1836 "XFS: unknown mount option [%s].", this_char);
1841 if (args->flags & XFSMNT_NORECOVERY) {
1842 if ((vfsp->vfs_flag & VFS_RDONLY) == 0) {
1844 "XFS: no-recovery mounts must be read-only.");
1849 if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) {
1851 "XFS: sunit and swidth options incompatible with the noalign option");
1855 if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
1857 "XFS: sunit and swidth must be specified together");
1861 if (dsunit && (dswidth % dsunit != 0)) {
1863 "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
1868 if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
1870 args->sunit = dsunit;
1871 args->flags |= XFSMNT_RETERR;
1873 args->sunit = vol_dsunit;
1875 dswidth ? (args->swidth = dswidth) :
1876 (args->swidth = vol_dswidth);
1878 args->sunit = args->swidth = 0;
1882 if (args->flags & XFSMNT_32BITINODES)
1883 vfsp->vfs_flag |= VFS_32BITINODES;
1885 args->flags |= XFSMNT_FLAGS2;
1891 struct bhv_desc *bhv,
1894 static struct proc_xfs_info {
1898 /* the few simple ones we can get from the mount struct */
1899 { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
1900 { XFS_MOUNT_INO64, "," MNTOPT_INO64 },
1901 { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
1902 { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
1903 { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
1904 { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
1905 { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
1908 struct proc_xfs_info *xfs_infop;
1909 struct xfs_mount *mp = XFS_BHVTOM(bhv);
1910 struct bhv_vfs *vfsp = XFS_MTOVFS(mp);
1912 for (xfs_infop = xfs_info; xfs_infop->flag; xfs_infop++) {
1913 if (mp->m_flags & xfs_infop->flag)
1914 seq_puts(m, xfs_infop->str);
1917 if (mp->m_flags & XFS_MOUNT_IHASHSIZE)
1918 seq_printf(m, "," MNTOPT_IHASHSIZE "=%d", (int)mp->m_ihsize);
1920 if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
1921 seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
1922 (int)(1 << mp->m_writeio_log) >> 10);
1924 if (mp->m_logbufs > 0)
1925 seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
1926 if (mp->m_logbsize > 0)
1927 seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
1930 seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
1932 seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
1934 if (mp->m_dalign > 0)
1935 seq_printf(m, "," MNTOPT_SUNIT "=%d",
1936 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
1937 if (mp->m_swidth > 0)
1938 seq_printf(m, "," MNTOPT_SWIDTH "=%d",
1939 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
1941 if (!(mp->m_flags & XFS_MOUNT_IDELETE))
1942 seq_printf(m, "," MNTOPT_IKEEP);
1943 if (!(mp->m_flags & XFS_MOUNT_COMPAT_IOSIZE))
1944 seq_printf(m, "," MNTOPT_LARGEIO);
1946 if (!(vfsp->vfs_flag & VFS_32BITINODES))
1947 seq_printf(m, "," MNTOPT_64BITINODE);
1948 if (vfsp->vfs_flag & VFS_GRPID)
1949 seq_printf(m, "," MNTOPT_GRPID);
1955 * Second stage of a freeze. The data is already frozen, now we have to take
1956 * care of the metadata. New transactions are already blocked, so we need to
1957 * wait for any remaining transactions to drain out before proceding.
1963 xfs_mount_t *mp = XFS_BHVTOM(bdp);
1965 /* wait for all modifications to complete */
1966 while (atomic_read(&mp->m_active_trans) > 0)
1969 /* flush inodes and push all remaining buffers out to disk */
1972 ASSERT_ALWAYS(atomic_read(&mp->m_active_trans) == 0);
1974 /* Push the superblock and write an unmount record */
1975 xfs_log_sbcount(mp, 1);
1976 xfs_log_unmount_write(mp);
1977 xfs_unmountfs_writesb(mp);
1978 xfs_fs_log_dummy(mp);
1982 bhv_vfsops_t xfs_vfsops = {
1983 BHV_IDENTITY_INIT(VFS_BHV_XFS,VFS_POSITION_XFS),
1984 .vfs_parseargs = xfs_parseargs,
1985 .vfs_showargs = xfs_showargs,
1986 .vfs_mount = xfs_mount,
1987 .vfs_unmount = xfs_unmount,
1988 .vfs_mntupdate = xfs_mntupdate,
1989 .vfs_root = xfs_root,
1990 .vfs_statvfs = xfs_statvfs,
1991 .vfs_sync = xfs_sync,
1992 .vfs_vget = xfs_vget,
1993 .vfs_dmapiops = (vfs_dmapiops_t)fs_nosys,
1994 .vfs_quotactl = (vfs_quotactl_t)fs_nosys,
1995 .vfs_init_vnode = xfs_initialize_vnode,
1996 .vfs_force_shutdown = xfs_do_force_shutdown,
1997 .vfs_freeze = xfs_freeze,