From 68d1144ea120e1c253cb1165969aa24fe280dd77 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Tue, 5 Feb 2008 20:39:06 +0000 Subject: [PATCH] Plugin implementation. First cut backup working git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6371 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/dird/dir-plugins.c | 60 ++++++++--------- bacula/src/dird/dir-plugins.h | 20 +++--- bacula/src/filed/backup.c | 6 +- bacula/src/filed/fd-plugins.c | 111 +++++++++++++++++++++---------- bacula/src/filed/pythonfd.c | 57 ---------------- bacula/src/findlib/bfile.c | 6 -- bacula/src/findlib/bfile.h | 15 ----- bacula/src/findlib/find.c | 2 +- bacula/src/jcr.h | 4 +- bacula/src/lib/plugins.c | 6 +- bacula/src/plugins/fd/bpipe-fd.c | 71 +++++++++++++------- bacula/src/version.h | 4 +- 12 files changed, 177 insertions(+), 185 deletions(-) diff --git a/bacula/src/dird/dir-plugins.c b/bacula/src/dird/dir-plugins.c index f2c2986b0b..53eaa3e6d8 100644 --- a/bacula/src/dird/dir-plugins.c +++ b/bacula/src/dird/dir-plugins.c @@ -40,12 +40,12 @@ const char *plugin_type = "-dir.so"; /* Forward referenced functions */ -static bpError baculaGetValue(bpContext *ctx, brVariable var, void *value); -static bpError baculaSetValue(bpContext *ctx, bwVariable var, void *value); -static bpError baculaRegisterEvents(bpContext *ctx, ...); -static bpError baculaJobMsg(bpContext *ctx, const char *file, int line, +static bRC baculaGetValue(bpContext *ctx, brVariable var, void *value); +static bRC baculaSetValue(bpContext *ctx, bwVariable var, void *value); +static bRC baculaRegisterEvents(bpContext *ctx, ...); +static bRC baculaJobMsg(bpContext *ctx, const char *file, int line, int type, time_t mtime, const char *msg); -static bpError baculaDebugMsg(bpContext *ctx, const char *file, int line, +static bRC baculaDebugMsg(bpContext *ctx, const char *file, int line, int level, const char *msg); @@ -79,11 +79,11 @@ void generate_plugin_event(JCR *jcr, bEventType eventType) return; } - bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx; - Dmsg2(dbglvl, "plugin_ctx=%p JobId=%d\n", jcr->plugin_ctx, jcr->JobId); + bpContext *plugin_ctx_list = (bpContext *)jcr->plugin_ctx_list; + Dmsg2(dbglvl, "plugin_ctx_list=%p JobId=%d\n", jcr->plugin_ctx_list, jcr->JobId); event.eventType = eventType; foreach_alist(plugin, plugin_list) { - plug_func(plugin)->handlePluginEvent(&plugin_ctx[i++], &event); + plug_func(plugin)->handlePluginEvent(&plugin_ctx_list[i++], &event); } } @@ -115,15 +115,15 @@ void new_plugins(JCR *jcr) return; } - jcr->plugin_ctx = (void *)malloc(sizeof(bpContext) * num); + jcr->plugin_ctx_list = (void *)malloc(sizeof(bpContext) * num); - bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx; - Dmsg2(dbglvl, "Instantiate plugin_ctx=%p JobId=%d\n", jcr->plugin_ctx, jcr->JobId); + bpContext *plugin_ctx_list = (bpContext *)jcr->plugin_ctx_list; + Dmsg2(dbglvl, "Instantiate plugin_ctx_list=%p JobId=%d\n", jcr->plugin_ctx_list, jcr->JobId); foreach_alist(plugin, plugin_list) { /* Start a new instance of each plugin */ - plugin_ctx[i].bContext = (void *)jcr; - plugin_ctx[i].pContext = NULL; - plug_func(plugin)->newPlugin(&plugin_ctx[i++]); + plugin_ctx_list[i].bContext = (void *)jcr; + plugin_ctx_list[i].pContext = NULL; + plug_func(plugin)->newPlugin(&plugin_ctx_list[i++]); } } @@ -139,14 +139,14 @@ void free_plugins(JCR *jcr) return; } - bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx; - Dmsg2(dbglvl, "Free instance plugin_ctx=%p JobId=%d\n", jcr->plugin_ctx, jcr->JobId); + bpContext *plugin_ctx_list = (bpContext *)jcr->plugin_ctx_list; + Dmsg2(dbglvl, "Free instance plugin_ctx_list=%p JobId=%d\n", jcr->plugin_ctx_list, jcr->JobId); foreach_alist(plugin, plugin_list) { /* Free the plugin instance */ - plug_func(plugin)->freePlugin(&plugin_ctx[i++]); + plug_func(plugin)->freePlugin(&plugin_ctx_list[i++]); } - free(plugin_ctx); - jcr->plugin_ctx = NULL; + free(plugin_ctx_list); + jcr->plugin_ctx_list = NULL; } @@ -156,12 +156,12 @@ void free_plugins(JCR *jcr) * * ============================================================== */ -static bpError baculaGetValue(bpContext *ctx, brVariable var, void *value) +static bRC baculaGetValue(bpContext *ctx, brVariable var, void *value) { JCR *jcr = (JCR *)(ctx->bContext); // Dmsg1(dbglvl, "bacula: baculaGetValue var=%d\n", var); if (!value) { - return 1; + return bRC_Error; } // Dmsg1(dbglvl, "Bacula: jcr=%p\n", jcr); switch (var) { @@ -172,16 +172,16 @@ static bpError baculaGetValue(bpContext *ctx, brVariable var, void *value) default: break; } - return 0; + return bRC_OK; } -static bpError baculaSetValue(bpContext *ctx, bwVariable var, void *value) +static bRC baculaSetValue(bpContext *ctx, bwVariable var, void *value) { Dmsg1(dbglvl, "bacula: baculaSetValue var=%d\n", var); - return 0; + return bRC_OK; } -static bpError baculaRegisterEvents(bpContext *ctx, ...) +static bRC baculaRegisterEvents(bpContext *ctx, ...) { va_list args; uint32_t event; @@ -191,23 +191,23 @@ static bpError baculaRegisterEvents(bpContext *ctx, ...) Dmsg1(dbglvl, "Plugin wants event=%u\n", event); } va_end(args); - return 0; + return bRC_OK; } -static bpError baculaJobMsg(bpContext *ctx, const char *file, int line, +static bRC baculaJobMsg(bpContext *ctx, const char *file, int line, int type, time_t mtime, const char *msg) { Dmsg5(dbglvl, "Job message: %s:%d type=%d time=%ld msg=%s\n", file, line, type, mtime, msg); - return 0; + return bRC_OK; } -static bpError baculaDebugMsg(bpContext *ctx, const char *file, int line, +static bRC baculaDebugMsg(bpContext *ctx, const char *file, int line, int level, const char *msg) { Dmsg4(dbglvl, "Debug message: %s:%d level=%d msg=%s\n", file, line, level, msg); - return 0; + return bRC_OK; } #ifdef TEST_PROGRAM diff --git a/bacula/src/dird/dir-plugins.h b/bacula/src/dird/dir-plugins.h index 6b779bbfa6..220b26882d 100644 --- a/bacula/src/dird/dir-plugins.h +++ b/bacula/src/dird/dir-plugins.h @@ -107,12 +107,12 @@ typedef struct s_baculaInfo { typedef struct s_baculaFuncs { uint32_t size; uint32_t version; - bpError (*registerBaculaEvents)(bpContext *ctx, ...); - bpError (*getBaculaValue)(bpContext *ctx, brVariable var, void *value); - bpError (*setBaculaValue)(bpContext *ctx, bwVariable var, void *value); - bpError (*JobMessage)(bpContext *ctx, const char *file, int line, + bRC (*registerBaculaEvents)(bpContext *ctx, ...); + bRC (*getBaculaValue)(bpContext *ctx, brVariable var, void *value); + bRC (*setBaculaValue)(bpContext *ctx, bwVariable var, void *value); + bRC (*JobMessage)(bpContext *ctx, const char *file, int line, int type, time_t mtime, const char *msg); - bpError (*DebugMessage)(bpContext *ctx, const char *file, int line, + bRC (*DebugMessage)(bpContext *ctx, const char *file, int line, int level, const char *msg); } bFuncs; @@ -153,11 +153,11 @@ typedef struct s_pluginInfo { typedef struct s_pluginFuncs { uint32_t size; uint32_t version; - bpError (*newPlugin)(bpContext *ctx); - bpError (*freePlugin)(bpContext *ctx); - bpError (*getPluginValue)(bpContext *ctx, pVariable var, void *value); - bpError (*setPluginValue)(bpContext *ctx, pVariable var, void *value); - bpError (*handlePluginEvent)(bpContext *ctx, bEvent *event); + bRC (*newPlugin)(bpContext *ctx); + bRC (*freePlugin)(bpContext *ctx); + bRC (*getPluginValue)(bpContext *ctx, pVariable var, void *value); + bRC (*setPluginValue)(bpContext *ctx, pVariable var, void *value); + bRC (*handlePluginEvent)(bpContext *ctx, bEvent *event); } pFuncs; #define plug_func(plugin) ((pFuncs *)(plugin->pfuncs)) diff --git a/bacula/src/filed/backup.c b/bacula/src/filed/backup.c index 5660fb8244..87afdb62a3 100644 --- a/bacula/src/filed/backup.c +++ b/bacula/src/filed/backup.c @@ -39,7 +39,7 @@ #include "filed.h" /* Forward referenced functions */ -static int save_file(FF_PKT *ff_pkt, void *pkt, bool top_level); +int save_file(FF_PKT *ff_pkt, void *pkt, bool top_level); static void strip_path(FF_PKT *ff_pkt); static void unstrip_path(FF_PKT *ff_pkt); static int send_data(JCR *jcr, int stream, FF_PKT *ff_pkt, DIGEST *digest, DIGEST *signature_digest); @@ -248,7 +248,7 @@ static bool crypto_session_send(JCR *jcr, BSOCK *sd) * 0 if error * -1 to ignore file/directory (not used here) */ -static int save_file(FF_PKT *ff_pkt, void *vjcr, bool top_level) +int save_file(FF_PKT *ff_pkt, void *vjcr, bool top_level) { bool do_read = false; int stat, data_stream; @@ -473,6 +473,8 @@ static int save_file(FF_PKT *ff_pkt, void *vjcr, bool top_level) ff_pkt->type == FT_REPARSE || (!is_portable_backup(&ff_pkt->bfd) && ff_pkt->type == FT_DIREND)) { do_read = true; + } else if (ff_pkt->cmd_plugin) { + do_read = true; } if (do_read) { diff --git a/bacula/src/filed/fd-plugins.c b/bacula/src/filed/fd-plugins.c index 12188cc685..d407240a1d 100644 --- a/bacula/src/filed/fd-plugins.c +++ b/bacula/src/filed/fd-plugins.c @@ -32,12 +32,14 @@ * Kern Sibbald, October 2007 */ #include "bacula.h" -#include "jcr.h" -#include "fd-plugins.h" +#include "filed.h" const int dbglvl = 50; const char *plugin_type = "-fd.so"; +extern int save_file(FF_PKT *ff_pkt, void *vjcr, bool top_level); + + /* Function pointers to be set here */ extern int (*plugin_bopen)(JCR *jcr, const char *fname, int flags, mode_t mode); extern int (*plugin_bclose)(JCR *jcr); @@ -94,36 +96,60 @@ void generate_plugin_event(JCR *jcr, bEventType eventType, void *value) return; } - bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx; + bpContext *plugin_ctx_list = (bpContext *)jcr->plugin_ctx_list; event.eventType = eventType; - Dmsg2(dbglvl, "plugin_ctx=%p JobId=%d\n", jcr->plugin_ctx, jcr->JobId); + 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[i++], &event, value); + plug_func(plugin)->handlePluginEvent(&plugin_ctx_list[i++], &event, value); } - return; + goto bail_out; } /* Handle plugin command here (backup/restore of file) */ + Dmsg1(000, "plugin cmd=%s\n", cmd); if (!(p = strchr(cmd, ':'))) { Jmsg1(jcr, M_ERROR, 0, "Malformed plugin command: %s\n", cmd); - return; + goto bail_out; } len = p - cmd; - if (len > 0) { - foreach_alist(plugin, plugin_list) { - Dmsg3(000, "plugin=%s cmd=%s len=%d\n", plugin->file, cmd, len); - if (strncmp(plugin->file, cmd, len) == 0) { - Dmsg1(000, "Command plugin = %s\n", cmd); - plug_func(plugin)->handlePluginEvent(&plugin_ctx[i], &event, value); - return; + if (len <= 0) { + goto bail_out; + } + + foreach_alist(plugin, plugin_list) { + Dmsg3(000, "plugin=%s cmd=%s len=%d\n", plugin->file, cmd, len); + if (strncmp(plugin->file, cmd, len) == 0) { + struct save_pkt sp; + FF_PKT *ff_pkt; + Dmsg1(000, "Command plugin = %s\n", cmd); + if (plug_func(plugin)->handlePluginEvent(&plugin_ctx_list[i], &event, value) != bRC_OK) { + goto bail_out; } - i++; + memset(&sp, 0, sizeof(sp)); + sp.type = FT_REG; + sp.portable = true; + Dmsg0(000, "Plugin startBackup\n"); + 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; + ff_pkt = jcr->ff; + ff_pkt->fname = sp.fname; + ff_pkt->type = sp.type; + ff_pkt->statp = sp.statp; /* structure copy */ + Dmsg1(000, "Save_file: file=%s\n", ff_pkt->fname); + save_file(ff_pkt, (void *)jcr, true); + goto bail_out; } + i++; } +bail_out: + return; } void load_fd_plugins(const char *plugin_dir) @@ -134,10 +160,10 @@ 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); - plugin_bopen = my_plugin_bopen; - plugin_bclose = my_plugin_bclose; - plugin_bread = my_plugin_bread; - plugin_bwrite = my_plugin_bwrite; + plugin_bopen = my_plugin_bopen; + plugin_bclose = my_plugin_bclose; + plugin_bread = my_plugin_bread; + plugin_bwrite = my_plugin_bwrite; } @@ -159,15 +185,15 @@ void new_plugins(JCR *jcr) return; } - jcr->plugin_ctx = (void *)malloc(sizeof(bpContext) * num); + jcr->plugin_ctx_list = (void *)malloc(sizeof(bpContext) * num); - bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx; - Dmsg2(dbglvl, "Instantiate plugin_ctx=%p JobId=%d\n", jcr->plugin_ctx, jcr->JobId); + bpContext *plugin_ctx_list = (bpContext *)jcr->plugin_ctx_list; + Dmsg2(dbglvl, "Instantiate plugin_ctx=%p JobId=%d\n", plugin_ctx_list, jcr->JobId); foreach_alist(plugin, plugin_list) { /* Start a new instance of each plugin */ - plugin_ctx[i].bContext = (void *)jcr; - plugin_ctx[i].pContext = NULL; - plug_func(plugin)->newPlugin(&plugin_ctx[i++]); + plugin_ctx_list[i].bContext = (void *)jcr; + plugin_ctx_list[i].pContext = NULL; + plug_func(plugin)->newPlugin(&plugin_ctx_list[i++]); } } @@ -183,55 +209,66 @@ void free_plugins(JCR *jcr) return; } - bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx; - Dmsg2(dbglvl, "Free instance plugin_ctx=%p JobId=%d\n", jcr->plugin_ctx, jcr->JobId); + bpContext *plugin_ctx_list = (bpContext *)jcr->plugin_ctx_list; + Dmsg2(dbglvl, "Free instance plugin_ctx=%p JobId=%d\n", plugin_ctx_list, jcr->JobId); foreach_alist(plugin, plugin_list) { /* Free the plugin instance */ - plug_func(plugin)->freePlugin(&plugin_ctx[i++]); + plug_func(plugin)->freePlugin(&plugin_ctx_list[i++]); } - free(plugin_ctx); - jcr->plugin_ctx = NULL; + free(plugin_ctx_list); + jcr->plugin_ctx_list = NULL; } static int my_plugin_bopen(JCR *jcr, const char *fname, int flags, mode_t mode) { + Plugin *plugin = (Plugin *)jcr->plugin; + bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx; struct io_pkt io; Dmsg0(000, "plugin_bopen\n"); io.func = IO_OPEN; io.count = 0; io.buf = NULL; - - return 0; + plug_func(plugin)->pluginIO(plugin_ctx, &io); + return io.status; } static int my_plugin_bclose(JCR *jcr) { + Plugin *plugin = (Plugin *)jcr->plugin; + bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx; struct io_pkt io; Dmsg0(000, "plugin_bclose\n"); io.func = IO_CLOSE; io.count = 0; io.buf = NULL; - return 0; + plug_func(plugin)->pluginIO(plugin_ctx, &io); + return io.status; } static ssize_t my_plugin_bread(JCR *jcr, void *buf, size_t count) { + Plugin *plugin = (Plugin *)jcr->plugin; + bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx; struct io_pkt io; Dmsg0(000, "plugin_bread\n"); io.func = IO_READ; io.count = count; io.buf = (char *)buf; - return 0; + plug_func(plugin)->pluginIO(plugin_ctx, &io); + return (ssize_t)io.status; } static ssize_t my_plugin_bwrite(JCR *jcr, void *buf, size_t count) { + Plugin *plugin = (Plugin *)jcr->plugin; + bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx; struct io_pkt io; Dmsg0(000, "plugin_bwrite\n"); io.func = IO_WRITE; io.count = count; io.buf = (char *)buf; - return 0; + plug_func(plugin)->pluginIO(plugin_ctx, &io); + return (ssize_t)io.status; } /* ============================================================== @@ -310,6 +347,10 @@ int (*plugin_bclose)(JCR *jcr) = NULL; ssize_t (*plugin_bread)(JCR *jcr, void *buf, size_t count) = NULL; ssize_t (*plugin_bwrite)(JCR *jcr, void *buf, size_t count) = NULL; +int save_file(FF_PKT *ff_pkt, void *vjcr, bool top_level) +{ + return 0; +} int main(int argc, char *argv[]) { diff --git a/bacula/src/filed/pythonfd.c b/bacula/src/filed/pythonfd.c index 72e96e54f0..08b1736cde 100644 --- a/bacula/src/filed/pythonfd.c +++ b/bacula/src/filed/pythonfd.c @@ -42,12 +42,6 @@ #undef _POSIX_C_SOURCE #include -/* External function pointers to be set */ -extern bool (*python_set_prog)(JCR *jcr, const char *prog); -extern int (*python_open)(BFILE *bfd, const char *fname, int flags, mode_t mode); -extern int (*python_close)(BFILE *bfd); -extern ssize_t (*python_read)(BFILE *bfd, void *buf, size_t count); - extern JCR *get_jcr_from_PyObject(PyObject *self); extern PyObject *find_method(PyObject *eventsObject, PyObject *method, @@ -64,12 +58,6 @@ PyMethodDef JobMethods[] = { }; -bool my_python_set_prog(JCR *jcr, const char *prog); -int my_python_open(BFILE *bfd, const char *fname, int flags, mode_t mode); -int my_python_close(BFILE *bfd); -ssize_t my_python_read(BFILE *bfd, void *buf, size_t count); - - struct s_vars { const char *name; char *fmt; @@ -231,12 +219,6 @@ static PyObject *set_job_events(PyObject *self, PyObject *arg) Py_INCREF(eObject); jcr->Python_events = (void *)eObject; /* set new events */ - /* Set function pointers to call here */ - python_set_prog = my_python_set_prog; - python_open = my_python_open; - python_close = my_python_close; - python_read = my_python_read; - Py_INCREF(Py_None); return Py_None; } @@ -282,45 +264,6 @@ bail_out: } -bool my_python_set_prog(JCR *jcr, const char *prog) -{ - PyObject *events = (PyObject *)jcr->Python_events; - BFILE *bfd = &jcr->ff->bfd; - char method[MAX_NAME_LENGTH]; - - if (!events) { - return false; - } - bstrncpy(method, prog, sizeof(method)); - bstrncat(method, "_", sizeof(method)); - bstrncat(method, "open", sizeof(method)); - bfd->pio.fo = find_method(events, bfd->pio.fo, method); - bstrncpy(method, prog, sizeof(method)); - bstrncat(method, "_", sizeof(method)); - bstrncat(method, "read", sizeof(method)); - bfd->pio.fr = find_method(events, bfd->pio.fr, method); - bstrncpy(method, prog, sizeof(method)); - bstrncat(method, "_", sizeof(method)); - bstrncat(method, "close", sizeof(method)); - bfd->pio.fc = find_method(events, bfd->pio.fc, method); - return bfd->pio.fo && bfd->pio.fr && bfd->pio.fc; -} - -int my_python_open(BFILE *bfd, const char *fname, int flags, mode_t mode) -{ - return -1; -} - -int my_python_close(BFILE *bfd) -{ - return 0; -} - -ssize_t my_python_read(BFILE *bfd, void *buf, size_t count) -{ - return -1; -} - #else /* Dummy if Python not configured */ diff --git a/bacula/src/findlib/bfile.c b/bacula/src/findlib/bfile.c index 8ee2ff7cd5..d5020dd385 100644 --- a/bacula/src/findlib/bfile.c +++ b/bacula/src/findlib/bfile.c @@ -39,12 +39,6 @@ #include "bacula.h" #include "find.h" -bool (*python_set_prog)(JCR *jcr, const char *prog) = NULL; -int (*python_open)(BFILE *bfd, const char *fname, int flags, mode_t mode) = NULL; -int (*python_close)(BFILE *bfd) = NULL; -ssize_t (*python_read)(BFILE *bfd, void *buf, size_t count) = NULL; -ssize_t (*python_write)(BFILE *bfd, void *buf, size_t count) = NULL; - int (*plugin_bopen)(JCR *jcr, const char *fname, int flags, mode_t mode) = NULL; int (*plugin_bclose)(JCR *jcr) = NULL; ssize_t (*plugin_bread)(JCR *jcr, void *buf, size_t count) = NULL; diff --git a/bacula/src/findlib/bfile.h b/bacula/src/findlib/bfile.h index 7d26775390..d8104d263a 100644 --- a/bacula/src/findlib/bfile.h +++ b/bacula/src/findlib/bfile.h @@ -36,19 +36,6 @@ #ifndef __BFILE_H #define __BFILE_H -#ifdef HAVE_PYTHON -#undef _POSIX_C_SOURCE -#include -struct Python_IO { - PyObject *fo; - PyObject *fr; - PyObject *fc; -}; -#else -struct Python_IO { -}; -#endif - /* this should physically correspond to WIN32_STREAM_ID * from winbase.h on Win32. We didn't inlcude cStreamName @@ -99,7 +86,6 @@ struct BFILE { DWORD lerror; /* Last error code */ int berrno; /* errno */ JCR *jcr; /* jcr for editing job codes */ - Python_IO pio; /* Python I/O routines */ PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT win32DecompContext; /* context for decomposition of win32 backup streams */ int use_backup_decomp; /* set if using BackupRead Stream Decomposition */ bool reparse_point; /* set if reparse point */ @@ -123,7 +109,6 @@ struct BFILE { int m_flags; /* open flags */ int berrno; JCR *jcr; /* jcr for editing job codes */ - Python_IO pio; /* Python I/O routines */ PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT win32DecompContext; /* context for decomposition of win32 backup streams */ int use_backup_decomp; /* set if using BackupRead Stream Decomposition */ bool reparse_point; /* not used in Unix */ diff --git a/bacula/src/findlib/find.c b/bacula/src/findlib/find.c index e2f1c0cd75..c7d789340a 100644 --- a/bacula/src/findlib/find.c +++ b/bacula/src/findlib/find.c @@ -198,7 +198,7 @@ find_files(JCR *jcr, FF_PKT *ff, int callback(FF_PKT *ff_pkt, void *hpkt, bool t } foreach_dlist(node, &incexe->plugin_list) { char *fname = node->c_str(); - Dmsg1(100, "P %s\n", fname); + Dmsg1(000, "PluginCommand: %s\n", fname); ff->top_fname = fname; ff->cmd_plugin = true; generate_plugin_event(jcr, bEventPluginCommand, (void *)fname); diff --git a/bacula/src/jcr.h b/bacula/src/jcr.h index 3a0c959d56..d7b6b9e816 100644 --- a/bacula/src/jcr.h +++ b/bacula/src/jcr.h @@ -209,7 +209,9 @@ public: ATTR_DBR *ar; /* DB attribute record */ guid_list *id_list; /* User/group id to name list */ - void *plugin_ctx; + void *plugin_ctx_list; /* list of contexts for plugins */ + void *plugin_ctx; /* current plugin context */ + void *plugin; /* plugin instance */ /* Daemon specific part of JCR */ /* This should be empty in the library */ diff --git a/bacula/src/lib/plugins.c b/bacula/src/lib/plugins.c index 81b7cfcb2a..3089a979a7 100644 --- a/bacula/src/lib/plugins.c +++ b/bacula/src/lib/plugins.c @@ -121,7 +121,7 @@ bool load_plugins(void *binfo, void *bfuncs, const char *plugin_dir, const char plugin->pHandle = dlopen(fname.c_str(), RTLD_NOW); if (!plugin->pHandle) { Jmsg(NULL, M_ERROR, 0, _("Plugin load %s failed: ERR=%s\n"), - fname.c_str(), dlerror()); + fname.c_str(), NPRT(dlerror())); goto get_out; } @@ -129,13 +129,13 @@ bool load_plugins(void *binfo, void *bfuncs, const char *plugin_dir, const char loadPlugin = (t_loadPlugin)dlsym(plugin->pHandle, "loadPlugin"); if (!loadPlugin) { Jmsg(NULL, M_ERROR, 0, _("Lookup of loadPlugin in plugin %s failed: ERR=%s\n"), - fname.c_str(), dlerror()); + fname.c_str(), NPRT(dlerror())); goto get_out; } plugin->unloadPlugin = (t_unloadPlugin)dlsym(plugin->pHandle, "unloadPlugin"); if (!plugin->unloadPlugin) { Jmsg(NULL, M_ERROR, 0, _("Lookup of unloadPlugin in plugin %s failed: ERR=%s\n"), - fname.c_str(), dlerror()); + fname.c_str(), NPRT(dlerror())); goto get_out; } diff --git a/bacula/src/plugins/fd/bpipe-fd.c b/bacula/src/plugins/fd/bpipe-fd.c index 01e30d3d30..f29eb72b2a 100644 --- a/bacula/src/plugins/fd/bpipe-fd.c +++ b/bacula/src/plugins/fd/bpipe-fd.c @@ -34,6 +34,9 @@ #include #include "fd-plugins.h" +#undef malloc +#undef free + #ifdef __cplusplus extern "C" { #endif @@ -83,11 +86,15 @@ static pFuncs pluginFuncs = { pluginIO }; +struct plugin_ctx { + int record; +}; + bRC loadPlugin(bInfo *lbinfo, bFuncs *lbfuncs, pInfo **pinfo, pFuncs **pfuncs) { bfuncs = lbfuncs; /* set Bacula funct pointers */ binfo = lbinfo; - printf("plugin: Loaded: size=%d version=%d\n", bfuncs->size, bfuncs->version); + printf("bpipe-fd: Loaded: size=%d version=%d\n", bfuncs->size, bfuncs->version); *pinfo = &pluginInfo; /* return pointer to our info */ *pfuncs = &pluginFuncs; /* return pointer to our functions */ @@ -97,36 +104,33 @@ bRC loadPlugin(bInfo *lbinfo, bFuncs *lbfuncs, pInfo **pinfo, pFuncs **pfuncs) bRC unloadPlugin() { - printf("plugin: Unloaded\n"); + printf("bpipe-fd: Unloaded\n"); return bRC_OK; } static bRC newPlugin(bpContext *ctx) { - int JobId = 0; - bfuncs->getBaculaValue(ctx, bVarJobId, (void *)&JobId); -// printf("plugin: newPlugin JobId=%d\n", JobId); - bfuncs->registerBaculaEvents(ctx, 1, 2, 0); + struct plugin_ctx *p_ctx = (struct plugin_ctx *)malloc(sizeof(struct plugin_ctx)); + + p_ctx->record = -1; + ctx->pContext = (void *)p_ctx; /* set our context pointer */ return bRC_OK; } static bRC freePlugin(bpContext *ctx) { - int JobId = 0; - bfuncs->getBaculaValue(ctx, bVarJobId, (void *)&JobId); -// printf("plugin: freePlugin JobId=%d\n", JobId); + struct plugin_ctx *p_ctx = (struct plugin_ctx *)ctx->pContext; + free(p_ctx); return bRC_OK; } static bRC getPluginValue(bpContext *ctx, pVariable var, void *value) { -// printf("plugin: getPluginValue var=%d\n", var); return bRC_OK; } static bRC setPluginValue(bpContext *ctx, pVariable var, void *value) { -// printf("plugin: setPluginValue var=%d\n", var); return bRC_OK; } @@ -136,31 +140,31 @@ static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value) switch (event->eventType) { case bEventJobStart: - printf("plugin: JobStart=%s\n", (char *)value); + printf("bpipe-fd: JobStart=%s\n", (char *)value); break; case bEventJobEnd: - printf("plugin: JobEnd\n"); + printf("bpipe-fd: JobEnd\n"); break; case bEventBackupStart: - printf("plugin: BackupStart\n"); + printf("bpipe-fd: BackupStart\n"); break; case bEventBackupEnd: - printf("plugin: BackupEnd\n"); + printf("bpipe-fd: BackupEnd\n"); break; case bEventLevel: - printf("plugin: JobLevel=%c %d\n", (int)value, (int)value); + printf("bpipe-fd: JobLevel=%c %d\n", (int)value, (int)value); break; case bEventSince: - printf("plugin: since=%d\n", (int)value); + printf("bpipe-fd: since=%d\n", (int)value); break; /* Plugin command e.g. plugin = ::command */ case bEventPluginCommand: - printf("plugin: command=%s\n", (char *)value); + printf("bpipe-fd: command=%s\n", (char *)value); break; default: - printf("plugin: unknown event=%d\n", event->eventType); + printf("bpipe-fd: unknown event=%d\n", event->eventType); } bfuncs->getBaculaValue(ctx, bVarFDName, (void *)&name); // printf("FD Name=%s\n", name); @@ -171,6 +175,17 @@ static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value) static bRC startPluginBackup(bpContext *ctx, struct save_pkt *sp) { + static char *fname = (char *)"/BPIPE/test.txt"; + time_t now = time(NULL); + sp->fname = fname; + sp->statp.st_mode = 0700; + sp->statp.st_ctime = now; + sp->statp.st_mtime = now; + sp->statp.st_atime = now; + sp->statp.st_size = 100; + sp->statp.st_blksize = 4096; + sp->statp.st_blocks = 1; + printf("bpipe-fd: startPluginBackup\n"); return bRC_OK; } @@ -179,20 +194,30 @@ static bRC startPluginBackup(bpContext *ctx, struct save_pkt *sp) */ static bRC pluginIO(bpContext *ctx, struct io_pkt *io) { + struct plugin_ctx *p_ctx = (struct plugin_ctx *)ctx->pContext; + io->status = 0; io->io_errno = 0; switch(io->func) { case IO_OPEN: - printf("plugin: IO_OPEN\n"); + p_ctx->record = 0; + printf("bpipe-fd: IO_OPEN\n"); break; case IO_READ: - printf("plugin: IO_READ buf=%p len=%d\n", io->buf, io->count); + printf("bpipe-fd: IO_READ buf=%p len=%d\n", io->buf, io->count); + if (p_ctx->record == 0) { + strcpy(io->buf, "This is a test string.\n"); + io->status = strlen(io->buf); + p_ctx->record = 1; + return bRC_OK; + } + io->status = 0; break; case IO_WRITE: - printf("plugin: IO_WRITE buf=%p len=%d\n", io->buf, io->count); + printf("bpipe-fd: IO_WRITE buf=%p len=%d\n", io->buf, io->count); break; case IO_CLOSE: - printf("plugin: IO_CLOSE\n"); + printf("bpipe-fd: IO_CLOSE\n"); break; } return bRC_OK; diff --git a/bacula/src/version.h b/bacula/src/version.h index 38620edfff..dce0a134c7 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -4,8 +4,8 @@ #undef VERSION #define VERSION "2.3.9" -#define BDATE "02 February 2008" -#define LSMDATE "02Feb08" +#define BDATE "05 February 2008" +#define LSMDATE "05Feb08" #define PROG_COPYRIGHT "Copyright (C) %d-2008 Free Software Foundation Europe e.V.\n" #define BYEAR "2008" /* year for copyright messages in progs */ -- 2.39.5