From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37985) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XnN9q-0000vx-WB for qemu-devel@nongnu.org; Sun, 09 Nov 2014 02:43:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XnN9k-00013L-UX for qemu-devel@nongnu.org; Sun, 09 Nov 2014 02:43:34 -0500 Received: from mail-pd0-f177.google.com ([209.85.192.177]:48686) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XnN9k-00013C-Ou for qemu-devel@nongnu.org; Sun, 09 Nov 2014 02:43:28 -0500 Received: by mail-pd0-f177.google.com with SMTP id v10so5825503pde.22 for ; Sat, 08 Nov 2014 23:43:28 -0800 (PST) From: Ming Lei Date: Sun, 9 Nov 2014 15:42:49 +0800 Message-Id: <1415518978-2837-5-git-send-email-ming.lei@canonical.com> In-Reply-To: <1415518978-2837-1-git-send-email-ming.lei@canonical.com> References: <1415518978-2837-1-git-send-email-ming.lei@canonical.com> Subject: [Qemu-devel] [PATCH 04/13] block/linux-aio: do more things in laio_state_alloc() and its pair List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, Peter Maydell , Paolo Bonzini , Stefan Hajnoczi , Kevin Wolf Cc: Ming Lei , Fam Zheng Now lifetime of 'completion_bh', io queue and io context is same, so move their allocation into laio_state_alloc() and their releasing into laio_state_free(). Signed-off-by: Ming Lei --- block/linux-aio.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/block/linux-aio.c b/block/linux-aio.c index 5fa3c1e..95cd0dc 100644 --- a/block/linux-aio.c +++ b/block/linux-aio.c @@ -388,7 +388,7 @@ static void laio_free_ioq(struct qemu_laio_state *s, LaioQueue *ioq) s->io_q = NULL; } -static struct qemu_laio_state *laio_state_alloc(void) +static struct qemu_laio_state *laio_state_alloc(AioContext *context) { struct qemu_laio_state *s; @@ -401,6 +401,10 @@ static struct qemu_laio_state *laio_state_alloc(void) goto out_close_efd; } + s->io_q = laio_alloc_ioq(context, s); + s->completion_bh = aio_bh_new(context, qemu_laio_completion_bh, s); + aio_set_event_notifier(context, &s->e, qemu_laio_completion_cb); + return s; out_close_efd: @@ -410,8 +414,12 @@ out_free_state: return NULL; } -static void laio_state_free(struct qemu_laio_state *s) +static void laio_state_free(struct qemu_laio_state *s, AioContext *context) { + aio_set_event_notifier(context, &s->e, NULL); + qemu_bh_delete(s->completion_bh); + + laio_free_ioq(s, s->io_q); event_notifier_cleanup(&s->e); if (io_destroy(s->ctx) != 0) { @@ -424,25 +432,15 @@ static void laio_state_free(struct qemu_laio_state *s) void laio_detach_aio_context(void *s_, AioContext *old_context) { QemuLaioState *qs = s_; - struct qemu_laio_state *s = qs->state; - aio_set_event_notifier(old_context, &s->e, NULL); - qemu_bh_delete(s->completion_bh); - - laio_free_ioq(s, s->io_q); - laio_state_free(s); + laio_state_free(qs->state, old_context); qs->state = NULL; } void laio_attach_aio_context(void *s_, AioContext *new_context) { QemuLaioState *qs = s_; - struct qemu_laio_state *s = laio_state_alloc(); - - s->io_q = laio_alloc_ioq(new_context, s); - - s->completion_bh = aio_bh_new(new_context, qemu_laio_completion_bh, s); - aio_set_event_notifier(new_context, &s->e, qemu_laio_completion_cb); + struct qemu_laio_state *s = laio_state_alloc(new_context); qs->state = s; } -- 1.7.9.5