From: "Benoît Canet" <benoit.canet@irqsave.net>
To: Jun Li <junmuzi@gmail.com>
Cc: "Benoît Canet" <benoit.canet@irqsave.net>,
kwolf@redhat.com, famz@redhat.com, juli@redhat.com,
qemu-devel@nongnu.org, stefanha@redhat.com
Subject: Re: [Qemu-devel] [PATCH v2] qcow2: add update refcount table realization for update_refcount
Date: Tue, 2 Sep 2014 15:38:37 +0200 [thread overview]
Message-ID: <20140902133837.GA28034@irqsave.net> (raw)
In-Reply-To: <20140901160408.GA4193@localhost.localdomain>
The Tuesday 02 Sep 2014 à 00:04:08 (+0800), Jun Li wrote :
> On Mon, 09/01 13:11, Benoît Canet wrote:
> > The Monday 01 Sep 2014 à 18:52:48 (+0800), Jun Li wrote :
> > > When every item of refcount block is NULL, free refcount block and reset the
> > > corresponding item of refcount table with NULL.
> > >
> > > Signed-off-by: Jun Li <address@hidden>
> > > ---
> > >
> > > The v2 do following change to modify some potential issue.
> > >
> > > +------- Here should start from "0".
> > > |
> > > for (k = 0; k < refcount_block_entries; k++) {
> > > if (refcount_block[k] != cpu_to_be16(0)) {
> > > ... | |
> > > } | |
> > > } | +---- Using "0" is more safe.
> > > |
> > > +-------- This should be "k" not "++k".
> > > ---
> > > block/qcow2-refcount.c | 31 +++++++++++++++++++++++++++++++
> > > 1 file changed, 31 insertions(+)
> > >
> > > diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
> > > index 43665b8..63f36e6 100644
> > > --- a/block/qcow2-refcount.c
> > > +++ b/block/qcow2-refcount.c
> > > @@ -586,6 +586,37 @@ static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs,
> > > if (refcount == 0 && s->discard_passthrough[type]) {
> > > update_refcount_discard(bs, cluster_offset, s->cluster_size);
> > > }
> > > +
> > > + /* When refcount block is NULL, update refcount table */
> > > + if (block_index == 0) {
> > > + int k = block_index;
> > > + int refcount_block_entries = s->cluster_size / sizeof(uint16_t);
> > > + for (k = 0; k < refcount_block_entries; k++) {
> > > + if (refcount_block[k] != cpu_to_be16(0)) {
> > > + break;
> > > + }
> > > + }
> > > +
> > > + if (k == refcount_block_entries) {
> > > + qemu_vfree(refcount_block);
> > > + /* update refcount table */
> > > + unsigned int refcount_table_index;
> > > + uint64_t data64 = cpu_to_be64(0);
> > > + refcount_table_index = cluster_index >> (s->cluster_bits -
> > > + REFCOUNT_SHIFT);
> > > + ret = bdrv_pwrite_sync(bs->file,
> > > + s->refcount_table_offset +
> > > + refcount_table_index *
> > > + sizeof(uint64_t),
> > > + &data64, sizeof(data64));
> > > + if (ret < 0) {
> > > + goto fail;
> > > + }
> > > +
> >
> > > + s->refcount_table[refcount_table_index] = data64;
> >
> > Shouldn't the in memory version be be in cpu order ? like
> > s->refcount_table[refcount_table_index] = 0;
>
> I don't think so. See following:
>
> (gdb) p sizeof(s->refcount_table[0])
> $5 = 8
> (gdb) p sizeof(s->refcount_table[1])
> $6 = 8
> (gdb) p sizeof(0)
> $7 = 4
There is two different thing here: endianness and type.
For the endianess you can look at qcow2_refcount_init.
The endianness of this in memory table is the one of the CPU.
Here data64 is big endian and this is wrong.
For the type integer promotion will take care of it.
See http://www.tutorialspoint.com/cprogramming/c_type_casting.htm
assigning zero means that the compiler will silently perform
a cast to int64_t.
Best regards
Benoît
>
> So I think here is right. Thank you for sharing Max's patch(qcow2: Drop
> REFCOUNT_SHIFT) with me. I find this patch has been reviewed, but it has not
> been merged. Maybe I will modify my realization after this patch merged.
>
> Thanks again.
>
> Jun Li
>
>
> >
> > Best regards
> >
> > Benoît
> > > +
> > > + }
> > > + }
> > > }
> > >
> > > ret = 0;
> > > --
> > > 1.9.3
> > >
> > >
>
next prev parent reply other threads:[~2014-09-02 13:39 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-01 10:52 [Qemu-devel] [PATCH v2] qcow2: add update refcount table realization for update_refcount Jun Li
2014-09-01 11:11 ` Benoît Canet
2014-09-01 16:04 ` Jun Li
2014-09-02 13:38 ` Benoît Canet [this message]
2014-09-02 17:12 ` Greg Kurz
2014-09-22 1:45 ` jun muzi
2014-09-05 10:21 ` Kevin Wolf
2014-09-09 2:52 ` Jun Li
2014-09-09 8:21 ` Kevin Wolf
2014-09-09 14:04 ` Jun Li
2014-09-05 15:33 ` Stefan Hajnoczi
2014-09-13 15:53 ` Jun Li
2014-09-15 9:27 ` Stefan Hajnoczi
2014-09-05 15:34 ` Stefan Hajnoczi
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=20140902133837.GA28034@irqsave.net \
--to=benoit.canet@irqsave.net \
--cc=famz@redhat.com \
--cc=juli@redhat.com \
--cc=junmuzi@gmail.com \
--cc=kwolf@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).