From nobody Mon Feb 9 02:28:26 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.47 as permitted sender) client-ip=209.51.188.47; 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 209.51.188.47 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1559849389; cv=none; d=zoho.com; s=zohoarc; b=f5kFhLxK3LcZHGEhT2PH0AEb1eIOJJ6+bV+H8C5iSTzkvloiTaiSfrRJbrotie3ChYR4a9d1PMHTKiDppjLG8TjGg2p9CRVJGPwcynsAuMXNY+F1Z3fLrIJMgjjJxlEV0YwClLFMM3mcMMmfeJV7Xudm6GzEQoaJZpwsuAqNT7k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559849389; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=Y5OI3UYtufuV7blzTw8Lik+RB1l2wvf/5oMpP8lKaU0=; b=lsoIMbkqleFcJr5AjQ7CFHlE51wHDA3xp6234T11o2VsBvs227+haxqAvnGSm/p5RocTpoBY+xdI0UR85XPl+sTH+EYdIAB80L9BWgQ7+GVWBAFaeSZxweqz3NZmd9jHIlwi0fwCSn+0UQlBzko7BQko3CJhCCyr4bSU90etb90= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.47 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.47]) by mx.zohomail.com with SMTPS id 1559849388960646.548519384338; Thu, 6 Jun 2019 12:29:48 -0700 (PDT) Received: from localhost ([::1]:56048 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hYy52-0007Jh-Aw for importer@patchew.org; Thu, 06 Jun 2019 15:29:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53591) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hYxlW-0004fI-Ie for qemu-devel@nongnu.org; Thu, 06 Jun 2019 15:09:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hYxLI-0000D0-LW for qemu-devel@nongnu.org; Thu, 06 Jun 2019 14:42:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57498) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hYxLE-0007tP-KQ; Thu, 06 Jun 2019 14:42:25 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 63E6159467; Thu, 6 Jun 2019 18:42:12 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-177.bos.redhat.com [10.18.17.177]) by smtp.corp.redhat.com (Postfix) with ESMTP id 43CAC5C2E6; Thu, 6 Jun 2019 18:42:09 +0000 (UTC) From: John Snow To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Thu, 6 Jun 2019 14:41:59 -0400 Message-Id: <20190606184159.979-6-jsnow@redhat.com> In-Reply-To: <20190606184159.979-1-jsnow@redhat.com> References: <20190606184159.979-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 06 Jun 2019 18:42:12 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PATCH 5/5] block/qcow2-bitmap: Count queued bitmaps towards directory_size X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Kevin Wolf , vsementsov@virtuozzo.com, Markus Armbruster , Max Reitz , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Similarly to the previous commit, we need to also keep a ledger of the additional directory size burden that we've not yet committed so we can reject new additions sooner instead of later. Signed-off-by: John Snow --- block/qcow2.h | 1 + block/qcow2-bitmap.c | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/block/qcow2.h b/block/qcow2.h index ebf60ac236..5aff97eb9c 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -318,6 +318,7 @@ typedef struct BDRVQcow2State { =20 uint32_t nb_bitmaps; uint32_t nb_queued_bitmaps; + uint32_t queued_directory_size; uint64_t bitmap_directory_size; uint64_t bitmap_directory_offset; =20 diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index 7193c66787..b103fab362 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -1405,16 +1405,23 @@ static Qcow2Bitmap *find_bitmap_by_name(Qcow2Bitmap= List *bm_list, static int qcow2_remove_queued_dirty_bitmap( BlockDriverState *bs, const char *name, Error **errp) { + uint32_t size_delta; BDRVQcow2State *s =3D bs->opaque; BdrvDirtyBitmap *bitmap =3D bdrv_find_dirty_bitmap(bs, name); + if (!bitmap) { error_setg(errp, "Node '%s' has no stored or enqueued bitmap '%s'", bdrv_get_node_name(bs), name); return -ENOENT; } + + size_delta =3D calc_dir_entry_size(strlen(name), 0); assert(s->nb_queued_bitmaps > 0); assert(bdrv_dirty_bitmap_get_persistence(bitmap)); + assert(s->queued_directory_size >=3D size_delta); + s->nb_queued_bitmaps -=3D 1; + s->queued_directory_size -=3D size_delta; =20 return 0; } @@ -1561,6 +1568,7 @@ void qcow2_store_persistent_dirty_bitmaps(BlockDriver= State *bs, Error **errp) goto fail; } s->nb_queued_bitmaps =3D 0; + s->queued_directory_size =3D 0; =20 /* Bitmap directory was successfully updated, so, old data can be drop= ped. * TODO it is better to reuse these clusters */ @@ -1636,6 +1644,7 @@ int qcow2_add_persistent_dirty_bitmap(BlockDriverStat= e *bs, const char *name =3D bdrv_dirty_bitmap_name(bitmap); uint32_t granularity =3D bdrv_dirty_bitmap_granularity(bitmap); uint32_t nb_bitmaps; + uint32_t size_delta; int ret =3D 0; =20 if (s->qcow_version < 3) { @@ -1666,7 +1675,8 @@ int qcow2_add_persistent_dirty_bitmap(BlockDriverStat= e *bs, goto fail; } =20 - if (s->bitmap_directory_size + calc_dir_entry_size(strlen(name), 0) > + size_delta =3D calc_dir_entry_size(strlen(name), 0); + if (s->bitmap_directory_size + s->queued_directory_size + size_delta > QCOW2_MAX_BITMAP_DIRECTORY_SIZE) { error_setg(errp, "Not enough space in the bitmap directory"); @@ -1687,6 +1697,7 @@ int qcow2_add_persistent_dirty_bitmap(BlockDriverStat= e *bs, } =20 s->nb_queued_bitmaps +=3D 1; + s->queued_directory_size +=3D size_delta; =20 return 0; fail: --=20 2.20.1