2 * Copyright (c) 2007-2008 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * $DragonFly: src/sys/vfs/hammer/hammer_ondisk.c,v 1.76 2008/08/29 20:19:08 dillon Exp $
37 * Manage HAMMER's on-disk structures. These routines are primarily
38 * responsible for interfacing with the kernel's I/O subsystem and for
39 * managing in-memory structures.
43 #include <sys/fcntl.h>
44 #include <sys/nlookup.h>
48 static void hammer_free_volume(hammer_volume_t volume);
49 static int hammer_load_volume(hammer_volume_t volume);
50 static int hammer_load_buffer(hammer_buffer_t buffer, int isnew);
51 static int hammer_load_node(hammer_transaction_t trans,
52 hammer_node_t node, int isnew);
53 static void _hammer_rel_node(hammer_node_t node, int locked);
56 hammer_vol_rb_compare(hammer_volume_t vol1, hammer_volume_t vol2)
58 if (vol1->vol_no < vol2->vol_no)
60 if (vol1->vol_no > vol2->vol_no)
66 * hammer_buffer structures are indexed via their zoneX_offset, not
70 hammer_buf_rb_compare(hammer_buffer_t buf1, hammer_buffer_t buf2)
72 if (buf1->zoneX_offset < buf2->zoneX_offset)
74 if (buf1->zoneX_offset > buf2->zoneX_offset)
80 hammer_nod_rb_compare(hammer_node_t node1, hammer_node_t node2)
82 if (node1->node_offset < node2->node_offset)
84 if (node1->node_offset > node2->node_offset)
89 RB_GENERATE2(hammer_vol_rb_tree, hammer_volume, rb_node,
90 hammer_vol_rb_compare, int32_t, vol_no);
91 RB_GENERATE2(hammer_buf_rb_tree, hammer_buffer, rb_node,
92 hammer_buf_rb_compare, hammer_off_t, zoneX_offset);
93 RB_GENERATE2(hammer_nod_rb_tree, hammer_node, rb_node,
94 hammer_nod_rb_compare, hammer_off_t, node_offset);
96 /************************************************************************
98 ************************************************************************
100 * Load a HAMMER volume by name. Returns 0 on success or a positive error
101 * code on failure. Volumes must be loaded at mount time, get_volume() will
102 * not load a new volume.
104 * Calls made to hammer_load_volume() or single-threaded
107 hammer_install_volume(struct hammer_mount *hmp, const char *volname,
111 hammer_volume_t volume;
112 struct hammer_volume_ondisk *ondisk;
113 struct nlookupdata nd;
114 struct buf *bp = NULL;
120 ronly = ((mp->mnt_flag & MNT_RDONLY) ? 1 : 0);
123 * Allocate a volume structure
125 ++hammer_count_volumes;
126 volume = kmalloc(sizeof(*volume), hmp->m_misc, M_WAITOK|M_ZERO);
127 volume->vol_name = kstrdup(volname, hmp->m_misc);
128 volume->io.hmp = hmp; /* bootstrap */
129 hammer_io_init(&volume->io, volume, HAMMER_STRUCTURE_VOLUME);
130 volume->io.offset = 0LL;
131 volume->io.bytes = HAMMER_BUFSIZE;
134 * Get the device vnode
137 error = nlookup_init(&nd, volume->vol_name, UIO_SYSSPACE, NLC_FOLLOW);
139 error = nlookup(&nd);
141 error = cache_vref(&nd.nl_nch, nd.nl_cred, &volume->devvp);
145 volume->devvp = devvp;
149 if (vn_isdisk(volume->devvp, &error)) {
150 error = vfs_mountedon(volume->devvp);
153 if (error == 0 && vcount(volume->devvp) > 0)
156 vn_lock(volume->devvp, LK_EXCLUSIVE | LK_RETRY);
157 error = vinvalbuf(volume->devvp, V_SAVE, 0, 0);
159 error = VOP_OPEN(volume->devvp,
160 (ronly ? FREAD : FREAD|FWRITE),
163 vn_unlock(volume->devvp);
166 hammer_free_volume(volume);
169 volume->devvp->v_rdev->si_mountpoint = mp;
173 * Extract the volume number from the volume header and do various
176 error = bread(volume->devvp, 0LL, HAMMER_BUFSIZE, &bp);
179 ondisk = (void *)bp->b_data;
180 if (ondisk->vol_signature != HAMMER_FSBUF_VOLUME) {
181 kprintf("hammer_mount: volume %s has an invalid header\n",
186 volume->vol_no = ondisk->vol_no;
187 volume->buffer_base = ondisk->vol_buf_beg;
188 volume->vol_flags = ondisk->vol_flags;
189 volume->nblocks = ondisk->vol_nblocks;
190 volume->maxbuf_off = HAMMER_ENCODE_RAW_BUFFER(volume->vol_no,
191 ondisk->vol_buf_end - ondisk->vol_buf_beg);
192 volume->maxraw_off = ondisk->vol_buf_end;
194 if (RB_EMPTY(&hmp->rb_vols_root)) {
195 hmp->fsid = ondisk->vol_fsid;
196 } else if (bcmp(&hmp->fsid, &ondisk->vol_fsid, sizeof(uuid_t))) {
197 kprintf("hammer_mount: volume %s's fsid does not match "
198 "other volumes\n", volume->vol_name);
204 * Insert the volume structure into the red-black tree.
206 if (RB_INSERT(hammer_vol_rb_tree, &hmp->rb_vols_root, volume)) {
207 kprintf("hammer_mount: volume %s has a duplicate vol_no %d\n",
208 volume->vol_name, volume->vol_no);
213 * Set the root volume . HAMMER special cases rootvol the structure.
214 * We do not hold a ref because this would prevent related I/O
215 * from being flushed.
217 if (error == 0 && ondisk->vol_rootvol == ondisk->vol_no) {
218 hmp->rootvol = volume;
219 hmp->nvolumes = ondisk->vol_count;
224 hmp->mp->mnt_stat.f_blocks += ondisk->vol0_stat_bigblocks *
225 (HAMMER_LARGEBLOCK_SIZE / HAMMER_BUFSIZE);
226 hmp->mp->mnt_vstat.f_blocks += ondisk->vol0_stat_bigblocks *
227 (HAMMER_LARGEBLOCK_SIZE / HAMMER_BUFSIZE);
233 /*vinvalbuf(volume->devvp, V_SAVE, 0, 0);*/
235 volume->devvp->v_rdev->si_mountpoint = NULL;
236 VOP_CLOSE(volume->devvp, ronly ? FREAD : FREAD|FWRITE);
237 hammer_free_volume(volume);
243 * This is called for each volume when updating the mount point from
244 * read-write to read-only or vise-versa.
247 hammer_adjust_volume_mode(hammer_volume_t volume, void *data __unused)
250 vn_lock(volume->devvp, LK_EXCLUSIVE | LK_RETRY);
251 if (volume->io.hmp->ronly) {
252 /* do not call vinvalbuf */
253 VOP_OPEN(volume->devvp, FREAD, FSCRED, NULL);
254 VOP_CLOSE(volume->devvp, FREAD|FWRITE);
256 /* do not call vinvalbuf */
257 VOP_OPEN(volume->devvp, FREAD|FWRITE, FSCRED, NULL);
258 VOP_CLOSE(volume->devvp, FREAD);
260 vn_unlock(volume->devvp);
266 * Unload and free a HAMMER volume. Must return >= 0 to continue scan
267 * so returns -1 on failure.
270 hammer_unload_volume(hammer_volume_t volume, void *data __unused)
272 hammer_mount_t hmp = volume->io.hmp;
273 int ronly = ((hmp->mp->mnt_flag & MNT_RDONLY) ? 1 : 0);
276 * Clean up the root volume pointer, which is held unlocked in hmp.
278 if (hmp->rootvol == volume)
282 * We must not flush a dirty buffer to disk on umount. It should
283 * have already been dealt with by the flusher, or we may be in
284 * catastrophic failure.
286 hammer_io_clear_modify(&volume->io, 1);
287 volume->io.waitdep = 1;
290 * Clean up the persistent ref ioerror might have on the volume
292 if (volume->io.ioerror) {
293 volume->io.ioerror = 0;
294 hammer_rel(&volume->io.lock);
298 * This should release the bp. Releasing the volume with flush set
299 * implies the interlock is set.
301 hammer_ref_interlock_true(&volume->io.lock);
302 hammer_rel_volume(volume, 1);
303 KKASSERT(volume->io.bp == NULL);
306 * There should be no references on the volume, no clusters, and
309 KKASSERT(hammer_norefs(&volume->io.lock));
311 volume->ondisk = NULL;
313 if (volume->devvp->v_rdev &&
314 volume->devvp->v_rdev->si_mountpoint == hmp->mp
316 volume->devvp->v_rdev->si_mountpoint = NULL;
320 * Make sure we don't sync anything to disk if we
321 * are in read-only mode (1) or critically-errored
322 * (2). Note that there may be dirty buffers in
323 * normal read-only mode from crash recovery.
325 vinvalbuf(volume->devvp, 0, 0, 0);
326 VOP_CLOSE(volume->devvp, FREAD);
329 * Normal termination, save any dirty buffers
330 * (XXX there really shouldn't be any).
332 vinvalbuf(volume->devvp, V_SAVE, 0, 0);
333 VOP_CLOSE(volume->devvp, FREAD|FWRITE);
338 * Destroy the structure
340 RB_REMOVE(hammer_vol_rb_tree, &hmp->rb_vols_root, volume);
341 hammer_free_volume(volume);
347 hammer_free_volume(hammer_volume_t volume)
349 hammer_mount_t hmp = volume->io.hmp;
351 if (volume->vol_name) {
352 kfree(volume->vol_name, hmp->m_misc);
353 volume->vol_name = NULL;
356 vrele(volume->devvp);
357 volume->devvp = NULL;
359 --hammer_count_volumes;
360 kfree(volume, hmp->m_misc);
364 * Get a HAMMER volume. The volume must already exist.
367 hammer_get_volume(struct hammer_mount *hmp, int32_t vol_no, int *errorp)
369 struct hammer_volume *volume;
372 * Locate the volume structure
374 volume = RB_LOOKUP(hammer_vol_rb_tree, &hmp->rb_vols_root, vol_no);
375 if (volume == NULL) {
381 * Reference the volume, load/check the data on the 0->1 transition.
382 * hammer_load_volume() will dispose of the interlock on return,
383 * and also clean up the ref count on error.
385 if (hammer_ref_interlock(&volume->io.lock)) {
386 *errorp = hammer_load_volume(volume);
390 KKASSERT(volume->ondisk);
397 hammer_ref_volume(hammer_volume_t volume)
402 * Reference the volume and deal with the check condition used to
403 * load its ondisk info.
405 if (hammer_ref_interlock(&volume->io.lock)) {
406 error = hammer_load_volume(volume);
408 KKASSERT(volume->ondisk);
415 hammer_get_root_volume(struct hammer_mount *hmp, int *errorp)
417 hammer_volume_t volume;
419 volume = hmp->rootvol;
420 KKASSERT(volume != NULL);
423 * Reference the volume and deal with the check condition used to
424 * load its ondisk info.
426 if (hammer_ref_interlock(&volume->io.lock)) {
427 *errorp = hammer_load_volume(volume);
431 KKASSERT(volume->ondisk);
438 * Load a volume's on-disk information. The volume must be referenced and
439 * the interlock is held on call. The interlock will be released on return.
440 * The reference will also be released on return if an error occurs.
443 hammer_load_volume(hammer_volume_t volume)
447 if (volume->ondisk == NULL) {
448 error = hammer_io_read(volume->devvp, &volume->io,
451 volume->ondisk = (void *)volume->io.bp->b_data;
452 hammer_ref_interlock_done(&volume->io.lock);
454 hammer_rel_volume(volume, 1);
463 * Release a previously acquired reference on the volume.
465 * Volumes are not unloaded from memory during normal operation.
468 hammer_rel_volume(hammer_volume_t volume, int locked)
472 if (hammer_rel_interlock(&volume->io.lock, locked)) {
473 volume->ondisk = NULL;
474 bp = hammer_io_release(&volume->io, locked);
475 hammer_rel_interlock_done(&volume->io.lock, locked);
482 hammer_mountcheck_volumes(struct hammer_mount *hmp)
487 for (i = 0; i < hmp->nvolumes; ++i) {
488 vol = RB_LOOKUP(hammer_vol_rb_tree, &hmp->rb_vols_root, i);
495 /************************************************************************
497 ************************************************************************
499 * Manage buffers. Currently most blockmap-backed zones are direct-mapped
500 * to zone-2 buffer offsets, without a translation stage. However, the
501 * hammer_buffer structure is indexed by its zoneX_offset, not its
504 * The proper zone must be maintained throughout the code-base all the way
505 * through to the big-block allocator, or routines like hammer_del_buffers()
506 * will not be able to locate all potentially conflicting buffers.
509 hammer_get_buffer(hammer_mount_t hmp, hammer_off_t buf_offset,
510 int bytes, int isnew, int *errorp)
512 hammer_buffer_t buffer;
513 hammer_volume_t volume;
514 hammer_off_t zone2_offset;
515 hammer_io_type_t iotype;
519 buf_offset &= ~HAMMER_BUFMASK64;
522 * Shortcut if the buffer is already cached
524 buffer = RB_LOOKUP(hammer_buf_rb_tree, &hmp->rb_bufs_root, buf_offset);
527 * Once refed the ondisk field will not be cleared by
528 * any other action. Shortcut the operation if the
529 * ondisk structure is valid.
531 if (hammer_ref_interlock(&buffer->io.lock) == 0) {
532 hammer_io_advance(&buffer->io);
533 KKASSERT(buffer->ondisk);
539 * 0->1 transition or defered 0->1 transition (CHECK),
540 * interlock now held. Shortcut if ondisk is already
543 ++hammer_count_refedbufs;
544 if (buffer->ondisk) {
545 hammer_io_advance(&buffer->io);
546 hammer_ref_interlock_done(&buffer->io.lock);
552 * The buffer is no longer loose if it has a ref, and
553 * cannot become loose once it gains a ref. Loose
554 * buffers will never be in a modified state. This should
555 * only occur on the 0->1 transition of refs.
557 * lose_list can be modified via a biodone() interrupt.
559 if (buffer->io.mod_list == &hmp->lose_list) {
560 crit_enter(); /* biodone race against list */
561 TAILQ_REMOVE(buffer->io.mod_list, &buffer->io,
564 buffer->io.mod_list = NULL;
565 KKASSERT(buffer->io.modified == 0);
571 * What is the buffer class?
573 zone = HAMMER_ZONE_DECODE(buf_offset);
576 case HAMMER_ZONE_LARGE_DATA_INDEX:
577 case HAMMER_ZONE_SMALL_DATA_INDEX:
578 iotype = HAMMER_STRUCTURE_DATA_BUFFER;
580 case HAMMER_ZONE_UNDO_INDEX:
581 iotype = HAMMER_STRUCTURE_UNDO_BUFFER;
583 case HAMMER_ZONE_META_INDEX:
586 * NOTE: inode data and directory entries are placed in this
587 * zone. inode atime/mtime is updated in-place and thus
588 * buffers containing inodes must be synchronized as
589 * meta-buffers, same as buffers containing B-Tree info.
591 iotype = HAMMER_STRUCTURE_META_BUFFER;
596 * Handle blockmap offset translations
598 if (zone >= HAMMER_ZONE_BTREE_INDEX) {
599 zone2_offset = hammer_blockmap_lookup(hmp, buf_offset, errorp);
600 } else if (zone == HAMMER_ZONE_UNDO_INDEX) {
601 zone2_offset = hammer_undo_lookup(hmp, buf_offset, errorp);
603 KKASSERT(zone == HAMMER_ZONE_RAW_BUFFER_INDEX);
604 zone2_offset = buf_offset;
611 * NOTE: zone2_offset and maxbuf_off are both full zone-2 offset
614 KKASSERT((zone2_offset & HAMMER_OFF_ZONE_MASK) ==
615 HAMMER_ZONE_RAW_BUFFER);
616 vol_no = HAMMER_VOL_DECODE(zone2_offset);
617 volume = hammer_get_volume(hmp, vol_no, errorp);
621 KKASSERT(zone2_offset < volume->maxbuf_off);
624 * Allocate a new buffer structure. We will check for races later.
626 ++hammer_count_buffers;
627 buffer = kmalloc(sizeof(*buffer), hmp->m_misc,
628 M_WAITOK|M_ZERO|M_USE_RESERVE);
629 buffer->zone2_offset = zone2_offset;
630 buffer->zoneX_offset = buf_offset;
632 hammer_io_init(&buffer->io, volume, iotype);
633 buffer->io.offset = volume->ondisk->vol_buf_beg +
634 (zone2_offset & HAMMER_OFF_SHORT_MASK);
635 buffer->io.bytes = bytes;
636 TAILQ_INIT(&buffer->clist);
637 hammer_ref_interlock_true(&buffer->io.lock);
640 * Insert the buffer into the RB tree and handle late collisions.
642 if (RB_INSERT(hammer_buf_rb_tree, &hmp->rb_bufs_root, buffer)) {
643 hammer_rel_volume(volume, 0);
644 buffer->io.volume = NULL; /* safety */
645 if (hammer_rel_interlock(&buffer->io.lock, 1)) /* safety */
646 hammer_rel_interlock_done(&buffer->io.lock, 1);
647 --hammer_count_buffers;
648 kfree(buffer, hmp->m_misc);
651 ++hammer_count_refedbufs;
655 * The buffer is referenced and interlocked. Load the buffer
656 * if necessary. hammer_load_buffer() deals with the interlock
657 * and, if an error is returned, also deals with the ref.
659 if (buffer->ondisk == NULL) {
660 *errorp = hammer_load_buffer(buffer, isnew);
664 hammer_io_advance(&buffer->io);
665 hammer_ref_interlock_done(&buffer->io.lock);
672 * This is used by the direct-read code to deal with large-data buffers
673 * created by the reblocker and mirror-write code. The direct-read code
674 * bypasses the HAMMER buffer subsystem and so any aliased dirty or write-
675 * running hammer buffers must be fully synced to disk before we can issue
678 * This code path is not considered critical as only the rebocker and
679 * mirror-write code will create large-data buffers via the HAMMER buffer
680 * subsystem. They do that because they operate at the B-Tree level and
681 * do not access the vnode/inode structures.
684 hammer_sync_buffers(hammer_mount_t hmp, hammer_off_t base_offset, int bytes)
686 hammer_buffer_t buffer;
689 KKASSERT((base_offset & HAMMER_OFF_ZONE_MASK) ==
690 HAMMER_ZONE_LARGE_DATA);
693 buffer = RB_LOOKUP(hammer_buf_rb_tree, &hmp->rb_bufs_root,
695 if (buffer && (buffer->io.modified || buffer->io.running)) {
696 error = hammer_ref_buffer(buffer);
698 hammer_io_wait(&buffer->io);
699 if (buffer->io.modified) {
700 hammer_io_write_interlock(&buffer->io);
701 hammer_io_flush(&buffer->io, 0);
702 hammer_io_done_interlock(&buffer->io);
703 hammer_io_wait(&buffer->io);
705 hammer_rel_buffer(buffer, 0);
708 base_offset += HAMMER_BUFSIZE;
709 bytes -= HAMMER_BUFSIZE;
714 * Destroy all buffers covering the specified zoneX offset range. This
715 * is called when the related blockmap layer2 entry is freed or when
716 * a direct write bypasses our buffer/buffer-cache subsystem.
718 * The buffers may be referenced by the caller itself. Setting reclaim
719 * will cause the buffer to be destroyed when it's ref count reaches zero.
721 * Return 0 on success, EAGAIN if some buffers could not be destroyed due
722 * to additional references held by other threads, or some other (typically
726 hammer_del_buffers(hammer_mount_t hmp, hammer_off_t base_offset,
727 hammer_off_t zone2_offset, int bytes,
728 int report_conflicts)
730 hammer_buffer_t buffer;
731 hammer_volume_t volume;
736 vol_no = HAMMER_VOL_DECODE(zone2_offset);
737 volume = hammer_get_volume(hmp, vol_no, &ret_error);
738 KKASSERT(ret_error == 0);
741 buffer = RB_LOOKUP(hammer_buf_rb_tree, &hmp->rb_bufs_root,
744 error = hammer_ref_buffer(buffer);
745 if (hammer_debug_general & 0x20000) {
746 kprintf("hammer: delbufr %016jx "
748 (intmax_t)buffer->zoneX_offset,
750 hammer_oneref(&buffer->io.lock));
752 if (error == 0 && !hammer_oneref(&buffer->io.lock)) {
754 hammer_rel_buffer(buffer, 0);
757 KKASSERT(buffer->zone2_offset == zone2_offset);
758 hammer_io_clear_modify(&buffer->io, 1);
759 buffer->io.reclaim = 1;
760 buffer->io.waitdep = 1;
761 KKASSERT(buffer->io.volume == volume);
762 hammer_rel_buffer(buffer, 0);
765 error = hammer_io_inval(volume, zone2_offset);
769 if (report_conflicts ||
770 (hammer_debug_general & 0x8000)) {
771 kprintf("hammer_del_buffers: unable to "
772 "invalidate %016llx buffer=%p rep=%d\n",
773 (long long)base_offset,
774 buffer, report_conflicts);
777 base_offset += HAMMER_BUFSIZE;
778 zone2_offset += HAMMER_BUFSIZE;
779 bytes -= HAMMER_BUFSIZE;
781 hammer_rel_volume(volume, 0);
786 * Given a referenced and interlocked buffer load/validate the data.
788 * The buffer interlock will be released on return. If an error is
789 * returned the buffer reference will also be released (and the buffer
790 * pointer will thus be stale).
793 hammer_load_buffer(hammer_buffer_t buffer, int isnew)
795 hammer_volume_t volume;
799 * Load the buffer's on-disk info
801 volume = buffer->io.volume;
803 if (hammer_debug_io & 0x0004) {
804 kprintf("load_buffer %016llx %016llx isnew=%d od=%p\n",
805 (long long)buffer->zoneX_offset,
806 (long long)buffer->zone2_offset,
807 isnew, buffer->ondisk);
810 if (buffer->ondisk == NULL) {
812 * Issue the read or generate a new buffer. When reading
813 * the limit argument controls any read-ahead clustering
814 * hammer_io_read() is allowed to do.
816 * We cannot read-ahead in the large-data zone and we cannot
817 * cross a largeblock boundary as the next largeblock might
818 * use a different buffer size.
821 error = hammer_io_new(volume->devvp, &buffer->io);
822 } else if ((buffer->zoneX_offset & HAMMER_OFF_ZONE_MASK) ==
823 HAMMER_ZONE_LARGE_DATA) {
824 error = hammer_io_read(volume->devvp, &buffer->io,
829 limit = (buffer->zone2_offset +
830 HAMMER_LARGEBLOCK_MASK64) &
831 ~HAMMER_LARGEBLOCK_MASK64;
832 limit -= buffer->zone2_offset;
833 error = hammer_io_read(volume->devvp, &buffer->io,
837 buffer->ondisk = (void *)buffer->io.bp->b_data;
839 error = hammer_io_new(volume->devvp, &buffer->io);
844 hammer_io_advance(&buffer->io);
845 hammer_ref_interlock_done(&buffer->io.lock);
847 hammer_rel_buffer(buffer, 1);
853 * NOTE: Called from RB_SCAN, must return >= 0 for scan to continue.
854 * This routine is only called during unmount or when a volume is
857 * If data != NULL, it specifies a volume whoose buffers should
861 hammer_unload_buffer(hammer_buffer_t buffer, void *data)
863 struct hammer_volume *volume = (struct hammer_volume *) data;
866 * If volume != NULL we are only interested in unloading buffers
867 * associated with a particular volume.
869 if (volume != NULL && volume != buffer->io.volume)
873 * Clean up the persistent ref ioerror might have on the buffer
874 * and acquire a ref. Expect a 0->1 transition.
876 if (buffer->io.ioerror) {
877 buffer->io.ioerror = 0;
878 hammer_rel(&buffer->io.lock);
879 --hammer_count_refedbufs;
881 hammer_ref_interlock_true(&buffer->io.lock);
882 ++hammer_count_refedbufs;
885 * We must not flush a dirty buffer to disk on umount. It should
886 * have already been dealt with by the flusher, or we may be in
887 * catastrophic failure.
889 * We must set waitdep to ensure that a running buffer is waited
890 * on and released prior to us trying to unload the volume.
892 hammer_io_clear_modify(&buffer->io, 1);
893 hammer_flush_buffer_nodes(buffer);
894 buffer->io.waitdep = 1;
895 hammer_rel_buffer(buffer, 1);
900 * Reference a buffer that is either already referenced or via a specially
901 * handled pointer (aka cursor->buffer).
904 hammer_ref_buffer(hammer_buffer_t buffer)
910 * Acquire a ref, plus the buffer will be interlocked on the
913 locked = hammer_ref_interlock(&buffer->io.lock);
916 * At this point a biodone() will not touch the buffer other then
917 * incidental bits. However, lose_list can be modified via
918 * a biodone() interrupt.
922 if (buffer->io.mod_list == &buffer->io.hmp->lose_list) {
924 if (buffer->io.mod_list == &buffer->io.hmp->lose_list) {
925 TAILQ_REMOVE(buffer->io.mod_list, &buffer->io,
927 buffer->io.mod_list = NULL;
933 ++hammer_count_refedbufs;
934 error = hammer_load_buffer(buffer, 0);
935 /* NOTE: on error the buffer pointer is stale */
943 * Release a reference on the buffer. On the 1->0 transition the
944 * underlying IO will be released but the data reference is left
947 * Only destroy the structure itself if the related buffer cache buffer
948 * was disassociated from it. This ties the management of the structure
949 * to the buffer cache subsystem. buffer->ondisk determines whether the
950 * embedded io is referenced or not.
953 hammer_rel_buffer(hammer_buffer_t buffer, int locked)
955 hammer_volume_t volume;
957 struct buf *bp = NULL;
960 hmp = buffer->io.hmp;
962 if (hammer_rel_interlock(&buffer->io.lock, locked) == 0)
966 * hammer_count_refedbufs accounting. Decrement if we are in
967 * the error path or if CHECK is clear.
969 * If we are not in the error path and CHECK is set the caller
970 * probably just did a hammer_ref() and didn't account for it,
971 * so we don't account for the loss here.
973 if (locked || (buffer->io.lock.refs & HAMMER_REFS_CHECK) == 0)
974 --hammer_count_refedbufs;
977 * If the caller locked us or the normal released transitions
978 * from 1->0 (and acquired the lock) attempt to release the
979 * io. If the called locked us we tell hammer_io_release()
980 * to flush (which would be the unload or failure path).
982 bp = hammer_io_release(&buffer->io, locked);
985 * If the buffer has no bp association and no refs we can destroy
988 * NOTE: It is impossible for any associated B-Tree nodes to have
989 * refs if the buffer has no additional refs.
991 if (buffer->io.bp == NULL && hammer_norefs(&buffer->io.lock)) {
992 RB_REMOVE(hammer_buf_rb_tree,
993 &buffer->io.hmp->rb_bufs_root,
995 volume = buffer->io.volume;
996 buffer->io.volume = NULL; /* sanity */
997 hammer_rel_volume(volume, 0);
998 hammer_io_clear_modlist(&buffer->io);
999 hammer_flush_buffer_nodes(buffer);
1000 KKASSERT(TAILQ_EMPTY(&buffer->clist));
1007 hammer_rel_interlock_done(&buffer->io.lock, locked);
1011 --hammer_count_buffers;
1012 kfree(buffer, hmp->m_misc);
1017 * Access the filesystem buffer containing the specified hammer offset.
1018 * buf_offset is a conglomeration of the volume number and vol_buf_beg
1019 * relative buffer offset. It must also have bit 55 set to be valid.
1020 * (see hammer_off_t in hammer_disk.h).
1022 * Any prior buffer in *bufferp will be released and replaced by the
1025 * NOTE: The buffer is indexed via its zoneX_offset but we allow the
1026 * passed cached *bufferp to match against either zoneX or zone2.
1030 _hammer_bread(hammer_mount_t hmp, hammer_off_t buf_offset, int bytes,
1031 int *errorp, struct hammer_buffer **bufferp)
1033 hammer_buffer_t buffer;
1034 int32_t xoff = (int32_t)buf_offset & HAMMER_BUFMASK;
1036 buf_offset &= ~HAMMER_BUFMASK64;
1037 KKASSERT((buf_offset & HAMMER_OFF_ZONE_MASK) != 0);
1040 if (buffer == NULL || (buffer->zone2_offset != buf_offset &&
1041 buffer->zoneX_offset != buf_offset)) {
1043 hammer_rel_buffer(buffer, 0);
1044 buffer = hammer_get_buffer(hmp, buf_offset, bytes, 0, errorp);
1051 * Return a pointer to the buffer data.
1056 return((char *)buffer->ondisk + xoff);
1060 hammer_bread(hammer_mount_t hmp, hammer_off_t buf_offset,
1061 int *errorp, struct hammer_buffer **bufferp)
1063 return(_hammer_bread(hmp, buf_offset, HAMMER_BUFSIZE, errorp, bufferp));
1067 hammer_bread_ext(hammer_mount_t hmp, hammer_off_t buf_offset, int bytes,
1068 int *errorp, struct hammer_buffer **bufferp)
1070 bytes = (bytes + HAMMER_BUFMASK) & ~HAMMER_BUFMASK;
1071 return(_hammer_bread(hmp, buf_offset, bytes, errorp, bufferp));
1075 * Access the filesystem buffer containing the specified hammer offset.
1076 * No disk read operation occurs. The result buffer may contain garbage.
1078 * Any prior buffer in *bufferp will be released and replaced by the
1081 * This function marks the buffer dirty but does not increment its
1082 * modify_refs count.
1086 _hammer_bnew(hammer_mount_t hmp, hammer_off_t buf_offset, int bytes,
1087 int *errorp, struct hammer_buffer **bufferp)
1089 hammer_buffer_t buffer;
1090 int32_t xoff = (int32_t)buf_offset & HAMMER_BUFMASK;
1092 buf_offset &= ~HAMMER_BUFMASK64;
1095 if (buffer == NULL || (buffer->zone2_offset != buf_offset &&
1096 buffer->zoneX_offset != buf_offset)) {
1098 hammer_rel_buffer(buffer, 0);
1099 buffer = hammer_get_buffer(hmp, buf_offset, bytes, 1, errorp);
1106 * Return a pointer to the buffer data.
1111 return((char *)buffer->ondisk + xoff);
1115 hammer_bnew(hammer_mount_t hmp, hammer_off_t buf_offset,
1116 int *errorp, struct hammer_buffer **bufferp)
1118 return(_hammer_bnew(hmp, buf_offset, HAMMER_BUFSIZE, errorp, bufferp));
1122 hammer_bnew_ext(hammer_mount_t hmp, hammer_off_t buf_offset, int bytes,
1123 int *errorp, struct hammer_buffer **bufferp)
1125 bytes = (bytes + HAMMER_BUFMASK) & ~HAMMER_BUFMASK;
1126 return(_hammer_bnew(hmp, buf_offset, bytes, errorp, bufferp));
1129 /************************************************************************
1131 ************************************************************************
1133 * Manage B-Tree nodes. B-Tree nodes represent the primary indexing
1134 * method used by the HAMMER filesystem.
1136 * Unlike other HAMMER structures, a hammer_node can be PASSIVELY
1137 * associated with its buffer, and will only referenced the buffer while
1138 * the node itself is referenced.
1140 * A hammer_node can also be passively associated with other HAMMER
1141 * structures, such as inodes, while retaining 0 references. These
1142 * associations can be cleared backwards using a pointer-to-pointer in
1145 * This allows the HAMMER implementation to cache hammer_nodes long-term
1146 * and short-cut a great deal of the infrastructure's complexity. In
1147 * most cases a cached node can be reacquired without having to dip into
1148 * either the buffer or cluster management code.
1150 * The caller must pass a referenced cluster on call and will retain
1151 * ownership of the reference on return. The node will acquire its own
1152 * additional references, if necessary.
1155 hammer_get_node(hammer_transaction_t trans, hammer_off_t node_offset,
1156 int isnew, int *errorp)
1158 hammer_mount_t hmp = trans->hmp;
1162 KKASSERT((node_offset & HAMMER_OFF_ZONE_MASK) == HAMMER_ZONE_BTREE);
1165 * Locate the structure, allocating one if necessary.
1168 node = RB_LOOKUP(hammer_nod_rb_tree, &hmp->rb_nods_root, node_offset);
1170 ++hammer_count_nodes;
1171 node = kmalloc(sizeof(*node), hmp->m_misc, M_WAITOK|M_ZERO|M_USE_RESERVE);
1172 node->node_offset = node_offset;
1174 TAILQ_INIT(&node->cursor_list);
1175 TAILQ_INIT(&node->cache_list);
1176 if (RB_INSERT(hammer_nod_rb_tree, &hmp->rb_nods_root, node)) {
1177 --hammer_count_nodes;
1178 kfree(node, hmp->m_misc);
1181 doload = hammer_ref_interlock_true(&node->lock);
1183 doload = hammer_ref_interlock(&node->lock);
1186 *errorp = hammer_load_node(trans, node, isnew);
1187 trans->flags |= HAMMER_TRANSF_DIDIO;
1191 KKASSERT(node->ondisk);
1193 hammer_io_advance(&node->buffer->io);
1199 * Reference an already-referenced node. 0->1 transitions should assert
1200 * so we do not have to deal with hammer_ref() setting CHECK.
1203 hammer_ref_node(hammer_node_t node)
1205 KKASSERT(hammer_isactive(&node->lock) && node->ondisk != NULL);
1206 hammer_ref(&node->lock);
1210 * Load a node's on-disk data reference. Called with the node referenced
1213 * On return the node interlock will be unlocked. If a non-zero error code
1214 * is returned the node will also be dereferenced (and the caller's pointer
1218 hammer_load_node(hammer_transaction_t trans, hammer_node_t node, int isnew)
1220 hammer_buffer_t buffer;
1221 hammer_off_t buf_offset;
1225 if (node->ondisk == NULL) {
1227 * This is a little confusing but the jist is that
1228 * node->buffer determines whether the node is on
1229 * the buffer's clist and node->ondisk determines
1230 * whether the buffer is referenced.
1232 * We could be racing a buffer release, in which case
1233 * node->buffer may become NULL while we are blocked
1234 * referencing the buffer.
1236 if ((buffer = node->buffer) != NULL) {
1237 error = hammer_ref_buffer(buffer);
1238 if (error == 0 && node->buffer == NULL) {
1239 TAILQ_INSERT_TAIL(&buffer->clist,
1241 node->buffer = buffer;
1244 buf_offset = node->node_offset & ~HAMMER_BUFMASK64;
1245 buffer = hammer_get_buffer(node->hmp, buf_offset,
1246 HAMMER_BUFSIZE, 0, &error);
1248 KKASSERT(error == 0);
1249 TAILQ_INSERT_TAIL(&buffer->clist,
1251 node->buffer = buffer;
1256 node->ondisk = (void *)((char *)buffer->ondisk +
1257 (node->node_offset & HAMMER_BUFMASK));
1260 * Check CRC. NOTE: Neither flag is set and the CRC is not
1261 * generated on new B-Tree nodes.
1264 (node->flags & HAMMER_NODE_CRCANY) == 0) {
1265 if (hammer_crc_test_btree(node->ondisk) == 0) {
1266 if (hammer_debug_critical)
1267 Debugger("CRC FAILED: B-TREE NODE");
1268 node->flags |= HAMMER_NODE_CRCBAD;
1270 node->flags |= HAMMER_NODE_CRCGOOD;
1274 if (node->flags & HAMMER_NODE_CRCBAD) {
1275 if (trans->flags & HAMMER_TRANSF_CRCDOM)
1282 _hammer_rel_node(node, 1);
1284 hammer_ref_interlock_done(&node->lock);
1290 * Safely reference a node, interlock against flushes via the IO subsystem.
1293 hammer_ref_node_safe(hammer_transaction_t trans, hammer_node_cache_t cache,
1301 doload = hammer_ref_interlock(&node->lock);
1303 *errorp = hammer_load_node(trans, node, 0);
1307 KKASSERT(node->ondisk);
1308 if (node->flags & HAMMER_NODE_CRCBAD) {
1309 if (trans->flags & HAMMER_TRANSF_CRCDOM)
1313 _hammer_rel_node(node, 0);
1326 * Release a hammer_node. On the last release the node dereferences
1327 * its underlying buffer and may or may not be destroyed.
1329 * If locked is non-zero the passed node has been interlocked by the
1330 * caller and we are in the failure/unload path, otherwise it has not and
1331 * we are doing a normal release.
1333 * This function will dispose of the interlock and the reference.
1334 * On return the node pointer is stale.
1337 _hammer_rel_node(hammer_node_t node, int locked)
1339 hammer_buffer_t buffer;
1342 * Deref the node. If this isn't the 1->0 transition we're basically
1343 * done. If locked is non-zero this function will just deref the
1344 * locked node and return TRUE, otherwise it will deref the locked
1345 * node and either lock and return TRUE on the 1->0 transition or
1346 * not lock and return FALSE.
1348 if (hammer_rel_interlock(&node->lock, locked) == 0)
1352 * Either locked was non-zero and we are interlocked, or the
1353 * hammer_rel_interlock() call returned non-zero and we are
1356 * The ref-count must still be decremented if locked != 0 so
1357 * the cleanup required still varies a bit.
1359 * hammer_flush_node() when called with 1 or 2 will dispose of
1360 * the lock and possible ref-count.
1362 if (node->ondisk == NULL) {
1363 hammer_flush_node(node, locked + 1);
1364 /* node is stale now */
1369 * Do not disassociate the node from the buffer if it represents
1370 * a modified B-Tree node that still needs its crc to be generated.
1372 if (node->flags & HAMMER_NODE_NEEDSCRC) {
1373 hammer_rel_interlock_done(&node->lock, locked);
1378 * Do final cleanups and then either destroy the node and leave it
1379 * passively cached. The buffer reference is removed regardless.
1381 buffer = node->buffer;
1382 node->ondisk = NULL;
1384 if ((node->flags & HAMMER_NODE_FLUSH) == 0) {
1388 hammer_rel_interlock_done(&node->lock, locked);
1393 hammer_flush_node(node, locked + 1);
1397 hammer_rel_buffer(buffer, 0);
1401 hammer_rel_node(hammer_node_t node)
1403 _hammer_rel_node(node, 0);
1407 * Free space on-media associated with a B-Tree node.
1410 hammer_delete_node(hammer_transaction_t trans, hammer_node_t node)
1412 KKASSERT((node->flags & HAMMER_NODE_DELETED) == 0);
1413 node->flags |= HAMMER_NODE_DELETED;
1414 hammer_blockmap_free(trans, node->node_offset, sizeof(*node->ondisk));
1418 * Passively cache a referenced hammer_node. The caller may release
1419 * the node on return.
1422 hammer_cache_node(hammer_node_cache_t cache, hammer_node_t node)
1425 * If the node doesn't exist, or is being deleted, don't cache it!
1427 * The node can only ever be NULL in the I/O failure path.
1429 if (node == NULL || (node->flags & HAMMER_NODE_DELETED))
1431 if (cache->node == node)
1434 hammer_uncache_node(cache);
1435 if (node->flags & HAMMER_NODE_DELETED)
1438 TAILQ_INSERT_TAIL(&node->cache_list, cache, entry);
1442 hammer_uncache_node(hammer_node_cache_t cache)
1446 if ((node = cache->node) != NULL) {
1447 TAILQ_REMOVE(&node->cache_list, cache, entry);
1449 if (TAILQ_EMPTY(&node->cache_list))
1450 hammer_flush_node(node, 0);
1455 * Remove a node's cache references and destroy the node if it has no
1456 * other references or backing store.
1458 * locked == 0 Normal unlocked operation
1459 * locked == 1 Call hammer_rel_interlock_done(..., 0);
1460 * locked == 2 Call hammer_rel_interlock_done(..., 1);
1462 * XXX for now this isn't even close to being MPSAFE so the refs check
1466 hammer_flush_node(hammer_node_t node, int locked)
1468 hammer_node_cache_t cache;
1469 hammer_buffer_t buffer;
1470 hammer_mount_t hmp = node->hmp;
1473 while ((cache = TAILQ_FIRST(&node->cache_list)) != NULL) {
1474 TAILQ_REMOVE(&node->cache_list, cache, entry);
1479 * NOTE: refs is predisposed if another thread is blocking and
1480 * will be larger than 0 in that case. We aren't MPSAFE
1483 if (node->ondisk == NULL && hammer_norefs(&node->lock)) {
1484 KKASSERT((node->flags & HAMMER_NODE_NEEDSCRC) == 0);
1485 RB_REMOVE(hammer_nod_rb_tree, &node->hmp->rb_nods_root, node);
1486 if ((buffer = node->buffer) != NULL) {
1487 node->buffer = NULL;
1488 TAILQ_REMOVE(&buffer->clist, node, entry);
1489 /* buffer is unreferenced because ondisk is NULL */
1497 * Deal with the interlock if locked == 1 or locked == 2.
1500 hammer_rel_interlock_done(&node->lock, locked - 1);
1503 * Destroy if requested
1506 --hammer_count_nodes;
1507 kfree(node, hmp->m_misc);
1512 * Flush passively cached B-Tree nodes associated with this buffer.
1513 * This is only called when the buffer is about to be destroyed, so
1514 * none of the nodes should have any references. The buffer is locked.
1516 * We may be interlocked with the buffer.
1519 hammer_flush_buffer_nodes(hammer_buffer_t buffer)
1523 while ((node = TAILQ_FIRST(&buffer->clist)) != NULL) {
1524 KKASSERT(node->ondisk == NULL);
1525 KKASSERT((node->flags & HAMMER_NODE_NEEDSCRC) == 0);
1527 if (hammer_try_interlock_norefs(&node->lock)) {
1528 hammer_ref(&node->lock);
1529 node->flags |= HAMMER_NODE_FLUSH;
1530 _hammer_rel_node(node, 1);
1532 KKASSERT(node->buffer != NULL);
1533 buffer = node->buffer;
1534 node->buffer = NULL;
1535 TAILQ_REMOVE(&buffer->clist, node, entry);
1536 /* buffer is unreferenced because ondisk is NULL */
1542 /************************************************************************
1544 ************************************************************************/
1547 * Allocate a B-Tree node.
1550 hammer_alloc_btree(hammer_transaction_t trans, hammer_off_t hint, int *errorp)
1552 hammer_buffer_t buffer = NULL;
1553 hammer_node_t node = NULL;
1554 hammer_off_t node_offset;
1556 node_offset = hammer_blockmap_alloc(trans, HAMMER_ZONE_BTREE_INDEX,
1557 sizeof(struct hammer_node_ondisk),
1560 node = hammer_get_node(trans, node_offset, 1, errorp);
1561 hammer_modify_node_noundo(trans, node);
1562 bzero(node->ondisk, sizeof(*node->ondisk));
1563 hammer_modify_node_done(node);
1566 hammer_rel_buffer(buffer, 0);
1571 * Allocate data. If the address of a data buffer is supplied then
1572 * any prior non-NULL *data_bufferp will be released and *data_bufferp
1573 * will be set to the related buffer. The caller must release it when
1574 * finally done. The initial *data_bufferp should be set to NULL by
1577 * The caller is responsible for making hammer_modify*() calls on the
1581 hammer_alloc_data(hammer_transaction_t trans, int32_t data_len,
1582 u_int16_t rec_type, hammer_off_t *data_offsetp,
1583 struct hammer_buffer **data_bufferp,
1584 hammer_off_t hint, int *errorp)
1594 case HAMMER_RECTYPE_INODE:
1595 case HAMMER_RECTYPE_DIRENTRY:
1596 case HAMMER_RECTYPE_EXT:
1597 case HAMMER_RECTYPE_FIX:
1598 case HAMMER_RECTYPE_PFS:
1599 case HAMMER_RECTYPE_SNAPSHOT:
1600 case HAMMER_RECTYPE_CONFIG:
1601 zone = HAMMER_ZONE_META_INDEX;
1603 case HAMMER_RECTYPE_DATA:
1604 case HAMMER_RECTYPE_DB:
1605 if (data_len <= HAMMER_BUFSIZE / 2) {
1606 zone = HAMMER_ZONE_SMALL_DATA_INDEX;
1608 data_len = (data_len + HAMMER_BUFMASK) &
1610 zone = HAMMER_ZONE_LARGE_DATA_INDEX;
1614 panic("hammer_alloc_data: rec_type %04x unknown",
1616 zone = 0; /* NOT REACHED */
1619 *data_offsetp = hammer_blockmap_alloc(trans, zone, data_len,
1624 if (*errorp == 0 && data_bufferp) {
1626 data = hammer_bread_ext(trans->hmp, *data_offsetp,
1627 data_len, errorp, data_bufferp);
1638 * Sync dirty buffers to the media and clean-up any loose ends.
1640 * These functions do not start the flusher going, they simply
1641 * queue everything up to the flusher.
1643 static int hammer_sync_scan1(struct mount *mp, struct vnode *vp, void *data);
1644 static int hammer_sync_scan2(struct mount *mp, struct vnode *vp, void *data);
1647 hammer_queue_inodes_flusher(hammer_mount_t hmp, int waitfor)
1649 struct hammer_sync_info info;
1652 info.waitfor = waitfor;
1653 if (waitfor == MNT_WAIT) {
1654 vmntvnodescan(hmp->mp, VMSC_GETVP|VMSC_ONEPASS,
1655 hammer_sync_scan1, hammer_sync_scan2, &info);
1657 vmntvnodescan(hmp->mp, VMSC_GETVP|VMSC_ONEPASS|VMSC_NOWAIT,
1658 hammer_sync_scan1, hammer_sync_scan2, &info);
1664 * Filesystem sync. If doing a synchronous sync make a second pass on
1665 * the vnodes in case any were already flushing during the first pass,
1666 * and activate the flusher twice (the second time brings the UNDO FIFO's
1667 * start position up to the end position after the first call).
1670 hammer_sync_hmp(hammer_mount_t hmp, int waitfor)
1672 struct hammer_sync_info info;
1675 info.waitfor = MNT_NOWAIT;
1676 vmntvnodescan(hmp->mp, VMSC_GETVP|VMSC_NOWAIT,
1677 hammer_sync_scan1, hammer_sync_scan2, &info);
1678 if (info.error == 0 && waitfor == MNT_WAIT) {
1679 info.waitfor = waitfor;
1680 vmntvnodescan(hmp->mp, VMSC_GETVP,
1681 hammer_sync_scan1, hammer_sync_scan2, &info);
1683 if (waitfor == MNT_WAIT) {
1684 hammer_flusher_sync(hmp);
1685 hammer_flusher_sync(hmp);
1687 hammer_flusher_async(hmp, NULL);
1688 hammer_flusher_async(hmp, NULL);
1694 hammer_sync_scan1(struct mount *mp, struct vnode *vp, void *data)
1696 struct hammer_inode *ip;
1699 if (vp->v_type == VNON || ip == NULL ||
1700 ((ip->flags & HAMMER_INODE_MODMASK) == 0 &&
1701 RB_EMPTY(&vp->v_rbdirty_tree))) {
1708 hammer_sync_scan2(struct mount *mp, struct vnode *vp, void *data)
1710 struct hammer_sync_info *info = data;
1711 struct hammer_inode *ip;
1715 if (vp->v_type == VNON || vp->v_type == VBAD ||
1716 ((ip->flags & HAMMER_INODE_MODMASK) == 0 &&
1717 RB_EMPTY(&vp->v_rbdirty_tree))) {
1720 error = VOP_FSYNC(vp, MNT_NOWAIT, 0);
1722 info->error = error;