From nobody Sat May 18 18:02:04 2024 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=1559849144; cv=none; d=zoho.com; s=zohoarc; b=EVH0iPc3QfYUGJ1a+Ytec5Mqr6r8ekBuboaVXJlNznXOGkahy3tFosOq3iCY0fDBZOwX99ywazqYsMlymrMUZQvM0DEJu5W5yrxBsqUKKcKIkhziMFeO2+MyvlnpaakhvdLuo3pSDridku31XfOUunFFWNRYXDNAioBjMp4B1CQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559849144; 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=iFlMSDpNC4GlyiDx3qeJq/8IzlF2h7Rsxr68DliESNY=; b=Ktw7/6asqvh6UpF2zWUcg0rgrZm23HxB8r4CVXHF70jaw211DfWNHgpnAKdgbeqtazLZbt2AigctwYBZU3jSduBs+ATlGmCbmpOfYdjL0BVNopqC1MhnPFHpuvskmWuhkr8esBVnaWJJTSBrcc5RhjTTXo1kjxIUEb+RFgfcDPc= 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 1559849144613521.5909169695514; Thu, 6 Jun 2019 12:25:44 -0700 (PDT) Received: from localhost ([::1]:55506 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hYy16-00058m-Jv for importer@patchew.org; Thu, 06 Jun 2019 15:25:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53577) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hYxlF-0004e6-Tu for qemu-devel@nongnu.org; Thu, 06 Jun 2019 15:09:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hYxLU-0000Rk-5h for qemu-devel@nongnu.org; Thu, 06 Jun 2019 14:42:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46740) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hYxLG-0007o5-OE; Thu, 06 Jun 2019 14:42:27 -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 D9490307D840; Thu, 6 Jun 2019 18:42:05 +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 E58615C2EC; Thu, 6 Jun 2019 18:42:04 +0000 (UTC) From: John Snow To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Thu, 6 Jun 2019 14:41:55 -0400 Message-Id: <20190606184159.979-2-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.48]); Thu, 06 Jun 2019 18:42:05 +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 1/5] block/qcow2-bitmap: allow bitmap_list_load to return an error code 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" This simply makes this function a little more convenient to call, and in a forthcoming patch gives us a return code we can report to the caller. (Which in turn makes THOSE functions easier to call.) While we're here, remove the offset+size arguments which are only ever called with the same values that can be determined inside this helper. Signed-off-by: John Snow Reported-by: aihua liang Reviewed-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/qcow2-bitmap.c | 64 +++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 36 deletions(-) diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index b2487101ed..83aee1a42a 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -547,30 +547,33 @@ static uint32_t bitmap_list_count(Qcow2BitmapList *bm= _list) * Get bitmap list from qcow2 image. Actually reads bitmap directory, * checks it and convert to bitmap list. */ -static Qcow2BitmapList *bitmap_list_load(BlockDriverState *bs, uint64_t of= fset, - uint64_t size, Error **errp) +static int bitmap_list_load(BlockDriverState *bs, Qcow2BitmapList **bm_lis= t_out, + Error **errp) { - int ret; + int ret =3D 0; BDRVQcow2State *s =3D bs->opaque; uint8_t *dir, *dir_end; Qcow2BitmapDirEntry *e; uint32_t nb_dir_entries =3D 0; Qcow2BitmapList *bm_list =3D NULL; =20 + uint64_t offset =3D s->bitmap_directory_offset; + uint64_t size =3D s->bitmap_directory_size; + if (size =3D=3D 0) { - error_setg(errp, "Requested bitmap directory size is zero"); - return NULL; + error_setg(errp, "Cannot load a bitmap directory of size 0"); + return -EINVAL; } =20 if (size > QCOW2_MAX_BITMAP_DIRECTORY_SIZE) { error_setg(errp, "Requested bitmap directory size is too big"); - return NULL; + return -EINVAL; } =20 dir =3D g_try_malloc(size); if (dir =3D=3D NULL) { error_setg(errp, "Failed to allocate space for bitmap directory"); - return NULL; + return -ENOMEM; } dir_end =3D dir + size; =20 @@ -594,6 +597,7 @@ static Qcow2BitmapList *bitmap_list_load(BlockDriverSta= te *bs, uint64_t offset, if (++nb_dir_entries > s->nb_bitmaps) { error_setg(errp, "More bitmaps found than specified in header" " extension"); + ret =3D -EINVAL; goto fail; } bitmap_dir_entry_to_cpu(e); @@ -604,6 +608,7 @@ static Qcow2BitmapList *bitmap_list_load(BlockDriverSta= te *bs, uint64_t offset, =20 if (e->extra_data_size !=3D 0) { error_setg(errp, "Bitmap extra data is not supported"); + ret =3D -ENOTSUP; goto fail; } =20 @@ -626,6 +631,7 @@ static Qcow2BitmapList *bitmap_list_load(BlockDriverSta= te *bs, uint64_t offset, if (nb_dir_entries !=3D s->nb_bitmaps) { error_setg(errp, "Less bitmaps found than specified in header" " extension"); + ret =3D -EINVAL; goto fail; } =20 @@ -634,7 +640,8 @@ static Qcow2BitmapList *bitmap_list_load(BlockDriverSta= te *bs, uint64_t offset, } =20 g_free(dir); - return bm_list; + *bm_list_out =3D bm_list; + return ret; =20 broken_dir: ret =3D -EINVAL; @@ -644,7 +651,7 @@ fail: g_free(dir); bitmap_list_free(bm_list); =20 - return NULL; + return ret; } =20 int qcow2_check_bitmaps_refcounts(BlockDriverState *bs, BdrvCheckResult *r= es, @@ -667,11 +674,10 @@ int qcow2_check_bitmaps_refcounts(BlockDriverState *b= s, BdrvCheckResult *res, return ret; } =20 - bm_list =3D bitmap_list_load(bs, s->bitmap_directory_offset, - s->bitmap_directory_size, NULL); - if (bm_list =3D=3D NULL) { + ret =3D bitmap_list_load(bs, &bm_list, NULL); + if (ret) { res->corruptions++; - return -EINVAL; + return ret; } =20 QSIMPLEQ_FOREACH(bm, bm_list, entry) { @@ -971,9 +977,7 @@ bool qcow2_load_dirty_bitmaps(BlockDriverState *bs, Err= or **errp) return false; } =20 - bm_list =3D bitmap_list_load(bs, s->bitmap_directory_offset, - s->bitmap_directory_size, errp); - if (bm_list =3D=3D NULL) { + if (bitmap_list_load(bs, &bm_list, errp)) { return false; } =20 @@ -1080,9 +1084,7 @@ Qcow2BitmapInfoList *qcow2_get_bitmap_info_list(Block= DriverState *bs, return NULL; } =20 - bm_list =3D bitmap_list_load(bs, s->bitmap_directory_offset, - s->bitmap_directory_size, errp); - if (bm_list =3D=3D NULL) { + if (bitmap_list_load(bs, &bm_list, errp)) { return NULL; } =20 @@ -1125,10 +1127,8 @@ int qcow2_reopen_bitmaps_rw_hint(BlockDriverState *b= s, bool *header_updated, return -EINVAL; } =20 - bm_list =3D bitmap_list_load(bs, s->bitmap_directory_offset, - s->bitmap_directory_size, errp); - if (bm_list =3D=3D NULL) { - return -EINVAL; + if ((ret =3D bitmap_list_load(bs, &bm_list, errp))) { + return ret; } =20 QSIMPLEQ_FOREACH(bm, bm_list, entry) { @@ -1186,10 +1186,8 @@ int qcow2_truncate_bitmaps_check(BlockDriverState *b= s, Error **errp) return 0; } =20 - bm_list =3D bitmap_list_load(bs, s->bitmap_directory_offset, - s->bitmap_directory_size, errp); - if (bm_list =3D=3D NULL) { - return -EINVAL; + if ((ret =3D bitmap_list_load(bs, &bm_list, errp))) { + return ret; } =20 QSIMPLEQ_FOREACH(bm, bm_list, entry) { @@ -1419,9 +1417,7 @@ void qcow2_remove_persistent_dirty_bitmap(BlockDriver= State *bs, return; } =20 - bm_list =3D bitmap_list_load(bs, s->bitmap_directory_offset, - s->bitmap_directory_size, errp); - if (bm_list =3D=3D NULL) { + if (bitmap_list_load(bs, &bm_list, errp)) { return; } =20 @@ -1472,9 +1468,7 @@ void qcow2_store_persistent_dirty_bitmaps(BlockDriver= State *bs, Error **errp) if (s->nb_bitmaps =3D=3D 0) { bm_list =3D bitmap_list_new(); } else { - bm_list =3D bitmap_list_load(bs, s->bitmap_directory_offset, - s->bitmap_directory_size, errp); - if (bm_list =3D=3D NULL) { + if (bitmap_list_load(bs, &bm_list, errp)) { return; } } @@ -1653,9 +1647,7 @@ bool qcow2_can_store_new_dirty_bitmap(BlockDriverStat= e *bs, goto fail; } =20 - bm_list =3D bitmap_list_load(bs, s->bitmap_directory_offset, - s->bitmap_directory_size, errp); - if (bm_list =3D=3D NULL) { + if (bitmap_list_load(bs, &bm_list, errp)) { goto fail; } =20 --=20 2.20.1 From nobody Sat May 18 18:02:04 2024 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=1559848434; cv=none; d=zoho.com; s=zohoarc; b=n0seoH75JXVBC+Ec/h2yNhAOB591U6hVodkQ9+bEWsdfS6VSt2k80bi04nSahIPkPTXCXQNZyl91FmHq/GfPRchEwXhTWfyiBIcKFM+Je5ZZM6whdMzr5jq5KPKQ+zFWDGbdAkATMLn9wdvhiPckqmCVlk6QryDmFrYxI6N0i4c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559848434; 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=v51KRZtnCLOvSBYyHi0syhxuw7p38EG3Z2OYT5XLyhs=; b=TAFj/wlwZjkIsfuiyDQ8Qh4AeandS+XU2IOwqxX5GnTea+nqGKN9ox0T62UMYUxAWrEaBNZsKiknofQdReXlJBlHAO46KSz8I7R86FJnP6pm2PRoIwzCdCvYd+p9zDHNOjgGWt76mSPBwqQ3Tw6pNVICekiE1jP5eyfosDCdaBE= 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 (209.51.188.47 [209.51.188.47]) by mx.zohomail.com with SMTPS id 1559848433998664.250290980282; Thu, 6 Jun 2019 12:13:53 -0700 (PDT) Received: from localhost ([::1]:53956 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hYxpX-0006eX-FH for importer@patchew.org; Thu, 06 Jun 2019 15:13:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53352) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hYxlF-0004T3-W5 for qemu-devel@nongnu.org; Thu, 06 Jun 2019 15:09:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hYxLT-0000R8-FG for qemu-devel@nongnu.org; Thu, 06 Jun 2019 14:42:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43852) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hYxLG-0007qf-OM; Thu, 06 Jun 2019 14:42:28 -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 ED22830832CE; Thu, 6 Jun 2019 18:42:06 +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 089115C2EB; Thu, 6 Jun 2019 18:42:05 +0000 (UTC) From: John Snow To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Thu, 6 Jun 2019 14:41:56 -0400 Message-Id: <20190606184159.979-3-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.44]); Thu, 06 Jun 2019 18:42:07 +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 2/5] block/dirty-bitmap: Refactor bdrv_can_store_new_bitmap 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" Instead of bdrv_can_store_new_bitmap, rework this as bdrv_add_persistent_dirty_bitmap. This makes a more obvious symmetry with bdrv_remove_persistent_dirty_bitmap. Most importantly, we are free to modify the driver state because we know we ARE adding a bitmap instead of simply being asked if we CAN store one. As part of this symmetry, move this function next to bdrv_remove_persistent_bitmap in block/dirty-bitmap.c. To cement this semantic distinction, use a bitmap object instead of the (name, granularity) pair as this allows us to set persistence as a condition of the "add" succeeding. Notably, the qcow2 implementation still does not actually store the new bitmap at add time, but merely ensures that it will be able to at store time. Signed-off-by: John Snow Reported-by: aihua liang Reviewed-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.h | 5 ++--- include/block/block.h | 2 -- include/block/block_int.h | 5 ++--- include/block/dirty-bitmap.h | 3 +++ block.c | 22 --------------------- block/dirty-bitmap.c | 38 ++++++++++++++++++++++++++++++++++++ block/qcow2-bitmap.c | 24 ++++++++++++++--------- block/qcow2.c | 2 +- blockdev.c | 19 +++++++----------- 9 files changed, 68 insertions(+), 52 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index fc1b0d3c1e..95d723d3c0 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -742,9 +742,8 @@ int qcow2_reopen_bitmaps_rw(BlockDriverState *bs, Error= **errp); int qcow2_truncate_bitmaps_check(BlockDriverState *bs, Error **errp); void qcow2_store_persistent_dirty_bitmaps(BlockDriverState *bs, Error **er= rp); int qcow2_reopen_bitmaps_ro(BlockDriverState *bs, Error **errp); -bool qcow2_can_store_new_dirty_bitmap(BlockDriverState *bs, - const char *name, - uint32_t granularity, +int qcow2_add_persistent_dirty_bitmap(BlockDriverState *bs, + BdrvDirtyBitmap *bitmap, Error **errp); void qcow2_remove_persistent_dirty_bitmap(BlockDriverState *bs, const char *name, diff --git a/include/block/block.h b/include/block/block.h index f9415ed740..6d520f3b59 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -683,8 +683,6 @@ void bdrv_add_child(BlockDriverState *parent, BlockDriv= erState *child, Error **errp); void bdrv_del_child(BlockDriverState *parent, BdrvChild *child, Error **er= rp); =20 -bool bdrv_can_store_new_dirty_bitmap(BlockDriverState *bs, const char *nam= e, - uint32_t granularity, Error **errp); /** * * bdrv_register_buf/bdrv_unregister_buf: diff --git a/include/block/block_int.h b/include/block/block_int.h index 06df2bda1b..93bbb66cd0 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -537,9 +537,8 @@ struct BlockDriver { * field of BlockDirtyBitmap's in case of success. */ int (*bdrv_reopen_bitmaps_rw)(BlockDriverState *bs, Error **errp); - bool (*bdrv_can_store_new_dirty_bitmap)(BlockDriverState *bs, - const char *name, - uint32_t granularity, + int (*bdrv_add_persistent_dirty_bitmap)(BlockDriverState *bs, + BdrvDirtyBitmap *bitmap, Error **errp); void (*bdrv_remove_persistent_dirty_bitmap)(BlockDriverState *bs, const char *name, diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h index 8044ace63e..c37edbe05f 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -38,6 +38,9 @@ int bdrv_dirty_bitmap_check(const BdrvDirtyBitmap *bitmap= , uint32_t flags, Error **errp); void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitm= ap); void bdrv_release_named_dirty_bitmaps(BlockDriverState *bs); +int bdrv_add_persistent_dirty_bitmap(BlockDriverState *bs, + BdrvDirtyBitmap *bitmap, + Error **errp); void bdrv_remove_persistent_dirty_bitmap(BlockDriverState *bs, const char *name, Error **errp); diff --git a/block.c b/block.c index e3e77feee0..6aec36b7c9 100644 --- a/block.c +++ b/block.c @@ -6379,25 +6379,3 @@ void bdrv_del_child(BlockDriverState *parent_bs, Bdr= vChild *child, Error **errp) =20 parent_bs->drv->bdrv_del_child(parent_bs, child, errp); } - -bool bdrv_can_store_new_dirty_bitmap(BlockDriverState *bs, const char *nam= e, - uint32_t granularity, Error **errp) -{ - BlockDriver *drv =3D bs->drv; - - if (!drv) { - error_setg_errno(errp, ENOMEDIUM, - "Can't store persistent bitmaps to %s", - bdrv_get_device_or_node_name(bs)); - return false; - } - - if (!drv->bdrv_can_store_new_dirty_bitmap) { - error_setg_errno(errp, ENOTSUP, - "Can't store persistent bitmaps to %s", - bdrv_get_device_or_node_name(bs)); - return false; - } - - return drv->bdrv_can_store_new_dirty_bitmap(bs, name, granularity, err= p); -} diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index 49646a30e6..615f8480b2 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -466,6 +466,44 @@ void bdrv_remove_persistent_dirty_bitmap(BlockDriverSt= ate *bs, } } =20 +int bdrv_add_persistent_dirty_bitmap(BlockDriverState *bs, + BdrvDirtyBitmap *bitmap, + Error **errp) +{ + BlockDriver *drv =3D bs->drv; + int ret; + + if (bdrv_dirty_bitmap_get_persistence(bitmap)) { + error_setg(errp, "Bitmap '%s' is already persistent, " + "and cannot be re-added to node '%s'", + bdrv_dirty_bitmap_name(bitmap), + bdrv_get_device_or_node_name(bs)); + return -EINVAL; + } + + if (!drv) { + error_setg_errno(errp, ENOMEDIUM, + "Can't store persistent bitmaps to %s", + bdrv_get_device_or_node_name(bs)); + return -ENOMEDIUM; + } + + if (!drv->bdrv_add_persistent_dirty_bitmap) { + error_setg_errno(errp, ENOTSUP, + "Can't store persistent bitmaps to %s", + bdrv_get_device_or_node_name(bs)); + return -ENOTSUP; + } + + ret =3D drv->bdrv_add_persistent_dirty_bitmap(bs, bitmap, errp); + if (ret =3D=3D 0) { + bdrv_dirty_bitmap_set_persistence(bitmap, true); + } + + return ret; +} + + void bdrv_disable_dirty_bitmap(BdrvDirtyBitmap *bitmap) { bdrv_dirty_bitmap_lock(bitmap); diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index 83aee1a42a..c3a72ca782 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -1607,14 +1607,16 @@ int qcow2_reopen_bitmaps_ro(BlockDriverState *bs, E= rror **errp) return 0; } =20 -bool qcow2_can_store_new_dirty_bitmap(BlockDriverState *bs, - const char *name, - uint32_t granularity, +int qcow2_add_persistent_dirty_bitmap(BlockDriverState *bs, + BdrvDirtyBitmap *bitmap, Error **errp) { BDRVQcow2State *s =3D bs->opaque; bool found; Qcow2BitmapList *bm_list; + const char *name =3D bdrv_dirty_bitmap_name(bitmap); + uint32_t granularity =3D bdrv_dirty_bitmap_granularity(bitmap); + int ret =3D 0; =20 if (s->qcow_version < 3) { /* Without autoclear_features, we would always have to assume @@ -1623,20 +1625,23 @@ bool qcow2_can_store_new_dirty_bitmap(BlockDriverSt= ate *bs, * have to drop all dirty bitmaps (defeating their purpose). */ error_setg(errp, "Cannot store dirty bitmaps in qcow2 v2 files"); + ret =3D -ENOTSUP; goto fail; } =20 - if (check_constraints_on_bitmap(bs, name, granularity, errp) !=3D 0) { + ret =3D check_constraints_on_bitmap(bs, name, granularity, errp); + if (ret) { goto fail; } =20 if (s->nb_bitmaps =3D=3D 0) { - return true; + return 0; } =20 if (s->nb_bitmaps >=3D QCOW2_MAX_BITMAPS) { error_setg(errp, "Maximum number of persistent bitmaps is already reache= d"); + ret =3D -EOVERFLOW; goto fail; } =20 @@ -1644,24 +1649,25 @@ bool qcow2_can_store_new_dirty_bitmap(BlockDriverSt= ate *bs, QCOW2_MAX_BITMAP_DIRECTORY_SIZE) { error_setg(errp, "Not enough space in the bitmap directory"); + ret =3D -EOVERFLOW; goto fail; } =20 - if (bitmap_list_load(bs, &bm_list, errp)) { + if ((ret =3D bitmap_list_load(bs, &bm_list, errp))) { goto fail; } =20 found =3D find_bitmap_by_name(bm_list, name); bitmap_list_free(bm_list); if (found) { + ret =3D -EEXIST; error_setg(errp, "Bitmap with the same name is already stored"); goto fail; } =20 - return true; - + return 0; fail: error_prepend(errp, "Can't make bitmap '%s' persistent in '%s': ", name, bdrv_get_device_or_node_name(bs)); - return false; + return ret; } diff --git a/block/qcow2.c b/block/qcow2.c index 9396d490d5..1c78eba71b 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -5229,7 +5229,7 @@ BlockDriver bdrv_qcow2 =3D { .bdrv_attach_aio_context =3D qcow2_attach_aio_context, =20 .bdrv_reopen_bitmaps_rw =3D qcow2_reopen_bitmaps_rw, - .bdrv_can_store_new_dirty_bitmap =3D qcow2_can_store_new_dirty_bitmap, + .bdrv_add_persistent_dirty_bitmap =3D qcow2_add_persistent_dirty_bitma= p, .bdrv_remove_persistent_dirty_bitmap =3D qcow2_remove_persistent_dirty= _bitmap, }; =20 diff --git a/blockdev.c b/blockdev.c index 3f44b891eb..169a8da831 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2851,26 +2851,21 @@ void qmp_block_dirty_bitmap_add(const char *node, c= onst char *name, disabled =3D false; } =20 - if (persistent) { - aio_context =3D bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); - if (!bdrv_can_store_new_dirty_bitmap(bs, name, granularity, errp))= { - goto out; - } - } - bitmap =3D bdrv_create_dirty_bitmap(bs, granularity, name, errp); if (bitmap =3D=3D NULL) { - goto out; + return; } =20 if (disabled) { bdrv_disable_dirty_bitmap(bitmap); } =20 - bdrv_dirty_bitmap_set_persistence(bitmap, persistent); - out: - if (aio_context) { + if (persistent) { + aio_context =3D bdrv_get_aio_context(bs); + aio_context_acquire(aio_context); + if (bdrv_add_persistent_dirty_bitmap(bs, bitmap, errp)) { + bdrv_release_dirty_bitmap(bs, bitmap); + } aio_context_release(aio_context); } } --=20 2.20.1 From nobody Sat May 18 18:02:04 2024 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=1559849007; cv=none; d=zoho.com; s=zohoarc; b=IJtjW6gndmDLyPdkl0/wXuXS6noW48HNgXWoTZAQ6CydUAxDd0o+o4KX48tC6+hGZ/xuKD8r/HjRdRqy6rqnRVXWsD6Gy0jCF69qWWOenqlJQtm/1sRH8XaUEX7ZUS2Ssf/2iQKgXMHLYDavrP0SbQjSR72DoZhRY49klXatdU4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559849007; 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=Wwq4NMMVaJX7MWxtNjU/YrUr5oKQXeoAOSKXk0+pkQo=; b=jbzIeYCnX3OJPdWpbz3O3tcUZM+eNfmcJnfAqQG3DdITvi0OvniCqkcVLBmr71zq++pz1MFErlCEZfQB6AsV8VQtBmZPpFyrHhFZMx/nJkJdrknykt1dQjmfNWRXucY9TtBld+EZNGwhHhHgMKDDfAWgaBA/69L8+jzlg9+xky8= 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 (209.51.188.47 [209.51.188.47]) by mx.zohomail.com with SMTPS id 1559849007736854.2332676629273; Thu, 6 Jun 2019 12:23:27 -0700 (PDT) Received: from localhost ([::1]:55286 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hYxyr-0003Ph-IW for importer@patchew.org; Thu, 06 Jun 2019 15:23:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53260) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hYxlF-0004Qx-VO for qemu-devel@nongnu.org; Thu, 06 Jun 2019 15:09:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hYxLU-0000RZ-0y for qemu-devel@nongnu.org; Thu, 06 Jun 2019 14:42:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54506) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hYxLG-0007up-OI; Thu, 06 Jun 2019 14:42:28 -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 0DE722F8BCA; Thu, 6 Jun 2019 18:42:08 +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 1B42118129; Thu, 6 Jun 2019 18:42:07 +0000 (UTC) From: John Snow To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Thu, 6 Jun 2019 14:41:57 -0400 Message-Id: <20190606184159.979-4-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.38]); Thu, 06 Jun 2019 18:42:08 +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 3/5] block/dirty-bitmap: rework bdrv_remove_persistent_dirty_bitmap 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" Allow propagating error code information from bdrv_remove_persistent_dirty_bitmap as well. Give it an interface that matches the newly revised bdrv_add_persistent_dirty_bitmap, including removing the persistent flag when the operation succeeds and refusing to operate on bitmaps that are not persistent. Signed-off-by: John Snow Reported-by: aihua liang Reviewed-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.h | 6 +++--- include/block/block_int.h | 6 +++--- include/block/dirty-bitmap.h | 6 +++--- block/dirty-bitmap.c | 25 ++++++++++++++++++++----- block/qcow2-bitmap.c | 16 +++++++++------- blockdev.c | 15 ++++++--------- 6 files changed, 44 insertions(+), 30 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index 95d723d3c0..ce07f003f7 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -745,9 +745,9 @@ int qcow2_reopen_bitmaps_ro(BlockDriverState *bs, Error= **errp); int qcow2_add_persistent_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap, Error **errp); -void qcow2_remove_persistent_dirty_bitmap(BlockDriverState *bs, - const char *name, - Error **errp); +int qcow2_remove_persistent_dirty_bitmap(BlockDriverState *bs, + BdrvDirtyBitmap *bitmap, + Error **errp); =20 ssize_t coroutine_fn qcow2_co_compress(BlockDriverState *bs, void *dest, size_t dest_size, diff --git a/include/block/block_int.h b/include/block/block_int.h index 93bbb66cd0..59f8cb9c12 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -540,9 +540,9 @@ struct BlockDriver { int (*bdrv_add_persistent_dirty_bitmap)(BlockDriverState *bs, BdrvDirtyBitmap *bitmap, Error **errp); - void (*bdrv_remove_persistent_dirty_bitmap)(BlockDriverState *bs, - const char *name, - Error **errp); + int (*bdrv_remove_persistent_dirty_bitmap)(BlockDriverState *bs, + BdrvDirtyBitmap *bitmap, + Error **errp); =20 /** * Register/unregister a buffer for I/O. For example, when the driver = is diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h index c37edbe05f..88a9832ddc 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -41,9 +41,9 @@ void bdrv_release_named_dirty_bitmaps(BlockDriverState *b= s); int bdrv_add_persistent_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap, Error **errp); -void bdrv_remove_persistent_dirty_bitmap(BlockDriverState *bs, - const char *name, - Error **errp); +int bdrv_remove_persistent_dirty_bitmap(BlockDriverState *bs, + BdrvDirtyBitmap *bitmap, + Error **errp); void bdrv_disable_dirty_bitmap(BdrvDirtyBitmap *bitmap); void bdrv_enable_dirty_bitmap(BdrvDirtyBitmap *bitmap); void bdrv_enable_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap); diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index 615f8480b2..4667f9e65a 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -455,15 +455,30 @@ void bdrv_release_named_dirty_bitmaps(BlockDriverStat= e *bs) * BdrvDirtyBitmap can have .persistent =3D true but not yet saved and hav= e no * stored version. For such bitmap bdrv_remove_persistent_dirty_bitmap() s= hould * not fail. - * This function doesn't release corresponding BdrvDirtyBitmap. + * This function doesn't release the corresponding BdrvDirtyBitmap. */ -void bdrv_remove_persistent_dirty_bitmap(BlockDriverState *bs, - const char *name, - Error **errp) +int bdrv_remove_persistent_dirty_bitmap(BlockDriverState *bs, + BdrvDirtyBitmap *bitmap, + Error **errp) { + int ret =3D 0; + + if (!bdrv_dirty_bitmap_get_persistence(bitmap)) { + error_setg(errp, "Bitmap '%s' is not persistent, " + "so it cannot be removed from node '%s'", + bdrv_dirty_bitmap_name(bitmap), + bdrv_get_device_or_node_name(bs)); + return -EINVAL; + } + if (bs->drv && bs->drv->bdrv_remove_persistent_dirty_bitmap) { - bs->drv->bdrv_remove_persistent_dirty_bitmap(bs, name, errp); + ret =3D bs->drv->bdrv_remove_persistent_dirty_bitmap(bs, bitmap, e= rrp); } + if (!ret) { + bdrv_dirty_bitmap_set_persistence(bitmap, false); + } + + return ret; } =20 int bdrv_add_persistent_dirty_bitmap(BlockDriverState *bs, diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index c3a72ca782..930a6c91ff 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -1402,23 +1402,24 @@ static Qcow2Bitmap *find_bitmap_by_name(Qcow2Bitmap= List *bm_list, return NULL; } =20 -void qcow2_remove_persistent_dirty_bitmap(BlockDriverState *bs, - const char *name, - Error **errp) +int qcow2_remove_persistent_dirty_bitmap(BlockDriverState *bs, + BdrvDirtyBitmap *bitmap, + Error **errp) { - int ret; + int ret =3D 0; BDRVQcow2State *s =3D bs->opaque; Qcow2Bitmap *bm; Qcow2BitmapList *bm_list; + const char *name =3D bdrv_dirty_bitmap_name(bitmap); =20 if (s->nb_bitmaps =3D=3D 0) { /* Absence of the bitmap is not an error: see explanation above * bdrv_remove_persistent_dirty_bitmap() definition. */ - return; + return 0; } =20 - if (bitmap_list_load(bs, &bm_list, errp)) { - return; + if ((ret =3D bitmap_list_load(bs, &bm_list, errp))) { + return ret; } =20 bm =3D find_bitmap_by_name(bm_list, name); @@ -1439,6 +1440,7 @@ void qcow2_remove_persistent_dirty_bitmap(BlockDriver= State *bs, fail: bitmap_free(bm); bitmap_list_free(bm_list); + return ret; } =20 void qcow2_store_persistent_dirty_bitmaps(BlockDriverState *bs, Error **er= rp) diff --git a/blockdev.c b/blockdev.c index 169a8da831..82f02d8e72 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2875,7 +2875,6 @@ void qmp_block_dirty_bitmap_remove(const char *node, = const char *name, { BlockDriverState *bs; BdrvDirtyBitmap *bitmap; - Error *local_err =3D NULL; AioContext *aio_context =3D NULL; =20 bitmap =3D block_dirty_bitmap_lookup(node, name, &bs, errp); @@ -2889,20 +2888,18 @@ void qmp_block_dirty_bitmap_remove(const char *node= , const char *name, } =20 if (bdrv_dirty_bitmap_get_persistence(bitmap)) { + int ret; + aio_context =3D bdrv_get_aio_context(bs); aio_context_acquire(aio_context); - bdrv_remove_persistent_dirty_bitmap(bs, name, &local_err); - if (local_err !=3D NULL) { - error_propagate(errp, local_err); - goto out; + ret =3D bdrv_remove_persistent_dirty_bitmap(bs, bitmap, errp); + aio_context_release(aio_context); + if (ret) { + return; } } =20 bdrv_release_dirty_bitmap(bs, bitmap); - out: - if (aio_context) { - aio_context_release(aio_context); - } } =20 /** --=20 2.20.1 From nobody Sat May 18 18:02:04 2024 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=1559849129; cv=none; d=zoho.com; s=zohoarc; b=kDV/Y0K/OpkbFpdIDKziW9fHkRICva+aAAoYcRidRgpg0A1T9UnF3AonoQVQ3ZfGsZjX9k/xevYXO7sKkuZx2FX1S7NyHS1H0l4v8nrPVKNRT5EgmrhhlU1/WQA8t5KzNCbUgb9jodTatwSlA3dG/Ja0so2SZvK7brZPwyDgRbg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559849129; 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=S5gqlRc+SJL4DIjGmMNVkS90yIvtNYE1rjBokzYtey0=; b=LcU157cVK5yH7jVi6TyDx9rf9YaGZ9SRk29njeQaw7ZxCVi3tlVZNst/doWVG4oPNGrPF2CalkiL5e89b5oLpdqWUVazLTysSKRAg+Fe+7QL3KzlnvmSanKmqlcJ6dc2s/DZRw0jZVE/cctd8WhjeE7UIUd7ycfK+kWaJkO8GMs= 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 1559849129380514.9247130423905; Thu, 6 Jun 2019 12:25:29 -0700 (PDT) Received: from localhost ([::1]:55492 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hYy0l-00051C-I9 for importer@patchew.org; Thu, 06 Jun 2019 15:25:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53567) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hYxlN-0004dY-2q for qemu-devel@nongnu.org; Thu, 06 Jun 2019 15:09:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hYxLI-0000D6-Lp for qemu-devel@nongnu.org; Thu, 06 Jun 2019 14:42:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38172) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hYxLE-0007ii-KO; 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 2337530821EC; Thu, 6 Jun 2019 18:42:09 +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 3014CBABF; Thu, 6 Jun 2019 18:42:08 +0000 (UTC) From: John Snow To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Thu, 6 Jun 2019 14:41:58 -0400 Message-Id: <20190606184159.979-5-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.47]); Thu, 06 Jun 2019 18:42:09 +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 4/5] block/qcow2-bitmap: Count queued bitmaps towards nb_bitmaps 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" When we check to see if we can store a bitmap, we don't check how many we've queued up. This can cause a problem saving bitmaps on close instead of when we request them to be added. With the stricter add interface, prohibit these bitmaps specifically. To match, make the remove interface more strict as well; now rejecting any requests to remove bitmaps that were never queued for storage. We don't need to "find" the bitmap when the interface has been given the bitmap explicitly, but this is done to make sure that the bitmap given actually does belong to the bs we were passed as a paranoia check to enforce consistency. Reported-by: aihua liang Reviewed-by: Eric Blake --- "What about directory size?" Please see the following patch. Signed-off-by: John Snow --- block/qcow2.h | 1 + block/dirty-bitmap.c | 8 +++----- block/qcow2-bitmap.c | 31 ++++++++++++++++++++++++++----- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index ce07f003f7..ebf60ac236 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -317,6 +317,7 @@ typedef struct BDRVQcow2State { QCowSnapshot *snapshots; =20 uint32_t nb_bitmaps; + uint32_t nb_queued_bitmaps; uint64_t bitmap_directory_size; uint64_t bitmap_directory_offset; =20 diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index 4667f9e65a..084c42af57 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -450,11 +450,9 @@ void bdrv_release_named_dirty_bitmaps(BlockDriverState= *bs) } =20 /** - * Remove persistent dirty bitmap from the storage if it exists. - * Absence of bitmap is not an error, because we have the following scenar= io: - * BdrvDirtyBitmap can have .persistent =3D true but not yet saved and hav= e no - * stored version. For such bitmap bdrv_remove_persistent_dirty_bitmap() s= hould - * not fail. + * Remove a persistent dirty bitmap from storage, + * or dequeue it from being stored if it is enqueued. + * * This function doesn't release the corresponding BdrvDirtyBitmap. */ int bdrv_remove_persistent_dirty_bitmap(BlockDriverState *bs, diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index 930a6c91ff..7193c66787 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -1402,6 +1402,23 @@ static Qcow2Bitmap *find_bitmap_by_name(Qcow2BitmapL= ist *bm_list, return NULL; } =20 +static int qcow2_remove_queued_dirty_bitmap( + BlockDriverState *bs, const char *name, Error **errp) +{ + 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; + } + assert(s->nb_queued_bitmaps > 0); + assert(bdrv_dirty_bitmap_get_persistence(bitmap)); + s->nb_queued_bitmaps -=3D 1; + + return 0; +} + int qcow2_remove_persistent_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap, Error **errp) @@ -1413,9 +1430,7 @@ int qcow2_remove_persistent_dirty_bitmap(BlockDriverS= tate *bs, const char *name =3D bdrv_dirty_bitmap_name(bitmap); =20 if (s->nb_bitmaps =3D=3D 0) { - /* Absence of the bitmap is not an error: see explanation above - * bdrv_remove_persistent_dirty_bitmap() definition. */ - return 0; + return qcow2_remove_queued_dirty_bitmap(bs, name, errp); } =20 if ((ret =3D bitmap_list_load(bs, &bm_list, errp))) { @@ -1424,6 +1439,7 @@ int qcow2_remove_persistent_dirty_bitmap(BlockDriverS= tate *bs, =20 bm =3D find_bitmap_by_name(bm_list, name); if (bm =3D=3D NULL) { + ret =3D qcow2_remove_queued_dirty_bitmap(bs, name, errp); goto fail; } =20 @@ -1544,6 +1560,7 @@ void qcow2_store_persistent_dirty_bitmaps(BlockDriver= State *bs, Error **errp) error_setg_errno(errp, -ret, "Failed to update bitmap extension"); goto fail; } + s->nb_queued_bitmaps =3D 0; =20 /* Bitmap directory was successfully updated, so, old data can be drop= ped. * TODO it is better to reuse these clusters */ @@ -1618,6 +1635,7 @@ int qcow2_add_persistent_dirty_bitmap(BlockDriverStat= e *bs, Qcow2BitmapList *bm_list; const char *name =3D bdrv_dirty_bitmap_name(bitmap); uint32_t granularity =3D bdrv_dirty_bitmap_granularity(bitmap); + uint32_t nb_bitmaps; int ret =3D 0; =20 if (s->qcow_version < 3) { @@ -1636,11 +1654,12 @@ int qcow2_add_persistent_dirty_bitmap(BlockDriverSt= ate *bs, goto fail; } =20 - if (s->nb_bitmaps =3D=3D 0) { + nb_bitmaps =3D s->nb_bitmaps + s->nb_queued_bitmaps; + if (nb_bitmaps =3D=3D 0) { return 0; } =20 - if (s->nb_bitmaps >=3D QCOW2_MAX_BITMAPS) { + if (nb_bitmaps >=3D QCOW2_MAX_BITMAPS) { error_setg(errp, "Maximum number of persistent bitmaps is already reache= d"); ret =3D -EOVERFLOW; @@ -1667,6 +1686,8 @@ int qcow2_add_persistent_dirty_bitmap(BlockDriverStat= e *bs, goto fail; } =20 + s->nb_queued_bitmaps +=3D 1; + return 0; fail: error_prepend(errp, "Can't make bitmap '%s' persistent in '%s': ", --=20 2.20.1 From nobody Sat May 18 18:02:04 2024 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 Reported-by: aihua liang --- 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