diff mbox series

[RESEND,v6,05/36] multi-process: Refactor monitor functions out of vl.c

Message ID 22a91b836f4105dc314f24536e96f883c0ad638c.1587614626.git.elena.ufimtseva@oracle.com (mailing list archive)
State New, archived
Headers show
Series [RESEND,v6,01/36] memory: alloc RAM from file at offset | expand

Commit Message

Elena Ufimtseva April 23, 2020, 4:13 a.m. UTC
From: Elena Ufimtseva <elena.ufimtseva@oracle.com>

Some of the initialization helper functions w.r.t monitor
in vl.c are also used by the remote process. Therefore, these functions
are refactored into shared files that both QEMU & remote process
could use.

Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
 include/monitor/monitor.h |  3 +++
 monitor/monitor.c         | 37 +++++++++++++++++++++++++++++++++++++
 softmmu/vl.c              | 35 -----------------------------------
 3 files changed, 40 insertions(+), 35 deletions(-)

Comments

Stefan Hajnoczi April 24, 2020, 1:02 p.m. UTC | #1
On Wed, Apr 22, 2020 at 09:13:40PM -0700, elena.ufimtseva@oracle.com wrote:
> From: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> 
> Some of the initialization helper functions w.r.t monitor
> in vl.c are also used by the remote process. Therefore, these functions
> are refactored into shared files that both QEMU & remote process
> could use.
> 
> Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> ---
>  include/monitor/monitor.h |  3 +++
>  monitor/monitor.c         | 37 +++++++++++++++++++++++++++++++++++++
>  softmmu/vl.c              | 35 -----------------------------------
>  3 files changed, 40 insertions(+), 35 deletions(-)

Kevin Wolf recently had to solve a similar problem when introducing
qemu-storage-daemon.

qemu-storage-daemon.c open-codes the command-line parsing instead of
trying to reuse vl.c's code.  The vl.c code is old and not very neat,
unless other code depends on it I would suggest writing modern clean
code like Kevin did instead of trying to keep using vl.c code.

> 
> diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
> index 1018d754a6..3803e904f2 100644
> --- a/include/monitor/monitor.h
> +++ b/include/monitor/monitor.h
> @@ -48,4 +48,7 @@ int monitor_fdset_dup_fd_add(int64_t fdset_id, int dup_fd);
>  void monitor_fdset_dup_fd_remove(int dup_fd);
>  int64_t monitor_fdset_dup_fd_find(int dup_fd);
>  
> +int mon_init_func(void *opaque, QemuOpts *opts, Error **errp);
> +void monitor_parse(const char *optarg, const char *mode, bool pretty);
> +
>  #endif /* MONITOR_H */
> diff --git a/monitor/monitor.c b/monitor/monitor.c
> index 125494410a..88423b38b6 100644
> --- a/monitor/monitor.c
> +++ b/monitor/monitor.c
> @@ -35,6 +35,8 @@
>  #include "sysemu/qtest.h"
>  #include "sysemu/sysemu.h"
>  #include "trace.h"
> +#include "qemu/cutils.h"
> +#include "qemu/config-file.h"
>  
>  /*
>   * To prevent flooding clients, events can be throttled. The
> @@ -611,6 +613,41 @@ void monitor_init_globals_core(void)
>                                     NULL);
>  }
>  
> +int mon_init_func(void *opaque, QemuOpts *opts, Error **errp)
> +{
> +    return monitor_init_opts(opts, errp);
> +}
> +
> +void monitor_parse(const char *optarg, const char *mode, bool pretty)
> +{
> +    static int monitor_device_index;
> +    QemuOpts *opts;
> +    const char *p;
> +    char label[32];
> +
> +    if (strstart(optarg, "chardev:", &p)) {
> +        snprintf(label, sizeof(label), "%s", p);
> +    } else {
> +        snprintf(label, sizeof(label), "compat_monitor%d",
> +                 monitor_device_index);
> +        opts = qemu_chr_parse_compat(label, optarg, true);
> +        if (!opts) {
> +            error_report("parse error: %s", optarg);
> +            exit(1);
> +        }
> +    }
> +
> +    opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, &error_fatal);
> +    qemu_opt_set(opts, "mode", mode, &error_abort);
> +    qemu_opt_set(opts, "chardev", label, &error_abort);
> +    if (!strcmp(mode, "control")) {
> +        qemu_opt_set_bool(opts, "pretty", pretty, &error_abort);
> +    } else {
> +        assert(pretty == false);
> +    }
> +    monitor_device_index++;
> +}
> +
>  int monitor_init(MonitorOptions *opts, bool allow_hmp, Error **errp)
>  {
>      Chardev *chr;
> diff --git a/softmmu/vl.c b/softmmu/vl.c
> index 6e35f3787d..abc746c1b5 100644
> --- a/softmmu/vl.c
> +++ b/softmmu/vl.c
> @@ -2045,41 +2045,6 @@ static int fsdev_init_func(void *opaque, QemuOpts *opts, Error **errp)
>  }
>  #endif
>  
> -static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp)
> -{
> -    return monitor_init_opts(opts, errp);
> -}
> -
> -static void monitor_parse(const char *optarg, const char *mode, bool pretty)
> -{
> -    static int monitor_device_index = 0;
> -    QemuOpts *opts;
> -    const char *p;
> -    char label[32];
> -
> -    if (strstart(optarg, "chardev:", &p)) {
> -        snprintf(label, sizeof(label), "%s", p);
> -    } else {
> -        snprintf(label, sizeof(label), "compat_monitor%d",
> -                 monitor_device_index);
> -        opts = qemu_chr_parse_compat(label, optarg, true);
> -        if (!opts) {
> -            error_report("parse error: %s", optarg);
> -            exit(1);
> -        }
> -    }
> -
> -    opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, &error_fatal);
> -    qemu_opt_set(opts, "mode", mode, &error_abort);
> -    qemu_opt_set(opts, "chardev", label, &error_abort);
> -    if (!strcmp(mode, "control")) {
> -        qemu_opt_set_bool(opts, "pretty", pretty, &error_abort);
> -    } else {
> -        assert(pretty == false);
> -    }
> -    monitor_device_index++;
> -}
> -
>  struct device_config {
>      enum {
>          DEV_USB,       /* -usbdevice     */
> -- 
> 2.25.GIT
>
diff mbox series

Patch

diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
index 1018d754a6..3803e904f2 100644
--- a/include/monitor/monitor.h
+++ b/include/monitor/monitor.h
@@ -48,4 +48,7 @@  int monitor_fdset_dup_fd_add(int64_t fdset_id, int dup_fd);
 void monitor_fdset_dup_fd_remove(int dup_fd);
 int64_t monitor_fdset_dup_fd_find(int dup_fd);
 
+int mon_init_func(void *opaque, QemuOpts *opts, Error **errp);
+void monitor_parse(const char *optarg, const char *mode, bool pretty);
+
 #endif /* MONITOR_H */
diff --git a/monitor/monitor.c b/monitor/monitor.c
index 125494410a..88423b38b6 100644
--- a/monitor/monitor.c
+++ b/monitor/monitor.c
@@ -35,6 +35,8 @@ 
 #include "sysemu/qtest.h"
 #include "sysemu/sysemu.h"
 #include "trace.h"
+#include "qemu/cutils.h"
+#include "qemu/config-file.h"
 
 /*
  * To prevent flooding clients, events can be throttled. The
@@ -611,6 +613,41 @@  void monitor_init_globals_core(void)
                                    NULL);
 }
 
+int mon_init_func(void *opaque, QemuOpts *opts, Error **errp)
+{
+    return monitor_init_opts(opts, errp);
+}
+
+void monitor_parse(const char *optarg, const char *mode, bool pretty)
+{
+    static int monitor_device_index;
+    QemuOpts *opts;
+    const char *p;
+    char label[32];
+
+    if (strstart(optarg, "chardev:", &p)) {
+        snprintf(label, sizeof(label), "%s", p);
+    } else {
+        snprintf(label, sizeof(label), "compat_monitor%d",
+                 monitor_device_index);
+        opts = qemu_chr_parse_compat(label, optarg, true);
+        if (!opts) {
+            error_report("parse error: %s", optarg);
+            exit(1);
+        }
+    }
+
+    opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, &error_fatal);
+    qemu_opt_set(opts, "mode", mode, &error_abort);
+    qemu_opt_set(opts, "chardev", label, &error_abort);
+    if (!strcmp(mode, "control")) {
+        qemu_opt_set_bool(opts, "pretty", pretty, &error_abort);
+    } else {
+        assert(pretty == false);
+    }
+    monitor_device_index++;
+}
+
 int monitor_init(MonitorOptions *opts, bool allow_hmp, Error **errp)
 {
     Chardev *chr;
diff --git a/softmmu/vl.c b/softmmu/vl.c
index 6e35f3787d..abc746c1b5 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -2045,41 +2045,6 @@  static int fsdev_init_func(void *opaque, QemuOpts *opts, Error **errp)
 }
 #endif
 
-static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp)
-{
-    return monitor_init_opts(opts, errp);
-}
-
-static void monitor_parse(const char *optarg, const char *mode, bool pretty)
-{
-    static int monitor_device_index = 0;
-    QemuOpts *opts;
-    const char *p;
-    char label[32];
-
-    if (strstart(optarg, "chardev:", &p)) {
-        snprintf(label, sizeof(label), "%s", p);
-    } else {
-        snprintf(label, sizeof(label), "compat_monitor%d",
-                 monitor_device_index);
-        opts = qemu_chr_parse_compat(label, optarg, true);
-        if (!opts) {
-            error_report("parse error: %s", optarg);
-            exit(1);
-        }
-    }
-
-    opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, &error_fatal);
-    qemu_opt_set(opts, "mode", mode, &error_abort);
-    qemu_opt_set(opts, "chardev", label, &error_abort);
-    if (!strcmp(mode, "control")) {
-        qemu_opt_set_bool(opts, "pretty", pretty, &error_abort);
-    } else {
-        assert(pretty == false);
-    }
-    monitor_device_index++;
-}
-
 struct device_config {
     enum {
         DEV_USB,       /* -usbdevice     */