From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39397) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fVgjn-0006EM-QV for qemu-devel@nongnu.org; Wed, 20 Jun 2018 13:17:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fVgjm-0004np-Of for qemu-devel@nongnu.org; Wed, 20 Jun 2018 13:17:43 -0400 References: <20180612172614.60107-1-vsementsov@virtuozzo.com> From: Vladimir Sementsov-Ogievskiy Message-ID: <32ef84ab-f979-8857-9bdc-c32d47e79aeb@virtuozzo.com> Date: Wed, 20 Jun 2018 20:17:29 +0300 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Subject: Re: [Qemu-devel] [Qemu-block] [PATCH] block/qcow2: fix logic around dirty_bitmaps_loaded List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: John Snow , qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: kwolf@redhat.com, den@openvz.org, mreitz@redhat.com 13.06.2018 01:18, John Snow wrote: > > On 06/12/2018 06:11 PM, John Snow wrote: >> >> On 06/12/2018 01:26 PM, Vladimir Sementsov-Ogievskiy wrote: >>> First: this variable was introduced to handle reopens. We need it on >>> following qcow2_do_open, to don't try loading bitmaps again. So, we are >>> fixing qcow2_invalidate_cache(). >>> >>> However, if we fix only qcow2_invalidate_cache, iotest 169 fails on >>> case test__persistent__not_migbitmap__online_shared, because on first >>> target open, source is not yet closed, and is not yet stored bitmaps, >>> so, we are load nothing. And on second open, dirty_bitmaps_loaded is >>> already true, but we have no bitmaps to reopen with >>> qcow2_reopen_bitmaps_rw_hint(). So, we are fixing qcow2_do_open() too. >>> >>> Signed-off-by: Vladimir Sementsov-Ogievskiy >>> --- >>> block/qcow2.c | 4 +++- >>> 1 file changed, 3 insertions(+), 1 deletion(-) >>> >>> diff --git a/block/qcow2.c b/block/qcow2.c >>> index 6fa5e1d71a..b4216a5830 100644 >>> --- a/block/qcow2.c >>> +++ b/block/qcow2.c >>> @@ -1499,7 +1499,7 @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options, >>> { >>> qcow2_reopen_bitmaps_rw_hint(bs, &header_updated, &local_err); >>> } >>> - } else { >>> + } else if (s->nb_bitmaps > 0) { >>> header_updated = qcow2_load_dirty_bitmaps(bs, &local_err); >>> s->dirty_bitmaps_loaded = true; >>> } >>> @@ -2178,6 +2178,7 @@ static void coroutine_fn qcow2_co_invalidate_cache(BlockDriverState *bs, >>> QDict *options; >>> Error *local_err = NULL; >>> int ret; >>> + bool dirty_bitmaps_loaded = s->dirty_bitmaps_loaded; >>> >>> /* >>> * Backing files are read-only which makes all of their metadata immutable, >>> @@ -2190,6 +2191,7 @@ static void coroutine_fn qcow2_co_invalidate_cache(BlockDriverState *bs, >>> qcow2_close(bs); >>> >>> memset(s, 0, sizeof(BDRVQcow2State)); >>> + s->dirty_bitmaps_loaded = dirty_bitmaps_loaded; >>> options = qdict_clone_shallow(bs->options); >>> >>> flags &= ~BDRV_O_INACTIVE; >>> >> Ah, tch... I didn't realize that invalidate completely wipes the qcow2 >> metadata. >> >> I guess the other three fields, nb_bitmaps, bitmap_directory_size and >> bitmap_directory_offset get initialized again on re-open. >> >> (I suppose this means I need to rethink caching bm_list more carefully, >> too...) >> >> I think this looks correct mechanically. >> > Oh, I meant: > > Reviewed-by: John Snow It is interesting, this patch also fixes iotest 169. It's not broken formally, but if we look at vm output of vm_b after migration, we'll see qemu-system-x86_64: Could not reopen qcow2 layer: Bitmap already exists: bitmap0 which leads to failed invalidation and bs->drv = NULL :) I'll improve iotest somehow, to show this failure. -- Best regards, Vladimir