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 != 16 * 1024 &&
242 ap->logbufsize != 32 * 1024 &&
243 ap->logbufsize != 64 * 1024 &&
244 ap->logbufsize != 128 * 1024 &&
245 ap->logbufsize != 256 * 1024) {
247 "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
249 return XFS_ERROR(EINVAL);
251 mp->m_ihsize = ap->ihashsize;
252 mp->m_logbsize = ap->logbufsize;
253 mp->m_fsname_len = strlen(ap->fsname) + 1;
254 mp->m_fsname = kmem_alloc(mp->m_fsname_len, KM_SLEEP);
255 strcpy(mp->m_fsname, ap->fsname);
257 mp->m_rtname = kmem_alloc(strlen(ap->rtname) + 1, KM_SLEEP);
258 strcpy(mp->m_rtname, ap->rtname);
260 if (ap->logname[0]) {
261 mp->m_logname = kmem_alloc(strlen(ap->logname) + 1, KM_SLEEP);
262 strcpy(mp->m_logname, ap->logname);
265 if (ap->flags & XFSMNT_WSYNC)
266 mp->m_flags |= XFS_MOUNT_WSYNC;
268 if (ap->flags & XFSMNT_INO64) {
269 mp->m_flags |= XFS_MOUNT_INO64;
270 mp->m_inoadd = XFS_INO64_OFFSET;
273 if (ap->flags & XFSMNT_RETERR)
274 mp->m_flags |= XFS_MOUNT_RETERR;
275 if (ap->flags & XFSMNT_NOALIGN)
276 mp->m_flags |= XFS_MOUNT_NOALIGN;
277 if (ap->flags & XFSMNT_SWALLOC)
278 mp->m_flags |= XFS_MOUNT_SWALLOC;
279 if (ap->flags & XFSMNT_OSYNCISOSYNC)
280 mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
281 if (ap->flags & XFSMNT_32BITINODES)
282 mp->m_flags |= XFS_MOUNT_32BITINODES;
284 if (ap->flags & XFSMNT_IOSIZE) {
285 if (ap->iosizelog > XFS_MAX_IO_LOG ||
286 ap->iosizelog < XFS_MIN_IO_LOG) {
288 "XFS: invalid log iosize: %d [not %d-%d]",
289 ap->iosizelog, XFS_MIN_IO_LOG,
291 return XFS_ERROR(EINVAL);
294 mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
295 mp->m_readio_log = mp->m_writeio_log = ap->iosizelog;
298 if (ap->flags & XFSMNT_IHASHSIZE)
299 mp->m_flags |= XFS_MOUNT_IHASHSIZE;
300 if (ap->flags & XFSMNT_IDELETE)
301 mp->m_flags |= XFS_MOUNT_IDELETE;
302 if (ap->flags & XFSMNT_DIRSYNC)
303 mp->m_flags |= XFS_MOUNT_DIRSYNC;
304 if (ap->flags & XFSMNT_ATTR2)
305 mp->m_flags |= XFS_MOUNT_ATTR2;
307 if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
308 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
311 * no recovery flag requires a read-only mount
313 if (ap->flags & XFSMNT_NORECOVERY) {
314 if (!(vfs->vfs_flag & VFS_RDONLY)) {
316 "XFS: tried to mount a FS read-write without recovery!");
317 return XFS_ERROR(EINVAL);
319 mp->m_flags |= XFS_MOUNT_NORECOVERY;
322 if (ap->flags & XFSMNT_NOUUID)
323 mp->m_flags |= XFS_MOUNT_NOUUID;
324 if (ap->flags & XFSMNT_BARRIER)
325 mp->m_flags |= XFS_MOUNT_BARRIER;
327 mp->m_flags &= ~XFS_MOUNT_BARRIER;
329 if (ap->flags2 & XFSMNT2_FILESTREAMS)
330 mp->m_flags |= XFS_MOUNT_FILESTREAMS;
336 * This function fills in xfs_mount_t fields based on mount args.
337 * Note: the superblock _has_ now been read in.
342 struct xfs_mount_args *ap,
343 struct xfs_mount *mp)
345 int ronly = (vfs->vfs_flag & VFS_RDONLY);
347 /* Fail a mount where the logbuf is smaller then the log stripe */
348 if (XFS_SB_VERSION_HASLOGV2(&mp->m_sb)) {
349 if ((ap->logbufsize <= 0) &&
350 (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) {
351 mp->m_logbsize = mp->m_sb.sb_logsunit;
352 } else if (ap->logbufsize > 0 &&
353 ap->logbufsize < mp->m_sb.sb_logsunit) {
355 "XFS: logbuf size must be greater than or equal to log stripe size");
356 return XFS_ERROR(EINVAL);
359 /* Fail a mount if the logbuf is larger than 32K */
360 if (ap->logbufsize > XLOG_BIG_RECORD_BSIZE) {
362 "XFS: logbuf size for version 1 logs must be 16K or 32K");
363 return XFS_ERROR(EINVAL);
367 if (XFS_SB_VERSION_HASATTR2(&mp->m_sb)) {
368 mp->m_flags |= XFS_MOUNT_ATTR2;
372 * prohibit r/w mounts of read-only filesystems
374 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
376 "XFS: cannot mount a read-only filesystem as read-write");
377 return XFS_ERROR(EROFS);
381 * check for shared mount.
383 if (ap->flags & XFSMNT_SHARED) {
384 if (!XFS_SB_VERSION_HASSHARED(&mp->m_sb))
385 return XFS_ERROR(EINVAL);
388 * For IRIX 6.5, shared mounts must have the shared
389 * version bit set, have the persistent readonly
390 * field set, must be version 0 and can only be mounted
393 if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) ||
394 (mp->m_sb.sb_shared_vn != 0))
395 return XFS_ERROR(EINVAL);
397 mp->m_flags |= XFS_MOUNT_SHARED;
400 * Shared XFS V0 can't deal with DMI. Return EINVAL.
402 if (mp->m_sb.sb_shared_vn == 0 && (ap->flags & XFSMNT_DMAPI))
403 return XFS_ERROR(EINVAL);
412 * The file system configurations are:
413 * (1) device (partition) with data and internal log
414 * (2) logical volume with data and log subvolumes.
415 * (3) logical volume with data, log, and realtime subvolumes.
417 * We only have to handle opening the log and realtime volumes here if
418 * they are present. The data subvolume has already been opened by
419 * get_sb_bdev() and is stored in vfsp->vfs_super->s_bdev.
423 struct bhv_desc *bhvp,
424 struct xfs_mount_args *args,
427 struct bhv_vfs *vfsp = bhvtovfs(bhvp);
429 struct xfs_mount *mp = XFS_BHVTOM(bhvp);
430 struct block_device *ddev, *logdev, *rtdev;
431 int flags = 0, error;
433 ddev = vfsp->vfs_super->s_bdev;
434 logdev = rtdev = NULL;
437 * Setup xfs_mount function vectors from available behaviors
439 p = vfs_bhv_lookup(vfsp, VFS_POSITION_DM);
440 mp->m_dm_ops = p ? *(xfs_dmops_t *) vfs_bhv_custom(p) : xfs_dmcore_stub;
441 p = vfs_bhv_lookup(vfsp, VFS_POSITION_QM);
442 mp->m_qm_ops = p ? *(xfs_qmops_t *) vfs_bhv_custom(p) : xfs_qmcore_stub;
443 p = vfs_bhv_lookup(vfsp, VFS_POSITION_IO);
444 mp->m_io_ops = p ? *(xfs_ioops_t *) vfs_bhv_custom(p) : xfs_iocore_xfs;
446 if (args->flags & XFSMNT_QUIET)
447 flags |= XFS_MFSI_QUIET;
450 * Open real time and log devices - order is important.
452 if (args->logname[0]) {
453 error = xfs_blkdev_get(mp, args->logname, &logdev);
457 if (args->rtname[0]) {
458 error = xfs_blkdev_get(mp, args->rtname, &rtdev);
460 xfs_blkdev_put(logdev);
464 if (rtdev == ddev || rtdev == logdev) {
466 "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
467 xfs_blkdev_put(logdev);
468 xfs_blkdev_put(rtdev);
474 * Setup xfs_mount buffer target pointers
477 mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
478 if (!mp->m_ddev_targp) {
479 xfs_blkdev_put(logdev);
480 xfs_blkdev_put(rtdev);
484 mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
485 if (!mp->m_rtdev_targp)
488 mp->m_logdev_targp = (logdev && logdev != ddev) ?
489 xfs_alloc_buftarg(logdev, 1) : mp->m_ddev_targp;
490 if (!mp->m_logdev_targp)
494 * Setup flags based on mount(2) options and then the superblock
496 error = xfs_start_flags(vfsp, args, mp);
499 error = xfs_readsb(mp, flags);
502 error = xfs_finish_flags(vfsp, args, mp);
507 * Setup xfs_mount buffer target pointers based on superblock
509 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
510 mp->m_sb.sb_sectsize);
511 if (!error && logdev && logdev != ddev) {
512 unsigned int log_sector_size = BBSIZE;
514 if (XFS_SB_VERSION_HASSECTOR(&mp->m_sb))
515 log_sector_size = mp->m_sb.sb_logsectsize;
516 error = xfs_setsize_buftarg(mp->m_logdev_targp,
517 mp->m_sb.sb_blocksize,
521 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
522 mp->m_sb.sb_blocksize,
523 mp->m_sb.sb_sectsize);
527 if (mp->m_flags & XFS_MOUNT_BARRIER)
528 xfs_mountfs_check_barriers(mp);
530 if ((error = xfs_filestream_mount(mp)))
533 error = XFS_IOINIT(vfsp, args, flags);
543 xfs_binval(mp->m_ddev_targp);
544 if (logdev && logdev != ddev)
545 xfs_binval(mp->m_logdev_targp);
547 xfs_binval(mp->m_rtdev_targp);
549 xfs_unmountfs_close(mp, credp);
559 bhv_vfs_t *vfsp = bhvtovfs(bdp);
560 xfs_mount_t *mp = XFS_BHVTOM(bdp);
563 int unmount_event_wanted = 0;
564 int unmount_event_flags = 0;
565 int xfs_unmountfs_needed = 0;
571 if (vfsp->vfs_flag & VFS_DMI) {
572 error = XFS_SEND_PREUNMOUNT(mp, vfsp,
573 rvp, DM_RIGHT_NULL, rvp, DM_RIGHT_NULL,
575 (mp->m_dmevmask & (1<<DM_EVENT_PREUNMOUNT))?
576 0:DM_FLAGS_UNWANTED);
578 return XFS_ERROR(error);
579 unmount_event_wanted = 1;
580 unmount_event_flags = (mp->m_dmevmask & (1<<DM_EVENT_UNMOUNT))?
581 0 : DM_FLAGS_UNWANTED;
585 * First blow any referenced inode from this file system
586 * out of the reference cache, and delete the timer.
588 xfs_refcache_purge_mp(mp);
591 * Blow away any referenced inode in the filestreams cache.
592 * This can and will cause log traffic as inodes go inactive
595 xfs_filestream_unmount(mp);
597 XFS_bflush(mp->m_ddev_targp);
598 error = xfs_unmount_flush(mp, 0);
602 ASSERT(vn_count(rvp) == 1);
605 * Drop the reference count
610 * If we're forcing a shutdown, typically because of a media error,
611 * we want to make sure we invalidate dirty pages that belong to
612 * referenced vnodes as well.
614 if (XFS_FORCED_SHUTDOWN(mp)) {
615 error = xfs_sync(&mp->m_bhv,
616 (SYNC_WAIT | SYNC_CLOSE), credp);
617 ASSERT(error != EFSCORRUPTED);
619 xfs_unmountfs_needed = 1;
622 /* Send DMAPI event, if required.
623 * Then do xfs_unmountfs() if needed.
624 * Then return error (or zero).
626 if (unmount_event_wanted) {
627 /* Note: mp structure must still exist for
628 * XFS_SEND_UNMOUNT() call.
630 XFS_SEND_UNMOUNT(mp, vfsp, error == 0 ? rvp : NULL,
631 DM_RIGHT_NULL, 0, error, unmount_event_flags);
633 if (xfs_unmountfs_needed) {
635 * Call common unmount function to flush to disk
636 * and free the super block buffer & mount structures.
638 xfs_unmountfs(mp, credp);
641 return XFS_ERROR(error);
648 int count = 0, pincount;
650 xfs_refcache_purge_mp(mp);
651 xfs_flush_buftarg(mp->m_ddev_targp, 0);
652 xfs_finish_reclaim_all(mp, 0);
654 /* This loop must run at least twice.
655 * The first instance of the loop will flush
656 * most meta data but that will generate more
657 * meta data (typically directory updates).
658 * Which then must be flushed and logged before
659 * we can write the unmount record.
662 xfs_syncsub(mp, SYNC_INODE_QUIESCE, NULL);
663 pincount = xfs_flush_buftarg(mp->m_ddev_targp, 1);
674 * Second stage of a quiesce. The data is already synced, now we have to take
675 * care of the metadata. New transactions are already blocked, so we need to
676 * wait for any remaining transactions to drain out before proceding.
682 /* wait for all modifications to complete */
683 while (atomic_read(&mp->m_active_trans) > 0)
686 /* flush inodes and push all remaining buffers out to disk */
689 ASSERT_ALWAYS(atomic_read(&mp->m_active_trans) == 0);
691 /* Push the superblock and write an unmount record */
692 xfs_log_sbcount(mp, 1);
693 xfs_log_unmount_write(mp);
694 xfs_unmountfs_writesb(mp);
701 struct xfs_mount_args *args)
703 bhv_vfs_t *vfsp = bhvtovfs(bdp);
704 xfs_mount_t *mp = XFS_BHVTOM(bdp);
706 if (!(*flags & MS_RDONLY)) { /* rw/ro -> rw */
707 if (vfsp->vfs_flag & VFS_RDONLY)
708 vfsp->vfs_flag &= ~VFS_RDONLY;
709 if (args->flags & XFSMNT_BARRIER) {
710 mp->m_flags |= XFS_MOUNT_BARRIER;
711 xfs_mountfs_check_barriers(mp);
713 mp->m_flags &= ~XFS_MOUNT_BARRIER;
715 } else if (!(vfsp->vfs_flag & VFS_RDONLY)) { /* rw -> ro */
716 xfs_filestream_flush(mp);
717 bhv_vfs_sync(vfsp, SYNC_DATA_QUIESCE, NULL);
718 xfs_attr_quiesce(mp);
719 vfsp->vfs_flag |= VFS_RDONLY;
725 * xfs_unmount_flush implements a set of flush operation on special
726 * inodes, which are needed as a separate set of operations so that
727 * they can be called as part of relocation process.
731 xfs_mount_t *mp, /* Mount structure we are getting
733 int relocation) /* Called from vfs relocation. */
735 xfs_inode_t *rip = mp->m_rootip;
737 xfs_inode_t *rsumip = NULL;
738 bhv_vnode_t *rvp = XFS_ITOV(rip);
741 xfs_ilock(rip, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT);
745 * Flush out the real time inodes.
747 if ((rbmip = mp->m_rbmip) != NULL) {
748 xfs_ilock(rbmip, XFS_ILOCK_EXCL);
750 error = xfs_iflush(rbmip, XFS_IFLUSH_SYNC);
751 xfs_iunlock(rbmip, XFS_ILOCK_EXCL);
753 if (error == EFSCORRUPTED)
756 ASSERT(vn_count(XFS_ITOV(rbmip)) == 1);
758 rsumip = mp->m_rsumip;
759 xfs_ilock(rsumip, XFS_ILOCK_EXCL);
761 error = xfs_iflush(rsumip, XFS_IFLUSH_SYNC);
762 xfs_iunlock(rsumip, XFS_ILOCK_EXCL);
764 if (error == EFSCORRUPTED)
767 ASSERT(vn_count(XFS_ITOV(rsumip)) == 1);
771 * Synchronously flush root inode to disk
773 error = xfs_iflush(rip, XFS_IFLUSH_SYNC);
774 if (error == EFSCORRUPTED)
777 if (vn_count(rvp) != 1 && !relocation) {
778 xfs_iunlock(rip, XFS_ILOCK_EXCL);
779 return XFS_ERROR(EBUSY);
783 * Release dquot that rootinode, rbmino and rsumino might be holding,
784 * flush and purge the quota inodes.
786 error = XFS_QM_UNMOUNT(mp);
787 if (error == EFSCORRUPTED)
791 VN_RELE(XFS_ITOV(rbmip));
792 VN_RELE(XFS_ITOV(rsumip));
795 xfs_iunlock(rip, XFS_ILOCK_EXCL);
802 xfs_iunlock(rip, XFS_ILOCK_EXCL);
804 return XFS_ERROR(EFSCORRUPTED);
808 * xfs_root extracts the root vnode from a vfs.
810 * vfsp -- the vfs struct for the desired file system
811 * vpp -- address of the caller's vnode pointer which should be
812 * set to the desired fs root vnode
821 vp = XFS_ITOV((XFS_BHVTOM(bdp))->m_rootip);
830 * Fill in the statvfs structure for the given file system. We use
831 * the superblock lock in the mount structure to ensure a consistent
832 * snapshot of the counters returned.
837 bhv_statvfs_t *statp,
846 mp = XFS_BHVTOM(bdp);
849 statp->f_type = XFS_SB_MAGIC;
851 xfs_icsb_sync_counters_flags(mp, XFS_ICSB_LAZY_COUNT);
853 statp->f_bsize = sbp->sb_blocksize;
854 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
855 statp->f_blocks = sbp->sb_dblocks - lsize;
856 statp->f_bfree = statp->f_bavail =
857 sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
858 fakeinos = statp->f_bfree << sbp->sb_inopblog;
860 fakeinos += mp->m_inoadd;
863 MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
868 statp->f_files = min_t(typeof(statp->f_files),
871 statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
872 XFS_SB_UNLOCK(mp, s);
874 xfs_statvfs_fsid(statp, mp);
875 statp->f_namelen = MAXNAMELEN - 1;
882 * xfs_sync flushes any pending I/O to file system vfsp.
884 * This routine is called by vfs_sync() to make sure that things make it
885 * out to disk eventually, on sync() system calls to flush out everything,
886 * and when the file system is unmounted. For the vfs_sync() case, all
887 * we really need to do is sync out the log to make all of our meta-data
888 * updates permanent (except for timestamps). For calls from pflushd(),
889 * dirty pages are kept moving by calling pdflush() on the inodes
890 * containing them. We also flush the inodes that we can lock without
891 * sleeping and the superblock if we can lock it without sleeping from
892 * vfs_sync() so that items at the tail of the log are always moving out.
895 * SYNC_BDFLUSH - We're being called from vfs_sync() so we don't want
896 * to sleep if we can help it. All we really need
897 * to do is ensure that the log is synced at least
898 * periodically. We also push the inodes and
899 * superblock if we can lock them without sleeping
900 * and they are not pinned.
901 * SYNC_ATTR - We need to flush the inodes. If SYNC_BDFLUSH is not
902 * set, then we really want to lock each inode and flush
904 * SYNC_WAIT - All the flushes that take place in this call should
906 * SYNC_DELWRI - This tells us to push dirty pages associated with
907 * inodes. SYNC_WAIT and SYNC_BDFLUSH are used to
908 * determine if they should be flushed sync, async, or
910 * SYNC_CLOSE - This flag is passed when the system is being
911 * unmounted. We should sync and invalidate everything.
912 * SYNC_FSDATA - This indicates that the caller would like to make
913 * sure the superblock is safe on disk. We can ensure
914 * this by simply making sure the log gets flushed
915 * if SYNC_BDFLUSH is set, and by actually writing it
917 * SYNC_IOWAIT - The caller wants us to wait for all data I/O to complete
918 * before we return (including direct I/O). Forms the drain
919 * side of the write barrier needed to safely quiesce the
930 xfs_mount_t *mp = XFS_BHVTOM(bdp);
932 if (flags & SYNC_IOWAIT)
933 xfs_filestream_flush(mp);
935 return xfs_syncsub(mp, flags, 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.
951 xfs_inode_t *ip = NULL;
952 xfs_inode_t *ip_next;
954 bhv_vnode_t *vp = NULL;
959 uint base_lock_flags;
960 boolean_t mount_locked;
961 boolean_t vnode_refed;
964 xfs_iptr_t *ipointer;
966 boolean_t ipointer_in = B_FALSE;
968 #define IPOINTER_SET ipointer_in = B_TRUE
969 #define IPOINTER_CLR ipointer_in = B_FALSE
976 /* Insert a marker record into the inode list after inode ip. The list
977 * must be locked when this is called. After the call the list will no
980 #define IPOINTER_INSERT(ip, mp) { \
981 ASSERT(ipointer_in == B_FALSE); \
982 ipointer->ip_mnext = ip->i_mnext; \
983 ipointer->ip_mprev = ip; \
984 ip->i_mnext = (xfs_inode_t *)ipointer; \
985 ipointer->ip_mnext->i_mprev = (xfs_inode_t *)ipointer; \
987 XFS_MOUNT_IUNLOCK(mp); \
988 mount_locked = B_FALSE; \
992 /* Remove the marker from the inode list. If the marker was the only item
993 * in the list then there are no remaining inodes and we should zero out
994 * the whole list. If we are the current head of the list then move the head
997 #define IPOINTER_REMOVE(ip, mp) { \
998 ASSERT(ipointer_in == B_TRUE); \
999 if (ipointer->ip_mnext != (xfs_inode_t *)ipointer) { \
1000 ip = ipointer->ip_mnext; \
1001 ip->i_mprev = ipointer->ip_mprev; \
1002 ipointer->ip_mprev->i_mnext = ip; \
1003 if (mp->m_inodes == (xfs_inode_t *)ipointer) { \
1004 mp->m_inodes = ip; \
1007 ASSERT(mp->m_inodes == (xfs_inode_t *)ipointer); \
1008 mp->m_inodes = NULL; \
1014 #define XFS_PREEMPT_MASK 0x7f
1018 if (XFS_MTOVFS(mp)->vfs_flag & VFS_RDONLY)
1024 /* Allocate a reference marker */
1025 ipointer = (xfs_iptr_t *)kmem_zalloc(sizeof(xfs_iptr_t), KM_SLEEP);
1027 fflag = XFS_B_ASYNC; /* default is don't wait */
1028 if (flags & (SYNC_BDFLUSH | SYNC_DELWRI))
1029 fflag = XFS_B_DELWRI;
1030 if (flags & SYNC_WAIT)
1031 fflag = 0; /* synchronous overrides all */
1033 base_lock_flags = XFS_ILOCK_SHARED;
1034 if (flags & (SYNC_DELWRI | SYNC_CLOSE)) {
1036 * We need the I/O lock if we're going to call any of
1037 * the flush/inval routines.
1039 base_lock_flags |= XFS_IOLOCK_SHARED;
1042 XFS_MOUNT_ILOCK(mp);
1046 mount_locked = B_TRUE;
1047 vnode_refed = B_FALSE;
1052 ASSERT(ipointer_in == B_FALSE);
1053 ASSERT(vnode_refed == B_FALSE);
1055 lock_flags = base_lock_flags;
1058 * There were no inodes in the list, just break out
1066 * We found another sync thread marker - skip it
1068 if (ip->i_mount == NULL) {
1073 vp = XFS_ITOV_NULL(ip);
1076 * If the vnode is gone then this is being torn down,
1077 * call reclaim if it is flushed, else let regular flush
1078 * code deal with it later in the loop.
1082 /* Skip ones already in reclaim */
1083 if (ip->i_flags & XFS_IRECLAIM) {
1087 if (xfs_ilock_nowait(ip, XFS_ILOCK_EXCL) == 0) {
1089 } else if ((xfs_ipincount(ip) == 0) &&
1090 xfs_iflock_nowait(ip)) {
1091 IPOINTER_INSERT(ip, mp);
1093 xfs_finish_reclaim(ip, 1,
1094 XFS_IFLUSH_DELWRI_ELSE_ASYNC);
1096 XFS_MOUNT_ILOCK(mp);
1097 mount_locked = B_TRUE;
1098 IPOINTER_REMOVE(ip, mp);
1100 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1111 if (XFS_FORCED_SHUTDOWN(mp) && !(flags & SYNC_CLOSE)) {
1112 XFS_MOUNT_IUNLOCK(mp);
1113 kmem_free(ipointer, sizeof(xfs_iptr_t));
1118 * If this is just vfs_sync() or pflushd() calling
1119 * then we can skip inodes for which it looks like
1120 * there is nothing to do. Since we don't have the
1121 * inode locked this is racy, but these are periodic
1122 * calls so it doesn't matter. For the others we want
1123 * to know for sure, so we at least try to lock them.
1125 if (flags & SYNC_BDFLUSH) {
1126 if (((ip->i_itemp == NULL) ||
1127 !(ip->i_itemp->ili_format.ilf_fields &
1129 (ip->i_update_core == 0)) {
1136 * Try to lock without sleeping. We're out of order with
1137 * the inode list lock here, so if we fail we need to drop
1138 * the mount lock and try again. If we're called from
1139 * bdflush() here, then don't bother.
1141 * The inode lock here actually coordinates with the
1142 * almost spurious inode lock in xfs_ireclaim() to prevent
1143 * the vnode we handle here without a reference from
1144 * being freed while we reference it. If we lock the inode
1145 * while it's on the mount list here, then the spurious inode
1146 * lock in xfs_ireclaim() after the inode is pulled from
1147 * the mount list will sleep until we release it here.
1148 * This keeps the vnode from being freed while we reference
1151 if (xfs_ilock_nowait(ip, lock_flags) == 0) {
1152 if ((flags & SYNC_BDFLUSH) || (vp == NULL)) {
1163 IPOINTER_INSERT(ip, mp);
1164 xfs_ilock(ip, lock_flags);
1166 ASSERT(vp == XFS_ITOV(ip));
1167 ASSERT(ip->i_mount == mp);
1169 vnode_refed = B_TRUE;
1172 /* From here on in the loop we may have a marker record
1173 * in the inode list.
1177 * If we have to flush data or wait for I/O completion
1178 * we need to drop the ilock that we currently hold.
1179 * If we need to drop the lock, insert a marker if we
1180 * have not already done so.
1182 if ((flags & (SYNC_CLOSE|SYNC_IOWAIT)) ||
1183 ((flags & SYNC_DELWRI) && VN_DIRTY(vp))) {
1185 IPOINTER_INSERT(ip, mp);
1187 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1189 if (flags & SYNC_CLOSE) {
1190 /* Shutdown case. Flush and invalidate. */
1191 if (XFS_FORCED_SHUTDOWN(mp))
1192 bhv_vop_toss_pages(vp, 0, -1, FI_REMAPF);
1194 error = bhv_vop_flushinval_pages(vp, 0,
1196 } else if ((flags & SYNC_DELWRI) && VN_DIRTY(vp)) {
1197 error = bhv_vop_flush_pages(vp, (xfs_off_t)0,
1198 -1, fflag, FI_NONE);
1202 * When freezing, we need to wait ensure all I/O (including direct
1203 * I/O) is complete to ensure no further data modification can take
1204 * place after this point
1206 if (flags & SYNC_IOWAIT)
1209 xfs_ilock(ip, XFS_ILOCK_SHARED);
1212 if (flags & SYNC_BDFLUSH) {
1213 if ((flags & SYNC_ATTR) &&
1214 ((ip->i_update_core) ||
1215 ((ip->i_itemp != NULL) &&
1216 (ip->i_itemp->ili_format.ilf_fields != 0)))) {
1218 /* Insert marker and drop lock if not already
1222 IPOINTER_INSERT(ip, mp);
1226 * We don't want the periodic flushing of the
1227 * inodes by vfs_sync() to interfere with
1228 * I/O to the file, especially read I/O
1229 * where it is only the access time stamp
1230 * that is being flushed out. To prevent
1231 * long periods where we have both inode
1232 * locks held shared here while reading the
1233 * inode's buffer in from disk, we drop the
1234 * inode lock while reading in the inode
1235 * buffer. We have to release the buffer
1236 * and reacquire the inode lock so that they
1237 * are acquired in the proper order (inode
1238 * locks first). The buffer will go at the
1239 * end of the lru chain, though, so we can
1240 * expect it to still be there when we go
1241 * for it again in xfs_iflush().
1243 if ((xfs_ipincount(ip) == 0) &&
1244 xfs_iflock_nowait(ip)) {
1247 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1249 error = xfs_itobp(mp, NULL, ip,
1254 /* Bailing out, remove the
1255 * marker and free it.
1257 XFS_MOUNT_ILOCK(mp);
1258 IPOINTER_REMOVE(ip, mp);
1259 XFS_MOUNT_IUNLOCK(mp);
1261 ASSERT(!(lock_flags &
1262 XFS_IOLOCK_SHARED));
1265 sizeof(xfs_iptr_t));
1270 * Since we dropped the inode lock,
1271 * the inode may have been reclaimed.
1272 * Therefore, we reacquire the mount
1273 * lock and check to see if we were the
1274 * inode reclaimed. If this happened
1275 * then the ipointer marker will no
1276 * longer point back at us. In this
1277 * case, move ip along to the inode
1278 * after the marker, remove the marker
1281 XFS_MOUNT_ILOCK(mp);
1282 mount_locked = B_TRUE;
1284 if (ip != ipointer->ip_mprev) {
1285 IPOINTER_REMOVE(ip, mp);
1287 ASSERT(!vnode_refed);
1288 ASSERT(!(lock_flags &
1289 XFS_IOLOCK_SHARED));
1293 ASSERT(ip->i_mount == mp);
1295 if (xfs_ilock_nowait(ip,
1296 XFS_ILOCK_SHARED) == 0) {
1297 ASSERT(ip->i_mount == mp);
1299 * We failed to reacquire
1300 * the inode lock without
1301 * sleeping, so just skip
1302 * the inode for now. We
1303 * clear the ILOCK bit from
1304 * the lock_flags so that we
1305 * won't try to drop a lock
1306 * we don't hold below.
1308 lock_flags &= ~XFS_ILOCK_SHARED;
1309 IPOINTER_REMOVE(ip_next, mp);
1310 } else if ((xfs_ipincount(ip) == 0) &&
1311 xfs_iflock_nowait(ip)) {
1312 ASSERT(ip->i_mount == mp);
1314 * Since this is vfs_sync()
1315 * calling we only flush the
1316 * inode out if we can lock
1317 * it without sleeping and
1318 * it is not pinned. Drop
1319 * the mount lock here so
1320 * that we don't hold it for
1321 * too long. We already have
1322 * a marker in the list here.
1324 XFS_MOUNT_IUNLOCK(mp);
1325 mount_locked = B_FALSE;
1326 error = xfs_iflush(ip,
1329 ASSERT(ip->i_mount == mp);
1330 IPOINTER_REMOVE(ip_next, mp);
1337 if ((flags & SYNC_ATTR) &&
1338 ((ip->i_update_core) ||
1339 ((ip->i_itemp != NULL) &&
1340 (ip->i_itemp->ili_format.ilf_fields != 0)))) {
1342 IPOINTER_INSERT(ip, mp);
1345 if (flags & SYNC_WAIT) {
1347 error = xfs_iflush(ip,
1351 * If we can't acquire the flush
1352 * lock, then the inode is already
1353 * being flushed so don't bother
1354 * waiting. If we can lock it then
1355 * do a delwri flush so we can
1356 * combine multiple inode flushes
1357 * in each disk write.
1359 if (xfs_iflock_nowait(ip)) {
1360 error = xfs_iflush(ip,
1369 if (lock_flags != 0) {
1370 xfs_iunlock(ip, lock_flags);
1375 * If we had to take a reference on the vnode
1376 * above, then wait until after we've unlocked
1377 * the inode to release the reference. This is
1378 * because we can be already holding the inode
1379 * lock when VN_RELE() calls xfs_inactive().
1381 * Make sure to drop the mount lock before calling
1382 * VN_RELE() so that we don't trip over ourselves if
1383 * we have to go for the mount lock again in the
1387 IPOINTER_INSERT(ip, mp);
1392 vnode_refed = B_FALSE;
1400 * bail out if the filesystem is corrupted.
1402 if (error == EFSCORRUPTED) {
1403 if (!mount_locked) {
1404 XFS_MOUNT_ILOCK(mp);
1405 IPOINTER_REMOVE(ip, mp);
1407 XFS_MOUNT_IUNLOCK(mp);
1408 ASSERT(ipointer_in == B_FALSE);
1409 kmem_free(ipointer, sizeof(xfs_iptr_t));
1410 return XFS_ERROR(error);
1413 /* Let other threads have a chance at the mount lock
1414 * if we have looped many times without dropping the
1417 if ((++preempt & XFS_PREEMPT_MASK) == 0) {
1419 IPOINTER_INSERT(ip, mp);
1423 if (mount_locked == B_FALSE) {
1424 XFS_MOUNT_ILOCK(mp);
1425 mount_locked = B_TRUE;
1426 IPOINTER_REMOVE(ip, mp);
1430 ASSERT(ipointer_in == B_FALSE);
1433 } while (ip != mp->m_inodes);
1435 XFS_MOUNT_IUNLOCK(mp);
1437 ASSERT(ipointer_in == B_FALSE);
1439 kmem_free(ipointer, sizeof(xfs_iptr_t));
1440 return XFS_ERROR(last_error);
1444 * xfs sync routine for internal use
1446 * This routine supports all of the flags defined for the generic vfs_sync
1447 * interface as explained above under xfs_sync.
1458 uint log_flags = XFS_LOG_FORCE;
1460 xfs_buf_log_item_t *bip;
1463 * Sync out the log. This ensures that the log is periodically
1464 * flushed even if there is not enough activity to fill it up.
1466 if (flags & SYNC_WAIT)
1467 log_flags |= XFS_LOG_SYNC;
1469 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1471 if (flags & (SYNC_ATTR|SYNC_DELWRI)) {
1472 if (flags & SYNC_BDFLUSH)
1473 xfs_finish_reclaim_all(mp, 1);
1475 error = xfs_sync_inodes(mp, flags, bypassed);
1479 * Flushing out dirty data above probably generated more
1480 * log activity, so if this isn't vfs_sync() then flush
1483 if (flags & SYNC_DELWRI) {
1484 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1487 if (flags & SYNC_FSDATA) {
1489 * If this is vfs_sync() then only sync the superblock
1490 * if we can lock it without sleeping and it is not pinned.
1492 if (flags & SYNC_BDFLUSH) {
1493 bp = xfs_getsb(mp, XFS_BUF_TRYLOCK);
1495 bip = XFS_BUF_FSPRIVATE(bp,xfs_buf_log_item_t*);
1496 if ((bip != NULL) &&
1497 xfs_buf_item_dirty(bip)) {
1498 if (!(XFS_BUF_ISPINNED(bp))) {
1500 error = xfs_bwrite(mp, bp);
1509 bp = xfs_getsb(mp, 0);
1511 * If the buffer is pinned then push on the log so
1512 * we won't get stuck waiting in the write for
1513 * someone, maybe ourselves, to flush the log.
1514 * Even though we just pushed the log above, we
1515 * did not have the superblock buffer locked at
1516 * that point so it can become pinned in between
1519 if (XFS_BUF_ISPINNED(bp))
1520 xfs_log_force(mp, (xfs_lsn_t)0, XFS_LOG_FORCE);
1521 if (flags & SYNC_WAIT)
1522 XFS_BUF_UNASYNC(bp);
1525 error = xfs_bwrite(mp, bp);
1533 * If this is the periodic sync, then kick some entries out of
1534 * the reference cache. This ensures that idle entries are
1535 * eventually kicked out of the cache.
1537 if (flags & SYNC_REFCACHE) {
1538 if (flags & SYNC_WAIT)
1539 xfs_refcache_purge_mp(mp);
1541 xfs_refcache_purge_some(mp);
1545 * If asked, update the disk superblock with incore counter values if we
1546 * are using non-persistent counters so that they don't get too far out
1547 * of sync if we crash or get a forced shutdown. We don't want to force
1548 * this to disk, just get a transaction into the iclogs....
1550 if (flags & SYNC_SUPER)
1551 xfs_log_sbcount(mp, 0);
1554 * Now check to see if the log needs a "dummy" transaction.
1557 if (!(flags & SYNC_REMOUNT) && xfs_log_need_covered(mp)) {
1562 * Put a dummy transaction in the log to tell
1563 * recovery that all others are OK.
1565 tp = xfs_trans_alloc(mp, XFS_TRANS_DUMMY1);
1566 if ((error = xfs_trans_reserve(tp, 0,
1567 XFS_ICHANGE_LOG_RES(mp),
1569 xfs_trans_cancel(tp, 0);
1574 xfs_ilock(ip, XFS_ILOCK_EXCL);
1576 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
1577 xfs_trans_ihold(tp, ip);
1578 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
1579 error = xfs_trans_commit(tp, 0);
1580 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1581 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1585 * When shutting down, we need to insure that the AIL is pushed
1586 * to disk or the filesystem can appear corrupt from the PROM.
1588 if ((flags & (SYNC_CLOSE|SYNC_WAIT)) == (SYNC_CLOSE|SYNC_WAIT)) {
1589 XFS_bflush(mp->m_ddev_targp);
1590 if (mp->m_rtdev_targp) {
1591 XFS_bflush(mp->m_rtdev_targp);
1595 return XFS_ERROR(last_error);
1599 * xfs_vget - called by DMAPI and NFSD to get vnode from file handle
1607 xfs_mount_t *mp = XFS_BHVTOM(bdp);
1608 xfs_fid_t *xfid = (struct xfs_fid *)fidp;
1615 * Invalid. Since handles can be created in user space and passed in
1616 * via gethandle(), this is not cause for a panic.
1618 if (xfid->xfs_fid_len != sizeof(*xfid) - sizeof(xfid->xfs_fid_len))
1619 return XFS_ERROR(EINVAL);
1621 ino = xfid->xfs_fid_ino;
1622 igen = xfid->xfs_fid_gen;
1625 * NFS can sometimes send requests for ino 0. Fail them gracefully.
1628 return XFS_ERROR(ESTALE);
1630 error = xfs_iget(mp, NULL, ino, 0, XFS_ILOCK_SHARED, &ip, 0);
1638 return XFS_ERROR(EIO);
1641 if (ip->i_d.di_mode == 0 || ip->i_d.di_gen != igen) {
1642 xfs_iput_new(ip, XFS_ILOCK_SHARED);
1644 return XFS_ERROR(ENOENT);
1647 *vpp = XFS_ITOV(ip);
1648 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1653 #define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
1654 #define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
1655 #define MNTOPT_LOGDEV "logdev" /* log device */
1656 #define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
1657 #define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
1658 #define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
1659 #define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
1660 #define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
1661 #define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
1662 #define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
1663 #define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
1664 #define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
1665 #define MNTOPT_MTPT "mtpt" /* filesystem mount point */
1666 #define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
1667 #define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
1668 #define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
1669 #define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
1670 #define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
1671 #define MNTOPT_IHASHSIZE "ihashsize" /* size of inode hash table */
1672 #define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
1673 #define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
1674 * unwritten extent conversion */
1675 #define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
1676 #define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
1677 #define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
1678 #define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
1679 #define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
1680 #define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
1681 #define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
1683 #define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
1684 #define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
1685 #define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
1687 STATIC unsigned long
1688 suffix_strtoul(char *s, char **endp, unsigned int base)
1690 int last, shift_left_factor = 0;
1693 last = strlen(value) - 1;
1694 if (value[last] == 'K' || value[last] == 'k') {
1695 shift_left_factor = 10;
1698 if (value[last] == 'M' || value[last] == 'm') {
1699 shift_left_factor = 20;
1702 if (value[last] == 'G' || value[last] == 'g') {
1703 shift_left_factor = 30;
1707 return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
1712 struct bhv_desc *bhv,
1714 struct xfs_mount_args *args,
1717 bhv_vfs_t *vfsp = bhvtovfs(bhv);
1718 char *this_char, *value, *eov;
1719 int dsunit, dswidth, vol_dsunit, vol_dswidth;
1722 args->flags |= XFSMNT_IDELETE;
1723 args->flags |= XFSMNT_BARRIER;
1724 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
1729 iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0;
1731 while ((this_char = strsep(&options, ",")) != NULL) {
1734 if ((value = strchr(this_char, '=')) != NULL)
1737 if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
1738 if (!value || !*value) {
1740 "XFS: %s option requires an argument",
1744 args->logbufs = simple_strtoul(value, &eov, 10);
1745 } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
1746 if (!value || !*value) {
1748 "XFS: %s option requires an argument",
1752 args->logbufsize = suffix_strtoul(value, &eov, 10);
1753 } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
1754 if (!value || !*value) {
1756 "XFS: %s option requires an argument",
1760 strncpy(args->logname, value, MAXNAMELEN);
1761 } else if (!strcmp(this_char, MNTOPT_MTPT)) {
1762 if (!value || !*value) {
1764 "XFS: %s option requires an argument",
1768 strncpy(args->mtpt, value, MAXNAMELEN);
1769 } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
1770 if (!value || !*value) {
1772 "XFS: %s option requires an argument",
1776 strncpy(args->rtname, value, MAXNAMELEN);
1777 } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
1778 if (!value || !*value) {
1780 "XFS: %s option requires an argument",
1784 iosize = simple_strtoul(value, &eov, 10);
1785 args->flags |= XFSMNT_IOSIZE;
1786 args->iosizelog = (uint8_t) iosize;
1787 } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
1788 if (!value || !*value) {
1790 "XFS: %s option requires an argument",
1794 iosize = suffix_strtoul(value, &eov, 10);
1795 args->flags |= XFSMNT_IOSIZE;
1796 args->iosizelog = ffs(iosize) - 1;
1797 } else if (!strcmp(this_char, MNTOPT_IHASHSIZE)) {
1798 if (!value || !*value) {
1800 "XFS: %s option requires an argument",
1804 args->flags |= XFSMNT_IHASHSIZE;
1805 args->ihashsize = simple_strtoul(value, &eov, 10);
1806 } else if (!strcmp(this_char, MNTOPT_GRPID) ||
1807 !strcmp(this_char, MNTOPT_BSDGROUPS)) {
1808 vfsp->vfs_flag |= VFS_GRPID;
1809 } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
1810 !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
1811 vfsp->vfs_flag &= ~VFS_GRPID;
1812 } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
1813 args->flags |= XFSMNT_WSYNC;
1814 } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
1815 args->flags |= XFSMNT_OSYNCISOSYNC;
1816 } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
1817 args->flags |= XFSMNT_NORECOVERY;
1818 } else if (!strcmp(this_char, MNTOPT_INO64)) {
1819 args->flags |= XFSMNT_INO64;
1822 "XFS: %s option not allowed on this system",
1826 } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
1827 args->flags |= XFSMNT_NOALIGN;
1828 } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
1829 args->flags |= XFSMNT_SWALLOC;
1830 } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
1831 if (!value || !*value) {
1833 "XFS: %s option requires an argument",
1837 dsunit = simple_strtoul(value, &eov, 10);
1838 } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
1839 if (!value || !*value) {
1841 "XFS: %s option requires an argument",
1845 dswidth = simple_strtoul(value, &eov, 10);
1846 } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
1847 args->flags &= ~XFSMNT_32BITINODES;
1850 "XFS: %s option not allowed on this system",
1854 } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
1855 args->flags |= XFSMNT_NOUUID;
1856 } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
1857 args->flags |= XFSMNT_BARRIER;
1858 } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
1859 args->flags &= ~XFSMNT_BARRIER;
1860 } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
1861 args->flags &= ~XFSMNT_IDELETE;
1862 } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
1863 args->flags |= XFSMNT_IDELETE;
1864 } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
1865 args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE;
1866 } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
1867 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
1868 } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
1869 args->flags |= XFSMNT_ATTR2;
1870 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
1871 args->flags &= ~XFSMNT_ATTR2;
1872 } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
1873 args->flags2 |= XFSMNT2_FILESTREAMS;
1874 } else if (!strcmp(this_char, "osyncisdsync")) {
1875 /* no-op, this is now the default */
1877 "XFS: osyncisdsync is now the default, option is deprecated.");
1878 } else if (!strcmp(this_char, "irixsgid")) {
1880 "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
1883 "XFS: unknown mount option [%s].", this_char);
1888 if (args->flags & XFSMNT_NORECOVERY) {
1889 if ((vfsp->vfs_flag & VFS_RDONLY) == 0) {
1891 "XFS: no-recovery mounts must be read-only.");
1896 if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) {
1898 "XFS: sunit and swidth options incompatible with the noalign option");
1902 if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
1904 "XFS: sunit and swidth must be specified together");
1908 if (dsunit && (dswidth % dsunit != 0)) {
1910 "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
1915 if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
1917 args->sunit = dsunit;
1918 args->flags |= XFSMNT_RETERR;
1920 args->sunit = vol_dsunit;
1922 dswidth ? (args->swidth = dswidth) :
1923 (args->swidth = vol_dswidth);
1925 args->sunit = args->swidth = 0;
1929 if (args->flags & XFSMNT_32BITINODES)
1930 vfsp->vfs_flag |= VFS_32BITINODES;
1932 args->flags |= XFSMNT_FLAGS2;
1938 struct bhv_desc *bhv,
1941 static struct proc_xfs_info {
1945 /* the few simple ones we can get from the mount struct */
1946 { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
1947 { XFS_MOUNT_INO64, "," MNTOPT_INO64 },
1948 { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
1949 { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
1950 { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
1951 { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
1952 { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
1955 struct proc_xfs_info *xfs_infop;
1956 struct xfs_mount *mp = XFS_BHVTOM(bhv);
1957 struct bhv_vfs *vfsp = XFS_MTOVFS(mp);
1959 for (xfs_infop = xfs_info; xfs_infop->flag; xfs_infop++) {
1960 if (mp->m_flags & xfs_infop->flag)
1961 seq_puts(m, xfs_infop->str);
1964 if (mp->m_flags & XFS_MOUNT_IHASHSIZE)
1965 seq_printf(m, "," MNTOPT_IHASHSIZE "=%d", (int)mp->m_ihsize);
1967 if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
1968 seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
1969 (int)(1 << mp->m_writeio_log) >> 10);
1971 if (mp->m_logbufs > 0)
1972 seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
1973 if (mp->m_logbsize > 0)
1974 seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
1977 seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
1979 seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
1981 if (mp->m_dalign > 0)
1982 seq_printf(m, "," MNTOPT_SUNIT "=%d",
1983 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
1984 if (mp->m_swidth > 0)
1985 seq_printf(m, "," MNTOPT_SWIDTH "=%d",
1986 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
1988 if (!(mp->m_flags & XFS_MOUNT_IDELETE))
1989 seq_printf(m, "," MNTOPT_IKEEP);
1990 if (!(mp->m_flags & XFS_MOUNT_COMPAT_IOSIZE))
1991 seq_printf(m, "," MNTOPT_LARGEIO);
1993 if (!(vfsp->vfs_flag & VFS_32BITINODES))
1994 seq_printf(m, "," MNTOPT_64BITINODE);
1995 if (vfsp->vfs_flag & VFS_GRPID)
1996 seq_printf(m, "," MNTOPT_GRPID);
2002 * Second stage of a freeze. The data is already frozen so we only
2003 * need to take care of themetadata. Once that's done write a dummy
2004 * record to dirty the log in case of a crash while frozen.
2010 xfs_mount_t *mp = XFS_BHVTOM(bdp);
2012 xfs_attr_quiesce(mp);
2013 xfs_fs_log_dummy(mp);
2017 bhv_vfsops_t xfs_vfsops = {
2018 BHV_IDENTITY_INIT(VFS_BHV_XFS,VFS_POSITION_XFS),
2019 .vfs_parseargs = xfs_parseargs,
2020 .vfs_showargs = xfs_showargs,
2021 .vfs_mount = xfs_mount,
2022 .vfs_unmount = xfs_unmount,
2023 .vfs_mntupdate = xfs_mntupdate,
2024 .vfs_root = xfs_root,
2025 .vfs_statvfs = xfs_statvfs,
2026 .vfs_sync = xfs_sync,
2027 .vfs_vget = xfs_vget,
2028 .vfs_dmapiops = (vfs_dmapiops_t)fs_nosys,
2029 .vfs_quotactl = (vfs_quotactl_t)fs_nosys,
2030 .vfs_init_vnode = xfs_initialize_vnode,
2031 .vfs_force_shutdown = xfs_do_force_shutdown,
2032 .vfs_freeze = xfs_freeze,