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 "qapi/error.h"
16 #include "qemu/error-report.h"
17 #include "guest-agent-core.h"
18 #include "vss-win32.h"
19 #include "vss-win32/requester.h"
21 #define QGA_VSS_DLL "qga-vss.dll"
23 static HMODULE provider_lib
;
25 /* Call a function in qga-vss.dll with the specified name */
26 static HRESULT
call_vss_provider_func(const char *func_name
)
30 g_assert(provider_lib
);
32 func
= GetProcAddress(provider_lib
, func_name
);
35 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
36 FORMAT_MESSAGE_FROM_SYSTEM
, NULL
, GetLastError(),
37 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
38 (char *)&msg
, 0, NULL
);
39 fprintf(stderr
, "failed to load %s from %s: %s",
40 func_name
, QGA_VSS_DLL
, msg
);
48 /* Check whether this OS version supports VSS providers */
49 static bool vss_check_os_version(void)
53 OSver
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
55 if ((OSver
.dwMajorVersion
== 5 && OSver
.dwMinorVersion
>= 2) ||
56 OSver
.dwMajorVersion
> 5) {
59 /* Provider doesn't work under WOW64 (32bit agent on 64bit OS) */
60 if (!IsWow64Process(GetCurrentProcess(), &wow64
)) {
61 fprintf(stderr
, "failed to IsWow64Process (Error: %lx\n)\n",
66 warn_report("Running under WOW64");
74 /* Load qga-vss.dll */
75 bool vss_init(bool init_requester
)
77 if (!vss_check_os_version()) {
78 /* Do nothing if OS doesn't support providers. */
79 fprintf(stderr
, "VSS provider is not supported in this OS version: "
80 "fsfreeze is disabled.\n");
84 provider_lib
= LoadLibraryA(QGA_VSS_DLL
);
87 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
88 FORMAT_MESSAGE_FROM_SYSTEM
, NULL
, GetLastError(),
89 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
90 (char *)&msg
, 0, NULL
);
91 fprintf(stderr
, "failed to load %s: %sfsfreeze is disabled\n",
98 HRESULT hr
= call_vss_provider_func("requester_init");
100 fprintf(stderr
, "fsfreeze is disabled.\n");
109 /* Unload qga-provider.dll */
110 void vss_deinit(bool deinit_requester
)
112 if (deinit_requester
) {
113 call_vss_provider_func("requester_deinit");
115 FreeLibrary(provider_lib
);
119 bool vss_initialized(void)
121 return !!provider_lib
;
124 int ga_install_vss_provider(void)
128 if (!vss_init(false)) {
129 fprintf(stderr
, "Installation of VSS provider is skipped. "
130 "fsfreeze will be disabled.\n");
133 hr
= call_vss_provider_func("COMRegister");
136 return SUCCEEDED(hr
) ? 0 : EXIT_FAILURE
;
139 void ga_uninstall_vss_provider(void)
141 if (!vss_init(false)) {
142 fprintf(stderr
, "Removal of VSS provider is skipped.\n");
145 call_vss_provider_func("COMUnregister");
149 /* Call VSS requester and freeze/thaw filesystems and applications */
150 void qga_vss_fsfreeze(int *nr_volume
, bool freeze
,
151 strList
*mountpoints
, Error
**errp
)
153 const char *func_name
= freeze
? "requester_freeze" : "requester_thaw";
154 QGAVSSRequesterFunc func
;
156 .error_setg_win32_wrapper
= error_setg_win32_internal
,
160 g_assert(errp
); /* requester.cpp requires it */
161 func
= (QGAVSSRequesterFunc
)GetProcAddress(provider_lib
, func_name
);
163 error_setg_win32(errp
, GetLastError(), "failed to load %s from %s",
164 func_name
, QGA_VSS_DLL
);
168 func(nr_volume
, mountpoints
, &errset
);