yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-qmp-add-ImageInfo-in-BlockDeviceInfo-used-by-query-b.patch

9ae3a8
From 5c10b431d0dd4538d33c21d7a46f7c8754f42a83 Mon Sep 17 00:00:00 2001
9ae3a8
From: Max Reitz <mreitz@redhat.com>
9ae3a8
Date: Wed, 6 Nov 2013 16:53:29 +0100
9ae3a8
Subject: [PATCH 72/87] qmp: add ImageInfo in BlockDeviceInfo used by query-block
9ae3a8
9ae3a8
RH-Author: Max Reitz <mreitz@redhat.com>
9ae3a8
Message-id: <1383756824-6921-7-git-send-email-mreitz@redhat.com>
9ae3a8
Patchwork-id: 55561
9ae3a8
O-Subject: [RHEL-7.0 qemu-kvm PATCH v2 06/21] qmp: add ImageInfo in BlockDeviceInfo used by query-block
9ae3a8
Bugzilla: 980771
9ae3a8
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
RH-Acked-by: Fam Zheng <famz@redhat.com>
9ae3a8
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
9ae3a8
9ae3a8
From: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
9ae3a8
9ae3a8
BZ: 980771
9ae3a8
9ae3a8
Now image info will be retrieved as an embbed json object inside
9ae3a8
BlockDeviceInfo, backing chain info and all related internal snapshot
9ae3a8
info can be got in the enhanced recursive structure of ImageInfo. New
9ae3a8
recursive member *backing-image is added to reflect the backing chain
9ae3a8
status.
9ae3a8
9ae3a8
Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
9ae3a8
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
(cherry picked from commit 553a7e871822d933beaefbd596f0e4eed1614373)
9ae3a8
9ae3a8
Signed-off-by: Max Reitz <mreitz@redhat.com>
9ae3a8
---
9ae3a8
 block/qapi.c         | 50 ++++++++++++++++++++++++++++++++++---
9ae3a8
 include/block/qapi.h |  4 ++-
9ae3a8
 qapi-schema.json     | 10 ++++++--
9ae3a8
 qmp-commands.hx      | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++--
9ae3a8
 4 files changed, 125 insertions(+), 8 deletions(-)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 block/qapi.c         |   50 ++++++++++++++++++++++++++++++++++--
9ae3a8
 include/block/qapi.h |    4 ++-
9ae3a8
 qapi-schema.json     |   10 ++++++-
9ae3a8
 qmp-commands.hx      |   69 ++++++++++++++++++++++++++++++++++++++++++++++++-
9ae3a8
 4 files changed, 125 insertions(+), 8 deletions(-)
9ae3a8
9ae3a8
diff --git a/block/qapi.c b/block/qapi.c
9ae3a8
index e9d8b74..a4bc411 100644
9ae3a8
--- a/block/qapi.c
9ae3a8
+++ b/block/qapi.c
9ae3a8
@@ -94,6 +94,13 @@ int bdrv_query_snapshot_info_list(BlockDriverState *bs,
9ae3a8
  * @p_info: location to store image information
9ae3a8
  * @errp: location to store error information
9ae3a8
  *
9ae3a8
+ * Store "flat" image information in @p_info.
9ae3a8
+ *
9ae3a8
+ * "Flat" means it does *not* query backing image information,
9ae3a8
+ * i.e. (*pinfo)->has_backing_image will be set to false and
9ae3a8
+ * (*pinfo)->backing_image to NULL even when the image does in fact have
9ae3a8
+ * a backing image.
9ae3a8
+ *
9ae3a8
  * @p_info will be set only on success. On error, store error in @errp.
9ae3a8
  */
9ae3a8
 void bdrv_query_image_info(BlockDriverState *bs,
9ae3a8
@@ -167,9 +174,15 @@ void bdrv_query_image_info(BlockDriverState *bs,
9ae3a8
     *p_info = info;
9ae3a8
 }
9ae3a8
 
9ae3a8
-BlockInfo *bdrv_query_info(BlockDriverState *bs)
9ae3a8
+/* @p_info will be set only on success. */
9ae3a8
+void bdrv_query_info(BlockDriverState *bs,
9ae3a8
+                     BlockInfo **p_info,
9ae3a8
+                     Error **errp)
9ae3a8
 {
9ae3a8
     BlockInfo *info = g_malloc0(sizeof(*info));
9ae3a8
+    BlockDriverState *bs0;
9ae3a8
+    ImageInfo **p_image_info;
9ae3a8
+    Error *local_err = NULL;
9ae3a8
     info->device = g_strdup(bs->device_name);
9ae3a8
     info->type = g_strdup("unknown");
9ae3a8
     info->locked = bdrv_dev_is_medium_locked(bs);
9ae3a8
@@ -223,8 +236,30 @@ BlockInfo *bdrv_query_info(BlockDriverState *bs)
9ae3a8
             info->inserted->iops_wr =
9ae3a8
                            bs->io_limits.iops[BLOCK_IO_LIMIT_WRITE];
9ae3a8
         }
9ae3a8
+
9ae3a8
+        bs0 = bs;
9ae3a8
+        p_image_info = &info->inserted->image;
9ae3a8
+        while (1) {
9ae3a8
+            bdrv_query_image_info(bs0, p_image_info, &local_err);
9ae3a8
+            if (error_is_set(&local_err)) {
9ae3a8
+                error_propagate(errp, local_err);
9ae3a8
+                goto err;
9ae3a8
+            }
9ae3a8
+            if (bs0->drv && bs0->backing_hd) {
9ae3a8
+                bs0 = bs0->backing_hd;
9ae3a8
+                (*p_image_info)->has_backing_image = true;
9ae3a8
+                p_image_info = &((*p_image_info)->backing_image);
9ae3a8
+            } else {
9ae3a8
+                break;
9ae3a8
+            }
9ae3a8
+        }
9ae3a8
     }
9ae3a8
-    return info;
9ae3a8
+
9ae3a8
+    *p_info = info;
9ae3a8
+    return;
9ae3a8
+
9ae3a8
+ err:
9ae3a8
+    qapi_free_BlockInfo(info);
9ae3a8
 }
9ae3a8
 
9ae3a8
 BlockStats *bdrv_query_stats(const BlockDriverState *bs)
9ae3a8
@@ -261,16 +296,25 @@ BlockInfoList *qmp_query_block(Error **errp)
9ae3a8
 {
9ae3a8
     BlockInfoList *head = NULL, **p_next = &head;
9ae3a8
     BlockDriverState *bs = NULL;
9ae3a8
+    Error *local_err = NULL;
9ae3a8
 
9ae3a8
      while ((bs = bdrv_next(bs))) {
9ae3a8
         BlockInfoList *info = g_malloc0(sizeof(*info));
9ae3a8
-        info->value = bdrv_query_info(bs);
9ae3a8
+        bdrv_query_info(bs, &info->value, &local_err);
9ae3a8
+        if (error_is_set(&local_err)) {
9ae3a8
+            error_propagate(errp, local_err);
9ae3a8
+            goto err;
9ae3a8
+        }
9ae3a8
 
9ae3a8
         *p_next = info;
9ae3a8
         p_next = &info->next;
9ae3a8
     }
9ae3a8
 
9ae3a8
     return head;
9ae3a8
+
9ae3a8
+ err:
9ae3a8
+    qapi_free_BlockInfoList(head);
9ae3a8
+    return NULL;
9ae3a8
 }
9ae3a8
 
9ae3a8
 BlockStatsList *qmp_query_blockstats(Error **errp)
9ae3a8
diff --git a/include/block/qapi.h b/include/block/qapi.h
9ae3a8
index ab1f48f..0496cc9 100644
9ae3a8
--- a/include/block/qapi.h
9ae3a8
+++ b/include/block/qapi.h
9ae3a8
@@ -35,7 +35,9 @@ int bdrv_query_snapshot_info_list(BlockDriverState *bs,
9ae3a8
 void bdrv_query_image_info(BlockDriverState *bs,
9ae3a8
                            ImageInfo **p_info,
9ae3a8
                            Error **errp);
9ae3a8
-BlockInfo *bdrv_query_info(BlockDriverState *s);
9ae3a8
+void bdrv_query_info(BlockDriverState *bs,
9ae3a8
+                     BlockInfo **p_info,
9ae3a8
+                     Error **errp);
9ae3a8
 BlockStats *bdrv_query_stats(const BlockDriverState *bs);
9ae3a8
 
9ae3a8
 void bdrv_snapshot_dump(fprintf_function func_fprintf, void *f,
9ae3a8
diff --git a/qapi-schema.json b/qapi-schema.json
9ae3a8
index 32b41b0..4091b99 100644
9ae3a8
--- a/qapi-schema.json
9ae3a8
+++ b/qapi-schema.json
9ae3a8
@@ -236,6 +236,8 @@
9ae3a8
 #
9ae3a8
 # @snapshots: #optional list of VM snapshots
9ae3a8
 #
9ae3a8
+# @backing-image: #optional info of the backing image (since 1.6)
9ae3a8
+#
9ae3a8
 # Since: 1.3
9ae3a8
 #
9ae3a8
 ##
9ae3a8
@@ -245,7 +247,8 @@
9ae3a8
            '*actual-size': 'int', 'virtual-size': 'int',
9ae3a8
            '*cluster-size': 'int', '*encrypted': 'bool',
9ae3a8
            '*backing-filename': 'str', '*full-backing-filename': 'str',
9ae3a8
-           '*backing-filename-format': 'str', '*snapshots': ['SnapshotInfo'] } }
9ae3a8
+           '*backing-filename-format': 'str', '*snapshots': ['SnapshotInfo'],
9ae3a8
+           '*backing-image': 'ImageInfo' } }
9ae3a8
 
9ae3a8
 ##
9ae3a8
 # @ImageCheck:
9ae3a8
@@ -768,6 +771,8 @@
9ae3a8
 #
9ae3a8
 # @iops_wr: write I/O operations per second is specified
9ae3a8
 #
9ae3a8
+# @image: the info of image used (since: 1.6)
9ae3a8
+#
9ae3a8
 # Since: 0.14.0
9ae3a8
 #
9ae3a8
 # Notes: This interface is only found in @BlockInfo.
9ae3a8
@@ -777,7 +782,8 @@
9ae3a8
             '*backing_file': 'str', 'backing_file_depth': 'int',
9ae3a8
             'encrypted': 'bool', 'encryption_key_missing': 'bool',
9ae3a8
             'bps': 'int', 'bps_rd': 'int', 'bps_wr': 'int',
9ae3a8
-            'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int'} }
9ae3a8
+            'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int',
9ae3a8
+            'image': 'ImageInfo' } }
9ae3a8
 
9ae3a8
 ##
9ae3a8
 # @BlockDeviceIoStatus:
9ae3a8
diff --git a/qmp-commands.hx b/qmp-commands.hx
9ae3a8
index d1f6f8b..f71c34e 100644
9ae3a8
--- a/qmp-commands.hx
9ae3a8
+++ b/qmp-commands.hx
9ae3a8
@@ -1713,6 +1713,47 @@ Each json-object contain the following:
9ae3a8
          - "iops": limit total I/O operations per second (json-int)
9ae3a8
          - "iops_rd": limit read operations per second (json-int)
9ae3a8
          - "iops_wr": limit write operations per second (json-int)
9ae3a8
+         - "image": the detail of the image, it is a json-object containing
9ae3a8
+            the following:
9ae3a8
+             - "filename": image file name (json-string)
9ae3a8
+             - "format": image format (json-string)
9ae3a8
+             - "virtual-size": image capacity in bytes (json-int)
9ae3a8
+             - "dirty-flag": true if image is not cleanly closed, not present
9ae3a8
+                             means clean (json-bool, optional)
9ae3a8
+             - "actual-size": actual size on disk in bytes of the image, not
9ae3a8
+                              present when image does not support thin
9ae3a8
+                              provision (json-int, optional)
9ae3a8
+             - "cluster-size": size of a cluster in bytes, not present if image
9ae3a8
+                               format does not support it (json-int, optional)
9ae3a8
+             - "encrypted": true if the image is encrypted, not present means
9ae3a8
+                            false or the image format does not support
9ae3a8
+                            encryption (json-bool, optional)
9ae3a8
+             - "backing_file": backing file name, not present means no backing
9ae3a8
+                               file is used or the image format does not
9ae3a8
+                               support backing file chain
9ae3a8
+                               (json-string, optional)
9ae3a8
+             - "full-backing-filename": full path of the backing file, not
9ae3a8
+                                        present if it equals backing_file or no
9ae3a8
+                                        backing file is used
9ae3a8
+                                        (json-string, optional)
9ae3a8
+             - "backing-filename-format": the format of the backing file, not
9ae3a8
+                                          present means unknown or no backing
9ae3a8
+                                          file (json-string, optional)
9ae3a8
+             - "snapshots": the internal snapshot info, it is an optional list
9ae3a8
+                of json-object containing the following:
9ae3a8
+                 - "id": unique snapshot id (json-string)
9ae3a8
+                 - "name": snapshot name (json-string)
9ae3a8
+                 - "vm-state-size": size of the VM state in bytes (json-int)
9ae3a8
+                 - "date-sec": UTC date of the snapshot in seconds (json-int)
9ae3a8
+                 - "date-nsec": fractional part in nanoseconds to be used with
9ae3a8
+                                date-sec(json-int)
9ae3a8
+                 - "vm-clock-sec": VM clock relative to boot in seconds
9ae3a8
+                                   (json-int)
9ae3a8
+                 - "vm-clock-nsec": fractional part in nanoseconds to be used
9ae3a8
+                                    with vm-clock-sec (json-int)
9ae3a8
+             - "backing-image": the detail of the backing image, it is an
9ae3a8
+                                optional json-object only present when a
9ae3a8
+                                backing image present for this image
9ae3a8
 
9ae3a8
 - "io-status": I/O operation status, only present if the device supports it
9ae3a8
                and the VM is configured to stop on errors. It's always reset
9ae3a8
@@ -1733,14 +1774,38 @@ Example:
9ae3a8
                "ro":false,
9ae3a8
                "drv":"qcow2",
9ae3a8
                "encrypted":false,
9ae3a8
-               "file":"disks/test.img",
9ae3a8
-               "backing_file_depth":0,
9ae3a8
+               "file":"disks/test.qcow2",
9ae3a8
+               "backing_file_depth":1,
9ae3a8
                "bps":1000000,
9ae3a8
                "bps_rd":0,
9ae3a8
                "bps_wr":0,
9ae3a8
                "iops":1000000,
9ae3a8
                "iops_rd":0,
9ae3a8
                "iops_wr":0,
9ae3a8
+               "image":{
9ae3a8
+                  "filename":"disks/test.qcow2",
9ae3a8
+                  "format":"qcow2",
9ae3a8
+                  "virtual-size":2048000,
9ae3a8
+                  "backing_file":"base.qcow2",
9ae3a8
+                  "full-backing-filename":"disks/base.qcow2",
9ae3a8
+                  "backing-filename-format:"qcow2",
9ae3a8
+                  "snapshots":[
9ae3a8
+                     {
9ae3a8
+                        "id": "1",
9ae3a8
+                        "name": "snapshot1",
9ae3a8
+                        "vm-state-size": 0,
9ae3a8
+                        "date-sec": 10000200,
9ae3a8
+                        "date-nsec": 12,
9ae3a8
+                        "vm-clock-sec": 206,
9ae3a8
+                        "vm-clock-nsec": 30
9ae3a8
+                     }
9ae3a8
+                  ],
9ae3a8
+                  "backing-image":{
9ae3a8
+                      "filename":"disks/base.qcow2",
9ae3a8
+                      "format":"qcow2",
9ae3a8
+                      "virtual-size":2048000
9ae3a8
+                  }
9ae3a8
+               }
9ae3a8
             },
9ae3a8
             "type":"unknown"
9ae3a8
          },
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8