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