From: Kevin Wolf <kwolf@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org, stefanha@linux.vnet.ibm.com
Subject: Re: [Qemu-devel] [PATCH 17/26] qemu-io: fix the alloc command
Date: Tue, 08 May 2012 15:16:25 +0200 [thread overview]
Message-ID: <4FA91CA9.8080603@redhat.com> (raw)
In-Reply-To: <4FA91A48.3050803@redhat.com>
Am 08.05.2012 15:06, schrieb Paolo Bonzini:
> Il 08/05/2012 14:57, Kevin Wolf ha scritto:
>>>>
>>>> diff --git a/qemu-io.c b/qemu-io.c
>>>> index 43643c8..27a0c3c 100644
>>>> --- a/qemu-io.c
>>>> +++ b/qemu-io.c
>>>> @@ -1560,7 +1560,7 @@ out:
>>>>
>>>> static int alloc_f(int argc, char **argv)
>>>> {
>>>> - int64_t offset;
>>>> + int64_t offset, sector_num;
>>>> int nb_sectors, remaining;
>>>> char s1[64];
>>>> int num, sum_alloc;
>>>> @@ -1581,12 +1581,18 @@ static int alloc_f(int argc, char **argv)
>>>>
>>>> remaining = nb_sectors;
>>>> sum_alloc = 0;
>>>> + sector_num = offset >> 9;
>>>> while (remaining) {
>>>> - ret = bdrv_is_allocated(bs, offset >> 9, nb_sectors, &num);
>>>> + ret = bdrv_is_allocated(bs, sector_num, remaining, &num);
>>>> + sector_num += num;
>>>> remaining -= num;
>>>> if (ret) {
>>>> sum_alloc += num;
>>>> }
>>>> + if (num == 0) {
>>>> + nb_sectors -= remaining;
>>>> + remaining = 0;
>>>> + }
>>>> }
>>>>
>>>> cvtstr(offset, s1, sizeof(s1));
>> This doesn't provide the semantics I expected, i.e. the semantics of
>> bdrv_is_allocated, which is the number of contiguous clusters that are
>> allocated or unallocated. Instead you provide the number of all
>> allocated in the whole area even if there are some unallocated clusters
>> in the middle.
>
> commit a7824a886ed50eb4fe3c6fcd6afd8814a6973583
> Author: Kevin Wolf <kwolf@redhat.com>
> Date: Mon Jul 20 16:48:43 2009 +0200
>
> qemu-io: Rework alloc command
>
> The alloc command in qemu-io is mostly useless currently. Instead of doing a
> single call to bdrv_is_allocated, we must call bdrv_is_allocated in a loop
> until we have found out for each requested sector if it is allocated or not
> (bdrv_is_allocated returns a number of sectors that are known to be in the same
> state as the first one, but it is not required to include all of them)
>
> This changes the output format of the alloc command so that a change to the
> expected output of qemu-iotests 019 is necessary once this is included.
>
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
>
> I guess this guy knows. :)
The commit message is talking about something different. Consider the
following image, x is allocated, . is unallocated:
xxx...xxx
bdrv_is_allocated(offset = 0, length = 9 * cluster_size) can tell you "2
clusters allocated", for example because after two clusters the L2 table
ended. I found this pretty confusing and instead expected that qemu-io
loops until it finds the first different cluster, i.e. the result would
always be "3 clusters allocated". This is what I think the quoted commit
(tried to) implement. (Yes, makes the existing code even more embarrassing)
Your code would output "6 clusters allocated", because it wouldn't care
about the unallocated clusters in the middle.
>> Do you think there's a use case for the sum of the whole area?
>
> I think for tests it's more useful, you don't want to depend on the implementation
> of is_allocated. That's what I can guess from the above commit message and from
> the way 019 uses alloc.
I think 019 would work with both.
Kevin
next prev parent reply other threads:[~2012-05-08 13:16 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1334232076-19018-1-git-send-email-pbonzini@redhat.com>
2012-05-04 16:20 ` [Qemu-devel] [PATCH 00/26] My block patches queue for 1.1 Paolo Bonzini
2012-05-07 12:44 ` Kevin Wolf
[not found] ` <1334232076-19018-18-git-send-email-pbonzini@redhat.com>
2012-05-08 12:57 ` [Qemu-devel] [PATCH 17/26] qemu-io: fix the alloc command Kevin Wolf
2012-05-08 13:06 ` Paolo Bonzini
2012-05-08 13:16 ` Kevin Wolf [this message]
2012-05-08 14:13 ` Paolo Bonzini
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=4FA91CA9.8080603@redhat.com \
--to=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@linux.vnet.ibm.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).