Ver Fonte

qemu-io: Switch 'map' output to byte-based reporting

Mixing byte offset and sector allocation counts is a bit
confusing.  Also, reporting n/m sectors, where m decreases
according to the remaining size of the file, isn't really
adding any useful information; and reporting an offset at
both the front and end of the line, with large amounts of
whitespace, is pointless.  Update the output to use byte
counts and shorter lines, then adjust the affected tests
(./check -qcow2 102, ./check -vpc 146).

Note that 'qemu-io map' is MUCH weaker than 'qemu-img map';
the former only shows which regions of the active layer are
allocated, without regards to where the allocation comes from
or whether the allocated portion is known to read as zero
(because it is using the weaker bdrv_is_allocated()); while the
latter (especially in --output=json mode) reports more details
from bdrv_get_block_status().

Signed-off-by: Eric Blake <eblake@redhat.com>
Message-id: 20170429191419.30051-4-eblake@redhat.com
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
Eric Blake há 8 anos atrás
pai
commit
6f3c90af3c
3 ficheiros alterados com 23 adições e 22 exclusões
  1. 6 5
      qemu-io-cmds.c
  2. 2 2
      tests/qemu-iotests/102.out
  3. 15 15
      tests/qemu-iotests/146.out

+ 6 - 5
qemu-io-cmds.c

@@ -1868,7 +1868,7 @@ static int map_f(BlockBackend *blk, int argc, char **argv)
 {
 {
     int64_t offset;
     int64_t offset;
     int64_t nb_sectors, total_sectors;
     int64_t nb_sectors, total_sectors;
-    char s1[64];
+    char s1[64], s2[64];
     int64_t num;
     int64_t num;
     int ret;
     int ret;
     const char *retstr;
     const char *retstr;
@@ -1894,10 +1894,11 @@ static int map_f(BlockBackend *blk, int argc, char **argv)
         }
         }
 
 
         retstr = ret ? "    allocated" : "not allocated";
         retstr = ret ? "    allocated" : "not allocated";
-        cvtstr(offset << 9ULL, s1, sizeof(s1));
-        printf("[% 24" PRId64 "] % 8" PRId64 "/% 8" PRId64 " sectors %s "
-               "at offset %s (%d)\n",
-               offset << 9ULL, num, nb_sectors, retstr, s1, ret);
+        cvtstr(num << BDRV_SECTOR_BITS, s1, sizeof(s1));
+        cvtstr(offset << BDRV_SECTOR_BITS, s2, sizeof(s2));
+        printf("%s (0x%" PRIx64 ") bytes %s at offset %s (0x%" PRIx64 ")\n",
+               s1, num << BDRV_SECTOR_BITS, retstr,
+               s2, offset << BDRV_SECTOR_BITS);
 
 
         offset += num;
         offset += num;
         nb_sectors -= num;
         nb_sectors -= num;

+ 2 - 2
tests/qemu-iotests/102.out

@@ -6,7 +6,7 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=65536
 wrote 65536/65536 bytes at offset 0
 wrote 65536/65536 bytes at offset 0
 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
 Image resized.
 Image resized.
-[                       0]      128/     128 sectors     allocated at offset 0 bytes (1)
+64 KiB (0x10000) bytes     allocated at offset 0 bytes (0x0)
 Offset          Length          Mapped to       File
 Offset          Length          Mapped to       File
 
 
 === Testing map on an image file truncated outside of qemu ===
 === Testing map on an image file truncated outside of qemu ===
@@ -17,5 +17,5 @@ wrote 65536/65536 bytes at offset 0
 Image resized.
 Image resized.
 QEMU X.Y.Z monitor - type 'help' for more information
 QEMU X.Y.Z monitor - type 'help' for more information
 (qemu) qemu-io drv0 map
 (qemu) qemu-io drv0 map
-[                       0]      128/     128 sectors     allocated at offset 0 bytes (1)
+64 KiB (0x10000) bytes     allocated at offset 0 bytes (0x0)
 *** done
 *** done

+ 15 - 15
tests/qemu-iotests/146.out

@@ -2,39 +2,39 @@ QA output created by 146
 
 
 === Testing VPC Autodetect ===
 === Testing VPC Autodetect ===
 
 
-[                       0]  266334240/ 266334240 sectors not allocated at offset 0 bytes (0)
+126.998 GiB (0x1fbfe04000) bytes not allocated at offset 0 bytes (0x0)
 
 
 === Testing VPC with current_size force ===
 === Testing VPC with current_size force ===
 
 
-[                       0]  266338304/ 266338304 sectors not allocated at offset 0 bytes (0)
+127 GiB (0x1fc0000000) bytes not allocated at offset 0 bytes (0x0)
 
 
 === Testing VPC with chs force ===
 === Testing VPC with chs force ===
 
 
-[                       0]  266334240/ 266334240 sectors not allocated at offset 0 bytes (0)
+126.998 GiB (0x1fbfe04000) bytes not allocated at offset 0 bytes (0x0)
 
 
 === Testing Hyper-V Autodetect ===
 === Testing Hyper-V Autodetect ===
 
 
-[                       0]  266338304/ 266338304 sectors not allocated at offset 0 bytes (0)
+127 GiB (0x1fc0000000) bytes not allocated at offset 0 bytes (0x0)
 
 
 === Testing Hyper-V with current_size force ===
 === Testing Hyper-V with current_size force ===
 
 
-[                       0]  266338304/ 266338304 sectors not allocated at offset 0 bytes (0)
+127 GiB (0x1fc0000000) bytes not allocated at offset 0 bytes (0x0)
 
 
 === Testing Hyper-V with chs force ===
 === Testing Hyper-V with chs force ===
 
 
-[                       0]  266334240/ 266334240 sectors not allocated at offset 0 bytes (0)
+126.998 GiB (0x1fbfe04000) bytes not allocated at offset 0 bytes (0x0)
 
 
 === Testing d2v Autodetect ===
 === Testing d2v Autodetect ===
 
 
-[                       0]   514560/  514560 sectors     allocated at offset 0 bytes (1)
+251.250 MiB (0xfb40000) bytes     allocated at offset 0 bytes (0x0)
 
 
 === Testing d2v with current_size force ===
 === Testing d2v with current_size force ===
 
 
-[                       0]   514560/  514560 sectors     allocated at offset 0 bytes (1)
+251.250 MiB (0xfb40000) bytes     allocated at offset 0 bytes (0x0)
 
 
 === Testing d2v with chs force ===
 === Testing d2v with chs force ===
 
 
-[                       0]   514560/  514560 sectors     allocated at offset 0 bytes (1)
+251.250 MiB (0xfb40000) bytes     allocated at offset 0 bytes (0x0)
 
 
 === Testing Image create, default ===
 === Testing Image create, default ===
 
 
@@ -42,15 +42,15 @@ Formatting 'TEST_DIR/IMGFMT-create-test.IMGFMT', fmt=IMGFMT size=4294967296
 
 
 === Read created image, default opts ====
 === Read created image, default opts ====
 
 
-[                       0]  8389584/ 8389584 sectors not allocated at offset 0 bytes (0)
+4 GiB (0x10007a000) bytes not allocated at offset 0 bytes (0x0)
 
 
 === Read created image, force_size_calc=chs ====
 === Read created image, force_size_calc=chs ====
 
 
-[                       0]  8389584/ 8389584 sectors not allocated at offset 0 bytes (0)
+4 GiB (0x10007a000) bytes not allocated at offset 0 bytes (0x0)
 
 
 === Read created image, force_size_calc=current_size ====
 === Read created image, force_size_calc=current_size ====
 
 
-[                       0]  8389584/ 8389584 sectors not allocated at offset 0 bytes (0)
+4 GiB (0x10007a000) bytes not allocated at offset 0 bytes (0x0)
 
 
 === Testing Image create, force_size ===
 === Testing Image create, force_size ===
 
 
@@ -58,13 +58,13 @@ Formatting 'TEST_DIR/IMGFMT-create-test.IMGFMT', fmt=IMGFMT size=4294967296 forc
 
 
 === Read created image, default opts ====
 === Read created image, default opts ====
 
 
-[                       0]  8388608/ 8388608 sectors not allocated at offset 0 bytes (0)
+4 GiB (0x100000000) bytes not allocated at offset 0 bytes (0x0)
 
 
 === Read created image, force_size_calc=chs ====
 === Read created image, force_size_calc=chs ====
 
 
-[                       0]  8388608/ 8388608 sectors not allocated at offset 0 bytes (0)
+4 GiB (0x100000000) bytes not allocated at offset 0 bytes (0x0)
 
 
 === Read created image, force_size_calc=current_size ====
 === Read created image, force_size_calc=current_size ====
 
 
-[                       0]  8388608/ 8388608 sectors not allocated at offset 0 bytes (0)
+4 GiB (0x100000000) bytes not allocated at offset 0 bytes (0x0)
 *** done
 *** done