2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include "xfs_types.h"
24 #include "xfs_trans.h"
28 #include "xfs_dmapi.h"
29 #include "xfs_mount.h"
30 #include "xfs_da_btree.h"
31 #include "xfs_bmap_btree.h"
32 #include "xfs_ialloc_btree.h"
33 #include "xfs_alloc_btree.h"
34 #include "xfs_dir2_sf.h"
35 #include "xfs_attr_sf.h"
36 #include "xfs_dinode.h"
37 #include "xfs_inode.h"
38 #include "xfs_inode_item.h"
39 #include "xfs_btree.h"
40 #include "xfs_alloc.h"
41 #include "xfs_ialloc.h"
42 #include "xfs_quota.h"
43 #include "xfs_error.h"
46 #include "xfs_refcache.h"
47 #include "xfs_buf_item.h"
48 #include "xfs_log_priv.h"
49 #include "xfs_dir2_trace.h"
50 #include "xfs_extfree_item.h"
54 #include "xfs_mru_cache.h"
55 #include "xfs_filestream.h"
56 #include "xfs_fsops.h"
58 STATIC
int xfs_sync(bhv_desc_t
*, int, cred_t
*);
63 extern kmem_zone_t
*xfs_bmap_free_item_zone
;
64 extern kmem_zone_t
*xfs_btree_cur_zone
;
65 extern kmem_zone_t
*xfs_trans_zone
;
66 extern kmem_zone_t
*xfs_buf_item_zone
;
67 extern kmem_zone_t
*xfs_dabuf_zone
;
68 #ifdef XFS_DABUF_DEBUG
69 extern lock_t xfs_dabuf_global_lock
;
70 spinlock_init(&xfs_dabuf_global_lock
, "xfsda");
74 * Initialize all of the zone allocators we use.
76 xfs_bmap_free_item_zone
= kmem_zone_init(sizeof(xfs_bmap_free_item_t
),
77 "xfs_bmap_free_item");
78 xfs_btree_cur_zone
= kmem_zone_init(sizeof(xfs_btree_cur_t
),
80 xfs_trans_zone
= kmem_zone_init(sizeof(xfs_trans_t
), "xfs_trans");
82 kmem_zone_init(sizeof(xfs_da_state_t
), "xfs_da_state");
83 xfs_dabuf_zone
= kmem_zone_init(sizeof(xfs_dabuf_t
), "xfs_dabuf");
84 xfs_ifork_zone
= kmem_zone_init(sizeof(xfs_ifork_t
), "xfs_ifork");
85 xfs_acl_zone_init(xfs_acl_zone
, "xfs_acl");
87 xfs_filestream_init();
90 * The size of the zone allocated buf log item is the maximum
91 * size possible under XFS. This wastes a little bit of memory,
92 * but it is much faster.
95 kmem_zone_init((sizeof(xfs_buf_log_item_t
) +
96 (((XFS_MAX_BLOCKSIZE
/ XFS_BLI_CHUNK
) /
97 NBWORD
) * sizeof(int))),
100 kmem_zone_init((sizeof(xfs_efd_log_item_t
) +
101 ((XFS_EFD_MAX_FAST_EXTENTS
- 1) *
102 sizeof(xfs_extent_t
))),
105 kmem_zone_init((sizeof(xfs_efi_log_item_t
) +
106 ((XFS_EFI_MAX_FAST_EXTENTS
- 1) *
107 sizeof(xfs_extent_t
))),
111 * These zones warrant special memory allocator hints
114 kmem_zone_init_flags(sizeof(xfs_inode_t
), "xfs_inode",
115 KM_ZONE_HWALIGN
| KM_ZONE_RECLAIM
|
116 KM_ZONE_SPREAD
, NULL
);
118 kmem_zone_init_flags(sizeof(xfs_inode_log_item_t
), "xfs_ili",
119 KM_ZONE_SPREAD
, NULL
);
121 kmem_zone_init_flags(sizeof(xfs_chashlist_t
), "xfs_chashlist",
122 KM_ZONE_SPREAD
, NULL
);
125 * Allocate global trace buffers.
127 #ifdef XFS_ALLOC_TRACE
128 xfs_alloc_trace_buf
= ktrace_alloc(XFS_ALLOC_TRACE_SIZE
, KM_SLEEP
);
130 #ifdef XFS_BMAP_TRACE
131 xfs_bmap_trace_buf
= ktrace_alloc(XFS_BMAP_TRACE_SIZE
, KM_SLEEP
);
133 #ifdef XFS_BMBT_TRACE
134 xfs_bmbt_trace_buf
= ktrace_alloc(XFS_BMBT_TRACE_SIZE
, KM_SLEEP
);
136 #ifdef XFS_ATTR_TRACE
137 xfs_attr_trace_buf
= ktrace_alloc(XFS_ATTR_TRACE_SIZE
, KM_SLEEP
);
139 #ifdef XFS_DIR2_TRACE
140 xfs_dir2_trace_buf
= ktrace_alloc(XFS_DIR2_GTRACE_SIZE
, KM_SLEEP
);
145 #if (defined(DEBUG) || defined(INDUCE_IO_ERROR))
146 xfs_error_test_init();
147 #endif /* DEBUG || INDUCE_IO_ERROR */
150 xfs_sysctl_register();
157 extern kmem_zone_t
*xfs_bmap_free_item_zone
;
158 extern kmem_zone_t
*xfs_btree_cur_zone
;
159 extern kmem_zone_t
*xfs_inode_zone
;
160 extern kmem_zone_t
*xfs_trans_zone
;
161 extern kmem_zone_t
*xfs_da_state_zone
;
162 extern kmem_zone_t
*xfs_dabuf_zone
;
163 extern kmem_zone_t
*xfs_efd_zone
;
164 extern kmem_zone_t
*xfs_efi_zone
;
165 extern kmem_zone_t
*xfs_buf_item_zone
;
166 extern kmem_zone_t
*xfs_chashlist_zone
;
168 xfs_cleanup_procfs();
169 xfs_sysctl_unregister();
170 xfs_refcache_destroy();
171 xfs_filestream_uninit();
172 xfs_mru_cache_uninit();
173 xfs_acl_zone_destroy(xfs_acl_zone
);
175 #ifdef XFS_DIR2_TRACE
176 ktrace_free(xfs_dir2_trace_buf
);
178 #ifdef XFS_ATTR_TRACE
179 ktrace_free(xfs_attr_trace_buf
);
181 #ifdef XFS_BMBT_TRACE
182 ktrace_free(xfs_bmbt_trace_buf
);
184 #ifdef XFS_BMAP_TRACE
185 ktrace_free(xfs_bmap_trace_buf
);
187 #ifdef XFS_ALLOC_TRACE
188 ktrace_free(xfs_alloc_trace_buf
);
191 kmem_zone_destroy(xfs_bmap_free_item_zone
);
192 kmem_zone_destroy(xfs_btree_cur_zone
);
193 kmem_zone_destroy(xfs_inode_zone
);
194 kmem_zone_destroy(xfs_trans_zone
);
195 kmem_zone_destroy(xfs_da_state_zone
);
196 kmem_zone_destroy(xfs_dabuf_zone
);
197 kmem_zone_destroy(xfs_buf_item_zone
);
198 kmem_zone_destroy(xfs_efd_zone
);
199 kmem_zone_destroy(xfs_efi_zone
);
200 kmem_zone_destroy(xfs_ifork_zone
);
201 kmem_zone_destroy(xfs_ili_zone
);
202 kmem_zone_destroy(xfs_chashlist_zone
);
208 * This function fills in xfs_mount_t fields based on mount args.
209 * Note: the superblock has _not_ yet been read in.
214 struct xfs_mount_args
*ap
,
215 struct xfs_mount
*mp
)
217 /* Values are in BBs */
218 if ((ap
->flags
& XFSMNT_NOALIGN
) != XFSMNT_NOALIGN
) {
220 * At this point the superblock has not been read
221 * in, therefore we do not know the block size.
222 * Before the mount call ends we will convert
225 mp
->m_dalign
= ap
->sunit
;
226 mp
->m_swidth
= ap
->swidth
;
229 if (ap
->logbufs
!= -1 &&
231 (ap
->logbufs
< XLOG_MIN_ICLOGS
||
232 ap
->logbufs
> XLOG_MAX_ICLOGS
)) {
234 "XFS: invalid logbufs value: %d [not %d-%d]",
235 ap
->logbufs
, XLOG_MIN_ICLOGS
, XLOG_MAX_ICLOGS
);
236 return XFS_ERROR(EINVAL
);
238 mp
->m_logbufs
= ap
->logbufs
;
239 if (ap
->logbufsize
!= -1 &&
240 ap
->logbufsize
!= 0 &&
241 (ap
->logbufsize
< 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_ihsize
= ap
->ihashsize
;
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_IHASHSIZE
)
297 mp
->m_flags
|= XFS_MOUNT_IHASHSIZE
;
298 if (ap
->flags
& XFSMNT_IDELETE
)
299 mp
->m_flags
|= XFS_MOUNT_IDELETE
;
300 if (ap
->flags
& XFSMNT_DIRSYNC
)
301 mp
->m_flags
|= XFS_MOUNT_DIRSYNC
;
302 if (ap
->flags
& XFSMNT_ATTR2
)
303 mp
->m_flags
|= XFS_MOUNT_ATTR2
;
305 if (ap
->flags2
& XFSMNT2_COMPAT_IOSIZE
)
306 mp
->m_flags
|= XFS_MOUNT_COMPAT_IOSIZE
;
309 * no recovery flag requires a read-only mount
311 if (ap
->flags
& XFSMNT_NORECOVERY
) {
312 if (!(vfs
->vfs_flag
& VFS_RDONLY
)) {
314 "XFS: tried to mount a FS read-write without recovery!");
315 return XFS_ERROR(EINVAL
);
317 mp
->m_flags
|= XFS_MOUNT_NORECOVERY
;
320 if (ap
->flags
& XFSMNT_NOUUID
)
321 mp
->m_flags
|= XFS_MOUNT_NOUUID
;
322 if (ap
->flags
& XFSMNT_BARRIER
)
323 mp
->m_flags
|= XFS_MOUNT_BARRIER
;
325 mp
->m_flags
&= ~XFS_MOUNT_BARRIER
;
327 if (ap
->flags2
& XFSMNT2_FILESTREAMS
)
328 mp
->m_flags
|= XFS_MOUNT_FILESTREAMS
;
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
);
410 * The file system configurations are:
411 * (1) device (partition) with data and internal log
412 * (2) logical volume with data and log subvolumes.
413 * (3) logical volume with data, log, and realtime subvolumes.
415 * We only have to handle opening the log and realtime volumes here if
416 * they are present. The data subvolume has already been opened by
417 * get_sb_bdev() and is stored in vfsp->vfs_super->s_bdev.
421 struct bhv_desc
*bhvp
,
422 struct xfs_mount_args
*args
,
425 struct bhv_vfs
*vfsp
= bhvtovfs(bhvp
);
427 struct xfs_mount
*mp
= XFS_BHVTOM(bhvp
);
428 struct block_device
*ddev
, *logdev
, *rtdev
;
429 int flags
= 0, error
;
431 ddev
= vfsp
->vfs_super
->s_bdev
;
432 logdev
= rtdev
= NULL
;
435 * Setup xfs_mount function vectors from available behaviors
437 p
= vfs_bhv_lookup(vfsp
, VFS_POSITION_DM
);
438 mp
->m_dm_ops
= p
? *(xfs_dmops_t
*) vfs_bhv_custom(p
) : xfs_dmcore_stub
;
439 p
= vfs_bhv_lookup(vfsp
, VFS_POSITION_QM
);
440 mp
->m_qm_ops
= p
? *(xfs_qmops_t
*) vfs_bhv_custom(p
) : xfs_qmcore_stub
;
441 p
= vfs_bhv_lookup(vfsp
, VFS_POSITION_IO
);
442 mp
->m_io_ops
= p
? *(xfs_ioops_t
*) vfs_bhv_custom(p
) : xfs_iocore_xfs
;
444 if (args
->flags
& XFSMNT_QUIET
)
445 flags
|= XFS_MFSI_QUIET
;
448 * Open real time and log devices - order is important.
450 if (args
->logname
[0]) {
451 error
= xfs_blkdev_get(mp
, args
->logname
, &logdev
);
455 if (args
->rtname
[0]) {
456 error
= xfs_blkdev_get(mp
, args
->rtname
, &rtdev
);
458 xfs_blkdev_put(logdev
);
462 if (rtdev
== ddev
|| rtdev
== logdev
) {
464 "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
465 xfs_blkdev_put(logdev
);
466 xfs_blkdev_put(rtdev
);
472 * Setup xfs_mount buffer target pointers
475 mp
->m_ddev_targp
= xfs_alloc_buftarg(ddev
, 0);
476 if (!mp
->m_ddev_targp
) {
477 xfs_blkdev_put(logdev
);
478 xfs_blkdev_put(rtdev
);
482 mp
->m_rtdev_targp
= xfs_alloc_buftarg(rtdev
, 1);
483 if (!mp
->m_rtdev_targp
) {
484 xfs_blkdev_put(logdev
);
485 xfs_blkdev_put(rtdev
);
489 mp
->m_logdev_targp
= (logdev
&& logdev
!= ddev
) ?
490 xfs_alloc_buftarg(logdev
, 1) : mp
->m_ddev_targp
;
491 if (!mp
->m_logdev_targp
) {
492 xfs_blkdev_put(logdev
);
493 xfs_blkdev_put(rtdev
);
498 * Setup flags based on mount(2) options and then the superblock
500 error
= xfs_start_flags(vfsp
, args
, mp
);
503 error
= xfs_readsb(mp
, flags
);
506 error
= xfs_finish_flags(vfsp
, args
, mp
);
511 * Setup xfs_mount buffer target pointers based on superblock
513 error
= xfs_setsize_buftarg(mp
->m_ddev_targp
, mp
->m_sb
.sb_blocksize
,
514 mp
->m_sb
.sb_sectsize
);
515 if (!error
&& logdev
&& logdev
!= ddev
) {
516 unsigned int log_sector_size
= BBSIZE
;
518 if (XFS_SB_VERSION_HASSECTOR(&mp
->m_sb
))
519 log_sector_size
= mp
->m_sb
.sb_logsectsize
;
520 error
= xfs_setsize_buftarg(mp
->m_logdev_targp
,
521 mp
->m_sb
.sb_blocksize
,
525 error
= xfs_setsize_buftarg(mp
->m_rtdev_targp
,
526 mp
->m_sb
.sb_blocksize
,
527 mp
->m_sb
.sb_sectsize
);
531 if (mp
->m_flags
& XFS_MOUNT_BARRIER
)
532 xfs_mountfs_check_barriers(mp
);
534 if ((error
= xfs_filestream_mount(mp
)))
537 error
= XFS_IOINIT(vfsp
, args
, flags
);
547 xfs_binval(mp
->m_ddev_targp
);
548 if (logdev
&& logdev
!= ddev
)
549 xfs_binval(mp
->m_logdev_targp
);
551 xfs_binval(mp
->m_rtdev_targp
);
553 xfs_unmountfs_close(mp
, credp
);
563 bhv_vfs_t
*vfsp
= bhvtovfs(bdp
);
564 xfs_mount_t
*mp
= XFS_BHVTOM(bdp
);
567 int unmount_event_wanted
= 0;
568 int unmount_event_flags
= 0;
569 int xfs_unmountfs_needed
= 0;
576 if (vfsp
->vfs_flag
& VFS_DMI
) {
577 error
= XFS_SEND_PREUNMOUNT(mp
, vfsp
,
578 rvp
, DM_RIGHT_NULL
, rvp
, DM_RIGHT_NULL
,
580 (mp
->m_dmevmask
& (1<<DM_EVENT_PREUNMOUNT
))?
581 0:DM_FLAGS_UNWANTED
);
583 return XFS_ERROR(error
);
584 unmount_event_wanted
= 1;
585 unmount_event_flags
= (mp
->m_dmevmask
& (1<<DM_EVENT_UNMOUNT
))?
586 0 : DM_FLAGS_UNWANTED
;
590 * First blow any referenced inode from this file system
591 * out of the reference cache, and delete the timer.
593 xfs_refcache_purge_mp(mp
);
596 * Blow away any referenced inode in the filestreams cache.
597 * This can and will cause log traffic as inodes go inactive
600 xfs_filestream_unmount(mp
);
602 XFS_bflush(mp
->m_ddev_targp
);
603 error
= xfs_unmount_flush(mp
, 0);
607 ASSERT(vn_count(rvp
) == 1);
610 * Drop the reference count
615 * If we're forcing a shutdown, typically because of a media error,
616 * we want to make sure we invalidate dirty pages that belong to
617 * referenced vnodes as well.
619 if (XFS_FORCED_SHUTDOWN(mp
)) {
620 error
= xfs_sync(&mp
->m_bhv
,
621 (SYNC_WAIT
| SYNC_CLOSE
), credp
);
622 ASSERT(error
!= EFSCORRUPTED
);
624 xfs_unmountfs_needed
= 1;
627 /* Send DMAPI event, if required.
628 * Then do xfs_unmountfs() if needed.
629 * Then return error (or zero).
631 if (unmount_event_wanted
) {
632 /* Note: mp structure must still exist for
633 * XFS_SEND_UNMOUNT() call.
635 XFS_SEND_UNMOUNT(mp
, vfsp
, error
== 0 ? rvp
: NULL
,
636 DM_RIGHT_NULL
, 0, error
, unmount_event_flags
);
638 if (xfs_unmountfs_needed
) {
640 * Call common unmount function to flush to disk
641 * and free the super block buffer & mount structures.
643 xfs_unmountfs(mp
, credp
);
646 return XFS_ERROR(error
);
653 int count
= 0, pincount
;
655 xfs_refcache_purge_mp(mp
);
656 xfs_flush_buftarg(mp
->m_ddev_targp
, 0);
657 xfs_finish_reclaim_all(mp
, 0);
659 /* This loop must run at least twice.
660 * The first instance of the loop will flush
661 * most meta data but that will generate more
662 * meta data (typically directory updates).
663 * Which then must be flushed and logged before
664 * we can write the unmount record.
667 xfs_syncsub(mp
, SYNC_INODE_QUIESCE
, NULL
);
668 pincount
= xfs_flush_buftarg(mp
->m_ddev_targp
, 1);
679 * Second stage of a quiesce. The data is already synced, now we have to take
680 * care of the metadata. New transactions are already blocked, so we need to
681 * wait for any remaining transactions to drain out before proceding.
687 /* wait for all modifications to complete */
688 while (atomic_read(&mp
->m_active_trans
) > 0)
691 /* flush inodes and push all remaining buffers out to disk */
694 ASSERT_ALWAYS(atomic_read(&mp
->m_active_trans
) == 0);
696 /* Push the superblock and write an unmount record */
697 xfs_log_sbcount(mp
, 1);
698 xfs_log_unmount_write(mp
);
699 xfs_unmountfs_writesb(mp
);
706 struct xfs_mount_args
*args
)
708 bhv_vfs_t
*vfsp
= bhvtovfs(bdp
);
709 xfs_mount_t
*mp
= XFS_BHVTOM(bdp
);
711 if (!(*flags
& MS_RDONLY
)) { /* rw/ro -> rw */
712 if (vfsp
->vfs_flag
& VFS_RDONLY
)
713 vfsp
->vfs_flag
&= ~VFS_RDONLY
;
714 if (args
->flags
& XFSMNT_BARRIER
) {
715 mp
->m_flags
|= XFS_MOUNT_BARRIER
;
716 xfs_mountfs_check_barriers(mp
);
718 mp
->m_flags
&= ~XFS_MOUNT_BARRIER
;
720 } else if (!(vfsp
->vfs_flag
& VFS_RDONLY
)) { /* rw -> ro */
721 xfs_filestream_flush(mp
);
722 bhv_vfs_sync(vfsp
, SYNC_DATA_QUIESCE
, NULL
);
723 xfs_attr_quiesce(mp
);
724 vfsp
->vfs_flag
|= VFS_RDONLY
;
730 * xfs_unmount_flush implements a set of flush operation on special
731 * inodes, which are needed as a separate set of operations so that
732 * they can be called as part of relocation process.
736 xfs_mount_t
*mp
, /* Mount structure we are getting
738 int relocation
) /* Called from vfs relocation. */
740 xfs_inode_t
*rip
= mp
->m_rootip
;
742 xfs_inode_t
*rsumip
= NULL
;
743 bhv_vnode_t
*rvp
= XFS_ITOV(rip
);
746 xfs_ilock(rip
, XFS_ILOCK_EXCL
| XFS_ILOCK_PARENT
);
750 * Flush out the real time inodes.
752 if ((rbmip
= mp
->m_rbmip
) != NULL
) {
753 xfs_ilock(rbmip
, XFS_ILOCK_EXCL
);
755 error
= xfs_iflush(rbmip
, XFS_IFLUSH_SYNC
);
756 xfs_iunlock(rbmip
, XFS_ILOCK_EXCL
);
758 if (error
== EFSCORRUPTED
)
761 ASSERT(vn_count(XFS_ITOV(rbmip
)) == 1);
763 rsumip
= mp
->m_rsumip
;
764 xfs_ilock(rsumip
, XFS_ILOCK_EXCL
);
766 error
= xfs_iflush(rsumip
, XFS_IFLUSH_SYNC
);
767 xfs_iunlock(rsumip
, XFS_ILOCK_EXCL
);
769 if (error
== EFSCORRUPTED
)
772 ASSERT(vn_count(XFS_ITOV(rsumip
)) == 1);
776 * Synchronously flush root inode to disk
778 error
= xfs_iflush(rip
, XFS_IFLUSH_SYNC
);
779 if (error
== EFSCORRUPTED
)
782 if (vn_count(rvp
) != 1 && !relocation
) {
783 xfs_iunlock(rip
, XFS_ILOCK_EXCL
);
784 return XFS_ERROR(EBUSY
);
788 * Release dquot that rootinode, rbmino and rsumino might be holding,
789 * flush and purge the quota inodes.
791 error
= XFS_QM_UNMOUNT(mp
);
792 if (error
== EFSCORRUPTED
)
796 VN_RELE(XFS_ITOV(rbmip
));
797 VN_RELE(XFS_ITOV(rsumip
));
800 xfs_iunlock(rip
, XFS_ILOCK_EXCL
);
807 xfs_iunlock(rip
, XFS_ILOCK_EXCL
);
809 return XFS_ERROR(EFSCORRUPTED
);
813 * xfs_root extracts the root vnode from a vfs.
815 * vfsp -- the vfs struct for the desired file system
816 * vpp -- address of the caller's vnode pointer which should be
817 * set to the desired fs root vnode
826 vp
= XFS_ITOV((XFS_BHVTOM(bdp
))->m_rootip
);
835 * Fill in the statvfs structure for the given file system. We use
836 * the superblock lock in the mount structure to ensure a consistent
837 * snapshot of the counters returned.
842 bhv_statvfs_t
*statp
,
851 mp
= XFS_BHVTOM(bdp
);
854 statp
->f_type
= XFS_SB_MAGIC
;
856 xfs_icsb_sync_counters_flags(mp
, XFS_ICSB_LAZY_COUNT
);
858 statp
->f_bsize
= sbp
->sb_blocksize
;
859 lsize
= sbp
->sb_logstart
? sbp
->sb_logblocks
: 0;
860 statp
->f_blocks
= sbp
->sb_dblocks
- lsize
;
861 statp
->f_bfree
= statp
->f_bavail
=
862 sbp
->sb_fdblocks
- XFS_ALLOC_SET_ASIDE(mp
);
863 fakeinos
= statp
->f_bfree
<< sbp
->sb_inopblog
;
865 fakeinos
+= mp
->m_inoadd
;
868 MIN(sbp
->sb_icount
+ fakeinos
, (__uint64_t
)XFS_MAXINUMBER
);
873 statp
->f_files
= min_t(typeof(statp
->f_files
),
876 statp
->f_ffree
= statp
->f_files
- (sbp
->sb_icount
- sbp
->sb_ifree
);
877 XFS_SB_UNLOCK(mp
, s
);
879 xfs_statvfs_fsid(statp
, mp
);
880 statp
->f_namelen
= MAXNAMELEN
- 1;
887 * xfs_sync flushes any pending I/O to file system vfsp.
889 * This routine is called by vfs_sync() to make sure that things make it
890 * out to disk eventually, on sync() system calls to flush out everything,
891 * and when the file system is unmounted. For the vfs_sync() case, all
892 * we really need to do is sync out the log to make all of our meta-data
893 * updates permanent (except for timestamps). For calls from pflushd(),
894 * dirty pages are kept moving by calling pdflush() on the inodes
895 * containing them. We also flush the inodes that we can lock without
896 * sleeping and the superblock if we can lock it without sleeping from
897 * vfs_sync() so that items at the tail of the log are always moving out.
900 * SYNC_BDFLUSH - We're being called from vfs_sync() so we don't want
901 * to sleep if we can help it. All we really need
902 * to do is ensure that the log is synced at least
903 * periodically. We also push the inodes and
904 * superblock if we can lock them without sleeping
905 * and they are not pinned.
906 * SYNC_ATTR - We need to flush the inodes. If SYNC_BDFLUSH is not
907 * set, then we really want to lock each inode and flush
909 * SYNC_WAIT - All the flushes that take place in this call should
911 * SYNC_DELWRI - This tells us to push dirty pages associated with
912 * inodes. SYNC_WAIT and SYNC_BDFLUSH are used to
913 * determine if they should be flushed sync, async, or
915 * SYNC_CLOSE - This flag is passed when the system is being
916 * unmounted. We should sync and invalidate everything.
917 * SYNC_FSDATA - This indicates that the caller would like to make
918 * sure the superblock is safe on disk. We can ensure
919 * this by simply making sure the log gets flushed
920 * if SYNC_BDFLUSH is set, and by actually writing it
922 * SYNC_IOWAIT - The caller wants us to wait for all data I/O to complete
923 * before we return (including direct I/O). Forms the drain
924 * side of the write barrier needed to safely quiesce the
935 xfs_mount_t
*mp
= XFS_BHVTOM(bdp
);
937 if (flags
& SYNC_IOWAIT
)
938 xfs_filestream_flush(mp
);
940 return xfs_syncsub(mp
, flags
, NULL
);
944 * xfs sync routine for internal use
946 * This routine supports all of the flags defined for the generic vfs_sync
947 * interface as explained above under xfs_sync.
956 xfs_inode_t
*ip
= NULL
;
957 xfs_inode_t
*ip_next
;
959 bhv_vnode_t
*vp
= NULL
;
964 uint base_lock_flags
;
965 boolean_t mount_locked
;
966 boolean_t vnode_refed
;
969 xfs_iptr_t
*ipointer
;
971 boolean_t ipointer_in
= B_FALSE
;
973 #define IPOINTER_SET ipointer_in = B_TRUE
974 #define IPOINTER_CLR ipointer_in = B_FALSE
981 /* Insert a marker record into the inode list after inode ip. The list
982 * must be locked when this is called. After the call the list will no
985 #define IPOINTER_INSERT(ip, mp) { \
986 ASSERT(ipointer_in == B_FALSE); \
987 ipointer->ip_mnext = ip->i_mnext; \
988 ipointer->ip_mprev = ip; \
989 ip->i_mnext = (xfs_inode_t *)ipointer; \
990 ipointer->ip_mnext->i_mprev = (xfs_inode_t *)ipointer; \
992 XFS_MOUNT_IUNLOCK(mp); \
993 mount_locked = B_FALSE; \
997 /* Remove the marker from the inode list. If the marker was the only item
998 * in the list then there are no remaining inodes and we should zero out
999 * the whole list. If we are the current head of the list then move the head
1002 #define IPOINTER_REMOVE(ip, mp) { \
1003 ASSERT(ipointer_in == B_TRUE); \
1004 if (ipointer->ip_mnext != (xfs_inode_t *)ipointer) { \
1005 ip = ipointer->ip_mnext; \
1006 ip->i_mprev = ipointer->ip_mprev; \
1007 ipointer->ip_mprev->i_mnext = ip; \
1008 if (mp->m_inodes == (xfs_inode_t *)ipointer) { \
1009 mp->m_inodes = ip; \
1012 ASSERT(mp->m_inodes == (xfs_inode_t *)ipointer); \
1013 mp->m_inodes = NULL; \
1019 #define XFS_PREEMPT_MASK 0x7f
1023 if (XFS_MTOVFS(mp
)->vfs_flag
& VFS_RDONLY
)
1029 /* Allocate a reference marker */
1030 ipointer
= (xfs_iptr_t
*)kmem_zalloc(sizeof(xfs_iptr_t
), KM_SLEEP
);
1032 fflag
= XFS_B_ASYNC
; /* default is don't wait */
1033 if (flags
& (SYNC_BDFLUSH
| SYNC_DELWRI
))
1034 fflag
= XFS_B_DELWRI
;
1035 if (flags
& SYNC_WAIT
)
1036 fflag
= 0; /* synchronous overrides all */
1038 base_lock_flags
= XFS_ILOCK_SHARED
;
1039 if (flags
& (SYNC_DELWRI
| SYNC_CLOSE
)) {
1041 * We need the I/O lock if we're going to call any of
1042 * the flush/inval routines.
1044 base_lock_flags
|= XFS_IOLOCK_SHARED
;
1047 XFS_MOUNT_ILOCK(mp
);
1051 mount_locked
= B_TRUE
;
1052 vnode_refed
= B_FALSE
;
1057 ASSERT(ipointer_in
== B_FALSE
);
1058 ASSERT(vnode_refed
== B_FALSE
);
1060 lock_flags
= base_lock_flags
;
1063 * There were no inodes in the list, just break out
1071 * We found another sync thread marker - skip it
1073 if (ip
->i_mount
== NULL
) {
1078 vp
= XFS_ITOV_NULL(ip
);
1081 * If the vnode is gone then this is being torn down,
1082 * call reclaim if it is flushed, else let regular flush
1083 * code deal with it later in the loop.
1087 /* Skip ones already in reclaim */
1088 if (ip
->i_flags
& XFS_IRECLAIM
) {
1092 if (xfs_ilock_nowait(ip
, XFS_ILOCK_EXCL
) == 0) {
1094 } else if ((xfs_ipincount(ip
) == 0) &&
1095 xfs_iflock_nowait(ip
)) {
1096 IPOINTER_INSERT(ip
, mp
);
1098 xfs_finish_reclaim(ip
, 1,
1099 XFS_IFLUSH_DELWRI_ELSE_ASYNC
);
1101 XFS_MOUNT_ILOCK(mp
);
1102 mount_locked
= B_TRUE
;
1103 IPOINTER_REMOVE(ip
, mp
);
1105 xfs_iunlock(ip
, XFS_ILOCK_EXCL
);
1116 if (XFS_FORCED_SHUTDOWN(mp
) && !(flags
& SYNC_CLOSE
)) {
1117 XFS_MOUNT_IUNLOCK(mp
);
1118 kmem_free(ipointer
, sizeof(xfs_iptr_t
));
1123 * If this is just vfs_sync() or pflushd() calling
1124 * then we can skip inodes for which it looks like
1125 * there is nothing to do. Since we don't have the
1126 * inode locked this is racy, but these are periodic
1127 * calls so it doesn't matter. For the others we want
1128 * to know for sure, so we at least try to lock them.
1130 if (flags
& SYNC_BDFLUSH
) {
1131 if (((ip
->i_itemp
== NULL
) ||
1132 !(ip
->i_itemp
->ili_format
.ilf_fields
&
1134 (ip
->i_update_core
== 0)) {
1141 * Try to lock without sleeping. We're out of order with
1142 * the inode list lock here, so if we fail we need to drop
1143 * the mount lock and try again. If we're called from
1144 * bdflush() here, then don't bother.
1146 * The inode lock here actually coordinates with the
1147 * almost spurious inode lock in xfs_ireclaim() to prevent
1148 * the vnode we handle here without a reference from
1149 * being freed while we reference it. If we lock the inode
1150 * while it's on the mount list here, then the spurious inode
1151 * lock in xfs_ireclaim() after the inode is pulled from
1152 * the mount list will sleep until we release it here.
1153 * This keeps the vnode from being freed while we reference
1156 if (xfs_ilock_nowait(ip
, lock_flags
) == 0) {
1157 if ((flags
& SYNC_BDFLUSH
) || (vp
== NULL
)) {
1168 IPOINTER_INSERT(ip
, mp
);
1169 xfs_ilock(ip
, lock_flags
);
1171 ASSERT(vp
== XFS_ITOV(ip
));
1172 ASSERT(ip
->i_mount
== mp
);
1174 vnode_refed
= B_TRUE
;
1177 /* From here on in the loop we may have a marker record
1178 * in the inode list.
1182 * If we have to flush data or wait for I/O completion
1183 * we need to drop the ilock that we currently hold.
1184 * If we need to drop the lock, insert a marker if we
1185 * have not already done so.
1187 if ((flags
& (SYNC_CLOSE
|SYNC_IOWAIT
)) ||
1188 ((flags
& SYNC_DELWRI
) && VN_DIRTY(vp
))) {
1190 IPOINTER_INSERT(ip
, mp
);
1192 xfs_iunlock(ip
, XFS_ILOCK_SHARED
);
1194 if (flags
& SYNC_CLOSE
) {
1195 /* Shutdown case. Flush and invalidate. */
1196 if (XFS_FORCED_SHUTDOWN(mp
))
1197 bhv_vop_toss_pages(vp
, 0, -1, FI_REMAPF
);
1199 error
= bhv_vop_flushinval_pages(vp
, 0,
1201 } else if ((flags
& SYNC_DELWRI
) && VN_DIRTY(vp
)) {
1202 error
= bhv_vop_flush_pages(vp
, (xfs_off_t
)0,
1203 -1, fflag
, FI_NONE
);
1207 * When freezing, we need to wait ensure all I/O (including direct
1208 * I/O) is complete to ensure no further data modification can take
1209 * place after this point
1211 if (flags
& SYNC_IOWAIT
)
1214 xfs_ilock(ip
, XFS_ILOCK_SHARED
);
1217 if (flags
& SYNC_BDFLUSH
) {
1218 if ((flags
& SYNC_ATTR
) &&
1219 ((ip
->i_update_core
) ||
1220 ((ip
->i_itemp
!= NULL
) &&
1221 (ip
->i_itemp
->ili_format
.ilf_fields
!= 0)))) {
1223 /* Insert marker and drop lock if not already
1227 IPOINTER_INSERT(ip
, mp
);
1231 * We don't want the periodic flushing of the
1232 * inodes by vfs_sync() to interfere with
1233 * I/O to the file, especially read I/O
1234 * where it is only the access time stamp
1235 * that is being flushed out. To prevent
1236 * long periods where we have both inode
1237 * locks held shared here while reading the
1238 * inode's buffer in from disk, we drop the
1239 * inode lock while reading in the inode
1240 * buffer. We have to release the buffer
1241 * and reacquire the inode lock so that they
1242 * are acquired in the proper order (inode
1243 * locks first). The buffer will go at the
1244 * end of the lru chain, though, so we can
1245 * expect it to still be there when we go
1246 * for it again in xfs_iflush().
1248 if ((xfs_ipincount(ip
) == 0) &&
1249 xfs_iflock_nowait(ip
)) {
1252 xfs_iunlock(ip
, XFS_ILOCK_SHARED
);
1254 error
= xfs_itobp(mp
, NULL
, ip
,
1259 /* Bailing out, remove the
1260 * marker and free it.
1262 XFS_MOUNT_ILOCK(mp
);
1263 IPOINTER_REMOVE(ip
, mp
);
1264 XFS_MOUNT_IUNLOCK(mp
);
1266 ASSERT(!(lock_flags
&
1267 XFS_IOLOCK_SHARED
));
1270 sizeof(xfs_iptr_t
));
1275 * Since we dropped the inode lock,
1276 * the inode may have been reclaimed.
1277 * Therefore, we reacquire the mount
1278 * lock and check to see if we were the
1279 * inode reclaimed. If this happened
1280 * then the ipointer marker will no
1281 * longer point back at us. In this
1282 * case, move ip along to the inode
1283 * after the marker, remove the marker
1286 XFS_MOUNT_ILOCK(mp
);
1287 mount_locked
= B_TRUE
;
1289 if (ip
!= ipointer
->ip_mprev
) {
1290 IPOINTER_REMOVE(ip
, mp
);
1292 ASSERT(!vnode_refed
);
1293 ASSERT(!(lock_flags
&
1294 XFS_IOLOCK_SHARED
));
1298 ASSERT(ip
->i_mount
== mp
);
1300 if (xfs_ilock_nowait(ip
,
1301 XFS_ILOCK_SHARED
) == 0) {
1302 ASSERT(ip
->i_mount
== mp
);
1304 * We failed to reacquire
1305 * the inode lock without
1306 * sleeping, so just skip
1307 * the inode for now. We
1308 * clear the ILOCK bit from
1309 * the lock_flags so that we
1310 * won't try to drop a lock
1311 * we don't hold below.
1313 lock_flags
&= ~XFS_ILOCK_SHARED
;
1314 IPOINTER_REMOVE(ip_next
, mp
);
1315 } else if ((xfs_ipincount(ip
) == 0) &&
1316 xfs_iflock_nowait(ip
)) {
1317 ASSERT(ip
->i_mount
== mp
);
1319 * Since this is vfs_sync()
1320 * calling we only flush the
1321 * inode out if we can lock
1322 * it without sleeping and
1323 * it is not pinned. Drop
1324 * the mount lock here so
1325 * that we don't hold it for
1326 * too long. We already have
1327 * a marker in the list here.
1329 XFS_MOUNT_IUNLOCK(mp
);
1330 mount_locked
= B_FALSE
;
1331 error
= xfs_iflush(ip
,
1334 ASSERT(ip
->i_mount
== mp
);
1335 IPOINTER_REMOVE(ip_next
, mp
);
1342 if ((flags
& SYNC_ATTR
) &&
1343 ((ip
->i_update_core
) ||
1344 ((ip
->i_itemp
!= NULL
) &&
1345 (ip
->i_itemp
->ili_format
.ilf_fields
!= 0)))) {
1347 IPOINTER_INSERT(ip
, mp
);
1350 if (flags
& SYNC_WAIT
) {
1352 error
= xfs_iflush(ip
,
1356 * If we can't acquire the flush
1357 * lock, then the inode is already
1358 * being flushed so don't bother
1359 * waiting. If we can lock it then
1360 * do a delwri flush so we can
1361 * combine multiple inode flushes
1362 * in each disk write.
1364 if (xfs_iflock_nowait(ip
)) {
1365 error
= xfs_iflush(ip
,
1374 if (lock_flags
!= 0) {
1375 xfs_iunlock(ip
, lock_flags
);
1380 * If we had to take a reference on the vnode
1381 * above, then wait until after we've unlocked
1382 * the inode to release the reference. This is
1383 * because we can be already holding the inode
1384 * lock when VN_RELE() calls xfs_inactive().
1386 * Make sure to drop the mount lock before calling
1387 * VN_RELE() so that we don't trip over ourselves if
1388 * we have to go for the mount lock again in the
1392 IPOINTER_INSERT(ip
, mp
);
1397 vnode_refed
= B_FALSE
;
1405 * bail out if the filesystem is corrupted.
1407 if (error
== EFSCORRUPTED
) {
1408 if (!mount_locked
) {
1409 XFS_MOUNT_ILOCK(mp
);
1410 IPOINTER_REMOVE(ip
, mp
);
1412 XFS_MOUNT_IUNLOCK(mp
);
1413 ASSERT(ipointer_in
== B_FALSE
);
1414 kmem_free(ipointer
, sizeof(xfs_iptr_t
));
1415 return XFS_ERROR(error
);
1418 /* Let other threads have a chance at the mount lock
1419 * if we have looped many times without dropping the
1422 if ((++preempt
& XFS_PREEMPT_MASK
) == 0) {
1424 IPOINTER_INSERT(ip
, mp
);
1428 if (mount_locked
== B_FALSE
) {
1429 XFS_MOUNT_ILOCK(mp
);
1430 mount_locked
= B_TRUE
;
1431 IPOINTER_REMOVE(ip
, mp
);
1435 ASSERT(ipointer_in
== B_FALSE
);
1438 } while (ip
!= mp
->m_inodes
);
1440 XFS_MOUNT_IUNLOCK(mp
);
1442 ASSERT(ipointer_in
== B_FALSE
);
1444 kmem_free(ipointer
, sizeof(xfs_iptr_t
));
1445 return XFS_ERROR(last_error
);
1449 * xfs sync routine for internal use
1451 * This routine supports all of the flags defined for the generic vfs_sync
1452 * interface as explained above under xfs_sync.
1463 uint log_flags
= XFS_LOG_FORCE
;
1465 xfs_buf_log_item_t
*bip
;
1468 * Sync out the log. This ensures that the log is periodically
1469 * flushed even if there is not enough activity to fill it up.
1471 if (flags
& SYNC_WAIT
)
1472 log_flags
|= XFS_LOG_SYNC
;
1474 xfs_log_force(mp
, (xfs_lsn_t
)0, log_flags
);
1476 if (flags
& (SYNC_ATTR
|SYNC_DELWRI
)) {
1477 if (flags
& SYNC_BDFLUSH
)
1478 xfs_finish_reclaim_all(mp
, 1);
1480 error
= xfs_sync_inodes(mp
, flags
, bypassed
);
1484 * Flushing out dirty data above probably generated more
1485 * log activity, so if this isn't vfs_sync() then flush
1488 if (flags
& SYNC_DELWRI
) {
1489 xfs_log_force(mp
, (xfs_lsn_t
)0, log_flags
);
1492 if (flags
& SYNC_FSDATA
) {
1494 * If this is vfs_sync() then only sync the superblock
1495 * if we can lock it without sleeping and it is not pinned.
1497 if (flags
& SYNC_BDFLUSH
) {
1498 bp
= xfs_getsb(mp
, XFS_BUF_TRYLOCK
);
1500 bip
= XFS_BUF_FSPRIVATE(bp
,xfs_buf_log_item_t
*);
1501 if ((bip
!= NULL
) &&
1502 xfs_buf_item_dirty(bip
)) {
1503 if (!(XFS_BUF_ISPINNED(bp
))) {
1505 error
= xfs_bwrite(mp
, bp
);
1514 bp
= xfs_getsb(mp
, 0);
1516 * If the buffer is pinned then push on the log so
1517 * we won't get stuck waiting in the write for
1518 * someone, maybe ourselves, to flush the log.
1519 * Even though we just pushed the log above, we
1520 * did not have the superblock buffer locked at
1521 * that point so it can become pinned in between
1524 if (XFS_BUF_ISPINNED(bp
))
1525 xfs_log_force(mp
, (xfs_lsn_t
)0, XFS_LOG_FORCE
);
1526 if (flags
& SYNC_WAIT
)
1527 XFS_BUF_UNASYNC(bp
);
1530 error
= xfs_bwrite(mp
, bp
);
1538 * If this is the periodic sync, then kick some entries out of
1539 * the reference cache. This ensures that idle entries are
1540 * eventually kicked out of the cache.
1542 if (flags
& SYNC_REFCACHE
) {
1543 if (flags
& SYNC_WAIT
)
1544 xfs_refcache_purge_mp(mp
);
1546 xfs_refcache_purge_some(mp
);
1550 * If asked, update the disk superblock with incore counter values if we
1551 * are using non-persistent counters so that they don't get too far out
1552 * of sync if we crash or get a forced shutdown. We don't want to force
1553 * this to disk, just get a transaction into the iclogs....
1555 if (flags
& SYNC_SUPER
)
1556 xfs_log_sbcount(mp
, 0);
1559 * Now check to see if the log needs a "dummy" transaction.
1562 if (!(flags
& SYNC_REMOUNT
) && xfs_log_need_covered(mp
)) {
1567 * Put a dummy transaction in the log to tell
1568 * recovery that all others are OK.
1570 tp
= xfs_trans_alloc(mp
, XFS_TRANS_DUMMY1
);
1571 if ((error
= xfs_trans_reserve(tp
, 0,
1572 XFS_ICHANGE_LOG_RES(mp
),
1574 xfs_trans_cancel(tp
, 0);
1579 xfs_ilock(ip
, XFS_ILOCK_EXCL
);
1581 xfs_trans_ijoin(tp
, ip
, XFS_ILOCK_EXCL
);
1582 xfs_trans_ihold(tp
, ip
);
1583 xfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
1584 error
= xfs_trans_commit(tp
, 0);
1585 xfs_iunlock(ip
, XFS_ILOCK_EXCL
);
1586 xfs_log_force(mp
, (xfs_lsn_t
)0, log_flags
);
1590 * When shutting down, we need to insure that the AIL is pushed
1591 * to disk or the filesystem can appear corrupt from the PROM.
1593 if ((flags
& (SYNC_CLOSE
|SYNC_WAIT
)) == (SYNC_CLOSE
|SYNC_WAIT
)) {
1594 XFS_bflush(mp
->m_ddev_targp
);
1595 if (mp
->m_rtdev_targp
) {
1596 XFS_bflush(mp
->m_rtdev_targp
);
1600 return XFS_ERROR(last_error
);
1604 * xfs_vget - called by DMAPI and NFSD to get vnode from file handle
1612 xfs_mount_t
*mp
= XFS_BHVTOM(bdp
);
1613 xfs_fid_t
*xfid
= (struct xfs_fid
*)fidp
;
1620 * Invalid. Since handles can be created in user space and passed in
1621 * via gethandle(), this is not cause for a panic.
1623 if (xfid
->xfs_fid_len
!= sizeof(*xfid
) - sizeof(xfid
->xfs_fid_len
))
1624 return XFS_ERROR(EINVAL
);
1626 ino
= xfid
->xfs_fid_ino
;
1627 igen
= xfid
->xfs_fid_gen
;
1630 * NFS can sometimes send requests for ino 0. Fail them gracefully.
1633 return XFS_ERROR(ESTALE
);
1635 error
= xfs_iget(mp
, NULL
, ino
, 0, XFS_ILOCK_SHARED
, &ip
, 0);
1643 return XFS_ERROR(EIO
);
1646 if (ip
->i_d
.di_mode
== 0 || ip
->i_d
.di_gen
!= igen
) {
1647 xfs_iput_new(ip
, XFS_ILOCK_SHARED
);
1649 return XFS_ERROR(ENOENT
);
1652 *vpp
= XFS_ITOV(ip
);
1653 xfs_iunlock(ip
, XFS_ILOCK_SHARED
);
1658 #define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
1659 #define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
1660 #define MNTOPT_LOGDEV "logdev" /* log device */
1661 #define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
1662 #define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
1663 #define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
1664 #define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
1665 #define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
1666 #define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
1667 #define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
1668 #define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
1669 #define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
1670 #define MNTOPT_MTPT "mtpt" /* filesystem mount point */
1671 #define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
1672 #define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
1673 #define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
1674 #define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
1675 #define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
1676 #define MNTOPT_IHASHSIZE "ihashsize" /* size of inode hash table */
1677 #define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
1678 #define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
1679 * unwritten extent conversion */
1680 #define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
1681 #define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
1682 #define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
1683 #define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
1684 #define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
1685 #define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
1686 #define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
1688 #define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
1689 #define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
1690 #define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
1692 STATIC
unsigned long
1693 suffix_strtoul(char *s
, char **endp
, unsigned int base
)
1695 int last
, shift_left_factor
= 0;
1698 last
= strlen(value
) - 1;
1699 if (value
[last
] == 'K' || value
[last
] == 'k') {
1700 shift_left_factor
= 10;
1703 if (value
[last
] == 'M' || value
[last
] == 'm') {
1704 shift_left_factor
= 20;
1707 if (value
[last
] == 'G' || value
[last
] == 'g') {
1708 shift_left_factor
= 30;
1712 return simple_strtoul((const char *)s
, endp
, base
) << shift_left_factor
;
1717 struct bhv_desc
*bhv
,
1719 struct xfs_mount_args
*args
,
1722 bhv_vfs_t
*vfsp
= bhvtovfs(bhv
);
1723 char *this_char
, *value
, *eov
;
1724 int dsunit
, dswidth
, vol_dsunit
, vol_dswidth
;
1727 args
->flags
|= XFSMNT_IDELETE
;
1728 args
->flags
|= XFSMNT_BARRIER
;
1729 args
->flags2
|= XFSMNT2_COMPAT_IOSIZE
;
1734 iosize
= dsunit
= dswidth
= vol_dsunit
= vol_dswidth
= 0;
1736 while ((this_char
= strsep(&options
, ",")) != NULL
) {
1739 if ((value
= strchr(this_char
, '=')) != NULL
)
1742 if (!strcmp(this_char
, MNTOPT_LOGBUFS
)) {
1743 if (!value
|| !*value
) {
1745 "XFS: %s option requires an argument",
1749 args
->logbufs
= simple_strtoul(value
, &eov
, 10);
1750 } else if (!strcmp(this_char
, MNTOPT_LOGBSIZE
)) {
1751 if (!value
|| !*value
) {
1753 "XFS: %s option requires an argument",
1757 args
->logbufsize
= suffix_strtoul(value
, &eov
, 10);
1758 } else if (!strcmp(this_char
, MNTOPT_LOGDEV
)) {
1759 if (!value
|| !*value
) {
1761 "XFS: %s option requires an argument",
1765 strncpy(args
->logname
, value
, MAXNAMELEN
);
1766 } else if (!strcmp(this_char
, MNTOPT_MTPT
)) {
1767 if (!value
|| !*value
) {
1769 "XFS: %s option requires an argument",
1773 strncpy(args
->mtpt
, value
, MAXNAMELEN
);
1774 } else if (!strcmp(this_char
, MNTOPT_RTDEV
)) {
1775 if (!value
|| !*value
) {
1777 "XFS: %s option requires an argument",
1781 strncpy(args
->rtname
, value
, MAXNAMELEN
);
1782 } else if (!strcmp(this_char
, MNTOPT_BIOSIZE
)) {
1783 if (!value
|| !*value
) {
1785 "XFS: %s option requires an argument",
1789 iosize
= simple_strtoul(value
, &eov
, 10);
1790 args
->flags
|= XFSMNT_IOSIZE
;
1791 args
->iosizelog
= (uint8_t) iosize
;
1792 } else if (!strcmp(this_char
, MNTOPT_ALLOCSIZE
)) {
1793 if (!value
|| !*value
) {
1795 "XFS: %s option requires an argument",
1799 iosize
= suffix_strtoul(value
, &eov
, 10);
1800 args
->flags
|= XFSMNT_IOSIZE
;
1801 args
->iosizelog
= ffs(iosize
) - 1;
1802 } else if (!strcmp(this_char
, MNTOPT_IHASHSIZE
)) {
1803 if (!value
|| !*value
) {
1805 "XFS: %s option requires an argument",
1809 args
->flags
|= XFSMNT_IHASHSIZE
;
1810 args
->ihashsize
= simple_strtoul(value
, &eov
, 10);
1811 } else if (!strcmp(this_char
, MNTOPT_GRPID
) ||
1812 !strcmp(this_char
, MNTOPT_BSDGROUPS
)) {
1813 vfsp
->vfs_flag
|= VFS_GRPID
;
1814 } else if (!strcmp(this_char
, MNTOPT_NOGRPID
) ||
1815 !strcmp(this_char
, MNTOPT_SYSVGROUPS
)) {
1816 vfsp
->vfs_flag
&= ~VFS_GRPID
;
1817 } else if (!strcmp(this_char
, MNTOPT_WSYNC
)) {
1818 args
->flags
|= XFSMNT_WSYNC
;
1819 } else if (!strcmp(this_char
, MNTOPT_OSYNCISOSYNC
)) {
1820 args
->flags
|= XFSMNT_OSYNCISOSYNC
;
1821 } else if (!strcmp(this_char
, MNTOPT_NORECOVERY
)) {
1822 args
->flags
|= XFSMNT_NORECOVERY
;
1823 } else if (!strcmp(this_char
, MNTOPT_INO64
)) {
1824 args
->flags
|= XFSMNT_INO64
;
1827 "XFS: %s option not allowed on this system",
1831 } else if (!strcmp(this_char
, MNTOPT_NOALIGN
)) {
1832 args
->flags
|= XFSMNT_NOALIGN
;
1833 } else if (!strcmp(this_char
, MNTOPT_SWALLOC
)) {
1834 args
->flags
|= XFSMNT_SWALLOC
;
1835 } else if (!strcmp(this_char
, MNTOPT_SUNIT
)) {
1836 if (!value
|| !*value
) {
1838 "XFS: %s option requires an argument",
1842 dsunit
= simple_strtoul(value
, &eov
, 10);
1843 } else if (!strcmp(this_char
, MNTOPT_SWIDTH
)) {
1844 if (!value
|| !*value
) {
1846 "XFS: %s option requires an argument",
1850 dswidth
= simple_strtoul(value
, &eov
, 10);
1851 } else if (!strcmp(this_char
, MNTOPT_64BITINODE
)) {
1852 args
->flags
&= ~XFSMNT_32BITINODES
;
1855 "XFS: %s option not allowed on this system",
1859 } else if (!strcmp(this_char
, MNTOPT_NOUUID
)) {
1860 args
->flags
|= XFSMNT_NOUUID
;
1861 } else if (!strcmp(this_char
, MNTOPT_BARRIER
)) {
1862 args
->flags
|= XFSMNT_BARRIER
;
1863 } else if (!strcmp(this_char
, MNTOPT_NOBARRIER
)) {
1864 args
->flags
&= ~XFSMNT_BARRIER
;
1865 } else if (!strcmp(this_char
, MNTOPT_IKEEP
)) {
1866 args
->flags
&= ~XFSMNT_IDELETE
;
1867 } else if (!strcmp(this_char
, MNTOPT_NOIKEEP
)) {
1868 args
->flags
|= XFSMNT_IDELETE
;
1869 } else if (!strcmp(this_char
, MNTOPT_LARGEIO
)) {
1870 args
->flags2
&= ~XFSMNT2_COMPAT_IOSIZE
;
1871 } else if (!strcmp(this_char
, MNTOPT_NOLARGEIO
)) {
1872 args
->flags2
|= XFSMNT2_COMPAT_IOSIZE
;
1873 } else if (!strcmp(this_char
, MNTOPT_ATTR2
)) {
1874 args
->flags
|= XFSMNT_ATTR2
;
1875 } else if (!strcmp(this_char
, MNTOPT_NOATTR2
)) {
1876 args
->flags
&= ~XFSMNT_ATTR2
;
1877 } else if (!strcmp(this_char
, MNTOPT_FILESTREAM
)) {
1878 args
->flags2
|= XFSMNT2_FILESTREAMS
;
1879 } else if (!strcmp(this_char
, "osyncisdsync")) {
1880 /* no-op, this is now the default */
1882 "XFS: osyncisdsync is now the default, option is deprecated.");
1883 } else if (!strcmp(this_char
, "irixsgid")) {
1885 "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
1888 "XFS: unknown mount option [%s].", this_char
);
1893 if (args
->flags
& XFSMNT_NORECOVERY
) {
1894 if ((vfsp
->vfs_flag
& VFS_RDONLY
) == 0) {
1896 "XFS: no-recovery mounts must be read-only.");
1901 if ((args
->flags
& XFSMNT_NOALIGN
) && (dsunit
|| dswidth
)) {
1903 "XFS: sunit and swidth options incompatible with the noalign option");
1907 if ((dsunit
&& !dswidth
) || (!dsunit
&& dswidth
)) {
1909 "XFS: sunit and swidth must be specified together");
1913 if (dsunit
&& (dswidth
% dsunit
!= 0)) {
1915 "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
1920 if ((args
->flags
& XFSMNT_NOALIGN
) != XFSMNT_NOALIGN
) {
1922 args
->sunit
= dsunit
;
1923 args
->flags
|= XFSMNT_RETERR
;
1925 args
->sunit
= vol_dsunit
;
1927 dswidth
? (args
->swidth
= dswidth
) :
1928 (args
->swidth
= vol_dswidth
);
1930 args
->sunit
= args
->swidth
= 0;
1934 if (args
->flags
& XFSMNT_32BITINODES
)
1935 vfsp
->vfs_flag
|= VFS_32BITINODES
;
1937 args
->flags
|= XFSMNT_FLAGS2
;
1943 struct bhv_desc
*bhv
,
1946 static struct proc_xfs_info
{
1950 /* the few simple ones we can get from the mount struct */
1951 { XFS_MOUNT_WSYNC
, "," MNTOPT_WSYNC
},
1952 { XFS_MOUNT_INO64
, "," MNTOPT_INO64
},
1953 { XFS_MOUNT_NOALIGN
, "," MNTOPT_NOALIGN
},
1954 { XFS_MOUNT_SWALLOC
, "," MNTOPT_SWALLOC
},
1955 { XFS_MOUNT_NOUUID
, "," MNTOPT_NOUUID
},
1956 { XFS_MOUNT_NORECOVERY
, "," MNTOPT_NORECOVERY
},
1957 { XFS_MOUNT_OSYNCISOSYNC
, "," MNTOPT_OSYNCISOSYNC
},
1960 struct proc_xfs_info
*xfs_infop
;
1961 struct xfs_mount
*mp
= XFS_BHVTOM(bhv
);
1962 struct bhv_vfs
*vfsp
= XFS_MTOVFS(mp
);
1964 for (xfs_infop
= xfs_info
; xfs_infop
->flag
; xfs_infop
++) {
1965 if (mp
->m_flags
& xfs_infop
->flag
)
1966 seq_puts(m
, xfs_infop
->str
);
1969 if (mp
->m_flags
& XFS_MOUNT_IHASHSIZE
)
1970 seq_printf(m
, "," MNTOPT_IHASHSIZE
"=%d", (int)mp
->m_ihsize
);
1972 if (mp
->m_flags
& XFS_MOUNT_DFLT_IOSIZE
)
1973 seq_printf(m
, "," MNTOPT_ALLOCSIZE
"=%dk",
1974 (int)(1 << mp
->m_writeio_log
) >> 10);
1976 if (mp
->m_logbufs
> 0)
1977 seq_printf(m
, "," MNTOPT_LOGBUFS
"=%d", mp
->m_logbufs
);
1978 if (mp
->m_logbsize
> 0)
1979 seq_printf(m
, "," MNTOPT_LOGBSIZE
"=%dk", mp
->m_logbsize
>> 10);
1982 seq_printf(m
, "," MNTOPT_LOGDEV
"=%s", mp
->m_logname
);
1984 seq_printf(m
, "," MNTOPT_RTDEV
"=%s", mp
->m_rtname
);
1986 if (mp
->m_dalign
> 0)
1987 seq_printf(m
, "," MNTOPT_SUNIT
"=%d",
1988 (int)XFS_FSB_TO_BB(mp
, mp
->m_dalign
));
1989 if (mp
->m_swidth
> 0)
1990 seq_printf(m
, "," MNTOPT_SWIDTH
"=%d",
1991 (int)XFS_FSB_TO_BB(mp
, mp
->m_swidth
));
1993 if (!(mp
->m_flags
& XFS_MOUNT_IDELETE
))
1994 seq_printf(m
, "," MNTOPT_IKEEP
);
1995 if (!(mp
->m_flags
& XFS_MOUNT_COMPAT_IOSIZE
))
1996 seq_printf(m
, "," MNTOPT_LARGEIO
);
1998 if (!(vfsp
->vfs_flag
& VFS_32BITINODES
))
1999 seq_printf(m
, "," MNTOPT_64BITINODE
);
2000 if (vfsp
->vfs_flag
& VFS_GRPID
)
2001 seq_printf(m
, "," MNTOPT_GRPID
);
2007 * Second stage of a freeze. The data is already frozen so we only
2008 * need to take care of themetadata. Once that's done write a dummy
2009 * record to dirty the log in case of a crash while frozen.
2015 xfs_mount_t
*mp
= XFS_BHVTOM(bdp
);
2017 xfs_attr_quiesce(mp
);
2018 xfs_fs_log_dummy(mp
);
2022 bhv_vfsops_t xfs_vfsops
= {
2023 BHV_IDENTITY_INIT(VFS_BHV_XFS
,VFS_POSITION_XFS
),
2024 .vfs_parseargs
= xfs_parseargs
,
2025 .vfs_showargs
= xfs_showargs
,
2026 .vfs_mount
= xfs_mount
,
2027 .vfs_unmount
= xfs_unmount
,
2028 .vfs_mntupdate
= xfs_mntupdate
,
2029 .vfs_root
= xfs_root
,
2030 .vfs_statvfs
= xfs_statvfs
,
2031 .vfs_sync
= xfs_sync
,
2032 .vfs_vget
= xfs_vget
,
2033 .vfs_dmapiops
= (vfs_dmapiops_t
)fs_nosys
,
2034 .vfs_quotactl
= (vfs_quotactl_t
)fs_nosys
,
2035 .vfs_init_vnode
= xfs_initialize_vnode
,
2036 .vfs_force_shutdown
= xfs_do_force_shutdown
,
2037 .vfs_freeze
= xfs_freeze
,