From nobody Tue Nov 11 15:58:01 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1564046395; cv=none; d=zoho.com; s=zohoarc; b=kTlWS/TpIegJ73rIf8Fjy6q3Gl6qlpeh+/QYQaXU7z009jQI1/5nJsLgyxtjJWrQu/nZitnnlZ8gOXXL+BmjJyORDXzAqFR8UjUYDI+7x8mDZw7kkIvV+wV/oJS5jOMgIO9HK/3DrK2OSxEGyBC0hPsPNUT4ZwJIDeXo1MW2iNM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564046395; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=xWvHbg/SUkPH7nDXCatehDrZV/I1L9CJxEy3mm0lDTI=; b=AWzhtjGA4FaGwyPYUHvsQPcLYYV6klpeFk1J5K8SldhuuRIzIjFWViiwTy+mcpYg6JDhvsfymqyBQxWtBLnn8azkrtjeETg11/A7ltCoFeKiLSyCngaBNSaUCq2O/GQlSJ4p9ryGFGLzauQ1bVXk8xSfbUoWh4KDao7i7MPECrE= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 1564046395032437.69375385530145; Thu, 25 Jul 2019 02:19:55 -0700 (PDT) Received: from localhost ([::1]:57472 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqZuj-0000yv-Ex for importer@patchew.org; Thu, 25 Jul 2019 05:19:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35759) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqZtz-0007SN-IH for qemu-devel@nongnu.org; Thu, 25 Jul 2019 05:19:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hqZtx-00044b-Vc for qemu-devel@nongnu.org; Thu, 25 Jul 2019 05:19:07 -0400 Received: from relay.sw.ru ([185.231.240.75]:44242) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hqZtx-00041t-Ly; Thu, 25 Jul 2019 05:19:05 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hqZtw-0001bs-3X; Thu, 25 Jul 2019 12:19:04 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Thu, 25 Jul 2019 12:18:58 +0300 Message-Id: <20190725091900.30542-8-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190725091900.30542-1-vsementsov@virtuozzo.com> References: <20190725091900.30542-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH v3 7/9] block/qcow2-bitmap: fix and improve qcow2_reopen_bitmaps_rw 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@euphon.net, kwolf@redhat.com, vsementsov@virtuozzo.com, mreitz@redhat.com, den@openvz.org, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" - Correct check for write access to file child, and in correct place (only if we want to write). - Support reopen rw -> rw (which will be used in furhter patches), for example, !bdrv_dirty_bitmap_readonly() is not a corruption if bitmap is marked IN_USE in the image. - Consider unexpected bitmap as a corruption and check other combinations of in-image and in-RAM bitmaps. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/qcow2-bitmap.c | 56 +++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index a636dc50ca..e276a95154 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -1108,18 +1108,14 @@ int qcow2_reopen_bitmaps_rw(BlockDriverState *bs, E= rror **errp) Qcow2BitmapList *bm_list; Qcow2Bitmap *bm; GSList *ro_dirty_bitmaps =3D NULL; - int ret =3D 0; + int ret =3D -EINVAL; + bool need_header_update =3D false; =20 if (s->nb_bitmaps =3D=3D 0) { /* No bitmaps - nothing to do */ return 0; } =20 - if (!can_write(bs)) { - error_setg(errp, "Can't write to the image on reopening bitmaps rw= "); - return -EINVAL; - } - bm_list =3D bitmap_list_load(bs, s->bitmap_directory_offset, s->bitmap_directory_size, errp); if (bm_list =3D=3D NULL) { @@ -1128,32 +1124,54 @@ int qcow2_reopen_bitmaps_rw(BlockDriverState *bs, E= rror **errp) =20 QSIMPLEQ_FOREACH(bm, bm_list, entry) { BdrvDirtyBitmap *bitmap =3D bdrv_find_dirty_bitmap(bs, bm->name); - if (bitmap =3D=3D NULL) { - continue; - } =20 - if (!bdrv_dirty_bitmap_readonly(bitmap)) { - error_setg(errp, "Bitmap %s was loaded prior to rw-reopen, but= was " - "not marked as readonly. This is a bug, something w= ent " - "wrong. All of the bitmaps may be corrupted", bm->n= ame); - ret =3D -EINVAL; + if (!bitmap) { + error_setg(errp, "Unexpected bitmap '%s' in the image '%s'", + bm->name, bs->filename); goto out; } =20 - bm->flags |=3D BME_FLAG_IN_USE; - ro_dirty_bitmaps =3D g_slist_append(ro_dirty_bitmaps, bitmap); + if (!(bm->flags & BME_FLAG_IN_USE)) { + if (!bdrv_dirty_bitmap_readonly(bitmap)) { + error_setg(errp, "Corruption: bitmap '%s' is not marked IN= _USE " + "in the image '%s' and not marked readonly in R= AM", + bm->name, bs->filename); + goto out; + } + if (bdrv_dirty_bitmap_inconsistent(bitmap)) { + error_setg(errp, "Corruption: bitmap '%s' is inconsistent = but " + "is not marked IN_USE in the image '%s'", bm->n= ame, + bs->filename); + goto out; + } + + bm->flags |=3D BME_FLAG_IN_USE; + need_header_update =3D true; + } + + if (bdrv_dirty_bitmap_readonly(bitmap)) { + ro_dirty_bitmaps =3D g_slist_append(ro_dirty_bitmaps, bitmap); + } } =20 - if (ro_dirty_bitmaps !=3D NULL) { + if (need_header_update) { + if (!can_write(bs->file->bs) || !(bs->file->perm & BLK_PERM_WRITE)= ) { + error_setg(errp, "Failed to reopen bitmaps rw: no write access= " + "the protocol file"); + goto out; + } + /* in_use flags must be updated */ ret =3D update_ext_header_and_dir_in_place(bs, bm_list); if (ret < 0) { - error_setg_errno(errp, -ret, "Can't update bitmap directory"); + error_setg_errno(errp, -ret, "Cannot update bitmap directory"); goto out; } - g_slist_foreach(ro_dirty_bitmaps, set_readonly_helper, false); } =20 + g_slist_foreach(ro_dirty_bitmaps, set_readonly_helper, false); + ret =3D 0; + out: g_slist_free(ro_dirty_bitmaps); bitmap_list_free(bm_list); --=20 2.18.0