From: Kern Sibbald Date: Tue, 12 Feb 2008 14:27:18 +0000 (+0000) Subject: Plugin update X-Git-Tag: Release-7.0.0~5036 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=3592a9b3d4fcc85340f4516d716c459c86311c4e;p=bacula%2Fbacula Plugin update git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6403 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/dird/restore.c b/bacula/src/dird/restore.c index 2c3b213bae..bd27d6e946 100644 --- a/bacula/src/dird/restore.c +++ b/bacula/src/dird/restore.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2007 Free Software Foundation Europe e.V. + Copyright (C) 2000-20087 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. @@ -117,7 +117,7 @@ bool do_restore(JCR *jcr) restore_cleanup(jcr, JS_ErrorTerminated); return false; } - if (!bnet_fsend(jcr->store_bsock, "run")) { + if (!jcr->store_bsock->fsend("run")) { return false; } /* @@ -150,7 +150,7 @@ bool do_restore(JCR *jcr) if (jcr->rstore->SDDport == 0) { jcr->rstore->SDDport = jcr->rstore->SDport; } - bnet_fsend(fd, storaddr, jcr->rstore->address, jcr->rstore->SDDport); + fd->fsend(storaddr, jcr->rstore->address, jcr->rstore->SDDport); Dmsg1(6, "dird>filed: %s\n", fd->msg); if (!response(jcr, fd, OKstore, "Storage", DISPLAY_ERROR)) { restore_cleanup(jcr, JS_ErrorTerminated); @@ -198,15 +198,15 @@ bool do_restore(JCR *jcr) where = jcr->job->RestoreWhere; /* no override take from job */ cmd = restorecmd; - } else { /* nothing was specified */ - where = ∅ /* use default */ - cmd = restorecmd; + } else { /* nothing was specified */ + where = ∅ /* use default */ + cmd = restorecmd; } jcr->prefix_links = jcr->job->PrefixLinks; bash_spaces(where); - bnet_fsend(fd, cmd, replace, jcr->prefix_links, where); + fd->fsend(cmd, replace, jcr->prefix_links, where); unbash_spaces(where); if (!response(jcr, fd, OKrestore, "Restore", DISPLAY_ERROR)) { @@ -265,7 +265,7 @@ void restore_cleanup(JCR *jcr, int TermCode) term_msg = _("*** Restore Error ***"); msg_type = M_ERROR; /* Generate error message */ if (jcr->store_bsock) { - bnet_sig(jcr->store_bsock, BNET_TERMINATE); + jcr->store_bsock->signal(BNET_TERMINATE); if (jcr->SD_msg_chan) { pthread_cancel(jcr->SD_msg_chan); } @@ -274,7 +274,7 @@ void restore_cleanup(JCR *jcr, int TermCode) case JS_Canceled: term_msg = _("Restore Canceled"); if (jcr->store_bsock) { - bnet_sig(jcr->store_bsock, BNET_TERMINATE); + jcr->store_bsock->signal(BNET_TERMINATE); if (jcr->SD_msg_chan) { pthread_cancel(jcr->SD_msg_chan); } diff --git a/bacula/src/filed/fd-plugins.c b/bacula/src/filed/fd-plugins.c index 4f866b766a..e562df1a05 100644 --- a/bacula/src/filed/fd-plugins.c +++ b/bacula/src/filed/fd-plugins.c @@ -283,6 +283,34 @@ bail_out: return; } +/* + * Tell the plugin to create the file. Return values are + * + * CF_ERROR -- error + * CF_SKIP -- skip processing this file + * CF_EXTRACT -- extract the file (i.e.call i/o routines) + * CF_CREATED -- created, but no content to extract (typically directories) + * + */ +int plugin_create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace) +{ +// bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx; +// Plugin *plugin = (Plugin *)jcr->plugin; + if (!set_cmd_plugin(bfd, jcr)) { + return CF_ERROR; + } + return CF_EXTRACT; +} + +/* + * Reset the file attributes after all file I/O is done -- this allows + * the previous access time/dates to be set properly, and it also allows + * us to properly set directory permissions. + */ +bool plugin_set_attributes(JCR *jcr, ATTR *attr, BFILE *ofd) +{ + return true; +} void load_fd_plugins(const char *plugin_dir) { @@ -494,11 +522,16 @@ ssize_t (*plugin_bread)(JCR *jcr, void *buf, size_t count) = NULL; ssize_t (*plugin_bwrite)(JCR *jcr, void *buf, size_t count) = NULL; boffset_t (*plugin_blseek)(JCR *jcr, boffset_t offset, int whence) = NULL; -int save_file(FF_PKT *ff_pkt, void *vjcr, bool top_level) +int save_file(JCR *jcr, FF_PKT *ff_pkt, bool top_level) { return 0; } +bool set_cmd_plugin(BFILE *bfd, JCR *jcr) +{ + return true; +} + 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 a725575a87..941192be2c 100644 --- a/bacula/src/filed/fd-plugins.h +++ b/bacula/src/filed/fd-plugins.h @@ -26,7 +26,7 @@ Switzerland, email:ftf@fsfeurope.org. */ /* - * Interface definition for Bacula Plugins + * Application Programming Interface (API) definition for Bacula Plugins * * Kern Sibbald, October 2007 * @@ -76,11 +76,13 @@ struct save_pkt { struct restore_pkt { }; -#define IO_OPEN 1 -#define IO_READ 2 -#define IO_WRITE 3 -#define IO_CLOSE 4 -#define IO_SEEK 5 +enum { + IO_OPEN = 1, + IO_READ = 2, + IO_WRITE = 3, + IO_CLOSE = 4, + IO_SEEK = 5 +}; struct io_pkt { int32_t func; /* Function code */ @@ -135,18 +137,24 @@ typedef struct s_baculaInfo { } bInfo; /* Bacula Core Routines -- not used by plugins */ +struct BFILE; /* forward referenced */ 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); bool send_plugin_name(JCR *jcr, BSOCK *sd, bool start); void plugin_name_stream(JCR *jcr, char *name); +int plugin_create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace); +bool plugin_set_attributes(JCR *jcr, ATTR *attr, BFILE *ofd); #ifdef __cplusplus extern "C" { #endif -/* Bacula interface version and function pointers */ +/* + * Bacula interface version and function pointers -- + * i.e. callbacks from the plugin to Bacula + */ typedef struct s_baculaFuncs { uint32_t size; uint32_t version; @@ -188,6 +196,10 @@ typedef struct s_pluginInfo { char *plugin_description; } pInfo; +/* + * This is a set of function pointers that Bacula can call + * within the plugin. + */ typedef struct s_pluginFuncs { uint32_t size; uint32_t version; @@ -198,8 +210,11 @@ typedef struct s_pluginFuncs { bRC (*handlePluginEvent)(bpContext *ctx, bEvent *event, void *value); bRC (*startPluginBackup)(bpContext *ctx, struct save_pkt *sp); bRC (*endPluginBackup)(bpContext *ctx); + bRC (*startRestoreFile)(bpContext *ctx, const char *cmd); + bRC (*endRestoreFile)(bpContext *ctx); bRC (*pluginIO)(bpContext *ctx, struct io_pkt *io); - bRC (*createPluginFile)(bpContext *ctx, struct restore_pkt *rp); + bRC (*createFile)(bpContext *ctx, struct restore_pkt *rp); + bRC (*setFileAttributes)(bpContext *ctx, struct restore_pkt *rp); } pFuncs; #define plug_func(plugin) ((pFuncs *)(plugin->pfuncs)) diff --git a/bacula/src/filed/restore.c b/bacula/src/filed/restore.c index 1aa65ec22a..2032af27b0 100644 --- a/bacula/src/filed/restore.c +++ b/bacula/src/filed/restore.c @@ -120,7 +120,7 @@ bool flush_cipher(JCR *jcr, BFILE *bfd, uint64_t *addr, int flags, /* * Close a bfd check that we are at the expected file offset. - * Makes some code in set_attributes(). + * Makes use of some code from set_attributes(). */ static int bclose_chksize(JCR *jcr, BFILE *bfd, boffset_t osize) { @@ -299,7 +299,11 @@ void do_restore(JCR *jcr) deallocate_fork_cipher(rctx); } - set_attributes(jcr, attr, &rctx.bfd); + if (jcr->plugin) { + plugin_set_attributes(jcr, attr, &rctx.bfd); + } else { + set_attributes(jcr, attr, &rctx.bfd); + } extract = false; /* Verify the cryptographic signature, if any */ @@ -345,11 +349,16 @@ void do_restore(JCR *jcr) build_attr_output_fnames(jcr, attr); /* - * Now determine if we are extracting or not. + * Try to actually create the file, which returns a status telling + * us if we need to extract or not. */ jcr->num_files_examined++; extract = false; - stat = create_file(jcr, attr, &rctx.bfd, jcr->replace); + if (jcr->plugin) { + stat = plugin_create_file(jcr, attr, &rctx.bfd, jcr->replace); + } else { + stat = create_file(jcr, attr, &rctx.bfd, jcr->replace); + } Dmsg2(30, "Outfile=%s create_file stat=%d\n", attr->ofname, stat); switch (stat) { case CF_ERROR: @@ -376,7 +385,11 @@ void do_restore(JCR *jcr) } if (!extract) { /* set attributes now because file will not be extracted */ - set_attributes(jcr, attr, &rctx.bfd); + if (jcr->plugin) { + plugin_set_attributes(jcr, attr, &rctx.bfd); + } else { + set_attributes(jcr, attr, &rctx.bfd); + } } break; } @@ -646,7 +659,11 @@ void do_restore(JCR *jcr) deallocate_cipher(rctx); deallocate_fork_cipher(rctx); - set_attributes(jcr, attr, &rctx.bfd); + if (jcr->plugin) { + plugin_set_attributes(jcr, attr, &rctx.bfd); + } else { + set_attributes(jcr, attr, &rctx.bfd); + } /* Verify the cryptographic signature if any */ rctx.type = attr->type; @@ -675,7 +692,11 @@ void do_restore(JCR *jcr) deallocate_cipher(rctx); deallocate_fork_cipher(rctx); - set_attributes(jcr, attr, &rctx.bfd); + if (jcr->plugin) { + plugin_set_attributes(jcr, attr, &rctx.bfd); + } else { + set_attributes(jcr, attr, &rctx.bfd); + } /* Verify the cryptographic signature on the last file, if any */ rctx.type = attr->type; diff --git a/bacula/src/findlib/bfile.c b/bacula/src/findlib/bfile.c index 586d7502f2..be0d49bd91 100644 --- a/bacula/src/findlib/bfile.c +++ b/bacula/src/findlib/bfile.c @@ -310,11 +310,6 @@ bool set_portable_backup(BFILE *bfd) return true; } -bool set_prog(BFILE *bfd, char *prog, JCR *jcr) -{ - return false; -} - bool set_cmd_plugin(BFILE *bfd, JCR *jcr) { bfd->cmd_plugin = true; diff --git a/bacula/src/jcr.h b/bacula/src/jcr.h index c520b685da..853dea4700 100644 --- a/bacula/src/jcr.h +++ b/bacula/src/jcr.h @@ -122,6 +122,8 @@ class JCR; struct FF_PKT; struct B_DB; struct ATTR_DBR; +struct Plugin; +struct save_pkt; #ifdef FILE_DAEMON struct CRYPTO_CTX { @@ -211,8 +213,8 @@ public: void *plugin_ctx_list; /* list of contexts for plugins */ void *plugin_ctx; /* current plugin context */ - void *plugin; /* plugin instance */ - void *plugin_sp; /* plugin save packet */ + Plugin *plugin; /* plugin instance */ + save_pkt *plugin_sp; /* plugin save packet */ /* Daemon specific part of JCR */ /* This should be empty in the library */ diff --git a/bacula/src/plugins/fd/bpipe-fd.c b/bacula/src/plugins/fd/bpipe-fd.c index c6c841cc76..85aa062bca 100644 --- a/bacula/src/plugins/fd/bpipe-fd.c +++ b/bacula/src/plugins/fd/bpipe-fd.c @@ -54,7 +54,12 @@ 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 startPluginBackup(bpContext *ctx, struct save_pkt *sp); +static bRC endPluginBackup(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); /* Pointers to Bacula functions */ @@ -83,7 +88,12 @@ static pFuncs pluginFuncs = { setPluginValue, handlePluginEvent, startPluginBackup, - pluginIO + endPluginBackup, + startRestoreFile, + endRestoreFile, + pluginIO, + createFile, + setFileAttributes }; struct plugin_ctx { @@ -231,6 +241,11 @@ static bRC startPluginBackup(bpContext *ctx, struct save_pkt *sp) return bRC_OK; } +static bRC endPluginBackup(bpContext *ctx) +{ + return bRC_OK; +} + /* * Do actual I/O */ @@ -281,6 +296,27 @@ static bRC pluginIO(bpContext *ctx, struct io_pkt *io) return bRC_OK; } +static bRC startRestoreFile(bpContext *ctx, const char *cmd) +{ + return bRC_OK; +} + +static bRC endRestoreFile(bpContext *ctx) +{ + return bRC_OK; +} + +static bRC createFile(bpContext *ctx, struct restore_pkt *rp) +{ + return bRC_OK; +} + +static bRC setFileAttributes(bpContext *ctx, struct restore_pkt *rp) +{ + return bRC_OK; +} + + #ifdef __cplusplus } #endif diff --git a/bacula/src/plugins/fd/example-plugin-fd.c b/bacula/src/plugins/fd/example-plugin-fd.c index 24eb218553..935ef6ef9f 100644 --- a/bacula/src/plugins/fd/example-plugin-fd.c +++ b/bacula/src/plugins/fd/example-plugin-fd.c @@ -51,7 +51,12 @@ 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 startPluginBackup(bpContext *ctx, struct save_pkt *sp); +static bRC endPluginBackup(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); /* Pointers to Bacula functions */ @@ -80,7 +85,12 @@ static pFuncs pluginFuncs = { setPluginValue, handlePluginEvent, startPluginBackup, - pluginIO + endPluginBackup, + startRestoreFile, + endRestoreFile, + pluginIO, + createFile, + setFileAttributes }; bRC loadPlugin(bInfo *lbinfo, bFuncs *lbfuncs, pInfo **pinfo, pFuncs **pfuncs) @@ -180,6 +190,11 @@ static bRC startPluginBackup(bpContext *ctx, struct save_pkt *sp) return bRC_OK; } +static bRC endPluginBackup(bpContext *ctx) +{ + return bRC_OK; +} + /* * Do actual I/O */ @@ -204,6 +219,27 @@ static bRC pluginIO(bpContext *ctx, struct io_pkt *io) return bRC_OK; } +static bRC startRestoreFile(bpContext *ctx, const char *cmd) +{ + return bRC_OK; +} + +static bRC endRestoreFile(bpContext *ctx) +{ + return bRC_OK; +} + +static bRC createFile(bpContext *ctx, struct restore_pkt *rp) +{ + return bRC_OK; +} + +static bRC setFileAttributes(bpContext *ctx, struct restore_pkt *rp) +{ + return bRC_OK; +} + + #ifdef __cplusplus } #endif