Skip to content

Commit

Permalink
QGA VSS: Add log in functions begin/end
Browse files Browse the repository at this point in the history
Add several qga_debug() statements in functions.

Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Konstantin Kostiuk <kkostiuk@redhat.com>
  • Loading branch information
kostyanf14 committed Jul 10, 2023
1 parent 24eecad commit 61df91b
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
35 changes: 35 additions & 0 deletions qga/vss-win32/install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ HRESULT put_Value(ICatalogObject *pObj, LPCWSTR name, T val)
/* Lookup Administrators group name from winmgmt */
static HRESULT GetAdminName(_bstr_t *name)
{
qga_debug_begin;

HRESULT hr;
COMPointer<IWbemLocator> pLoc;
COMPointer<IWbemServices> pSvc;
Expand Down Expand Up @@ -142,13 +144,16 @@ static HRESULT GetAdminName(_bstr_t *name)
}

out:
qga_debug_end;
return hr;
}

/* Acquire group or user name by SID */
static HRESULT getNameByStringSID(
const wchar_t *sid, LPWSTR buffer, LPDWORD bufferLen)
{
qga_debug_begin;

HRESULT hr = S_OK;
PSID psid = NULL;
SID_NAME_USE groupType;
Expand All @@ -168,13 +173,16 @@ static HRESULT getNameByStringSID(
LocalFree(psid);

out:
qga_debug_end;
return hr;
}

/* Find and iterate QGA VSS provider in COM+ Application Catalog */
static HRESULT QGAProviderFind(
HRESULT (*found)(ICatalogCollection *, int, void *), void *arg)
{
qga_debug_begin;

HRESULT hr;
COMInitializer initializer;
COMPointer<IUnknown> pUnknown;
Expand Down Expand Up @@ -205,41 +213,53 @@ static HRESULT QGAProviderFind(
chk(pColl->SaveChanges(&n));

out:
qga_debug_end;
return hr;
}

/* Count QGA VSS provider in COM+ Application Catalog */
static HRESULT QGAProviderCount(ICatalogCollection *coll, int i, void *arg)
{
qga_debug_begin;

(*(int *)arg)++;

qga_debug_end;
return S_OK;
}

/* Remove QGA VSS provider from COM+ Application Catalog Collection */
static HRESULT QGAProviderRemove(ICatalogCollection *coll, int i, void *arg)
{
qga_debug_begin;
HRESULT hr;

qga_debug("Removing COM+ Application: %s", QGA_PROVIDER_NAME);
chk(coll->Remove(i));
out:
qga_debug_end;
return hr;
}

/* Unregister this module from COM+ Applications Catalog */
STDAPI COMUnregister(void)
{
qga_debug_begin;

HRESULT hr;

DllUnregisterServer();
chk(QGAProviderFind(QGAProviderRemove, NULL));
out:
qga_debug_end;
return hr;
}

/* Register this module to COM+ Applications Catalog */
STDAPI COMRegister(void)
{
qga_debug_begin;

HRESULT hr;
COMInitializer initializer;
COMPointer<IUnknown> pUnknown;
Expand All @@ -259,12 +279,14 @@ STDAPI COMRegister(void)

if (!g_hinstDll) {
errmsg(E_FAIL, "Failed to initialize DLL");
qga_debug_end;
return E_FAIL;
}

chk(QGAProviderFind(QGAProviderCount, (void *)&count));
if (count) {
errmsg(E_ABORT, "QGA VSS Provider is already installed");
qga_debug_end;
return E_ABORT;
}

Expand Down Expand Up @@ -354,6 +376,7 @@ STDAPI COMRegister(void)
COMUnregister();
}

qga_debug_end;
return hr;
}

Expand All @@ -369,6 +392,8 @@ STDAPI_(void) CALLBACK DLLCOMUnregister(HWND, HINSTANCE, LPSTR, int)

static BOOL CreateRegistryKey(LPCTSTR key, LPCTSTR value, LPCTSTR data)
{
qga_debug_begin;

HKEY hKey;
LONG ret;
DWORD size;
Expand All @@ -389,6 +414,7 @@ static BOOL CreateRegistryKey(LPCTSTR key, LPCTSTR value, LPCTSTR data)
RegCloseKey(hKey);

out:
qga_debug_end;
if (ret != ERROR_SUCCESS) {
/* As we cannot printf within DllRegisterServer(), show a dialog. */
errmsg_dialog(ret, "Cannot add registry", key);
Expand All @@ -400,6 +426,8 @@ static BOOL CreateRegistryKey(LPCTSTR key, LPCTSTR value, LPCTSTR data)
/* Register this dll as a VSS provider */
STDAPI DllRegisterServer(void)
{
qga_debug_begin;

COMInitializer initializer;
COMPointer<IVssAdmin> pVssAdmin;
HRESULT hr = E_FAIL;
Expand Down Expand Up @@ -478,12 +506,15 @@ STDAPI DllRegisterServer(void)
DllUnregisterServer();
}

qga_debug_end;
return hr;
}

/* Unregister this VSS hardware provider from the system */
STDAPI DllUnregisterServer(void)
{
qga_debug_begin;

TCHAR key[256];
COMInitializer initializer;
COMPointer<IVssAdmin> pVssAdmin;
Expand All @@ -501,6 +532,7 @@ STDAPI DllUnregisterServer(void)
SHDeleteKey(HKEY_CLASSES_ROOT, key);
SHDeleteKey(HKEY_CLASSES_ROOT, g_szProgid);

qga_debug_end;
return S_OK; /* Uninstall should never fail */
}

Expand All @@ -527,6 +559,8 @@ namespace _com_util
/* Stop QGA VSS provider service using Winsvc API */
STDAPI StopService(void)
{
qga_debug_begin;

HRESULT hr = S_OK;
SC_HANDLE manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
SC_HANDLE service = NULL;
Expand All @@ -551,5 +585,6 @@ STDAPI StopService(void)
out:
CloseServiceHandle(service);
CloseServiceHandle(manager);
qga_debug_end;
return hr;
}
3 changes: 3 additions & 0 deletions qga/vss-win32/provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "qemu/osdep.h"
#include "vss-common.h"
#include "vss-debug.h"
#ifdef HAVE_VSS_SDK
#include <vscoordint.h>
#else
Expand Down Expand Up @@ -529,9 +530,11 @@ STDAPI DllCanUnloadNow()
EXTERN_C
BOOL WINAPI DllMain(HINSTANCE hinstDll, DWORD dwReason, LPVOID lpReserved)
{
qga_debug("begin, reason = %lu", dwReason);
if (dwReason == DLL_PROCESS_ATTACH) {
g_hinstDll = hinstDll;
DisableThreadLibraryCalls(hinstDll);
}
qga_debug_end;
return TRUE;
}
34 changes: 34 additions & 0 deletions qga/vss-win32/requester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ static struct QGAVSSContext {

STDAPI requester_init(void)
{
qga_debug_begin;

COMInitializer initializer; /* to call CoInitializeSecurity */
HRESULT hr = CoInitializeSecurity(
NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
Expand Down Expand Up @@ -92,11 +94,14 @@ STDAPI requester_init(void)
return HRESULT_FROM_WIN32(GetLastError());
}

qga_debug_end;
return S_OK;
}

static void requester_cleanup(void)
{
qga_debug_begin;

if (vss_ctx.hEventFrozen) {
CloseHandle(vss_ctx.hEventFrozen);
vss_ctx.hEventFrozen = NULL;
Expand All @@ -118,10 +123,13 @@ static void requester_cleanup(void)
vss_ctx.pVssbc = NULL;
}
vss_ctx.cFrozenVols = 0;
qga_debug_end;
}

STDAPI requester_deinit(void)
{
qga_debug_begin;

requester_cleanup();

pCreateVssBackupComponents = NULL;
Expand All @@ -131,11 +139,14 @@ STDAPI requester_deinit(void)
hLib = NULL;
}

qga_debug_end;
return S_OK;
}

static HRESULT WaitForAsync(IVssAsync *pAsync)
{
qga_debug_begin;

HRESULT ret, hr;

do {
Expand All @@ -151,11 +162,14 @@ static HRESULT WaitForAsync(IVssAsync *pAsync)
}
} while (ret == VSS_S_ASYNC_PENDING);

qga_debug_end;
return ret;
}

static void AddComponents(ErrorSet *errset)
{
qga_debug_begin;

unsigned int cWriters, i;
VSS_ID id, idInstance, idWriter;
BSTR bstrWriterName = NULL;
Expand Down Expand Up @@ -237,17 +251,21 @@ static void AddComponents(ErrorSet *errset)
if (pComponent && info) {
pComponent->FreeComponentInfo(info);
}
qga_debug_end;
}

DWORD get_reg_dword_value(HKEY baseKey, LPCSTR subKey, LPCSTR valueName,
DWORD defaultData)
{
qga_debug_begin;

DWORD regGetValueError;
DWORD dwordData;
DWORD dataSize = sizeof(DWORD);

regGetValueError = RegGetValue(baseKey, subKey, valueName, RRF_RT_DWORD,
NULL, &dwordData, &dataSize);
qga_debug_end;
if (regGetValueError != ERROR_SUCCESS) {
return defaultData;
}
Expand All @@ -262,13 +280,16 @@ bool is_valid_vss_backup_type(VSS_BACKUP_TYPE vssBT)
VSS_BACKUP_TYPE get_vss_backup_type(
VSS_BACKUP_TYPE defaultVssBT = DEFAULT_VSS_BACKUP_TYPE)
{
qga_debug_begin;

VSS_BACKUP_TYPE vssBackupType;

vssBackupType = static_cast<VSS_BACKUP_TYPE>(
get_reg_dword_value(HKEY_LOCAL_MACHINE,
QGA_PROVIDER_REGISTRY_ADDRESS,
"VssOption",
defaultVssBT));
qga_debug_end;
if (!is_valid_vss_backup_type(vssBackupType)) {
return defaultVssBT;
}
Expand All @@ -277,6 +298,8 @@ VSS_BACKUP_TYPE get_vss_backup_type(

void requester_freeze(int *num_vols, void *mountpoints, ErrorSet *errset)
{
qga_debug_begin;

COMPointer<IVssAsync> pAsync;
HANDLE volume;
HRESULT hr;
Expand All @@ -292,6 +315,7 @@ void requester_freeze(int *num_vols, void *mountpoints, ErrorSet *errset)

if (vss_ctx.pVssbc) { /* already frozen */
*num_vols = 0;
qga_debug("finished, already frozen");
return;
}

Expand Down Expand Up @@ -449,6 +473,7 @@ void requester_freeze(int *num_vols, void *mountpoints, ErrorSet *errset)
}
}

qga_debug("preparing for backup");
hr = vss_ctx.pVssbc->PrepareForBackup(pAsync.replace());
if (SUCCEEDED(hr)) {
hr = WaitForAsync(pAsync);
Expand All @@ -472,6 +497,7 @@ void requester_freeze(int *num_vols, void *mountpoints, ErrorSet *errset)
* CQGAVssProvider::CommitSnapshots will kick vss_ctx.hEventFrozen
* after the applications and filesystems are frozen.
*/
qga_debug("do snapshot set");
hr = vss_ctx.pVssbc->DoSnapshotSet(&vss_ctx.pAsyncSnapshot);
if (FAILED(hr)) {
err_set(errset, hr, "failed to do snapshot set");
Expand Down Expand Up @@ -518,6 +544,7 @@ void requester_freeze(int *num_vols, void *mountpoints, ErrorSet *errset)
*num_vols = vss_ctx.cFrozenVols = num_fixed_drives;
}

qga_debug("end successful");
return;

out:
Expand All @@ -528,11 +555,14 @@ void requester_freeze(int *num_vols, void *mountpoints, ErrorSet *errset)
out1:
requester_cleanup();
CoUninitialize();

qga_debug_end;
}


void requester_thaw(int *num_vols, void *mountpints, ErrorSet *errset)
{
qga_debug_begin;
COMPointer<IVssAsync> pAsync;

if (!vss_ctx.hEventThaw) {
Expand All @@ -541,6 +571,8 @@ void requester_thaw(int *num_vols, void *mountpints, ErrorSet *errset)
* and no volumes must be frozen. We return without an error.
*/
*num_vols = 0;
qga_debug("finished, no volumes were frozen");

return;
}

Expand Down Expand Up @@ -597,4 +629,6 @@ void requester_thaw(int *num_vols, void *mountpints, ErrorSet *errset)

CoUninitialize();
StopService();

qga_debug_end;
}

0 comments on commit 61df91b

Please sign in to comment.