From patchwork Thu May 11 02:20:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 9720839 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 288C160236 for ; Thu, 11 May 2017 02:31:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2DDC3285F3 for ; Thu, 11 May 2017 02:31:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 22051285F0; Thu, 11 May 2017 02:31:45 +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=-6.9 required=2.0 tests=BAYES_00,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 B3F1D285F3 for ; Thu, 11 May 2017 02:31:44 +0000 (UTC) Received: from localhost ([::1]:45616 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8dtH-0003G5-OQ for patchwork-qemu-devel@patchwork.kernel.org; Wed, 10 May 2017 22:31:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41204) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8djJ-0003Qo-Hu for qemu-devel@nongnu.org; Wed, 10 May 2017 22:21:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d8djI-0005f2-OF for qemu-devel@nongnu.org; Wed, 10 May 2017 22:21:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44072) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d8djG-0005cW-J3; Wed, 10 May 2017 22:21:22 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B5DBD8553D; Thu, 11 May 2017 02:21:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B5DBD8553D Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com B5DBD8553D Received: from red.redhat.com (ovpn-120-208.rdu2.redhat.com [10.10.120.208]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8381C179DA; Thu, 11 May 2017 02:21:19 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 10 May 2017 21:20:35 -0500 Message-Id: <20170511022036.32225-20-eblake@redhat.com> In-Reply-To: <20170511022036.32225-1-eblake@redhat.com> References: <20170511022036.32225-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 11 May 2017 02:21:21 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 19/20] block: Minimize raw use of bds->total_sectors 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 , Fam Zheng , qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi , jsnow@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP bdrv_is_allocated_above() was relying on intermediate->total_sectors, which is a field that can have stale contents depending on the value of intermediate->has_variable_length. An audit shows that we are safe (we were first calling through bdrv_co_get_block_status() which in turn calls bdrv_nb_sectors() and therefore just refreshed the current length), but it's nicer to favor our accessor functions to avoid having to repeat such an audit, even if it means refresh_total_sectors() is called more frequently. Suggested-by: John Snow Signed-off-by: Eric Blake --- v2: new patch --- block/io.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/block/io.c b/block/io.c index 9ab89cb..20d3ebd 100644 --- a/block/io.c +++ b/block/io.c @@ -1939,6 +1939,7 @@ int bdrv_is_allocated_above(BlockDriverState *top, intermediate = top; while (intermediate && intermediate != base) { int64_t pnum_inter; + int64_t size_inter; int psectors_inter; ret = bdrv_is_allocated(intermediate, sector_num * BDRV_SECTOR_SIZE, @@ -1956,13 +1957,14 @@ int bdrv_is_allocated_above(BlockDriverState *top, /* * [sector_num, nb_sectors] is unallocated on top but intermediate - * might have - * - * [sector_num+x, nr_sectors] allocated. + * might have [sector_num+x, nb_sectors-x] allocated. */ + size_inter = bdrv_nb_sectors(intermediate); + if (size_inter < 0) { + return size_inter; + } if (n > psectors_inter && - (intermediate == top || - sector_num + psectors_inter < intermediate->total_sectors)) { + (intermediate == top || sector_num + psectors_inter < size_inter)) { n = psectors_inter; }