From patchwork Tue Mar 15 20:04:21 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: 8592201 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 347609F44D for ; Tue, 15 Mar 2016 20:10:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A73B32026C for ; Tue, 15 Mar 2016 20:09:55 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DF8B620263 for ; Tue, 15 Mar 2016 20:09:54 +0000 (UTC) Received: from localhost ([::1]:51198 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1afvHu-0008Ig-5X for patchwork-qemu-devel@patchwork.kernel.org; Tue, 15 Mar 2016 16:09:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38902) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1afvDo-0008L7-5d for qemu-devel@nongnu.org; Tue, 15 Mar 2016 16:05:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1afvDm-0008KN-Hs for qemu-devel@nongnu.org; Tue, 15 Mar 2016 16:05:40 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:46315 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1afvDm-0008Js-6m for qemu-devel@nongnu.org; Tue, 15 Mar 2016 16:05:38 -0400 Received: from kvm.sw.ru. ([10.28.8.145]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id u2FK4bCp005992; Tue, 15 Mar 2016 23:05:18 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Tue, 15 Mar 2016 23:04:21 +0300 Message-Id: <1458072268-53705-16-git-send-email-vsementsov@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1458072268-53705-1-git-send-email-vsementsov@virtuozzo.com> References: <1458072268-53705-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 Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, famz@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, den@openvz.org, jsnow@redhat.com Subject: [Qemu-devel] [PATCH 15/22] qcow2-dirty-bitmap: add autoclear bit X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add autoclear bit for handling rewriting image by old qemu version. If autoclear bit is not set, but bitmaps extension is found it would not be loaded and warning will be generated. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/qcow2-dirty-bitmap.c | 4 ++++ block/qcow2.c | 12 ++++++++++-- block/qcow2.h | 9 +++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/block/qcow2-dirty-bitmap.c b/block/qcow2-dirty-bitmap.c index 24415df..384ccea 100644 --- a/block/qcow2-dirty-bitmap.c +++ b/block/qcow2-dirty-bitmap.c @@ -419,6 +419,7 @@ static int directory_push_entry(BlockDriverState *bs, QCow2BitmapHeader *header) int64_t new_offset = 0, old_offset = 0; uint64_t new_size = s->bitmap_directory_size + entry_size, old_size = 0; void *p; + uint64_t old_autocl; int64_t nb_sectors = bdrv_nb_sectors(bs); if (nb_sectors < 0) { @@ -437,6 +438,7 @@ static int directory_push_entry(BlockDriverState *bs, QCow2BitmapHeader *header) old_offset = s->bitmap_directory_offset; old_size = s->bitmap_directory_size; + old_autocl = s->autoclear_features; uint8_t *new_dir = g_try_malloc(new_size); if (new_dir == NULL) { @@ -458,6 +460,7 @@ static int directory_push_entry(BlockDriverState *bs, QCow2BitmapHeader *header) s->bitmap_directory_offset = new_offset; s->bitmap_directory_size = new_size; + s->autoclear_features |= QCOW2_AUTOCLEAR_DIRTY_BITMAPS; ret = update_header_sync(bs); if (ret < 0) { @@ -479,6 +482,7 @@ fail: qcow2_free_clusters(bs, new_offset, new_size, QCOW2_DISCARD_ALWAYS); s->bitmap_directory_offset = old_offset; s->bitmap_directory_size = old_size; + s->autoclear_features = old_autocl; } p = g_try_realloc(s->bitmap_directory, s->bitmap_directory_size); diff --git a/block/qcow2.c b/block/qcow2.c index 7a342c2..f269bab 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -164,6 +164,13 @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset, break; case QCOW2_EXT_MAGIC_DIRTY_BITMAPS: + if (!(s->autoclear_features & QCOW2_AUTOCLEAR_DIRTY_BITMAPS)) { + fprintf(stderr, + "WARNING: bitmaps_ext: autoclear flag is not " + "set, all bitmaps will be considered as inconsistent"); + break; + } + ret = bdrv_pread(bs->file->bs, offset, &bitmaps_ext, ext.len); if (ret < 0) { error_setg_errno(errp, -ret, "ERROR: bitmaps_ext: " @@ -1205,8 +1212,9 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags, } /* Clear unknown autoclear feature bits */ - if (!bs->read_only && !(flags & BDRV_O_INACTIVE) && s->autoclear_features) { - s->autoclear_features = 0; + if (!bs->read_only && !(flags & BDRV_O_INACTIVE) && + (s->autoclear_features & ~QCOW2_AUTOCLEAR_MASK)) { + s->autoclear_features &= QCOW2_AUTOCLEAR_MASK; ret = qcow2_update_header(bs); if (ret < 0) { error_setg_errno(errp, -ret, "Could not update qcow2 header"); diff --git a/block/qcow2.h b/block/qcow2.h index 423c279..63ea543 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -220,6 +220,15 @@ enum { QCOW2_COMPAT_FEAT_MASK = QCOW2_COMPAT_LAZY_REFCOUNTS, }; +/* Autoclear feature bits */ +enum { + QCOW2_AUTOCLEAR_DIRTY_BITMAPS_BITNR = 0, + QCOW2_AUTOCLEAR_DIRTY_BITMAPS = + 1 << QCOW2_AUTOCLEAR_DIRTY_BITMAPS_BITNR, + + QCOW2_AUTOCLEAR_MASK = QCOW2_AUTOCLEAR_DIRTY_BITMAPS, +}; + enum qcow2_discard_type { QCOW2_DISCARD_NEVER = 0, QCOW2_DISCARD_ALWAYS,