Skip to contentSkip to conversation

qemu-ga fixes for 1.1

GIT PULL New Michael Roth 2 participants 15 messages May 15, 2012 – May 21, 2012

lore
Share & tools
lore
#2 lore raw

PATCH 2/13 qemu-ga: don't warn on no command return

In reply to Michael Roth

From: Luiz Capitulino <[email protected]>

This is a valid condition when a command chooses to not emit a success response.

---
 qemu-ga.c |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)
qemu-ga.c +0 -2
index 680997e..cf61cb9 100644
@@ -488,8 +488,6 @@ static void process_command(GAState *s, QDict *req)
             g_warning("error sending response: %s", strerror(ret));
         }
         qobject_decref(rsp);
-    } else {
-        g_warning("error getting response");
     }
 }
 
Signature · 1 line
1.7.4.1
#0 lore raw

The following changes since commit 76ee152a86d5f2533443ce4d2be6fe253cfb3c45:

Update version to 1.1.0-rc2 (2012-05-14 17:56:50 -0500)

are available in the git repository at:
git://github.com/mdroth/qemu.git qga-pull-5-15-12

The bulk of these patches finish out the transition to making guest-suspend*/guest-shutdown forgo sending a response on success, and making them synchronous on the guest side such that errors can be be reported back to the host.

There are also a mix of odd fixes and a version bump for qemu-ga.

Luiz Capitulino (11):
qapi: add support for command options
qemu-ga: don't warn on no command return
qemu-ga: guest-shutdown: don't emit a success response
qemu-ga: guest-suspend-disk: don't emit a success response
qemu-ga: guest-suspend-ram: don't emit a success response
qemu-ga: guest-suspend-hybrid: don't emit a success response
qemu-ga: make reopen_fd_to_null() public
qemu-ga: become_daemon(): reopen standard fds to /dev/null
qemu-ga: guest-suspend: make the API synchronous
qemu-ga: guest-shutdown: become synchronous
qemu-ga: guest-shutdown: use only async-signal-safe functions

Michael Roth (2):
qemu-ga: fix segv after failure to open log file
qemu-ga: align versioning with QEMU_VERSION

 qapi-schema-guest.json   |   59 +++++++++------
 qapi/qmp-core.h          |   10 ++-
 qapi/qmp-dispatch.c      |    8 ++-
 qapi/qmp-registry.c      |    4 +-
 qemu-ga.c                |   49 ++++++------
 qga/commands-posix.c     |  185 +++++++++++++++++++---------------------------
 qga/commands.c           |    2 +-
 qga/guest-agent-core.h   |    5 +-
 scripts/qapi-commands.py |   14 +++-
 9 files changed, 174 insertions(+), 162 deletions(-)
#4 lore raw

PATCH 4/13 qemu-ga: guest-suspend-disk: don't emit a success response

From: Luiz Capitulino <[email protected]>

Today, qemu-ga may not be able to emit a success response when guest-suspend-disk completes. This happens because the VM may vanish before qemu-ga is able to emit a response.

This semantic is a bit confusing, as it's not clear for clients if they should wait for a response or how they should check for success.

This commit solves that problem by changing guest-suspend-disk to never emit a success response and suggests in the documentation what clients could do to check for success.

---
 qapi-schema-guest.json |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
qapi-schema-guest.json +10 -6
index 1dd3454..88b165c 100644
@@ -363,17 +363,21 @@
 # For the best results it's strongly recommended to have the pm-utils
 # package installed in the guest.
 #
-# Returns: nothing on success
+# This command does NOT return a response on success. There is a high chance
+# the command succeeded if the VM exits with a zero exit status or, when
+# running with --no-shutdown, by issuing the query-status QMP command to
+# to confirm the VM status is "shutdown". However, the VM could also exit
+# (or set its status to "shutdown") due to other reasons.
+#
+# The following errors may be returned:
 #          If suspend to disk is not supported, Unsupported
 #
-# Notes: o This is an asynchronous request. There's no guarantee a response
-#          will be sent
-#        o It's strongly recommended to issue the guest-sync command before
-#          sending commands when the guest resumes
+# Notes: It's strongly recommended to issue the guest-sync command before
+#        sending commands when the guest resumes
 #
 # Since: 1.1
 ##
-{ 'command': 'guest-suspend-disk' }
+{ 'command': 'guest-suspend-disk', 'success-response': 'no' }
 
 ##
 # @guest-suspend-ram
Signature · 1 line
1.7.4.1
#1 lore raw

PATCH 1/13 qapi: add support for command options

In reply to Michael Roth

From: Luiz Capitulino <[email protected]>

Options allow for changes in commands behavior. This commit introduces the QCO_NO_SUCCESS_RESP option, which causes a command to not emit a success response.

This is needed by commands such as qemu-ga's guest-shutdown, which may not be able to complete before the VM vanishes. In this case, it's useful and simpler not to bother sending a success response.

---
 qapi/qmp-core.h          |   10 +++++++++-
 qapi/qmp-dispatch.c      |    8 ++++++--
 qapi/qmp-registry.c      |    4 +++-
 scripts/qapi-commands.py |   14 ++++++++++++--
 4 files changed, 30 insertions(+), 6 deletions(-)
qapi/qmp-core.h +9 -1
index 431ddbb..b0f64ba 100644
@@ -25,16 +25,24 @@ typedef enum QmpCommandType
     QCT_NORMAL,
 } QmpCommandType;
 
+typedef enum QmpCommandOptions
+{
+    QCO_NO_OPTIONS = 0x0,
+    QCO_NO_SUCCESS_RESP = 0x1,
+} QmpCommandOptions;
+
 typedef struct QmpCommand
 {
     const char *name;
     QmpCommandType type;
     QmpCommandFunc *fn;
+    QmpCommandOptions options;
     QTAILQ_ENTRY(QmpCommand) node;
     bool enabled;
 } QmpCommand;
 
-void qmp_register_command(const char *name, QmpCommandFunc *fn);
+void qmp_register_command(const char *name, QmpCommandFunc *fn,
+                          QmpCommandOptions options);
 QmpCommand *qmp_find_command(const char *name);
 QObject *qmp_dispatch(QObject *request);
 void qmp_disable_command(const char *name);
qapi/qmp-dispatch.c +6 -2
index 43f640a..122c1a2 100644
@@ -94,8 +94,12 @@ static QObject *do_qmp_dispatch(QObject *request, Error **errp)
     switch (cmd->type) {
     case QCT_NORMAL:
         cmd->fn(args, &ret, errp);
-        if (!error_is_set(errp) && ret == NULL) {
-            ret = QOBJECT(qdict_new());
+        if (!error_is_set(errp)) {
+            if (cmd->options & QCO_NO_SUCCESS_RESP) {
+                g_assert(!ret);
+            } else if (!ret) {
+                ret = QOBJECT(qdict_new());
+            }
         }
         break;
     }
qapi/qmp-registry.c +3 -1
index 43d5cde..5414613 100644
@@ -17,7 +17,8 @@
 static QTAILQ_HEAD(QmpCommandList, QmpCommand) qmp_commands =
     QTAILQ_HEAD_INITIALIZER(qmp_commands);
 
-void qmp_register_command(const char *name, QmpCommandFunc *fn)
+void qmp_register_command(const char *name, QmpCommandFunc *fn,
+                          QmpCommandOptions options)
 {
     QmpCommand *cmd = g_malloc0(sizeof(*cmd));
 
@@ -25,6 +26,7 @@ void qmp_register_command(const char *name, QmpCommandFunc *fn)
     cmd->type = QCT_NORMAL;
     cmd->fn = fn;
     cmd->enabled = true;
+    cmd->options = options;
     QTAILQ_INSERT_TAIL(&qmp_commands, cmd, node);
 }
 
scripts/qapi-commands.py +12 -2
index 0b4f0a0..9eed40e 100644
@@ -291,14 +291,24 @@ out:
 
     return ret
 
+def option_value_matches(opt, val, cmd):
+    if opt in cmd and cmd[opt] == val:
+        return True
+    return False
+
 def gen_registry(commands):
     registry=""
     push_indent()
     for cmd in commands:
+        options = 'QCO_NO_OPTIONS'
+        if option_value_matches('success-response', 'no', cmd):
+            options = 'QCO_NO_SUCCESS_RESP'
+
         registry += mcgen('''
-qmp_register_command("%(name)s", qmp_marshal_input_%(c_name)s);
+qmp_register_command("%(name)s", qmp_marshal_input_%(c_name)s, %(opts)s);
 ''',
-                     name=cmd['command'], c_name=c_fun(cmd['command']))
+                     name=cmd['command'], c_name=c_fun(cmd['command']),
+                     opts=options)
     pop_indent()
     ret = mcgen('''
 static void qmp_init_marshal(void)
Signature · 1 line
1.7.4.1
#3 lore raw

PATCH 3/13 qemu-ga: guest-shutdown: don't emit a success response

In reply to Michael Roth

From: Luiz Capitulino <[email protected]>

Today, qemu-ga may not be able to emit a success response when guest-shutdown completes. This happens because the VM may vanish before qemu-ga is able to emit a response.

This semantic is a bit confusing, as it's not clear for clients if they should wait for a response or how they should check for success.

This commit solves that problem by changing guest-shutdown to never emit a success response and suggests in the documentation what clients could do to check for success.

---
 qapi-schema-guest.json |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
qapi-schema-guest.json +6 -2
index 692b570..1dd3454 100644
@@ -131,11 +131,15 @@
 #
 # @mode: #optional "halt", "powerdown" (default), or "reboot"
 #
-# Returns: Nothing on success
+# This command does NOT return a response on success. Success condition
+# is indicated by the VM exiting with a zero exit status or, when
+# running with --no-shutdown, by issuing the query-status QMP command
+# to confirm the VM status is "shutdown".
 #
 # Since: 0.15.0
 ##
-{ 'command': 'guest-shutdown', 'data': { '*mode': 'str' } }
+{ 'command': 'guest-shutdown', 'data': { '*mode': 'str' },
+  'success-response': 'no' }
 
 ##
 # @guest-file-open:
Signature · 1 line
1.7.4.1
#6 lore raw

PATCH 6/13 qemu-ga: guest-suspend-hybrid: don't emit a success response

In reply to Michael Roth

From: Luiz Capitulino <[email protected]>

Today, qemu-ga may not be able to emit a success response when guest-suspend-hybrid completes. This happens because the VM may suspend before qemu-ga is able to emit a response.

This semantic is a bit confusing, as it's not clear for clients if they should wait for a response or how they should check for success.

This commit solves that problem by changing guest-suspend-hybrid to never emit a success response and suggests in the documentation what clients should do to check for success.

---
 qapi-schema-guest.json |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
qapi-schema-guest.json +10 -6
index 50e2815..7c6cb21 100644
@@ -422,17 +422,21 @@
 # command.  Thus, it's *required* to query QEMU for the presence of the
 # 'system_wakeup' command before issuing guest-suspend-hybrid.
 #
-# Returns: nothing on success
+# This command does NOT return a response on success. There are two options
+# to check for success:
+#   1. Wait for the SUSPEND QMP event from QEMU
+#   2. Issue the query-status QMP command to confirm the VM status is
+#      "suspended"
+#
+# The following errors may be returned:
 #          If hybrid suspend is not supported, Unsupported
 #
-# Notes: o This is an asynchronous request. There's no guarantee a response
-#          will be sent
-#        o It's strongly recommended to issue the guest-sync command before
-#          sending commands when the guest resumes
+# Notes: It's strongly recommended to issue the guest-sync command before
+#        sending commands when the guest resumes
 #
 # Since: 1.1
 ##
-{ 'command': 'guest-suspend-hybrid' }
+{ 'command': 'guest-suspend-hybrid', 'success-response': 'no' }
 
 ##
 # @GuestIpAddressType:
Signature · 1 line
1.7.4.1
#5 lore raw

PATCH 5/13 qemu-ga: guest-suspend-ram: don't emit a success response

In reply to Michael Roth

From: Luiz Capitulino <[email protected]>

Today, qemu-ga may not be able to emit a success response when guest-suspend-ram completes. This happens because the VM may suspend before qemu-ga is able to emit a response.

This semantic is a bit confusing, as it's not clear for clients if they should wait for a response or how they should check for success.

This commit solves that problem by changing guest-suspend-ram to never emit a success response and suggests in the documentation what clients should do to check for success.

---
 qapi-schema-guest.json |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
qapi-schema-guest.json +10 -6
index 88b165c..50e2815 100644
@@ -395,17 +395,21 @@
 # command.  Thus, it's *required* to query QEMU for the presence of the
 # 'system_wakeup' command before issuing guest-suspend-ram.
 #
-# Returns: nothing on success
+# This command does NOT return a response on success. There are two options
+# to check for success:
+#   1. Wait for the SUSPEND QMP event from QEMU
+#   2. Issue the query-status QMP command to confirm the VM status is
+#      "suspended"
+#
+# The following errors may be returned:
 #          If suspend to ram is not supported, Unsupported
 #
-# Notes: o This is an asynchronous request. There's no guarantee a response
-#          will be sent
-#        o It's strongly recommended to issue the guest-sync command before
-#          sending commands when the guest resumes
+# Notes: It's strongly recommended to issue the guest-sync command before
+#        sending commands when the guest resumes
 #
 # Since: 1.1
 ##
-{ 'command': 'guest-suspend-ram' }
+{ 'command': 'guest-suspend-ram', 'success-response': 'no' }
 
 ##
 # @guest-suspend-hybrid
Signature · 1 line
1.7.4.1
#12 lore raw

PATCH 12/13 qemu-ga: fix segv after failure to open log file

In reply to Michael Roth

Currently, if we fail to open the specified log file (generally due to a permissions issue), we'll assign NULL to the logfile handle (stderr, initially) used by the logging routines, which can cause a segfault to occur when we attempt to report the error before exiting.

Instead, only re-assign if the open() was successful.

---
 qemu-ga.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
qemu-ga.c +3 -2
index 3a88333..42e271f 100644
@@ -836,12 +836,13 @@ int main(int argc, char **argv)
             become_daemon(pid_filepath);
         }
         if (log_filepath) {
-            s->log_file = fopen(log_filepath, "a");
-            if (!s->log_file) {
+            FILE *log_file = fopen(log_filepath, "a");
+            if (!log_file) {
                 g_critical("unable to open specified log file: %s",
                            strerror(errno));
                 goto out_bad;
             }
+            s->log_file = log_file;
         }
     }
 
Signature · 1 line
1.7.4.1
#8 lore raw

PATCH 8/13 qemu-ga: become_daemon(): reopen standard fds to /dev/null

In reply to Michael Roth

From: Luiz Capitulino <[email protected]>

This fixes a bug where qemu-ga doesn't suspend the guest because it fails to detect suspend support even when the guest does support suspend. This happens because of the way qemu-ga fds are managed in daemon mode.

When starting qemu-ga with --daemon, become_daemon() will close all standard fds. This will cause qemu-ga to end up with the following fds (if started with 'qemu-ga --daemon'):

    0 -> /dev/vport0p1
    3 -> /run/qemu-ga.pid

Then a guest-suspend-* function is issued. They call bios_supports_mode(), which will call pipe(), and qemu-ga's fd will be:

    0 -> /dev/vport0p1
    1 -> pipe:[16247]
    2 -> pipe:[16247]
    3 -> /run/qemu-ga.pid

bios_supports_mode() forks off a child and blocks waiting for the child to write something to the pipe. The child, however, closes its reading end of the pipe _and_ reopen all standard fds to /dev/null. This will cause the child's fds to be:

    0 -> /dev/null
    1 -> /dev/null
    2 -> /dev/null
    3 -> /run/qemu-ga.pid

In other words, the child's writing end of the pipe is now /dev/null. It writes there and exits. The parent process (blocked on read()) will get an EOF and interpret this as "something unexpected happened in the child, let's assume the guest doesn't support suspend". And suspend will fail.

To solve this problem we have to reopen standard fds to /dev/null in become_daemon(), instead of closing them.

---
 qemu-ga.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
qemu-ga.c +3 -3
index 8d53e04..6e7caed 100644
@@ -445,9 +445,9 @@ static void become_daemon(const char *pidfile)
         goto fail;
     }
 
-    close(STDIN_FILENO);
-    close(STDOUT_FILENO);
-    close(STDERR_FILENO);
+    reopen_fd_to_null(STDIN_FILENO);
+    reopen_fd_to_null(STDOUT_FILENO);
+    reopen_fd_to_null(STDERR_FILENO);
     return;
 
 fail:
Signature · 1 line
1.7.4.1
#11 lore raw

PATCH 11/13 qemu-ga: guest-shutdown: use only async-signal-safe functions

In reply to Michael Roth

From: Luiz Capitulino <[email protected]>

POSIX mandates[1] that a child process of a multi-thread program uses only async-signal-safe functions before exec(). We consider qemu-ga to be multi-thread, because it uses glib.

However, qmp_guest_shutdown() uses functions that are not async-signal-safe. Fix it the following way:

- fclose() -> reopen_fd_to_null()
- execl() -> execle()
- exit() -> _exit()
- drop slog() usage (which is not safe)

[1] http://pubs.opengroup.org/onlinepubs/009695399/functions/fork.html

---
 qapi-schema-guest.json |    3 +--
 qga/commands-posix.c   |   17 +++++++----------
 2 files changed, 8 insertions(+), 12 deletions(-)
qapi-schema-guest.json +1 -2
index 7c6cb21..d4055d2 100644
@@ -126,8 +126,7 @@
 # @guest-shutdown:
 #
 # Initiate guest-activated shutdown. Note: this is an asynchronous
-# shutdown request, with no guaruntee of successful shutdown. Errors
-# will be logged to guest's syslog.
+# shutdown request, with no guarantee of successful shutdown.
 #
 # @mode: #optional "halt", "powerdown" (default), or "reboot"
 #
qga/commands-posix.c +8 -11
index 68da71f..7664be1 100644
@@ -37,8 +37,8 @@
 void qmp_guest_shutdown(bool has_mode, const char *mode, Error **err)
 {
     const char *shutdown_flag;
-    int ret, status;
     pid_t rpid, pid;
+    int status;
 
     slog("guest-shutdown called, mode: %s", mode);
     if (!has_mode || strcmp(mode, "powerdown") == 0) {
@@ -57,16 +57,13 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **err)
     if (pid == 0) {
         /* child, start the shutdown */
         setsid();
-        fclose(stdin);
-        fclose(stdout);
-        fclose(stderr);
-
-        ret = execl("/sbin/shutdown", "shutdown", shutdown_flag, "+0",
-                    "hypervisor initiated shutdown", (char*)NULL);
-        if (ret) {
-            slog("guest-shutdown failed: %s", strerror(errno));
-        }
-        exit(!!ret);
+        reopen_fd_to_null(0);
+        reopen_fd_to_null(1);
+        reopen_fd_to_null(2);
+
+        execle("/sbin/shutdown", "shutdown", shutdown_flag, "+0",
+               "hypervisor initiated shutdown", (char*)NULL, environ);
+        _exit(EXIT_FAILURE);
     } else if (pid < 0) {
         goto exit_err;
     }
Signature · 1 line
1.7.4.1
#7 lore raw

PATCH 7/13 qemu-ga: make reopen_fd_to_null() public

In reply to Michael Roth

From: Luiz Capitulino <[email protected]>

The next commit wants to use it.

---
 qemu-ga.c              |   17 +++++++++++++++++
 qga/commands-posix.c   |   19 -------------------
 qga/guest-agent-core.h |    4 ++++
 3 files changed, 21 insertions(+), 19 deletions(-)
qemu-ga.c +17 -0
index cf61cb9..8d53e04 100644
@@ -140,6 +140,23 @@ static gboolean register_signal_handlers(void)
 
     return true;
 }
+
+/* TODO: use this in place of all post-fork() fclose(std*) callers */
+void reopen_fd_to_null(int fd)
+{
+    int nullfd;
+
+    nullfd = open("/dev/null", O_RDWR);
+    if (nullfd < 0) {
+        return;
+    }
+
+    dup2(nullfd, fd);
+
+    if (nullfd != fd) {
+        close(nullfd);
+    }
+}
 #endif
 
 static void usage(const char *cmd)
qga/commands-posix.c +0 -19
index e448431..adb9b3d 100644
@@ -34,25 +34,6 @@
 #endif
 #endif
 
-#if defined(__linux__)
-/* TODO: use this in place of all post-fork() fclose(std*) callers */
-static void reopen_fd_to_null(int fd)
-{
-    int nullfd;
-
-    nullfd = open("/dev/null", O_RDWR);
-    if (nullfd < 0) {
-        return;
-    }
-
-    dup2(nullfd, fd);
-
-    if (nullfd != fd) {
-        close(nullfd);
-    }
-}
-#endif /* defined(__linux__) */
-
 void qmp_guest_shutdown(bool has_mode, const char *mode, Error **err)
 {
     int ret;
qga/guest-agent-core.h +4 -0
index bbb8b9b..6dba104 100644
@@ -35,3 +35,7 @@ void ga_set_response_delimited(GAState *s);
 bool ga_is_frozen(GAState *s);
 void ga_set_frozen(GAState *s);
 void ga_unset_frozen(GAState *s);
+
+#ifndef _WIN32
+void reopen_fd_to_null(int fd);
+#endif
Signature · 1 line
1.7.4.1
#9 lore raw

PATCH 9/13 qemu-ga: guest-suspend: make the API synchronous

In reply to 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.

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 6e7caed..3a88333 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
#10 lore raw

PATCH 10/13 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 76c8235..68da71f 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
#13 lore raw

PATCH 13/13 qemu-ga: align versioning with QEMU_VERSION

In reply to Michael Roth

Previously qemu-ga version was defined seperately. Since it is aligned with QEMU releases, use QEMU_VERSION instead. This also implies the version bump for 1.1[-rcN] release of qemu-ga.

---
 qemu-ga.c              |    4 ++--
 qga/commands.c         |    2 +-
 qga/guest-agent-core.h |    1 -
 3 files changed, 3 insertions(+), 4 deletions(-)
qemu-ga.c +2 -2
index 42e271f..8199da7 100644
@@ -169,7 +169,7 @@ static void usage(const char *cmd)
 "  -h, --help        display this help and exit\n"
 "\n"
 "Report bugs to <[email protected]>\n"
-    , cmd, QGA_VERSION, QGA_VIRTIO_PATH_DEFAULT, QGA_PIDFILE_DEFAULT,
+    , cmd, QEMU_VERSION, QGA_VIRTIO_PATH_DEFAULT, QGA_PIDFILE_DEFAULT,
     QGA_STATEDIR_DEFAULT);
 }
 
@@ -729,7 +729,7 @@ int main(int argc, char **argv)
             log_level = G_LOG_LEVEL_MASK;
             break;
         case 'V':
-            printf("QEMU Guest Agent %s\n", QGA_VERSION);
+            printf("QEMU Guest Agent %s\n", QEMU_VERSION);
             return 0;
         case 'd':
             daemonize = 1;
qga/commands.c +1 -1
index 5bcceaa..46b0b08 100644
@@ -52,7 +52,7 @@ struct GuestAgentInfo *qmp_guest_info(Error **err)
     GuestAgentCommandInfoList *cmd_info_list;
     char **cmd_list_head, **cmd_list;
 
-    info->version = g_strdup(QGA_VERSION);
+    info->version = g_strdup(QEMU_VERSION);
 
     cmd_list_head = cmd_list = qmp_get_command_list();
     if (*cmd_list_head == NULL) {
qga/guest-agent-core.h +0 -1
index 6dba104..49a7abe 100644
@@ -13,7 +13,6 @@
 #include "qapi/qmp-core.h"
 #include "qemu-common.h"
 
-#define QGA_VERSION "1.0"
 #define QGA_READ_COUNT_DEFAULT 4096
 
 typedef struct GAState GAState;
Signature · 1 line
1.7.4.1
#14 lore raw
In reply to Michael Roth
Quoted 11 lines · On Tue, 15 May 2012 09:48:46 -0500 Michael Roth <[email protected]>…

The following changes since commit 76ee152a86d5f2533443ce4d2be6fe253cfb3c45:

Update version to 1.1.0-rc2 (2012-05-14 17:56:50 -0500)

are available in the git repository at:
git://github.com/mdroth/qemu.git qga-pull-5-15-12

The bulk of these patches finish out the transition to making guest-suspend*/guest-shutdown forgo sending a response on success, and making them synchronous on the guest side such that errors can be be reported back to the host.

ping?