qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RFC 0/7] move softmmu options processing from os-posix.c to vl.c
@ 2023-08-12 12:47 Michael Tokarev
  2023-08-12 12:47 ` [PATCH RFC 1/7] include/sysemu/os-posix.h: move *daemonize* declaration together Michael Tokarev
                   ` (7 more replies)
  0 siblings, 8 replies; 17+ messages in thread
From: Michael Tokarev @ 2023-08-12 12:47 UTC (permalink / raw)
  To: qemu-devel; +Cc: Michael Tokarev

qemu_init() calls os_parse_cmd_args(), which is obviously a very vl.c-specicic
piece of code.  It looks like when moving vl.c to softmmu/, os-posix.c should've
been moved too (together with os-win32.c).  But there are other functions in
os-posix.c which are used by other parts of the code, eg qemu-nbd or
qemu-storage-daemon both uses parts from there.  The result is rather ugly.
One of the side-effects is that even if system build is disabled, we still
have to compile util/async-teardown.c, since it is used in os-posix.c, - and
this one can not be built on ia64 due to lack of clone syscall.  But qemu-nbd
does not need async-teardown, which is also very softmmu-specific.

This patchset tries to address these defects.  It moves the "bottom half" of
vl.c options processing back into vl.c, effectively undoing commit 59a5264b99434
from 2010.  We do not have many os-specific options, and this move makes
qemu_init() the only function which processes options, all in the single
place, which is, in my opinion, easier to manage.

Before this move, lower-level constructs (chroot, runas) are being exported.

In the end, we have almost no softmmu-related things in os-posix.c, and the
same functionality can be actually used in qemu-storage-daemon or qemu-nbd.
For qemu-nbd, it is now possible to switch to using -runas/-chroot/etc the
same way as qemu-storage-daemon does, instead of having one more abstraction
named qemu_daemon().

Michael Tokarev (7):
  include/sysemu/os-posix.h: move *daemonize* declaration together
  os-posix: create and export os_set_runas()
  os-posix.c: create and export os_set_chroot()
  os-posix.c, softmmu/vl.c: move os_parse_cmd_args() into qemu_init()
  softmmu/vl.c: inline include/qemu/qemu-options.h into vl.c
  os-posix.c: move code around
  util/async-teardown.c: move to softmmu/, only build it when system
    build is requested

 include/qemu/qemu-options.h        |  41 --------
 include/sysemu/os-posix.h          |   8 +-
 include/sysemu/os-win32.h          |   1 -
 os-posix.c                         | 152 +++++++++--------------------
 {util => softmmu}/async-teardown.c |   0
 softmmu/meson.build                |   1 +
 softmmu/vl.c                       |  87 ++++++++++++++++-
 util/meson.build                   |   1 -
 8 files changed, 134 insertions(+), 157 deletions(-)
 delete mode 100644 include/qemu/qemu-options.h
 rename {util => softmmu}/async-teardown.c (100%)

-- 
2.39.2



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

* [PATCH RFC 1/7] include/sysemu/os-posix.h: move *daemonize* declaration together
  2023-08-12 12:47 [PATCH RFC 0/7] move softmmu options processing from os-posix.c to vl.c Michael Tokarev
@ 2023-08-12 12:47 ` Michael Tokarev
  2023-08-15 16:22   ` Eric Blake
  2023-08-12 12:47 ` [PATCH RFC 2/7] os-posix: create and export os_set_runas() Michael Tokarev
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 17+ messages in thread
From: Michael Tokarev @ 2023-08-12 12:47 UTC (permalink / raw)
  To: qemu-devel; +Cc: Michael Tokarev

Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---
 include/sysemu/os-posix.h | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/include/sysemu/os-posix.h b/include/sysemu/os-posix.h
index 1030d39904..65b9c94e91 100644
--- a/include/sysemu/os-posix.h
+++ b/include/sysemu/os-posix.h
@@ -47,13 +47,12 @@ void os_set_line_buffering(void);
 void os_setup_early_signal_handling(void);
 void os_set_proc_name(const char *s);
 void os_setup_signal_handling(void);
+int os_set_daemonize(bool d);
+bool is_daemonized(void);
 void os_daemonize(void);
 void os_setup_post(void);
 int os_mlock(void);
 
-int os_set_daemonize(bool d);
-bool is_daemonized(void);
-
 /**
  * qemu_alloc_stack:
  * @sz: pointer to a size_t holding the requested usable stack size
-- 
2.39.2



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

* [PATCH RFC 2/7] os-posix: create and export os_set_runas()
  2023-08-12 12:47 [PATCH RFC 0/7] move softmmu options processing from os-posix.c to vl.c Michael Tokarev
  2023-08-12 12:47 ` [PATCH RFC 1/7] include/sysemu/os-posix.h: move *daemonize* declaration together Michael Tokarev
@ 2023-08-12 12:47 ` Michael Tokarev
  2023-08-15 16:25   ` Eric Blake
  2023-08-12 12:47 ` [PATCH RFC 3/7] os-posix.c: create and export os_set_chroot() Michael Tokarev
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 17+ messages in thread
From: Michael Tokarev @ 2023-08-12 12:47 UTC (permalink / raw)
  To: qemu-devel; +Cc: Michael Tokarev

Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---
 include/sysemu/os-posix.h |  1 +
 os-posix.c                | 23 ++++++++++++++++-------
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/include/sysemu/os-posix.h b/include/sysemu/os-posix.h
index 65b9c94e91..d32630f9e7 100644
--- a/include/sysemu/os-posix.h
+++ b/include/sysemu/os-posix.h
@@ -50,6 +50,7 @@ void os_setup_signal_handling(void);
 int os_set_daemonize(bool d);
 bool is_daemonized(void);
 void os_daemonize(void);
+bool os_set_runas(const char *optarg);
 void os_setup_post(void);
 int os_mlock(void);
 
diff --git a/os-posix.c b/os-posix.c
index cfcb96533c..0202bb4898 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -102,8 +102,14 @@ void os_set_proc_name(const char *s)
 #endif
 }
 
-
-static bool os_parse_runas_uid_gid(const char *optarg)
+/*
+ * Prepare to change user ID. optarg can be one of 3 forms:
+ *   - a username, in which case user ID will be changed to its uid,
+ *     with primary and supplementary groups set up too;
+ *   - a nemeric uid, in which case only the uid will be set;
+ *   - a pair of numeric uid:gid.
+ */
+bool os_set_runas(const char *optarg)
 {
     unsigned long lv;
     const char *ep;
@@ -111,6 +117,13 @@ static bool os_parse_runas_uid_gid(const char *optarg)
     gid_t got_gid;
     int rc;
 
+    user_pwd = getpwnam(optarg);
+    if (user_pwd) {
+        user_uid = -1;
+        user_gid = -1;
+        return true;
+    }
+
     rc = qemu_strtoul(optarg, &ep, 0, &lv);
     got_uid = lv; /* overflow here is ID in C99 */
     if (rc || *ep != ':' || got_uid != lv || got_uid == (uid_t)-1) {
@@ -137,11 +150,7 @@ int os_parse_cmd_args(int index, const char *optarg)
 {
     switch (index) {
     case QEMU_OPTION_runas:
-        user_pwd = getpwnam(optarg);
-        if (user_pwd) {
-            user_uid = -1;
-            user_gid = -1;
-        } else if (!os_parse_runas_uid_gid(optarg)) {
+        if (!os_set_runas(optarg)) {
             error_report("User \"%s\" doesn't exist"
                          " (and is not <uid>:<gid>)",
                          optarg);
-- 
2.39.2



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

* [PATCH RFC 3/7] os-posix.c: create and export os_set_chroot()
  2023-08-12 12:47 [PATCH RFC 0/7] move softmmu options processing from os-posix.c to vl.c Michael Tokarev
  2023-08-12 12:47 ` [PATCH RFC 1/7] include/sysemu/os-posix.h: move *daemonize* declaration together Michael Tokarev
  2023-08-12 12:47 ` [PATCH RFC 2/7] os-posix: create and export os_set_runas() Michael Tokarev
@ 2023-08-12 12:47 ` Michael Tokarev
  2023-08-15 16:26   ` Eric Blake
  2023-08-12 12:47 ` [PATCH RFC 4/7] os-posix.c, softmmu/vl.c: move os_parse_cmd_args() into qemu_init() Michael Tokarev
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 17+ messages in thread
From: Michael Tokarev @ 2023-08-12 12:47 UTC (permalink / raw)
  To: qemu-devel; +Cc: Michael Tokarev

Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---
 include/sysemu/os-posix.h | 1 +
 os-posix.c                | 9 +++++++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/include/sysemu/os-posix.h b/include/sysemu/os-posix.h
index d32630f9e7..8a66763395 100644
--- a/include/sysemu/os-posix.h
+++ b/include/sysemu/os-posix.h
@@ -51,6 +51,7 @@ int os_set_daemonize(bool d);
 bool is_daemonized(void);
 void os_daemonize(void);
 bool os_set_runas(const char *optarg);
+void os_set_chroot(const char *optarg);
 void os_setup_post(void);
 int os_mlock(void);
 
diff --git a/os-posix.c b/os-posix.c
index 0202bb4898..081f3db685 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -159,7 +159,7 @@ int os_parse_cmd_args(int index, const char *optarg)
         break;
     case QEMU_OPTION_chroot:
         warn_report("option is deprecated, use '-run-with chroot=...' instead");
-        chroot_dir = optarg;
+        os_set_chroot(optarg);
         break;
     case QEMU_OPTION_daemonize:
         daemonize = 1;
@@ -184,7 +184,7 @@ int os_parse_cmd_args(int index, const char *optarg)
 #endif
         str = qemu_opt_get(opts, "chroot");
         if (str) {
-            chroot_dir = str;
+            os_set_chroot(str);
         }
         break;
     }
@@ -232,6 +232,11 @@ static void change_process_uid(void)
     }
 }
 
+void os_set_chroot(const char *optarg)
+{
+    chroot_dir = optarg;
+}
+
 static void change_root(void)
 {
     if (chroot_dir) {
-- 
2.39.2



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

* [PATCH RFC 4/7] os-posix.c, softmmu/vl.c: move os_parse_cmd_args() into qemu_init()
  2023-08-12 12:47 [PATCH RFC 0/7] move softmmu options processing from os-posix.c to vl.c Michael Tokarev
                   ` (2 preceding siblings ...)
  2023-08-12 12:47 ` [PATCH RFC 3/7] os-posix.c: create and export os_set_chroot() Michael Tokarev
@ 2023-08-12 12:47 ` Michael Tokarev
  2023-08-15 17:03   ` Eric Blake
  2023-08-12 12:47 ` [PATCH RFC 5/7] softmmu/vl.c: inline include/qemu/qemu-options.h into vl.c Michael Tokarev
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 17+ messages in thread
From: Michael Tokarev @ 2023-08-12 12:47 UTC (permalink / raw)
  To: qemu-devel; +Cc: Michael Tokarev

This will stop linking softmmu-specific os_parse_cmd_args() into every
qemu executable which happens to use other functions from os-posix.c,
such as os_set_line_buffering() or os_setup_signal_handling().

Also, since there's no win32-specific options, *all* option parsing is
now done in softmmu/vl.c:qemu_init(), which is easier to read without
extra indirection, - all options are in the single function now.

This effectively reverts commit 59a5264b99434.

Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---
 include/sysemu/os-posix.h |  1 -
 include/sysemu/os-win32.h |  1 -
 os-posix.c                | 79 ---------------------------------------
 softmmu/vl.c              | 76 +++++++++++++++++++++++++++++++++++--
 4 files changed, 73 insertions(+), 84 deletions(-)

diff --git a/include/sysemu/os-posix.h b/include/sysemu/os-posix.h
index 8a66763395..6dfdcbb086 100644
--- a/include/sysemu/os-posix.h
+++ b/include/sysemu/os-posix.h
@@ -42,7 +42,6 @@
 extern "C" {
 #endif
 
-int os_parse_cmd_args(int index, const char *optarg);
 void os_set_line_buffering(void);
 void os_setup_early_signal_handling(void);
 void os_set_proc_name(const char *s);
diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h
index 91aa0d7ec0..8ae30fac15 100644
--- a/include/sysemu/os-win32.h
+++ b/include/sysemu/os-win32.h
@@ -101,7 +101,6 @@ static inline void os_setup_signal_handling(void) {}
 static inline void os_daemonize(void) {}
 static inline void os_setup_post(void) {}
 static inline void os_set_proc_name(const char *dummy) {}
-static inline int os_parse_cmd_args(int index, const char *optarg) { return -1; }
 void os_set_line_buffering(void);
 void os_setup_early_signal_handling(void);
 
diff --git a/os-posix.c b/os-posix.c
index 081f3db685..e4cdcf8839 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -31,7 +31,6 @@
 
 /* Needed early for CONFIG_BSD etc. */
 #include "net/slirp.h"
-#include "qemu/qemu-options.h"
 #include "qemu/error-report.h"
 #include "qemu/log.h"
 #include "sysemu/runstate.h"
@@ -42,7 +41,6 @@
 
 #ifdef CONFIG_LINUX
 #include <sys/prctl.h>
-#include "qemu/async-teardown.h"
 #endif
 
 /*
@@ -142,59 +140,6 @@ bool os_set_runas(const char *optarg)
     return true;
 }
 
-/*
- * Parse OS specific command line options.
- * return 0 if option handled, -1 otherwise
- */
-int os_parse_cmd_args(int index, const char *optarg)
-{
-    switch (index) {
-    case QEMU_OPTION_runas:
-        if (!os_set_runas(optarg)) {
-            error_report("User \"%s\" doesn't exist"
-                         " (and is not <uid>:<gid>)",
-                         optarg);
-            exit(1);
-        }
-        break;
-    case QEMU_OPTION_chroot:
-        warn_report("option is deprecated, use '-run-with chroot=...' instead");
-        os_set_chroot(optarg);
-        break;
-    case QEMU_OPTION_daemonize:
-        daemonize = 1;
-        break;
-#if defined(CONFIG_LINUX)
-    /* deprecated */
-    case QEMU_OPTION_asyncteardown:
-        init_async_teardown();
-        break;
-#endif
-    case QEMU_OPTION_run_with: {
-        const char *str;
-        QemuOpts *opts = qemu_opts_parse_noisily(qemu_find_opts("run-with"),
-                                                 optarg, false);
-        if (!opts) {
-            exit(1);
-        }
-#if defined(CONFIG_LINUX)
-        if (qemu_opt_get_bool(opts, "async-teardown", false)) {
-            init_async_teardown();
-        }
-#endif
-        str = qemu_opt_get(opts, "chroot");
-        if (str) {
-            os_set_chroot(str);
-        }
-        break;
-    }
-    default:
-        return -1;
-    }
-
-    return 0;
-}
-
 static void change_process_uid(void)
 {
     assert((user_uid == (uid_t)-1) || user_pwd == NULL);
@@ -371,27 +316,3 @@ int os_mlock(void)
     return -ENOSYS;
 #endif
 }
-
-static QemuOptsList qemu_run_with_opts = {
-    .name = "run-with",
-    .head = QTAILQ_HEAD_INITIALIZER(qemu_run_with_opts.head),
-    .desc = {
-#if defined(CONFIG_LINUX)
-        {
-            .name = "async-teardown",
-            .type = QEMU_OPT_BOOL,
-        },
-#endif
-        {
-            .name = "chroot",
-            .type = QEMU_OPT_STRING,
-        },
-        { /* end of list */ }
-    },
-};
-
-static void register_runwith(void)
-{
-    qemu_add_opts(&qemu_run_with_opts);
-}
-opts_init(register_runwith);
diff --git a/softmmu/vl.c b/softmmu/vl.c
index b0b96f67fa..0a74810ca3 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -49,6 +49,7 @@
 #include "qemu/error-report.h"
 #include "qemu/sockets.h"
 #include "qemu/accel.h"
+#include "qemu/async-teardown.h"
 #include "hw/usb.h"
 #include "hw/isa/isa.h"
 #include "hw/scsi/scsi.h"
@@ -748,6 +749,33 @@ static QemuOptsList qemu_smp_opts = {
     },
 };
 
+#if defined(CONFIG_POSIX)
+static QemuOptsList qemu_run_with_opts = {
+    .name = "run-with",
+    .head = QTAILQ_HEAD_INITIALIZER(qemu_run_with_opts.head),
+    .desc = {
+#if defined(CONFIG_LINUX)
+        {
+            .name = "async-teardown",
+            .type = QEMU_OPT_BOOL,
+        },
+#endif
+        {
+            .name = "chroot",
+            .type = QEMU_OPT_STRING,
+        },
+        { /* end of list */ }
+    },
+};
+
+#define qemu_add_run_with_opts() qemu_add_opts(&qemu_run_with_opts)
+
+#else
+
+#define qemu_add_run_with_opts()
+
+#endif /* CONFIG_POSIX */
+
 static void realtime_init(void)
 {
     if (enable_mlock) {
@@ -2704,6 +2732,7 @@ void qemu_init(int argc, char **argv)
     qemu_add_opts(&qemu_semihosting_config_opts);
     qemu_add_opts(&qemu_fw_cfg_opts);
     qemu_add_opts(&qemu_action_opts);
+    qemu_add_run_with_opts();
     module_call_init(MODULE_INIT_OPTS);
 
     error_init(argv[0]);
@@ -3522,11 +3551,52 @@ void qemu_init(int argc, char **argv)
             case QEMU_OPTION_nouserconfig:
                 /* Nothing to be parsed here. Especially, do not error out below. */
                 break;
-            default:
-                if (os_parse_cmd_args(popt->index, optarg)) {
-                    error_report("Option not supported in this build");
+#if defined(CONFIG_POSIX)
+            case QEMU_OPTION_runas:
+                if (!os_set_runas(optarg)) {
+                    error_report("User \"%s\" doesn't exist"
+                                 " (and is not <uid>:<gid>)",
+                                 optarg);
+                    exit(1);
+                }
+                break;
+            case QEMU_OPTION_chroot:
+                warn_report("option is deprecated,"
+                            " use '-run-with chroot=...' instead");
+                os_set_chroot(optarg);
+                break;
+            case QEMU_OPTION_daemonize:
+                os_set_daemonize(true);
+                break;
+#if defined(CONFIG_LINUX)
+            /* deprecated */
+            case QEMU_OPTION_asyncteardown:
+                init_async_teardown();
+                break;
+#endif
+            case QEMU_OPTION_run_with: {
+                const char *str;
+                opts = qemu_opts_parse_noisily(qemu_find_opts("run-with"),
+                                                         optarg, false);
+                if (!opts) {
                     exit(1);
                 }
+#if defined(CONFIG_LINUX)
+                if (qemu_opt_get_bool(opts, "async-teardown", false)) {
+                    init_async_teardown();
+                }
+#endif
+                str = qemu_opt_get(opts, "chroot");
+                if (str) {
+                    os_set_chroot(str);
+                }
+                break;
+            }
+#endif /* CONFIG_POSIX */
+
+            default:
+                error_report("Option not supported in this build");
+                exit(1);
             }
         }
     }
-- 
2.39.2



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

* [PATCH RFC 5/7] softmmu/vl.c: inline include/qemu/qemu-options.h into vl.c
  2023-08-12 12:47 [PATCH RFC 0/7] move softmmu options processing from os-posix.c to vl.c Michael Tokarev
                   ` (3 preceding siblings ...)
  2023-08-12 12:47 ` [PATCH RFC 4/7] os-posix.c, softmmu/vl.c: move os_parse_cmd_args() into qemu_init() Michael Tokarev
@ 2023-08-12 12:47 ` Michael Tokarev
  2023-08-15 18:23   ` Eric Blake
  2023-08-12 12:48 ` [PATCH RFC 6/7] os-posix.c: move code around Michael Tokarev
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 17+ messages in thread
From: Michael Tokarev @ 2023-08-12 12:47 UTC (permalink / raw)
  To: qemu-devel; +Cc: Michael Tokarev

qemu-options.h just includes qemu-options.def with some #defines.
We already do this in vl.c in other place. Since no other file
includes qemu-options.h anymore, just inline it in vl.c.

This effectively reverts second half of commit 59a5264b99434.

Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---
 include/qemu/qemu-options.h | 41 -------------------------------------
 softmmu/vl.c                | 11 +++++++++-
 2 files changed, 10 insertions(+), 42 deletions(-)
 delete mode 100644 include/qemu/qemu-options.h

diff --git a/include/qemu/qemu-options.h b/include/qemu/qemu-options.h
deleted file mode 100644
index 4a62c83c45..0000000000
--- a/include/qemu/qemu-options.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * qemu-options.h
- *
- * Defines needed for command line argument processing.
- *
- * Copyright (c) 2003-2008 Fabrice Bellard
- * Copyright (c) 2010 Jes Sorensen <Jes.Sorensen@redhat.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#ifndef QEMU_OPTIONS_H
-#define QEMU_OPTIONS_H
-
-enum {
-
-#define DEF(option, opt_arg, opt_enum, opt_help, arch_mask)     \
-    opt_enum,
-#define DEFHEADING(text)
-#define ARCHHEADING(text, arch_mask)
-
-#include "qemu-options.def"
-};
-
-#endif
diff --git a/softmmu/vl.c b/softmmu/vl.c
index 0a74810ca3..78b6570f19 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -91,7 +91,6 @@
 #include "qapi/qobject-input-visitor.h"
 #include "qemu/option.h"
 #include "qemu/config-file.h"
-#include "qemu/qemu-options.h"
 #include "qemu/main-loop.h"
 #ifdef CONFIG_VIRTFS
 #include "fsdev/qemu-fsdev.h"
@@ -894,6 +893,16 @@ static void help(int exitcode)
     exit(exitcode);
 }
 
+enum {
+
+#define DEF(option, opt_arg, opt_enum, opt_help, arch_mask)     \
+    opt_enum,
+#define DEFHEADING(text)
+#define ARCHHEADING(text, arch_mask)
+
+#include "qemu-options.def"
+};
+
 #define HAS_ARG 0x0001
 
 typedef struct QEMUOption {
-- 
2.39.2



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

* [PATCH RFC 6/7] os-posix.c: move code around
  2023-08-12 12:47 [PATCH RFC 0/7] move softmmu options processing from os-posix.c to vl.c Michael Tokarev
                   ` (4 preceding siblings ...)
  2023-08-12 12:47 ` [PATCH RFC 5/7] softmmu/vl.c: inline include/qemu/qemu-options.h into vl.c Michael Tokarev
@ 2023-08-12 12:48 ` Michael Tokarev
  2023-08-15 18:25   ` Eric Blake
  2023-08-12 12:48 ` [PATCH RFC 7/7] util/async-teardown.c: move to softmmu/, only build it when system build is requested Michael Tokarev
  2023-09-01 12:56 ` [PATCH RFC 0/7] move softmmu options processing from os-posix.c to vl.c Eric Blake
  7 siblings, 1 reply; 17+ messages in thread
From: Michael Tokarev @ 2023-08-12 12:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Michael Tokarev

this moves code blocks so that functions and variables which
belongs to the same concept are now close to each other.
There's no actual code changes in there.

Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---
 os-posix.c | 49 +++++++++++++++++++++++++++----------------------
 1 file changed, 27 insertions(+), 22 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index e4cdcf8839..76f0edc4f9 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -43,17 +43,6 @@
 #include <sys/prctl.h>
 #endif
 
-/*
- * Must set all three of these at once.
- * Legal combinations are              unset   by name   by uid
- */
-static struct passwd *user_pwd;    /*   NULL   non-NULL   NULL   */
-static uid_t user_uid = (uid_t)-1; /*   -1      -1        >=0    */
-static gid_t user_gid = (gid_t)-1; /*   -1      -1        >=0    */
-
-static const char *chroot_dir;
-static int daemonize;
-static int daemon_pipe;
 
 void os_setup_early_signal_handling(void)
 {
@@ -100,6 +89,15 @@ void os_set_proc_name(const char *s)
 #endif
 }
 
+
+/*
+ * Must set all three of these at once.
+ * Legal combinations are              unset   by name   by uid
+ */
+static struct passwd *user_pwd;    /*   NULL   non-NULL   NULL   */
+static uid_t user_uid = (uid_t)-1; /*   -1      -1        >=0    */
+static gid_t user_gid = (gid_t)-1; /*   -1      -1        >=0    */
+
 /*
  * Prepare to change user ID. optarg can be one of 3 forms:
  *   - a username, in which case user ID will be changed to its uid,
@@ -177,6 +175,9 @@ static void change_process_uid(void)
     }
 }
 
+
+static const char *chroot_dir;
+
 void os_set_chroot(const char *optarg)
 {
     chroot_dir = optarg;
@@ -197,6 +198,21 @@ static void change_root(void)
 
 }
 
+
+static int daemonize;
+static int daemon_pipe;
+
+bool is_daemonized(void)
+{
+    return daemonize;
+}
+
+int os_set_daemonize(bool d)
+{
+    daemonize = d;
+    return 0;
+}
+
 void os_daemonize(void)
 {
     if (daemonize) {
@@ -290,17 +306,6 @@ void os_set_line_buffering(void)
     setvbuf(stdout, NULL, _IOLBF, 0);
 }
 
-bool is_daemonized(void)
-{
-    return daemonize;
-}
-
-int os_set_daemonize(bool d)
-{
-    daemonize = d;
-    return 0;
-}
-
 int os_mlock(void)
 {
 #ifdef HAVE_MLOCKALL
-- 
2.39.2



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

* [PATCH RFC 7/7] util/async-teardown.c: move to softmmu/, only build it when system build is requested
  2023-08-12 12:47 [PATCH RFC 0/7] move softmmu options processing from os-posix.c to vl.c Michael Tokarev
                   ` (5 preceding siblings ...)
  2023-08-12 12:48 ` [PATCH RFC 6/7] os-posix.c: move code around Michael Tokarev
@ 2023-08-12 12:48 ` Michael Tokarev
  2023-08-15 18:25   ` Eric Blake
  2023-09-01 12:56 ` [PATCH RFC 0/7] move softmmu options processing from os-posix.c to vl.c Eric Blake
  7 siblings, 1 reply; 17+ messages in thread
From: Michael Tokarev @ 2023-08-12 12:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Michael Tokarev

Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---
 {util => softmmu}/async-teardown.c | 0
 softmmu/meson.build                | 1 +
 util/meson.build                   | 1 -
 3 files changed, 1 insertion(+), 1 deletion(-)
 rename {util => softmmu}/async-teardown.c (100%)

diff --git a/util/async-teardown.c b/softmmu/async-teardown.c
similarity index 100%
rename from util/async-teardown.c
rename to softmmu/async-teardown.c
diff --git a/softmmu/meson.build b/softmmu/meson.build
index ea5603f021..c18b7ad738 100644
--- a/softmmu/meson.build
+++ b/softmmu/meson.build
@@ -37,3 +37,4 @@ endif
 
 system_ss.add(when: seccomp, if_true: files('qemu-seccomp.c'))
 system_ss.add(when: fdt, if_true: files('device_tree.c'))
+system_ss.add(when: 'CONFIG_LINUX', if_true: files('async-teardown.c'))
diff --git a/util/meson.build b/util/meson.build
index a375160286..c4827fd70a 100644
--- a/util/meson.build
+++ b/util/meson.build
@@ -3,7 +3,6 @@ util_ss.add(files('thread-context.c'), numa)
 if not config_host_data.get('CONFIG_ATOMIC64')
   util_ss.add(files('atomic64.c'))
 endif
-util_ss.add(when: 'CONFIG_LINUX', if_true: files('async-teardown.c'))
 util_ss.add(when: 'CONFIG_POSIX', if_true: files('aio-posix.c'))
 util_ss.add(when: 'CONFIG_POSIX', if_true: files('fdmon-poll.c'))
 if config_host_data.get('CONFIG_EPOLL_CREATE1')
-- 
2.39.2



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

* Re: [PATCH RFC 1/7] include/sysemu/os-posix.h: move *daemonize* declaration together
  2023-08-12 12:47 ` [PATCH RFC 1/7] include/sysemu/os-posix.h: move *daemonize* declaration together Michael Tokarev
@ 2023-08-15 16:22   ` Eric Blake
  2023-09-01 10:10     ` Michael Tokarev
  0 siblings, 1 reply; 17+ messages in thread
From: Eric Blake @ 2023-08-15 16:22 UTC (permalink / raw)
  To: Michael Tokarev; +Cc: qemu-devel

On Sat, Aug 12, 2023 at 03:47:55PM +0300, Michael Tokarev wrote:
> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
> ---
>  include/sysemu/os-posix.h | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)

Reviewed-by: Eric Blake <eblake@redhat.com>

> 
> diff --git a/include/sysemu/os-posix.h b/include/sysemu/os-posix.h
> index 1030d39904..65b9c94e91 100644
> --- a/include/sysemu/os-posix.h
> +++ b/include/sysemu/os-posix.h
> @@ -47,13 +47,12 @@ void os_set_line_buffering(void);
>  void os_setup_early_signal_handling(void);
>  void os_set_proc_name(const char *s);
>  void os_setup_signal_handling(void);
> +int os_set_daemonize(bool d);
> +bool is_daemonized(void);
>  void os_daemonize(void);
>  void os_setup_post(void);
>  int os_mlock(void);
>  
> -int os_set_daemonize(bool d);
> -bool is_daemonized(void);
> -
>  /**
>   * qemu_alloc_stack:
>   * @sz: pointer to a size_t holding the requested usable stack size
> -- 
> 2.39.2
> 
> 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org



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

* Re: [PATCH RFC 2/7] os-posix: create and export os_set_runas()
  2023-08-12 12:47 ` [PATCH RFC 2/7] os-posix: create and export os_set_runas() Michael Tokarev
@ 2023-08-15 16:25   ` Eric Blake
  0 siblings, 0 replies; 17+ messages in thread
From: Eric Blake @ 2023-08-15 16:25 UTC (permalink / raw)
  To: Michael Tokarev; +Cc: qemu-devel

On Sat, Aug 12, 2023 at 03:47:56PM +0300, Michael Tokarev wrote:
> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
> ---
>  include/sysemu/os-posix.h |  1 +
>  os-posix.c                | 23 ++++++++++++++++-------
>  2 files changed, 17 insertions(+), 7 deletions(-)
>

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org



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

* Re: [PATCH RFC 3/7] os-posix.c: create and export os_set_chroot()
  2023-08-12 12:47 ` [PATCH RFC 3/7] os-posix.c: create and export os_set_chroot() Michael Tokarev
@ 2023-08-15 16:26   ` Eric Blake
  0 siblings, 0 replies; 17+ messages in thread
From: Eric Blake @ 2023-08-15 16:26 UTC (permalink / raw)
  To: Michael Tokarev; +Cc: qemu-devel

On Sat, Aug 12, 2023 at 03:47:57PM +0300, Michael Tokarev wrote:
> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
> ---
>  include/sysemu/os-posix.h | 1 +
>  os-posix.c                | 9 +++++++--
>  2 files changed, 8 insertions(+), 2 deletions(-)
>

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org



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

* Re: [PATCH RFC 4/7] os-posix.c, softmmu/vl.c: move os_parse_cmd_args() into qemu_init()
  2023-08-12 12:47 ` [PATCH RFC 4/7] os-posix.c, softmmu/vl.c: move os_parse_cmd_args() into qemu_init() Michael Tokarev
@ 2023-08-15 17:03   ` Eric Blake
  0 siblings, 0 replies; 17+ messages in thread
From: Eric Blake @ 2023-08-15 17:03 UTC (permalink / raw)
  To: Michael Tokarev; +Cc: qemu-devel

On Sat, Aug 12, 2023 at 03:47:58PM +0300, Michael Tokarev wrote:
> This will stop linking softmmu-specific os_parse_cmd_args() into every
> qemu executable which happens to use other functions from os-posix.c,
> such as os_set_line_buffering() or os_setup_signal_handling().
> 
> Also, since there's no win32-specific options, *all* option parsing is
> now done in softmmu/vl.c:qemu_init(), which is easier to read without
> extra indirection, - all options are in the single function now.
> 
> This effectively reverts commit 59a5264b99434.
> 
> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
> ---
>  include/sysemu/os-posix.h |  1 -
>  include/sysemu/os-win32.h |  1 -
>  os-posix.c                | 79 ---------------------------------------
>  softmmu/vl.c              | 76 +++++++++++++++++++++++++++++++++++--
>  4 files changed, 73 insertions(+), 84 deletions(-)

> +++ b/os-posix.c

> -    case QEMU_OPTION_chroot:
> -        warn_report("option is deprecated, use '-run-with chroot=...' instead");
> -        os_set_chroot(optarg);
> -        break;

How long has this been deprecated (to make sure code motion still
makes sense, rather than deletion)...

/me reads docs/about/deprecated.rst

Ah, just recently, in 8.1.  Okay.

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org



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

* Re: [PATCH RFC 5/7] softmmu/vl.c: inline include/qemu/qemu-options.h into vl.c
  2023-08-12 12:47 ` [PATCH RFC 5/7] softmmu/vl.c: inline include/qemu/qemu-options.h into vl.c Michael Tokarev
@ 2023-08-15 18:23   ` Eric Blake
  0 siblings, 0 replies; 17+ messages in thread
From: Eric Blake @ 2023-08-15 18:23 UTC (permalink / raw)
  To: Michael Tokarev; +Cc: qemu-devel

On Sat, Aug 12, 2023 at 03:47:59PM +0300, Michael Tokarev wrote:
> qemu-options.h just includes qemu-options.def with some #defines.
> We already do this in vl.c in other place. Since no other file
> includes qemu-options.h anymore, just inline it in vl.c.
> 
> This effectively reverts second half of commit 59a5264b99434.
> 
> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
> ---
>  include/qemu/qemu-options.h | 41 -------------------------------------
>  softmmu/vl.c                | 11 +++++++++-
>  2 files changed, 10 insertions(+), 42 deletions(-)
>  delete mode 100644 include/qemu/qemu-options.h

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org



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

* Re: [PATCH RFC 6/7] os-posix.c: move code around
  2023-08-12 12:48 ` [PATCH RFC 6/7] os-posix.c: move code around Michael Tokarev
@ 2023-08-15 18:25   ` Eric Blake
  0 siblings, 0 replies; 17+ messages in thread
From: Eric Blake @ 2023-08-15 18:25 UTC (permalink / raw)
  To: Michael Tokarev; +Cc: qemu-devel

On Sat, Aug 12, 2023 at 03:48:00PM +0300, Michael Tokarev wrote:
> this moves code blocks so that functions and variables which
> belongs to the same concept are now close to each other.
> There's no actual code changes in there.
> 
> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
> ---
>  os-posix.c | 49 +++++++++++++++++++++++++++----------------------
>  1 file changed, 27 insertions(+), 22 deletions(-)
> 

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org



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

* Re: [PATCH RFC 7/7] util/async-teardown.c: move to softmmu/, only build it when system build is requested
  2023-08-12 12:48 ` [PATCH RFC 7/7] util/async-teardown.c: move to softmmu/, only build it when system build is requested Michael Tokarev
@ 2023-08-15 18:25   ` Eric Blake
  0 siblings, 0 replies; 17+ messages in thread
From: Eric Blake @ 2023-08-15 18:25 UTC (permalink / raw)
  To: Michael Tokarev; +Cc: qemu-devel

On Sat, Aug 12, 2023 at 03:48:01PM +0300, Michael Tokarev wrote:
> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
> ---
>  {util => softmmu}/async-teardown.c | 0
>  softmmu/meson.build                | 1 +
>  util/meson.build                   | 1 -
>  3 files changed, 1 insertion(+), 1 deletion(-)
>  rename {util => softmmu}/async-teardown.c (100%)
>

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org



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

* Re: [PATCH RFC 1/7] include/sysemu/os-posix.h: move *daemonize* declaration together
  2023-08-15 16:22   ` Eric Blake
@ 2023-09-01 10:10     ` Michael Tokarev
  0 siblings, 0 replies; 17+ messages in thread
From: Michael Tokarev @ 2023-09-01 10:10 UTC (permalink / raw)
  To: Eric Blake; +Cc: qemu-devel

15.08.2023 19:22, Eric Blake wrote:
> On Sat, Aug 12, 2023 at 03:47:55PM +0300, Michael Tokarev wrote:
>> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
>> ---
>>   include/sysemu/os-posix.h | 5 ++---
>>   1 file changed, 2 insertions(+), 3 deletions(-)
> 
> Reviewed-by: Eric Blake <eblake@redhat.com>

Eric, thank you very much for the review!
This is usually an ungrateful work.. :)

/mjt


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

* Re: [PATCH RFC 0/7] move softmmu options processing from os-posix.c to vl.c
  2023-08-12 12:47 [PATCH RFC 0/7] move softmmu options processing from os-posix.c to vl.c Michael Tokarev
                   ` (6 preceding siblings ...)
  2023-08-12 12:48 ` [PATCH RFC 7/7] util/async-teardown.c: move to softmmu/, only build it when system build is requested Michael Tokarev
@ 2023-09-01 12:56 ` Eric Blake
  7 siblings, 0 replies; 17+ messages in thread
From: Eric Blake @ 2023-09-01 12:56 UTC (permalink / raw)
  To: Michael Tokarev; +Cc: qemu-devel

On Sat, Aug 12, 2023 at 03:47:54PM +0300, Michael Tokarev wrote:
> qemu_init() calls os_parse_cmd_args(), which is obviously a very vl.c-specicic
> piece of code.  It looks like when moving vl.c to softmmu/, os-posix.c should've
> been moved too (together with os-win32.c).  But there are other functions in
> os-posix.c which are used by other parts of the code, eg qemu-nbd or
> qemu-storage-daemon both uses parts from there.  The result is rather ugly.
> One of the side-effects is that even if system build is disabled, we still
> have to compile util/async-teardown.c, since it is used in os-posix.c, - and
> this one can not be built on ia64 due to lack of clone syscall.  But qemu-nbd
> does not need async-teardown, which is also very softmmu-specific.
> 
> This patchset tries to address these defects.  It moves the "bottom half" of
> vl.c options processing back into vl.c, effectively undoing commit 59a5264b99434
> from 2010.  We do not have many os-specific options, and this move makes
> qemu_init() the only function which processes options, all in the single
> place, which is, in my opinion, easier to manage.
> 
> Before this move, lower-level constructs (chroot, runas) are being exported.
> 
> In the end, we have almost no softmmu-related things in os-posix.c, and the
> same functionality can be actually used in qemu-storage-daemon or qemu-nbd.
> For qemu-nbd, it is now possible to switch to using -runas/-chroot/etc the
> same way as qemu-storage-daemon does, instead of having one more abstraction
> named qemu_daemon().

Given that qemu-nbd is affected, I'm happy to queue this through my
NBD tree if no one else picks it up first.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org



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

end of thread, other threads:[~2023-09-01 12:57 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-12 12:47 [PATCH RFC 0/7] move softmmu options processing from os-posix.c to vl.c Michael Tokarev
2023-08-12 12:47 ` [PATCH RFC 1/7] include/sysemu/os-posix.h: move *daemonize* declaration together Michael Tokarev
2023-08-15 16:22   ` Eric Blake
2023-09-01 10:10     ` Michael Tokarev
2023-08-12 12:47 ` [PATCH RFC 2/7] os-posix: create and export os_set_runas() Michael Tokarev
2023-08-15 16:25   ` Eric Blake
2023-08-12 12:47 ` [PATCH RFC 3/7] os-posix.c: create and export os_set_chroot() Michael Tokarev
2023-08-15 16:26   ` Eric Blake
2023-08-12 12:47 ` [PATCH RFC 4/7] os-posix.c, softmmu/vl.c: move os_parse_cmd_args() into qemu_init() Michael Tokarev
2023-08-15 17:03   ` Eric Blake
2023-08-12 12:47 ` [PATCH RFC 5/7] softmmu/vl.c: inline include/qemu/qemu-options.h into vl.c Michael Tokarev
2023-08-15 18:23   ` Eric Blake
2023-08-12 12:48 ` [PATCH RFC 6/7] os-posix.c: move code around Michael Tokarev
2023-08-15 18:25   ` Eric Blake
2023-08-12 12:48 ` [PATCH RFC 7/7] util/async-teardown.c: move to softmmu/, only build it when system build is requested Michael Tokarev
2023-08-15 18:25   ` Eric Blake
2023-09-01 12:56 ` [PATCH RFC 0/7] move softmmu options processing from os-posix.c to vl.c Eric Blake

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).