From patchwork Thu Jun 20 14:26:23 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Beno=C3=AEt_Canet?= X-Patchwork-Id: 252954 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A5D032C009D for ; Fri, 21 Jun 2013 00:33:02 +1000 (EST) Received: from localhost ([::1]:33722 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Upfv2-0000bX-DQ for incoming@patchwork.ozlabs.org; Thu, 20 Jun 2013 10:33:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60464) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Upfr8-0003me-KU for qemu-devel@nongnu.org; Thu, 20 Jun 2013 10:29:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Upfr1-0001Sj-DJ for qemu-devel@nongnu.org; Thu, 20 Jun 2013 10:28:58 -0400 Received: from nodalink.pck.nerim.net ([62.212.105.220]:37608 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Upfr0-0001SV-NC for qemu-devel@nongnu.org; Thu, 20 Jun 2013 10:28:51 -0400 Received: by paradis.irqsave.net (Postfix, from userid 1002) id 1BC67874673; Thu, 20 Jun 2013 16:28:50 +0200 (CEST) Received: from localhost.localdomain (unknown [192.168.77.1]) by paradis.irqsave.net (Postfix) with ESMTP id 6F4F087467A; Thu, 20 Jun 2013 16:25:01 +0200 (CEST) From: =?UTF-8?q?Beno=C3=AEt=20Canet?= To: qemu-devel@nongnu.org Date: Thu, 20 Jun 2013 16:26:23 +0200 Message-Id: <1371738392-9594-16-git-send-email-benoit@irqsave.net> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1371738392-9594-1-git-send-email-benoit@irqsave.net> References: <1371738392-9594-1-git-send-email-benoit@irqsave.net> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 62.212.105.220 Cc: kwolf@redhat.com, =?UTF-8?q?Beno=C3=AEt=20Canet?= , stefanha@redhat.com Subject: [Qemu-devel] [RFC V8 15/24] qcow2: Extract qcow2_set_incompat_feature and qcow2_clear_incompat_feature. 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Also change callers. Signed-off-by: Benoit Canet --- block/qcow2-cluster.c | 2 +- block/qcow2.c | 43 ++++++++++++++++++++++--------------------- block/qcow2.h | 7 ++++--- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 41c4bc2..7cd6e75 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -672,7 +672,7 @@ int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m) /* Update L2 table. */ if (s->use_lazy_refcounts) { - qcow2_mark_dirty(bs); + qcow2_set_incompat_feature(bs, QCOW2_INCOMPAT_DIRTY); } if (qcow2_need_accurate_refcounts(s)) { qcow2_cache_set_dependency(bs, s->l2_table_cache, diff --git a/block/qcow2.c b/block/qcow2.c index 3cd1051..58e6236 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -250,56 +250,57 @@ static void report_unsupported_feature(BlockDriverState *bs, } /* - * Sets the dirty bit and flushes afterwards if necessary. + * Sets the an incompatible feature bit and flushes afterwards if necessary. * * The incompatible_features bit is only set if the image file header was * updated successfully. Therefore it is not required to check the return * value of this function. */ -int qcow2_mark_dirty(BlockDriverState *bs) +int qcow2_set_incompat_feature(BlockDriverState *bs, + QCow2IncompatibleFeature feature) { BDRVQcowState *s = bs->opaque; uint64_t val; - int ret; + int ret = 0; assert(s->qcow_version >= 3); - if (s->incompatible_features & QCOW2_INCOMPAT_DIRTY) { - return 0; /* already dirty */ + if (s->incompatible_features & feature) { + return 0; /* already added */ } - val = cpu_to_be64(s->incompatible_features | QCOW2_INCOMPAT_DIRTY); + val = cpu_to_be64(s->incompatible_features | feature); ret = bdrv_pwrite(bs->file, offsetof(QCowHeader, incompatible_features), &val, sizeof(val)); if (ret < 0) { return ret; } - ret = bdrv_flush(bs->file); - if (ret < 0) { - return ret; - } - /* Only treat image as dirty if the header was updated successfully */ - s->incompatible_features |= QCOW2_INCOMPAT_DIRTY; + /* Only treat image as having the feature if the header was updated + * successfully + */ + s->incompatible_features |= feature; return 0; } /* - * Clears the dirty bit and flushes before if necessary. Only call this - * function when there are no pending requests, it does not guard against - * concurrent requests dirtying the image. + * Clears an incompatible feature bit and flushes before if necessary. + * Only call this function when there are no pending requests, it does not + * guard against concurrent requests adding a feature to the image. */ -static int qcow2_mark_clean(BlockDriverState *bs) +static int qcow2_clear_incompat_feature(BlockDriverState *bs, + QCow2IncompatibleFeature feature) { BDRVQcowState *s = bs->opaque; + int ret = 0; - if (s->incompatible_features & QCOW2_INCOMPAT_DIRTY) { - int ret = bdrv_flush(bs); + if (s->incompatible_features & feature) { + ret = bdrv_flush(bs); if (ret < 0) { return ret; } - s->incompatible_features &= ~QCOW2_INCOMPAT_DIRTY; + s->incompatible_features &= ~feature; return qcow2_update_header(bs); } return 0; @@ -314,7 +315,7 @@ static int qcow2_check(BlockDriverState *bs, BdrvCheckResult *result, } if (fix && result->check_errors == 0 && result->corruptions == 0) { - return qcow2_mark_clean(bs); + return qcow2_clear_incompat_feature(bs, QCOW2_INCOMPAT_DIRTY); } return ret; } @@ -949,7 +950,7 @@ static void qcow2_close(BlockDriverState *bs) qcow2_cache_flush(bs, s->l2_table_cache); qcow2_cache_flush(bs, s->refcount_block_cache); - qcow2_mark_clean(bs); + qcow2_clear_incompat_feature(bs, QCOW2_INCOMPAT_DIRTY); qcow2_cache_destroy(bs, s->l2_table_cache); qcow2_cache_destroy(bs, s->refcount_block_cache); diff --git a/block/qcow2.h b/block/qcow2.h index ff26e81..720131d 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -290,14 +290,14 @@ enum { }; /* Incompatible feature bits */ -enum { +typedef enum { QCOW2_INCOMPAT_DIRTY_BITNR = 0, QCOW2_INCOMPAT_DIRTY = 1 << QCOW2_INCOMPAT_DIRTY_BITNR, QCOW2_INCOMPAT_DEDUP_BITNR = 1, QCOW2_INCOMPAT_DEDUP = 1 << QCOW2_INCOMPAT_DEDUP_BITNR, QCOW2_INCOMPAT_MASK = QCOW2_INCOMPAT_DIRTY | QCOW2_INCOMPAT_DEDUP, -}; +} QCow2IncompatibleFeature; /* Compatible feature bits */ enum { @@ -543,7 +543,8 @@ static inline uint64_t l2meta_cow_end(QCowL2Meta *m) int qcow2_backing_read1(BlockDriverState *bs, QEMUIOVector *qiov, int64_t sector_num, int nb_sectors); -int qcow2_mark_dirty(BlockDriverState *bs); +int qcow2_set_incompat_feature(BlockDriverState *bs, + QCow2IncompatibleFeature feature); int qcow2_update_header(BlockDriverState *bs); int qcow2_read_cluster_data(BlockDriverState *bs, uint8_t *data,