2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include "xfs_types.h"
24 #include "xfs_trans.h"
28 #include "xfs_dmapi.h"
29 #include "xfs_mount.h"
30 #include "xfs_da_btree.h"
31 #include "xfs_bmap_btree.h"
32 #include "xfs_ialloc_btree.h"
33 #include "xfs_alloc_btree.h"
34 #include "xfs_dir2_sf.h"
35 #include "xfs_attr_sf.h"
36 #include "xfs_dinode.h"
37 #include "xfs_inode.h"
38 #include "xfs_inode_item.h"
39 #include "xfs_btree.h"
40 #include "xfs_alloc.h"
41 #include "xfs_ialloc.h"
42 #include "xfs_quota.h"
43 #include "xfs_error.h"
46 #include "xfs_refcache.h"
47 #include "xfs_buf_item.h"
48 #include "xfs_log_priv.h"
49 #include "xfs_dir2_trace.h"
50 #include "xfs_extfree_item.h"
54 #include "xfs_mru_cache.h"
55 #include "xfs_filestream.h"
56 #include "xfs_fsops.h"
57 #include "xfs_vnodeops.h"
58 #include "xfs_vfsops.h"
64 extern kmem_zone_t
*xfs_bmap_free_item_zone
;
65 extern kmem_zone_t
*xfs_btree_cur_zone
;
66 extern kmem_zone_t
*xfs_trans_zone
;
67 extern kmem_zone_t
*xfs_buf_item_zone
;
68 extern kmem_zone_t
*xfs_dabuf_zone
;
69 #ifdef XFS_DABUF_DEBUG
70 extern lock_t xfs_dabuf_global_lock
;
71 spinlock_init(&xfs_dabuf_global_lock
, "xfsda");
75 * Initialize all of the zone allocators we use.
77 xfs_bmap_free_item_zone
= kmem_zone_init(sizeof(xfs_bmap_free_item_t
),
78 "xfs_bmap_free_item");
79 xfs_btree_cur_zone
= kmem_zone_init(sizeof(xfs_btree_cur_t
),
81 xfs_trans_zone
= kmem_zone_init(sizeof(xfs_trans_t
), "xfs_trans");
83 kmem_zone_init(sizeof(xfs_da_state_t
), "xfs_da_state");
84 xfs_dabuf_zone
= kmem_zone_init(sizeof(xfs_dabuf_t
), "xfs_dabuf");
85 xfs_ifork_zone
= kmem_zone_init(sizeof(xfs_ifork_t
), "xfs_ifork");
86 xfs_acl_zone_init(xfs_acl_zone
, "xfs_acl");
88 xfs_filestream_init();
91 * The size of the zone allocated buf log item is the maximum
92 * size possible under XFS. This wastes a little bit of memory,
93 * but it is much faster.
96 kmem_zone_init((sizeof(xfs_buf_log_item_t
) +
97 (((XFS_MAX_BLOCKSIZE
/ XFS_BLI_CHUNK
) /
98 NBWORD
) * sizeof(int))),
101 kmem_zone_init((sizeof(xfs_efd_log_item_t
) +
102 ((XFS_EFD_MAX_FAST_EXTENTS
- 1) *
103 sizeof(xfs_extent_t
))),
106 kmem_zone_init((sizeof(xfs_efi_log_item_t
) +
107 ((XFS_EFI_MAX_FAST_EXTENTS
- 1) *
108 sizeof(xfs_extent_t
))),
112 * These zones warrant special memory allocator hints
115 kmem_zone_init_flags(sizeof(xfs_inode_t
), "xfs_inode",
116 KM_ZONE_HWALIGN
| KM_ZONE_RECLAIM
|
117 KM_ZONE_SPREAD
, NULL
);
119 kmem_zone_init_flags(sizeof(xfs_inode_log_item_t
), "xfs_ili",
120 KM_ZONE_SPREAD
, NULL
);
122 kmem_zone_init_flags(sizeof(xfs_icluster_t
), "xfs_icluster",
123 KM_ZONE_SPREAD
, NULL
);
126 * Allocate global trace buffers.
128 #ifdef XFS_ALLOC_TRACE
129 xfs_alloc_trace_buf
= ktrace_alloc(XFS_ALLOC_TRACE_SIZE
, KM_SLEEP
);
131 #ifdef XFS_BMAP_TRACE
132 xfs_bmap_trace_buf
= ktrace_alloc(XFS_BMAP_TRACE_SIZE
, KM_SLEEP
);
134 #ifdef XFS_BMBT_TRACE
135 xfs_bmbt_trace_buf
= ktrace_alloc(XFS_BMBT_TRACE_SIZE
, KM_SLEEP
);
137 #ifdef XFS_ATTR_TRACE
138 xfs_attr_trace_buf
= ktrace_alloc(XFS_ATTR_TRACE_SIZE
, KM_SLEEP
);
140 #ifdef XFS_DIR2_TRACE
141 xfs_dir2_trace_buf
= ktrace_alloc(XFS_DIR2_GTRACE_SIZE
, KM_SLEEP
);
146 #if (defined(DEBUG) || defined(INDUCE_IO_ERROR))
147 xfs_error_test_init();
148 #endif /* DEBUG || INDUCE_IO_ERROR */
151 xfs_sysctl_register();
158 extern kmem_zone_t
*xfs_bmap_free_item_zone
;
159 extern kmem_zone_t
*xfs_btree_cur_zone
;
160 extern kmem_zone_t
*xfs_inode_zone
;
161 extern kmem_zone_t
*xfs_trans_zone
;
162 extern kmem_zone_t
*xfs_da_state_zone
;
163 extern kmem_zone_t
*xfs_dabuf_zone
;
164 extern kmem_zone_t
*xfs_efd_zone
;
165 extern kmem_zone_t
*xfs_efi_zone
;
166 extern kmem_zone_t
*xfs_buf_item_zone
;
167 extern kmem_zone_t
*xfs_icluster_zone
;
169 xfs_cleanup_procfs();
170 xfs_sysctl_unregister();
171 xfs_refcache_destroy();
172 xfs_filestream_uninit();
173 xfs_mru_cache_uninit();
174 xfs_acl_zone_destroy(xfs_acl_zone
);
176 #ifdef XFS_DIR2_TRACE
177 ktrace_free(xfs_dir2_trace_buf
);
179 #ifdef XFS_ATTR_TRACE
180 ktrace_free(xfs_attr_trace_buf
);
182 #ifdef XFS_BMBT_TRACE
183 ktrace_free(xfs_bmbt_trace_buf
);
185 #ifdef XFS_BMAP_TRACE
186 ktrace_free(xfs_bmap_trace_buf
);
188 #ifdef XFS_ALLOC_TRACE
189 ktrace_free(xfs_alloc_trace_buf
);
192 kmem_zone_destroy(xfs_bmap_free_item_zone
);
193 kmem_zone_destroy(xfs_btree_cur_zone
);
194 kmem_zone_destroy(xfs_inode_zone
);
195 kmem_zone_destroy(xfs_trans_zone
);
196 kmem_zone_destroy(xfs_da_state_zone
);
197 kmem_zone_destroy(xfs_dabuf_zone
);
198 kmem_zone_destroy(xfs_buf_item_zone
);
199 kmem_zone_destroy(xfs_efd_zone
);
200 kmem_zone_destroy(xfs_efi_zone
);
201 kmem_zone_destroy(xfs_ifork_zone
);
202 kmem_zone_destroy(xfs_ili_zone
);
203 kmem_zone_destroy(xfs_icluster_zone
);
209 * This function fills in xfs_mount_t fields based on mount args.
210 * Note: the superblock has _not_ yet been read in.
215 struct xfs_mount_args
*ap
,
216 struct xfs_mount
*mp
)
218 /* Values are in BBs */
219 if ((ap
->flags
& XFSMNT_NOALIGN
) != XFSMNT_NOALIGN
) {
221 * At this point the superblock has not been read
222 * in, therefore we do not know the block size.
223 * Before the mount call ends we will convert
226 mp
->m_dalign
= ap
->sunit
;
227 mp
->m_swidth
= ap
->swidth
;
230 if (ap
->logbufs
!= -1 &&
232 (ap
->logbufs
< XLOG_MIN_ICLOGS
||
233 ap
->logbufs
> XLOG_MAX_ICLOGS
)) {
235 "XFS: invalid logbufs value: %d [not %d-%d]",
236 ap
->logbufs
, XLOG_MIN_ICLOGS
, XLOG_MAX_ICLOGS
);
237 return XFS_ERROR(EINVAL
);
239 mp
->m_logbufs
= ap
->logbufs
;
240 if (ap
->logbufsize
!= -1 &&
241 ap
->logbufsize
!= 0 &&
242 (ap
->logbufsize
< XLOG_MIN_RECORD_BSIZE
||
243 ap
->logbufsize
> XLOG_MAX_RECORD_BSIZE
||
244 !is_power_of_2(ap
->logbufsize
))) {
246 "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
248 return XFS_ERROR(EINVAL
);
250 mp
->m_logbsize
= ap
->logbufsize
;
251 mp
->m_fsname_len
= strlen(ap
->fsname
) + 1;
252 mp
->m_fsname
= kmem_alloc(mp
->m_fsname_len
, KM_SLEEP
);
253 strcpy(mp
->m_fsname
, ap
->fsname
);
255 mp
->m_rtname
= kmem_alloc(strlen(ap
->rtname
) + 1, KM_SLEEP
);
256 strcpy(mp
->m_rtname
, ap
->rtname
);
258 if (ap
->logname
[0]) {
259 mp
->m_logname
= kmem_alloc(strlen(ap
->logname
) + 1, KM_SLEEP
);
260 strcpy(mp
->m_logname
, ap
->logname
);
263 if (ap
->flags
& XFSMNT_WSYNC
)
264 mp
->m_flags
|= XFS_MOUNT_WSYNC
;
266 if (ap
->flags
& XFSMNT_INO64
) {
267 mp
->m_flags
|= XFS_MOUNT_INO64
;
268 mp
->m_inoadd
= XFS_INO64_OFFSET
;
271 if (ap
->flags
& XFSMNT_RETERR
)
272 mp
->m_flags
|= XFS_MOUNT_RETERR
;
273 if (ap
->flags
& XFSMNT_NOALIGN
)
274 mp
->m_flags
|= XFS_MOUNT_NOALIGN
;
275 if (ap
->flags
& XFSMNT_SWALLOC
)
276 mp
->m_flags
|= XFS_MOUNT_SWALLOC
;
277 if (ap
->flags
& XFSMNT_OSYNCISOSYNC
)
278 mp
->m_flags
|= XFS_MOUNT_OSYNCISOSYNC
;
279 if (ap
->flags
& XFSMNT_32BITINODES
)
280 mp
->m_flags
|= XFS_MOUNT_32BITINODES
;
282 if (ap
->flags
& XFSMNT_IOSIZE
) {
283 if (ap
->iosizelog
> XFS_MAX_IO_LOG
||
284 ap
->iosizelog
< XFS_MIN_IO_LOG
) {
286 "XFS: invalid log iosize: %d [not %d-%d]",
287 ap
->iosizelog
, XFS_MIN_IO_LOG
,
289 return XFS_ERROR(EINVAL
);
292 mp
->m_flags
|= XFS_MOUNT_DFLT_IOSIZE
;
293 mp
->m_readio_log
= mp
->m_writeio_log
= ap
->iosizelog
;
296 if (ap
->flags
& XFSMNT_IDELETE
)
297 mp
->m_flags
|= XFS_MOUNT_IDELETE
;
298 if (ap
->flags
& XFSMNT_DIRSYNC
)
299 mp
->m_flags
|= XFS_MOUNT_DIRSYNC
;
300 if (ap
->flags
& XFSMNT_ATTR2
)
301 mp
->m_flags
|= XFS_MOUNT_ATTR2
;
303 if (ap
->flags2
& XFSMNT2_COMPAT_IOSIZE
)
304 mp
->m_flags
|= XFS_MOUNT_COMPAT_IOSIZE
;
307 * no recovery flag requires a read-only mount
309 if (ap
->flags
& XFSMNT_NORECOVERY
) {
310 if (!(mp
->m_flags
& XFS_MOUNT_RDONLY
)) {
312 "XFS: tried to mount a FS read-write without recovery!");
313 return XFS_ERROR(EINVAL
);
315 mp
->m_flags
|= XFS_MOUNT_NORECOVERY
;
318 if (ap
->flags
& XFSMNT_NOUUID
)
319 mp
->m_flags
|= XFS_MOUNT_NOUUID
;
320 if (ap
->flags
& XFSMNT_BARRIER
)
321 mp
->m_flags
|= XFS_MOUNT_BARRIER
;
323 mp
->m_flags
&= ~XFS_MOUNT_BARRIER
;
325 if (ap
->flags2
& XFSMNT2_FILESTREAMS
)
326 mp
->m_flags
|= XFS_MOUNT_FILESTREAMS
;
328 if (ap
->flags
& XFSMNT_DMAPI
)
329 mp
->m_flags
|= XFS_MOUNT_DMAPI
;
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
= (mp
->m_flags
& XFS_MOUNT_RDONLY
);
345 /* Fail a mount where the logbuf is smaller then the log stripe */
346 if (XFS_SB_VERSION_HASLOGV2(&mp
->m_sb
)) {
347 if ((ap
->logbufsize
<= 0) &&
348 (mp
->m_sb
.sb_logsunit
> XLOG_BIG_RECORD_BSIZE
)) {
349 mp
->m_logbsize
= mp
->m_sb
.sb_logsunit
;
350 } else if (ap
->logbufsize
> 0 &&
351 ap
->logbufsize
< mp
->m_sb
.sb_logsunit
) {
353 "XFS: logbuf size must be greater than or equal to log stripe size");
354 return XFS_ERROR(EINVAL
);
357 /* Fail a mount if the logbuf is larger than 32K */
358 if (ap
->logbufsize
> XLOG_BIG_RECORD_BSIZE
) {
360 "XFS: logbuf size for version 1 logs must be 16K or 32K");
361 return XFS_ERROR(EINVAL
);
365 if (XFS_SB_VERSION_HASATTR2(&mp
->m_sb
)) {
366 mp
->m_flags
|= XFS_MOUNT_ATTR2
;
370 * prohibit r/w mounts of read-only filesystems
372 if ((mp
->m_sb
.sb_flags
& XFS_SBF_READONLY
) && !ronly
) {
374 "XFS: cannot mount a read-only filesystem as read-write");
375 return XFS_ERROR(EROFS
);
379 * check for shared mount.
381 if (ap
->flags
& XFSMNT_SHARED
) {
382 if (!XFS_SB_VERSION_HASSHARED(&mp
->m_sb
))
383 return XFS_ERROR(EINVAL
);
386 * For IRIX 6.5, shared mounts must have the shared
387 * version bit set, have the persistent readonly
388 * field set, must be version 0 and can only be mounted
391 if (!ronly
|| !(mp
->m_sb
.sb_flags
& XFS_SBF_READONLY
) ||
392 (mp
->m_sb
.sb_shared_vn
!= 0))
393 return XFS_ERROR(EINVAL
);
395 mp
->m_flags
|= XFS_MOUNT_SHARED
;
398 * Shared XFS V0 can't deal with DMI. Return EINVAL.
400 if (mp
->m_sb
.sb_shared_vn
== 0 && (ap
->flags
& XFSMNT_DMAPI
))
401 return XFS_ERROR(EINVAL
);
404 if (ap
->flags
& XFSMNT_UQUOTA
) {
405 mp
->m_qflags
|= (XFS_UQUOTA_ACCT
| XFS_UQUOTA_ACTIVE
);
406 if (ap
->flags
& XFSMNT_UQUOTAENF
)
407 mp
->m_qflags
|= XFS_UQUOTA_ENFD
;
410 if (ap
->flags
& XFSMNT_GQUOTA
) {
411 mp
->m_qflags
|= (XFS_GQUOTA_ACCT
| XFS_GQUOTA_ACTIVE
);
412 if (ap
->flags
& XFSMNT_GQUOTAENF
)
413 mp
->m_qflags
|= XFS_OQUOTA_ENFD
;
414 } else if (ap
->flags
& XFSMNT_PQUOTA
) {
415 mp
->m_qflags
|= (XFS_PQUOTA_ACCT
| XFS_PQUOTA_ACTIVE
);
416 if (ap
->flags
& XFSMNT_PQUOTAENF
)
417 mp
->m_qflags
|= XFS_OQUOTA_ENFD
;
426 * The file system configurations are:
427 * (1) device (partition) with data and internal log
428 * (2) logical volume with data and log subvolumes.
429 * (3) logical volume with data, log, and realtime subvolumes.
431 * We only have to handle opening the log and realtime volumes here if
432 * they are present. The data subvolume has already been opened by
433 * get_sb_bdev() and is stored in vfsp->vfs_super->s_bdev.
437 struct xfs_mount
*mp
,
438 struct xfs_mount_args
*args
,
441 struct bhv_vfs
*vfsp
= XFS_MTOVFS(mp
);
442 struct block_device
*ddev
, *logdev
, *rtdev
;
443 int flags
= 0, error
;
445 ddev
= vfsp
->vfs_super
->s_bdev
;
446 logdev
= rtdev
= NULL
;
448 error
= xfs_dmops_get(mp
, args
);
451 error
= xfs_qmops_get(mp
, args
);
455 mp
->m_io_ops
= xfs_iocore_xfs
;
457 if (args
->flags
& XFSMNT_QUIET
)
458 flags
|= XFS_MFSI_QUIET
;
461 * Open real time and log devices - order is important.
463 if (args
->logname
[0]) {
464 error
= xfs_blkdev_get(mp
, args
->logname
, &logdev
);
468 if (args
->rtname
[0]) {
469 error
= xfs_blkdev_get(mp
, args
->rtname
, &rtdev
);
471 xfs_blkdev_put(logdev
);
475 if (rtdev
== ddev
|| rtdev
== logdev
) {
477 "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
478 xfs_blkdev_put(logdev
);
479 xfs_blkdev_put(rtdev
);
485 * Setup xfs_mount buffer target pointers
488 mp
->m_ddev_targp
= xfs_alloc_buftarg(ddev
, 0);
489 if (!mp
->m_ddev_targp
) {
490 xfs_blkdev_put(logdev
);
491 xfs_blkdev_put(rtdev
);
495 mp
->m_rtdev_targp
= xfs_alloc_buftarg(rtdev
, 1);
496 if (!mp
->m_rtdev_targp
) {
497 xfs_blkdev_put(logdev
);
498 xfs_blkdev_put(rtdev
);
502 mp
->m_logdev_targp
= (logdev
&& logdev
!= ddev
) ?
503 xfs_alloc_buftarg(logdev
, 1) : mp
->m_ddev_targp
;
504 if (!mp
->m_logdev_targp
) {
505 xfs_blkdev_put(logdev
);
506 xfs_blkdev_put(rtdev
);
511 * Setup flags based on mount(2) options and then the superblock
513 error
= xfs_start_flags(vfsp
, args
, mp
);
516 error
= xfs_readsb(mp
, flags
);
519 error
= xfs_finish_flags(vfsp
, args
, mp
);
524 * Setup xfs_mount buffer target pointers based on superblock
526 error
= xfs_setsize_buftarg(mp
->m_ddev_targp
, mp
->m_sb
.sb_blocksize
,
527 mp
->m_sb
.sb_sectsize
);
528 if (!error
&& logdev
&& logdev
!= ddev
) {
529 unsigned int log_sector_size
= BBSIZE
;
531 if (XFS_SB_VERSION_HASSECTOR(&mp
->m_sb
))
532 log_sector_size
= mp
->m_sb
.sb_logsectsize
;
533 error
= xfs_setsize_buftarg(mp
->m_logdev_targp
,
534 mp
->m_sb
.sb_blocksize
,
538 error
= xfs_setsize_buftarg(mp
->m_rtdev_targp
,
539 mp
->m_sb
.sb_blocksize
,
540 mp
->m_sb
.sb_sectsize
);
544 if (mp
->m_flags
& XFS_MOUNT_BARRIER
)
545 xfs_mountfs_check_barriers(mp
);
547 if ((error
= xfs_filestream_mount(mp
)))
550 error
= XFS_IOINIT(vfsp
, args
, flags
);
554 XFS_SEND_MOUNT(mp
, DM_RIGHT_NULL
, args
->mtpt
, args
->fsname
);
562 xfs_binval(mp
->m_ddev_targp
);
563 if (logdev
&& logdev
!= ddev
)
564 xfs_binval(mp
->m_logdev_targp
);
566 xfs_binval(mp
->m_rtdev_targp
);
568 xfs_unmountfs_close(mp
, credp
);
580 bhv_vfs_t
*vfsp
= XFS_MTOVFS(mp
);
583 int unmount_event_wanted
= 0;
584 int unmount_event_flags
= 0;
585 int xfs_unmountfs_needed
= 0;
592 if (mp
->m_flags
& XFS_MOUNT_DMAPI
) {
593 error
= XFS_SEND_PREUNMOUNT(mp
, vfsp
,
594 rvp
, DM_RIGHT_NULL
, rvp
, DM_RIGHT_NULL
,
596 (mp
->m_dmevmask
& (1<<DM_EVENT_PREUNMOUNT
))?
597 0:DM_FLAGS_UNWANTED
);
599 return XFS_ERROR(error
);
600 unmount_event_wanted
= 1;
601 unmount_event_flags
= (mp
->m_dmevmask
& (1<<DM_EVENT_UNMOUNT
))?
602 0 : DM_FLAGS_UNWANTED
;
606 * First blow any referenced inode from this file system
607 * out of the reference cache, and delete the timer.
609 xfs_refcache_purge_mp(mp
);
612 * Blow away any referenced inode in the filestreams cache.
613 * This can and will cause log traffic as inodes go inactive
616 xfs_filestream_unmount(mp
);
618 XFS_bflush(mp
->m_ddev_targp
);
619 error
= xfs_unmount_flush(mp
, 0);
623 ASSERT(vn_count(rvp
) == 1);
626 * Drop the reference count
631 * If we're forcing a shutdown, typically because of a media error,
632 * we want to make sure we invalidate dirty pages that belong to
633 * referenced vnodes as well.
635 if (XFS_FORCED_SHUTDOWN(mp
)) {
636 error
= xfs_sync(mp
, SYNC_WAIT
| SYNC_CLOSE
);
637 ASSERT(error
!= EFSCORRUPTED
);
639 xfs_unmountfs_needed
= 1;
642 /* Send DMAPI event, if required.
643 * Then do xfs_unmountfs() if needed.
644 * Then return error (or zero).
646 if (unmount_event_wanted
) {
647 /* Note: mp structure must still exist for
648 * XFS_SEND_UNMOUNT() call.
650 XFS_SEND_UNMOUNT(mp
, vfsp
, error
== 0 ? rvp
: NULL
,
651 DM_RIGHT_NULL
, 0, error
, unmount_event_flags
);
653 if (xfs_unmountfs_needed
) {
655 * Call common unmount function to flush to disk
656 * and free the super block buffer & mount structures.
658 xfs_unmountfs(mp
, credp
);
661 kmem_free(mp
, sizeof(xfs_mount_t
));
664 return XFS_ERROR(error
);
671 int count
= 0, pincount
;
673 xfs_refcache_purge_mp(mp
);
674 xfs_flush_buftarg(mp
->m_ddev_targp
, 0);
675 xfs_finish_reclaim_all(mp
, 0);
677 /* This loop must run at least twice.
678 * The first instance of the loop will flush
679 * most meta data but that will generate more
680 * meta data (typically directory updates).
681 * Which then must be flushed and logged before
682 * we can write the unmount record.
685 xfs_syncsub(mp
, SYNC_INODE_QUIESCE
, NULL
);
686 pincount
= xfs_flush_buftarg(mp
->m_ddev_targp
, 1);
697 * Second stage of a quiesce. The data is already synced, now we have to take
698 * care of the metadata. New transactions are already blocked, so we need to
699 * wait for any remaining transactions to drain out before proceding.
705 /* wait for all modifications to complete */
706 while (atomic_read(&mp
->m_active_trans
) > 0)
709 /* flush inodes and push all remaining buffers out to disk */
712 ASSERT_ALWAYS(atomic_read(&mp
->m_active_trans
) == 0);
714 /* Push the superblock and write an unmount record */
715 xfs_log_sbcount(mp
, 1);
716 xfs_log_unmount_write(mp
);
717 xfs_unmountfs_writesb(mp
);
722 struct xfs_mount
*mp
,
724 struct xfs_mount_args
*args
)
726 if (!(*flags
& MS_RDONLY
)) { /* rw/ro -> rw */
727 if (mp
->m_flags
& XFS_MOUNT_RDONLY
)
728 mp
->m_flags
&= ~XFS_MOUNT_RDONLY
;
729 if (args
->flags
& XFSMNT_BARRIER
) {
730 mp
->m_flags
|= XFS_MOUNT_BARRIER
;
731 xfs_mountfs_check_barriers(mp
);
733 mp
->m_flags
&= ~XFS_MOUNT_BARRIER
;
735 } else if (!(mp
->m_flags
& XFS_MOUNT_RDONLY
)) { /* rw -> ro */
736 xfs_filestream_flush(mp
);
737 xfs_sync(mp
, SYNC_DATA_QUIESCE
);
738 xfs_attr_quiesce(mp
);
739 mp
->m_flags
|= XFS_MOUNT_RDONLY
;
745 * xfs_unmount_flush implements a set of flush operation on special
746 * inodes, which are needed as a separate set of operations so that
747 * they can be called as part of relocation process.
751 xfs_mount_t
*mp
, /* Mount structure we are getting
753 int relocation
) /* Called from vfs relocation. */
755 xfs_inode_t
*rip
= mp
->m_rootip
;
757 xfs_inode_t
*rsumip
= NULL
;
758 bhv_vnode_t
*rvp
= XFS_ITOV(rip
);
761 xfs_ilock(rip
, XFS_ILOCK_EXCL
| XFS_ILOCK_PARENT
);
765 * Flush out the real time inodes.
767 if ((rbmip
= mp
->m_rbmip
) != NULL
) {
768 xfs_ilock(rbmip
, XFS_ILOCK_EXCL
);
770 error
= xfs_iflush(rbmip
, XFS_IFLUSH_SYNC
);
771 xfs_iunlock(rbmip
, XFS_ILOCK_EXCL
);
773 if (error
== EFSCORRUPTED
)
776 ASSERT(vn_count(XFS_ITOV(rbmip
)) == 1);
778 rsumip
= mp
->m_rsumip
;
779 xfs_ilock(rsumip
, XFS_ILOCK_EXCL
);
781 error
= xfs_iflush(rsumip
, XFS_IFLUSH_SYNC
);
782 xfs_iunlock(rsumip
, XFS_ILOCK_EXCL
);
784 if (error
== EFSCORRUPTED
)
787 ASSERT(vn_count(XFS_ITOV(rsumip
)) == 1);
791 * Synchronously flush root inode to disk
793 error
= xfs_iflush(rip
, XFS_IFLUSH_SYNC
);
794 if (error
== EFSCORRUPTED
)
797 if (vn_count(rvp
) != 1 && !relocation
) {
798 xfs_iunlock(rip
, XFS_ILOCK_EXCL
);
799 return XFS_ERROR(EBUSY
);
803 * Release dquot that rootinode, rbmino and rsumino might be holding,
804 * flush and purge the quota inodes.
806 error
= XFS_QM_UNMOUNT(mp
);
807 if (error
== EFSCORRUPTED
)
811 VN_RELE(XFS_ITOV(rbmip
));
812 VN_RELE(XFS_ITOV(rsumip
));
815 xfs_iunlock(rip
, XFS_ILOCK_EXCL
);
822 xfs_iunlock(rip
, XFS_ILOCK_EXCL
);
824 return XFS_ERROR(EFSCORRUPTED
);
828 * xfs_root extracts the root vnode from a vfs.
830 * vfsp -- the vfs struct for the desired file system
831 * vpp -- address of the caller's vnode pointer which should be
832 * set to the desired fs root vnode
841 vp
= XFS_ITOV(mp
->m_rootip
);
850 * Fill in the statvfs structure for the given file system. We use
851 * the superblock lock in the mount structure to ensure a consistent
852 * snapshot of the counters returned.
857 bhv_statvfs_t
*statp
,
867 statp
->f_type
= XFS_SB_MAGIC
;
869 xfs_icsb_sync_counters_flags(mp
, XFS_ICSB_LAZY_COUNT
);
871 statp
->f_bsize
= sbp
->sb_blocksize
;
872 lsize
= sbp
->sb_logstart
? sbp
->sb_logblocks
: 0;
873 statp
->f_blocks
= sbp
->sb_dblocks
- lsize
;
874 statp
->f_bfree
= statp
->f_bavail
=
875 sbp
->sb_fdblocks
- XFS_ALLOC_SET_ASIDE(mp
);
876 fakeinos
= statp
->f_bfree
<< sbp
->sb_inopblog
;
878 fakeinos
+= mp
->m_inoadd
;
881 MIN(sbp
->sb_icount
+ fakeinos
, (__uint64_t
)XFS_MAXINUMBER
);
886 statp
->f_files
= min_t(typeof(statp
->f_files
),
889 statp
->f_ffree
= statp
->f_files
- (sbp
->sb_icount
- sbp
->sb_ifree
);
890 XFS_SB_UNLOCK(mp
, s
);
892 xfs_statvfs_fsid(statp
, mp
);
893 statp
->f_namelen
= MAXNAMELEN
- 1;
896 XFS_QM_DQSTATVFS(xfs_vtoi(vp
), statp
);
902 * xfs_sync flushes any pending I/O to file system vfsp.
904 * This routine is called by vfs_sync() to make sure that things make it
905 * out to disk eventually, on sync() system calls to flush out everything,
906 * and when the file system is unmounted. For the vfs_sync() case, all
907 * we really need to do is sync out the log to make all of our meta-data
908 * updates permanent (except for timestamps). For calls from pflushd(),
909 * dirty pages are kept moving by calling pdflush() on the inodes
910 * containing them. We also flush the inodes that we can lock without
911 * sleeping and the superblock if we can lock it without sleeping from
912 * vfs_sync() so that items at the tail of the log are always moving out.
915 * SYNC_BDFLUSH - We're being called from vfs_sync() so we don't want
916 * to sleep if we can help it. All we really need
917 * to do is ensure that the log is synced at least
918 * periodically. We also push the inodes and
919 * superblock if we can lock them without sleeping
920 * and they are not pinned.
921 * SYNC_ATTR - We need to flush the inodes. If SYNC_BDFLUSH is not
922 * set, then we really want to lock each inode and flush
924 * SYNC_WAIT - All the flushes that take place in this call should
926 * SYNC_DELWRI - This tells us to push dirty pages associated with
927 * inodes. SYNC_WAIT and SYNC_BDFLUSH are used to
928 * determine if they should be flushed sync, async, or
930 * SYNC_CLOSE - This flag is passed when the system is being
931 * unmounted. We should sync and invalidate everything.
932 * SYNC_FSDATA - This indicates that the caller would like to make
933 * sure the superblock is safe on disk. We can ensure
934 * this by simply making sure the log gets flushed
935 * if SYNC_BDFLUSH is set, and by actually writing it
937 * SYNC_IOWAIT - The caller wants us to wait for all data I/O to complete
938 * before we return (including direct I/O). Forms the drain
939 * side of the write barrier needed to safely quiesce the
951 * Get the Quota Manager to flush the dquots.
953 * If XFS quota support is not enabled or this filesystem
954 * instance does not use quotas XFS_QM_DQSYNC will always
957 error
= XFS_QM_DQSYNC(mp
, flags
);
960 * If we got an IO error, we will be shutting down.
961 * So, there's nothing more for us to do here.
963 ASSERT(error
!= EIO
|| XFS_FORCED_SHUTDOWN(mp
));
964 if (XFS_FORCED_SHUTDOWN(mp
))
965 return XFS_ERROR(error
);
968 if (flags
& SYNC_IOWAIT
)
969 xfs_filestream_flush(mp
);
971 return xfs_syncsub(mp
, flags
, NULL
);
975 * xfs sync routine for internal use
977 * This routine supports all of the flags defined for the generic vfs_sync
978 * interface as explained above under xfs_sync.
987 xfs_inode_t
*ip
= NULL
;
988 xfs_inode_t
*ip_next
;
990 bhv_vnode_t
*vp
= NULL
;
995 uint base_lock_flags
;
996 boolean_t mount_locked
;
997 boolean_t vnode_refed
;
1000 xfs_iptr_t
*ipointer
;
1002 boolean_t ipointer_in
= B_FALSE
;
1004 #define IPOINTER_SET ipointer_in = B_TRUE
1005 #define IPOINTER_CLR ipointer_in = B_FALSE
1007 #define IPOINTER_SET
1008 #define IPOINTER_CLR
1012 /* Insert a marker record into the inode list after inode ip. The list
1013 * must be locked when this is called. After the call the list will no
1016 #define IPOINTER_INSERT(ip, mp) { \
1017 ASSERT(ipointer_in == B_FALSE); \
1018 ipointer->ip_mnext = ip->i_mnext; \
1019 ipointer->ip_mprev = ip; \
1020 ip->i_mnext = (xfs_inode_t *)ipointer; \
1021 ipointer->ip_mnext->i_mprev = (xfs_inode_t *)ipointer; \
1023 XFS_MOUNT_IUNLOCK(mp); \
1024 mount_locked = B_FALSE; \
1028 /* Remove the marker from the inode list. If the marker was the only item
1029 * in the list then there are no remaining inodes and we should zero out
1030 * the whole list. If we are the current head of the list then move the head
1033 #define IPOINTER_REMOVE(ip, mp) { \
1034 ASSERT(ipointer_in == B_TRUE); \
1035 if (ipointer->ip_mnext != (xfs_inode_t *)ipointer) { \
1036 ip = ipointer->ip_mnext; \
1037 ip->i_mprev = ipointer->ip_mprev; \
1038 ipointer->ip_mprev->i_mnext = ip; \
1039 if (mp->m_inodes == (xfs_inode_t *)ipointer) { \
1040 mp->m_inodes = ip; \
1043 ASSERT(mp->m_inodes == (xfs_inode_t *)ipointer); \
1044 mp->m_inodes = NULL; \
1050 #define XFS_PREEMPT_MASK 0x7f
1054 if (mp
->m_flags
& XFS_MOUNT_RDONLY
)
1060 /* Allocate a reference marker */
1061 ipointer
= (xfs_iptr_t
*)kmem_zalloc(sizeof(xfs_iptr_t
), KM_SLEEP
);
1063 fflag
= XFS_B_ASYNC
; /* default is don't wait */
1064 if (flags
& (SYNC_BDFLUSH
| SYNC_DELWRI
))
1065 fflag
= XFS_B_DELWRI
;
1066 if (flags
& SYNC_WAIT
)
1067 fflag
= 0; /* synchronous overrides all */
1069 base_lock_flags
= XFS_ILOCK_SHARED
;
1070 if (flags
& (SYNC_DELWRI
| SYNC_CLOSE
)) {
1072 * We need the I/O lock if we're going to call any of
1073 * the flush/inval routines.
1075 base_lock_flags
|= XFS_IOLOCK_SHARED
;
1078 XFS_MOUNT_ILOCK(mp
);
1082 mount_locked
= B_TRUE
;
1083 vnode_refed
= B_FALSE
;
1088 ASSERT(ipointer_in
== B_FALSE
);
1089 ASSERT(vnode_refed
== B_FALSE
);
1091 lock_flags
= base_lock_flags
;
1094 * There were no inodes in the list, just break out
1102 * We found another sync thread marker - skip it
1104 if (ip
->i_mount
== NULL
) {
1109 vp
= XFS_ITOV_NULL(ip
);
1112 * If the vnode is gone then this is being torn down,
1113 * call reclaim if it is flushed, else let regular flush
1114 * code deal with it later in the loop.
1118 /* Skip ones already in reclaim */
1119 if (ip
->i_flags
& XFS_IRECLAIM
) {
1123 if (xfs_ilock_nowait(ip
, XFS_ILOCK_EXCL
) == 0) {
1125 } else if ((xfs_ipincount(ip
) == 0) &&
1126 xfs_iflock_nowait(ip
)) {
1127 IPOINTER_INSERT(ip
, mp
);
1129 xfs_finish_reclaim(ip
, 1,
1130 XFS_IFLUSH_DELWRI_ELSE_ASYNC
);
1132 XFS_MOUNT_ILOCK(mp
);
1133 mount_locked
= B_TRUE
;
1134 IPOINTER_REMOVE(ip
, mp
);
1136 xfs_iunlock(ip
, XFS_ILOCK_EXCL
);
1147 if (XFS_FORCED_SHUTDOWN(mp
) && !(flags
& SYNC_CLOSE
)) {
1148 XFS_MOUNT_IUNLOCK(mp
);
1149 kmem_free(ipointer
, sizeof(xfs_iptr_t
));
1154 * If this is just vfs_sync() or pflushd() calling
1155 * then we can skip inodes for which it looks like
1156 * there is nothing to do. Since we don't have the
1157 * inode locked this is racy, but these are periodic
1158 * calls so it doesn't matter. For the others we want
1159 * to know for sure, so we at least try to lock them.
1161 if (flags
& SYNC_BDFLUSH
) {
1162 if (((ip
->i_itemp
== NULL
) ||
1163 !(ip
->i_itemp
->ili_format
.ilf_fields
&
1165 (ip
->i_update_core
== 0)) {
1172 * Try to lock without sleeping. We're out of order with
1173 * the inode list lock here, so if we fail we need to drop
1174 * the mount lock and try again. If we're called from
1175 * bdflush() here, then don't bother.
1177 * The inode lock here actually coordinates with the
1178 * almost spurious inode lock in xfs_ireclaim() to prevent
1179 * the vnode we handle here without a reference from
1180 * being freed while we reference it. If we lock the inode
1181 * while it's on the mount list here, then the spurious inode
1182 * lock in xfs_ireclaim() after the inode is pulled from
1183 * the mount list will sleep until we release it here.
1184 * This keeps the vnode from being freed while we reference
1187 if (xfs_ilock_nowait(ip
, lock_flags
) == 0) {
1188 if ((flags
& SYNC_BDFLUSH
) || (vp
== NULL
)) {
1199 IPOINTER_INSERT(ip
, mp
);
1200 xfs_ilock(ip
, lock_flags
);
1202 ASSERT(vp
== XFS_ITOV(ip
));
1203 ASSERT(ip
->i_mount
== mp
);
1205 vnode_refed
= B_TRUE
;
1208 /* From here on in the loop we may have a marker record
1209 * in the inode list.
1213 * If we have to flush data or wait for I/O completion
1214 * we need to drop the ilock that we currently hold.
1215 * If we need to drop the lock, insert a marker if we
1216 * have not already done so.
1218 if ((flags
& (SYNC_CLOSE
|SYNC_IOWAIT
)) ||
1219 ((flags
& SYNC_DELWRI
) && VN_DIRTY(vp
))) {
1221 IPOINTER_INSERT(ip
, mp
);
1223 xfs_iunlock(ip
, XFS_ILOCK_SHARED
);
1225 if (flags
& SYNC_CLOSE
) {
1226 /* Shutdown case. Flush and invalidate. */
1227 if (XFS_FORCED_SHUTDOWN(mp
))
1228 xfs_tosspages(ip
, 0, -1,
1231 error
= xfs_flushinval_pages(ip
,
1233 } else if ((flags
& SYNC_DELWRI
) && VN_DIRTY(vp
)) {
1234 error
= xfs_flush_pages(ip
, 0,
1235 -1, fflag
, FI_NONE
);
1239 * When freezing, we need to wait ensure all I/O (including direct
1240 * I/O) is complete to ensure no further data modification can take
1241 * place after this point
1243 if (flags
& SYNC_IOWAIT
)
1246 xfs_ilock(ip
, XFS_ILOCK_SHARED
);
1249 if (flags
& SYNC_BDFLUSH
) {
1250 if ((flags
& SYNC_ATTR
) &&
1251 ((ip
->i_update_core
) ||
1252 ((ip
->i_itemp
!= NULL
) &&
1253 (ip
->i_itemp
->ili_format
.ilf_fields
!= 0)))) {
1255 /* Insert marker and drop lock if not already
1259 IPOINTER_INSERT(ip
, mp
);
1263 * We don't want the periodic flushing of the
1264 * inodes by vfs_sync() to interfere with
1265 * I/O to the file, especially read I/O
1266 * where it is only the access time stamp
1267 * that is being flushed out. To prevent
1268 * long periods where we have both inode
1269 * locks held shared here while reading the
1270 * inode's buffer in from disk, we drop the
1271 * inode lock while reading in the inode
1272 * buffer. We have to release the buffer
1273 * and reacquire the inode lock so that they
1274 * are acquired in the proper order (inode
1275 * locks first). The buffer will go at the
1276 * end of the lru chain, though, so we can
1277 * expect it to still be there when we go
1278 * for it again in xfs_iflush().
1280 if ((xfs_ipincount(ip
) == 0) &&
1281 xfs_iflock_nowait(ip
)) {
1284 xfs_iunlock(ip
, XFS_ILOCK_SHARED
);
1286 error
= xfs_itobp(mp
, NULL
, ip
,
1291 /* Bailing out, remove the
1292 * marker and free it.
1294 XFS_MOUNT_ILOCK(mp
);
1295 IPOINTER_REMOVE(ip
, mp
);
1296 XFS_MOUNT_IUNLOCK(mp
);
1298 ASSERT(!(lock_flags
&
1299 XFS_IOLOCK_SHARED
));
1302 sizeof(xfs_iptr_t
));
1307 * Since we dropped the inode lock,
1308 * the inode may have been reclaimed.
1309 * Therefore, we reacquire the mount
1310 * lock and check to see if we were the
1311 * inode reclaimed. If this happened
1312 * then the ipointer marker will no
1313 * longer point back at us. In this
1314 * case, move ip along to the inode
1315 * after the marker, remove the marker
1318 XFS_MOUNT_ILOCK(mp
);
1319 mount_locked
= B_TRUE
;
1321 if (ip
!= ipointer
->ip_mprev
) {
1322 IPOINTER_REMOVE(ip
, mp
);
1324 ASSERT(!vnode_refed
);
1325 ASSERT(!(lock_flags
&
1326 XFS_IOLOCK_SHARED
));
1330 ASSERT(ip
->i_mount
== mp
);
1332 if (xfs_ilock_nowait(ip
,
1333 XFS_ILOCK_SHARED
) == 0) {
1334 ASSERT(ip
->i_mount
== mp
);
1336 * We failed to reacquire
1337 * the inode lock without
1338 * sleeping, so just skip
1339 * the inode for now. We
1340 * clear the ILOCK bit from
1341 * the lock_flags so that we
1342 * won't try to drop a lock
1343 * we don't hold below.
1345 lock_flags
&= ~XFS_ILOCK_SHARED
;
1346 IPOINTER_REMOVE(ip_next
, mp
);
1347 } else if ((xfs_ipincount(ip
) == 0) &&
1348 xfs_iflock_nowait(ip
)) {
1349 ASSERT(ip
->i_mount
== mp
);
1351 * Since this is vfs_sync()
1352 * calling we only flush the
1353 * inode out if we can lock
1354 * it without sleeping and
1355 * it is not pinned. Drop
1356 * the mount lock here so
1357 * that we don't hold it for
1358 * too long. We already have
1359 * a marker in the list here.
1361 XFS_MOUNT_IUNLOCK(mp
);
1362 mount_locked
= B_FALSE
;
1363 error
= xfs_iflush(ip
,
1366 ASSERT(ip
->i_mount
== mp
);
1367 IPOINTER_REMOVE(ip_next
, mp
);
1374 if ((flags
& SYNC_ATTR
) &&
1375 ((ip
->i_update_core
) ||
1376 ((ip
->i_itemp
!= NULL
) &&
1377 (ip
->i_itemp
->ili_format
.ilf_fields
!= 0)))) {
1379 IPOINTER_INSERT(ip
, mp
);
1382 if (flags
& SYNC_WAIT
) {
1384 error
= xfs_iflush(ip
,
1388 * If we can't acquire the flush
1389 * lock, then the inode is already
1390 * being flushed so don't bother
1391 * waiting. If we can lock it then
1392 * do a delwri flush so we can
1393 * combine multiple inode flushes
1394 * in each disk write.
1396 if (xfs_iflock_nowait(ip
)) {
1397 error
= xfs_iflush(ip
,
1406 if (lock_flags
!= 0) {
1407 xfs_iunlock(ip
, lock_flags
);
1412 * If we had to take a reference on the vnode
1413 * above, then wait until after we've unlocked
1414 * the inode to release the reference. This is
1415 * because we can be already holding the inode
1416 * lock when VN_RELE() calls xfs_inactive().
1418 * Make sure to drop the mount lock before calling
1419 * VN_RELE() so that we don't trip over ourselves if
1420 * we have to go for the mount lock again in the
1424 IPOINTER_INSERT(ip
, mp
);
1429 vnode_refed
= B_FALSE
;
1437 * bail out if the filesystem is corrupted.
1439 if (error
== EFSCORRUPTED
) {
1440 if (!mount_locked
) {
1441 XFS_MOUNT_ILOCK(mp
);
1442 IPOINTER_REMOVE(ip
, mp
);
1444 XFS_MOUNT_IUNLOCK(mp
);
1445 ASSERT(ipointer_in
== B_FALSE
);
1446 kmem_free(ipointer
, sizeof(xfs_iptr_t
));
1447 return XFS_ERROR(error
);
1450 /* Let other threads have a chance at the mount lock
1451 * if we have looped many times without dropping the
1454 if ((++preempt
& XFS_PREEMPT_MASK
) == 0) {
1456 IPOINTER_INSERT(ip
, mp
);
1460 if (mount_locked
== B_FALSE
) {
1461 XFS_MOUNT_ILOCK(mp
);
1462 mount_locked
= B_TRUE
;
1463 IPOINTER_REMOVE(ip
, mp
);
1467 ASSERT(ipointer_in
== B_FALSE
);
1470 } while (ip
!= mp
->m_inodes
);
1472 XFS_MOUNT_IUNLOCK(mp
);
1474 ASSERT(ipointer_in
== B_FALSE
);
1476 kmem_free(ipointer
, sizeof(xfs_iptr_t
));
1477 return XFS_ERROR(last_error
);
1481 * xfs sync routine for internal use
1483 * This routine supports all of the flags defined for the generic vfs_sync
1484 * interface as explained above under xfs_sync.
1495 uint log_flags
= XFS_LOG_FORCE
;
1497 xfs_buf_log_item_t
*bip
;
1500 * Sync out the log. This ensures that the log is periodically
1501 * flushed even if there is not enough activity to fill it up.
1503 if (flags
& SYNC_WAIT
)
1504 log_flags
|= XFS_LOG_SYNC
;
1506 xfs_log_force(mp
, (xfs_lsn_t
)0, log_flags
);
1508 if (flags
& (SYNC_ATTR
|SYNC_DELWRI
)) {
1509 if (flags
& SYNC_BDFLUSH
)
1510 xfs_finish_reclaim_all(mp
, 1);
1512 error
= xfs_sync_inodes(mp
, flags
, bypassed
);
1516 * Flushing out dirty data above probably generated more
1517 * log activity, so if this isn't vfs_sync() then flush
1520 if (flags
& SYNC_DELWRI
) {
1521 xfs_log_force(mp
, (xfs_lsn_t
)0, log_flags
);
1524 if (flags
& SYNC_FSDATA
) {
1526 * If this is vfs_sync() then only sync the superblock
1527 * if we can lock it without sleeping and it is not pinned.
1529 if (flags
& SYNC_BDFLUSH
) {
1530 bp
= xfs_getsb(mp
, XFS_BUF_TRYLOCK
);
1532 bip
= XFS_BUF_FSPRIVATE(bp
,xfs_buf_log_item_t
*);
1533 if ((bip
!= NULL
) &&
1534 xfs_buf_item_dirty(bip
)) {
1535 if (!(XFS_BUF_ISPINNED(bp
))) {
1537 error
= xfs_bwrite(mp
, bp
);
1546 bp
= xfs_getsb(mp
, 0);
1548 * If the buffer is pinned then push on the log so
1549 * we won't get stuck waiting in the write for
1550 * someone, maybe ourselves, to flush the log.
1551 * Even though we just pushed the log above, we
1552 * did not have the superblock buffer locked at
1553 * that point so it can become pinned in between
1556 if (XFS_BUF_ISPINNED(bp
))
1557 xfs_log_force(mp
, (xfs_lsn_t
)0, XFS_LOG_FORCE
);
1558 if (flags
& SYNC_WAIT
)
1559 XFS_BUF_UNASYNC(bp
);
1562 error
= xfs_bwrite(mp
, bp
);
1570 * If this is the periodic sync, then kick some entries out of
1571 * the reference cache. This ensures that idle entries are
1572 * eventually kicked out of the cache.
1574 if (flags
& SYNC_REFCACHE
) {
1575 if (flags
& SYNC_WAIT
)
1576 xfs_refcache_purge_mp(mp
);
1578 xfs_refcache_purge_some(mp
);
1582 * If asked, update the disk superblock with incore counter values if we
1583 * are using non-persistent counters so that they don't get too far out
1584 * of sync if we crash or get a forced shutdown. We don't want to force
1585 * this to disk, just get a transaction into the iclogs....
1587 if (flags
& SYNC_SUPER
)
1588 xfs_log_sbcount(mp
, 0);
1591 * Now check to see if the log needs a "dummy" transaction.
1594 if (!(flags
& SYNC_REMOUNT
) && xfs_log_need_covered(mp
)) {
1599 * Put a dummy transaction in the log to tell
1600 * recovery that all others are OK.
1602 tp
= xfs_trans_alloc(mp
, XFS_TRANS_DUMMY1
);
1603 if ((error
= xfs_trans_reserve(tp
, 0,
1604 XFS_ICHANGE_LOG_RES(mp
),
1606 xfs_trans_cancel(tp
, 0);
1611 xfs_ilock(ip
, XFS_ILOCK_EXCL
);
1613 xfs_trans_ijoin(tp
, ip
, XFS_ILOCK_EXCL
);
1614 xfs_trans_ihold(tp
, ip
);
1615 xfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
1616 error
= xfs_trans_commit(tp
, 0);
1617 xfs_iunlock(ip
, XFS_ILOCK_EXCL
);
1618 xfs_log_force(mp
, (xfs_lsn_t
)0, log_flags
);
1622 * When shutting down, we need to insure that the AIL is pushed
1623 * to disk or the filesystem can appear corrupt from the PROM.
1625 if ((flags
& (SYNC_CLOSE
|SYNC_WAIT
)) == (SYNC_CLOSE
|SYNC_WAIT
)) {
1626 XFS_bflush(mp
->m_ddev_targp
);
1627 if (mp
->m_rtdev_targp
) {
1628 XFS_bflush(mp
->m_rtdev_targp
);
1632 return XFS_ERROR(last_error
);
1636 * xfs_vget - called by DMAPI and NFSD to get vnode from file handle
1644 xfs_fid_t
*xfid
= (struct xfs_fid
*)fidp
;
1651 * Invalid. Since handles can be created in user space and passed in
1652 * via gethandle(), this is not cause for a panic.
1654 if (xfid
->xfs_fid_len
!= sizeof(*xfid
) - sizeof(xfid
->xfs_fid_len
))
1655 return XFS_ERROR(EINVAL
);
1657 ino
= xfid
->xfs_fid_ino
;
1658 igen
= xfid
->xfs_fid_gen
;
1661 * NFS can sometimes send requests for ino 0. Fail them gracefully.
1664 return XFS_ERROR(ESTALE
);
1666 error
= xfs_iget(mp
, NULL
, ino
, 0, XFS_ILOCK_SHARED
, &ip
, 0);
1674 return XFS_ERROR(EIO
);
1677 if (ip
->i_d
.di_mode
== 0 || ip
->i_d
.di_gen
!= igen
) {
1678 xfs_iput_new(ip
, XFS_ILOCK_SHARED
);
1680 return XFS_ERROR(ENOENT
);
1683 *vpp
= XFS_ITOV(ip
);
1684 xfs_iunlock(ip
, XFS_ILOCK_SHARED
);
1689 #define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
1690 #define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
1691 #define MNTOPT_LOGDEV "logdev" /* log device */
1692 #define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
1693 #define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
1694 #define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
1695 #define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
1696 #define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
1697 #define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
1698 #define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
1699 #define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
1700 #define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
1701 #define MNTOPT_MTPT "mtpt" /* filesystem mount point */
1702 #define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
1703 #define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
1704 #define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
1705 #define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
1706 #define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
1707 #define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
1708 #define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
1709 * unwritten extent conversion */
1710 #define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
1711 #define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
1712 #define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
1713 #define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
1714 #define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
1715 #define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
1716 #define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
1718 #define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
1719 #define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
1720 #define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
1721 #define MNTOPT_QUOTA "quota" /* disk quotas (user) */
1722 #define MNTOPT_NOQUOTA "noquota" /* no quotas */
1723 #define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */
1724 #define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */
1725 #define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */
1726 #define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */
1727 #define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */
1728 #define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */
1729 #define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
1730 #define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
1731 #define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
1732 #define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */
1733 #define MNTOPT_DMAPI "dmapi" /* DMI enabled (DMAPI / XDSM) */
1734 #define MNTOPT_XDSM "xdsm" /* DMI enabled (DMAPI / XDSM) */
1735 #define MNTOPT_DMI "dmi" /* DMI enabled (DMAPI / XDSM) */
1737 STATIC
unsigned long
1738 suffix_strtoul(char *s
, char **endp
, unsigned int base
)
1740 int last
, shift_left_factor
= 0;
1743 last
= strlen(value
) - 1;
1744 if (value
[last
] == 'K' || value
[last
] == 'k') {
1745 shift_left_factor
= 10;
1748 if (value
[last
] == 'M' || value
[last
] == 'm') {
1749 shift_left_factor
= 20;
1752 if (value
[last
] == 'G' || value
[last
] == 'g') {
1753 shift_left_factor
= 30;
1757 return simple_strtoul((const char *)s
, endp
, base
) << shift_left_factor
;
1762 struct xfs_mount
*mp
,
1764 struct xfs_mount_args
*args
,
1767 char *this_char
, *value
, *eov
;
1768 int dsunit
, dswidth
, vol_dsunit
, vol_dswidth
;
1772 * Applications using DMI filesystems often expect the
1773 * inode generation number to be monotonically increasing.
1774 * If we delete inode chunks we break this assumption, so
1775 * keep unused inode chunks on disk for DMI filesystems
1776 * until we come up with a better solution.
1777 * Note that if "ikeep" or "noikeep" mount options are
1778 * supplied, then they are honored.
1780 if (!(args
->flags
& XFSMNT_DMAPI
))
1781 args
->flags
|= XFSMNT_IDELETE
;
1783 args
->flags
|= XFSMNT_BARRIER
;
1784 args
->flags2
|= XFSMNT2_COMPAT_IOSIZE
;
1789 iosize
= dsunit
= dswidth
= vol_dsunit
= vol_dswidth
= 0;
1791 while ((this_char
= strsep(&options
, ",")) != NULL
) {
1794 if ((value
= strchr(this_char
, '=')) != NULL
)
1797 if (!strcmp(this_char
, MNTOPT_LOGBUFS
)) {
1798 if (!value
|| !*value
) {
1800 "XFS: %s option requires an argument",
1804 args
->logbufs
= simple_strtoul(value
, &eov
, 10);
1805 } else if (!strcmp(this_char
, MNTOPT_LOGBSIZE
)) {
1806 if (!value
|| !*value
) {
1808 "XFS: %s option requires an argument",
1812 args
->logbufsize
= suffix_strtoul(value
, &eov
, 10);
1813 } else if (!strcmp(this_char
, MNTOPT_LOGDEV
)) {
1814 if (!value
|| !*value
) {
1816 "XFS: %s option requires an argument",
1820 strncpy(args
->logname
, value
, MAXNAMELEN
);
1821 } else if (!strcmp(this_char
, MNTOPT_MTPT
)) {
1822 if (!value
|| !*value
) {
1824 "XFS: %s option requires an argument",
1828 strncpy(args
->mtpt
, value
, MAXNAMELEN
);
1829 } else if (!strcmp(this_char
, MNTOPT_RTDEV
)) {
1830 if (!value
|| !*value
) {
1832 "XFS: %s option requires an argument",
1836 strncpy(args
->rtname
, value
, MAXNAMELEN
);
1837 } else if (!strcmp(this_char
, MNTOPT_BIOSIZE
)) {
1838 if (!value
|| !*value
) {
1840 "XFS: %s option requires an argument",
1844 iosize
= simple_strtoul(value
, &eov
, 10);
1845 args
->flags
|= XFSMNT_IOSIZE
;
1846 args
->iosizelog
= (uint8_t) iosize
;
1847 } else if (!strcmp(this_char
, MNTOPT_ALLOCSIZE
)) {
1848 if (!value
|| !*value
) {
1850 "XFS: %s option requires an argument",
1854 iosize
= suffix_strtoul(value
, &eov
, 10);
1855 args
->flags
|= XFSMNT_IOSIZE
;
1856 args
->iosizelog
= ffs(iosize
) - 1;
1857 } else if (!strcmp(this_char
, MNTOPT_GRPID
) ||
1858 !strcmp(this_char
, MNTOPT_BSDGROUPS
)) {
1859 mp
->m_flags
|= XFS_MOUNT_GRPID
;
1860 } else if (!strcmp(this_char
, MNTOPT_NOGRPID
) ||
1861 !strcmp(this_char
, MNTOPT_SYSVGROUPS
)) {
1862 mp
->m_flags
&= ~XFS_MOUNT_GRPID
;
1863 } else if (!strcmp(this_char
, MNTOPT_WSYNC
)) {
1864 args
->flags
|= XFSMNT_WSYNC
;
1865 } else if (!strcmp(this_char
, MNTOPT_OSYNCISOSYNC
)) {
1866 args
->flags
|= XFSMNT_OSYNCISOSYNC
;
1867 } else if (!strcmp(this_char
, MNTOPT_NORECOVERY
)) {
1868 args
->flags
|= XFSMNT_NORECOVERY
;
1869 } else if (!strcmp(this_char
, MNTOPT_INO64
)) {
1870 args
->flags
|= XFSMNT_INO64
;
1873 "XFS: %s option not allowed on this system",
1877 } else if (!strcmp(this_char
, MNTOPT_NOALIGN
)) {
1878 args
->flags
|= XFSMNT_NOALIGN
;
1879 } else if (!strcmp(this_char
, MNTOPT_SWALLOC
)) {
1880 args
->flags
|= XFSMNT_SWALLOC
;
1881 } else if (!strcmp(this_char
, MNTOPT_SUNIT
)) {
1882 if (!value
|| !*value
) {
1884 "XFS: %s option requires an argument",
1888 dsunit
= simple_strtoul(value
, &eov
, 10);
1889 } else if (!strcmp(this_char
, MNTOPT_SWIDTH
)) {
1890 if (!value
|| !*value
) {
1892 "XFS: %s option requires an argument",
1896 dswidth
= simple_strtoul(value
, &eov
, 10);
1897 } else if (!strcmp(this_char
, MNTOPT_64BITINODE
)) {
1898 args
->flags
&= ~XFSMNT_32BITINODES
;
1901 "XFS: %s option not allowed on this system",
1905 } else if (!strcmp(this_char
, MNTOPT_NOUUID
)) {
1906 args
->flags
|= XFSMNT_NOUUID
;
1907 } else if (!strcmp(this_char
, MNTOPT_BARRIER
)) {
1908 args
->flags
|= XFSMNT_BARRIER
;
1909 } else if (!strcmp(this_char
, MNTOPT_NOBARRIER
)) {
1910 args
->flags
&= ~XFSMNT_BARRIER
;
1911 } else if (!strcmp(this_char
, MNTOPT_IKEEP
)) {
1912 args
->flags
&= ~XFSMNT_IDELETE
;
1913 } else if (!strcmp(this_char
, MNTOPT_NOIKEEP
)) {
1914 args
->flags
|= XFSMNT_IDELETE
;
1915 } else if (!strcmp(this_char
, MNTOPT_LARGEIO
)) {
1916 args
->flags2
&= ~XFSMNT2_COMPAT_IOSIZE
;
1917 } else if (!strcmp(this_char
, MNTOPT_NOLARGEIO
)) {
1918 args
->flags2
|= XFSMNT2_COMPAT_IOSIZE
;
1919 } else if (!strcmp(this_char
, MNTOPT_ATTR2
)) {
1920 args
->flags
|= XFSMNT_ATTR2
;
1921 } else if (!strcmp(this_char
, MNTOPT_NOATTR2
)) {
1922 args
->flags
&= ~XFSMNT_ATTR2
;
1923 } else if (!strcmp(this_char
, MNTOPT_FILESTREAM
)) {
1924 args
->flags2
|= XFSMNT2_FILESTREAMS
;
1925 } else if (!strcmp(this_char
, MNTOPT_NOQUOTA
)) {
1926 args
->flags
&= ~(XFSMNT_UQUOTAENF
|XFSMNT_UQUOTA
);
1927 args
->flags
&= ~(XFSMNT_GQUOTAENF
|XFSMNT_GQUOTA
);
1928 } else if (!strcmp(this_char
, MNTOPT_QUOTA
) ||
1929 !strcmp(this_char
, MNTOPT_UQUOTA
) ||
1930 !strcmp(this_char
, MNTOPT_USRQUOTA
)) {
1931 args
->flags
|= XFSMNT_UQUOTA
| XFSMNT_UQUOTAENF
;
1932 } else if (!strcmp(this_char
, MNTOPT_QUOTANOENF
) ||
1933 !strcmp(this_char
, MNTOPT_UQUOTANOENF
)) {
1934 args
->flags
|= XFSMNT_UQUOTA
;
1935 args
->flags
&= ~XFSMNT_UQUOTAENF
;
1936 } else if (!strcmp(this_char
, MNTOPT_PQUOTA
) ||
1937 !strcmp(this_char
, MNTOPT_PRJQUOTA
)) {
1938 args
->flags
|= XFSMNT_PQUOTA
| XFSMNT_PQUOTAENF
;
1939 } else if (!strcmp(this_char
, MNTOPT_PQUOTANOENF
)) {
1940 args
->flags
|= XFSMNT_PQUOTA
;
1941 args
->flags
&= ~XFSMNT_PQUOTAENF
;
1942 } else if (!strcmp(this_char
, MNTOPT_GQUOTA
) ||
1943 !strcmp(this_char
, MNTOPT_GRPQUOTA
)) {
1944 args
->flags
|= XFSMNT_GQUOTA
| XFSMNT_GQUOTAENF
;
1945 } else if (!strcmp(this_char
, MNTOPT_GQUOTANOENF
)) {
1946 args
->flags
|= XFSMNT_GQUOTA
;
1947 args
->flags
&= ~XFSMNT_GQUOTAENF
;
1948 } else if (!strcmp(this_char
, MNTOPT_DMAPI
)) {
1949 args
->flags
|= XFSMNT_DMAPI
;
1950 } else if (!strcmp(this_char
, MNTOPT_XDSM
)) {
1951 args
->flags
|= XFSMNT_DMAPI
;
1952 } else if (!strcmp(this_char
, MNTOPT_DMI
)) {
1953 args
->flags
|= XFSMNT_DMAPI
;
1954 } else if (!strcmp(this_char
, "ihashsize")) {
1956 "XFS: ihashsize no longer used, option is deprecated.");
1957 } else if (!strcmp(this_char
, "osyncisdsync")) {
1958 /* no-op, this is now the default */
1960 "XFS: osyncisdsync is now the default, option is deprecated.");
1961 } else if (!strcmp(this_char
, "irixsgid")) {
1963 "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
1966 "XFS: unknown mount option [%s].", this_char
);
1971 if (args
->flags
& XFSMNT_NORECOVERY
) {
1972 if ((mp
->m_flags
& XFS_MOUNT_RDONLY
) == 0) {
1974 "XFS: no-recovery mounts must be read-only.");
1979 if ((args
->flags
& XFSMNT_NOALIGN
) && (dsunit
|| dswidth
)) {
1981 "XFS: sunit and swidth options incompatible with the noalign option");
1985 if ((args
->flags
& XFSMNT_GQUOTA
) && (args
->flags
& XFSMNT_PQUOTA
)) {
1987 "XFS: cannot mount with both project and group quota");
1991 if ((args
->flags
& XFSMNT_DMAPI
) && *args
->mtpt
== '\0') {
1992 printk("XFS: %s option needs the mount point option as well\n",
1997 if ((dsunit
&& !dswidth
) || (!dsunit
&& dswidth
)) {
1999 "XFS: sunit and swidth must be specified together");
2003 if (dsunit
&& (dswidth
% dsunit
!= 0)) {
2005 "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
2010 if ((args
->flags
& XFSMNT_NOALIGN
) != XFSMNT_NOALIGN
) {
2012 args
->sunit
= dsunit
;
2013 args
->flags
|= XFSMNT_RETERR
;
2015 args
->sunit
= vol_dsunit
;
2017 dswidth
? (args
->swidth
= dswidth
) :
2018 (args
->swidth
= vol_dswidth
);
2020 args
->sunit
= args
->swidth
= 0;
2024 if (args
->flags
& XFSMNT_32BITINODES
)
2025 mp
->m_flags
|= XFS_MOUNT_SMALL_INUMS
;
2027 args
->flags
|= XFSMNT_FLAGS2
;
2033 struct xfs_mount
*mp
,
2036 static struct proc_xfs_info
{
2040 /* the few simple ones we can get from the mount struct */
2041 { XFS_MOUNT_WSYNC
, "," MNTOPT_WSYNC
},
2042 { XFS_MOUNT_INO64
, "," MNTOPT_INO64
},
2043 { XFS_MOUNT_NOALIGN
, "," MNTOPT_NOALIGN
},
2044 { XFS_MOUNT_SWALLOC
, "," MNTOPT_SWALLOC
},
2045 { XFS_MOUNT_NOUUID
, "," MNTOPT_NOUUID
},
2046 { XFS_MOUNT_NORECOVERY
, "," MNTOPT_NORECOVERY
},
2047 { XFS_MOUNT_OSYNCISOSYNC
, "," MNTOPT_OSYNCISOSYNC
},
2050 struct proc_xfs_info
*xfs_infop
;
2052 for (xfs_infop
= xfs_info
; xfs_infop
->flag
; xfs_infop
++) {
2053 if (mp
->m_flags
& xfs_infop
->flag
)
2054 seq_puts(m
, xfs_infop
->str
);
2057 if (mp
->m_flags
& XFS_MOUNT_DFLT_IOSIZE
)
2058 seq_printf(m
, "," MNTOPT_ALLOCSIZE
"=%dk",
2059 (int)(1 << mp
->m_writeio_log
) >> 10);
2061 if (mp
->m_logbufs
> 0)
2062 seq_printf(m
, "," MNTOPT_LOGBUFS
"=%d", mp
->m_logbufs
);
2063 if (mp
->m_logbsize
> 0)
2064 seq_printf(m
, "," MNTOPT_LOGBSIZE
"=%dk", mp
->m_logbsize
>> 10);
2067 seq_printf(m
, "," MNTOPT_LOGDEV
"=%s", mp
->m_logname
);
2069 seq_printf(m
, "," MNTOPT_RTDEV
"=%s", mp
->m_rtname
);
2071 if (mp
->m_dalign
> 0)
2072 seq_printf(m
, "," MNTOPT_SUNIT
"=%d",
2073 (int)XFS_FSB_TO_BB(mp
, mp
->m_dalign
));
2074 if (mp
->m_swidth
> 0)
2075 seq_printf(m
, "," MNTOPT_SWIDTH
"=%d",
2076 (int)XFS_FSB_TO_BB(mp
, mp
->m_swidth
));
2078 if (!(mp
->m_flags
& XFS_MOUNT_IDELETE
))
2079 seq_printf(m
, "," MNTOPT_IKEEP
);
2080 if (!(mp
->m_flags
& XFS_MOUNT_COMPAT_IOSIZE
))
2081 seq_printf(m
, "," MNTOPT_LARGEIO
);
2083 if (!(mp
->m_flags
& XFS_MOUNT_SMALL_INUMS
))
2084 seq_printf(m
, "," MNTOPT_64BITINODE
);
2085 if (mp
->m_flags
& XFS_MOUNT_GRPID
)
2086 seq_printf(m
, "," MNTOPT_GRPID
);
2088 if (mp
->m_qflags
& XFS_UQUOTA_ACCT
) {
2089 if (mp
->m_qflags
& XFS_UQUOTA_ENFD
)
2090 seq_puts(m
, "," MNTOPT_USRQUOTA
);
2092 seq_puts(m
, "," MNTOPT_UQUOTANOENF
);
2095 if (mp
->m_qflags
& XFS_PQUOTA_ACCT
) {
2096 if (mp
->m_qflags
& XFS_OQUOTA_ENFD
)
2097 seq_puts(m
, "," MNTOPT_PRJQUOTA
);
2099 seq_puts(m
, "," MNTOPT_PQUOTANOENF
);
2102 if (mp
->m_qflags
& XFS_GQUOTA_ACCT
) {
2103 if (mp
->m_qflags
& XFS_OQUOTA_ENFD
)
2104 seq_puts(m
, "," MNTOPT_GRPQUOTA
);
2106 seq_puts(m
, "," MNTOPT_GQUOTANOENF
);
2109 if (!(mp
->m_qflags
& XFS_ALL_QUOTA_ACCT
))
2110 seq_puts(m
, "," MNTOPT_NOQUOTA
);
2112 if (mp
->m_flags
& XFS_MOUNT_DMAPI
)
2113 seq_puts(m
, "," MNTOPT_DMAPI
);
2118 * Second stage of a freeze. The data is already frozen so we only
2119 * need to take care of themetadata. Once that's done write a dummy
2120 * record to dirty the log in case of a crash while frozen.
2126 xfs_attr_quiesce(mp
);
2127 xfs_fs_log_dummy(mp
);