All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tomoki Sekiyama <tomoki.sekiyama@hds.com>
To: qemu-devel@nongnu.org
Cc: libaiqing@huawei.com, stefanha@gmail.com,
	mdroth@linux.vnet.ibm.com, lcapitulino@redhat.com,
	vrozenfe@redhat.com, pbonzini@redhat.com, seiji.aguchi@hds.com,
	areis@redhat.com
Subject: [Qemu-devel] [PATCH v4 08/10] qemu-ga: call Windows VSS requester in fsfreeze command handler
Date: Thu, 06 Jun 2013 11:06:53 -0400	[thread overview]
Message-ID: <20130606150653.10486.34913.stgit@hds.com> (raw)
In-Reply-To: <20130606150618.10486.60669.stgit@hds.com>

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.

Signed-off-by: Tomoki Sekiyama <tomoki.sekiyama@hds.com>
---
 qga/commands-win32.c |   74 ++++++++++++++++++++++++++++++++++++++++++++++----
 qga/main.c           |   33 ++++++++++++++++++++++
 2 files changed, 100 insertions(+), 7 deletions(-)

diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index 24e4ad0..67dca60 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -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.
diff --git a/qga/main.c b/qga/main.c
index 0e04e73..8bcedaf 100644
--- a/qga/main.c
+++ b/qga/main.c
@@ -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__
@@ -701,6 +705,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)
 {
@@ -743,8 +766,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);
 }
@@ -1175,7 +1202,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
 

  parent reply	other threads:[~2013-06-06 15:08 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-06 15:06 [Qemu-devel] [PATCH v4 00/10] qemu-ga: fsfreeze on Windows using VSS Tomoki Sekiyama
2013-06-06 15:06 ` [Qemu-devel] [PATCH v4 01/10] configure: Support configuring c++ compiler Tomoki Sekiyama
2013-06-18 10:17   ` Paolo Bonzini
2013-06-25  8:15   ` Laszlo Ersek
2013-06-06 15:06 ` [Qemu-devel] [PATCH v4 02/10] Add c++ keywords to QAPI helper script Tomoki Sekiyama
2013-06-25  8:16   ` Laszlo Ersek
2013-06-06 15:06 ` [Qemu-devel] [PATCH v4 03/10] checkpatch.pl: check .cpp files Tomoki Sekiyama
2013-06-25  8:17   ` Laszlo Ersek
2013-06-06 15:06 ` [Qemu-devel] [PATCH v4 04/10] Add a script to extract VSS SDK headers on POSIX system Tomoki Sekiyama
2013-06-25  8:30   ` Laszlo Ersek
2013-06-25 15:01   ` Laszlo Ersek
2013-06-25 15:01     ` Paolo Bonzini
2013-06-26 10:52       ` Laszlo Ersek
2013-06-06 15:06 ` [Qemu-devel] [PATCH v4 05/10] qemu-ga: Add configure options to specify path to Windows/VSS SDK Tomoki Sekiyama
2013-06-25 11:16   ` Laszlo Ersek
2013-06-28 10:43     ` Daniel P. Berrange
2013-06-28 10:54       ` Paolo Bonzini
2013-06-28 11:01         ` Daniel P. Berrange
2013-06-28 11:18           ` Paolo Bonzini
2013-06-28 11:30             ` Daniel P. Berrange
2013-06-28 12:18               ` Paolo Bonzini
2013-06-28 11:05       ` Laszlo Ersek
2013-06-06 15:06 ` [Qemu-devel] [PATCH v4 06/10] qemu-ga: Add Windows VSS provider to quiesce applications on fsfreeze Tomoki Sekiyama
2013-06-25 16:03   ` Laszlo Ersek
2013-06-25 16:19     ` Paolo Bonzini
2013-06-25 18:23     ` Tomoki Sekiyama
2013-06-25 18:59       ` Paolo Bonzini
2013-06-25 19:28         ` Tomoki Sekiyama
2013-06-25 19:52       ` Laszlo Ersek
2013-06-26 14:32     ` Laszlo Ersek
2013-06-26 21:27       ` Paolo Bonzini
2013-06-26 22:09       ` Tomoki Sekiyama
2013-06-27 15:01       ` Laszlo Ersek
2013-06-27 22:25         ` Tomoki Sekiyama
2013-06-28  7:05           ` Paolo Bonzini
2013-06-28 10:40             ` Laszlo Ersek
2013-06-28 10:40               ` Paolo Bonzini
2013-06-28 17:18                 ` Tomoki Sekiyama
2013-06-28 10:44           ` Laszlo Ersek
2013-06-25 21:15   ` Paolo Bonzini
2013-06-25 22:31     ` Tomoki Sekiyama
2013-06-26  5:59       ` Paolo Bonzini
2013-06-26 14:13         ` Tomoki Sekiyama
2013-06-30 13:16       ` Gal Hammer
2013-07-01 18:57         ` Tomoki Sekiyama
2013-07-02 12:36           ` Gal Hammer
2013-06-06 15:06 ` [Qemu-devel] [PATCH v4 07/10] qemu-ga: Add Windows VSS requester to quiesce applications and filesystems Tomoki Sekiyama
2013-06-28 18:01   ` Laszlo Ersek
2013-06-28 18:34     ` Laszlo Ersek
2013-06-30  1:21     ` Tomoki Sekiyama
2013-07-01  8:31       ` Laszlo Ersek
2013-06-06 15:06 ` Tomoki Sekiyama [this message]
2013-07-01 13:29   ` [Qemu-devel] [PATCH v4 08/10] qemu-ga: call Windows VSS requester in fsfreeze command handler Laszlo Ersek
2013-07-01 17:48     ` Eric Blake
2013-07-01 17:59     ` Tomoki Sekiyama
2013-07-02  6:36       ` Laszlo Ersek
2013-07-02 14:09         ` Luiz Capitulino
2013-07-02 14:44           ` Laszlo Ersek
2013-07-02 15:16             ` Luiz Capitulino
2013-07-02 15:28               ` Laszlo Ersek
2013-07-02 14:58         ` Michael Roth
2013-06-06 15:06 ` [Qemu-devel] [PATCH v4 09/10] qemu-ga: install Windows VSS provider on `qemu-ga -s install' Tomoki Sekiyama
2013-07-01 14:50   ` Laszlo Ersek
2013-07-01 17:59     ` Tomoki Sekiyama
2013-06-06 15:07 ` [Qemu-devel] [PATCH v4 10/10] QMP/qemu-ga-client: make timeout longer for guest-fsfreeze-freeze command Tomoki Sekiyama
2013-06-18 10:17   ` Paolo Bonzini
2013-07-01 15:02   ` Laszlo Ersek
2013-06-10  9:26 ` [Qemu-devel] [PATCH v4 00/10] qemu-ga: fsfreeze on Windows using VSS Stefan Hajnoczi
2013-06-24 19:30 ` Tomoki Sekiyama
2013-06-24 21:13   ` Laszlo Ersek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130606150653.10486.34913.stgit@hds.com \
    --to=tomoki.sekiyama@hds.com \
    --cc=areis@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=libaiqing@huawei.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=seiji.aguchi@hds.com \
    --cc=stefanha@gmail.com \
    --cc=vrozenfe@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.