From 42e3a72c468d44e2a89e5fae2f9eb8175bf1b82f Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Tue, 16 Sep 2008 08:40:35 +0000 Subject: [PATCH] Tweaks to htable code to improved debugging and make names a bit more meaningful. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@7599 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/dird/fd_cmds.c | 4 ++-- bacula/src/filed/accurate.c | 9 ++++----- bacula/src/filed/job.c | 4 ++-- bacula/src/lib/htable.c | 40 ++++++++++++++++++------------------- bacula/src/lib/htable.h | 8 ++++---- bacula/src/version.h | 4 ++-- bacula/technotes-2.5 | 3 +++ 7 files changed, 37 insertions(+), 35 deletions(-) diff --git a/bacula/src/dird/fd_cmds.c b/bacula/src/dird/fd_cmds.c index 90a151d8e9..99b123b38f 100644 --- a/bacula/src/dird/fd_cmds.c +++ b/bacula/src/dird/fd_cmds.c @@ -261,8 +261,8 @@ static void send_since_time(JCR *jcr) bool send_level_command(JCR *jcr) { BSOCK *fd = jcr->file_bsock; - const char *accurate=jcr->job->accurate?"accurate_":""; - const char *not_accurate=""; + const char *accurate = jcr->job->accurate?"accurate_":""; + const char *not_accurate = ""; /* * Send Level command to File daemon */ diff --git a/bacula/src/filed/accurate.c b/bacula/src/filed/accurate.c index fd396c251e..3f6059ea5d 100644 --- a/bacula/src/filed/accurate.c +++ b/bacula/src/filed/accurate.c @@ -26,7 +26,7 @@ Switzerland, email:ftf@fsfeurope.org. */ /* - * Version $Id$ + * Version $Id $ * */ @@ -216,7 +216,7 @@ static bool accurate_lookup(JCR *jcr, char *fname, CurFile *ret) static bool accurate_init(JCR *jcr, int nbfile) { - CurFile *elt=NULL; + CurFile *elt = NULL; jcr->file_list = (htable *)malloc(sizeof(htable)); jcr->file_list->init(elt, &elt->link, nbfile); return true; @@ -243,7 +243,7 @@ bool accurate_send_deleted_list(JCR *jcr) ff_pkt = init_find_files(); ff_pkt->type = FT_DELETED; - foreach_htable (elt, jcr->file_list) { + foreach_htable(elt, jcr->file_list) { if (!elt->seen) { /* already seen */ Dmsg2(dbglvl, "deleted fname=%s seen=%i\n", elt->fname, elt->seen); ff_pkt->fname = elt->fname; @@ -352,7 +352,7 @@ bail_out: } /* - * TODO: use bigbuffer from htable + * TODO: use big buffer from htable */ int accurate_cmd(JCR *jcr) { @@ -393,7 +393,6 @@ int accurate_cmd(JCR *jcr) edit_uint64_with_commas(sm_max_bytes, b3), edit_uint64_with_commas(sm_buffers, b4), edit_uint64_with_commas(sm_max_buffers, b5)); - #endif return true; diff --git a/bacula/src/filed/job.c b/bacula/src/filed/job.c index b685a971d4..0c21ffe558 100644 --- a/bacula/src/filed/job.c +++ b/bacula/src/filed/job.c @@ -107,7 +107,7 @@ static struct s_cmds cmds[] = { {"RunBeforeJob", runbefore_cmd, 0}, {"RunAfterJob", runafter_cmd, 0}, {"Run", runscript_cmd, 0}, - {"accurate", accurate_cmd, 0}, + {"accurate", accurate_cmd, 0}, {NULL, NULL} /* list terminator */ }; @@ -1226,7 +1226,7 @@ static int level_cmd(JCR *jcr) int mtime_only; level = get_memory(dir->msglen+1); - Dmsg1(110, "level_cmd: %s", dir->msg); + Dmsg1(100, "level_cmd: %s", dir->msg); if (strstr(dir->msg, "accurate")) { jcr->accurate = true; } diff --git a/bacula/src/lib/htable.c b/bacula/src/lib/htable.c index 121c4c513d..d2877d43f0 100644 --- a/bacula/src/lib/htable.c +++ b/bacula/src/lib/htable.c @@ -62,52 +62,57 @@ /* * This subroutine gets a big buffer. */ -void htable::malloc_buf(int size) +void htable::malloc_big_buf(int size) { struct h_mem *hmem; hmem = (struct h_mem *)malloc(size); total_size += size; blocks++; - hmem->next = this->mem; - this->mem = hmem; - hmem->mem = mem->first; + hmem->next = mem_block; + mem_block = hmem; + hmem->mem = mem_block->first; hmem->rem = (char *)hmem + size - hmem->mem; - Dmsg2(200, "malloc buf size=%d rem=%d\n", size, hmem->rem); + Dmsg3(100, "malloc buf=%p size=%d rem=%d\n", hmem, size, hmem->rem); } /* This routine frees the whole tree */ -void htable::hash_free() +void htable::hash_big_free() { struct h_mem *hmem, *rel; - for (hmem=mem; hmem; ) { + for (hmem=mem_block; hmem; ) { rel = hmem; hmem = hmem->next; + Dmsg1(100, "free malloc buf=%p\n", rel); free(rel); } } #endif +/* + * Normal hash malloc routine that gets a + * "small" buffer from the big buffer + */ char *htable::hash_malloc(int size) { #ifdef BIG_MALLOC char *buf; int asize = BALIGN(size); - if (mem->rem < asize) { + if (mem_block->rem < asize) { uint32_t mb_size; if (total_size >= 1000000) { mb_size = 1000000; } else { mb_size = 100000; } - malloc_buf(mb_size); + malloc_big_buf(mb_size); } - mem->rem -= asize; - buf = mem->mem; - mem->mem += asize; + mem_block->rem -= asize; + buf = mem_block->mem; + mem_block->mem += asize; return buf; #else total_size += size; @@ -147,6 +152,7 @@ void htable::init(void *item, void *link, int tsize) { int pwr; + memset(this, 0, sizeof(htable)); if (tsize < 31) { tsize = 31; } @@ -157,18 +163,12 @@ void htable::init(void *item, void *link, int tsize) loffset = (char *)link - (char *)item; mask = ~((~0)< table size = 8 */ rshift = 30 - pwr; /* start using bits 28, 29, 30 */ - num_items = 0; /* number of entries in table */ buckets = 1<