Skip to contentSkip to conversation

Fix a bug where qemu-ga service is stuck during stop operation

PATCH Superseded Sameeh Jubran 2 participants 3 messages Mar 21, 2017 – Apr 4, 2017

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix a bug where qemu-ga service is stuck during stop operation

After triggering a freeze command without any following thaw command, qemu-ga will not respond to stop operation. This behaviour is wanted on Linux as there is no time limit for a freeze command and we want to prevent quitting in the middle of freeze, on the other hand on Windows the time limit for freeze is 10 seconds, so we should wait for the timeout, thaw the file system and quit.

---
 qga/main.c                 | 20 ++++++++++++++++++++
 qga/vss-win32.h            |  1 +
 qga/vss-win32/vss-common.h |  5 +++++
 3 files changed, 26 insertions(+)
qga/main.c +20 -0
index 92658bc..de37c85 100644
@@ -130,9 +130,29 @@ static void quit_handler(int sig)
      * unless all log/pid files are on unfreezable filesystems. there's
      * also a very likely chance killing the agent before unfreezing
      * the filesystems is a mistake (or will be viewed as one later).
+     * On Windows the freeze interval is limited to 10 seconds, so
+     * we should quit, but first we should wait for the timeout, thaw
+     * the filesystem and quit.
      */
     if (ga_is_frozen(ga_state)) {
+#ifdef _WIN32
+        int i = 0;
+        Error *err = NULL;
+        HANDLE hEventTimeout;
+
+        hEventTimeout = OpenEvent(EVENT_ALL_ACCESS, FALSE, EVENT_NAME_TIMEOUT);
+        if (hEventTimeout) {
+            WaitForSingleObject(hEventTimeout, 0);
+            CloseHandle(hEventTimeout);
+        }
+        qga_vss_fsfreeze(&i, &err, false);
+        if (err) {
+            g_debug("Error: %s", error_get_pretty(err));
+            error_free(err);
+        }
+#else
         return;
+#endif
     }
     g_debug("received signal num %d, quitting", sig);
 
qga/vss-win32.h +1 -0
index 4d1d150..5f4ea70 100644
@@ -13,6 +13,7 @@
 #ifndef VSS_WIN32_H
 #define VSS_WIN32_H
 
+#include "qga/vss-win32/vss-common.h"
 
 bool vss_init(bool init_requester);
 void vss_deinit(bool deinit_requester);
qga/vss-win32/vss-common.h +5 -0
index c81a856..5756d00 100644
@@ -12,6 +12,7 @@
 
 #ifndef VSS_COMMON_H
 #define VSS_COMMON_H
+#ifndef VSS_WIN32_H
 
 #define __MIDL_user_allocate_free_DEFINED__
 #include <windows.h>
@@ -57,6 +58,7 @@
 #define L(a) _L(a)
 
 /* Constants for QGA VSS Provider */
+#endif
 
 #define QGA_PROVIDER_NAME "QEMU Guest Agent VSS Provider"
 #define QGA_PROVIDER_LNAME L(QGA_PROVIDER_NAME)
@@ -66,6 +68,8 @@
 #define EVENT_NAME_THAW    "Global\\QGAVSSEvent-thaw"
 #define EVENT_NAME_TIMEOUT "Global\\QGAVSSEvent-timeout"
 
+#ifndef VSS_WIN32_H
+
 const GUID g_gProviderId = { 0x3629d4ed, 0xee09, 0x4e0e,
     {0x9a, 0x5c, 0x6d, 0x8b, 0xa2, 0x87, 0x2a, 0xef} };
 const GUID g_gProviderVersion = { 0x11ef8b15, 0xcac6, 0x40d6,
@@ -126,3 +130,4 @@ public:
 };
 
 #endif
+#endif
Signature · 1 line
2.9.3
#1 lore raw

Ping.

Quoted 100 lines · Sameeh Jubran

After triggering a freeze command without any following thaw command, qemu-ga will not respond to stop operation. This behaviour is wanted on Linux
as there is no time limit for a freeze command and we want to prevent quitting in the middle of freeze, on the other hand on Windows the time limit for freeze is 10 seconds, so we should wait for the timeout, thaw the file system and quit.

---
 qga/main.c                 | 20 ++++++++++++++++++++
 qga/vss-win32.h            |  1 +
 qga/vss-win32/vss-common.h |  5 +++++
 3 files changed, 26 insertions(+)
qga/main.c +20 -0
index 92658bc..de37c85 100644
@@ -130,9 +130,29 @@ static void quit_handler(int sig)
      * unless all log/pid files are on unfreezable filesystems. there's
      * also a very likely chance killing the agent before unfreezing
      * the filesystems is a mistake (or will be viewed as one later).
+     * On Windows the freeze interval is limited to 10 seconds, so
+     * we should quit, but first we should wait for the timeout, thaw
+     * the filesystem and quit.
      */
     if (ga_is_frozen(ga_state)) {
+#ifdef _WIN32
+        int i = 0;
+        Error *err = NULL;
+        HANDLE hEventTimeout;
+
+        hEventTimeout = OpenEvent(EVENT_ALL_ACCESS, FALSE,
 EVENT_NAME_TIMEOUT);
+        if (hEventTimeout) {
+            WaitForSingleObject(hEventTimeout, 0);
+            CloseHandle(hEventTimeout);
+        }
+        qga_vss_fsfreeze(&i, &err, false);
+        if (err) {
+            g_debug("Error: %s", error_get_pretty(err));
+            error_free(err);
+        }
+#else
         return;
+#endif
     }
     g_debug("received signal num %d, quitting", sig);
qga/vss-win32.h +1 -0
index 4d1d150..5f4ea70 100644
@@ -13,6 +13,7 @@
 #ifndef VSS_WIN32_H
 #define VSS_WIN32_H
 
+#include "qga/vss-win32/vss-common.h"
 
 bool vss_init(bool init_requester);
 void vss_deinit(bool deinit_requester);
qga/vss-win32/vss-common.h +5 -1
index c81a856..5756d00 100644
@@ -12,6 +12,7 @@
 
 #ifndef VSS_COMMON_H
 #define VSS_COMMON_H
+#ifndef VSS_WIN32_H
 
 #define __MIDL_user_allocate_free_DEFINED__
 #include <windows.h>
@@ -57,6 +58,7 @@
 #define L(a) _L(a)
 
 /* Constants for QGA VSS Provider */
+#endif
 
 #define QGA_PROVIDER_NAME "QEMU Guest Agent VSS Provider"
 #define QGA_PROVIDER_LNAME L(QGA_PROVIDER_NAME)
@@ -66,6 +68,8 @@
 #define EVENT_NAME_THAW    "Global\\QGAVSSEvent-thaw"
 #define EVENT_NAME_TIMEOUT "Global\\QGAVSSEvent-timeout"
 
+#ifndef VSS_WIN32_H
+
 const GUID g_gProviderId = { 0x3629d4ed, 0xee09, 0x4e0e,
     {0x9a, 0x5c, 0x6d, 0x8b, 0xa2, 0x87, 0x2a, 0xef} };
 const GUID g_gProviderVersion = { 0x11ef8b15, 0xcac6, 0x40d6,
@@ -126,3 +130,4 @@ public:
 };
 
 #endif
+#endif
--

2.9.3

Signature · 4 lines
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*
#2 lore raw
In reply to Sameeh Jubran

Quoting Sameeh Jubran (2017-03-21 08:59:11)

Quoted 21 lines

After triggering a freeze command without any following thaw command, qemu-ga will not respond to stop operation. This behaviour is wanted on Linux as there is no time limit for a freeze command and we want to prevent quitting in the middle of freeze, on the other hand on Windows the time limit for freeze is 10 seconds, so we should wait for the timeout, thaw the file system and quit.

---
 qga/main.c                 | 20 ++++++++++++++++++++
 qga/vss-win32.h            |  1 +
 qga/vss-win32/vss-common.h |  5 +++++
 3 files changed, 26 insertions(+)
qga/main.c +0 -0
index 92658bc..de37c85 100644
@@ -130,9 +130,29 @@ static void quit_handler(int sig)
      * unless all log/pid files are on unfreezable filesystems. there's
      * also a very likely chance killing the agent before unfreezing

qga/main.c static void quit_handler(int sig) · line 141

Quoted 10 lines
qga/main.c +7 -0
      * the filesystems is a mistake (or will be viewed as one later).
+     * On Windows the freeze interval is limited to 10 seconds, so
+     * we should quit, but first we should wait for the timeout, thaw
+     * the filesystem and quit.
      */
     if (ga_is_frozen(ga_state)) {
+#ifdef _WIN32
+        int i = 0;
+        Error *err = NULL;
+        HANDLE hEventTimeout;

Maybe add the following to help explain the added delay:

           g_debug("Thawing filesystems before exiting");

qga/main.c static void quit_handler(int sig) · line 150

Quoted 9 lines
qga/main.c +9 -0
+
+        hEventTimeout = OpenEvent(EVENT_ALL_ACCESS, FALSE, EVENT_NAME_TIMEOUT);
+        if (hEventTimeout) {
+            WaitForSingleObject(hEventTimeout, 0);
+            CloseHandle(hEventTimeout);
+        }
+        qga_vss_fsfreeze(&i, &err, false);
+        if (err) {
+            g_debug("Error: %s", error_get_pretty(err));

Perhaps: "Error unfreezing filesystems prior to exiting: %s"

Quoted 41 lines
qga/main.c +4 -0
+            error_free(err);
+        }
+#else
         return;
+#endif
     }
     g_debug("received signal num %d, quitting", sig);
 
qga/vss-win32.h +1 -0
index 4d1d150..5f4ea70 100644
@@ -13,6 +13,7 @@
 #ifndef VSS_WIN32_H
 #define VSS_WIN32_H
 
+#include "qga/vss-win32/vss-common.h"
 
 bool vss_init(bool init_requester);
 void vss_deinit(bool deinit_requester);
qga/vss-win32/vss-common.h +2 -0
index c81a856..5756d00 100644
@@ -12,6 +12,7 @@
 
 #ifndef VSS_COMMON_H
 #define VSS_COMMON_H
+#ifndef VSS_WIN32_H
 
 #define __MIDL_user_allocate_free_DEFINED__
 #include <windows.h>
@@ -57,6 +58,7 @@
 #define L(a) _L(a)
 
 /* Constants for QGA VSS Provider */
+#endif
 
 #define QGA_PROVIDER_NAME "QEMU Guest Agent VSS Provider"
 #define QGA_PROVIDER_LNAME L(QGA_PROVIDER_NAME)

qga/vss-win32/vss-common.h line 69

Quoted 2 lines
qga/vss-win32/vss-common.h +0 -0
@@ -66,6 +68,8 @@
 #define EVENT_NAME_THAW    "Global\\QGAVSSEvent-thaw"
 #define EVENT_NAME_TIMEOUT "Global\\QGAVSSEvent-timeout"

This is a bit of tangle. I'd rather you just move these out into a separate header, vss-handles.h or something, and then include that in main.c and vss-common.h.

Quoted 14 lines
qga/vss-win32/vss-common.h +3 -0
+#ifndef VSS_WIN32_H
+
 const GUID g_gProviderId = { 0x3629d4ed, 0xee09, 0x4e0e,
     {0x9a, 0x5c, 0x6d, 0x8b, 0xa2, 0x87, 0x2a, 0xef} };
 const GUID g_gProviderVersion = { 0x11ef8b15, 0xcac6, 0x40d6,
@@ -126,3 +130,4 @@ public:
 };
 
 #endif
+#endif
Signature · 1 line
2.9.3