All of lore.kernel.org
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
	qemu-block@nongnu.org, qemu-devel@nongnu.org
Cc: kwolf@redhat.com, armbru@redhat.com, eblake@redhat.com,
	jsnow@redhat.com, famz@redhat.com, den@openvz.org,
	stefanha@redhat.com, pbonzini@redhat.com
Subject: Re: [Qemu-devel] [PATCH 20/22] qcow2-dirty-bitmap: refcounts
Date: Mon, 10 Oct 2016 19:59:33 +0200	[thread overview]
Message-ID: <45d25503-97e1-8629-8731-3ae64c4bf12c@redhat.com> (raw)
In-Reply-To: <1475232808-4852-21-git-send-email-vsementsov@virtuozzo.com>

[-- Attachment #1: Type: text/plain, Size: 6619 bytes --]

On 30.09.2016 12:53, Vladimir Sementsov-Ogievskiy wrote:
> Calculate refcounts for dirty bitmaps.

The commit message should mention that this is for qcow2's qemu-img
check implementation.

> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
>  block/qcow2-bitmap.c   | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  block/qcow2-refcount.c | 14 +++++++-----
>  block/qcow2.h          |  5 +++++
>  3 files changed, 74 insertions(+), 5 deletions(-)
> 
> diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c
> index 76f7e2b..6d9394a 100644
> --- a/block/qcow2-bitmap.c
> +++ b/block/qcow2-bitmap.c
> @@ -901,3 +901,63 @@ out:
>      g_free(new_dir);
>      g_free(dir);
>  }
> +
> +int qcow2_dirty_bitmaps_refcounts(BlockDriverState *bs,
> +                                  BdrvCheckResult *res,
> +                                  void **refcount_table,
> +                                  int64_t *refcount_table_size)

I'd rename this function to make clear that this is for checking the
refcounts, e.g. to "qcow2_check_dirty_bitmaps_refcounts" or
"qcow2_count_dirty_bitmaps_refcounts" or just
"qcow2_check_dirty_bitmaps". Probably the last one is the best because
this function should ideally perform a full check of the dirty bitmaps
extension.

> +{
> +    BDRVQcow2State *s = bs->opaque;
> +    uint8_t *dir;
> +    Qcow2BitmapDirEntry *e;
> +    Error *local_err = NULL;
> +
> +    int i;
> +    int ret = inc_refcounts(bs, res, refcount_table, refcount_table_size,
> +                            s->bitmap_directory_offset,
> +                            s->bitmap_directory_size);
> +    if (ret < 0) {
> +        return ret;
> +    }
> +
> +    dir = directory_read(bs, s->bitmap_directory_offset,
> +                         s->bitmap_directory_size, &local_err);
> +    if (dir == NULL) {
> +        error_report_err(local_err);

I think you should increment res->corruptions here.

> +        return -EINVAL;
> +    }
> +
> +    for_each_bitmap_dir_entry(e, dir, s->bitmap_directory_size) {
> +        uint64_t *bitmap_table = NULL;

I think you should call check_constraints() here.

> +
> +        ret = inc_refcounts(bs, res, refcount_table, refcount_table_size,
> +                            e->bitmap_table_offset,
> +                            e->bitmap_table_size);

Probably rather e->bitmap_table_size * sizeof(uint64_t).

> +        if (ret < 0) {
> +            return ret;
> +        }
> +
> +        ret = bitmap_table_load(bs, e, &bitmap_table);
> +        if (ret < 0) {

Again, it would make sense to increment res->corruptions here.

> +            return ret;
> +        }
> +
> +        for (i = 0; i < e->bitmap_table_size; ++i) {
> +            uint64_t off = be64_to_cpu(bitmap_table[i]);
> +            if (off <= 1) {
> +                continue;
> +            }

As I said in some other patch, I'd write this condition differently
(with an offset mask, etc.).

Also, you should check that the offset is aligned to a cluster boundary
and that no unknown flags are set.

> +
> +            ret = inc_refcounts(bs, res, refcount_table, refcount_table_size,
> +                                off, s->cluster_size);
> +            if (ret < 0) {
> +                g_free(bitmap_table);
> +                return ret;
> +            }
> +        }
> +
> +        g_free(bitmap_table);
> +    }
> +
> +    return 0;

dir is leaked here.

> +}
> diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
> index cbfb3fe..05bcc57 100644
> --- a/block/qcow2-refcount.c
> +++ b/block/qcow2-refcount.c
> @@ -1309,11 +1309,9 @@ static int realloc_refcount_array(BDRVQcow2State *s, void **array,
>   *
>   * Modifies the number of errors in res.
>   */
> -static int inc_refcounts(BlockDriverState *bs,
> -                         BdrvCheckResult *res,
> -                         void **refcount_table,
> -                         int64_t *refcount_table_size,
> -                         int64_t offset, int64_t size)
> +int inc_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
> +                  void **refcount_table, int64_t *refcount_table_size,
> +                  int64_t offset, int64_t size)

First, if you make this function public, you have to give it a qcow2_
prefix.

Second, if this function is public, it should have a name that makes
sense. inc_refcounts() sounds as if it's the same as update_refcount()
with an addend of 1. I'd rename it qcow2_inc_refcounts_imrt(), because
that's probably the shortest name I can come up with (and
qcow2-refcount.c explains what an IMRT is in some comment).

>  {
>      BDRVQcow2State *s = bs->opaque;
>      uint64_t start, last, cluster_offset, k, refcount;
> @@ -1843,6 +1841,12 @@ static int calculate_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
>          return ret;
>      }
>  
> +    /* dirty bitmaps */
> +    ret = qcow2_dirty_bitmaps_refcounts(bs, res, refcount_table, nb_clusters);
> +    if (ret < 0) {
> +        return ret;
> +    }
> +
>      return check_refblocks(bs, res, fix, rebuild, refcount_table, nb_clusters);
>  }
>  
> diff --git a/block/qcow2.h b/block/qcow2.h
> index a5e7592..0a050ea 100644
> --- a/block/qcow2.h
> +++ b/block/qcow2.h
> @@ -563,6 +563,9 @@ int qcow2_check_metadata_overlap(BlockDriverState *bs, int ign, int64_t offset,
>                                   int64_t size);
>  int qcow2_pre_write_overlap_check(BlockDriverState *bs, int ign, int64_t offset,
>                                    int64_t size);
> +int inc_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
> +                  void **refcount_table, int64_t *refcount_table_size,
> +                  int64_t offset, int64_t size);
>  
>  int qcow2_change_refcount_order(BlockDriverState *bs, int refcount_order,
>                                  BlockDriverAmendStatusCB *status_cb,
> @@ -616,6 +619,8 @@ int qcow2_read_snapshots(BlockDriverState *bs);
>  int qcow2_read_bitmaps(BlockDriverState *bs, Error **errp);
>  
>  int qcow2_delete_bitmaps(BlockDriverState *bs);
> +int qcow2_dirty_bitmaps_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
> +    void **refcount_table, int64_t *refcount_table_size);

Normally we try to align parameters along the opening parenthesis as
long as there is enough space, and there is enough space here.

Max

>  
>  /* qcow2-cache.c functions */
>  Qcow2Cache *qcow2_cache_create(BlockDriverState *bs, int num_tables);
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 480 bytes --]

  reply	other threads:[~2016-10-10 17:59 UTC|newest]

Thread overview: 100+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-30 10:53 [Qemu-devel] [PATCH v7 00/22] qcow2: persistent dirty bitmaps Vladimir Sementsov-Ogievskiy
2016-09-30 10:53 ` [Qemu-devel] [PATCH 01/22] hbitmap: improve dirty iter Vladimir Sementsov-Ogievskiy
2016-10-01 13:52   ` Max Reitz
2016-09-30 10:53 ` [Qemu-devel] [PATCH 02/22] tests: add hbitmap iter test Vladimir Sementsov-Ogievskiy
2016-10-01 14:02   ` Max Reitz
2016-09-30 10:53 ` [Qemu-devel] [PATCH 03/22] block: fix bdrv_dirty_bitmap_granularity signature Vladimir Sementsov-Ogievskiy
2016-09-30 10:53 ` [Qemu-devel] [PATCH 04/22] block/dirty-bitmap: add deserialize_ones func Vladimir Sementsov-Ogievskiy
2016-09-30 10:53 ` [Qemu-devel] [PATCH 05/22] qcow2-bitmap: structs and consts Vladimir Sementsov-Ogievskiy
2016-10-01 14:34   ` Max Reitz
2016-10-01 14:56     ` Max Reitz
2016-10-07 13:11     ` Vladimir Sementsov-Ogievskiy
2016-10-11 11:50     ` Vladimir Sementsov-Ogievskiy
2016-10-12 18:20       ` Max Reitz
2016-09-30 10:53 ` [Qemu-devel] [PATCH 06/22] qcow2: add dirty bitmaps extension Vladimir Sementsov-Ogievskiy
2016-10-01 14:46   ` Max Reitz
2016-10-11 12:09     ` Vladimir Sementsov-Ogievskiy
2016-10-12 18:21       ` Max Reitz
2016-10-13 12:18         ` Vladimir Sementsov-Ogievskiy
2016-09-30 10:53 ` [Qemu-devel] [PATCH 07/22] qcow2-bitmap: introduce auto-loading bitmaps Vladimir Sementsov-Ogievskiy
2016-10-01 16:26   ` Max Reitz
2016-10-14 18:44     ` Vladimir Sementsov-Ogievskiy
2016-10-15 17:03       ` Max Reitz
2016-10-15 17:22         ` Vladimir Sementsov-Ogievskiy
2016-10-20 12:22     ` Vladimir Sementsov-Ogievskiy
2016-10-21 19:49       ` Max Reitz
2016-10-07 19:25   ` Max Reitz
2016-10-21 11:59     ` Vladimir Sementsov-Ogievskiy
2016-10-21 19:56       ` Max Reitz
2016-09-30 10:53 ` [Qemu-devel] [PATCH 08/22] block/dirty-bitmap: add autoload field to BdrvDirtyBitmap Vladimir Sementsov-Ogievskiy
2016-10-07 17:05   ` Max Reitz
2016-09-30 10:53 ` [Qemu-devel] [PATCH 09/22] block: introduce persistent dirty bitmaps Vladimir Sementsov-Ogievskiy
2016-10-07 17:54   ` Max Reitz
2016-10-11 13:11     ` Vladimir Sementsov-Ogievskiy
2016-10-12 18:24       ` Max Reitz
2016-10-07 19:28   ` Max Reitz
2016-10-12 11:38     ` Vladimir Sementsov-Ogievskiy
2016-10-12 12:30       ` Vladimir Sementsov-Ogievskiy
2016-10-12 18:25         ` Max Reitz
2016-09-30 10:53 ` [Qemu-devel] [PATCH 10/22] block/dirty-bitmap: add bdrv_dirty_bitmap_next() Vladimir Sementsov-Ogievskiy
2016-10-07 18:11   ` Max Reitz
2016-09-30 10:53 ` [Qemu-devel] [PATCH 11/22] qcow2-bitmap: add qcow2_store_persistent_bitmaps() Vladimir Sementsov-Ogievskiy
2016-10-07 19:24   ` Max Reitz
2016-10-13 16:48     ` Vladimir Sementsov-Ogievskiy
2016-10-15 16:40       ` Max Reitz
2016-10-17 17:19     ` Vladimir Sementsov-Ogievskiy
2016-10-21 19:44       ` Max Reitz
2016-10-21 21:04         ` Eric Blake
2016-10-17 17:57   ` Vladimir Sementsov-Ogievskiy
2016-10-17 17:58     ` [Qemu-devel] DROP THIS " Vladimir Sementsov-Ogievskiy
2016-09-30 10:53 ` [Qemu-devel] [PATCH 12/22] qcow2-bitmap: add IN_USE flag Vladimir Sementsov-Ogievskiy
2016-10-07 19:44   ` Max Reitz
2016-10-21 15:34     ` Vladimir Sementsov-Ogievskiy
2016-10-21 19:58       ` Max Reitz
2016-10-24 10:32         ` Vladimir Sementsov-Ogievskiy
2016-10-24 11:35           ` Vladimir Sementsov-Ogievskiy
2016-10-24 17:08             ` Max Reitz
2016-10-24 17:18               ` Max Reitz
2016-10-25 10:53                 ` Vladimir Sementsov-Ogievskiy
2016-10-26  9:04                   ` Vladimir Sementsov-Ogievskiy
2016-10-26  9:21                     ` Vladimir Sementsov-Ogievskiy
2016-10-26 12:13                       ` Vladimir Sementsov-Ogievskiy
2016-10-26 13:02                         ` Vladimir Sementsov-Ogievskiy
2016-10-26 15:28                     ` Max Reitz
2016-11-07 16:12                   ` Vladimir Sementsov-Ogievskiy
2016-11-07 16:18                     ` Max Reitz
2016-10-24 16:54           ` Max Reitz
2016-09-30 10:53 ` [Qemu-devel] [PATCH 13/22] qcow2-bitmap: check constraints Vladimir Sementsov-Ogievskiy
2016-10-07 19:54   ` Max Reitz
2016-09-30 10:53 ` [Qemu-devel] [PATCH 14/22] qcow2: delete bitmaps on truncate Vladimir Sementsov-Ogievskiy
2016-10-07 19:58   ` Max Reitz
2016-09-30 10:53 ` [Qemu-devel] [PATCH 15/22] qcow2-bitmap: add autoclear bit Vladimir Sementsov-Ogievskiy
2016-10-07 20:11   ` Max Reitz
2016-10-24 14:25     ` Vladimir Sementsov-Ogievskiy
2016-10-24 17:21       ` Max Reitz
2016-09-30 10:53 ` [Qemu-devel] [PATCH 16/22] qmp: add persistent flag to block-dirty-bitmap-add Vladimir Sementsov-Ogievskiy
2016-10-07 19:52   ` Eric Blake
2016-10-24 14:44     ` Vladimir Sementsov-Ogievskiy
2016-10-10 16:08   ` Max Reitz
2016-10-24 15:12     ` Vladimir Sementsov-Ogievskiy
2016-10-24 17:30       ` Max Reitz
2016-10-25 11:05         ` Vladimir Sementsov-Ogievskiy
2016-09-30 10:53 ` [Qemu-devel] [PATCH 17/22] qmp: add autoload parameter " Vladimir Sementsov-Ogievskiy
2016-10-07 19:53   ` Eric Blake
2016-10-10 16:25   ` Max Reitz
2016-10-24 15:55     ` Vladimir Sementsov-Ogievskiy
2016-09-30 10:53 ` [Qemu-devel] [PATCH 18/22] qapi: add md5 checksum of last dirty bitmap level to query-block Vladimir Sementsov-Ogievskiy
2016-10-10 16:44   ` Max Reitz
2016-10-10 17:03     ` Max Reitz
2016-10-10 19:22       ` Eric Blake
2016-09-30 10:53 ` [Qemu-devel] [PATCH 19/22] iotests: test qcow2 persistent dirty bitmap Vladimir Sementsov-Ogievskiy
2016-10-10 17:04   ` Max Reitz
2016-09-30 10:53 ` [Qemu-devel] [PATCH 20/22] qcow2-dirty-bitmap: refcounts Vladimir Sementsov-Ogievskiy
2016-10-10 17:59   ` Max Reitz [this message]
2016-09-30 10:53 ` [Qemu-devel] [PATCH 21/22] specs/qcow2: fix bitmap granularity qemu-specific note Vladimir Sementsov-Ogievskiy
2016-10-07 20:18   ` Eric Blake
2016-11-09 16:43     ` Vladimir Sementsov-Ogievskiy
2016-09-30 10:53 ` [Qemu-devel] [PATCH 22/22] specs/qcow2: do not use wording 'bitmap header' Vladimir Sementsov-Ogievskiy
2016-10-07 20:20   ` Eric Blake
2016-10-01 13:37 ` [Qemu-devel] [PATCH v7 00/22] qcow2: persistent dirty bitmaps Max Reitz
2016-10-13 18:11   ` John Snow

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=45d25503-97e1-8629-8731-3ae64c4bf12c@redhat.com \
    --to=mreitz@redhat.com \
    --cc=armbru@redhat.com \
    --cc=den@openvz.org \
    --cc=eblake@redhat.com \
    --cc=famz@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=vsementsov@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.