From patchwork Fri Feb 5 02:00:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 8230021 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 BCF1F9F1C1 for ; Fri, 5 Feb 2016 02:01:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2314620383 for ; Fri, 5 Feb 2016 02:01:08 +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 5015A202F8 for ; Fri, 5 Feb 2016 02:01:07 +0000 (UTC) Received: from localhost ([::1]:45367 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRVhq-0006c7-Qf for patchwork-qemu-devel@patchwork.kernel.org; Thu, 04 Feb 2016 21:01:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41970) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRVhe-0006Xc-Hi for qemu-devel@nongnu.org; Thu, 04 Feb 2016 21:00:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aRVhZ-00015l-J5 for qemu-devel@nongnu.org; Thu, 04 Feb 2016 21:00:54 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53799) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRVhX-00015Q-HV; Thu, 04 Feb 2016 21:00:47 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 1933F8F4ED; Fri, 5 Feb 2016 02:00:47 +0000 (UTC) Received: from fam-t430.nay.redhat.com (dhcp-15-42.nay.redhat.com [10.66.15.42]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u1520WpK005747; Thu, 4 Feb 2016 21:00:43 -0500 From: Fam Zheng To: qemu-devel@nongnu.org Date: Fri, 5 Feb 2016 10:00:30 +0800 Message-Id: <1454637630-10585-3-git-send-email-famz@redhat.com> In-Reply-To: <1454637630-10585-1-git-send-email-famz@redhat.com> References: <1454637630-10585-1-git-send-email-famz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 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 v12 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 48cd0b3..9635fa8 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);