From nobody Wed May 15 09:10:38 2024 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=1559320487; cv=none; d=zoho.com; s=zohoarc; b=OJ5XMSZoBuXQcesBlDDKJy3OBdL0T61J9NrXw37g6noJOe+Rwxy5YR4yvd4dZak9DFqj8GmHHOat5Qy1tSUKYqw6bjrhj1HJ7QgYFhmzKHcxP0Sn7jcdIX24ubVqFPcqiXNN61aUJ9SVd7LnU6QEVXXqFz8xwQ/MGoEP3CJWKB4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559320487; 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=hTERQcxDdoSZLAmTLag5lHP57JXGdcQjEDszo27QjWw=; b=E3Kb7pt6dCIOCOJb716NzHGI3B45Xb23pKgCtIQFudmWIH6uBDS9EnqETwElRmzwX49n0ex34i4a3JKcWVGJABdx4zYn41Z0uERk12gaJSecWqCM+SnbF8xuQrNZLM97cnYpe88gyG9McTbkzlsBviJvqzdOO3lvxpTqXIVq2+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 1559320487058397.7439288957297; Fri, 31 May 2019 09:34:47 -0700 (PDT) Received: from localhost ([127.0.0.1]:46165 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWkUH-00087p-0m for importer@patchew.org; Fri, 31 May 2019 12:34:37 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40248) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWkRu-0006mT-JD for qemu-devel@nongnu.org; Fri, 31 May 2019 12:32:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hWkRs-0008DJ-LD for qemu-devel@nongnu.org; Fri, 31 May 2019 12:32:10 -0400 Received: from relay.sw.ru ([185.231.240.75]:57228) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hWkRs-0008Ab-9L; Fri, 31 May 2019 12:32:08 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1hWkRn-0006Lb-9a; Fri, 31 May 2019 19:32:03 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Fri, 31 May 2019 19:31:54 +0300 Message-Id: <20190531163202.162543-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190531163202.162543-1-vsementsov@virtuozzo.com> References: <20190531163202.162543-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 v2 1/9] block: add .bdrv_need_rw_file_child_during_reopen_rw handler X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 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" On reopen to rw parent may need rw access to child in .prepare, for example qcow2 needs to write IN_USE flags into stored bitmaps (currently it is done in a hacky way after commit and don't work). So, let's introduce such logic. The drawback is that in worst case bdrv_reopen_set_read_only may finish with error and in some intermediate state: some nodes reopened RW and some are not. But this is a way to fix bug around reopening qcow2 bitmaps in the following commits. Signed-off-by: Vladimir Sementsov-Ogievskiy --- include/block/block_int.h | 2 + block.c | 144 ++++++++++++++++++++++++++++++++++---- 2 files changed, 133 insertions(+), 13 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index 1eebc7c8f3..7b22fb5d9c 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -531,6 +531,8 @@ struct BlockDriver { uint64_t parent_perm, uint64_t parent_shared, uint64_t *nperm, uint64_t *nshared); =20 + bool (*bdrv_need_rw_file_child_during_reopen_rw)(BlockDriverState *bs= ); + /** * 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 diff --git a/block.c b/block.c index 1a73e310c1..56e1388908 100644 --- a/block.c +++ b/block.c @@ -1713,10 +1713,12 @@ static void bdrv_get_cumulative_perm(BlockDriverSta= te *bs, uint64_t *perm, uint64_t *shared_perm); =20 typedef struct BlockReopenQueueEntry { - bool prepared; - bool perms_checked; - BDRVReopenState state; - QSIMPLEQ_ENTRY(BlockReopenQueueEntry) entry; + bool reopened_file_child_rw; + bool changed_file_child_perm_rw; + bool prepared; + bool perms_checked; + BDRVReopenState state; + QSIMPLEQ_ENTRY(BlockReopenQueueEntry) entry; } BlockReopenQueueEntry; =20 /* @@ -3278,6 +3280,105 @@ BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueu= e *bs_queue, keep_old_opts); } =20 +static int bdrv_reopen_set_read_only_drained(BlockDriverState *bs, + bool read_only, + Error **errp) +{ + BlockReopenQueue *queue; + QDict *opts =3D qdict_new(); + + qdict_put_bool(opts, BDRV_OPT_READ_ONLY, read_only); + + queue =3D bdrv_reopen_queue(NULL, bs, opts, true); + + return bdrv_reopen_multiple(queue, errp); +} + +/* + * handle_recursive_reopens + * + * On fail it needs rollback_recursive_reopens to be called. + */ +static int handle_recursive_reopens(BlockReopenQueueEntry *current, + Error **errp) +{ + int ret; + BlockDriverState *bs =3D current->state.bs; + + /* + * We use the fact that in reopen-queue children are always following + * parents. + * TODO: Switch BlockReopenQueue to be QTAILQ and use + * QTAILQ_FOREACH_REVERSE. + */ + if (QSIMPLEQ_NEXT(current, entry)) { + ret =3D handle_recursive_reopens(QSIMPLEQ_NEXT(current, entry), er= rp); + if (ret < 0) { + return ret; + } + } + + if ((current->state.flags & BDRV_O_RDWR) && bs->file && bs->drv && + bs->drv->bdrv_need_rw_file_child_during_reopen_rw && + bs->drv->bdrv_need_rw_file_child_during_reopen_rw(bs)) + { + if (!bdrv_is_writable(bs->file->bs)) { + ret =3D bdrv_reopen_set_read_only_drained(bs->file->bs, false,= errp); + if (ret < 0) { + return ret; + } + current->reopened_file_child_rw =3D true; + } + + if (!(bs->file->perm & BLK_PERM_WRITE)) { + ret =3D bdrv_child_try_set_perm(bs->file, + bs->file->perm | BLK_PERM_WRITE, + bs->file->shared_perm, errp); + if (ret < 0) { + return ret; + } + current->changed_file_child_perm_rw =3D true; + } + } + + return 0; +} + +static int rollback_recursive_reopens(BlockReopenQueue *bs_queue, + Error **errp) +{ + int ret; + BlockReopenQueueEntry *bs_entry; + + /* + * We use the fact that in reopen-queue children are always following + * parents. + */ + QSIMPLEQ_FOREACH(bs_entry, bs_queue, entry) { + BlockDriverState *bs =3D bs_entry->state.bs; + + if (bs_entry->changed_file_child_perm_rw) { + ret =3D bdrv_child_try_set_perm(bs->file, + bs->file->perm & ~BLK_PERM_WRITE, + bs->file->shared_perm, errp); + + if (ret < 0) { + return ret; + } + } + + if (bs_entry->reopened_file_child_rw) { + ret =3D bdrv_reopen_set_read_only_drained(bs, true, errp); + + if (ret < 0) { + return ret; + } + } + } + + return 0; +} + /* * Reopen multiple BlockDriverStates atomically & transactionally. * @@ -3297,11 +3398,18 @@ BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueu= e *bs_queue, */ int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp) { - int ret =3D -1; + int ret; BlockReopenQueueEntry *bs_entry, *next; =20 assert(bs_queue !=3D NULL); =20 + ret =3D handle_recursive_reopens(QSIMPLEQ_FIRST(bs_queue), errp); + if (ret < 0) { + goto rollback_recursion; + } + + ret =3D -1; + QSIMPLEQ_FOREACH(bs_entry, bs_queue, entry) { assert(bs_entry->state.bs->quiesce_counter > 0); if (bdrv_reopen_prepare(&bs_entry->state, bs_queue, errp)) { @@ -3342,7 +3450,7 @@ int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, = Error **errp) =20 ret =3D 0; cleanup_perm: - QSIMPLEQ_FOREACH_SAFE(bs_entry, bs_queue, entry, next) { + QSIMPLEQ_FOREACH(bs_entry, bs_queue, entry) { BDRVReopenState *state =3D &bs_entry->state; =20 if (!bs_entry->perms_checked) { @@ -3359,7 +3467,7 @@ cleanup_perm: } } cleanup: - QSIMPLEQ_FOREACH_SAFE(bs_entry, bs_queue, entry, next) { + QSIMPLEQ_FOREACH(bs_entry, bs_queue, entry) { if (ret) { if (bs_entry->prepared) { bdrv_reopen_abort(&bs_entry->state); @@ -3370,8 +3478,23 @@ cleanup: if (bs_entry->state.new_backing_bs) { bdrv_unref(bs_entry->state.new_backing_bs); } + } + +rollback_recursion: + if (ret) { + Error *local_err =3D NULL; + int ret2 =3D rollback_recursive_reopens(bs_queue, &local_err); + + if (ret2 < 0) { + error_reportf_err(local_err, "Failed to rollback partially " + "succeeded reopen to RW: "); + } + } + + QSIMPLEQ_FOREACH_SAFE(bs_entry, bs_queue, entry, next) { g_free(bs_entry); } + g_free(bs_queue); =20 return ret; @@ -3381,14 +3504,9 @@ int bdrv_reopen_set_read_only(BlockDriverState *bs, = bool read_only, Error **errp) { int ret; - BlockReopenQueue *queue; - QDict *opts =3D qdict_new(); - - qdict_put_bool(opts, BDRV_OPT_READ_ONLY, read_only); =20 bdrv_subtree_drained_begin(bs); - queue =3D bdrv_reopen_queue(NULL, bs, opts, true); - ret =3D bdrv_reopen_multiple(queue, errp); + ret =3D bdrv_reopen_set_read_only_drained(bs, read_only, errp); bdrv_subtree_drained_end(bs); =20 return ret; --=20 2.18.0 From nobody Wed May 15 09:10:38 2024 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=1559320628; cv=none; d=zoho.com; s=zohoarc; b=H+wrqqCl1fDmXlxLAUKnTjtU7NckjDaFv9qxMSNSAALNw84pFloxzhW3XXVtetKGMbg0BD4Cc80ym+0DTL470sp0I65vqdLIxnZ72sSE04hY5r3ouVNP820333Jb90wdGH8QbLVY5iEMxvLKUjct8qlzNFSAMA4IoHJqyaG8Nuw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559320628; 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=sKjAySt8yNV92MvJAf5cYFu+mdOo+HRrBuX42Hb5MXc=; b=kw1cIxa88qQ8Gug6Y5a19Ku0RdHRVt7JKjbI1wMtcxOH2cQob0T22zVP9k9N7AVCTJX2tG44uSDAcKoeSARYarDAfF0FK9BPj5mDgJiJF+vSUaLZb0ySHCipO7JyyPDiAwGpaeHTSJ538pUhU/TnFcdbT54z9gpWvZ9Hi27Q23E= 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1559320628357141.14677203864278; Fri, 31 May 2019 09:37:08 -0700 (PDT) Received: from localhost ([127.0.0.1]:46219 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWkWc-0001Ux-DO for importer@patchew.org; Fri, 31 May 2019 12:37:02 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40216) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWkRt-0006lz-Uu for qemu-devel@nongnu.org; Fri, 31 May 2019 12:32:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hWkRs-0008Ci-G8 for qemu-devel@nongnu.org; Fri, 31 May 2019 12:32:09 -0400 Received: from relay.sw.ru ([185.231.240.75]:57240) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hWkRs-0008Ae-6u; Fri, 31 May 2019 12:32:08 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1hWkRn-0006Lb-FF; Fri, 31 May 2019 19:32:03 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Fri, 31 May 2019 19:31:55 +0300 Message-Id: <20190531163202.162543-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190531163202.162543-1-vsementsov@virtuozzo.com> References: <20190531163202.162543-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 v2 2/9] python/qemu: improve event_wait method of vm X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 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" Support several names to wait for, which useful, when we don't sure which event will we get. For example when mirror fails we get BLOCK_JOB_COMPLETE otherwise we get BLOCK_JOB_READY (and only then, after completing block-job we get BLOCK_JOB_COMPLETE). Also, add filtered version for convenient use. Signed-off-by: Vladimir Sementsov-Ogievskiy --- python/qemu/__init__.py | 9 ++++++--- tests/qemu-iotests/iotests.py | 5 +++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/python/qemu/__init__.py b/python/qemu/__init__.py index 81d9657ec0..5e517025b9 100644 --- a/python/qemu/__init__.py +++ b/python/qemu/__init__.py @@ -402,7 +402,7 @@ class QEMUMachine(object): self._qmp.clear_events() return events =20 - def event_wait(self, name, timeout=3D60.0, match=3DNone): + def event_wait(self, names, timeout=3D60.0, match=3DNone): """ Wait for specified timeout on named event in QMP; optionally filter results by match. @@ -412,6 +412,9 @@ class QEMUMachine(object): {"foo": {"bar": 1}} matches {"foo": None} {"foo": {"bar": 1}} does not matches {"foo": {"baz": None}} """ + if not isinstance(names, list): + names =3D [names] + def event_match(event, match=3DNone): if match is None: return True @@ -430,14 +433,14 @@ class QEMUMachine(object): =20 # Search cached events for event in self._events: - if (event['event'] =3D=3D name) and event_match(event, match): + if (event['event'] in names) and event_match(event, match): self._events.remove(event) return event =20 # Poll for new events while True: event =3D self._qmp.pull_event(wait=3Dtimeout) - if (event['event'] =3D=3D name) and event_match(event, match): + if (event['event'] in names) and event_match(event, match): return event self._events.append(event) =20 diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index 7bde380d96..4218fc908b 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -532,6 +532,11 @@ class VM(qtest.QEMUQtestMachine): log(result, filters, indent=3Dindent) return result =20 + def event_wait_log(self, names, **kwargs): + event =3D self.event_wait(names, **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): error =3D None --=20 2.18.0 From nobody Wed May 15 09:10:38 2024 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=1559320962; cv=none; d=zoho.com; s=zohoarc; b=Nlv2AhQTb2UYk38rO3EHWwpAvvfCuzGPE1OM9WzXsCVm5eJweamfVgyWjVKXJLMSi25dMDO+S94FawKgcYaL38BmZNbruno5LBHE8x2UHUFZzporMyr1dlsUulpq0+RrxVy/NYOKEsPEEneeznv4udKnDdljjykvAcUk/04LbEA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559320962; 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=7IMTrlkkR+fqavxYrxb5sSMgVLeDZrd4CFn8WKWOib8=; b=ei2Agk61/fDwlhhCHSr4/cbpd6Vg0Fg/XX5JF20BqxUS0IST8mT413tuyP1hwIrWtJ8CdguAOnoUB+Ahtp/s0yzIEkFFqI5avtCB1SpBMJbB88BLJcAOHnxPTFvgl1R2mPxjG+8YvWWjV4zL4rJPif2rjO3Z0yRmQZbzM6daurM= 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1559320962753416.05040202212365; Fri, 31 May 2019 09:42:42 -0700 (PDT) Received: from localhost ([127.0.0.1]:46287 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWkbz-00058T-J7 for importer@patchew.org; Fri, 31 May 2019 12:42:35 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40256) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWkRu-0006mb-OJ for qemu-devel@nongnu.org; Fri, 31 May 2019 12:32:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hWkRs-0008DN-Kn for qemu-devel@nongnu.org; Fri, 31 May 2019 12:32:10 -0400 Received: from relay.sw.ru ([185.231.240.75]:57238) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hWkRs-0008Af-9n; Fri, 31 May 2019 12:32:08 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1hWkRn-0006Lb-Lo; Fri, 31 May 2019 19:32:03 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Fri, 31 May 2019 19:31:56 +0300 Message-Id: <20190531163202.162543-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190531163202.162543-1-vsementsov@virtuozzo.com> References: <20190531163202.162543-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 v2 3/9] iotests: add test 255 to check bitmap life after snapshot + commit X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 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" Two testcases with persistent bitmaps are not added here, as there are bugs to be fixed soon. Signed-off-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/255 | 84 ++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/255.out | 17 ++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 102 insertions(+) create mode 100755 tests/qemu-iotests/255 create mode 100644 tests/qemu-iotests/255.out diff --git a/tests/qemu-iotests/255 b/tests/qemu-iotests/255 new file mode 100755 index 0000000000..1b3c081a68 --- /dev/null +++ b/tests/qemu-iotests/255 @@ -0,0 +1,84 @@ +#!/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.event_wait_log(['BLOCK_JOB_READY', 'BLOCK_JOB_COMPLETED']) + 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) diff --git a/tests/qemu-iotests/255.out b/tests/qemu-iotests/255.out new file mode 100644 index 0000000000..5239d27c46 --- /dev/null +++ b/tests/qemu-iotests/255.out @@ -0,0 +1,17 @@ + +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 diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 859c4b5e9f..88049ad46c 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -265,3 +265,4 @@ 252 rw auto backing quick 253 rw auto quick 254 rw auto backing quick +255 rw auto quick --=20 2.18.0 From nobody Wed May 15 09:10:38 2024 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=1559320743; cv=none; d=zoho.com; s=zohoarc; b=hxE8bsyxjMT3TutHFPJfno65SbuHhQ9vw9N0yXaqn6DaV/dMBz0zqIfUuMKNghqixyzpQxBuzQzai8tUokZWhHicAwNl6BIEFDE5j14FLJtkMUyZCyllvT+ixE2y8vb+gHokwrql8RCaaiJPgjXKntM03om/ZC9o2jMzhvtcoCo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559320743; 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=dprFXzgeeZf6fXf7vpKUQtd9c/GPc22IYUkCR8G0lKw=; b=LXRvHqGK2ZQaRSsuplerLK5UeDzbUBqcHm0d1jbXtpiAVKP9Y9bCRyXqNM8zIxhRex54eRkgLEPZFIEhzFArnPeNo1QjYDpI8bkCSL7cNjRDi3PhLZaPMLh89BT+U2NsvoTuDXYw4yCVSiAK5LBzDMp00saGyLZPCYHiNPzYh28= 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1559320743021738.7017578289377; Fri, 31 May 2019 09:39:03 -0700 (PDT) Received: from localhost ([127.0.0.1]:46231 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWkYT-0002k3-41 for importer@patchew.org; Fri, 31 May 2019 12:38:57 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40240) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWkRu-0006mI-C5 for qemu-devel@nongnu.org; Fri, 31 May 2019 12:32:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hWkRs-0008D9-Jm for qemu-devel@nongnu.org; Fri, 31 May 2019 12:32:10 -0400 Received: from relay.sw.ru ([185.231.240.75]:57218) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hWkRs-0008Ac-7y; Fri, 31 May 2019 12:32:08 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1hWkRn-0006Lb-RT; Fri, 31 May 2019 19:32:04 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Fri, 31 May 2019 19:31:57 +0300 Message-Id: <20190531163202.162543-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190531163202.162543-1-vsementsov@virtuozzo.com> References: <20190531163202.162543-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 v2 4/9] block/qcow2-bitmap: get rid of bdrv_has_changed_persistent_bitmaps X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 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" 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 8044ace63e..816022972b 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -105,7 +105,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 49646a30e6..d4923ee614 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -775,18 +775,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 Wed May 15 09:10:38 2024 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=1559320887; cv=none; d=zoho.com; s=zohoarc; b=P5o6brJqwLfTHP1+05qUjOs3gkrRmYPnXr8dPI8R7Kc3XWJb2gyz1lxvi7Ey8v9VHvYXLT5rdiJUawDY2TRFsYePDXPL40FxrojK4wCYdrHJydoKMA0lOmJo2RJMJrASeaQdZn6Cdz09Tp85wWFHBfQBxT37rCn2xL6sEQIn97A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559320887; 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=25kUqzp8UkrX5+ooSbcMzMTdUxxSyd1SA1YgIUayeQU=; b=WASdeMQgvjd/N/IEDdqLWIu8B5usFLwno0rdGERrMEhs2BqthhZcbm+9sAwx0GDBWoKN3rfCdSXSmV1JeohfT2b3IKZVUOsUapwWj7bp3GGEVFoJgRpPtd4mlYnjmOmEjaEhPl8sPb2v3oLE2GU2rezCR8WBnOIYH6pp/8Q5Fh4= 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1559320887153884.6635612881369; Fri, 31 May 2019 09:41:27 -0700 (PDT) Received: from localhost ([127.0.0.1]:46275 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWkaF-0003zD-RM for importer@patchew.org; Fri, 31 May 2019 12:40:47 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40269) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWkRv-0006mt-2A for qemu-devel@nongnu.org; Fri, 31 May 2019 12:32:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hWkRs-0008Dm-O5 for qemu-devel@nongnu.org; Fri, 31 May 2019 12:32:11 -0400 Received: from relay.sw.ru ([185.231.240.75]:57214) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hWkRs-0008Aa-CQ; Fri, 31 May 2019 12:32:08 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1hWkRo-0006Lb-BU; Fri, 31 May 2019 19:32:04 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Fri, 31 May 2019 19:31:58 +0300 Message-Id: <20190531163202.162543-6-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190531163202.162543-1-vsementsov@virtuozzo.com> References: <20190531163202.162543-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 v2 5/9] block/qcow2-bitmap: drop qcow2_reopen_bitmaps_rw_hint() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 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" 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 567375e56c..88a2030f54 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -732,8 +732,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 Wed May 15 09:10:38 2024 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=1559320876; cv=none; d=zoho.com; s=zohoarc; b=GDxSGUlfuq9fzmaOFFy4+C0VUeYWI2IDXL96MwDst6BBgSXEevFwTWcXlWROgOLrVTSLO2qKgN8HljdOT1H2XRpydVlTtx5Uhuq0JJTAfeI7yjicCh+2JuBNtItDy63CnWDxCNSiGQ2zUjSArGjB39vcWRq0JgvDBclZRaZgVeo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559320876; 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=ftDtXS4rwc7AOTHIpmsvhgQf7eIwFMH6CxJIW2ditmw=; b=if2lK3qh+OsIvsbLRSo77Og5J6pwvTEvBVbgEktw4Q8HWH/a+KerrgYDKirpyJRXw7rgCbTiYeJwYMeLoq2mxyWOt32dL6y8U5tS0nM5rMxuCjyvkhmg2ba04cZkdrBhtMyKQcCSXJCXwYMpIPMyduIBbD4PDvgCplbJzbElYB4= 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1559320876292540.3267881608477; Fri, 31 May 2019 09:41:16 -0700 (PDT) Received: from localhost ([127.0.0.1]:46273 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWkaF-0003yF-EG for importer@patchew.org; Fri, 31 May 2019 12:40:47 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40236) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWkRu-0006mF-Aj for qemu-devel@nongnu.org; Fri, 31 May 2019 12:32:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hWkRs-0008DZ-Mu for qemu-devel@nongnu.org; Fri, 31 May 2019 12:32:10 -0400 Received: from relay.sw.ru ([185.231.240.75]:57220) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hWkRs-0008Ag-8D; Fri, 31 May 2019 12:32:08 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1hWkRo-0006Lb-HS; Fri, 31 May 2019 19:32:04 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Fri, 31 May 2019 19:31:59 +0300 Message-Id: <20190531163202.162543-7-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190531163202.162543-1-vsementsov@virtuozzo.com> References: <20190531163202.162543-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 v2 6/9] block/qcow2-bitmap: do not remove bitmaps on reopen-ro X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 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" 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 255 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 | 46 +++++++++++++++++++++++++++++--------------- block/qcow2.c | 2 +- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index 88a2030f54..4c8435141b 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -734,7 +734,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..25b1e069a7 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -1432,7 +1432,29 @@ 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's. + * + * @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. + */ +void qcow2_store_persistent_dirty_bitmaps(BlockDriverState *bs, + bool release_stored, Error **err= p) { BdrvDirtyBitmap *bitmap; BDRVQcow2State *s =3D bs->opaque; @@ -1545,20 +1567,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 +1602,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 f2cb131048..02d8ce7534 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2344,7 +2344,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 Wed May 15 09:10:38 2024 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=1559320743; cv=none; d=zoho.com; s=zohoarc; b=GRVyQDbXXI8TvlfIZCqD7PaUDIJvKOD9N/zhUx5nRcBGqReGbHP4z4li6Lb59yIpGrT1kzfZQxOTl3UBxkQwbV27HrcEoOJuf28ykMnO9stR1bDEf8CVKuNdig1Qs4H8rjHrr1NYt4bZHIFzFYGoUH8CouHAB1BN8GmsA9ioYl0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559320743; 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=4Y2Auj46qIuInk8Sl5XK9opXidSeCIqAb8Aj+EGvQHY=; b=m6Y5c4/ugcRwNTqgfO+GM0JLe+rZnbYbmXV4drXGuzJX6Xg/Zhk57pSRi34PDEyA6PJFUm92DuRe4AHkV4OpGU3wmYv6ZJsnGfh3YlXbwTTlFogCv4nOO3MPbEjEmffnzJbor9K3ZrpH8BxJy7dEzZKpjDkCW8Clvy3X7pytIiw= 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1559320743892312.76936947340573; Fri, 31 May 2019 09:39:03 -0700 (PDT) Received: from localhost ([127.0.0.1]:46233 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWkYT-0002km-Tu for importer@patchew.org; Fri, 31 May 2019 12:38:57 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40263) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWkRu-0006mn-Un for qemu-devel@nongnu.org; Fri, 31 May 2019 12:32:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hWkRs-0008Dr-Os for qemu-devel@nongnu.org; Fri, 31 May 2019 12:32:10 -0400 Received: from relay.sw.ru ([185.231.240.75]:57234) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hWkRs-0008Ai-Bs; Fri, 31 May 2019 12:32:08 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1hWkRo-0006Lb-Ot; Fri, 31 May 2019 19:32:04 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Fri, 31 May 2019 19:32:00 +0300 Message-Id: <20190531163202.162543-8-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190531163202.162543-1-vsementsov@virtuozzo.com> References: <20190531163202.162543-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 v2 7/9] block/qcow2-bitmap: fix and improve qcow2_reopen_bitmaps_rw X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 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 25b1e069a7..f48b5b4eaf 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 Wed May 15 09:10:38 2024 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=1559320629; cv=none; d=zoho.com; s=zohoarc; b=AJTBItXh74dbr7Zhb0T1H5SrjIxgFXzuqJoSEd90QSE/12kxMG54fZi/G4LFuzWW1XHMyC6khc7glFAi8l8vY5AcP88rjVgRUM6A+woG68ZntrcHNyfS2w67+wWqhZC17Mb8ygR02C6kovEWuXtvmiAMm3MFjtonL9nmLacYWM8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559320629; 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=IcS3Wabw4L+zBxmrj280CVhsVXXQ7hZ9N1qj+2UqDrg=; b=FAdcuE5Fwl4b1ArBlGv4zHjXSEJbz1dOnoIq8KQQSS9fZ+WkyVHaxRpvID/5OUKXxHc5SdR96cO7ibhQFRV3ISLGdyeO6JObAPCdQ8E83rUcKvHw2LDA4K2UWI1/stC+C8Z8PsnDi5zRvcn+oODR+LHZlUzxZ38RhUGPaTaciRM= 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1559320629481889.0104165842305; Fri, 31 May 2019 09:37:09 -0700 (PDT) Received: from localhost ([127.0.0.1]:46221 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWkWd-0001Vm-GG for importer@patchew.org; Fri, 31 May 2019 12:37:03 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40226) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWkRu-0006m7-5b for qemu-devel@nongnu.org; Fri, 31 May 2019 12:32:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hWkRs-0008Cq-Go for qemu-devel@nongnu.org; Fri, 31 May 2019 12:32:10 -0400 Received: from relay.sw.ru ([185.231.240.75]:57226) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hWkRs-0008Ah-7A; Fri, 31 May 2019 12:32:08 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1hWkRo-0006Lb-UY; Fri, 31 May 2019 19:32:05 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Fri, 31 May 2019 19:32:01 +0300 Message-Id: <20190531163202.162543-9-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190531163202.162543-1-vsementsov@virtuozzo.com> References: <20190531163202.162543-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 v2 8/9] block/qcow2-bitmap: fix reopening bitmaps to RW X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 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" Currently reopening bitmaps to RW can't work, as qcow2 needs write access to file child, to mark bitmaps in-image with IN_USE flag. The possibility to write-access file child during reopen-RW was implemented several patches ago with help of .bdrv_need_rw_file_child_during_reopen_rw handler. Let's use this new API to fix bitmaps reopening. Add corresponding test-cases to 255 iotest. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.h | 1 + block/qcow2-bitmap.c | 6 ++++++ block/qcow2.c | 1 + tests/qemu-iotests/255 | 2 ++ tests/qemu-iotests/255.out | 35 +++++++++++++++++++++++++++++++++++ 5 files changed, 45 insertions(+) diff --git a/block/qcow2.h b/block/qcow2.h index 4c8435141b..d6398bd030 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -726,6 +726,7 @@ void *qcow2_cache_is_table_offset(Qcow2Cache *c, uint64= _t offset); void qcow2_cache_discard(Qcow2Cache *c, void *table); =20 /* qcow2-bitmap.c functions */ +bool qcow2_has_bitmaps(BlockDriverState *bs); int qcow2_check_bitmaps_refcounts(BlockDriverState *bs, BdrvCheckResult *r= es, void **refcount_table, int64_t *refcount_table_size); diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index f48b5b4eaf..803818b29a 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -1102,6 +1102,12 @@ Qcow2BitmapInfoList *qcow2_get_bitmap_info_list(Bloc= kDriverState *bs, return list; } =20 +bool qcow2_has_bitmaps(BlockDriverState *bs) +{ + BDRVQcow2State *s =3D bs->opaque; + return s->nb_bitmaps; +} + int qcow2_reopen_bitmaps_rw(BlockDriverState *bs, Error **errp) { BDRVQcow2State *s =3D bs->opaque; diff --git a/block/qcow2.c b/block/qcow2.c index 02d8ce7534..ffc067a8ac 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -5218,6 +5218,7 @@ BlockDriver bdrv_qcow2 =3D { .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, + .bdrv_need_rw_file_child_during_reopen_rw =3D qcow2_has_bitmaps, }; =20 static void bdrv_qcow2_init(void) diff --git a/tests/qemu-iotests/255 b/tests/qemu-iotests/255 index 1b3c081a68..5e8d01686f 100755 --- a/tests/qemu-iotests/255 +++ b/tests/qemu-iotests/255 @@ -82,3 +82,5 @@ def test(persistent, restart): =20 =20 test(persistent=3DFalse, restart=3DFalse) +test(persistent=3DTrue, restart=3DFalse) +test(persistent=3DTrue, restart=3DTrue) diff --git a/tests/qemu-iotests/255.out b/tests/qemu-iotests/255.out index 5239d27c46..2f0d98d036 100644 --- a/tests/qemu-iotests/255.out +++ b/tests/qemu-iotests/255.out @@ -15,3 +15,38 @@ check that no bitmaps are in snapshot: not found {"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 --=20 2.18.0 From nobody Wed May 15 09:10:38 2024 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=1559320512; cv=none; d=zoho.com; s=zohoarc; b=niTGvmdYKV6XkxXI8KCEelJr3KcFKhsuzGbaGMhsNN6Txh4rbpEqSiqJA3fZ5jMaF6ZLxIpJLJiHE3OC87XcoO4RlchIxZDCPCl9jaPK+ZBILw6H9x2/K7GsRVKOZNSkvP+jF7ajutunSbkqDDlD3pmtEaSLaIxepu/TJNEAq2w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559320512; 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=fIuxOpjesoIJdcvmSZEkt6Wmva9R/JAtomhKTfhwEks=; b=S8Ur12cN/l4yB9fyAbYMKX8ZyxTnF4wegZcCYwzqLU2Fez3ZaOKNQYqw1s3LO08s7uG/CMeHWkN4qXNpVCktT2nKUSsspxv3JcFltgVKyN7LVU8DWzEU9DTKC5aaAhWwenIvFXmEr+YEG/meAa8dWKM+nCdnIjxzjJ1HqTccusc= 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1559320512594837.6648344378758; Fri, 31 May 2019 09:35:12 -0700 (PDT) Received: from localhost ([127.0.0.1]:46163 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWkU9-00081l-Ki for importer@patchew.org; Fri, 31 May 2019 12:34:29 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40231) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWkRu-0006mB-7U for qemu-devel@nongnu.org; Fri, 31 May 2019 12:32:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hWkRs-0008DV-NK for qemu-devel@nongnu.org; Fri, 31 May 2019 12:32:10 -0400 Received: from relay.sw.ru ([185.231.240.75]:57244) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hWkRs-0008Aj-8x; Fri, 31 May 2019 12:32:08 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1hWkRp-0006Lb-2U; Fri, 31 May 2019 19:32:05 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Fri, 31 May 2019 19:32:02 +0300 Message-Id: <20190531163202.162543-10-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190531163202.162543-1-vsementsov@virtuozzo.com> References: <20190531163202.162543-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 v2 9/9] qcow2-bitmap: move bitmap reopen-rw code to qcow2_reopen_prepare X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 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" Since we have used .bdrv_need_rw_file_child_during_reopen_rw handler, and have write access to file child in reopen-prepare, and we prepared qcow2_reopen_bitmaps_rw to be called from reopening rw -> rw, we now can simple move qcow2_reopen_bitmaps_rw() call to qcow2_reopen_prepare() and handle errors as befits. Hacky handler .bdrv_reopen_bitmaps_rw is not needed more and therefore dropped. Signed-off-by: Vladimir Sementsov-Ogievskiy --- include/block/block_int.h | 6 ------ block.c | 19 ------------------- block/qcow2.c | 6 +++++- 3 files changed, 5 insertions(+), 26 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index 7b22fb5d9c..a35b3e0d96 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -533,12 +533,6 @@ struct BlockDriver { =20 bool (*bdrv_need_rw_file_child_during_reopen_rw)(BlockDriverState *bs= ); =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 56e1388908..b5527ae713 100644 --- a/block.c +++ b/block.c @@ -3894,16 +3894,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); @@ -3947,21 +3943,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 ffc067a8ac..945fae74b5 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1815,6 +1815,11 @@ static int qcow2_reopen_prepare(BDRVReopenState *sta= te, if (ret < 0) { goto fail; } + } else { + ret =3D qcow2_reopen_bitmaps_rw(state->bs, errp); + if (ret < 0) { + goto fail; + } } =20 return 0; @@ -5215,7 +5220,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, .bdrv_need_rw_file_child_during_reopen_rw =3D qcow2_has_bitmaps, --=20 2.18.0