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"
29 #include "xfs_dmapi.h"
30 #include "xfs_mount.h"
31 #include "xfs_da_btree.h"
32 #include "xfs_bmap_btree.h"
33 #include "xfs_ialloc_btree.h"
34 #include "xfs_alloc_btree.h"
35 #include "xfs_dir_sf.h"
36 #include "xfs_dir2_sf.h"
37 #include "xfs_attr_sf.h"
38 #include "xfs_dinode.h"
39 #include "xfs_inode.h"
40 #include "xfs_inode_item.h"
41 #include "xfs_btree.h"
42 #include "xfs_alloc.h"
43 #include "xfs_ialloc.h"
44 #include "xfs_quota.h"
45 #include "xfs_error.h"
48 #include "xfs_refcache.h"
49 #include "xfs_buf_item.h"
50 #include "xfs_log_priv.h"
51 #include "xfs_dir2_trace.h"
52 #include "xfs_extfree_item.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");
88 * The size of the zone allocated buf log item is the maximum
89 * size possible under XFS. This wastes a little bit of memory,
90 * but it is much faster.
93 kmem_zone_init((sizeof(xfs_buf_log_item_t
) +
94 (((XFS_MAX_BLOCKSIZE
/ XFS_BLI_CHUNK
) /
95 NBWORD
) * sizeof(int))),
98 kmem_zone_init((sizeof(xfs_efd_log_item_t
) +
99 ((XFS_EFD_MAX_FAST_EXTENTS
- 1) *
100 sizeof(xfs_extent_t
))),
103 kmem_zone_init((sizeof(xfs_efi_log_item_t
) +
104 ((XFS_EFI_MAX_FAST_EXTENTS
- 1) *
105 sizeof(xfs_extent_t
))),
109 * These zones warrant special memory allocator hints
112 kmem_zone_init_flags(sizeof(xfs_inode_t
), "xfs_inode",
113 KM_ZONE_HWALIGN
| KM_ZONE_RECLAIM
|
114 KM_ZONE_SPREAD
, NULL
);
116 kmem_zone_init_flags(sizeof(xfs_inode_log_item_t
), "xfs_ili",
117 KM_ZONE_SPREAD
, NULL
);
119 kmem_zone_init_flags(sizeof(xfs_chashlist_t
), "xfs_chashlist",
120 KM_ZONE_SPREAD
, NULL
);
123 * Allocate global trace buffers.
125 #ifdef XFS_ALLOC_TRACE
126 xfs_alloc_trace_buf
= ktrace_alloc(XFS_ALLOC_TRACE_SIZE
, KM_SLEEP
);
128 #ifdef XFS_BMAP_TRACE
129 xfs_bmap_trace_buf
= ktrace_alloc(XFS_BMAP_TRACE_SIZE
, KM_SLEEP
);
131 #ifdef XFS_BMBT_TRACE
132 xfs_bmbt_trace_buf
= ktrace_alloc(XFS_BMBT_TRACE_SIZE
, KM_SLEEP
);
135 xfs_dir_trace_buf
= ktrace_alloc(XFS_DIR_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_chashlist_zone
;
169 xfs_cleanup_procfs();
170 xfs_sysctl_unregister();
171 xfs_refcache_destroy();
172 xfs_acl_zone_destroy(xfs_acl_zone
);
174 #ifdef XFS_DIR2_TRACE
175 ktrace_free(xfs_dir2_trace_buf
);
177 #ifdef XFS_ATTR_TRACE
178 ktrace_free(xfs_attr_trace_buf
);
181 ktrace_free(xfs_dir_trace_buf
);
183 #ifdef XFS_BMBT_TRACE
184 ktrace_free(xfs_bmbt_trace_buf
);
186 #ifdef XFS_BMAP_TRACE
187 ktrace_free(xfs_bmap_trace_buf
);
189 #ifdef XFS_ALLOC_TRACE
190 ktrace_free(xfs_alloc_trace_buf
);
193 kmem_zone_destroy(xfs_bmap_free_item_zone
);
194 kmem_zone_destroy(xfs_btree_cur_zone
);
195 kmem_zone_destroy(xfs_inode_zone
);
196 kmem_zone_destroy(xfs_trans_zone
);
197 kmem_zone_destroy(xfs_da_state_zone
);
198 kmem_zone_destroy(xfs_dabuf_zone
);
199 kmem_zone_destroy(xfs_buf_item_zone
);
200 kmem_zone_destroy(xfs_efd_zone
);
201 kmem_zone_destroy(xfs_efi_zone
);
202 kmem_zone_destroy(xfs_ifork_zone
);
203 kmem_zone_destroy(xfs_ili_zone
);
204 kmem_zone_destroy(xfs_chashlist_zone
);
210 * This function fills in xfs_mount_t fields based on mount args.
211 * Note: the superblock has _not_ yet been read in.
216 struct xfs_mount_args
*ap
,
217 struct xfs_mount
*mp
)
219 /* Values are in BBs */
220 if ((ap
->flags
& XFSMNT_NOALIGN
) != XFSMNT_NOALIGN
) {
222 * At this point the superblock has not been read
223 * in, therefore we do not know the block size.
224 * Before the mount call ends we will convert
227 mp
->m_dalign
= ap
->sunit
;
228 mp
->m_swidth
= ap
->swidth
;
231 if (ap
->logbufs
!= -1 &&
233 (ap
->logbufs
< XLOG_MIN_ICLOGS
||
234 ap
->logbufs
> XLOG_MAX_ICLOGS
)) {
236 "XFS: invalid logbufs value: %d [not %d-%d]",
237 ap
->logbufs
, XLOG_MIN_ICLOGS
, XLOG_MAX_ICLOGS
);
238 return XFS_ERROR(EINVAL
);
240 mp
->m_logbufs
= ap
->logbufs
;
241 if (ap
->logbufsize
!= -1 &&
242 ap
->logbufsize
!= 0 &&
243 ap
->logbufsize
!= 16 * 1024 &&
244 ap
->logbufsize
!= 32 * 1024 &&
245 ap
->logbufsize
!= 64 * 1024 &&
246 ap
->logbufsize
!= 128 * 1024 &&
247 ap
->logbufsize
!= 256 * 1024) {
249 "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
251 return XFS_ERROR(EINVAL
);
253 mp
->m_ihsize
= ap
->ihashsize
;
254 mp
->m_logbsize
= ap
->logbufsize
;
255 mp
->m_fsname_len
= strlen(ap
->fsname
) + 1;
256 mp
->m_fsname
= kmem_alloc(mp
->m_fsname_len
, KM_SLEEP
);
257 strcpy(mp
->m_fsname
, ap
->fsname
);
259 mp
->m_rtname
= kmem_alloc(strlen(ap
->rtname
) + 1, KM_SLEEP
);
260 strcpy(mp
->m_rtname
, ap
->rtname
);
262 if (ap
->logname
[0]) {
263 mp
->m_logname
= kmem_alloc(strlen(ap
->logname
) + 1, KM_SLEEP
);
264 strcpy(mp
->m_logname
, ap
->logname
);
267 if (ap
->flags
& XFSMNT_WSYNC
)
268 mp
->m_flags
|= XFS_MOUNT_WSYNC
;
270 if (ap
->flags
& XFSMNT_INO64
) {
271 mp
->m_flags
|= XFS_MOUNT_INO64
;
272 mp
->m_inoadd
= XFS_INO64_OFFSET
;
275 if (ap
->flags
& XFSMNT_RETERR
)
276 mp
->m_flags
|= XFS_MOUNT_RETERR
;
277 if (ap
->flags
& XFSMNT_NOALIGN
)
278 mp
->m_flags
|= XFS_MOUNT_NOALIGN
;
279 if (ap
->flags
& XFSMNT_SWALLOC
)
280 mp
->m_flags
|= XFS_MOUNT_SWALLOC
;
281 if (ap
->flags
& XFSMNT_OSYNCISOSYNC
)
282 mp
->m_flags
|= XFS_MOUNT_OSYNCISOSYNC
;
283 if (ap
->flags
& XFSMNT_32BITINODES
)
284 mp
->m_flags
|= XFS_MOUNT_32BITINODES
;
286 if (ap
->flags
& XFSMNT_IOSIZE
) {
287 if (ap
->iosizelog
> XFS_MAX_IO_LOG
||
288 ap
->iosizelog
< XFS_MIN_IO_LOG
) {
290 "XFS: invalid log iosize: %d [not %d-%d]",
291 ap
->iosizelog
, XFS_MIN_IO_LOG
,
293 return XFS_ERROR(EINVAL
);
296 mp
->m_flags
|= XFS_MOUNT_DFLT_IOSIZE
;
297 mp
->m_readio_log
= mp
->m_writeio_log
= ap
->iosizelog
;
300 if (ap
->flags
& XFSMNT_IHASHSIZE
)
301 mp
->m_flags
|= XFS_MOUNT_IHASHSIZE
;
302 if (ap
->flags
& XFSMNT_IDELETE
)
303 mp
->m_flags
|= XFS_MOUNT_IDELETE
;
304 if (ap
->flags
& XFSMNT_DIRSYNC
)
305 mp
->m_flags
|= XFS_MOUNT_DIRSYNC
;
306 if (ap
->flags
& XFSMNT_ATTR2
)
307 mp
->m_flags
|= XFS_MOUNT_ATTR2
;
309 if (ap
->flags2
& XFSMNT2_COMPAT_IOSIZE
)
310 mp
->m_flags
|= XFS_MOUNT_COMPAT_IOSIZE
;
313 * no recovery flag requires a read-only mount
315 if (ap
->flags
& XFSMNT_NORECOVERY
) {
316 if (!(vfs
->vfs_flag
& VFS_RDONLY
)) {
318 "XFS: tried to mount a FS read-write without recovery!");
319 return XFS_ERROR(EINVAL
);
321 mp
->m_flags
|= XFS_MOUNT_NORECOVERY
;
324 if (ap
->flags
& XFSMNT_NOUUID
)
325 mp
->m_flags
|= XFS_MOUNT_NOUUID
;
326 if (ap
->flags
& XFSMNT_BARRIER
)
327 mp
->m_flags
|= XFS_MOUNT_BARRIER
;
329 mp
->m_flags
&= ~XFS_MOUNT_BARRIER
;
335 * This function fills in xfs_mount_t fields based on mount args.
336 * Note: the superblock _has_ now been read in.
341 struct xfs_mount_args
*ap
,
342 struct xfs_mount
*mp
)
344 int ronly
= (vfs
->vfs_flag
& VFS_RDONLY
);
346 /* Fail a mount where the logbuf is smaller then the log stripe */
347 if (XFS_SB_VERSION_HASLOGV2(&mp
->m_sb
)) {
348 if ((ap
->logbufsize
<= 0) &&
349 (mp
->m_sb
.sb_logsunit
> XLOG_BIG_RECORD_BSIZE
)) {
350 mp
->m_logbsize
= mp
->m_sb
.sb_logsunit
;
351 } else if (ap
->logbufsize
> 0 &&
352 ap
->logbufsize
< mp
->m_sb
.sb_logsunit
) {
354 "XFS: logbuf size must be greater than or equal to log stripe size");
355 return XFS_ERROR(EINVAL
);
358 /* Fail a mount if the logbuf is larger than 32K */
359 if (ap
->logbufsize
> XLOG_BIG_RECORD_BSIZE
) {
361 "XFS: logbuf size for version 1 logs must be 16K or 32K");
362 return XFS_ERROR(EINVAL
);
366 if (XFS_SB_VERSION_HASATTR2(&mp
->m_sb
)) {
367 mp
->m_flags
|= XFS_MOUNT_ATTR2
;
371 * prohibit r/w mounts of read-only filesystems
373 if ((mp
->m_sb
.sb_flags
& XFS_SBF_READONLY
) && !ronly
) {
375 "XFS: cannot mount a read-only filesystem as read-write");
376 return XFS_ERROR(EROFS
);
380 * check for shared mount.
382 if (ap
->flags
& XFSMNT_SHARED
) {
383 if (!XFS_SB_VERSION_HASSHARED(&mp
->m_sb
))
384 return XFS_ERROR(EINVAL
);
387 * For IRIX 6.5, shared mounts must have the shared
388 * version bit set, have the persistent readonly
389 * field set, must be version 0 and can only be mounted
392 if (!ronly
|| !(mp
->m_sb
.sb_flags
& XFS_SBF_READONLY
) ||
393 (mp
->m_sb
.sb_shared_vn
!= 0))
394 return XFS_ERROR(EINVAL
);
396 mp
->m_flags
|= XFS_MOUNT_SHARED
;
399 * Shared XFS V0 can't deal with DMI. Return EINVAL.
401 if (mp
->m_sb
.sb_shared_vn
== 0 && (ap
->flags
& XFSMNT_DMAPI
))
402 return XFS_ERROR(EINVAL
);
411 * The file system configurations are:
412 * (1) device (partition) with data and internal log
413 * (2) logical volume with data and log subvolumes.
414 * (3) logical volume with data, log, and realtime subvolumes.
416 * We only have to handle opening the log and realtime volumes here if
417 * they are present. The data subvolume has already been opened by
418 * get_sb_bdev() and is stored in vfsp->vfs_super->s_bdev.
422 struct bhv_desc
*bhvp
,
423 struct xfs_mount_args
*args
,
426 struct vfs
*vfsp
= bhvtovfs(bhvp
);
428 struct xfs_mount
*mp
= XFS_BHVTOM(bhvp
);
429 struct block_device
*ddev
, *logdev
, *rtdev
;
430 int flags
= 0, error
;
432 ddev
= vfsp
->vfs_super
->s_bdev
;
433 logdev
= rtdev
= NULL
;
436 * Setup xfs_mount function vectors from available behaviors
438 p
= vfs_bhv_lookup(vfsp
, VFS_POSITION_DM
);
439 mp
->m_dm_ops
= p
? *(xfs_dmops_t
*) vfs_bhv_custom(p
) : xfs_dmcore_stub
;
440 p
= vfs_bhv_lookup(vfsp
, VFS_POSITION_QM
);
441 mp
->m_qm_ops
= p
? *(xfs_qmops_t
*) vfs_bhv_custom(p
) : xfs_qmcore_stub
;
442 p
= vfs_bhv_lookup(vfsp
, VFS_POSITION_IO
);
443 mp
->m_io_ops
= p
? *(xfs_ioops_t
*) vfs_bhv_custom(p
) : xfs_iocore_xfs
;
445 if (args
->flags
& XFSMNT_QUIET
)
446 flags
|= XFS_MFSI_QUIET
;
449 * Open real time and log devices - order is important.
451 if (args
->logname
[0]) {
452 error
= xfs_blkdev_get(mp
, args
->logname
, &logdev
);
456 if (args
->rtname
[0]) {
457 error
= xfs_blkdev_get(mp
, args
->rtname
, &rtdev
);
459 xfs_blkdev_put(logdev
);
463 if (rtdev
== ddev
|| rtdev
== logdev
) {
465 "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
466 xfs_blkdev_put(logdev
);
467 xfs_blkdev_put(rtdev
);
473 * Setup xfs_mount buffer target pointers
476 mp
->m_ddev_targp
= xfs_alloc_buftarg(ddev
, 0);
477 if (!mp
->m_ddev_targp
) {
478 xfs_blkdev_put(logdev
);
479 xfs_blkdev_put(rtdev
);
483 mp
->m_rtdev_targp
= xfs_alloc_buftarg(rtdev
, 1);
484 if (!mp
->m_rtdev_targp
)
487 mp
->m_logdev_targp
= (logdev
&& logdev
!= ddev
) ?
488 xfs_alloc_buftarg(logdev
, 1) : mp
->m_ddev_targp
;
489 if (!mp
->m_logdev_targp
)
493 * Setup flags based on mount(2) options and then the superblock
495 error
= xfs_start_flags(vfsp
, args
, mp
);
498 error
= xfs_readsb(mp
, flags
);
501 error
= xfs_finish_flags(vfsp
, args
, mp
);
506 * Setup xfs_mount buffer target pointers based on superblock
508 error
= xfs_setsize_buftarg(mp
->m_ddev_targp
, mp
->m_sb
.sb_blocksize
,
509 mp
->m_sb
.sb_sectsize
);
510 if (!error
&& logdev
&& logdev
!= ddev
) {
511 unsigned int log_sector_size
= BBSIZE
;
513 if (XFS_SB_VERSION_HASSECTOR(&mp
->m_sb
))
514 log_sector_size
= mp
->m_sb
.sb_logsectsize
;
515 error
= xfs_setsize_buftarg(mp
->m_logdev_targp
,
516 mp
->m_sb
.sb_blocksize
,
520 error
= xfs_setsize_buftarg(mp
->m_rtdev_targp
,
521 mp
->m_sb
.sb_blocksize
,
522 mp
->m_sb
.sb_sectsize
);
526 if ((mp
->m_flags
& XFS_MOUNT_BARRIER
) && !(vfsp
->vfs_flag
& VFS_RDONLY
))
527 xfs_mountfs_check_barriers(mp
);
529 error
= XFS_IOINIT(vfsp
, args
, flags
);
539 xfs_binval(mp
->m_ddev_targp
);
540 if (logdev
&& logdev
!= ddev
)
541 xfs_binval(mp
->m_logdev_targp
);
543 xfs_binval(mp
->m_rtdev_targp
);
545 xfs_unmountfs_close(mp
, credp
);
555 struct vfs
*vfsp
= bhvtovfs(bdp
);
556 xfs_mount_t
*mp
= XFS_BHVTOM(bdp
);
559 int unmount_event_wanted
= 0;
560 int unmount_event_flags
= 0;
561 int xfs_unmountfs_needed
= 0;
567 if (vfsp
->vfs_flag
& VFS_DMI
) {
568 error
= XFS_SEND_PREUNMOUNT(mp
, vfsp
,
569 rvp
, DM_RIGHT_NULL
, rvp
, DM_RIGHT_NULL
,
571 (mp
->m_dmevmask
& (1<<DM_EVENT_PREUNMOUNT
))?
572 0:DM_FLAGS_UNWANTED
);
574 return XFS_ERROR(error
);
575 unmount_event_wanted
= 1;
576 unmount_event_flags
= (mp
->m_dmevmask
& (1<<DM_EVENT_UNMOUNT
))?
577 0 : DM_FLAGS_UNWANTED
;
581 * First blow any referenced inode from this file system
582 * out of the reference cache, and delete the timer.
584 xfs_refcache_purge_mp(mp
);
586 XFS_bflush(mp
->m_ddev_targp
);
587 error
= xfs_unmount_flush(mp
, 0);
591 ASSERT(vn_count(rvp
) == 1);
594 * Drop the reference count
599 * If we're forcing a shutdown, typically because of a media error,
600 * we want to make sure we invalidate dirty pages that belong to
601 * referenced vnodes as well.
603 if (XFS_FORCED_SHUTDOWN(mp
)) {
604 error
= xfs_sync(&mp
->m_bhv
,
605 (SYNC_WAIT
| SYNC_CLOSE
), credp
);
606 ASSERT(error
!= EFSCORRUPTED
);
608 xfs_unmountfs_needed
= 1;
611 /* Send DMAPI event, if required.
612 * Then do xfs_unmountfs() if needed.
613 * Then return error (or zero).
615 if (unmount_event_wanted
) {
616 /* Note: mp structure must still exist for
617 * XFS_SEND_UNMOUNT() call.
619 XFS_SEND_UNMOUNT(mp
, vfsp
, error
== 0 ? rvp
: NULL
,
620 DM_RIGHT_NULL
, 0, error
, unmount_event_flags
);
622 if (xfs_unmountfs_needed
) {
624 * Call common unmount function to flush to disk
625 * and free the super block buffer & mount structures.
627 xfs_unmountfs(mp
, credp
);
630 return XFS_ERROR(error
);
637 int count
= 0, pincount
;
639 xfs_refcache_purge_mp(mp
);
640 xfs_flush_buftarg(mp
->m_ddev_targp
, 0);
641 xfs_finish_reclaim_all(mp
, 0);
643 /* This loop must run at least twice.
644 * The first instance of the loop will flush
645 * most meta data but that will generate more
646 * meta data (typically directory updates).
647 * Which then must be flushed and logged before
648 * we can write the unmount record.
651 xfs_syncsub(mp
, SYNC_REMOUNT
|SYNC_ATTR
|SYNC_WAIT
, 0, NULL
);
652 pincount
= xfs_flush_buftarg(mp
->m_ddev_targp
, 1);
666 struct xfs_mount_args
*args
)
668 struct vfs
*vfsp
= bhvtovfs(bdp
);
669 xfs_mount_t
*mp
= XFS_BHVTOM(bdp
);
672 if (!(*flags
& MS_RDONLY
)) { /* rw/ro -> rw */
673 if (vfsp
->vfs_flag
& VFS_RDONLY
)
674 vfsp
->vfs_flag
&= ~VFS_RDONLY
;
675 if (args
->flags
& XFSMNT_BARRIER
) {
676 mp
->m_flags
|= XFS_MOUNT_BARRIER
;
677 xfs_mountfs_check_barriers(mp
);
679 mp
->m_flags
&= ~XFS_MOUNT_BARRIER
;
681 } else if (!(vfsp
->vfs_flag
& VFS_RDONLY
)) { /* rw -> ro */
682 VFS_SYNC(vfsp
, SYNC_FSDATA
|SYNC_BDFLUSH
|SYNC_ATTR
, NULL
, error
);
684 xfs_log_unmount_write(mp
);
685 xfs_unmountfs_writesb(mp
);
686 vfsp
->vfs_flag
|= VFS_RDONLY
;
692 * xfs_unmount_flush implements a set of flush operation on special
693 * inodes, which are needed as a separate set of operations so that
694 * they can be called as part of relocation process.
698 xfs_mount_t
*mp
, /* Mount structure we are getting
700 int relocation
) /* Called from vfs relocation. */
702 xfs_inode_t
*rip
= mp
->m_rootip
;
704 xfs_inode_t
*rsumip
= NULL
;
705 vnode_t
*rvp
= XFS_ITOV(rip
);
708 xfs_ilock(rip
, XFS_ILOCK_EXCL
);
712 * Flush out the real time inodes.
714 if ((rbmip
= mp
->m_rbmip
) != NULL
) {
715 xfs_ilock(rbmip
, XFS_ILOCK_EXCL
);
717 error
= xfs_iflush(rbmip
, XFS_IFLUSH_SYNC
);
718 xfs_iunlock(rbmip
, XFS_ILOCK_EXCL
);
720 if (error
== EFSCORRUPTED
)
723 ASSERT(vn_count(XFS_ITOV(rbmip
)) == 1);
725 rsumip
= mp
->m_rsumip
;
726 xfs_ilock(rsumip
, XFS_ILOCK_EXCL
);
728 error
= xfs_iflush(rsumip
, XFS_IFLUSH_SYNC
);
729 xfs_iunlock(rsumip
, XFS_ILOCK_EXCL
);
731 if (error
== EFSCORRUPTED
)
734 ASSERT(vn_count(XFS_ITOV(rsumip
)) == 1);
738 * Synchronously flush root inode to disk
740 error
= xfs_iflush(rip
, XFS_IFLUSH_SYNC
);
741 if (error
== EFSCORRUPTED
)
744 if (vn_count(rvp
) != 1 && !relocation
) {
745 xfs_iunlock(rip
, XFS_ILOCK_EXCL
);
746 return XFS_ERROR(EBUSY
);
750 * Release dquot that rootinode, rbmino and rsumino might be holding,
751 * flush and purge the quota inodes.
753 error
= XFS_QM_UNMOUNT(mp
);
754 if (error
== EFSCORRUPTED
)
758 VN_RELE(XFS_ITOV(rbmip
));
759 VN_RELE(XFS_ITOV(rsumip
));
762 xfs_iunlock(rip
, XFS_ILOCK_EXCL
);
769 xfs_iunlock(rip
, XFS_ILOCK_EXCL
);
771 return XFS_ERROR(EFSCORRUPTED
);
775 * xfs_root extracts the root vnode from a vfs.
777 * vfsp -- the vfs struct for the desired file system
778 * vpp -- address of the caller's vnode pointer which should be
779 * set to the desired fs root vnode
788 vp
= XFS_ITOV((XFS_BHVTOM(bdp
))->m_rootip
);
797 * Fill in the statvfs structure for the given file system. We use
798 * the superblock lock in the mount structure to ensure a consistent
799 * snapshot of the counters returned.
813 mp
= XFS_BHVTOM(bdp
);
816 statp
->f_type
= XFS_SB_MAGIC
;
818 xfs_icsb_sync_counters_lazy(mp
);
820 statp
->f_bsize
= sbp
->sb_blocksize
;
821 lsize
= sbp
->sb_logstart
? sbp
->sb_logblocks
: 0;
822 statp
->f_blocks
= sbp
->sb_dblocks
- lsize
;
823 statp
->f_bfree
= statp
->f_bavail
= sbp
->sb_fdblocks
;
824 fakeinos
= statp
->f_bfree
<< sbp
->sb_inopblog
;
826 fakeinos
+= mp
->m_inoadd
;
829 MIN(sbp
->sb_icount
+ fakeinos
, (__uint64_t
)XFS_MAXINUMBER
);
834 statp
->f_files
= min_t(typeof(statp
->f_files
),
837 statp
->f_ffree
= statp
->f_files
- (sbp
->sb_icount
- sbp
->sb_ifree
);
838 XFS_SB_UNLOCK(mp
, s
);
840 xfs_statvfs_fsid(statp
, mp
);
841 statp
->f_namelen
= MAXNAMELEN
- 1;
848 * xfs_sync flushes any pending I/O to file system vfsp.
850 * This routine is called by vfs_sync() to make sure that things make it
851 * out to disk eventually, on sync() system calls to flush out everything,
852 * and when the file system is unmounted. For the vfs_sync() case, all
853 * we really need to do is sync out the log to make all of our meta-data
854 * updates permanent (except for timestamps). For calls from pflushd(),
855 * dirty pages are kept moving by calling pdflush() on the inodes
856 * containing them. We also flush the inodes that we can lock without
857 * sleeping and the superblock if we can lock it without sleeping from
858 * vfs_sync() so that items at the tail of the log are always moving out.
861 * SYNC_BDFLUSH - We're being called from vfs_sync() so we don't want
862 * to sleep if we can help it. All we really need
863 * to do is ensure that the log is synced at least
864 * periodically. We also push the inodes and
865 * superblock if we can lock them without sleeping
866 * and they are not pinned.
867 * SYNC_ATTR - We need to flush the inodes. If SYNC_BDFLUSH is not
868 * set, then we really want to lock each inode and flush
870 * SYNC_WAIT - All the flushes that take place in this call should
872 * SYNC_DELWRI - This tells us to push dirty pages associated with
873 * inodes. SYNC_WAIT and SYNC_BDFLUSH are used to
874 * determine if they should be flushed sync, async, or
876 * SYNC_CLOSE - This flag is passed when the system is being
877 * unmounted. We should sync and invalidate everything.
878 * SYNC_FSDATA - This indicates that the caller would like to make
879 * sure the superblock is safe on disk. We can ensure
880 * this by simply making sure the log gets flushed
881 * if SYNC_BDFLUSH is set, and by actually writing it
892 xfs_mount_t
*mp
= XFS_BHVTOM(bdp
);
894 if (unlikely(flags
== SYNC_QUIESCE
))
895 return xfs_quiesce_fs(mp
);
897 return xfs_syncsub(mp
, flags
, 0, NULL
);
901 * xfs sync routine for internal use
903 * This routine supports all of the flags defined for the generic VFS_SYNC
904 * interface as explained above under xfs_sync. In the interests of not
905 * changing interfaces within the 6.5 family, additional internally-
906 * required functions are specified within a separate xflags parameter,
907 * only available by calling this routine.
917 xfs_inode_t
*ip
= NULL
;
918 xfs_inode_t
*ip_next
;
925 uint base_lock_flags
;
926 boolean_t mount_locked
;
927 boolean_t vnode_refed
;
930 xfs_iptr_t
*ipointer
;
932 boolean_t ipointer_in
= B_FALSE
;
934 #define IPOINTER_SET ipointer_in = B_TRUE
935 #define IPOINTER_CLR ipointer_in = B_FALSE
942 /* Insert a marker record into the inode list after inode ip. The list
943 * must be locked when this is called. After the call the list will no
946 #define IPOINTER_INSERT(ip, mp) { \
947 ASSERT(ipointer_in == B_FALSE); \
948 ipointer->ip_mnext = ip->i_mnext; \
949 ipointer->ip_mprev = ip; \
950 ip->i_mnext = (xfs_inode_t *)ipointer; \
951 ipointer->ip_mnext->i_mprev = (xfs_inode_t *)ipointer; \
953 XFS_MOUNT_IUNLOCK(mp); \
954 mount_locked = B_FALSE; \
958 /* Remove the marker from the inode list. If the marker was the only item
959 * in the list then there are no remaining inodes and we should zero out
960 * the whole list. If we are the current head of the list then move the head
963 #define IPOINTER_REMOVE(ip, mp) { \
964 ASSERT(ipointer_in == B_TRUE); \
965 if (ipointer->ip_mnext != (xfs_inode_t *)ipointer) { \
966 ip = ipointer->ip_mnext; \
967 ip->i_mprev = ipointer->ip_mprev; \
968 ipointer->ip_mprev->i_mnext = ip; \
969 if (mp->m_inodes == (xfs_inode_t *)ipointer) { \
973 ASSERT(mp->m_inodes == (xfs_inode_t *)ipointer); \
974 mp->m_inodes = NULL; \
980 #define XFS_PREEMPT_MASK 0x7f
984 if (XFS_MTOVFS(mp
)->vfs_flag
& VFS_RDONLY
)
990 /* Allocate a reference marker */
991 ipointer
= (xfs_iptr_t
*)kmem_zalloc(sizeof(xfs_iptr_t
), KM_SLEEP
);
993 fflag
= XFS_B_ASYNC
; /* default is don't wait */
994 if (flags
& (SYNC_BDFLUSH
| SYNC_DELWRI
))
995 fflag
= XFS_B_DELWRI
;
996 if (flags
& SYNC_WAIT
)
997 fflag
= 0; /* synchronous overrides all */
999 base_lock_flags
= XFS_ILOCK_SHARED
;
1000 if (flags
& (SYNC_DELWRI
| SYNC_CLOSE
)) {
1002 * We need the I/O lock if we're going to call any of
1003 * the flush/inval routines.
1005 base_lock_flags
|= XFS_IOLOCK_SHARED
;
1008 XFS_MOUNT_ILOCK(mp
);
1012 mount_locked
= B_TRUE
;
1013 vnode_refed
= B_FALSE
;
1018 ASSERT(ipointer_in
== B_FALSE
);
1019 ASSERT(vnode_refed
== B_FALSE
);
1021 lock_flags
= base_lock_flags
;
1024 * There were no inodes in the list, just break out
1032 * We found another sync thread marker - skip it
1034 if (ip
->i_mount
== NULL
) {
1039 vp
= XFS_ITOV_NULL(ip
);
1042 * If the vnode is gone then this is being torn down,
1043 * call reclaim if it is flushed, else let regular flush
1044 * code deal with it later in the loop.
1048 /* Skip ones already in reclaim */
1049 if (ip
->i_flags
& XFS_IRECLAIM
) {
1053 if (xfs_ilock_nowait(ip
, XFS_ILOCK_EXCL
) == 0) {
1055 } else if ((xfs_ipincount(ip
) == 0) &&
1056 xfs_iflock_nowait(ip
)) {
1057 IPOINTER_INSERT(ip
, mp
);
1059 xfs_finish_reclaim(ip
, 1,
1060 XFS_IFLUSH_DELWRI_ELSE_ASYNC
);
1062 XFS_MOUNT_ILOCK(mp
);
1063 mount_locked
= B_TRUE
;
1064 IPOINTER_REMOVE(ip
, mp
);
1066 xfs_iunlock(ip
, XFS_ILOCK_EXCL
);
1077 if (XFS_FORCED_SHUTDOWN(mp
) && !(flags
& SYNC_CLOSE
)) {
1078 XFS_MOUNT_IUNLOCK(mp
);
1079 kmem_free(ipointer
, sizeof(xfs_iptr_t
));
1084 * If this is just vfs_sync() or pflushd() calling
1085 * then we can skip inodes for which it looks like
1086 * there is nothing to do. Since we don't have the
1087 * inode locked this is racy, but these are periodic
1088 * calls so it doesn't matter. For the others we want
1089 * to know for sure, so we at least try to lock them.
1091 if (flags
& SYNC_BDFLUSH
) {
1092 if (((ip
->i_itemp
== NULL
) ||
1093 !(ip
->i_itemp
->ili_format
.ilf_fields
&
1095 (ip
->i_update_core
== 0)) {
1102 * Try to lock without sleeping. We're out of order with
1103 * the inode list lock here, so if we fail we need to drop
1104 * the mount lock and try again. If we're called from
1105 * bdflush() here, then don't bother.
1107 * The inode lock here actually coordinates with the
1108 * almost spurious inode lock in xfs_ireclaim() to prevent
1109 * the vnode we handle here without a reference from
1110 * being freed while we reference it. If we lock the inode
1111 * while it's on the mount list here, then the spurious inode
1112 * lock in xfs_ireclaim() after the inode is pulled from
1113 * the mount list will sleep until we release it here.
1114 * This keeps the vnode from being freed while we reference
1117 if (xfs_ilock_nowait(ip
, lock_flags
) == 0) {
1118 if ((flags
& SYNC_BDFLUSH
) || (vp
== NULL
)) {
1129 IPOINTER_INSERT(ip
, mp
);
1130 xfs_ilock(ip
, lock_flags
);
1132 ASSERT(vp
== XFS_ITOV(ip
));
1133 ASSERT(ip
->i_mount
== mp
);
1135 vnode_refed
= B_TRUE
;
1138 /* From here on in the loop we may have a marker record
1139 * in the inode list.
1142 if ((flags
& SYNC_CLOSE
) && (vp
!= NULL
)) {
1144 * This is the shutdown case. We just need to
1145 * flush and invalidate all the pages associated
1146 * with the inode. Drop the inode lock since
1147 * we can't hold it across calls to the buffer
1150 * We don't set the VREMAPPING bit in the vnode
1151 * here, because we don't hold the vnode lock
1152 * exclusively. It doesn't really matter, though,
1153 * because we only come here when we're shutting
1156 xfs_iunlock(ip
, XFS_ILOCK_SHARED
);
1158 if (XFS_FORCED_SHUTDOWN(mp
)) {
1159 VOP_TOSS_PAGES(vp
, 0, -1, FI_REMAPF
);
1161 VOP_FLUSHINVAL_PAGES(vp
, 0, -1, FI_REMAPF
);
1164 xfs_ilock(ip
, XFS_ILOCK_SHARED
);
1166 } else if ((flags
& SYNC_DELWRI
) && (vp
!= NULL
)) {
1168 /* We need to have dropped the lock here,
1169 * so insert a marker if we have not already
1173 IPOINTER_INSERT(ip
, mp
);
1177 * Drop the inode lock since we can't hold it
1178 * across calls to the buffer cache.
1180 xfs_iunlock(ip
, XFS_ILOCK_SHARED
);
1181 VOP_FLUSH_PAGES(vp
, (xfs_off_t
)0, -1,
1182 fflag
, FI_NONE
, error
);
1183 xfs_ilock(ip
, XFS_ILOCK_SHARED
);
1188 if (flags
& SYNC_BDFLUSH
) {
1189 if ((flags
& SYNC_ATTR
) &&
1190 ((ip
->i_update_core
) ||
1191 ((ip
->i_itemp
!= NULL
) &&
1192 (ip
->i_itemp
->ili_format
.ilf_fields
!= 0)))) {
1194 /* Insert marker and drop lock if not already
1198 IPOINTER_INSERT(ip
, mp
);
1202 * We don't want the periodic flushing of the
1203 * inodes by vfs_sync() to interfere with
1204 * I/O to the file, especially read I/O
1205 * where it is only the access time stamp
1206 * that is being flushed out. To prevent
1207 * long periods where we have both inode
1208 * locks held shared here while reading the
1209 * inode's buffer in from disk, we drop the
1210 * inode lock while reading in the inode
1211 * buffer. We have to release the buffer
1212 * and reacquire the inode lock so that they
1213 * are acquired in the proper order (inode
1214 * locks first). The buffer will go at the
1215 * end of the lru chain, though, so we can
1216 * expect it to still be there when we go
1217 * for it again in xfs_iflush().
1219 if ((xfs_ipincount(ip
) == 0) &&
1220 xfs_iflock_nowait(ip
)) {
1223 xfs_iunlock(ip
, XFS_ILOCK_SHARED
);
1225 error
= xfs_itobp(mp
, NULL
, ip
,
1230 /* Bailing out, remove the
1231 * marker and free it.
1233 XFS_MOUNT_ILOCK(mp
);
1235 IPOINTER_REMOVE(ip
, mp
);
1237 XFS_MOUNT_IUNLOCK(mp
);
1239 ASSERT(!(lock_flags
&
1240 XFS_IOLOCK_SHARED
));
1243 sizeof(xfs_iptr_t
));
1248 * Since we dropped the inode lock,
1249 * the inode may have been reclaimed.
1250 * Therefore, we reacquire the mount
1251 * lock and check to see if we were the
1252 * inode reclaimed. If this happened
1253 * then the ipointer marker will no
1254 * longer point back at us. In this
1255 * case, move ip along to the inode
1256 * after the marker, remove the marker
1259 XFS_MOUNT_ILOCK(mp
);
1260 mount_locked
= B_TRUE
;
1262 if (ip
!= ipointer
->ip_mprev
) {
1263 IPOINTER_REMOVE(ip
, mp
);
1265 ASSERT(!vnode_refed
);
1266 ASSERT(!(lock_flags
&
1267 XFS_IOLOCK_SHARED
));
1271 ASSERT(ip
->i_mount
== mp
);
1273 if (xfs_ilock_nowait(ip
,
1274 XFS_ILOCK_SHARED
) == 0) {
1275 ASSERT(ip
->i_mount
== mp
);
1277 * We failed to reacquire
1278 * the inode lock without
1279 * sleeping, so just skip
1280 * the inode for now. We
1281 * clear the ILOCK bit from
1282 * the lock_flags so that we
1283 * won't try to drop a lock
1284 * we don't hold below.
1286 lock_flags
&= ~XFS_ILOCK_SHARED
;
1287 IPOINTER_REMOVE(ip_next
, mp
);
1288 } else if ((xfs_ipincount(ip
) == 0) &&
1289 xfs_iflock_nowait(ip
)) {
1290 ASSERT(ip
->i_mount
== mp
);
1292 * Since this is vfs_sync()
1293 * calling we only flush the
1294 * inode out if we can lock
1295 * it without sleeping and
1296 * it is not pinned. Drop
1297 * the mount lock here so
1298 * that we don't hold it for
1299 * too long. We already have
1300 * a marker in the list here.
1302 XFS_MOUNT_IUNLOCK(mp
);
1303 mount_locked
= B_FALSE
;
1304 error
= xfs_iflush(ip
,
1307 ASSERT(ip
->i_mount
== mp
);
1308 IPOINTER_REMOVE(ip_next
, mp
);
1315 if ((flags
& SYNC_ATTR
) &&
1316 ((ip
->i_update_core
) ||
1317 ((ip
->i_itemp
!= NULL
) &&
1318 (ip
->i_itemp
->ili_format
.ilf_fields
!= 0)))) {
1320 IPOINTER_INSERT(ip
, mp
);
1323 if (flags
& SYNC_WAIT
) {
1325 error
= xfs_iflush(ip
,
1329 * If we can't acquire the flush
1330 * lock, then the inode is already
1331 * being flushed so don't bother
1332 * waiting. If we can lock it then
1333 * do a delwri flush so we can
1334 * combine multiple inode flushes
1335 * in each disk write.
1337 if (xfs_iflock_nowait(ip
)) {
1338 error
= xfs_iflush(ip
,
1347 if (lock_flags
!= 0) {
1348 xfs_iunlock(ip
, lock_flags
);
1353 * If we had to take a reference on the vnode
1354 * above, then wait until after we've unlocked
1355 * the inode to release the reference. This is
1356 * because we can be already holding the inode
1357 * lock when VN_RELE() calls xfs_inactive().
1359 * Make sure to drop the mount lock before calling
1360 * VN_RELE() so that we don't trip over ourselves if
1361 * we have to go for the mount lock again in the
1365 IPOINTER_INSERT(ip
, mp
);
1370 vnode_refed
= B_FALSE
;
1378 * bail out if the filesystem is corrupted.
1380 if (error
== EFSCORRUPTED
) {
1381 if (!mount_locked
) {
1382 XFS_MOUNT_ILOCK(mp
);
1383 IPOINTER_REMOVE(ip
, mp
);
1385 XFS_MOUNT_IUNLOCK(mp
);
1386 ASSERT(ipointer_in
== B_FALSE
);
1387 kmem_free(ipointer
, sizeof(xfs_iptr_t
));
1388 return XFS_ERROR(error
);
1391 /* Let other threads have a chance at the mount lock
1392 * if we have looped many times without dropping the
1395 if ((++preempt
& XFS_PREEMPT_MASK
) == 0) {
1397 IPOINTER_INSERT(ip
, mp
);
1401 if (mount_locked
== B_FALSE
) {
1402 XFS_MOUNT_ILOCK(mp
);
1403 mount_locked
= B_TRUE
;
1404 IPOINTER_REMOVE(ip
, mp
);
1408 ASSERT(ipointer_in
== B_FALSE
);
1411 } while (ip
!= mp
->m_inodes
);
1413 XFS_MOUNT_IUNLOCK(mp
);
1415 ASSERT(ipointer_in
== B_FALSE
);
1417 kmem_free(ipointer
, sizeof(xfs_iptr_t
));
1418 return XFS_ERROR(last_error
);
1422 * xfs sync routine for internal use
1424 * This routine supports all of the flags defined for the generic VFS_SYNC
1425 * interface as explained above under xfs_sync. In the interests of not
1426 * changing interfaces within the 6.5 family, additional internally-
1427 * required functions are specified within a separate xflags parameter,
1428 * only available by calling this routine.
1440 uint log_flags
= XFS_LOG_FORCE
;
1442 xfs_buf_log_item_t
*bip
;
1445 * Sync out the log. This ensures that the log is periodically
1446 * flushed even if there is not enough activity to fill it up.
1448 if (flags
& SYNC_WAIT
)
1449 log_flags
|= XFS_LOG_SYNC
;
1451 xfs_log_force(mp
, (xfs_lsn_t
)0, log_flags
);
1453 if (flags
& (SYNC_ATTR
|SYNC_DELWRI
)) {
1454 if (flags
& SYNC_BDFLUSH
)
1455 xfs_finish_reclaim_all(mp
, 1);
1457 error
= xfs_sync_inodes(mp
, flags
, xflags
, bypassed
);
1461 * Flushing out dirty data above probably generated more
1462 * log activity, so if this isn't vfs_sync() then flush
1465 if (flags
& SYNC_DELWRI
) {
1466 xfs_log_force(mp
, (xfs_lsn_t
)0, log_flags
);
1469 if (flags
& SYNC_FSDATA
) {
1471 * If this is vfs_sync() then only sync the superblock
1472 * if we can lock it without sleeping and it is not pinned.
1474 if (flags
& SYNC_BDFLUSH
) {
1475 bp
= xfs_getsb(mp
, XFS_BUF_TRYLOCK
);
1477 bip
= XFS_BUF_FSPRIVATE(bp
,xfs_buf_log_item_t
*);
1478 if ((bip
!= NULL
) &&
1479 xfs_buf_item_dirty(bip
)) {
1480 if (!(XFS_BUF_ISPINNED(bp
))) {
1482 error
= xfs_bwrite(mp
, bp
);
1491 bp
= xfs_getsb(mp
, 0);
1493 * If the buffer is pinned then push on the log so
1494 * we won't get stuck waiting in the write for
1495 * someone, maybe ourselves, to flush the log.
1496 * Even though we just pushed the log above, we
1497 * did not have the superblock buffer locked at
1498 * that point so it can become pinned in between
1501 if (XFS_BUF_ISPINNED(bp
))
1502 xfs_log_force(mp
, (xfs_lsn_t
)0, XFS_LOG_FORCE
);
1503 if (flags
& SYNC_WAIT
)
1504 XFS_BUF_UNASYNC(bp
);
1507 error
= xfs_bwrite(mp
, bp
);
1515 * If this is the periodic sync, then kick some entries out of
1516 * the reference cache. This ensures that idle entries are
1517 * eventually kicked out of the cache.
1519 if (flags
& SYNC_REFCACHE
) {
1520 if (flags
& SYNC_WAIT
)
1521 xfs_refcache_purge_mp(mp
);
1523 xfs_refcache_purge_some(mp
);
1527 * Now check to see if the log needs a "dummy" transaction.
1530 if (!(flags
& SYNC_REMOUNT
) && xfs_log_need_covered(mp
)) {
1535 * Put a dummy transaction in the log to tell
1536 * recovery that all others are OK.
1538 tp
= xfs_trans_alloc(mp
, XFS_TRANS_DUMMY1
);
1539 if ((error
= xfs_trans_reserve(tp
, 0,
1540 XFS_ICHANGE_LOG_RES(mp
),
1542 xfs_trans_cancel(tp
, 0);
1547 xfs_ilock(ip
, XFS_ILOCK_EXCL
);
1549 xfs_trans_ijoin(tp
, ip
, XFS_ILOCK_EXCL
);
1550 xfs_trans_ihold(tp
, ip
);
1551 xfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
1552 error
= xfs_trans_commit(tp
, 0, NULL
);
1553 xfs_iunlock(ip
, XFS_ILOCK_EXCL
);
1554 xfs_log_force(mp
, (xfs_lsn_t
)0, log_flags
);
1558 * When shutting down, we need to insure that the AIL is pushed
1559 * to disk or the filesystem can appear corrupt from the PROM.
1561 if ((flags
& (SYNC_CLOSE
|SYNC_WAIT
)) == (SYNC_CLOSE
|SYNC_WAIT
)) {
1562 XFS_bflush(mp
->m_ddev_targp
);
1563 if (mp
->m_rtdev_targp
) {
1564 XFS_bflush(mp
->m_rtdev_targp
);
1568 return XFS_ERROR(last_error
);
1572 * xfs_vget - called by DMAPI and NFSD to get vnode from file handle
1580 xfs_mount_t
*mp
= XFS_BHVTOM(bdp
);
1581 xfs_fid_t
*xfid
= (struct xfs_fid
*)fidp
;
1588 * Invalid. Since handles can be created in user space and passed in
1589 * via gethandle(), this is not cause for a panic.
1591 if (xfid
->xfs_fid_len
!= sizeof(*xfid
) - sizeof(xfid
->xfs_fid_len
))
1592 return XFS_ERROR(EINVAL
);
1594 ino
= xfid
->xfs_fid_ino
;
1595 igen
= xfid
->xfs_fid_gen
;
1598 * NFS can sometimes send requests for ino 0. Fail them gracefully.
1601 return XFS_ERROR(ESTALE
);
1603 error
= xfs_iget(mp
, NULL
, ino
, 0, XFS_ILOCK_SHARED
, &ip
, 0);
1611 return XFS_ERROR(EIO
);
1614 if (ip
->i_d
.di_mode
== 0 || ip
->i_d
.di_gen
!= igen
) {
1615 xfs_iput_new(ip
, XFS_ILOCK_SHARED
);
1617 return XFS_ERROR(ENOENT
);
1620 *vpp
= XFS_ITOV(ip
);
1621 xfs_iunlock(ip
, XFS_ILOCK_SHARED
);
1626 #define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
1627 #define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
1628 #define MNTOPT_LOGDEV "logdev" /* log device */
1629 #define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
1630 #define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
1631 #define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
1632 #define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
1633 #define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
1634 #define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
1635 #define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
1636 #define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
1637 #define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
1638 #define MNTOPT_MTPT "mtpt" /* filesystem mount point */
1639 #define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
1640 #define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
1641 #define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
1642 #define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
1643 #define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
1644 #define MNTOPT_IHASHSIZE "ihashsize" /* size of inode hash table */
1645 #define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
1646 #define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
1647 * unwritten extent conversion */
1648 #define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
1649 #define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
1650 #define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
1651 #define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
1652 #define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
1653 #define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
1654 #define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
1656 #define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
1657 #define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
1659 STATIC
unsigned long
1660 suffix_strtoul(const char *cp
, char **endp
, unsigned int base
)
1662 int last
, shift_left_factor
= 0;
1663 char *value
= (char *)cp
;
1665 last
= strlen(value
) - 1;
1666 if (value
[last
] == 'K' || value
[last
] == 'k') {
1667 shift_left_factor
= 10;
1670 if (value
[last
] == 'M' || value
[last
] == 'm') {
1671 shift_left_factor
= 20;
1674 if (value
[last
] == 'G' || value
[last
] == 'g') {
1675 shift_left_factor
= 30;
1679 return simple_strtoul(cp
, endp
, base
) << shift_left_factor
;
1684 struct bhv_desc
*bhv
,
1686 struct xfs_mount_args
*args
,
1689 struct vfs
*vfsp
= bhvtovfs(bhv
);
1690 char *this_char
, *value
, *eov
;
1691 int dsunit
, dswidth
, vol_dsunit
, vol_dswidth
;
1694 args
->flags
|= XFSMNT_IDELETE
;
1695 args
->flags
|= XFSMNT_BARRIER
;
1696 args
->flags2
|= XFSMNT2_COMPAT_IOSIZE
;
1701 iosize
= dsunit
= dswidth
= vol_dsunit
= vol_dswidth
= 0;
1703 while ((this_char
= strsep(&options
, ",")) != NULL
) {
1706 if ((value
= strchr(this_char
, '=')) != NULL
)
1709 if (!strcmp(this_char
, MNTOPT_LOGBUFS
)) {
1710 if (!value
|| !*value
) {
1711 printk("XFS: %s option requires an argument\n",
1715 args
->logbufs
= simple_strtoul(value
, &eov
, 10);
1716 } else if (!strcmp(this_char
, MNTOPT_LOGBSIZE
)) {
1717 if (!value
|| !*value
) {
1718 printk("XFS: %s option requires an argument\n",
1722 args
->logbufsize
= suffix_strtoul(value
, &eov
, 10);
1723 } else if (!strcmp(this_char
, MNTOPT_LOGDEV
)) {
1724 if (!value
|| !*value
) {
1725 printk("XFS: %s option requires an argument\n",
1729 strncpy(args
->logname
, value
, MAXNAMELEN
);
1730 } else if (!strcmp(this_char
, MNTOPT_MTPT
)) {
1731 if (!value
|| !*value
) {
1732 printk("XFS: %s option requires an argument\n",
1736 strncpy(args
->mtpt
, value
, MAXNAMELEN
);
1737 } else if (!strcmp(this_char
, MNTOPT_RTDEV
)) {
1738 if (!value
|| !*value
) {
1739 printk("XFS: %s option requires an argument\n",
1743 strncpy(args
->rtname
, value
, MAXNAMELEN
);
1744 } else if (!strcmp(this_char
, MNTOPT_BIOSIZE
)) {
1745 if (!value
|| !*value
) {
1746 printk("XFS: %s option requires an argument\n",
1750 iosize
= simple_strtoul(value
, &eov
, 10);
1751 args
->flags
|= XFSMNT_IOSIZE
;
1752 args
->iosizelog
= (uint8_t) iosize
;
1753 } else if (!strcmp(this_char
, MNTOPT_ALLOCSIZE
)) {
1754 if (!value
|| !*value
) {
1755 printk("XFS: %s option requires an argument\n",
1759 iosize
= suffix_strtoul(value
, &eov
, 10);
1760 args
->flags
|= XFSMNT_IOSIZE
;
1761 args
->iosizelog
= ffs(iosize
) - 1;
1762 } else if (!strcmp(this_char
, MNTOPT_IHASHSIZE
)) {
1763 if (!value
|| !*value
) {
1764 printk("XFS: %s option requires an argument\n",
1768 args
->flags
|= XFSMNT_IHASHSIZE
;
1769 args
->ihashsize
= simple_strtoul(value
, &eov
, 10);
1770 } else if (!strcmp(this_char
, MNTOPT_GRPID
) ||
1771 !strcmp(this_char
, MNTOPT_BSDGROUPS
)) {
1772 vfsp
->vfs_flag
|= VFS_GRPID
;
1773 } else if (!strcmp(this_char
, MNTOPT_NOGRPID
) ||
1774 !strcmp(this_char
, MNTOPT_SYSVGROUPS
)) {
1775 vfsp
->vfs_flag
&= ~VFS_GRPID
;
1776 } else if (!strcmp(this_char
, MNTOPT_WSYNC
)) {
1777 args
->flags
|= XFSMNT_WSYNC
;
1778 } else if (!strcmp(this_char
, MNTOPT_OSYNCISOSYNC
)) {
1779 args
->flags
|= XFSMNT_OSYNCISOSYNC
;
1780 } else if (!strcmp(this_char
, MNTOPT_NORECOVERY
)) {
1781 args
->flags
|= XFSMNT_NORECOVERY
;
1782 } else if (!strcmp(this_char
, MNTOPT_INO64
)) {
1783 args
->flags
|= XFSMNT_INO64
;
1785 printk("XFS: %s option not allowed on this system\n",
1789 } else if (!strcmp(this_char
, MNTOPT_NOALIGN
)) {
1790 args
->flags
|= XFSMNT_NOALIGN
;
1791 } else if (!strcmp(this_char
, MNTOPT_SWALLOC
)) {
1792 args
->flags
|= XFSMNT_SWALLOC
;
1793 } else if (!strcmp(this_char
, MNTOPT_SUNIT
)) {
1794 if (!value
|| !*value
) {
1795 printk("XFS: %s option requires an argument\n",
1799 dsunit
= simple_strtoul(value
, &eov
, 10);
1800 } else if (!strcmp(this_char
, MNTOPT_SWIDTH
)) {
1801 if (!value
|| !*value
) {
1802 printk("XFS: %s option requires an argument\n",
1806 dswidth
= simple_strtoul(value
, &eov
, 10);
1807 } else if (!strcmp(this_char
, MNTOPT_64BITINODE
)) {
1808 args
->flags
&= ~XFSMNT_32BITINODES
;
1810 printk("XFS: %s option not allowed on this system\n",
1814 } else if (!strcmp(this_char
, MNTOPT_NOUUID
)) {
1815 args
->flags
|= XFSMNT_NOUUID
;
1816 } else if (!strcmp(this_char
, MNTOPT_BARRIER
)) {
1817 args
->flags
|= XFSMNT_BARRIER
;
1818 } else if (!strcmp(this_char
, MNTOPT_NOBARRIER
)) {
1819 args
->flags
&= ~XFSMNT_BARRIER
;
1820 } else if (!strcmp(this_char
, MNTOPT_IKEEP
)) {
1821 args
->flags
&= ~XFSMNT_IDELETE
;
1822 } else if (!strcmp(this_char
, MNTOPT_NOIKEEP
)) {
1823 args
->flags
|= XFSMNT_IDELETE
;
1824 } else if (!strcmp(this_char
, MNTOPT_LARGEIO
)) {
1825 args
->flags2
&= ~XFSMNT2_COMPAT_IOSIZE
;
1826 } else if (!strcmp(this_char
, MNTOPT_NOLARGEIO
)) {
1827 args
->flags2
|= XFSMNT2_COMPAT_IOSIZE
;
1828 } else if (!strcmp(this_char
, MNTOPT_ATTR2
)) {
1829 args
->flags
|= XFSMNT_ATTR2
;
1830 } else if (!strcmp(this_char
, MNTOPT_NOATTR2
)) {
1831 args
->flags
&= ~XFSMNT_ATTR2
;
1832 } else if (!strcmp(this_char
, "osyncisdsync")) {
1833 /* no-op, this is now the default */
1834 printk("XFS: osyncisdsync is now the default, option is deprecated.\n");
1835 } else if (!strcmp(this_char
, "irixsgid")) {
1836 printk("XFS: irixsgid is now a sysctl(2) variable, option is deprecated.\n");
1838 printk("XFS: unknown mount option [%s].\n", this_char
);
1843 if (args
->flags
& XFSMNT_NORECOVERY
) {
1844 if ((vfsp
->vfs_flag
& VFS_RDONLY
) == 0) {
1845 printk("XFS: no-recovery mounts must be read-only.\n");
1850 if ((args
->flags
& XFSMNT_NOALIGN
) && (dsunit
|| dswidth
)) {
1852 "XFS: sunit and swidth options incompatible with the noalign option\n");
1856 if ((dsunit
&& !dswidth
) || (!dsunit
&& dswidth
)) {
1857 printk("XFS: sunit and swidth must be specified together\n");
1861 if (dsunit
&& (dswidth
% dsunit
!= 0)) {
1863 "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)\n",
1868 if ((args
->flags
& XFSMNT_NOALIGN
) != XFSMNT_NOALIGN
) {
1870 args
->sunit
= dsunit
;
1871 args
->flags
|= XFSMNT_RETERR
;
1873 args
->sunit
= vol_dsunit
;
1875 dswidth
? (args
->swidth
= dswidth
) :
1876 (args
->swidth
= vol_dswidth
);
1878 args
->sunit
= args
->swidth
= 0;
1882 if (args
->flags
& XFSMNT_32BITINODES
)
1883 vfsp
->vfs_flag
|= VFS_32BITINODES
;
1885 args
->flags
|= XFSMNT_FLAGS2
;
1891 struct bhv_desc
*bhv
,
1894 static struct proc_xfs_info
{
1898 /* the few simple ones we can get from the mount struct */
1899 { XFS_MOUNT_WSYNC
, "," MNTOPT_WSYNC
},
1900 { XFS_MOUNT_INO64
, "," MNTOPT_INO64
},
1901 { XFS_MOUNT_NOALIGN
, "," MNTOPT_NOALIGN
},
1902 { XFS_MOUNT_SWALLOC
, "," MNTOPT_SWALLOC
},
1903 { XFS_MOUNT_NOUUID
, "," MNTOPT_NOUUID
},
1904 { XFS_MOUNT_NORECOVERY
, "," MNTOPT_NORECOVERY
},
1905 { XFS_MOUNT_OSYNCISOSYNC
, "," MNTOPT_OSYNCISOSYNC
},
1908 struct proc_xfs_info
*xfs_infop
;
1909 struct xfs_mount
*mp
= XFS_BHVTOM(bhv
);
1910 struct vfs
*vfsp
= XFS_MTOVFS(mp
);
1912 for (xfs_infop
= xfs_info
; xfs_infop
->flag
; xfs_infop
++) {
1913 if (mp
->m_flags
& xfs_infop
->flag
)
1914 seq_puts(m
, xfs_infop
->str
);
1917 if (mp
->m_flags
& XFS_MOUNT_IHASHSIZE
)
1918 seq_printf(m
, "," MNTOPT_IHASHSIZE
"=%d", mp
->m_ihsize
);
1920 if (mp
->m_flags
& XFS_MOUNT_DFLT_IOSIZE
)
1921 seq_printf(m
, "," MNTOPT_ALLOCSIZE
"=%dk",
1922 (int)(1 << mp
->m_writeio_log
) >> 10);
1924 if (mp
->m_logbufs
> 0)
1925 seq_printf(m
, "," MNTOPT_LOGBUFS
"=%d", mp
->m_logbufs
);
1926 if (mp
->m_logbsize
> 0)
1927 seq_printf(m
, "," MNTOPT_LOGBSIZE
"=%dk", mp
->m_logbsize
>> 10);
1930 seq_printf(m
, "," MNTOPT_LOGDEV
"=%s", mp
->m_logname
);
1932 seq_printf(m
, "," MNTOPT_RTDEV
"=%s", mp
->m_rtname
);
1934 if (mp
->m_dalign
> 0)
1935 seq_printf(m
, "," MNTOPT_SUNIT
"=%d",
1936 (int)XFS_FSB_TO_BB(mp
, mp
->m_dalign
));
1937 if (mp
->m_swidth
> 0)
1938 seq_printf(m
, "," MNTOPT_SWIDTH
"=%d",
1939 (int)XFS_FSB_TO_BB(mp
, mp
->m_swidth
));
1941 if (!(mp
->m_flags
& XFS_MOUNT_IDELETE
))
1942 seq_printf(m
, "," MNTOPT_IKEEP
);
1943 if (!(mp
->m_flags
& XFS_MOUNT_COMPAT_IOSIZE
))
1944 seq_printf(m
, "," MNTOPT_LARGEIO
);
1946 if (!(vfsp
->vfs_flag
& VFS_32BITINODES
))
1947 seq_printf(m
, "," MNTOPT_64BITINODE
);
1948 if (vfsp
->vfs_flag
& VFS_GRPID
)
1949 seq_printf(m
, "," MNTOPT_GRPID
);
1958 xfs_mount_t
*mp
= XFS_BHVTOM(bdp
);
1960 while (atomic_read(&mp
->m_active_trans
) > 0)
1963 /* Push the superblock and write an unmount record */
1964 xfs_log_unmount_write(mp
);
1965 xfs_unmountfs_writesb(mp
);
1966 xfs_fs_log_dummy(mp
);
1970 vfsops_t xfs_vfsops
= {
1971 BHV_IDENTITY_INIT(VFS_BHV_XFS
,VFS_POSITION_XFS
),
1972 .vfs_parseargs
= xfs_parseargs
,
1973 .vfs_showargs
= xfs_showargs
,
1974 .vfs_mount
= xfs_mount
,
1975 .vfs_unmount
= xfs_unmount
,
1976 .vfs_mntupdate
= xfs_mntupdate
,
1977 .vfs_root
= xfs_root
,
1978 .vfs_statvfs
= xfs_statvfs
,
1979 .vfs_sync
= xfs_sync
,
1980 .vfs_vget
= xfs_vget
,
1981 .vfs_dmapiops
= (vfs_dmapiops_t
)fs_nosys
,
1982 .vfs_quotactl
= (vfs_quotactl_t
)fs_nosys
,
1983 .vfs_init_vnode
= xfs_initialize_vnode
,
1984 .vfs_force_shutdown
= xfs_do_force_shutdown
,
1985 .vfs_freeze
= xfs_freeze
,