From patchwork Wed Apr 20 15:03:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 8891021 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 B6F1C9F441 for ; Wed, 20 Apr 2016 15:06:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1ABA5200DF for ; Wed, 20 Apr 2016 15:06:30 +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 42EE82020F for ; Wed, 20 Apr 2016 15:06:29 +0000 (UTC) Received: from localhost ([::1]:51010 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1asti0-0005UQ-D9 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 20 Apr 2016 11:06:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44342) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1astfR-0007sb-Tn for qemu-devel@nongnu.org; Wed, 20 Apr 2016 11:03:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1astfN-0002Oy-V7 for qemu-devel@nongnu.org; Wed, 20 Apr 2016 11:03:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45592) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1astfE-0002Jo-R2; Wed, 20 Apr 2016 11:03:36 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5BB9D6266C; Wed, 20 Apr 2016 15:03:35 +0000 (UTC) Received: from noname.str.redhat.com. (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3KF3X3p023049; Wed, 20 Apr 2016 11:03:34 -0400 From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 20 Apr 2016 17:03:28 +0200 Message-Id: <1461164612-25805-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1461164612-25805-1-git-send-email-kwolf@redhat.com> References: <1461164612-25805-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 20 Apr 2016 15:03:35 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 1/5] block/mirror: Revive dead yielding code 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: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 From: Max Reitz mirror_iteration() is supposed to wait if the current chunk is subject to a still in-flight mirroring operation. However, it mixed checking this conflict situation with checking the dirty status of a chunk. A simplification for the latter condition (the first chunk encountered is always dirty) led to neglecting the former: We just skip the first chunk and thus never test whether it conflicts with an in-flight operation. To fix this, pull out the code which waits for in-flight operations on the first chunk of the range to be mirrored to settle. Signed-off-by: Max Reitz Reviewed-by: Fam Zheng Signed-off-by: Kevin Wolf --- block/mirror.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index c2cfc1a..2714a77 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -298,7 +298,7 @@ static void mirror_do_zero_or_discard(MirrorBlockJob *s, static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s) { BlockDriverState *source = s->common.bs; - int64_t sector_num; + int64_t sector_num, first_chunk; uint64_t delay_ns = 0; /* At least the first dirty chunk is mirrored in one iteration. */ int nb_chunks = 1; @@ -313,6 +313,12 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s) assert(sector_num >= 0); } + first_chunk = sector_num / sectors_per_chunk; + while (test_bit(first_chunk, s->in_flight_bitmap)) { + trace_mirror_yield_in_flight(s, first_chunk, s->in_flight); + mirror_wait_for_io(s); + } + /* Find the number of consective dirty chunks following the first dirty * one, and wait for in flight requests in them. */ while (nb_chunks * sectors_per_chunk < (s->buf_size >> BDRV_SECTOR_BITS)) { @@ -324,17 +330,12 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s) break; } if (test_bit(next_chunk, s->in_flight_bitmap)) { - if (nb_chunks > 0) { - break; - } - trace_mirror_yield_in_flight(s, next_sector, s->in_flight); - mirror_wait_for_io(s); - /* Now retry. */ - } else { - hbitmap_next = hbitmap_iter_next(&s->hbi); - assert(hbitmap_next == next_sector); - nb_chunks++; + break; } + + hbitmap_next = hbitmap_iter_next(&s->hbi); + assert(hbitmap_next == next_sector); + nb_chunks++; } /* Clear dirty bits before querying the block status, because