From: Stefan Hajnoczi <stefanha@gmail.com>
To: Chrysostomos Nanakos <cnanakos@grnet.gr>
Cc: kwolf@redhat.com, pingfank@linux.vnet.ibm.com, famz@redhat.com,
benoit@irqsave.net, jan.kiszka@siemens.com, mjt@tls.msk.ru,
qemu-devel@nongnu.org, stefanha@redhat.com, sw@weilnetz.de,
pbonzini@redhat.com, kroosec@gmail.com, afaerber@suse.de,
aliguori@amazon.com
Subject: Re: [Qemu-devel] [PATCH v4] async: aio_context_new(): Handle event_notifier_init failure
Date: Thu, 18 Sep 2014 11:46:47 +0100 [thread overview]
Message-ID: <20140918104647.GE8847@stefanha-thinkpad.redhat.com> (raw)
In-Reply-To: <1410961715-21347-2-git-send-email-cnanakos@grnet.gr>
[-- Attachment #1: Type: text/plain, Size: 4050 bytes --]
On Wed, Sep 17, 2014 at 04:48:34PM +0300, Chrysostomos Nanakos wrote:
> diff --git a/iothread.c b/iothread.c
> index d9403cf..6e394a0 100644
> --- a/iothread.c
> +++ b/iothread.c
> @@ -17,6 +17,7 @@
> #include "block/aio.h"
> #include "sysemu/iothread.h"
> #include "qmp-commands.h"
> +#include "qemu/error-report.h"
>
> #define IOTHREADS_PATH "/objects"
>
> @@ -53,6 +54,9 @@ static void iothread_instance_finalize(Object *obj)
> {
> IOThread *iothread = IOTHREAD(obj);
>
> + if (!iothread->ctx) {
> + return;
> + }
> iothread->stopping = true;
> aio_notify(iothread->ctx);
> qemu_thread_join(&iothread->thread);
> @@ -63,10 +67,15 @@ static void iothread_instance_finalize(Object *obj)
>
> static void iothread_complete(UserCreatable *obj, Error **errp)
> {
> + Error *local_error = NULL;
> IOThread *iothread = IOTHREAD(obj);
>
> iothread->stopping = false;
> - iothread->ctx = aio_context_new();
> + iothread->ctx = aio_context_new(&local_error);
> + if (!iothread->ctx) {
> + error_propagate(errp, local_error);
> + return;
> + }
> iothread->thread_id = -1;
Please move this under ->stopping = false so that ->thread_id is
initialized. That way qmp_query_iothreads() will display thread_id -1
for failed IOThread objects instead of an uninitialized value.
Normally QEMU should exit or the IOThread object should be deleted
before anyone has a chance to call qmp_query_iothreads() but you never
know so let's get the lifecycle right...
> diff --git a/main-loop.c b/main-loop.c
> index 3cc79f8..2f83d80 100644
> --- a/main-loop.c
> +++ b/main-loop.c
> @@ -126,10 +126,11 @@ void qemu_notify_event(void)
>
> static GArray *gpollfds;
>
> -int qemu_init_main_loop(void)
> +int qemu_init_main_loop(Error **errp)
> {
> int ret;
> GSource *src;
> + Error *local_error = NULL;
>
> init_clocks();
>
> @@ -138,8 +139,12 @@ int qemu_init_main_loop(void)
> return ret;
> }
>
> + qemu_aio_context = aio_context_new(&local_error);
> + if (!qemu_aio_context) {
> + error_propagate(errp, local_error);
> + return -1;
This function returns -errno so -1 would be -EPERM. Please use an
actual errno constant like -EMFILE.
> diff --git a/tests/test-aio.c b/tests/test-aio.c
> index c6a8713..029716f 100644
> --- a/tests/test-aio.c
> +++ b/tests/test-aio.c
> @@ -14,6 +14,7 @@
> #include "block/aio.h"
> #include "qemu/timer.h"
> #include "qemu/sockets.h"
> +#include "qemu/error-report.h"
>
> static AioContext *ctx;
>
> @@ -810,11 +811,18 @@ static void test_source_timer_schedule(void)
>
> int main(int argc, char **argv)
> {
> + Error *local_error;
local_error = NULL
It must be NULL otherwise error_setg() will read uninitialized memory
(it checks that the error hasn't been set yet because Error objects can
only be set once).
> diff --git a/tests/test-thread-pool.c b/tests/test-thread-pool.c
> index f40b7fc..57c0836 100644
> --- a/tests/test-thread-pool.c
> +++ b/tests/test-thread-pool.c
> @@ -4,6 +4,7 @@
> #include "block/thread-pool.h"
> #include "block/block.h"
> #include "qemu/timer.h"
> +#include "qemu/error-report.h"
>
> static AioContext *ctx;
> static ThreadPool *pool;
> @@ -205,10 +206,17 @@ static void test_cancel(void)
> int main(int argc, char **argv)
> {
> int ret;
> + Error *local_error;
Same.
> diff --git a/tests/test-throttle.c b/tests/test-throttle.c
> index 000ae31..42141a0 100644
> --- a/tests/test-throttle.c
> +++ b/tests/test-throttle.c
> @@ -14,6 +14,7 @@
> #include <math.h>
> #include "block/aio.h"
> #include "qemu/throttle.h"
> +#include "qemu/error-report.h"
>
> static AioContext *ctx;
> static LeakyBucket bkt;
> @@ -492,10 +493,17 @@ static void test_accounting(void)
> int main(int argc, char **argv)
> {
> GSource *src;
> + Error *local_error;
Same.
[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]
next prev parent reply other threads:[~2014-09-18 10:47 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-17 13:48 [Qemu-devel] [PATCH v4] async: aio_context_new(): Handle event_notifier_init failure Chrysostomos Nanakos
2014-09-17 13:48 ` Chrysostomos Nanakos
2014-09-18 10:46 ` Stefan Hajnoczi [this message]
2014-09-17 13:51 ` Andreas Färber
2014-09-17 13:59 ` Eric Blake
2014-09-18 3:06 ` Nanakos Chrysostomos
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=20140918104647.GE8847@stefanha-thinkpad.redhat.com \
--to=stefanha@gmail.com \
--cc=afaerber@suse.de \
--cc=aliguori@amazon.com \
--cc=benoit@irqsave.net \
--cc=cnanakos@grnet.gr \
--cc=famz@redhat.com \
--cc=jan.kiszka@siemens.com \
--cc=kroosec@gmail.com \
--cc=kwolf@redhat.com \
--cc=mjt@tls.msk.ru \
--cc=pbonzini@redhat.com \
--cc=pingfank@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=sw@weilnetz.de \
/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 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).