From nobody Sun Oct 5 19:22:52 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 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=1615306372; cv=none; d=zohomail.com; s=zohoarc; b=IgVLSCqd8cE2C2bDFWT/Jo9HbE/t9LnMmUbVKvRxh1H8Opza/dX0/ARrX5jYdhcXPuT7w7SjN51qy4ZEsjzAKGZY3+0Ge3mTySHNVaMt/N/yUD9p2FTHpVXoWRqjp1ta1txGNkAhr/DzSUGW6hMtixmxEUK+nkWKgw1ZVeRgAA8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615306372; h=Content-Type: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; bh=kMt3Fnjxun6BSypjzU1rj3E5jd86KGm0GeloFw/XvWI=; b=dCGB0DHejNQG5ft646uznlR0bHwzn22zoqTzLw/hjdl0W7tgh8iRGTxhU4QDa4O6Sw0lE7XZr8jtZ4HLx6cuIy0UZhr8yDEHv9CFqz3gln9rKJGq2XCIfuCmSBGebQX5w2UZs16y0fTkbbb9x3xj54mJzKb0shv/URyOf6OAMrM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 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.17]) by mx.zohomail.com with SMTPS id 1615306372332550.5956887968321; Tue, 9 Mar 2021 08:12:52 -0800 (PST) Received: from localhost ([::1]:40840 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lJeyY-0007rv-EX for importer@patchew.org; Tue, 09 Mar 2021 11:12:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36514) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJef7-00046d-A6 for qemu-devel@nongnu.org; Tue, 09 Mar 2021 10:52:50 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:21871) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lJeew-0000zL-AC for qemu-devel@nongnu.org; Tue, 09 Mar 2021 10:52:44 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-214-_0DpQaFKOH6ymIHKAqMVLg-1; Tue, 09 Mar 2021 10:52:31 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4CECD10866A0; Tue, 9 Mar 2021 15:52:30 +0000 (UTC) Received: from blue.redhat.com (ovpn-112-36.phx2.redhat.com [10.3.112.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id A3F9119C46; Tue, 9 Mar 2021 15:52:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615305153; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kMt3Fnjxun6BSypjzU1rj3E5jd86KGm0GeloFw/XvWI=; b=Z97NA+Mo2jqv3yp6c0y4ZDk0a5mteM+MHRFYE9fQXisDiGEckeOVNrE2MbFCinq/g0UZuk QR4b7E6drLlig9pRjWgsJhpYkyczBDDmwwpR+2eQB0MtK7QL5h22FhIFGxvk7GAvsm38kG 6UPmUSORzGNzN9Pajn+wx5OM2S6DxBM= X-MC-Unique: _0DpQaFKOH6ymIHKAqMVLg-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PULL 12/17] block/qcow2-bitmap: improve qcow2_load_dirty_bitmaps() interface Date: Tue, 9 Mar 2021 09:51:57 -0600 Message-Id: <20210309155202.1312571-13-eblake@redhat.com> In-Reply-To: <20210309155202.1312571-1-eblake@redhat.com> References: <20210309155202.1312571-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eblake@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.251, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: Kevin Wolf , Vladimir Sementsov-Ogievskiy , Alberto Garcia , "open list:qcow2" , Greg Kurz , Max Reitz , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy It's recommended for bool functions with errp to return true on success and false on failure. Non-standard interfaces don't help to understand the code. The change is also needed to reduce error propagation. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Alberto Garcia Reviewed-by: Greg Kurz Message-Id: <20210202124956.63146-10-vsementsov@virtuozzo.com> Signed-off-by: Eric Blake --- block/qcow2.h | 3 ++- block/qcow2-bitmap.c | 26 +++++++++++++++----------- block/qcow2.c | 6 ++---- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index a6bf2881bba6..d19c8832062e 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -978,7 +978,8 @@ void qcow2_cache_discard(Qcow2Cache *c, void *table); int qcow2_check_bitmaps_refcounts(BlockDriverState *bs, BdrvCheckResult *r= es, void **refcount_table, int64_t *refcount_table_size); -bool qcow2_load_dirty_bitmaps(BlockDriverState *bs, Error **errp); +bool qcow2_load_dirty_bitmaps(BlockDriverState *bs, bool *header_updated, + Error **errp); bool qcow2_get_bitmap_info_list(BlockDriverState *bs, Qcow2BitmapInfoList **info_list, Error **e= rrp); int qcow2_reopen_bitmaps_rw(BlockDriverState *bs, Error **errp); diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index 3c9dcaf0a23a..9452e9fe76c3 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -962,25 +962,27 @@ static void set_readonly_helper(gpointer bitmap, gpoi= nter value) bdrv_dirty_bitmap_set_readonly(bitmap, (bool)value); } -/* qcow2_load_dirty_bitmaps() - * Return value is a hint for caller: true means that the Qcow2 header was - * updated. (false doesn't mean that the header should be updated by the - * caller, it just means that updating was not needed or the image cannot = be - * written to). - * On failure the function returns false. +/* + * Return true on success, false on failure. + * If header_updated is not NULL then it is set appropriately regardless of + * the return value. */ -bool qcow2_load_dirty_bitmaps(BlockDriverState *bs, Error **errp) +bool qcow2_load_dirty_bitmaps(BlockDriverState *bs, bool *header_updated, + Error **errp) { BDRVQcow2State *s =3D bs->opaque; Qcow2BitmapList *bm_list; Qcow2Bitmap *bm; GSList *created_dirty_bitmaps =3D NULL; - bool header_updated =3D false; bool needs_update =3D false; + if (header_updated) { + *header_updated =3D false; + } + if (s->nb_bitmaps =3D=3D 0) { /* No bitmaps - nothing to do */ - return false; + return true; } bm_list =3D bitmap_list_load(bs, s->bitmap_directory_offset, @@ -1036,7 +1038,9 @@ bool qcow2_load_dirty_bitmaps(BlockDriverState *bs, E= rror **errp) error_setg_errno(errp, -ret, "Can't update bitmap directory"); goto fail; } - header_updated =3D true; + if (header_updated) { + *header_updated =3D true; + } } if (!can_write(bs)) { @@ -1047,7 +1051,7 @@ bool qcow2_load_dirty_bitmaps(BlockDriverState *bs, E= rror **errp) g_slist_free(created_dirty_bitmaps); bitmap_list_free(bm_list); - return header_updated; + return true; fail: g_slist_foreach(created_dirty_bitmaps, release_dirty_bitmap_helper, bs= ); diff --git a/block/qcow2.c b/block/qcow2.c index 289e3dbc9769..31042b87a186 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1297,7 +1297,6 @@ static int coroutine_fn qcow2_do_open(BlockDriverStat= e *bs, QDict *options, unsigned int len, i; int ret =3D 0; QCowHeader header; - Error *local_err =3D NULL; uint64_t ext_end; uint64_t l1_vm_state_index; bool update_header =3D false; @@ -1785,9 +1784,8 @@ static int coroutine_fn qcow2_do_open(BlockDriverStat= e *bs, QDict *options, if (!(bdrv_get_flags(bs) & BDRV_O_INACTIVE)) { /* It's case 1, 2 or 3.2. Or 3.1 which is BUG in management layer.= */ - bool header_updated =3D qcow2_load_dirty_bitmaps(bs, &local_err); - if (local_err !=3D NULL) { - error_propagate(errp, local_err); + bool header_updated; + if (!qcow2_load_dirty_bitmaps(bs, &header_updated, errp)) { ret =3D -EINVAL; goto fail; } --=20 2.30.1