All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Fei Li <fli@suse.com>
Cc: qemu-devel@nongnu.org, quintela@redhat.com, dgilbert@redhat.com,
	peterx@redhat.com, armbru@redhat.com, famz@redhat.com
Subject: Re: [Qemu-devel] [PATCH RFC v5 2/7] ui/vnc.c: polish vnc_init_func
Date: Thu, 11 Oct 2018 15:13:40 +0200	[thread overview]
Message-ID: <87h8hs4oe3.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <20181010120841.13214-3-fli@suse.com> (Fei Li's message of "Wed, 10 Oct 2018 20:08:36 +0800")

Fei Li <fli@suse.com> writes:

> Add a new Error parameter for vnc_display_init() to handle errors
> in its caller: vnc_init_func(), just like vnc_display_open() does.
> And let the call trace propagate the Error.
>
> Besides, make vnc_start_worker_thread() return a bool to indicate
> whether it succeeds instead of returning nothing.
>
> Signed-off-by: Fei Li <fli@suse.com>
> Reviewed-by: Fam Zheng <famz@redhat.com>
> ---
>  include/ui/console.h |  2 +-
>  ui/vnc-jobs.c        |  9 ++++++---
>  ui/vnc-jobs.h        |  2 +-
>  ui/vnc.c             | 12 +++++++++---
>  4 files changed, 17 insertions(+), 8 deletions(-)
>
> diff --git a/include/ui/console.h b/include/ui/console.h
> index fb969caf70..c17803c530 100644
> --- a/include/ui/console.h
> +++ b/include/ui/console.h
> @@ -453,7 +453,7 @@ void qemu_display_early_init(DisplayOptions *opts);
>  void qemu_display_init(DisplayState *ds, DisplayOptions *opts);
>  
>  /* vnc.c */
> -void vnc_display_init(const char *id);
> +void vnc_display_init(const char *id, Error **errp);
>  void vnc_display_open(const char *id, Error **errp);
>  void vnc_display_add_client(const char *id, int csock, bool skipauth);
>  int vnc_display_password(const char *id, const char *password);
> diff --git a/ui/vnc-jobs.c b/ui/vnc-jobs.c
> index 929391f85d..8807d7217c 100644
> --- a/ui/vnc-jobs.c
> +++ b/ui/vnc-jobs.c
> @@ -331,15 +331,18 @@ static bool vnc_worker_thread_running(void)
>      return queue; /* Check global queue */
>  }
>  
> -void vnc_start_worker_thread(void)
> +bool vnc_start_worker_thread(Error **errp)
>  {
>      VncJobQueue *q;
>  
> -    if (vnc_worker_thread_running())
> -        return ;
> +    if (vnc_worker_thread_running()) {
> +        goto out;
> +    }
>  
>      q = vnc_queue_init();
>      qemu_thread_create(&q->thread, "vnc_worker", vnc_worker_thread, q,
>                         QEMU_THREAD_DETACHED);
>      queue = q; /* Set global queue */
> +out:
> +    return true;
>  }

This function cannot fail.  Why convert it to Error, and complicate its
caller?

> diff --git a/ui/vnc-jobs.h b/ui/vnc-jobs.h
> index 59f66bcc35..14640593db 100644
> --- a/ui/vnc-jobs.h
> +++ b/ui/vnc-jobs.h
> @@ -37,7 +37,7 @@ void vnc_job_push(VncJob *job);
>  void vnc_jobs_join(VncState *vs);
>  
>  void vnc_jobs_consume_buffer(VncState *vs);
> -void vnc_start_worker_thread(void);
> +bool vnc_start_worker_thread(Error **errp);
>  
>  /* Locks */
>  static inline int vnc_trylock_display(VncDisplay *vd)
> diff --git a/ui/vnc.c b/ui/vnc.c
> index cf221c83cc..f3806e76db 100644
> --- a/ui/vnc.c
> +++ b/ui/vnc.c
> @@ -3205,7 +3205,7 @@ static const DisplayChangeListenerOps dcl_ops = {
>      .dpy_cursor_define    = vnc_dpy_cursor_define,
>  };
>  
> -void vnc_display_init(const char *id)
> +void vnc_display_init(const char *id, Error **errp)
>  {
>      VncDisplay *vd;
>  
       if (vnc_display_find(id) != NULL) {
           return;
       }
       vd = g_malloc0(sizeof(*vd));

       vd->id = strdup(id);
       QTAILQ_INSERT_TAIL(&vnc_displays, vd, next);

       QTAILQ_INIT(&vd->clients);
       vd->expires = TIME_MAX;

       if (keyboard_layout) {
           trace_vnc_key_map_init(keyboard_layout);
           vd->kbd_layout = init_keyboard_layout(name2keysym, keyboard_layout);
       } else {
           vd->kbd_layout = init_keyboard_layout(name2keysym, "en-us");
       }

       if (!vd->kbd_layout) {
           exit(1);

Uh, init_keyboard_layout() reports errors to stderr, and the exit(1)
here makes them fatal.  Okay before this patch, but inappropriate
afterwards.  I'm afraid you have to convert init_keyboard_layout() to
Error first.

       }

       vd->share_policy = VNC_SHARE_POLICY_ALLOW_EXCLUSIVE;
> @@ -3235,7 +3235,9 @@ void vnc_display_init(const char *id)
>      vd->connections_limit = 32;
>  
>      qemu_mutex_init(&vd->mutex);
> -    vnc_start_worker_thread();
> +    if (!vnc_start_worker_thread(errp)) {
> +        return;
> +    }
>  
>      vd->dcl.ops = &dcl_ops;
>      register_displaychangelistener(&vd->dcl);
> @@ -4079,7 +4081,11 @@ int vnc_init_func(void *opaque, QemuOpts *opts, Error **errp)
>      char *id = (char *)qemu_opts_id(opts);
>  
>      assert(id);
> -    vnc_display_init(id);
> +    vnc_display_init(id, &local_err);
> +    if (local_err) {
> +        error_reportf_err(local_err, "Failed to init VNC server: ");
> +        exit(1);
> +    }
>      vnc_display_open(id, &local_err);
>      if (local_err != NULL) {
>          error_reportf_err(local_err, "Failed to start VNC server: ");

Conflicts with my "[PATCH 24/31] vl: Clean up error reporting in
vnc_init_func()".  Your patch shows that mine is incomplete.

Without my patch, there's no real reason for yours, however.  The two
should be squashed together.

  reply	other threads:[~2018-10-11 13:13 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-10 12:08 [Qemu-devel] [PATCH RFC v5 0/7] qemu_thread_create: propagate errors to callers to check Fei Li
2018-10-10 12:08 ` [Qemu-devel] [PATCH RFC v5 1/7] Fix segmentation fault when qemu_signal_init fails Fei Li
2018-10-11 10:02   ` Markus Armbruster
2018-10-12  4:24     ` Fei Li
2018-10-12  7:56       ` Markus Armbruster
2018-10-12  9:42         ` Fei Li
2018-10-12 13:26           ` Markus Armbruster
2018-10-17  8:17             ` Fei Li
2018-10-19  3:14               ` Fei Li
2018-10-10 12:08 ` [Qemu-devel] [PATCH RFC v5 2/7] ui/vnc.c: polish vnc_init_func Fei Li
2018-10-11 13:13   ` Markus Armbruster [this message]
2018-10-12  5:40     ` Fei Li
2018-10-12  8:18       ` Markus Armbruster
2018-10-12 10:23         ` Fei Li
2018-10-12 10:50           ` Fei Li
2018-10-10 12:08 ` [Qemu-devel] [PATCH RFC v5 3/7] qemu_init_vcpu: add a new Error parameter to propagate Fei Li
2018-10-11 13:19   ` Markus Armbruster
2018-10-12  5:55     ` Fei Li
2018-10-12  8:24       ` Markus Armbruster
2018-10-12 10:25         ` Fei Li
2018-10-10 12:08 ` [Qemu-devel] [PATCH RFC v5 4/7] qemu_thread_join: fix segmentation fault Fei Li
2018-10-10 12:08 ` [Qemu-devel] [PATCH RFC v5 5/7] migration: fix the multifd code Fei Li
2018-10-11 13:28   ` Markus Armbruster
2018-10-10 12:08 ` [Qemu-devel] [PATCH RFC v5 6/7] migration: fix some error handling Fei Li
2018-10-10 12:08 ` [Qemu-devel] [PATCH RFC v5 7/7] qemu_thread_create: propagate the error to callers to handle Fei Li
2018-10-11 13:45   ` Markus Armbruster
2018-10-12  6:00     ` Fei Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87h8hs4oe3.fsf@dusky.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=famz@redhat.com \
    --cc=fli@suse.com \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.