Skip to contentSkip to conversation

qemu-ga: fsfreeze on Windows using VSS

RFC PATCH In review Tomoki Sekiyama 3 participants 15 messages Apr 12, 2013 – Apr 29, 2013 Kbuild

lore
Share & tools
lore
#0 lore raw

v2 cover qemu-ga: fsfreeze on Windows using VSS

Hi,

This patch series is attempts to add fsfreeze support for Windows qemu-guest-agent.

changes from v1:
- Fix out-tree build by stop using recursive Makefile
- Added script to extract VSS SDK headers on POSIX systems using msitools (thanks Paolo)
- Remove some unnecessary header files

v1: http://lists.gnu.org/archive/html/qemu-devel/2013-02/msg01963.html

* Description
In Windows, VSS (Volume Shadow Copy Service) provides a facility to quiesce filesystems and applications before disk snapshots are taken. This patch series implements "fsfreeze" command of qemu-ga using VSS.

* How to build & run qemu-ga with VSS support

- Download Microsoft VSS SDK from:
http://www.microsoft.com/en-us/download/details.aspx?id=23490

- Setup the SDK
scripts/extract-vsssdk-headers setup.exe (on POSIX-systems)

- Specify installed SDK directory to configure option as:
./configure -with-vss-sdk="path/to/VSS SDK" --cross-prefix=i686-w64-mingw32-

- Make qemu-ga.exe

- Install qemu-ga.exe and qga/vss-win32-provider/qga-provider.{dll,tlb} into the same directory in guests

- Run qemu-ga.exe -s install' and net start qemu-ga' in the guests

Any feedback are appliciated.

---
Tomoki Sekiyama (11):
configure: Support configuring c++ compiler
Fix errors and warnings while compiling with c++ compilier
Add a script to extract VSS SDK headers on POSIX system
qemu-ga: Add an configure option to specify path to Windows VSS SDK
qemu-ga: Add Windows VSS provider to quiesce applications on fsfreeze
qemu-ga: Add Windows VSS requester to quisce applications and filesystems
qemu-ga: call Windows VSS requester in fsfreeze command handler
qemu-ga: install Windows VSS provider on `qemu-ga -s install'
qemu-ga: Add VSS provider .tlb file in the repository QMP/qemu-ga-client: make timeout longer for guest-fsfreeze-freeze command QMP/qmp.py: set locale for exceptions to display non-ascii messages correctly

 .gitignore                              |    1 
 Makefile                                |    3 
 Makefile.objs                           |    2 
 QMP/qemu-ga-client                      |    4 
 QMP/qmp.py                              |    4 
 configure                               |   59 ++++
 hmp.c                                   |    2 
 hw/pci/pci.c                            |    2 
 qga/Makefile.objs                       |    7 
 qga/commands-win32.c                    |   74 ++++-
 qga/main.c                              |   41 +++
 qga/vss-win32-provider.h                |   26 ++
 qga/vss-win32-provider/Makefile.objs    |   25 ++
 qga/vss-win32-provider/install.cpp      |  494 +++++++++++++++++++++++++++++++
 qga/vss-win32-provider/provider.cpp     |  474 ++++++++++++++++++++++++++++++
 qga/vss-win32-provider/qga-provider.def |   10 +
 qga/vss-win32-provider/qga-provider.idl |   20 +
 qga/vss-win32-provider/qga-provider.tlb |  Bin
 qga/vss-win32-requester.cpp             |  393 +++++++++++++++++++++++++
 qga/vss-win32-requester.h               |   31 ++
 qga/vss-win32.h                         |   85 +++++
 rules.mak                               |    9 +
 scripts/extract-vsssdk-headers          |   25 ++
 scripts/qapi.py                         |    9 +
 24 files changed, 1785 insertions(+), 15 deletions(-)
 create mode 100644 qga/vss-win32-provider.h
 create mode 100644 qga/vss-win32-provider/Makefile.objs
 create mode 100644 qga/vss-win32-provider/install.cpp
 create mode 100644 qga/vss-win32-provider/provider.cpp
 create mode 100644 qga/vss-win32-provider/qga-provider.def
 create mode 100644 qga/vss-win32-provider/qga-provider.idl
 create mode 100644 qga/vss-win32-provider/qga-provider.tlb
 create mode 100644 qga/vss-win32-requester.cpp
 create mode 100644 qga/vss-win32-requester.h
 create mode 100644 qga/vss-win32.h
 create mode 100755 scripts/extract-vsssdk-headers
#1 lore raw

RFC PATCH v2 1/11 configure: Support configuring c++ compiler

Add configuration for c++ compiler (${corss_prefix}g++ as default) in configure and Makefiles.

Currently, usage of c++ language is only for access to Windows VSS using COM+ services in qemu-guest-agent for Windows.

---
 configure |    6 ++++++
 rules.mak |    9 ++++++++-
 2 files changed, 14 insertions(+), 1 deletion(-)
configure +6 -0
index 1ed939a..b74572f 100755
@@ -278,6 +278,7 @@ else
   cc="${CC-${cross_prefix}gcc}"
 fi
 
+cxx="${CXX-${cross_prefix}g++}"
 ar="${AR-${cross_prefix}ar}"
 as="${AS-${cross_prefix}as}"
 cpp="${CPP-$cc -E}"
@@ -615,6 +616,8 @@ for opt do
   ;;
   --host-cc=*) host_cc="$optarg"
   ;;
+  --cxx=*) cxx="$optarg"
+  ;;
   --objcc=*) objcc="$optarg"
   ;;
   --make=*) make="$optarg"
@@ -1053,6 +1056,7 @@ echo "  --cross-prefix=PREFIX    use PREFIX for compile tools [$cross_prefix]"
 echo "  --cc=CC                  use C compiler CC [$cc]"
 echo "  --host-cc=CC             use C compiler CC [$host_cc] for code run at"
 echo "                           build time"
+echo "  --cxx=CXX                use C++ compiler CXX [$cxx]"
 echo "  --objcc=OBJCC            use Objective-C compiler OBJCC [$objcc]"
 echo "  --extra-cflags=CFLAGS    append extra C compiler flags QEMU_CFLAGS"
 echo "  --extra-ldflags=LDFLAGS  append extra linker flags LDFLAGS"
@@ -3349,6 +3353,7 @@ fi
 echo "Source path       $source_path"
 echo "C compiler        $cc"
 echo "Host C compiler   $host_cc"
+echo "C++ compiler      $cxx"
 echo "Objective-C compiler $objcc"
 echo "CFLAGS            $CFLAGS"
 echo "QEMU_CFLAGS       $QEMU_CFLAGS"
@@ -3860,6 +3865,7 @@ echo "PYTHON=$python" >> $config_host_mak
 echo "CC=$cc" >> $config_host_mak
 echo "CC_I386=$cc_i386" >> $config_host_mak
 echo "HOST_CC=$host_cc" >> $config_host_mak
+echo "CXX=$cxx" >> $config_host_mak
 echo "OBJCC=$objcc" >> $config_host_mak
 echo "AR=$ar" >> $config_host_mak
 echo "AS=$as" >> $config_host_mak
rules.mak +8 -1
index edc2552..9dfd23a 100644
@@ -8,9 +8,13 @@ MAKEFLAGS += -rR
 %.d:
 %.h:
 %.c:
+%.cpp:
 %.m:
 %.mak:
 
+# Flags for C++ compilation
+QEMU_CXXFLAGS = -D__STDC_LIMIT_MACROS $(filter-out -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Wold-style-declaration -Wold-style-definition -Wredundant-decls, $(QEMU_CFLAGS))
+
 # Flags for dependency generation
 QEMU_DGFLAGS += -MMD -MP -MT $@ -MF $(*D)/$(*F).d
 
@@ -45,6 +49,9 @@ endif
 %.o: %.asm
 	$(call quiet-command,$(AS) $(ASFLAGS) -o $@ $<,"  AS    $(TARGET_DIR)$@")
 
+%.o: %.cpp
+	$(call quiet-command,$(CXX) $(QEMU_INCLUDES) $(QEMU_CXXFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<,"  CXX   $(TARGET_DIR)$@")
+
 %.o: %.m
 	$(call quiet-command,$(OBJCC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<,"  OBJC  $(TARGET_DIR)$@")
 
@@ -65,7 +72,7 @@ quiet-command = $(if $(V),$1,$(if $(2),@echo $2 && $1, @$1))
 cc-option = $(if $(shell $(CC) $1 $2 -S -o /dev/null -xc /dev/null \
               >/dev/null 2>&1 && echo OK), $2, $3)
 
-VPATH_SUFFIXES = %.c %.h %.S %.m %.mak %.texi %.sh
+VPATH_SUFFIXES = %.c %.h %.S %.cpp %.m %.mak %.texi %.sh
 set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath $(PATTERN) $1)))
 
 # find-in-path
#2 lore raw

RFC PATCH v2 2/11 Fix errors and warnings while compiling with c++ compilier

In reply to Tomoki Sekiyama

Add C++ keywords to avoid errors in compiling with c++ compiler. This also renames class member of PciDeviceInfo to q_class.

---
 hmp.c           |    2 +-
 hw/pci/pci.c    |    2 +-
 scripts/qapi.py |    9 ++++++++-
 3 files changed, 10 insertions(+), 3 deletions(-)
hmp.c +1 -1
index dbe9b90..9fa89a4 100644
@@ -484,7 +484,7 @@ static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
     if (dev->class_info.has_desc) {
         monitor_printf(mon, "%s", dev->class_info.desc);
     } else {
-        monitor_printf(mon, "Class %04" PRId64, dev->class_info.class);
+        monitor_printf(mon, "Class %04" PRId64, dev->class_info.q_class);
     }
 
     monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
hw/pci/pci.c +1 -1
index d5257ed..a3eaf47 100644
@@ -1460,7 +1460,7 @@ static PciDeviceInfo *qmp_query_pci_device(PCIDevice *dev, PCIBus *bus,
     info->function = PCI_FUNC(dev->devfn);
 
     class = pci_get_word(dev->config + PCI_CLASS_DEVICE);
-    info->class_info.class = class;
+    info->class_info.q_class = class;
     desc = get_class_desc(class);
     if (desc->desc) {
         info->class_info.has_desc = true;
scripts/qapi.py +8 -1
index afc5f32..b174acb 100644
@@ -156,9 +156,16 @@ def c_var(name, protect=True):
     # GCC http://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/C-Extensions.html
     # excluding _.*
     gcc_words = set(['asm', 'typeof'])
+    # C++ ISO/IEC 14882:2003 2.11
+    cpp_words = set(['bool', 'catch', 'class', 'const_cast', 'delete',
+                     'dynamic_cast', 'explicit', 'false', 'friend', 'mutable',
+                     'namespace', 'new', 'operator', 'private', 'protected',
+                     'public', 'reinterpret_cast', 'static_cast', 'template',
+                     'this', 'throw', 'true', 'try', 'typeid', 'typename',
+                     'using', 'virtual', 'wchar_t'])
     # namespace pollution:
     polluted_words = set(['unix'])
-    if protect and (name in c89_words | c99_words | c11_words | gcc_words | polluted_words):
+    if protect and (name in c89_words | c99_words | c11_words | gcc_words | cpp_words | polluted_words):
         return "q_" + name
     return name.replace('-', '_').lstrip("*")
 
#3 lore raw

RFC PATCH v2 3/11 Add a script to extract VSS SDK headers on POSIX system

In reply to Tomoki Sekiyama

VSS SDK(*) setup.exe is only runnable on Windows. This adds a script to extract VSS SDK headers on POSIX-systems using msitools.

* http://www.microsoft.com/en-us/download/details.aspx?id=23490

From: Paolo Bonzini <[email protected]>

---
 scripts/extract-vsssdk-headers |   25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100755 scripts/extract-vsssdk-headers
scripts/extract-vsssdk-headers new file +25 -0
new file mode 100755
index 0000000..5877137
@@ -0,0 +1,25 @@
+#! /bin/bash
+
+# extract-vsssdk-headers
+# Author: Paolo Bonzini <[email protected]>
+
+set -e
+if test $# = 0 || ! test -f "$1"; then
+  echo 'Usage: extract-vsssdk-headers /path/to/setup.exe'
+  exit 1
+fi
+
+# Extract .MSI file in the .exe, looking for the OLE compound
+# document signature.  Extra data at the end does not matter.
+export LC_ALL=C
+MAGIC=$'\xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1'
+offset=`grep -abom1 "$MAGIC" "$1" | sed -n 's/:/\n/; P' `
+(dd of=/dev/null skip=$offset bs=1 count=0; cat) < "$1" > vsssdk.msi
+
+# Now extract the files.
+tmpdir=tmp$$
+mkdir $tmpdir
+msiextract -C $tmpdir vsssdk.msi
+mv "$tmpdir/Program Files/Microsoft/VSSSDK72/inc" inc
+rm -rf $tmpdir vsssdk.msi
+exit 0
#4 lore raw

RFC PATCH v2 4/11 qemu-ga: Add an configure option to specify path to Windows VSS SDK

In reply to Tomoki Sekiyama

To enable VSS support in qemu-ga for Windows, header files included in VSS SDK is required.
The VSS support is enabled when the option like below:
./configure --with-vss-sdk="/pass/to/VSS SDK"

VSS SDK is available from:
http://www.microsoft.com/en-us/download/details.aspx?id=23490

To cross-compilie using mingw32 for Linux, you need to setup the SDK on Windows environments to extract headers. You can also extract the SDK headers using scripts/extract-vss-headers, written by Paolo Bonzini.

---
 .gitignore |    1 +
 Makefile   |    1 +
 configure  |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 50 insertions(+)
.gitignore +1 -0
index 487813a..b98e851 100644
@@ -79,6 +79,7 @@ fsdev/virtfs-proxy-helper.pod
 *.la
 *.pc
 .libs
+.sdk
 *.swp
 *.orig
 .pc
Makefile +1 -0
index 0b6e6a1..8d4506f 100644
@@ -261,6 +261,7 @@ distclean: clean
 	for d in $(TARGET_DIRS); do \
 	rm -rf $$d || exit 1 ; \
         done
+	rm -Rf .sdk
 	if test -f pixman/config.log; then make -C pixman distclean; fi
 
 KEYMAPS=da     en-gb  et  fr     fr-ch  is  lt  modifiers  no  pt-br  sv \
configure +48 -0

84 lines not on this page · raw message

#5 lore raw

RFC PATCH v2 5/11 qemu-ga: Add Windows VSS provider to quiesce applications on fsfreeze

In reply to Tomoki Sekiyama

Implements a basic stub of software VSS provider. Currently, this modules only provides a relay function of events between qemu-guest-agent and Windows VSS when VSS finished filesystem freeze and when qemu snapshot is done.

In the future, this module could be extended to support the other VSS functions, such as query for snapshot volumes and recovery.

---
 Makefile.objs                           |    2 
 configure                               |    5 
 qga/Makefile.objs                       |    6 
 qga/vss-win32-provider.h                |   26 ++
 qga/vss-win32-provider/Makefile.objs    |   21 +
 qga/vss-win32-provider/install.cpp      |  494 +++++++++++++++++++++++++++++++
 qga/vss-win32-provider/provider.cpp     |  474 ++++++++++++++++++++++++++++++
 qga/vss-win32-provider/qga-provider.def |   10 +
 qga/vss-win32-provider/qga-provider.idl |   20 +
 qga/vss-win32.h                         |   85 +++++
 10 files changed, 1142 insertions(+), 1 deletion(-)
 create mode 100644 qga/vss-win32-provider.h
 create mode 100644 qga/vss-win32-provider/Makefile.objs
 create mode 100644 qga/vss-win32-provider/install.cpp
 create mode 100644 qga/vss-win32-provider/provider.cpp
 create mode 100644 qga/vss-win32-provider/qga-provider.def
 create mode 100644 qga/vss-win32-provider/qga-provider.idl
 create mode 100644 qga/vss-win32.h
Makefile.objs +2 -0
index e568c01..15264a1 100644
@@ -96,6 +96,7 @@ common-obj-y += disas/
 # 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-prv-obj-y = qga/
 
 vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
 
@@ -107,6 +108,7 @@ nested-vars += \
 	stub-obj-y \
 	util-obj-y \
 	qga-obj-y \
+	qga-prv-obj-y \
 	block-obj-y \
 	common-obj-y
 dummy := $(call unnest-vars)
configure +4 -1
index 310bf9f..ebc4114 100755
@@ -3360,9 +3360,12 @@ if test "$softmmu" = yes ; then
       virtfs=no
     fi
   fi
-  if [ "$linux" = "yes" -o "$bsd" = "yes" -o "$solaris" = "yes" ] ; then
+  if [ "$linux" = "yes" -o "$bsd" = "yes" -o "$solaris" = "yes" -o "$mingw32" = "yes" ] ; then
     if [ "$guest_agent" = "yes" ]; then
       tools="qemu-ga\$(EXESUF) $tools"
+      if [ "$mingw32" = "yes" ]; then
+        tools="qga/vss-win32-provider/qga-provider.dll qga/vss-win32-provider/qga-provider.tlb $tools"
+      fi
     fi
   fi
 fi
qga/Makefile.objs +6 -0
index b8d7cd0..8d93866 100644
@@ -3,3 +3,9 @@ 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
+
+ifeq ($(CONFIG_QGA_VSS),y)
+QEMU_CFLAGS += -DHAS_VSS_SDK
+qga-obj-y += vss-win32-provider/
+qga-prv-obj-y += vss-win32-provider/
+endif
qga/vss-win32-provider.h new file +26 -0
new file mode 100644
index 0000000..a437e71
@@ -0,0 +1,26 @@
+/*
+ * QEMU Guest Agent win32 VSS provider declarations
+ *
+ * Copyright Hitachi Data Systems Corp. 2013
+ *
+ * Authors:
+ *  Tomoki Sekiyama   <[email protected]>
+ *
+ * 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_PROVIDER_H
+#define VSS_WIN32_PROVIDER_H
+
+#include <windows.h>
+
+STDAPI VSSCheckOSVersion(void);
+
+STDAPI COMRegister(void);
+STDAPI COMUnregister(void);
+
+STDAPI DllRegisterServer(void);
+STDAPI DllUnregisterServer(void);
+
+#endif
qga/vss-win32-provider/Makefile.objs new file +21 -0
new file mode 100644
index 0000000..73ef752
@@ -0,0 +1,21 @@
+# rules to build qga-provider.dll
+
+qga-obj-y += qga-provider.dll
+qga-prv-obj-y += provider.o install.o
+
+obj-qga-prv-obj-y = $(addprefix $(obj)/, $(qga-prv-obj-y))
+$(obj-qga-prv-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-provider.dll: LDFLAGS = -shared -Wl,--add-stdcall-alias,--enable-stdcall-fixup -lole32 -loleaut32 -lshlwapi -luuid -static
+$(obj)/qga-provider.dll: $(obj-qga-prv-obj-y) $(SRC_PATH)/$(obj)/qga-provider.def $(obj)/qga-provider.tlb
+	$(call quiet-command,$(CXX) -o $@ $(qga-prv-obj-y) $(SRC_PATH)/qga/vss-win32-provider/qga-provider.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 (included in VC++).
+MIDL=midl
+WINSDK="C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\Include"
+
+$(obj)/qga-provider.tlb: $(SRC_PATH)/$(obj)/qga-provider.idl
+	$(call quiet-command,$(MIDL) -m64 -o $@ -I $(WINSDK) $<,"  MIDL  $(TARGET_DIR)$@")
qga/vss-win32-provider/install.cpp new file +494 -0

494 lines not on this page · raw message

qga/vss-win32-provider/provider.cpp new file +474 -0

474 lines not on this page · raw message

qga/vss-win32-provider/qga-provider.def new file +10 -0
new file mode 100644
index 0000000..9f3afc8
@@ -0,0 +1,10 @@
+LIBRARY      "QGA-PROVIDER.DLL"
+
+EXPORTS
+	VSSCheckOSVersion	PRIVATE
+	COMRegister		PRIVATE
+	COMUnregister		PRIVATE
+	DllCanUnloadNow		PRIVATE
+	DllGetClassObject	PRIVATE
+	DllRegisterServer	PRIVATE
+	DllUnregisterServer	PRIVATE
qga/vss-win32-provider/qga-provider.idl new file +20 -0
new file mode 100644
index 0000000..17abca0
@@ -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;
+    };
+};
qga/vss-win32.h new file +85 -0

85 lines not on this page · raw message

#6 lore raw

RFC PATCH v2 6/11 qemu-ga: Add Windows VSS requester to quisce applications and filesystems

In reply to Tomoki Sekiyama

This adds VSS requester functions for to qemu-ga.
This provides facility to request VSS service in Windows guest to quisce applications and filesystems.
This function is only supported in Windows 2003 or later. In older guests, this function does nothing.

---
 qga/Makefile.objs           |    3 
 qga/vss-win32-requester.cpp |  393 +++++++++++++++++++++++++++++++++++++++++++
 qga/vss-win32-requester.h   |   31 +++
 3 files changed, 426 insertions(+), 1 deletion(-)
 create mode 100644 qga/vss-win32-requester.cpp
 create mode 100644 qga/vss-win32-requester.h
qga/Makefile.objs +2 -1
index 8d93866..f17a380 100644
@@ -6,6 +6,7 @@ qga-obj-y += qapi-generated/qga-qmp-marshal.o
 
 ifeq ($(CONFIG_QGA_VSS),y)
 QEMU_CFLAGS += -DHAS_VSS_SDK
-qga-obj-y += vss-win32-provider/
+qga-obj-y += vss-win32-provider/ vss-win32-requester.o
 qga-prv-obj-y += vss-win32-provider/
+$(obj)/vss-win32-requester.o: QEMU_CXXFLAGS += -Wno-unknown-pragmas
 endif
qga/vss-win32-requester.cpp new file +393 -0

393 lines not on this page · raw message

qga/vss-win32-requester.h new file +31 -0
new file mode 100644
index 0000000..f180f56
@@ -0,0 +1,31 @@
+/*
+ * QEMU Guest Agent VSS Requester declarations
+ *
+ * Copyright Hitachi Data Systems Corp. 2013
+ *
+ * Authors:
+ *  Tomoki Sekiyama   <[email protected]>
+ *
+ * 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
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+HRESULT vss_init(void);
+void vss_deinit(void);
+int vss_initialized(void);
+
+void qga_vss_fsfreeze_freeze(int *nr_volume, struct Error **err);
+void qga_vss_fsfreeze_thaw(int *nr_volume, struct Error **err);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
#7 lore raw

RFC PATCH v2 7/11 qemu-ga: call Windows VSS requester in fsfreeze command handler

In reply to Tomoki Sekiyama

Support guest-fsfreeze-freeze and guest-fsfreeze-thaw commands for Windows guests. When fsfreeze command is issued, it calls the VSS requester to freeze filesystems and applications. On thaw command, it again tells the VSS requester to thaw them.

This also adds calling of initialize functions for the VSS requester.

---
 qga/commands-win32.c |   74 ++++++++++++++++++++++++++++++++++++++++++++++----
 qga/main.c           |   33 ++++++++++++++++++++++
 2 files changed, 100 insertions(+), 7 deletions(-)
qga/commands-win32.c +68 -6
index 24e4ad0..67dca60 100644
@@ -15,6 +15,7 @@
 #include <wtypes.h>
 #include <powrprof.h>
 #include "qga/guest-agent-core.h"
+#include "qga/vss-win32-requester.h"
 #include "qga-qmp-commands.h"
 #include "qapi/qmp/qerror.h"
 
@@ -151,34 +152,95 @@ void qmp_guest_file_flush(int64_t handle, Error **err)
     error_set(err, QERR_UNSUPPORTED);
 }
 
+#ifdef HAS_VSS_SDK
+
 /*
  * Return status of freeze/thaw
  */
 GuestFsfreezeStatus qmp_guest_fsfreeze_status(Error **err)
 {
-    error_set(err, QERR_UNSUPPORTED);
-    return 0;
+    if (!vss_initialized()) {
+        error_set(err, QERR_UNSUPPORTED);
+        return 0;
+    }
+
+    if (ga_is_frozen(ga_state)) {
+        return GUEST_FSFREEZE_STATUS_FROZEN;
+    }
+
+    return GUEST_FSFREEZE_STATUS_THAWED;
 }
 
 /*
- * Walk list of mounted file systems in the guest, and freeze the ones which
- * are real local file systems.
+ * Freeze local file systems using Volume Shadow-copy Service.
+ * The frozen state is limited for up to 10 seconds by VSS.
  */
 int64_t qmp_guest_fsfreeze_freeze(Error **err)
 {
-    error_set(err, QERR_UNSUPPORTED);
+    int i;
+
+    slog("guest-fsfreeze called");
+
+    if (!vss_initialized()) {
+        error_set(err, QERR_UNSUPPORTED);
+        return 0;
+    }
+
+    /* cannot risk guest agent blocking itself on a write in this state */
+    ga_set_frozen(ga_state);
+
+    qga_vss_fsfreeze_freeze(&i, err);
+    if (error_is_set(err)) {
+        goto error;
+    }
+
+    return i;
+
+error:
+    qmp_guest_fsfreeze_thaw(NULL);
     return 0;
 }
 
 /*
- * Walk list of frozen file systems in the guest, and thaw them.
+ * Thaw local file systems using Volume Shadow-copy Service.
  */
 int64_t qmp_guest_fsfreeze_thaw(Error **err)
 {
+    int i;
+
+    if (!vss_initialized()) {
+        error_set(err, QERR_UNSUPPORTED);
+        return 0;
+    }
+
+    qga_vss_fsfreeze_thaw(&i, err);
+
+    ga_unset_frozen(ga_state);
+    return i;
+}
+
+#else
+
+GuestFsfreezeStatus qmp_guest_fsfreeze_status(Error **err)
+{
+    error_set(err, QERR_UNSUPPORTED);
+    return 0;
+}
+
+int64_t qmp_guest_fsfreeze_freeze(Error **err)
+{
+    error_set(err, QERR_UNSUPPORTED);
+    return 0;
+}
+
+int64_t qmp_guest_fsfreeze_thaw(Error **err)
+{
     error_set(err, QERR_UNSUPPORTED);
     return 0;
 }
 
+#endif
+
 /*
  * Walk list of mounted file systems in the guest, and discard unused
  * areas.
qga/main.c +32 -1
index 1841759..92230e9 100644
@@ -34,6 +34,10 @@
 #include "qemu/bswap.h"
 #ifdef _WIN32
 #include "qga/service-win32.h"
+#ifdef HAS_VSS_SDK
+#include "qga/vss-win32-provider.h"
+#include "qga/vss-win32-requester.h"
+#endif
 #include <windows.h>
 #endif
 #ifdef __linux__
@@ -685,6 +689,25 @@ static gboolean channel_init(GAState *s, const gchar *method, const gchar *path)
 }
 
 #ifdef _WIN32
+
+static gboolean vss_win32_init(void)
+{
+#ifdef HAS_VSS_SDK
+    if (FAILED(vss_init())) {
+        g_critical("failed to initialize VSS");
+        return false;
+    }
+#endif
+    return true;
+}
+
+static void vss_win32_deinit(void)
+{
+#ifdef HAS_VSS_SDK
+    vss_deinit();
+#endif
+}
+
 DWORD WINAPI service_ctrl_handler(DWORD ctrl, DWORD type, LPVOID data,
                                   LPVOID ctx)
 {
@@ -727,8 +750,12 @@ VOID WINAPI service_main(DWORD argc, TCHAR *argv[])
     service->status.dwWaitHint = 0;
     SetServiceStatus(service->status_handle, &service->status);
 
+    if (!vss_win32_init()) {
+        goto out_bad;
+    }
     g_main_loop_run(ga_state->main_loop);
-
+    vss_win32_deinit();
+out_bad:
     service->status.dwCurrentState = SERVICE_STOPPED;
     SetServiceStatus(service->status_handle, &service->status);
 }
@@ -1132,7 +1159,11 @@ int main(int argc, char **argv)
             { (char *)QGA_SERVICE_NAME, service_main }, { NULL, NULL } };
         StartServiceCtrlDispatcher(service_table);
     } else {
+        if (!vss_win32_init()) {
+            goto out_bad;
+        }
         g_main_loop_run(ga_state->main_loop);
+        vss_win32_deinit();
     }
 #endif
 
#8 lore raw

RFC PATCH v2 8/11 qemu-ga: install Windows VSS provider on `qemu-ga -s install'

In reply to Tomoki Sekiyama

Register QGA VSS provider library into Windows when qemu-ga is installed as Windows service ('-s install' option). It is deregistered when the service is uninstalled ('-s uninstall' option).

---
 qga/main.c |    8 ++++++++
 1 file changed, 8 insertions(+)
qga/main.c +8 -0
index 92230e9..09fa291 100644
@@ -1029,8 +1029,16 @@ int main(int argc, char **argv)
         case 's':
             service = optarg;
             if (strcmp(service, "install") == 0) {
+#ifdef HAS_VSS_SDK
+                if (FAILED(COMRegister())) {
+                    return EXIT_FAILURE;
+                }
+#endif
                 return ga_install_service(path, log_filepath);
             } else if (strcmp(service, "uninstall") == 0) {
+#ifdef HAS_VSS_SDK
+                COMUnregister();
+#endif
                 return ga_uninstall_service();
             } else {
                 printf("Unknown service command.\n");
#9 lore raw

RFC PATCH v2 9/11 qemu-ga: Add VSS provider .tlb file in the repository

In reply to Tomoki Sekiyama

To build type library (.tlb) for qga-provider.dll from COM IDL (.idl), MIDL in VisualC++ and stdole2.tlb in Windows SDK are required.

This patch adds pre-compiled .tlb file in the repository in order to enable cross-compile qemu-ga.exe for Windows with VSS support.

---
 Makefile                                |    2 +-
 qga/vss-win32-provider/Makefile.objs    |    4 ++++
 qga/vss-win32-provider/qga-provider.tlb |  Bin
 3 files changed, 5 insertions(+), 1 deletion(-)
 create mode 100644 qga/vss-win32-provider/qga-provider.tlb
Makefile +1 -1
index 8d4506f..c938aec 100644
@@ -224,7 +224,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
qga/vss-win32-provider/Makefile.objs +4 -0
index 73ef752..698359b 100644
@@ -18,4 +18,8 @@ MIDL=midl
 WINSDK="C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\Include"
 
 $(obj)/qga-provider.tlb: $(SRC_PATH)/$(obj)/qga-provider.idl
+ifeq ($(wildcard $(SRC_PATH)/$(obj)/qga-provider.tlb),)
 	$(call quiet-command,$(MIDL) -m64 -o $@ -I $(WINSDK) $<,"  MIDL  $(TARGET_DIR)$@")
+else
+	$(call quiet-command,cp $(dir $<)qga-provider.tlb $@, "  COPY  $(TARGET_DIR)$@")
+endif
qga/vss-win32-provider/qga-provider.tlb new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..226452a1861371ffe0cad1019cf90fdfdcd5ef49
GIT binary patch
#10 lore raw

RFC PATCH v2 10/11 QMP/qemu-ga-client: make timeout longer for guest-fsfreeze-freeze command

In reply to Tomoki Sekiyama

guest-fsfreeze-freeze command can take longer than 3 seconds when heavy disk I/O is running. To avoid unexpected timeout, this changes the timeout to 30 seconds.

---
 QMP/qemu-ga-client |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
QMP/qemu-ga-client +3 -1
index 46676c3..1f7011a 100755
@@ -267,7 +267,9 @@ def main(address, cmd, args):
             print('Hint: qemu is not running?')
         sys.exit(1)
 
-    if cmd != 'ping':
+    if cmd == 'fsfreeze' and args[0] == 'freeze':
+        client.sync(30)
+    elif cmd != 'ping':
         client.sync()
 
     globals()['_cmd_' + cmd](client, args)
#11 lore raw

RFC PATCH v2 11/11 QMP/qmp.py: set locale for exceptions to display non-ascii messages correctly

In reply to Tomoki Sekiyama

qemu-ga in Windows might return error message with multibyte characters when the guest OS language is set to other than English. To display such messages correctly, this decodes the message based on locale settings.

---
 QMP/qmp.py |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
QMP/qmp.py +3 -1
index c551df1..ee21819 100644
@@ -11,6 +11,7 @@
 import json
 import errno
 import socket
+import locale
 
 class QMPError(Exception):
     pass
@@ -133,7 +134,8 @@ class QEMUMonitorProtocol:
     def command(self, cmd, **kwds):
         ret = self.cmd(cmd, kwds)
         if ret.has_key('error'):
-            raise Exception(ret['error']['desc'])
+            enc = locale.getpreferredencoding()
+            raise Exception(ret['error']['desc'].encode(enc))
         return ret['return']
 
     def pull_event(self, wait=False):
#12 lore raw
In reply to Tomoki Sekiyama

Hi,
I tried the patch v2,with the following config.

Guest os : win7 32bit professional
Host os : fedora 17
Command:
qemu-kvm -enable-kvm -name win7 -M pc-0.15 -m 1024 -smp 2 -boot c -device virtio-serial -drive file=/home/libaiqing/vss/win7.img,if=virtio,index=0,format=qcow2 - -monitor stdio -vga qxl -vnc :1 -chardev socket,id=charchannel0,path=/var/lib/libvirt/qemu/wahaha1_requester,server,nowait -device virtserialport,chardev=charchannel0,id=channel0,name=org.qemu.guest_agent.1

Issue:
1 Extcuting the command "net start qemu-ga" failed,but the command "qemu-qa.exe -m virtio-serial -p \\.\Global\org.qemu.guest_agent.1" is ok. 2 executing the command "{"execute":"guest-fsfreeze-freeze"}" failed,the output is:

[root@fedora121 ~]# socat stdio,ignoreeof unix-connect:/var/lib/libvirt/qemu/wahaha1_requester
{'execute':'guest-info'}
{"return": {"version": "1.4.50", "supported_commands": [{"enabled": true, "name": "guest-set-vcpus"}, {"enabled": true, "name": "guest-get-vcpus"}, {"enabled": true, "name": "guest-network-get-interfaces"}, {"enabled": true, "name": "guest-suspend-hybrid"}, {"enabled": true, "name": "guest-suspend-ram"}, {"enabled": true, "name": "guest-suspend-disk"}, {"enabled": true, "name": "guest-fstrim"}, {"enabled": true, "name": "guest-fsfreeze-thaw"}, {"enabled": true, "name": "guest-fsfreeze-freeze"}, {"enabled": true, "name": "guest-fsfreeze-status"}, {"enabled": true, "name": "guest-file-flush"}, {"enabled": true, "name": "guest-file-seek"}, {"enabled": true, "name": "guest-file-write"}, {"enabled": true, "name": "guest-file-read"}, {"enabled": true, "name": "guest-file-close"}, {"enabled": true, "name": "guest-file-open"}, {"enabled": true, "name": "guest-shutdown"}, {"enabled": true, "name": "guest-info"}, {"enabled": true, "name": "guest-set-time"}, {"enabled": true, "name": "guest-get-time"}, {"enabled": true, "name": "guest-ping"}, {"enabled": true, "name": "guest-sync"}, {"enabled": true, "name": "guest-sync-delimited"}]}} {"execute":"guest-fsfreeze-status"}
{"return": "thawed"}
{"execute":"guest-fsfreeze-freeze"}
{"error": {"class": "GenericError", "desc": "Failed to pVssbc->SetContext. (Error: 8004231b) "}}

Could you give me some advise to debug this problem ? I can provide more information if need.

Regards,
baiqing
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Tomoki Sekiyama
Sent: Saturday, April 13, 2013 4:02 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: [Qemu-devel] [RFC PATCH v2 00/11] qemu-ga: fsfreeze on Windows using VSS

Hi,

This patch series is attempts to add fsfreeze support for Windows qemu-guest-agent.

changes from v1:
- Fix out-tree build by stop using recursive Makefile
- Added script to extract VSS SDK headers on POSIX systems using msitools (thanks Paolo)
- Remove some unnecessary header files

v1: http://lists.gnu.org/archive/html/qemu-devel/2013-02/msg01963.html

* Description
In Windows, VSS (Volume Shadow Copy Service) provides a facility to quiesce filesystems and applications before disk snapshots are taken. This patch series implements "fsfreeze" command of qemu-ga using VSS.

* How to build & run qemu-ga with VSS support

- Download Microsoft VSS SDK from:
http://www.microsoft.com/en-us/download/details.aspx?id=23490

- Setup the SDK
scripts/extract-vsssdk-headers setup.exe (on POSIX-systems)

- Specify installed SDK directory to configure option as:
./configure -with-vss-sdk="path/to/VSS SDK" --cross-prefix=i686-w64-mingw32-

- Make qemu-ga.exe

- Install qemu-ga.exe and qga/vss-win32-provider/qga-provider.{dll,tlb} into the same directory in guests

- Run qemu-ga.exe -s install' and net start qemu-ga' in the guests

Any feedback are appliciated.

---
Tomoki Sekiyama (11):
configure: Support configuring c++ compiler
Fix errors and warnings while compiling with c++ compilier
Add a script to extract VSS SDK headers on POSIX system
qemu-ga: Add an configure option to specify path to Windows VSS SDK
qemu-ga: Add Windows VSS provider to quiesce applications on fsfreeze
qemu-ga: Add Windows VSS requester to quisce applications and filesystems
qemu-ga: call Windows VSS requester in fsfreeze command handler
qemu-ga: install Windows VSS provider on `qemu-ga -s install'
qemu-ga: Add VSS provider .tlb file in the repository QMP/qemu-ga-client: make timeout longer for guest-fsfreeze-freeze command QMP/qmp.py: set locale for exceptions to display non-ascii messages correctly

 .gitignore                              |    1 
 Makefile                                |    3 
 Makefile.objs                           |    2 
 QMP/qemu-ga-client                      |    4 
 QMP/qmp.py                              |    4 
 configure                               |   59 ++++
 hmp.c                                   |    2 
 hw/pci/pci.c                            |    2 
 qga/Makefile.objs                       |    7 
 qga/commands-win32.c                    |   74 ++++-
 qga/main.c                              |   41 +++
 qga/vss-win32-provider.h                |   26 ++
 qga/vss-win32-provider/Makefile.objs    |   25 ++
 qga/vss-win32-provider/install.cpp      |  494 +++++++++++++++++++++++++++++++
 qga/vss-win32-provider/provider.cpp     |  474 ++++++++++++++++++++++++++++++
 qga/vss-win32-provider/qga-provider.def |   10 +
 qga/vss-win32-provider/qga-provider.idl |   20 +
 qga/vss-win32-provider/qga-provider.tlb |  Bin
 qga/vss-win32-requester.cpp             |  393 +++++++++++++++++++++++++
 qga/vss-win32-requester.h               |   31 ++
 qga/vss-win32.h                         |   85 +++++
 rules.mak                               |    9 +
 scripts/extract-vsssdk-headers          |   25 ++
 scripts/qapi.py                         |    9 +
 24 files changed, 1785 insertions(+), 15 deletions(-)
 create mode 100644 qga/vss-win32-provider.h
 create mode 100644 qga/vss-win32-provider/Makefile.objs
 create mode 100644 qga/vss-win32-provider/install.cpp
 create mode 100644 qga/vss-win32-provider/provider.cpp
 create mode 100644 qga/vss-win32-provider/qga-provider.def
 create mode 100644 qga/vss-win32-provider/qga-provider.idl
 create mode 100644 qga/vss-win32-provider/qga-provider.tlb
 create mode 100644 qga/vss-win32-requester.cpp
 create mode 100644 qga/vss-win32-requester.h
 create mode 100644 qga/vss-win32.h
 create mode 100755 scripts/extract-vsssdk-headers
#13 lore raw

Hi Baiqing,

Thank you for your testing.

Quoted 2 lines

1 Extcuting the command "net start qemu-ga" failed,but the command
"qemu-qa.exe -m virtio-serial -p \\.\Global\org.qemu.guest_agent.1" is ok.

`qemu-ga.exe -s install -p \\.\Global\org.qemu.guest_agent.1' may help to use virtio-serial ".1" in qemu-ga service. Otherwise ".0" is used by default.

Quoted 2 lines

2 executing the command "{"execute":"guest-fsfreeze-freeze"}"
failed,the output is:

<snip>

Quoted 6 lines

{"execute":"guest-fsfreeze-freeze"}
{"error": {"class": "GenericError", "desc": "Failed to pVssbc->SetContext. (Error: 8004231b) "}}

Could you give me some advise to debug this problem ? I can provide more information if need.

Is there any logs corresponding to the error in Event Viewer?

And this might be caused by unsupported VSS_VOLSNAP_ATTR_* flags in SetContext()
called from qga_vss_fsfreeze_freeze() at qga/vss-win32-requester.cpp, but I couldn't find out flags not supported on Windows 7 from VSS references.

Could you try whether removing some of these flags is effective to avoid the error in your environment?

Thanks,
Tomoki Sekiyama

Quoted 164 lines · Libaiqing

Hi,
I tried the patch v2,with the following config.

Guest os : win7 32bit professional
Host os : fedora 17
Command:

    qemu-kvm -enable-kvm -name win7 -M pc-0.15 -m 1024 -smp 2 -boot c

-device virtio-serial -drive file=/home/libaiqing/vss/win7.img,if=virtio,index=0,format=qcow2 - -monitor stdio -vga qxl -vnc :1 -chardev

socket,id=charchannel0,path=/var/lib/libvirt/qemu/wahaha1_requester,server ,nowait -device virtserialport,chardev=charchannel0,id=channel0,name=org.qemu.guest_agent. 1

Issue:
1 Extcuting the command "net start qemu-ga" failed,but the command
"qemu-qa.exe -m virtio-serial -p \\.\Global\org.qemu.guest_agent.1" is ok.
2 executing the command "{"execute":"guest-fsfreeze-freeze"}"
failed,the output is:

[root@fedora121 ~]# socat stdio,ignoreeof unix-connect:/var/lib/libvirt/qemu/wahaha1_requester {'execute':'guest-info'}
{"return": {"version": "1.4.50", "supported_commands": [{"enabled": true, "name": "guest-set-vcpus"}, {"enabled": true, "name": "guest-get-vcpus"}, {"enabled": true, "name": "guest-network-get-interfaces"}, {"enabled":
true, "name": "guest-suspend-hybrid"}, {"enabled": true, "name":
"guest-suspend-ram"}, {"enabled": true, "name": "guest-suspend-disk"}, {"enabled": true, "name": "guest-fstrim"}, {"enabled": true, "name":
"guest-fsfreeze-thaw"}, {"enabled": true, "name":
"guest-fsfreeze-freeze"}, {"enabled": true, "name":
"guest-fsfreeze-status"}, {"enabled": true, "name": "guest-file-flush"}, {"enabled": true, "name": "guest-file-seek"}, {"enabled": true, "name":
"guest-file-write"}, {"enabled": true, "name": "guest-file-read"}, {"enabled": true, "name": "guest-file-close"}, {"enabled": true, "name":
"guest-file-open"}, {"enabled": true, "name": "guest-shutdown"}, {"enabled": true, "name": "guest-info"}, {"enabled": true, "name":
"guest-set-time"}, {"enabled": true, "name": "guest-get-time"}, {"enabled": true, "name": "guest-ping"}, {"enabled": true, "name":
"guest-sync"}, {"enabled": true, "name": "guest-sync-delimited"}]}} {"execute":"guest-fsfreeze-status"}
{"return": "thawed"}
{"execute":"guest-fsfreeze-freeze"}
{"error": {"class": "GenericError", "desc": "Failed to pVssbc->SetContext. (Error: 8004231b) "}}

Could you give me some advise to debug this problem ? I can provide more information if need.

Regards,
baiqing
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Tomoki Sekiyama
Sent: Saturday, April 13, 2013 4:02 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: [Qemu-devel] [RFC PATCH v2 00/11] qemu-ga: fsfreeze on Windows using VSS

Hi,

This patch series is attempts to add fsfreeze support for Windows qemu-guest-agent.

changes from v1:
- Fix out-tree build by stop using recursive Makefile
- Added script to extract VSS SDK headers on POSIX systems using msitools (thanks Paolo)
- Remove some unnecessary header files

v1: http://lists.gnu.org/archive/html/qemu-devel/2013-02/msg01963.html

* Description
In Windows, VSS (Volume Shadow Copy Service) provides a facility to quiesce filesystems and applications before disk snapshots are taken. This patch series implements "fsfreeze" command of qemu-ga using VSS.

* How to build & run qemu-ga with VSS support

- Download Microsoft VSS SDK from:
http://www.microsoft.com/en-us/download/details.aspx?id=23490

- Setup the SDK
scripts/extract-vsssdk-headers setup.exe (on POSIX-systems)

- Specify installed SDK directory to configure option as:
./configure -with-vss-sdk="path/to/VSS SDK"
--cross-prefix=i686-w64-mingw32-

- Make qemu-ga.exe

- Install qemu-ga.exe and qga/vss-win32-provider/qga-provider.{dll,tlb} into
the same directory in guests

- Run qemu-ga.exe -s install' and net start qemu-ga' in the guests

Any feedback are appliciated.

---
Tomoki Sekiyama (11):
configure: Support configuring c++ compiler
Fix errors and warnings while compiling with c++ compilier Add a script to extract VSS SDK headers on POSIX system
qemu-ga: Add an configure option to specify path to Windows VSS SDK
qemu-ga: Add Windows VSS provider to quiesce applications on
fsfreeze
qemu-ga: Add Windows VSS requester to quisce applications and
filesystems
qemu-ga: call Windows VSS requester in fsfreeze command handler
qemu-ga: install Windows VSS provider on `qemu-ga -s install'
qemu-ga: Add VSS provider .tlb file in the repository QMP/qemu-ga-client: make timeout longer for guest-fsfreeze-freeze
command
QMP/qmp.py: set locale for exceptions to display non-ascii messages
correctly

.gitignore                              |    1
Makefile                                |    3
Makefile.objs                           |    2
QMP/qemu-ga-client                      |    4
QMP/qmp.py                              |    4
configure                               |   59 ++++
hmp.c                                   |    2
hw/pci/pci.c                            |    2
qga/Makefile.objs                       |    7
qga/commands-win32.c                    |   74 ++++-
qga/main.c                              |   41 +++
qga/vss-win32-provider.h                |   26 ++
qga/vss-win32-provider/Makefile.objs    |   25 ++
qga/vss-win32-provider/install.cpp      |  494
+++++++++++++++++++++++++++++++
qga/vss-win32-provider/provider.cpp     |  474
++++++++++++++++++++++++++++++
qga/vss-win32-provider/qga-provider.def |   10 +
qga/vss-win32-provider/qga-provider.idl |   20 +
qga/vss-win32-provider/qga-provider.tlb |  Bin
qga/vss-win32-requester.cpp             |  393 +++++++++++++++++++++++++
qga/vss-win32-requester.h               |   31 ++
qga/vss-win32.h                         |   85 +++++
rules.mak                               |    9 +
scripts/extract-vsssdk-headers          |   25 ++
scripts/qapi.py                         |    9 +
24 files changed, 1785 insertions(+), 15 deletions(-)

create mode 100644 qga/vss-win32-provider.h create mode 100644 qga/vss-win32-provider/Makefile.objs create mode 100644 qga/vss-win32-provider/install.cpp create mode 100644 qga/vss-win32-provider/provider.cpp create mode 100644 qga/vss-win32-provider/qga-provider.def create mode 100644 qga/vss-win32-provider/qga-provider.idl create mode 100644 qga/vss-win32-provider/qga-provider.tlb create mode 100644 qga/vss-win32-requester.cpp create mode 100644 qga/vss-win32-requester.h create mode 100644 qga/vss-win32.h
create mode 100755 scripts/extract-vsssdk-headers

#14 lore raw

Hi,

Quoted 10 lines · Tomoki Sekiyama
Quoted 2 lines

2 executing the command "{"execute":"guest-fsfreeze-freeze"}"
failed,the output is:

<snip>

Quoted 6 lines

{"execute":"guest-fsfreeze-freeze"}
{"error": {"class": "GenericError", "desc": "Failed to pVssbc->SetContext. (Error: 8004231b) "}}

Could you give me some advise to debug this problem ? I can provide more information if need.

Quoted 7 lines

Is there any logs corresponding to the error in Event Viewer?

And this might be caused by unsupported VSS_VOLSNAP_ATTR_* flags in SetContext()
called from qga_vss_fsfreeze_freeze() at qga/vss-win32-requester.cpp, but I couldn't find out flags not supported on Windows 7 from VSS references.

I'm investigating this issue. Some versions of Windows seem to ignore VSS_VOLSNAP_ATTR_NO_AUTORECOVERY, and to cause an error with VSS_VOLSNAP_ATTR_TRANSPORTABLE. In such cases, we cannot disable Auto-recovery that requires writable snapshots we don't yet support. Because of this, even if we remove TRANSPORTABLE flag, auto-recovery would be enabled and cause another error (VSS_E_OBJECT_NOT_FOUND) on thaw.

The patch attached (to be applied after v2 patch) removes TRANSPORTABLE flag, and ignores the VSS_E_OBJECT_NOT_FOUND error on thaw. I think this should resolve the issue in Windows 7, and also works in the other versions of Windows. Could you try this?

If it works, I will merge this into my path set and resend it as v3.

Thanks,
Tomoki Sekiyama

qga/vss-win32-requester.cpp +16 -4
index 90ff026..0e02818 100644
@@ -259,12 +259,11 @@ void qga_vss_fsfreeze_freeze(int *num_vols, Error **err)
     /*
      * Currently writable snapshots are not supported.
      * To prevent the final commit (which requires to write to snapshots),
-     * VSS_VOLSNAP_ATTR_NO_AUTORECOVERY (for Win2008 SP2 or later) and
-     * VSS_VOLSNAP_ATTR_TRANSPORTABLE (for ealier versions) are specified here.
+     * VSS_VOLSNAP_ATTR_NO_AUTORECOVERY (for Win2008 SP2 or later) 
+     * are specified here.
      */
     chk( pVssbc->SetContext(VSS_CTX_APP_ROLLBACK |
                             VSS_VOLSNAP_ATTR_NO_AUTORECOVERY |
-                            VSS_VOLSNAP_ATTR_TRANSPORTABLE |
                             VSS_VOLSNAP_ATTR_TXF_RECOVERY) );
 
     chk( pVssbc->GatherWriterMetadata(&pAsync) );
@@ -372,7 +371,19 @@ void qga_vss_fsfreeze_thaw(int *num_vols, Error **err)
     assert(pVssbc);
     assert(pAsyncSnapshot);
 
-    _chk( WaitForAsync(pAsyncSnapshot), "DoSnapshotSet", err, out );
+    HRESULT hr = WaitForAsync(pAsyncSnapshot);
+    if (hr == VSS_E_OBJECT_NOT_FOUND) {
+        /*
+         * On Windows earlier than 2008 SP2 which does not support
+         * VSS_VOLSNAP_ATTR_NO_AUTORECOVERY context, final commit is not
+         * skipped and VSS is aborted. In this case, we get here. Still the
+         * snapshot is taken successfully, so we just ignore the error.
+         */
+        pAsyncSnapshot->Release();
+        pAsyncSnapshot = NULL;
+        goto final;
+    }
+    _chk( hr, "DoSnapshotSet", err, out );
     pAsyncSnapshot->Release();
     pAsyncSnapshot = NULL;
 
@@ -380,6 +391,7 @@ void qga_vss_fsfreeze_thaw(int *num_vols, Error **err)
     _chk( WaitForAsync(pAsync), "BackupComplete", err, out );
     pAsync->Release();
 
+final:
     *num_vols = cFrozenVols;
     cFrozenVols = 0;
     goto done;