From a85fa9d2687794425a74e8489840dc388d6a41fb Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Mon, 11 Feb 2008 09:26:35 +0000 Subject: [PATCH] Plugin update git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6401 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/filed/fd-plugins.c | 49 ++++++++++++++++++++++++++--------- bacula/src/filed/fd-plugins.h | 11 +++++++- bacula/src/lib/plugins.h | 5 ++-- 3 files changed, 50 insertions(+), 15 deletions(-) diff --git a/bacula/src/filed/fd-plugins.c b/bacula/src/filed/fd-plugins.c index 320bce366c..4f866b766a 100644 --- a/bacula/src/filed/fd-plugins.c +++ b/bacula/src/filed/fd-plugins.c @@ -81,6 +81,21 @@ static bFuncs bfuncs = { baculaDebugMsg }; +/* + * Sequence of calls for a backup: + * 1. generate_plugin_event called with bEventPluginCommand + * the command string is passed as an argument. + * 2. we find the plugin requested on the command string + * 3. we generate a bEventPluginCommand event to the specified plugin + * 4. we make a startPluginBackup call to the plugin, which gives + * us the data we need in save_pkt + * 5. we call Bacula's save_file() subroutine to save the specified + * file. The plugin will be called at pluginIO() to supply the + * file data. + * + * Sequence of calls for restore: + * See subroutine plugin_name_stream() below. + */ /* * Create a plugin event @@ -119,7 +134,11 @@ void generate_plugin_event(JCR *jcr, bEventType eventType, void *value) 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) { + if (strncmp(plugin->file, cmd, len) != 0) { + i++; + continue; + } + while (!job_canceled(jcr)) { Dmsg1(100, "Command plugin = %s\n", cmd); if (plug_func(plugin)->handlePluginEvent(&plugin_ctx_list[i], &event, value) != bRC_OK) { goto bail_out; @@ -142,9 +161,10 @@ void generate_plugin_event(JCR *jcr, bEventType eventType, void *value) 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); + /* ***FIXME***/ + /* add call to endPluginBackup() and loop on bRC_MORE */ goto bail_out; } - i++; } Jmsg1(jcr, M_ERROR, 0, "Command plugin \"%s\" not found.\n", cmd); break; @@ -152,7 +172,11 @@ void generate_plugin_event(JCR *jcr, bEventType eventType, void *value) default: /* Pass event to every plugin */ foreach_alist(plugin, plugin_list) { - plug_func(plugin)->handlePluginEvent(&plugin_ctx_list[i++], &event, value); + bRC rc; + rc = plug_func(plugin)->handlePluginEvent(&plugin_ctx_list[i++], &event, value); + if (rc != bRC_OK) { + break; + } } break; } @@ -242,17 +266,18 @@ void plugin_name_stream(JCR *jcr, char *name) 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; + if (strncmp(plugin->file, cmd, len) != 0) { + i++; + continue; + } + Dmsg1(100, "Command plugin = %s\n", cmd); + if (plug_func(plugin)->handlePluginEvent(&plugin_ctx_list[i], + &event, (void *)name) != bRC_OK) { goto bail_out; } - i++; + jcr->plugin_ctx = &plugin_ctx_list[i]; + jcr->plugin = plugin; + goto bail_out; } bail_out: return; diff --git a/bacula/src/filed/fd-plugins.h b/bacula/src/filed/fd-plugins.h index 1c73569c4c..a725575a87 100644 --- a/bacula/src/filed/fd-plugins.h +++ b/bacula/src/filed/fd-plugins.h @@ -58,7 +58,8 @@ #include /* - * This packet is used for file save/restore info transfer */ + * This packet is used for file save info transfer. +*/ struct save_pkt { char *fname; /* Full path and filename */ char *link; /* Link name if any */ @@ -69,6 +70,12 @@ struct save_pkt { char *cmd; /* command */ }; +/* + * This packet is used for file restore info transfer. +*/ +struct restore_pkt { +}; + #define IO_OPEN 1 #define IO_READ 2 #define IO_WRITE 3 @@ -190,7 +197,9 @@ typedef struct s_pluginFuncs { bRC (*setPluginValue)(bpContext *ctx, pVariable var, void *value); bRC (*handlePluginEvent)(bpContext *ctx, bEvent *event, void *value); bRC (*startPluginBackup)(bpContext *ctx, struct save_pkt *sp); + bRC (*endPluginBackup)(bpContext *ctx); bRC (*pluginIO)(bpContext *ctx, struct io_pkt *io); + bRC (*createPluginFile)(bpContext *ctx, struct restore_pkt *rp); } pFuncs; #define plug_func(plugin) ((pFuncs *)(plugin->pfuncs)) diff --git a/bacula/src/lib/plugins.h b/bacula/src/lib/plugins.h index 0c8332261b..990f5985ae 100644 --- a/bacula/src/lib/plugins.h +++ b/bacula/src/lib/plugins.h @@ -60,8 +60,9 @@ extern DLL_IMP_EXP alist *plugin_list; /* Universal return codes from all functions */ typedef enum { bRC_OK = 0, /* OK */ - bRC_Stop = 1, /* Stop calling plugins */ - bRC_Error = 2, + bRC_Stop = 1, /* Stop calling other plugins */ + bRC_Error = 2, /* Some kind of error */ + bRC_More = 3, /* More files to backup */ } bRC; /* Context packet as first argument of all functions */ -- 2.39.2