From patchwork Wed Feb 3 01:52:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 8196981 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 C0F399F37A for ; Wed, 3 Feb 2016 01:53:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1B70220253 for ; Wed, 3 Feb 2016 01:53:24 +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 65AF720221 for ; Wed, 3 Feb 2016 01:53:23 +0000 (UTC) Received: from localhost ([::1]:60311 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aQmdG-0007DH-TE for patchwork-qemu-devel@patchwork.kernel.org; Tue, 02 Feb 2016 20:53:22 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38927) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aQmce-0006Tc-SC for qemu-devel@nongnu.org; Tue, 02 Feb 2016 20:52:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aQmcZ-0002xG-Nv for qemu-devel@nongnu.org; Tue, 02 Feb 2016 20:52:44 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41363) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aQmcX-0002vY-ME; Tue, 02 Feb 2016 20:52:37 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 45EAC461D5; Wed, 3 Feb 2016 01:52:37 +0000 (UTC) Received: from fam-t430.nay.redhat.com (dhcp-15-42.nay.redhat.com [10.66.15.42]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u131qMOW020138; Tue, 2 Feb 2016 20:52:34 -0500 From: Fam Zheng To: qemu-devel@nongnu.org Date: Wed, 3 Feb 2016 09:52:21 +0800 Message-Id: <1454464341-9494-3-git-send-email-famz@redhat.com> In-Reply-To: <1454464341-9494-1-git-send-email-famz@redhat.com> References: <1454464341-9494-1-git-send-email-famz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , pbonzini@redhat.com, Jeff Cody , qemu-block@nongnu.org, mreitz@redhat.com Subject: [Qemu-devel] [PATCH v11 2/2] mirror: Add mirror_wait_for_io 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.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable 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 The three lines are duplicated a number of times now, refactor a function. Signed-off-by: Fam Zheng Reviewed-by: Max Reitz --- block/mirror.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index 8b06a31..219decd 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -196,6 +196,14 @@ static int mirror_cow_align(MirrorBlockJob *s, return ret; } +static inline void mirror_wait_for_io(MirrorBlockJob *s) +{ + assert(!s->waiting_for_io); + s->waiting_for_io = true; + qemu_coroutine_yield(); + s->waiting_for_io = false; +} + /* Submit async read while handling COW. * Returns: nb_sectors if no alignment is necessary, or * (new_end - sector_num) if tail is rounded up or down due to @@ -228,9 +236,7 @@ static int mirror_do_read(MirrorBlockJob *s, int64_t sector_num, while (s->buf_free_count < nb_chunks) { trace_mirror_yield_in_flight(s, sector_num, s->in_flight); - s->waiting_for_io = true; - qemu_coroutine_yield(); - s->waiting_for_io = false; + mirror_wait_for_io(s); } /* Allocate a MirrorOp that is used as an AIO callback. */ @@ -321,9 +327,7 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s) break; } trace_mirror_yield_in_flight(s, next_sector, s->in_flight); - s->waiting_for_io = true; - qemu_coroutine_yield(); - s->waiting_for_io = false; + mirror_wait_for_io(s); /* Now retry. */ } else { hbitmap_next = hbitmap_iter_next(&s->hbi); @@ -414,9 +418,7 @@ static void mirror_free_init(MirrorBlockJob *s) static void mirror_drain(MirrorBlockJob *s) { while (s->in_flight > 0) { - s->waiting_for_io = true; - qemu_coroutine_yield(); - s->waiting_for_io = false; + mirror_wait_for_io(s); } } @@ -604,9 +606,7 @@ static void coroutine_fn mirror_run(void *opaque) if (s->in_flight == MAX_IN_FLIGHT || s->buf_free_count == 0 || (cnt == 0 && s->in_flight > 0)) { trace_mirror_yield(s, s->in_flight, s->buf_free_count, cnt); - s->waiting_for_io = true; - qemu_coroutine_yield(); - s->waiting_for_io = false; + mirror_wait_for_io(s); continue; } else if (cnt != 0) { delay_ns = mirror_iteration(s);