qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH RESEND v6 05/36] multi-process: Refactor monitor functions ou


From: Stefan Hajnoczi
Subject: Re: [PATCH RESEND v6 05/36] multi-process: Refactor monitor functions out of vl.c
Date: Fri, 24 Apr 2020 14:02:36 +0100

On Wed, Apr 22, 2020 at 09:13:40PM -0700, address@hidden wrote:
> From: Elena Ufimtseva <address@hidden>
> 
> 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 <address@hidden>
> Signed-off-by: John G Johnson <address@hidden>
> Signed-off-by: Jagannathan Raman <address@hidden>
> Reviewed-by: Dr. David Alan Gilbert <address@hidden>
> ---
>  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
> 

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]