From: Jakob Haufe Date: Sat, 27 Apr 2013 15:40:59 +0000 (+0200) Subject: First playground for bacula AFS volume FD plugin X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=refs%2Fheads%2Fbafsvol-fd;p=bacula%2Fbacula First playground for bacula AFS volume FD plugin --- diff --git a/bacula/src/plugins/fd/Makefile.in b/bacula/src/plugins/fd/Makefile.in index 207590c166..6d1a7b29d0 100644 --- a/bacula/src/plugins/fd/Makefile.in +++ b/bacula/src/plugins/fd/Makefile.in @@ -16,7 +16,13 @@ LIBDIR=../../lib .c.lo: $(LIBTOOL_COMPILE) $(CXX) $(DEFS) $(DEBUG) $(CPPFLAGS) -I${SRCDIR} -I${FDDIR} -DTEST_PROGRAM -c $< -all: bpipe-fd.la test-plugin-fd.la test-deltaseq-fd.la +all: bpipe-fd.la test-plugin-fd.la test-deltaseq-fd.la bafsvol-fd.la + +bafsvol-fd.lo: bafsvol-fd.c $(FDDIR)/fd_plugins.h + $(LIBTOOL_COMPILE) $(CXX) $(DEFS) $(DEBUG) $(CPPFLAGS) $(CFLAGS) -I../.. -I$(FDDIR) -c bafsvol-fd.c + +bafsvol-fd.la: Makefile bafsvol-fd$(DEFAULT_OBJECT_TYPE) + $(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -shared bafsvol-fd.lo -o $@ -rpath $(plugindir) -module -export-dynamic -avoid-version example-plugin-fd.lo: example-plugin-fd.c ${FDDIR}/fd_plugins.h $(LIBTOOL_COMPILE) $(CXX) $(DEFS) $(DEBUG) $(CPPFLAGS) $(CFLAGS) -I../.. -I${FDDIR} -c example-plugin-fd.c diff --git a/bacula/src/plugins/fd/bafsvol-fd.c b/bacula/src/plugins/fd/bafsvol-fd.c new file mode 100644 index 0000000000..b9848fdbcd --- /dev/null +++ b/bacula/src/plugins/fd/bafsvol-fd.c @@ -0,0 +1,138 @@ +/* vim: set tw=85 ts=8 sw=3 et : */ + +#define BUILD_PLUGIN +#define BUILDING_DLL + +#include "bacula.h" +#include "fd_plugins.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define PLUGIN_LICENSE "AGPLv3" +#define PLUGIN_AUTHOR "Jakob Haufe" +#define PLUGIN_DATE "April 2013" +#define PLUGIN_VERSION "1" +#define PLUGIN_DESCRIPTION "AFS Volume File Daemon Plugin" + +static bRC newPlugin(bpContext *ctx); +static bRC freePlugin(bpContext *ctx); +static bRC getPluginValue(bpContext *ctx, pVariable var, void *value); +static bRC setPluginValue(bpContext *ctx, pVariable var, void *value); +static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value); +static bRC startBackupFile(bpContext *ctx, struct save_pkt *sp); +static bRC endBackupFile(bpContext *ctx); +static bRC pluginIO(bpContext *ctx, struct io_pkt *io); +static bRC startRestoreFile(bpContext *ctx, const char *cmd); +static bRC endRestoreFile(bpContext *ctx); +static bRC createFile(bpContext *ctx, struct restore_pkt *rp); +static bRC setFileAttributes(bpContext *ctx, struct restore_pkt *rp); +static bRC checkFile(bpContext *ctx, char *fname); + +static bFuncs *bfuncs = NULL; +static bInfo *binfo = NULL; + +static pInfo pluginInfo = { + sizeof(pluginInfo), + FD_PLUGIN_INTERFACE_VERSION, + FD_PLUGIN_MAGIC, + PLUGIN_LICENSE, + PLUGIN_AUTHOR, + PLUGIN_DATE, + PLUGIN_VERSION, + PLUGIN_DESCRIPTION, +}; + +static pFuncs pluginFuncs = { + sizeof(pluginFuncs), + FD_PLUGIN_INTERFACE_VERSION, + + newPlugin, + freePlugin, + getPluginValue, + setPluginValue, + handlePluginEvent, + startBackupFile, + endBackupFile, + startRestoreFile, + endRestoreFile, + pluginIO, + createFile, + setFileAttributes, + checkFile +}; + +typedef struct { + char *backupCommand; + uint8_t pluginCommandCnt; + char **pluginCommands; +} pluginInstance; + + +bRC DLL_IMP_EXP +loadPlugin(bInfo *lbinfo, bFuncs *lbfuncs, pInfo **pinfo, pFuncs **pfuncs) +{ + binfo = lbinfo; + bfuncs = lbfuncs; + *pinfo = &pluginInfo; + *pfuncs = &pluginFuncs; + + return bRC_OK; +} + + +bRC DLL_IMP_EXP +unloadPlugin() +{ + return bRC_OK; +} + + +static bRC +newPlugin(bpContext *ctx) +{ + int JobId; + bfuncs->getBaculaValue(ctx, bVarJobId, &JobId); + ctx->pContext=malloc(sizeof(pluginInstance)); + return bRC_OK; +} + +static bRC +freePlugin(bpContext *ctx) +{ + free(ctx->pContext); + return bRC_OK; +} + +static bRC +getPluginValue(bpContext *ctx, pVariable var, void *value) +{ + return bRC_OK; +} + +static bRC +setPluginValue(bpContext *ctx, pVariable var, void *value) +{ + return bRC_OK; +} + +static bRC +handlePluginEvent(bpContext *ctx, bEvent *event, void *value) +{ + bRC retval; + + switch(event->eventType) + { + case bEventJobStart: + retval=bRC_OK; + break; + } + return retval; +} + + + +#ifdef __cplusplus +} +#endif