From 7b74fe048cfbc9d5307f62bdd3d61e3857e55009 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sun, 3 Feb 2008 13:51:07 +0000 Subject: [PATCH] FD plugin enhancements git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6362 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/filed/fd-plugins.c | 9 +++--- bacula/src/filed/fd-plugins.h | 35 ++++++++++++++--------- bacula/src/filed/job.c | 18 ++++++++---- bacula/src/findlib/find.c | 8 +++++- bacula/src/findlib/find.h | 3 +- bacula/src/lib/plugins.h | 1 - bacula/src/plugins/fd/example-plugin-fd.c | 8 +++--- bacula/src/stored/bextract.c | 3 ++ bacula/src/stored/bls.c | 3 ++ bacula/src/tools/Makefile.in | 2 +- bacula/src/tools/testfind.c | 16 +++++------ bacula/src/tools/testls.c | 15 +++++----- 12 files changed, 74 insertions(+), 47 deletions(-) diff --git a/bacula/src/filed/fd-plugins.c b/bacula/src/filed/fd-plugins.c index 1547f14a52..5fd41338db 100644 --- a/bacula/src/filed/fd-plugins.c +++ b/bacula/src/filed/fd-plugins.c @@ -52,13 +52,13 @@ static bpError baculaDebugMsg(bpContext *ctx, const char *file, int line, /* Bacula info */ static bInfo binfo = { sizeof(bFuncs), - PLUGIN_INTERFACE, + PLUGIN_INTERFACE_VERSION }; /* Bacula entry points */ static bFuncs bfuncs = { sizeof(bFuncs), - PLUGIN_INTERFACE, + PLUGIN_INTERFACE_VERSION, baculaRegisterEvents, baculaGetValue, baculaSetValue, @@ -69,7 +69,7 @@ static bFuncs bfuncs = { /* * Create a plugin event */ -void generate_plugin_event(JCR *jcr, bEventType eventType) +void generate_plugin_event(JCR *jcr, bEventType eventType, void *value) { bEvent event; Plugin *plugin; @@ -83,7 +83,7 @@ void generate_plugin_event(JCR *jcr, bEventType eventType) Dmsg2(dbglvl, "plugin_ctx=%p JobId=%d\n", jcr->plugin_ctx, jcr->JobId); event.eventType = eventType; foreach_alist(plugin, plugin_list) { - plug_func(plugin)->handlePluginEvent(&plugin_ctx[i++], &event); + plug_func(plugin)->handlePluginEvent(&plugin_ctx[i++], &event, value); } } @@ -221,7 +221,6 @@ static bpError baculaDebugMsg(bpContext *ctx, const char *file, int line, #ifdef TEST_PROGRAM - int main(int argc, char *argv[]) { char plugin_dir[1000]; diff --git a/bacula/src/filed/fd-plugins.h b/bacula/src/filed/fd-plugins.h index 550dce40e6..dc608f557c 100644 --- a/bacula/src/filed/fd-plugins.h +++ b/bacula/src/filed/fd-plugins.h @@ -43,12 +43,6 @@ #include "bc_types.h" #include "lib/plugins.h" -#ifdef __cplusplus -extern "C" { -#endif - - - /**************************************************************************** * * @@ -71,6 +65,16 @@ typedef enum { typedef enum { bEventJobStart = 1, bEventJobEnd = 2, + bEventBackupStart = 3, + bEventBackupEnd = 4, + bEventRestoreStart = 5, + bEventRestoreEnd = 6, + bEventVerifyStart = 7, + bEventVerifyEnd = 8, + bEventPluginCommand = 9, + bEventPluginFile = 10, + bEventLevel = 11, + bEventSince = 12, } bEventType; typedef struct s_bEvent { @@ -82,6 +86,16 @@ typedef struct s_baculaInfo { uint32_t version; } bInfo; +/* Bacula Core Routines -- not used by plugins */ +void load_fd_plugins(const char *plugin_dir); +void new_plugins(JCR *jcr); +void free_plugins(JCR *jcr); +void generate_plugin_event(JCR *jcr, bEventType event, void *value=NULL); + +#ifdef __cplusplus +extern "C" { +#endif + /* Bacula interface version and function pointers */ typedef struct s_baculaFuncs { uint32_t size; @@ -95,11 +109,6 @@ typedef struct s_baculaFuncs { int level, const char *msg); } bFuncs; -/* Bacula Subroutines */ -void load_fd_plugins(const char *plugin_dir); -void new_plugins(JCR *jcr); -void free_plugins(JCR *jcr); -void generate_plugin_event(JCR *jcr, bEventType event); @@ -116,7 +125,7 @@ typedef enum { #define PLUGIN_MAGIC "*PluginData*" -#define PLUGIN_INTERFACE 1 +#define PLUGIN_INTERFACE_VERSION 1 typedef struct s_pluginInfo { uint32_t size; @@ -136,7 +145,7 @@ typedef struct s_pluginFuncs { 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); + bpError (*handlePluginEvent)(bpContext *ctx, bEvent *event, void *value); } pFuncs; #define plug_func(plugin) ((pFuncs *)(plugin->pfuncs)) diff --git a/bacula/src/filed/job.c b/bacula/src/filed/job.c index 106bff14a8..6617d6a58b 100644 --- a/bacula/src/filed/job.c +++ b/bacula/src/filed/job.c @@ -465,6 +465,7 @@ static int job_cmd(JCR *jcr) jcr->sd_auth_key = bstrdup(sd_auth_key); free_pool_memory(sd_auth_key); Dmsg2(120, "JobId=%d Auth=%s\n", jcr->JobId, jcr->sd_auth_key); + generate_plugin_event(jcr, bEventJobStart, (void *)dir->msg); return dir->fsend(OKjob, VERSION, LSMDATE, HOST_OS, DISTNAME, DISTVER); } @@ -1283,6 +1284,7 @@ static int level_cmd(JCR *jcr) Dmsg2(100, "adj = %d since_time=%d\n", (int)adj, (int)since_time); jcr->incremental = 1; /* set incremental or decremental backup */ jcr->mtime = (time_t)since_time; /* set since time */ + generate_plugin_event(jcr, bEventSince, (void *)jcr->mtime); } else { Jmsg1(jcr, M_FATAL, 0, _("Unknown backup level: %s\n"), level); free_memory(level); @@ -1292,6 +1294,7 @@ static int level_cmd(JCR *jcr) if (buf) { free_memory(buf); } + generate_plugin_event(jcr, bEventLevel, (void *)jcr->JobLevel); return dir->fsend(OKlevel); bail_out: @@ -1437,10 +1440,10 @@ static int backup_cmd(JCR *jcr) } generate_daemon_event(jcr, "JobStart"); - generate_plugin_event(jcr, bEventJobStart); + generate_plugin_event(jcr, bEventBackupStart); #if defined(WIN32_VSS) - /* START VSS ON WIN 32 */ + /* START VSS ON WIN32 */ if (jcr->VSS) { if (g_pVSSClient->InitializeForBackup()) { /* tell vss which drives to snapshot */ @@ -1532,7 +1535,7 @@ static int backup_cmd(JCR *jcr) cleanup: #if defined(WIN32_VSS) - /* STOP VSS ON WIN 32 */ + /* STOP VSS ON WIN32 */ /* tell vss to close the backup session */ if (jcr->VSS) { if (g_pVSSClient->CloseBackup()) { @@ -1550,6 +1553,7 @@ cleanup: } #endif + generate_plugin_event(jcr, bEventBackupEnd); return 0; /* return and stop command loop */ } @@ -1587,7 +1591,8 @@ static int verify_cmd(JCR *jcr) dir->fsend(OKverify); generate_daemon_event(jcr, "JobStart"); - generate_plugin_event(jcr, bEventJobStart); + generate_plugin_event(jcr, bEventLevel, (void *)jcr->JobLevel); + generate_plugin_event(jcr, bEventVerifyStart); Dmsg1(110, "bfiled>dird: %s", dir->msg); @@ -1625,7 +1630,7 @@ static int verify_cmd(JCR *jcr) } dir->signal(BNET_EOD); - + generate_plugin_event(jcr, bEventVerifyEnd); return 0; /* return and terminate command loop */ } @@ -1703,7 +1708,7 @@ static int restore_cmd(JCR *jcr) */ start_dir_heartbeat(jcr); generate_daemon_event(jcr, "JobStart"); - generate_plugin_event(jcr, bEventJobStart); + generate_plugin_event(jcr, bEventRestoreStart); do_restore(jcr); stop_dir_heartbeat(jcr); @@ -1730,6 +1735,7 @@ bail_out: } Dmsg0(130, "Done in job.c\n"); + generate_plugin_event(jcr, bEventRestoreEnd); return 0; /* return and terminate command loop */ } diff --git a/bacula/src/findlib/find.c b/bacula/src/findlib/find.c index d12fcf48ff..e9e1d94f25 100644 --- a/bacula/src/findlib/find.c +++ b/bacula/src/findlib/find.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2007 Free Software Foundation Europe e.V. + Copyright (C) 2000-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. @@ -201,6 +201,12 @@ find_files(JCR *jcr, FF_PKT *ff, int callback(FF_PKT *ff_pkt, void *hpkt, bool t return 0; /* error return */ } } + foreach_dlist(node, &incexe->plugin_list) { + char *fname = node->c_str(); + Dmsg1(100, "P %s\n", fname); + ff->top_fname = fname; + generate_plugin_event(jcr, bEventPluginCommand, (void *)fname); + } } } return 1; diff --git a/bacula/src/findlib/find.h b/bacula/src/findlib/find.h index 3dd02c0841..9860ff5369 100644 --- a/bacula/src/findlib/find.h +++ b/bacula/src/findlib/find.h @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2001-2007 Free Software Foundation Europe e.V. + Copyright (C) 2001-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. @@ -36,6 +36,7 @@ #include "jcr.h" #include "bfile.h" +#include "../filed/fd-plugins.h" #ifdef HAVE_DIRENT_H #include diff --git a/bacula/src/lib/plugins.h b/bacula/src/lib/plugins.h index 241d34a35f..0320832309 100644 --- a/bacula/src/lib/plugins.h +++ b/bacula/src/lib/plugins.h @@ -57,7 +57,6 @@ int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result); extern DLL_IMP_EXP alist *plugin_list; - /* Universal return code from all functions */ typedef int32_t bpError; diff --git a/bacula/src/plugins/fd/example-plugin-fd.c b/bacula/src/plugins/fd/example-plugin-fd.c index 50452936e0..044b7594db 100644 --- a/bacula/src/plugins/fd/example-plugin-fd.c +++ b/bacula/src/plugins/fd/example-plugin-fd.c @@ -49,7 +49,7 @@ static bpError newPlugin(bpContext *ctx); static bpError freePlugin(bpContext *ctx); static bpError getPluginValue(bpContext *ctx, pVariable var, void *value); static bpError setPluginValue(bpContext *ctx, pVariable var, void *value); -static bpError handlePluginEvent(bpContext *ctx, bEvent *event); +static bpError handlePluginEvent(bpContext *ctx, bEvent *event, void *value); /* Pointers to Bacula functions */ @@ -58,7 +58,7 @@ static bInfo *binfo = NULL; static pInfo pluginInfo = { sizeof(pluginInfo), - PLUGIN_INTERFACE, + PLUGIN_INTERFACE_VERSION, PLUGIN_MAGIC, PLUGIN_LICENSE, PLUGIN_AUTHOR, @@ -69,7 +69,7 @@ static pInfo pluginInfo = { static pFuncs pluginFuncs = { sizeof(pluginFuncs), - PLUGIN_INTERFACE, + PLUGIN_INTERFACE_VERSION, /* Entry points into plugin */ newPlugin, /* new plugin instance */ @@ -126,7 +126,7 @@ static bpError setPluginValue(bpContext *ctx, pVariable var, void *value) return 0; } -static bpError handlePluginEvent(bpContext *ctx, bEvent *event) +static bpError handlePluginEvent(bpContext *ctx, bEvent *event, void *value) { char *name; switch (event->eventType) { diff --git a/bacula/src/stored/bextract.c b/bacula/src/stored/bextract.c index d3bda67e04..b4c9ff1a44 100644 --- a/bacula/src/stored/bextract.c +++ b/bacula/src/stored/bextract.c @@ -515,3 +515,6 @@ bool dir_get_volume_info(DCR *dcr, enum get_vol_info_rw writing) Dmsg2(500, "Vol=%s num_parts=%d\n", dcr->VolCatInfo.VolCatName, dcr->VolCatInfo.VolCatParts); return 1; } + +void generate_plugin_event(JCR *jcr, bEventType eventType, void *value) +{ return; } diff --git a/bacula/src/stored/bls.c b/bacula/src/stored/bls.c index ab36f4af8f..a3a344eeed 100644 --- a/bacula/src/stored/bls.c +++ b/bacula/src/stored/bls.c @@ -472,3 +472,6 @@ bool dir_get_volume_info(DCR *dcr, enum get_vol_info_rw writing) Dmsg2(500, "Vol=%s num_parts=%d\n", dcr->VolCatInfo.VolCatName, dcr->VolCatInfo.VolCatParts); return 1; } + +void generate_plugin_event(JCR *jcr, bEventType eventType, void *value) +{ return; } diff --git a/bacula/src/tools/Makefile.in b/bacula/src/tools/Makefile.in index 1dc10c8b9f..be1ebdd3bb 100644 --- a/bacula/src/tools/Makefile.in +++ b/bacula/src/tools/Makefile.in @@ -81,7 +81,7 @@ inc_conf.o: ../dird/inc_conf.c $(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) $(PYTHON_INC) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) $< testfind: ../findlib/libfind.a ../lib/libbac.a $(FINDOBJS) - $(CXX) -g $(LDFLAGS) -L. -L../lib -L../findlib -o $@ $(FINDOBJS) \ + $(CXX) -g $(LDFLAGS) -o $@ $(FINDOBJS) -L. -L../lib -L../findlib \ $(DLIB) -lfind -lbac -lm $(LIBS) $(GETTEXT_LIBS) $(OPENSSL_LIBS) testls: ../findlib/libfind.a ../lib/libbac.a testls.o diff --git a/bacula/src/tools/testfind.c b/bacula/src/tools/testfind.c index 2c3d5d0f34..c42a9043a3 100644 --- a/bacula/src/tools/testfind.c +++ b/bacula/src/tools/testfind.c @@ -1,13 +1,7 @@ -/* - * Test program for find files - * - * Kern Sibbald, MM - * - */ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2006 Free Software Foundation Europe e.V. + Copyright (C) 2000-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. @@ -31,12 +25,17 @@ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, Switzerland, email:ftf@fsfeurope.org. */ +/* + * Test program for find files + * + * Kern Sibbald, MM + * + */ #include "bacula.h" #include "dird/dird.h" #include "findlib/find.h" - #if defined(HAVE_WIN32) #define isatty(fd) (fd==0) #endif @@ -44,6 +43,7 @@ /* Dummy functions */ int generate_daemon_event(JCR *jcr, const char *event) { return 1; } int generate_job_event(JCR *jcr, const char *event) { return 1; } +void generate_plugin_event(JCR *jcr, bEventType eventType, void *value) { } /* Global variables */ static int num_files = 0; diff --git a/bacula/src/tools/testls.c b/bacula/src/tools/testls.c index c28b4c4007..22d9a78a66 100644 --- a/bacula/src/tools/testls.c +++ b/bacula/src/tools/testls.c @@ -1,13 +1,7 @@ -/* - * Test program for listing files during regression testing - * - * Kern Sibbald, MM - * - */ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2006 Free Software Foundation Europe e.V. + Copyright (C) 2000-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. @@ -31,6 +25,12 @@ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, Switzerland, email:ftf@fsfeurope.org. */ +/* + * Test program for listing files during regression testing + * + * Kern Sibbald, MM + * + */ #include "bacula.h" #include "findlib/find.h" @@ -38,6 +38,7 @@ /* Dummy functions */ int generate_daemon_event(JCR *jcr, const char *event) { return 1; } int generate_job_event(JCR *jcr, const char *event) { return 1; } +void generate_plugin_event(JCR *jcr, bEventType eventType, void *value) { } /* Global variables */ -- 2.39.5