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"
29 #include "xfs_dmapi.h"
30 #include "xfs_mount.h"
31 #include "xfs_da_btree.h"
32 #include "xfs_bmap_btree.h"
33 #include "xfs_ialloc_btree.h"
34 #include "xfs_alloc_btree.h"
35 #include "xfs_dir_sf.h"
36 #include "xfs_dir2_sf.h"
37 #include "xfs_attr_sf.h"
38 #include "xfs_dinode.h"
39 #include "xfs_inode.h"
40 #include "xfs_inode_item.h"
41 #include "xfs_btree.h"
42 #include "xfs_alloc.h"
43 #include "xfs_ialloc.h"
44 #include "xfs_quota.h"
45 #include "xfs_error.h"
48 #include "xfs_refcache.h"
49 #include "xfs_buf_item.h"
50 #include "xfs_log_priv.h"
51 #include "xfs_dir2_trace.h"
52 #include "xfs_extfree_item.h"
56 #include "xfs_fsops.h"
57 #include "xfs_vnode.h"
59 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_dabuf_zone;
65 extern kmem_zone_t *xfs_buf_item_zone;
67 #ifdef XFS_DABUF_DEBUG
68 extern lock_t xfs_dabuf_global_lock;
75 extern kmem_zone_t *xfs_bmap_free_item_zone;
76 extern kmem_zone_t *xfs_btree_cur_zone;
77 extern kmem_zone_t *xfs_trans_zone;
78 extern kmem_zone_t *xfs_buf_item_zone;
79 extern kmem_zone_t *xfs_dabuf_zone;
81 #ifdef XFS_DABUF_DEBUG
82 spinlock_init(&xfs_dabuf_global_lock, "xfsda");
85 * Initialize all of the zone allocators we use.
87 xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
88 "xfs_bmap_free_item");
89 xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
91 xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
93 kmem_zone_init(sizeof(xfs_da_state_t), "xfs_da_state");
94 xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf");
95 xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
96 xfs_acl_zone_init(xfs_acl_zone, "xfs_acl");
99 * The size of the zone allocated buf log item is the maximum
100 * size possible under XFS. This wastes a little bit of memory,
101 * but it is much faster.
104 kmem_zone_init((sizeof(xfs_buf_log_item_t) +
105 (((XFS_MAX_BLOCKSIZE / XFS_BLI_CHUNK) /
106 NBWORD) * sizeof(int))),
109 kmem_zone_init((sizeof(xfs_efd_log_item_t) +
110 ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
111 sizeof(xfs_extent_t))),
114 kmem_zone_init((sizeof(xfs_efi_log_item_t) +
115 ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
116 sizeof(xfs_extent_t))),
120 * These zones warrant special memory allocator hints
123 kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
124 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM |
125 KM_ZONE_SPREAD, NULL);
127 kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
128 KM_ZONE_SPREAD, NULL);
130 kmem_zone_init_flags(sizeof(xfs_chashlist_t), "xfs_chashlist",
131 KM_ZONE_SPREAD, NULL);
134 * Allocate global trace buffers.
136 #ifdef XFS_ALLOC_TRACE
137 xfs_alloc_trace_buf = ktrace_alloc(XFS_ALLOC_TRACE_SIZE, KM_SLEEP);
139 #ifdef XFS_BMAP_TRACE
140 xfs_bmap_trace_buf = ktrace_alloc(XFS_BMAP_TRACE_SIZE, KM_SLEEP);
142 #ifdef XFS_BMBT_TRACE
143 xfs_bmbt_trace_buf = ktrace_alloc(XFS_BMBT_TRACE_SIZE, KM_SLEEP);
146 xfs_dir_trace_buf = ktrace_alloc(XFS_DIR_TRACE_SIZE, KM_SLEEP);
148 #ifdef XFS_ATTR_TRACE
149 xfs_attr_trace_buf = ktrace_alloc(XFS_ATTR_TRACE_SIZE, KM_SLEEP);
151 #ifdef XFS_DIR2_TRACE
152 xfs_dir2_trace_buf = ktrace_alloc(XFS_DIR2_GTRACE_SIZE, KM_SLEEP);
157 #if (defined(DEBUG) || defined(INDUCE_IO_ERROR))
158 xfs_error_test_init();
159 #endif /* DEBUG || INDUCE_IO_ERROR */
163 xfs_sysctl_register();
171 extern kmem_zone_t *xfs_bmap_free_item_zone;
172 extern kmem_zone_t *xfs_btree_cur_zone;
173 extern kmem_zone_t *xfs_inode_zone;
174 extern kmem_zone_t *xfs_trans_zone;
175 extern kmem_zone_t *xfs_da_state_zone;
176 extern kmem_zone_t *xfs_dabuf_zone;
177 extern kmem_zone_t *xfs_efd_zone;
178 extern kmem_zone_t *xfs_efi_zone;
179 extern kmem_zone_t *xfs_buf_item_zone;
180 extern kmem_zone_t *xfs_chashlist_zone;
183 xfs_cleanup_procfs();
184 xfs_sysctl_unregister();
185 xfs_refcache_destroy();
186 xfs_acl_zone_destroy(xfs_acl_zone);
188 #ifdef XFS_DIR2_TRACE
189 ktrace_free(xfs_dir2_trace_buf);
191 #ifdef XFS_ATTR_TRACE
192 ktrace_free(xfs_attr_trace_buf);
195 ktrace_free(xfs_dir_trace_buf);
197 #ifdef XFS_BMBT_TRACE
198 ktrace_free(xfs_bmbt_trace_buf);
200 #ifdef XFS_BMAP_TRACE
201 ktrace_free(xfs_bmap_trace_buf);
203 #ifdef XFS_ALLOC_TRACE
204 ktrace_free(xfs_alloc_trace_buf);
207 kmem_zone_destroy(xfs_bmap_free_item_zone);
208 kmem_zone_destroy(xfs_btree_cur_zone);
209 kmem_zone_destroy(xfs_inode_zone);
210 kmem_zone_destroy(xfs_trans_zone);
211 kmem_zone_destroy(xfs_da_state_zone);
212 kmem_zone_destroy(xfs_dabuf_zone);
213 kmem_zone_destroy(xfs_buf_item_zone);
214 kmem_zone_destroy(xfs_efd_zone);
215 kmem_zone_destroy(xfs_efi_zone);
216 kmem_zone_destroy(xfs_ifork_zone);
217 kmem_zone_destroy(xfs_ili_zone);
218 kmem_zone_destroy(xfs_chashlist_zone);
224 * This function fills in xfs_mount_t fields based on mount args.
225 * Note: the superblock has _not_ yet been read in.
230 struct xfs_mount_args *ap,
231 struct xfs_mount *mp)
233 /* Values are in BBs */
234 if ((ap->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
236 * At this point the superblock has not been read
237 * in, therefore we do not know the block size.
238 * Before the mount call ends we will convert
241 mp->m_dalign = ap->sunit;
242 mp->m_swidth = ap->swidth;
245 if (ap->logbufs != -1 &&
247 (ap->logbufs < XLOG_MIN_ICLOGS ||
248 ap->logbufs > XLOG_MAX_ICLOGS)) {
250 "XFS: invalid logbufs value: %d [not %d-%d]",
251 ap->logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
252 return XFS_ERROR(EINVAL);
254 mp->m_logbufs = ap->logbufs;
255 if (ap->logbufsize != -1 &&
256 ap->logbufsize != 0 &&
257 ap->logbufsize != 16 * 1024 &&
258 ap->logbufsize != 32 * 1024 &&
259 ap->logbufsize != 64 * 1024 &&
260 ap->logbufsize != 128 * 1024 &&
261 ap->logbufsize != 256 * 1024) {
263 "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
265 return XFS_ERROR(EINVAL);
267 mp->m_ihsize = ap->ihashsize;
268 mp->m_logbsize = ap->logbufsize;
269 mp->m_fsname_len = strlen(ap->fsname) + 1;
270 mp->m_fsname = kmem_alloc(mp->m_fsname_len, KM_SLEEP);
271 strcpy(mp->m_fsname, ap->fsname);
273 mp->m_rtname = kmem_alloc(strlen(ap->rtname) + 1, KM_SLEEP);
274 strcpy(mp->m_rtname, ap->rtname);
276 if (ap->logname[0]) {
277 mp->m_logname = kmem_alloc(strlen(ap->logname) + 1, KM_SLEEP);
278 strcpy(mp->m_logname, ap->logname);
281 if (ap->flags & XFSMNT_WSYNC)
282 mp->m_flags |= XFS_MOUNT_WSYNC;
284 if (ap->flags & XFSMNT_INO64) {
285 mp->m_flags |= XFS_MOUNT_INO64;
286 mp->m_inoadd = XFS_INO64_OFFSET;
289 if (ap->flags & XFSMNT_RETERR)
290 mp->m_flags |= XFS_MOUNT_RETERR;
291 if (ap->flags & XFSMNT_NOALIGN)
292 mp->m_flags |= XFS_MOUNT_NOALIGN;
293 if (ap->flags & XFSMNT_SWALLOC)
294 mp->m_flags |= XFS_MOUNT_SWALLOC;
295 if (ap->flags & XFSMNT_OSYNCISOSYNC)
296 mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
297 if (ap->flags & XFSMNT_32BITINODES)
298 mp->m_flags |= XFS_MOUNT_32BITINODES;
300 if (ap->flags & XFSMNT_IOSIZE) {
301 if (ap->iosizelog > XFS_MAX_IO_LOG ||
302 ap->iosizelog < XFS_MIN_IO_LOG) {
304 "XFS: invalid log iosize: %d [not %d-%d]",
305 ap->iosizelog, XFS_MIN_IO_LOG,
307 return XFS_ERROR(EINVAL);
310 mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
311 mp->m_readio_log = mp->m_writeio_log = ap->iosizelog;
314 if (ap->flags & XFSMNT_IHASHSIZE)
315 mp->m_flags |= XFS_MOUNT_IHASHSIZE;
316 if (ap->flags & XFSMNT_IDELETE)
317 mp->m_flags |= XFS_MOUNT_IDELETE;
318 if (ap->flags & XFSMNT_DIRSYNC)
319 mp->m_flags |= XFS_MOUNT_DIRSYNC;
320 if (ap->flags & XFSMNT_ATTR2)
321 mp->m_flags |= XFS_MOUNT_ATTR2;
323 if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
324 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
327 * no recovery flag requires a read-only mount
329 if (ap->flags & XFSMNT_NORECOVERY) {
330 if (!(vfs->vfs_flag & VFS_RDONLY)) {
332 "XFS: tried to mount a FS read-write without recovery!");
333 return XFS_ERROR(EINVAL);
335 mp->m_flags |= XFS_MOUNT_NORECOVERY;
338 if (ap->flags & XFSMNT_NOUUID)
339 mp->m_flags |= XFS_MOUNT_NOUUID;
340 if (ap->flags & XFSMNT_BARRIER)
341 mp->m_flags |= XFS_MOUNT_BARRIER;
343 mp->m_flags &= ~XFS_MOUNT_BARRIER;
349 * This function fills in xfs_mount_t fields based on mount args.
350 * Note: the superblock _has_ now been read in.
355 struct xfs_mount_args *ap,
356 struct xfs_mount *mp)
358 int ronly = (vfs->vfs_flag & VFS_RDONLY);
360 /* Fail a mount where the logbuf is smaller then the log stripe */
361 if (XFS_SB_VERSION_HASLOGV2(&mp->m_sb)) {
362 if ((ap->logbufsize <= 0) &&
363 (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) {
364 mp->m_logbsize = mp->m_sb.sb_logsunit;
365 } else if (ap->logbufsize > 0 &&
366 ap->logbufsize < mp->m_sb.sb_logsunit) {
368 "XFS: logbuf size must be greater than or equal to log stripe size");
369 return XFS_ERROR(EINVAL);
372 /* Fail a mount if the logbuf is larger than 32K */
373 if (ap->logbufsize > XLOG_BIG_RECORD_BSIZE) {
375 "XFS: logbuf size for version 1 logs must be 16K or 32K");
376 return XFS_ERROR(EINVAL);
380 if (XFS_SB_VERSION_HASATTR2(&mp->m_sb)) {
381 mp->m_flags |= XFS_MOUNT_ATTR2;
385 * prohibit r/w mounts of read-only filesystems
387 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
389 "XFS: cannot mount a read-only filesystem as read-write");
390 return XFS_ERROR(EROFS);
394 * check for shared mount.
396 if (ap->flags & XFSMNT_SHARED) {
397 if (!XFS_SB_VERSION_HASSHARED(&mp->m_sb))
398 return XFS_ERROR(EINVAL);
401 * For IRIX 6.5, shared mounts must have the shared
402 * version bit set, have the persistent readonly
403 * field set, must be version 0 and can only be mounted
406 if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) ||
407 (mp->m_sb.sb_shared_vn != 0))
408 return XFS_ERROR(EINVAL);
410 mp->m_flags |= XFS_MOUNT_SHARED;
413 * Shared XFS V0 can't deal with DMI. Return EINVAL.
415 if (mp->m_sb.sb_shared_vn == 0 && (ap->flags & XFSMNT_DMAPI))
416 return XFS_ERROR(EINVAL);
425 * The file system configurations are:
426 * (1) device (partition) with data and internal log
427 * (2) logical volume with data and log subvolumes.
428 * (3) logical volume with data, log, and realtime subvolumes.
430 * We only have to handle opening the log and realtime volumes here if
431 * they are present. The data subvolume has already been opened by
432 * get_sb_bdev() and is stored in vfsp->vfs_super->s_bdev.
436 struct bhv_desc *bhvp,
437 struct xfs_mount_args *args,
440 struct xfs_vfs *vfsp = bhvtovfs(bhvp);
442 struct xfs_mount *mp = XFS_BHVTOM(bhvp);
443 struct vnode *ddev, *logdev, *rtdev;
444 int flags = 0, error;
446 ddev = logdev = rtdev = NULL;
448 error = xfs_blkdev_get(mp, args->fsname, &ddev);
453 * Setup xfs_mount function vectors from available behaviors
455 p = vfs_bhv_lookup(vfsp, VFS_POSITION_DM);
456 mp->m_dm_ops = p ? *(xfs_dmops_t *) vfs_bhv_custom(p) : xfs_dmcore_stub;
457 p = vfs_bhv_lookup(vfsp, VFS_POSITION_QM);
458 mp->m_qm_ops = p ? *(xfs_qmops_t *) vfs_bhv_custom(p) : xfs_qmcore_stub;
459 p = vfs_bhv_lookup(vfsp, VFS_POSITION_IO);
460 mp->m_io_ops = p ? *(xfs_ioops_t *) vfs_bhv_custom(p) : xfs_iocore_xfs;
462 if (args->flags & XFSMNT_QUIET)
463 flags |= XFS_MFSI_QUIET;
466 * Open real time and log devices - order is important.
468 if (args->logname[0]) {
469 error = xfs_blkdev_get(mp, args->logname, &logdev);
471 xfs_blkdev_put(ddev);
475 if (args->rtname[0]) {
476 error = xfs_blkdev_get(mp, args->rtname, &rtdev);
478 xfs_blkdev_put(logdev);
479 xfs_blkdev_put(ddev);
483 if (rtdev == ddev || rtdev == logdev) {
485 "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
486 xfs_blkdev_put(logdev);
487 xfs_blkdev_put(rtdev);
488 xfs_blkdev_put(ddev);
494 * Setup xfs_mount buffer target pointers
497 mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
498 if (!mp->m_ddev_targp) {
499 xfs_blkdev_put(logdev);
500 xfs_blkdev_put(rtdev);
504 mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
505 if (!mp->m_rtdev_targp)
508 mp->m_logdev_targp = (logdev && logdev != ddev) ?
509 xfs_alloc_buftarg(logdev, 1) : mp->m_ddev_targp;
510 if (!mp->m_logdev_targp)
514 * Setup flags based on mount(2) options and then the superblock
516 error = xfs_start_flags(vfsp, args, mp);
519 error = xfs_readsb(mp, flags);
522 error = xfs_finish_flags(vfsp, args, mp);
527 * Setup xfs_mount buffer target pointers based on superblock
529 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
530 mp->m_sb.sb_sectsize);
531 if (!error && logdev && logdev != ddev) {
532 unsigned int log_sector_size = BBSIZE;
534 if (XFS_SB_VERSION_HASSECTOR(&mp->m_sb))
535 log_sector_size = mp->m_sb.sb_logsectsize;
536 error = xfs_setsize_buftarg(mp->m_logdev_targp,
537 mp->m_sb.sb_blocksize,
541 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
542 mp->m_sb.sb_blocksize,
543 mp->m_sb.sb_sectsize);
547 if ((mp->m_flags & XFS_MOUNT_BARRIER) && !(vfsp->vfs_flag & VFS_RDONLY))
548 xfs_mountfs_check_barriers(mp);
550 error = XFS_IOINIT(vfsp, args, flags);
560 xfs_binval(mp->m_ddev_targp);
561 if (logdev && logdev != ddev)
562 xfs_binval(mp->m_logdev_targp);
564 xfs_binval(mp->m_rtdev_targp);
566 xfs_unmountfs_close(mp, credp);
576 struct xfs_vfs *vfsp = bhvtovfs(bdp);
577 xfs_mount_t *mp = XFS_BHVTOM(bdp);
580 int unmount_event_wanted = 0;
581 int unmount_event_flags = 0;
582 int xfs_unmountfs_needed = 0;
588 if (vfsp->vfs_flag & VFS_DMI) {
589 error = XFS_SEND_PREUNMOUNT(mp, vfsp,
590 rvp, DM_RIGHT_NULL, rvp, DM_RIGHT_NULL,
592 (mp->m_dmevmask & (1<<DM_EVENT_PREUNMOUNT))?
593 0:DM_FLAGS_UNWANTED);
595 return XFS_ERROR(error);
596 unmount_event_wanted = 1;
597 unmount_event_flags = (mp->m_dmevmask & (1<<DM_EVENT_UNMOUNT))?
598 0 : DM_FLAGS_UNWANTED;
602 * Linux (& presumably Irix) do not reach this code if
603 * any of this FS vnodes have active references. FreeBSD
604 * relies on FS to clean after itself.
609 * First blow any referenced inode from this file system
610 * out of the reference cache, and delete the timer.
612 xfs_refcache_purge_mp(mp);
614 XFS_bflush(mp->m_ddev_targp);
615 error = xfs_unmount_flush(mp, 0);
619 ASSERT(vn_count(rvp) == 1);
622 * Drop the reference count
627 * If we're forcing a shutdown, typically because of a media error,
628 * we want to make sure we invalidate dirty pages that belong to
629 * referenced vnodes as well.
631 if (XFS_FORCED_SHUTDOWN(mp)) {
632 error = xfs_sync(&mp->m_bhv,
633 (SYNC_WAIT | SYNC_CLOSE), credp);
634 ASSERT(error != EFSCORRUPTED);
636 xfs_unmountfs_needed = 1;
639 /* Send DMAPI event, if required.
640 * Then do xfs_unmountfs() if needed.
641 * Then return error (or zero).
643 if (unmount_event_wanted) {
644 /* Note: mp structure must still exist for
645 * XFS_SEND_UNMOUNT() call.
647 XFS_SEND_UNMOUNT(mp, vfsp, error == 0 ? rvp : NULL,
648 DM_RIGHT_NULL, 0, error, unmount_event_flags);
650 if (xfs_unmountfs_needed) {
652 * Call common unmount function to flush to disk
653 * and free the super block buffer & mount structures.
655 xfs_unmountfs(mp, credp);
658 return XFS_ERROR(error);
665 int count = 0, pincount;
667 xfs_refcache_purge_mp(mp);
668 xfs_flush_buftarg(mp->m_ddev_targp, 0);
669 xfs_finish_reclaim_all(mp, 0);
671 /* This loop must run at least twice.
672 * The first instance of the loop will flush
673 * most meta data but that will generate more
674 * meta data (typically directory updates).
675 * Which then must be flushed and logged before
676 * we can write the unmount record.
679 xfs_syncsub(mp, SYNC_REMOUNT|SYNC_ATTR|SYNC_WAIT, 0, NULL);
680 pincount = xfs_flush_buftarg(mp->m_ddev_targp, 1);
691 #define pagebuf_delwri_flush(a,b,c) \
693 printf("pagebuf_delwri_flush NI\n"); \
694 if (c) *((int *)(c)) = 0; \
701 struct xfs_mount_args *args)
703 struct xfs_vfs *vfsp = bhvtovfs(bdp);
704 xfs_mount_t *mp = XFS_BHVTOM(bdp);
708 if (!(*flags & MS_RDONLY)) { /* rw/ro -> rw */
710 if (!(*flags & VFS_RDONLY)) { /* rw/ro -> rw */
711 if (vfsp->vfs_flag & VFS_RDONLY)
712 vfsp->vfs_flag &= ~VFS_RDONLY;
713 if (args->flags & XFSMNT_BARRIER) {
714 mp->m_flags |= XFS_MOUNT_BARRIER;
715 xfs_mountfs_check_barriers(mp);
717 mp->m_flags &= ~XFS_MOUNT_BARRIER;
719 } else if (!(vfsp->vfs_flag & VFS_RDONLY)) { /* rw -> ro */
720 XVFS_SYNC(vfsp, SYNC_FSDATA|SYNC_BDFLUSH|SYNC_ATTR, NULL, error);
722 xfs_log_unmount_write(mp);
723 xfs_unmountfs_writesb(mp);
724 vfsp->vfs_flag |= VFS_RDONLY;
730 * xfs_unmount_flush implements a set of flush operation on special
731 * inodes, which are needed as a separate set of operations so that
732 * they can be called as part of relocation process.
736 xfs_mount_t *mp, /* Mount structure we are getting
738 int relocation) /* Called from vfs relocation. */
740 xfs_inode_t *rip = mp->m_rootip;
742 xfs_inode_t *rsumip = NULL;
743 xfs_vnode_t *rvp = XFS_ITOV_NULL(rip);
748 xfs_ilock(rip, XFS_ILOCK_EXCL);
752 * Flush out the real time inodes.
754 if ((rbmip = mp->m_rbmip) != NULL) {
755 xfs_ilock(rbmip, XFS_ILOCK_EXCL);
757 error = xfs_iflush(rbmip, XFS_IFLUSH_SYNC);
758 xfs_iunlock(rbmip, XFS_ILOCK_EXCL);
760 if (error == EFSCORRUPTED)
763 ASSERT(vn_count(XFS_ITOV(rbmip)) == 1);
765 rsumip = mp->m_rsumip;
766 xfs_ilock(rsumip, XFS_ILOCK_EXCL);
768 error = xfs_iflush(rsumip, XFS_IFLUSH_SYNC);
769 xfs_iunlock(rsumip, XFS_ILOCK_EXCL);
771 if (error == EFSCORRUPTED)
774 ASSERT(vn_count(XFS_ITOV(rsumip)) == 1);
778 * Synchronously flush root inode to disk
780 error = xfs_iflush(rip, XFS_IFLUSH_SYNC);
781 if (error == EFSCORRUPTED)
784 if (vn_count(rvp) != 1 && !relocation) {
785 xfs_iunlock(rip, XFS_ILOCK_EXCL);
786 return XFS_ERROR(EBUSY);
790 * Release dquot that rootinode, rbmino and rsumino might be holding,
791 * flush and purge the quota inodes.
793 error = XFS_QM_UNMOUNT(mp);
794 if (error == EFSCORRUPTED)
798 VN_RELE(XFS_ITOV(rbmip));
799 VN_RELE(XFS_ITOV(rsumip));
802 xfs_iunlock(rip, XFS_ILOCK_EXCL);
809 xfs_iunlock(rip, XFS_ILOCK_EXCL);
811 return XFS_ERROR(EFSCORRUPTED);
815 * xfs_root extracts the root vnode from a vfs.
817 * vfsp -- the vfs struct for the desired file system
818 * vpp -- address of the caller's vnode pointer which should be
819 * set to the desired fs root vnode
828 vp = XFS_ITOV((XFS_BHVTOM(bdp))->m_rootip);
837 * Fill in the statvfs structure for the given file system. We use
838 * the superblock lock in the mount structure to ensure a consistent
839 * snapshot of the counters returned.
853 mp = XFS_BHVTOM(bdp);
856 statp->f_type = XFS_SB_MAGIC;
858 xfs_icsb_sync_counters_lazy(mp);
860 statp->f_bsize = sbp->sb_blocksize;
861 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
862 statp->f_blocks = sbp->sb_dblocks - lsize;
863 statp->f_bfree = statp->f_bavail = sbp->sb_fdblocks;
864 fakeinos = statp->f_bfree << sbp->sb_inopblog;
866 fakeinos += mp->m_inoadd;
869 MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
874 statp->f_files = min_t(typeof(statp->f_files),
877 statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
878 XFS_SB_UNLOCK(mp, s);
880 xfs_statvfs_fsid(statp, mp);
886 * xfs_sync flushes any pending I/O to file system vfsp.
888 * This routine is called by vfs_sync() to make sure that things make it
889 * out to disk eventually, on sync() system calls to flush out everything,
890 * and when the file system is unmounted. For the vfs_sync() case, all
891 * we really need to do is sync out the log to make all of our meta-data
892 * updates permanent (except for timestamps). For calls from pflushd(),
893 * dirty pages are kept moving by calling pdflush() on the inodes
894 * containing them. We also flush the inodes that we can lock without
895 * sleeping and the superblock if we can lock it without sleeping from
896 * vfs_sync() so that items at the tail of the log are always moving out.
899 * SYNC_BDFLUSH - We're being called from vfs_sync() so we don't want
900 * to sleep if we can help it. All we really need
901 * to do is ensure that the log is synced at least
902 * periodically. We also push the inodes and
903 * superblock if we can lock them without sleeping
904 * and they are not pinned.
905 * SYNC_ATTR - We need to flush the inodes. If SYNC_BDFLUSH is not
906 * set, then we really want to lock each inode and flush
908 * SYNC_WAIT - All the flushes that take place in this call should
910 * SYNC_DELWRI - This tells us to push dirty pages associated with
911 * inodes. SYNC_WAIT and SYNC_BDFLUSH are used to
912 * determine if they should be flushed sync, async, or
914 * SYNC_CLOSE - This flag is passed when the system is being
915 * unmounted. We should sync and invalidate everything.
916 * SYNC_FSDATA - This indicates that the caller would like to make
917 * sure the superblock is safe on disk. We can ensure
918 * this by simply making sure the log gets flushed
919 * if SYNC_BDFLUSH is set, and by actually writing it
930 xfs_mount_t *mp = XFS_BHVTOM(bdp);
932 if (unlikely(flags == SYNC_QUIESCE))
933 return xfs_quiesce_fs(mp);
935 return xfs_syncsub(mp, flags, 0, NULL);
939 * xfs sync routine for internal use
941 * This routine supports all of the flags defined for the generic VFS_SYNC
942 * interface as explained above under xfs_sync. In the interests of not
943 * changing interfaces within the 6.5 family, additional internally-
944 * required functions are specified within a separate xflags parameter,
945 * only available by calling this routine.
955 xfs_inode_t *ip = NULL;
956 xfs_inode_t *ip_next;
958 xfs_vnode_t *vp = NULL;
963 uint base_lock_flags;
964 boolean_t mount_locked;
965 boolean_t vnode_refed;
968 xfs_iptr_t *ipointer;
970 boolean_t ipointer_in = B_FALSE;
972 #define IPOINTER_SET ipointer_in = B_TRUE
973 #define IPOINTER_CLR ipointer_in = B_FALSE
980 /* Insert a marker record into the inode list after inode ip. The list
981 * must be locked when this is called. After the call the list will no
984 #define IPOINTER_INSERT(ip, mp) { \
985 ASSERT(ipointer_in == B_FALSE); \
986 ipointer->ip_mnext = ip->i_mnext; \
987 ipointer->ip_mprev = ip; \
988 ip->i_mnext = (xfs_inode_t *)ipointer; \
989 ipointer->ip_mnext->i_mprev = (xfs_inode_t *)ipointer; \
991 XFS_MOUNT_IUNLOCK(mp); \
992 mount_locked = B_FALSE; \
996 /* Remove the marker from the inode list. If the marker was the only item
997 * in the list then there are no remaining inodes and we should zero out
998 * the whole list. If we are the current head of the list then move the head
1001 #define IPOINTER_REMOVE(ip, mp) { \
1002 ASSERT(ipointer_in == B_TRUE); \
1003 if (ipointer->ip_mnext != (xfs_inode_t *)ipointer) { \
1004 ip = ipointer->ip_mnext; \
1005 ip->i_mprev = ipointer->ip_mprev; \
1006 ipointer->ip_mprev->i_mnext = ip; \
1007 if (mp->m_inodes == (xfs_inode_t *)ipointer) { \
1008 mp->m_inodes = ip; \
1011 ASSERT(mp->m_inodes == (xfs_inode_t *)ipointer); \
1012 mp->m_inodes = NULL; \
1018 #define XFS_PREEMPT_MASK 0x7f
1022 if (XFS_MTOVFS(mp)->vfs_flag & VFS_RDONLY)
1028 /* Allocate a reference marker */
1029 ipointer = (xfs_iptr_t *)kmem_zalloc(sizeof(xfs_iptr_t), KM_SLEEP);
1031 fflag = XFS_B_ASYNC; /* default is don't wait */
1032 if (flags & (SYNC_BDFLUSH | SYNC_DELWRI))
1033 fflag = XFS_B_DELWRI;
1034 if (flags & SYNC_WAIT)
1035 fflag = 0; /* synchronous overrides all */
1037 base_lock_flags = XFS_ILOCK_SHARED;
1038 if (flags & (SYNC_DELWRI | SYNC_CLOSE)) {
1040 * We need the I/O lock if we're going to call any of
1041 * the flush/inval routines.
1043 base_lock_flags |= XFS_IOLOCK_SHARED;
1046 XFS_MOUNT_ILOCK(mp);
1050 mount_locked = B_TRUE;
1051 vnode_refed = B_FALSE;
1056 ASSERT(ipointer_in == B_FALSE);
1057 ASSERT(vnode_refed == B_FALSE);
1059 lock_flags = base_lock_flags;
1062 * There were no inodes in the list, just break out
1070 * We found another sync thread marker - skip it
1072 if (ip->i_mount == NULL) {
1077 vp = XFS_ITOV_NULL(ip);
1080 * If the vnode is gone then this is being torn down,
1081 * call reclaim if it is flushed, else let regular flush
1082 * code deal with it later in the loop.
1086 /* Skip ones already in reclaim */
1087 if (ip->i_flags & XFS_IRECLAIM) {
1091 if (xfs_ilock_nowait(ip, XFS_ILOCK_EXCL) == 0) {
1093 } else if ((xfs_ipincount(ip) == 0) &&
1094 xfs_iflock_nowait(ip)) {
1095 IPOINTER_INSERT(ip, mp);
1097 xfs_finish_reclaim(ip, 1,
1098 XFS_IFLUSH_DELWRI_ELSE_ASYNC);
1100 XFS_MOUNT_ILOCK(mp);
1101 mount_locked = B_TRUE;
1102 IPOINTER_REMOVE(ip, mp);
1104 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1115 if (XFS_FORCED_SHUTDOWN(mp) && !(flags & SYNC_CLOSE)) {
1116 XFS_MOUNT_IUNLOCK(mp);
1117 kmem_free(ipointer, sizeof(xfs_iptr_t));
1122 * If this is just vfs_sync() or pflushd() calling
1123 * then we can skip inodes for which it looks like
1124 * there is nothing to do. Since we don't have the
1125 * inode locked this is racy, but these are periodic
1126 * calls so it doesn't matter. For the others we want
1127 * to know for sure, so we at least try to lock them.
1129 if (flags & SYNC_BDFLUSH) {
1130 if (((ip->i_itemp == NULL) ||
1131 !(ip->i_itemp->ili_format.ilf_fields &
1133 (ip->i_update_core == 0)) {
1140 * Try to lock without sleeping. We're out of order with
1141 * the inode list lock here, so if we fail we need to drop
1142 * the mount lock and try again. If we're called from
1143 * bdflush() here, then don't bother.
1145 * The inode lock here actually coordinates with the
1146 * almost spurious inode lock in xfs_ireclaim() to prevent
1147 * the vnode we handle here without a reference from
1148 * being freed while we reference it. If we lock the inode
1149 * while it's on the mount list here, then the spurious inode
1150 * lock in xfs_ireclaim() after the inode is pulled from
1151 * the mount list will sleep until we release it here.
1152 * This keeps the vnode from being freed while we reference
1155 if (xfs_ilock_nowait(ip, lock_flags) == 0) {
1156 if ((flags & SYNC_BDFLUSH) || (vp == NULL)) {
1167 IPOINTER_INSERT(ip, mp);
1168 xfs_ilock(ip, lock_flags);
1170 ASSERT(vp == XFS_ITOV(ip));
1171 ASSERT(ip->i_mount == mp);
1173 vnode_refed = B_TRUE;
1176 /* From here on in the loop we may have a marker record
1177 * in the inode list.
1180 if ((flags & SYNC_CLOSE) && (vp != NULL)) {
1182 * This is the shutdown case. We just need to
1183 * flush and invalidate all the pages associated
1184 * with the inode. Drop the inode lock since
1185 * we can't hold it across calls to the buffer
1188 * We don't set the VREMAPPING bit in the vnode
1189 * here, because we don't hold the vnode lock
1190 * exclusively. It doesn't really matter, though,
1191 * because we only come here when we're shutting
1194 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1196 if (XFS_FORCED_SHUTDOWN(mp)) {
1197 XVOP_TOSS_PAGES(vp, 0, -1, FI_REMAPF);
1199 XVOP_FLUSHINVAL_PAGES(vp, 0, -1, FI_REMAPF);
1202 xfs_ilock(ip, XFS_ILOCK_SHARED);
1204 } else if ((flags & SYNC_DELWRI) && (vp != NULL)) {
1206 /* We need to have dropped the lock here,
1207 * so insert a marker if we have not already
1211 IPOINTER_INSERT(ip, mp);
1215 * Drop the inode lock since we can't hold it
1216 * across calls to the buffer cache.
1218 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1219 XVOP_FLUSH_PAGES(vp, (xfs_off_t)0, -1,
1220 fflag, FI_NONE, error);
1221 xfs_ilock(ip, XFS_ILOCK_SHARED);
1226 if (flags & SYNC_BDFLUSH) {
1227 if ((flags & SYNC_ATTR) &&
1228 ((ip->i_update_core) ||
1229 ((ip->i_itemp != NULL) &&
1230 (ip->i_itemp->ili_format.ilf_fields != 0)))) {
1232 /* Insert marker and drop lock if not already
1236 IPOINTER_INSERT(ip, mp);
1240 * We don't want the periodic flushing of the
1241 * inodes by vfs_sync() to interfere with
1242 * I/O to the file, especially read I/O
1243 * where it is only the access time stamp
1244 * that is being flushed out. To prevent
1245 * long periods where we have both inode
1246 * locks held shared here while reading the
1247 * inode's buffer in from disk, we drop the
1248 * inode lock while reading in the inode
1249 * buffer. We have to release the buffer
1250 * and reacquire the inode lock so that they
1251 * are acquired in the proper order (inode
1252 * locks first). The buffer will go at the
1253 * end of the lru chain, though, so we can
1254 * expect it to still be there when we go
1255 * for it again in xfs_iflush().
1257 if ((xfs_ipincount(ip) == 0) &&
1258 xfs_iflock_nowait(ip)) {
1261 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1263 error = xfs_itobp(mp, NULL, ip,
1268 /* Bailing out, remove the
1269 * marker and free it.
1271 XFS_MOUNT_ILOCK(mp);
1273 IPOINTER_REMOVE(ip, mp);
1275 XFS_MOUNT_IUNLOCK(mp);
1277 ASSERT(!(lock_flags &
1278 XFS_IOLOCK_SHARED));
1281 sizeof(xfs_iptr_t));
1286 * Since we dropped the inode lock,
1287 * the inode may have been reclaimed.
1288 * Therefore, we reacquire the mount
1289 * lock and check to see if we were the
1290 * inode reclaimed. If this happened
1291 * then the ipointer marker will no
1292 * longer point back at us. In this
1293 * case, move ip along to the inode
1294 * after the marker, remove the marker
1297 XFS_MOUNT_ILOCK(mp);
1298 mount_locked = B_TRUE;
1300 if (ip != ipointer->ip_mprev) {
1301 IPOINTER_REMOVE(ip, mp);
1303 ASSERT(!vnode_refed);
1304 ASSERT(!(lock_flags &
1305 XFS_IOLOCK_SHARED));
1309 ASSERT(ip->i_mount == mp);
1311 if (xfs_ilock_nowait(ip,
1312 XFS_ILOCK_SHARED) == 0) {
1313 ASSERT(ip->i_mount == mp);
1315 * We failed to reacquire
1316 * the inode lock without
1317 * sleeping, so just skip
1318 * the inode for now. We
1319 * clear the ILOCK bit from
1320 * the lock_flags so that we
1321 * won't try to drop a lock
1322 * we don't hold below.
1324 lock_flags &= ~XFS_ILOCK_SHARED;
1325 IPOINTER_REMOVE(ip_next, mp);
1326 } else if ((xfs_ipincount(ip) == 0) &&
1327 xfs_iflock_nowait(ip)) {
1328 ASSERT(ip->i_mount == mp);
1330 * Since this is vfs_sync()
1331 * calling we only flush the
1332 * inode out if we can lock
1333 * it without sleeping and
1334 * it is not pinned. Drop
1335 * the mount lock here so
1336 * that we don't hold it for
1337 * too long. We already have
1338 * a marker in the list here.
1340 XFS_MOUNT_IUNLOCK(mp);
1341 mount_locked = B_FALSE;
1342 error = xfs_iflush(ip,
1345 ASSERT(ip->i_mount == mp);
1346 IPOINTER_REMOVE(ip_next, mp);
1353 if ((flags & SYNC_ATTR) &&
1354 ((ip->i_update_core) ||
1355 ((ip->i_itemp != NULL) &&
1356 (ip->i_itemp->ili_format.ilf_fields != 0)))) {
1358 IPOINTER_INSERT(ip, mp);
1361 if (flags & SYNC_WAIT) {
1363 error = xfs_iflush(ip,
1367 * If we can't acquire the flush
1368 * lock, then the inode is already
1369 * being flushed so don't bother
1370 * waiting. If we can lock it then
1371 * do a delwri flush so we can
1372 * combine multiple inode flushes
1373 * in each disk write.
1375 if (xfs_iflock_nowait(ip)) {
1376 error = xfs_iflush(ip,
1385 if (lock_flags != 0) {
1386 xfs_iunlock(ip, lock_flags);
1391 * If we had to take a reference on the vnode
1392 * above, then wait until after we've unlocked
1393 * the inode to release the reference. This is
1394 * because we can be already holding the inode
1395 * lock when VN_RELE() calls xfs_inactive().
1397 * Make sure to drop the mount lock before calling
1398 * VN_RELE() so that we don't trip over ourselves if
1399 * we have to go for the mount lock again in the
1403 IPOINTER_INSERT(ip, mp);
1408 vnode_refed = B_FALSE;
1416 * bail out if the filesystem is corrupted.
1418 if (error == EFSCORRUPTED) {
1419 if (!mount_locked) {
1420 XFS_MOUNT_ILOCK(mp);
1421 IPOINTER_REMOVE(ip, mp);
1423 XFS_MOUNT_IUNLOCK(mp);
1424 ASSERT(ipointer_in == B_FALSE);
1425 kmem_free(ipointer, sizeof(xfs_iptr_t));
1426 return XFS_ERROR(error);
1429 /* Let other threads have a chance at the mount lock
1430 * if we have looped many times without dropping the
1433 if ((++preempt & XFS_PREEMPT_MASK) == 0) {
1435 IPOINTER_INSERT(ip, mp);
1439 if (mount_locked == B_FALSE) {
1440 XFS_MOUNT_ILOCK(mp);
1441 mount_locked = B_TRUE;
1442 IPOINTER_REMOVE(ip, mp);
1446 ASSERT(ipointer_in == B_FALSE);
1449 } while (ip != mp->m_inodes);
1451 XFS_MOUNT_IUNLOCK(mp);
1453 ASSERT(ipointer_in == B_FALSE);
1455 kmem_free(ipointer, sizeof(xfs_iptr_t));
1456 return XFS_ERROR(last_error);
1460 * xfs sync routine for internal use
1462 * This routine supports all of the flags defined for the generic VFS_SYNC
1463 * interface as explained above under xfs_sync. In the interests of not
1464 * changing interfaces within the 6.5 family, additional internally-
1465 * required functions are specified within a separate xflags parameter,
1466 * only available by calling this routine.
1478 uint log_flags = XFS_LOG_FORCE;
1480 xfs_buf_log_item_t *bip;
1483 * Sync out the log. This ensures that the log is periodically
1484 * flushed even if there is not enough activity to fill it up.
1486 if (flags & SYNC_WAIT)
1487 log_flags |= XFS_LOG_SYNC;
1489 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1491 if (flags & (SYNC_ATTR|SYNC_DELWRI)) {
1492 if (flags & SYNC_BDFLUSH)
1493 xfs_finish_reclaim_all(mp, 1);
1495 error = xfs_sync_inodes(mp, flags, xflags, bypassed);
1499 * Flushing out dirty data above probably generated more
1500 * log activity, so if this isn't vfs_sync() then flush
1503 if (flags & SYNC_DELWRI) {
1504 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1507 if (flags & SYNC_FSDATA) {
1509 * If this is vfs_sync() then only sync the superblock
1510 * if we can lock it without sleeping and it is not pinned.
1512 if (flags & SYNC_BDFLUSH) {
1513 bp = xfs_getsb(mp, XFS_BUF_TRYLOCK);
1515 bip = XFS_BUF_FSPRIVATE(bp,xfs_buf_log_item_t*);
1516 if ((bip != NULL) &&
1517 xfs_buf_item_dirty(bip)) {
1518 if (!(XFS_BUF_ISPINNED(bp))) {
1520 error = xfs_bwrite(mp, bp);
1529 bp = xfs_getsb(mp, 0);
1531 * If the buffer is pinned then push on the log so
1532 * we won't get stuck waiting in the write for
1533 * someone, maybe ourselves, to flush the log.
1534 * Even though we just pushed the log above, we
1535 * did not have the superblock buffer locked at
1536 * that point so it can become pinned in between
1539 if (XFS_BUF_ISPINNED(bp))
1540 xfs_log_force(mp, (xfs_lsn_t)0, XFS_LOG_FORCE);
1541 if (flags & SYNC_WAIT)
1542 XFS_BUF_UNASYNC(bp);
1545 error = xfs_bwrite(mp, bp);
1553 * If this is the periodic sync, then kick some entries out of
1554 * the reference cache. This ensures that idle entries are
1555 * eventually kicked out of the cache.
1557 if (flags & SYNC_REFCACHE) {
1558 if (flags & SYNC_WAIT)
1559 xfs_refcache_purge_mp(mp);
1561 xfs_refcache_purge_some(mp);
1565 * Now check to see if the log needs a "dummy" transaction.
1568 if (!(flags & SYNC_REMOUNT) && xfs_log_need_covered(mp)) {
1573 * Put a dummy transaction in the log to tell
1574 * recovery that all others are OK.
1576 tp = xfs_trans_alloc(mp, XFS_TRANS_DUMMY1);
1577 if ((error = xfs_trans_reserve(tp, 0,
1578 XFS_ICHANGE_LOG_RES(mp),
1580 xfs_trans_cancel(tp, 0);
1585 xfs_ilock(ip, XFS_ILOCK_EXCL);
1587 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
1588 xfs_trans_ihold(tp, ip);
1589 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
1590 error = xfs_trans_commit(tp, 0, NULL);
1591 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1592 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1596 * When shutting down, we need to insure that the AIL is pushed
1597 * to disk or the filesystem can appear corrupt from the PROM.
1599 if ((flags & (SYNC_CLOSE|SYNC_WAIT)) == (SYNC_CLOSE|SYNC_WAIT)) {
1600 XFS_bflush(mp->m_ddev_targp);
1601 if (mp->m_rtdev_targp) {
1602 XFS_bflush(mp->m_rtdev_targp);
1606 return XFS_ERROR(last_error);
1610 * xfs_vget - called by DMAPI and NFSD to get vnode from file handle
1618 xfs_mount_t *mp = XFS_BHVTOM(bdp);
1619 xfs_fid_t *xfid = (struct xfs_fid *)fidp;
1626 * Invalid. Since handles can be created in user space and passed in
1627 * via gethandle(), this is not cause for a panic.
1629 if (xfid->xfs_fid_len != sizeof(*xfid) - sizeof(xfid->xfs_fid_len))
1630 return XFS_ERROR(EINVAL);
1632 ino = xfid->xfs_fid_ino;
1633 igen = xfid->xfs_fid_gen;
1636 * NFS can sometimes send requests for ino 0. Fail them gracefully.
1639 return XFS_ERROR(ESTALE);
1641 error = xfs_iget(mp, NULL, ino, 0, XFS_ILOCK_SHARED, &ip, 0);
1649 return XFS_ERROR(EIO);
1652 if (ip->i_d.di_mode == 0 || ip->i_d.di_gen != igen) {
1653 xfs_iput_new(ip, XFS_ILOCK_SHARED);
1655 return XFS_ERROR(ENOENT);
1658 *vpp = XFS_ITOV(ip);
1659 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1664 #define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
1665 #define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
1666 #define MNTOPT_LOGDEV "logdev" /* log device */
1667 #define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
1668 #define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
1669 #define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
1670 #define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
1671 #define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
1672 #define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
1673 #define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
1674 #define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
1675 #define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
1676 #define MNTOPT_MTPT "mtpt" /* filesystem mount point */
1677 #define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
1678 #define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
1679 #define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
1680 #define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
1681 #define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
1682 #define MNTOPT_IHASHSIZE "ihashsize" /* size of inode hash table */
1683 #define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
1684 #define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
1685 * unwritten extent conversion */
1686 #define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
1687 #define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
1688 #define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
1689 #define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
1690 #define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
1691 #define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
1692 #define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
1694 #define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
1695 #define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
1696 #define simple_strtoul strtoul
1698 STATIC unsigned long
1699 suffix_strtoul(char *cp, char **endp, unsigned int base)
1701 int last, shift_left_factor = 0;
1702 char *value = (char *)cp;
1704 last = strlen(value) - 1;
1705 if (value[last] == 'K' || value[last] == 'k') {
1706 shift_left_factor = 10;
1709 if (value[last] == 'M' || value[last] == 'm') {
1710 shift_left_factor = 20;
1713 if (value[last] == 'G' || value[last] == 'g') {
1714 shift_left_factor = 30;
1718 return simple_strtoul(cp, endp, base) << shift_left_factor;
1724 struct bhv_desc *bhv,
1726 struct xfs_mount_args *args,
1729 struct xfs_vfs *vfsp = bhvtovfs(bhv);
1730 char *this_char, *value, *eov;
1731 int dsunit, dswidth, vol_dsunit, vol_dswidth;
1734 args->flags |= XFSMNT_IDELETE;
1735 args->flags |= XFSMNT_BARRIER;
1736 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
1741 iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0;
1743 while ((this_char = strsep(&options, ",")) != NULL) {
1747 if ((value = index(this_char, '=')) != NULL)
1750 if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
1751 if (!value || !*value) {
1752 printf("XFS: %s option requires an argument\n",
1756 args->logbufs = simple_strtoul(value, &eov, 10);
1757 } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
1758 if (!value || !*value) {
1759 printf("XFS: %s option requires an argument\n",
1763 args->logbufsize = suffix_strtoul(value, &eov, 10);
1764 } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
1765 if (!value || !*value) {
1766 printf("XFS: %s option requires an argument\n",
1770 strncpy(args->logname, value, MAXNAMELEN);
1771 } else if (!strcmp(this_char, MNTOPT_MTPT)) {
1772 if (!value || !*value) {
1773 printf("XFS: %s option requires an argument\n",
1777 strncpy(args->mtpt, value, MAXNAMELEN);
1778 } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
1779 if (!value || !*value) {
1780 printf("XFS: %s option requires an argument\n",
1784 strncpy(args->rtname, value, MAXNAMELEN);
1785 } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
1786 if (!value || !*value) {
1787 printf("XFS: %s option requires an argument\n",
1791 iosize = simple_strtoul(value, &eov, 10);
1792 args->flags |= XFSMNT_IOSIZE;
1793 args->iosizelog = (uint8_t) iosize;
1794 } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
1795 if (!value || !*value) {
1796 printk("XFS: %s option requires an argument\n",
1800 iosize = suffix_strtoul(value, &eov, 10);
1801 args->flags |= XFSMNT_IOSIZE;
1802 args->iosizelog = ffs(iosize) - 1;
1803 } else if (!strcmp(this_char, MNTOPT_IHASHSIZE)) {
1804 if (!value || !*value) {
1805 printk("XFS: %s option requires an argument\n",
1809 args->flags |= XFSMNT_IHASHSIZE;
1810 args->ihashsize = simple_strtoul(value, &eov, 10);
1811 } else if (!strcmp(this_char, MNTOPT_GRPID) ||
1812 !strcmp(this_char, MNTOPT_BSDGROUPS)) {
1813 vfsp->vfs_flag |= VFS_GRPID;
1814 } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
1815 !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
1816 vfsp->vfs_flag &= ~VFS_GRPID;
1817 } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
1818 args->flags |= XFSMNT_WSYNC;
1819 } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
1820 args->flags |= XFSMNT_OSYNCISOSYNC;
1821 } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
1822 args->flags |= XFSMNT_NORECOVERY;
1823 } else if (!strcmp(this_char, MNTOPT_INO64)) {
1824 args->flags |= XFSMNT_INO64;
1827 printf("XFS: %s option not allowed on this system\n",
1831 } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
1832 args->flags |= XFSMNT_NOALIGN;
1833 } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
1834 args->flags |= XFSMNT_SWALLOC;
1835 } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
1836 if (!value || !*value) {
1837 printf("XFS: %s option requires an argument\n",
1841 dsunit = simple_strtoul(value, &eov, 10);
1842 } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
1843 if (!value || !*value) {
1844 printf("XFS: %s option requires an argument\n",
1848 dswidth = simple_strtoul(value, &eov, 10);
1849 } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
1850 args->flags &= ~XFSMNT_32BITINODES;
1853 printf("XFS: %s option not allowed on this system\n",
1857 } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
1858 args->flags |= XFSMNT_NOUUID;
1859 } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
1860 args->flags |= XFSMNT_BARRIER;
1861 } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
1862 args->flags &= ~XFSMNT_BARRIER;
1863 } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
1864 args->flags &= ~XFSMNT_IDELETE;
1865 } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
1866 args->flags |= XFSMNT_IDELETE;
1867 } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
1868 args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE;
1869 } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
1870 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
1871 } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
1872 args->flags |= XFSMNT_ATTR2;
1873 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
1874 args->flags &= ~XFSMNT_ATTR2;
1875 } else if (!strcmp(this_char, "osyncisdsync")) {
1876 /* no-op, this is now the default */
1877 printf("XFS: osyncisdsync is now the default, option is deprecated.\n");
1878 } else if (!strcmp(this_char, "irixsgid")) {
1879 printf("XFS: irixsgid is now a sysctl(2) variable, option is deprecated.\n");
1881 printf("XFS: unknown mount option [%s].\n", this_char);
1886 if (args->flags & XFSMNT_NORECOVERY) {
1887 if ((vfsp->vfs_flag & VFS_RDONLY) == 0) {
1888 printf("XFS: no-recovery mounts must be read-only.\n");
1893 if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) {
1895 "XFS: sunit and swidth options incompatible with the noalign option\n");
1899 if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
1900 printf("XFS: sunit and swidth must be specified together\n");
1904 if (dsunit && (dswidth % dsunit != 0)) {
1906 "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)\n",
1911 if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
1913 args->sunit = dsunit;
1914 args->flags |= XFSMNT_RETERR;
1916 args->sunit = vol_dsunit;
1918 dswidth ? (args->swidth = dswidth) :
1919 (args->swidth = vol_dswidth);
1921 args->sunit = args->swidth = 0;
1925 if (args->flags & XFSMNT_32BITINODES)
1926 vfsp->vfs_flag |= VFS_32BITINODES;
1928 args->flags |= XFSMNT_FLAGS2;
1932 #define seq_printf sbuf_printf
1935 struct bhv_desc *bhv,
1938 static struct proc_xfs_info {
1942 /* the few simple ones we can get from the mount struct */
1943 { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
1944 { XFS_MOUNT_INO64, "," MNTOPT_INO64 },
1945 { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
1946 { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
1947 { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
1948 { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
1949 { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
1952 struct proc_xfs_info *xfs_infop;
1953 struct xfs_mount *mp = XFS_BHVTOM(bhv);
1954 struct xfs_vfs *vfsp = XFS_MTOVFS(mp);
1956 for (xfs_infop = xfs_info; xfs_infop->flag; xfs_infop++) {
1957 if (mp->m_flags & xfs_infop->flag)
1958 sbuf_printf(m, xfs_infop->str);
1961 if (mp->m_flags & XFS_MOUNT_IHASHSIZE)
1962 seq_printf(m, "," MNTOPT_IHASHSIZE "=%d", mp->m_ihsize);
1964 if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
1965 seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
1966 (int)(1 << mp->m_writeio_log) >> 10);
1968 if (mp->m_logbufs > 0)
1969 sbuf_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
1970 if (mp->m_logbsize > 0)
1971 seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
1974 seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
1976 seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
1978 if (mp->m_dalign > 0)
1979 sbuf_printf(m, "," MNTOPT_SUNIT "=%d",
1980 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
1981 if (mp->m_swidth > 0)
1982 sbuf_printf(m, "," MNTOPT_SWIDTH "=%d",
1983 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
1985 if (!(mp->m_flags & XFS_MOUNT_IDELETE))
1986 seq_printf(m, "," MNTOPT_IKEEP);
1987 if (!(mp->m_flags & XFS_MOUNT_COMPAT_IOSIZE))
1988 seq_printf(m, "," MNTOPT_LARGEIO);
1990 if (!(vfsp->vfs_flag & VFS_32BITINODES))
1991 sbuf_printf(m, "," MNTOPT_64BITINODE);
1992 if (vfsp->vfs_flag & VFS_GRPID)
1993 seq_printf(m, "," MNTOPT_GRPID);
2002 xfs_mount_t *mp = XFS_BHVTOM(bdp);
2004 while (atomic_read(&mp->m_active_trans) > 0)
2007 /* Push the superblock and write an unmount record */
2008 xfs_log_unmount_write(mp);
2009 xfs_unmountfs_writesb(mp);
2010 xfs_fs_log_dummy(mp);
2014 xvfsops_t xfs_vfsops = {
2015 BHV_IDENTITY_INIT(VFS_BHV_XFS,VFS_POSITION_XFS),
2016 .xvfs_parseargs = xfs_parseargs,
2017 .xvfs_showargs = xfs_showargs,
2018 .xvfs_mount = xfs_mount,
2019 .xvfs_unmount = xfs_unmount,
2020 .xvfs_mntupdate = xfs_mntupdate,
2021 .xvfs_root = xfs_root,
2022 .xvfs_statvfs = xfs_statvfs,
2023 .xvfs_sync = xfs_sync,
2024 .xvfs_vget = xfs_vget,
2025 .xvfs_dmapiops = (xvfs_dmapiops_t)fs_nosys,
2026 .xvfs_quotactl = (xvfs_quotactl_t)fs_nosys,
2027 .xvfs_get_inode = (xvfs_get_inode_t)fs_nosys,
2028 .xvfs_init_vnode = xfs_initialize_vnode,
2029 .xvfs_force_shutdown = xfs_do_force_shutdown,
2030 .xvfs_freeze = xfs_freeze,