Skip to contentSkip to conversation

util/async-teardown: appear in query-command-line-options

PATCH Superseded Claudio Imbrenda 4 participants 6 messages Mar 27, 2023 – Mar 28, 2023

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v5 cover util/async-teardown: appear in query-command-line-options

Add new -teardown option with an async=on|off parameter. It is visible in the output of query-command-line-options QMP command, so it can be discovered and used by libvirt.

The option -async-teardown is now redundant. We'd normally deprecate it and remove it after a grace period, but it was introduced only in the previous version and it had no users, since it was not visible in the query-command-line-options QMP command. Drop it.

v4->v5
* reword commit message [Markus]
* document the removal of the -async-teardown commandline option in docs/about/removed-features.rst [Markus]

v3->v4
* completely remove the useless -async-teardown option, since it was not wired up properly and it had no users [thomas]
* QEMU should be always uppercase in text and documentation [thomas]
* if the new -teardown option fails to parse, exit immediately instead of returning an error [thomas]

v2->v3
* add a new teardown option with an async parameter [Markus]
* reworded documentation of existing -async-teardown option so that it points to the new teardown option

v1->v2
* remove the unneeded .implied_opt_name initializer [Thomas]

Claudio Imbrenda (1):
util/async-teardown: wire up query-command-line-options

 docs/about/removed-features.rst |  5 +++++
 os-posix.c                      | 15 +++++++++++++--
 qemu-options.hx                 | 33 +++++++++++++++++++--------------
 util/async-teardown.c           | 21 +++++++++++++++++++++
 4 files changed, 58 insertions(+), 16 deletions(-)
Signature · 1 line
2.39.2
#1 lore raw

PATCH v5 1/1 util/async-teardown: wire up query-command-line-options

Add new -teardown option with an async=on|off parameter. It is visible in the output of query-command-line-options QMP command, so it can be discovered and used by libvirt.

The option -async-teardown is now redundant. We'd normally deprecate it and remove it after a grace period, but it was introduced only in the previous version and it had no users, since it was not visible in the query-command-line-options QMP command. Drop it.

Fixes c891c24b1a ("os-posix: asynchronous teardown for shutdown on Linux")
---
 docs/about/removed-features.rst |  5 +++++
 os-posix.c                      | 15 +++++++++++++--
 qemu-options.hx                 | 33 +++++++++++++++++++--------------
 util/async-teardown.c           | 21 +++++++++++++++++++++
 4 files changed, 58 insertions(+), 16 deletions(-)
docs/about/removed-features.rst +5 -0
index 5b258b446b..6d89f69be9 100644
@@ -416,6 +416,11 @@ Input parameters that take a size value should only use a size suffix
 the value is hexadecimal.  That is, '0x20M' should be written either as
 '32M' or as '0x2000000'.
 
+``-async-teardown`` (removed in 8.0)
+,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+
+Use ``-teardown async=on`` instead.
+
 ``-chardev`` backend aliases ``tty`` and ``parport`` (removed in 8.0)
 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 
os-posix.c +13 -2
index 5adc69f560..c1ca7b1cb3 100644
@@ -36,6 +36,8 @@
 #include "qemu/log.h"
 #include "sysemu/runstate.h"
 #include "qemu/cutils.h"
+#include "qemu/config-file.h"
+#include "qemu/option.h"
 
 #ifdef CONFIG_LINUX
 #include <sys/prctl.h>
@@ -132,6 +134,8 @@ static bool os_parse_runas_uid_gid(const char *optarg)
  */
 int os_parse_cmd_args(int index, const char *optarg)
 {
+    QemuOpts *opts;
+
     switch (index) {
     case QEMU_OPTION_runas:
         user_pwd = getpwnam(optarg);
@@ -152,8 +156,15 @@ int os_parse_cmd_args(int index, const char *optarg)
         daemonize = 1;
         break;
 #if defined(CONFIG_LINUX)
-    case QEMU_OPTION_asyncteardown:
-        init_async_teardown();
+    case QEMU_OPTION_teardown:
+        opts = qemu_opts_parse_noisily(qemu_find_opts("teardown"),
+                                       optarg, false);
+        if (!opts) {
+            exit(1);
+        }
+        if (qemu_opt_get_bool(opts, "async", false)) {
+            init_async_teardown();
+        }
         break;
 #endif
     default:
qemu-options.hx +19 -14
index d42f60fb91..6a69b84f3c 100644
@@ -4763,23 +4763,28 @@ DEF("qtest", HAS_ARG, QEMU_OPTION_qtest, "", QEMU_ARCH_ALL)
 DEF("qtest-log", HAS_ARG, QEMU_OPTION_qtest_log, "", QEMU_ARCH_ALL)
 
 #ifdef __linux__
-DEF("async-teardown", 0, QEMU_OPTION_asyncteardown,
-    "-async-teardown enable asynchronous teardown\n",
+DEF("teardown", HAS_ARG, QEMU_OPTION_teardown,
+    "-teardown async[=on|off]\n"
+    "                process teardown options\n"
+    "                async=on enables asynchronous teardown\n"
+   ,
     QEMU_ARCH_ALL)
-#endif
 SRST
-``-async-teardown``
-    Enable asynchronous teardown. A new process called "cleanup/<QEMU_PID>"
-    will be created at startup sharing the address space with the main qemu
-    process, using clone. It will wait for the main qemu process to
-    terminate completely, and then exit.
-    This allows qemu to terminate very quickly even if the guest was
-    huge, leaving the teardown of the address space to the cleanup
-    process. Since the cleanup process shares the same cgroups as the
-    main qemu process, accounting is performed correctly. This only
-    works if the cleanup process is not forcefully killed with SIGKILL
-    before the main qemu process has terminated completely.
+``-teardown``
+    Set process teardown options.
+
+    ``async=on`` enables asynchronous teardown. A new process called
+    "cleanup/<QEMU_PID>" will be created at startup sharing the address
+    space with the main QEMU process, using clone. It will wait for the
+    main QEMU process to terminate completely, and then exit. This allows
+    QEMU to terminate very quickly even if the guest was huge, leaving the
+    teardown of the address space to the cleanup process. Since the cleanup
+    process shares the same cgroups as the main QEMU process, accounting is
+    performed correctly. This only works if the cleanup process is not
+    forcefully killed with SIGKILL before the main QEMU process has
+    terminated completely.
 ERST
+#endif
 
 DEF("msg", HAS_ARG, QEMU_OPTION_msg,
     "-msg [timestamp[=on|off]][,guest-name=[on|off]]\n"
util/async-teardown.c +21 -0
index 62cdeb0f20..4a5dbce958 100644
@@ -12,6 +12,9 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/config-file.h"
+#include "qemu/option.h"
+#include "qemu/module.h"
 #include <dirent.h>
 #include <sys/prctl.h>
 #include <sched.h>
@@ -144,3 +147,21 @@ void init_async_teardown(void)
     clone(async_teardown_fn, new_stack_for_clone(), CLONE_VM, NULL);
     sigprocmask(SIG_SETMASK, &old_signals, NULL);
 }
+
+static QemuOptsList qemu_teardown_opts = {
+    .name = "teardown",
+    .head = QTAILQ_HEAD_INITIALIZER(qemu_teardown_opts.head),
+    .desc = {
+        {
+            .name = "async",
+            .type = QEMU_OPT_BOOL,
+        },
+        { /* end of list */ }
+    },
+};
+
+static void register_teardown(void)
+{
+    qemu_add_opts(&qemu_teardown_opts);
+}
+opts_init(register_teardown);
Signature · 1 line
2.39.2
#2 lore raw

Re: [PATCH v5 1/1] util/async-teardown: wire up query-command-line-options

I am honestly not a fan of adding a more complex option,.just because query-command-line-options only returns the square holes whereas here we got a round one.

Can we imagine another functionality that would be added to -teardown? If not, it's not a good design. If it works, I would add a completely dummy (no suboptions) group "async-teardown" and not modify the parsing at all.

Paolo

Il lun 27 mar 2023, 15:35 Claudio Imbrenda <[email protected]> ha scritto:

Quoted 169 lines

Add new -teardown option with an async=on|off parameter. It is visible in the output of query-command-line-options QMP command, so it can be discovered and used by libvirt.

The option -async-teardown is now redundant. We'd normally deprecate it and remove it after a grace period, but it was introduced only in the previous version and it had no users, since it was not visible in the query-command-line-options QMP command. Drop it.

Fixes c891c24b1a ("os-posix: asynchronous teardown for shutdown on Linux")
---
 docs/about/removed-features.rst |  5 +++++
 os-posix.c                      | 15 +++++++++++++--
 qemu-options.hx                 | 33 +++++++++++++++++++--------------
 util/async-teardown.c           | 21 +++++++++++++++++++++
 4 files changed, 58 insertions(+), 16 deletions(-)
docs/about/removed-features.rst +0 -0
index 5b258b446b..6d89f69be9 100644
@@ -416,6 +416,11 @@ Input parameters that take a size value should only

use a size suffix
the value is hexadecimal. That is, '0x20M' should be written either as '32M' or as '0x2000000'.

+``-async-teardown`` (removed in 8.0)
+,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

docs/about/removed-features.rst +3 -0
+
+Use ``-teardown async=on`` instead.
+
 ``-chardev`` backend aliases ``tty`` and ``parport`` (removed in 8.0)
 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
os-posix.c +13 -2
index 5adc69f560..c1ca7b1cb3 100644
@@ -36,6 +36,8 @@
 #include "qemu/log.h"
 #include "sysemu/runstate.h"
 #include "qemu/cutils.h"
+#include "qemu/config-file.h"
+#include "qemu/option.h"
 
 #ifdef CONFIG_LINUX
 #include <sys/prctl.h>
@@ -132,6 +134,8 @@ static bool os_parse_runas_uid_gid(const char *optarg)
  */
 int os_parse_cmd_args(int index, const char *optarg)
 {
+    QemuOpts *opts;
+
     switch (index) {
     case QEMU_OPTION_runas:
         user_pwd = getpwnam(optarg);
@@ -152,8 +156,15 @@ int os_parse_cmd_args(int index, const char *optarg)
         daemonize = 1;
         break;
 #if defined(CONFIG_LINUX)
-    case QEMU_OPTION_asyncteardown:
-        init_async_teardown();
+    case QEMU_OPTION_teardown:
+        opts = qemu_opts_parse_noisily(qemu_find_opts("teardown"),
+                                       optarg, false);
+        if (!opts) {
+            exit(1);
+        }
+        if (qemu_opt_get_bool(opts, "async", false)) {
+            init_async_teardown();
+        }
         break;
 #endif
     default:
qemu-options.hx +5 -5
index d42f60fb91..6a69b84f3c 100644
@@ -4763,23 +4763,28 @@ DEF("qtest", HAS_ARG, QEMU_OPTION_qtest, "",
 QEMU_ARCH_ALL)
 DEF("qtest-log", HAS_ARG, QEMU_OPTION_qtest_log, "", QEMU_ARCH_ALL)
 
 #ifdef __linux__
-DEF("async-teardown", 0, QEMU_OPTION_asyncteardown,
-    "-async-teardown enable asynchronous teardown\n",
+DEF("teardown", HAS_ARG, QEMU_OPTION_teardown,
+    "-teardown async[=on|off]\n"
+    "                process teardown options\n"
+    "                async=on enables asynchronous teardown\n"
+   ,
     QEMU_ARCH_ALL)
-#endif
 SRST
-``-async-teardown``
-    Enable asynchronous teardown. A new process called

"cleanup/<QEMU_PID>"
- will be created at startup sharing the address space with the main
qemu

qemu-options.hx +9 -8
-    process, using clone. It will wait for the main qemu process to
-    terminate completely, and then exit.
-    This allows qemu to terminate very quickly even if the guest was
-    huge, leaving the teardown of the address space to the cleanup
-    process. Since the cleanup process shares the same cgroups as the
-    main qemu process, accounting is performed correctly. This only
-    works if the cleanup process is not forcefully killed with SIGKILL
-    before the main qemu process has terminated completely.
+``-teardown``
+    Set process teardown options.
+
+    ``async=on`` enables asynchronous teardown. A new process called
+    "cleanup/<QEMU_PID>" will be created at startup sharing the address
+    space with the main QEMU process, using clone. It will wait for the
+    main QEMU process to terminate completely, and then exit. This allows
+    QEMU to terminate very quickly even if the guest was huge, leaving the
+    teardown of the address space to the cleanup process. Since the

cleanup
+ process shares the same cgroups as the main QEMU process, accounting
is

qemu-options.hx +4 -0
+    performed correctly. This only works if the cleanup process is not
+    forcefully killed with SIGKILL before the main QEMU process has
+    terminated completely.
 ERST
+#endif
 
 DEF("msg", HAS_ARG, QEMU_OPTION_msg,
     "-msg [timestamp[=on|off]][,guest-name=[on|off]]\n"
util/async-teardown.c +21 -1
index 62cdeb0f20..4a5dbce958 100644
@@ -12,6 +12,9 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/config-file.h"
+#include "qemu/option.h"
+#include "qemu/module.h"
 #include <dirent.h>
 #include <sys/prctl.h>
 #include <sched.h>
@@ -144,3 +147,21 @@ void init_async_teardown(void)
     clone(async_teardown_fn, new_stack_for_clone(), CLONE_VM, NULL);
     sigprocmask(SIG_SETMASK, &old_signals, NULL);
 }
+
+static QemuOptsList qemu_teardown_opts = {
+    .name = "teardown",
+    .head = QTAILQ_HEAD_INITIALIZER(qemu_teardown_opts.head),
+    .desc = {
+        {
+            .name = "async",
+            .type = QEMU_OPT_BOOL,
+        },
+        { /* end of list */ }
+    },
+};
+
+static void register_teardown(void)
+{
+    qemu_add_opts(&qemu_teardown_opts);
+}
+opts_init(register_teardown);
--

2.39.2

#3 lore raw

Re: [PATCH v5 1/1] util/async-teardown: wire up query-command-line-options

Quoted 7 lines · Paolo Bonzini

I am honestly not a fan of adding a more complex option,.just because query-command-line-options only returns the square holes whereas here we got a round one.

Can we imagine another functionality that would be added to -teardown? If not, it's not a good design. If it works, I would add a completely dummy (no suboptions) group "async-teardown" and not modify the parsing at all.

Does v2 implement your suggestion?
Message-Id: <[email protected]>

I dislike it, because it makes query-command-line-options claim -async-teardown has an option argument with unknown keys, which is plainly wrong, and must be treated as a special case. Worse, a new kind of special case.

Can we have a QMP command, so libvirt can use query-qmp-schema?

In case QMP becomes functional too late for the command to actually
work: make it always fail for now. It can still serve as a witness for -async-teardown. If we rework QEMU startup so that QMP can do everything the CLI can do, we'll make the QMP command work.

#4 lore raw

Re: [PATCH v5 1/1] util/async-teardown: wire up query-command-line-options

Quoted 10 lines · Markus Armbruster
Quoted 7 lines · Paolo Bonzini

I am honestly not a fan of adding a more complex option,.just because query-command-line-options only returns the square holes whereas here we got a round one.

Can we imagine another functionality that would be added to -teardown? If not, it's not a good design. If it works, I would add a completely dummy (no suboptions) group "async-teardown" and not modify the parsing at all.

Quoted 7 lines

Does v2 implement your suggestion?
Message-Id: <[email protected]>

I dislike it, because it makes query-command-line-options claim -async-teardown has an option argument with unknown keys, which is plainly wrong, and must be treated as a special case. Worse, a new kind of special case.

I agree with Markus, it sounds like a bad idea to create a new special case for this.

Paolo, what do you think of my "-run-with" suggestion here:

https://lore.kernel.org/qemu-devel/[email protected]/

I still think that this is a good idea, even if it is a "grab-bag" as Markus said, it would give us a place where we could wire future similar options, too, without running into this problem here again and again.

Quoted 1 line

Can we have a QMP command, so libvirt can use query-qmp-schema?

Question is whether this could be toggled during runtime...? Or did you mean a command that just queries the setting of the option, e.g. "query-async-teardown" which then reports whether it is enabled or not?

Quoted 4 lines

In case QMP becomes functional too late for the command to actually
work: make it always fail for now. It can still serve as a witness for -async-teardown. If we rework QEMU startup so that QMP can do everything the CLI can do, we'll make the QMP command work.

Adding non-working functions sounds ugly... Anyway, we're slowly running out of time for QEMU 8.0 ... if we can't find an easy solution, I think we should rather postpone this to the next cycle instead of rushing unfinished stuff now.

Thomas

#5 lore raw

Re: [PATCH v5 1/1] util/async-teardown: wire up query-command-line-options

Quoted 24 lines · Thomas Huth
Quoted 10 lines · Markus Armbruster
Quoted 7 lines · Paolo Bonzini

I am honestly not a fan of adding a more complex option,.just because query-command-line-options only returns the square holes whereas here we got a round one.

Can we imagine another functionality that would be added to -teardown? If not, it's not a good design. If it works, I would add a completely dummy (no suboptions) group "async-teardown" and not modify the parsing at all.

Quoted 7 lines

Does v2 implement your suggestion?
Message-Id: <[email protected]>

I dislike it, because it makes query-command-line-options claim -async-teardown has an option argument with unknown keys, which is plainly wrong, and must be treated as a special case. Worse, a new kind of special case.

I agree with Markus, it sounds like a bad idea to create a new special case for this.

Paolo, what do you think of my "-run-with" suggestion here:

Quoted 7 lines

https://lore.kernel.org/qemu-devel/[email protected]/

I still think that this is a good idea, even if it is a "grab-bag" as Markus said, it would give us a place where we could wire future similar options, too, without running into this problem here again and again.

Quoted 1 line

Can we have a QMP command, so libvirt can use query-qmp-schema?

Question is whether this could be toggled during runtime...? Or did you mean a command that just queries the setting of the option, e.g. "query-async-teardown" which then reports whether it is enabled or not?

Mildly ugly, as the command is pretty much useless except as a witness for the CLI option. We've done this before.

Quoted 6 lines
Quoted 4 lines

In case QMP becomes functional too late for the command to actually
work: make it always fail for now. It can still serve as a witness for -async-teardown. If we rework QEMU startup so that QMP can do everything the CLI can do, we'll make the QMP command work.

Adding non-working functions sounds ugly...

Non-working functions that could totally work with QEMU startup reworked are only mildly ugly, I think.

Quoted 1 line

Anyway, we're slowly running out of time for QEMU 8.0 ... if we can't find an easy solution, I think we should rather postpone this to the next cycle instead of rushing unfinished stuff now.

Yes.

I think we can still do it if we agree quickly on which kind of ugly we hate the least.

Adding -async-teardown as a stable interface was premature. We should have marked it unstable when no libvirt patch was ready when we cut QEMU 7.2.

Adding new external interfaces is still not hard enough :)