* [Qemu-devel] [PATCH] qemu-io: Rework alloc command
@ 2009-07-20 14:48 Kevin Wolf
2009-07-20 20:54 ` Christoph Hellwig
0 siblings, 1 reply; 4+ messages in thread
From: Kevin Wolf @ 2009-07-20 14:48 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf
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>
---
qemu-io.c | 22 ++++++++++++++--------
1 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/qemu-io.c b/qemu-io.c
index 6c35a07..f938575 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -1170,11 +1170,10 @@ static int
alloc_f(int argc, char **argv)
{
int64_t offset;
- int nb_sectors;
+ int nb_sectors, remaining;
char s1[64];
- int num;
+ int num, sum_alloc;
int ret;
- const char *retstr;
offset = cvtnum(argv[1]);
if (offset & 0x1ff) {
@@ -1188,16 +1187,23 @@ alloc_f(int argc, char **argv)
else
nb_sectors = 1;
- ret = bdrv_is_allocated(bs, offset >> 9, nb_sectors, &num);
+ remaining = nb_sectors;
+ sum_alloc = 0;
+ while (remaining) {
+ ret = bdrv_is_allocated(bs, offset >> 9, nb_sectors, &num);
+ remaining -= num;
+ if (ret) {
+ sum_alloc += num;
+ }
+ }
cvtstr(offset, s1, sizeof(s1));
- retstr = ret ? "allocated" : "not allocated";
if (nb_sectors == 1)
- printf("sector %s at offset %s\n", retstr, s1);
+ printf("sector allocated at offset %s\n", s1);
else
- printf("%d/%d sectors %s at offset %s\n",
- num, nb_sectors, retstr, s1);
+ printf("%d/%d sectors allocated at offset %s\n",
+ sum_alloc, nb_sectors, s1);
return 0;
}
--
1.6.0.6
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] qemu-io: Rework alloc command
2009-07-20 14:48 [Qemu-devel] [PATCH] qemu-io: Rework alloc command Kevin Wolf
@ 2009-07-20 20:54 ` Christoph Hellwig
2009-07-21 7:22 ` Kevin Wolf
0 siblings, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2009-07-20 20:54 UTC (permalink / raw)
To: Kevin Wolf; +Cc: qemu-devel
On Mon, Jul 20, 2009 at 04:48:43PM +0200, Kevin Wolf wrote:
> 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.
Looks good to me. Can you post the corresponding qemu-iotests patch,
too?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] qemu-io: Rework alloc command
2009-07-20 20:54 ` Christoph Hellwig
@ 2009-07-21 7:22 ` Kevin Wolf
2009-07-27 11:16 ` Christoph Hellwig
0 siblings, 1 reply; 4+ messages in thread
From: Kevin Wolf @ 2009-07-21 7:22 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: qemu-devel
[-- Attachment #1: Type: text/plain, Size: 895 bytes --]
Christoph Hellwig schrieb:
> On Mon, Jul 20, 2009 at 04:48:43PM +0200, Kevin Wolf wrote:
>> 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.
>
> Looks good to me. Can you post the corresponding qemu-iotests patch,
> too?
I wanted to post it when the qemu-io change is in, but if you want to
apply it earlier (makes qcow2 and vmdk fail until the qemu-io patch is
committed), here is it.
Kevin
[-- Attachment #2: 0001-qemu-iotests-Fix-expected-result-for-019-after-qemu.patch --]
[-- Type: text/plain, Size: 969 bytes --]
>From 41f80a74b4177e5396dab7916f8f7b40a65cef07 Mon Sep 17 00:00:00 2001
From: Kevin Wolf <kwolf@redhat.com>
Date: Tue, 21 Jul 2009 09:16:37 +0200
Subject: [PATCH] qemu-iotests: Fix expected result for 019 after qemu-io change
The output of the alloc command in qemu-io has changed.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
019.out | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/019.out b/019.out
index f461f8b..9ac1a21 100644
--- a/019.out
+++ b/019.out
@@ -539,8 +539,8 @@ qemu-io> wrote 65536/65536 bytes at offset 4296146944
qemu-io> No errors were found on the image.
Checking if backing clusters are allocated when they shouldn't
-qemu-io> 128/128 sectors not allocated at offset 1 MiB
-qemu-io> qemu-io> 128/128 sectors not allocated at offset 4.001 GiB
+qemu-io> 0/128 sectors allocated at offset 1 MiB
+qemu-io> qemu-io> 0/128 sectors allocated at offset 4.001 GiB
qemu-io> Reading
=== IO: pattern 0
--
1.6.0.6
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] qemu-io: Rework alloc command
2009-07-21 7:22 ` Kevin Wolf
@ 2009-07-27 11:16 ` Christoph Hellwig
0 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2009-07-27 11:16 UTC (permalink / raw)
To: Kevin Wolf; +Cc: Christoph Hellwig, qemu-devel
On Tue, Jul 21, 2009 at 09:22:04AM +0200, Kevin Wolf wrote:
> I wanted to post it when the qemu-io change is in, but if you want to
> apply it earlier (makes qcow2 and vmdk fail until the qemu-io patch is
> committed), here is it.
Thanks, I've put it in now that the qemu-io change went in.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-07-27 11:16 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-20 14:48 [Qemu-devel] [PATCH] qemu-io: Rework alloc command Kevin Wolf
2009-07-20 20:54 ` Christoph Hellwig
2009-07-21 7:22 ` Kevin Wolf
2009-07-27 11:16 ` Christoph Hellwig
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).