From 9916d0facd8bee39ba7a07ad49201ff14d4ef018 Mon Sep 17 00:00:00 2001 From: Tomohiro Kusumi Date: Wed, 7 Jan 2015 21:45:43 +0900 Subject: [PATCH] sbin/hammer: remove obsolete "spike" code from hammer show command This patch removes spike related code from print_btree_node(). The idea of spike type node (HAMMER_BTREE_TYPE_SPIKE_XXX) within the hammer btree has been removed since 47197d71536907482d2d215e222600eed3aedc0e in 2008. Prior to 47197d71 there was a special case where a leaf node's element was a spike node, and such data structure required hammer show command recursively call hammer_cmd_show() (see 47197d71 -- sbin/hammer/cmd_show.c). Since now that spike node is gone, calling print_btree_node() with int spike=1 (in addition to int spike=0 case) is no longer relevant as spike=1 goes down through btree doing nothing. spike=1 currently does nothing to result because it neither goes to "if (spike == 0) { ..." block nor recursively calls hammer_cmd_show(). This patch simply gets rid of spike code as well as fixing indents for "if (spike == 0) { ..." block, and nothing else. Following test shows there is no diff between two results. Note that I've reverted a commit ffb1cc63 (on top of this patch at my local git work branch) only for this test so the output format equals that of 4.0 inbox binary which was built prior to ffb1cc63. This patch itself applies to the latest upstream master. \# uname -r 4.0-RELEASE creat fs and poplulate fs with bunch of inode/dentry/data. \# mkdir -p /HAMMER \# newfs_hammer -L TEST /dev/ad1 /dev/ad2 /dev/ad3 > /dev/null \# mount_hammer /dev/ad1:/dev/ad2:/dev/ad3 /HAMMER \# cd /HAMMER \# git clone git://git.dragonflybsd.org/dragonfly.git > /dev/null \# git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git > /dev/null \# cd try the original /sbin/hammer and this patch \# umount /HAMMER \# mount_hammer /dev/ad1:/dev/ad2:/dev/ad3 /HAMMER \# /sbin/hammer -f /dev/ad1:/dev/ad2:/dev/ad3 show > out1 \# umount /HAMMER \# mount_hammer /dev/ad1:/dev/ad2:/dev/ad3 /HAMMER \# ~/work/dragonfly/sbin/hammer/hammer -f /dev/ad1:/dev/ad2:/dev/ad3 show > out2 compare results \# grep ELM ./out1 | wc -l 330370 \# grep ELM ./out2 | wc -l 330370 \# diff out1 out2 \# try the original /sbin/hammer and this patch with localization:obj_id specified \# umount /HAMMER \# mount_hammer /dev/ad1:/dev/ad2:/dev/ad3 /HAMMER \# /sbin/hammer -f /dev/ad1:/dev/ad2:/dev/ad3 show 00000001:0000000102c8eef7 > out1 \# umount /HAMMER \# mount_hammer /dev/ad1:/dev/ad2:/dev/ad3 /HAMMER \# ~/work/dragonfly/sbin/hammer/hammer -f /dev/ad1:/dev/ad2:/dev/ad3 show 00000001:0000000102c8eef7 > out2 compare results \# grep ELM out1 | wc -l 200971 \# grep ELM out2 | wc -l 200971 \# diff out1 out2 \# --- sbin/hammer/cmd_show.c | 108 +++++++++++++++++++++++------------------------- 1 files changed, 52 insertions(+), 56 deletions(-) diff --git a/sbin/hammer/cmd_show.c b/sbin/hammer/cmd_show.c index 4d69e36..a52edb6 100644 --- a/sbin/hammer/cmd_show.c +++ b/sbin/hammer/cmd_show.c @@ -46,7 +46,7 @@ typedef struct btree_search { } *btree_search_t; static void print_btree_node(hammer_off_t node_offset, btree_search_t search, - int depth, int spike, hammer_tid_t mirror_tid, + int depth, hammer_tid_t mirror_tid, hammer_base_elm_t left_bound, hammer_base_elm_t right_bound); static const char *check_data_crc(hammer_btree_elm_t elm); @@ -100,9 +100,7 @@ hammer_cmd_show(hammer_off_t node_offset, u_int32_t lo, int64_t obj_id, printf("show %016jx lo %08x obj_id %016jx depth %d\n", (uintmax_t)node_offset, lo, (uintmax_t)obj_id, depth); } - print_btree_node(node_offset, searchp, depth, 0, HAMMER_MAX_TID, - left_bound, right_bound); - print_btree_node(node_offset, searchp, depth, 1, HAMMER_MAX_TID, + print_btree_node(node_offset, searchp, depth, HAMMER_MAX_TID, left_bound, right_bound); AssertOnFailure = 1; @@ -110,7 +108,7 @@ hammer_cmd_show(hammer_off_t node_offset, u_int32_t lo, int64_t obj_id, static void print_btree_node(hammer_off_t node_offset, btree_search_t search, - int depth, int spike, hammer_tid_t mirror_tid, + int depth, hammer_tid_t mirror_tid, hammer_base_elm_t left_bound, hammer_base_elm_t right_bound) { struct buffer_info *buffer = NULL; @@ -143,65 +141,63 @@ print_btree_node(hammer_off_t node_offset, btree_search_t search, badc = 'B'; } - if (spike == 0) { - printf("%c%c NODE %016jx cnt=%02d p=%016jx " - "type=%c depth=%d", - badc, - badm, - (uintmax_t)node_offset, node->count, - (uintmax_t)node->parent, - (node->type ? node->type : '?'), depth); - printf(" mirror %016jx", (uintmax_t)node->mirror_tid); - if (QuietOpt < 3) { - printf(" fill="); - print_bigblock_fill(node_offset); - } - printf(" {\n"); + printf("%c%c NODE %016jx cnt=%02d p=%016jx " + "type=%c depth=%d", + badc, + badm, + (uintmax_t)node_offset, node->count, + (uintmax_t)node->parent, + (node->type ? node->type : '?'), depth); + printf(" mirror %016jx", (uintmax_t)node->mirror_tid); + if (QuietOpt < 3) { + printf(" fill="); + print_bigblock_fill(node_offset); + } + printf(" {\n"); - maxcount = (node->type == HAMMER_BTREE_TYPE_INTERNAL) ? - HAMMER_BTREE_INT_ELMS : HAMMER_BTREE_LEAF_ELMS; + maxcount = (node->type == HAMMER_BTREE_TYPE_INTERNAL) ? + HAMMER_BTREE_INT_ELMS : HAMMER_BTREE_LEAF_ELMS; - for (i = 0; i < node->count && i < maxcount; ++i) { - elm = &node->elms[i]; + for (i = 0; i < node->count && i < maxcount; ++i) { + elm = &node->elms[i]; - if (node->type != HAMMER_BTREE_TYPE_INTERNAL) { - ext = NULL; - if (search && - elm->base.localization == search->lo && - elm->base.obj_id == search->obj_id) { - ext = " *"; - } - } else if (search) { + if (node->type != HAMMER_BTREE_TYPE_INTERNAL) { + ext = NULL; + if (search && + elm->base.localization == search->lo && + elm->base.obj_id == search->obj_id) { ext = " *"; - if (elm->base.localization > search->lo || - (elm->base.localization == search->lo && - elm->base.obj_id > search->obj_id)) { - ext = NULL; - } - if (elm[1].base.localization < search->lo || - (elm[1].base.localization == search->lo && - elm[1].base.obj_id < search->obj_id)) { - ext = NULL; - } - } else { + } + } else if (search) { + ext = " *"; + if (elm->base.localization > search->lo || + (elm->base.localization == search->lo && + elm->base.obj_id > search->obj_id)) { ext = NULL; } - - flags = print_elm_flags(node, node_offset, - elm, elm->base.btype, - left_bound, right_bound); - print_btree_elm(elm, i, node->type, flags, "ELM", ext); + if (elm[1].base.localization < search->lo || + (elm[1].base.localization == search->lo && + elm[1].base.obj_id < search->obj_id)) { + ext = NULL; + } + } else { + ext = NULL; } - if (node->type == HAMMER_BTREE_TYPE_INTERNAL) { - elm = &node->elms[i]; - flags = print_elm_flags(node, node_offset, - elm, 'I', - left_bound, right_bound); - print_btree_elm(elm, i, node->type, flags, "RBN", NULL); - } - printf(" }\n"); + flags = print_elm_flags(node, node_offset, + elm, elm->base.btype, + left_bound, right_bound); + print_btree_elm(elm, i, node->type, flags, "ELM", ext); + } + if (node->type == HAMMER_BTREE_TYPE_INTERNAL) { + elm = &node->elms[i]; + + flags = print_elm_flags(node, node_offset, + elm, 'I', + left_bound, right_bound); + print_btree_elm(elm, i, node->type, flags, "RBN", NULL); } + printf(" }\n"); for (i = 0; i < node->count; ++i) { elm = &node->elms[i]; @@ -222,7 +218,7 @@ print_btree_node(hammer_off_t node_offset, btree_search_t search, } if (elm->internal.subtree_offset) { print_btree_node(elm->internal.subtree_offset, - search, depth + 1, spike, + search, depth + 1, elm->internal.mirror_tid, &elm[0].base, &elm[1].base); /* -- 1.7.1