From 825c0873892d670f37535baa095e4e1e49d2197a Mon Sep 17 00:00:00 2001 From: Thorsten Engel Date: Fri, 5 Aug 2005 08:16:51 +0000 Subject: [PATCH] small vss improvement (more complete shutdown and startup after each backup instead of after restart) git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2295 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/win32/compat/vss.cpp | 1 + bacula/src/win32/compat/vss.h | 1 + bacula/src/win32/compat/vss_generic.cpp | 68 ++++++++++++++----------- 3 files changed, 39 insertions(+), 31 deletions(-) diff --git a/bacula/src/win32/compat/vss.cpp b/bacula/src/win32/compat/vss.cpp index d08409eddc..8234aad317 100644 --- a/bacula/src/win32/compat/vss.cpp +++ b/bacula/src/win32/compat/vss.cpp @@ -72,6 +72,7 @@ using namespace std; VSSClient::VSSClient() { m_bCoInitializeCalled = false; + m_bCoInitializeSecurityCalled = false; m_dwContext = 0; // VSS_CTX_BACKUP; m_bDuringRestore = false; m_bBackupIsInitialized = false; diff --git a/bacula/src/win32/compat/vss.h b/bacula/src/win32/compat/vss.h index f3726ada87..65ae9380eb 100644 --- a/bacula/src/win32/compat/vss.h +++ b/bacula/src/win32/compat/vss.h @@ -63,6 +63,7 @@ protected: HMODULE m_hLib; BOOL m_bCoInitializeCalled; + BOOL m_bCoInitializeSecurityCalled; DWORD m_dwContext; IUnknown* m_pVssObject; diff --git a/bacula/src/win32/compat/vss_generic.cpp b/bacula/src/win32/compat/vss_generic.cpp index ccb981fbc0..54a2d3153d 100644 --- a/bacula/src/win32/compat/vss_generic.cpp +++ b/bacula/src/win32/compat/vss_generic.cpp @@ -215,10 +215,11 @@ BOOL VSSClientGeneric::Initialize(DWORD dwContext, BOOL bDuringRestore) errno = b_errno_win32; return FALSE; } - m_bCoInitializeCalled = true; + } - // Initialize COM security + // Initialize COM security + if (!m_bCoInitializeSecurityCalled) { hr = CoInitializeSecurity( NULL, // Allow *all* VSS writers to communicate back! @@ -236,6 +237,7 @@ BOOL VSSClientGeneric::Initialize(DWORD dwContext, BOOL bDuringRestore) errno = b_errno_win32; return FALSE; } + m_bCoInitializeSecurityCalled = true; } // Release the IVssBackupComponents interface @@ -388,43 +390,47 @@ BOOL VSSClientGeneric::CreateSnapshots(char* szDriveLetters) BOOL VSSClientGeneric::CloseBackup() { - if (!m_pVssObject) { + BOOL bRet = FALSE; + if (!m_pVssObject) errno = ENOSYS; - return FALSE; - } + else { + IVssBackupComponents* pVss = (IVssBackupComponents*) m_pVssObject; + CComPtr pAsync; + + m_bBackupIsInitialized = false; - BOOL bRet = FALSE; - IVssBackupComponents* pVss = (IVssBackupComponents*) m_pVssObject; - CComPtr pAsync; - - m_bBackupIsInitialized = false; + if (SUCCEEDED(pVss->BackupComplete(&pAsync))) { + // Waits for the async operation to finish and checks the result + WaitAndCheckForAsyncOperation(pAsync); + bRet = TRUE; + } else { + errno = b_errno_win32; + pVss->AbortBackup(); + } - if (SUCCEEDED(pVss->BackupComplete(&pAsync))) { - // Waits for the async operation to finish and checks the result - WaitAndCheckForAsyncOperation(pAsync); - bRet = TRUE; - } else { - errno = b_errno_win32; - pVss->AbortBackup(); - } + if (m_uidCurrentSnapshotSet != GUID_NULL) { + VSS_ID idNonDeletedSnapshotID = GUID_NULL; + LONG lSnapshots; - if (m_uidCurrentSnapshotSet != GUID_NULL) { - VSS_ID idNonDeletedSnapshotID = GUID_NULL; - LONG lSnapshots; + pVss->DeleteSnapshots( + m_uidCurrentSnapshotSet, + VSS_OBJECT_SNAPSHOT_SET, + FALSE, + &lSnapshots, + &idNonDeletedSnapshotID); - pVss->DeleteSnapshots( - m_uidCurrentSnapshotSet, - VSS_OBJECT_SNAPSHOT_SET, - FALSE, - &lSnapshots, - &idNonDeletedSnapshotID); + m_uidCurrentSnapshotSet = GUID_NULL; + } - m_uidCurrentSnapshotSet = GUID_NULL; + pVss->Release(); + m_pVssObject = NULL; } - - pVss->Release(); - m_pVssObject = NULL; + // Call CoUninitialize if the CoInitialize was performed sucesfully + if (m_bCoInitializeCalled) { + CoUninitialize(); + m_bCoInitializeCalled = false; + } return bRet; } -- 2.39.5