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"
58 #include "xfs_vfsops.h"
64 extern kmem_zone_t *xfs_bmap_free_item_zone;
65 extern kmem_zone_t *xfs_btree_cur_zone;
66 extern kmem_zone_t *xfs_trans_zone;
67 extern kmem_zone_t *xfs_buf_item_zone;
68 extern kmem_zone_t *xfs_dabuf_zone;
69 #ifdef XFS_DABUF_DEBUG
70 extern lock_t xfs_dabuf_global_lock;
71 spinlock_init(&xfs_dabuf_global_lock, "xfsda");
75 * Initialize all of the zone allocators we use.
77 xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
78 "xfs_bmap_free_item");
79 xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
81 xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
83 kmem_zone_init(sizeof(xfs_da_state_t), "xfs_da_state");
84 xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf");
85 xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
86 xfs_acl_zone_init(xfs_acl_zone, "xfs_acl");
88 xfs_filestream_init();
91 * The size of the zone allocated buf log item is the maximum
92 * size possible under XFS. This wastes a little bit of memory,
93 * but it is much faster.
96 kmem_zone_init((sizeof(xfs_buf_log_item_t) +
97 (((XFS_MAX_BLOCKSIZE / XFS_BLI_CHUNK) /
98 NBWORD) * sizeof(int))),
101 kmem_zone_init((sizeof(xfs_efd_log_item_t) +
102 ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
103 sizeof(xfs_extent_t))),
106 kmem_zone_init((sizeof(xfs_efi_log_item_t) +
107 ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
108 sizeof(xfs_extent_t))),
112 * These zones warrant special memory allocator hints
115 kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
116 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM |
117 KM_ZONE_SPREAD, NULL);
119 kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
120 KM_ZONE_SPREAD, NULL);
122 kmem_zone_init_flags(sizeof(xfs_icluster_t), "xfs_icluster",
123 KM_ZONE_SPREAD, NULL);
126 * Allocate global trace buffers.
128 #ifdef XFS_ALLOC_TRACE
129 xfs_alloc_trace_buf = ktrace_alloc(XFS_ALLOC_TRACE_SIZE, KM_SLEEP);
131 #ifdef XFS_BMAP_TRACE
132 xfs_bmap_trace_buf = ktrace_alloc(XFS_BMAP_TRACE_SIZE, KM_SLEEP);
134 #ifdef XFS_BMBT_TRACE
135 xfs_bmbt_trace_buf = ktrace_alloc(XFS_BMBT_TRACE_SIZE, KM_SLEEP);
137 #ifdef XFS_ATTR_TRACE
138 xfs_attr_trace_buf = ktrace_alloc(XFS_ATTR_TRACE_SIZE, KM_SLEEP);
140 #ifdef XFS_DIR2_TRACE
141 xfs_dir2_trace_buf = ktrace_alloc(XFS_DIR2_GTRACE_SIZE, KM_SLEEP);
146 #if (defined(DEBUG) || defined(INDUCE_IO_ERROR))
147 xfs_error_test_init();
148 #endif /* DEBUG || INDUCE_IO_ERROR */
151 xfs_sysctl_register();
158 extern kmem_zone_t *xfs_bmap_free_item_zone;
159 extern kmem_zone_t *xfs_btree_cur_zone;
160 extern kmem_zone_t *xfs_inode_zone;
161 extern kmem_zone_t *xfs_trans_zone;
162 extern kmem_zone_t *xfs_da_state_zone;
163 extern kmem_zone_t *xfs_dabuf_zone;
164 extern kmem_zone_t *xfs_efd_zone;
165 extern kmem_zone_t *xfs_efi_zone;
166 extern kmem_zone_t *xfs_buf_item_zone;
167 extern kmem_zone_t *xfs_icluster_zone;
169 xfs_cleanup_procfs();
170 xfs_sysctl_unregister();
171 xfs_refcache_destroy();
172 xfs_filestream_uninit();
173 xfs_mru_cache_uninit();
174 xfs_acl_zone_destroy(xfs_acl_zone);
176 #ifdef XFS_DIR2_TRACE
177 ktrace_free(xfs_dir2_trace_buf);
179 #ifdef XFS_ATTR_TRACE
180 ktrace_free(xfs_attr_trace_buf);
182 #ifdef XFS_BMBT_TRACE
183 ktrace_free(xfs_bmbt_trace_buf);
185 #ifdef XFS_BMAP_TRACE
186 ktrace_free(xfs_bmap_trace_buf);
188 #ifdef XFS_ALLOC_TRACE
189 ktrace_free(xfs_alloc_trace_buf);
192 kmem_zone_destroy(xfs_bmap_free_item_zone);
193 kmem_zone_destroy(xfs_btree_cur_zone);
194 kmem_zone_destroy(xfs_inode_zone);
195 kmem_zone_destroy(xfs_trans_zone);
196 kmem_zone_destroy(xfs_da_state_zone);
197 kmem_zone_destroy(xfs_dabuf_zone);
198 kmem_zone_destroy(xfs_buf_item_zone);
199 kmem_zone_destroy(xfs_efd_zone);
200 kmem_zone_destroy(xfs_efi_zone);
201 kmem_zone_destroy(xfs_ifork_zone);
202 kmem_zone_destroy(xfs_ili_zone);
203 kmem_zone_destroy(xfs_icluster_zone);
209 * This function fills in xfs_mount_t fields based on mount args.
210 * Note: the superblock has _not_ yet been read in.
215 struct xfs_mount_args *ap,
216 struct xfs_mount *mp)
218 /* Values are in BBs */
219 if ((ap->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
221 * At this point the superblock has not been read
222 * in, therefore we do not know the block size.
223 * Before the mount call ends we will convert
226 mp->m_dalign = ap->sunit;
227 mp->m_swidth = ap->swidth;
230 if (ap->logbufs != -1 &&
232 (ap->logbufs < XLOG_MIN_ICLOGS ||
233 ap->logbufs > XLOG_MAX_ICLOGS)) {
235 "XFS: invalid logbufs value: %d [not %d-%d]",
236 ap->logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
237 return XFS_ERROR(EINVAL);
239 mp->m_logbufs = ap->logbufs;
240 if (ap->logbufsize != -1 &&
241 ap->logbufsize != 0 &&
242 (ap->logbufsize < XLOG_MIN_RECORD_BSIZE ||
243 ap->logbufsize > XLOG_MAX_RECORD_BSIZE ||
244 !is_power_of_2(ap->logbufsize))) {
246 "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
248 return XFS_ERROR(EINVAL);
250 mp->m_logbsize = ap->logbufsize;
251 mp->m_fsname_len = strlen(ap->fsname) + 1;
252 mp->m_fsname = kmem_alloc(mp->m_fsname_len, KM_SLEEP);
253 strcpy(mp->m_fsname, ap->fsname);
255 mp->m_rtname = kmem_alloc(strlen(ap->rtname) + 1, KM_SLEEP);
256 strcpy(mp->m_rtname, ap->rtname);
258 if (ap->logname[0]) {
259 mp->m_logname = kmem_alloc(strlen(ap->logname) + 1, KM_SLEEP);
260 strcpy(mp->m_logname, ap->logname);
263 if (ap->flags & XFSMNT_WSYNC)
264 mp->m_flags |= XFS_MOUNT_WSYNC;
266 if (ap->flags & XFSMNT_INO64) {
267 mp->m_flags |= XFS_MOUNT_INO64;
268 mp->m_inoadd = XFS_INO64_OFFSET;
271 if (ap->flags & XFSMNT_RETERR)
272 mp->m_flags |= XFS_MOUNT_RETERR;
273 if (ap->flags & XFSMNT_NOALIGN)
274 mp->m_flags |= XFS_MOUNT_NOALIGN;
275 if (ap->flags & XFSMNT_SWALLOC)
276 mp->m_flags |= XFS_MOUNT_SWALLOC;
277 if (ap->flags & XFSMNT_OSYNCISOSYNC)
278 mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
279 if (ap->flags & XFSMNT_32BITINODES)
280 mp->m_flags |= XFS_MOUNT_32BITINODES;
282 if (ap->flags & XFSMNT_IOSIZE) {
283 if (ap->iosizelog > XFS_MAX_IO_LOG ||
284 ap->iosizelog < XFS_MIN_IO_LOG) {
286 "XFS: invalid log iosize: %d [not %d-%d]",
287 ap->iosizelog, XFS_MIN_IO_LOG,
289 return XFS_ERROR(EINVAL);
292 mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
293 mp->m_readio_log = mp->m_writeio_log = ap->iosizelog;
296 if (ap->flags & XFSMNT_IDELETE)
297 mp->m_flags |= XFS_MOUNT_IDELETE;
298 if (ap->flags & XFSMNT_DIRSYNC)
299 mp->m_flags |= XFS_MOUNT_DIRSYNC;
300 if (ap->flags & XFSMNT_ATTR2)
301 mp->m_flags |= XFS_MOUNT_ATTR2;
303 if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
304 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
307 * no recovery flag requires a read-only mount
309 if (ap->flags & XFSMNT_NORECOVERY) {
310 if (!(vfs->vfs_flag & VFS_RDONLY)) {
312 "XFS: tried to mount a FS read-write without recovery!");
313 return XFS_ERROR(EINVAL);
315 mp->m_flags |= XFS_MOUNT_NORECOVERY;
318 if (ap->flags & XFSMNT_NOUUID)
319 mp->m_flags |= XFS_MOUNT_NOUUID;
320 if (ap->flags & XFSMNT_BARRIER)
321 mp->m_flags |= XFS_MOUNT_BARRIER;
323 mp->m_flags &= ~XFS_MOUNT_BARRIER;
325 if (ap->flags2 & XFSMNT2_FILESTREAMS)
326 mp->m_flags |= XFS_MOUNT_FILESTREAMS;
328 if (ap->flags & XFSMNT_DMAPI)
329 vfs->vfs_flag |= VFS_DMI;
334 * This function fills in xfs_mount_t fields based on mount args.
335 * Note: the superblock _has_ now been read in.
340 struct xfs_mount_args *ap,
341 struct xfs_mount *mp)
343 int ronly = (vfs->vfs_flag & VFS_RDONLY);
345 /* Fail a mount where the logbuf is smaller then the log stripe */
346 if (XFS_SB_VERSION_HASLOGV2(&mp->m_sb)) {
347 if ((ap->logbufsize <= 0) &&
348 (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) {
349 mp->m_logbsize = mp->m_sb.sb_logsunit;
350 } else if (ap->logbufsize > 0 &&
351 ap->logbufsize < mp->m_sb.sb_logsunit) {
353 "XFS: logbuf size must be greater than or equal to log stripe size");
354 return XFS_ERROR(EINVAL);
357 /* Fail a mount if the logbuf is larger than 32K */
358 if (ap->logbufsize > XLOG_BIG_RECORD_BSIZE) {
360 "XFS: logbuf size for version 1 logs must be 16K or 32K");
361 return XFS_ERROR(EINVAL);
365 if (XFS_SB_VERSION_HASATTR2(&mp->m_sb)) {
366 mp->m_flags |= XFS_MOUNT_ATTR2;
370 * prohibit r/w mounts of read-only filesystems
372 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
374 "XFS: cannot mount a read-only filesystem as read-write");
375 return XFS_ERROR(EROFS);
379 * check for shared mount.
381 if (ap->flags & XFSMNT_SHARED) {
382 if (!XFS_SB_VERSION_HASSHARED(&mp->m_sb))
383 return XFS_ERROR(EINVAL);
386 * For IRIX 6.5, shared mounts must have the shared
387 * version bit set, have the persistent readonly
388 * field set, must be version 0 and can only be mounted
391 if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) ||
392 (mp->m_sb.sb_shared_vn != 0))
393 return XFS_ERROR(EINVAL);
395 mp->m_flags |= XFS_MOUNT_SHARED;
398 * Shared XFS V0 can't deal with DMI. Return EINVAL.
400 if (mp->m_sb.sb_shared_vn == 0 && (ap->flags & XFSMNT_DMAPI))
401 return XFS_ERROR(EINVAL);
404 if (ap->flags & XFSMNT_UQUOTA) {
405 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
406 if (ap->flags & XFSMNT_UQUOTAENF)
407 mp->m_qflags |= XFS_UQUOTA_ENFD;
410 if (ap->flags & XFSMNT_GQUOTA) {
411 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
412 if (ap->flags & XFSMNT_GQUOTAENF)
413 mp->m_qflags |= XFS_OQUOTA_ENFD;
414 } else if (ap->flags & XFSMNT_PQUOTA) {
415 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
416 if (ap->flags & XFSMNT_PQUOTAENF)
417 mp->m_qflags |= XFS_OQUOTA_ENFD;
426 * The file system configurations are:
427 * (1) device (partition) with data and internal log
428 * (2) logical volume with data and log subvolumes.
429 * (3) logical volume with data, log, and realtime subvolumes.
431 * We only have to handle opening the log and realtime volumes here if
432 * they are present. The data subvolume has already been opened by
433 * get_sb_bdev() and is stored in vfsp->vfs_super->s_bdev.
437 struct xfs_mount *mp,
438 struct xfs_mount_args *args,
441 struct bhv_vfs *vfsp = XFS_MTOVFS(mp);
443 struct block_device *ddev, *logdev, *rtdev;
444 int flags = 0, error;
446 ddev = vfsp->vfs_super->s_bdev;
447 logdev = rtdev = NULL;
449 error = xfs_dmops_get(mp, args);
452 error = xfs_qmops_get(mp, args);
457 * Setup xfs_mount function vectors from available behaviors
459 p = vfs_bhv_lookup(vfsp, VFS_POSITION_IO);
460 mp->m_io_ops = p ? *(xfs_ioops_t *) vfs_bhv_custom(p) : xfs_iocore_xfs;
462 if (args->flags & XFSMNT_QUIET)
463 flags |= XFS_MFSI_QUIET;
466 * Open real time and log devices - order is important.
468 if (args->logname[0]) {
469 error = xfs_blkdev_get(mp, args->logname, &logdev);
473 if (args->rtname[0]) {
474 error = xfs_blkdev_get(mp, args->rtname, &rtdev);
476 xfs_blkdev_put(logdev);
480 if (rtdev == ddev || rtdev == logdev) {
482 "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
483 xfs_blkdev_put(logdev);
484 xfs_blkdev_put(rtdev);
490 * Setup xfs_mount buffer target pointers
493 mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
494 if (!mp->m_ddev_targp) {
495 xfs_blkdev_put(logdev);
496 xfs_blkdev_put(rtdev);
500 mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
501 if (!mp->m_rtdev_targp) {
502 xfs_blkdev_put(logdev);
503 xfs_blkdev_put(rtdev);
507 mp->m_logdev_targp = (logdev && logdev != ddev) ?
508 xfs_alloc_buftarg(logdev, 1) : mp->m_ddev_targp;
509 if (!mp->m_logdev_targp) {
510 xfs_blkdev_put(logdev);
511 xfs_blkdev_put(rtdev);
516 * Setup flags based on mount(2) options and then the superblock
518 error = xfs_start_flags(vfsp, args, mp);
521 error = xfs_readsb(mp, flags);
524 error = xfs_finish_flags(vfsp, args, mp);
529 * Setup xfs_mount buffer target pointers based on superblock
531 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
532 mp->m_sb.sb_sectsize);
533 if (!error && logdev && logdev != ddev) {
534 unsigned int log_sector_size = BBSIZE;
536 if (XFS_SB_VERSION_HASSECTOR(&mp->m_sb))
537 log_sector_size = mp->m_sb.sb_logsectsize;
538 error = xfs_setsize_buftarg(mp->m_logdev_targp,
539 mp->m_sb.sb_blocksize,
543 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
544 mp->m_sb.sb_blocksize,
545 mp->m_sb.sb_sectsize);
549 if (mp->m_flags & XFS_MOUNT_BARRIER)
550 xfs_mountfs_check_barriers(mp);
552 if ((error = xfs_filestream_mount(mp)))
555 error = XFS_IOINIT(vfsp, args, flags);
559 XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, args->mtpt, args->fsname);
567 xfs_binval(mp->m_ddev_targp);
568 if (logdev && logdev != ddev)
569 xfs_binval(mp->m_logdev_targp);
571 xfs_binval(mp->m_rtdev_targp);
573 xfs_unmountfs_close(mp, credp);
585 bhv_vfs_t *vfsp = XFS_MTOVFS(mp);
588 int unmount_event_wanted = 0;
589 int unmount_event_flags = 0;
590 int xfs_unmountfs_needed = 0;
597 if (vfsp->vfs_flag & VFS_DMI) {
598 error = XFS_SEND_PREUNMOUNT(mp, vfsp,
599 rvp, DM_RIGHT_NULL, rvp, DM_RIGHT_NULL,
601 (mp->m_dmevmask & (1<<DM_EVENT_PREUNMOUNT))?
602 0:DM_FLAGS_UNWANTED);
604 return XFS_ERROR(error);
605 unmount_event_wanted = 1;
606 unmount_event_flags = (mp->m_dmevmask & (1<<DM_EVENT_UNMOUNT))?
607 0 : DM_FLAGS_UNWANTED;
611 * First blow any referenced inode from this file system
612 * out of the reference cache, and delete the timer.
614 xfs_refcache_purge_mp(mp);
617 * Blow away any referenced inode in the filestreams cache.
618 * This can and will cause log traffic as inodes go inactive
621 xfs_filestream_unmount(mp);
623 XFS_bflush(mp->m_ddev_targp);
624 error = xfs_unmount_flush(mp, 0);
628 ASSERT(vn_count(rvp) == 1);
631 * Drop the reference count
636 * If we're forcing a shutdown, typically because of a media error,
637 * we want to make sure we invalidate dirty pages that belong to
638 * referenced vnodes as well.
640 if (XFS_FORCED_SHUTDOWN(mp)) {
641 error = xfs_sync(mp, SYNC_WAIT | SYNC_CLOSE);
642 ASSERT(error != EFSCORRUPTED);
644 xfs_unmountfs_needed = 1;
647 /* Send DMAPI event, if required.
648 * Then do xfs_unmountfs() if needed.
649 * Then return error (or zero).
651 if (unmount_event_wanted) {
652 /* Note: mp structure must still exist for
653 * XFS_SEND_UNMOUNT() call.
655 XFS_SEND_UNMOUNT(mp, vfsp, error == 0 ? rvp : NULL,
656 DM_RIGHT_NULL, 0, error, unmount_event_flags);
658 if (xfs_unmountfs_needed) {
660 * Call common unmount function to flush to disk
661 * and free the super block buffer & mount structures.
663 xfs_unmountfs(mp, credp);
666 kmem_free(mp, sizeof(xfs_mount_t));
669 return XFS_ERROR(error);
676 int count = 0, pincount;
678 xfs_refcache_purge_mp(mp);
679 xfs_flush_buftarg(mp->m_ddev_targp, 0);
680 xfs_finish_reclaim_all(mp, 0);
682 /* This loop must run at least twice.
683 * The first instance of the loop will flush
684 * most meta data but that will generate more
685 * meta data (typically directory updates).
686 * Which then must be flushed and logged before
687 * we can write the unmount record.
690 xfs_syncsub(mp, SYNC_INODE_QUIESCE, NULL);
691 pincount = xfs_flush_buftarg(mp->m_ddev_targp, 1);
702 * Second stage of a quiesce. The data is already synced, now we have to take
703 * care of the metadata. New transactions are already blocked, so we need to
704 * wait for any remaining transactions to drain out before proceding.
710 /* wait for all modifications to complete */
711 while (atomic_read(&mp->m_active_trans) > 0)
714 /* flush inodes and push all remaining buffers out to disk */
717 ASSERT_ALWAYS(atomic_read(&mp->m_active_trans) == 0);
719 /* Push the superblock and write an unmount record */
720 xfs_log_sbcount(mp, 1);
721 xfs_log_unmount_write(mp);
722 xfs_unmountfs_writesb(mp);
727 struct xfs_mount *mp,
729 struct xfs_mount_args *args)
731 struct bhv_vfs *vfsp = XFS_MTOVFS(mp);
733 if (!(*flags & MS_RDONLY)) { /* rw/ro -> rw */
734 if (vfsp->vfs_flag & VFS_RDONLY)
735 vfsp->vfs_flag &= ~VFS_RDONLY;
736 if (args->flags & XFSMNT_BARRIER) {
737 mp->m_flags |= XFS_MOUNT_BARRIER;
738 xfs_mountfs_check_barriers(mp);
740 mp->m_flags &= ~XFS_MOUNT_BARRIER;
742 } else if (!(vfsp->vfs_flag & VFS_RDONLY)) { /* rw -> ro */
743 xfs_filestream_flush(mp);
744 bhv_vfs_sync(vfsp, SYNC_DATA_QUIESCE, NULL);
745 xfs_attr_quiesce(mp);
746 vfsp->vfs_flag |= VFS_RDONLY;
752 * xfs_unmount_flush implements a set of flush operation on special
753 * inodes, which are needed as a separate set of operations so that
754 * they can be called as part of relocation process.
758 xfs_mount_t *mp, /* Mount structure we are getting
760 int relocation) /* Called from vfs relocation. */
762 xfs_inode_t *rip = mp->m_rootip;
764 xfs_inode_t *rsumip = NULL;
765 bhv_vnode_t *rvp = XFS_ITOV(rip);
768 xfs_ilock(rip, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT);
772 * Flush out the real time inodes.
774 if ((rbmip = mp->m_rbmip) != NULL) {
775 xfs_ilock(rbmip, XFS_ILOCK_EXCL);
777 error = xfs_iflush(rbmip, XFS_IFLUSH_SYNC);
778 xfs_iunlock(rbmip, XFS_ILOCK_EXCL);
780 if (error == EFSCORRUPTED)
783 ASSERT(vn_count(XFS_ITOV(rbmip)) == 1);
785 rsumip = mp->m_rsumip;
786 xfs_ilock(rsumip, XFS_ILOCK_EXCL);
788 error = xfs_iflush(rsumip, XFS_IFLUSH_SYNC);
789 xfs_iunlock(rsumip, XFS_ILOCK_EXCL);
791 if (error == EFSCORRUPTED)
794 ASSERT(vn_count(XFS_ITOV(rsumip)) == 1);
798 * Synchronously flush root inode to disk
800 error = xfs_iflush(rip, XFS_IFLUSH_SYNC);
801 if (error == EFSCORRUPTED)
804 if (vn_count(rvp) != 1 && !relocation) {
805 xfs_iunlock(rip, XFS_ILOCK_EXCL);
806 return XFS_ERROR(EBUSY);
810 * Release dquot that rootinode, rbmino and rsumino might be holding,
811 * flush and purge the quota inodes.
813 error = XFS_QM_UNMOUNT(mp);
814 if (error == EFSCORRUPTED)
818 VN_RELE(XFS_ITOV(rbmip));
819 VN_RELE(XFS_ITOV(rsumip));
822 xfs_iunlock(rip, XFS_ILOCK_EXCL);
829 xfs_iunlock(rip, XFS_ILOCK_EXCL);
831 return XFS_ERROR(EFSCORRUPTED);
835 * xfs_root extracts the root vnode from a vfs.
837 * vfsp -- the vfs struct for the desired file system
838 * vpp -- address of the caller's vnode pointer which should be
839 * set to the desired fs root vnode
848 vp = XFS_ITOV(mp->m_rootip);
857 * Fill in the statvfs structure for the given file system. We use
858 * the superblock lock in the mount structure to ensure a consistent
859 * snapshot of the counters returned.
864 bhv_statvfs_t *statp,
874 statp->f_type = XFS_SB_MAGIC;
876 xfs_icsb_sync_counters_flags(mp, XFS_ICSB_LAZY_COUNT);
878 statp->f_bsize = sbp->sb_blocksize;
879 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
880 statp->f_blocks = sbp->sb_dblocks - lsize;
881 statp->f_bfree = statp->f_bavail =
882 sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
883 fakeinos = statp->f_bfree << sbp->sb_inopblog;
885 fakeinos += mp->m_inoadd;
888 MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
893 statp->f_files = min_t(typeof(statp->f_files),
896 statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
897 XFS_SB_UNLOCK(mp, s);
899 xfs_statvfs_fsid(statp, mp);
900 statp->f_namelen = MAXNAMELEN - 1;
903 XFS_QM_DQSTATVFS(xfs_vtoi(vp), statp);
909 * xfs_sync flushes any pending I/O to file system vfsp.
911 * This routine is called by vfs_sync() to make sure that things make it
912 * out to disk eventually, on sync() system calls to flush out everything,
913 * and when the file system is unmounted. For the vfs_sync() case, all
914 * we really need to do is sync out the log to make all of our meta-data
915 * updates permanent (except for timestamps). For calls from pflushd(),
916 * dirty pages are kept moving by calling pdflush() on the inodes
917 * containing them. We also flush the inodes that we can lock without
918 * sleeping and the superblock if we can lock it without sleeping from
919 * vfs_sync() so that items at the tail of the log are always moving out.
922 * SYNC_BDFLUSH - We're being called from vfs_sync() so we don't want
923 * to sleep if we can help it. All we really need
924 * to do is ensure that the log is synced at least
925 * periodically. We also push the inodes and
926 * superblock if we can lock them without sleeping
927 * and they are not pinned.
928 * SYNC_ATTR - We need to flush the inodes. If SYNC_BDFLUSH is not
929 * set, then we really want to lock each inode and flush
931 * SYNC_WAIT - All the flushes that take place in this call should
933 * SYNC_DELWRI - This tells us to push dirty pages associated with
934 * inodes. SYNC_WAIT and SYNC_BDFLUSH are used to
935 * determine if they should be flushed sync, async, or
937 * SYNC_CLOSE - This flag is passed when the system is being
938 * unmounted. We should sync and invalidate everything.
939 * SYNC_FSDATA - This indicates that the caller would like to make
940 * sure the superblock is safe on disk. We can ensure
941 * this by simply making sure the log gets flushed
942 * if SYNC_BDFLUSH is set, and by actually writing it
944 * SYNC_IOWAIT - The caller wants us to wait for all data I/O to complete
945 * before we return (including direct I/O). Forms the drain
946 * side of the write barrier needed to safely quiesce the
958 * Get the Quota Manager to flush the dquots.
960 * If XFS quota support is not enabled or this filesystem
961 * instance does not use quotas XFS_QM_DQSYNC will always
964 error = XFS_QM_DQSYNC(mp, flags);
967 * If we got an IO error, we will be shutting down.
968 * So, there's nothing more for us to do here.
970 ASSERT(error != EIO || XFS_FORCED_SHUTDOWN(mp));
971 if (XFS_FORCED_SHUTDOWN(mp))
972 return XFS_ERROR(error);
975 if (flags & SYNC_IOWAIT)
976 xfs_filestream_flush(mp);
978 return xfs_syncsub(mp, flags, NULL);
982 * xfs sync routine for internal use
984 * This routine supports all of the flags defined for the generic vfs_sync
985 * interface as explained above under xfs_sync.
994 xfs_inode_t *ip = NULL;
995 xfs_inode_t *ip_next;
997 bhv_vnode_t *vp = NULL;
1002 uint base_lock_flags;
1003 boolean_t mount_locked;
1004 boolean_t vnode_refed;
1007 xfs_iptr_t *ipointer;
1009 boolean_t ipointer_in = B_FALSE;
1011 #define IPOINTER_SET ipointer_in = B_TRUE
1012 #define IPOINTER_CLR ipointer_in = B_FALSE
1014 #define IPOINTER_SET
1015 #define IPOINTER_CLR
1019 /* Insert a marker record into the inode list after inode ip. The list
1020 * must be locked when this is called. After the call the list will no
1023 #define IPOINTER_INSERT(ip, mp) { \
1024 ASSERT(ipointer_in == B_FALSE); \
1025 ipointer->ip_mnext = ip->i_mnext; \
1026 ipointer->ip_mprev = ip; \
1027 ip->i_mnext = (xfs_inode_t *)ipointer; \
1028 ipointer->ip_mnext->i_mprev = (xfs_inode_t *)ipointer; \
1030 XFS_MOUNT_IUNLOCK(mp); \
1031 mount_locked = B_FALSE; \
1035 /* Remove the marker from the inode list. If the marker was the only item
1036 * in the list then there are no remaining inodes and we should zero out
1037 * the whole list. If we are the current head of the list then move the head
1040 #define IPOINTER_REMOVE(ip, mp) { \
1041 ASSERT(ipointer_in == B_TRUE); \
1042 if (ipointer->ip_mnext != (xfs_inode_t *)ipointer) { \
1043 ip = ipointer->ip_mnext; \
1044 ip->i_mprev = ipointer->ip_mprev; \
1045 ipointer->ip_mprev->i_mnext = ip; \
1046 if (mp->m_inodes == (xfs_inode_t *)ipointer) { \
1047 mp->m_inodes = ip; \
1050 ASSERT(mp->m_inodes == (xfs_inode_t *)ipointer); \
1051 mp->m_inodes = NULL; \
1057 #define XFS_PREEMPT_MASK 0x7f
1061 if (XFS_MTOVFS(mp)->vfs_flag & VFS_RDONLY)
1067 /* Allocate a reference marker */
1068 ipointer = (xfs_iptr_t *)kmem_zalloc(sizeof(xfs_iptr_t), KM_SLEEP);
1070 fflag = XFS_B_ASYNC; /* default is don't wait */
1071 if (flags & (SYNC_BDFLUSH | SYNC_DELWRI))
1072 fflag = XFS_B_DELWRI;
1073 if (flags & SYNC_WAIT)
1074 fflag = 0; /* synchronous overrides all */
1076 base_lock_flags = XFS_ILOCK_SHARED;
1077 if (flags & (SYNC_DELWRI | SYNC_CLOSE)) {
1079 * We need the I/O lock if we're going to call any of
1080 * the flush/inval routines.
1082 base_lock_flags |= XFS_IOLOCK_SHARED;
1085 XFS_MOUNT_ILOCK(mp);
1089 mount_locked = B_TRUE;
1090 vnode_refed = B_FALSE;
1095 ASSERT(ipointer_in == B_FALSE);
1096 ASSERT(vnode_refed == B_FALSE);
1098 lock_flags = base_lock_flags;
1101 * There were no inodes in the list, just break out
1109 * We found another sync thread marker - skip it
1111 if (ip->i_mount == NULL) {
1116 vp = XFS_ITOV_NULL(ip);
1119 * If the vnode is gone then this is being torn down,
1120 * call reclaim if it is flushed, else let regular flush
1121 * code deal with it later in the loop.
1125 /* Skip ones already in reclaim */
1126 if (ip->i_flags & XFS_IRECLAIM) {
1130 if (xfs_ilock_nowait(ip, XFS_ILOCK_EXCL) == 0) {
1132 } else if ((xfs_ipincount(ip) == 0) &&
1133 xfs_iflock_nowait(ip)) {
1134 IPOINTER_INSERT(ip, mp);
1136 xfs_finish_reclaim(ip, 1,
1137 XFS_IFLUSH_DELWRI_ELSE_ASYNC);
1139 XFS_MOUNT_ILOCK(mp);
1140 mount_locked = B_TRUE;
1141 IPOINTER_REMOVE(ip, mp);
1143 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1154 if (XFS_FORCED_SHUTDOWN(mp) && !(flags & SYNC_CLOSE)) {
1155 XFS_MOUNT_IUNLOCK(mp);
1156 kmem_free(ipointer, sizeof(xfs_iptr_t));
1161 * If this is just vfs_sync() or pflushd() calling
1162 * then we can skip inodes for which it looks like
1163 * there is nothing to do. Since we don't have the
1164 * inode locked this is racy, but these are periodic
1165 * calls so it doesn't matter. For the others we want
1166 * to know for sure, so we at least try to lock them.
1168 if (flags & SYNC_BDFLUSH) {
1169 if (((ip->i_itemp == NULL) ||
1170 !(ip->i_itemp->ili_format.ilf_fields &
1172 (ip->i_update_core == 0)) {
1179 * Try to lock without sleeping. We're out of order with
1180 * the inode list lock here, so if we fail we need to drop
1181 * the mount lock and try again. If we're called from
1182 * bdflush() here, then don't bother.
1184 * The inode lock here actually coordinates with the
1185 * almost spurious inode lock in xfs_ireclaim() to prevent
1186 * the vnode we handle here without a reference from
1187 * being freed while we reference it. If we lock the inode
1188 * while it's on the mount list here, then the spurious inode
1189 * lock in xfs_ireclaim() after the inode is pulled from
1190 * the mount list will sleep until we release it here.
1191 * This keeps the vnode from being freed while we reference
1194 if (xfs_ilock_nowait(ip, lock_flags) == 0) {
1195 if ((flags & SYNC_BDFLUSH) || (vp == NULL)) {
1206 IPOINTER_INSERT(ip, mp);
1207 xfs_ilock(ip, lock_flags);
1209 ASSERT(vp == XFS_ITOV(ip));
1210 ASSERT(ip->i_mount == mp);
1212 vnode_refed = B_TRUE;
1215 /* From here on in the loop we may have a marker record
1216 * in the inode list.
1220 * If we have to flush data or wait for I/O completion
1221 * we need to drop the ilock that we currently hold.
1222 * If we need to drop the lock, insert a marker if we
1223 * have not already done so.
1225 if ((flags & (SYNC_CLOSE|SYNC_IOWAIT)) ||
1226 ((flags & SYNC_DELWRI) && VN_DIRTY(vp))) {
1228 IPOINTER_INSERT(ip, mp);
1230 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1232 if (flags & SYNC_CLOSE) {
1233 /* Shutdown case. Flush and invalidate. */
1234 if (XFS_FORCED_SHUTDOWN(mp))
1235 xfs_tosspages(ip, 0, -1,
1238 error = xfs_flushinval_pages(ip,
1240 } else if ((flags & SYNC_DELWRI) && VN_DIRTY(vp)) {
1241 error = xfs_flush_pages(ip, 0,
1242 -1, fflag, FI_NONE);
1246 * When freezing, we need to wait ensure all I/O (including direct
1247 * I/O) is complete to ensure no further data modification can take
1248 * place after this point
1250 if (flags & SYNC_IOWAIT)
1253 xfs_ilock(ip, XFS_ILOCK_SHARED);
1256 if (flags & SYNC_BDFLUSH) {
1257 if ((flags & SYNC_ATTR) &&
1258 ((ip->i_update_core) ||
1259 ((ip->i_itemp != NULL) &&
1260 (ip->i_itemp->ili_format.ilf_fields != 0)))) {
1262 /* Insert marker and drop lock if not already
1266 IPOINTER_INSERT(ip, mp);
1270 * We don't want the periodic flushing of the
1271 * inodes by vfs_sync() to interfere with
1272 * I/O to the file, especially read I/O
1273 * where it is only the access time stamp
1274 * that is being flushed out. To prevent
1275 * long periods where we have both inode
1276 * locks held shared here while reading the
1277 * inode's buffer in from disk, we drop the
1278 * inode lock while reading in the inode
1279 * buffer. We have to release the buffer
1280 * and reacquire the inode lock so that they
1281 * are acquired in the proper order (inode
1282 * locks first). The buffer will go at the
1283 * end of the lru chain, though, so we can
1284 * expect it to still be there when we go
1285 * for it again in xfs_iflush().
1287 if ((xfs_ipincount(ip) == 0) &&
1288 xfs_iflock_nowait(ip)) {
1291 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1293 error = xfs_itobp(mp, NULL, ip,
1298 /* Bailing out, remove the
1299 * marker and free it.
1301 XFS_MOUNT_ILOCK(mp);
1302 IPOINTER_REMOVE(ip, mp);
1303 XFS_MOUNT_IUNLOCK(mp);
1305 ASSERT(!(lock_flags &
1306 XFS_IOLOCK_SHARED));
1309 sizeof(xfs_iptr_t));
1314 * Since we dropped the inode lock,
1315 * the inode may have been reclaimed.
1316 * Therefore, we reacquire the mount
1317 * lock and check to see if we were the
1318 * inode reclaimed. If this happened
1319 * then the ipointer marker will no
1320 * longer point back at us. In this
1321 * case, move ip along to the inode
1322 * after the marker, remove the marker
1325 XFS_MOUNT_ILOCK(mp);
1326 mount_locked = B_TRUE;
1328 if (ip != ipointer->ip_mprev) {
1329 IPOINTER_REMOVE(ip, mp);
1331 ASSERT(!vnode_refed);
1332 ASSERT(!(lock_flags &
1333 XFS_IOLOCK_SHARED));
1337 ASSERT(ip->i_mount == mp);
1339 if (xfs_ilock_nowait(ip,
1340 XFS_ILOCK_SHARED) == 0) {
1341 ASSERT(ip->i_mount == mp);
1343 * We failed to reacquire
1344 * the inode lock without
1345 * sleeping, so just skip
1346 * the inode for now. We
1347 * clear the ILOCK bit from
1348 * the lock_flags so that we
1349 * won't try to drop a lock
1350 * we don't hold below.
1352 lock_flags &= ~XFS_ILOCK_SHARED;
1353 IPOINTER_REMOVE(ip_next, mp);
1354 } else if ((xfs_ipincount(ip) == 0) &&
1355 xfs_iflock_nowait(ip)) {
1356 ASSERT(ip->i_mount == mp);
1358 * Since this is vfs_sync()
1359 * calling we only flush the
1360 * inode out if we can lock
1361 * it without sleeping and
1362 * it is not pinned. Drop
1363 * the mount lock here so
1364 * that we don't hold it for
1365 * too long. We already have
1366 * a marker in the list here.
1368 XFS_MOUNT_IUNLOCK(mp);
1369 mount_locked = B_FALSE;
1370 error = xfs_iflush(ip,
1373 ASSERT(ip->i_mount == mp);
1374 IPOINTER_REMOVE(ip_next, mp);
1381 if ((flags & SYNC_ATTR) &&
1382 ((ip->i_update_core) ||
1383 ((ip->i_itemp != NULL) &&
1384 (ip->i_itemp->ili_format.ilf_fields != 0)))) {
1386 IPOINTER_INSERT(ip, mp);
1389 if (flags & SYNC_WAIT) {
1391 error = xfs_iflush(ip,
1395 * If we can't acquire the flush
1396 * lock, then the inode is already
1397 * being flushed so don't bother
1398 * waiting. If we can lock it then
1399 * do a delwri flush so we can
1400 * combine multiple inode flushes
1401 * in each disk write.
1403 if (xfs_iflock_nowait(ip)) {
1404 error = xfs_iflush(ip,
1413 if (lock_flags != 0) {
1414 xfs_iunlock(ip, lock_flags);
1419 * If we had to take a reference on the vnode
1420 * above, then wait until after we've unlocked
1421 * the inode to release the reference. This is
1422 * because we can be already holding the inode
1423 * lock when VN_RELE() calls xfs_inactive().
1425 * Make sure to drop the mount lock before calling
1426 * VN_RELE() so that we don't trip over ourselves if
1427 * we have to go for the mount lock again in the
1431 IPOINTER_INSERT(ip, mp);
1436 vnode_refed = B_FALSE;
1444 * bail out if the filesystem is corrupted.
1446 if (error == EFSCORRUPTED) {
1447 if (!mount_locked) {
1448 XFS_MOUNT_ILOCK(mp);
1449 IPOINTER_REMOVE(ip, mp);
1451 XFS_MOUNT_IUNLOCK(mp);
1452 ASSERT(ipointer_in == B_FALSE);
1453 kmem_free(ipointer, sizeof(xfs_iptr_t));
1454 return XFS_ERROR(error);
1457 /* Let other threads have a chance at the mount lock
1458 * if we have looped many times without dropping the
1461 if ((++preempt & XFS_PREEMPT_MASK) == 0) {
1463 IPOINTER_INSERT(ip, mp);
1467 if (mount_locked == B_FALSE) {
1468 XFS_MOUNT_ILOCK(mp);
1469 mount_locked = B_TRUE;
1470 IPOINTER_REMOVE(ip, mp);
1474 ASSERT(ipointer_in == B_FALSE);
1477 } while (ip != mp->m_inodes);
1479 XFS_MOUNT_IUNLOCK(mp);
1481 ASSERT(ipointer_in == B_FALSE);
1483 kmem_free(ipointer, sizeof(xfs_iptr_t));
1484 return XFS_ERROR(last_error);
1488 * xfs sync routine for internal use
1490 * This routine supports all of the flags defined for the generic vfs_sync
1491 * interface as explained above under xfs_sync.
1502 uint log_flags = XFS_LOG_FORCE;
1504 xfs_buf_log_item_t *bip;
1507 * Sync out the log. This ensures that the log is periodically
1508 * flushed even if there is not enough activity to fill it up.
1510 if (flags & SYNC_WAIT)
1511 log_flags |= XFS_LOG_SYNC;
1513 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1515 if (flags & (SYNC_ATTR|SYNC_DELWRI)) {
1516 if (flags & SYNC_BDFLUSH)
1517 xfs_finish_reclaim_all(mp, 1);
1519 error = xfs_sync_inodes(mp, flags, bypassed);
1523 * Flushing out dirty data above probably generated more
1524 * log activity, so if this isn't vfs_sync() then flush
1527 if (flags & SYNC_DELWRI) {
1528 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1531 if (flags & SYNC_FSDATA) {
1533 * If this is vfs_sync() then only sync the superblock
1534 * if we can lock it without sleeping and it is not pinned.
1536 if (flags & SYNC_BDFLUSH) {
1537 bp = xfs_getsb(mp, XFS_BUF_TRYLOCK);
1539 bip = XFS_BUF_FSPRIVATE(bp,xfs_buf_log_item_t*);
1540 if ((bip != NULL) &&
1541 xfs_buf_item_dirty(bip)) {
1542 if (!(XFS_BUF_ISPINNED(bp))) {
1544 error = xfs_bwrite(mp, bp);
1553 bp = xfs_getsb(mp, 0);
1555 * If the buffer is pinned then push on the log so
1556 * we won't get stuck waiting in the write for
1557 * someone, maybe ourselves, to flush the log.
1558 * Even though we just pushed the log above, we
1559 * did not have the superblock buffer locked at
1560 * that point so it can become pinned in between
1563 if (XFS_BUF_ISPINNED(bp))
1564 xfs_log_force(mp, (xfs_lsn_t)0, XFS_LOG_FORCE);
1565 if (flags & SYNC_WAIT)
1566 XFS_BUF_UNASYNC(bp);
1569 error = xfs_bwrite(mp, bp);
1577 * If this is the periodic sync, then kick some entries out of
1578 * the reference cache. This ensures that idle entries are
1579 * eventually kicked out of the cache.
1581 if (flags & SYNC_REFCACHE) {
1582 if (flags & SYNC_WAIT)
1583 xfs_refcache_purge_mp(mp);
1585 xfs_refcache_purge_some(mp);
1589 * If asked, update the disk superblock with incore counter values if we
1590 * are using non-persistent counters so that they don't get too far out
1591 * of sync if we crash or get a forced shutdown. We don't want to force
1592 * this to disk, just get a transaction into the iclogs....
1594 if (flags & SYNC_SUPER)
1595 xfs_log_sbcount(mp, 0);
1598 * Now check to see if the log needs a "dummy" transaction.
1601 if (!(flags & SYNC_REMOUNT) && xfs_log_need_covered(mp)) {
1606 * Put a dummy transaction in the log to tell
1607 * recovery that all others are OK.
1609 tp = xfs_trans_alloc(mp, XFS_TRANS_DUMMY1);
1610 if ((error = xfs_trans_reserve(tp, 0,
1611 XFS_ICHANGE_LOG_RES(mp),
1613 xfs_trans_cancel(tp, 0);
1618 xfs_ilock(ip, XFS_ILOCK_EXCL);
1620 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
1621 xfs_trans_ihold(tp, ip);
1622 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
1623 error = xfs_trans_commit(tp, 0);
1624 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1625 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1629 * When shutting down, we need to insure that the AIL is pushed
1630 * to disk or the filesystem can appear corrupt from the PROM.
1632 if ((flags & (SYNC_CLOSE|SYNC_WAIT)) == (SYNC_CLOSE|SYNC_WAIT)) {
1633 XFS_bflush(mp->m_ddev_targp);
1634 if (mp->m_rtdev_targp) {
1635 XFS_bflush(mp->m_rtdev_targp);
1639 return XFS_ERROR(last_error);
1643 * xfs_vget - called by DMAPI and NFSD to get vnode from file handle
1651 xfs_fid_t *xfid = (struct xfs_fid *)fidp;
1658 * Invalid. Since handles can be created in user space and passed in
1659 * via gethandle(), this is not cause for a panic.
1661 if (xfid->xfs_fid_len != sizeof(*xfid) - sizeof(xfid->xfs_fid_len))
1662 return XFS_ERROR(EINVAL);
1664 ino = xfid->xfs_fid_ino;
1665 igen = xfid->xfs_fid_gen;
1668 * NFS can sometimes send requests for ino 0. Fail them gracefully.
1671 return XFS_ERROR(ESTALE);
1673 error = xfs_iget(mp, NULL, ino, 0, XFS_ILOCK_SHARED, &ip, 0);
1681 return XFS_ERROR(EIO);
1684 if (ip->i_d.di_mode == 0 || ip->i_d.di_gen != igen) {
1685 xfs_iput_new(ip, XFS_ILOCK_SHARED);
1687 return XFS_ERROR(ENOENT);
1690 *vpp = XFS_ITOV(ip);
1691 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1696 #define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
1697 #define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
1698 #define MNTOPT_LOGDEV "logdev" /* log device */
1699 #define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
1700 #define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
1701 #define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
1702 #define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
1703 #define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
1704 #define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
1705 #define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
1706 #define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
1707 #define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
1708 #define MNTOPT_MTPT "mtpt" /* filesystem mount point */
1709 #define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
1710 #define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
1711 #define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
1712 #define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
1713 #define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
1714 #define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
1715 #define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
1716 * unwritten extent conversion */
1717 #define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
1718 #define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
1719 #define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
1720 #define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
1721 #define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
1722 #define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
1723 #define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
1725 #define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
1726 #define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
1727 #define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
1728 #define MNTOPT_QUOTA "quota" /* disk quotas (user) */
1729 #define MNTOPT_NOQUOTA "noquota" /* no quotas */
1730 #define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */
1731 #define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */
1732 #define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */
1733 #define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */
1734 #define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */
1735 #define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */
1736 #define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
1737 #define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
1738 #define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
1739 #define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */
1740 #define MNTOPT_DMAPI "dmapi" /* DMI enabled (DMAPI / XDSM) */
1741 #define MNTOPT_XDSM "xdsm" /* DMI enabled (DMAPI / XDSM) */
1742 #define MNTOPT_DMI "dmi" /* DMI enabled (DMAPI / XDSM) */
1744 STATIC unsigned long
1745 suffix_strtoul(char *s, char **endp, unsigned int base)
1747 int last, shift_left_factor = 0;
1750 last = strlen(value) - 1;
1751 if (value[last] == 'K' || value[last] == 'k') {
1752 shift_left_factor = 10;
1755 if (value[last] == 'M' || value[last] == 'm') {
1756 shift_left_factor = 20;
1759 if (value[last] == 'G' || value[last] == 'g') {
1760 shift_left_factor = 30;
1764 return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
1769 struct xfs_mount *mp,
1771 struct xfs_mount_args *args,
1774 bhv_vfs_t *vfsp = XFS_MTOVFS(mp);
1775 char *this_char, *value, *eov;
1776 int dsunit, dswidth, vol_dsunit, vol_dswidth;
1780 * Applications using DMI filesystems often expect the
1781 * inode generation number to be monotonically increasing.
1782 * If we delete inode chunks we break this assumption, so
1783 * keep unused inode chunks on disk for DMI filesystems
1784 * until we come up with a better solution.
1785 * Note that if "ikeep" or "noikeep" mount options are
1786 * supplied, then they are honored.
1788 if (!(args->flags & XFSMNT_DMAPI))
1789 args->flags |= XFSMNT_IDELETE;
1791 args->flags |= XFSMNT_BARRIER;
1792 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
1797 iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0;
1799 while ((this_char = strsep(&options, ",")) != NULL) {
1802 if ((value = strchr(this_char, '=')) != NULL)
1805 if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
1806 if (!value || !*value) {
1808 "XFS: %s option requires an argument",
1812 args->logbufs = simple_strtoul(value, &eov, 10);
1813 } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
1814 if (!value || !*value) {
1816 "XFS: %s option requires an argument",
1820 args->logbufsize = suffix_strtoul(value, &eov, 10);
1821 } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
1822 if (!value || !*value) {
1824 "XFS: %s option requires an argument",
1828 strncpy(args->logname, value, MAXNAMELEN);
1829 } else if (!strcmp(this_char, MNTOPT_MTPT)) {
1830 if (!value || !*value) {
1832 "XFS: %s option requires an argument",
1836 strncpy(args->mtpt, value, MAXNAMELEN);
1837 } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
1838 if (!value || !*value) {
1840 "XFS: %s option requires an argument",
1844 strncpy(args->rtname, value, MAXNAMELEN);
1845 } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
1846 if (!value || !*value) {
1848 "XFS: %s option requires an argument",
1852 iosize = simple_strtoul(value, &eov, 10);
1853 args->flags |= XFSMNT_IOSIZE;
1854 args->iosizelog = (uint8_t) iosize;
1855 } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
1856 if (!value || !*value) {
1858 "XFS: %s option requires an argument",
1862 iosize = suffix_strtoul(value, &eov, 10);
1863 args->flags |= XFSMNT_IOSIZE;
1864 args->iosizelog = ffs(iosize) - 1;
1865 } else if (!strcmp(this_char, MNTOPT_GRPID) ||
1866 !strcmp(this_char, MNTOPT_BSDGROUPS)) {
1867 vfsp->vfs_flag |= VFS_GRPID;
1868 } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
1869 !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
1870 vfsp->vfs_flag &= ~VFS_GRPID;
1871 } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
1872 args->flags |= XFSMNT_WSYNC;
1873 } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
1874 args->flags |= XFSMNT_OSYNCISOSYNC;
1875 } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
1876 args->flags |= XFSMNT_NORECOVERY;
1877 } else if (!strcmp(this_char, MNTOPT_INO64)) {
1878 args->flags |= XFSMNT_INO64;
1881 "XFS: %s option not allowed on this system",
1885 } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
1886 args->flags |= XFSMNT_NOALIGN;
1887 } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
1888 args->flags |= XFSMNT_SWALLOC;
1889 } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
1890 if (!value || !*value) {
1892 "XFS: %s option requires an argument",
1896 dsunit = simple_strtoul(value, &eov, 10);
1897 } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
1898 if (!value || !*value) {
1900 "XFS: %s option requires an argument",
1904 dswidth = simple_strtoul(value, &eov, 10);
1905 } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
1906 args->flags &= ~XFSMNT_32BITINODES;
1909 "XFS: %s option not allowed on this system",
1913 } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
1914 args->flags |= XFSMNT_NOUUID;
1915 } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
1916 args->flags |= XFSMNT_BARRIER;
1917 } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
1918 args->flags &= ~XFSMNT_BARRIER;
1919 } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
1920 args->flags &= ~XFSMNT_IDELETE;
1921 } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
1922 args->flags |= XFSMNT_IDELETE;
1923 } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
1924 args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE;
1925 } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
1926 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
1927 } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
1928 args->flags |= XFSMNT_ATTR2;
1929 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
1930 args->flags &= ~XFSMNT_ATTR2;
1931 } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
1932 args->flags2 |= XFSMNT2_FILESTREAMS;
1933 } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
1934 args->flags &= ~(XFSMNT_UQUOTAENF|XFSMNT_UQUOTA);
1935 args->flags &= ~(XFSMNT_GQUOTAENF|XFSMNT_GQUOTA);
1936 } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
1937 !strcmp(this_char, MNTOPT_UQUOTA) ||
1938 !strcmp(this_char, MNTOPT_USRQUOTA)) {
1939 args->flags |= XFSMNT_UQUOTA | XFSMNT_UQUOTAENF;
1940 } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
1941 !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
1942 args->flags |= XFSMNT_UQUOTA;
1943 args->flags &= ~XFSMNT_UQUOTAENF;
1944 } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
1945 !strcmp(this_char, MNTOPT_PRJQUOTA)) {
1946 args->flags |= XFSMNT_PQUOTA | XFSMNT_PQUOTAENF;
1947 } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
1948 args->flags |= XFSMNT_PQUOTA;
1949 args->flags &= ~XFSMNT_PQUOTAENF;
1950 } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
1951 !strcmp(this_char, MNTOPT_GRPQUOTA)) {
1952 args->flags |= XFSMNT_GQUOTA | XFSMNT_GQUOTAENF;
1953 } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
1954 args->flags |= XFSMNT_GQUOTA;
1955 args->flags &= ~XFSMNT_GQUOTAENF;
1956 } else if (!strcmp(this_char, MNTOPT_DMAPI)) {
1957 args->flags |= XFSMNT_DMAPI;
1958 } else if (!strcmp(this_char, MNTOPT_XDSM)) {
1959 args->flags |= XFSMNT_DMAPI;
1960 } else if (!strcmp(this_char, MNTOPT_DMI)) {
1961 args->flags |= XFSMNT_DMAPI;
1962 } else if (!strcmp(this_char, "ihashsize")) {
1964 "XFS: ihashsize no longer used, option is deprecated.");
1965 } else if (!strcmp(this_char, "osyncisdsync")) {
1966 /* no-op, this is now the default */
1968 "XFS: osyncisdsync is now the default, option is deprecated.");
1969 } else if (!strcmp(this_char, "irixsgid")) {
1971 "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
1974 "XFS: unknown mount option [%s].", this_char);
1979 if (args->flags & XFSMNT_NORECOVERY) {
1980 if ((vfsp->vfs_flag & VFS_RDONLY) == 0) {
1982 "XFS: no-recovery mounts must be read-only.");
1987 if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) {
1989 "XFS: sunit and swidth options incompatible with the noalign option");
1993 if ((args->flags & XFSMNT_GQUOTA) && (args->flags & XFSMNT_PQUOTA)) {
1995 "XFS: cannot mount with both project and group quota");
1999 if ((args->flags & XFSMNT_DMAPI) && *args->mtpt == '\0') {
2000 printk("XFS: %s option needs the mount point option as well\n",
2005 if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
2007 "XFS: sunit and swidth must be specified together");
2011 if (dsunit && (dswidth % dsunit != 0)) {
2013 "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
2018 if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
2020 args->sunit = dsunit;
2021 args->flags |= XFSMNT_RETERR;
2023 args->sunit = vol_dsunit;
2025 dswidth ? (args->swidth = dswidth) :
2026 (args->swidth = vol_dswidth);
2028 args->sunit = args->swidth = 0;
2032 if (args->flags & XFSMNT_32BITINODES)
2033 vfsp->vfs_flag |= VFS_32BITINODES;
2035 args->flags |= XFSMNT_FLAGS2;
2041 struct xfs_mount *mp,
2044 static struct proc_xfs_info {
2048 /* the few simple ones we can get from the mount struct */
2049 { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
2050 { XFS_MOUNT_INO64, "," MNTOPT_INO64 },
2051 { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
2052 { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
2053 { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
2054 { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
2055 { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
2058 struct proc_xfs_info *xfs_infop;
2059 struct bhv_vfs *vfsp = XFS_MTOVFS(mp);
2061 for (xfs_infop = xfs_info; xfs_infop->flag; xfs_infop++) {
2062 if (mp->m_flags & xfs_infop->flag)
2063 seq_puts(m, xfs_infop->str);
2066 if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
2067 seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
2068 (int)(1 << mp->m_writeio_log) >> 10);
2070 if (mp->m_logbufs > 0)
2071 seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
2072 if (mp->m_logbsize > 0)
2073 seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
2076 seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
2078 seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
2080 if (mp->m_dalign > 0)
2081 seq_printf(m, "," MNTOPT_SUNIT "=%d",
2082 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
2083 if (mp->m_swidth > 0)
2084 seq_printf(m, "," MNTOPT_SWIDTH "=%d",
2085 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
2087 if (!(mp->m_flags & XFS_MOUNT_IDELETE))
2088 seq_printf(m, "," MNTOPT_IKEEP);
2089 if (!(mp->m_flags & XFS_MOUNT_COMPAT_IOSIZE))
2090 seq_printf(m, "," MNTOPT_LARGEIO);
2092 if (!(vfsp->vfs_flag & VFS_32BITINODES))
2093 seq_printf(m, "," MNTOPT_64BITINODE);
2094 if (vfsp->vfs_flag & VFS_GRPID)
2095 seq_printf(m, "," MNTOPT_GRPID);
2097 if (mp->m_qflags & XFS_UQUOTA_ACCT) {
2098 if (mp->m_qflags & XFS_UQUOTA_ENFD)
2099 seq_puts(m, "," MNTOPT_USRQUOTA);
2101 seq_puts(m, "," MNTOPT_UQUOTANOENF);
2104 if (mp->m_qflags & XFS_PQUOTA_ACCT) {
2105 if (mp->m_qflags & XFS_OQUOTA_ENFD)
2106 seq_puts(m, "," MNTOPT_PRJQUOTA);
2108 seq_puts(m, "," MNTOPT_PQUOTANOENF);
2111 if (mp->m_qflags & XFS_GQUOTA_ACCT) {
2112 if (mp->m_qflags & XFS_OQUOTA_ENFD)
2113 seq_puts(m, "," MNTOPT_GRPQUOTA);
2115 seq_puts(m, "," MNTOPT_GQUOTANOENF);
2118 if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
2119 seq_puts(m, "," MNTOPT_NOQUOTA);
2121 if (vfsp->vfs_flag & VFS_DMI)
2122 seq_puts(m, "," MNTOPT_DMAPI);
2127 * Second stage of a freeze. The data is already frozen so we only
2128 * need to take care of themetadata. Once that's done write a dummy
2129 * record to dirty the log in case of a crash while frozen.
2135 xfs_attr_quiesce(mp);
2136 xfs_fs_log_dummy(mp);