Commit a7824a886ed50eb4fe3c6fcd6afd8814a6973583

Authored by Kevin Wolf
Committed by Anthony Liguori
1 parent d032044f

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>
Showing 1 changed file with 14 additions and 8 deletions
qemu-io.c
... ... @@ -1170,11 +1170,10 @@ static int
1170 1170 alloc_f(int argc, char **argv)
1171 1171 {
1172 1172 int64_t offset;
1173   - int nb_sectors;
  1173 + int nb_sectors, remaining;
1174 1174 char s1[64];
1175   - int num;
  1175 + int num, sum_alloc;
1176 1176 int ret;
1177   - const char *retstr;
1178 1177  
1179 1178 offset = cvtnum(argv[1]);
1180 1179 if (offset & 0x1ff) {
... ... @@ -1188,16 +1187,23 @@ alloc_f(int argc, char **argv)
1188 1187 else
1189 1188 nb_sectors = 1;
1190 1189  
1191   - ret = bdrv_is_allocated(bs, offset >> 9, nb_sectors, &num);
  1190 + remaining = nb_sectors;
  1191 + sum_alloc = 0;
  1192 + while (remaining) {
  1193 + ret = bdrv_is_allocated(bs, offset >> 9, nb_sectors, &num);
  1194 + remaining -= num;
  1195 + if (ret) {
  1196 + sum_alloc += num;
  1197 + }
  1198 + }
1192 1199  
1193 1200 cvtstr(offset, s1, sizeof(s1));
1194 1201  
1195   - retstr = ret ? "allocated" : "not allocated";
1196 1202 if (nb_sectors == 1)
1197   - printf("sector %s at offset %s\n", retstr, s1);
  1203 + printf("sector allocated at offset %s\n", s1);
1198 1204 else
1199   - printf("%d/%d sectors %s at offset %s\n",
1200   - num, nb_sectors, retstr, s1);
  1205 + printf("%d/%d sectors allocated at offset %s\n",
  1206 + sum_alloc, nb_sectors, s1);
1201 1207 return 0;
1202 1208 }
1203 1209  
... ...