thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-block-add-image-info-query-function-bdrv_query_image.patch

218e99
From e705ed7009ed1d53dd1d382cb8cf61a562dc8a44 Mon Sep 17 00:00:00 2001
218e99
From: Max Reitz <mreitz@redhat.com>
218e99
Date: Wed, 6 Nov 2013 16:53:28 +0100
218e99
Subject: [PATCH 71/87] block: add image info query function bdrv_query_image_info()
218e99
218e99
RH-Author: Max Reitz <mreitz@redhat.com>
218e99
Message-id: <1383756824-6921-6-git-send-email-mreitz@redhat.com>
218e99
Patchwork-id: 55560
218e99
O-Subject: [RHEL-7.0 qemu-kvm PATCH v2 05/21] block: add image info query function bdrv_query_image_info()
218e99
Bugzilla: 980771
218e99
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
218e99
RH-Acked-by: Fam Zheng <famz@redhat.com>
218e99
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
218e99
218e99
From: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
218e99
218e99
BZ: 980771
218e99
218e99
This patch adds function bdrv_query_image_info(), which will
218e99
retrieve image info in qmp object format. The implementation is
218e99
based on the code moved from qemu-img.c, but uses block layer
218e99
function to get snapshot info.
218e99
218e99
Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
218e99
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
218e99
(cherry picked from commit 43526ec8d1395fe4efbed15e9764b64641b95bcc)
218e99
218e99
Signed-off-by: Max Reitz <mreitz@redhat.com>
218e99
---
218e99
 block/qapi.c         | 43 +++++++++++++++++++++++++++++++++++++------
218e99
 include/block/qapi.h |  6 +++---
218e99
 qemu-img.c           | 11 ++++++-----
218e99
 3 files changed, 46 insertions(+), 14 deletions(-)
218e99
218e99
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
---
218e99
 block/qapi.c         |   43 +++++++++++++++++++++++++++++++++++++------
218e99
 include/block/qapi.h |    6 +++---
218e99
 qemu-img.c           |   11 ++++++-----
218e99
 3 files changed, 46 insertions(+), 14 deletions(-)
218e99
218e99
diff --git a/block/qapi.c b/block/qapi.c
218e99
index 1ed56da..e9d8b74 100644
218e99
--- a/block/qapi.c
218e99
+++ b/block/qapi.c
218e99
@@ -88,18 +88,29 @@ int bdrv_query_snapshot_info_list(BlockDriverState *bs,
218e99
     return 0;
218e99
 }
218e99
 
218e99
-void bdrv_collect_image_info(BlockDriverState *bs,
218e99
-                             ImageInfo *info,
218e99
-                             const char *filename)
218e99
+/**
218e99
+ * bdrv_query_image_info:
218e99
+ * @bs: block device to examine
218e99
+ * @p_info: location to store image information
218e99
+ * @errp: location to store error information
218e99
+ *
218e99
+ * @p_info will be set only on success. On error, store error in @errp.
218e99
+ */
218e99
+void bdrv_query_image_info(BlockDriverState *bs,
218e99
+                           ImageInfo **p_info,
218e99
+                           Error **errp)
218e99
 {
218e99
     uint64_t total_sectors;
218e99
-    char backing_filename[1024];
218e99
+    const char *backing_filename;
218e99
     char backing_filename2[1024];
218e99
     BlockDriverInfo bdi;
218e99
+    int ret;
218e99
+    Error *err = NULL;
218e99
+    ImageInfo *info = g_new0(ImageInfo, 1);
218e99
 
218e99
     bdrv_get_geometry(bs, &total_sectors);
218e99
 
218e99
-    info->filename        = g_strdup(filename);
218e99
+    info->filename        = g_strdup(bs->filename);
218e99
     info->format          = g_strdup(bdrv_get_format_name(bs));
218e99
     info->virtual_size    = total_sectors * 512;
218e99
     info->actual_size     = bdrv_get_allocated_file_size(bs);
218e99
@@ -116,7 +127,7 @@ void bdrv_collect_image_info(BlockDriverState *bs,
218e99
         info->dirty_flag = bdi.is_dirty;
218e99
         info->has_dirty_flag = true;
218e99
     }
218e99
-    bdrv_get_backing_filename(bs, backing_filename, sizeof(backing_filename));
218e99
+    backing_filename = bs->backing_file;
218e99
     if (backing_filename[0] != '\0') {
218e99
         info->backing_filename = g_strdup(backing_filename);
218e99
         info->has_backing_filename = true;
218e99
@@ -134,6 +145,26 @@ void bdrv_collect_image_info(BlockDriverState *bs,
218e99
             info->has_backing_filename_format = true;
218e99
         }
218e99
     }
218e99
+
218e99
+    ret = bdrv_query_snapshot_info_list(bs, &info->snapshots, &err;;
218e99
+    switch (ret) {
218e99
+    case 0:
218e99
+        if (info->snapshots) {
218e99
+            info->has_snapshots = true;
218e99
+        }
218e99
+        break;
218e99
+    /* recoverable error */
218e99
+    case -ENOMEDIUM:
218e99
+    case -ENOTSUP:
218e99
+        error_free(err);
218e99
+        break;
218e99
+    default:
218e99
+        error_propagate(errp, err);
218e99
+        qapi_free_ImageInfo(info);
218e99
+        return;
218e99
+    }
218e99
+
218e99
+    *p_info = info;
218e99
 }
218e99
 
218e99
 BlockInfo *bdrv_query_info(BlockDriverState *bs)
218e99
diff --git a/include/block/qapi.h b/include/block/qapi.h
218e99
index 4f223d1..ab1f48f 100644
218e99
--- a/include/block/qapi.h
218e99
+++ b/include/block/qapi.h
218e99
@@ -32,9 +32,9 @@
218e99
 int bdrv_query_snapshot_info_list(BlockDriverState *bs,
218e99
                                   SnapshotInfoList **p_list,
218e99
                                   Error **errp);
218e99
-void bdrv_collect_image_info(BlockDriverState *bs,
218e99
-                             ImageInfo *info,
218e99
-                             const char *filename);
218e99
+void bdrv_query_image_info(BlockDriverState *bs,
218e99
+                           ImageInfo **p_info,
218e99
+                           Error **errp);
218e99
 BlockInfo *bdrv_query_info(BlockDriverState *s);
218e99
 BlockStats *bdrv_query_stats(const BlockDriverState *bs);
218e99
 
218e99
diff --git a/qemu-img.c b/qemu-img.c
218e99
index e1fb148..fa0fd0e 100644
218e99
--- a/qemu-img.c
218e99
+++ b/qemu-img.c
218e99
@@ -1663,6 +1663,7 @@ static ImageInfoList *collect_image_info_list(const char *filename,
218e99
     ImageInfoList *head = NULL;
218e99
     ImageInfoList **last = &head;
218e99
     GHashTable *filenames;
218e99
+    Error *err = NULL;
218e99
 
218e99
     filenames = g_hash_table_new_full(g_str_hash, str_equal_func, NULL, NULL);
218e99
 
218e99
@@ -1684,11 +1685,11 @@ static ImageInfoList *collect_image_info_list(const char *filename,
218e99
             goto err;
218e99
         }
218e99
 
218e99
-        info = g_new0(ImageInfo, 1);
218e99
-        bdrv_collect_image_info(bs, info, filename);
218e99
-        bdrv_query_snapshot_info_list(bs, &info->snapshots, NULL);
218e99
-        if (info->snapshots) {
218e99
-            info->has_snapshots = true;
218e99
+        bdrv_query_image_info(bs, &info, &err;;
218e99
+        if (error_is_set(&err)) {
218e99
+            error_report("%s", error_get_pretty(err));
218e99
+            error_free(err);
218e99
+            goto err;
218e99
         }
218e99
 
218e99
         elem = g_new0(ImageInfoList, 1);
218e99
-- 
218e99
1.7.1
218e99