qemu-ga: Add Windows VSS provider and requester as DLL

Adds VSS provider and requester as a qga-vss.dll, which is loaded by
Windows VSS service as well as by qemu-ga.

"provider.cpp" implements a basic stub of a software VSS provider.
Currently, this module only relays a frozen event from VSS service to the
agent, and thaw event from the agent to VSS service, to block VSS process
to keep the system frozen while snapshots are taken at the host.

To register the provider to the guest system as COM+ application, the type
library (.tlb) for qga-vss.dll is required. To build it from COM IDL (.idl),
VisualC++, MIDL and stdole2.tlb in Windows SDK are required. This patch also
adds pre-compiled .tlb file in the repository in order to enable
cross-compile qemu-ga.exe for Windows with VSS support.

"requester.cpp" provides the VSS requester to kick the VSS snapshot process.
Qemu-ga.exe works without the DLL, although fsfreeze features are disabled.

These functions are only supported in Windows 2003 or later. In older
systems, fsfreeze features are disabled.

In several versions of Windows which don't support attribute
VSS_VOLSNAP_ATTR_NO_AUTORECOVERY, DoSnapshotSet fails with error
VSS_E_OBJECT_NOT_FOUND. In this patch, we just ignore this error.
To solve this fundamentally, we need a framework to handle mount writable
snapshot on guests, which is required by VSS auto-recovery feature
(cleanup phase after a snapshot is taken).

Signed-off-by: Tomoki Sekiyama <tomoki.sekiyama@hds.com>
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
This commit is contained in:
Tomoki Sekiyama
2013-09-09 14:17:57 -05:00
committed by Michael Roth
parent 20840d4cfe
commit b39297aedf
13 changed files with 1724 additions and 2 deletions
+1 -1
View File
@@ -235,7 +235,7 @@ clean:
rm -f qemu-options.def
find . -name '*.[oda]' -type f -exec rm -f {} +
find . -name '*.l[oa]' -type f -exec rm -f {} +
rm -f $(TOOLS) $(HELPERS-y) qemu-ga TAGS cscope.* *.pod *~ */*~
rm -f $(filter-out %.tlb,$(TOOLS)) $(HELPERS-y) qemu-ga TAGS cscope.* *.pod *~ */*~
rm -Rf .libs
rm -f qemu-img-cmds.h
@# May not be present in GENERATED_HEADERS
+2
View File
@@ -109,6 +109,7 @@ version-lobj-$(CONFIG_WIN32) += $(BUILD_DIR)/version.lo
# FIXME: a few definitions from qapi-types.o/qapi-visit.o are needed
# by libqemuutil.a. These should be moved to a separate .json schema.
qga-obj-y = qga/ qapi-types.o qapi-visit.o
qga-vss-dll-obj-y = qga/
vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
@@ -120,6 +121,7 @@ nested-vars += \
stub-obj-y \
util-obj-y \
qga-obj-y \
qga-vss-dll-obj-y \
block-obj-y \
common-obj-y
dummy := $(call unnest-vars)
Vendored
+4 -1
View File
@@ -3568,8 +3568,11 @@ if test "$softmmu" = yes ; then
fi
fi
if [ "$guest_agent" != "no" ]; then
if [ "$linux" = "yes" -o "$bsd" = "yes" -o "$solaris" = "yes" ] ; then
if [ "$linux" = "yes" -o "$bsd" = "yes" -o "$solaris" = "yes" -o "$mingw32" = "yes" ] ; then
tools="qemu-ga\$(EXESUF) $tools"
if [ "$mingw32" = "yes" -a "$guest_agent_with_vss" = "yes" ]; then
tools="qga/vss-win32/qga-vss.dll qga/vss-win32/qga-vss.tlb $tools"
fi
guest_agent=yes
elif [ "$guest_agent" != yes ]; then
guest_agent=no
+2
View File
@@ -3,3 +3,5 @@ qga-obj-$(CONFIG_POSIX) += commands-posix.o channel-posix.o
qga-obj-$(CONFIG_WIN32) += commands-win32.o channel-win32.o service-win32.o
qga-obj-y += qapi-generated/qga-qapi-types.o qapi-generated/qga-qapi-visit.o
qga-obj-y += qapi-generated/qga-qmp-marshal.o
qga-vss-dll-obj-$(CONFIG_QGA_VSS) += vss-win32/
+23
View File
@@ -0,0 +1,23 @@
# rules to build qga-vss.dll
qga-vss-dll-obj-y += requester.o provider.o install.o
obj-qga-vss-dll-obj-y = $(addprefix $(obj)/, $(qga-vss-dll-obj-y))
$(obj-qga-vss-dll-obj-y): QEMU_CXXFLAGS = $(filter-out -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Wold-style-declaration -Wold-style-definition -Wredundant-decls -fstack-protector-all, $(QEMU_CFLAGS)) -Wno-unknown-pragmas -Wno-delete-non-virtual-dtor
$(obj)/qga-vss.dll: LDFLAGS = -shared -Wl,--add-stdcall-alias,--enable-stdcall-fixup -lole32 -loleaut32 -lshlwapi -luuid -static
$(obj)/qga-vss.dll: $(obj-qga-vss-dll-obj-y) $(SRC_PATH)/$(obj)/qga-vss.def
$(call quiet-command,$(CXX) -o $@ $(qga-vss-dll-obj-y) $(SRC_PATH)/qga/vss-win32/qga-vss.def $(CXXFLAGS) $(LDFLAGS)," LINK $(TARGET_DIR)$@")
# rules to build qga-provider.tlb
# Currently, only native build is supported because building .tlb
# (TypeLibrary) from .idl requires WindowsSDK and MIDL (and cl.exe in VC++).
MIDL=$(WIN_SDK)/Bin/midl
$(obj)/qga-vss.tlb: $(SRC_PATH)/$(obj)/qga-vss.idl
ifeq ($(WIN_SDK),"")
$(call quiet-command,cp $(dir $<)qga-vss.tlb $@, " COPY $(TARGET_DIR)$@")
else
$(call quiet-command,$(MIDL) -tlb $@ -I $(WIN_SDK)/Include $<," MIDL $(TARGET_DIR)$@")
endif
+458
View File
@@ -0,0 +1,458 @@
/*
* QEMU Guest Agent win32 VSS Provider installer
*
* Copyright Hitachi Data Systems Corp. 2013
*
* Authors:
* Tomoki Sekiyama <tomoki.sekiyama@hds.com>
*
* This work is licensed under the terms of the GNU GPL, version 2 or later.
* See the COPYING file in the top-level directory.
*/
#include <stdio.h>
#include <string.h>
#include "vss-common.h"
#include "inc/win2003/vscoordint.h"
#include <comadmin.h>
#include <wbemidl.h>
#include <comdef.h>
#include <comutil.h>
extern HINSTANCE g_hinstDll;
const GUID CLSID_COMAdminCatalog = { 0xF618C514, 0xDFB8, 0x11d1,
{0xA2, 0xCF, 0x00, 0x80, 0x5F, 0xC7, 0x92, 0x35} };
const GUID IID_ICOMAdminCatalog = { 0xDD662187, 0xDFC2, 0x11d1,
{0xA2, 0xCF, 0x00, 0x80, 0x5F, 0xC7, 0x92, 0x35} };
const GUID CLSID_WbemLocator = { 0x4590f811, 0x1d3a, 0x11d0,
{0x89, 0x1f, 0x00, 0xaa, 0x00, 0x4b, 0x2e, 0x24} };
const GUID IID_IWbemLocator = { 0xdc12a687, 0x737f, 0x11cf,
{0x88, 0x4d, 0x00, 0xaa, 0x00, 0x4b, 0x2e, 0x24} };
void errmsg(DWORD err, const char *text)
{
/*
* `text' contains function call statement when errmsg is called via chk().
* To make error message more readable, we cut off the text after '('.
* If text doesn't contains '(', negative precision is given, which is
* treated as though it were missing.
*/
char *msg = NULL, *nul = strchr(text, '(');
int len = nul ? nul - text : -1;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(char *)&msg, 0, NULL);
fprintf(stderr, "%.*s. (Error: %lx) %s\n", len, text, err, msg);
LocalFree(msg);
}
static void errmsg_dialog(DWORD err, const char *text, const char *opt = "")
{
char *msg, buf[512];
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(char *)&msg, 0, NULL);
snprintf(buf, sizeof(buf), "%s%s. (Error: %lx) %s", text, opt, err, msg);
MessageBox(NULL, buf, "Error from " QGA_PROVIDER_NAME, MB_OK|MB_ICONERROR);
LocalFree(msg);
}
#define _chk(hr, status, msg, err_label) \
do { \
hr = (status); \
if (FAILED(hr)) { \
errmsg(hr, msg); \
goto err_label; \
} \
} while (0)
#define chk(status) _chk(hr, status, "Failed to " #status, out)
void __stdcall _com_issue_error(HRESULT hr)
{
errmsg(hr, "Unexpected error in COM");
}
template<class T>
HRESULT put_Value(ICatalogObject *pObj, LPCWSTR name, T val)
{
return pObj->put_Value(_bstr_t(name), _variant_t(val));
}
/* Lookup Administrators group name from winmgmt */
static HRESULT GetAdminName(_bstr_t *name)
{
HRESULT hr;
COMPointer<IWbemLocator> pLoc;
COMPointer<IWbemServices> pSvc;
COMPointer<IEnumWbemClassObject> pEnum;
COMPointer<IWbemClassObject> pWobj;
ULONG returned;
_variant_t var;
chk(CoCreateInstance(CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER,
IID_IWbemLocator, (LPVOID *)pLoc.replace()));
chk(pLoc->ConnectServer(_bstr_t(L"ROOT\\CIMV2"), NULL, NULL, NULL,
0, 0, 0, pSvc.replace()));
chk(CoSetProxyBlanket(pSvc, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE,
NULL, RPC_C_AUTHN_LEVEL_CALL,
RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE));
chk(pSvc->ExecQuery(_bstr_t(L"WQL"),
_bstr_t(L"select * from Win32_Account where "
"SID='S-1-5-32-544' and localAccount=TRUE"),
WBEM_FLAG_RETURN_IMMEDIATELY | WBEM_FLAG_FORWARD_ONLY,
NULL, pEnum.replace()));
if (!pEnum) {
hr = E_FAIL;
errmsg(hr, "Failed to query for Administrators");
goto out;
}
chk(pEnum->Next(WBEM_INFINITE, 1, pWobj.replace(), &returned));
if (returned == 0) {
hr = E_FAIL;
errmsg(hr, "No Administrators found");
goto out;
}
chk(pWobj->Get(_bstr_t(L"Name"), 0, &var, 0, 0));
try {
*name = var;
} catch(...) {
hr = E_FAIL;
errmsg(hr, "Failed to get name of Administrators");
goto out;
}
out:
return hr;
}
/* Find and iterate QGA VSS provider in COM+ Application Catalog */
static HRESULT QGAProviderFind(
HRESULT (*found)(ICatalogCollection *, int, void *), void *arg)
{
HRESULT hr;
COMInitializer initializer;
COMPointer<IUnknown> pUnknown;
COMPointer<ICOMAdminCatalog> pCatalog;
COMPointer<ICatalogCollection> pColl;
COMPointer<ICatalogObject> pObj;
_variant_t var;
long i, n;
chk(CoCreateInstance(CLSID_COMAdminCatalog, NULL, CLSCTX_INPROC_SERVER,
IID_IUnknown, (void **)pUnknown.replace()));
chk(pUnknown->QueryInterface(IID_ICOMAdminCatalog,
(void **)pCatalog.replace()));
chk(pCatalog->GetCollection(_bstr_t(L"Applications"),
(IDispatch **)pColl.replace()));
chk(pColl->Populate());
chk(pColl->get_Count(&n));
for (i = n - 1; i >= 0; i--) {
chk(pColl->get_Item(i, (IDispatch **)pObj.replace()));
chk(pObj->get_Value(_bstr_t(L"Name"), &var));
if (var == _variant_t(QGA_PROVIDER_LNAME)) {
if (FAILED(found(pColl, i, arg))) {
goto out;
}
}
}
chk(pColl->SaveChanges(&n));
out:
return hr;
}
/* Count QGA VSS provider in COM+ Application Catalog */
static HRESULT QGAProviderCount(ICatalogCollection *coll, int i, void *arg)
{
(*(int *)arg)++;
return S_OK;
}
/* Remove QGA VSS provider from COM+ Application Catalog Collection */
static HRESULT QGAProviderRemove(ICatalogCollection *coll, int i, void *arg)
{
HRESULT hr;
fprintf(stderr, "Removing COM+ Application: %s\n", QGA_PROVIDER_NAME);
chk(coll->Remove(i));
out:
return hr;
}
/* Unregister this module from COM+ Applications Catalog */
STDAPI COMUnregister(void)
{
HRESULT hr;
DllUnregisterServer();
chk(QGAProviderFind(QGAProviderRemove, NULL));
out:
return hr;
}
/* Register this module to COM+ Applications Catalog */
STDAPI COMRegister(void)
{
HRESULT hr;
COMInitializer initializer;
COMPointer<IUnknown> pUnknown;
COMPointer<ICOMAdminCatalog> pCatalog;
COMPointer<ICatalogCollection> pApps, pRoles, pUsersInRole;
COMPointer<ICatalogObject> pObj;
long n;
_bstr_t name;
_variant_t key;
CHAR dllPath[MAX_PATH], tlbPath[MAX_PATH];
bool unregisterOnFailure = false;
int count = 0;
if (!g_hinstDll) {
errmsg(E_FAIL, "Failed to initialize DLL");
return E_FAIL;
}
chk(QGAProviderFind(QGAProviderCount, (void *)&count));
if (count) {
errmsg(E_ABORT, "QGA VSS Provider is already installed");
return E_ABORT;
}
chk(CoCreateInstance(CLSID_COMAdminCatalog, NULL, CLSCTX_INPROC_SERVER,
IID_IUnknown, (void **)pUnknown.replace()));
chk(pUnknown->QueryInterface(IID_ICOMAdminCatalog,
(void **)pCatalog.replace()));
/* Install COM+ Component */
chk(pCatalog->GetCollection(_bstr_t(L"Applications"),
(IDispatch **)pApps.replace()));
chk(pApps->Populate());
chk(pApps->Add((IDispatch **)&pObj));
chk(put_Value(pObj, L"Name", QGA_PROVIDER_LNAME));
chk(put_Value(pObj, L"Description", QGA_PROVIDER_LNAME));
chk(put_Value(pObj, L"ApplicationAccessChecksEnabled", true));
chk(put_Value(pObj, L"Authentication", short(6)));
chk(put_Value(pObj, L"AuthenticationCapability", short(2)));
chk(put_Value(pObj, L"ImpersonationLevel", short(2)));
chk(pApps->SaveChanges(&n));
/* The app should be deleted if something fails after SaveChanges */
unregisterOnFailure = true;
chk(pObj->get_Key(&key));
if (!GetModuleFileName(g_hinstDll, dllPath, sizeof(dllPath))) {
hr = HRESULT_FROM_WIN32(GetLastError());
errmsg(hr, "GetModuleFileName failed");
goto out;
}
n = strlen(dllPath);
if (n < 3) {
hr = E_FAIL;
errmsg(hr, "Failed to lookup dll");
goto out;
}
strcpy(tlbPath, dllPath);
strcpy(tlbPath+n-3, "tlb");
fprintf(stderr, "Registering " QGA_PROVIDER_NAME ":\n");
fprintf(stderr, " %s\n", dllPath);
fprintf(stderr, " %s\n", tlbPath);
if (!PathFileExists(tlbPath)) {
hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
errmsg(hr, "Failed to lookup tlb");
goto out;
}
chk(pCatalog->InstallComponent(_bstr_t(QGA_PROVIDER_LNAME),
_bstr_t(dllPath), _bstr_t(tlbPath),
_bstr_t("")));
/* Setup roles of the applicaion */
chk(pApps->GetCollection(_bstr_t(L"Roles"), key,
(IDispatch **)pRoles.replace()));
chk(pRoles->Populate());
chk(pRoles->Add((IDispatch **)pObj.replace()));
chk(put_Value(pObj, L"Name", L"Administrators"));
chk(put_Value(pObj, L"Description", L"Administrators group"));
chk(pRoles->SaveChanges(&n));
chk(pObj->get_Key(&key));
/* Setup users in the role */
chk(pRoles->GetCollection(_bstr_t(L"UsersInRole"), key,
(IDispatch **)pUsersInRole.replace()));
chk(pUsersInRole->Populate());
chk(pUsersInRole->Add((IDispatch **)pObj.replace()));
chk(GetAdminName(&name));
chk(put_Value(pObj, L"User", _bstr_t(".\\") + name));
chk(pUsersInRole->Add((IDispatch **)pObj.replace()));
chk(put_Value(pObj, L"User", L"SYSTEM"));
chk(pUsersInRole->SaveChanges(&n));
out:
if (unregisterOnFailure && FAILED(hr)) {
COMUnregister();
}
return hr;
}
static BOOL CreateRegistryKey(LPCTSTR key, LPCTSTR value, LPCTSTR data)
{
HKEY hKey;
LONG ret;
DWORD size;
ret = RegCreateKeyEx(HKEY_CLASSES_ROOT, key, 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL);
if (ret != ERROR_SUCCESS) {
goto out;
}
if (data != NULL) {
size = strlen(data) + 1;
} else {
size = 0;
}
ret = RegSetValueEx(hKey, value, 0, REG_SZ, (LPBYTE)data, size);
RegCloseKey(hKey);
out:
if (ret != ERROR_SUCCESS) {
/* As we cannot printf within DllRegisterServer(), show a dialog. */
errmsg_dialog(ret, "Cannot add registry", key);
return FALSE;
}
return TRUE;
}
/* Register this dll as a VSS provider */
STDAPI DllRegisterServer(void)
{
COMInitializer initializer;
COMPointer<IVssAdmin> pVssAdmin;
HRESULT hr = E_FAIL;
char dllPath[MAX_PATH];
char key[256];
if (!g_hinstDll) {
errmsg_dialog(hr, "Module instance is not available");
goto out;
}
/* Add this module to registery */
sprintf(key, "CLSID\\%s", g_szClsid);
if (!CreateRegistryKey(key, NULL, g_szClsid)) {
goto out;
}
if (!GetModuleFileName(g_hinstDll, dllPath, sizeof(dllPath))) {
errmsg_dialog(GetLastError(), "GetModuleFileName failed");
goto out;
}
sprintf(key, "CLSID\\%s\\InprocServer32", g_szClsid);
if (!CreateRegistryKey(key, NULL, dllPath)) {
goto out;
}
if (!CreateRegistryKey(key, "ThreadingModel", "Apartment")) {
goto out;
}
sprintf(key, "CLSID\\%s\\ProgID", g_szClsid);
if (!CreateRegistryKey(key, NULL, g_szProgid)) {
goto out;
}
if (!CreateRegistryKey(g_szProgid, NULL, QGA_PROVIDER_NAME)) {
goto out;
}
sprintf(key, "%s\\CLSID", g_szProgid);
if (!CreateRegistryKey(key, NULL, g_szClsid)) {
goto out;
}
hr = CoCreateInstance(CLSID_VSSCoordinator, NULL, CLSCTX_ALL,
IID_IVssAdmin, (void **)pVssAdmin.replace());
if (FAILED(hr)) {
errmsg_dialog(hr, "CoCreateInstance(VSSCoordinator) failed");
goto out;
}
hr = pVssAdmin->RegisterProvider(g_gProviderId, CLSID_QGAVSSProvider,
const_cast<WCHAR*>(QGA_PROVIDER_LNAME),
VSS_PROV_SOFTWARE,
const_cast<WCHAR*>(QGA_PROVIDER_VERSION),
g_gProviderVersion);
if (FAILED(hr)) {
errmsg_dialog(hr, "RegisterProvider failed");
}
out:
if (FAILED(hr)) {
DllUnregisterServer();
}
return hr;
}
/* Unregister this VSS hardware provider from the system */
STDAPI DllUnregisterServer(void)
{
TCHAR key[256];
COMInitializer initializer;
COMPointer<IVssAdmin> pVssAdmin;
HRESULT hr = CoCreateInstance(CLSID_VSSCoordinator,
NULL, CLSCTX_ALL, IID_IVssAdmin,
(void **)pVssAdmin.replace());
if (SUCCEEDED(hr)) {
hr = pVssAdmin->UnregisterProvider(g_gProviderId);
} else {
errmsg(hr, "CoCreateInstance(VSSCoordinator) failed");
}
sprintf(key, "CLSID\\%s", g_szClsid);
SHDeleteKey(HKEY_CLASSES_ROOT, key);
SHDeleteKey(HKEY_CLASSES_ROOT, g_szProgid);
return S_OK; /* Uninstall should never fail */
}
/* Support function to convert ASCII string into BSTR (used in _bstr_t) */
namespace _com_util
{
BSTR WINAPI ConvertStringToBSTR(const char *ascii) {
int len = strlen(ascii);
BSTR bstr = SysAllocStringLen(NULL, len);
if (!bstr) {
return NULL;
}
if (mbstowcs(bstr, ascii, len) == (size_t)-1) {
fprintf(stderr, "Failed to convert string '%s' into BSTR", ascii);
bstr[0] = 0;
}
return bstr;
}
}
File diff suppressed because it is too large Load Diff
+13
View File
@@ -0,0 +1,13 @@
LIBRARY "QGA-PROVIDER.DLL"
EXPORTS
COMRegister PRIVATE
COMUnregister PRIVATE
DllCanUnloadNow PRIVATE
DllGetClassObject PRIVATE
DllRegisterServer PRIVATE
DllUnregisterServer PRIVATE
requester_init PRIVATE
requester_deinit PRIVATE
requester_freeze PRIVATE
requester_thaw PRIVATE
+20
View File
@@ -0,0 +1,20 @@
import "oaidl.idl";
import "ocidl.idl";
[
uuid(103B8142-6CE5-48A7-BDE1-794D3192FCF1),
version(1.0),
helpstring("QGAVSSProvider Type Library")
]
library QGAVSSHWProviderLib
{
importlib("stdole2.tlb");
[
uuid(6E6A3492-8D4D-440C-9619-5E5D0CC31CA8),
helpstring("QGAVSSProvider Class")
]
coclass QGAVSSHWProvider
{
[default] interface IUnknown;
};
};
Binary file not shown.
File diff suppressed because it is too large Load Diff
+42
View File
@@ -0,0 +1,42 @@
/*
* QEMU Guest Agent VSS requester declarations
*
* Copyright Hitachi Data Systems Corp. 2013
*
* Authors:
* Tomoki Sekiyama <tomoki.sekiyama@hds.com>
*
* This work is licensed under the terms of the GNU GPL, version 2 or later.
* See the COPYING file in the top-level directory.
*/
#ifndef VSS_WIN32_REQUESTER_H
#define VSS_WIN32_REQUESTER_H
#include "qemu/compiler.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Callback to set Error; used to avoid linking glib to the DLL */
typedef void (*ErrorSetFunc)(void **errp, int win32_err, int err_class,
const char *fmt, ...) GCC_FMT_ATTR(4, 5);
typedef struct ErrorSet {
ErrorSetFunc error_set;
void **errp;
int err_class;
} ErrorSet;
STDAPI requester_init(void);
STDAPI requester_deinit(void);
typedef void (*QGAVSSRequesterFunc)(int *, ErrorSet *);
void requester_freeze(int *num_vols, ErrorSet *errset);
void requester_thaw(int *num_vols, ErrorSet *errset);
#ifdef __cplusplus
}
#endif
#endif
+129
View File
@@ -0,0 +1,129 @@
/*
* QEMU Guest Agent win32 VSS common declarations
*
* Copyright Hitachi Data Systems Corp. 2013
*
* Authors:
* Tomoki Sekiyama <tomoki.sekiyama@hds.com>
*
* This work is licensed under the terms of the GNU GPL, version 2 or later.
* See the COPYING file in the top-level directory.
*/
#ifndef VSS_WIN32_H
#define VSS_WIN32_H
#define __MIDL_user_allocate_free_DEFINED__
#include "config-host.h"
#include <windows.h>
#include <shlwapi.h>
/* Reduce warnings to include vss.h */
/* Ignore annotations for MS IDE */
#define __in IN
#define __out OUT
#define __RPC_unique_pointer
#define __RPC_string
#define __RPC__deref_inout_opt
#define __RPC__out
#ifndef __RPC__out_ecount_part
#define __RPC__out_ecount_part(x, y)
#endif
#define _declspec(x)
#undef uuid
#define uuid(x)
/* Undef some duplicated error codes redefined in vss.h */
#undef VSS_E_BAD_STATE
#undef VSS_E_PROVIDER_NOT_REGISTERED
#undef VSS_E_PROVIDER_VETO
#undef VSS_E_OBJECT_NOT_FOUND
#undef VSS_E_VOLUME_NOT_SUPPORTED
#undef VSS_E_VOLUME_NOT_SUPPORTED_BY_PROVIDER
#undef VSS_E_OBJECT_ALREADY_EXISTS
#undef VSS_E_UNEXPECTED_PROVIDER_ERROR
#undef VSS_E_INVALID_XML_DOCUMENT
#undef VSS_E_MAXIMUM_NUMBER_OF_VOLUMES_REACHED
#undef VSS_E_MAXIMUM_NUMBER_OF_SNAPSHOTS_REACHED
/*
* VSS headers must be installed from Microsoft VSS SDK 7.2 available at:
* http://www.microsoft.com/en-us/download/details.aspx?id=23490
*/
#include "inc/win2003/vss.h"
/* Macros to convert char definitions to wchar */
#define _L(a) L##a
#define L(a) _L(a)
/* Constants for QGA VSS Provider */
#define QGA_PROVIDER_NAME "QEMU Guest Agent VSS Provider"
#define QGA_PROVIDER_LNAME L(QGA_PROVIDER_NAME)
#define QGA_PROVIDER_VERSION L(QEMU_VERSION)
#define EVENT_NAME_FROZEN "Global\\QGAVSSEvent-frozen"
#define EVENT_NAME_THAW "Global\\QGAVSSEvent-thaw"
#define EVENT_NAME_TIMEOUT "Global\\QGAVSSEvent-timeout"
const GUID g_gProviderId = { 0x3629d4ed, 0xee09, 0x4e0e,
{0x9a, 0x5c, 0x6d, 0x8b, 0xa2, 0x87, 0x2a, 0xef} };
const GUID g_gProviderVersion = { 0x11ef8b15, 0xcac6, 0x40d6,
{0x8d, 0x5c, 0x8f, 0xfc, 0x16, 0x3f, 0x24, 0xca} };
const CLSID CLSID_QGAVSSProvider = { 0x6e6a3492, 0x8d4d, 0x440c,
{0x96, 0x19, 0x5e, 0x5d, 0x0c, 0xc3, 0x1c, 0xa8} };
const TCHAR g_szClsid[] = TEXT("{6E6A3492-8D4D-440C-9619-5E5D0CC31CA8}");
const TCHAR g_szProgid[] = TEXT("QGAVSSProvider");
/* Enums undefined in VSS SDK 7.2 but defined in newer Windows SDK */
enum __VSS_VOLUME_SNAPSHOT_ATTRIBUTES {
VSS_VOLSNAP_ATTR_NO_AUTORECOVERY = 0x00000002,
VSS_VOLSNAP_ATTR_TXF_RECOVERY = 0x02000000
};
/* COM pointer utility; call ->Release() when it goes out of scope */
template <class T>
class COMPointer {
COMPointer(const COMPointer<T> &p) { } /* no copy */
T *p;
public:
COMPointer &operator=(T *new_p)
{
/* Assignment of a new T* (or NULL) causes release of previous p */
if (p && p != new_p) {
p->Release();
}
p = new_p;
return *this;
}
/* Replace by assignment to the pointer of p */
T **replace(void)
{
*this = NULL;
return &p;
}
/* Make COMPointer be used like T* */
operator T*() { return p; }
T *operator->(void) { return p; }
T &operator*(void) { return *p; }
operator bool() { return !!p; }
COMPointer(T *p = NULL) : p(p) { }
~COMPointer() { *this = NULL; } /* Automatic release */
};
/*
* COM initializer; this should declared before COMPointer to uninitialize COM
* after releasing COM objects.
*/
class COMInitializer {
public:
COMInitializer() { CoInitialize(NULL); }
~COMInitializer() { CoUninitialize(); }
};
#endif