From patchwork Mon Aug 13 02:19:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 10563839 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 80BA81510 for ; Mon, 13 Aug 2018 02:25:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E53E28CF4 for ; Mon, 13 Aug 2018 02:25:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 62A2428CF9; Mon, 13 Aug 2018 02:25:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 13C7E28CF4 for ; Mon, 13 Aug 2018 02:25:35 +0000 (UTC) Received: from localhost ([::1]:37189 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fp2Y2-0008Ep-Bh for patchwork-qemu-devel@patchwork.kernel.org; Sun, 12 Aug 2018 22:25:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53168) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fp2TB-0003WJ-5C for qemu-devel@nongnu.org; Sun, 12 Aug 2018 22:20:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fp2TA-0008BQ-1m for qemu-devel@nongnu.org; Sun, 12 Aug 2018 22:20:33 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:40342 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fp2T4-0007y2-SD; Sun, 12 Aug 2018 22:20:26 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 38F8B40241C0; Mon, 13 Aug 2018 02:20:26 +0000 (UTC) Received: from localhost (ovpn-204-21.brq.redhat.com [10.40.204.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CB77D2156712; Mon, 13 Aug 2018 02:20:25 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 13 Aug 2018 04:19:55 +0200 Message-Id: <20180813022006.7216-7-mreitz@redhat.com> In-Reply-To: <20180813022006.7216-1-mreitz@redhat.com> References: <20180813022006.7216-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 13 Aug 2018 02:20:26 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 13 Aug 2018 02:20:26 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 06/17] mirror: Create mirror_co_perform() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Jeff Cody , Fam Zheng , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP While very simple now, this function will be fattened in future patches. Signed-off-by: Max Reitz --- block/mirror.c | 48 +++++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index f05404e557..89452ad371 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -85,8 +85,16 @@ typedef struct MirrorBDSOpaque { MirrorBlockJob *job; } MirrorBDSOpaque; +typedef enum MirrorMethod { + MIRROR_METHOD_COPY, + MIRROR_METHOD_ZERO, + MIRROR_METHOD_DISCARD, +} MirrorMethod; + struct MirrorOp { MirrorBlockJob *s; + MirrorMethod mirror_method; + QEMUIOVector qiov; int64_t offset; int64_t bytes; @@ -98,12 +106,6 @@ struct MirrorOp { QTAILQ_ENTRY(MirrorOp) next; }; -typedef enum MirrorMethod { - MIRROR_METHOD_COPY, - MIRROR_METHOD_ZERO, - MIRROR_METHOD_DISCARD, -} MirrorMethod; - static BlockErrorAction mirror_error_action(MirrorBlockJob *s, bool read, int error) { @@ -387,6 +389,25 @@ static void coroutine_fn mirror_co_discard(void *opaque) mirror_write_complete(op, ret); } +static void coroutine_fn mirror_co_perform(void *opaque) +{ + MirrorOp *op = opaque; + + switch (op->mirror_method) { + case MIRROR_METHOD_COPY: + mirror_co_read(opaque); + return; + case MIRROR_METHOD_ZERO: + mirror_co_zero(opaque); + return; + case MIRROR_METHOD_DISCARD: + mirror_co_discard(opaque); + return; + default: + abort(); + } +} + /* If mirror_method == MIRROR_METHOD_COPY, *offset and *bytes will be * aligned as necessary */ static void mirror_perform(MirrorBlockJob *s, int64_t *offset, int64_t *bytes, @@ -402,24 +423,13 @@ static void mirror_perform(MirrorBlockJob *s, int64_t *offset, int64_t *bytes, op = g_new(MirrorOp, 1); *op = (MirrorOp){ .s = s, + .mirror_method = mirror_method, .offset = *offset, .bytes = *bytes, }; qemu_co_queue_init(&op->waiting_requests); - switch (mirror_method) { - case MIRROR_METHOD_COPY: - co = qemu_coroutine_create(mirror_co_read, op); - break; - case MIRROR_METHOD_ZERO: - co = qemu_coroutine_create(mirror_co_zero, op); - break; - case MIRROR_METHOD_DISCARD: - co = qemu_coroutine_create(mirror_co_discard, op); - break; - default: - abort(); - } + co = qemu_coroutine_create(mirror_co_perform, op); QTAILQ_INSERT_TAIL(&s->ops_in_flight, op, next); qemu_coroutine_enter(co);