qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PULL 0/3] Misc QGA patches for 2025-02-26
@ 2025-02-26 12:21 Konstantin Kostiuk
  2025-02-26 12:21 ` [PULL 1/3] qga: Add log to guest-fsfreeze-thaw command Konstantin Kostiuk
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Konstantin Kostiuk @ 2025-02-26 12:21 UTC (permalink / raw)
  To: qemu-devel, Peter Maydell, Stefan Hajnoczi

The following changes since commit b69801dd6b1eb4d107f7c2f643adf0a4e3ec9124:

  Merge tag 'for_upstream' of https://git.kernel.org/pub/scm/virt/kvm/mst/qemu into staging (2025-02-22 05:06:39 +0800)

are available in the Git repository at:

  https://github.com/kostyanf14/qemu.git tags/qga-pull-2025-02-26

for you to fetch changes up to c6f5dd7ac8ef62dcdec4cdeda1467c658161afff:

  qga: Don't daemonize before channel is initialized (2025-02-26 13:34:25 +0200)

----------------------------------------------------------------
qga-pull-2025-02-26

----------------------------------------------------------------
Konstantin Kostiuk (1):
      qga: Add log to guest-fsfreeze-thaw command

Michal Privoznik (2):
      qga: Invert logic on return value in main()
      qga: Don't daemonize before channel is initialized

 qga/commands-posix.c |  2 ++
 qga/commands-win32.c |  3 +++
 qga/main.c           | 31 +++++++++++++++++++++----------
 3 files changed, 26 insertions(+), 10 deletions(-)

--
2.48.1



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PULL 1/3] qga: Add log to guest-fsfreeze-thaw command
  2025-02-26 12:21 [PULL 0/3] Misc QGA patches for 2025-02-26 Konstantin Kostiuk
@ 2025-02-26 12:21 ` Konstantin Kostiuk
  2025-02-26 12:21 ` [PULL 2/3] qga: Invert logic on return value in main() Konstantin Kostiuk
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Konstantin Kostiuk @ 2025-02-26 12:21 UTC (permalink / raw)
  To: qemu-devel, Peter Maydell, Stefan Hajnoczi

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Message-ID: <20241216154552.213961-2-kkostiuk@redhat.com>
Signed-off-by: Konstantin Kostiuk <kkostiuk@redhat.com>
---
 qga/commands-posix.c | 2 ++
 qga/commands-win32.c | 3 +++
 2 files changed, 5 insertions(+)

diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index 6e3c15f539..12bc086d79 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -805,8 +805,10 @@ int64_t qmp_guest_fsfreeze_thaw(Error **errp)
     int ret;
 
     ret = qmp_guest_fsfreeze_do_thaw(errp);
+
     if (ret >= 0) {
         ga_unset_frozen(ga_state);
+        slog("guest-fsthaw called");
         execute_fsfreeze_hook(FSFREEZE_HOOK_THAW, errp);
     } else {
         ret = 0;
diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index 99c026c0a0..749fdf8895 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -1273,6 +1273,9 @@ int64_t qmp_guest_fsfreeze_thaw(Error **errp)
     qga_vss_fsfreeze(&i, false, NULL, errp);
 
     ga_unset_frozen(ga_state);
+
+    slog("guest-fsthaw called");
+
     return i;
 }
 
-- 
2.48.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PULL 2/3] qga: Invert logic on return value in main()
  2025-02-26 12:21 [PULL 0/3] Misc QGA patches for 2025-02-26 Konstantin Kostiuk
  2025-02-26 12:21 ` [PULL 1/3] qga: Add log to guest-fsfreeze-thaw command Konstantin Kostiuk
@ 2025-02-26 12:21 ` Konstantin Kostiuk
  2025-02-26 12:21 ` [PULL 3/3] qga: Don't daemonize before channel is initialized Konstantin Kostiuk
  2025-03-03 12:12 ` [PULL 0/3] Misc QGA patches for 2025-02-26 Stefan Hajnoczi
  3 siblings, 0 replies; 5+ messages in thread
From: Konstantin Kostiuk @ 2025-02-26 12:21 UTC (permalink / raw)
  To: qemu-devel, Peter Maydell, Stefan Hajnoczi

From: Michal Privoznik <mprivozn@redhat.com>

Current logic on return value ('ret' variable) in main() is error
prone. The variable is initialized to EXIT_SUCCESS and then set
to EXIT_FAILURE on error paths. This makes it very easy to forget
to set the variable to indicate error when adding new error path,
as is demonstrated by handling of initialize_agent() failure.
It's simply lacking setting of the variable.

There's just one case where success should be indicated: when
dumping the config ('-D' cmd line argument).

To resolve this, initialize the variable to failure value and set
it explicitly to success value in that one specific case.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com>
Message-ID: <8a28265f50177a8dc4c10fcf4146e85a7fd748ee.1736261360.git.mprivozn@redhat.com>
Signed-off-by: Konstantin Kostiuk <kkostiuk@redhat.com>
---
 qga/main.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/qga/main.c b/qga/main.c
index 531853e13d..eccfa33871 100644
--- a/qga/main.c
+++ b/qga/main.c
@@ -1579,7 +1579,7 @@ static void stop_agent(GAState *s, bool requested)
 
 int main(int argc, char **argv)
 {
-    int ret = EXIT_SUCCESS;
+    int ret = EXIT_FAILURE;
     GAState *s;
     GAConfig *config = g_new0(GAConfig, 1);
     int socket_activation;
@@ -1607,7 +1607,6 @@ int main(int argc, char **argv)
     socket_activation = check_socket_activation();
     if (socket_activation > 1) {
         g_critical("qemu-ga only supports listening on one socket");
-        ret = EXIT_FAILURE;
         goto end;
     }
     if (socket_activation) {
@@ -1631,7 +1630,6 @@ int main(int argc, char **argv)
 
         if (!config->method) {
             g_critical("unsupported listen fd type");
-            ret = EXIT_FAILURE;
             goto end;
         }
     } else if (config->channel_path == NULL) {
@@ -1643,13 +1641,13 @@ int main(int argc, char **argv)
             config->channel_path = g_strdup(QGA_SERIAL_PATH_DEFAULT);
         } else {
             g_critical("must specify a path for this channel");
-            ret = EXIT_FAILURE;
             goto end;
         }
     }
 
     if (config->dumpconf) {
         config_dump(config);
+        ret = EXIT_SUCCESS;
         goto end;
     }
 
@@ -1664,6 +1662,7 @@ int main(int argc, char **argv)
         SERVICE_TABLE_ENTRY service_table[] = {
             { (char *)QGA_SERVICE_NAME, service_main }, { NULL, NULL } };
         StartServiceCtrlDispatcher(service_table);
+        ret = EXIT_SUCCESS;
     } else {
         ret = run_agent(s);
     }
-- 
2.48.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PULL 3/3] qga: Don't daemonize before channel is initialized
  2025-02-26 12:21 [PULL 0/3] Misc QGA patches for 2025-02-26 Konstantin Kostiuk
  2025-02-26 12:21 ` [PULL 1/3] qga: Add log to guest-fsfreeze-thaw command Konstantin Kostiuk
  2025-02-26 12:21 ` [PULL 2/3] qga: Invert logic on return value in main() Konstantin Kostiuk
@ 2025-02-26 12:21 ` Konstantin Kostiuk
  2025-03-03 12:12 ` [PULL 0/3] Misc QGA patches for 2025-02-26 Stefan Hajnoczi
  3 siblings, 0 replies; 5+ messages in thread
From: Konstantin Kostiuk @ 2025-02-26 12:21 UTC (permalink / raw)
  To: qemu-devel, Peter Maydell, Stefan Hajnoczi

From: Michal Privoznik <mprivozn@redhat.com>

If the agent is set to daemonize but for whatever reason fails to
init the channel, the error message is lost. Worse, the agent
daemonizes needlessly and returns success. For instance:

  # qemu-ga -m virtio-serial \
            -p /dev/nonexistent_device \
            -f /run/qemu-ga.pid \
            -t /run \
            -d
  # echo $?
  0

This makes it needlessly hard for init scripts to detect a
failure in qemu-ga startup. Though, they shouldn't pass '-d' in
the first place.

Let's open the channel first and only after that become a daemon.

Related bug: https://bugs.gentoo.org/810628

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com>
Message-ID: <7a42b0cbda5c7e01cf76bc1b29a1210cd018fa78.1736261360.git.mprivozn@redhat.com>
Signed-off-by: Konstantin Kostiuk <kkostiuk@redhat.com>
---
 qga/main.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/qga/main.c b/qga/main.c
index eccfa33871..72c39b042f 100644
--- a/qga/main.c
+++ b/qga/main.c
@@ -1430,7 +1430,6 @@ static GAState *initialize_agent(GAConfig *config, int socket_activation)
         if (config->daemonize) {
             /* delay opening/locking of pidfile till filesystems are unfrozen */
             s->deferred_options.pid_filepath = config->pid_filepath;
-            become_daemon(NULL);
         }
         if (config->log_filepath) {
             /* delay opening the log file till filesystems are unfrozen */
@@ -1438,9 +1437,6 @@ static GAState *initialize_agent(GAConfig *config, int socket_activation)
         }
         ga_disable_logging(s);
     } else {
-        if (config->daemonize) {
-            become_daemon(config->pid_filepath);
-        }
         if (config->log_filepath) {
             FILE *log_file = ga_open_logfile(config->log_filepath);
             if (!log_file) {
@@ -1487,6 +1483,20 @@ static GAState *initialize_agent(GAConfig *config, int socket_activation)
 
     ga_apply_command_filters(s);
 
+    if (!channel_init(s, s->config->method, s->config->channel_path,
+                      s->socket_activation ? FIRST_SOCKET_ACTIVATION_FD : -1)) {
+        g_critical("failed to initialize guest agent channel");
+        return NULL;
+    }
+
+    if (config->daemonize) {
+        if (ga_is_frozen(s)) {
+            become_daemon(NULL);
+        } else {
+            become_daemon(config->pid_filepath);
+        }
+    }
+
     ga_state = s;
     return s;
 }
@@ -1513,8 +1523,9 @@ static void cleanup_agent(GAState *s)
 
 static int run_agent_once(GAState *s)
 {
-    if (!channel_init(s, s->config->method, s->config->channel_path,
-                      s->socket_activation ? FIRST_SOCKET_ACTIVATION_FD : -1)) {
+    if (!s->channel &&
+        channel_init(s, s->config->method, s->config->channel_path,
+                     s->socket_activation ? FIRST_SOCKET_ACTIVATION_FD : -1)) {
         g_critical("failed to initialize guest agent channel");
         return EXIT_FAILURE;
     }
@@ -1523,6 +1534,7 @@ static int run_agent_once(GAState *s)
 
     if (s->channel) {
         ga_channel_free(s->channel);
+        s->channel = NULL;
     }
 
     return EXIT_SUCCESS;
-- 
2.48.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PULL 0/3] Misc QGA patches for 2025-02-26
  2025-02-26 12:21 [PULL 0/3] Misc QGA patches for 2025-02-26 Konstantin Kostiuk
                   ` (2 preceding siblings ...)
  2025-02-26 12:21 ` [PULL 3/3] qga: Don't daemonize before channel is initialized Konstantin Kostiuk
@ 2025-03-03 12:12 ` Stefan Hajnoczi
  3 siblings, 0 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2025-03-03 12:12 UTC (permalink / raw)
  To: Konstantin Kostiuk; +Cc: qemu-devel, Peter Maydell, Stefan Hajnoczi

[-- Attachment #1: Type: text/plain, Size: 116 bytes --]

Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/10.0 for any user-visible changes.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-03-03 12:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-26 12:21 [PULL 0/3] Misc QGA patches for 2025-02-26 Konstantin Kostiuk
2025-02-26 12:21 ` [PULL 1/3] qga: Add log to guest-fsfreeze-thaw command Konstantin Kostiuk
2025-02-26 12:21 ` [PULL 2/3] qga: Invert logic on return value in main() Konstantin Kostiuk
2025-02-26 12:21 ` [PULL 3/3] qga: Don't daemonize before channel is initialized Konstantin Kostiuk
2025-03-03 12:12 ` [PULL 0/3] Misc QGA patches for 2025-02-26 Stefan Hajnoczi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).