From: Kern Sibbald Date: Thu, 16 Apr 2009 13:13:28 +0000 (+0000) Subject: Fix bug #1246 Sometimes access denied with VSS enabled. UCS X-Git-Tag: Release-3.0.1~34 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=05b561ae0416abac31cd1f3b65d3617df2723659;p=bacula%2Fbacula Fix bug #1246 Sometimes access denied with VSS enabled. UCS conversion cache was not properly flushed at the end of a Job git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@8737 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/patches/2.4.x/2.4.4-winvss.patch b/bacula/patches/2.4.x/2.4.4-winvss.patch new file mode 100644 index 0000000000..86eea75d9e --- /dev/null +++ b/bacula/patches/2.4.x/2.4.4-winvss.patch @@ -0,0 +1,170 @@ + + This patch is fixes Fix bug #1246 Sometimes access with + VSS enabled. UCS conversion cache was not properly flushed + at the end of a Job. + + Apply it to version 2.4.4 with: + + cd + patch -p0 <2.4.4-winvss.patch + ./configure + make + ... + make install + + +Index: src/filed/job.c +=================================================================== +--- src/filed/job.c (revision 8733) ++++ src/filed/job.c (working copy) +@@ -1,7 +1,7 @@ + /* + Bacula® - The Network Backup Solution + +- Copyright (C) 2000-2007 Free Software Foundation Europe e.V. ++ Copyright (C) 2000-2009 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. +@@ -41,7 +41,7 @@ + #include "vss.h" + + static pthread_mutex_t vss_mutex = PTHREAD_MUTEX_INITIALIZER; +-static int enable_vss; ++static int enable_vss = 0; + #endif + + extern CLIENT *me; /* our client resource */ +@@ -1422,7 +1422,7 @@ + /* inform user about writer states */ + for (i=0; i < (int)g_pVSSClient->GetWriterCount(); i++) + if (g_pVSSClient->GetWriterState(i) < 1) { +- Jmsg(jcr, M_WARNING, 0, _("VSS Writer (PrepareForBackup): %s\n"), g_pVSSClient->GetWriterInfo(i)); ++ Jmsg(jcr, M_WARNING, 0, _("VSS Writer (PrepareForBackup): %s\n"), g_pVSSClient->GetWriterInfo(i)); + jcr->Errors++; + } + } +@@ -1506,6 +1506,7 @@ + Jmsg(jcr, msg_type, 0, _("VSS Writer (BackupComplete): %s\n"), g_pVSSClient->GetWriterInfo(i)); + } + } ++ Win32ConvCleanupCache(); + V(vss_mutex); + } + #endif +Index: src/win32/Makefile +=================================================================== +--- src/win32/Makefile (revision 8733) ++++ src/win32/Makefile (working copy) +@@ -30,7 +30,7 @@ + Makefile.inc: Makefile.inc.in + @echo Creating $@ + $(ECHO_CMD)TOPDIR=`(cd ../../..;pwd)`; \ +- if test -e ../../../cross-tools/mingw32/bin/mingw32-gcc; then \ ++ if test -e $${TOPDIR}/cross-tools/mingw32/bin/mingw32-gcc; then \ + BINDIR=$${TOPDIR}/cross-tools/mingw32/bin; \ + INCDIR=$${TOPDIR}/cross-tools/mingw32/mingw32/include; \ + DLLDIR=$${TOPDIR}/cross-tools/mingw32/mingw32/bin; \ +@@ -43,7 +43,7 @@ + echo "You must run build-win32-cross-tools and build-dependencies first.\n"; \ + exit 1; \ + fi ; \ +- $(ECHO_CMD)BUILDDIR=`(pwd)`; \ ++ BUILDDIR=`(pwd)`; \ + sed \ + -e "s^@BUILDDIR@^$${BUILDDIR}^" \ + -e "s^@TOPDIR@^$${TOPDIR}^" \ +Index: src/win32/compat/compat.cpp +=================================================================== +--- src/win32/compat/compat.cpp (revision 8733) ++++ src/win32/compat/compat.cpp (working copy) +@@ -1,7 +1,7 @@ + /* + Bacula® - The Network Backup Solution + +- Copyright (C) 2004-2008 Free Software Foundation Europe e.V. ++ Copyright (C) 2004-2009 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. +@@ -51,8 +51,8 @@ + conversion is called 3 times (lstat, attribs, open), + by using the cache this is reduced to 1 time */ + +-static POOLMEM *g_pWin32ConvUTF8Cache = get_pool_memory(PM_FNAME); +-static POOLMEM *g_pWin32ConvUCS2Cache = get_pool_memory(PM_FNAME); ++static POOLMEM *g_pWin32ConvUTF8Cache = NULL; ++static POOLMEM *g_pWin32ConvUCS2Cache = NULL; + static DWORD g_dwWin32ConvUTF8strlen = 0; + static pthread_mutex_t Win32Convmutex = PTHREAD_MUTEX_INITIALIZER; + +@@ -69,8 +69,19 @@ + g_pVSSPathConvertW = pPathConvertW; + } + ++static void Win32ConvInitCache() ++{ ++ if (g_pWin32ConvUTF8Cache) { ++ return; ++ } ++ g_pWin32ConvUTF8Cache = get_pool_memory(PM_FNAME); ++ g_pWin32ConvUCS2Cache = get_pool_memory(PM_FNAME); ++} ++ ++ + void Win32ConvCleanupCache() + { ++ P(Win32Convmutex); + if (g_pWin32ConvUTF8Cache) { + free_pool_memory(g_pWin32ConvUTF8Cache); + g_pWin32ConvUTF8Cache = NULL; +@@ -82,6 +93,7 @@ + } + + g_dwWin32ConvUTF8strlen = 0; ++ V(Win32Convmutex); + } + + +@@ -451,11 +463,14 @@ + /* if we find the utf8 string in cache, we use the cached ucs2 version. + we compare the stringlength first (quick check) and then compare the content. + */ +- if (g_dwWin32ConvUTF8strlen == strlen(pszUTF)) { ++ if (!g_pWin32ConvUTF8Cache) { ++ Win32ConvInitCache(); ++ } else if (g_dwWin32ConvUTF8strlen == strlen(pszUTF)) { + if (bstrcmp(pszUTF, g_pWin32ConvUTF8Cache)) { ++ /* Return cached value */ + int32_t nBufSize = sizeof_pool_memory(g_pWin32ConvUCS2Cache); + *pszUCS = check_pool_memory_size(*pszUCS, nBufSize); +- wcscpy((LPWSTR) *pszUCS, (LPWSTR) g_pWin32ConvUCS2Cache); ++ wcscpy((LPWSTR) *pszUCS, (LPWSTR)g_pWin32ConvUCS2Cache); + V(Win32Convmutex); + return nBufSize / sizeof (WCHAR); + } +@@ -477,7 +492,7 @@ + wcscpy((LPWSTR) g_pWin32ConvUCS2Cache, (LPWSTR) *pszUCS); + + g_dwWin32ConvUTF8strlen = strlen(pszUTF); +- g_pWin32ConvUTF8Cache = check_pool_memory_size(g_pWin32ConvUTF8Cache, g_dwWin32ConvUTF8strlen+1); ++ g_pWin32ConvUTF8Cache = check_pool_memory_size(g_pWin32ConvUTF8Cache, g_dwWin32ConvUTF8strlen+2); + bstrncpy(g_pWin32ConvUTF8Cache, pszUTF, g_dwWin32ConvUTF8strlen+1); + V(Win32Convmutex); + +Index: src/win32/Makefile.inc.in +=================================================================== +--- src/win32/Makefile.inc.in (revision 8733) ++++ src/win32/Makefile.inc.in (working copy) +@@ -11,9 +11,9 @@ + + BUILDDIR := @BUILDDIR@ + TOPDIR := @TOPDIR@ +-DEPKGS := $(TOPDIR)/depkgs-mingw32 ++DEPKGS := @TOPDIR@/depkgs-mingw32 + +-DOCDIR := $(TOPDIR)/docs ++DOCDIR := @TOPDIR@/docs + BINDIR := ../release + LIBDIR := ../release + OBJDIR := . diff --git a/bacula/src/filed/job.c b/bacula/src/filed/job.c index ddc7faa955..c85e5ad0b0 100644 --- a/bacula/src/filed/job.c +++ b/bacula/src/filed/job.c @@ -41,7 +41,7 @@ #include "vss.h" static pthread_mutex_t vss_mutex = PTHREAD_MUTEX_INITIALIZER; -static int enable_vss; +static int enable_vss = 0; #endif extern CLIENT *me; /* our client resource */ @@ -1591,6 +1591,7 @@ cleanup: Jmsg(jcr, msg_type, 0, _("VSS Writer (BackupComplete): %s\n"), g_pVSSClient->GetWriterInfo(i)); } } + Win32ConvCleanupCache(); V(vss_mutex); } #endif diff --git a/bacula/src/win32/compat/compat.cpp b/bacula/src/win32/compat/compat.cpp index e93ce9c45b..8caa8c2954 100644 --- a/bacula/src/win32/compat/compat.cpp +++ b/bacula/src/win32/compat/compat.cpp @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2004-2008 Free Software Foundation Europe e.V. + Copyright (C) 2004-2009 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. @@ -51,8 +51,8 @@ conversion is called 3 times (lstat, attribs, open), by using the cache this is reduced to 1 time */ -static POOLMEM *g_pWin32ConvUTF8Cache = get_pool_memory(PM_FNAME); -static POOLMEM *g_pWin32ConvUCS2Cache = get_pool_memory(PM_FNAME); +static POOLMEM *g_pWin32ConvUTF8Cache = NULL; +static POOLMEM *g_pWin32ConvUCS2Cache = NULL; static DWORD g_dwWin32ConvUTF8strlen = 0; static pthread_mutex_t Win32Convmutex = PTHREAD_MUTEX_INITIALIZER; @@ -69,8 +69,18 @@ void SetVSSPathConvert(t_pVSSPathConvert pPathConvert, t_pVSSPathConvertW pPathC g_pVSSPathConvertW = pPathConvertW; } +static void Win32ConvInitCache() +{ + if (g_pWin32ConvUTF8Cache) { + return; + } + g_pWin32ConvUTF8Cache = get_pool_memory(PM_FNAME); + g_pWin32ConvUCS2Cache = get_pool_memory(PM_FNAME); +} + void Win32ConvCleanupCache() { + P(Win32Convmutex); if (g_pWin32ConvUTF8Cache) { free_pool_memory(g_pWin32ConvUTF8Cache); g_pWin32ConvUTF8Cache = NULL; @@ -82,6 +92,7 @@ void Win32ConvCleanupCache() } g_dwWin32ConvUTF8strlen = 0; + V(Win32Convmutex); } @@ -451,11 +462,14 @@ make_win32_path_UTF8_2_wchar(POOLMEM **pszUCS, const char *pszUTF, BOOL* pBIsRaw /* if we find the utf8 string in cache, we use the cached ucs2 version. we compare the stringlength first (quick check) and then compare the content. */ - if (g_dwWin32ConvUTF8strlen == strlen(pszUTF)) { + if (!g_pWin32ConvUTF8Cache) { + Win32ConvInitCache(); + } else if (g_dwWin32ConvUTF8strlen == strlen(pszUTF)) { if (bstrcmp(pszUTF, g_pWin32ConvUTF8Cache)) { + /* Return cached value */ int32_t nBufSize = sizeof_pool_memory(g_pWin32ConvUCS2Cache); *pszUCS = check_pool_memory_size(*pszUCS, nBufSize); - wcscpy((LPWSTR) *pszUCS, (LPWSTR) g_pWin32ConvUCS2Cache); + wcscpy((LPWSTR) *pszUCS, (LPWSTR)g_pWin32ConvUCS2Cache); V(Win32Convmutex); return nBufSize / sizeof (WCHAR); } @@ -477,7 +491,7 @@ make_win32_path_UTF8_2_wchar(POOLMEM **pszUCS, const char *pszUTF, BOOL* pBIsRaw wcscpy((LPWSTR) g_pWin32ConvUCS2Cache, (LPWSTR) *pszUCS); g_dwWin32ConvUTF8strlen = strlen(pszUTF); - g_pWin32ConvUTF8Cache = check_pool_memory_size(g_pWin32ConvUTF8Cache, g_dwWin32ConvUTF8strlen+1); + g_pWin32ConvUTF8Cache = check_pool_memory_size(g_pWin32ConvUTF8Cache, g_dwWin32ConvUTF8strlen+2); bstrncpy(g_pWin32ConvUTF8Cache, pszUTF, g_dwWin32ConvUTF8strlen+1); V(Win32Convmutex); diff --git a/bacula/technotes b/bacula/technotes index 3334291aed..9594ff90cf 100644 --- a/bacula/technotes +++ b/bacula/technotes @@ -3,6 +3,8 @@ General: 14Apr09 +kes Fix bug #1246 Sometimes access denied with VSS enabled. UCS + conversion cache was not properly flushed at the end of a Job. kes Fix bug #1268 Full Max Run Time cancels jobs (when Max Run Time = 0). 11Apr09 kes Modify insertion of read Volumes in SD to be done before the