From: Kern Sibbald Date: Thu, 25 Sep 2008 13:23:58 +0000 (+0000) Subject: kes Make first cut attempt to correct SQL that computes the current X-Git-Tag: Release-7.0.0~4095 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=355bc99baeda35a68bf923f173ba6bccf0ae71e1;p=bacula%2Fbacula kes Make first cut attempt to correct SQL that computes the current Pool usage. This is to fix bug #1159. kes Do a bunch of plugin cleanups for Win32 and more careful checking of PluginDirectory and whether or not a plugin was found. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@7637 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/dird/migrate.c b/bacula/src/dird/migrate.c index de7c383c72..f692e713fa 100644 --- a/bacula/src/dird/migrate.c +++ b/bacula/src/dird/migrate.c @@ -560,9 +560,19 @@ const char *sql_jobids_from_mediaid = /* Get the number of bytes in the pool */ const char *sql_pool_bytes = + "SELECT SUM(JobBytes) FROM Job WHERE JobId IN" + " (SELECT DISTINCT Job.JobId from Pool,Job,Media,JobMedia WHERE" + " Pool.Name='%s' AND Media.PoolId=Pool.PoolId AND" + " VolStatus in ('Full','Used','Error','Append') AND Media.Enabled=1 AND" + " Job.Type='B' AND" + " JobMedia.JobId=Job.JobId AND Job.PoolId=Media.PoolId)"; + +#ifdef xxx +/* Broken */ "SELECT SUM(VolBytes) FROM Media,Pool WHERE" " VolStatus in ('Full','Used','Error','Append') AND Media.Enabled=1 AND" " Media.PoolId=Pool.PoolId AND Pool.Name='%s'"; +#endif /* Get the number of bytes in the Jobs */ const char *sql_job_bytes = diff --git a/bacula/src/filed/fd_plugins.c b/bacula/src/filed/fd_plugins.c index d72f7700f1..135c2fbedd 100644 --- a/bacula/src/filed/fd_plugins.c +++ b/bacula/src/filed/fd_plugins.c @@ -35,7 +35,11 @@ #include "filed.h" const int dbglvl = 50; +#ifdef HAVE_WIN32 +const char *plugin_type = "-fd.dll"; +#else const char *plugin_type = "-fd.so"; +#endif extern int save_file(JCR *jcr, FF_PKT *ff_pkt, bool top_level); @@ -90,7 +94,7 @@ void generate_plugin_event(JCR *jcr, bEventType eventType, void *value) Plugin *plugin; int i = 0; - if (!plugin_list) { + if (!plugin_list || !jcr->plugin_ctx_list) { return; /* Return if no plugins loaded */ } @@ -136,7 +140,7 @@ int plugin_save(JCR *jcr, FF_PKT *ff_pkt, bool top_level) struct save_pkt sp; bEvent event; - if (!plugin_list) { + if (!plugin_list || !jcr->plugin_ctx_list) { return 1; /* Return if no plugins loaded */ } @@ -244,6 +248,9 @@ void plugin_name_stream(JCR *jcr, char *name) int len; int i = 0; bpContext *plugin_ctx_list = (bpContext *)jcr->plugin_ctx_list; + if (!plugin_ctx_list) { + goto bail_out; + } Dmsg1(100, "Read plugin stream string=%s\n", name); skip_nonspaces(&p); /* skip over jcr->JobFiles */ @@ -375,7 +382,14 @@ void load_fd_plugins(const char *plugin_dir) } plugin_list = New(alist(10, not_owned_by_alist)); - load_plugins((void *)&binfo, (void *)&bfuncs, plugin_dir, plugin_type); + if (!load_plugins((void *)&binfo, (void *)&bfuncs, plugin_dir, plugin_type)) { + /* Either none found, or some error */ + if (plugin_list->size() == 0) { + delete plugin_list; + plugin_list = NULL; + return; + } + } /* Plug entry points called from findlib */ plugin_bopen = my_plugin_bopen; @@ -391,6 +405,8 @@ void load_fd_plugins(const char *plugin_dir) /* * Create a new instance of each plugin for this Job + * Note, plugin_list can exist but jcr->plugin_ctx_list can + * be NULL if no plugins were loaded. */ void new_plugins(JCR *jcr) { @@ -427,8 +443,8 @@ void free_plugins(JCR *jcr) Plugin *plugin; int i = 0; - if (!plugin_list) { - return; + if (!plugin_list || !jcr->plugin_ctx_list) { + return; /* no plugins, nothing to do */ } bpContext *plugin_ctx_list = (bpContext *)jcr->plugin_ctx_list; diff --git a/bacula/src/lib/alist.c b/bacula/src/lib/alist.c index 7f99ad30d9..7b53dfe8bc 100644 --- a/bacula/src/lib/alist.c +++ b/bacula/src/lib/alist.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2003-2007 Free Software Foundation Europe e.V. + Copyright (C) 2003-2008 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. diff --git a/bacula/src/lib/alist.h b/bacula/src/lib/alist.h index 5658cb7075..d19bf5393c 100644 --- a/bacula/src/lib/alist.h +++ b/bacula/src/lib/alist.h @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2003-2007 Free Software Foundation Europe e.V. + Copyright (C) 2003-2008 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. diff --git a/bacula/src/lib/htable.c b/bacula/src/lib/htable.c index c08527e7b9..ee56f875a4 100644 --- a/bacula/src/lib/htable.c +++ b/bacula/src/lib/htable.c @@ -54,6 +54,8 @@ #include "htable.h" +static const int dbglvl = 500; + /* =================================================================== * htable */ @@ -137,7 +139,7 @@ void htable::hash_index(char *key) } /* Multiply by large prime number, take top bits, mask for remainder */ index = ((hash * 1103515249) >> rshift) & mask; - Dmsg2(500, "Leave hash_index hash=0x%x index=%d\n", hash, index); + Dmsg2(dbglvl, "Leave hash_index hash=0x%x index=%d\n", hash, index); } /* @@ -276,22 +278,22 @@ bool htable::insert(char *key, void *item) return false; /* already exists */ } ASSERT(index < buckets); - Dmsg2(500, "Insert: hash=%p index=%d\n", hash, index); + Dmsg2(dbglvl, "Insert: hash=%p index=%d\n", hash, index); hp = (hlink *)(((char *)item)+loffset); - Dmsg4(500, "Insert hp=%p index=%d item=%p offset=%u\n", hp, + Dmsg4(dbglvl, "Insert hp=%p index=%d item=%p offset=%u\n", hp, index, item, loffset); hp->next = table[index]; hp->hash = hash; hp->key = key; table[index] = hp; - Dmsg3(500, "Insert hp->next=%p hp->hash=0x%x hp->key=%s\n", + Dmsg3(dbglvl, "Insert hp->next=%p hp->hash=0x%x hp->key=%s\n", hp->next, hp->hash, hp->key); if (++num_items >= max_items) { - Dmsg2(500, "num_items=%d max_items=%d\n", num_items, max_items); + Dmsg2(dbglvl, "num_items=%d max_items=%d\n", num_items, max_items); grow_table(); } - Dmsg3(500, "Leave insert index=%d num_items=%d key=%s\n", index, num_items, key); + Dmsg3(dbglvl, "Leave insert index=%d num_items=%d key=%s\n", index, num_items, key); return true; } @@ -301,7 +303,7 @@ void *htable::lookup(char *key) for (hlink *hp=table[index]; hp; hp=(hlink *)hp->next) { // Dmsg2(100, "hp=%p key=%s\n", hp, hp->key); if (hash == hp->hash && strcmp(key, hp->key) == 0) { - Dmsg1(500, "lookup return %p\n", ((char *)hp)-loffset); + Dmsg1(dbglvl, "lookup return %p\n", ((char *)hp)-loffset); return ((char *)hp)-loffset; } } @@ -310,43 +312,43 @@ void *htable::lookup(char *key) void *htable::next() { - Dmsg1(500, "Enter next: walkptr=%p\n", walkptr); + Dmsg1(dbglvl, "Enter next: walkptr=%p\n", walkptr); if (walkptr) { walkptr = (hlink *)(walkptr->next); } while (!walkptr && walk_index < buckets) { walkptr = table[walk_index++]; if (walkptr) { - Dmsg3(500, "new walkptr=%p next=%p inx=%d\n", walkptr, + Dmsg3(dbglvl, "new walkptr=%p next=%p inx=%d\n", walkptr, walkptr->next, walk_index-1); } } if (walkptr) { - Dmsg2(500, "next: rtn %p walk_index=%d\n", + Dmsg2(dbglvl, "next: rtn %p walk_index=%d\n", ((char *)walkptr)-loffset, walk_index); return ((char *)walkptr)-loffset; } - Dmsg0(500, "next: return NULL\n"); + Dmsg0(dbglvl, "next: return NULL\n"); return NULL; } void *htable::first() { - Dmsg0(500, "Enter first\n"); + Dmsg0(dbglvl, "Enter first\n"); walkptr = table[0]; /* get first bucket */ walk_index = 1; /* Point to next index */ while (!walkptr && walk_index < buckets) { walkptr = table[walk_index++]; /* go to next bucket */ if (walkptr) { - Dmsg3(500, "first new walkptr=%p next=%p inx=%d\n", walkptr, + Dmsg3(dbglvl, "first new walkptr=%p next=%p inx=%d\n", walkptr, walkptr->next, walk_index-1); } } if (walkptr) { - Dmsg1(500, "Leave first walkptr=%p\n", walkptr); + Dmsg1(dbglvl, "Leave first walkptr=%p\n", walkptr); return ((char *)walkptr)-loffset; } - Dmsg0(500, "Leave first walkptr=NULL\n"); + Dmsg0(dbglvl, "Leave first walkptr=NULL\n"); return NULL; } diff --git a/bacula/src/lib/plugins.c b/bacula/src/lib/plugins.c index 1c60be7cf4..599e5dea84 100644 --- a/bacula/src/lib/plugins.c +++ b/bacula/src/lib/plugins.c @@ -58,7 +58,6 @@ Plugin *new_plugin() bool load_plugins(void *binfo, void *bfuncs, const char *plugin_dir, const char *type) { bool found = false; -//#ifndef HAVE_WIN32 t_loadPlugin loadPlugin; Plugin *plugin; DIR* dp = NULL; @@ -77,7 +76,7 @@ bool load_plugins(void *binfo, void *bfuncs, const char *plugin_dir, const char if (!(dp = opendir(plugin_dir))) { berrno be; - Jmsg(NULL, M_ERROR, 0, _("Failed to open Plugin directory %s: ERR=%s\n"), + Jmsg(NULL, M_ERROR_TERM, 0, _("Failed to open Plugin directory %s: ERR=%s\n"), plugin_dir, be.bstrerror()); goto get_out; } @@ -90,7 +89,7 @@ bool load_plugins(void *binfo, void *bfuncs, const char *plugin_dir, const char for ( ;; ) { if ((readdir_r(dp, entry, &result) != 0) || (result == NULL)) { if (!found) { - Jmsg(NULL, M_INFO, 0, _("Failed to find any plugins in %s\n"), + Jmsg(NULL, M_WARNING, 0, _("Failed to find any plugins in %s\n"), plugin_dir); } break; @@ -153,7 +152,6 @@ get_out: if (dp) { closedir(dp); } -//#endif return found; } @@ -162,7 +160,6 @@ get_out: */ void unload_plugins() { -//#ifndef HAVE_WIN32 Plugin *plugin; if (!plugin_list) { @@ -179,5 +176,4 @@ void unload_plugins() } delete plugin_list; plugin_list = NULL; -//#endif } diff --git a/bacula/technotes-2.5 b/bacula/technotes-2.5 index e1b3f659f8..51c7c63188 100644 --- a/bacula/technotes-2.5 +++ b/bacula/technotes-2.5 @@ -18,6 +18,11 @@ dbdriver remove reader/writer in FOPTS???? General: +25Sep08 +kes Make first cut attempt to correct SQL that computes the current + Pool usage. This is to fix bug #1159. +kes Do a bunch of plugin cleanups for Win32 and more careful checking + of PluginDirectory and whether or not a plugin was found. 24Sep08 kes This code should fix the race condition that leads to a Director crash at job end time when the job list is updated. This was reported