From: Kevin Wolf <kwolf@suse.de>
To: Laurent Vivier <Laurent.Vivier@bull.net>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 2/4] qcow2: Allow update_cluster_refcount() to update several clusters refcount.
Date: Fri, 07 Nov 2008 11:21:51 +0100 [thread overview]
Message-ID: <491416BF.8070007@suse.de> (raw)
In-Reply-To: <1226052194.4046.21.camel@frecb07144>
Laurent Vivier schrieb:
>>> + block_index = cluster_index & (refcount_cache_size - 1);
>>> + refcount = 0;
>>> + while (nb_clusters &&
>>> + block_index + nb_block_index < refcount_cache_size) {
>>> +
>>> + refcount = be16_to_cpu(
>>> + s->refcount_block_cache[block_index + nb_block_index]);
>>> + refcount += addend;
>>> + if (refcount < 0 || refcount > 0xffff)
>>> + return -EINVAL;
>> Here we possibly abort in the middle of the operation. If it fails
>> somewhere in the fifth refcount block, what happens with the four
>> already updated blocks?
>
> Yes, you're right. I think we have at least to save refcount we have
> updated.
>
>>> + if (refcount == 0 &&
>>> + cluster_index + nb_block_index < s->free_cluster_index) {
>>> + s->free_cluster_index = cluster_index + nb_block_index;
>>> + }
>>> + s->refcount_block_cache[block_index + nb_block_index] =
>>> + cpu_to_be16(refcount);
>>> + nb_block_index++;
>>> + nb_clusters--;
>>> + }
>>> + if (bdrv_pwrite(s->hd,
>>> + refcount_block_offset + (block_index << REFCOUNT_SHIFT),
>>> + s->refcount_block_cache + block_index,
>>> + nb_block_index * sizeof(uint16_t)) !=
>>> + nb_block_index * sizeof(uint16_t))
>>> return -EIO;
>> Same here.
>
> I think we are not worst than the original behavior. I don't know how to
> manage this better.
Right, this hasn't been optimal before either. I noticed later that
update_refcount didn't even check the return value. So the difference is
that you abort while the old implementation tries the next block.
I'm unsure which behaviour is the better one. Actually, both don't feel
quite right. But being not worse in this aspect than the original still
makes this patch an improvement, so...
>>> }
>>> - /* we can update the count and save it */
>>> - block_index = cluster_index &
>>> - ((1 << (s->cluster_bits - REFCOUNT_SHIFT)) - 1);
>>> - refcount = be16_to_cpu(s->refcount_block_cache[block_index]);
>>> - refcount += addend;
>>> - if (refcount < 0 || refcount > 0xffff)
>>> - return -EINVAL;
>>> - if (refcount == 0 && cluster_index < s->free_cluster_index) {
>>> - s->free_cluster_index = cluster_index;
>>> - }
>>> - s->refcount_block_cache[block_index] = cpu_to_be16(refcount);
>>> - if (bdrv_pwrite(s->hd,
>>> - refcount_block_offset + (block_index << REFCOUNT_SHIFT),
>>> - &s->refcount_block_cache[block_index], 2) != 2)
>>> - return -EIO;
>>> return refcount;
>>> }
>>>
>>> @@ -2437,7 +2469,7 @@ static void update_refcount(BlockDriverS
>>> int addend)
>>> {
>>> BDRVQcowState *s = bs->opaque;
>>> - int64_t start, last, cluster_offset;
>>> + int64_t start, last;
>>>
>>> #ifdef DEBUG_ALLOC2
>>> printf("update_refcount: offset=%lld size=%lld addend=%d\n",
>>> @@ -2445,12 +2477,9 @@ static void update_refcount(BlockDriverS
>>> #endif
>>> if (length <= 0)
>>> return;
>>> - start = offset & ~(s->cluster_size - 1);
>>> - last = (offset + length - 1) & ~(s->cluster_size - 1);
>>> - for(cluster_offset = start; cluster_offset <= last;
>>> - cluster_offset += s->cluster_size) {
>>> - update_cluster_refcount(bs, cluster_offset >> s->cluster_bits, addend);
>>> - }
>>> + start = offset >> s->cluster_bits;
>>> + last = (offset + length) >> s->cluster_bits;
>> Off by one for length % cluster_size == 0?
>
> Explain, please (but notice the "<=" in the "for (...)").
I didn't even look at the old code yesterday, but the difference is that
you dropped the - 1 for last.
Let's do it by example: Assume cluster_size = 0x1000 for simplicity and
we get offset = 0x1000 and length = 0x2000 (i.e. the last affected byte
would be 0x2fff). The old code correctly produces start = 0x1000 and
last = 0x2000 whereas you get start = 1 and last = 3.
Kevin
next prev parent reply other threads:[~2008-11-07 10:19 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20081106165212.380421945@bull.net>
2008-11-06 16:55 ` [Qemu-devel] [PATCH 1/4] qcow2: Clean-up update_cluster_refcount() Laurent Vivier
2008-11-06 17:32 ` Kevin Wolf
2008-11-07 8:48 ` Laurent Vivier
2008-11-07 8:54 ` Kevin Wolf
2008-11-07 9:22 ` Laurent Vivier
2008-11-06 16:55 ` [Qemu-devel] [PATCH 2/4] qcow2: Allow update_cluster_refcount() to update several clusters refcount Laurent Vivier
2008-11-06 18:11 ` Kevin Wolf
2008-11-07 10:03 ` Laurent Vivier
2008-11-07 10:21 ` Kevin Wolf [this message]
2008-11-07 11:39 ` Laurent Vivier
2008-11-06 16:55 ` [Qemu-devel] [PATCH 3/4] qcow2: Align I/O access to l2 table and refcount block Laurent Vivier
2008-11-06 16:56 ` [Qemu-devel] [PATCH 4/4] qcow2: detect if no disk cache Laurent Vivier
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=491416BF.8070007@suse.de \
--to=kwolf@suse.de \
--cc=Laurent.Vivier@bull.net \
--cc=qemu-devel@nongnu.org \
/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).