From: Kern Sibbald Date: Thu, 7 Feb 2008 21:24:51 +0000 (+0000) Subject: Plugin update X-Git-Tag: Release-7.0.0~5060 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=20fc7f2a60430f0c87f182aa7e8dc60d5afe168a;p=bacula%2Fbacula Plugin update git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6375 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/baconfig.h b/bacula/src/baconfig.h index c947d31739..0891c40e53 100644 --- a/bacula/src/baconfig.h +++ b/bacula/src/baconfig.h @@ -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. @@ -207,27 +207,27 @@ void InitWinAPIWrapper(); * STREAM_SHA256_DIGEST * STREAM_SHA512_DIGEST */ -#define STREAM_NONE 0 /* Reserved Non-Stream */ -#define STREAM_UNIX_ATTRIBUTES 1 /* Generic Unix attributes */ -#define STREAM_FILE_DATA 2 /* Standard uncompressed data */ -#define STREAM_MD5_SIGNATURE 3 /* deprecated */ -#define STREAM_MD5_DIGEST 3 /* MD5 digest for the file */ -#define STREAM_GZIP_DATA 4 /* GZip compressed file data */ +#define STREAM_NONE 0 /* Reserved Non-Stream */ +#define STREAM_UNIX_ATTRIBUTES 1 /* Generic Unix attributes */ +#define STREAM_FILE_DATA 2 /* Standard uncompressed data */ +#define STREAM_MD5_SIGNATURE 3 /* deprecated */ +#define STREAM_MD5_DIGEST 3 /* MD5 digest for the file */ +#define STREAM_GZIP_DATA 4 /* GZip compressed file data */ /* Extended Unix attributes with Win32 Extended data. Deprecated. */ -#define STREAM_UNIX_ATTRIBUTES_EX 5 /* Extended Unix attr for Win32 EX */ -#define STREAM_SPARSE_DATA 6 /* Sparse data stream */ -#define STREAM_SPARSE_GZIP_DATA 7 -#define STREAM_PROGRAM_NAMES 8 /* program names for program data */ -#define STREAM_PROGRAM_DATA 9 /* Data needing program */ -#define STREAM_SHA1_SIGNATURE 10 /* deprecated */ -#define STREAM_SHA1_DIGEST 10 /* SHA1 digest for the file */ -#define STREAM_WIN32_DATA 11 /* Win32 BackupRead data */ -#define STREAM_WIN32_GZIP_DATA 12 /* Gzipped Win32 BackupRead data */ -#define STREAM_MACOS_FORK_DATA 13 /* Mac resource fork */ -#define STREAM_HFSPLUS_ATTRIBUTES 14 /* Mac OS extra attributes */ +#define STREAM_UNIX_ATTRIBUTES_EX 5 /* Extended Unix attr for Win32 EX */ +#define STREAM_SPARSE_DATA 6 /* Sparse data stream */ +#define STREAM_SPARSE_GZIP_DATA 7 +#define STREAM_PROGRAM_NAMES 8 /* program names for program data */ +#define STREAM_PROGRAM_DATA 9 /* Data needing program */ +#define STREAM_SHA1_SIGNATURE 10 /* deprecated */ +#define STREAM_SHA1_DIGEST 10 /* SHA1 digest for the file */ +#define STREAM_WIN32_DATA 11 /* Win32 BackupRead data */ +#define STREAM_WIN32_GZIP_DATA 12 /* Gzipped Win32 BackupRead data */ +#define STREAM_MACOS_FORK_DATA 13 /* Mac resource fork */ +#define STREAM_HFSPLUS_ATTRIBUTES 14 /* Mac OS extra attributes */ /*** FIXME ***/ -#define STREAM_UNIX_ATTRIBUTES_ACCESS_ACL 15 /* Standard ACL attributes on UNIX */ -#define STREAM_UNIX_ATTRIBUTES_DEFAULT_ACL 16 /* Default ACL attributes on UNIX */ +#define STREAM_UNIX_ACCESS_ACL 15 /* Standard ACL attributes on UNIX */ +#define STREAM_UNIX_DEFAULT_ACL 16 /* Default ACL attributes on UNIX */ /*** FIXME ***/ #define STREAM_SHA256_DIGEST 17 /* SHA-256 digest for the file */ #define STREAM_SHA512_DIGEST 18 /* SHA-512 digest for the file */ diff --git a/bacula/src/dird/bacula-dir.conf.in b/bacula/src/dird/bacula-dir.conf.in index 2efe50f499..f2e72d6652 100644 --- a/bacula/src/dird/bacula-dir.conf.in +++ b/bacula/src/dird/bacula-dir.conf.in @@ -63,7 +63,9 @@ Job { # This creates an ASCII copy of the catalog # WARNING!!! Passing the password via the command line is insecure. # see comments in make_catalog_backup for details. - RunBeforeJob = "@scriptdir@/make_catalog_backup bacula bacula" + # Arguments to make_catalog_backup are: + # make_catalog_backup + RunBeforeJob = "@scriptdir@/make_catalog_backup @db_name@ @db_user@" # This deletes the copy of the catalog RunAfterJob = "@scriptdir@/delete_catalog_backup" Write Bootstrap = "@working_dir@/BackupCatalog.bsr" diff --git a/bacula/src/filed/backup.c b/bacula/src/filed/backup.c index 87afdb62a3..708a1635db 100644 --- a/bacula/src/filed/backup.c +++ b/bacula/src/filed/backup.c @@ -443,6 +443,7 @@ int save_file(FF_PKT *ff_pkt, void *vjcr, bool top_level) if (!set_cmd_plugin(&ff_pkt->bfd, jcr)) { goto bail_out; } + send_plugin_name(jcr, sd); } /* Send attributes -- must be done after binit() */ @@ -567,12 +568,12 @@ int save_file(FF_PKT *ff_pkt, void *vjcr, bool top_level) if (ff_pkt->flags & FO_ACL) { /* Read access ACLs for files, dirs and links */ - if (!read_and_send_acl(jcr, BACL_TYPE_ACCESS, STREAM_UNIX_ATTRIBUTES_ACCESS_ACL)) { + if (!read_and_send_acl(jcr, BACL_TYPE_ACCESS, STREAM_UNIX_ACCESS_ACL)) { goto bail_out; } /* Directories can have default ACLs too */ if (ff_pkt->type == FT_DIREND && (BACL_CAP & BACL_CAP_DEFAULTS_DIR)) { - if (!read_and_send_acl(jcr, BACL_TYPE_DEFAULT, STREAM_UNIX_ATTRIBUTES_DEFAULT_ACL)) { + if (!read_and_send_acl(jcr, BACL_TYPE_DEFAULT, STREAM_UNIX_DEFAULT_ACL)) { goto bail_out; } } diff --git a/bacula/src/filed/fd-plugins.c b/bacula/src/filed/fd-plugins.c index d407240a1d..53ba28879f 100644 --- a/bacula/src/filed/fd-plugins.c +++ b/bacula/src/filed/fd-plugins.c @@ -45,6 +45,7 @@ extern int (*plugin_bopen)(JCR *jcr, const char *fname, int flags, mode_t mo extern int (*plugin_bclose)(JCR *jcr); extern ssize_t (*plugin_bread)(JCR *jcr, void *buf, size_t count); extern ssize_t (*plugin_bwrite)(JCR *jcr, void *buf, size_t count); +extern boffset_t (*plugin_blseek)(JCR *jcr, boffset_t offset, int whence); /* Forward referenced functions */ @@ -60,6 +61,7 @@ static int my_plugin_bopen(JCR *jcr, const char *fname, int flags, mode_t mo static int my_plugin_bclose(JCR *jcr); static ssize_t my_plugin_bread(JCR *jcr, void *buf, size_t count); static ssize_t my_plugin_bwrite(JCR *jcr, void *buf, size_t count); +static boffset_t my_plugin_blseek(JCR *jcr, boffset_t offset, int whence); /* Bacula info */ @@ -131,16 +133,18 @@ void generate_plugin_event(JCR *jcr, bEventType eventType, void *value) memset(&sp, 0, sizeof(sp)); sp.type = FT_REG; sp.portable = true; + sp.cmd = cmd; 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; + jcr->plugin_sp = &sp; ff_pkt = jcr->ff; ff_pkt->fname = sp.fname; ff_pkt->type = sp.type; - ff_pkt->statp = sp.statp; /* structure copy */ + memcpy(&ff_pkt->statp, &sp.statp, sizeof(ff_pkt->statp)); Dmsg1(000, "Save_file: file=%s\n", ff_pkt->fname); save_file(ff_pkt, (void *)jcr, true); goto bail_out; @@ -152,6 +156,31 @@ bail_out: return; } +/* + * Send plugin name record to SD + */ +bool send_plugin_name(JCR *jcr, BSOCK *sd) +{ + int stat; + struct save_pkt *sp = (struct save_pkt *)jcr->plugin_sp; + Plugin *plugin = (Plugin *)jcr->plugin; + if (!sd->fsend("%ld %d 0", jcr->JobFiles, STREAM_PLUGIN_NAME)) { + Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"), + sd->bstrerror()); + return false; + } + stat = sd->fsend("%ld %d %s%c%s%c", jcr->JobFiles, sp->portable, 0, plugin->file, + sp->cmd, 0); + if (!stat) { + Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"), + sd->bstrerror()); + return false; + } + sd->signal(BNET_EOD); /* indicate end of plugin name data */ + return true; +} + + void load_fd_plugins(const char *plugin_dir) { if (!plugin_dir) { @@ -164,6 +193,7 @@ void load_fd_plugins(const char *plugin_dir) plugin_bclose = my_plugin_bclose; plugin_bread = my_plugin_bread; plugin_bwrite = my_plugin_bwrite; + plugin_blseek = my_plugin_blseek; } @@ -271,6 +301,19 @@ static ssize_t my_plugin_bwrite(JCR *jcr, void *buf, size_t count) return (ssize_t)io.status; } +static boffset_t my_plugin_blseek(JCR *jcr, boffset_t offset, int whence) +{ + Plugin *plugin = (Plugin *)jcr->plugin; + bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx; + struct io_pkt io; + Dmsg0(000, "plugin_bseek\n"); + io.func = IO_SEEK; + io.offset = offset; + io.whence = whence; + plug_func(plugin)->pluginIO(plugin_ctx, &io); + return (boffset_t)io.offset; +} + /* ============================================================== * * Callbacks from the plugin @@ -346,6 +389,7 @@ int (*plugin_bopen)(JCR *jcr, const char *fname, int flags, mode_t mode) = N 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; +boffset_t (*plugin_blseek)(JCR *jcr, boffset_t offset, int whence) = NULL; int save_file(FF_PKT *ff_pkt, void *vjcr, bool top_level) { diff --git a/bacula/src/filed/fd-plugins.h b/bacula/src/filed/fd-plugins.h index 30f4d35103..18e392fceb 100644 --- a/bacula/src/filed/fd-plugins.h +++ b/bacula/src/filed/fd-plugins.h @@ -50,22 +50,26 @@ struct save_pkt { char *fname; /* Full path and filename */ char *link; /* Link name if any */ struct stat statp; /* System stat() packet for file */ - int type; /* FT_xx for this file */ + int32_t type; /* FT_xx for this file */ uint32_t flags; /* Bacula internal flags */ bool portable; /* set if data format is portable */ + char *cmd; /* command */ }; #define IO_OPEN 1 #define IO_READ 2 #define IO_WRITE 3 #define IO_CLOSE 4 +#define IO_SEEK 5 struct io_pkt { - int func; /* Function code */ - int count; /* read/write count */ + int32_t func; /* Function code */ + int32_t count; /* read/write count */ char *buf; /* read/write buffer */ - int status; /* return status */ - int io_errno; /* errno code */ + int32_t status; /* return status */ + int32_t io_errno; /* errno code */ + int32_t whence; + boffset_t offset; }; /**************************************************************************** @@ -115,6 +119,7 @@ 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); #ifdef __cplusplus extern "C" { diff --git a/bacula/src/filed/restore.c b/bacula/src/filed/restore.c index 30fb4dc4da..8abe454371 100644 --- a/bacula/src/filed/restore.c +++ b/bacula/src/filed/restore.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. @@ -122,7 +122,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(). */ -int bclose_chksize(JCR *jcr, BFILE *bfd, boffset_t osize) +static int bclose_chksize(JCR *jcr, BFILE *bfd, boffset_t osize) { char ec1[50], ec2[50]; boffset_t fsize; @@ -580,7 +580,7 @@ void do_restore(JCR *jcr) #endif break; - case STREAM_UNIX_ATTRIBUTES_ACCESS_ACL: + case STREAM_UNIX_ACCESS_ACL: if (have_acl) { pm_strcpy(jcr->acl_text, sd->msg); Dmsg2(400, "Restoring ACL type 0x%2x <%s>\n", BACL_TYPE_ACCESS, jcr->acl_text); @@ -592,7 +592,7 @@ void do_restore(JCR *jcr) } break; - case STREAM_UNIX_ATTRIBUTES_DEFAULT_ACL: + case STREAM_UNIX_DEFAULT_ACL: if (have_acl) { pm_strcpy(jcr->acl_text, sd->msg); Dmsg2(400, "Restoring ACL type 0x%2x <%s>\n", BACL_TYPE_DEFAULT, jcr->acl_text); diff --git a/bacula/src/findlib/bfile.c b/bacula/src/findlib/bfile.c index d5020dd385..1473db5999 100644 --- a/bacula/src/findlib/bfile.c +++ b/bacula/src/findlib/bfile.c @@ -43,6 +43,7 @@ int (*plugin_bopen)(JCR *jcr, const char *fname, int flags, mode_t mode) = N 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; +boffset_t (*plugin_blseek)(JCR *jcr, boffset_t offset, int whence) = NULL; #ifdef HAVE_DARWIN_OS @@ -106,9 +107,9 @@ const char *stream_to_ascii(int stream) return _("MacOS Fork data"); case STREAM_HFSPLUS_ATTRIBUTES: return _("HFS+ attribs"); - case STREAM_UNIX_ATTRIBUTES_ACCESS_ACL: + case STREAM_UNIX_ACCESS_ACL: return _("Standard Unix ACL attribs"); - case STREAM_UNIX_ATTRIBUTES_DEFAULT_ACL: + case STREAM_UNIX_DEFAULT_ACL: return _("Default Unix ACL attribs"); case STREAM_SHA256_DIGEST: return _("SHA256 digest"); @@ -903,6 +904,10 @@ bool is_bopen(BFILE *bfd) boffset_t blseek(BFILE *bfd, boffset_t offset, int whence) { boffset_t pos; + + if (bfd->cmd_plugin && plugin_bwrite) { + return plugin_blseek(bfd->jcr, offset, whence); + } pos = (boffset_t)lseek(bfd->fid, (off_t)offset, whence); bfd->berrno = errno; return pos; diff --git a/bacula/src/jcr.h b/bacula/src/jcr.h index d7b6b9e816..c520b685da 100644 --- a/bacula/src/jcr.h +++ b/bacula/src/jcr.h @@ -212,6 +212,7 @@ 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 */ /* 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 f29eb72b2a..a14c8292e3 100644 --- a/bacula/src/plugins/fd/bpipe-fd.c +++ b/bacula/src/plugins/fd/bpipe-fd.c @@ -88,6 +88,7 @@ static pFuncs pluginFuncs = { struct plugin_ctx { int record; + boffset_t offset; }; bRC loadPlugin(bInfo *lbinfo, bFuncs *lbfuncs, pInfo **pinfo, pFuncs **pfuncs) @@ -158,6 +159,13 @@ static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value) printf("bpipe-fd: since=%d\n", (int)value); break; + case bEventRestoreStart: + printf("bpipe-fd: RestoreStart\n"); + break; + case bEventRestoreEnd: + printf("bpipe-fd: RestoreEnd\n"); + break; + /* Plugin command e.g. plugin = ::command */ case bEventPluginCommand: printf("bpipe-fd: command=%s\n", (char *)value); @@ -175,7 +183,7 @@ 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"; + static char *fname = (char *)"/@BPIPE/test.txt"; time_t now = time(NULL); sp->fname = fname; sp->statp.st_mode = 0700; @@ -208,6 +216,7 @@ static bRC pluginIO(bpContext *ctx, struct io_pkt *io) if (p_ctx->record == 0) { strcpy(io->buf, "This is a test string.\n"); io->status = strlen(io->buf); + p_ctx->offset = io->status; p_ctx->record = 1; return bRC_OK; } @@ -219,6 +228,9 @@ static bRC pluginIO(bpContext *ctx, struct io_pkt *io) case IO_CLOSE: printf("bpipe-fd: IO_CLOSE\n"); break; + case IO_SEEK: + io->offset = p_ctx->offset; + break; } return bRC_OK; } diff --git a/bacula/src/plugins/fd/example-plugin-fd.c b/bacula/src/plugins/fd/example-plugin-fd.c index 01e30d3d30..24eb218553 100644 --- a/bacula/src/plugins/fd/example-plugin-fd.c +++ b/bacula/src/plugins/fd/example-plugin-fd.c @@ -153,6 +153,12 @@ static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value) case bEventSince: printf("plugin: since=%d\n", (int)value); break; + case bEventRestoreStart: + printf("bpipe-fd: RestoreStart\n"); + break; + case bEventRestoreEnd: + printf("bpipe-fd: RestoreEnd\n"); + break; /* Plugin command e.g. plugin = ::command */ case bEventPluginCommand: diff --git a/bacula/src/stored/bscan.c b/bacula/src/stored/bscan.c index a5b6cf2841..2bdeac3f04 100644 --- a/bacula/src/stored/bscan.c +++ b/bacula/src/stored/bscan.c @@ -790,8 +790,8 @@ static bool record_cb(DCR *dcr, DEV_RECORD *rec) } break; - case STREAM_UNIX_ATTRIBUTES_ACCESS_ACL: /* Standard ACL attributes on UNIX */ - case STREAM_UNIX_ATTRIBUTES_DEFAULT_ACL: /* Default ACL attributes on UNIX */ + case STREAM_UNIX_ACCESS_ACL: /* Standard ACL attributes on UNIX */ + case STREAM_UNIX_DEFAULT_ACL: /* Default ACL attributes on UNIX */ /* Ignore Unix attributes */ break;