From patchwork Fri Sep 30 10:53:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 676981 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3slprC1k9qz9s4n for ; Fri, 30 Sep 2016 21:19:55 +1000 (AEST) Received: from localhost ([::1]:43295 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpvr5-0002Ri-RQ for incoming@patchwork.ozlabs.org; Fri, 30 Sep 2016 07:19:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53580) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpvRm-0003ZA-8N for qemu-devel@nongnu.org; Fri, 30 Sep 2016 06:53:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bpvRi-00008i-51 for qemu-devel@nongnu.org; Fri, 30 Sep 2016 06:53:41 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:40948 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpvRh-00004r-Oq for qemu-devel@nongnu.org; Fri, 30 Sep 2016 06:53:38 -0400 Received: from kvm.qa.sw.ru. ([10.28.8.145]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id u8UArVlf029823; Fri, 30 Sep 2016 13:53:32 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Fri, 30 Sep 2016 13:53:18 +0300 Message-Id: <1475232808-4852-13-git-send-email-vsementsov@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1475232808-4852-1-git-send-email-vsementsov@virtuozzo.com> References: <1475232808-4852-1-git-send-email-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH 12/22] qcow2-bitmap: add IN_USE flag 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: kwolf@redhat.com, vsementsov@virtuozzo.com, famz@redhat.com, armbru@redhat.com, mreitz@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, den@openvz.org, jsnow@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This flag means that the bitmap is now in use by the software or was not successfully saved. In any way, with this flag set the bitmap data must be considered inconsistent and should not be loaded. With current implementation this flag is never set, as we just remove bitmaps from the image after loading. But it defined in qcow2 spec and must be handled. Also, it can be used in future, if async schemes of bitmap loading/saving are implemented. We also remove in-use bitmaps from the image on open. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/qcow2-bitmap.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index a5be25a..8cf40f0 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -28,6 +28,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" #include "qemu/cutils.h" +#include "exec/log.h" #include "block/block_int.h" #include "block/qcow2.h" @@ -44,7 +45,8 @@ #define BME_MAX_NAME_SIZE 1023 /* Bitmap directory entry flags */ -#define BME_RESERVED_FLAGS 0xfffffffd +#define BME_RESERVED_FLAGS 0xfffffffc +#define BME_FLAG_IN_USE 1 #define BME_FLAG_AUTO (1U << 1) /* bits [1, 8] U [56, 63] are reserved */ @@ -287,6 +289,11 @@ static BdrvDirtyBitmap *load_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap = NULL; char *name = g_strndup(dir_entry_name_notcstr(entry), entry->name_size); + if (entry->flags & BME_FLAG_IN_USE) { + error_setg(errp, "Bitmap '%s' is in use", name); + goto fail; + } + ret = bitmap_table_load(bs, entry, &bitmap_table); if (ret < 0) { error_setg_errno(errp, -ret, @@ -533,6 +540,14 @@ int qcow2_read_bitmaps(BlockDriverState *bs, Error **errp) for_each_bitmap_dir_entry(e, dir, dir_size) { uint32_t fl = e->flags; + if (fl & BME_FLAG_IN_USE) { + qemu_log("qcow2 warning: " + "removing in_use bitmap '%.*s' for image %s.\n", + e->name_size, (char *)(e + 1), bdrv_get_device_or_node_name(bs)); + + continue; + } + if (fl & BME_FLAG_AUTO) { BdrvDirtyBitmap *bitmap = load_bitmap(bs, e, errp); if (bitmap == NULL) {