From 77062c8a3b75f492d0a239470f367a11ae226799 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Tue, 6 May 2008 00:21:08 +0000 Subject: [PATCH] HAMMER 41B/Many: Cleanup. * Disable (most) debugging kprintfs unless a hammer debug sysctl is set. * Do not allow buffers to be synced on panic. --- sys/vfs/hammer/hammer.h | 6 +++-- sys/vfs/hammer/hammer_blockmap.c | 10 +++---- sys/vfs/hammer/hammer_btree.c | 10 +++---- sys/vfs/hammer/hammer_flusher.c | 14 +++++----- sys/vfs/hammer/hammer_inode.c | 6 ++--- sys/vfs/hammer/hammer_io.c | 46 +++++++++++++++++++++----------- sys/vfs/hammer/hammer_recover.c | 4 +-- sys/vfs/hammer/hammer_subs.c | 14 +++++++++- sys/vfs/hammer/hammer_undo.c | 4 +-- sys/vfs/hammer/hammer_vfsops.c | 17 +++++++++--- sys/vfs/hammer/hammer_vnops.c | 11 ++++---- 11 files changed, 92 insertions(+), 50 deletions(-) diff --git a/sys/vfs/hammer/hammer.h b/sys/vfs/hammer/hammer.h index 5d01fe3633..2ae0e2fac5 100644 --- a/sys/vfs/hammer/hammer.h +++ b/sys/vfs/hammer/hammer.h @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/vfs/hammer/hammer.h,v 1.61 2008/05/05 20:34:47 dillon Exp $ + * $DragonFly: src/sys/vfs/hammer/hammer.h,v 1.62 2008/05/06 00:21:07 dillon Exp $ */ /* * This header file contains structures used internally by the HAMMERFS @@ -593,6 +593,7 @@ extern struct vop_ops hammer_fifo_vops; extern struct bio_ops hammer_bioops; extern int hammer_debug_general; +extern int hammer_debug_debug; extern int hammer_debug_inode; extern int hammer_debug_locks; extern int hammer_debug_btree; @@ -857,6 +858,7 @@ int hammer_crc_test_blockmap(hammer_blockmap_t blockmap); int hammer_crc_test_volume(hammer_volume_ondisk_t ondisk); int hammer_crc_test_record(hammer_record_ondisk_t ondisk); int hammer_crc_test_btree(hammer_node_ondisk_t ondisk); +void hkprintf(const char *ctl, ...); #endif @@ -957,5 +959,5 @@ hammer_modify_record_done(hammer_buffer_t buffer, hammer_record_ondisk_t rec) #define hammer_modify_record_field(trans, buffer, rec, field, dodelete) \ hammer_modify_record(trans, buffer, rec, &(rec)->field, \ - sizeof((rec)->field), dodelete) + sizeof((rec)->field), dodelete) diff --git a/sys/vfs/hammer/hammer_blockmap.c b/sys/vfs/hammer/hammer_blockmap.c index 7df1838750..06c293c445 100644 --- a/sys/vfs/hammer/hammer_blockmap.c +++ b/sys/vfs/hammer/hammer_blockmap.c @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/vfs/hammer/hammer_blockmap.c,v 1.11 2008/05/05 20:34:47 dillon Exp $ + * $DragonFly: src/sys/vfs/hammer/hammer_blockmap.c,v 1.12 2008/05/06 00:21:07 dillon Exp $ */ /* @@ -162,11 +162,11 @@ again: */ if (layer1->blocks_free == 0 && ((next_offset ^ rootmap->alloc_offset) & ~HAMMER_BLOCKMAP_LAYER2_MASK) != 0) { - kprintf("blockmap skip1 %016llx\n", next_offset); + hkprintf("blockmap skip1 %016llx\n", next_offset); next_offset = (next_offset + HAMMER_BLOCKMAP_LAYER2_MASK) & ~HAMMER_BLOCKMAP_LAYER2_MASK; if (next_offset >= trans->hmp->zone_limits[zone]) { - kprintf("blockmap wrap1\n"); + hkprintf("blockmap wrap1\n"); next_offset = HAMMER_ZONE_ENCODE(zone, 0); if (++loops == 2) { /* XXX poor-man's */ next_offset = 0; @@ -229,12 +229,12 @@ again: * We have encountered a block that is already * partially allocated. We must skip this block. */ - kprintf("blockmap skip2 %016llx %d\n", + hkprintf("blockmap skip2 %016llx %d\n", next_offset, layer2->bytes_free); next_offset += HAMMER_LARGEBLOCK_SIZE; if (next_offset >= trans->hmp->zone_limits[zone]) { next_offset = HAMMER_ZONE_ENCODE(zone, 0); - kprintf("blockmap wrap2\n"); + hkprintf("blockmap wrap2\n"); if (++loops == 2) { /* XXX poor-man's */ next_offset = 0; *errorp = ENOSPC; diff --git a/sys/vfs/hammer/hammer_btree.c b/sys/vfs/hammer/hammer_btree.c index 124214d542..61603f166b 100644 --- a/sys/vfs/hammer/hammer_btree.c +++ b/sys/vfs/hammer/hammer_btree.c @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/vfs/hammer/hammer_btree.c,v 1.43 2008/05/05 20:34:47 dillon Exp $ + * $DragonFly: src/sys/vfs/hammer/hammer_btree.c,v 1.44 2008/05/06 00:21:07 dillon Exp $ */ /* @@ -219,7 +219,7 @@ hammer_btree_iterate(hammer_cursor_t cursor) * deadlocks, but it is ok if we can't. */ if (elm->internal.subtree_offset == 0) { - kprintf("REMOVE DELETED ELEMENT\n"); + hkprintf("REMOVE DELETED ELEMENT\n"); btree_remove_deleted_element(cursor); /* note: elm also invalid */ } else if (elm->internal.subtree_offset != 0) { @@ -1795,7 +1795,7 @@ hammer_btree_correct_rhb(hammer_cursor_t cursor, hammer_tid_t tid) error = 0; while (error == 0 && (rhb = TAILQ_FIRST(&rhb_list)) != NULL) { error = hammer_cursor_seek(cursor, rhb->node, rhb->index); - kprintf("CORRECT RHB %016llx index %d type=%c\n", + hkprintf("CORRECT RHB %016llx index %d type=%c\n", rhb->node->node_offset, rhb->index, cursor->node->ondisk->type); if (error) @@ -1915,7 +1915,7 @@ hammer_btree_correct_lhb(hammer_cursor_t cursor, hammer_tid_t tid) elm = &cursor->node->ondisk->elms[cursor->index].base; if (cursor->node->ondisk->type == HAMMER_BTREE_TYPE_INTERNAL) { - kprintf("hammer_btree_correct_lhb-I @%016llx[%d]\n", + hkprintf("hammer_btree_correct_lhb-I @%016llx[%d]\n", cursor->node->node_offset, cursor->index); hammer_modify_node(cursor->trans, cursor->node, &elm->create_tid, @@ -2069,7 +2069,7 @@ btree_remove_deleted_element(hammer_cursor_t cursor) if (elm->internal.subtree_offset == 0) { do { error = btree_remove(cursor); - kprintf("BTREE REMOVE DELETED ELEMENT %d\n", error); + hkprintf("BTREE REMOVE DELETED ELEMENT %d\n", error); } while (error == EAGAIN); } return(error); diff --git a/sys/vfs/hammer/hammer_flusher.c b/sys/vfs/hammer/hammer_flusher.c index 5bd671cb0b..488ddb79aa 100644 --- a/sys/vfs/hammer/hammer_flusher.c +++ b/sys/vfs/hammer/hammer_flusher.c @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/vfs/hammer/hammer_flusher.c,v 1.13 2008/05/05 20:34:47 dillon Exp $ + * $DragonFly: src/sys/vfs/hammer/hammer_flusher.c,v 1.14 2008/05/06 00:21:07 dillon Exp $ */ /* * HAMMER dependancy flusher thread @@ -109,7 +109,7 @@ hammer_flusher_thread(void *arg) tsleep(&hmp->flusher_lock, 0, "hmrhld", 0); hmp->flusher_act = hmp->flusher_next; ++hmp->flusher_next; - kprintf("F"); + hkprintf("F"); hammer_flusher_clean_loose_ios(hmp); hammer_flusher_flush(hmp); hammer_flusher_clean_loose_ios(hmp); @@ -122,7 +122,7 @@ hammer_flusher_thread(void *arg) */ if (hmp->flusher_exiting && TAILQ_EMPTY(&hmp->flush_list)) break; - kprintf("E"); + hkprintf("E"); /* * This is a hack until we can dispose of frontend buffer @@ -216,7 +216,7 @@ int hammer_must_finalize_undo(hammer_mount_t hmp) { if (hammer_undo_space(hmp) < hammer_undo_max(hmp) / 2) { - kprintf("*"); + hkprintf("*"); return(1); } else { return(0); @@ -289,7 +289,7 @@ hammer_flusher_finalize(hammer_transaction_t trans) ++count; } if (count) - kprintf("X%d", count); + hkprintf("X%d", count); /* * Flush data bufs @@ -304,7 +304,7 @@ hammer_flusher_finalize(hammer_transaction_t trans) ++count; } if (count) - kprintf("Y%d", count); + hkprintf("Y%d", count); /* * Wait for I/O to complete @@ -371,6 +371,6 @@ hammer_flusher_finalize(hammer_transaction_t trans) } hammer_unlock(&hmp->sync_lock); if (count) - kprintf("Z%d", count); + hkprintf("Z%d", count); } diff --git a/sys/vfs/hammer/hammer_inode.c b/sys/vfs/hammer/hammer_inode.c index 3bb0261b5c..94d630576e 100644 --- a/sys/vfs/hammer/hammer_inode.c +++ b/sys/vfs/hammer/hammer_inode.c @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/vfs/hammer/hammer_inode.c,v 1.52 2008/05/05 20:34:47 dillon Exp $ + * $DragonFly: src/sys/vfs/hammer/hammer_inode.c,v 1.53 2008/05/06 00:21:08 dillon Exp $ */ #include "hammer.h" @@ -289,7 +289,7 @@ retry: if ((flags & HAMMER_INODE_RO) == 0) { kprintf("hammer_get_inode: failed ip %p obj_id %016llx cursor %p error %d\n", ip, ip->obj_id, &cursor, *errorp); - Debugger("x"); + Debugger("x"); } --hammer_count_inodes; kfree(ip, M_HAMMER); @@ -1510,7 +1510,7 @@ hammer_sync_inode(hammer_inode_t ip) (ip->flags & HAMMER_INODE_DELETED) == 0) { int count1 = 0; - kprintf("Y"); + hkprintf("Y"); ip->flags |= HAMMER_INODE_DELETED; error = hammer_ip_delete_range_all(&cursor, ip, &count1); if (error == 0) { diff --git a/sys/vfs/hammer/hammer_io.c b/sys/vfs/hammer/hammer_io.c index c73e7f7f69..bc2a533a2c 100644 --- a/sys/vfs/hammer/hammer_io.c +++ b/sys/vfs/hammer/hammer_io.c @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/vfs/hammer/hammer_io.c,v 1.29 2008/05/04 09:06:45 dillon Exp $ + * $DragonFly: src/sys/vfs/hammer/hammer_io.c,v 1.30 2008/05/06 00:21:08 dillon Exp $ */ /* * IO Primitives and buffer cache management @@ -347,6 +347,24 @@ hammer_io_flush(struct hammer_io *io) KKASSERT(io->bp); KKASSERT(io->modify_refs == 0); + /* + * Acquire ownership of the bp, particularly before we clear our + * modified flag. + * + * We are going to bawrite() this bp. Don't leave a window where + * io->released is set, we actually own the bp rather then our + * buffer. + */ + bp = io->bp; + if (io->released) { + regetblk(bp); + /* BUF_KERNPROC(io->bp); */ + /* io->released = 0; */ + KKASSERT(io->released); + KKASSERT(io->bp == bp); + } + io->released = 1; + /* * Acquire exclusive access to the bp and then clear the modified * state of the buffer prior to issuing I/O to interlock any @@ -371,21 +389,10 @@ hammer_io_flush(struct hammer_io *io) io->mod_list = NULL; io->modified = 0; io->flush = 0; - bp = io->bp; - - /* - * Acquire ownership (released variable set for clarity) - */ - if (io->released) { - regetblk(bp); - /* BUF_KERNPROC(io->bp); */ - io->released = 0; - } /* * Transfer ownership to the kernel and initiate I/O. */ - io->released = 1; io->running = 1; ++io->hmp->io_running_count; bawrite(bp); @@ -531,7 +538,7 @@ hammer_io_clear_modify(struct hammer_io *io) io->released = 1; } if (io->modified == 0) { - kprintf("hammer_io_clear_modify: cleared %p\n", io); + hkprintf("hammer_io_clear_modify: cleared %p\n", io); bundirty(bp); bqrelse(bp); } else { @@ -683,8 +690,17 @@ hammer_io_checkwrite(struct buf *bp) { hammer_io_t io = (void *)LIST_FIRST(&bp->b_dep); - KKASSERT(io->type != HAMMER_STRUCTURE_VOLUME && - io->type != HAMMER_STRUCTURE_META_BUFFER); + /* + * This shouldn't happen under normal operation. + */ + if (io->type == HAMMER_STRUCTURE_VOLUME || + io->type == HAMMER_STRUCTURE_META_BUFFER) { + if (!panicstr) + panic("hammer_io_checkwrite: illegal buffer"); + hkprintf("x"); + bp->b_flags |= B_LOCKED; + return(1); + } /* * We can only clear the modified bit if the IO is not currently diff --git a/sys/vfs/hammer/hammer_recover.c b/sys/vfs/hammer/hammer_recover.c index 4c08d119f8..16c9b79f93 100644 --- a/sys/vfs/hammer/hammer_recover.c +++ b/sys/vfs/hammer/hammer_recover.c @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/vfs/hammer/hammer_recover.c,v 1.15 2008/05/04 09:06:45 dillon Exp $ + * $DragonFly: src/sys/vfs/hammer/hammer_recover.c,v 1.16 2008/05/06 00:21:08 dillon Exp $ */ #include "hammer.h" @@ -327,7 +327,7 @@ static void hammer_recover_copy_undo(hammer_off_t undo_offset, char *src, char *dst, int bytes) { - kprintf("U"); + hkprintf("U"); if (hammer_debug_general & 0x0080) kprintf("NDO %016llx: %d\n", undo_offset, bytes); #if 0 diff --git a/sys/vfs/hammer/hammer_subs.c b/sys/vfs/hammer/hammer_subs.c index e6918515f5..3d05691aa5 100644 --- a/sys/vfs/hammer/hammer_subs.c +++ b/sys/vfs/hammer/hammer_subs.c @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/vfs/hammer/hammer_subs.c,v 1.17 2008/05/05 20:34:48 dillon Exp $ + * $DragonFly: src/sys/vfs/hammer/hammer_subs.c,v 1.18 2008/05/06 00:21:08 dillon Exp $ */ /* * HAMMER structural locking @@ -405,3 +405,15 @@ hammer_crc_test_btree(hammer_node_ondisk_t ondisk) return (ondisk->crc == crc); } +void +hkprintf(const char *ctl, ...) +{ + __va_list va; + + if (hammer_debug_debug) { + __va_start(va, ctl); + kvprintf(ctl, va); + __va_end(va); + } +} + diff --git a/sys/vfs/hammer/hammer_undo.c b/sys/vfs/hammer/hammer_undo.c index b3aff4af43..23c3a34de2 100644 --- a/sys/vfs/hammer/hammer_undo.c +++ b/sys/vfs/hammer/hammer_undo.c @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/vfs/hammer/hammer_undo.c,v 1.13 2008/05/05 20:34:48 dillon Exp $ + * $DragonFly: src/sys/vfs/hammer/hammer_undo.c,v 1.14 2008/05/06 00:21:08 dillon Exp $ */ /* @@ -128,7 +128,7 @@ again: if (undomap->next_offset == undomap->alloc_offset) { next_offset = HAMMER_ZONE_ENCODE(HAMMER_ZONE_UNDO_INDEX, 0); undomap->next_offset = next_offset; - kprintf("undo zone's next_offset wrapped\n"); + hkprintf("undo zone's next_offset wrapped\n"); } undo = hammer_bread(trans->hmp, next_offset, &error, &buffer); diff --git a/sys/vfs/hammer/hammer_vfsops.c b/sys/vfs/hammer/hammer_vfsops.c index 2de7e7758b..e9b9773056 100644 --- a/sys/vfs/hammer/hammer_vfsops.c +++ b/sys/vfs/hammer/hammer_vfsops.c @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/vfs/hammer/hammer_vfsops.c,v 1.33 2008/05/04 09:06:45 dillon Exp $ + * $DragonFly: src/sys/vfs/hammer/hammer_vfsops.c,v 1.34 2008/05/06 00:21:08 dillon Exp $ */ #include @@ -48,6 +48,7 @@ #include "hammer.h" int hammer_debug_general; +int hammer_debug_debug; int hammer_debug_inode; int hammer_debug_locks; int hammer_debug_btree; @@ -69,6 +70,8 @@ int64_t hammer_zone_limit; SYSCTL_NODE(_vfs, OID_AUTO, hammer, CTLFLAG_RW, 0, "HAMMER filesystem"); SYSCTL_INT(_vfs_hammer, OID_AUTO, debug_general, CTLFLAG_RW, &hammer_debug_general, 0, ""); +SYSCTL_INT(_vfs_hammer, OID_AUTO, debug_debug, CTLFLAG_RW, + &hammer_debug_debug, 0, ""); SYSCTL_INT(_vfs_hammer, OID_AUTO, debug_inode, CTLFLAG_RW, &hammer_debug_inode, 0, ""); SYSCTL_INT(_vfs_hammer, OID_AUTO, debug_locks, CTLFLAG_RW, @@ -557,6 +560,9 @@ hammer_vfs_statfs(struct mount *mp, struct statfs *sbp, struct ucred *cred) * Sync the filesystem. Currently we have to run it twice, the second * one will advance the undo start index to the end index, so if a crash * occurs no undos will be run on mount. + * + * We do not sync the filesystem if we are called from a panic. If we did + * we might end up blowing up a sync that was already in progress. */ static int hammer_vfs_sync(struct mount *mp, int waitfor) @@ -564,9 +570,14 @@ hammer_vfs_sync(struct mount *mp, int waitfor) struct hammer_mount *hmp = (void *)mp->mnt_data; int error; - error = hammer_sync_hmp(hmp, waitfor); - if (error == 0) + if (panicstr == NULL) { error = hammer_sync_hmp(hmp, waitfor); + if (error == 0) + error = hammer_sync_hmp(hmp, waitfor); + } else { + error = EIO; + hkprintf("S"); + } return (error); } diff --git a/sys/vfs/hammer/hammer_vnops.c b/sys/vfs/hammer/hammer_vnops.c index 2cf0ce9ae7..f2dcefdd50 100644 --- a/sys/vfs/hammer/hammer_vnops.c +++ b/sys/vfs/hammer/hammer_vnops.c @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/vfs/hammer/hammer_vnops.c,v 1.48 2008/05/05 20:34:48 dillon Exp $ + * $DragonFly: src/sys/vfs/hammer/hammer_vnops.c,v 1.49 2008/05/06 00:21:08 dillon Exp $ */ #include @@ -489,7 +489,7 @@ hammer_vop_ncreate(struct vop_ncreate_args *ap) error = hammer_create_inode(&trans, ap->a_vap, ap->a_cred, dip, &nip); if (error) { - kprintf("hammer_create_inode error %d\n", error); + hkprintf("hammer_create_inode error %d\n", error); hammer_done_transaction(&trans); *ap->a_vpp = NULL; return (error); @@ -501,7 +501,7 @@ hammer_vop_ncreate(struct vop_ncreate_args *ap) */ error = hammer_ip_add_directory(&trans, dip, nch->ncp, nip); if (error) - kprintf("hammer_ip_add_directory error %d\n", error); + hkprintf("hammer_ip_add_directory error %d\n", error); /* * Finish up. @@ -855,7 +855,7 @@ hammer_vop_nmkdir(struct vop_nmkdir_args *ap) */ error = hammer_create_inode(&trans, ap->a_vap, ap->a_cred, dip, &nip); if (error) { - kprintf("hammer_mkdir error %d\n", error); + hkprintf("hammer_mkdir error %d\n", error); hammer_done_transaction(&trans); *ap->a_vpp = NULL; return (error); @@ -866,7 +866,7 @@ hammer_vop_nmkdir(struct vop_nmkdir_args *ap) */ error = hammer_ip_add_directory(&trans, dip, nch->ncp, nip); if (error) - kprintf("hammer_mkdir (add) error %d\n", error); + hkprintf("hammer_mkdir (add) error %d\n", error); /* * Finish up. @@ -1897,6 +1897,7 @@ hammer_dowrite(hammer_cursor_t cursor, hammer_inode_t ip, struct bio *bio) if (ip->flags & HAMMER_INODE_DELETED) { bp->b_resid = 0; biodone(bio); + --hammer_bio_count; } /* -- 2.41.0