thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
ed5979
From 54e290df4bc1c9e83be7357caed6a2b1ba4f21f0 Mon Sep 17 00:00:00 2001
ed5979
From: Hanna Reitz <hreitz@redhat.com>
ed5979
Date: Mon, 20 Jun 2022 18:26:56 +0200
ed5979
Subject: [PATCH 09/20] block: Split BlockNodeInfo off of ImageInfo
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: [4/12] fc8d69d549bb9a929db218b91697ee3ae95c1ff6 (hreitz/qemu-kvm-c-9-s)
ed5979
ed5979
ImageInfo sometimes contains flat information, and sometimes it does
ed5979
not.  Split off a BlockNodeInfo struct, which only contains information
ed5979
about a single node and has no link to the backing image.
ed5979
ed5979
We do this so we can extend BlockNodeInfo to a BlockGraphInfo struct,
ed5979
which has links to all child nodes, not just the backing node.  It would
ed5979
be strange to base BlockGraphInfo on ImageInfo, because then this
ed5979
extended struct would have two links to the backing node (one in
ed5979
BlockGraphInfo as one of all the child links, and one in ImageInfo).
ed5979
ed5979
Furthermore, it is quite common to ignore the backing-image field
ed5979
altogether: bdrv_query_image_info() does not set it, and
ed5979
bdrv_image_info_dump() does not evaluate it.  That signals that we
ed5979
should have different structs for describing a single node and one that
ed5979
has a link to the backing image.
ed5979
ed5979
Still, bdrv_query_image_info() and bdrv_image_info_dump() are not
ed5979
changed too much in this patch.  Follow-up patches will handle them.
ed5979
ed5979
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
ed5979
Message-Id: <20220620162704.80987-5-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 a2085f8909377b6df738f6c3f7ee6db4d16da8f7)
ed5979
Signed-off-by: Hanna Czenczek <hreitz@redhat.com>
ed5979
---
ed5979
 block/qapi.c         | 86 ++++++++++++++++++++++++++++++++------------
ed5979
 include/block/qapi.h |  3 ++
ed5979
 qapi/block-core.json | 24 +++++++++----
ed5979
 3 files changed, 85 insertions(+), 28 deletions(-)
ed5979
ed5979
diff --git a/block/qapi.c b/block/qapi.c
ed5979
index 51202b470a..e5022b4481 100644
ed5979
--- a/block/qapi.c
ed5979
+++ b/block/qapi.c
ed5979
@@ -241,30 +241,18 @@ int bdrv_query_snapshot_info_list(BlockDriverState *bs,
ed5979
 }
ed5979
 
ed5979
 /**
ed5979
- * bdrv_query_image_info:
ed5979
- * @bs: block device to examine
ed5979
- * @p_info: location to store image information
ed5979
- * @errp: location to store error information
ed5979
- *
ed5979
- * Store "flat" image information in @p_info.
ed5979
- *
ed5979
- * "Flat" means it does *not* query backing image information,
ed5979
- * i.e. (*pinfo)->has_backing_image will be set to false and
ed5979
- * (*pinfo)->backing_image to NULL even when the image does in fact have
ed5979
- * a backing image.
ed5979
- *
ed5979
- * @p_info will be set only on success. On error, store error in @errp.
ed5979
+ * Helper function for other query info functions.  Store information about @bs
ed5979
+ * in @info, setting @errp on error.
ed5979
  */
ed5979
-void bdrv_query_image_info(BlockDriverState *bs,
ed5979
-                           ImageInfo **p_info,
ed5979
-                           Error **errp)
ed5979
+static void bdrv_do_query_node_info(BlockDriverState *bs,
ed5979
+                                    BlockNodeInfo *info,
ed5979
+                                    Error **errp)
ed5979
 {
ed5979
     int64_t size;
ed5979
     const char *backing_filename;
ed5979
     BlockDriverInfo bdi;
ed5979
     int ret;
ed5979
     Error *err = NULL;
ed5979
-    ImageInfo *info;
ed5979
 
ed5979
     aio_context_acquire(bdrv_get_aio_context(bs));
ed5979
 
ed5979
@@ -277,7 +265,6 @@ void bdrv_query_image_info(BlockDriverState *bs,
ed5979
 
ed5979
     bdrv_refresh_filename(bs);
ed5979
 
ed5979
-    info = g_new0(ImageInfo, 1);
ed5979
     info->filename        = g_strdup(bs->filename);
ed5979
     info->format          = g_strdup(bdrv_get_format_name(bs));
ed5979
     info->virtual_size    = size;
ed5979
@@ -298,7 +285,6 @@ void bdrv_query_image_info(BlockDriverState *bs,
ed5979
     info->format_specific = bdrv_get_specific_info(bs, &err;;
ed5979
     if (err) {
ed5979
         error_propagate(errp, err);
ed5979
-        qapi_free_ImageInfo(info);
ed5979
         goto out;
ed5979
     }
ed5979
     info->has_format_specific = info->format_specific != NULL;
ed5979
@@ -339,16 +325,72 @@ void bdrv_query_image_info(BlockDriverState *bs,
ed5979
         break;
ed5979
     default:
ed5979
         error_propagate(errp, err);
ed5979
-        qapi_free_ImageInfo(info);
ed5979
         goto out;
ed5979
     }
ed5979
 
ed5979
-    *p_info = info;
ed5979
-
ed5979
 out:
ed5979
     aio_context_release(bdrv_get_aio_context(bs));
ed5979
 }
ed5979
 
ed5979
+/**
ed5979
+ * bdrv_query_block_node_info:
ed5979
+ * @bs: block node to examine
ed5979
+ * @p_info: location to store node information
ed5979
+ * @errp: location to store error information
ed5979
+ *
ed5979
+ * Store image information about @bs in @p_info.
ed5979
+ *
ed5979
+ * @p_info will be set only on success. On error, store error in @errp.
ed5979
+ */
ed5979
+void bdrv_query_block_node_info(BlockDriverState *bs,
ed5979
+                                BlockNodeInfo **p_info,
ed5979
+                                Error **errp)
ed5979
+{
ed5979
+    BlockNodeInfo *info;
ed5979
+    ERRP_GUARD();
ed5979
+
ed5979
+    info = g_new0(BlockNodeInfo, 1);
ed5979
+    bdrv_do_query_node_info(bs, info, errp);
ed5979
+    if (*errp) {
ed5979
+        qapi_free_BlockNodeInfo(info);
ed5979
+        return;
ed5979
+    }
ed5979
+
ed5979
+    *p_info = info;
ed5979
+}
ed5979
+
ed5979
+/**
ed5979
+ * bdrv_query_image_info:
ed5979
+ * @bs: block node to examine
ed5979
+ * @p_info: location to store image information
ed5979
+ * @errp: location to store error information
ed5979
+ *
ed5979
+ * Store "flat" image information in @p_info.
ed5979
+ *
ed5979
+ * "Flat" means it does *not* query backing image information,
ed5979
+ * i.e. (*pinfo)->has_backing_image will be set to false and
ed5979
+ * (*pinfo)->backing_image to NULL even when the image does in fact have
ed5979
+ * a backing image.
ed5979
+ *
ed5979
+ * @p_info will be set only on success. On error, store error in @errp.
ed5979
+ */
ed5979
+void bdrv_query_image_info(BlockDriverState *bs,
ed5979
+                           ImageInfo **p_info,
ed5979
+                           Error **errp)
ed5979
+{
ed5979
+    ImageInfo *info;
ed5979
+    ERRP_GUARD();
ed5979
+
ed5979
+    info = g_new0(ImageInfo, 1);
ed5979
+    bdrv_do_query_node_info(bs, qapi_ImageInfo_base(info), errp);
ed5979
+    if (*errp) {
ed5979
+        qapi_free_ImageInfo(info);
ed5979
+        return;
ed5979
+    }
ed5979
+
ed5979
+    *p_info = info;
ed5979
+}
ed5979
+
ed5979
 /* @p_info will be set only on success. */
ed5979
 static void bdrv_query_info(BlockBackend *blk, BlockInfo **p_info,
ed5979
                             Error **errp)
ed5979
diff --git a/include/block/qapi.h b/include/block/qapi.h
ed5979
index c09859ea78..c7de4e3fa9 100644
ed5979
--- a/include/block/qapi.h
ed5979
+++ b/include/block/qapi.h
ed5979
@@ -35,6 +35,9 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *blk,
ed5979
 int bdrv_query_snapshot_info_list(BlockDriverState *bs,
ed5979
                                   SnapshotInfoList **p_list,
ed5979
                                   Error **errp);
ed5979
+void bdrv_query_block_node_info(BlockDriverState *bs,
ed5979
+                                BlockNodeInfo **p_info,
ed5979
+                                Error **errp);
ed5979
 void bdrv_query_image_info(BlockDriverState *bs,
ed5979
                            ImageInfo **p_info,
ed5979
                            Error **errp);
ed5979
diff --git a/qapi/block-core.json b/qapi/block-core.json
ed5979
index 4b9365167f..7720da0498 100644
ed5979
--- a/qapi/block-core.json
ed5979
+++ b/qapi/block-core.json
ed5979
@@ -251,7 +251,7 @@
ed5979
   } }
ed5979
 
ed5979
 ##
ed5979
-# @ImageInfo:
ed5979
+# @BlockNodeInfo:
ed5979
 #
ed5979
 # Information about a QEMU image file
ed5979
 #
ed5979
@@ -279,22 +279,34 @@
ed5979
 #
ed5979
 # @snapshots: list of VM snapshots
ed5979
 #
ed5979
-# @backing-image: info of the backing image (since 1.6)
ed5979
-#
ed5979
 # @format-specific: structure supplying additional format-specific
ed5979
 #                   information (since 1.7)
ed5979
 #
ed5979
-# Since: 1.3
ed5979
+# Since: 8.0
ed5979
 ##
ed5979
-{ 'struct': 'ImageInfo',
ed5979
+{ 'struct': 'BlockNodeInfo',
ed5979
   'data': {'filename': 'str', 'format': 'str', '*dirty-flag': 'bool',
ed5979
            '*actual-size': 'int', 'virtual-size': 'int',
ed5979
            '*cluster-size': 'int', '*encrypted': 'bool', '*compressed': 'bool',
ed5979
            '*backing-filename': 'str', '*full-backing-filename': 'str',
ed5979
            '*backing-filename-format': 'str', '*snapshots': ['SnapshotInfo'],
ed5979
-           '*backing-image': 'ImageInfo',
ed5979
            '*format-specific': 'ImageInfoSpecific' } }
ed5979
 
ed5979
+##
ed5979
+# @ImageInfo:
ed5979
+#
ed5979
+# Information about a QEMU image file, and potentially its backing image
ed5979
+#
ed5979
+# @backing-image: info of the backing image
ed5979
+#
ed5979
+# Since: 1.3
ed5979
+##
ed5979
+{ 'struct': 'ImageInfo',
ed5979
+  'base': 'BlockNodeInfo',
ed5979
+  'data': {
ed5979
+      '*backing-image': 'ImageInfo'
ed5979
+  } }
ed5979
+
ed5979
 ##
ed5979
 # @ImageCheck:
ed5979
 #
ed5979
-- 
ed5979
2.31.1
ed5979