thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 8 months ago
Clone
7f1c5b
From c8c282c2e1d74cfc5de6527f7e20dfc3e76b67ac Mon Sep 17 00:00:00 2001
7f1c5b
From: Hanna Reitz <hreitz@redhat.com>
7f1c5b
Date: Mon, 20 Jun 2022 18:27:00 +0200
7f1c5b
Subject: [PATCH 13/20] block/qapi: Add indentation to bdrv_node_info_dump()
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: [8/12] d3a697e81ab9828457198075e5815a592363c725 (hreitz/qemu-kvm-c-9-s)
7f1c5b
7f1c5b
In order to let qemu-img info present a block graph, add a parameter to
7f1c5b
bdrv_node_info_dump() and bdrv_image_info_specific_dump() so that the
7f1c5b
information of nodes below the root level can be given an indentation.
7f1c5b
7f1c5b
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
7f1c5b
Message-Id: <20220620162704.80987-9-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 76c9e9750d1bd580e8ed4465f6be3a986434e7c3)
7f1c5b
Signed-off-by: Hanna Czenczek <hreitz@redhat.com>
7f1c5b
---
7f1c5b
 block/monitor/block-hmp-cmds.c |  2 +-
7f1c5b
 block/qapi.c                   | 47 +++++++++++++++++++---------------
7f1c5b
 include/block/qapi.h           |  5 ++--
7f1c5b
 qemu-img.c                     |  2 +-
7f1c5b
 qemu-io-cmds.c                 |  3 ++-
7f1c5b
 5 files changed, 34 insertions(+), 25 deletions(-)
7f1c5b
7f1c5b
diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c
7f1c5b
index aa37faa601..72824d4e2e 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));
7f1c5b
+            bdrv_node_info_dump(qapi_ImageInfo_base(image_info), 0);
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 f208c21ccf..3e35603f0c 100644
7f1c5b
--- a/block/qapi.c
7f1c5b
+++ b/block/qapi.c
7f1c5b
@@ -915,7 +915,8 @@ static bool qobject_is_empty_dump(const QObject *obj)
7f1c5b
  * prepending an optional prefix if the dump is not empty.
7f1c5b
  */
7f1c5b
 void bdrv_image_info_specific_dump(ImageInfoSpecific *info_spec,
7f1c5b
-                                   const char *prefix)
7f1c5b
+                                   const char *prefix,
7f1c5b
+                                   int indentation)
7f1c5b
 {
7f1c5b
     QObject *obj, *data;
7f1c5b
     Visitor *v = qobject_output_visitor_new(&obj);
7f1c5b
@@ -925,48 +926,51 @@ void bdrv_image_info_specific_dump(ImageInfoSpecific *info_spec,
7f1c5b
     data = qdict_get(qobject_to(QDict, obj), "data");
7f1c5b
     if (!qobject_is_empty_dump(data)) {
7f1c5b
         if (prefix) {
7f1c5b
-            qemu_printf("%s", prefix);
7f1c5b
+            qemu_printf("%*s%s", indentation * 4, "", prefix);
7f1c5b
         }
7f1c5b
-        dump_qobject(1, data);
7f1c5b
+        dump_qobject(indentation + 1, data);
7f1c5b
     }
7f1c5b
     qobject_unref(obj);
7f1c5b
     visit_free(v);
7f1c5b
 }
7f1c5b
 
7f1c5b
-void bdrv_node_info_dump(BlockNodeInfo *info)
7f1c5b
+void bdrv_node_info_dump(BlockNodeInfo *info, int indentation)
7f1c5b
 {
7f1c5b
     char *size_buf, *dsize_buf;
7f1c5b
+    g_autofree char *ind_s = g_strdup_printf("%*s", indentation * 4, "");
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("image: %s\n"
7f1c5b
-                "file format: %s\n"
7f1c5b
-                "virtual size: %s (%" PRId64 " bytes)\n"
7f1c5b
-                "disk size: %s\n",
7f1c5b
-                info->filename, info->format, size_buf,
7f1c5b
-                info->virtual_size,
7f1c5b
-                dsize_buf);
7f1c5b
+    qemu_printf("%simage: %s\n"
7f1c5b
+                "%sfile format: %s\n"
7f1c5b
+                "%svirtual size: %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, dsize_buf);
7f1c5b
     g_free(size_buf);
7f1c5b
     g_free(dsize_buf);
7f1c5b
 
7f1c5b
     if (info->has_encrypted && info->encrypted) {
7f1c5b
-        qemu_printf("encrypted: yes\n");
7f1c5b
+        qemu_printf("%sencrypted: yes\n", ind_s);
7f1c5b
     }
7f1c5b
 
7f1c5b
     if (info->has_cluster_size) {
7f1c5b
-        qemu_printf("cluster_size: %" PRId64 "\n",
7f1c5b
-                    info->cluster_size);
7f1c5b
+        qemu_printf("%scluster_size: %" PRId64 "\n",
7f1c5b
+                    ind_s, info->cluster_size);
7f1c5b
     }
7f1c5b
 
7f1c5b
     if (info->has_dirty_flag && info->dirty_flag) {
7f1c5b
-        qemu_printf("cleanly shut down: no\n");
7f1c5b
+        qemu_printf("%scleanly shut down: no\n", ind_s);
7f1c5b
     }
7f1c5b
 
7f1c5b
     if (info->has_backing_filename) {
7f1c5b
-        qemu_printf("backing file: %s", info->backing_filename);
7f1c5b
+        qemu_printf("%sbacking file: %s", ind_s, info->backing_filename);
7f1c5b
         if (!info->has_full_backing_filename) {
7f1c5b
             qemu_printf(" (cannot determine actual path)");
7f1c5b
         } else if (strcmp(info->backing_filename,
7f1c5b
@@ -975,15 +979,16 @@ void bdrv_node_info_dump(BlockNodeInfo *info)
7f1c5b
         }
7f1c5b
         qemu_printf("\n");
7f1c5b
         if (info->has_backing_filename_format) {
7f1c5b
-            qemu_printf("backing file format: %s\n",
7f1c5b
-                        info->backing_filename_format);
7f1c5b
+            qemu_printf("%sbacking file format: %s\n",
7f1c5b
+                        ind_s, info->backing_filename_format);
7f1c5b
         }
7f1c5b
     }
7f1c5b
 
7f1c5b
     if (info->has_snapshots) {
7f1c5b
         SnapshotInfoList *elem;
7f1c5b
 
7f1c5b
-        qemu_printf("Snapshot list:\n");
7f1c5b
+        qemu_printf("%sSnapshot list:\n", ind_s);
7f1c5b
+        qemu_printf("%s", ind_s);
7f1c5b
         bdrv_snapshot_dump(NULL);
7f1c5b
         qemu_printf("\n");
7f1c5b
 
7f1c5b
@@ -1003,6 +1008,7 @@ void bdrv_node_info_dump(BlockNodeInfo *info)
7f1c5b
 
7f1c5b
             pstrcpy(sn.id_str, sizeof(sn.id_str), elem->value->id);
7f1c5b
             pstrcpy(sn.name, sizeof(sn.name), elem->value->name);
7f1c5b
+            qemu_printf("%s", ind_s);
7f1c5b
             bdrv_snapshot_dump(&sn;;
7f1c5b
             qemu_printf("\n");
7f1c5b
         }
7f1c5b
@@ -1010,6 +1016,7 @@ void bdrv_node_info_dump(BlockNodeInfo *info)
7f1c5b
 
7f1c5b
     if (info->has_format_specific) {
7f1c5b
         bdrv_image_info_specific_dump(info->format_specific,
7f1c5b
-                                      "Format specific information:\n");
7f1c5b
+                                      "Format specific information:\n",
7f1c5b
+                                      indentation);
7f1c5b
     }
7f1c5b
 }
7f1c5b
diff --git a/include/block/qapi.h b/include/block/qapi.h
7f1c5b
index 196436020e..38855f2ae9 100644
7f1c5b
--- a/include/block/qapi.h
7f1c5b
+++ b/include/block/qapi.h
7f1c5b
@@ -49,6 +49,7 @@ void bdrv_query_block_graph_info(BlockDriverState *bs,
7f1c5b
 
7f1c5b
 void bdrv_snapshot_dump(QEMUSnapshotInfo *sn);
7f1c5b
 void bdrv_image_info_specific_dump(ImageInfoSpecific *info_spec,
7f1c5b
-                                   const char *prefix);
7f1c5b
-void bdrv_node_info_dump(BlockNodeInfo *info);
7f1c5b
+                                   const char *prefix,
7f1c5b
+                                   int indentation);
7f1c5b
+void bdrv_node_info_dump(BlockNodeInfo *info, int indentation);
7f1c5b
 #endif
7f1c5b
diff --git a/qemu-img.c b/qemu-img.c
7f1c5b
index 3b2ca3bbcb..30b4ea58bb 100644
7f1c5b
--- a/qemu-img.c
7f1c5b
+++ b/qemu-img.c
7f1c5b
@@ -2859,7 +2859,7 @@ static void dump_human_image_info_list(BlockNodeInfoList *list)
7f1c5b
         }
7f1c5b
         delim = true;
7f1c5b
 
7f1c5b
-        bdrv_node_info_dump(elem->value);
7f1c5b
+        bdrv_node_info_dump(elem->value, 0);
7f1c5b
     }
7f1c5b
 }
7f1c5b
 
7f1c5b
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
7f1c5b
index f4a374528e..fdcb89211b 100644
7f1c5b
--- a/qemu-io-cmds.c
7f1c5b
+++ b/qemu-io-cmds.c
7f1c5b
@@ -1826,7 +1826,8 @@ static int info_f(BlockBackend *blk, int argc, char **argv)
7f1c5b
     }
7f1c5b
     if (spec_info) {
7f1c5b
         bdrv_image_info_specific_dump(spec_info,
7f1c5b
-                                      "Format specific information:\n");
7f1c5b
+                                      "Format specific information:\n",
7f1c5b
+                                      0);
7f1c5b
         qapi_free_ImageInfoSpecific(spec_info);
7f1c5b
     }
7f1c5b
 
7f1c5b
-- 
7f1c5b
2.31.1
7f1c5b