Blame SOURCES/kvm-qemu-img-Change-info-key-names-for-protocol-nodes.patch

7f1c5b
From b1970c733dc46b2a8f648997a7e1c5d12900ff54 Mon Sep 17 00:00:00 2001
7f1c5b
From: Hanna Reitz <hreitz@redhat.com>
7f1c5b
Date: Mon, 20 Jun 2022 18:27:04 +0200
7f1c5b
Subject: [PATCH 17/20] qemu-img: Change info key names for protocol nodes
7f1c5b
7f1c5b
RH-Author: Hanna Czenczek <hreitz@redhat.com>
7f1c5b
RH-MergeRequest: 145: Show protocol-level information in qemu-img info
7f1c5b
RH-Bugzilla: 1860292
7f1c5b
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
7f1c5b
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
7f1c5b
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
7f1c5b
RH-Commit: [12/12] 67c260aaa05466410503fecee6210bf9d47e8c7c (hreitz/qemu-kvm-c-9-s)
7f1c5b
7f1c5b
Currently, when querying a qcow2 image, qemu-img info reports something
7f1c5b
like this:
7f1c5b
7f1c5b
image: test.qcow2
7f1c5b
file format: qcow2
7f1c5b
virtual size: 64 MiB (67108864 bytes)
7f1c5b
disk size: 196 KiB
7f1c5b
cluster_size: 65536
7f1c5b
Format specific information:
7f1c5b
    compat: 1.1
7f1c5b
    compression type: zlib
7f1c5b
    lazy refcounts: false
7f1c5b
    refcount bits: 16
7f1c5b
    corrupt: false
7f1c5b
    extended l2: false
7f1c5b
Child node '/file':
7f1c5b
    image: test.qcow2
7f1c5b
    file format: file
7f1c5b
    virtual size: 192 KiB (197120 bytes)
7f1c5b
    disk size: 196 KiB
7f1c5b
    Format specific information:
7f1c5b
        extent size hint: 1048576
7f1c5b
7f1c5b
Notably, the way the keys are named is specific for image files: The
7f1c5b
filename is shown under "image", the BDS driver under "file format", and
7f1c5b
the BDS length under "virtual size".  This does not make much sense for
7f1c5b
nodes that are not actually supposed to be guest images, like the /file
7f1c5b
child node shown above.
7f1c5b
7f1c5b
Give bdrv_node_info_dump() a @protocol parameter that gives a hint that
7f1c5b
the respective node is probably just used for data storage and does not
7f1c5b
necessarily present the data for a VM guest disk.  This renames the keys
7f1c5b
so that with this patch, the output becomes:
7f1c5b
7f1c5b
image: test.qcow2
7f1c5b
[...]
7f1c5b
Child node '/file':
7f1c5b
    filename: test.qcow2
7f1c5b
    protocol type: file
7f1c5b
    file length: 192 KiB (197120 bytes)
7f1c5b
    disk size: 196 KiB
7f1c5b
    Format specific information:
7f1c5b
        extent size hint: 1048576
7f1c5b
7f1c5b
(Perhaps we should also rename "Format specific information", but I
7f1c5b
could not come up with anything better that will not become problematic
7f1c5b
if we guess wrong with the protocol "heuristic".)
7f1c5b
7f1c5b
This change affects iotest 302, which has protocol node information in
7f1c5b
its reference output.
7f1c5b
7f1c5b
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
7f1c5b
Message-Id: <20220620162704.80987-13-hreitz@redhat.com>
7f1c5b
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
7f1c5b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
7f1c5b
(cherry picked from commit d570177b50c389f379f93183155a27d44856ab46)
7f1c5b
Signed-off-by: Hanna Czenczek <hreitz@redhat.com>
7f1c5b
---
7f1c5b
 block/monitor/block-hmp-cmds.c |  2 +-
7f1c5b
 block/qapi.c                   | 39 ++++++++++++++++++++++++++++------
7f1c5b
 include/block/qapi.h           |  2 +-
7f1c5b
 qemu-img.c                     |  3 ++-
7f1c5b
 tests/qemu-iotests/302.out     |  6 +++---
7f1c5b
 5 files changed, 39 insertions(+), 13 deletions(-)
7f1c5b
7f1c5b
diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c
7f1c5b
index 72824d4e2e..4d83339a5d 100644
7f1c5b
--- a/block/monitor/block-hmp-cmds.c
7f1c5b
+++ b/block/monitor/block-hmp-cmds.c
7f1c5b
@@ -734,7 +734,7 @@ static void print_block_info(Monitor *mon, BlockInfo *info,
7f1c5b
         monitor_printf(mon, "\nImages:\n");
7f1c5b
         image_info = inserted->image;
7f1c5b
         while (1) {
7f1c5b
-            bdrv_node_info_dump(qapi_ImageInfo_base(image_info), 0);
7f1c5b
+            bdrv_node_info_dump(qapi_ImageInfo_base(image_info), 0, false);
7f1c5b
             if (image_info->has_backing_image) {
7f1c5b
                 image_info = image_info->backing_image;
7f1c5b
             } else {
7f1c5b
diff --git a/block/qapi.c b/block/qapi.c
7f1c5b
index 3e35603f0c..56f398c500 100644
7f1c5b
--- a/block/qapi.c
7f1c5b
+++ b/block/qapi.c
7f1c5b
@@ -934,24 +934,49 @@ void bdrv_image_info_specific_dump(ImageInfoSpecific *info_spec,
7f1c5b
     visit_free(v);
7f1c5b
 }
7f1c5b
 
7f1c5b
-void bdrv_node_info_dump(BlockNodeInfo *info, int indentation)
7f1c5b
+/**
7f1c5b
+ * Print the given @info object in human-readable form.  Every field is indented
7f1c5b
+ * using the given @indentation (four spaces per indentation level).
7f1c5b
+ *
7f1c5b
+ * When using this to print a whole block graph, @protocol can be set to true to
7f1c5b
+ * signify that the given information is associated with a protocol node, i.e.
7f1c5b
+ * just data storage for an image, such that the data it presents is not really
7f1c5b
+ * a full VM disk.  If so, several fields change name: For example, "virtual
7f1c5b
+ * size" is printed as "file length".
7f1c5b
+ * (Consider a qcow2 image, which is represented by a qcow2 node and a file
7f1c5b
+ * node.  Printing a "virtual size" for the file node does not make sense,
7f1c5b
+ * because without the qcow2 node, it is not really a guest disk, so it does not
7f1c5b
+ * have a "virtual size".  Therefore, we call it "file length" instead.)
7f1c5b
+ *
7f1c5b
+ * @protocol is ignored when @indentation is 0, because we take that to mean
7f1c5b
+ * that the associated node is the root node in the queried block graph, and
7f1c5b
+ * thus is always to be interpreted as a standalone guest disk.
7f1c5b
+ */
7f1c5b
+void bdrv_node_info_dump(BlockNodeInfo *info, int indentation, bool protocol)
7f1c5b
 {
7f1c5b
     char *size_buf, *dsize_buf;
7f1c5b
     g_autofree char *ind_s = g_strdup_printf("%*s", indentation * 4, "");
7f1c5b
 
7f1c5b
+    if (indentation == 0) {
7f1c5b
+        /* Top level, consider this a normal image */
7f1c5b
+        protocol = false;
7f1c5b
+    }
7f1c5b
+
7f1c5b
     if (!info->has_actual_size) {
7f1c5b
         dsize_buf = g_strdup("unavailable");
7f1c5b
     } else {
7f1c5b
         dsize_buf = size_to_str(info->actual_size);
7f1c5b
     }
7f1c5b
     size_buf = size_to_str(info->virtual_size);
7f1c5b
-    qemu_printf("%simage: %s\n"
7f1c5b
-                "%sfile format: %s\n"
7f1c5b
-                "%svirtual size: %s (%" PRId64 " bytes)\n"
7f1c5b
+    qemu_printf("%s%s: %s\n"
7f1c5b
+                "%s%s: %s\n"
7f1c5b
+                "%s%s: %s (%" PRId64 " bytes)\n"
7f1c5b
                 "%sdisk size: %s\n",
7f1c5b
-                ind_s, info->filename,
7f1c5b
-                ind_s, info->format,
7f1c5b
-                ind_s, size_buf, info->virtual_size,
7f1c5b
+                ind_s, protocol ? "filename" : "image", info->filename,
7f1c5b
+                ind_s, protocol ? "protocol type" : "file format",
7f1c5b
+                info->format,
7f1c5b
+                ind_s, protocol ? "file length" : "virtual size",
7f1c5b
+                size_buf, info->virtual_size,
7f1c5b
                 ind_s, dsize_buf);
7f1c5b
     g_free(size_buf);
7f1c5b
     g_free(dsize_buf);
7f1c5b
diff --git a/include/block/qapi.h b/include/block/qapi.h
7f1c5b
index 38855f2ae9..26113da21a 100644
7f1c5b
--- a/include/block/qapi.h
7f1c5b
+++ b/include/block/qapi.h
7f1c5b
@@ -51,5 +51,5 @@ void bdrv_snapshot_dump(QEMUSnapshotInfo *sn);
7f1c5b
 void bdrv_image_info_specific_dump(ImageInfoSpecific *info_spec,
7f1c5b
                                    const char *prefix,
7f1c5b
                                    int indentation);
7f1c5b
-void bdrv_node_info_dump(BlockNodeInfo *info, int indentation);
7f1c5b
+void bdrv_node_info_dump(BlockNodeInfo *info, int indentation, bool protocol);
7f1c5b
 #endif
7f1c5b
diff --git a/qemu-img.c b/qemu-img.c
7f1c5b
index e281011245..2943625c67 100644
7f1c5b
--- a/qemu-img.c
7f1c5b
+++ b/qemu-img.c
7f1c5b
@@ -2853,7 +2853,8 @@ static void dump_human_image_info(BlockGraphInfo *info, int indentation,
7f1c5b
 {
7f1c5b
     BlockChildInfoList *children_list;
7f1c5b
 
7f1c5b
-    bdrv_node_info_dump(qapi_BlockGraphInfo_base(info), indentation);
7f1c5b
+    bdrv_node_info_dump(qapi_BlockGraphInfo_base(info), indentation,
7f1c5b
+                        info->children == NULL);
7f1c5b
 
7f1c5b
     for (children_list = info->children; children_list;
7f1c5b
          children_list = children_list->next)
7f1c5b
diff --git a/tests/qemu-iotests/302.out b/tests/qemu-iotests/302.out
7f1c5b
index edfa1c4f05..7b5014cdd8 100644
7f1c5b
--- a/tests/qemu-iotests/302.out
7f1c5b
+++ b/tests/qemu-iotests/302.out
7f1c5b
@@ -5,9 +5,9 @@ file format: raw
7f1c5b
 virtual size: 448 KiB (458752 bytes)
7f1c5b
 disk size: unavailable
7f1c5b
 Child node '/file':
7f1c5b
-    image: nbd+unix:///exp?socket=SOCK_DIR/PID-nbd-sock
7f1c5b
-    file format: nbd
7f1c5b
-    virtual size: 448 KiB (458752 bytes)
7f1c5b
+    filename: nbd+unix:///exp?socket=SOCK_DIR/PID-nbd-sock
7f1c5b
+    protocol type: nbd
7f1c5b
+    file length: 448 KiB (458752 bytes)
7f1c5b
     disk size: unavailable
7f1c5b
 
7f1c5b
 === Converted image info ===
7f1c5b
-- 
7f1c5b
2.31.1
7f1c5b