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 spinlock_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.
214 struct xfs_mount_args *ap,
215 struct xfs_mount *mp)
217 /* Values are in BBs */
218 if ((ap->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
220 * At this point the superblock has not been read
221 * in, therefore we do not know the block size.
222 * Before the mount call ends we will convert
225 mp->m_dalign = ap->sunit;
226 mp->m_swidth = ap->swidth;
229 if (ap->logbufs != -1 &&
231 (ap->logbufs < XLOG_MIN_ICLOGS ||
232 ap->logbufs > XLOG_MAX_ICLOGS)) {
234 "XFS: invalid logbufs value: %d [not %d-%d]",
235 ap->logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
236 return XFS_ERROR(EINVAL);
238 mp->m_logbufs = ap->logbufs;
239 if (ap->logbufsize != -1 &&
240 ap->logbufsize != 0 &&
241 (ap->logbufsize < XLOG_MIN_RECORD_BSIZE ||
242 ap->logbufsize > XLOG_MAX_RECORD_BSIZE ||
243 !is_power_of_2(ap->logbufsize))) {
245 "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
247 return XFS_ERROR(EINVAL);
249 mp->m_logbsize = ap->logbufsize;
250 mp->m_fsname_len = strlen(ap->fsname) + 1;
251 mp->m_fsname = kmem_alloc(mp->m_fsname_len, KM_SLEEP);
252 strcpy(mp->m_fsname, ap->fsname);
254 mp->m_rtname = kmem_alloc(strlen(ap->rtname) + 1, KM_SLEEP);
255 strcpy(mp->m_rtname, ap->rtname);
257 if (ap->logname[0]) {
258 mp->m_logname = kmem_alloc(strlen(ap->logname) + 1, KM_SLEEP);
259 strcpy(mp->m_logname, ap->logname);
262 if (ap->flags & XFSMNT_WSYNC)
263 mp->m_flags |= XFS_MOUNT_WSYNC;
265 if (ap->flags & XFSMNT_INO64) {
266 mp->m_flags |= XFS_MOUNT_INO64;
267 mp->m_inoadd = XFS_INO64_OFFSET;
270 if (ap->flags & XFSMNT_RETERR)
271 mp->m_flags |= XFS_MOUNT_RETERR;
272 if (ap->flags & XFSMNT_NOALIGN)
273 mp->m_flags |= XFS_MOUNT_NOALIGN;
274 if (ap->flags & XFSMNT_SWALLOC)
275 mp->m_flags |= XFS_MOUNT_SWALLOC;
276 if (ap->flags & XFSMNT_OSYNCISOSYNC)
277 mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
278 if (ap->flags & XFSMNT_32BITINODES)
279 mp->m_flags |= XFS_MOUNT_32BITINODES;
281 if (ap->flags & XFSMNT_IOSIZE) {
282 if (ap->iosizelog > XFS_MAX_IO_LOG ||
283 ap->iosizelog < XFS_MIN_IO_LOG) {
285 "XFS: invalid log iosize: %d [not %d-%d]",
286 ap->iosizelog, XFS_MIN_IO_LOG,
288 return XFS_ERROR(EINVAL);
291 mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
292 mp->m_readio_log = mp->m_writeio_log = ap->iosizelog;
295 if (ap->flags & XFSMNT_IDELETE)
296 mp->m_flags |= XFS_MOUNT_IDELETE;
297 if (ap->flags & XFSMNT_DIRSYNC)
298 mp->m_flags |= XFS_MOUNT_DIRSYNC;
299 if (ap->flags & XFSMNT_ATTR2)
300 mp->m_flags |= XFS_MOUNT_ATTR2;
302 if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
303 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
306 * no recovery flag requires a read-only mount
308 if (ap->flags & XFSMNT_NORECOVERY) {
309 if (!(mp->m_flags & XFS_MOUNT_RDONLY)) {
311 "XFS: tried to mount a FS read-write without recovery!");
312 return XFS_ERROR(EINVAL);
314 mp->m_flags |= XFS_MOUNT_NORECOVERY;
317 if (ap->flags & XFSMNT_NOUUID)
318 mp->m_flags |= XFS_MOUNT_NOUUID;
319 if (ap->flags & XFSMNT_BARRIER)
320 mp->m_flags |= XFS_MOUNT_BARRIER;
322 mp->m_flags &= ~XFS_MOUNT_BARRIER;
324 if (ap->flags2 & XFSMNT2_FILESTREAMS)
325 mp->m_flags |= XFS_MOUNT_FILESTREAMS;
327 if (ap->flags & XFSMNT_DMAPI)
328 mp->m_flags |= XFS_MOUNT_DMAPI;
333 * This function fills in xfs_mount_t fields based on mount args.
334 * Note: the superblock _has_ now been read in.
338 struct xfs_mount_args *ap,
339 struct xfs_mount *mp)
341 int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
343 /* Fail a mount where the logbuf is smaller then the log stripe */
344 if (XFS_SB_VERSION_HASLOGV2(&mp->m_sb)) {
345 if ((ap->logbufsize <= 0) &&
346 (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) {
347 mp->m_logbsize = mp->m_sb.sb_logsunit;
348 } else if (ap->logbufsize > 0 &&
349 ap->logbufsize < mp->m_sb.sb_logsunit) {
351 "XFS: logbuf size must be greater than or equal to log stripe size");
352 return XFS_ERROR(EINVAL);
355 /* Fail a mount if the logbuf is larger than 32K */
356 if (ap->logbufsize > XLOG_BIG_RECORD_BSIZE) {
358 "XFS: logbuf size for version 1 logs must be 16K or 32K");
359 return XFS_ERROR(EINVAL);
363 if (XFS_SB_VERSION_HASATTR2(&mp->m_sb)) {
364 mp->m_flags |= XFS_MOUNT_ATTR2;
368 * prohibit r/w mounts of read-only filesystems
370 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
372 "XFS: cannot mount a read-only filesystem as read-write");
373 return XFS_ERROR(EROFS);
377 * check for shared mount.
379 if (ap->flags & XFSMNT_SHARED) {
380 if (!XFS_SB_VERSION_HASSHARED(&mp->m_sb))
381 return XFS_ERROR(EINVAL);
384 * For IRIX 6.5, shared mounts must have the shared
385 * version bit set, have the persistent readonly
386 * field set, must be version 0 and can only be mounted
389 if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) ||
390 (mp->m_sb.sb_shared_vn != 0))
391 return XFS_ERROR(EINVAL);
393 mp->m_flags |= XFS_MOUNT_SHARED;
396 * Shared XFS V0 can't deal with DMI. Return EINVAL.
398 if (mp->m_sb.sb_shared_vn == 0 && (ap->flags & XFSMNT_DMAPI))
399 return XFS_ERROR(EINVAL);
402 if (ap->flags & XFSMNT_UQUOTA) {
403 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
404 if (ap->flags & XFSMNT_UQUOTAENF)
405 mp->m_qflags |= XFS_UQUOTA_ENFD;
408 if (ap->flags & XFSMNT_GQUOTA) {
409 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
410 if (ap->flags & XFSMNT_GQUOTAENF)
411 mp->m_qflags |= XFS_OQUOTA_ENFD;
412 } else if (ap->flags & XFSMNT_PQUOTA) {
413 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
414 if (ap->flags & XFSMNT_PQUOTAENF)
415 mp->m_qflags |= XFS_OQUOTA_ENFD;
424 * The file system configurations are:
425 * (1) device (partition) with data and internal log
426 * (2) logical volume with data and log subvolumes.
427 * (3) logical volume with data, log, and realtime subvolumes.
429 * We only have to handle opening the log and realtime volumes here if
430 * they are present. The data subvolume has already been opened by
431 * get_sb_bdev() and is stored in vfsp->vfs_super->s_bdev.
435 struct xfs_mount *mp,
436 struct xfs_mount_args *args,
439 struct block_device *ddev, *logdev, *rtdev;
440 int flags = 0, error;
442 ddev = mp->m_super->s_bdev;
443 logdev = rtdev = NULL;
445 error = xfs_dmops_get(mp, args);
448 error = xfs_qmops_get(mp, args);
452 if (args->flags & XFSMNT_QUIET)
453 flags |= XFS_MFSI_QUIET;
456 * Open real time and log devices - order is important.
458 if (args->logname[0]) {
459 error = xfs_blkdev_get(mp, args->logname, &logdev);
463 if (args->rtname[0]) {
464 error = xfs_blkdev_get(mp, args->rtname, &rtdev);
466 xfs_blkdev_put(logdev);
470 if (rtdev == ddev || rtdev == logdev) {
472 "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
473 xfs_blkdev_put(logdev);
474 xfs_blkdev_put(rtdev);
480 * Setup xfs_mount buffer target pointers
483 mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
484 if (!mp->m_ddev_targp) {
485 xfs_blkdev_put(logdev);
486 xfs_blkdev_put(rtdev);
490 mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
491 if (!mp->m_rtdev_targp) {
492 xfs_blkdev_put(logdev);
493 xfs_blkdev_put(rtdev);
497 mp->m_logdev_targp = (logdev && logdev != ddev) ?
498 xfs_alloc_buftarg(logdev, 1) : mp->m_ddev_targp;
499 if (!mp->m_logdev_targp) {
500 xfs_blkdev_put(logdev);
501 xfs_blkdev_put(rtdev);
506 * Setup flags based on mount(2) options and then the superblock
508 error = xfs_start_flags(args, mp);
511 error = xfs_readsb(mp, flags);
514 error = xfs_finish_flags(args, mp);
519 * Setup xfs_mount buffer target pointers based on superblock
521 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
522 mp->m_sb.sb_sectsize);
523 if (!error && logdev && logdev != ddev) {
524 unsigned int log_sector_size = BBSIZE;
526 if (XFS_SB_VERSION_HASSECTOR(&mp->m_sb))
527 log_sector_size = mp->m_sb.sb_logsectsize;
528 error = xfs_setsize_buftarg(mp->m_logdev_targp,
529 mp->m_sb.sb_blocksize,
533 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
534 mp->m_sb.sb_blocksize,
535 mp->m_sb.sb_sectsize);
539 if (mp->m_flags & XFS_MOUNT_BARRIER)
540 xfs_mountfs_check_barriers(mp);
542 if ((error = xfs_filestream_mount(mp)))
545 error = xfs_mountfs(mp, flags);
549 XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, args->mtpt, args->fsname);
557 xfs_binval(mp->m_ddev_targp);
558 if (logdev && logdev != ddev)
559 xfs_binval(mp->m_logdev_targp);
561 xfs_binval(mp->m_rtdev_targp);
563 xfs_unmountfs_close(mp, credp);
577 int unmount_event_wanted = 0;
578 int unmount_event_flags = 0;
579 int xfs_unmountfs_needed = 0;
586 if (mp->m_flags & XFS_MOUNT_DMAPI) {
587 error = XFS_SEND_PREUNMOUNT(mp,
588 rvp, DM_RIGHT_NULL, rvp, DM_RIGHT_NULL,
590 (mp->m_dmevmask & (1<<DM_EVENT_PREUNMOUNT))?
591 0:DM_FLAGS_UNWANTED);
593 return XFS_ERROR(error);
594 unmount_event_wanted = 1;
595 unmount_event_flags = (mp->m_dmevmask & (1<<DM_EVENT_UNMOUNT))?
596 0 : DM_FLAGS_UNWANTED;
600 * First blow any referenced inode from this file system
601 * out of the reference cache, and delete the timer.
603 xfs_refcache_purge_mp(mp);
606 * Blow away any referenced inode in the filestreams cache.
607 * This can and will cause log traffic as inodes go inactive
610 xfs_filestream_unmount(mp);
612 XFS_bflush(mp->m_ddev_targp);
613 error = xfs_unmount_flush(mp, 0);
617 ASSERT(vn_count(rvp) == 1);
620 * Drop the reference count
625 * If we're forcing a shutdown, typically because of a media error,
626 * we want to make sure we invalidate dirty pages that belong to
627 * referenced vnodes as well.
629 if (XFS_FORCED_SHUTDOWN(mp)) {
630 error = xfs_sync(mp, SYNC_WAIT | SYNC_CLOSE);
631 ASSERT(error != EFSCORRUPTED);
633 xfs_unmountfs_needed = 1;
636 /* Send DMAPI event, if required.
637 * Then do xfs_unmountfs() if needed.
638 * Then return error (or zero).
640 if (unmount_event_wanted) {
641 /* Note: mp structure must still exist for
642 * XFS_SEND_UNMOUNT() call.
644 XFS_SEND_UNMOUNT(mp, error == 0 ? rvp : NULL,
645 DM_RIGHT_NULL, 0, error, unmount_event_flags);
647 if (xfs_unmountfs_needed) {
649 * Call common unmount function to flush to disk
650 * and free the super block buffer & mount structures.
652 xfs_unmountfs(mp, credp);
655 kmem_free(mp, sizeof(xfs_mount_t));
658 return XFS_ERROR(error);
665 int count = 0, pincount;
667 xfs_refcache_purge_mp(mp);
668 xfs_flush_buftarg(mp->m_ddev_targp, 0);
669 xfs_finish_reclaim_all(mp, 0);
671 /* This loop must run at least twice.
672 * The first instance of the loop will flush
673 * most meta data but that will generate more
674 * meta data (typically directory updates).
675 * Which then must be flushed and logged before
676 * we can write the unmount record.
679 xfs_syncsub(mp, SYNC_INODE_QUIESCE, NULL);
680 pincount = xfs_flush_buftarg(mp->m_ddev_targp, 1);
691 * Second stage of a quiesce. The data is already synced, now we have to take
692 * care of the metadata. New transactions are already blocked, so we need to
693 * wait for any remaining transactions to drain out before proceding.
699 /* wait for all modifications to complete */
700 while (atomic_read(&mp->m_active_trans) > 0)
703 /* flush inodes and push all remaining buffers out to disk */
706 ASSERT_ALWAYS(atomic_read(&mp->m_active_trans) == 0);
708 /* Push the superblock and write an unmount record */
709 xfs_log_sbcount(mp, 1);
710 xfs_log_unmount_write(mp);
711 xfs_unmountfs_writesb(mp);
716 struct xfs_mount *mp,
718 struct xfs_mount_args *args)
720 if (!(*flags & MS_RDONLY)) { /* rw/ro -> rw */
721 if (mp->m_flags & XFS_MOUNT_RDONLY)
722 mp->m_flags &= ~XFS_MOUNT_RDONLY;
723 if (args->flags & XFSMNT_BARRIER) {
724 mp->m_flags |= XFS_MOUNT_BARRIER;
725 xfs_mountfs_check_barriers(mp);
727 mp->m_flags &= ~XFS_MOUNT_BARRIER;
729 } else if (!(mp->m_flags & XFS_MOUNT_RDONLY)) { /* rw -> ro */
730 xfs_filestream_flush(mp);
731 xfs_sync(mp, SYNC_DATA_QUIESCE);
732 xfs_attr_quiesce(mp);
733 mp->m_flags |= XFS_MOUNT_RDONLY;
739 * xfs_unmount_flush implements a set of flush operation on special
740 * inodes, which are needed as a separate set of operations so that
741 * they can be called as part of relocation process.
745 xfs_mount_t *mp, /* Mount structure we are getting
747 int relocation) /* Called from vfs relocation. */
749 xfs_inode_t *rip = mp->m_rootip;
751 xfs_inode_t *rsumip = NULL;
752 bhv_vnode_t *rvp = XFS_ITOV(rip);
755 xfs_ilock(rip, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT);
759 * Flush out the real time inodes.
761 if ((rbmip = mp->m_rbmip) != NULL) {
762 xfs_ilock(rbmip, XFS_ILOCK_EXCL);
764 error = xfs_iflush(rbmip, XFS_IFLUSH_SYNC);
765 xfs_iunlock(rbmip, XFS_ILOCK_EXCL);
767 if (error == EFSCORRUPTED)
770 ASSERT(vn_count(XFS_ITOV(rbmip)) == 1);
772 rsumip = mp->m_rsumip;
773 xfs_ilock(rsumip, XFS_ILOCK_EXCL);
775 error = xfs_iflush(rsumip, XFS_IFLUSH_SYNC);
776 xfs_iunlock(rsumip, XFS_ILOCK_EXCL);
778 if (error == EFSCORRUPTED)
781 ASSERT(vn_count(XFS_ITOV(rsumip)) == 1);
785 * Synchronously flush root inode to disk
787 error = xfs_iflush(rip, XFS_IFLUSH_SYNC);
788 if (error == EFSCORRUPTED)
791 if (vn_count(rvp) != 1 && !relocation) {
792 xfs_iunlock(rip, XFS_ILOCK_EXCL);
793 return XFS_ERROR(EBUSY);
797 * Release dquot that rootinode, rbmino and rsumino might be holding,
798 * flush and purge the quota inodes.
800 error = XFS_QM_UNMOUNT(mp);
801 if (error == EFSCORRUPTED)
805 VN_RELE(XFS_ITOV(rbmip));
806 VN_RELE(XFS_ITOV(rsumip));
809 xfs_iunlock(rip, XFS_ILOCK_EXCL);
816 xfs_iunlock(rip, XFS_ILOCK_EXCL);
818 return XFS_ERROR(EFSCORRUPTED);
822 * xfs_root extracts the root vnode from a vfs.
824 * vfsp -- the vfs struct for the desired file system
825 * vpp -- address of the caller's vnode pointer which should be
826 * set to the desired fs root vnode
835 vp = XFS_ITOV(mp->m_rootip);
844 * Fill in the statvfs structure for the given file system. We use
845 * the superblock lock in the mount structure to ensure a consistent
846 * snapshot of the counters returned.
851 bhv_statvfs_t *statp,
861 statp->f_type = XFS_SB_MAGIC;
863 xfs_icsb_sync_counters_flags(mp, XFS_ICSB_LAZY_COUNT);
865 statp->f_bsize = sbp->sb_blocksize;
866 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
867 statp->f_blocks = sbp->sb_dblocks - lsize;
868 statp->f_bfree = statp->f_bavail =
869 sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
870 fakeinos = statp->f_bfree << sbp->sb_inopblog;
872 fakeinos += mp->m_inoadd;
875 MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
880 statp->f_files = min_t(typeof(statp->f_files),
883 statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
884 XFS_SB_UNLOCK(mp, s);
886 xfs_statvfs_fsid(statp, mp);
887 statp->f_namelen = MAXNAMELEN - 1;
890 XFS_QM_DQSTATVFS(xfs_vtoi(vp), statp);
896 * xfs_sync flushes any pending I/O to file system vfsp.
898 * This routine is called by vfs_sync() to make sure that things make it
899 * out to disk eventually, on sync() system calls to flush out everything,
900 * and when the file system is unmounted. For the vfs_sync() case, all
901 * we really need to do is sync out the log to make all of our meta-data
902 * updates permanent (except for timestamps). For calls from pflushd(),
903 * dirty pages are kept moving by calling pdflush() on the inodes
904 * containing them. We also flush the inodes that we can lock without
905 * sleeping and the superblock if we can lock it without sleeping from
906 * vfs_sync() so that items at the tail of the log are always moving out.
909 * SYNC_BDFLUSH - We're being called from vfs_sync() so we don't want
910 * to sleep if we can help it. All we really need
911 * to do is ensure that the log is synced at least
912 * periodically. We also push the inodes and
913 * superblock if we can lock them without sleeping
914 * and they are not pinned.
915 * SYNC_ATTR - We need to flush the inodes. If SYNC_BDFLUSH is not
916 * set, then we really want to lock each inode and flush
918 * SYNC_WAIT - All the flushes that take place in this call should
920 * SYNC_DELWRI - This tells us to push dirty pages associated with
921 * inodes. SYNC_WAIT and SYNC_BDFLUSH are used to
922 * determine if they should be flushed sync, async, or
924 * SYNC_CLOSE - This flag is passed when the system is being
925 * unmounted. We should sync and invalidate everything.
926 * SYNC_FSDATA - This indicates that the caller would like to make
927 * sure the superblock is safe on disk. We can ensure
928 * this by simply making sure the log gets flushed
929 * if SYNC_BDFLUSH is set, and by actually writing it
931 * SYNC_IOWAIT - The caller wants us to wait for all data I/O to complete
932 * before we return (including direct I/O). Forms the drain
933 * side of the write barrier needed to safely quiesce the
945 * Get the Quota Manager to flush the dquots.
947 * If XFS quota support is not enabled or this filesystem
948 * instance does not use quotas XFS_QM_DQSYNC will always
951 error = XFS_QM_DQSYNC(mp, flags);
954 * If we got an IO error, we will be shutting down.
955 * So, there's nothing more for us to do here.
957 ASSERT(error != EIO || XFS_FORCED_SHUTDOWN(mp));
958 if (XFS_FORCED_SHUTDOWN(mp))
959 return XFS_ERROR(error);
962 if (flags & SYNC_IOWAIT)
963 xfs_filestream_flush(mp);
965 return xfs_syncsub(mp, flags, NULL);
969 * xfs sync routine for internal use
971 * This routine supports all of the flags defined for the generic vfs_sync
972 * interface as explained above under xfs_sync.
981 xfs_inode_t *ip = NULL;
982 bhv_vnode_t *vp = NULL;
987 uint base_lock_flags;
988 boolean_t mount_locked;
989 boolean_t vnode_refed;
991 xfs_iptr_t *ipointer;
993 boolean_t ipointer_in = B_FALSE;
995 #define IPOINTER_SET ipointer_in = B_TRUE
996 #define IPOINTER_CLR ipointer_in = B_FALSE
1003 /* Insert a marker record into the inode list after inode ip. The list
1004 * must be locked when this is called. After the call the list will no
1007 #define IPOINTER_INSERT(ip, mp) { \
1008 ASSERT(ipointer_in == B_FALSE); \
1009 ipointer->ip_mnext = ip->i_mnext; \
1010 ipointer->ip_mprev = ip; \
1011 ip->i_mnext = (xfs_inode_t *)ipointer; \
1012 ipointer->ip_mnext->i_mprev = (xfs_inode_t *)ipointer; \
1014 XFS_MOUNT_IUNLOCK(mp); \
1015 mount_locked = B_FALSE; \
1019 /* Remove the marker from the inode list. If the marker was the only item
1020 * in the list then there are no remaining inodes and we should zero out
1021 * the whole list. If we are the current head of the list then move the head
1024 #define IPOINTER_REMOVE(ip, mp) { \
1025 ASSERT(ipointer_in == B_TRUE); \
1026 if (ipointer->ip_mnext != (xfs_inode_t *)ipointer) { \
1027 ip = ipointer->ip_mnext; \
1028 ip->i_mprev = ipointer->ip_mprev; \
1029 ipointer->ip_mprev->i_mnext = ip; \
1030 if (mp->m_inodes == (xfs_inode_t *)ipointer) { \
1031 mp->m_inodes = ip; \
1034 ASSERT(mp->m_inodes == (xfs_inode_t *)ipointer); \
1035 mp->m_inodes = NULL; \
1041 #define XFS_PREEMPT_MASK 0x7f
1043 ASSERT(!(flags & SYNC_BDFLUSH));
1047 if (mp->m_flags & XFS_MOUNT_RDONLY)
1053 /* Allocate a reference marker */
1054 ipointer = (xfs_iptr_t *)kmem_zalloc(sizeof(xfs_iptr_t), KM_SLEEP);
1056 fflag = XFS_B_ASYNC; /* default is don't wait */
1057 if (flags & SYNC_DELWRI)
1058 fflag = XFS_B_DELWRI;
1059 if (flags & SYNC_WAIT)
1060 fflag = 0; /* synchronous overrides all */
1062 base_lock_flags = XFS_ILOCK_SHARED;
1063 if (flags & (SYNC_DELWRI | SYNC_CLOSE)) {
1065 * We need the I/O lock if we're going to call any of
1066 * the flush/inval routines.
1068 base_lock_flags |= XFS_IOLOCK_SHARED;
1071 XFS_MOUNT_ILOCK(mp);
1075 mount_locked = B_TRUE;
1076 vnode_refed = B_FALSE;
1081 ASSERT(ipointer_in == B_FALSE);
1082 ASSERT(vnode_refed == B_FALSE);
1084 lock_flags = base_lock_flags;
1087 * There were no inodes in the list, just break out
1095 * We found another sync thread marker - skip it
1097 if (ip->i_mount == NULL) {
1102 vp = XFS_ITOV_NULL(ip);
1105 * If the vnode is gone then this is being torn down,
1106 * call reclaim if it is flushed, else let regular flush
1107 * code deal with it later in the loop.
1111 /* Skip ones already in reclaim */
1112 if (ip->i_flags & XFS_IRECLAIM) {
1116 if (xfs_ilock_nowait(ip, XFS_ILOCK_EXCL) == 0) {
1118 } else if ((xfs_ipincount(ip) == 0) &&
1119 xfs_iflock_nowait(ip)) {
1120 IPOINTER_INSERT(ip, mp);
1122 xfs_finish_reclaim(ip, 1,
1123 XFS_IFLUSH_DELWRI_ELSE_ASYNC);
1125 XFS_MOUNT_ILOCK(mp);
1126 mount_locked = B_TRUE;
1127 IPOINTER_REMOVE(ip, mp);
1129 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1140 if (XFS_FORCED_SHUTDOWN(mp) && !(flags & SYNC_CLOSE)) {
1141 XFS_MOUNT_IUNLOCK(mp);
1142 kmem_free(ipointer, sizeof(xfs_iptr_t));
1147 * Try to lock without sleeping. We're out of order with
1148 * the inode list lock here, so if we fail we need to drop
1149 * the mount lock and try again. If we're called from
1150 * bdflush() here, then don't bother.
1152 * The inode lock here actually coordinates with the
1153 * almost spurious inode lock in xfs_ireclaim() to prevent
1154 * the vnode we handle here without a reference from
1155 * being freed while we reference it. If we lock the inode
1156 * while it's on the mount list here, then the spurious inode
1157 * lock in xfs_ireclaim() after the inode is pulled from
1158 * the mount list will sleep until we release it here.
1159 * This keeps the vnode from being freed while we reference
1162 if (xfs_ilock_nowait(ip, lock_flags) == 0) {
1174 IPOINTER_INSERT(ip, mp);
1175 xfs_ilock(ip, lock_flags);
1177 ASSERT(vp == XFS_ITOV(ip));
1178 ASSERT(ip->i_mount == mp);
1180 vnode_refed = B_TRUE;
1183 /* From here on in the loop we may have a marker record
1184 * in the inode list.
1188 * If we have to flush data or wait for I/O completion
1189 * we need to drop the ilock that we currently hold.
1190 * If we need to drop the lock, insert a marker if we
1191 * have not already done so.
1193 if ((flags & (SYNC_CLOSE|SYNC_IOWAIT)) ||
1194 ((flags & SYNC_DELWRI) && VN_DIRTY(vp))) {
1196 IPOINTER_INSERT(ip, mp);
1198 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1200 if (flags & SYNC_CLOSE) {
1201 /* Shutdown case. Flush and invalidate. */
1202 if (XFS_FORCED_SHUTDOWN(mp))
1203 xfs_tosspages(ip, 0, -1,
1206 error = xfs_flushinval_pages(ip,
1208 } else if ((flags & SYNC_DELWRI) && VN_DIRTY(vp)) {
1209 error = xfs_flush_pages(ip, 0,
1210 -1, fflag, FI_NONE);
1214 * When freezing, we need to wait ensure all I/O (including direct
1215 * I/O) is complete to ensure no further data modification can take
1216 * place after this point
1218 if (flags & SYNC_IOWAIT)
1221 xfs_ilock(ip, XFS_ILOCK_SHARED);
1224 if ((flags & SYNC_ATTR) &&
1225 (ip->i_update_core ||
1226 (ip->i_itemp && ip->i_itemp->ili_format.ilf_fields))) {
1228 IPOINTER_INSERT(ip, mp);
1230 if (flags & SYNC_WAIT) {
1232 error = xfs_iflush(ip, XFS_IFLUSH_SYNC);
1235 * If we can't acquire the flush lock, then the inode
1236 * is already being flushed so don't bother waiting.
1238 * If we can lock it then do a delwri flush so we can
1239 * combine multiple inode flushes in each disk write.
1241 } else if (xfs_iflock_nowait(ip)) {
1242 error = xfs_iflush(ip, XFS_IFLUSH_DELWRI);
1243 } else if (bypassed) {
1248 if (lock_flags != 0) {
1249 xfs_iunlock(ip, lock_flags);
1254 * If we had to take a reference on the vnode
1255 * above, then wait until after we've unlocked
1256 * the inode to release the reference. This is
1257 * because we can be already holding the inode
1258 * lock when VN_RELE() calls xfs_inactive().
1260 * Make sure to drop the mount lock before calling
1261 * VN_RELE() so that we don't trip over ourselves if
1262 * we have to go for the mount lock again in the
1266 IPOINTER_INSERT(ip, mp);
1271 vnode_refed = B_FALSE;
1279 * bail out if the filesystem is corrupted.
1281 if (error == EFSCORRUPTED) {
1282 if (!mount_locked) {
1283 XFS_MOUNT_ILOCK(mp);
1284 IPOINTER_REMOVE(ip, mp);
1286 XFS_MOUNT_IUNLOCK(mp);
1287 ASSERT(ipointer_in == B_FALSE);
1288 kmem_free(ipointer, sizeof(xfs_iptr_t));
1289 return XFS_ERROR(error);
1292 /* Let other threads have a chance at the mount lock
1293 * if we have looped many times without dropping the
1296 if ((++preempt & XFS_PREEMPT_MASK) == 0) {
1298 IPOINTER_INSERT(ip, mp);
1302 if (mount_locked == B_FALSE) {
1303 XFS_MOUNT_ILOCK(mp);
1304 mount_locked = B_TRUE;
1305 IPOINTER_REMOVE(ip, mp);
1309 ASSERT(ipointer_in == B_FALSE);
1312 } while (ip != mp->m_inodes);
1314 XFS_MOUNT_IUNLOCK(mp);
1316 ASSERT(ipointer_in == B_FALSE);
1318 kmem_free(ipointer, sizeof(xfs_iptr_t));
1319 return XFS_ERROR(last_error);
1323 * xfs sync routine for internal use
1325 * This routine supports all of the flags defined for the generic vfs_sync
1326 * interface as explained above under xfs_sync.
1337 uint log_flags = XFS_LOG_FORCE;
1339 xfs_buf_log_item_t *bip;
1342 * Sync out the log. This ensures that the log is periodically
1343 * flushed even if there is not enough activity to fill it up.
1345 if (flags & SYNC_WAIT)
1346 log_flags |= XFS_LOG_SYNC;
1348 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1350 if (flags & (SYNC_ATTR|SYNC_DELWRI)) {
1351 if (flags & SYNC_BDFLUSH)
1352 xfs_finish_reclaim_all(mp, 1);
1354 error = xfs_sync_inodes(mp, flags, bypassed);
1358 * Flushing out dirty data above probably generated more
1359 * log activity, so if this isn't vfs_sync() then flush
1362 if (flags & SYNC_DELWRI) {
1363 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1366 if (flags & SYNC_FSDATA) {
1368 * If this is vfs_sync() then only sync the superblock
1369 * if we can lock it without sleeping and it is not pinned.
1371 if (flags & SYNC_BDFLUSH) {
1372 bp = xfs_getsb(mp, XFS_BUF_TRYLOCK);
1374 bip = XFS_BUF_FSPRIVATE(bp,xfs_buf_log_item_t*);
1375 if ((bip != NULL) &&
1376 xfs_buf_item_dirty(bip)) {
1377 if (!(XFS_BUF_ISPINNED(bp))) {
1379 error = xfs_bwrite(mp, bp);
1388 bp = xfs_getsb(mp, 0);
1390 * If the buffer is pinned then push on the log so
1391 * we won't get stuck waiting in the write for
1392 * someone, maybe ourselves, to flush the log.
1393 * Even though we just pushed the log above, we
1394 * did not have the superblock buffer locked at
1395 * that point so it can become pinned in between
1398 if (XFS_BUF_ISPINNED(bp))
1399 xfs_log_force(mp, (xfs_lsn_t)0, XFS_LOG_FORCE);
1400 if (flags & SYNC_WAIT)
1401 XFS_BUF_UNASYNC(bp);
1404 error = xfs_bwrite(mp, bp);
1412 * If this is the periodic sync, then kick some entries out of
1413 * the reference cache. This ensures that idle entries are
1414 * eventually kicked out of the cache.
1416 if (flags & SYNC_REFCACHE) {
1417 if (flags & SYNC_WAIT)
1418 xfs_refcache_purge_mp(mp);
1420 xfs_refcache_purge_some(mp);
1424 * If asked, update the disk superblock with incore counter values if we
1425 * are using non-persistent counters so that they don't get too far out
1426 * of sync if we crash or get a forced shutdown. We don't want to force
1427 * this to disk, just get a transaction into the iclogs....
1429 if (flags & SYNC_SUPER)
1430 xfs_log_sbcount(mp, 0);
1433 * Now check to see if the log needs a "dummy" transaction.
1436 if (!(flags & SYNC_REMOUNT) && xfs_log_need_covered(mp)) {
1441 * Put a dummy transaction in the log to tell
1442 * recovery that all others are OK.
1444 tp = xfs_trans_alloc(mp, XFS_TRANS_DUMMY1);
1445 if ((error = xfs_trans_reserve(tp, 0,
1446 XFS_ICHANGE_LOG_RES(mp),
1448 xfs_trans_cancel(tp, 0);
1453 xfs_ilock(ip, XFS_ILOCK_EXCL);
1455 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
1456 xfs_trans_ihold(tp, ip);
1457 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
1458 error = xfs_trans_commit(tp, 0);
1459 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1460 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1464 * When shutting down, we need to insure that the AIL is pushed
1465 * to disk or the filesystem can appear corrupt from the PROM.
1467 if ((flags & (SYNC_CLOSE|SYNC_WAIT)) == (SYNC_CLOSE|SYNC_WAIT)) {
1468 XFS_bflush(mp->m_ddev_targp);
1469 if (mp->m_rtdev_targp) {
1470 XFS_bflush(mp->m_rtdev_targp);
1474 return XFS_ERROR(last_error);
1478 * xfs_vget - called by DMAPI and NFSD to get vnode from file handle
1492 * Invalid. Since handles can be created in user space and passed in
1493 * via gethandle(), this is not cause for a panic.
1495 if (xfid->fid_len != sizeof(*xfid) - sizeof(xfid->fid_len))
1496 return XFS_ERROR(EINVAL);
1498 ino = xfid->fid_ino;
1499 igen = xfid->fid_gen;
1502 * NFS can sometimes send requests for ino 0. Fail them gracefully.
1505 return XFS_ERROR(ESTALE);
1507 error = xfs_iget(mp, NULL, ino, 0, XFS_ILOCK_SHARED, &ip, 0);
1515 return XFS_ERROR(EIO);
1518 if (ip->i_d.di_mode == 0 || ip->i_d.di_gen != igen) {
1519 xfs_iput_new(ip, XFS_ILOCK_SHARED);
1521 return XFS_ERROR(ENOENT);
1524 *vpp = XFS_ITOV(ip);
1525 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1530 #define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
1531 #define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
1532 #define MNTOPT_LOGDEV "logdev" /* log device */
1533 #define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
1534 #define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
1535 #define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
1536 #define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
1537 #define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
1538 #define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
1539 #define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
1540 #define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
1541 #define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
1542 #define MNTOPT_MTPT "mtpt" /* filesystem mount point */
1543 #define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
1544 #define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
1545 #define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
1546 #define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
1547 #define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
1548 #define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
1549 #define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
1550 * unwritten extent conversion */
1551 #define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
1552 #define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
1553 #define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
1554 #define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
1555 #define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
1556 #define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
1557 #define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
1559 #define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
1560 #define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
1561 #define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
1562 #define MNTOPT_QUOTA "quota" /* disk quotas (user) */
1563 #define MNTOPT_NOQUOTA "noquota" /* no quotas */
1564 #define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */
1565 #define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */
1566 #define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */
1567 #define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */
1568 #define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */
1569 #define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */
1570 #define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
1571 #define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
1572 #define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
1573 #define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */
1574 #define MNTOPT_DMAPI "dmapi" /* DMI enabled (DMAPI / XDSM) */
1575 #define MNTOPT_XDSM "xdsm" /* DMI enabled (DMAPI / XDSM) */
1576 #define MNTOPT_DMI "dmi" /* DMI enabled (DMAPI / XDSM) */
1578 STATIC unsigned long
1579 suffix_strtoul(char *s, char **endp, unsigned int base)
1581 int last, shift_left_factor = 0;
1584 last = strlen(value) - 1;
1585 if (value[last] == 'K' || value[last] == 'k') {
1586 shift_left_factor = 10;
1589 if (value[last] == 'M' || value[last] == 'm') {
1590 shift_left_factor = 20;
1593 if (value[last] == 'G' || value[last] == 'g') {
1594 shift_left_factor = 30;
1598 return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
1603 struct xfs_mount *mp,
1605 struct xfs_mount_args *args,
1608 char *this_char, *value, *eov;
1609 int dsunit, dswidth, vol_dsunit, vol_dswidth;
1613 args->flags |= XFSMNT_BARRIER;
1614 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
1619 iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0;
1621 while ((this_char = strsep(&options, ",")) != NULL) {
1624 if ((value = strchr(this_char, '=')) != NULL)
1627 if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
1628 if (!value || !*value) {
1630 "XFS: %s option requires an argument",
1634 args->logbufs = simple_strtoul(value, &eov, 10);
1635 } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
1636 if (!value || !*value) {
1638 "XFS: %s option requires an argument",
1642 args->logbufsize = suffix_strtoul(value, &eov, 10);
1643 } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
1644 if (!value || !*value) {
1646 "XFS: %s option requires an argument",
1650 strncpy(args->logname, value, MAXNAMELEN);
1651 } else if (!strcmp(this_char, MNTOPT_MTPT)) {
1652 if (!value || !*value) {
1654 "XFS: %s option requires an argument",
1658 strncpy(args->mtpt, value, MAXNAMELEN);
1659 } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
1660 if (!value || !*value) {
1662 "XFS: %s option requires an argument",
1666 strncpy(args->rtname, value, MAXNAMELEN);
1667 } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
1668 if (!value || !*value) {
1670 "XFS: %s option requires an argument",
1674 iosize = simple_strtoul(value, &eov, 10);
1675 args->flags |= XFSMNT_IOSIZE;
1676 args->iosizelog = (uint8_t) iosize;
1677 } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
1678 if (!value || !*value) {
1680 "XFS: %s option requires an argument",
1684 iosize = suffix_strtoul(value, &eov, 10);
1685 args->flags |= XFSMNT_IOSIZE;
1686 args->iosizelog = ffs(iosize) - 1;
1687 } else if (!strcmp(this_char, MNTOPT_GRPID) ||
1688 !strcmp(this_char, MNTOPT_BSDGROUPS)) {
1689 mp->m_flags |= XFS_MOUNT_GRPID;
1690 } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
1691 !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
1692 mp->m_flags &= ~XFS_MOUNT_GRPID;
1693 } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
1694 args->flags |= XFSMNT_WSYNC;
1695 } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
1696 args->flags |= XFSMNT_OSYNCISOSYNC;
1697 } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
1698 args->flags |= XFSMNT_NORECOVERY;
1699 } else if (!strcmp(this_char, MNTOPT_INO64)) {
1700 args->flags |= XFSMNT_INO64;
1703 "XFS: %s option not allowed on this system",
1707 } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
1708 args->flags |= XFSMNT_NOALIGN;
1709 } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
1710 args->flags |= XFSMNT_SWALLOC;
1711 } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
1712 if (!value || !*value) {
1714 "XFS: %s option requires an argument",
1718 dsunit = simple_strtoul(value, &eov, 10);
1719 } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
1720 if (!value || !*value) {
1722 "XFS: %s option requires an argument",
1726 dswidth = simple_strtoul(value, &eov, 10);
1727 } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
1728 args->flags &= ~XFSMNT_32BITINODES;
1731 "XFS: %s option not allowed on this system",
1735 } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
1736 args->flags |= XFSMNT_NOUUID;
1737 } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
1738 args->flags |= XFSMNT_BARRIER;
1739 } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
1740 args->flags &= ~XFSMNT_BARRIER;
1741 } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
1743 args->flags &= ~XFSMNT_IDELETE;
1744 } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
1745 args->flags |= XFSMNT_IDELETE;
1746 } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
1747 args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE;
1748 } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
1749 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
1750 } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
1751 args->flags |= XFSMNT_ATTR2;
1752 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
1753 args->flags &= ~XFSMNT_ATTR2;
1754 } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
1755 args->flags2 |= XFSMNT2_FILESTREAMS;
1756 } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
1757 args->flags &= ~(XFSMNT_UQUOTAENF|XFSMNT_UQUOTA);
1758 args->flags &= ~(XFSMNT_GQUOTAENF|XFSMNT_GQUOTA);
1759 } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
1760 !strcmp(this_char, MNTOPT_UQUOTA) ||
1761 !strcmp(this_char, MNTOPT_USRQUOTA)) {
1762 args->flags |= XFSMNT_UQUOTA | XFSMNT_UQUOTAENF;
1763 } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
1764 !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
1765 args->flags |= XFSMNT_UQUOTA;
1766 args->flags &= ~XFSMNT_UQUOTAENF;
1767 } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
1768 !strcmp(this_char, MNTOPT_PRJQUOTA)) {
1769 args->flags |= XFSMNT_PQUOTA | XFSMNT_PQUOTAENF;
1770 } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
1771 args->flags |= XFSMNT_PQUOTA;
1772 args->flags &= ~XFSMNT_PQUOTAENF;
1773 } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
1774 !strcmp(this_char, MNTOPT_GRPQUOTA)) {
1775 args->flags |= XFSMNT_GQUOTA | XFSMNT_GQUOTAENF;
1776 } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
1777 args->flags |= XFSMNT_GQUOTA;
1778 args->flags &= ~XFSMNT_GQUOTAENF;
1779 } else if (!strcmp(this_char, MNTOPT_DMAPI)) {
1780 args->flags |= XFSMNT_DMAPI;
1781 } else if (!strcmp(this_char, MNTOPT_XDSM)) {
1782 args->flags |= XFSMNT_DMAPI;
1783 } else if (!strcmp(this_char, MNTOPT_DMI)) {
1784 args->flags |= XFSMNT_DMAPI;
1785 } else if (!strcmp(this_char, "ihashsize")) {
1787 "XFS: ihashsize no longer used, option is deprecated.");
1788 } else if (!strcmp(this_char, "osyncisdsync")) {
1789 /* no-op, this is now the default */
1791 "XFS: osyncisdsync is now the default, option is deprecated.");
1792 } else if (!strcmp(this_char, "irixsgid")) {
1794 "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
1797 "XFS: unknown mount option [%s].", this_char);
1802 if (args->flags & XFSMNT_NORECOVERY) {
1803 if ((mp->m_flags & XFS_MOUNT_RDONLY) == 0) {
1805 "XFS: no-recovery mounts must be read-only.");
1810 if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) {
1812 "XFS: sunit and swidth options incompatible with the noalign option");
1816 if ((args->flags & XFSMNT_GQUOTA) && (args->flags & XFSMNT_PQUOTA)) {
1818 "XFS: cannot mount with both project and group quota");
1822 if ((args->flags & XFSMNT_DMAPI) && *args->mtpt == '\0') {
1823 printk("XFS: %s option needs the mount point option as well\n",
1828 if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
1830 "XFS: sunit and swidth must be specified together");
1834 if (dsunit && (dswidth % dsunit != 0)) {
1836 "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
1842 * Applications using DMI filesystems often expect the
1843 * inode generation number to be monotonically increasing.
1844 * If we delete inode chunks we break this assumption, so
1845 * keep unused inode chunks on disk for DMI filesystems
1846 * until we come up with a better solution.
1847 * Note that if "ikeep" or "noikeep" mount options are
1848 * supplied, then they are honored.
1850 if (!(args->flags & XFSMNT_DMAPI) && !ikeep)
1851 args->flags |= XFSMNT_IDELETE;
1853 if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
1855 args->sunit = dsunit;
1856 args->flags |= XFSMNT_RETERR;
1858 args->sunit = vol_dsunit;
1860 dswidth ? (args->swidth = dswidth) :
1861 (args->swidth = vol_dswidth);
1863 args->sunit = args->swidth = 0;
1867 if (args->flags & XFSMNT_32BITINODES)
1868 mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
1870 args->flags |= XFSMNT_FLAGS2;
1876 struct xfs_mount *mp,
1879 static struct proc_xfs_info {
1883 /* the few simple ones we can get from the mount struct */
1884 { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
1885 { XFS_MOUNT_INO64, "," MNTOPT_INO64 },
1886 { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
1887 { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
1888 { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
1889 { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
1890 { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
1893 struct proc_xfs_info *xfs_infop;
1895 for (xfs_infop = xfs_info; xfs_infop->flag; xfs_infop++) {
1896 if (mp->m_flags & xfs_infop->flag)
1897 seq_puts(m, xfs_infop->str);
1900 if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
1901 seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
1902 (int)(1 << mp->m_writeio_log) >> 10);
1904 if (mp->m_logbufs > 0)
1905 seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
1906 if (mp->m_logbsize > 0)
1907 seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
1910 seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
1912 seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
1914 if (mp->m_dalign > 0)
1915 seq_printf(m, "," MNTOPT_SUNIT "=%d",
1916 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
1917 if (mp->m_swidth > 0)
1918 seq_printf(m, "," MNTOPT_SWIDTH "=%d",
1919 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
1921 if (!(mp->m_flags & XFS_MOUNT_IDELETE))
1922 seq_printf(m, "," MNTOPT_IKEEP);
1923 if (!(mp->m_flags & XFS_MOUNT_COMPAT_IOSIZE))
1924 seq_printf(m, "," MNTOPT_LARGEIO);
1926 if (!(mp->m_flags & XFS_MOUNT_SMALL_INUMS))
1927 seq_printf(m, "," MNTOPT_64BITINODE);
1928 if (mp->m_flags & XFS_MOUNT_GRPID)
1929 seq_printf(m, "," MNTOPT_GRPID);
1931 if (mp->m_qflags & XFS_UQUOTA_ACCT) {
1932 if (mp->m_qflags & XFS_UQUOTA_ENFD)
1933 seq_puts(m, "," MNTOPT_USRQUOTA);
1935 seq_puts(m, "," MNTOPT_UQUOTANOENF);
1938 if (mp->m_qflags & XFS_PQUOTA_ACCT) {
1939 if (mp->m_qflags & XFS_OQUOTA_ENFD)
1940 seq_puts(m, "," MNTOPT_PRJQUOTA);
1942 seq_puts(m, "," MNTOPT_PQUOTANOENF);
1945 if (mp->m_qflags & XFS_GQUOTA_ACCT) {
1946 if (mp->m_qflags & XFS_OQUOTA_ENFD)
1947 seq_puts(m, "," MNTOPT_GRPQUOTA);
1949 seq_puts(m, "," MNTOPT_GQUOTANOENF);
1952 if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
1953 seq_puts(m, "," MNTOPT_NOQUOTA);
1955 if (mp->m_flags & XFS_MOUNT_DMAPI)
1956 seq_puts(m, "," MNTOPT_DMAPI);
1961 * Second stage of a freeze. The data is already frozen so we only
1962 * need to take care of themetadata. Once that's done write a dummy
1963 * record to dirty the log in case of a crash while frozen.
1969 xfs_attr_quiesce(mp);
1970 xfs_fs_log_dummy(mp);