From nobody Sun Feb 8 18:33:09 2026 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=1565187355; cv=none; d=zoho.com; s=zohoarc; b=WipXcXi9TVou3A1F55lKf709EpWBfKu1svfEAjS4s4NJ9PC6oZ3s5tFkA/8Fv0I6YwunlxNW96xPdDEjwyF6NnZmy1o/Ep1fBlaAUrhwnPjW0NqIzcygIME3pkcd99huSwOT775O4eclfMemYURKrwEB2ZCkZmzjd5ZwoQo5Tkw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565187355; 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=e7C1XRDcTFkzCkVs1Zp640Z2gbxK2InUutYapwCBRAA=; b=ktn+zFDkZL/8Tk3/JZ9KehGd6aYmeNProStSS3DHtZcAZn1a+JSXiT5L0ubKMc6r2kKuwPbOfgPHamKZJnvBOLDsujgiPO0BY7DEVPUq4Te3aNeSJ1TT+LqfV65YIFLLDuAQhhv0b0QPTuu/SFw2i5TRyKGFEIv0lBbkqdZ+MJE= 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 15651873550601016.9679418765311; Wed, 7 Aug 2019 07:15:55 -0700 (PDT) Received: from localhost ([::1]:41660 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hvMjK-0007Kh-1R for importer@patchew.org; Wed, 07 Aug 2019 10:15:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36666) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hvMg9-0007q4-4w for qemu-devel@nongnu.org; Wed, 07 Aug 2019 10:12:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hvMg7-0003LB-Ra for qemu-devel@nongnu.org; Wed, 07 Aug 2019 10:12:37 -0400 Received: from relay.sw.ru ([185.231.240.75]:40648) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hvMg4-0003Cw-Bk; Wed, 07 Aug 2019 10:12:32 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hvMfz-0005oH-B8; Wed, 07 Aug 2019 17:12:27 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Date: Wed, 7 Aug 2019 17:12:17 +0300 Message-Id: <20190807141226.193501-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190807141226.193501-1-vsementsov@virtuozzo.com> References: <20190807141226.193501-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 v4 01/10] block: switch reopen queue from QSIMPLEQ to QTAILQ 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, qemu-devel@nongnu.org, 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" We'll need reverse-foreach in the following commit, QTAILQ support it, so move to QTAILQ. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz --- include/block/block.h | 2 +- block.c | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index 50a07c1c33..3d84b2a2c9 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -192,7 +192,7 @@ typedef struct HDGeometry { #define BDRV_BLOCK_RECURSE 0x40 #define BDRV_BLOCK_OFFSET_MASK BDRV_SECTOR_MASK =20 -typedef QSIMPLEQ_HEAD(BlockReopenQueue, BlockReopenQueueEntry) BlockReopen= Queue; +typedef QTAILQ_HEAD(BlockReopenQueue, BlockReopenQueueEntry) BlockReopenQu= eue; =20 typedef struct BDRVReopenState { BlockDriverState *bs; diff --git a/block.c b/block.c index cbd8da5f3b..696162cd7a 100644 --- a/block.c +++ b/block.c @@ -1718,7 +1718,7 @@ typedef struct BlockReopenQueueEntry { bool prepared; bool perms_checked; BDRVReopenState state; - QSIMPLEQ_ENTRY(BlockReopenQueueEntry) entry; + QTAILQ_ENTRY(BlockReopenQueueEntry) entry; } BlockReopenQueueEntry; =20 /* @@ -1731,7 +1731,7 @@ static int bdrv_reopen_get_flags(BlockReopenQueue *q,= BlockDriverState *bs) BlockReopenQueueEntry *entry; =20 if (q !=3D NULL) { - QSIMPLEQ_FOREACH(entry, q, entry) { + QTAILQ_FOREACH(entry, q, entry) { if (entry->state.bs =3D=3D bs) { return entry->state.flags; } @@ -3280,7 +3280,7 @@ static BlockReopenQueue *bdrv_reopen_queue_child(Bloc= kReopenQueue *bs_queue, =20 if (bs_queue =3D=3D NULL) { bs_queue =3D g_new0(BlockReopenQueue, 1); - QSIMPLEQ_INIT(bs_queue); + QTAILQ_INIT(bs_queue); } =20 if (!options) { @@ -3288,7 +3288,7 @@ static BlockReopenQueue *bdrv_reopen_queue_child(Bloc= kReopenQueue *bs_queue, } =20 /* Check if this BlockDriverState is already in the queue */ - QSIMPLEQ_FOREACH(bs_entry, bs_queue, entry) { + QTAILQ_FOREACH(bs_entry, bs_queue, entry) { if (bs =3D=3D bs_entry->state.bs) { break; } @@ -3344,7 +3344,7 @@ static BlockReopenQueue *bdrv_reopen_queue_child(Bloc= kReopenQueue *bs_queue, =20 if (!bs_entry) { bs_entry =3D g_new0(BlockReopenQueueEntry, 1); - QSIMPLEQ_INSERT_TAIL(bs_queue, bs_entry, entry); + QTAILQ_INSERT_TAIL(bs_queue, bs_entry, entry); } else { qobject_unref(bs_entry->state.options); qobject_unref(bs_entry->state.explicit_options); @@ -3445,7 +3445,7 @@ int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, = Error **errp) =20 assert(bs_queue !=3D NULL); =20 - QSIMPLEQ_FOREACH(bs_entry, bs_queue, entry) { + QTAILQ_FOREACH(bs_entry, bs_queue, entry) { assert(bs_entry->state.bs->quiesce_counter > 0); if (bdrv_reopen_prepare(&bs_entry->state, bs_queue, errp)) { goto cleanup; @@ -3453,7 +3453,7 @@ int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, = Error **errp) bs_entry->prepared =3D true; } =20 - QSIMPLEQ_FOREACH(bs_entry, bs_queue, entry) { + QTAILQ_FOREACH(bs_entry, bs_queue, entry) { BDRVReopenState *state =3D &bs_entry->state; ret =3D bdrv_check_perm(state->bs, bs_queue, state->perm, state->shared_perm, NULL, NULL, errp); @@ -3479,13 +3479,13 @@ int bdrv_reopen_multiple(BlockReopenQueue *bs_queue= , Error **errp) /* If we reach this point, we have success and just need to apply the * changes */ - QSIMPLEQ_FOREACH(bs_entry, bs_queue, entry) { + QTAILQ_FOREACH(bs_entry, bs_queue, entry) { bdrv_reopen_commit(&bs_entry->state); } =20 ret =3D 0; cleanup_perm: - QSIMPLEQ_FOREACH_SAFE(bs_entry, bs_queue, entry, next) { + QTAILQ_FOREACH_SAFE(bs_entry, bs_queue, entry, next) { BDRVReopenState *state =3D &bs_entry->state; =20 if (!bs_entry->perms_checked) { @@ -3502,7 +3502,7 @@ cleanup_perm: } } cleanup: - QSIMPLEQ_FOREACH_SAFE(bs_entry, bs_queue, entry, next) { + QTAILQ_FOREACH_SAFE(bs_entry, bs_queue, entry, next) { if (ret) { if (bs_entry->prepared) { bdrv_reopen_abort(&bs_entry->state); @@ -3542,7 +3542,7 @@ static BlockReopenQueueEntry *find_parent_in_reopen_q= ueue(BlockReopenQueue *q, { BlockReopenQueueEntry *entry; =20 - QSIMPLEQ_FOREACH(entry, q, entry) { + QTAILQ_FOREACH(entry, q, entry) { BlockDriverState *bs =3D entry->state.bs; BdrvChild *child; =20 --=20 2.18.0 From nobody Sun Feb 8 18:33:09 2026 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=1565187217; cv=none; d=zoho.com; s=zohoarc; b=eIISy4vy5QT8LhtjBmaF8yZC3w0ihsBpNFByCSev/DXYI4l4INtyrufjp+dvZsCEZ15uVEYVCCBtGDrz2vkguPad00JPgRbQly4RZB/Sam/8VPZOAv7qvrDcxITIdKKZ7rSPo4chHEUYtioDWLPlwK/HVeGrJF5mDfNqfVuWCCk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565187217; 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=HMFjzgHx0ppTKSTl1M79M4zIK9NoAmHVS+xD35fOk8Q=; b=VnpBFTP6VdHOoAHXZ7izru+fsRpLR30nkPTa2mmoNKcm3M4WH7YChIYam7ECvh9P5xY7LHuxGyjPhc+17urnp8J7IJsISZcYHYudkEMPP53v8aGUfIYSrQEywSq/YliCFqXc3MKLju09dh2kJJG3OkrbGQqwl9kzOj9Ij7qawRg= 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 1565187217768367.46908902665507; Wed, 7 Aug 2019 07:13:37 -0700 (PDT) Received: from localhost ([::1]:41610 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hvMh5-0001Ur-LQ for importer@patchew.org; Wed, 07 Aug 2019 10:13:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36616) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hvMg8-0007lf-3S for qemu-devel@nongnu.org; Wed, 07 Aug 2019 10:12:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hvMg6-0003KJ-T0 for qemu-devel@nongnu.org; Wed, 07 Aug 2019 10:12:35 -0400 Received: from relay.sw.ru ([185.231.240.75]:40636) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hvMg4-0003Cz-4t; Wed, 07 Aug 2019 10:12:32 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hvMfz-0005oH-EK; Wed, 07 Aug 2019 17:12:27 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Date: Wed, 7 Aug 2019 17:12:18 +0300 Message-Id: <20190807141226.193501-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190807141226.193501-1-vsementsov@virtuozzo.com> References: <20190807141226.193501-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 v4 02/10] block: reverse order for reopen commits 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, qemu-devel@nongnu.org, 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" It's needed to fix reopening qcow2 with bitmaps to RW. Currently it can't work, as qcow2 needs write access to file child, to mark bitmaps in-image with IN_USE flag. But usually children goes after parents in reopen queue and file child is still RO on qcow2 reopen commit. Reverse reopen order to fix it. Signed-off-by: Vladimir Sementsov-Ogievskiy Acked-by: John Snow Acked-by: Max Reitz --- block.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/block.c b/block.c index 696162cd7a..d59f9f97cb 100644 --- a/block.c +++ b/block.c @@ -3476,10 +3476,16 @@ int bdrv_reopen_multiple(BlockReopenQueue *bs_queue= , Error **errp) bs_entry->perms_checked =3D true; } =20 - /* If we reach this point, we have success and just need to apply the - * changes + /* + * If we reach this point, we have success and just need to apply the + * changes. + * + * Reverse order is used to comfort qcow2 driver: on commit it need to= write + * IN_USE flag to the image, to mark bitmaps in the image as invalid. = But + * children are usually goes after parents in reopen-queue, so go from= last + * to first element. */ - QTAILQ_FOREACH(bs_entry, bs_queue, entry) { + QTAILQ_FOREACH_REVERSE(bs_entry, bs_queue, entry) { bdrv_reopen_commit(&bs_entry->state); } =20 --=20 2.18.0 From nobody Sun Feb 8 18:33:09 2026 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=1565187224; cv=none; d=zoho.com; s=zohoarc; b=i7FeP3t8aEzfibQdL/cbtDxv2LJeOh/hbcmLxBHerZnt5OapkNmJmkjEOMXKyV487PG+9DfdpB3Oo1QWwxA6i9wJ4kLTbGwNXTw+CbOJ+fXUqOndfH0f33Fio2CqY1eN0e9vlueNcyzCCvm+4URZyN6XwL2fYX9wBfFR2nON7AU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565187224; 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=dWk7OLBiTdh/I91usL/pJgBTHTtY9y56fXjx52E7SYY=; b=gDZ6YtcBvN697o3/2M0wvaNpil+sbWllMx2HnaMm4drJMAPBsrR7P4yzDlnqk2/cDd3zPFTjYXlZAPDL8acC6AgpsUVKXH+8KLF6X7fShCPTEvvmLW41w9HG1KfZmuUdwObcav/PcY7JZkZnAXdnQBVMKPRwdjjiCyvRpSd2/PE= 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 1565187224042818.8852040343227; Wed, 7 Aug 2019 07:13:44 -0700 (PDT) Received: from localhost ([::1]:41616 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hvMhB-0001nH-7Q for importer@patchew.org; Wed, 07 Aug 2019 10:13:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36615) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hvMg8-0007le-3S for qemu-devel@nongnu.org; Wed, 07 Aug 2019 10:12:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hvMg6-0003KA-RR for qemu-devel@nongnu.org; Wed, 07 Aug 2019 10:12:35 -0400 Received: from relay.sw.ru ([185.231.240.75]:40620) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hvMg3-0003Cs-VD; Wed, 07 Aug 2019 10:12:32 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hvMfz-0005oH-HZ; Wed, 07 Aug 2019 17:12:27 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Date: Wed, 7 Aug 2019 17:12:19 +0300 Message-Id: <20190807141226.193501-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190807141226.193501-1-vsementsov@virtuozzo.com> References: <20190807141226.193501-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 v4 03/10] iotests: add test-case to 165 to test reopening qcow2 bitmaps to 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, qemu-devel@nongnu.org, 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" Reopening bitmaps to RW was broken prior to previous commit. Check that it works now. Signed-off-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/165 | 46 ++++++++++++++++++++++++++++++++++++-- tests/qemu-iotests/165.out | 4 ++-- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/tests/qemu-iotests/165 b/tests/qemu-iotests/165 index 88f62d3c6d..dd93b5a2d0 100755 --- a/tests/qemu-iotests/165 +++ b/tests/qemu-iotests/165 @@ -43,10 +43,10 @@ class TestPersistentDirtyBitmap(iotests.QMPTestCase): os.remove(disk) =20 def mkVm(self): - return iotests.VM().add_drive(disk) + return iotests.VM().add_drive(disk, opts=3D'node-name=3Dnode0') =20 def mkVmRo(self): - return iotests.VM().add_drive(disk, opts=3D'readonly=3Don') + return iotests.VM().add_drive(disk, opts=3D'readonly=3Don,node-nam= e=3Dnode0') =20 def getSha256(self): result =3D self.vm.qmp('x-debug-block-dirty-bitmap-sha256', @@ -102,5 +102,47 @@ class TestPersistentDirtyBitmap(iotests.QMPTestCase): =20 self.vm.shutdown() =20 + def test_reopen_rw(self): + self.vm =3D self.mkVm() + self.vm.launch() + self.qmpAddBitmap() + + # Calculate sha256 corresponding to regions1 + self.writeRegions(regions1) + sha256 =3D self.getSha256() + result =3D self.vm.qmp('block-dirty-bitmap-clear', node=3D'drive0', + name=3D'bitmap0') + self.assert_qmp(result, 'return', {}) + + self.vm.shutdown() + + self.vm =3D self.mkVmRo() + self.vm.launch() + + # We've loaded empty bitmap + assert sha256 !=3D self.getSha256() + + # Check that we are in RO mode + self.writeRegions(regions1) + assert sha256 !=3D self.getSha256() + + result =3D self.vm.qmp('x-blockdev-reopen', **{ + 'node-name': 'node0', + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'file', + 'filename': disk + }, + 'read-only': False + }) + self.assert_qmp(result, 'return', {}) + + # Check that bitmap is reopened to RW and we can write to it. + self.writeRegions(regions1) + assert sha256 =3D=3D self.getSha256() + + self.vm.shutdown() + + if __name__ =3D=3D '__main__': iotests.main(supported_fmts=3D['qcow2']) diff --git a/tests/qemu-iotests/165.out b/tests/qemu-iotests/165.out index ae1213e6f8..fbc63e62f8 100644 --- a/tests/qemu-iotests/165.out +++ b/tests/qemu-iotests/165.out @@ -1,5 +1,5 @@ -. +.. ---------------------------------------------------------------------- -Ran 1 tests +Ran 2 tests =20 OK --=20 2.18.0 From nobody Sun Feb 8 18:33:09 2026 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=1565187221; cv=none; d=zoho.com; s=zohoarc; b=PwUrhsZF42+wA/84UTNl4NvKIaSmCk/5wdk/pQta6mP3jPyUBn0doCQ5OtgOZg6rNXHzpxQT3VnQ9EuRZ0VoVS9kYAtLfePbpYl4VFIzOKHPOXBJ5ohUTVRB9pL/iTkbKruLtCJJCb9QoFjQuhtll2Nn299AWioR8c1soXM1DUM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565187221; 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=fycJqQnM9SRyerIWyZ/v3DzpUXYBLEdSFtVq/ahtOaY=; b=GjN1uPdFRG30Wq2Wt0Zhl4T+gdFiNUMbXIWTRupdWCmMcyAZNfVQknOtCl9MtFah5ue/zx4ymRBnuqA0HJ4qBMoOXLLWKEYuViJWZtnAePGH+34QzWV9vBL6w91MWtQmUrr+v55/vGVdx3vSPl2PZte9Hvv+5kLLvWWGe/VPxcM= 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 1565187221766653.9853144347643; Wed, 7 Aug 2019 07:13:41 -0700 (PDT) Received: from localhost ([::1]:41612 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hvMhA-0001kQ-2Q for importer@patchew.org; Wed, 07 Aug 2019 10:13:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36597) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hvMg7-0007jm-Kw for qemu-devel@nongnu.org; Wed, 07 Aug 2019 10:12:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hvMg6-0003JW-Iw for qemu-devel@nongnu.org; Wed, 07 Aug 2019 10:12:35 -0400 Received: from relay.sw.ru ([185.231.240.75]:40634) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hvMg4-0003Cy-27; Wed, 07 Aug 2019 10:12:32 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hvMfz-0005oH-Oj; Wed, 07 Aug 2019 17:12:27 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Date: Wed, 7 Aug 2019 17:12:20 +0300 Message-Id: <20190807141226.193501-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190807141226.193501-1-vsementsov@virtuozzo.com> References: <20190807141226.193501-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 v4 04/10] iotests.py: add event_wait_log and events_wait_log helpers 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, qemu-devel@nongnu.org, 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" Signed-off-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/iotests.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index ce74177ab1..4ad265f140 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -540,6 +540,16 @@ class VM(qtest.QEMUQtestMachine): log(result, filters, indent=3Dindent) return result =20 + def event_wait_log(self, name, **kwargs): + event =3D self.event_wait(name, **kwargs) + log(event, filters=3D[filter_qmp_event]) + return event + + def events_wait_log(self, events, **kwargs): + event =3D self.events_wait(events, **kwargs) + log(event, filters=3D[filter_qmp_event]) + return event + # Returns None on success, and an error string on failure def run_job(self, job, auto_finalize=3DTrue, auto_dismiss=3DFalse, pre_finalize=3DNone, use_log=3DTrue, wait=3D60.0): --=20 2.18.0 From nobody Sun Feb 8 18:33:09 2026 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=1565187356; cv=none; d=zoho.com; s=zohoarc; b=MGu/nfN1L6bM3X/Db5Ot7aQiwM2acaLlmndquhmQqMJQJcxzii+cKCopXS8iUASFsi159Bz9V+V7f9DRnqeNnKtBrcOBOSYKO1u9uBbrh0IoEt6WO9AVFPwXAg28N+AZJL1jzEdo020W5S93o+ug8jS74r+nMcMbDgYcFDFgt4k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565187356; 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=3qLEC4D/Kr4XXnTlsMk1bKtqNMdj11/kWhlta6wcIrE=; b=oADrYz0PZu+R0yl8iWeBtBEE60m/dgwPnRiD0DBvvConDgeXEOvMwwYgjf/R14eKgnRkXKfd24A5/nc78ZGtUcbQcHCpeHoMkPOQkeuFV94CcZR0znJ3HacoI0fRLvV2ufYsMlS5ro5Ck8yt/hgPW9IRb6W6hRlPyxUKx9SZ6/U= 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 1565187356997521.5166289113439; Wed, 7 Aug 2019 07:15:56 -0700 (PDT) Received: from localhost ([::1]:41662 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hvMjM-0007Pe-1g for importer@patchew.org; Wed, 07 Aug 2019 10:15:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36652) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hvMg8-0007oq-Qc for qemu-devel@nongnu.org; Wed, 07 Aug 2019 10:12:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hvMg7-0003Kr-Hh for qemu-devel@nongnu.org; Wed, 07 Aug 2019 10:12:36 -0400 Received: from relay.sw.ru ([185.231.240.75]:40642) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hvMg4-0003D1-Bj; Wed, 07 Aug 2019 10:12:32 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hvMfz-0005oH-T2; Wed, 07 Aug 2019 17:12:27 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Date: Wed, 7 Aug 2019 17:12:21 +0300 Message-Id: <20190807141226.193501-6-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190807141226.193501-1-vsementsov@virtuozzo.com> References: <20190807141226.193501-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 v4 05/10] block/qcow2-bitmap: get rid of bdrv_has_changed_persistent_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@euphon.net, kwolf@redhat.com, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, 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" Firstly, no reason to optimize failure path. Then, function name is ambiguous: it checks for readonly and similar things, but someone may think that it will ignore normal bitmaps which was just unchanged, and this is in bad relation with the fact that we should drop IN_USE flag for unchanged bitmaps in the image. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: John Snow --- include/block/dirty-bitmap.h | 1 - block/dirty-bitmap.c | 12 ------------ block/qcow2-bitmap.c | 23 +++++++++++++---------- 3 files changed, 13 insertions(+), 23 deletions(-) diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h index 62682eb865..acca86d0fc 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -104,7 +104,6 @@ bool bdrv_has_readonly_bitmaps(BlockDriverState *bs); bool bdrv_dirty_bitmap_get_autoload(const BdrvDirtyBitmap *bitmap); bool bdrv_dirty_bitmap_get_persistence(BdrvDirtyBitmap *bitmap); bool bdrv_dirty_bitmap_inconsistent(const BdrvDirtyBitmap *bitmap); -bool bdrv_has_changed_persistent_bitmaps(BlockDriverState *bs); BdrvDirtyBitmap *bdrv_dirty_bitmap_next(BlockDriverState *bs, BdrvDirtyBitmap *bitmap); char *bdrv_dirty_bitmap_sha256(const BdrvDirtyBitmap *bitmap, Error **errp= ); diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index 95a9c2a5d8..2e0cecf5ff 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -774,18 +774,6 @@ bool bdrv_dirty_bitmap_inconsistent(const BdrvDirtyBit= map *bitmap) return bitmap->inconsistent; } =20 -bool bdrv_has_changed_persistent_bitmaps(BlockDriverState *bs) -{ - BdrvDirtyBitmap *bm; - QLIST_FOREACH(bm, &bs->dirty_bitmaps, list) { - if (bm->persistent && !bm->readonly && !bm->migration) { - return true; - } - } - - return false; -} - BdrvDirtyBitmap *bdrv_dirty_bitmap_next(BlockDriverState *bs, BdrvDirtyBitmap *bitmap) { diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index b2487101ed..60b79f1dac 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -1456,16 +1456,7 @@ void qcow2_store_persistent_dirty_bitmaps(BlockDrive= rState *bs, Error **errp) Qcow2Bitmap *bm; QSIMPLEQ_HEAD(, Qcow2BitmapTable) drop_tables; Qcow2BitmapTable *tb, *tb_next; - - if (!bdrv_has_changed_persistent_bitmaps(bs)) { - /* nothing to do */ - return; - } - - if (!can_write(bs)) { - error_setg(errp, "No write access"); - return; - } + bool need_write =3D false; =20 QSIMPLEQ_INIT(&drop_tables); =20 @@ -1493,6 +1484,8 @@ void qcow2_store_persistent_dirty_bitmaps(BlockDriver= State *bs, Error **errp) continue; } =20 + need_write =3D true; + if (check_constraints_on_bitmap(bs, name, granularity, errp) < 0) { error_prepend(errp, "Bitmap '%s' doesn't satisfy the constrain= ts: ", name); @@ -1531,6 +1524,15 @@ void qcow2_store_persistent_dirty_bitmaps(BlockDrive= rState *bs, Error **errp) bm->dirty_bitmap =3D bitmap; } =20 + if (!need_write) { + goto success; + } + + if (!can_write(bs)) { + error_setg(errp, "No write access"); + goto fail; + } + /* allocate clusters and store bitmaps */ QSIMPLEQ_FOREACH(bm, bm_list, entry) { if (bm->dirty_bitmap =3D=3D NULL) { @@ -1572,6 +1574,7 @@ void qcow2_store_persistent_dirty_bitmaps(BlockDriver= State *bs, Error **errp) bdrv_release_dirty_bitmap(bs, bm->dirty_bitmap); } =20 +success: bitmap_list_free(bm_list); return; =20 --=20 2.18.0 From nobody Sun Feb 8 18:33:09 2026 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=1565187224; cv=none; d=zoho.com; s=zohoarc; b=eJe/xuN/ZYAa7LGn6HRD2JO2JrwXCOS1V+NmUw0KG9pAmQSkHC9BU+9jsWPY5y9FEY2+bluIFseCJ8fnyFXra3h6B6fMpZcpt6CZ2sq/UKCMT/kmmHVv9QafTggtzDtriQVoZy6wWDXCzkeVaFT8r6U/D/rDa+68qz+/3F3e4d8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565187224; 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=LqwuiPnG8lZiyMN/uanfdpl/hQH6H9khaXZW2QWIj0Q=; b=dZ/q6/8ejPmFXUDxjgQPOCpdQfd8Pn1/tOPAKdxPf/WmmlJy2sTBm5Jz44rBNUTmj9Iyos9fNCkRSPbPFeKl6zTdNQkiKr48i5QizpOWe/1D36OUhwKb9zVJBDLiumcbHDfqEzRnSgJwS2AYze97I60oFTf5opOZ1y35SiJkQ60= 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 1565187224086717.153235972907; Wed, 7 Aug 2019 07:13:44 -0700 (PDT) Received: from localhost ([::1]:41614 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hvMhB-0001mm-0d for importer@patchew.org; Wed, 07 Aug 2019 10:13:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36618) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hvMg8-0007lo-5X for qemu-devel@nongnu.org; Wed, 07 Aug 2019 10:12:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hvMg6-0003K5-RL for qemu-devel@nongnu.org; Wed, 07 Aug 2019 10:12:36 -0400 Received: from relay.sw.ru ([185.231.240.75]:40618) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hvMg4-0003Cu-2b; Wed, 07 Aug 2019 10:12:32 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hvMg0-0005oH-15; Wed, 07 Aug 2019 17:12:28 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Date: Wed, 7 Aug 2019 17:12:22 +0300 Message-Id: <20190807141226.193501-7-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190807141226.193501-1-vsementsov@virtuozzo.com> References: <20190807141226.193501-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 v4 06/10] block/qcow2-bitmap: drop qcow2_reopen_bitmaps_rw_hint() 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, qemu-devel@nongnu.org, 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" The function is unused, drop it. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: John Snow --- block/qcow2.h | 2 -- block/qcow2-bitmap.c | 15 +-------------- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index fc1b0d3c1e..a5b24f4eec 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -736,8 +736,6 @@ int qcow2_check_bitmaps_refcounts(BlockDriverState *bs,= BdrvCheckResult *res, bool qcow2_load_dirty_bitmaps(BlockDriverState *bs, Error **errp); Qcow2BitmapInfoList *qcow2_get_bitmap_info_list(BlockDriverState *bs, Error **errp); -int qcow2_reopen_bitmaps_rw_hint(BlockDriverState *bs, bool *header_update= d, - Error **errp); 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); diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index 60b79f1dac..fbeee37243 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -1102,8 +1102,7 @@ Qcow2BitmapInfoList *qcow2_get_bitmap_info_list(Block= DriverState *bs, return list; } =20 -int qcow2_reopen_bitmaps_rw_hint(BlockDriverState *bs, bool *header_update= d, - Error **errp) +int qcow2_reopen_bitmaps_rw(BlockDriverState *bs, Error **errp) { BDRVQcow2State *s =3D bs->opaque; Qcow2BitmapList *bm_list; @@ -1111,10 +1110,6 @@ int qcow2_reopen_bitmaps_rw_hint(BlockDriverState *b= s, bool *header_updated, GSList *ro_dirty_bitmaps =3D NULL; int ret =3D 0; =20 - if (header_updated !=3D NULL) { - *header_updated =3D false; - } - if (s->nb_bitmaps =3D=3D 0) { /* No bitmaps - nothing to do */ return 0; @@ -1156,9 +1151,6 @@ int qcow2_reopen_bitmaps_rw_hint(BlockDriverState *bs= , bool *header_updated, error_setg_errno(errp, -ret, "Can't update bitmap directory"); goto out; } - if (header_updated !=3D NULL) { - *header_updated =3D true; - } g_slist_foreach(ro_dirty_bitmaps, set_readonly_helper, false); } =20 @@ -1169,11 +1161,6 @@ out: return ret; } =20 -int qcow2_reopen_bitmaps_rw(BlockDriverState *bs, Error **errp) -{ - return qcow2_reopen_bitmaps_rw_hint(bs, NULL, errp); -} - /* Checks to see if it's safe to resize bitmaps */ int qcow2_truncate_bitmaps_check(BlockDriverState *bs, Error **errp) { --=20 2.18.0 From nobody Sun Feb 8 18:33:09 2026 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=1565187352; cv=none; d=zoho.com; s=zohoarc; b=ObhLbvdPoUJu3D9BryiVoFEu2eYSM02Qwn+rHtxNuFX/vEYFCv3hSySE9oPxCOXSGL9zu372rBmLSR3MGP6p/zrjsrLGz+9CVjNT6+awq27YBRt3xs23WM5WqoZ1+IkUJg39ptjiOJ5xtMEOra89/LNv9btu2K5g9OwbGUxjuk0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565187352; 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=n22WfQaLwYyP0l8gZyTQJNLNs2Kh43O5k2wB4gghXiE=; b=DjRF6y88ZKOouEprfwdO9DYbWYvwJJvs8kH90O7u3gJPMEBzaBB39wDrNqwapLhB9rVh17UFyloXuiwGvaYYb1HtG/JewrIf7x1OMgDtxEFnsWWUqWVDWhFoVnK/MOx8j4viaj0vHg/ha3ys0Ul/07bE0KBmlB+sVj6MTew8ktM= 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 1565187352238551.1369624650555; Wed, 7 Aug 2019 07:15:52 -0700 (PDT) Received: from localhost ([::1]:41658 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hvMjH-0007BX-8p for importer@patchew.org; Wed, 07 Aug 2019 10:15:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36678) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hvMg9-0007ro-Hg for qemu-devel@nongnu.org; Wed, 07 Aug 2019 10:12:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hvMg8-0003LY-2Y for qemu-devel@nongnu.org; Wed, 07 Aug 2019 10:12:37 -0400 Received: from relay.sw.ru ([185.231.240.75]:40632) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hvMg4-0003Ct-BS; Wed, 07 Aug 2019 10:12:32 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hvMg0-0005oH-4M; Wed, 07 Aug 2019 17:12:28 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Date: Wed, 7 Aug 2019 17:12:23 +0300 Message-Id: <20190807141226.193501-8-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190807141226.193501-1-vsementsov@virtuozzo.com> References: <20190807141226.193501-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 v4 07/10] block/qcow2-bitmap: do not remove bitmaps on reopen-ro 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, qemu-devel@nongnu.org, 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" qcow2_reopen_bitmaps_ro wants to store bitmaps and then mark them all readonly. But the latter don't work, as qcow2_store_persistent_dirty_bitmaps removes bitmaps after storing. It's OK for inactivation but bad idea for reopen-ro. And this leads to the following bug: Assume we have persistent bitmap 'bitmap0'. Create external snapshot bitmap0 is stored and therefore removed Commit snapshot now we have no bitmaps Do some writes from guest (*) they are not marked in bitmap Shutdown Start bitmap0 is loaded as valid, but it is actually broken! It misses writes (*) Incremental backup it will be inconsistent So, let's stop removing bitmaps on reopen-ro. But don't rejoice: reopening bitmaps to rw is broken too, so the whole scenario will not work after this patch and we can't enable corresponding test cases in 260 iotests still. Reopening bitmaps rw will be fixed in the following patches. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: John Snow --- block/qcow2.h | 3 ++- block/qcow2-bitmap.c | 49 ++++++++++++++++++++++++++++++-------------- block/qcow2.c | 2 +- 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index a5b24f4eec..a67e6a7d7c 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -738,7 +738,8 @@ Qcow2BitmapInfoList *qcow2_get_bitmap_info_list(BlockDr= iverState *bs, Error **errp); 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); +void qcow2_store_persistent_dirty_bitmaps(BlockDriverState *bs, + bool release_stored, Error **err= p); int qcow2_reopen_bitmaps_ro(BlockDriverState *bs, Error **errp); bool qcow2_can_store_new_dirty_bitmap(BlockDriverState *bs, const char *name, diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index fbeee37243..a636dc50ca 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -1432,7 +1432,32 @@ fail: bitmap_list_free(bm_list); } =20 -void qcow2_store_persistent_dirty_bitmaps(BlockDriverState *bs, Error **er= rp) +/* + * qcow2_store_persistent_dirty_bitmaps + * + * Stores persistent BdrvDirtyBitmap objects. + * + * @release_stored: if true, release BdrvDirtyBitmap's after storing to the + * image. This is used in two cases, both via qcow2_inactivate: + * 1. bdrv_close: It's correct to remove bitmaps on close. + * 2. migration: If bitmaps are migrated through migration channel via + * 'dirty-bitmaps' migration capability they are not handled by this co= de. + * Otherwise, it's OK to drop BdrvDirtyBitmap's and reload them on + * invalidation. + * + * Anyway, it's correct to remove BdrvDirtyBitmap's on inactivation, as + * inactivation means that we lose control on disk, and therefore on bitma= ps, + * we should sync them and do not touch more. + * + * Contrariwise, we don't want to release any bitmaps on just reopen-to-ro, + * when we need to store them, as image is still under our control, and it= 's + * good to keep all the bitmaps in read-only mode. Moreover, keeping them + * read-only is correct because this is what would happen if we opened the= node + * readonly to begin with, and whether we opened directly or reopened to t= hat + * state shouldn't matter for the state we get afterward. + */ +void qcow2_store_persistent_dirty_bitmaps(BlockDriverState *bs, + bool release_stored, Error **err= p) { BdrvDirtyBitmap *bitmap; BDRVQcow2State *s =3D bs->opaque; @@ -1545,20 +1570,14 @@ void qcow2_store_persistent_dirty_bitmaps(BlockDriv= erState *bs, Error **errp) g_free(tb); } =20 - QSIMPLEQ_FOREACH(bm, bm_list, entry) { - /* For safety, we remove bitmap after storing. - * We may be here in two cases: - * 1. bdrv_close. It's ok to drop bitmap. - * 2. inactivation. It means migration without 'dirty-bitmaps' - * capability, so bitmaps are not marked with - * BdrvDirtyBitmap.migration flags. It's not bad to drop them t= oo, - * and reload on invalidation. - */ - if (bm->dirty_bitmap =3D=3D NULL) { - continue; - } + if (release_stored) { + QSIMPLEQ_FOREACH(bm, bm_list, entry) { + if (bm->dirty_bitmap =3D=3D NULL) { + continue; + } =20 - bdrv_release_dirty_bitmap(bs, bm->dirty_bitmap); + bdrv_release_dirty_bitmap(bs, bm->dirty_bitmap); + } } =20 success: @@ -1586,7 +1605,7 @@ int qcow2_reopen_bitmaps_ro(BlockDriverState *bs, Err= or **errp) BdrvDirtyBitmap *bitmap; Error *local_err =3D NULL; =20 - qcow2_store_persistent_dirty_bitmaps(bs, &local_err); + qcow2_store_persistent_dirty_bitmaps(bs, false, &local_err); if (local_err !=3D NULL) { error_propagate(errp, local_err); return -EINVAL; diff --git a/block/qcow2.c b/block/qcow2.c index 039bdc2f7e..5c1187e2f9 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2356,7 +2356,7 @@ static int qcow2_inactivate(BlockDriverState *bs) int ret, result =3D 0; Error *local_err =3D NULL; =20 - qcow2_store_persistent_dirty_bitmaps(bs, &local_err); + qcow2_store_persistent_dirty_bitmaps(bs, true, &local_err); if (local_err !=3D NULL) { result =3D -EINVAL; error_reportf_err(local_err, "Lost persistent bitmaps during " --=20 2.18.0 From nobody Sun Feb 8 18:33:09 2026 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=1565187424; cv=none; d=zoho.com; s=zohoarc; b=AqFeaz0KVRj2P13N7ZZ/X1TzAHiuqSm2AqLnlwC0PBCeHQd7P89MpkD4Sp1A0BkxrP0hDBshC3HYZ/YXH67Xc8uSK0a5/MCf6YlHnC67wu9+X7LcGgqi0945hsTrQ9hBqKcISqJF7fqmbALFP4+1ImSJBpuYoY+pQWBuR+pRvqM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565187424; 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=jMGAlAkOgYnQ5KoVkEIB3/q90q3fMdqAY74dGDiSjhc=; b=GR5SAZzJy+KSkgv8xVvReE5tFdgS87mDogIsOMKw4jjB5J6u1e/fE9czzRxiC9qQWTrYNhWePNts7lEqzttHrGCu9bd8wSvkjPOSzchauuvRQf4bEXSvvh2EHNShfcXoKpdYwjGVuM5VJyoN46gZK0+qWB4QUrHul/QGRUoOtEM= 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 1565187424865750.2478294231062; Wed, 7 Aug 2019 07:17:04 -0700 (PDT) Received: from localhost ([::1]:41688 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hvMkQ-00019x-V5 for importer@patchew.org; Wed, 07 Aug 2019 10:17:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36702) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hvMgA-0007v2-DP for qemu-devel@nongnu.org; Wed, 07 Aug 2019 10:12:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hvMg8-0003MP-Kx for qemu-devel@nongnu.org; Wed, 07 Aug 2019 10:12:38 -0400 Received: from relay.sw.ru ([185.231.240.75]:40628) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hvMg4-0003Cv-9n; Wed, 07 Aug 2019 10:12:32 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hvMg0-0005oH-5i; Wed, 07 Aug 2019 17:12:28 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Date: Wed, 7 Aug 2019 17:12:24 +0300 Message-Id: <20190807141226.193501-9-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190807141226.193501-1-vsementsov@virtuozzo.com> References: <20190807141226.193501-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 v4 08/10] iotests: add test 260 to check bitmap life after snapshot + commit 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, qemu-devel@nongnu.org, 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" Two testcases with persistent bitmaps are not added here, as there are bugs to be fixed soon. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: John Snow --- tests/qemu-iotests/260 | 87 ++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/260.out | 52 +++++++++++++++++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 140 insertions(+) create mode 100755 tests/qemu-iotests/260 create mode 100644 tests/qemu-iotests/260.out diff --git a/tests/qemu-iotests/260 b/tests/qemu-iotests/260 new file mode 100755 index 0000000000..d8fcf4567a --- /dev/null +++ b/tests/qemu-iotests/260 @@ -0,0 +1,87 @@ +#!/usr/bin/env python +# +# Tests for temporary external snapshot when we have bitmaps. +# +# Copyright (c) 2019 Virtuozzo International GmbH. All rights reserved. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import iotests +from iotests import qemu_img_create, file_path, log + +iotests.verify_image_format(supported_fmts=3D['qcow2']) + +base, top =3D file_path('base', 'top') +size =3D 64 * 1024 * 3 + + +def print_bitmap(msg, vm): + result =3D vm.qmp('query-block')['return'][0] + if 'dirty-bitmaps' in result: + bitmap =3D result['dirty-bitmaps'][0] + log('{}: name=3D{} dirty-clusters=3D{}'.format(msg, bitmap['name'], + bitmap['count'] // 64 // 1024)) + else: + log(msg + ': not found') + + +def test(persistent, restart): + assert persistent or not restart + log("\nTestcase {}persistent {} restart\n".format( + '' if persistent else 'non-', 'with' if restart else 'without'= )) + + qemu_img_create('-f', iotests.imgfmt, base, str(size)) + + vm =3D iotests.VM().add_drive(base) + vm.launch() + + vm.qmp_log('block-dirty-bitmap-add', node=3D'drive0', name=3D'bitmap0', + persistent=3Dpersistent) + vm.hmp_qemu_io('drive0', 'write 0 64K') + print_bitmap('initial bitmap', vm) + + vm.qmp_log('blockdev-snapshot-sync', device=3D'drive0', snapshot_file= =3Dtop, + format=3Diotests.imgfmt, filters=3D[iotests.filter_qmp_test= files]) + vm.hmp_qemu_io('drive0', 'write 64K 512') + print_bitmap('check that no bitmaps are in snapshot', vm) + + if restart: + log("... Restart ...") + vm.shutdown() + vm =3D iotests.VM().add_drive(top) + vm.launch() + + vm.qmp_log('block-commit', device=3D'drive0', top=3Dtop, + filters=3D[iotests.filter_qmp_testfiles]) + ev =3D vm.events_wait_log((('BLOCK_JOB_READY', None), + ('BLOCK_JOB_COMPLETED', None))) + if (ev['event'] =3D=3D 'BLOCK_JOB_COMPLETED'): + vm.shutdown() + log(vm.get_log()) + exit() + + vm.qmp_log('block-job-complete', device=3D'drive0') + vm.event_wait_log('BLOCK_JOB_COMPLETED') + print_bitmap('check bitmap after commit', vm) + + vm.hmp_qemu_io('drive0', 'write 128K 64K') + print_bitmap('check updated bitmap', vm) + + vm.shutdown() + + +test(persistent=3DFalse, restart=3DFalse) +test(persistent=3DTrue, restart=3DFalse) +test(persistent=3DTrue, restart=3DTrue) diff --git a/tests/qemu-iotests/260.out b/tests/qemu-iotests/260.out new file mode 100644 index 0000000000..2f0d98d036 --- /dev/null +++ b/tests/qemu-iotests/260.out @@ -0,0 +1,52 @@ + +Testcase non-persistent without restart + +{"execute": "block-dirty-bitmap-add", "arguments": {"name": "bitmap0", "no= de": "drive0", "persistent": false}} +{"return": {}} +initial bitmap: name=3Dbitmap0 dirty-clusters=3D1 +{"execute": "blockdev-snapshot-sync", "arguments": {"device": "drive0", "f= ormat": "qcow2", "snapshot-file": "TEST_DIR/PID-top"}} +{"return": {}} +check that no bitmaps are in snapshot: not found +{"execute": "block-commit", "arguments": {"device": "drive0", "top": "TEST= _DIR/PID-top"}} +{"return": {}} +{"data": {"device": "drive0", "len": 65536, "offset": 65536, "speed": 0, "= type": "commit"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds":= "USECS", "seconds": "SECS"}} +{"execute": "block-job-complete", "arguments": {"device": "drive0"}} +{"return": {}} +{"data": {"device": "drive0", "len": 65536, "offset": 65536, "speed": 0, "= type": "commit"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microsecon= ds": "USECS", "seconds": "SECS"}} +check bitmap after commit: name=3Dbitmap0 dirty-clusters=3D2 +check updated bitmap: name=3Dbitmap0 dirty-clusters=3D3 + +Testcase persistent without restart + +{"execute": "block-dirty-bitmap-add", "arguments": {"name": "bitmap0", "no= de": "drive0", "persistent": true}} +{"return": {}} +initial bitmap: name=3Dbitmap0 dirty-clusters=3D1 +{"execute": "blockdev-snapshot-sync", "arguments": {"device": "drive0", "f= ormat": "qcow2", "snapshot-file": "TEST_DIR/PID-top"}} +{"return": {}} +check that no bitmaps are in snapshot: not found +{"execute": "block-commit", "arguments": {"device": "drive0", "top": "TEST= _DIR/PID-top"}} +{"return": {}} +{"data": {"device": "drive0", "len": 65536, "offset": 65536, "speed": 0, "= type": "commit"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds":= "USECS", "seconds": "SECS"}} +{"execute": "block-job-complete", "arguments": {"device": "drive0"}} +{"return": {}} +{"data": {"device": "drive0", "len": 65536, "offset": 65536, "speed": 0, "= type": "commit"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microsecon= ds": "USECS", "seconds": "SECS"}} +check bitmap after commit: name=3Dbitmap0 dirty-clusters=3D2 +check updated bitmap: name=3Dbitmap0 dirty-clusters=3D3 + +Testcase persistent with restart + +{"execute": "block-dirty-bitmap-add", "arguments": {"name": "bitmap0", "no= de": "drive0", "persistent": true}} +{"return": {}} +initial bitmap: name=3Dbitmap0 dirty-clusters=3D1 +{"execute": "blockdev-snapshot-sync", "arguments": {"device": "drive0", "f= ormat": "qcow2", "snapshot-file": "TEST_DIR/PID-top"}} +{"return": {}} +check that no bitmaps are in snapshot: not found +... Restart ... +{"execute": "block-commit", "arguments": {"device": "drive0", "top": "TEST= _DIR/PID-top"}} +{"return": {}} +{"data": {"device": "drive0", "len": 65536, "offset": 65536, "speed": 0, "= type": "commit"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds":= "USECS", "seconds": "SECS"}} +{"execute": "block-job-complete", "arguments": {"device": "drive0"}} +{"return": {}} +{"data": {"device": "drive0", "len": 65536, "offset": 65536, "speed": 0, "= type": "commit"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microsecon= ds": "USECS", "seconds": "SECS"}} +check bitmap after commit: name=3Dbitmap0 dirty-clusters=3D2 +check updated bitmap: name=3Dbitmap0 dirty-clusters=3D3 diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index f13e5f2e23..06f1ea904c 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -271,3 +271,4 @@ 254 rw backing quick 255 rw quick 256 rw quick +260 rw auto quick --=20 2.18.0 From nobody Sun Feb 8 18:33:09 2026 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=1565187285; cv=none; d=zoho.com; s=zohoarc; b=N/ho4m61ktLm6CUd6m82DJZDwmHF4SsaRxNEixp9HlqW5xmyRX+u4haXhytOgtWqmnS//aY/QgxnIEyglqfaFFy273PsYlZG8rlj749RhqgLVdq+8M0+Ppw6g+TOd1QpSnSjAPtBhEIsB7zhoFt5nyhBFWVBC8swGBWOQiZlglM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565187285; 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=89REYQ+kqx0R0rDxkiGSj6AQ7aJeHCxflwoRpmyCS+M=; b=CGw0+aNR8CvN0lf7MABRn4Eu+E7AJY+tBQYr71qBJjedM8CxWJ1wDv3NtLFd57V5Hhy4bQbG5ljrPcv7ZI5urtYVM29p2mnWsiZOxeaWMQSb/bm9Gxu7X7CxBN6C4Xj/vAbUwVW1xDQxX2FeZf8P73HZbr21vmf9KPoRFIGK5W4= 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 1565187285521664.4151302311523; Wed, 7 Aug 2019 07:14:45 -0700 (PDT) Received: from localhost ([::1]:41632 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hvMiC-0004Wo-JK for importer@patchew.org; Wed, 07 Aug 2019 10:14:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36638) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hvMg8-0007nt-Ks for qemu-devel@nongnu.org; Wed, 07 Aug 2019 10:12:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hvMg7-0003Kk-EL for qemu-devel@nongnu.org; Wed, 07 Aug 2019 10:12:36 -0400 Received: from relay.sw.ru ([185.231.240.75]:40638) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hvMg4-0003D0-Bh; Wed, 07 Aug 2019 10:12:32 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hvMg0-0005oH-8Q; Wed, 07 Aug 2019 17:12:28 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Date: Wed, 7 Aug 2019 17:12:25 +0300 Message-Id: <20190807141226.193501-10-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190807141226.193501-1-vsementsov@virtuozzo.com> References: <20190807141226.193501-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 v4 09/10] 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, qemu-devel@nongnu.org, 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 following commit), 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 From nobody Sun Feb 8 18:33:09 2026 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=1565187289; cv=none; d=zoho.com; s=zohoarc; b=aMXWPmDp61h9YA5EogYmoFI9/brNGC6KxjWej50Ag3cbfB1fDAKwCoQ6YACFHxduj1DK9caOJWvqigH9SXsSJdQd3mPjeMt23rntwfaOKfHez+8bl9Yv2sHOrDXZT+pwh0Ql+NzqPr1SDWqrMFtrKYaibMDY3h/glbIWifOfDLM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565187289; 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=qQq/pLLAAjd7nStwwpYlo4ConsIrAWYA5wj+P4u3s70=; b=kWTZwzrr+t53x4Wvr58JheW7YBHWagv2S36dhbI5NJ43Tf20Jr8ypuvSG1Y6qy5bOb8oQCBkziY9XLt9mKD/qkl0Ky1romFlWBzeLCRF2xcZ+kRcJWTWmMKUKD5pupbfyViUbeo3+nMv+gMpG2BWO6/qbtHb63jtrNie+fV2etw= 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 1565187289741749.1778220616944; Wed, 7 Aug 2019 07:14:49 -0700 (PDT) Received: from localhost ([::1]:41636 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hvMiG-0004ko-QN for importer@patchew.org; Wed, 07 Aug 2019 10:14:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36630) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hvMg8-0007mi-Gb for qemu-devel@nongnu.org; Wed, 07 Aug 2019 10:12:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hvMg7-0003KS-5e for qemu-devel@nongnu.org; Wed, 07 Aug 2019 10:12:36 -0400 Received: from relay.sw.ru ([185.231.240.75]:40658) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hvMg4-0003Cx-1h; Wed, 07 Aug 2019 10:12:32 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hvMg0-0005oH-BO; Wed, 07 Aug 2019 17:12:28 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Date: Wed, 7 Aug 2019 17:12:26 +0300 Message-Id: <20190807141226.193501-11-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190807141226.193501-1-vsementsov@virtuozzo.com> References: <20190807141226.193501-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 v4 10/10] qcow2-bitmap: move bitmap reopen-rw code to qcow2_reopen_commit 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, qemu-devel@nongnu.org, 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" The only reason I can imagine for this strange code at the very-end of bdrv_reopen_commit is the fact that bs->read_only updated after calling drv->bdrv_reopen_commit in bdrv_reopen_commit. And in the same time, prior to previous commit, qcow2_reopen_bitmaps_rw did a wrong check for being writable, when actually it only need writable file child not self. So, as it's fixed, let's move things to correct place. Signed-off-by: Vladimir Sementsov-Ogievskiy Acked-by: Max Reitz Reviewed-by: John Snow --- include/block/block_int.h | 6 ------ block.c | 19 ------------------- block/qcow2.c | 15 ++++++++++++++- 3 files changed, 14 insertions(+), 26 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index 3aa1e832a8..18a1e81194 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -531,12 +531,6 @@ struct BlockDriver { uint64_t parent_perm, uint64_t parent_shared, uint64_t *nperm, uint64_t *nshared); =20 - /** - * Bitmaps should be marked as 'IN_USE' in the image on reopening image - * as rw. This handler should realize it. It also should unset readonly - * 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, diff --git a/block.c b/block.c index d59f9f97cb..395bc88045 100644 --- a/block.c +++ b/block.c @@ -3925,16 +3925,12 @@ void bdrv_reopen_commit(BDRVReopenState *reopen_sta= te) BlockDriver *drv; BlockDriverState *bs; BdrvChild *child; - bool old_can_write, new_can_write; =20 assert(reopen_state !=3D NULL); bs =3D reopen_state->bs; drv =3D bs->drv; assert(drv !=3D NULL); =20 - old_can_write =3D - !bdrv_is_read_only(bs) && !(bdrv_get_flags(bs) & BDRV_O_INACTIVE); - /* If there are any driver level actions to take */ if (drv->bdrv_reopen_commit) { drv->bdrv_reopen_commit(reopen_state); @@ -3978,21 +3974,6 @@ void bdrv_reopen_commit(BDRVReopenState *reopen_stat= e) } =20 bdrv_refresh_limits(bs, NULL); - - new_can_write =3D - !bdrv_is_read_only(bs) && !(bdrv_get_flags(bs) & BDRV_O_INACTIVE); - if (!old_can_write && new_can_write && drv->bdrv_reopen_bitmaps_rw) { - Error *local_err =3D NULL; - if (drv->bdrv_reopen_bitmaps_rw(bs, &local_err) < 0) { - /* This is not fatal, bitmaps just left read-only, so all foll= owing - * writes will fail. User can remove read-only bitmaps to unbl= ock - * writes. - */ - error_reportf_err(local_err, - "%s: Failed to make dirty bitmaps writable: = ", - bdrv_get_node_name(bs)); - } - } } =20 /* diff --git a/block/qcow2.c b/block/qcow2.c index 5c1187e2f9..9e6210c282 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1828,6 +1828,20 @@ fail: static void qcow2_reopen_commit(BDRVReopenState *state) { qcow2_update_options_commit(state->bs, state->opaque); + if (state->flags & BDRV_O_RDWR) { + Error *local_err =3D NULL; + + if (qcow2_reopen_bitmaps_rw(state->bs, &local_err) < 0) { + /* + * This is not fatal, bitmaps just left read-only, so all foll= owing + * writes will fail. User can remove read-only bitmaps to unbl= ock + * writes or retry reopen. + */ + error_reportf_err(local_err, + "%s: Failed to make dirty bitmaps writable: = ", + bdrv_get_node_name(state->bs)); + } + } g_free(state->opaque); } =20 @@ -5229,7 +5243,6 @@ BlockDriver bdrv_qcow2 =3D { .bdrv_detach_aio_context =3D qcow2_detach_aio_context, .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_remove_persistent_dirty_bitmap =3D qcow2_remove_persistent_dirty= _bitmap, }; --=20 2.18.0