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_mru_cache.h"
55 #include "xfs_filestream.h"
56 #include "xfs_fsops.h"
58 STATIC int xfs_sync(bhv_desc_t *, int, cred_t *);
63 extern kmem_zone_t *xfs_bmap_free_item_zone;
64 extern kmem_zone_t *xfs_btree_cur_zone;
65 extern kmem_zone_t *xfs_trans_zone;
66 extern kmem_zone_t *xfs_buf_item_zone;
67 extern kmem_zone_t *xfs_dabuf_zone;
68 #ifdef XFS_DABUF_DEBUG
69 extern lock_t xfs_dabuf_global_lock;
70 spinlock_init(&xfs_dabuf_global_lock, "xfsda");
74 * Initialize all of the zone allocators we use.
76 xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
77 "xfs_bmap_free_item");
78 xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
80 xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
82 kmem_zone_init(sizeof(xfs_da_state_t), "xfs_da_state");
83 xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf");
84 xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
85 xfs_acl_zone_init(xfs_acl_zone, "xfs_acl");
87 xfs_filestream_init();
90 * The size of the zone allocated buf log item is the maximum
91 * size possible under XFS. This wastes a little bit of memory,
92 * but it is much faster.
95 kmem_zone_init((sizeof(xfs_buf_log_item_t) +
96 (((XFS_MAX_BLOCKSIZE / XFS_BLI_CHUNK) /
97 NBWORD) * sizeof(int))),
100 kmem_zone_init((sizeof(xfs_efd_log_item_t) +
101 ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
102 sizeof(xfs_extent_t))),
105 kmem_zone_init((sizeof(xfs_efi_log_item_t) +
106 ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
107 sizeof(xfs_extent_t))),
111 * These zones warrant special memory allocator hints
114 kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
115 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM |
116 KM_ZONE_SPREAD, NULL);
118 kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
119 KM_ZONE_SPREAD, NULL);
121 kmem_zone_init_flags(sizeof(xfs_chashlist_t), "xfs_chashlist",
122 KM_ZONE_SPREAD, NULL);
125 * Allocate global trace buffers.
127 #ifdef XFS_ALLOC_TRACE
128 xfs_alloc_trace_buf = ktrace_alloc(XFS_ALLOC_TRACE_SIZE, KM_SLEEP);
130 #ifdef XFS_BMAP_TRACE
131 xfs_bmap_trace_buf = ktrace_alloc(XFS_BMAP_TRACE_SIZE, KM_SLEEP);
133 #ifdef XFS_BMBT_TRACE
134 xfs_bmbt_trace_buf = ktrace_alloc(XFS_BMBT_TRACE_SIZE, KM_SLEEP);
136 #ifdef XFS_ATTR_TRACE
137 xfs_attr_trace_buf = ktrace_alloc(XFS_ATTR_TRACE_SIZE, KM_SLEEP);
139 #ifdef XFS_DIR2_TRACE
140 xfs_dir2_trace_buf = ktrace_alloc(XFS_DIR2_GTRACE_SIZE, KM_SLEEP);
145 #if (defined(DEBUG) || defined(INDUCE_IO_ERROR))
146 xfs_error_test_init();
147 #endif /* DEBUG || INDUCE_IO_ERROR */
150 xfs_sysctl_register();
157 extern kmem_zone_t *xfs_bmap_free_item_zone;
158 extern kmem_zone_t *xfs_btree_cur_zone;
159 extern kmem_zone_t *xfs_inode_zone;
160 extern kmem_zone_t *xfs_trans_zone;
161 extern kmem_zone_t *xfs_da_state_zone;
162 extern kmem_zone_t *xfs_dabuf_zone;
163 extern kmem_zone_t *xfs_efd_zone;
164 extern kmem_zone_t *xfs_efi_zone;
165 extern kmem_zone_t *xfs_buf_item_zone;
166 extern kmem_zone_t *xfs_chashlist_zone;
168 xfs_cleanup_procfs();
169 xfs_sysctl_unregister();
170 xfs_refcache_destroy();
171 xfs_filestream_uninit();
172 xfs_mru_cache_uninit();
173 xfs_acl_zone_destroy(xfs_acl_zone);
175 #ifdef XFS_DIR2_TRACE
176 ktrace_free(xfs_dir2_trace_buf);
178 #ifdef XFS_ATTR_TRACE
179 ktrace_free(xfs_attr_trace_buf);
181 #ifdef XFS_BMBT_TRACE
182 ktrace_free(xfs_bmbt_trace_buf);
184 #ifdef XFS_BMAP_TRACE
185 ktrace_free(xfs_bmap_trace_buf);
187 #ifdef XFS_ALLOC_TRACE
188 ktrace_free(xfs_alloc_trace_buf);
191 kmem_zone_destroy(xfs_bmap_free_item_zone);
192 kmem_zone_destroy(xfs_btree_cur_zone);
193 kmem_zone_destroy(xfs_inode_zone);
194 kmem_zone_destroy(xfs_trans_zone);
195 kmem_zone_destroy(xfs_da_state_zone);
196 kmem_zone_destroy(xfs_dabuf_zone);
197 kmem_zone_destroy(xfs_buf_item_zone);
198 kmem_zone_destroy(xfs_efd_zone);
199 kmem_zone_destroy(xfs_efi_zone);
200 kmem_zone_destroy(xfs_ifork_zone);
201 kmem_zone_destroy(xfs_ili_zone);
202 kmem_zone_destroy(xfs_chashlist_zone);
208 * This function fills in xfs_mount_t fields based on mount args.
209 * Note: the superblock has _not_ yet been read in.
214 struct xfs_mount_args *ap,
215 struct xfs_mount *mp)
217 /* Values are in BBs */
218 if ((ap->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
220 * At this point the superblock has not been read
221 * in, therefore we do not know the block size.
222 * Before the mount call ends we will convert
225 mp->m_dalign = ap->sunit;
226 mp->m_swidth = ap->swidth;
229 if (ap->logbufs != -1 &&
231 (ap->logbufs < XLOG_MIN_ICLOGS ||
232 ap->logbufs > XLOG_MAX_ICLOGS)) {
234 "XFS: invalid logbufs value: %d [not %d-%d]",
235 ap->logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
236 return XFS_ERROR(EINVAL);
238 mp->m_logbufs = ap->logbufs;
239 if (ap->logbufsize != -1 &&
240 ap->logbufsize != 0 &&
241 (ap->logbufsize < XLOG_MIN_RECORD_BSIZE ||
242 ap->logbufsize > XLOG_MAX_RECORD_BSIZE ||
243 !is_power_of_2(ap->logbufsize))) {
245 "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
247 return XFS_ERROR(EINVAL);
249 mp->m_ihsize = ap->ihashsize;
250 mp->m_logbsize = ap->logbufsize;
251 mp->m_fsname_len = strlen(ap->fsname) + 1;
252 mp->m_fsname = kmem_alloc(mp->m_fsname_len, KM_SLEEP);
253 strcpy(mp->m_fsname, ap->fsname);
255 mp->m_rtname = kmem_alloc(strlen(ap->rtname) + 1, KM_SLEEP);
256 strcpy(mp->m_rtname, ap->rtname);
258 if (ap->logname[0]) {
259 mp->m_logname = kmem_alloc(strlen(ap->logname) + 1, KM_SLEEP);
260 strcpy(mp->m_logname, ap->logname);
263 if (ap->flags & XFSMNT_WSYNC)
264 mp->m_flags |= XFS_MOUNT_WSYNC;
266 if (ap->flags & XFSMNT_INO64) {
267 mp->m_flags |= XFS_MOUNT_INO64;
268 mp->m_inoadd = XFS_INO64_OFFSET;
271 if (ap->flags & XFSMNT_RETERR)
272 mp->m_flags |= XFS_MOUNT_RETERR;
273 if (ap->flags & XFSMNT_NOALIGN)
274 mp->m_flags |= XFS_MOUNT_NOALIGN;
275 if (ap->flags & XFSMNT_SWALLOC)
276 mp->m_flags |= XFS_MOUNT_SWALLOC;
277 if (ap->flags & XFSMNT_OSYNCISOSYNC)
278 mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
279 if (ap->flags & XFSMNT_32BITINODES)
280 mp->m_flags |= XFS_MOUNT_32BITINODES;
282 if (ap->flags & XFSMNT_IOSIZE) {
283 if (ap->iosizelog > XFS_MAX_IO_LOG ||
284 ap->iosizelog < XFS_MIN_IO_LOG) {
286 "XFS: invalid log iosize: %d [not %d-%d]",
287 ap->iosizelog, XFS_MIN_IO_LOG,
289 return XFS_ERROR(EINVAL);
292 mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
293 mp->m_readio_log = mp->m_writeio_log = ap->iosizelog;
296 if (ap->flags & XFSMNT_IHASHSIZE)
297 mp->m_flags |= XFS_MOUNT_IHASHSIZE;
298 if (ap->flags & XFSMNT_IDELETE)
299 mp->m_flags |= XFS_MOUNT_IDELETE;
300 if (ap->flags & XFSMNT_DIRSYNC)
301 mp->m_flags |= XFS_MOUNT_DIRSYNC;
302 if (ap->flags & XFSMNT_ATTR2)
303 mp->m_flags |= XFS_MOUNT_ATTR2;
305 if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
306 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
309 * no recovery flag requires a read-only mount
311 if (ap->flags & XFSMNT_NORECOVERY) {
312 if (!(vfs->vfs_flag & VFS_RDONLY)) {
314 "XFS: tried to mount a FS read-write without recovery!");
315 return XFS_ERROR(EINVAL);
317 mp->m_flags |= XFS_MOUNT_NORECOVERY;
320 if (ap->flags & XFSMNT_NOUUID)
321 mp->m_flags |= XFS_MOUNT_NOUUID;
322 if (ap->flags & XFSMNT_BARRIER)
323 mp->m_flags |= XFS_MOUNT_BARRIER;
325 mp->m_flags &= ~XFS_MOUNT_BARRIER;
327 if (ap->flags2 & XFSMNT2_FILESTREAMS)
328 mp->m_flags |= XFS_MOUNT_FILESTREAMS;
334 * This function fills in xfs_mount_t fields based on mount args.
335 * Note: the superblock _has_ now been read in.
340 struct xfs_mount_args *ap,
341 struct xfs_mount *mp)
343 int ronly = (vfs->vfs_flag & VFS_RDONLY);
345 /* Fail a mount where the logbuf is smaller then the log stripe */
346 if (XFS_SB_VERSION_HASLOGV2(&mp->m_sb)) {
347 if ((ap->logbufsize <= 0) &&
348 (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) {
349 mp->m_logbsize = mp->m_sb.sb_logsunit;
350 } else if (ap->logbufsize > 0 &&
351 ap->logbufsize < mp->m_sb.sb_logsunit) {
353 "XFS: logbuf size must be greater than or equal to log stripe size");
354 return XFS_ERROR(EINVAL);
357 /* Fail a mount if the logbuf is larger than 32K */
358 if (ap->logbufsize > XLOG_BIG_RECORD_BSIZE) {
360 "XFS: logbuf size for version 1 logs must be 16K or 32K");
361 return XFS_ERROR(EINVAL);
365 if (XFS_SB_VERSION_HASATTR2(&mp->m_sb)) {
366 mp->m_flags |= XFS_MOUNT_ATTR2;
370 * prohibit r/w mounts of read-only filesystems
372 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
374 "XFS: cannot mount a read-only filesystem as read-write");
375 return XFS_ERROR(EROFS);
379 * check for shared mount.
381 if (ap->flags & XFSMNT_SHARED) {
382 if (!XFS_SB_VERSION_HASSHARED(&mp->m_sb))
383 return XFS_ERROR(EINVAL);
386 * For IRIX 6.5, shared mounts must have the shared
387 * version bit set, have the persistent readonly
388 * field set, must be version 0 and can only be mounted
391 if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) ||
392 (mp->m_sb.sb_shared_vn != 0))
393 return XFS_ERROR(EINVAL);
395 mp->m_flags |= XFS_MOUNT_SHARED;
398 * Shared XFS V0 can't deal with DMI. Return EINVAL.
400 if (mp->m_sb.sb_shared_vn == 0 && (ap->flags & XFSMNT_DMAPI))
401 return XFS_ERROR(EINVAL);
410 * The file system configurations are:
411 * (1) device (partition) with data and internal log
412 * (2) logical volume with data and log subvolumes.
413 * (3) logical volume with data, log, and realtime subvolumes.
415 * We only have to handle opening the log and realtime volumes here if
416 * they are present. The data subvolume has already been opened by
417 * get_sb_bdev() and is stored in vfsp->vfs_super->s_bdev.
421 struct bhv_desc *bhvp,
422 struct xfs_mount_args *args,
425 struct bhv_vfs *vfsp = bhvtovfs(bhvp);
427 struct xfs_mount *mp = XFS_BHVTOM(bhvp);
428 struct block_device *ddev, *logdev, *rtdev;
429 int flags = 0, error;
431 ddev = vfsp->vfs_super->s_bdev;
432 logdev = rtdev = NULL;
435 * Setup xfs_mount function vectors from available behaviors
437 p = vfs_bhv_lookup(vfsp, VFS_POSITION_DM);
438 mp->m_dm_ops = p ? *(xfs_dmops_t *) vfs_bhv_custom(p) : xfs_dmcore_stub;
439 p = vfs_bhv_lookup(vfsp, VFS_POSITION_QM);
440 mp->m_qm_ops = p ? *(xfs_qmops_t *) vfs_bhv_custom(p) : xfs_qmcore_stub;
441 p = vfs_bhv_lookup(vfsp, VFS_POSITION_IO);
442 mp->m_io_ops = p ? *(xfs_ioops_t *) vfs_bhv_custom(p) : xfs_iocore_xfs;
444 if (args->flags & XFSMNT_QUIET)
445 flags |= XFS_MFSI_QUIET;
448 * Open real time and log devices - order is important.
450 if (args->logname[0]) {
451 error = xfs_blkdev_get(mp, args->logname, &logdev);
455 if (args->rtname[0]) {
456 error = xfs_blkdev_get(mp, args->rtname, &rtdev);
458 xfs_blkdev_put(logdev);
462 if (rtdev == ddev || rtdev == logdev) {
464 "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
465 xfs_blkdev_put(logdev);
466 xfs_blkdev_put(rtdev);
472 * Setup xfs_mount buffer target pointers
475 mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
476 if (!mp->m_ddev_targp) {
477 xfs_blkdev_put(logdev);
478 xfs_blkdev_put(rtdev);
482 mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
483 if (!mp->m_rtdev_targp)
486 mp->m_logdev_targp = (logdev && logdev != ddev) ?
487 xfs_alloc_buftarg(logdev, 1) : mp->m_ddev_targp;
488 if (!mp->m_logdev_targp)
492 * Setup flags based on mount(2) options and then the superblock
494 error = xfs_start_flags(vfsp, args, mp);
497 error = xfs_readsb(mp, flags);
500 error = xfs_finish_flags(vfsp, args, mp);
505 * Setup xfs_mount buffer target pointers based on superblock
507 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
508 mp->m_sb.sb_sectsize);
509 if (!error && logdev && logdev != ddev) {
510 unsigned int log_sector_size = BBSIZE;
512 if (XFS_SB_VERSION_HASSECTOR(&mp->m_sb))
513 log_sector_size = mp->m_sb.sb_logsectsize;
514 error = xfs_setsize_buftarg(mp->m_logdev_targp,
515 mp->m_sb.sb_blocksize,
519 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
520 mp->m_sb.sb_blocksize,
521 mp->m_sb.sb_sectsize);
525 if (mp->m_flags & XFS_MOUNT_BARRIER)
526 xfs_mountfs_check_barriers(mp);
528 if ((error = xfs_filestream_mount(mp)))
531 error = XFS_IOINIT(vfsp, args, flags);
541 xfs_binval(mp->m_ddev_targp);
542 if (logdev && logdev != ddev)
543 xfs_binval(mp->m_logdev_targp);
545 xfs_binval(mp->m_rtdev_targp);
547 xfs_unmountfs_close(mp, credp);
557 bhv_vfs_t *vfsp = bhvtovfs(bdp);
558 xfs_mount_t *mp = XFS_BHVTOM(bdp);
561 int unmount_event_wanted = 0;
562 int unmount_event_flags = 0;
563 int xfs_unmountfs_needed = 0;
569 if (vfsp->vfs_flag & VFS_DMI) {
570 error = XFS_SEND_PREUNMOUNT(mp, vfsp,
571 rvp, DM_RIGHT_NULL, rvp, DM_RIGHT_NULL,
573 (mp->m_dmevmask & (1<<DM_EVENT_PREUNMOUNT))?
574 0:DM_FLAGS_UNWANTED);
576 return XFS_ERROR(error);
577 unmount_event_wanted = 1;
578 unmount_event_flags = (mp->m_dmevmask & (1<<DM_EVENT_UNMOUNT))?
579 0 : DM_FLAGS_UNWANTED;
583 * First blow any referenced inode from this file system
584 * out of the reference cache, and delete the timer.
586 xfs_refcache_purge_mp(mp);
589 * Blow away any referenced inode in the filestreams cache.
590 * This can and will cause log traffic as inodes go inactive
593 xfs_filestream_unmount(mp);
595 XFS_bflush(mp->m_ddev_targp);
596 error = xfs_unmount_flush(mp, 0);
600 ASSERT(vn_count(rvp) == 1);
603 * Drop the reference count
608 * If we're forcing a shutdown, typically because of a media error,
609 * we want to make sure we invalidate dirty pages that belong to
610 * referenced vnodes as well.
612 if (XFS_FORCED_SHUTDOWN(mp)) {
613 error = xfs_sync(&mp->m_bhv,
614 (SYNC_WAIT | SYNC_CLOSE), credp);
615 ASSERT(error != EFSCORRUPTED);
617 xfs_unmountfs_needed = 1;
620 /* Send DMAPI event, if required.
621 * Then do xfs_unmountfs() if needed.
622 * Then return error (or zero).
624 if (unmount_event_wanted) {
625 /* Note: mp structure must still exist for
626 * XFS_SEND_UNMOUNT() call.
628 XFS_SEND_UNMOUNT(mp, vfsp, error == 0 ? rvp : NULL,
629 DM_RIGHT_NULL, 0, error, unmount_event_flags);
631 if (xfs_unmountfs_needed) {
633 * Call common unmount function to flush to disk
634 * and free the super block buffer & mount structures.
636 xfs_unmountfs(mp, credp);
639 return XFS_ERROR(error);
646 int count = 0, pincount;
648 xfs_refcache_purge_mp(mp);
649 xfs_flush_buftarg(mp->m_ddev_targp, 0);
650 xfs_finish_reclaim_all(mp, 0);
652 /* This loop must run at least twice.
653 * The first instance of the loop will flush
654 * most meta data but that will generate more
655 * meta data (typically directory updates).
656 * Which then must be flushed and logged before
657 * we can write the unmount record.
660 xfs_syncsub(mp, SYNC_INODE_QUIESCE, NULL);
661 pincount = xfs_flush_buftarg(mp->m_ddev_targp, 1);
672 * Second stage of a quiesce. The data is already synced, now we have to take
673 * care of the metadata. New transactions are already blocked, so we need to
674 * wait for any remaining transactions to drain out before proceding.
680 /* wait for all modifications to complete */
681 while (atomic_read(&mp->m_active_trans) > 0)
684 /* flush inodes and push all remaining buffers out to disk */
687 ASSERT_ALWAYS(atomic_read(&mp->m_active_trans) == 0);
689 /* Push the superblock and write an unmount record */
690 xfs_log_sbcount(mp, 1);
691 xfs_log_unmount_write(mp);
692 xfs_unmountfs_writesb(mp);
699 struct xfs_mount_args *args)
701 bhv_vfs_t *vfsp = bhvtovfs(bdp);
702 xfs_mount_t *mp = XFS_BHVTOM(bdp);
704 if (!(*flags & MS_RDONLY)) { /* rw/ro -> rw */
705 if (vfsp->vfs_flag & VFS_RDONLY)
706 vfsp->vfs_flag &= ~VFS_RDONLY;
707 if (args->flags & XFSMNT_BARRIER) {
708 mp->m_flags |= XFS_MOUNT_BARRIER;
709 xfs_mountfs_check_barriers(mp);
711 mp->m_flags &= ~XFS_MOUNT_BARRIER;
713 } else if (!(vfsp->vfs_flag & VFS_RDONLY)) { /* rw -> ro */
714 xfs_filestream_flush(mp);
715 bhv_vfs_sync(vfsp, SYNC_DATA_QUIESCE, NULL);
716 xfs_attr_quiesce(mp);
717 vfsp->vfs_flag |= VFS_RDONLY;
723 * xfs_unmount_flush implements a set of flush operation on special
724 * inodes, which are needed as a separate set of operations so that
725 * they can be called as part of relocation process.
729 xfs_mount_t *mp, /* Mount structure we are getting
731 int relocation) /* Called from vfs relocation. */
733 xfs_inode_t *rip = mp->m_rootip;
735 xfs_inode_t *rsumip = NULL;
736 bhv_vnode_t *rvp = XFS_ITOV(rip);
739 xfs_ilock(rip, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT);
743 * Flush out the real time inodes.
745 if ((rbmip = mp->m_rbmip) != NULL) {
746 xfs_ilock(rbmip, XFS_ILOCK_EXCL);
748 error = xfs_iflush(rbmip, XFS_IFLUSH_SYNC);
749 xfs_iunlock(rbmip, XFS_ILOCK_EXCL);
751 if (error == EFSCORRUPTED)
754 ASSERT(vn_count(XFS_ITOV(rbmip)) == 1);
756 rsumip = mp->m_rsumip;
757 xfs_ilock(rsumip, XFS_ILOCK_EXCL);
759 error = xfs_iflush(rsumip, XFS_IFLUSH_SYNC);
760 xfs_iunlock(rsumip, XFS_ILOCK_EXCL);
762 if (error == EFSCORRUPTED)
765 ASSERT(vn_count(XFS_ITOV(rsumip)) == 1);
769 * Synchronously flush root inode to disk
771 error = xfs_iflush(rip, XFS_IFLUSH_SYNC);
772 if (error == EFSCORRUPTED)
775 if (vn_count(rvp) != 1 && !relocation) {
776 xfs_iunlock(rip, XFS_ILOCK_EXCL);
777 return XFS_ERROR(EBUSY);
781 * Release dquot that rootinode, rbmino and rsumino might be holding,
782 * flush and purge the quota inodes.
784 error = XFS_QM_UNMOUNT(mp);
785 if (error == EFSCORRUPTED)
789 VN_RELE(XFS_ITOV(rbmip));
790 VN_RELE(XFS_ITOV(rsumip));
793 xfs_iunlock(rip, XFS_ILOCK_EXCL);
800 xfs_iunlock(rip, XFS_ILOCK_EXCL);
802 return XFS_ERROR(EFSCORRUPTED);
806 * xfs_root extracts the root vnode from a vfs.
808 * vfsp -- the vfs struct for the desired file system
809 * vpp -- address of the caller's vnode pointer which should be
810 * set to the desired fs root vnode
819 vp = XFS_ITOV((XFS_BHVTOM(bdp))->m_rootip);
828 * Fill in the statvfs structure for the given file system. We use
829 * the superblock lock in the mount structure to ensure a consistent
830 * snapshot of the counters returned.
835 bhv_statvfs_t *statp,
844 mp = XFS_BHVTOM(bdp);
847 statp->f_type = XFS_SB_MAGIC;
849 xfs_icsb_sync_counters_flags(mp, XFS_ICSB_LAZY_COUNT);
851 statp->f_bsize = sbp->sb_blocksize;
852 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
853 statp->f_blocks = sbp->sb_dblocks - lsize;
854 statp->f_bfree = statp->f_bavail =
855 sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
856 fakeinos = statp->f_bfree << sbp->sb_inopblog;
858 fakeinos += mp->m_inoadd;
861 MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
866 statp->f_files = min_t(typeof(statp->f_files),
869 statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
870 XFS_SB_UNLOCK(mp, s);
872 xfs_statvfs_fsid(statp, mp);
873 statp->f_namelen = MAXNAMELEN - 1;
880 * xfs_sync flushes any pending I/O to file system vfsp.
882 * This routine is called by vfs_sync() to make sure that things make it
883 * out to disk eventually, on sync() system calls to flush out everything,
884 * and when the file system is unmounted. For the vfs_sync() case, all
885 * we really need to do is sync out the log to make all of our meta-data
886 * updates permanent (except for timestamps). For calls from pflushd(),
887 * dirty pages are kept moving by calling pdflush() on the inodes
888 * containing them. We also flush the inodes that we can lock without
889 * sleeping and the superblock if we can lock it without sleeping from
890 * vfs_sync() so that items at the tail of the log are always moving out.
893 * SYNC_BDFLUSH - We're being called from vfs_sync() so we don't want
894 * to sleep if we can help it. All we really need
895 * to do is ensure that the log is synced at least
896 * periodically. We also push the inodes and
897 * superblock if we can lock them without sleeping
898 * and they are not pinned.
899 * SYNC_ATTR - We need to flush the inodes. If SYNC_BDFLUSH is not
900 * set, then we really want to lock each inode and flush
902 * SYNC_WAIT - All the flushes that take place in this call should
904 * SYNC_DELWRI - This tells us to push dirty pages associated with
905 * inodes. SYNC_WAIT and SYNC_BDFLUSH are used to
906 * determine if they should be flushed sync, async, or
908 * SYNC_CLOSE - This flag is passed when the system is being
909 * unmounted. We should sync and invalidate everything.
910 * SYNC_FSDATA - This indicates that the caller would like to make
911 * sure the superblock is safe on disk. We can ensure
912 * this by simply making sure the log gets flushed
913 * if SYNC_BDFLUSH is set, and by actually writing it
915 * SYNC_IOWAIT - The caller wants us to wait for all data I/O to complete
916 * before we return (including direct I/O). Forms the drain
917 * side of the write barrier needed to safely quiesce the
928 xfs_mount_t *mp = XFS_BHVTOM(bdp);
930 if (flags & SYNC_IOWAIT)
931 xfs_filestream_flush(mp);
933 return xfs_syncsub(mp, flags, NULL);
937 * xfs sync routine for internal use
939 * This routine supports all of the flags defined for the generic vfs_sync
940 * interface as explained above under xfs_sync.
949 xfs_inode_t *ip = NULL;
950 xfs_inode_t *ip_next;
952 bhv_vnode_t *vp = NULL;
957 uint base_lock_flags;
958 boolean_t mount_locked;
959 boolean_t vnode_refed;
962 xfs_iptr_t *ipointer;
964 boolean_t ipointer_in = B_FALSE;
966 #define IPOINTER_SET ipointer_in = B_TRUE
967 #define IPOINTER_CLR ipointer_in = B_FALSE
974 /* Insert a marker record into the inode list after inode ip. The list
975 * must be locked when this is called. After the call the list will no
978 #define IPOINTER_INSERT(ip, mp) { \
979 ASSERT(ipointer_in == B_FALSE); \
980 ipointer->ip_mnext = ip->i_mnext; \
981 ipointer->ip_mprev = ip; \
982 ip->i_mnext = (xfs_inode_t *)ipointer; \
983 ipointer->ip_mnext->i_mprev = (xfs_inode_t *)ipointer; \
985 XFS_MOUNT_IUNLOCK(mp); \
986 mount_locked = B_FALSE; \
990 /* Remove the marker from the inode list. If the marker was the only item
991 * in the list then there are no remaining inodes and we should zero out
992 * the whole list. If we are the current head of the list then move the head
995 #define IPOINTER_REMOVE(ip, mp) { \
996 ASSERT(ipointer_in == B_TRUE); \
997 if (ipointer->ip_mnext != (xfs_inode_t *)ipointer) { \
998 ip = ipointer->ip_mnext; \
999 ip->i_mprev = ipointer->ip_mprev; \
1000 ipointer->ip_mprev->i_mnext = ip; \
1001 if (mp->m_inodes == (xfs_inode_t *)ipointer) { \
1002 mp->m_inodes = ip; \
1005 ASSERT(mp->m_inodes == (xfs_inode_t *)ipointer); \
1006 mp->m_inodes = NULL; \
1012 #define XFS_PREEMPT_MASK 0x7f
1016 if (XFS_MTOVFS(mp)->vfs_flag & VFS_RDONLY)
1022 /* Allocate a reference marker */
1023 ipointer = (xfs_iptr_t *)kmem_zalloc(sizeof(xfs_iptr_t), KM_SLEEP);
1025 fflag = XFS_B_ASYNC; /* default is don't wait */
1026 if (flags & (SYNC_BDFLUSH | SYNC_DELWRI))
1027 fflag = XFS_B_DELWRI;
1028 if (flags & SYNC_WAIT)
1029 fflag = 0; /* synchronous overrides all */
1031 base_lock_flags = XFS_ILOCK_SHARED;
1032 if (flags & (SYNC_DELWRI | SYNC_CLOSE)) {
1034 * We need the I/O lock if we're going to call any of
1035 * the flush/inval routines.
1037 base_lock_flags |= XFS_IOLOCK_SHARED;
1040 XFS_MOUNT_ILOCK(mp);
1044 mount_locked = B_TRUE;
1045 vnode_refed = B_FALSE;
1050 ASSERT(ipointer_in == B_FALSE);
1051 ASSERT(vnode_refed == B_FALSE);
1053 lock_flags = base_lock_flags;
1056 * There were no inodes in the list, just break out
1064 * We found another sync thread marker - skip it
1066 if (ip->i_mount == NULL) {
1071 vp = XFS_ITOV_NULL(ip);
1074 * If the vnode is gone then this is being torn down,
1075 * call reclaim if it is flushed, else let regular flush
1076 * code deal with it later in the loop.
1080 /* Skip ones already in reclaim */
1081 if (ip->i_flags & XFS_IRECLAIM) {
1085 if (xfs_ilock_nowait(ip, XFS_ILOCK_EXCL) == 0) {
1087 } else if ((xfs_ipincount(ip) == 0) &&
1088 xfs_iflock_nowait(ip)) {
1089 IPOINTER_INSERT(ip, mp);
1091 xfs_finish_reclaim(ip, 1,
1092 XFS_IFLUSH_DELWRI_ELSE_ASYNC);
1094 XFS_MOUNT_ILOCK(mp);
1095 mount_locked = B_TRUE;
1096 IPOINTER_REMOVE(ip, mp);
1098 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1109 if (XFS_FORCED_SHUTDOWN(mp) && !(flags & SYNC_CLOSE)) {
1110 XFS_MOUNT_IUNLOCK(mp);
1111 kmem_free(ipointer, sizeof(xfs_iptr_t));
1116 * If this is just vfs_sync() or pflushd() calling
1117 * then we can skip inodes for which it looks like
1118 * there is nothing to do. Since we don't have the
1119 * inode locked this is racy, but these are periodic
1120 * calls so it doesn't matter. For the others we want
1121 * to know for sure, so we at least try to lock them.
1123 if (flags & SYNC_BDFLUSH) {
1124 if (((ip->i_itemp == NULL) ||
1125 !(ip->i_itemp->ili_format.ilf_fields &
1127 (ip->i_update_core == 0)) {
1134 * Try to lock without sleeping. We're out of order with
1135 * the inode list lock here, so if we fail we need to drop
1136 * the mount lock and try again. If we're called from
1137 * bdflush() here, then don't bother.
1139 * The inode lock here actually coordinates with the
1140 * almost spurious inode lock in xfs_ireclaim() to prevent
1141 * the vnode we handle here without a reference from
1142 * being freed while we reference it. If we lock the inode
1143 * while it's on the mount list here, then the spurious inode
1144 * lock in xfs_ireclaim() after the inode is pulled from
1145 * the mount list will sleep until we release it here.
1146 * This keeps the vnode from being freed while we reference
1149 if (xfs_ilock_nowait(ip, lock_flags) == 0) {
1150 if ((flags & SYNC_BDFLUSH) || (vp == NULL)) {
1161 IPOINTER_INSERT(ip, mp);
1162 xfs_ilock(ip, lock_flags);
1164 ASSERT(vp == XFS_ITOV(ip));
1165 ASSERT(ip->i_mount == mp);
1167 vnode_refed = B_TRUE;
1170 /* From here on in the loop we may have a marker record
1171 * in the inode list.
1175 * If we have to flush data or wait for I/O completion
1176 * we need to drop the ilock that we currently hold.
1177 * If we need to drop the lock, insert a marker if we
1178 * have not already done so.
1180 if ((flags & (SYNC_CLOSE|SYNC_IOWAIT)) ||
1181 ((flags & SYNC_DELWRI) && VN_DIRTY(vp))) {
1183 IPOINTER_INSERT(ip, mp);
1185 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1187 if (flags & SYNC_CLOSE) {
1188 /* Shutdown case. Flush and invalidate. */
1189 if (XFS_FORCED_SHUTDOWN(mp))
1190 bhv_vop_toss_pages(vp, 0, -1, FI_REMAPF);
1192 error = bhv_vop_flushinval_pages(vp, 0,
1194 } else if ((flags & SYNC_DELWRI) && VN_DIRTY(vp)) {
1195 error = bhv_vop_flush_pages(vp, (xfs_off_t)0,
1196 -1, fflag, FI_NONE);
1200 * When freezing, we need to wait ensure all I/O (including direct
1201 * I/O) is complete to ensure no further data modification can take
1202 * place after this point
1204 if (flags & SYNC_IOWAIT)
1207 xfs_ilock(ip, XFS_ILOCK_SHARED);
1210 if (flags & SYNC_BDFLUSH) {
1211 if ((flags & SYNC_ATTR) &&
1212 ((ip->i_update_core) ||
1213 ((ip->i_itemp != NULL) &&
1214 (ip->i_itemp->ili_format.ilf_fields != 0)))) {
1216 /* Insert marker and drop lock if not already
1220 IPOINTER_INSERT(ip, mp);
1224 * We don't want the periodic flushing of the
1225 * inodes by vfs_sync() to interfere with
1226 * I/O to the file, especially read I/O
1227 * where it is only the access time stamp
1228 * that is being flushed out. To prevent
1229 * long periods where we have both inode
1230 * locks held shared here while reading the
1231 * inode's buffer in from disk, we drop the
1232 * inode lock while reading in the inode
1233 * buffer. We have to release the buffer
1234 * and reacquire the inode lock so that they
1235 * are acquired in the proper order (inode
1236 * locks first). The buffer will go at the
1237 * end of the lru chain, though, so we can
1238 * expect it to still be there when we go
1239 * for it again in xfs_iflush().
1241 if ((xfs_ipincount(ip) == 0) &&
1242 xfs_iflock_nowait(ip)) {
1245 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1247 error = xfs_itobp(mp, NULL, ip,
1252 /* Bailing out, remove the
1253 * marker and free it.
1255 XFS_MOUNT_ILOCK(mp);
1256 IPOINTER_REMOVE(ip, mp);
1257 XFS_MOUNT_IUNLOCK(mp);
1259 ASSERT(!(lock_flags &
1260 XFS_IOLOCK_SHARED));
1263 sizeof(xfs_iptr_t));
1268 * Since we dropped the inode lock,
1269 * the inode may have been reclaimed.
1270 * Therefore, we reacquire the mount
1271 * lock and check to see if we were the
1272 * inode reclaimed. If this happened
1273 * then the ipointer marker will no
1274 * longer point back at us. In this
1275 * case, move ip along to the inode
1276 * after the marker, remove the marker
1279 XFS_MOUNT_ILOCK(mp);
1280 mount_locked = B_TRUE;
1282 if (ip != ipointer->ip_mprev) {
1283 IPOINTER_REMOVE(ip, mp);
1285 ASSERT(!vnode_refed);
1286 ASSERT(!(lock_flags &
1287 XFS_IOLOCK_SHARED));
1291 ASSERT(ip->i_mount == mp);
1293 if (xfs_ilock_nowait(ip,
1294 XFS_ILOCK_SHARED) == 0) {
1295 ASSERT(ip->i_mount == mp);
1297 * We failed to reacquire
1298 * the inode lock without
1299 * sleeping, so just skip
1300 * the inode for now. We
1301 * clear the ILOCK bit from
1302 * the lock_flags so that we
1303 * won't try to drop a lock
1304 * we don't hold below.
1306 lock_flags &= ~XFS_ILOCK_SHARED;
1307 IPOINTER_REMOVE(ip_next, mp);
1308 } else if ((xfs_ipincount(ip) == 0) &&
1309 xfs_iflock_nowait(ip)) {
1310 ASSERT(ip->i_mount == mp);
1312 * Since this is vfs_sync()
1313 * calling we only flush the
1314 * inode out if we can lock
1315 * it without sleeping and
1316 * it is not pinned. Drop
1317 * the mount lock here so
1318 * that we don't hold it for
1319 * too long. We already have
1320 * a marker in the list here.
1322 XFS_MOUNT_IUNLOCK(mp);
1323 mount_locked = B_FALSE;
1324 error = xfs_iflush(ip,
1327 ASSERT(ip->i_mount == mp);
1328 IPOINTER_REMOVE(ip_next, mp);
1335 if ((flags & SYNC_ATTR) &&
1336 ((ip->i_update_core) ||
1337 ((ip->i_itemp != NULL) &&
1338 (ip->i_itemp->ili_format.ilf_fields != 0)))) {
1340 IPOINTER_INSERT(ip, mp);
1343 if (flags & SYNC_WAIT) {
1345 error = xfs_iflush(ip,
1349 * If we can't acquire the flush
1350 * lock, then the inode is already
1351 * being flushed so don't bother
1352 * waiting. If we can lock it then
1353 * do a delwri flush so we can
1354 * combine multiple inode flushes
1355 * in each disk write.
1357 if (xfs_iflock_nowait(ip)) {
1358 error = xfs_iflush(ip,
1367 if (lock_flags != 0) {
1368 xfs_iunlock(ip, lock_flags);
1373 * If we had to take a reference on the vnode
1374 * above, then wait until after we've unlocked
1375 * the inode to release the reference. This is
1376 * because we can be already holding the inode
1377 * lock when VN_RELE() calls xfs_inactive().
1379 * Make sure to drop the mount lock before calling
1380 * VN_RELE() so that we don't trip over ourselves if
1381 * we have to go for the mount lock again in the
1385 IPOINTER_INSERT(ip, mp);
1390 vnode_refed = B_FALSE;
1398 * bail out if the filesystem is corrupted.
1400 if (error == EFSCORRUPTED) {
1401 if (!mount_locked) {
1402 XFS_MOUNT_ILOCK(mp);
1403 IPOINTER_REMOVE(ip, mp);
1405 XFS_MOUNT_IUNLOCK(mp);
1406 ASSERT(ipointer_in == B_FALSE);
1407 kmem_free(ipointer, sizeof(xfs_iptr_t));
1408 return XFS_ERROR(error);
1411 /* Let other threads have a chance at the mount lock
1412 * if we have looped many times without dropping the
1415 if ((++preempt & XFS_PREEMPT_MASK) == 0) {
1417 IPOINTER_INSERT(ip, mp);
1421 if (mount_locked == B_FALSE) {
1422 XFS_MOUNT_ILOCK(mp);
1423 mount_locked = B_TRUE;
1424 IPOINTER_REMOVE(ip, mp);
1428 ASSERT(ipointer_in == B_FALSE);
1431 } while (ip != mp->m_inodes);
1433 XFS_MOUNT_IUNLOCK(mp);
1435 ASSERT(ipointer_in == B_FALSE);
1437 kmem_free(ipointer, sizeof(xfs_iptr_t));
1438 return XFS_ERROR(last_error);
1442 * xfs sync routine for internal use
1444 * This routine supports all of the flags defined for the generic vfs_sync
1445 * interface as explained above under xfs_sync.
1456 uint log_flags = XFS_LOG_FORCE;
1458 xfs_buf_log_item_t *bip;
1461 * Sync out the log. This ensures that the log is periodically
1462 * flushed even if there is not enough activity to fill it up.
1464 if (flags & SYNC_WAIT)
1465 log_flags |= XFS_LOG_SYNC;
1467 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1469 if (flags & (SYNC_ATTR|SYNC_DELWRI)) {
1470 if (flags & SYNC_BDFLUSH)
1471 xfs_finish_reclaim_all(mp, 1);
1473 error = xfs_sync_inodes(mp, flags, bypassed);
1477 * Flushing out dirty data above probably generated more
1478 * log activity, so if this isn't vfs_sync() then flush
1481 if (flags & SYNC_DELWRI) {
1482 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1485 if (flags & SYNC_FSDATA) {
1487 * If this is vfs_sync() then only sync the superblock
1488 * if we can lock it without sleeping and it is not pinned.
1490 if (flags & SYNC_BDFLUSH) {
1491 bp = xfs_getsb(mp, XFS_BUF_TRYLOCK);
1493 bip = XFS_BUF_FSPRIVATE(bp,xfs_buf_log_item_t*);
1494 if ((bip != NULL) &&
1495 xfs_buf_item_dirty(bip)) {
1496 if (!(XFS_BUF_ISPINNED(bp))) {
1498 error = xfs_bwrite(mp, bp);
1507 bp = xfs_getsb(mp, 0);
1509 * If the buffer is pinned then push on the log so
1510 * we won't get stuck waiting in the write for
1511 * someone, maybe ourselves, to flush the log.
1512 * Even though we just pushed the log above, we
1513 * did not have the superblock buffer locked at
1514 * that point so it can become pinned in between
1517 if (XFS_BUF_ISPINNED(bp))
1518 xfs_log_force(mp, (xfs_lsn_t)0, XFS_LOG_FORCE);
1519 if (flags & SYNC_WAIT)
1520 XFS_BUF_UNASYNC(bp);
1523 error = xfs_bwrite(mp, bp);
1531 * If this is the periodic sync, then kick some entries out of
1532 * the reference cache. This ensures that idle entries are
1533 * eventually kicked out of the cache.
1535 if (flags & SYNC_REFCACHE) {
1536 if (flags & SYNC_WAIT)
1537 xfs_refcache_purge_mp(mp);
1539 xfs_refcache_purge_some(mp);
1543 * If asked, update the disk superblock with incore counter values if we
1544 * are using non-persistent counters so that they don't get too far out
1545 * of sync if we crash or get a forced shutdown. We don't want to force
1546 * this to disk, just get a transaction into the iclogs....
1548 if (flags & SYNC_SUPER)
1549 xfs_log_sbcount(mp, 0);
1552 * Now check to see if the log needs a "dummy" transaction.
1555 if (!(flags & SYNC_REMOUNT) && xfs_log_need_covered(mp)) {
1560 * Put a dummy transaction in the log to tell
1561 * recovery that all others are OK.
1563 tp = xfs_trans_alloc(mp, XFS_TRANS_DUMMY1);
1564 if ((error = xfs_trans_reserve(tp, 0,
1565 XFS_ICHANGE_LOG_RES(mp),
1567 xfs_trans_cancel(tp, 0);
1572 xfs_ilock(ip, XFS_ILOCK_EXCL);
1574 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
1575 xfs_trans_ihold(tp, ip);
1576 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
1577 error = xfs_trans_commit(tp, 0);
1578 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1579 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1583 * When shutting down, we need to insure that the AIL is pushed
1584 * to disk or the filesystem can appear corrupt from the PROM.
1586 if ((flags & (SYNC_CLOSE|SYNC_WAIT)) == (SYNC_CLOSE|SYNC_WAIT)) {
1587 XFS_bflush(mp->m_ddev_targp);
1588 if (mp->m_rtdev_targp) {
1589 XFS_bflush(mp->m_rtdev_targp);
1593 return XFS_ERROR(last_error);
1597 * xfs_vget - called by DMAPI and NFSD to get vnode from file handle
1605 xfs_mount_t *mp = XFS_BHVTOM(bdp);
1606 xfs_fid_t *xfid = (struct xfs_fid *)fidp;
1613 * Invalid. Since handles can be created in user space and passed in
1614 * via gethandle(), this is not cause for a panic.
1616 if (xfid->xfs_fid_len != sizeof(*xfid) - sizeof(xfid->xfs_fid_len))
1617 return XFS_ERROR(EINVAL);
1619 ino = xfid->xfs_fid_ino;
1620 igen = xfid->xfs_fid_gen;
1623 * NFS can sometimes send requests for ino 0. Fail them gracefully.
1626 return XFS_ERROR(ESTALE);
1628 error = xfs_iget(mp, NULL, ino, 0, XFS_ILOCK_SHARED, &ip, 0);
1636 return XFS_ERROR(EIO);
1639 if (ip->i_d.di_mode == 0 || ip->i_d.di_gen != igen) {
1640 xfs_iput_new(ip, XFS_ILOCK_SHARED);
1642 return XFS_ERROR(ENOENT);
1645 *vpp = XFS_ITOV(ip);
1646 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1651 #define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
1652 #define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
1653 #define MNTOPT_LOGDEV "logdev" /* log device */
1654 #define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
1655 #define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
1656 #define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
1657 #define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
1658 #define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
1659 #define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
1660 #define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
1661 #define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
1662 #define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
1663 #define MNTOPT_MTPT "mtpt" /* filesystem mount point */
1664 #define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
1665 #define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
1666 #define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
1667 #define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
1668 #define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
1669 #define MNTOPT_IHASHSIZE "ihashsize" /* size of inode hash table */
1670 #define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
1671 #define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
1672 * unwritten extent conversion */
1673 #define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
1674 #define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
1675 #define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
1676 #define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
1677 #define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
1678 #define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
1679 #define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
1681 #define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
1682 #define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
1683 #define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
1685 STATIC unsigned long
1686 suffix_strtoul(char *s, char **endp, unsigned int base)
1688 int last, shift_left_factor = 0;
1691 last = strlen(value) - 1;
1692 if (value[last] == 'K' || value[last] == 'k') {
1693 shift_left_factor = 10;
1696 if (value[last] == 'M' || value[last] == 'm') {
1697 shift_left_factor = 20;
1700 if (value[last] == 'G' || value[last] == 'g') {
1701 shift_left_factor = 30;
1705 return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
1710 struct bhv_desc *bhv,
1712 struct xfs_mount_args *args,
1715 bhv_vfs_t *vfsp = bhvtovfs(bhv);
1716 char *this_char, *value, *eov;
1717 int dsunit, dswidth, vol_dsunit, vol_dswidth;
1720 args->flags |= XFSMNT_IDELETE;
1721 args->flags |= XFSMNT_BARRIER;
1722 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
1727 iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0;
1729 while ((this_char = strsep(&options, ",")) != NULL) {
1732 if ((value = strchr(this_char, '=')) != NULL)
1735 if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
1736 if (!value || !*value) {
1738 "XFS: %s option requires an argument",
1742 args->logbufs = simple_strtoul(value, &eov, 10);
1743 } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
1744 if (!value || !*value) {
1746 "XFS: %s option requires an argument",
1750 args->logbufsize = suffix_strtoul(value, &eov, 10);
1751 } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
1752 if (!value || !*value) {
1754 "XFS: %s option requires an argument",
1758 strncpy(args->logname, value, MAXNAMELEN);
1759 } else if (!strcmp(this_char, MNTOPT_MTPT)) {
1760 if (!value || !*value) {
1762 "XFS: %s option requires an argument",
1766 strncpy(args->mtpt, value, MAXNAMELEN);
1767 } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
1768 if (!value || !*value) {
1770 "XFS: %s option requires an argument",
1774 strncpy(args->rtname, value, MAXNAMELEN);
1775 } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
1776 if (!value || !*value) {
1778 "XFS: %s option requires an argument",
1782 iosize = simple_strtoul(value, &eov, 10);
1783 args->flags |= XFSMNT_IOSIZE;
1784 args->iosizelog = (uint8_t) iosize;
1785 } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
1786 if (!value || !*value) {
1788 "XFS: %s option requires an argument",
1792 iosize = suffix_strtoul(value, &eov, 10);
1793 args->flags |= XFSMNT_IOSIZE;
1794 args->iosizelog = ffs(iosize) - 1;
1795 } else if (!strcmp(this_char, MNTOPT_IHASHSIZE)) {
1796 if (!value || !*value) {
1798 "XFS: %s option requires an argument",
1802 args->flags |= XFSMNT_IHASHSIZE;
1803 args->ihashsize = simple_strtoul(value, &eov, 10);
1804 } else if (!strcmp(this_char, MNTOPT_GRPID) ||
1805 !strcmp(this_char, MNTOPT_BSDGROUPS)) {
1806 vfsp->vfs_flag |= VFS_GRPID;
1807 } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
1808 !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
1809 vfsp->vfs_flag &= ~VFS_GRPID;
1810 } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
1811 args->flags |= XFSMNT_WSYNC;
1812 } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
1813 args->flags |= XFSMNT_OSYNCISOSYNC;
1814 } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
1815 args->flags |= XFSMNT_NORECOVERY;
1816 } else if (!strcmp(this_char, MNTOPT_INO64)) {
1817 args->flags |= XFSMNT_INO64;
1820 "XFS: %s option not allowed on this system",
1824 } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
1825 args->flags |= XFSMNT_NOALIGN;
1826 } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
1827 args->flags |= XFSMNT_SWALLOC;
1828 } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
1829 if (!value || !*value) {
1831 "XFS: %s option requires an argument",
1835 dsunit = simple_strtoul(value, &eov, 10);
1836 } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
1837 if (!value || !*value) {
1839 "XFS: %s option requires an argument",
1843 dswidth = simple_strtoul(value, &eov, 10);
1844 } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
1845 args->flags &= ~XFSMNT_32BITINODES;
1848 "XFS: %s option not allowed on this system",
1852 } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
1853 args->flags |= XFSMNT_NOUUID;
1854 } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
1855 args->flags |= XFSMNT_BARRIER;
1856 } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
1857 args->flags &= ~XFSMNT_BARRIER;
1858 } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
1859 args->flags &= ~XFSMNT_IDELETE;
1860 } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
1861 args->flags |= XFSMNT_IDELETE;
1862 } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
1863 args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE;
1864 } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
1865 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
1866 } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
1867 args->flags |= XFSMNT_ATTR2;
1868 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
1869 args->flags &= ~XFSMNT_ATTR2;
1870 } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
1871 args->flags2 |= XFSMNT2_FILESTREAMS;
1872 } else if (!strcmp(this_char, "osyncisdsync")) {
1873 /* no-op, this is now the default */
1875 "XFS: osyncisdsync is now the default, option is deprecated.");
1876 } else if (!strcmp(this_char, "irixsgid")) {
1878 "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
1881 "XFS: unknown mount option [%s].", this_char);
1886 if (args->flags & XFSMNT_NORECOVERY) {
1887 if ((vfsp->vfs_flag & VFS_RDONLY) == 0) {
1889 "XFS: no-recovery mounts must be read-only.");
1894 if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) {
1896 "XFS: sunit and swidth options incompatible with the noalign option");
1900 if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
1902 "XFS: sunit and swidth must be specified together");
1906 if (dsunit && (dswidth % dsunit != 0)) {
1908 "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
1913 if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
1915 args->sunit = dsunit;
1916 args->flags |= XFSMNT_RETERR;
1918 args->sunit = vol_dsunit;
1920 dswidth ? (args->swidth = dswidth) :
1921 (args->swidth = vol_dswidth);
1923 args->sunit = args->swidth = 0;
1927 if (args->flags & XFSMNT_32BITINODES)
1928 vfsp->vfs_flag |= VFS_32BITINODES;
1930 args->flags |= XFSMNT_FLAGS2;
1936 struct bhv_desc *bhv,
1939 static struct proc_xfs_info {
1943 /* the few simple ones we can get from the mount struct */
1944 { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
1945 { XFS_MOUNT_INO64, "," MNTOPT_INO64 },
1946 { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
1947 { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
1948 { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
1949 { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
1950 { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
1953 struct proc_xfs_info *xfs_infop;
1954 struct xfs_mount *mp = XFS_BHVTOM(bhv);
1955 struct bhv_vfs *vfsp = XFS_MTOVFS(mp);
1957 for (xfs_infop = xfs_info; xfs_infop->flag; xfs_infop++) {
1958 if (mp->m_flags & xfs_infop->flag)
1959 seq_puts(m, xfs_infop->str);
1962 if (mp->m_flags & XFS_MOUNT_IHASHSIZE)
1963 seq_printf(m, "," MNTOPT_IHASHSIZE "=%d", (int)mp->m_ihsize);
1965 if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
1966 seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
1967 (int)(1 << mp->m_writeio_log) >> 10);
1969 if (mp->m_logbufs > 0)
1970 seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
1971 if (mp->m_logbsize > 0)
1972 seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
1975 seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
1977 seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
1979 if (mp->m_dalign > 0)
1980 seq_printf(m, "," MNTOPT_SUNIT "=%d",
1981 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
1982 if (mp->m_swidth > 0)
1983 seq_printf(m, "," MNTOPT_SWIDTH "=%d",
1984 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
1986 if (!(mp->m_flags & XFS_MOUNT_IDELETE))
1987 seq_printf(m, "," MNTOPT_IKEEP);
1988 if (!(mp->m_flags & XFS_MOUNT_COMPAT_IOSIZE))
1989 seq_printf(m, "," MNTOPT_LARGEIO);
1991 if (!(vfsp->vfs_flag & VFS_32BITINODES))
1992 seq_printf(m, "," MNTOPT_64BITINODE);
1993 if (vfsp->vfs_flag & VFS_GRPID)
1994 seq_printf(m, "," MNTOPT_GRPID);
2000 * Second stage of a freeze. The data is already frozen so we only
2001 * need to take care of themetadata. Once that's done write a dummy
2002 * record to dirty the log in case of a crash while frozen.
2008 xfs_mount_t *mp = XFS_BHVTOM(bdp);
2010 xfs_attr_quiesce(mp);
2011 xfs_fs_log_dummy(mp);
2015 bhv_vfsops_t xfs_vfsops = {
2016 BHV_IDENTITY_INIT(VFS_BHV_XFS,VFS_POSITION_XFS),
2017 .vfs_parseargs = xfs_parseargs,
2018 .vfs_showargs = xfs_showargs,
2019 .vfs_mount = xfs_mount,
2020 .vfs_unmount = xfs_unmount,
2021 .vfs_mntupdate = xfs_mntupdate,
2022 .vfs_root = xfs_root,
2023 .vfs_statvfs = xfs_statvfs,
2024 .vfs_sync = xfs_sync,
2025 .vfs_vget = xfs_vget,
2026 .vfs_dmapiops = (vfs_dmapiops_t)fs_nosys,
2027 .vfs_quotactl = (vfs_quotactl_t)fs_nosys,
2028 .vfs_init_vnode = xfs_initialize_vnode,
2029 .vfs_force_shutdown = xfs_do_force_shutdown,
2030 .vfs_freeze = xfs_freeze,