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_io.c,v 1.39 2008/06/11 22:33:21 dillon Exp $
37 * IO Primitives and buffer cache management
39 * All major data-tracking structures in HAMMER contain a struct hammer_io
40 * which is used to manage their backing store. We use filesystem buffers
41 * for backing store and we leave them passively associated with their
44 * If the kernel tries to destroy a passively associated buf which we cannot
45 * yet let go we set B_LOCKED in the buffer and then actively released it
50 #include <sys/fcntl.h>
51 #include <sys/nlookup.h>
55 static void hammer_io_modify(hammer_io_t io
, int count
);
56 static void hammer_io_deallocate(struct buf
*bp
);
59 * Initialize a new, already-zero'd hammer_io structure, or reinitialize
60 * an existing hammer_io structure which may have switched to another type.
63 hammer_io_init(hammer_io_t io
, hammer_mount_t hmp
, enum hammer_io_type type
)
70 * Helper routine to disassociate a buffer cache buffer from an I/O
71 * structure. Called with the io structure exclusively locked.
73 * The io may have 0 or 1 references depending on who called us. The
74 * caller is responsible for dealing with the refs.
76 * This call can only be made when no action is required on the buffer.
77 * HAMMER must own the buffer (released == 0) since we mess around with it.
80 hammer_io_disassociate(hammer_io_structure_t iou
, int elseit
)
82 struct buf
*bp
= iou
->io
.bp
;
84 KKASSERT(iou
->io
.modified
== 0);
85 KKASSERT(LIST_FIRST(&bp
->b_dep
) == (void *)iou
);
90 * If the buffer was locked someone wanted to get rid of it.
92 if (bp
->b_flags
& B_LOCKED
) {
93 --hammer_count_io_locked
;
94 bp
->b_flags
&= ~B_LOCKED
;
98 * elseit is 0 when called from the kernel path, the caller is
99 * holding the buffer locked and will deal with its final disposition.
102 KKASSERT(iou
->io
.released
== 0);
103 iou
->io
.released
= 1;
105 bp
->b_flags
|= B_NOCACHE
|B_RELBUF
;
108 KKASSERT(iou
->io
.released
);
112 switch(iou
->io
.type
) {
113 case HAMMER_STRUCTURE_VOLUME
:
114 iou
->volume
.ondisk
= NULL
;
116 case HAMMER_STRUCTURE_DATA_BUFFER
:
117 case HAMMER_STRUCTURE_META_BUFFER
:
118 case HAMMER_STRUCTURE_UNDO_BUFFER
:
119 iou
->buffer
.ondisk
= NULL
;
125 * Wait for any physical IO to complete
128 hammer_io_wait(hammer_io_t io
)
132 tsleep_interlock(io
);
135 tsleep(io
, 0, "hmrflw", 0);
136 if (io
->running
== 0)
138 tsleep_interlock(io
);
140 if (io
->running
== 0)
148 * Wait for all hammer_io-initated write I/O's to complete. This is not
149 * supposed to count direct I/O's but some can leak through (for
150 * non-full-sized direct I/Os).
153 hammer_io_wait_all(hammer_mount_t hmp
, const char *ident
)
156 while (hmp
->io_running_count
)
157 tsleep(&hmp
->io_running_count
, 0, ident
, 0);
161 #define HAMMER_MAXRA 4
164 * Load bp for a HAMMER structure. The io must be exclusively locked by
167 * This routine is mostly used on meta-data and small-data blocks. Generally
168 * speaking HAMMER assumes some locality of reference and will cluster
171 * Note that clustering occurs at the device layer, not the logical layer.
172 * If the buffers do not apply to the current operation they may apply to
176 hammer_io_read(struct vnode
*devvp
, struct hammer_io
*io
, hammer_off_t limit
)
181 if ((bp
= io
->bp
) == NULL
) {
182 ++hammer_count_io_running_read
;
183 error
= cluster_read(devvp
, limit
, io
->offset
,
186 HAMMER_CLUSTER_BUFS
, &io
->bp
);
187 --hammer_count_io_running_read
;
190 bp
->b_ops
= &hammer_bioops
;
191 KKASSERT(LIST_FIRST(&bp
->b_dep
) == NULL
);
192 LIST_INSERT_HEAD(&bp
->b_dep
, &io
->worklist
, node
);
195 KKASSERT(io
->modified
== 0);
196 KKASSERT(io
->running
== 0);
197 KKASSERT(io
->waiting
== 0);
198 io
->released
= 0; /* we hold an active lock on bp */
206 * Similar to hammer_io_read() but returns a zero'd out buffer instead.
207 * Must be called with the IO exclusively locked.
209 * vfs_bio_clrbuf() is kinda nasty, enforce serialization against background
210 * I/O by forcing the buffer to not be in a released state before calling
213 * This function will also mark the IO as modified but it will not
214 * increment the modify_refs count.
217 hammer_io_new(struct vnode
*devvp
, struct hammer_io
*io
)
221 if ((bp
= io
->bp
) == NULL
) {
222 io
->bp
= getblk(devvp
, io
->offset
, HAMMER_BUFSIZE
, 0, 0);
224 bp
->b_ops
= &hammer_bioops
;
225 KKASSERT(LIST_FIRST(&bp
->b_dep
) == NULL
);
226 LIST_INSERT_HEAD(&bp
->b_dep
, &io
->worklist
, node
);
228 KKASSERT(io
->running
== 0);
238 hammer_io_modify(io
, 0);
244 * Remove potential device level aliases against buffers managed by high level
248 hammer_io_inval(hammer_volume_t volume
, hammer_off_t zone2_offset
)
250 hammer_io_structure_t iou
;
251 hammer_off_t phys_offset
;
254 phys_offset
= volume
->ondisk
->vol_buf_beg
+
255 (zone2_offset
& HAMMER_OFF_SHORT_MASK
);
256 if (findblk(volume
->devvp
, phys_offset
)) {
257 bp
= getblk(volume
->devvp
, phys_offset
, HAMMER_BUFSIZE
, 0, 0);
258 if ((iou
= (void *)LIST_FIRST(&bp
->b_dep
)) != NULL
) {
259 hammer_io_clear_modify(&iou
->io
);
262 hammer_io_deallocate(bp
);
264 KKASSERT((bp
->b_flags
& B_LOCKED
) == 0);
266 bp
->b_flags
|= B_NOCACHE
|B_RELBUF
;
273 * This routine is called on the last reference to a hammer structure.
274 * The io is usually locked exclusively (but may not be during unmount).
276 * This routine is responsible for the disposition of the buffer cache
277 * buffer backing the IO. Only pure-data and undo buffers can be handed
278 * back to the kernel. Volume and meta-data buffers must be retained
279 * by HAMMER until explicitly flushed by the backend.
282 hammer_io_release(struct hammer_io
*io
, int flush
)
284 union hammer_io_structure
*iou
= (void *)io
;
287 if ((bp
= io
->bp
) == NULL
)
291 * Try to flush a dirty IO to disk if asked to by the
292 * caller or if the kernel tried to flush the buffer in the past.
294 * Kernel-initiated flushes are only allowed for pure-data buffers.
295 * meta-data and volume buffers can only be flushed explicitly
301 } else if (bp
->b_flags
& B_LOCKED
) {
303 case HAMMER_STRUCTURE_DATA_BUFFER
:
304 case HAMMER_STRUCTURE_UNDO_BUFFER
:
310 } /* else no explicit request to flush the buffer */
314 * Wait for the IO to complete if asked to.
316 if (io
->waitdep
&& io
->running
) {
321 * Return control of the buffer to the kernel (with the provisio
322 * that our bioops can override kernel decisions with regards to
325 if ((flush
|| io
->reclaim
) && io
->modified
== 0 && io
->running
== 0) {
327 * Always disassociate the bp if an explicit flush
328 * was requested and the IO completed with no error
329 * (so unmount can really clean up the structure).
336 hammer_io_disassociate((hammer_io_structure_t
)io
, 1);
337 } else if (io
->modified
) {
339 * Only certain IO types can be released to the kernel.
340 * volume and meta-data IO types must be explicitly flushed
344 case HAMMER_STRUCTURE_DATA_BUFFER
:
345 case HAMMER_STRUCTURE_UNDO_BUFFER
:
346 if (io
->released
== 0) {
354 } else if (io
->released
== 0) {
356 * Clean buffers can be generally released to the kernel.
357 * We leave the bp passively associated with the HAMMER
358 * structure and use bioops to disconnect it later on
359 * if the kernel wants to discard the buffer.
361 if (bp
->b_flags
& B_LOCKED
) {
362 hammer_io_disassociate(iou
, 1);
365 hammer_io_disassociate(iou
, 1);
373 * A released buffer is passively associate with our
374 * hammer_io structure. The kernel cannot destroy it
375 * without making a bioops call. If the kernel (B_LOCKED)
376 * or we (reclaim) requested that the buffer be destroyed
377 * we destroy it, otherwise we do a quick get/release to
378 * reset its position in the kernel's LRU list.
380 * Leaving the buffer passively associated allows us to
381 * use the kernel's LRU buffer flushing mechanisms rather
382 * then rolling our own.
385 if (io
->running
== 0) {
387 if ((bp
->b_flags
& B_LOCKED
) || io
->reclaim
) {
389 hammer_io_disassociate(iou
, 1);
399 * This routine is called with a locked IO when a flush is desired and
400 * no other references to the structure exists other then ours. This
401 * routine is ONLY called when HAMMER believes it is safe to flush a
402 * potentially modified buffer out.
405 hammer_io_flush(struct hammer_io
*io
)
410 * Degenerate case - nothing to flush if nothing is dirty.
412 if (io
->modified
== 0) {
417 KKASSERT(io
->modify_refs
<= 0);
420 * Acquire ownership of the bp, particularly before we clear our
423 * We are going to bawrite() this bp. Don't leave a window where
424 * io->released is set, we actually own the bp rather then our
430 /* BUF_KERNPROC(io->bp); */
431 /* io->released = 0; */
432 KKASSERT(io
->released
);
433 KKASSERT(io
->bp
== bp
);
438 * Acquire exclusive access to the bp and then clear the modified
439 * state of the buffer prior to issuing I/O to interlock any
440 * modifications made while the I/O is in progress. This shouldn't
441 * happen anyway but losing data would be worse. The modified bit
442 * will be rechecked after the IO completes.
444 * This is only legal when lock.refs == 1 (otherwise we might clear
445 * the modified bit while there are still users of the cluster
446 * modifying the data).
448 * Do this before potentially blocking so any attempt to modify the
449 * ondisk while we are blocked blocks waiting for us.
451 hammer_io_clear_modify(io
);
454 * Transfer ownership to the kernel and initiate I/O.
457 ++io
->hmp
->io_running_count
;
458 ++hammer_count_io_running_write
;
462 /************************************************************************
464 ************************************************************************
466 * These routines deal with dependancies created when IO buffers get
467 * modified. The caller must call hammer_modify_*() on a referenced
468 * HAMMER structure prior to modifying its on-disk data.
470 * Any intent to modify an IO buffer acquires the related bp and imposes
471 * various write ordering dependancies.
475 * Mark a HAMMER structure as undergoing modification. Meta-data buffers
476 * are locked until the flusher can deal with them, pure data buffers
477 * can be written out.
481 hammer_io_modify(hammer_io_t io
, int count
)
483 struct hammer_mount
*hmp
= io
->hmp
;
486 * io->modify_refs must be >= 0
488 while (io
->modify_refs
< 0) {
490 tsleep(io
, 0, "hmrmod", 0);
494 * Shortcut if nothing to do.
496 KKASSERT(io
->lock
.refs
!= 0 && io
->bp
!= NULL
);
497 io
->modify_refs
+= count
;
498 if (io
->modified
&& io
->released
== 0)
501 hammer_lock_ex(&io
->lock
);
502 if (io
->modified
== 0) {
503 KKASSERT(io
->mod_list
== NULL
);
505 case HAMMER_STRUCTURE_VOLUME
:
506 io
->mod_list
= &hmp
->volu_list
;
507 ++hmp
->locked_dirty_count
;
508 ++hammer_count_dirtybufs
;
510 case HAMMER_STRUCTURE_META_BUFFER
:
511 io
->mod_list
= &hmp
->meta_list
;
512 ++hmp
->locked_dirty_count
;
513 ++hammer_count_dirtybufs
;
515 case HAMMER_STRUCTURE_UNDO_BUFFER
:
516 io
->mod_list
= &hmp
->undo_list
;
518 case HAMMER_STRUCTURE_DATA_BUFFER
:
519 io
->mod_list
= &hmp
->data_list
;
522 TAILQ_INSERT_TAIL(io
->mod_list
, io
, mod_entry
);
527 BUF_KERNPROC(io
->bp
);
529 KKASSERT(io
->modified
!= 0);
531 hammer_unlock(&io
->lock
);
536 hammer_io_modify_done(hammer_io_t io
)
538 KKASSERT(io
->modify_refs
> 0);
540 if (io
->modify_refs
== 0 && io
->waitmod
) {
547 hammer_io_write_interlock(hammer_io_t io
)
549 while (io
->modify_refs
!= 0) {
551 tsleep(io
, 0, "hmrmod", 0);
553 io
->modify_refs
= -1;
557 hammer_io_done_interlock(hammer_io_t io
)
559 KKASSERT(io
->modify_refs
== -1);
568 * Caller intends to modify a volume's ondisk structure.
570 * This is only allowed if we are the flusher or we have a ref on the
574 hammer_modify_volume(hammer_transaction_t trans
, hammer_volume_t volume
,
577 KKASSERT (trans
== NULL
|| trans
->sync_lock_refs
> 0);
579 hammer_io_modify(&volume
->io
, 1);
581 intptr_t rel_offset
= (intptr_t)base
- (intptr_t)volume
->ondisk
;
582 KKASSERT((rel_offset
& ~(intptr_t)HAMMER_BUFMASK
) == 0);
583 hammer_generate_undo(trans
, &volume
->io
,
584 HAMMER_ENCODE_RAW_VOLUME(volume
->vol_no
, rel_offset
),
590 * Caller intends to modify a buffer's ondisk structure.
592 * This is only allowed if we are the flusher or we have a ref on the
596 hammer_modify_buffer(hammer_transaction_t trans
, hammer_buffer_t buffer
,
599 KKASSERT (trans
== NULL
|| trans
->sync_lock_refs
> 0);
601 hammer_io_modify(&buffer
->io
, 1);
603 intptr_t rel_offset
= (intptr_t)base
- (intptr_t)buffer
->ondisk
;
604 KKASSERT((rel_offset
& ~(intptr_t)HAMMER_BUFMASK
) == 0);
605 hammer_generate_undo(trans
, &buffer
->io
,
606 buffer
->zone2_offset
+ rel_offset
,
612 hammer_modify_volume_done(hammer_volume_t volume
)
614 hammer_io_modify_done(&volume
->io
);
618 hammer_modify_buffer_done(hammer_buffer_t buffer
)
620 hammer_io_modify_done(&buffer
->io
);
624 * Mark an entity as not being dirty any more.
627 hammer_io_clear_modify(struct hammer_io
*io
)
630 KKASSERT(io
->mod_list
!= NULL
);
631 if (io
->mod_list
== &io
->hmp
->volu_list
||
632 io
->mod_list
== &io
->hmp
->meta_list
) {
633 --io
->hmp
->locked_dirty_count
;
634 --hammer_count_dirtybufs
;
636 TAILQ_REMOVE(io
->mod_list
, io
, mod_entry
);
643 * Clear the IO's modify list. Even though the IO is no longer modified
644 * it may still be on the lose_list. This routine is called just before
645 * the governing hammer_buffer is destroyed.
648 hammer_io_clear_modlist(struct hammer_io
*io
)
651 crit_enter(); /* biodone race against list */
652 KKASSERT(io
->mod_list
== &io
->hmp
->lose_list
);
653 TAILQ_REMOVE(io
->mod_list
, io
, mod_entry
);
659 /************************************************************************
661 ************************************************************************
666 * Pre-IO initiation kernel callback - cluster build only
669 hammer_io_start(struct buf
*bp
)
674 * Post-IO completion kernel callback
676 * NOTE: HAMMER may modify a buffer after initiating I/O. The modified bit
677 * may also be set if we were marking a cluster header open. Only remove
678 * our dependancy if the modified bit is clear.
681 hammer_io_complete(struct buf
*bp
)
683 union hammer_io_structure
*iou
= (void *)LIST_FIRST(&bp
->b_dep
);
685 KKASSERT(iou
->io
.released
== 1);
687 if (iou
->io
.running
) {
688 --hammer_count_io_running_write
;
689 if (--iou
->io
.hmp
->io_running_count
== 0)
690 wakeup(&iou
->io
.hmp
->io_running_count
);
691 KKASSERT(iou
->io
.hmp
->io_running_count
>= 0);
696 * If no lock references remain and we can acquire the IO lock and
697 * someone at some point wanted us to flush (B_LOCKED test), then
698 * try to dispose of the IO.
700 if (iou
->io
.waiting
) {
706 * Someone wanted us to flush, try to clean out the buffer.
708 if ((bp
->b_flags
& B_LOCKED
) && iou
->io
.lock
.refs
== 0) {
709 KKASSERT(iou
->io
.modified
== 0);
710 --hammer_count_io_locked
;
711 bp
->b_flags
&= ~B_LOCKED
;
712 hammer_io_deallocate(bp
);
713 /* structure may be dead now */
718 * Callback from kernel when it wishes to deallocate a passively
719 * associated structure. This mostly occurs with clean buffers
720 * but it may be possible for a holding structure to be marked dirty
721 * while its buffer is passively associated.
723 * If we cannot disassociate we set B_LOCKED to prevent the buffer
724 * from getting reused.
726 * WARNING: Because this can be called directly by getnewbuf we cannot
727 * recurse into the tree. If a bp cannot be immediately disassociated
728 * our only recourse is to set B_LOCKED.
731 hammer_io_deallocate(struct buf
*bp
)
733 hammer_io_structure_t iou
= (void *)LIST_FIRST(&bp
->b_dep
);
735 KKASSERT((bp
->b_flags
& B_LOCKED
) == 0 && iou
->io
.running
== 0);
736 if (iou
->io
.lock
.refs
> 0 || iou
->io
.modified
) {
738 * It is not legal to disassociate a modified buffer. This
739 * case really shouldn't ever occur.
741 bp
->b_flags
|= B_LOCKED
;
742 ++hammer_count_io_locked
;
745 * Disassociate the BP. If the io has no refs left we
746 * have to add it to the loose list.
748 hammer_io_disassociate(iou
, 0);
749 if (iou
->io
.bp
== NULL
&&
750 iou
->io
.type
!= HAMMER_STRUCTURE_VOLUME
) {
751 KKASSERT(iou
->io
.mod_list
== NULL
);
752 crit_enter(); /* biodone race against list */
753 iou
->io
.mod_list
= &iou
->io
.hmp
->lose_list
;
754 TAILQ_INSERT_TAIL(iou
->io
.mod_list
, &iou
->io
, mod_entry
);
761 hammer_io_fsync(struct vnode
*vp
)
767 * NOTE: will not be called unless we tell the kernel about the
768 * bioops. Unused... we use the mount's VFS_SYNC instead.
771 hammer_io_sync(struct mount
*mp
)
777 hammer_io_movedeps(struct buf
*bp1
, struct buf
*bp2
)
782 * I/O pre-check for reading and writing. HAMMER only uses this for
783 * B_CACHE buffers so checkread just shouldn't happen, but if it does
786 * Writing is a different case. We don't want the kernel to try to write
787 * out a buffer that HAMMER may be modifying passively or which has a
788 * dependancy. In addition, kernel-demanded writes can only proceed for
789 * certain types of buffers (i.e. UNDO and DATA types). Other dirty
790 * buffer types can only be explicitly written by the flusher.
792 * checkwrite will only be called for bdwrite()n buffers. If we return
793 * success the kernel is guaranteed to initiate the buffer write.
796 hammer_io_checkread(struct buf
*bp
)
802 hammer_io_checkwrite(struct buf
*bp
)
804 hammer_io_t io
= (void *)LIST_FIRST(&bp
->b_dep
);
807 * This shouldn't happen under normal operation.
809 if (io
->type
== HAMMER_STRUCTURE_VOLUME
||
810 io
->type
== HAMMER_STRUCTURE_META_BUFFER
) {
812 panic("hammer_io_checkwrite: illegal buffer");
813 if ((bp
->b_flags
& B_LOCKED
) == 0) {
814 bp
->b_flags
|= B_LOCKED
;
815 ++hammer_count_io_locked
;
821 * We can only clear the modified bit if the IO is not currently
822 * undergoing modification. Otherwise we may miss changes.
824 if (io
->modify_refs
== 0 && io
->modified
)
825 hammer_io_clear_modify(io
);
828 * The kernel is going to start the IO, set io->running.
830 KKASSERT(io
->running
== 0);
832 ++io
->hmp
->io_running_count
;
833 ++hammer_count_io_running_write
;
838 * Return non-zero if we wish to delay the kernel's attempt to flush
839 * this buffer to disk.
842 hammer_io_countdeps(struct buf
*bp
, int n
)
847 struct bio_ops hammer_bioops
= {
848 .io_start
= hammer_io_start
,
849 .io_complete
= hammer_io_complete
,
850 .io_deallocate
= hammer_io_deallocate
,
851 .io_fsync
= hammer_io_fsync
,
852 .io_sync
= hammer_io_sync
,
853 .io_movedeps
= hammer_io_movedeps
,
854 .io_countdeps
= hammer_io_countdeps
,
855 .io_checkread
= hammer_io_checkread
,
856 .io_checkwrite
= hammer_io_checkwrite
,
859 /************************************************************************
861 ************************************************************************
863 * These functions operate directly on the buffer cache buffer associated
864 * with a front-end vnode rather then a back-end device vnode.
868 * Read a buffer associated with a front-end vnode directly from the
869 * disk media. The bio may be issued asynchronously.
871 * This function can takes a zone-2 or zone-X blockmap offset.
874 hammer_io_direct_read(hammer_mount_t hmp
, hammer_off_t data_offset
,
877 hammer_off_t zone2_offset
;
878 hammer_volume_t volume
;
884 if ((data_offset
& HAMMER_OFF_ZONE_MASK
) == HAMMER_ZONE_RAW_BUFFER
) {
885 zone2_offset
= data_offset
;
888 KKASSERT(data_offset
>= HAMMER_ZONE_BTREE
);
889 KKASSERT((data_offset
& HAMMER_BUFMASK
) == 0);
890 zone2_offset
= hammer_blockmap_lookup(hmp
, data_offset
, &error
);
893 vol_no
= HAMMER_VOL_DECODE(zone2_offset
);
894 volume
= hammer_get_volume(hmp
, vol_no
, &error
);
895 if (error
== 0 && zone2_offset
>= volume
->maxbuf_off
)
898 zone2_offset
&= HAMMER_OFF_SHORT_MASK
;
899 nbio
= push_bio(bio
);
900 nbio
->bio_offset
= volume
->ondisk
->vol_buf_beg
+
902 vn_strategy(volume
->devvp
, nbio
);
904 hammer_rel_volume(volume
, 0);
907 kprintf("hammer_direct_read: failed @ %016llx\n",
911 bp
->b_flags
|= B_ERROR
;
918 * Write a buffer associated with a front-end vnode directly to the
919 * disk media. The bio may be issued asynchronously.
922 hammer_io_direct_write(hammer_mount_t hmp
, hammer_btree_leaf_elm_t leaf
,
925 hammer_off_t buf_offset
;
926 hammer_off_t zone2_offset
;
927 hammer_volume_t volume
;
928 hammer_buffer_t buffer
;
935 buf_offset
= leaf
->data_offset
;
937 KKASSERT(buf_offset
> HAMMER_ZONE_BTREE
);
938 KKASSERT(bio
->bio_buf
->b_cmd
== BUF_CMD_WRITE
);
940 if ((buf_offset
& HAMMER_BUFMASK
) == 0 &&
941 leaf
->data_len
== HAMMER_BUFSIZE
) {
943 * We are using the vnode's bio to write directly to the
944 * media, any hammer_buffer at the same zone-X offset will
945 * now have stale data.
947 zone2_offset
= hammer_blockmap_lookup(hmp
, buf_offset
, &error
);
948 vol_no
= HAMMER_VOL_DECODE(zone2_offset
);
949 volume
= hammer_get_volume(hmp
, vol_no
, &error
);
951 if (error
== 0 && zone2_offset
>= volume
->maxbuf_off
)
954 hammer_del_buffers(hmp
, buf_offset
,
955 zone2_offset
, HAMMER_BUFSIZE
);
957 KKASSERT(bp
->b_bufsize
== HAMMER_BUFSIZE
);
958 zone2_offset
&= HAMMER_OFF_SHORT_MASK
;
960 nbio
= push_bio(bio
);
961 nbio
->bio_offset
= volume
->ondisk
->vol_buf_beg
+
963 if (hammer_debug_write_release
& 1)
964 nbio
->bio_buf
->b_flags
|= B_RELBUF
|B_NOCACHE
;
965 vn_strategy(volume
->devvp
, nbio
);
967 hammer_rel_volume(volume
, 0);
969 KKASSERT(((buf_offset
^ (buf_offset
+ leaf
->data_len
- 1)) & ~HAMMER_BUFMASK64
) == 0);
971 ptr
= hammer_bread(hmp
, buf_offset
, &error
, &buffer
);
974 hammer_io_modify(&buffer
->io
, 1);
975 bcopy(bp
->b_data
, ptr
, leaf
->data_len
);
976 hammer_io_modify_done(&buffer
->io
);
977 hammer_rel_buffer(buffer
, (hammer_debug_write_release
& 2));
983 kprintf("hammer_direct_write: failed @ %016llx\n",
988 bp
->b_flags
|= B_ERROR
;