From 6ce98e9f31b36fa71737dfb45bfb4281bd7e0f45 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Fri, 26 Sep 2008 19:27:59 +0000 Subject: [PATCH] kes Rework the pluginIO Bacula internal code to enable proper handling of Win32 error codes from GetLastError. kes Apply Joao's patch to regress startover_libdbi. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@7652 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/filed/fd_plugins.c | 83 +++++++++++++++++++++++++++------- bacula/src/filed/fd_plugins.h | 9 ++-- bacula/src/findlib/bfile.c | 30 ++++++------ bacula/src/findlib/bfile.h | 3 +- bacula/src/plugins/fd/Makefile | 8 ++-- bacula/src/version.h | 6 +-- bacula/technotes-2.5 | 4 ++ 7 files changed, 101 insertions(+), 42 deletions(-) diff --git a/bacula/src/filed/fd_plugins.c b/bacula/src/filed/fd_plugins.c index 596c372bbc..8bcf51d17c 100644 --- a/bacula/src/filed/fd_plugins.c +++ b/bacula/src/filed/fd_plugins.c @@ -44,11 +44,11 @@ const char *plugin_type = "-fd.so"; extern int save_file(JCR *jcr, FF_PKT *ff_pkt, bool top_level); /* Function pointers to be set here */ -extern DLL_IMP_EXP int (*plugin_bopen)(JCR *jcr, const char *fname, int flags, mode_t mode); -extern DLL_IMP_EXP int (*plugin_bclose)(JCR *jcr); -extern DLL_IMP_EXP ssize_t (*plugin_bread)(JCR *jcr, void *buf, size_t count); -extern DLL_IMP_EXP ssize_t (*plugin_bwrite)(JCR *jcr, void *buf, size_t count); -extern DLL_IMP_EXP boffset_t (*plugin_blseek)(JCR *jcr, boffset_t offset, int whence); +extern DLL_IMP_EXP int (*plugin_bopen)(BFILE *bfd, const char *fname, int flags, mode_t mode); +extern DLL_IMP_EXP int (*plugin_bclose)(BFILE *bfd); +extern DLL_IMP_EXP ssize_t (*plugin_bread)(BFILE *bfd, void *buf, size_t count); +extern DLL_IMP_EXP ssize_t (*plugin_bwrite)(BFILE *bfd, void *buf, size_t count); +extern DLL_IMP_EXP boffset_t (*plugin_blseek)(BFILE *bfd, boffset_t offset, int whence); /* Forward referenced functions */ @@ -60,11 +60,11 @@ static bRC baculaJobMsg(bpContext *ctx, const char *file, int line, static bRC baculaDebugMsg(bpContext *ctx, const char *file, int line, int level, const char *fmt, ...); -static int my_plugin_bopen(JCR *jcr, const char *fname, int flags, mode_t mode); -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); +static int my_plugin_bopen(BFILE *bfd, const char *fname, int flags, mode_t mode); +static int my_plugin_bclose(BFILE *bfd); +static ssize_t my_plugin_bread(BFILE *bfd, void *buf, size_t count); +static ssize_t my_plugin_bwrite(BFILE *bfd, void *buf, size_t count); +static boffset_t my_plugin_blseek(BFILE *bfd, boffset_t offset, int whence); /* Bacula info */ @@ -463,8 +463,9 @@ void free_plugins(JCR *jcr) jcr->plugin_ctx_list = NULL; } -static int my_plugin_bopen(JCR *jcr, const char *fname, int flags, mode_t mode) +static int my_plugin_bopen(BFILE *bfd, const char *fname, int flags, mode_t mode) { + JCR *jcr = bfd->jcr; Plugin *plugin = (Plugin *)jcr->plugin; bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx; struct io_pkt io; @@ -472,14 +473,25 @@ static int my_plugin_bopen(JCR *jcr, const char *fname, int flags, mode_t mode) io.func = IO_OPEN; io.count = 0; io.buf = NULL; - io.mode = mode; + io.fname = fname; io.flags = flags; + io.mode = mode; + io.win32 = false; + io.lerror = 0; plug_func(plugin)->pluginIO(plugin_ctx, &io); + bfd->berrno = io.io_errno; + if (io.win32) { + errno = b_errno_win32; + } else { + errno = io.io_errno; + bfd->lerror = io.lerror; + } return io.status; } -static int my_plugin_bclose(JCR *jcr) +static int my_plugin_bclose(BFILE *bfd) { + JCR *jcr = bfd->jcr; Plugin *plugin = (Plugin *)jcr->plugin; bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx; struct io_pkt io; @@ -487,12 +499,22 @@ static int my_plugin_bclose(JCR *jcr) io.func = IO_CLOSE; io.count = 0; io.buf = NULL; + io.win32 = false; + io.lerror = 0; plug_func(plugin)->pluginIO(plugin_ctx, &io); + bfd->berrno = io.io_errno; + if (io.win32) { + errno = b_errno_win32; + } else { + errno = io.io_errno; + bfd->lerror = io.lerror; + } return io.status; } -static ssize_t my_plugin_bread(JCR *jcr, void *buf, size_t count) +static ssize_t my_plugin_bread(BFILE *bfd, void *buf, size_t count) { + JCR *jcr = bfd->jcr; Plugin *plugin = (Plugin *)jcr->plugin; bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx; struct io_pkt io; @@ -500,12 +522,22 @@ static ssize_t my_plugin_bread(JCR *jcr, void *buf, size_t count) io.func = IO_READ; io.count = count; io.buf = (char *)buf; + io.win32 = false; + io.lerror = 0; plug_func(plugin)->pluginIO(plugin_ctx, &io); + bfd->berrno = io.io_errno; + if (io.win32) { + errno = b_errno_win32; + } else { + errno = io.io_errno; + bfd->lerror = io.lerror; + } return (ssize_t)io.status; } -static ssize_t my_plugin_bwrite(JCR *jcr, void *buf, size_t count) +static ssize_t my_plugin_bwrite(BFILE *bfd, void *buf, size_t count) { + JCR *jcr = bfd->jcr; Plugin *plugin = (Plugin *)jcr->plugin; bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx; struct io_pkt io; @@ -513,12 +545,22 @@ static ssize_t my_plugin_bwrite(JCR *jcr, void *buf, size_t count) io.func = IO_WRITE; io.count = count; io.buf = (char *)buf; + io.win32 = false; + io.lerror = 0; plug_func(plugin)->pluginIO(plugin_ctx, &io); + bfd->berrno = io.io_errno; + if (io.win32) { + errno = b_errno_win32; + } else { + errno = io.io_errno; + bfd->lerror = io.lerror; + } return (ssize_t)io.status; } -static boffset_t my_plugin_blseek(JCR *jcr, boffset_t offset, int whence) +static boffset_t my_plugin_blseek(BFILE *bfd, boffset_t offset, int whence) { + JCR *jcr = bfd->jcr; Plugin *plugin = (Plugin *)jcr->plugin; bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx; struct io_pkt io; @@ -526,7 +568,16 @@ static boffset_t my_plugin_blseek(JCR *jcr, boffset_t offset, int whence) io.func = IO_SEEK; io.offset = offset; io.whence = whence; + io.win32 = false; + io.lerror = 0; plug_func(plugin)->pluginIO(plugin_ctx, &io); + bfd->berrno = io.io_errno; + if (io.win32) { + errno = b_errno_win32; + } else { + errno = io.io_errno; + bfd->lerror = io.lerror; + } return (boffset_t)io.offset; } diff --git a/bacula/src/filed/fd_plugins.h b/bacula/src/filed/fd_plugins.h index 8625de7fc8..ae96109d94 100644 --- a/bacula/src/filed/fd_plugins.h +++ b/bacula/src/filed/fd_plugins.h @@ -110,13 +110,16 @@ enum { struct io_pkt { int32_t func; /* Function code */ int32_t count; /* read/write count */ + int32_t flags; /* Open flags */ mode_t mode; /* permissions for created files */ - int32_t flags; /* open flags (e.g. O_WRONLY ...) */ char *buf; /* read/write buffer */ + const char *fname; /* open filename */ int32_t status; /* return status */ int32_t io_errno; /* errno code */ - int32_t whence; - boffset_t offset; + int32_t lerror; /* Win32 error code */ + int32_t whence; /* lseek argument */ + boffset_t offset; /* lseek argument */ + bool win32; /* Win32 GetLastError returned */ }; /**************************************************************************** diff --git a/bacula/src/findlib/bfile.c b/bacula/src/findlib/bfile.c index 7fa74bac61..658d7577a8 100644 --- a/bacula/src/findlib/bfile.c +++ b/bacula/src/findlib/bfile.c @@ -41,11 +41,11 @@ const int dbglvl = 200; -int (*plugin_bopen)(JCR *jcr, const char *fname, int flags, mode_t mode) = NULL; -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 (*plugin_bopen)(BFILE *bfd, const char *fname, int flags, mode_t mode) = NULL; +int (*plugin_bclose)(BFILE *bfd) = NULL; +ssize_t (*plugin_bread)(BFILE *bfd, void *buf, size_t count) = NULL; +ssize_t (*plugin_bwrite)(BFILE *bfd, void *buf, size_t count) = NULL; +boffset_t (*plugin_blseek)(BFILE *bfd, boffset_t offset, int whence) = NULL; #ifdef HAVE_DARWIN_OS @@ -421,7 +421,7 @@ int bopen(BFILE *bfd, const char *fname, int flags, mode_t mode) if (bfd->cmd_plugin && plugin_bopen) { int rtnstat; Dmsg1(000, "call plugin_bopen fname=%s\n", fname); - rtnstat = plugin_bopen(bfd->jcr, fname, flags, mode); + rtnstat = plugin_bopen(bfd, fname, flags, mode); free_pool_memory(win32_fname_wchar); free_pool_memory(win32_fname); return rtnstat; @@ -563,7 +563,7 @@ int bclose(BFILE *bfd) } if (bfd->cmd_plugin && plugin_bclose) { - stat = plugin_bclose(bfd->jcr); + stat = plugin_bclose(bfd); goto all_done; } @@ -618,7 +618,7 @@ ssize_t bread(BFILE *bfd, void *buf, size_t count) bfd->rw_bytes = 0; if (bfd->cmd_plugin && plugin_bread) { - return plugin_bread(bfd->jcr, buf, count); + return plugin_bread(bfd, buf, count); } if (bfd->use_backup_api) { @@ -655,7 +655,7 @@ ssize_t bwrite(BFILE *bfd, void *buf, size_t count) bfd->rw_bytes = 0; if (bfd->cmd_plugin && plugin_bwrite) { - return plugin_bwrite(bfd->jcr, buf, count); + return plugin_bwrite(bfd, buf, count); } if (bfd->use_backup_api) { @@ -698,7 +698,7 @@ boffset_t blseek(BFILE *bfd, boffset_t offset, int whence) DWORD dwResult; if (bfd->cmd_plugin && plugin_bwrite) { - return plugin_blseek(bfd->jcr, offset, whence); + return plugin_blseek(bfd, offset, whence); } dwResult = SetFilePointer(bfd->fh, offset_low, &offset_high, whence); @@ -828,7 +828,7 @@ int bopen(BFILE *bfd, const char *fname, int flags, mode_t mode) { if (bfd->cmd_plugin && plugin_bopen) { Dmsg1(000, "call plugin_bopen fname=%s\n", fname); - return plugin_bopen(bfd->jcr, fname, flags, mode); + return plugin_bopen(bfd, fname, flags, mode); } /* Normal file open */ @@ -895,7 +895,7 @@ int bclose(BFILE *bfd) Dmsg1(400, "Close file %d\n", bfd->fid); if (bfd->cmd_plugin && plugin_bclose) { - stat = plugin_bclose(bfd->jcr); + stat = plugin_bclose(bfd); bfd->fid = -1; bfd->cmd_plugin = false; } @@ -924,7 +924,7 @@ ssize_t bread(BFILE *bfd, void *buf, size_t count) ssize_t stat; if (bfd->cmd_plugin && plugin_bread) { - return plugin_bread(bfd->jcr, buf, count); + return plugin_bread(bfd, buf, count); } stat = read(bfd->fid, buf, count); @@ -937,7 +937,7 @@ ssize_t bwrite(BFILE *bfd, void *buf, size_t count) ssize_t stat; if (bfd->cmd_plugin && plugin_bwrite) { - return plugin_bwrite(bfd->jcr, buf, count); + return plugin_bwrite(bfd, buf, count); } stat = write(bfd->fid, buf, count); bfd->berrno = errno; @@ -954,7 +954,7 @@ 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); + return plugin_blseek(bfd, offset, whence); } pos = (boffset_t)lseek(bfd->fid, offset, whence); bfd->berrno = errno; diff --git a/bacula/src/findlib/bfile.h b/bacula/src/findlib/bfile.h index d0167e985d..6355217743 100644 --- a/bacula/src/findlib/bfile.h +++ b/bacula/src/findlib/bfile.h @@ -107,7 +107,8 @@ HANDLE bget_handle(BFILE *bfd); struct BFILE { int fid; /* file id on Unix */ int m_flags; /* open flags */ - int berrno; + int berrno; /* errno */ + int32_t lerror; /* not used - simplies Win32 builds */ JCR *jcr; /* jcr for editing job codes */ PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT win32DecompContext; /* context for decomposition of win32 backup streams */ int use_backup_decomp; /* set if using BackupRead Stream Decomposition */ diff --git a/bacula/src/plugins/fd/Makefile b/bacula/src/plugins/fd/Makefile index 8fcbeda10c..00a4efe051 100644 --- a/bacula/src/plugins/fd/Makefile +++ b/bacula/src/plugins/fd/Makefile @@ -1,16 +1,16 @@ # # Simple Makefile for building test FD plugins for Bacula # -# Version $Id: $ +# Version $Id: Makefile.in 7638 2008-09-25 14:04:17Z kerns $ # # # This file is pulled in by all the Unix Bacula Makefiles # so it has all the "common" definitions # -DATE="24 September 2008" -LSMDATE=24Sep08 -VERSION=2.5.3 +DATE="25 September 2008" +LSMDATE=25Sep08 +VERSION=2.5.4 VERNAME=bacula-$(VERSION)# MAINT=Kern Sibbald# MAINTEMAIL=# diff --git a/bacula/src/version.h b/bacula/src/version.h index c8c8a09200..3256ff4256 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -3,9 +3,9 @@ */ #undef VERSION -#define VERSION "2.5.4" -#define BDATE "25 September 2008" -#define LSMDATE "25Sep08" +#define VERSION "2.5.5" +#define BDATE "26 September 2008" +#define LSMDATE "26Sep08" #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/technotes-2.5 b/bacula/technotes-2.5 index bdb8357ee5..aa53dd2aeb 100644 --- a/bacula/technotes-2.5 +++ b/bacula/technotes-2.5 @@ -18,6 +18,10 @@ dbdriver remove reader/writer in FOPTS???? General: +26Sep08 +kes Rework the pluginIO Bacula internal code to enable + proper handling of Win32 error codes from GetLastError. +kes Apply Joao's patch to regress startover_libdbi. 25Sep08 ebl Add -B option to dbcheck to get catalog information kes Fix Win32 build to include new library function. -- 2.39.5