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 hammer_io_clear_error_noassert(&volume->io);
296 * This should release the bp. Releasing the volume with flush set
297 * implies the interlock is set.
299 hammer_ref_interlock_true(&volume->io.lock);
300 hammer_rel_volume(volume, 1);
301 KKASSERT(volume->io.bp == NULL);
304 * There should be no references on the volume, no clusters, and
307 KKASSERT(hammer_norefs(&volume->io.lock));
309 volume->ondisk = NULL;
311 if (volume->devvp->v_rdev &&
312 volume->devvp->v_rdev->si_mountpoint == hmp->mp
314 volume->devvp->v_rdev->si_mountpoint = NULL;
318 * Make sure we don't sync anything to disk if we
319 * are in read-only mode (1) or critically-errored
320 * (2). Note that there may be dirty buffers in
321 * normal read-only mode from crash recovery.
323 vinvalbuf(volume->devvp, 0, 0, 0);
324 VOP_CLOSE(volume->devvp, FREAD);
327 * Normal termination, save any dirty buffers
328 * (XXX there really shouldn't be any).
330 vinvalbuf(volume->devvp, V_SAVE, 0, 0);
331 VOP_CLOSE(volume->devvp, FREAD|FWRITE);
336 * Destroy the structure
338 RB_REMOVE(hammer_vol_rb_tree, &hmp->rb_vols_root, volume);
339 hammer_free_volume(volume);
345 hammer_free_volume(hammer_volume_t volume)
347 hammer_mount_t hmp = volume->io.hmp;
349 if (volume->vol_name) {
350 kfree(volume->vol_name, hmp->m_misc);
351 volume->vol_name = NULL;
354 vrele(volume->devvp);
355 volume->devvp = NULL;
357 --hammer_count_volumes;
358 kfree(volume, hmp->m_misc);
362 * Get a HAMMER volume. The volume must already exist.
365 hammer_get_volume(struct hammer_mount *hmp, int32_t vol_no, int *errorp)
367 struct hammer_volume *volume;
370 * Locate the volume structure
372 volume = RB_LOOKUP(hammer_vol_rb_tree, &hmp->rb_vols_root, vol_no);
373 if (volume == NULL) {
379 * Reference the volume, load/check the data on the 0->1 transition.
380 * hammer_load_volume() will dispose of the interlock on return,
381 * and also clean up the ref count on error.
383 if (hammer_ref_interlock(&volume->io.lock)) {
384 *errorp = hammer_load_volume(volume);
388 KKASSERT(volume->ondisk);
395 hammer_ref_volume(hammer_volume_t volume)
400 * Reference the volume and deal with the check condition used to
401 * load its ondisk info.
403 if (hammer_ref_interlock(&volume->io.lock)) {
404 error = hammer_load_volume(volume);
406 KKASSERT(volume->ondisk);
413 hammer_get_root_volume(struct hammer_mount *hmp, int *errorp)
415 hammer_volume_t volume;
417 volume = hmp->rootvol;
418 KKASSERT(volume != NULL);
421 * Reference the volume and deal with the check condition used to
422 * load its ondisk info.
424 if (hammer_ref_interlock(&volume->io.lock)) {
425 *errorp = hammer_load_volume(volume);
429 KKASSERT(volume->ondisk);
436 * Load a volume's on-disk information. The volume must be referenced and
437 * the interlock is held on call. The interlock will be released on return.
438 * The reference will also be released on return if an error occurs.
441 hammer_load_volume(hammer_volume_t volume)
445 if (volume->ondisk == NULL) {
446 error = hammer_io_read(volume->devvp, &volume->io,
449 volume->ondisk = (void *)volume->io.bp->b_data;
450 hammer_ref_interlock_done(&volume->io.lock);
452 hammer_rel_volume(volume, 1);
461 * Release a previously acquired reference on the volume.
463 * Volumes are not unloaded from memory during normal operation.
466 hammer_rel_volume(hammer_volume_t volume, int locked)
470 if (hammer_rel_interlock(&volume->io.lock, locked)) {
471 volume->ondisk = NULL;
472 bp = hammer_io_release(&volume->io, locked);
473 hammer_rel_interlock_done(&volume->io.lock, locked);
480 hammer_mountcheck_volumes(struct hammer_mount *hmp)
485 for (i = 0; i < hmp->nvolumes; ++i) {
486 vol = RB_LOOKUP(hammer_vol_rb_tree, &hmp->rb_vols_root, i);
493 /************************************************************************
495 ************************************************************************
497 * Manage buffers. Currently most blockmap-backed zones are direct-mapped
498 * to zone-2 buffer offsets, without a translation stage. However, the
499 * hammer_buffer structure is indexed by its zoneX_offset, not its
502 * The proper zone must be maintained throughout the code-base all the way
503 * through to the big-block allocator, or routines like hammer_del_buffers()
504 * will not be able to locate all potentially conflicting buffers.
507 hammer_get_buffer(hammer_mount_t hmp, hammer_off_t buf_offset,
508 int bytes, int isnew, int *errorp)
510 hammer_buffer_t buffer;
511 hammer_volume_t volume;
512 hammer_off_t zone2_offset;
513 hammer_io_type_t iotype;
517 buf_offset &= ~HAMMER_BUFMASK64;
520 * Shortcut if the buffer is already cached
522 buffer = RB_LOOKUP(hammer_buf_rb_tree, &hmp->rb_bufs_root, buf_offset);
525 * Once refed the ondisk field will not be cleared by
526 * any other action. Shortcut the operation if the
527 * ondisk structure is valid.
529 if (hammer_ref_interlock(&buffer->io.lock) == 0) {
530 hammer_io_advance(&buffer->io);
531 KKASSERT(buffer->ondisk);
537 * 0->1 transition or defered 0->1 transition (CHECK),
538 * interlock now held. Shortcut if ondisk is already
541 ++hammer_count_refedbufs;
542 if (buffer->ondisk) {
543 hammer_io_advance(&buffer->io);
544 hammer_ref_interlock_done(&buffer->io.lock);
550 * The buffer is no longer loose if it has a ref, and
551 * cannot become loose once it gains a ref. Loose
552 * buffers will never be in a modified state. This should
553 * only occur on the 0->1 transition of refs.
555 * lose_list can be modified via a biodone() interrupt
556 * so the io_token must be held.
558 if (buffer->io.mod_list == &hmp->lose_list) {
559 lwkt_gettoken(&hmp->io_token);
560 if (buffer->io.mod_list == &hmp->lose_list) {
561 TAILQ_REMOVE(buffer->io.mod_list, &buffer->io,
563 buffer->io.mod_list = NULL;
564 KKASSERT(buffer->io.modified == 0);
566 lwkt_reltoken(&hmp->io_token);
572 * What is the buffer class?
574 zone = HAMMER_ZONE_DECODE(buf_offset);
577 case HAMMER_ZONE_LARGE_DATA_INDEX:
578 case HAMMER_ZONE_SMALL_DATA_INDEX:
579 iotype = HAMMER_STRUCTURE_DATA_BUFFER;
581 case HAMMER_ZONE_UNDO_INDEX:
582 iotype = HAMMER_STRUCTURE_UNDO_BUFFER;
584 case HAMMER_ZONE_META_INDEX:
587 * NOTE: inode data and directory entries are placed in this
588 * zone. inode atime/mtime is updated in-place and thus
589 * buffers containing inodes must be synchronized as
590 * meta-buffers, same as buffers containing B-Tree info.
592 iotype = HAMMER_STRUCTURE_META_BUFFER;
597 * Handle blockmap offset translations
599 if (zone >= HAMMER_ZONE_BTREE_INDEX) {
600 zone2_offset = hammer_blockmap_lookup(hmp, buf_offset, errorp);
601 } else if (zone == HAMMER_ZONE_UNDO_INDEX) {
602 zone2_offset = hammer_undo_lookup(hmp, buf_offset, errorp);
604 KKASSERT(zone == HAMMER_ZONE_RAW_BUFFER_INDEX);
605 zone2_offset = buf_offset;
612 * NOTE: zone2_offset and maxbuf_off are both full zone-2 offset
615 KKASSERT((zone2_offset & HAMMER_OFF_ZONE_MASK) ==
616 HAMMER_ZONE_RAW_BUFFER);
617 vol_no = HAMMER_VOL_DECODE(zone2_offset);
618 volume = hammer_get_volume(hmp, vol_no, errorp);
622 KKASSERT(zone2_offset < volume->maxbuf_off);
625 * Allocate a new buffer structure. We will check for races later.
627 ++hammer_count_buffers;
628 buffer = kmalloc(sizeof(*buffer), hmp->m_misc,
629 M_WAITOK|M_ZERO|M_USE_RESERVE);
630 buffer->zone2_offset = zone2_offset;
631 buffer->zoneX_offset = buf_offset;
633 hammer_io_init(&buffer->io, volume, iotype);
634 buffer->io.offset = volume->ondisk->vol_buf_beg +
635 (zone2_offset & HAMMER_OFF_SHORT_MASK);
636 buffer->io.bytes = bytes;
637 TAILQ_INIT(&buffer->clist);
638 hammer_ref_interlock_true(&buffer->io.lock);
641 * Insert the buffer into the RB tree and handle late collisions.
643 if (RB_INSERT(hammer_buf_rb_tree, &hmp->rb_bufs_root, buffer)) {
644 hammer_rel_volume(volume, 0);
645 buffer->io.volume = NULL; /* safety */
646 if (hammer_rel_interlock(&buffer->io.lock, 1)) /* safety */
647 hammer_rel_interlock_done(&buffer->io.lock, 1);
648 --hammer_count_buffers;
649 kfree(buffer, hmp->m_misc);
652 ++hammer_count_refedbufs;
656 * The buffer is referenced and interlocked. Load the buffer
657 * if necessary. hammer_load_buffer() deals with the interlock
658 * and, if an error is returned, also deals with the ref.
660 if (buffer->ondisk == NULL) {
661 *errorp = hammer_load_buffer(buffer, isnew);
665 hammer_io_advance(&buffer->io);
666 hammer_ref_interlock_done(&buffer->io.lock);
673 * This is used by the direct-read code to deal with large-data buffers
674 * created by the reblocker and mirror-write code. The direct-read code
675 * bypasses the HAMMER buffer subsystem and so any aliased dirty or write-
676 * running hammer buffers must be fully synced to disk before we can issue
679 * This code path is not considered critical as only the rebocker and
680 * mirror-write code will create large-data buffers via the HAMMER buffer
681 * subsystem. They do that because they operate at the B-Tree level and
682 * do not access the vnode/inode structures.
685 hammer_sync_buffers(hammer_mount_t hmp, hammer_off_t base_offset, int bytes)
687 hammer_buffer_t buffer;
690 KKASSERT((base_offset & HAMMER_OFF_ZONE_MASK) ==
691 HAMMER_ZONE_LARGE_DATA);
694 buffer = RB_LOOKUP(hammer_buf_rb_tree, &hmp->rb_bufs_root,
696 if (buffer && (buffer->io.modified || buffer->io.running)) {
697 error = hammer_ref_buffer(buffer);
699 hammer_io_wait(&buffer->io);
700 if (buffer->io.modified) {
701 hammer_io_write_interlock(&buffer->io);
702 hammer_io_flush(&buffer->io, 0);
703 hammer_io_done_interlock(&buffer->io);
704 hammer_io_wait(&buffer->io);
706 hammer_rel_buffer(buffer, 0);
709 base_offset += HAMMER_BUFSIZE;
710 bytes -= HAMMER_BUFSIZE;
715 * Destroy all buffers covering the specified zoneX offset range. This
716 * is called when the related blockmap layer2 entry is freed or when
717 * a direct write bypasses our buffer/buffer-cache subsystem.
719 * The buffers may be referenced by the caller itself. Setting reclaim
720 * will cause the buffer to be destroyed when it's ref count reaches zero.
722 * Return 0 on success, EAGAIN if some buffers could not be destroyed due
723 * to additional references held by other threads, or some other (typically
727 hammer_del_buffers(hammer_mount_t hmp, hammer_off_t base_offset,
728 hammer_off_t zone2_offset, int bytes,
729 int report_conflicts)
731 hammer_buffer_t buffer;
732 hammer_volume_t volume;
737 vol_no = HAMMER_VOL_DECODE(zone2_offset);
738 volume = hammer_get_volume(hmp, vol_no, &ret_error);
739 KKASSERT(ret_error == 0);
742 buffer = RB_LOOKUP(hammer_buf_rb_tree, &hmp->rb_bufs_root,
745 error = hammer_ref_buffer(buffer);
746 if (hammer_debug_general & 0x20000) {
747 kprintf("hammer: delbufr %016jx "
749 (intmax_t)buffer->zoneX_offset,
751 hammer_oneref(&buffer->io.lock));
753 if (error == 0 && !hammer_oneref(&buffer->io.lock)) {
755 hammer_rel_buffer(buffer, 0);
758 KKASSERT(buffer->zone2_offset == zone2_offset);
759 hammer_io_clear_modify(&buffer->io, 1);
760 buffer->io.reclaim = 1;
761 buffer->io.waitdep = 1;
762 KKASSERT(buffer->io.volume == volume);
763 hammer_rel_buffer(buffer, 0);
766 error = hammer_io_inval(volume, zone2_offset);
770 if (report_conflicts ||
771 (hammer_debug_general & 0x8000)) {
772 kprintf("hammer_del_buffers: unable to "
773 "invalidate %016llx buffer=%p rep=%d\n",
774 (long long)base_offset,
775 buffer, report_conflicts);
778 base_offset += HAMMER_BUFSIZE;
779 zone2_offset += HAMMER_BUFSIZE;
780 bytes -= HAMMER_BUFSIZE;
782 hammer_rel_volume(volume, 0);
787 * Given a referenced and interlocked buffer load/validate the data.
789 * The buffer interlock will be released on return. If an error is
790 * returned the buffer reference will also be released (and the buffer
791 * pointer will thus be stale).
794 hammer_load_buffer(hammer_buffer_t buffer, int isnew)
796 hammer_volume_t volume;
800 * Load the buffer's on-disk info
802 volume = buffer->io.volume;
804 if (hammer_debug_io & 0x0004) {
805 kprintf("load_buffer %016llx %016llx isnew=%d od=%p\n",
806 (long long)buffer->zoneX_offset,
807 (long long)buffer->zone2_offset,
808 isnew, buffer->ondisk);
811 if (buffer->ondisk == NULL) {
813 * Issue the read or generate a new buffer. When reading
814 * the limit argument controls any read-ahead clustering
815 * hammer_io_read() is allowed to do.
817 * We cannot read-ahead in the large-data zone and we cannot
818 * cross a largeblock boundary as the next largeblock might
819 * use a different buffer size.
822 error = hammer_io_new(volume->devvp, &buffer->io);
823 } else if ((buffer->zoneX_offset & HAMMER_OFF_ZONE_MASK) ==
824 HAMMER_ZONE_LARGE_DATA) {
825 error = hammer_io_read(volume->devvp, &buffer->io,
830 limit = (buffer->zone2_offset +
831 HAMMER_LARGEBLOCK_MASK64) &
832 ~HAMMER_LARGEBLOCK_MASK64;
833 limit -= buffer->zone2_offset;
834 error = hammer_io_read(volume->devvp, &buffer->io,
838 buffer->ondisk = (void *)buffer->io.bp->b_data;
840 error = hammer_io_new(volume->devvp, &buffer->io);
845 hammer_io_advance(&buffer->io);
846 hammer_ref_interlock_done(&buffer->io.lock);
848 hammer_rel_buffer(buffer, 1);
854 * NOTE: Called from RB_SCAN, must return >= 0 for scan to continue.
855 * This routine is only called during unmount or when a volume is
858 * If data != NULL, it specifies a volume whoose buffers should
862 hammer_unload_buffer(hammer_buffer_t buffer, void *data)
864 struct hammer_volume *volume = (struct hammer_volume *) data;
867 * If volume != NULL we are only interested in unloading buffers
868 * associated with a particular volume.
870 if (volume != NULL && volume != buffer->io.volume)
874 * Clean up the persistent ref ioerror might have on the buffer
875 * and acquire a ref. Expect a 0->1 transition.
877 if (buffer->io.ioerror) {
878 hammer_io_clear_error_noassert(&buffer->io);
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)
911 * Acquire a ref, plus the buffer will be interlocked on the
914 locked = hammer_ref_interlock(&buffer->io.lock);
915 hmp = buffer->io.hmp;
918 * At this point a biodone() will not touch the buffer other then
919 * incidental bits. However, lose_list can be modified via
920 * a biodone() interrupt.
922 * No longer loose. lose_list requires the io_token.
924 if (buffer->io.mod_list == &hmp->lose_list) {
925 lwkt_gettoken(&hmp->io_token);
926 if (buffer->io.mod_list == &hmp->lose_list) {
927 TAILQ_REMOVE(buffer->io.mod_list, &buffer->io,
929 buffer->io.mod_list = NULL;
931 lwkt_reltoken(&hmp->io_token);
935 ++hammer_count_refedbufs;
936 error = hammer_load_buffer(buffer, 0);
937 /* NOTE: on error the buffer pointer is stale */
945 * Release a reference on the buffer. On the 1->0 transition the
946 * underlying IO will be released but the data reference is left
949 * Only destroy the structure itself if the related buffer cache buffer
950 * was disassociated from it. This ties the management of the structure
951 * to the buffer cache subsystem. buffer->ondisk determines whether the
952 * embedded io is referenced or not.
955 hammer_rel_buffer(hammer_buffer_t buffer, int locked)
957 hammer_volume_t volume;
959 struct buf *bp = NULL;
962 hmp = buffer->io.hmp;
964 if (hammer_rel_interlock(&buffer->io.lock, locked) == 0)
968 * hammer_count_refedbufs accounting. Decrement if we are in
969 * the error path or if CHECK is clear.
971 * If we are not in the error path and CHECK is set the caller
972 * probably just did a hammer_ref() and didn't account for it,
973 * so we don't account for the loss here.
975 if (locked || (buffer->io.lock.refs & HAMMER_REFS_CHECK) == 0)
976 --hammer_count_refedbufs;
979 * If the caller locked us or the normal released transitions
980 * from 1->0 (and acquired the lock) attempt to release the
981 * io. If the called locked us we tell hammer_io_release()
982 * to flush (which would be the unload or failure path).
984 bp = hammer_io_release(&buffer->io, locked);
987 * If the buffer has no bp association and no refs we can destroy
990 * NOTE: It is impossible for any associated B-Tree nodes to have
991 * refs if the buffer has no additional refs.
993 if (buffer->io.bp == NULL && hammer_norefs(&buffer->io.lock)) {
994 RB_REMOVE(hammer_buf_rb_tree,
995 &buffer->io.hmp->rb_bufs_root,
997 volume = buffer->io.volume;
998 buffer->io.volume = NULL; /* sanity */
999 hammer_rel_volume(volume, 0);
1000 hammer_io_clear_modlist(&buffer->io);
1001 hammer_flush_buffer_nodes(buffer);
1002 KKASSERT(TAILQ_EMPTY(&buffer->clist));
1009 hammer_rel_interlock_done(&buffer->io.lock, locked);
1013 --hammer_count_buffers;
1014 kfree(buffer, hmp->m_misc);
1019 * Access the filesystem buffer containing the specified hammer offset.
1020 * buf_offset is a conglomeration of the volume number and vol_buf_beg
1021 * relative buffer offset. It must also have bit 55 set to be valid.
1022 * (see hammer_off_t in hammer_disk.h).
1024 * Any prior buffer in *bufferp will be released and replaced by the
1027 * NOTE: The buffer is indexed via its zoneX_offset but we allow the
1028 * passed cached *bufferp to match against either zoneX or zone2.
1032 _hammer_bread(hammer_mount_t hmp, hammer_off_t buf_offset, int bytes,
1033 int *errorp, struct hammer_buffer **bufferp)
1035 hammer_buffer_t buffer;
1036 int32_t xoff = (int32_t)buf_offset & HAMMER_BUFMASK;
1038 buf_offset &= ~HAMMER_BUFMASK64;
1039 KKASSERT((buf_offset & HAMMER_OFF_ZONE_MASK) != 0);
1042 if (buffer == NULL || (buffer->zone2_offset != buf_offset &&
1043 buffer->zoneX_offset != buf_offset)) {
1045 hammer_rel_buffer(buffer, 0);
1046 buffer = hammer_get_buffer(hmp, buf_offset, bytes, 0, errorp);
1053 * Return a pointer to the buffer data.
1058 return((char *)buffer->ondisk + xoff);
1062 hammer_bread(hammer_mount_t hmp, hammer_off_t buf_offset,
1063 int *errorp, struct hammer_buffer **bufferp)
1065 return(_hammer_bread(hmp, buf_offset, HAMMER_BUFSIZE, errorp, bufferp));
1069 hammer_bread_ext(hammer_mount_t hmp, hammer_off_t buf_offset, int bytes,
1070 int *errorp, struct hammer_buffer **bufferp)
1072 bytes = (bytes + HAMMER_BUFMASK) & ~HAMMER_BUFMASK;
1073 return(_hammer_bread(hmp, buf_offset, bytes, errorp, bufferp));
1077 * Access the filesystem buffer containing the specified hammer offset.
1078 * No disk read operation occurs. The result buffer may contain garbage.
1080 * Any prior buffer in *bufferp will be released and replaced by the
1083 * This function marks the buffer dirty but does not increment its
1084 * modify_refs count.
1088 _hammer_bnew(hammer_mount_t hmp, hammer_off_t buf_offset, int bytes,
1089 int *errorp, struct hammer_buffer **bufferp)
1091 hammer_buffer_t buffer;
1092 int32_t xoff = (int32_t)buf_offset & HAMMER_BUFMASK;
1094 buf_offset &= ~HAMMER_BUFMASK64;
1097 if (buffer == NULL || (buffer->zone2_offset != buf_offset &&
1098 buffer->zoneX_offset != buf_offset)) {
1100 hammer_rel_buffer(buffer, 0);
1101 buffer = hammer_get_buffer(hmp, buf_offset, bytes, 1, errorp);
1108 * Return a pointer to the buffer data.
1113 return((char *)buffer->ondisk + xoff);
1117 hammer_bnew(hammer_mount_t hmp, hammer_off_t buf_offset,
1118 int *errorp, struct hammer_buffer **bufferp)
1120 return(_hammer_bnew(hmp, buf_offset, HAMMER_BUFSIZE, errorp, bufferp));
1124 hammer_bnew_ext(hammer_mount_t hmp, hammer_off_t buf_offset, int bytes,
1125 int *errorp, struct hammer_buffer **bufferp)
1127 bytes = (bytes + HAMMER_BUFMASK) & ~HAMMER_BUFMASK;
1128 return(_hammer_bnew(hmp, buf_offset, bytes, errorp, bufferp));
1131 /************************************************************************
1133 ************************************************************************
1135 * Manage B-Tree nodes. B-Tree nodes represent the primary indexing
1136 * method used by the HAMMER filesystem.
1138 * Unlike other HAMMER structures, a hammer_node can be PASSIVELY
1139 * associated with its buffer, and will only referenced the buffer while
1140 * the node itself is referenced.
1142 * A hammer_node can also be passively associated with other HAMMER
1143 * structures, such as inodes, while retaining 0 references. These
1144 * associations can be cleared backwards using a pointer-to-pointer in
1147 * This allows the HAMMER implementation to cache hammer_nodes long-term
1148 * and short-cut a great deal of the infrastructure's complexity. In
1149 * most cases a cached node can be reacquired without having to dip into
1150 * either the buffer or cluster management code.
1152 * The caller must pass a referenced cluster on call and will retain
1153 * ownership of the reference on return. The node will acquire its own
1154 * additional references, if necessary.
1157 hammer_get_node(hammer_transaction_t trans, hammer_off_t node_offset,
1158 int isnew, int *errorp)
1160 hammer_mount_t hmp = trans->hmp;
1164 KKASSERT((node_offset & HAMMER_OFF_ZONE_MASK) == HAMMER_ZONE_BTREE);
1167 * Locate the structure, allocating one if necessary.
1170 node = RB_LOOKUP(hammer_nod_rb_tree, &hmp->rb_nods_root, node_offset);
1172 ++hammer_count_nodes;
1173 node = kmalloc(sizeof(*node), hmp->m_misc, M_WAITOK|M_ZERO|M_USE_RESERVE);
1174 node->node_offset = node_offset;
1176 TAILQ_INIT(&node->cursor_list);
1177 TAILQ_INIT(&node->cache_list);
1178 if (RB_INSERT(hammer_nod_rb_tree, &hmp->rb_nods_root, node)) {
1179 --hammer_count_nodes;
1180 kfree(node, hmp->m_misc);
1183 doload = hammer_ref_interlock_true(&node->lock);
1185 doload = hammer_ref_interlock(&node->lock);
1188 *errorp = hammer_load_node(trans, node, isnew);
1189 trans->flags |= HAMMER_TRANSF_DIDIO;
1193 KKASSERT(node->ondisk);
1195 hammer_io_advance(&node->buffer->io);
1201 * Reference an already-referenced node. 0->1 transitions should assert
1202 * so we do not have to deal with hammer_ref() setting CHECK.
1205 hammer_ref_node(hammer_node_t node)
1207 KKASSERT(hammer_isactive(&node->lock) && node->ondisk != NULL);
1208 hammer_ref(&node->lock);
1212 * Load a node's on-disk data reference. Called with the node referenced
1215 * On return the node interlock will be unlocked. If a non-zero error code
1216 * is returned the node will also be dereferenced (and the caller's pointer
1220 hammer_load_node(hammer_transaction_t trans, hammer_node_t node, int isnew)
1222 hammer_buffer_t buffer;
1223 hammer_off_t buf_offset;
1227 if (node->ondisk == NULL) {
1229 * This is a little confusing but the jist is that
1230 * node->buffer determines whether the node is on
1231 * the buffer's clist and node->ondisk determines
1232 * whether the buffer is referenced.
1234 * We could be racing a buffer release, in which case
1235 * node->buffer may become NULL while we are blocked
1236 * referencing the buffer.
1238 if ((buffer = node->buffer) != NULL) {
1239 error = hammer_ref_buffer(buffer);
1240 if (error == 0 && node->buffer == NULL) {
1241 TAILQ_INSERT_TAIL(&buffer->clist,
1243 node->buffer = buffer;
1246 buf_offset = node->node_offset & ~HAMMER_BUFMASK64;
1247 buffer = hammer_get_buffer(node->hmp, buf_offset,
1248 HAMMER_BUFSIZE, 0, &error);
1250 KKASSERT(error == 0);
1251 TAILQ_INSERT_TAIL(&buffer->clist,
1253 node->buffer = buffer;
1258 node->ondisk = (void *)((char *)buffer->ondisk +
1259 (node->node_offset & HAMMER_BUFMASK));
1262 * Check CRC. NOTE: Neither flag is set and the CRC is not
1263 * generated on new B-Tree nodes.
1266 (node->flags & HAMMER_NODE_CRCANY) == 0) {
1267 if (hammer_crc_test_btree(node->ondisk) == 0) {
1268 if (hammer_debug_critical)
1269 Debugger("CRC FAILED: B-TREE NODE");
1270 node->flags |= HAMMER_NODE_CRCBAD;
1272 node->flags |= HAMMER_NODE_CRCGOOD;
1276 if (node->flags & HAMMER_NODE_CRCBAD) {
1277 if (trans->flags & HAMMER_TRANSF_CRCDOM)
1284 _hammer_rel_node(node, 1);
1286 hammer_ref_interlock_done(&node->lock);
1292 * Safely reference a node, interlock against flushes via the IO subsystem.
1295 hammer_ref_node_safe(hammer_transaction_t trans, hammer_node_cache_t cache,
1303 doload = hammer_ref_interlock(&node->lock);
1305 *errorp = hammer_load_node(trans, node, 0);
1309 KKASSERT(node->ondisk);
1310 if (node->flags & HAMMER_NODE_CRCBAD) {
1311 if (trans->flags & HAMMER_TRANSF_CRCDOM)
1315 _hammer_rel_node(node, 0);
1328 * Release a hammer_node. On the last release the node dereferences
1329 * its underlying buffer and may or may not be destroyed.
1331 * If locked is non-zero the passed node has been interlocked by the
1332 * caller and we are in the failure/unload path, otherwise it has not and
1333 * we are doing a normal release.
1335 * This function will dispose of the interlock and the reference.
1336 * On return the node pointer is stale.
1339 _hammer_rel_node(hammer_node_t node, int locked)
1341 hammer_buffer_t buffer;
1344 * Deref the node. If this isn't the 1->0 transition we're basically
1345 * done. If locked is non-zero this function will just deref the
1346 * locked node and return TRUE, otherwise it will deref the locked
1347 * node and either lock and return TRUE on the 1->0 transition or
1348 * not lock and return FALSE.
1350 if (hammer_rel_interlock(&node->lock, locked) == 0)
1354 * Either locked was non-zero and we are interlocked, or the
1355 * hammer_rel_interlock() call returned non-zero and we are
1358 * The ref-count must still be decremented if locked != 0 so
1359 * the cleanup required still varies a bit.
1361 * hammer_flush_node() when called with 1 or 2 will dispose of
1362 * the lock and possible ref-count.
1364 if (node->ondisk == NULL) {
1365 hammer_flush_node(node, locked + 1);
1366 /* node is stale now */
1371 * Do not disassociate the node from the buffer if it represents
1372 * a modified B-Tree node that still needs its crc to be generated.
1374 if (node->flags & HAMMER_NODE_NEEDSCRC) {
1375 hammer_rel_interlock_done(&node->lock, locked);
1380 * Do final cleanups and then either destroy the node and leave it
1381 * passively cached. The buffer reference is removed regardless.
1383 buffer = node->buffer;
1384 node->ondisk = NULL;
1386 if ((node->flags & HAMMER_NODE_FLUSH) == 0) {
1390 hammer_rel_interlock_done(&node->lock, locked);
1395 hammer_flush_node(node, locked + 1);
1399 hammer_rel_buffer(buffer, 0);
1403 hammer_rel_node(hammer_node_t node)
1405 _hammer_rel_node(node, 0);
1409 * Free space on-media associated with a B-Tree node.
1412 hammer_delete_node(hammer_transaction_t trans, hammer_node_t node)
1414 KKASSERT((node->flags & HAMMER_NODE_DELETED) == 0);
1415 node->flags |= HAMMER_NODE_DELETED;
1416 hammer_blockmap_free(trans, node->node_offset, sizeof(*node->ondisk));
1420 * Passively cache a referenced hammer_node. The caller may release
1421 * the node on return.
1424 hammer_cache_node(hammer_node_cache_t cache, hammer_node_t node)
1427 * If the node doesn't exist, or is being deleted, don't cache it!
1429 * The node can only ever be NULL in the I/O failure path.
1431 if (node == NULL || (node->flags & HAMMER_NODE_DELETED))
1433 if (cache->node == node)
1436 hammer_uncache_node(cache);
1437 if (node->flags & HAMMER_NODE_DELETED)
1440 TAILQ_INSERT_TAIL(&node->cache_list, cache, entry);
1444 hammer_uncache_node(hammer_node_cache_t cache)
1448 if ((node = cache->node) != NULL) {
1449 TAILQ_REMOVE(&node->cache_list, cache, entry);
1451 if (TAILQ_EMPTY(&node->cache_list))
1452 hammer_flush_node(node, 0);
1457 * Remove a node's cache references and destroy the node if it has no
1458 * other references or backing store.
1460 * locked == 0 Normal unlocked operation
1461 * locked == 1 Call hammer_rel_interlock_done(..., 0);
1462 * locked == 2 Call hammer_rel_interlock_done(..., 1);
1464 * XXX for now this isn't even close to being MPSAFE so the refs check
1468 hammer_flush_node(hammer_node_t node, int locked)
1470 hammer_node_cache_t cache;
1471 hammer_buffer_t buffer;
1472 hammer_mount_t hmp = node->hmp;
1475 while ((cache = TAILQ_FIRST(&node->cache_list)) != NULL) {
1476 TAILQ_REMOVE(&node->cache_list, cache, entry);
1481 * NOTE: refs is predisposed if another thread is blocking and
1482 * will be larger than 0 in that case. We aren't MPSAFE
1485 if (node->ondisk == NULL && hammer_norefs(&node->lock)) {
1486 KKASSERT((node->flags & HAMMER_NODE_NEEDSCRC) == 0);
1487 RB_REMOVE(hammer_nod_rb_tree, &node->hmp->rb_nods_root, node);
1488 if ((buffer = node->buffer) != NULL) {
1489 node->buffer = NULL;
1490 TAILQ_REMOVE(&buffer->clist, node, entry);
1491 /* buffer is unreferenced because ondisk is NULL */
1499 * Deal with the interlock if locked == 1 or locked == 2.
1502 hammer_rel_interlock_done(&node->lock, locked - 1);
1505 * Destroy if requested
1508 --hammer_count_nodes;
1509 kfree(node, hmp->m_misc);
1514 * Flush passively cached B-Tree nodes associated with this buffer.
1515 * This is only called when the buffer is about to be destroyed, so
1516 * none of the nodes should have any references. The buffer is locked.
1518 * We may be interlocked with the buffer.
1521 hammer_flush_buffer_nodes(hammer_buffer_t buffer)
1525 while ((node = TAILQ_FIRST(&buffer->clist)) != NULL) {
1526 KKASSERT(node->ondisk == NULL);
1527 KKASSERT((node->flags & HAMMER_NODE_NEEDSCRC) == 0);
1529 if (hammer_try_interlock_norefs(&node->lock)) {
1530 hammer_ref(&node->lock);
1531 node->flags |= HAMMER_NODE_FLUSH;
1532 _hammer_rel_node(node, 1);
1534 KKASSERT(node->buffer != NULL);
1535 buffer = node->buffer;
1536 node->buffer = NULL;
1537 TAILQ_REMOVE(&buffer->clist, node, entry);
1538 /* buffer is unreferenced because ondisk is NULL */
1544 /************************************************************************
1546 ************************************************************************/
1549 * Allocate a B-Tree node.
1552 hammer_alloc_btree(hammer_transaction_t trans, hammer_off_t hint, int *errorp)
1554 hammer_buffer_t buffer = NULL;
1555 hammer_node_t node = NULL;
1556 hammer_off_t node_offset;
1558 node_offset = hammer_blockmap_alloc(trans, HAMMER_ZONE_BTREE_INDEX,
1559 sizeof(struct hammer_node_ondisk),
1562 node = hammer_get_node(trans, node_offset, 1, errorp);
1563 hammer_modify_node_noundo(trans, node);
1564 bzero(node->ondisk, sizeof(*node->ondisk));
1565 hammer_modify_node_done(node);
1568 hammer_rel_buffer(buffer, 0);
1573 * Allocate data. If the address of a data buffer is supplied then
1574 * any prior non-NULL *data_bufferp will be released and *data_bufferp
1575 * will be set to the related buffer. The caller must release it when
1576 * finally done. The initial *data_bufferp should be set to NULL by
1579 * The caller is responsible for making hammer_modify*() calls on the
1583 hammer_alloc_data(hammer_transaction_t trans, int32_t data_len,
1584 u_int16_t rec_type, hammer_off_t *data_offsetp,
1585 struct hammer_buffer **data_bufferp,
1586 hammer_off_t hint, int *errorp)
1596 case HAMMER_RECTYPE_INODE:
1597 case HAMMER_RECTYPE_DIRENTRY:
1598 case HAMMER_RECTYPE_EXT:
1599 case HAMMER_RECTYPE_FIX:
1600 case HAMMER_RECTYPE_PFS:
1601 case HAMMER_RECTYPE_SNAPSHOT:
1602 case HAMMER_RECTYPE_CONFIG:
1603 zone = HAMMER_ZONE_META_INDEX;
1605 case HAMMER_RECTYPE_DATA:
1606 case HAMMER_RECTYPE_DB:
1607 if (data_len <= HAMMER_BUFSIZE / 2) {
1608 zone = HAMMER_ZONE_SMALL_DATA_INDEX;
1610 data_len = (data_len + HAMMER_BUFMASK) &
1612 zone = HAMMER_ZONE_LARGE_DATA_INDEX;
1616 panic("hammer_alloc_data: rec_type %04x unknown",
1618 zone = 0; /* NOT REACHED */
1621 *data_offsetp = hammer_blockmap_alloc(trans, zone, data_len,
1626 if (*errorp == 0 && data_bufferp) {
1628 data = hammer_bread_ext(trans->hmp, *data_offsetp,
1629 data_len, errorp, data_bufferp);
1640 * Sync dirty buffers to the media and clean-up any loose ends.
1642 * These functions do not start the flusher going, they simply
1643 * queue everything up to the flusher.
1645 static int hammer_sync_scan1(struct mount *mp, struct vnode *vp, void *data);
1646 static int hammer_sync_scan2(struct mount *mp, struct vnode *vp, void *data);
1649 hammer_queue_inodes_flusher(hammer_mount_t hmp, int waitfor)
1651 struct hammer_sync_info info;
1654 info.waitfor = waitfor;
1655 if (waitfor == MNT_WAIT) {
1656 vmntvnodescan(hmp->mp, VMSC_GETVP|VMSC_ONEPASS,
1657 hammer_sync_scan1, hammer_sync_scan2, &info);
1659 vmntvnodescan(hmp->mp, VMSC_GETVP|VMSC_ONEPASS|VMSC_NOWAIT,
1660 hammer_sync_scan1, hammer_sync_scan2, &info);
1666 * Filesystem sync. If doing a synchronous sync make a second pass on
1667 * the vnodes in case any were already flushing during the first pass,
1668 * and activate the flusher twice (the second time brings the UNDO FIFO's
1669 * start position up to the end position after the first call).
1672 hammer_sync_hmp(hammer_mount_t hmp, int waitfor)
1674 struct hammer_sync_info info;
1677 info.waitfor = MNT_NOWAIT;
1678 vmntvnodescan(hmp->mp, VMSC_GETVP|VMSC_NOWAIT,
1679 hammer_sync_scan1, hammer_sync_scan2, &info);
1680 if (info.error == 0 && waitfor == MNT_WAIT) {
1681 info.waitfor = waitfor;
1682 vmntvnodescan(hmp->mp, VMSC_GETVP,
1683 hammer_sync_scan1, hammer_sync_scan2, &info);
1685 if (waitfor == MNT_WAIT) {
1686 hammer_flusher_sync(hmp);
1687 hammer_flusher_sync(hmp);
1689 hammer_flusher_async(hmp, NULL);
1690 hammer_flusher_async(hmp, NULL);
1696 hammer_sync_scan1(struct mount *mp, struct vnode *vp, void *data)
1698 struct hammer_inode *ip;
1701 if (vp->v_type == VNON || ip == NULL ||
1702 ((ip->flags & HAMMER_INODE_MODMASK) == 0 &&
1703 RB_EMPTY(&vp->v_rbdirty_tree))) {
1710 hammer_sync_scan2(struct mount *mp, struct vnode *vp, void *data)
1712 struct hammer_sync_info *info = data;
1713 struct hammer_inode *ip;
1717 if (vp->v_type == VNON || vp->v_type == VBAD ||
1718 ((ip->flags & HAMMER_INODE_MODMASK) == 0 &&
1719 RB_EMPTY(&vp->v_rbdirty_tree))) {
1722 error = VOP_FSYNC(vp, MNT_NOWAIT, 0);
1724 info->error = error;