Skip to contentSkip to conversation

: qemu-ga: make shutdown & suspend synchronous

PATCH In review Luiz Capitulino 4 participants 18 messages May 11, 2012 – May 14, 2012

lore
Share & tools
lore
#0 lore raw

cover : qemu-ga: make shutdown & suspend synchronous

The main motivation for this series is fixing two possible race conditions in the guest-suspend-* API due to the complexity that arose from the way we handle terminated children processes today. Full details in the first patch.

This series applies on top of my two other qemu-ga series submitted previously:

http://lists.gnu.org/archive/html/qemu-devel/2012-05/msg00999.html

http://lists.gnu.org/archive/html/qemu-devel/2012-05/msg01507.html

 qapi-schema-guest.json   |   56 ++++++++++------
 qapi/qmp-core.h          |   10 ++-
 qapi/qmp-dispatch.c      |    8 ++-
 qapi/qmp-registry.c      |    4 +-
 qemu-ga.c                |   40 ++++++------
 qga/commands-posix.c     |  162 ++++++++++++++++++----------------------------
 qga/guest-agent-core.h   |    4 ++
 scripts/qapi-commands.py |   14 +++-
 8 files changed, 154 insertions(+), 144 deletions(-)
#1 lore raw

PATCH 1/2 qemu-ga: guest-suspend: make the API synchronous

Currently, qemu-ga has a SIGCHLD handler that automatically reaps terminated children processes. The idea is to avoid having qemu-ga commands blocked waiting for children to terminate.

That approach has two problems:

1. qemu-ga is unable to detect errors in the child, meaning that qemu-ga returns success even if the child fails to perform its task

2. if a command does depend on the child exit status, the command has to play tricks to bypass the automatic reaper

Case 2 impacts the guest-suspend-* API, because it has to execute an external program to check for suspend support. Today, to bypass the automatic reaper, suspend code has to double fork and pass exit status information through a pipe. Besides being complex, this is prone to race condition bugs. Indeed, the current code does have such bugs.

Making the guest-suspend-* API synchronous (ie. by dropping the SIGCHLD handler and calling waitpid() from commands) is a much simpler approach, which fixes current race conditions bugs and enables commands to detect errors in the child.

This commit does just that. There's a side effect though, guest-shutdown will generate zombies if shutting down fails. This will be fixed by the next commit.

---
 qemu-ga.c            |   17 +------
 qga/commands-posix.c |  124 ++++++++++++++++++++------------------------------
 2 files changed, 51 insertions(+), 90 deletions(-)
qemu-ga.c +1 -16
index 822f527..c0ca8b2 100644
@@ -104,16 +104,9 @@ static void quit_handler(int sig)
 }
 
 #ifndef _WIN32
-/* reap _all_ terminated children */
-static void child_handler(int sig)
-{
-    int status;
-    while (waitpid(-1, &status, WNOHANG) > 0) /* NOTHING */;
-}
-
 static gboolean register_signal_handlers(void)
 {
-    struct sigaction sigact, sigact_chld;
+    struct sigaction sigact;
     int ret;
 
     memset(&sigact, 0, sizeof(struct sigaction));
@@ -130,14 +123,6 @@ static gboolean register_signal_handlers(void)
         return false;
     }
 
-    memset(&sigact_chld, 0, sizeof(struct sigaction));
-    sigact_chld.sa_handler = child_handler;
-    sigact_chld.sa_flags = SA_NOCLDSTOP;
-    ret = sigaction(SIGCHLD, &sigact_chld, NULL);
-    if (ret == -1) {
-        g_error("error configuring signal handler: %s", strerror(errno));
-    }
-
     return true;
 }
 
qga/commands-posix.c +50 -74

176 lines not on this page · raw message

Signature · 1 line
1.7.9.2.384.g4a92a
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] qemu-ga: guest-suspend: make the API synchronous

Review

Quoted 7 lines · Luiz Capitulino

Currently, qemu-ga has a SIGCHLD handler that automatically reaps terminated children processes. The idea is to avoid having qemu-ga commands blocked waiting for children to terminate.

(quoted diff) +2 -0
+
+    rpid = waitpid(pid, &status, 0);

You need to worry about signals interrupting the wait. Something like:

while ((rpid = waitpid(pid, &status, 0) == -1 && errno == EINTR) { }

qga/commands-posix.c static void guest_suspend(const char *pmutils_bin, const char *sysfile_str, · line 641

Quoted 11 lines
qga/commands-posix.c +5 -1
@@ -664,9 +633,16 @@ static void guest_suspend(const char *pmutils_bin, const char *sysfile_str,
     g_free(pmutils_path);
 
     if (pid < 0) {
-        error_set(err, QERR_UNDEFINED_ERROR);
+        goto exit_err;
+    }
+
+    rpid = waitpid(pid, &status, 0);
+    if (rpid == pid && WIFEXITED(status) && !WEXITSTATUS(status)) {
         return;

And again.

Signature · 2 lines
Eric Blake   [email protected]    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#3 lore raw

PATCH 2/2 qemu-ga: guest-shutdown: become synchronous

In reply to Luiz Capitulino

Last commit dropped qemu-ga's SIGCHLD handler, used to automatically reap terminated children processes. This introduced a bug to qmp_guest_shutdown(): it will generate zombies.

This problem probably doesn't matter in the success case, as the VM will shutdown anyway, but let's do the right thing and reap the created process. This ultimately means that guest-shutdown is now a synchronous command.

An interesting side effect is that guest-shutdown is now able to report an error to the client if shutting down fails.

---
 qga/commands-posix.c |   19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)
qga/commands-posix.c +14 -5
index a61f9e0..f1b19af 100644
@@ -36,8 +36,9 @@
 
 void qmp_guest_shutdown(bool has_mode, const char *mode, Error **err)
 {
-    int ret;
     const char *shutdown_flag;
+    int ret, status;
+    pid_t rpid, pid;
 
     slog("guest-shutdown called, mode: %s", mode);
     if (!has_mode || strcmp(mode, "powerdown") == 0) {
@@ -52,8 +53,8 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **err)
         return;
     }
 
-    ret = fork();
-    if (ret == 0) {
+    pid = fork();
+    if (pid == 0) {
         /* child, start the shutdown */
         setsid();
         fclose(stdin);
@@ -66,9 +67,17 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **err)
             slog("guest-shutdown failed: %s", strerror(errno));
         }
         exit(!!ret);
-    } else if (ret < 0) {
-        error_set(err, QERR_UNDEFINED_ERROR);
+    } else if (pid < 0) {
+        goto exit_err;
     }
+
+    rpid = waitpid(pid, &status, 0);
+    if (rpid == pid && WIFEXITED(status) && !WEXITSTATUS(status)) {
+        return;
+    }
+
+exit_err:
+    error_set(err, QERR_UNDEFINED_ERROR);
 }
 
 typedef struct GuestFileHandle {
Signature · 1 line
1.7.9.2.384.g4a92a
#4 lore raw

Re: [Qemu-devel] [PATCH 2/2] qemu-ga: guest-shutdown: become synchronous

Quoted 19 lines · Luiz Capitulino

Last commit dropped qemu-ga's SIGCHLD handler, used to automatically reap terminated children processes. This introduced a bug to qmp_guest_shutdown(): it will generate zombies.

This problem probably doesn't matter in the success case, as the VM will shutdown anyway, but let's do the right thing and reap the created process. This ultimately means that guest-shutdown is now a synchronous command.

An interesting side effect is that guest-shutdown is now able to report an error to the client if shutting down fails.

---
 qga/commands-posix.c |   19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)
         exit(!!ret);

qga/commands-posix.c void qmp_guest_shutdown(bool has_mode, const char *mode, Error **err) · line 75

Quoted 8 lines
qga/commands-posix.c +5 -2
-    } else if (ret < 0) {
-        error_set(err, QERR_UNDEFINED_ERROR);
+    } else if (pid < 0) {
+        goto exit_err;
     }
+
+    rpid = waitpid(pid, &status, 0);
+    if (rpid == pid && WIFEXITED(status) && !WEXITSTATUS(status)) {

And another case where waitpid should be used in a loop.

Other than that, I'm in favor of this series.

Signature · 2 lines
Eric Blake   [email protected]    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#5 lore raw
In reply to Luiz Capitulino

Hi Luiz,

I have these patches applied to qga branch with Eric's suggested fix-ups included. I've attached them for your review. If all looks good I'll send a PULL some time today with what's hopefully all the pending fixes for qemu-ga 1.1

#6 lore raw

PATCH 1/2 qemu-ga: guest-suspend: make the API synchronous

From: Luiz Capitulino <[email protected]>

Currently, qemu-ga has a SIGCHLD handler that automatically reaps terminated children processes. The idea is to avoid having qemu-ga commands blocked waiting for children to terminate.

That approach has two problems:

1. qemu-ga is unable to detect errors in the child, meaning that qemu-ga returns success even if the child fails to perform its task

2. if a command does depend on the child exit status, the command has to play tricks to bypass the automatic reaper

Case 2 impacts the guest-suspend-* API, because it has to execute an external program to check for suspend support. Today, to bypass the automatic reaper, suspend code has to double fork and pass exit status information through a pipe. Besides being complex, this is prone to race condition bugs. Indeed, the current code does have such bugs.

Making the guest-suspend-* API synchronous (ie. by dropping the SIGCHLD handler and calling waitpid() from commands) is a much simpler approach, which fixes current race conditions bugs and enables commands to detect errors in the child.

This commit does just that. There's a side effect though, guest-shutdown will generate zombies if shutting down fails. This will be fixed by the next commit.

---
 qemu-ga.c            |   17 +------
 qga/commands-posix.c |  128 +++++++++++++++++++++-----------------------------
 2 files changed, 55 insertions(+), 90 deletions(-)
qemu-ga.c +1 -16
index 822f527..c0ca8b2 100644
@@ -104,16 +104,9 @@ static void quit_handler(int sig)
 }
 
 #ifndef _WIN32
-/* reap _all_ terminated children */
-static void child_handler(int sig)
-{
-    int status;
-    while (waitpid(-1, &status, WNOHANG) > 0) /* NOTHING */;
-}
-
 static gboolean register_signal_handlers(void)
 {
-    struct sigaction sigact, sigact_chld;
+    struct sigaction sigact;
     int ret;
 
     memset(&sigact, 0, sizeof(struct sigaction));
@@ -130,14 +123,6 @@ static gboolean register_signal_handlers(void)
         return false;
     }
 
-    memset(&sigact_chld, 0, sizeof(struct sigaction));
-    sigact_chld.sa_handler = child_handler;
-    sigact_chld.sa_flags = SA_NOCLDSTOP;
-    ret = sigaction(SIGCHLD, &sigact_chld, NULL);
-    if (ret == -1) {
-        g_error("error configuring signal handler: %s", strerror(errno));
-    }
-
     return true;
 }
 
qga/commands-posix.c +54 -74

180 lines not on this page · raw message

Signature · 1 line
1.7.4.1
Reviewed-by on v1 1/2
#7 lore raw

Re: [Qemu-devel] [PATCH 1/2] qemu-ga: guest-suspend: make the API synchronous

Quoted 11 lines · Michael Roth

From: Luiz Capitulino <[email protected]>

Currently, qemu-ga has a SIGCHLD handler that automatically reaps terminated children processes. The idea is to avoid having qemu-ga commands blocked waiting for children to terminate.

This commit does just that. There's a side effect though, guest-shutdown will generate zombies if shutting down fails. This will be fixed by the next commit.

Quoted 6 lines
---
 qemu-ga.c            |   17 +------
 qga/commands-posix.c |  128 +++++++++++++++++++++-----------------------------
 2 files changed, 55 insertions(+), 90 deletions(-)
Signature · 2 lines
Eric Blake   [email protected]    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#8 lore raw

PATCH 2/2 qemu-ga: guest-shutdown: become synchronous

In reply to Michael Roth

From: Luiz Capitulino <[email protected]>

Last commit dropped qemu-ga's SIGCHLD handler, used to automatically reap terminated children processes. This introduced a bug to qmp_guest_shutdown(): it will generate zombies.

This problem probably doesn't matter in the success case, as the VM will shutdown anyway, but let's do the right thing and reap the created process. This ultimately means that guest-shutdown is now a synchronous command.

An interesting side effect is that guest-shutdown is now able to report an error to the client if shutting down fails.

---
 qga/commands-posix.c |   21 ++++++++++++++++-----
 1 files changed, 16 insertions(+), 5 deletions(-)
qga/commands-posix.c +16 -5
index cb97646..9a59276 100644
@@ -36,8 +36,9 @@
 
 void qmp_guest_shutdown(bool has_mode, const char *mode, Error **err)
 {
-    int ret;
     const char *shutdown_flag;
+    int ret, status;
+    pid_t rpid, pid;
 
     slog("guest-shutdown called, mode: %s", mode);
     if (!has_mode || strcmp(mode, "powerdown") == 0) {
@@ -52,8 +53,8 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **err)
         return;
     }
 
-    ret = fork();
-    if (ret == 0) {
+    pid = fork();
+    if (pid == 0) {
         /* child, start the shutdown */
         setsid();
         fclose(stdin);
@@ -66,9 +67,19 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **err)
             slog("guest-shutdown failed: %s", strerror(errno));
         }
         exit(!!ret);
-    } else if (ret < 0) {
-        error_set(err, QERR_UNDEFINED_ERROR);
+    } else if (pid < 0) {
+        goto exit_err;
     }
+
+    do {
+        rpid = waitpid(pid, &status, 0);
+    } while (rpid == -1 && errno == EINTR);
+    if (rpid == pid && WIFEXITED(status) && !WEXITSTATUS(status)) {
+        return;
+    }
+
+exit_err:
+    error_set(err, QERR_UNDEFINED_ERROR);
 }
 
 typedef struct GuestFileHandle {
Signature · 1 line
1.7.4.1
Reviewed-by on v1 2/2
#9 lore raw

Re: [Qemu-devel] [PATCH 2/2] qemu-ga: guest-shutdown: become synchronous

Quoted 11 lines · Michael Roth

From: Luiz Capitulino <[email protected]>

Last commit dropped qemu-ga's SIGCHLD handler, used to automatically reap terminated children processes. This introduced a bug to qmp_guest_shutdown(): it will generate zombies.

This problem probably doesn't matter in the success case, as the VM will shutdown anyway, but let's do the right thing and reap the created process. This ultimately means that guest-shutdown is now a synchronous command.

Quoted 8 lines

An interesting side effect is that guest-shutdown is now able to report an error to the client if shutting down fails.

---
 qga/commands-posix.c |   21 ++++++++++++++++-----
 1 files changed, 16 insertions(+), 5 deletions(-)
Signature · 2 lines
Eric Blake   [email protected]    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#10 lore raw
In reply to Michael Roth
Quoted 3 lines · On Mon, 14 May 2012 09:56:30 -0500 Michael Roth <[email protected]>…

Hi Luiz,

I have these patches applied to qga branch with Eric's suggested fix-ups included. I've attached them for your review. If all looks good I'll send a PULL some time today with what's hopefully all the pending fixes for qemu-ga 1.1

Yes, looks good. I was finishing to work on a similar version that moves the loop to a function called ga_waitpid(), it's only missing some testing. But you can merge this version if you're hurrying.

Btw, I have another fix that fixes guest-shutdown to use async-safe-signal functions.

What's the best way to go? Do you want me to send just the guest-shutdown fix or should I post my v2 of this series too (that uses ga_waitpid())?

#11 lore raw
Quoted 11 lines · Luiz Capitulino
Quoted 3 lines · On Mon, 14 May 2012 09:56:30 -0500 Michael Roth <[email protected]>…

Hi Luiz,

I have these patches applied to qga branch with Eric's suggested fix-ups included. I've attached them for your review. If all looks good I'll send a PULL some time today with what's hopefully all the pending fixes for qemu-ga 1.1

Yes, looks good. I was finishing to work on a similar version that moves the loop to a function called ga_waitpid(), it's only missing some testing. But you can merge this version if you're hurrying.

Quoted 6 lines

Btw, I have another fix that fixes guest-shutdown to use async-safe-signal functions.

What's the best way to go? Do you want me to send just the guest-shutdown fix or should I post my v2 of this series too (that uses ga_waitpid())?

Hmm, since Eric has already reviewed the quick fix let's just save ga_waitpid() for another day.

Will keep an eye out for guest-shutdown fixes. I have a patch that switches it to using reopen_to_null() btw, but if that's already part of your patch I'll drop it in favor of yours:

https://github.com/mdroth/qemu/commits/qga

#12 lore raw
Quoted 15 lines · On Mon, 14 May 2012 12:19:04 -0500 Michael Roth <[email protected]>…
Quoted 14 lines · Luiz Capitulino
Quoted 3 lines · On Mon, 14 May 2012 09:56:30 -0500 Michael Roth <[email protected]>…

Hi Luiz,

I have these patches applied to qga branch with Eric's suggested fix-ups included. I've attached them for your review. If all looks good I'll send a PULL some time today with what's hopefully all the pending fixes for qemu-ga 1.1

Yes, looks good. I was finishing to work on a similar version that moves the loop to a function called ga_waitpid(), it's only missing some testing. But you can merge this version if you're hurrying.

Btw, I have another fix that fixes guest-shutdown to use async-safe-signal functions.

Quoted 6 lines
Quoted 3 lines

What's the best way to go? Do you want me to send just the guest-shutdown fix or should I post my v2 of this series too (that uses ga_waitpid())?

Hmm, since Eric has already reviewed the quick fix let's just save ga_waitpid() for another day.

OK.

Quoted 5 lines

Will keep an eye out for guest-shutdown fixes. I have a patch that switches it to using reopen_to_null() btw, but if that's already part of your patch I'll drop it in favor of yours:

https://github.com/mdroth/qemu/commits/qga

Yes, it's. Besides using reopen_to_null() we also have to switch to execle() and _exit(). I'll give it a quick test and post it shortly.

#13 lore raw
In reply to Luiz Capitulino
Quoted 12 lines · Luiz Capitulino

The main motivation for this series is fixing two possible race conditions in the guest-suspend-* API due to the complexity that arose from the way we handle terminated children processes today. Full details in the first patch.

This series applies on top of my two other qemu-ga series submitted previously:

http://lists.gnu.org/archive/html/qemu-devel/2012-05/msg00999.html

http://lists.gnu.org/archive/html/qemu-devel/2012-05/msg01507.html

Quoted 10 lines
 qapi-schema-guest.json   |   56 ++++++++++------
 qapi/qmp-core.h          |   10 ++-
 qapi/qmp-dispatch.c      |    8 ++-
 qapi/qmp-registry.c      |    4 +-
 qemu-ga.c                |   40 ++++++------
 qga/commands-posix.c     |  162 ++++++++++++++++++----------------------------
 qga/guest-agent-core.h   |    4 ++
 scripts/qapi-commands.py |   14 +++-
 8 files changed, 154 insertions(+), 144 deletions(-)

Okay, this is definitely an enhancement and fix of bogus implementation. One thing that I'd like to ask is - how can user distinguish between these implementations. I am asking basically from libvirt POV. Because if I assume I am dealing with the previous implementation and thus waiting for the {'return':{}} before I can return form an API, but the GA actually uses the new implementation I will block endlessly.

Thanks,

Michal

#14 lore raw
Quoted 24 lines · On Mon, 14 May 2012 19:06:28 +0200 Michal Privoznik <[email protected]> wrote:
Quoted 12 lines · Luiz Capitulino

The main motivation for this series is fixing two possible race conditions in the guest-suspend-* API due to the complexity that arose from the way we handle terminated children processes today. Full details in the first patch.

This series applies on top of my two other qemu-ga series submitted previously:

http://lists.gnu.org/archive/html/qemu-devel/2012-05/msg00999.html

http://lists.gnu.org/archive/html/qemu-devel/2012-05/msg01507.html

Quoted 10 lines
 qapi-schema-guest.json   |   56 ++++++++++------
 qapi/qmp-core.h          |   10 ++-
 qapi/qmp-dispatch.c      |    8 ++-
 qapi/qmp-registry.c      |    4 +-
 qemu-ga.c                |   40 ++++++------
 qga/commands-posix.c     |  162 ++++++++++++++++++----------------------------
 qga/guest-agent-core.h   |    4 ++
 scripts/qapi-commands.py |   14 +++-
 8 files changed, 154 insertions(+), 144 deletions(-)
Quoted 6 lines

Okay, this is definitely an enhancement and fix of bogus implementation. One thing that I'd like to ask is - how can user distinguish between these implementations. I am asking basically from libvirt POV. Because if I assume I am dealing with the previous implementation and thus waiting for the {'return':{}} before I can return form an API, but the GA actually uses the new implementation I will block endlessly.

There's no way to distinguish. It's a bug to wait for an OK response for the guest-shutdown and guest-suspend-*, because a response may not been sent even before this series (and this is correctly documented).

#15 lore raw
In reply to Michal Privoznik
Quoted 24 lines · Michal Privoznik
Quoted 12 lines · Luiz Capitulino

The main motivation for this series is fixing two possible race conditions in the guest-suspend-* API due to the complexity that arose from the way we handle terminated children processes today. Full details in the first patch.

This series applies on top of my two other qemu-ga series submitted previously:

http://lists.gnu.org/archive/html/qemu-devel/2012-05/msg00999.html

http://lists.gnu.org/archive/html/qemu-devel/2012-05/msg01507.html

Quoted 10 lines
 qapi-schema-guest.json   |   56 ++++++++++------
 qapi/qmp-core.h          |   10 ++-
 qapi/qmp-dispatch.c      |    8 ++-
 qapi/qmp-registry.c      |    4 +-
 qemu-ga.c                |   40 ++++++------
 qga/commands-posix.c     |  162 ++++++++++++++++++----------------------------
 qga/guest-agent-core.h   |    4 ++
 scripts/qapi-commands.py |   14 +++-
 8 files changed, 154 insertions(+), 144 deletions(-)
Quoted 6 lines

Okay, this is definitely an enhancement and fix of bogus implementation. One thing that I'd like to ask is - how can user distinguish between these implementations. I am asking basically from libvirt POV. Because if I assume I am dealing with the previous implementation and thus waiting for the {'return':{}} before I can return form an API, but the GA actually uses the new implementation I will block endlessly.

I think the point was that you would block endlessly waiting for the {'return':{}} anyways, even with the old implementation, because there was no guarantee that the guest agent could issue the reply in a timely manner. Therefore, the only sane implementation in libvirt is to assume that success will not be reported via the guest agent, and that libvirt must _always_ probe for the listed side effects (a change in guest status, qemu exiting, an event, or so forth), and optionally have a timeout if the associated timeout does not occur in a reasonable time.

Signature · 2 lines
Eric Blake   [email protected]    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#16 lore raw
Quoted 32 lines · Eric Blake
Quoted 24 lines · Michal Privoznik
Quoted 12 lines · Luiz Capitulino

The main motivation for this series is fixing two possible race conditions in the guest-suspend-* API due to the complexity that arose from the way we handle terminated children processes today. Full details in the first patch.

This series applies on top of my two other qemu-ga series submitted previously:

http://lists.gnu.org/archive/html/qemu-devel/2012-05/msg00999.html

http://lists.gnu.org/archive/html/qemu-devel/2012-05/msg01507.html

Quoted 10 lines
 qapi-schema-guest.json   |   56 ++++++++++------
 qapi/qmp-core.h          |   10 ++-
 qapi/qmp-dispatch.c      |    8 ++-
 qapi/qmp-registry.c      |    4 +-
 qemu-ga.c                |   40 ++++++------
 qga/commands-posix.c     |  162 ++++++++++++++++++----------------------------
 qga/guest-agent-core.h   |    4 ++
 scripts/qapi-commands.py |   14 +++-
 8 files changed, 154 insertions(+), 144 deletions(-)
Quoted 6 lines

Okay, this is definitely an enhancement and fix of bogus implementation. One thing that I'd like to ask is - how can user distinguish between these implementations. I am asking basically from libvirt POV. Because if I assume I am dealing with the previous implementation and thus waiting for the {'return':{}} before I can return form an API, but the GA actually uses the new implementation I will block endlessly.

Quoted 8 lines

I think the point was that you would block endlessly waiting for the {'return':{}} anyways, even with the old implementation, because there was no guarantee that the guest agent could issue the reply in a timely manner. Therefore, the only sane implementation in libvirt is to assume that success will not be reported via the guest agent, and that libvirt must _always_ probe for the listed side effects (a change in guest status, qemu exiting, an event, or so forth), and optionally have a timeout if the associated timeout does not occur in a reasonable time.

Additionally, *all* commands carry the risk that qemu-ga can die (killed, crashed, guest reboots, not being installed to begin with, etc) before issuing a response, so a timeout mechanism *must* be in place if it blocks libvirt.

Let me know if it's unclear how timeout+reset is to be implemented/used. I've captured most of the ins/outs here but I realize it's still a bit of a headache:

http://wiki.qemu.org/Features/QAPI/GuestAgent#QEMU_Guest_Agent_Protocol

Quoted 5 lines
Signature · 3 lines
-- 
Eric Blake   [email protected]    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#17 lore raw
Quoted 4 lines · On Mon, 14 May 2012 13:12:35 -0500 Michael Roth <[email protected]>…

Additionally, *all* commands carry the risk that qemu-ga can die (killed, crashed, guest reboots, not being installed to begin with, etc) before issuing a response, so a timeout mechanism *must* be in place if it blocks libvirt.

True. This is unrelated to qemu-ga, but I think libvirt should allow the user to change the timeout. You could have a very long default timeout, or even infinite.