From 0c854c8e78436a592740b1b41a10854e8ee1130c Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sun, 10 Feb 2008 18:26:40 +0000 Subject: [PATCH] First cut of plugin restore code git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6397 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/filed/fd-plugins.c | 172 ++++++++++++++++++++++++---------- bacula/src/filed/fd-plugins.h | 1 + bacula/src/filed/job.c | 2 +- bacula/src/filed/restore.c | 4 + bacula/src/version.h | 4 +- bacula/technotes-2.3 | 5 + 6 files changed, 134 insertions(+), 54 deletions(-) diff --git a/bacula/src/filed/fd-plugins.c b/bacula/src/filed/fd-plugins.c index bd2d3ac1e1..320bce366c 100644 --- a/bacula/src/filed/fd-plugins.c +++ b/bacula/src/filed/fd-plugins.c @@ -104,55 +104,59 @@ void generate_plugin_event(JCR *jcr, bEventType eventType, void *value) event.eventType = eventType; Dmsg2(dbglvl, "plugin_ctx=%p JobId=%d\n", jcr->plugin_ctx_list, jcr->JobId); - if (eventType != bEventPluginCommand) { - /* Pass event to every plugin */ - foreach_alist(plugin, plugin_list) { - plug_func(plugin)->handlePluginEvent(&plugin_ctx_list[i++], &event, value); + switch (eventType) { + case bEventPluginCommand: + /* Handle plugin command here backup */ + Dmsg1(100, "plugin cmd=%s\n", cmd); + if (!(p = strchr(cmd, ':'))) { + Jmsg1(jcr, M_ERROR, 0, "Malformed plugin command: %s\n", cmd); + goto bail_out; + } + len = p - cmd; + if (len <= 0) { + goto bail_out; } - goto bail_out; - } - - /* Handle plugin command here (backup/restore of file) */ - Dmsg1(100, "plugin cmd=%s\n", cmd); - if (!(p = strchr(cmd, ':'))) { - Jmsg1(jcr, M_ERROR, 0, "Malformed plugin command: %s\n", cmd); - goto bail_out; - } - len = p - cmd; - if (len <= 0) { - goto bail_out; - } - foreach_alist(plugin, plugin_list) { - Dmsg3(100, "plugin=%s cmd=%s len=%d\n", plugin->file, cmd, len); - if (strncmp(plugin->file, cmd, len) == 0) { - Dmsg1(100, "Command plugin = %s\n", cmd); - if (plug_func(plugin)->handlePluginEvent(&plugin_ctx_list[i], &event, value) != bRC_OK) { - goto bail_out; - } - memset(&sp, 0, sizeof(sp)); - sp.type = FT_REG; - sp.portable = true; - sp.cmd = cmd; - Dmsg3(000, "startBackup st_size=%p st_blocks=%p sp=%p\n", &sp.statp.st_size, &sp.statp.st_blocks, - &sp); - if (plug_func(plugin)->startPluginBackup(&plugin_ctx_list[i], &sp) != bRC_OK) { + foreach_alist(plugin, plugin_list) { + Dmsg3(100, "plugin=%s cmd=%s len=%d\n", plugin->file, cmd, len); + if (strncmp(plugin->file, cmd, len) == 0) { + Dmsg1(100, "Command plugin = %s\n", cmd); + if (plug_func(plugin)->handlePluginEvent(&plugin_ctx_list[i], &event, value) != bRC_OK) { + goto bail_out; + } + memset(&sp, 0, sizeof(sp)); + sp.type = FT_REG; + sp.portable = true; + sp.cmd = cmd; + Dmsg3(000, "startBackup st_size=%p st_blocks=%p sp=%p\n", &sp.statp.st_size, &sp.statp.st_blocks, + &sp); + if (plug_func(plugin)->startPluginBackup(&plugin_ctx_list[i], &sp) != bRC_OK) { + goto bail_out; + } + jcr->plugin_ctx = &plugin_ctx_list[i]; + jcr->plugin = plugin; + jcr->plugin_sp = &sp; + ff_pkt = jcr->ff; + ff_pkt->fname = sp.fname; + ff_pkt->type = sp.type; + memcpy(&ff_pkt->statp, &sp.statp, sizeof(ff_pkt->statp)); + Dmsg1(000, "Save_file: file=%s\n", ff_pkt->fname); + save_file(jcr, ff_pkt, true); goto bail_out; } - jcr->plugin_ctx = &plugin_ctx_list[i]; - jcr->plugin = plugin; - jcr->plugin_sp = &sp; - ff_pkt = jcr->ff; - ff_pkt->fname = sp.fname; - ff_pkt->type = sp.type; - memcpy(&ff_pkt->statp, &sp.statp, sizeof(ff_pkt->statp)); - Dmsg1(000, "Save_file: file=%s\n", ff_pkt->fname); - save_file(jcr, ff_pkt, true); - goto bail_out; + i++; } - i++; + Jmsg1(jcr, M_ERROR, 0, "Command plugin \"%s\" not found.\n", cmd); + break; + + default: + /* Pass event to every plugin */ + foreach_alist(plugin, plugin_list) { + plug_func(plugin)->handlePluginEvent(&plugin_ctx_list[i++], &event, value); + } + break; } - Jmsg1(jcr, M_ERROR, 0, "Command plugin \"%s\" not found.\n", cmd); + bail_out: return; @@ -165,20 +169,13 @@ bool send_plugin_name(JCR *jcr, BSOCK *sd, bool start) { int stat; struct save_pkt *sp = (struct save_pkt *)jcr->plugin_sp; - Plugin *plugin = (Plugin *)jcr->plugin; if (!sd->fsend("%ld %d %d", jcr->JobFiles, STREAM_PLUGIN_NAME, start)) { Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"), sd->bstrerror()); return false; } - if (start) { - stat = sd->fsend("%ld 1 %d %s%c%s%c", jcr->JobFiles, sp->portable, plugin->file, 0, - sp->cmd, 0); - } else { - stat = sd->fsend("%ld 0 %d %s%c%s%c", jcr->JobFiles, sp->portable, plugin->file, 0, - sp->cmd, 0); - } + stat = sd->fsend("%ld %d %d %s%c", jcr->JobFiles, start, sp->portable, sp->cmd, 0); if (!stat) { Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"), sd->bstrerror()); @@ -188,6 +185,79 @@ bool send_plugin_name(JCR *jcr, BSOCK *sd, bool start) return true; } +/* + * Plugin name stream found during restore. This is the record + * that was generated in send_plugin_name() above. + */ +void plugin_name_stream(JCR *jcr, char *name) +{ + char *p = name; + char *cmd; + bool start, portable; + bEvent event; + Plugin *plugin; + int len; + int i = 0; + bpContext *plugin_ctx_list; + + Dmsg1(000, "plugin stream string=%s\n", name); + skip_nonspaces(&p); /* skip over jcr->JobFiles */ + skip_spaces(&p); + start = *p == '1'; + skip_nonspaces(&p); /* skip start/end flag */ + skip_spaces(&p); + portable = *p == '1'; + skip_nonspaces(&p); /* skip portable flag */ + skip_spaces(&p); + cmd = p; + event.eventType = start ? bEventRestoreStart : bEventRestoreEnd; + + /* Check for restore end */ + if (!start) { + /* + * If end of restore, notify plugin, then clear flags + */ + plugin = (Plugin *)jcr->plugin; + plug_func(plugin)->handlePluginEvent((bpContext *)jcr->plugin_ctx, &event, cmd); + jcr->plugin_ctx = NULL; + jcr->plugin = NULL; + goto bail_out; + } + + /* + * After this point, we are dealing with a restore start + */ + + Dmsg1(000, "plugin cmd=%s\n", cmd); + if (!(p = strchr(cmd, ':'))) { + Jmsg1(jcr, M_ERROR, 0, "Malformed plugin command: %s\n", cmd); + goto bail_out; + } + len = p - cmd; + if (len <= 0) { + goto bail_out; + } + + + plugin_ctx_list = (bpContext *)jcr->plugin_ctx_list; + foreach_alist(plugin, plugin_list) { + Dmsg3(100, "plugin=%s cmd=%s len=%d\n", plugin->file, cmd, len); + if (strncmp(plugin->file, cmd, len) == 0) { + Dmsg1(100, "Command plugin = %s\n", cmd); + if (plug_func(plugin)->handlePluginEvent(&plugin_ctx_list[i], + &event, (void *)name) != bRC_OK) { + goto bail_out; + } + jcr->plugin_ctx = &plugin_ctx_list[i]; + jcr->plugin = plugin; + goto bail_out; + } + i++; + } +bail_out: + return; +} + void load_fd_plugins(const char *plugin_dir) { diff --git a/bacula/src/filed/fd-plugins.h b/bacula/src/filed/fd-plugins.h index e6a9cdf37a..1c73569c4c 100644 --- a/bacula/src/filed/fd-plugins.h +++ b/bacula/src/filed/fd-plugins.h @@ -133,6 +133,7 @@ void new_plugins(JCR *jcr); void free_plugins(JCR *jcr); void generate_plugin_event(JCR *jcr, bEventType event, void *value=NULL); bool send_plugin_name(JCR *jcr, BSOCK *sd, bool start); +void plugin_name_stream(JCR *jcr, char *name); #ifdef __cplusplus extern "C" { diff --git a/bacula/src/filed/job.c b/bacula/src/filed/job.c index 7ee5cb826d..b7d821e696 100644 --- a/bacula/src/filed/job.c +++ b/bacula/src/filed/job.c @@ -1120,7 +1120,7 @@ static int fileset_cmd(JCR *jcr) if (!term_fileset(jcr)) { return 0; } - return bnet_fsend(dir, OKinc); + return dir->fsend(OKinc); } static void free_bootstrap(JCR *jcr) diff --git a/bacula/src/filed/restore.c b/bacula/src/filed/restore.c index 0996f9a9a7..1aa65ec22a 100644 --- a/bacula/src/filed/restore.c +++ b/bacula/src/filed/restore.c @@ -631,6 +631,10 @@ void do_restore(JCR *jcr) } break; + case STREAM_PLUGIN_NAME: + plugin_name_stream(jcr, sd->msg); + break; + default: /* If extracting, wierd stream (not 1 or 2), close output file anyway */ if (extract) { diff --git a/bacula/src/version.h b/bacula/src/version.h index ed6856e6a3..48b3fedd8c 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -4,8 +4,8 @@ #undef VERSION #define VERSION "2.3.9" -#define BDATE "09 February 2008" -#define LSMDATE "09Feb08" +#define BDATE "10 February 2008" +#define LSMDATE "10Feb08" #define PROG_COPYRIGHT "Copyright (C) %d-2008 Free Software Foundation Europe e.V.\n" #define BYEAR "2008" /* year for copyright messages in progs */ diff --git a/bacula/technotes-2.3 b/bacula/technotes-2.3 index c786cb6230..4ab6ca0061 100644 --- a/bacula/technotes-2.3 +++ b/bacula/technotes-2.3 @@ -2,6 +2,11 @@ General: 10Feb08 +kes First cut of plugin restore code. +kes Fix bug #1047, which had a heap overrun when stripping certain paths, + and do not strip paths on symbolic links. +kes Set catalog backup database and user name from values specified on + the ./configure line. ebl Fix #1031 about wrong pool source information in job report. 09Feb08 kes Fix Win32 build. -- 2.39.5