From a40b9b3347e5a4eec10ac412c8606aeb23e21c11 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sat, 27 Sep 2008 16:46:55 +0000 Subject: [PATCH] kes Implement build and install of bpipe-fd.so plugin. kes Rework the interface that passes packets to the plugin so that the packet is started and ended by the packet size. This allows the driver to do a sanity check. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@7656 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/Makefile.in | 2 +- bacula/autoconf/Make.common.in | 1 + bacula/src/filed/fd_plugins.c | 29 +++++++++++++++++++++++++---- bacula/src/filed/fd_plugins.h | 6 ++++++ bacula/src/plugins/fd/Makefile | 18 +++++++++++++++--- bacula/src/plugins/fd/Makefile.in | 11 +++++++++++ bacula/src/plugins/fd/bpipe-fd.c | 1 + bacula/src/version.h | 6 +++--- bacula/src/win32/compat/compat.h | 4 ++-- bacula/technotes-2.5 | 5 +++++ 10 files changed, 70 insertions(+), 13 deletions(-) diff --git a/bacula/Makefile.in b/bacula/Makefile.in index 6fba576ecb..16958259e3 100755 --- a/bacula/Makefile.in +++ b/bacula/Makefile.in @@ -21,7 +21,7 @@ dummy: # --client-only directories fd_subdirs = src scripts src/lib src/findlib src/filed \ @READLINE_SRC@ @BAT_DIR@ @GNOME_DIR@ @TRAY_MONITOR_DIR@ @WX_DIR@ \ - src/console + src/console src/plugins/fd # Non-client-only directores subdirs = src/cats @DIRD_DIR@ @STORED_DIR@ src/tools diff --git a/bacula/autoconf/Make.common.in b/bacula/autoconf/Make.common.in index baee082c4c..a1155fb8ce 100644 --- a/bacula/autoconf/Make.common.in +++ b/bacula/autoconf/Make.common.in @@ -26,6 +26,7 @@ manprefix = datarootdir = @datarootdir@ sbindir = @sbindir@ sysconfdir = @sysconfdir@ +plugindir = @plugindir@ scriptdir = @scriptdir@ mandir = @mandir@ manext = 8 diff --git a/bacula/src/filed/fd_plugins.c b/bacula/src/filed/fd_plugins.c index 8bcf51d17c..b0bc92ff1e 100644 --- a/bacula/src/filed/fd_plugins.c +++ b/bacula/src/filed/fd_plugins.c @@ -172,7 +172,8 @@ int plugin_save(JCR *jcr, FF_PKT *ff_pkt, bool top_level) /* Loop getting filenames to backup then saving them */ while (!job_canceled(jcr)) { memset(&sp, 0, sizeof(sp)); - sp.type = FT_REG; + sp.pkt_size = sizeof(sp); + sp.pkt_end = sizeof(sp); sp.portable = true; sp.cmd = cmd; Dmsg3(dbglvl, "startBackup st_size=%p st_blocks=%p sp=%p\n", &sp.statp.st_size, &sp.statp.st_blocks, @@ -181,6 +182,11 @@ int plugin_save(JCR *jcr, FF_PKT *ff_pkt, bool top_level) if (plug_func(plugin)->startBackupFile(&plugin_ctx_list[i], &sp) != bRC_OK) { goto bail_out; } + if (sp.type == 0 || sp.fname == NULL) { + Jmsg1(jcr, M_FATAL, 0, _("Command plugin \"%s\" returned bad startBackupFile packet.\n"), + cmd); + goto bail_out; + } jcr->plugin_ctx = &plugin_ctx_list[i]; jcr->plugin = plugin; jcr->plugin_sp = &sp; @@ -190,9 +196,11 @@ int plugin_save(JCR *jcr, FF_PKT *ff_pkt, bool top_level) memcpy(&ff_pkt->statp, &sp.statp, sizeof(ff_pkt->statp)); Dmsg1(dbglvl, "Save_file: file=%s\n", ff_pkt->fname); save_file(jcr, ff_pkt, true); - if (plug_func(plugin)->endBackupFile(&plugin_ctx_list[i]) != bRC_More) { - goto bail_out; + bRC rc = plug_func(plugin)->endBackupFile(&plugin_ctx_list[i]); + if (rc == bRC_More) { + continue; } + goto bail_out; } } Jmsg1(jcr, M_ERROR, 0, "Command plugin \"%s\" not found.\n", cmd); @@ -332,6 +340,8 @@ int plugin_create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace) if (!set_cmd_plugin(bfd, jcr)) { return CF_ERROR; } + rp.pkt_size = sizeof(rp); + rp.pkt_end = sizeof(rp); rp.stream = attr->stream; rp.data_stream = attr->data_stream; rp.type = attr->type; @@ -348,6 +358,8 @@ int plugin_create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace) if (plug_func(plugin)->createFile(plugin_ctx, &rp) != bRC_OK) { return CF_ERROR; } + io.pkt_size = sizeof(io); + io.pkt_end = sizeof(io); io.func = IO_OPEN; io.count = 0; io.buf = NULL; @@ -404,7 +416,6 @@ void load_fd_plugins(const char *plugin_dir) Dmsg1(dbglvl, "Loaded plugin: %s\n", plugin->file); } - } /* @@ -470,6 +481,8 @@ static int my_plugin_bopen(BFILE *bfd, const char *fname, int flags, mode_t mode bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx; struct io_pkt io; Dmsg0(dbglvl, "plugin_bopen\n"); + io.pkt_size = sizeof(io); + io.pkt_end = sizeof(io); io.func = IO_OPEN; io.count = 0; io.buf = NULL; @@ -496,6 +509,8 @@ static int my_plugin_bclose(BFILE *bfd) bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx; struct io_pkt io; Dmsg0(dbglvl, "plugin_bclose\n"); + io.pkt_size = sizeof(io); + io.pkt_end = sizeof(io); io.func = IO_CLOSE; io.count = 0; io.buf = NULL; @@ -519,6 +534,8 @@ static ssize_t my_plugin_bread(BFILE *bfd, void *buf, size_t count) bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx; struct io_pkt io; Dmsg0(dbglvl, "plugin_bread\n"); + io.pkt_size = sizeof(io); + io.pkt_end = sizeof(io); io.func = IO_READ; io.count = count; io.buf = (char *)buf; @@ -542,6 +559,8 @@ static ssize_t my_plugin_bwrite(BFILE *bfd, void *buf, size_t count) bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx; struct io_pkt io; Dmsg0(dbglvl, "plugin_bwrite\n"); + io.pkt_size = sizeof(io); + io.pkt_end = sizeof(io); io.func = IO_WRITE; io.count = count; io.buf = (char *)buf; @@ -565,6 +584,8 @@ static boffset_t my_plugin_blseek(BFILE *bfd, boffset_t offset, int whence) bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx; struct io_pkt io; Dmsg0(dbglvl, "plugin_bseek\n"); + io.pkt_size = sizeof(io); + io.pkt_end = sizeof(io); io.func = IO_SEEK; io.offset = offset; io.whence = whence; diff --git a/bacula/src/filed/fd_plugins.h b/bacula/src/filed/fd_plugins.h index ae96109d94..0370ee29e7 100644 --- a/bacula/src/filed/fd_plugins.h +++ b/bacula/src/filed/fd_plugins.h @@ -71,6 +71,7 @@ * This packet is used for file save info transfer. */ struct save_pkt { + int32_t pkt_size; /* size of this packet */ char *fname; /* Full path and filename */ char *link; /* Link name if any */ struct stat statp; /* System stat() packet for file */ @@ -78,12 +79,14 @@ struct save_pkt { uint32_t flags; /* Bacula internal flags */ bool portable; /* set if data format is portable */ char *cmd; /* command */ + int32_t pkt_end; /* end packet sentinel */ }; /* * This packet is used for file restore info transfer. */ struct restore_pkt { + int32_t pkt_size; /* size of this packet */ int32_t stream; /* attribute stream id */ int32_t data_stream; /* id of data stream to follow */ int32_t type; /* file type FT */ @@ -97,6 +100,7 @@ struct restore_pkt { const char *where; /* where */ const char *RegexWhere; /* regex where */ int replace; /* replace flag */ + int32_t pkt_end; /* end packet sentinel */ }; enum { @@ -108,6 +112,7 @@ enum { }; struct io_pkt { + int32_t pkt_size; /* Size of this packet */ int32_t func; /* Function code */ int32_t count; /* read/write count */ int32_t flags; /* Open flags */ @@ -120,6 +125,7 @@ struct io_pkt { int32_t whence; /* lseek argument */ boffset_t offset; /* lseek argument */ bool win32; /* Win32 GetLastError returned */ + int32_t pkt_end; /* end packet sentinel */ }; /**************************************************************************** diff --git a/bacula/src/plugins/fd/Makefile b/bacula/src/plugins/fd/Makefile index 00a4efe051..2e61bf2930 100644 --- a/bacula/src/plugins/fd/Makefile +++ b/bacula/src/plugins/fd/Makefile @@ -8,9 +8,9 @@ # so it has all the "common" definitions # -DATE="25 September 2008" -LSMDATE=25Sep08 -VERSION=2.5.4 +DATE="26 September 2008" +LSMDATE=26Sep08 +VERSION=2.5.5 VERNAME=bacula-$(VERSION)# MAINT=Kern Sibbald# MAINTEMAIL=# @@ -31,6 +31,7 @@ manprefix = datarootdir = ${prefix}/share sbindir = /home/kern/bacula/bin sysconfdir = /home/kern/bacula/bin +plugindir = /home/kern/bacula/bin scriptdir = /home/kern/bacula/bin mandir = /home/kern/bacula/bin manext = 8 @@ -125,5 +126,16 @@ bpipe-fd.o: bpipe-fd.c ${FDDIR}/fd_plugins.h bpipe-fd.so: bpipe-fd.o $(CXX) $(LDFLAGS) -shared bpipe-fd.o -o bpipe-fd.so +install: all + $(INSTALL_PROGRAM) bpipe-fd.so $(DESTDIR)$(plugindir)/bpipe-fd.so + clean: rm -f main *.so *.o 1 2 3 + +distclean: clean + rm -f Makefile + +uninstall: + $(RMF) $(DESTDIR)$(plugindir)/bpipe-fd.so + +depend: diff --git a/bacula/src/plugins/fd/Makefile.in b/bacula/src/plugins/fd/Makefile.in index 8305b6a5db..eef99a58aa 100644 --- a/bacula/src/plugins/fd/Makefile.in +++ b/bacula/src/plugins/fd/Makefile.in @@ -38,5 +38,16 @@ bpipe-fd.o: bpipe-fd.c ${FDDIR}/fd_plugins.h bpipe-fd.so: bpipe-fd.o $(CXX) $(LDFLAGS) -shared bpipe-fd.o -o bpipe-fd.so +install: all + $(INSTALL_PROGRAM) bpipe-fd.so $(DESTDIR)$(plugindir)/bpipe-fd.so + clean: rm -f main *.so *.o 1 2 3 + +distclean: clean + rm -f Makefile + +uninstall: + $(RMF) $(DESTDIR)$(plugindir)/bpipe-fd.so + +depend: diff --git a/bacula/src/plugins/fd/bpipe-fd.c b/bacula/src/plugins/fd/bpipe-fd.c index fa2488a6ad..35e891314c 100644 --- a/bacula/src/plugins/fd/bpipe-fd.c +++ b/bacula/src/plugins/fd/bpipe-fd.c @@ -279,6 +279,7 @@ static bRC startBackupFile(bpContext *ctx, struct save_pkt *sp) struct plugin_ctx *p_ctx = (struct plugin_ctx *)ctx->pContext; time_t now = time(NULL); sp->fname = p_ctx->fname; + sp->type = FT_REG; sp->statp.st_mode = 0700 | S_IFREG; sp->statp.st_ctime = now; sp->statp.st_mtime = now; diff --git a/bacula/src/version.h b/bacula/src/version.h index 3256ff4256..d0a7c8c77a 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -3,9 +3,9 @@ */ #undef VERSION -#define VERSION "2.5.5" -#define BDATE "26 September 2008" -#define LSMDATE "26Sep08" +#define VERSION "2.5.6" +#define BDATE "27 September 2008" +#define LSMDATE "27Sep08" #define PROG_COPYRIGHT "Copyright (C) %d-2008 Free Software Foundation Europe e.V.\n" #define BYEAR "2008" /* year for copyright messages in progs */ diff --git a/bacula/src/win32/compat/compat.h b/bacula/src/win32/compat/compat.h index 20a4498aa5..7f23c85e41 100644 --- a/bacula/src/win32/compat/compat.h +++ b/bacula/src/win32/compat/compat.h @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2004-2007 Free Software Foundation Europe e.V. + Copyright (C) 2004-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. @@ -386,7 +386,7 @@ int win32_ftruncate(int fd, int64_t length); #define MAP_FAILED ((void *) -1) void *mmap(void *start, size_t length, int prot, int flags, - int fd, off_t offset); + int fd, off_t offset); int munmap(void *start, size_t length); #endif /* __COMPAT_H_ */ diff --git a/bacula/technotes-2.5 b/bacula/technotes-2.5 index 1a38a8a623..43a9bfe2b2 100644 --- a/bacula/technotes-2.5 +++ b/bacula/technotes-2.5 @@ -17,6 +17,11 @@ dbdriver remove reader/writer in FOPTS???? General: +27Sep08 +kes Implement build and install of bpipe-fd.so plugin. +kes Rework the interface that passes packets to the plugin + so that the packet is started and ended by the packet size. + This allows the driver to do a sanity check. 26Sep08 kes Rework the pluginIO Bacula internal code to enable proper handling of Win32 error codes from GetLastError. -- 2.39.5