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"
57 #include "xfs_vnodeops.h"
60 STATIC int xfs_sync(bhv_desc_t *, int, cred_t *);
65 extern kmem_zone_t *xfs_bmap_free_item_zone;
66 extern kmem_zone_t *xfs_btree_cur_zone;
67 extern kmem_zone_t *xfs_trans_zone;
68 extern kmem_zone_t *xfs_buf_item_zone;
69 extern kmem_zone_t *xfs_dabuf_zone;
70 #ifdef XFS_DABUF_DEBUG
71 extern lock_t xfs_dabuf_global_lock;
72 spinlock_init(&xfs_dabuf_global_lock, "xfsda");
76 * Initialize all of the zone allocators we use.
78 xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
79 "xfs_bmap_free_item");
80 xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
82 xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
84 kmem_zone_init(sizeof(xfs_da_state_t), "xfs_da_state");
85 xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf");
86 xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
87 xfs_acl_zone_init(xfs_acl_zone, "xfs_acl");
89 xfs_filestream_init();
92 * The size of the zone allocated buf log item is the maximum
93 * size possible under XFS. This wastes a little bit of memory,
94 * but it is much faster.
97 kmem_zone_init((sizeof(xfs_buf_log_item_t) +
98 (((XFS_MAX_BLOCKSIZE / XFS_BLI_CHUNK) /
99 NBWORD) * sizeof(int))),
102 kmem_zone_init((sizeof(xfs_efd_log_item_t) +
103 ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
104 sizeof(xfs_extent_t))),
107 kmem_zone_init((sizeof(xfs_efi_log_item_t) +
108 ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
109 sizeof(xfs_extent_t))),
113 * These zones warrant special memory allocator hints
116 kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
117 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM |
118 KM_ZONE_SPREAD, NULL);
120 kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
121 KM_ZONE_SPREAD, NULL);
123 kmem_zone_init_flags(sizeof(xfs_icluster_t), "xfs_icluster",
124 KM_ZONE_SPREAD, NULL);
127 * Allocate global trace buffers.
129 #ifdef XFS_ALLOC_TRACE
130 xfs_alloc_trace_buf = ktrace_alloc(XFS_ALLOC_TRACE_SIZE, KM_SLEEP);
132 #ifdef XFS_BMAP_TRACE
133 xfs_bmap_trace_buf = ktrace_alloc(XFS_BMAP_TRACE_SIZE, KM_SLEEP);
135 #ifdef XFS_BMBT_TRACE
136 xfs_bmbt_trace_buf = ktrace_alloc(XFS_BMBT_TRACE_SIZE, KM_SLEEP);
138 #ifdef XFS_ATTR_TRACE
139 xfs_attr_trace_buf = ktrace_alloc(XFS_ATTR_TRACE_SIZE, KM_SLEEP);
141 #ifdef XFS_DIR2_TRACE
142 xfs_dir2_trace_buf = ktrace_alloc(XFS_DIR2_GTRACE_SIZE, KM_SLEEP);
147 #if (defined(DEBUG) || defined(INDUCE_IO_ERROR))
148 xfs_error_test_init();
149 #endif /* DEBUG || INDUCE_IO_ERROR */
152 xfs_sysctl_register();
159 extern kmem_zone_t *xfs_bmap_free_item_zone;
160 extern kmem_zone_t *xfs_btree_cur_zone;
161 extern kmem_zone_t *xfs_inode_zone;
162 extern kmem_zone_t *xfs_trans_zone;
163 extern kmem_zone_t *xfs_da_state_zone;
164 extern kmem_zone_t *xfs_dabuf_zone;
165 extern kmem_zone_t *xfs_efd_zone;
166 extern kmem_zone_t *xfs_efi_zone;
167 extern kmem_zone_t *xfs_buf_item_zone;
168 extern kmem_zone_t *xfs_icluster_zone;
170 xfs_cleanup_procfs();
171 xfs_sysctl_unregister();
172 xfs_refcache_destroy();
173 xfs_filestream_uninit();
174 xfs_mru_cache_uninit();
175 xfs_acl_zone_destroy(xfs_acl_zone);
177 #ifdef XFS_DIR2_TRACE
178 ktrace_free(xfs_dir2_trace_buf);
180 #ifdef XFS_ATTR_TRACE
181 ktrace_free(xfs_attr_trace_buf);
183 #ifdef XFS_BMBT_TRACE
184 ktrace_free(xfs_bmbt_trace_buf);
186 #ifdef XFS_BMAP_TRACE
187 ktrace_free(xfs_bmap_trace_buf);
189 #ifdef XFS_ALLOC_TRACE
190 ktrace_free(xfs_alloc_trace_buf);
193 kmem_zone_destroy(xfs_bmap_free_item_zone);
194 kmem_zone_destroy(xfs_btree_cur_zone);
195 kmem_zone_destroy(xfs_inode_zone);
196 kmem_zone_destroy(xfs_trans_zone);
197 kmem_zone_destroy(xfs_da_state_zone);
198 kmem_zone_destroy(xfs_dabuf_zone);
199 kmem_zone_destroy(xfs_buf_item_zone);
200 kmem_zone_destroy(xfs_efd_zone);
201 kmem_zone_destroy(xfs_efi_zone);
202 kmem_zone_destroy(xfs_ifork_zone);
203 kmem_zone_destroy(xfs_ili_zone);
204 kmem_zone_destroy(xfs_icluster_zone);
210 * This function fills in xfs_mount_t fields based on mount args.
211 * Note: the superblock has _not_ yet been read in.
216 struct xfs_mount_args *ap,
217 struct xfs_mount *mp)
219 /* Values are in BBs */
220 if ((ap->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
222 * At this point the superblock has not been read
223 * in, therefore we do not know the block size.
224 * Before the mount call ends we will convert
227 mp->m_dalign = ap->sunit;
228 mp->m_swidth = ap->swidth;
231 if (ap->logbufs != -1 &&
233 (ap->logbufs < XLOG_MIN_ICLOGS ||
234 ap->logbufs > XLOG_MAX_ICLOGS)) {
236 "XFS: invalid logbufs value: %d [not %d-%d]",
237 ap->logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
238 return XFS_ERROR(EINVAL);
240 mp->m_logbufs = ap->logbufs;
241 if (ap->logbufsize != -1 &&
242 ap->logbufsize != 0 &&
243 (ap->logbufsize < XLOG_MIN_RECORD_BSIZE ||
244 ap->logbufsize > XLOG_MAX_RECORD_BSIZE ||
245 !is_power_of_2(ap->logbufsize))) {
247 "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
249 return XFS_ERROR(EINVAL);
251 mp->m_logbsize = ap->logbufsize;
252 mp->m_fsname_len = strlen(ap->fsname) + 1;
253 mp->m_fsname = kmem_alloc(mp->m_fsname_len, KM_SLEEP);
254 strcpy(mp->m_fsname, ap->fsname);
256 mp->m_rtname = kmem_alloc(strlen(ap->rtname) + 1, KM_SLEEP);
257 strcpy(mp->m_rtname, ap->rtname);
259 if (ap->logname[0]) {
260 mp->m_logname = kmem_alloc(strlen(ap->logname) + 1, KM_SLEEP);
261 strcpy(mp->m_logname, ap->logname);
264 if (ap->flags & XFSMNT_WSYNC)
265 mp->m_flags |= XFS_MOUNT_WSYNC;
267 if (ap->flags & XFSMNT_INO64) {
268 mp->m_flags |= XFS_MOUNT_INO64;
269 mp->m_inoadd = XFS_INO64_OFFSET;
272 if (ap->flags & XFSMNT_RETERR)
273 mp->m_flags |= XFS_MOUNT_RETERR;
274 if (ap->flags & XFSMNT_NOALIGN)
275 mp->m_flags |= XFS_MOUNT_NOALIGN;
276 if (ap->flags & XFSMNT_SWALLOC)
277 mp->m_flags |= XFS_MOUNT_SWALLOC;
278 if (ap->flags & XFSMNT_OSYNCISOSYNC)
279 mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
280 if (ap->flags & XFSMNT_32BITINODES)
281 mp->m_flags |= XFS_MOUNT_32BITINODES;
283 if (ap->flags & XFSMNT_IOSIZE) {
284 if (ap->iosizelog > XFS_MAX_IO_LOG ||
285 ap->iosizelog < XFS_MIN_IO_LOG) {
287 "XFS: invalid log iosize: %d [not %d-%d]",
288 ap->iosizelog, XFS_MIN_IO_LOG,
290 return XFS_ERROR(EINVAL);
293 mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
294 mp->m_readio_log = mp->m_writeio_log = ap->iosizelog;
297 if (ap->flags & XFSMNT_IDELETE)
298 mp->m_flags |= XFS_MOUNT_IDELETE;
299 if (ap->flags & XFSMNT_DIRSYNC)
300 mp->m_flags |= XFS_MOUNT_DIRSYNC;
301 if (ap->flags & XFSMNT_ATTR2)
302 mp->m_flags |= XFS_MOUNT_ATTR2;
304 if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
305 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
308 * no recovery flag requires a read-only mount
310 if (ap->flags & XFSMNT_NORECOVERY) {
311 if (!(vfs->vfs_flag & VFS_RDONLY)) {
313 "XFS: tried to mount a FS read-write without recovery!");
314 return XFS_ERROR(EINVAL);
316 mp->m_flags |= XFS_MOUNT_NORECOVERY;
319 if (ap->flags & XFSMNT_NOUUID)
320 mp->m_flags |= XFS_MOUNT_NOUUID;
321 if (ap->flags & XFSMNT_BARRIER)
322 mp->m_flags |= XFS_MOUNT_BARRIER;
324 mp->m_flags &= ~XFS_MOUNT_BARRIER;
326 if (ap->flags2 & XFSMNT2_FILESTREAMS)
327 mp->m_flags |= XFS_MOUNT_FILESTREAMS;
329 if (ap->flags & XFSMNT_DMAPI)
330 vfs->vfs_flag |= VFS_DMI;
335 * This function fills in xfs_mount_t fields based on mount args.
336 * Note: the superblock _has_ now been read in.
341 struct xfs_mount_args *ap,
342 struct xfs_mount *mp)
344 int ronly = (vfs->vfs_flag & VFS_RDONLY);
346 /* Fail a mount where the logbuf is smaller then the log stripe */
347 if (XFS_SB_VERSION_HASLOGV2(&mp->m_sb)) {
348 if ((ap->logbufsize <= 0) &&
349 (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) {
350 mp->m_logbsize = mp->m_sb.sb_logsunit;
351 } else if (ap->logbufsize > 0 &&
352 ap->logbufsize < mp->m_sb.sb_logsunit) {
354 "XFS: logbuf size must be greater than or equal to log stripe size");
355 return XFS_ERROR(EINVAL);
358 /* Fail a mount if the logbuf is larger than 32K */
359 if (ap->logbufsize > XLOG_BIG_RECORD_BSIZE) {
361 "XFS: logbuf size for version 1 logs must be 16K or 32K");
362 return XFS_ERROR(EINVAL);
366 if (XFS_SB_VERSION_HASATTR2(&mp->m_sb)) {
367 mp->m_flags |= XFS_MOUNT_ATTR2;
371 * prohibit r/w mounts of read-only filesystems
373 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
375 "XFS: cannot mount a read-only filesystem as read-write");
376 return XFS_ERROR(EROFS);
380 * check for shared mount.
382 if (ap->flags & XFSMNT_SHARED) {
383 if (!XFS_SB_VERSION_HASSHARED(&mp->m_sb))
384 return XFS_ERROR(EINVAL);
387 * For IRIX 6.5, shared mounts must have the shared
388 * version bit set, have the persistent readonly
389 * field set, must be version 0 and can only be mounted
392 if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) ||
393 (mp->m_sb.sb_shared_vn != 0))
394 return XFS_ERROR(EINVAL);
396 mp->m_flags |= XFS_MOUNT_SHARED;
399 * Shared XFS V0 can't deal with DMI. Return EINVAL.
401 if (mp->m_sb.sb_shared_vn == 0 && (ap->flags & XFSMNT_DMAPI))
402 return XFS_ERROR(EINVAL);
405 if (ap->flags & XFSMNT_UQUOTA) {
406 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
407 if (ap->flags & XFSMNT_UQUOTAENF)
408 mp->m_qflags |= XFS_UQUOTA_ENFD;
411 if (ap->flags & XFSMNT_GQUOTA) {
412 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
413 if (ap->flags & XFSMNT_GQUOTAENF)
414 mp->m_qflags |= XFS_OQUOTA_ENFD;
415 } else if (ap->flags & XFSMNT_PQUOTA) {
416 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
417 if (ap->flags & XFSMNT_PQUOTAENF)
418 mp->m_qflags |= XFS_OQUOTA_ENFD;
427 * The file system configurations are:
428 * (1) device (partition) with data and internal log
429 * (2) logical volume with data and log subvolumes.
430 * (3) logical volume with data, log, and realtime subvolumes.
432 * We only have to handle opening the log and realtime volumes here if
433 * they are present. The data subvolume has already been opened by
434 * get_sb_bdev() and is stored in vfsp->vfs_super->s_bdev.
438 struct bhv_desc *bhvp,
439 struct xfs_mount_args *args,
442 struct bhv_vfs *vfsp = bhvtovfs(bhvp);
444 struct xfs_mount *mp = XFS_BHVTOM(bhvp);
445 struct block_device *ddev, *logdev, *rtdev;
446 int flags = 0, error;
448 ddev = vfsp->vfs_super->s_bdev;
449 logdev = rtdev = NULL;
451 error = xfs_dmops_get(mp, args);
454 error = xfs_qmops_get(mp, args);
459 * Setup xfs_mount function vectors from available behaviors
461 p = vfs_bhv_lookup(vfsp, VFS_POSITION_IO);
462 mp->m_io_ops = p ? *(xfs_ioops_t *) vfs_bhv_custom(p) : xfs_iocore_xfs;
464 if (args->flags & XFSMNT_QUIET)
465 flags |= XFS_MFSI_QUIET;
468 * Open real time and log devices - order is important.
470 if (args->logname[0]) {
471 error = xfs_blkdev_get(mp, args->logname, &logdev);
475 if (args->rtname[0]) {
476 error = xfs_blkdev_get(mp, args->rtname, &rtdev);
478 xfs_blkdev_put(logdev);
482 if (rtdev == ddev || rtdev == logdev) {
484 "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
485 xfs_blkdev_put(logdev);
486 xfs_blkdev_put(rtdev);
492 * Setup xfs_mount buffer target pointers
495 mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
496 if (!mp->m_ddev_targp) {
497 xfs_blkdev_put(logdev);
498 xfs_blkdev_put(rtdev);
502 mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
503 if (!mp->m_rtdev_targp) {
504 xfs_blkdev_put(logdev);
505 xfs_blkdev_put(rtdev);
509 mp->m_logdev_targp = (logdev && logdev != ddev) ?
510 xfs_alloc_buftarg(logdev, 1) : mp->m_ddev_targp;
511 if (!mp->m_logdev_targp) {
512 xfs_blkdev_put(logdev);
513 xfs_blkdev_put(rtdev);
518 * Setup flags based on mount(2) options and then the superblock
520 error = xfs_start_flags(vfsp, args, mp);
523 error = xfs_readsb(mp, flags);
526 error = xfs_finish_flags(vfsp, args, mp);
531 * Setup xfs_mount buffer target pointers based on superblock
533 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
534 mp->m_sb.sb_sectsize);
535 if (!error && logdev && logdev != ddev) {
536 unsigned int log_sector_size = BBSIZE;
538 if (XFS_SB_VERSION_HASSECTOR(&mp->m_sb))
539 log_sector_size = mp->m_sb.sb_logsectsize;
540 error = xfs_setsize_buftarg(mp->m_logdev_targp,
541 mp->m_sb.sb_blocksize,
545 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
546 mp->m_sb.sb_blocksize,
547 mp->m_sb.sb_sectsize);
551 if (mp->m_flags & XFS_MOUNT_BARRIER)
552 xfs_mountfs_check_barriers(mp);
554 if ((error = xfs_filestream_mount(mp)))
557 error = XFS_IOINIT(vfsp, args, flags);
561 XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, args->mtpt, args->fsname);
569 xfs_binval(mp->m_ddev_targp);
570 if (logdev && logdev != ddev)
571 xfs_binval(mp->m_logdev_targp);
573 xfs_binval(mp->m_rtdev_targp);
575 xfs_unmountfs_close(mp, credp);
587 bhv_vfs_t *vfsp = bhvtovfs(bdp);
588 xfs_mount_t *mp = XFS_BHVTOM(bdp);
591 int unmount_event_wanted = 0;
592 int unmount_event_flags = 0;
593 int xfs_unmountfs_needed = 0;
600 if (vfsp->vfs_flag & VFS_DMI) {
601 error = XFS_SEND_PREUNMOUNT(mp, vfsp,
602 rvp, DM_RIGHT_NULL, rvp, DM_RIGHT_NULL,
604 (mp->m_dmevmask & (1<<DM_EVENT_PREUNMOUNT))?
605 0:DM_FLAGS_UNWANTED);
607 return XFS_ERROR(error);
608 unmount_event_wanted = 1;
609 unmount_event_flags = (mp->m_dmevmask & (1<<DM_EVENT_UNMOUNT))?
610 0 : DM_FLAGS_UNWANTED;
614 * First blow any referenced inode from this file system
615 * out of the reference cache, and delete the timer.
617 xfs_refcache_purge_mp(mp);
620 * Blow away any referenced inode in the filestreams cache.
621 * This can and will cause log traffic as inodes go inactive
624 xfs_filestream_unmount(mp);
626 XFS_bflush(mp->m_ddev_targp);
627 error = xfs_unmount_flush(mp, 0);
631 ASSERT(vn_count(rvp) == 1);
634 * Drop the reference count
639 * If we're forcing a shutdown, typically because of a media error,
640 * we want to make sure we invalidate dirty pages that belong to
641 * referenced vnodes as well.
643 if (XFS_FORCED_SHUTDOWN(mp)) {
644 error = xfs_sync(&mp->m_bhv,
645 (SYNC_WAIT | SYNC_CLOSE), credp);
646 ASSERT(error != EFSCORRUPTED);
648 xfs_unmountfs_needed = 1;
651 /* Send DMAPI event, if required.
652 * Then do xfs_unmountfs() if needed.
653 * Then return error (or zero).
655 if (unmount_event_wanted) {
656 /* Note: mp structure must still exist for
657 * XFS_SEND_UNMOUNT() call.
659 XFS_SEND_UNMOUNT(mp, vfsp, error == 0 ? rvp : NULL,
660 DM_RIGHT_NULL, 0, error, unmount_event_flags);
662 if (xfs_unmountfs_needed) {
664 * Call common unmount function to flush to disk
665 * and free the super block buffer & mount structures.
667 xfs_unmountfs(mp, credp);
670 kmem_free(mp, sizeof(xfs_mount_t));
673 return XFS_ERROR(error);
680 int count = 0, pincount;
682 xfs_refcache_purge_mp(mp);
683 xfs_flush_buftarg(mp->m_ddev_targp, 0);
684 xfs_finish_reclaim_all(mp, 0);
686 /* This loop must run at least twice.
687 * The first instance of the loop will flush
688 * most meta data but that will generate more
689 * meta data (typically directory updates).
690 * Which then must be flushed and logged before
691 * we can write the unmount record.
694 xfs_syncsub(mp, SYNC_INODE_QUIESCE, NULL);
695 pincount = xfs_flush_buftarg(mp->m_ddev_targp, 1);
706 * Second stage of a quiesce. The data is already synced, now we have to take
707 * care of the metadata. New transactions are already blocked, so we need to
708 * wait for any remaining transactions to drain out before proceding.
714 /* wait for all modifications to complete */
715 while (atomic_read(&mp->m_active_trans) > 0)
718 /* flush inodes and push all remaining buffers out to disk */
721 ASSERT_ALWAYS(atomic_read(&mp->m_active_trans) == 0);
723 /* Push the superblock and write an unmount record */
724 xfs_log_sbcount(mp, 1);
725 xfs_log_unmount_write(mp);
726 xfs_unmountfs_writesb(mp);
733 struct xfs_mount_args *args)
735 bhv_vfs_t *vfsp = bhvtovfs(bdp);
736 xfs_mount_t *mp = XFS_BHVTOM(bdp);
738 if (!(*flags & MS_RDONLY)) { /* rw/ro -> rw */
739 if (vfsp->vfs_flag & VFS_RDONLY)
740 vfsp->vfs_flag &= ~VFS_RDONLY;
741 if (args->flags & XFSMNT_BARRIER) {
742 mp->m_flags |= XFS_MOUNT_BARRIER;
743 xfs_mountfs_check_barriers(mp);
745 mp->m_flags &= ~XFS_MOUNT_BARRIER;
747 } else if (!(vfsp->vfs_flag & VFS_RDONLY)) { /* rw -> ro */
748 xfs_filestream_flush(mp);
749 bhv_vfs_sync(vfsp, SYNC_DATA_QUIESCE, NULL);
750 xfs_attr_quiesce(mp);
751 vfsp->vfs_flag |= VFS_RDONLY;
757 * xfs_unmount_flush implements a set of flush operation on special
758 * inodes, which are needed as a separate set of operations so that
759 * they can be called as part of relocation process.
763 xfs_mount_t *mp, /* Mount structure we are getting
765 int relocation) /* Called from vfs relocation. */
767 xfs_inode_t *rip = mp->m_rootip;
769 xfs_inode_t *rsumip = NULL;
770 bhv_vnode_t *rvp = XFS_ITOV(rip);
773 xfs_ilock(rip, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT);
777 * Flush out the real time inodes.
779 if ((rbmip = mp->m_rbmip) != NULL) {
780 xfs_ilock(rbmip, XFS_ILOCK_EXCL);
782 error = xfs_iflush(rbmip, XFS_IFLUSH_SYNC);
783 xfs_iunlock(rbmip, XFS_ILOCK_EXCL);
785 if (error == EFSCORRUPTED)
788 ASSERT(vn_count(XFS_ITOV(rbmip)) == 1);
790 rsumip = mp->m_rsumip;
791 xfs_ilock(rsumip, XFS_ILOCK_EXCL);
793 error = xfs_iflush(rsumip, XFS_IFLUSH_SYNC);
794 xfs_iunlock(rsumip, XFS_ILOCK_EXCL);
796 if (error == EFSCORRUPTED)
799 ASSERT(vn_count(XFS_ITOV(rsumip)) == 1);
803 * Synchronously flush root inode to disk
805 error = xfs_iflush(rip, XFS_IFLUSH_SYNC);
806 if (error == EFSCORRUPTED)
809 if (vn_count(rvp) != 1 && !relocation) {
810 xfs_iunlock(rip, XFS_ILOCK_EXCL);
811 return XFS_ERROR(EBUSY);
815 * Release dquot that rootinode, rbmino and rsumino might be holding,
816 * flush and purge the quota inodes.
818 error = XFS_QM_UNMOUNT(mp);
819 if (error == EFSCORRUPTED)
823 VN_RELE(XFS_ITOV(rbmip));
824 VN_RELE(XFS_ITOV(rsumip));
827 xfs_iunlock(rip, XFS_ILOCK_EXCL);
834 xfs_iunlock(rip, XFS_ILOCK_EXCL);
836 return XFS_ERROR(EFSCORRUPTED);
840 * xfs_root extracts the root vnode from a vfs.
842 * vfsp -- the vfs struct for the desired file system
843 * vpp -- address of the caller's vnode pointer which should be
844 * set to the desired fs root vnode
853 vp = XFS_ITOV((XFS_BHVTOM(bdp))->m_rootip);
862 * Fill in the statvfs structure for the given file system. We use
863 * the superblock lock in the mount structure to ensure a consistent
864 * snapshot of the counters returned.
869 bhv_statvfs_t *statp,
878 mp = XFS_BHVTOM(bdp);
881 statp->f_type = XFS_SB_MAGIC;
883 xfs_icsb_sync_counters_flags(mp, XFS_ICSB_LAZY_COUNT);
885 statp->f_bsize = sbp->sb_blocksize;
886 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
887 statp->f_blocks = sbp->sb_dblocks - lsize;
888 statp->f_bfree = statp->f_bavail =
889 sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
890 fakeinos = statp->f_bfree << sbp->sb_inopblog;
892 fakeinos += mp->m_inoadd;
895 MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
900 statp->f_files = min_t(typeof(statp->f_files),
903 statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
904 XFS_SB_UNLOCK(mp, s);
906 xfs_statvfs_fsid(statp, mp);
907 statp->f_namelen = MAXNAMELEN - 1;
910 XFS_QM_DQSTATVFS(xfs_vtoi(vp), statp);
916 * xfs_sync flushes any pending I/O to file system vfsp.
918 * This routine is called by vfs_sync() to make sure that things make it
919 * out to disk eventually, on sync() system calls to flush out everything,
920 * and when the file system is unmounted. For the vfs_sync() case, all
921 * we really need to do is sync out the log to make all of our meta-data
922 * updates permanent (except for timestamps). For calls from pflushd(),
923 * dirty pages are kept moving by calling pdflush() on the inodes
924 * containing them. We also flush the inodes that we can lock without
925 * sleeping and the superblock if we can lock it without sleeping from
926 * vfs_sync() so that items at the tail of the log are always moving out.
929 * SYNC_BDFLUSH - We're being called from vfs_sync() so we don't want
930 * to sleep if we can help it. All we really need
931 * to do is ensure that the log is synced at least
932 * periodically. We also push the inodes and
933 * superblock if we can lock them without sleeping
934 * and they are not pinned.
935 * SYNC_ATTR - We need to flush the inodes. If SYNC_BDFLUSH is not
936 * set, then we really want to lock each inode and flush
938 * SYNC_WAIT - All the flushes that take place in this call should
940 * SYNC_DELWRI - This tells us to push dirty pages associated with
941 * inodes. SYNC_WAIT and SYNC_BDFLUSH are used to
942 * determine if they should be flushed sync, async, or
944 * SYNC_CLOSE - This flag is passed when the system is being
945 * unmounted. We should sync and invalidate everything.
946 * SYNC_FSDATA - This indicates that the caller would like to make
947 * sure the superblock is safe on disk. We can ensure
948 * this by simply making sure the log gets flushed
949 * if SYNC_BDFLUSH is set, and by actually writing it
951 * SYNC_IOWAIT - The caller wants us to wait for all data I/O to complete
952 * before we return (including direct I/O). Forms the drain
953 * side of the write barrier needed to safely quiesce the
964 xfs_mount_t *mp = XFS_BHVTOM(bdp);
968 * Get the Quota Manager to flush the dquots.
970 * If XFS quota support is not enabled or this filesystem
971 * instance does not use quotas XFS_QM_DQSYNC will always
974 error = XFS_QM_DQSYNC(mp, flags);
977 * If we got an IO error, we will be shutting down.
978 * So, there's nothing more for us to do here.
980 ASSERT(error != EIO || XFS_FORCED_SHUTDOWN(mp));
981 if (XFS_FORCED_SHUTDOWN(mp))
982 return XFS_ERROR(error);
985 if (flags & SYNC_IOWAIT)
986 xfs_filestream_flush(mp);
988 return xfs_syncsub(mp, flags, NULL);
992 * xfs sync routine for internal use
994 * This routine supports all of the flags defined for the generic vfs_sync
995 * interface as explained above under xfs_sync.
1004 xfs_inode_t *ip = NULL;
1005 xfs_inode_t *ip_next;
1007 bhv_vnode_t *vp = NULL;
1012 uint base_lock_flags;
1013 boolean_t mount_locked;
1014 boolean_t vnode_refed;
1017 xfs_iptr_t *ipointer;
1019 boolean_t ipointer_in = B_FALSE;
1021 #define IPOINTER_SET ipointer_in = B_TRUE
1022 #define IPOINTER_CLR ipointer_in = B_FALSE
1024 #define IPOINTER_SET
1025 #define IPOINTER_CLR
1029 /* Insert a marker record into the inode list after inode ip. The list
1030 * must be locked when this is called. After the call the list will no
1033 #define IPOINTER_INSERT(ip, mp) { \
1034 ASSERT(ipointer_in == B_FALSE); \
1035 ipointer->ip_mnext = ip->i_mnext; \
1036 ipointer->ip_mprev = ip; \
1037 ip->i_mnext = (xfs_inode_t *)ipointer; \
1038 ipointer->ip_mnext->i_mprev = (xfs_inode_t *)ipointer; \
1040 XFS_MOUNT_IUNLOCK(mp); \
1041 mount_locked = B_FALSE; \
1045 /* Remove the marker from the inode list. If the marker was the only item
1046 * in the list then there are no remaining inodes and we should zero out
1047 * the whole list. If we are the current head of the list then move the head
1050 #define IPOINTER_REMOVE(ip, mp) { \
1051 ASSERT(ipointer_in == B_TRUE); \
1052 if (ipointer->ip_mnext != (xfs_inode_t *)ipointer) { \
1053 ip = ipointer->ip_mnext; \
1054 ip->i_mprev = ipointer->ip_mprev; \
1055 ipointer->ip_mprev->i_mnext = ip; \
1056 if (mp->m_inodes == (xfs_inode_t *)ipointer) { \
1057 mp->m_inodes = ip; \
1060 ASSERT(mp->m_inodes == (xfs_inode_t *)ipointer); \
1061 mp->m_inodes = NULL; \
1067 #define XFS_PREEMPT_MASK 0x7f
1071 if (XFS_MTOVFS(mp)->vfs_flag & VFS_RDONLY)
1077 /* Allocate a reference marker */
1078 ipointer = (xfs_iptr_t *)kmem_zalloc(sizeof(xfs_iptr_t), KM_SLEEP);
1080 fflag = XFS_B_ASYNC; /* default is don't wait */
1081 if (flags & (SYNC_BDFLUSH | SYNC_DELWRI))
1082 fflag = XFS_B_DELWRI;
1083 if (flags & SYNC_WAIT)
1084 fflag = 0; /* synchronous overrides all */
1086 base_lock_flags = XFS_ILOCK_SHARED;
1087 if (flags & (SYNC_DELWRI | SYNC_CLOSE)) {
1089 * We need the I/O lock if we're going to call any of
1090 * the flush/inval routines.
1092 base_lock_flags |= XFS_IOLOCK_SHARED;
1095 XFS_MOUNT_ILOCK(mp);
1099 mount_locked = B_TRUE;
1100 vnode_refed = B_FALSE;
1105 ASSERT(ipointer_in == B_FALSE);
1106 ASSERT(vnode_refed == B_FALSE);
1108 lock_flags = base_lock_flags;
1111 * There were no inodes in the list, just break out
1119 * We found another sync thread marker - skip it
1121 if (ip->i_mount == NULL) {
1126 vp = XFS_ITOV_NULL(ip);
1129 * If the vnode is gone then this is being torn down,
1130 * call reclaim if it is flushed, else let regular flush
1131 * code deal with it later in the loop.
1135 /* Skip ones already in reclaim */
1136 if (ip->i_flags & XFS_IRECLAIM) {
1140 if (xfs_ilock_nowait(ip, XFS_ILOCK_EXCL) == 0) {
1142 } else if ((xfs_ipincount(ip) == 0) &&
1143 xfs_iflock_nowait(ip)) {
1144 IPOINTER_INSERT(ip, mp);
1146 xfs_finish_reclaim(ip, 1,
1147 XFS_IFLUSH_DELWRI_ELSE_ASYNC);
1149 XFS_MOUNT_ILOCK(mp);
1150 mount_locked = B_TRUE;
1151 IPOINTER_REMOVE(ip, mp);
1153 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1164 if (XFS_FORCED_SHUTDOWN(mp) && !(flags & SYNC_CLOSE)) {
1165 XFS_MOUNT_IUNLOCK(mp);
1166 kmem_free(ipointer, sizeof(xfs_iptr_t));
1171 * If this is just vfs_sync() or pflushd() calling
1172 * then we can skip inodes for which it looks like
1173 * there is nothing to do. Since we don't have the
1174 * inode locked this is racy, but these are periodic
1175 * calls so it doesn't matter. For the others we want
1176 * to know for sure, so we at least try to lock them.
1178 if (flags & SYNC_BDFLUSH) {
1179 if (((ip->i_itemp == NULL) ||
1180 !(ip->i_itemp->ili_format.ilf_fields &
1182 (ip->i_update_core == 0)) {
1189 * Try to lock without sleeping. We're out of order with
1190 * the inode list lock here, so if we fail we need to drop
1191 * the mount lock and try again. If we're called from
1192 * bdflush() here, then don't bother.
1194 * The inode lock here actually coordinates with the
1195 * almost spurious inode lock in xfs_ireclaim() to prevent
1196 * the vnode we handle here without a reference from
1197 * being freed while we reference it. If we lock the inode
1198 * while it's on the mount list here, then the spurious inode
1199 * lock in xfs_ireclaim() after the inode is pulled from
1200 * the mount list will sleep until we release it here.
1201 * This keeps the vnode from being freed while we reference
1204 if (xfs_ilock_nowait(ip, lock_flags) == 0) {
1205 if ((flags & SYNC_BDFLUSH) || (vp == NULL)) {
1216 IPOINTER_INSERT(ip, mp);
1217 xfs_ilock(ip, lock_flags);
1219 ASSERT(vp == XFS_ITOV(ip));
1220 ASSERT(ip->i_mount == mp);
1222 vnode_refed = B_TRUE;
1225 /* From here on in the loop we may have a marker record
1226 * in the inode list.
1230 * If we have to flush data or wait for I/O completion
1231 * we need to drop the ilock that we currently hold.
1232 * If we need to drop the lock, insert a marker if we
1233 * have not already done so.
1235 if ((flags & (SYNC_CLOSE|SYNC_IOWAIT)) ||
1236 ((flags & SYNC_DELWRI) && VN_DIRTY(vp))) {
1238 IPOINTER_INSERT(ip, mp);
1240 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1242 if (flags & SYNC_CLOSE) {
1243 /* Shutdown case. Flush and invalidate. */
1244 if (XFS_FORCED_SHUTDOWN(mp))
1245 xfs_tosspages(ip, 0, -1,
1248 error = xfs_flushinval_pages(ip,
1250 } else if ((flags & SYNC_DELWRI) && VN_DIRTY(vp)) {
1251 error = xfs_flush_pages(ip, 0,
1252 -1, fflag, FI_NONE);
1256 * When freezing, we need to wait ensure all I/O (including direct
1257 * I/O) is complete to ensure no further data modification can take
1258 * place after this point
1260 if (flags & SYNC_IOWAIT)
1263 xfs_ilock(ip, XFS_ILOCK_SHARED);
1266 if (flags & SYNC_BDFLUSH) {
1267 if ((flags & SYNC_ATTR) &&
1268 ((ip->i_update_core) ||
1269 ((ip->i_itemp != NULL) &&
1270 (ip->i_itemp->ili_format.ilf_fields != 0)))) {
1272 /* Insert marker and drop lock if not already
1276 IPOINTER_INSERT(ip, mp);
1280 * We don't want the periodic flushing of the
1281 * inodes by vfs_sync() to interfere with
1282 * I/O to the file, especially read I/O
1283 * where it is only the access time stamp
1284 * that is being flushed out. To prevent
1285 * long periods where we have both inode
1286 * locks held shared here while reading the
1287 * inode's buffer in from disk, we drop the
1288 * inode lock while reading in the inode
1289 * buffer. We have to release the buffer
1290 * and reacquire the inode lock so that they
1291 * are acquired in the proper order (inode
1292 * locks first). The buffer will go at the
1293 * end of the lru chain, though, so we can
1294 * expect it to still be there when we go
1295 * for it again in xfs_iflush().
1297 if ((xfs_ipincount(ip) == 0) &&
1298 xfs_iflock_nowait(ip)) {
1301 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1303 error = xfs_itobp(mp, NULL, ip,
1308 /* Bailing out, remove the
1309 * marker and free it.
1311 XFS_MOUNT_ILOCK(mp);
1312 IPOINTER_REMOVE(ip, mp);
1313 XFS_MOUNT_IUNLOCK(mp);
1315 ASSERT(!(lock_flags &
1316 XFS_IOLOCK_SHARED));
1319 sizeof(xfs_iptr_t));
1324 * Since we dropped the inode lock,
1325 * the inode may have been reclaimed.
1326 * Therefore, we reacquire the mount
1327 * lock and check to see if we were the
1328 * inode reclaimed. If this happened
1329 * then the ipointer marker will no
1330 * longer point back at us. In this
1331 * case, move ip along to the inode
1332 * after the marker, remove the marker
1335 XFS_MOUNT_ILOCK(mp);
1336 mount_locked = B_TRUE;
1338 if (ip != ipointer->ip_mprev) {
1339 IPOINTER_REMOVE(ip, mp);
1341 ASSERT(!vnode_refed);
1342 ASSERT(!(lock_flags &
1343 XFS_IOLOCK_SHARED));
1347 ASSERT(ip->i_mount == mp);
1349 if (xfs_ilock_nowait(ip,
1350 XFS_ILOCK_SHARED) == 0) {
1351 ASSERT(ip->i_mount == mp);
1353 * We failed to reacquire
1354 * the inode lock without
1355 * sleeping, so just skip
1356 * the inode for now. We
1357 * clear the ILOCK bit from
1358 * the lock_flags so that we
1359 * won't try to drop a lock
1360 * we don't hold below.
1362 lock_flags &= ~XFS_ILOCK_SHARED;
1363 IPOINTER_REMOVE(ip_next, mp);
1364 } else if ((xfs_ipincount(ip) == 0) &&
1365 xfs_iflock_nowait(ip)) {
1366 ASSERT(ip->i_mount == mp);
1368 * Since this is vfs_sync()
1369 * calling we only flush the
1370 * inode out if we can lock
1371 * it without sleeping and
1372 * it is not pinned. Drop
1373 * the mount lock here so
1374 * that we don't hold it for
1375 * too long. We already have
1376 * a marker in the list here.
1378 XFS_MOUNT_IUNLOCK(mp);
1379 mount_locked = B_FALSE;
1380 error = xfs_iflush(ip,
1383 ASSERT(ip->i_mount == mp);
1384 IPOINTER_REMOVE(ip_next, mp);
1391 if ((flags & SYNC_ATTR) &&
1392 ((ip->i_update_core) ||
1393 ((ip->i_itemp != NULL) &&
1394 (ip->i_itemp->ili_format.ilf_fields != 0)))) {
1396 IPOINTER_INSERT(ip, mp);
1399 if (flags & SYNC_WAIT) {
1401 error = xfs_iflush(ip,
1405 * If we can't acquire the flush
1406 * lock, then the inode is already
1407 * being flushed so don't bother
1408 * waiting. If we can lock it then
1409 * do a delwri flush so we can
1410 * combine multiple inode flushes
1411 * in each disk write.
1413 if (xfs_iflock_nowait(ip)) {
1414 error = xfs_iflush(ip,
1423 if (lock_flags != 0) {
1424 xfs_iunlock(ip, lock_flags);
1429 * If we had to take a reference on the vnode
1430 * above, then wait until after we've unlocked
1431 * the inode to release the reference. This is
1432 * because we can be already holding the inode
1433 * lock when VN_RELE() calls xfs_inactive().
1435 * Make sure to drop the mount lock before calling
1436 * VN_RELE() so that we don't trip over ourselves if
1437 * we have to go for the mount lock again in the
1441 IPOINTER_INSERT(ip, mp);
1446 vnode_refed = B_FALSE;
1454 * bail out if the filesystem is corrupted.
1456 if (error == EFSCORRUPTED) {
1457 if (!mount_locked) {
1458 XFS_MOUNT_ILOCK(mp);
1459 IPOINTER_REMOVE(ip, mp);
1461 XFS_MOUNT_IUNLOCK(mp);
1462 ASSERT(ipointer_in == B_FALSE);
1463 kmem_free(ipointer, sizeof(xfs_iptr_t));
1464 return XFS_ERROR(error);
1467 /* Let other threads have a chance at the mount lock
1468 * if we have looped many times without dropping the
1471 if ((++preempt & XFS_PREEMPT_MASK) == 0) {
1473 IPOINTER_INSERT(ip, mp);
1477 if (mount_locked == B_FALSE) {
1478 XFS_MOUNT_ILOCK(mp);
1479 mount_locked = B_TRUE;
1480 IPOINTER_REMOVE(ip, mp);
1484 ASSERT(ipointer_in == B_FALSE);
1487 } while (ip != mp->m_inodes);
1489 XFS_MOUNT_IUNLOCK(mp);
1491 ASSERT(ipointer_in == B_FALSE);
1493 kmem_free(ipointer, sizeof(xfs_iptr_t));
1494 return XFS_ERROR(last_error);
1498 * xfs sync routine for internal use
1500 * This routine supports all of the flags defined for the generic vfs_sync
1501 * interface as explained above under xfs_sync.
1512 uint log_flags = XFS_LOG_FORCE;
1514 xfs_buf_log_item_t *bip;
1517 * Sync out the log. This ensures that the log is periodically
1518 * flushed even if there is not enough activity to fill it up.
1520 if (flags & SYNC_WAIT)
1521 log_flags |= XFS_LOG_SYNC;
1523 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1525 if (flags & (SYNC_ATTR|SYNC_DELWRI)) {
1526 if (flags & SYNC_BDFLUSH)
1527 xfs_finish_reclaim_all(mp, 1);
1529 error = xfs_sync_inodes(mp, flags, bypassed);
1533 * Flushing out dirty data above probably generated more
1534 * log activity, so if this isn't vfs_sync() then flush
1537 if (flags & SYNC_DELWRI) {
1538 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1541 if (flags & SYNC_FSDATA) {
1543 * If this is vfs_sync() then only sync the superblock
1544 * if we can lock it without sleeping and it is not pinned.
1546 if (flags & SYNC_BDFLUSH) {
1547 bp = xfs_getsb(mp, XFS_BUF_TRYLOCK);
1549 bip = XFS_BUF_FSPRIVATE(bp,xfs_buf_log_item_t*);
1550 if ((bip != NULL) &&
1551 xfs_buf_item_dirty(bip)) {
1552 if (!(XFS_BUF_ISPINNED(bp))) {
1554 error = xfs_bwrite(mp, bp);
1563 bp = xfs_getsb(mp, 0);
1565 * If the buffer is pinned then push on the log so
1566 * we won't get stuck waiting in the write for
1567 * someone, maybe ourselves, to flush the log.
1568 * Even though we just pushed the log above, we
1569 * did not have the superblock buffer locked at
1570 * that point so it can become pinned in between
1573 if (XFS_BUF_ISPINNED(bp))
1574 xfs_log_force(mp, (xfs_lsn_t)0, XFS_LOG_FORCE);
1575 if (flags & SYNC_WAIT)
1576 XFS_BUF_UNASYNC(bp);
1579 error = xfs_bwrite(mp, bp);
1587 * If this is the periodic sync, then kick some entries out of
1588 * the reference cache. This ensures that idle entries are
1589 * eventually kicked out of the cache.
1591 if (flags & SYNC_REFCACHE) {
1592 if (flags & SYNC_WAIT)
1593 xfs_refcache_purge_mp(mp);
1595 xfs_refcache_purge_some(mp);
1599 * If asked, update the disk superblock with incore counter values if we
1600 * are using non-persistent counters so that they don't get too far out
1601 * of sync if we crash or get a forced shutdown. We don't want to force
1602 * this to disk, just get a transaction into the iclogs....
1604 if (flags & SYNC_SUPER)
1605 xfs_log_sbcount(mp, 0);
1608 * Now check to see if the log needs a "dummy" transaction.
1611 if (!(flags & SYNC_REMOUNT) && xfs_log_need_covered(mp)) {
1616 * Put a dummy transaction in the log to tell
1617 * recovery that all others are OK.
1619 tp = xfs_trans_alloc(mp, XFS_TRANS_DUMMY1);
1620 if ((error = xfs_trans_reserve(tp, 0,
1621 XFS_ICHANGE_LOG_RES(mp),
1623 xfs_trans_cancel(tp, 0);
1628 xfs_ilock(ip, XFS_ILOCK_EXCL);
1630 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
1631 xfs_trans_ihold(tp, ip);
1632 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
1633 error = xfs_trans_commit(tp, 0);
1634 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1635 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1639 * When shutting down, we need to insure that the AIL is pushed
1640 * to disk or the filesystem can appear corrupt from the PROM.
1642 if ((flags & (SYNC_CLOSE|SYNC_WAIT)) == (SYNC_CLOSE|SYNC_WAIT)) {
1643 XFS_bflush(mp->m_ddev_targp);
1644 if (mp->m_rtdev_targp) {
1645 XFS_bflush(mp->m_rtdev_targp);
1649 return XFS_ERROR(last_error);
1653 * xfs_vget - called by DMAPI and NFSD to get vnode from file handle
1661 xfs_mount_t *mp = XFS_BHVTOM(bdp);
1662 xfs_fid_t *xfid = (struct xfs_fid *)fidp;
1669 * Invalid. Since handles can be created in user space and passed in
1670 * via gethandle(), this is not cause for a panic.
1672 if (xfid->xfs_fid_len != sizeof(*xfid) - sizeof(xfid->xfs_fid_len))
1673 return XFS_ERROR(EINVAL);
1675 ino = xfid->xfs_fid_ino;
1676 igen = xfid->xfs_fid_gen;
1679 * NFS can sometimes send requests for ino 0. Fail them gracefully.
1682 return XFS_ERROR(ESTALE);
1684 error = xfs_iget(mp, NULL, ino, 0, XFS_ILOCK_SHARED, &ip, 0);
1692 return XFS_ERROR(EIO);
1695 if (ip->i_d.di_mode == 0 || ip->i_d.di_gen != igen) {
1696 xfs_iput_new(ip, XFS_ILOCK_SHARED);
1698 return XFS_ERROR(ENOENT);
1701 *vpp = XFS_ITOV(ip);
1702 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1707 #define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
1708 #define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
1709 #define MNTOPT_LOGDEV "logdev" /* log device */
1710 #define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
1711 #define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
1712 #define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
1713 #define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
1714 #define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
1715 #define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
1716 #define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
1717 #define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
1718 #define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
1719 #define MNTOPT_MTPT "mtpt" /* filesystem mount point */
1720 #define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
1721 #define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
1722 #define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
1723 #define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
1724 #define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
1725 #define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
1726 #define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
1727 * unwritten extent conversion */
1728 #define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
1729 #define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
1730 #define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
1731 #define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
1732 #define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
1733 #define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
1734 #define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
1736 #define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
1737 #define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
1738 #define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
1739 #define MNTOPT_QUOTA "quota" /* disk quotas (user) */
1740 #define MNTOPT_NOQUOTA "noquota" /* no quotas */
1741 #define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */
1742 #define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */
1743 #define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */
1744 #define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */
1745 #define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */
1746 #define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */
1747 #define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
1748 #define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
1749 #define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
1750 #define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */
1751 #define MNTOPT_DMAPI "dmapi" /* DMI enabled (DMAPI / XDSM) */
1752 #define MNTOPT_XDSM "xdsm" /* DMI enabled (DMAPI / XDSM) */
1753 #define MNTOPT_DMI "dmi" /* DMI enabled (DMAPI / XDSM) */
1755 STATIC unsigned long
1756 suffix_strtoul(char *s, char **endp, unsigned int base)
1758 int last, shift_left_factor = 0;
1761 last = strlen(value) - 1;
1762 if (value[last] == 'K' || value[last] == 'k') {
1763 shift_left_factor = 10;
1766 if (value[last] == 'M' || value[last] == 'm') {
1767 shift_left_factor = 20;
1770 if (value[last] == 'G' || value[last] == 'g') {
1771 shift_left_factor = 30;
1775 return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
1780 struct bhv_desc *bhv,
1782 struct xfs_mount_args *args,
1785 bhv_vfs_t *vfsp = bhvtovfs(bhv);
1786 char *this_char, *value, *eov;
1787 int dsunit, dswidth, vol_dsunit, vol_dswidth;
1791 * Applications using DMI filesystems often expect the
1792 * inode generation number to be monotonically increasing.
1793 * If we delete inode chunks we break this assumption, so
1794 * keep unused inode chunks on disk for DMI filesystems
1795 * until we come up with a better solution.
1796 * Note that if "ikeep" or "noikeep" mount options are
1797 * supplied, then they are honored.
1799 if (!(args->flags & XFSMNT_DMAPI))
1800 args->flags |= XFSMNT_IDELETE;
1802 args->flags |= XFSMNT_BARRIER;
1803 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
1808 iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0;
1810 while ((this_char = strsep(&options, ",")) != NULL) {
1813 if ((value = strchr(this_char, '=')) != NULL)
1816 if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
1817 if (!value || !*value) {
1819 "XFS: %s option requires an argument",
1823 args->logbufs = simple_strtoul(value, &eov, 10);
1824 } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
1825 if (!value || !*value) {
1827 "XFS: %s option requires an argument",
1831 args->logbufsize = suffix_strtoul(value, &eov, 10);
1832 } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
1833 if (!value || !*value) {
1835 "XFS: %s option requires an argument",
1839 strncpy(args->logname, value, MAXNAMELEN);
1840 } else if (!strcmp(this_char, MNTOPT_MTPT)) {
1841 if (!value || !*value) {
1843 "XFS: %s option requires an argument",
1847 strncpy(args->mtpt, value, MAXNAMELEN);
1848 } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
1849 if (!value || !*value) {
1851 "XFS: %s option requires an argument",
1855 strncpy(args->rtname, value, MAXNAMELEN);
1856 } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
1857 if (!value || !*value) {
1859 "XFS: %s option requires an argument",
1863 iosize = simple_strtoul(value, &eov, 10);
1864 args->flags |= XFSMNT_IOSIZE;
1865 args->iosizelog = (uint8_t) iosize;
1866 } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
1867 if (!value || !*value) {
1869 "XFS: %s option requires an argument",
1873 iosize = suffix_strtoul(value, &eov, 10);
1874 args->flags |= XFSMNT_IOSIZE;
1875 args->iosizelog = ffs(iosize) - 1;
1876 } else if (!strcmp(this_char, MNTOPT_GRPID) ||
1877 !strcmp(this_char, MNTOPT_BSDGROUPS)) {
1878 vfsp->vfs_flag |= VFS_GRPID;
1879 } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
1880 !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
1881 vfsp->vfs_flag &= ~VFS_GRPID;
1882 } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
1883 args->flags |= XFSMNT_WSYNC;
1884 } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
1885 args->flags |= XFSMNT_OSYNCISOSYNC;
1886 } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
1887 args->flags |= XFSMNT_NORECOVERY;
1888 } else if (!strcmp(this_char, MNTOPT_INO64)) {
1889 args->flags |= XFSMNT_INO64;
1892 "XFS: %s option not allowed on this system",
1896 } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
1897 args->flags |= XFSMNT_NOALIGN;
1898 } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
1899 args->flags |= XFSMNT_SWALLOC;
1900 } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
1901 if (!value || !*value) {
1903 "XFS: %s option requires an argument",
1907 dsunit = simple_strtoul(value, &eov, 10);
1908 } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
1909 if (!value || !*value) {
1911 "XFS: %s option requires an argument",
1915 dswidth = simple_strtoul(value, &eov, 10);
1916 } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
1917 args->flags &= ~XFSMNT_32BITINODES;
1920 "XFS: %s option not allowed on this system",
1924 } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
1925 args->flags |= XFSMNT_NOUUID;
1926 } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
1927 args->flags |= XFSMNT_BARRIER;
1928 } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
1929 args->flags &= ~XFSMNT_BARRIER;
1930 } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
1931 args->flags &= ~XFSMNT_IDELETE;
1932 } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
1933 args->flags |= XFSMNT_IDELETE;
1934 } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
1935 args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE;
1936 } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
1937 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
1938 } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
1939 args->flags |= XFSMNT_ATTR2;
1940 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
1941 args->flags &= ~XFSMNT_ATTR2;
1942 } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
1943 args->flags2 |= XFSMNT2_FILESTREAMS;
1944 } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
1945 args->flags &= ~(XFSMNT_UQUOTAENF|XFSMNT_UQUOTA);
1946 args->flags &= ~(XFSMNT_GQUOTAENF|XFSMNT_GQUOTA);
1947 } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
1948 !strcmp(this_char, MNTOPT_UQUOTA) ||
1949 !strcmp(this_char, MNTOPT_USRQUOTA)) {
1950 args->flags |= XFSMNT_UQUOTA | XFSMNT_UQUOTAENF;
1951 } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
1952 !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
1953 args->flags |= XFSMNT_UQUOTA;
1954 args->flags &= ~XFSMNT_UQUOTAENF;
1955 } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
1956 !strcmp(this_char, MNTOPT_PRJQUOTA)) {
1957 args->flags |= XFSMNT_PQUOTA | XFSMNT_PQUOTAENF;
1958 } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
1959 args->flags |= XFSMNT_PQUOTA;
1960 args->flags &= ~XFSMNT_PQUOTAENF;
1961 } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
1962 !strcmp(this_char, MNTOPT_GRPQUOTA)) {
1963 args->flags |= XFSMNT_GQUOTA | XFSMNT_GQUOTAENF;
1964 } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
1965 args->flags |= XFSMNT_GQUOTA;
1966 args->flags &= ~XFSMNT_GQUOTAENF;
1967 } else if (!strcmp(this_char, MNTOPT_DMAPI)) {
1968 args->flags |= XFSMNT_DMAPI;
1969 } else if (!strcmp(this_char, MNTOPT_XDSM)) {
1970 args->flags |= XFSMNT_DMAPI;
1971 } else if (!strcmp(this_char, MNTOPT_DMI)) {
1972 args->flags |= XFSMNT_DMAPI;
1973 } else if (!strcmp(this_char, "ihashsize")) {
1975 "XFS: ihashsize no longer used, option is deprecated.");
1976 } else if (!strcmp(this_char, "osyncisdsync")) {
1977 /* no-op, this is now the default */
1979 "XFS: osyncisdsync is now the default, option is deprecated.");
1980 } else if (!strcmp(this_char, "irixsgid")) {
1982 "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
1985 "XFS: unknown mount option [%s].", this_char);
1990 if (args->flags & XFSMNT_NORECOVERY) {
1991 if ((vfsp->vfs_flag & VFS_RDONLY) == 0) {
1993 "XFS: no-recovery mounts must be read-only.");
1998 if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) {
2000 "XFS: sunit and swidth options incompatible with the noalign option");
2004 if ((args->flags & XFSMNT_GQUOTA) && (args->flags & XFSMNT_PQUOTA)) {
2006 "XFS: cannot mount with both project and group quota");
2010 if ((args->flags & XFSMNT_DMAPI) && *args->mtpt == '\0') {
2011 printk("XFS: %s option needs the mount point option as well\n",
2016 if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
2018 "XFS: sunit and swidth must be specified together");
2022 if (dsunit && (dswidth % dsunit != 0)) {
2024 "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
2029 if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
2031 args->sunit = dsunit;
2032 args->flags |= XFSMNT_RETERR;
2034 args->sunit = vol_dsunit;
2036 dswidth ? (args->swidth = dswidth) :
2037 (args->swidth = vol_dswidth);
2039 args->sunit = args->swidth = 0;
2043 if (args->flags & XFSMNT_32BITINODES)
2044 vfsp->vfs_flag |= VFS_32BITINODES;
2046 args->flags |= XFSMNT_FLAGS2;
2052 struct bhv_desc *bhv,
2055 static struct proc_xfs_info {
2059 /* the few simple ones we can get from the mount struct */
2060 { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
2061 { XFS_MOUNT_INO64, "," MNTOPT_INO64 },
2062 { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
2063 { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
2064 { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
2065 { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
2066 { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
2069 struct proc_xfs_info *xfs_infop;
2070 struct xfs_mount *mp = XFS_BHVTOM(bhv);
2071 struct bhv_vfs *vfsp = XFS_MTOVFS(mp);
2073 for (xfs_infop = xfs_info; xfs_infop->flag; xfs_infop++) {
2074 if (mp->m_flags & xfs_infop->flag)
2075 seq_puts(m, xfs_infop->str);
2078 if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
2079 seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
2080 (int)(1 << mp->m_writeio_log) >> 10);
2082 if (mp->m_logbufs > 0)
2083 seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
2084 if (mp->m_logbsize > 0)
2085 seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
2088 seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
2090 seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
2092 if (mp->m_dalign > 0)
2093 seq_printf(m, "," MNTOPT_SUNIT "=%d",
2094 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
2095 if (mp->m_swidth > 0)
2096 seq_printf(m, "," MNTOPT_SWIDTH "=%d",
2097 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
2099 if (!(mp->m_flags & XFS_MOUNT_IDELETE))
2100 seq_printf(m, "," MNTOPT_IKEEP);
2101 if (!(mp->m_flags & XFS_MOUNT_COMPAT_IOSIZE))
2102 seq_printf(m, "," MNTOPT_LARGEIO);
2104 if (!(vfsp->vfs_flag & VFS_32BITINODES))
2105 seq_printf(m, "," MNTOPT_64BITINODE);
2106 if (vfsp->vfs_flag & VFS_GRPID)
2107 seq_printf(m, "," MNTOPT_GRPID);
2109 if (mp->m_qflags & XFS_UQUOTA_ACCT) {
2110 if (mp->m_qflags & XFS_UQUOTA_ENFD)
2111 seq_puts(m, "," MNTOPT_USRQUOTA);
2113 seq_puts(m, "," MNTOPT_UQUOTANOENF);
2116 if (mp->m_qflags & XFS_PQUOTA_ACCT) {
2117 if (mp->m_qflags & XFS_OQUOTA_ENFD)
2118 seq_puts(m, "," MNTOPT_PRJQUOTA);
2120 seq_puts(m, "," MNTOPT_PQUOTANOENF);
2123 if (mp->m_qflags & XFS_GQUOTA_ACCT) {
2124 if (mp->m_qflags & XFS_OQUOTA_ENFD)
2125 seq_puts(m, "," MNTOPT_GRPQUOTA);
2127 seq_puts(m, "," MNTOPT_GQUOTANOENF);
2130 if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
2131 seq_puts(m, "," MNTOPT_NOQUOTA);
2133 if (vfsp->vfs_flag & VFS_DMI)
2134 seq_puts(m, "," MNTOPT_DMAPI);
2139 * Second stage of a freeze. The data is already frozen so we only
2140 * need to take care of themetadata. Once that's done write a dummy
2141 * record to dirty the log in case of a crash while frozen.
2147 xfs_mount_t *mp = XFS_BHVTOM(bdp);
2149 xfs_attr_quiesce(mp);
2150 xfs_fs_log_dummy(mp);
2154 bhv_vfsops_t xfs_vfsops = {
2155 BHV_IDENTITY_INIT(VFS_BHV_XFS,VFS_POSITION_XFS),
2156 .vfs_parseargs = xfs_parseargs,
2157 .vfs_showargs = xfs_showargs,
2158 .vfs_mount = xfs_mount,
2159 .vfs_unmount = xfs_unmount,
2160 .vfs_mntupdate = xfs_mntupdate,
2161 .vfs_root = xfs_root,
2162 .vfs_statvfs = xfs_statvfs,
2163 .vfs_sync = xfs_sync,
2164 .vfs_vget = xfs_vget,
2165 .vfs_quotactl = (vfs_quotactl_t)fs_nosys,
2166 .vfs_init_vnode = xfs_initialize_vnode,
2167 .vfs_force_shutdown = xfs_do_force_shutdown,
2168 .vfs_freeze = xfs_freeze,