diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2012-05-08 16:51:52 +0200 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2012-05-10 10:32:13 +0200 |
commit | cc785c349de002596a4f4d116e62846fc18d7b9e (patch) | |
tree | f8b5b740a73ac927ab5718487a4d7234703bc33b /qemu-io.c | |
parent | 8655d2de0a101782b8066779b8b04e59a80c7d85 (diff) | |
download | qemu-cc785c349de002596a4f4d116e62846fc18d7b9e.zip qemu-cc785c349de002596a4f4d116e62846fc18d7b9e.tar.gz qemu-cc785c349de002596a4f4d116e62846fc18d7b9e.tar.bz2 |
qemu-io: fix the alloc command
Because sector_num is not updated, the loop would either go on
forever or return garbage.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'qemu-io.c')
-rw-r--r-- | qemu-io.c | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -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)); |