From patchwork Thu Apr 7 16:33:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 8774891 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 7542C9F3D1 for ; Thu, 7 Apr 2016 16:38:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8D7A920166 for ; Thu, 7 Apr 2016 16:38:57 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 970B920155 for ; Thu, 7 Apr 2016 16:38:56 +0000 (UTC) Received: from localhost ([::1]:51347 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aoCxM-0002No-0b for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Apr 2016 12:38:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41299) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aoCsQ-0001RE-AJ for qemu-devel@nongnu.org; Thu, 07 Apr 2016 12:33:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aoCsO-0005lo-Om for qemu-devel@nongnu.org; Thu, 07 Apr 2016 12:33:50 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:34210) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aoCsO-0005lZ-EL; Thu, 07 Apr 2016 12:33:48 -0400 Received: by mail-wm0-x241.google.com with SMTP id n3so22831074wmn.1; Thu, 07 Apr 2016 09:33:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=+dHlfpMbM467sW9pslMk3/9JnNPlzUvN6OlAo+2H4Xc=; b=PLzRfuUXru2pGIAB87KVDx7y5t4tSVpiHeeDfcWU0PtcAvi4a2lNvg2C/751WieLzP 0YnM5ImHllYf1BykLsfUL3YMwIRgyZRXsApDA7jmBzjWRknalyI0Un/B+ruEycSuVg1/ swbMbcvRlaL7xUTwO2IF+LiKKlhN1KbmL/xsL0Z/ldNH3/ZB1dItFveAXUxmQPGj86iN XF1HjcHSyE+qhmdbLXP0tz4/yIhEtb6TzV3Dghu6OxVuznErOMmPgZv+0KiyLIjK87q8 aDN/SSRomLc/Y3pa17rGPn2uXjf1ki1eSOzv92woXD9Tua86Tc6xhTk1rmmNNR7GZV5e mO4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=+dHlfpMbM467sW9pslMk3/9JnNPlzUvN6OlAo+2H4Xc=; b=HRzZjTENe2NrhPaVKx/cf/HeJSxljfe/NSmWlm0P194KVp5NjW3PyAyOZoUwLfD6Zm PEtPQ83k0dyf5wzIoZVaZZgjib9yKeWzfc+o/k3nXVMzR6V4tTEsH2trA+jrNxuRX51e xjqO66LJ+9q//feg/V+Bu7CNyMFghJMRpu3Cb6+yU3BvOcaUPd3gIgKIQmXPLkMR/xv/ Hh3ghygsgFBd3Fwh9hQoceqVaBVEHyoJxjwKwaEL1gp3LrX08xH5KW7HbyM8kvrMy8hL XsZdBBw0HyVRJtGDiyPmg7AL5N+sQYs2MOFGtUZk2OXLSjhKhW0l5tdyzEBPk5xjSdSg hs0Q== X-Gm-Message-State: AD7BkJLcK41HqxLptMZ03AKZhYfNBYz24mq1sQVCRu0r1QnCEO7IUoUKTViIxHaMhQKUIA== X-Received: by 10.194.89.38 with SMTP id bl6mr4507285wjb.44.1460046827850; Thu, 07 Apr 2016 09:33:47 -0700 (PDT) Received: from 640k.lan (94-39-141-76.adsl-ull.clienti.tiscali.it. [94.39.141.76]) by smtp.gmail.com with ESMTPSA id hh8sm9218862wjc.42.2016.04.07.09.33.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Apr 2016 09:33:47 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Apr 2016 18:33:35 +0200 Message-Id: <1460046816-102846-8-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1460046816-102846-1-git-send-email-pbonzini@redhat.com> References: <1460046816-102846-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::241 Cc: kwolf@redhat.com, berto@igalia.com, famz@redhat.com, qemu-block@nongnu.org, stefanha@redhat.com Subject: [Qemu-devel] [PATCH v4 7/8] linux-aio: make it more type safe X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Replace void* with an opaque LinuxAioState type. Signed-off-by: Paolo Bonzini --- block/linux-aio.c | 46 +++++++++++++++++----------------------------- block/raw-aio.h | 15 ++++++++------- block/raw-posix.c | 4 ++-- 3 files changed, 27 insertions(+), 38 deletions(-) diff --git a/block/linux-aio.c b/block/linux-aio.c index 102bf92..90ec98e 100644 --- a/block/linux-aio.c +++ b/block/linux-aio.c @@ -30,7 +30,7 @@ struct qemu_laiocb { BlockAIOCB common; - struct qemu_laio_state *ctx; + LinuxAioState *ctx; struct iocb iocb; ssize_t ret; size_t nbytes; @@ -46,7 +46,7 @@ typedef struct { QSIMPLEQ_HEAD(, qemu_laiocb) pending; } LaioQueue; -struct qemu_laio_state { +struct LinuxAioState { io_context_t ctx; EventNotifier e; @@ -60,7 +60,7 @@ struct qemu_laio_state { int event_max; }; -static void ioq_submit(struct qemu_laio_state *s); +static void ioq_submit(LinuxAioState *s); static inline ssize_t io_event_ret(struct io_event *ev) { @@ -70,8 +70,7 @@ static inline ssize_t io_event_ret(struct io_event *ev) /* * Completes an AIO request (calls the callback and frees the ACB). */ -static void qemu_laio_process_completion(struct qemu_laio_state *s, - struct qemu_laiocb *laiocb) +static void qemu_laio_process_completion(struct qemu_laiocb *laiocb) { int ret; @@ -99,7 +98,7 @@ static void qemu_laio_process_completion(struct qemu_laio_state *s, * * The function is somewhat tricky because it supports nested event loops, for * example when a request callback invokes aio_poll(). In order to do this, - * the completion events array and index are kept in qemu_laio_state. The BH + * the completion events array and index are kept in LinuxAioState. The BH * reschedules itself as long as there are completions pending so it will * either be called again in a nested event loop or will be called after all * events have been completed. When there are no events left to complete, the @@ -107,7 +106,7 @@ static void qemu_laio_process_completion(struct qemu_laio_state *s, */ static void qemu_laio_completion_bh(void *opaque) { - struct qemu_laio_state *s = opaque; + LinuxAioState *s = opaque; /* Fetch more completion events when empty */ if (s->event_idx == s->event_max) { @@ -136,7 +135,7 @@ static void qemu_laio_completion_bh(void *opaque) laiocb->ret = io_event_ret(&s->events[s->event_idx]); s->event_idx++; - qemu_laio_process_completion(s, laiocb); + qemu_laio_process_completion(laiocb); } if (!s->io_q.plugged && !QSIMPLEQ_EMPTY(&s->io_q.pending)) { @@ -146,7 +145,7 @@ static void qemu_laio_completion_bh(void *opaque) static void qemu_laio_completion_cb(EventNotifier *e) { - struct qemu_laio_state *s = container_of(e, struct qemu_laio_state, e); + LinuxAioState *s = container_of(e, LinuxAioState, e); if (event_notifier_test_and_clear(&s->e)) { qemu_bh_schedule(s->completion_bh); @@ -185,7 +184,7 @@ static void ioq_init(LaioQueue *io_q) io_q->blocked = false; } -static void ioq_submit(struct qemu_laio_state *s) +static void ioq_submit(LinuxAioState *s) { int ret, len; struct qemu_laiocb *aiocb; @@ -216,18 +215,14 @@ static void ioq_submit(struct qemu_laio_state *s) s->io_q.blocked = (s->io_q.n > 0); } -void laio_io_plug(BlockDriverState *bs, void *aio_ctx) +void laio_io_plug(BlockDriverState *bs, LinuxAioState *s) { - struct qemu_laio_state *s = aio_ctx; - assert(!s->io_q.plugged); s->io_q.plugged = 1; } -void laio_io_unplug(BlockDriverState *bs, void *aio_ctx) +void laio_io_unplug(BlockDriverState *bs, LinuxAioState *s) { - struct qemu_laio_state *s = aio_ctx; - assert(s->io_q.plugged); s->io_q.plugged = 0; if (!s->io_q.blocked && !QSIMPLEQ_EMPTY(&s->io_q.pending)) { @@ -235,11 +230,10 @@ void laio_io_unplug(BlockDriverState *bs, void *aio_ctx) } } -BlockAIOCB *laio_submit(BlockDriverState *bs, void *aio_ctx, int fd, +BlockAIOCB *laio_submit(BlockDriverState *bs, LinuxAioState *s, int fd, int64_t sector_num, QEMUIOVector *qiov, int nb_sectors, BlockCompletionFunc *cb, void *opaque, int type) { - struct qemu_laio_state *s = aio_ctx; struct qemu_laiocb *laiocb; struct iocb *iocbs; off_t offset = sector_num * 512; @@ -281,26 +275,22 @@ out_free_aiocb: return NULL; } -void laio_detach_aio_context(void *s_, AioContext *old_context) +void laio_detach_aio_context(LinuxAioState *s, AioContext *old_context) { - struct qemu_laio_state *s = s_; - aio_set_event_notifier(old_context, &s->e, false, NULL); qemu_bh_delete(s->completion_bh); } -void laio_attach_aio_context(void *s_, AioContext *new_context) +void laio_attach_aio_context(LinuxAioState *s, AioContext *new_context) { - struct qemu_laio_state *s = s_; - s->completion_bh = aio_bh_new(new_context, qemu_laio_completion_bh, s); aio_set_event_notifier(new_context, &s->e, false, qemu_laio_completion_cb); } -void *laio_init(void) +LinuxAioState *laio_init(void) { - struct qemu_laio_state *s; + LinuxAioState *s; s = g_malloc0(sizeof(*s)); if (event_notifier_init(&s->e, false) < 0) { @@ -322,10 +312,8 @@ out_free_state: return NULL; } -void laio_cleanup(void *s_) +void laio_cleanup(LinuxAioState *s) { - struct qemu_laio_state *s = s_; - event_notifier_cleanup(&s->e); if (io_destroy(s->ctx) != 0) { diff --git a/block/raw-aio.h b/block/raw-aio.h index 0f5e35a..714714e 100644 --- a/block/raw-aio.h +++ b/block/raw-aio.h @@ -35,15 +35,16 @@ /* linux-aio.c - Linux native implementation */ #ifdef CONFIG_LINUX_AIO -void *laio_init(void); -void laio_cleanup(void *s); -BlockAIOCB *laio_submit(BlockDriverState *bs, void *aio_ctx, int fd, +typedef struct LinuxAioState LinuxAioState; +LinuxAioState *laio_init(void); +void laio_cleanup(LinuxAioState *s); +BlockAIOCB *laio_submit(BlockDriverState *bs, LinuxAioState *s, int fd, int64_t sector_num, QEMUIOVector *qiov, int nb_sectors, BlockCompletionFunc *cb, void *opaque, int type); -void laio_detach_aio_context(void *s, AioContext *old_context); -void laio_attach_aio_context(void *s, AioContext *new_context); -void laio_io_plug(BlockDriverState *bs, void *aio_ctx); -void laio_io_unplug(BlockDriverState *bs, void *aio_ctx); +void laio_detach_aio_context(LinuxAioState *s, AioContext *old_context); +void laio_attach_aio_context(LinuxAioState *s, AioContext *new_context); +void laio_io_plug(BlockDriverState *bs, LinuxAioState *s); +void laio_io_unplug(BlockDriverState *bs, LinuxAioState *s); #endif #ifdef _WIN32 diff --git a/block/raw-posix.c b/block/raw-posix.c index 50135ad..71ec463 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -139,7 +139,7 @@ typedef struct BDRVRawState { #ifdef CONFIG_LINUX_AIO int use_aio; - void *aio_ctx; + LinuxAioState *aio_ctx; #endif #ifdef CONFIG_XFS bool is_xfs:1; @@ -398,7 +398,7 @@ static void raw_attach_aio_context(BlockDriverState *bs, } #ifdef CONFIG_LINUX_AIO -static int raw_set_aio(void **aio_ctx, int *use_aio, int bdrv_flags) +static int raw_set_aio(LinuxAioState **aio_ctx, int *use_aio, int bdrv_flags) { int ret = -1; assert(aio_ctx != NULL);