ed5979
From dca4cbe680baff837ca8ac8bd39b77b46af3f64b Mon Sep 17 00:00:00 2001
ed5979
From: Hanna Reitz <hreitz@redhat.com>
ed5979
Date: Mon, 20 Jun 2022 18:26:57 +0200
ed5979
Subject: [PATCH 10/20] qemu-img: Use BlockNodeInfo
ed5979
ed5979
RH-Author: Hanna Czenczek <hreitz@redhat.com>
ed5979
RH-MergeRequest: 145: Show protocol-level information in qemu-img info
ed5979
RH-Bugzilla: 1860292
ed5979
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
ed5979
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
ed5979
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
ed5979
RH-Commit: [5/12] b599af3ec05951a0ba11d9eae2ee19148d6bf624 (hreitz/qemu-kvm-c-9-s)
ed5979
ed5979
qemu-img info never uses ImageInfo's backing-image field, because it
ed5979
opens the backing chain one by one with BDRV_O_NO_BACKING, and prints
ed5979
all backing chain nodes' information consecutively.  Use BlockNodeInfo
ed5979
to make it clear that we only print information about a single node, and
ed5979
that we are not using the backing-image field.
ed5979
ed5979
Notably, bdrv_image_info_dump() does not evaluate the backing-image
ed5979
field, so we can easily make it take a BlockNodeInfo pointer (and
ed5979
consequentially rename it to bdrv_node_info_dump()).  It makes more
ed5979
sense this way, because again, the interface now makes it syntactically
ed5979
clear that backing-image is ignored by this function.
ed5979
ed5979
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
ed5979
Message-Id: <20220620162704.80987-6-hreitz@redhat.com>
ed5979
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
ed5979
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
ed5979
(cherry picked from commit b1f4cd1589a16fec02f264a09bd3560e4ccce3c2)
ed5979
Signed-off-by: Hanna Czenczek <hreitz@redhat.com>
ed5979
---
ed5979
 block/monitor/block-hmp-cmds.c |  2 +-
ed5979
 block/qapi.c                   |  2 +-
ed5979
 include/block/qapi.h           |  2 +-
ed5979
 qapi/block-core.json           |  4 +--
ed5979
 qemu-img.c                     | 48 +++++++++++++++++-----------------
ed5979
 5 files changed, 29 insertions(+), 29 deletions(-)
ed5979
ed5979
diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c
ed5979
index b6135e9bfe..aa37faa601 100644
ed5979
--- a/block/monitor/block-hmp-cmds.c
ed5979
+++ b/block/monitor/block-hmp-cmds.c
ed5979
@@ -734,7 +734,7 @@ static void print_block_info(Monitor *mon, BlockInfo *info,
ed5979
         monitor_printf(mon, "\nImages:\n");
ed5979
         image_info = inserted->image;
ed5979
         while (1) {
ed5979
-                bdrv_image_info_dump(image_info);
ed5979
+            bdrv_node_info_dump(qapi_ImageInfo_base(image_info));
ed5979
             if (image_info->has_backing_image) {
ed5979
                 image_info = image_info->backing_image;
ed5979
             } else {
ed5979
diff --git a/block/qapi.c b/block/qapi.c
ed5979
index e5022b4481..ad88bf9b38 100644
ed5979
--- a/block/qapi.c
ed5979
+++ b/block/qapi.c
ed5979
@@ -865,7 +865,7 @@ void bdrv_image_info_specific_dump(ImageInfoSpecific *info_spec,
ed5979
     visit_free(v);
ed5979
 }
ed5979
 
ed5979
-void bdrv_image_info_dump(ImageInfo *info)
ed5979
+void bdrv_node_info_dump(BlockNodeInfo *info)
ed5979
 {
ed5979
     char *size_buf, *dsize_buf;
ed5979
     if (!info->has_actual_size) {
ed5979
diff --git a/include/block/qapi.h b/include/block/qapi.h
ed5979
index c7de4e3fa9..22198dcd0c 100644
ed5979
--- a/include/block/qapi.h
ed5979
+++ b/include/block/qapi.h
ed5979
@@ -45,5 +45,5 @@ void bdrv_query_image_info(BlockDriverState *bs,
ed5979
 void bdrv_snapshot_dump(QEMUSnapshotInfo *sn);
ed5979
 void bdrv_image_info_specific_dump(ImageInfoSpecific *info_spec,
ed5979
                                    const char *prefix);
ed5979
-void bdrv_image_info_dump(ImageInfo *info);
ed5979
+void bdrv_node_info_dump(BlockNodeInfo *info);
ed5979
 #endif
ed5979
diff --git a/qapi/block-core.json b/qapi/block-core.json
ed5979
index 7720da0498..4cf2deeb6c 100644
ed5979
--- a/qapi/block-core.json
ed5979
+++ b/qapi/block-core.json
ed5979
@@ -5796,9 +5796,9 @@
ed5979
 ##
ed5979
 # @DummyBlockCoreForceArrays:
ed5979
 #
ed5979
-# Not used by QMP; hack to let us use ImageInfoList internally
ed5979
+# Not used by QMP; hack to let us use BlockNodeInfoList internally
ed5979
 #
ed5979
 # Since: 8.0
ed5979
 ##
ed5979
 { 'struct': 'DummyBlockCoreForceArrays',
ed5979
-  'data': { 'unused-image-info': ['ImageInfo'] } }
ed5979
+  'data': { 'unused-block-node-info': ['BlockNodeInfo'] } }
ed5979
diff --git a/qemu-img.c b/qemu-img.c
ed5979
index 2f85bb7ede..3b2ca3bbcb 100644
ed5979
--- a/qemu-img.c
ed5979
+++ b/qemu-img.c
ed5979
@@ -2816,13 +2816,13 @@ static void dump_snapshots(BlockDriverState *bs)
ed5979
     g_free(sn_tab);
ed5979
 }
ed5979
 
ed5979
-static void dump_json_image_info_list(ImageInfoList *list)
ed5979
+static void dump_json_block_node_info_list(BlockNodeInfoList *list)
ed5979
 {
ed5979
     GString *str;
ed5979
     QObject *obj;
ed5979
     Visitor *v = qobject_output_visitor_new(&obj);
ed5979
 
ed5979
-    visit_type_ImageInfoList(v, NULL, &list, &error_abort);
ed5979
+    visit_type_BlockNodeInfoList(v, NULL, &list, &error_abort);
ed5979
     visit_complete(v, &obj);
ed5979
     str = qobject_to_json_pretty(obj, true);
ed5979
     assert(str != NULL);
ed5979
@@ -2832,13 +2832,13 @@ static void dump_json_image_info_list(ImageInfoList *list)
ed5979
     g_string_free(str, true);
ed5979
 }
ed5979
 
ed5979
-static void dump_json_image_info(ImageInfo *info)
ed5979
+static void dump_json_block_node_info(BlockNodeInfo *info)
ed5979
 {
ed5979
     GString *str;
ed5979
     QObject *obj;
ed5979
     Visitor *v = qobject_output_visitor_new(&obj);
ed5979
 
ed5979
-    visit_type_ImageInfo(v, NULL, &info, &error_abort);
ed5979
+    visit_type_BlockNodeInfo(v, NULL, &info, &error_abort);
ed5979
     visit_complete(v, &obj);
ed5979
     str = qobject_to_json_pretty(obj, true);
ed5979
     assert(str != NULL);
ed5979
@@ -2848,9 +2848,9 @@ static void dump_json_image_info(ImageInfo *info)
ed5979
     g_string_free(str, true);
ed5979
 }
ed5979
 
ed5979
-static void dump_human_image_info_list(ImageInfoList *list)
ed5979
+static void dump_human_image_info_list(BlockNodeInfoList *list)
ed5979
 {
ed5979
-    ImageInfoList *elem;
ed5979
+    BlockNodeInfoList *elem;
ed5979
     bool delim = false;
ed5979
 
ed5979
     for (elem = list; elem; elem = elem->next) {
ed5979
@@ -2859,7 +2859,7 @@ static void dump_human_image_info_list(ImageInfoList *list)
ed5979
         }
ed5979
         delim = true;
ed5979
 
ed5979
-        bdrv_image_info_dump(elem->value);
ed5979
+        bdrv_node_info_dump(elem->value);
ed5979
     }
ed5979
 }
ed5979
 
ed5979
@@ -2869,24 +2869,24 @@ static gboolean str_equal_func(gconstpointer a, gconstpointer b)
ed5979
 }
ed5979
 
ed5979
 /**
ed5979
- * Open an image file chain and return an ImageInfoList
ed5979
+ * Open an image file chain and return an BlockNodeInfoList
ed5979
  *
ed5979
  * @filename: topmost image filename
ed5979
  * @fmt: topmost image format (may be NULL to autodetect)
ed5979
  * @chain: true  - enumerate entire backing file chain
ed5979
  *         false - only topmost image file
ed5979
  *
ed5979
- * Returns a list of ImageInfo objects or NULL if there was an error opening an
ed5979
- * image file.  If there was an error a message will have been printed to
ed5979
- * stderr.
ed5979
+ * Returns a list of BlockNodeInfo objects or NULL if there was an error
ed5979
+ * opening an image file.  If there was an error a message will have been
ed5979
+ * printed to stderr.
ed5979
  */
ed5979
-static ImageInfoList *collect_image_info_list(bool image_opts,
ed5979
-                                              const char *filename,
ed5979
-                                              const char *fmt,
ed5979
-                                              bool chain, bool force_share)
ed5979
+static BlockNodeInfoList *collect_image_info_list(bool image_opts,
ed5979
+                                                  const char *filename,
ed5979
+                                                  const char *fmt,
ed5979
+                                                  bool chain, bool force_share)
ed5979
 {
ed5979
-    ImageInfoList *head = NULL;
ed5979
-    ImageInfoList **tail = &head;
ed5979
+    BlockNodeInfoList *head = NULL;
ed5979
+    BlockNodeInfoList **tail = &head;
ed5979
     GHashTable *filenames;
ed5979
     Error *err = NULL;
ed5979
 
ed5979
@@ -2895,7 +2895,7 @@ static ImageInfoList *collect_image_info_list(bool image_opts,
ed5979
     while (filename) {
ed5979
         BlockBackend *blk;
ed5979
         BlockDriverState *bs;
ed5979
-        ImageInfo *info;
ed5979
+        BlockNodeInfo *info;
ed5979
 
ed5979
         if (g_hash_table_lookup_extended(filenames, filename, NULL, NULL)) {
ed5979
             error_report("Backing file '%s' creates an infinite loop.",
ed5979
@@ -2912,7 +2912,7 @@ static ImageInfoList *collect_image_info_list(bool image_opts,
ed5979
         }
ed5979
         bs = blk_bs(blk);
ed5979
 
ed5979
-        bdrv_query_image_info(bs, &info, &err;;
ed5979
+        bdrv_query_block_node_info(bs, &info, &err;;
ed5979
         if (err) {
ed5979
             error_report_err(err);
ed5979
             blk_unref(blk);
ed5979
@@ -2945,7 +2945,7 @@ static ImageInfoList *collect_image_info_list(bool image_opts,
ed5979
     return head;
ed5979
 
ed5979
 err:
ed5979
-    qapi_free_ImageInfoList(head);
ed5979
+    qapi_free_BlockNodeInfoList(head);
ed5979
     g_hash_table_destroy(filenames);
ed5979
     return NULL;
ed5979
 }
ed5979
@@ -2956,7 +2956,7 @@ static int img_info(int argc, char **argv)
ed5979
     OutputFormat output_format = OFORMAT_HUMAN;
ed5979
     bool chain = false;
ed5979
     const char *filename, *fmt, *output;
ed5979
-    ImageInfoList *list;
ed5979
+    BlockNodeInfoList *list;
ed5979
     bool image_opts = false;
ed5979
     bool force_share = false;
ed5979
 
ed5979
@@ -3035,14 +3035,14 @@ static int img_info(int argc, char **argv)
ed5979
         break;
ed5979
     case OFORMAT_JSON:
ed5979
         if (chain) {
ed5979
-            dump_json_image_info_list(list);
ed5979
+            dump_json_block_node_info_list(list);
ed5979
         } else {
ed5979
-            dump_json_image_info(list->value);
ed5979
+            dump_json_block_node_info(list->value);
ed5979
         }
ed5979
         break;
ed5979
     }
ed5979
 
ed5979
-    qapi_free_ImageInfoList(list);
ed5979
+    qapi_free_BlockNodeInfoList(list);
ed5979
     return 0;
ed5979
 }
ed5979
 
ed5979
-- 
ed5979
2.31.1
ed5979