2 * QEMU Guest Agent VSS utility functions
4 * Copyright Hitachi Data Systems Corp. 2013
7 * Tomoki Sekiyama <tomoki.sekiyama@hds.com>
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
13 #include "qemu/osdep.h"
15 #include "qga/guest-agent-core.h"
16 #include "qga/vss-win32.h"
17 #include "qga/vss-win32/requester.h"
19 #define QGA_VSS_DLL "qga-vss.dll"
21 static HMODULE provider_lib
;
23 /* Call a function in qga-vss.dll with the specified name */
24 static HRESULT
call_vss_provider_func(const char *func_name
)
28 g_assert(provider_lib
);
30 func
= GetProcAddress(provider_lib
, func_name
);
33 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
34 FORMAT_MESSAGE_FROM_SYSTEM
, NULL
, GetLastError(),
35 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
36 (char *)&msg
, 0, NULL
);
37 fprintf(stderr
, "failed to load %s from %s: %s",
38 func_name
, QGA_VSS_DLL
, msg
);
46 /* Check whether this OS version supports VSS providers */
47 static bool vss_check_os_version(void)
51 OSver
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
53 if ((OSver
.dwMajorVersion
== 5 && OSver
.dwMinorVersion
>= 2) ||
54 OSver
.dwMajorVersion
> 5) {
57 /* Provider doesn't work under WOW64 (32bit agent on 64bit OS) */
58 if (!IsWow64Process(GetCurrentProcess(), &wow64
)) {
59 fprintf(stderr
, "failed to IsWow64Process (Error: %lx\n)\n",
64 fprintf(stderr
, "Warning: Running under WOW64\n");
72 /* Load qga-vss.dll */
73 bool vss_init(bool init_requester
)
75 if (!vss_check_os_version()) {
76 /* Do nothing if OS doesn't support providers. */
77 fprintf(stderr
, "VSS provider is not supported in this OS version: "
78 "fsfreeze is disabled.\n");
82 provider_lib
= LoadLibraryA(QGA_VSS_DLL
);
85 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
86 FORMAT_MESSAGE_FROM_SYSTEM
, NULL
, GetLastError(),
87 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
88 (char *)&msg
, 0, NULL
);
89 fprintf(stderr
, "failed to load %s: %sfsfreeze is disabled\n",
96 HRESULT hr
= call_vss_provider_func("requester_init");
98 fprintf(stderr
, "fsfreeze is disabled.\n");
107 /* Unload qga-provider.dll */
108 void vss_deinit(bool deinit_requester
)
110 if (deinit_requester
) {
111 call_vss_provider_func("requester_deinit");
113 FreeLibrary(provider_lib
);
117 bool vss_initialized(void)
119 return !!provider_lib
;
122 int ga_install_vss_provider(void)
126 if (!vss_init(false)) {
127 fprintf(stderr
, "Installation of VSS provider is skipped. "
128 "fsfreeze will be disabled.\n");
131 hr
= call_vss_provider_func("COMRegister");
134 return SUCCEEDED(hr
) ? 0 : EXIT_FAILURE
;
137 void ga_uninstall_vss_provider(void)
139 if (!vss_init(false)) {
140 fprintf(stderr
, "Removal of VSS provider is skipped.\n");
143 call_vss_provider_func("COMUnregister");
147 /* Call VSS requester and freeze/thaw filesystems and applications */
148 void qga_vss_fsfreeze(int *nr_volume
, Error
**errp
, bool freeze
)
150 const char *func_name
= freeze
? "requester_freeze" : "requester_thaw";
151 QGAVSSRequesterFunc func
;
153 .error_setg_win32_wrapper
= error_setg_win32_internal
,
157 g_assert(errp
); /* requester.cpp requires it */
158 func
= (QGAVSSRequesterFunc
)GetProcAddress(provider_lib
, func_name
);
160 error_setg_win32(errp
, GetLastError(), "failed to load %s from %s",
161 func_name
, QGA_VSS_DLL
);
165 func(nr_volume
, &errset
);