qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: Max Reitz <mreitz@redhat.com>
Cc: qemu-devel@nongnu.org, "Stefan Hajnoczi" <stefanha@redhat.com>,
	"Benoît Canet" <benoit.canet@nodalink.com>
Subject: Re: [Qemu-devel] [PATCH v6 08/11] qcow2: Rebuild refcount structure during check
Date: Tue, 21 Oct 2014 12:12:38 +0200	[thread overview]
Message-ID: <20141021101238.GG4409@noname.redhat.com> (raw)
In-Reply-To: <54462CE9.4020909@redhat.com>

Am 21.10.2014 um 11:52 hat Max Reitz geschrieben:
> On 2014-10-21 at 11:31, Kevin Wolf wrote:
> >Am 20.10.2014 um 16:35 hat Max Reitz geschrieben:
> >>The previous commit introduced the "rebuild" variable to qcow2's
> >>implementation of the image consistency check. Now make use of this by
> >>adding a function which creates a completely new refcount structure
> >>based solely on the in-memory information gathered before.
> >>
> >>The old refcount structure will be leaked, however. This leak will be
> >>dealt with in a follow-up commit.
> >>
> >>Signed-off-by: Max Reitz <mreitz@redhat.com>
> >>---
> >>  block/qcow2-refcount.c | 296 ++++++++++++++++++++++++++++++++++++++++++++++++-
> >>  1 file changed, 293 insertions(+), 3 deletions(-)

> >>+/*
> >>+ * Creates a new refcount structure based solely on the in-memory information
> >>+ * given through *refcount_table. All necessary allocations will be reflected
> >>+ * in that array.
> >>+ *
> >>+ * On success, the old refcount structure is leaked (it will be covered by the
> >>+ * new refcount structure).
> >>+ */
> >>+static int rebuild_refcount_structure(BlockDriverState *bs,
> >>+                                      BdrvCheckResult *res,
> >>+                                      uint16_t **refcount_table,
> >>+                                      int64_t *nb_clusters)
> >>+{
> >>+    BDRVQcowState *s = bs->opaque;
> >>+    int64_t first_free_cluster = 0, reftable_offset = -1, cluster = 0;
> >>+    int64_t refblock_offset, refblock_start, refblock_index;
> >>+    uint32_t reftable_size = 0;
> >>+    uint64_t *reftable = NULL;
> >refcount_table and reftable? Seriously?
> 
> Reviewing would have been too easy otherwise. *cough*
> 
> One option is s/refcount_table/imrt/. I like it more than the second
> option, but it simply goes against the current naming convention.
> 
> The other option would be s/reftable/on_disk_reftable/, following
> the convention used in the next line.

The second option is probably more consistent with the rest (and less
cryptic).

> >>+        ret = qcow2_pre_write_overlap_check(bs, 0, refblock_offset,
> >>+                                            s->cluster_size);
> >>+        if (ret < 0) {
> >>+            fprintf(stderr, "ERROR writing refblock: %s\n", strerror(-ret));
> >>+            goto fail;
> >>+        }
> >>+
> >>+        on_disk_refblock = g_malloc0(s->cluster_size);
> >qemu_blockalign?
> 
> Meh, I think I have to write a qemu_blockalign0() some time...
> 
> If I do so, it's one more patch you have to review; if I just use
> qemu_blockalign(), I find the memset() directly afterwards rather
> ugly, but would be fine with it. I guess it's up to you, then.

A qemu_blockalign0() sounds easy enough to review. It's not the number
of patches that makes review hard, it's their content.

Anyway, you're the patch author, it's your choice.

> >>+    ret = qcow2_pre_write_overlap_check(bs, 0, reftable_offset,
> >>+                                        reftable_size * sizeof(uint64_t));
> >>+    if (ret < 0) {
> >>+        fprintf(stderr, "ERROR writing reftable: %s\n", strerror(-ret));
> >>+        goto fail;
> >>+    }
> >>+
> >>+    ret = bdrv_write(bs->file, reftable_offset / BDRV_SECTOR_SIZE,
> >>+                     (void *)reftable,
> >>+                     reftable_size * sizeof(uint64_t) / BDRV_SECTOR_SIZE);
> >Why not bdrv_pwrite when you only have byte offset and length?
> 
> I don't like pwrite probably only because it takes an int byte
> length. reftable_size * sizeof(uint64_t) should be well below
> INT_MAX, but I don't see why we should use pwrite if we are writing
> full sectors to a sector-aligned offset.

Good point, we should look into fixing the type of the length argument
sometime.

Other than that, I'd prefer bdrv_pread/pwrite because it doesn't require
unit conversion here, and later in block.c back (bdrv_co_do_pwritev is
the native block layer interface, and it's byte based). bdrv_write()
goes through more emulation layers in block.c.

Kevin

  reply	other threads:[~2014-10-21 10:12 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-20 14:35 [Qemu-devel] [PATCH v6 00/11] qcow2: Fix image repairing Max Reitz
2014-10-20 14:35 ` [Qemu-devel] [PATCH v6 01/11] qcow2: Calculate refcount block entry count Max Reitz
2014-10-20 14:35 ` [Qemu-devel] [PATCH v6 02/11] qcow2: Fix leaks in dirty images Max Reitz
2014-10-20 14:35 ` [Qemu-devel] [PATCH v6 03/11] qcow2: Split qcow2_check_refcounts() Max Reitz
2014-10-20 14:35 ` [Qemu-devel] [PATCH v6 04/11] qcow2: Pull check_refblocks() up Max Reitz
2014-10-20 15:07   ` Kevin Wolf
2014-10-20 14:35 ` [Qemu-devel] [PATCH v6 05/11] qcow2: Reuse refcount table in calculate_refcounts() Max Reitz
2014-10-20 15:09   ` Kevin Wolf
2014-10-20 14:35 ` [Qemu-devel] [PATCH v6 06/11] qcow2: Fix refcount blocks beyond image end Max Reitz
2014-10-20 16:44   ` Kevin Wolf
2014-10-21  7:14     ` Max Reitz
2014-10-20 14:35 ` [Qemu-devel] [PATCH v6 07/11] qcow2: Do not perform potentially damaging repairs Max Reitz
2014-10-21  7:52   ` Kevin Wolf
2014-10-21 10:10     ` Max Reitz
2014-10-20 14:35 ` [Qemu-devel] [PATCH v6 08/11] qcow2: Rebuild refcount structure during check Max Reitz
2014-10-21  9:31   ` Kevin Wolf
2014-10-21  9:52     ` Max Reitz
2014-10-21 10:12       ` Kevin Wolf [this message]
2014-10-20 14:35 ` [Qemu-devel] [PATCH v6 09/11] qcow2: Clean up after refcount rebuild Max Reitz
2014-10-21  9:59   ` Kevin Wolf
2014-10-21 10:16     ` Max Reitz
2014-10-21 14:55       ` Max Reitz
2014-10-21 15:11         ` Kevin Wolf
2014-10-21 15:17           ` Max Reitz
2014-10-20 14:35 ` [Qemu-devel] [PATCH v6 10/11] iotests: Fix test outputs Max Reitz
2014-10-21 13:42   ` Kevin Wolf
2014-10-20 14:35 ` [Qemu-devel] [PATCH v6 11/11] iotests: Add test for potentially damaging repairs Max Reitz
2014-10-21 14:12   ` Kevin Wolf
2014-10-21 14:20     ` Max Reitz
2014-10-21 15:16       ` Kevin Wolf

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=20141021101238.GG4409@noname.redhat.com \
    --to=kwolf@redhat.com \
    --cc=benoit.canet@nodalink.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).