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 "qemu/error-report.h"
16 #include "qga/guest-agent-core.h"
17 #include "qga/vss-win32.h"
18 #include "qga/vss-win32/requester.h"
20 #define QGA_VSS_DLL "qga-vss.dll"
22 static HMODULE provider_lib
;
24 /* Call a function in qga-vss.dll with the specified name */
25 static HRESULT
call_vss_provider_func(const char *func_name
)
29 g_assert(provider_lib
);
31 func
= GetProcAddress(provider_lib
, func_name
);
34 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
35 FORMAT_MESSAGE_FROM_SYSTEM
, NULL
, GetLastError(),
36 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
37 (char *)&msg
, 0, NULL
);
38 fprintf(stderr
, "failed to load %s from %s: %s",
39 func_name
, QGA_VSS_DLL
, msg
);
47 /* Check whether this OS version supports VSS providers */
48 static bool vss_check_os_version(void)
52 OSver
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
54 if ((OSver
.dwMajorVersion
== 5 && OSver
.dwMinorVersion
>= 2) ||
55 OSver
.dwMajorVersion
> 5) {
58 /* Provider doesn't work under WOW64 (32bit agent on 64bit OS) */
59 if (!IsWow64Process(GetCurrentProcess(), &wow64
)) {
60 fprintf(stderr
, "failed to IsWow64Process (Error: %lx\n)\n",
65 warn_report("Running under WOW64");
73 /* Load qga-vss.dll */
74 bool vss_init(bool init_requester
)
76 if (!vss_check_os_version()) {
77 /* Do nothing if OS doesn't support providers. */
78 fprintf(stderr
, "VSS provider is not supported in this OS version: "
79 "fsfreeze is disabled.\n");
83 provider_lib
= LoadLibraryA(QGA_VSS_DLL
);
86 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
87 FORMAT_MESSAGE_FROM_SYSTEM
, NULL
, GetLastError(),
88 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
89 (char *)&msg
, 0, NULL
);
90 fprintf(stderr
, "failed to load %s: %sfsfreeze is disabled\n",
97 HRESULT hr
= call_vss_provider_func("requester_init");
99 fprintf(stderr
, "fsfreeze is disabled.\n");
108 /* Unload qga-provider.dll */
109 void vss_deinit(bool deinit_requester
)
111 if (deinit_requester
) {
112 call_vss_provider_func("requester_deinit");
114 FreeLibrary(provider_lib
);
118 bool vss_initialized(void)
120 return !!provider_lib
;
123 int ga_install_vss_provider(void)
127 if (!vss_init(false)) {
128 fprintf(stderr
, "Installation of VSS provider is skipped. "
129 "fsfreeze will be disabled.\n");
132 hr
= call_vss_provider_func("COMRegister");
135 return SUCCEEDED(hr
) ? 0 : EXIT_FAILURE
;
138 void ga_uninstall_vss_provider(void)
140 if (!vss_init(false)) {
141 fprintf(stderr
, "Removal of VSS provider is skipped.\n");
144 call_vss_provider_func("COMUnregister");
148 /* Call VSS requester and freeze/thaw filesystems and applications */
149 void qga_vss_fsfreeze(int *nr_volume
, bool freeze
, Error
**errp
)
151 const char *func_name
= freeze
? "requester_freeze" : "requester_thaw";
152 QGAVSSRequesterFunc func
;
154 .error_setg_win32_wrapper
= error_setg_win32_internal
,
158 g_assert(errp
); /* requester.cpp requires it */
159 func
= (QGAVSSRequesterFunc
)GetProcAddress(provider_lib
, func_name
);
161 error_setg_win32(errp
, GetLastError(), "failed to load %s from %s",
162 func_name
, QGA_VSS_DLL
);
166 func(nr_volume
, &errset
);