From nobody Mon Feb 9 16:03:00 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1505248602050731.781956761456; Tue, 12 Sep 2017 13:36:42 -0700 (PDT) Received: from localhost ([::1]:38464 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drrvF-0006p6-5O for importer@patchew.org; Tue, 12 Sep 2017 16:36:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39359) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drrqP-0001eM-VJ for qemu-devel@nongnu.org; Tue, 12 Sep 2017 16:31:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1drrqO-0005b4-Pj for qemu-devel@nongnu.org; Tue, 12 Sep 2017 16:31:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38376) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1drrqK-0005Uj-NC; Tue, 12 Sep 2017 16:31:36 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C62C381DED; Tue, 12 Sep 2017 20:31:35 +0000 (UTC) Received: from red.redhat.com (ovpn-120-44.rdu2.redhat.com [10.10.120.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5B9A55C6D7; Tue, 12 Sep 2017 20:31:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C62C381DED Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 12 Sep 2017 15:31:04 -0500 Message-Id: <20170912203119.24166-6-eblake@redhat.com> In-Reply-To: <20170912203119.24166-1-eblake@redhat.com> References: <20170912203119.24166-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 12 Sep 2017 20:31:35 +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 v7 05/20] dirty-bitmap: Check for size query failure during truncate 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, vsementsov@virtuozzo.com, Fam Zheng , qemu-block@nongnu.org, Max Reitz , jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We've previously fixed several places where we failed to account for possible errors from bdrv_nb_sectors(). Fix another one by making bdrv_dirty_bitmap_truncate() report the error rather then silently resizing bitmaps to -1. Then adjust the sole caller bdrv_truncate() to both reduce the likelihood of failure (blindly calling bdrv_dirty_bitmap_truncate() after refresh_total_sectors() fails was not nice) as well as propagate any actual failures. Signed-off-by: Eric Blake --- v7: new patch [Kevin] --- include/block/dirty-bitmap.h | 2 +- block.c | 19 ++++++++++++++----- block/dirty-bitmap.c | 12 ++++++++---- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h index 8fd842eac9..15101b59d5 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -83,7 +83,7 @@ int64_t bdrv_dirty_iter_next(BdrvDirtyBitmapIter *iter); void bdrv_set_dirty_iter(BdrvDirtyBitmapIter *hbi, int64_t sector_num); int64_t bdrv_get_dirty_count(BdrvDirtyBitmap *bitmap); int64_t bdrv_get_meta_dirty_count(BdrvDirtyBitmap *bitmap); -void bdrv_dirty_bitmap_truncate(BlockDriverState *bs); +int bdrv_dirty_bitmap_truncate(BlockDriverState *bs); bool bdrv_dirty_bitmap_readonly(const BdrvDirtyBitmap *bitmap); bool bdrv_has_readonly_bitmaps(BlockDriverState *bs); bool bdrv_dirty_bitmap_get_autoload(const BdrvDirtyBitmap *bitmap); diff --git a/block.c b/block.c index ee6a48976e..790dcce360 100644 --- a/block.c +++ b/block.c @@ -3450,12 +3450,21 @@ int bdrv_truncate(BdrvChild *child, int64_t offset,= PreallocMode prealloc, assert(!(bs->open_flags & BDRV_O_INACTIVE)); ret =3D drv->bdrv_truncate(bs, offset, prealloc, errp); - if (ret =3D=3D 0) { - ret =3D refresh_total_sectors(bs, offset >> BDRV_SECTOR_BITS); - bdrv_dirty_bitmap_truncate(bs); - bdrv_parent_cb_resize(bs); - atomic_inc(&bs->write_gen); + if (ret < 0) { + return ret; } + ret =3D refresh_total_sectors(bs, offset >> BDRV_SECTOR_BITS); + if (ret < 0) { + error_setg_errno(errp, -ret, "Could not refresh total sector count= "); + return ret; + } + ret =3D bdrv_dirty_bitmap_truncate(bs); + if (ret < 0) { + error_setg_errno(errp, -ret, "Could not refresh total sector count= "); + return ret; + } + bdrv_parent_cb_resize(bs); + atomic_inc(&bs->write_gen); return ret; } diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index 42a55e4a4b..52f7a399b2 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -1,7 +1,7 @@ /* * Block Dirty Bitmap * - * Copyright (c) 2016 Red Hat. Inc + * Copyright (c) 2016-2017 Red Hat. Inc * * Permission is hereby granted, free of charge, to any person obtaining a= copy * of this software and associated documentation files (the "Software"), t= o deal @@ -300,13 +300,16 @@ BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BlockDrive= rState *bs, /** * Truncates _all_ bitmaps attached to a BDS. - * Called with BQL taken. + * Called with BQL taken, returns -errno on failure. */ -void bdrv_dirty_bitmap_truncate(BlockDriverState *bs) +int bdrv_dirty_bitmap_truncate(BlockDriverState *bs) { BdrvDirtyBitmap *bitmap; - uint64_t size =3D bdrv_nb_sectors(bs); + int64_t size =3D bdrv_nb_sectors(bs); + if (size < 0) { + return size; + } bdrv_dirty_bitmaps_lock(bs); QLIST_FOREACH(bitmap, &bs->dirty_bitmaps, list) { assert(!bdrv_dirty_bitmap_frozen(bitmap)); @@ -315,6 +318,7 @@ void bdrv_dirty_bitmap_truncate(BlockDriverState *bs) bitmap->size =3D size; } bdrv_dirty_bitmaps_unlock(bs); + return 0; } static bool bdrv_dirty_bitmap_has_name(BdrvDirtyBitmap *bitmap) --=20 2.13.5