|
|
9ae3a8 |
From 427c29cd043ba19a46096c66fafb321aecb8bc9b Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
From: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
Date: Wed, 6 Nov 2013 16:53:26 +0100
|
|
|
9ae3a8 |
Subject: [PATCH 69/87] block: dump snapshot and image info to specified output
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
RH-Author: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
Message-id: <1383756824-6921-4-git-send-email-mreitz@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 55558
|
|
|
9ae3a8 |
O-Subject: [RHEL-7.0 qemu-kvm PATCH v2 03/21] block: dump snapshot and image info to specified output
|
|
|
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 |
bdrv_snapshot_dump() and bdrv_image_info_dump() do not dump to a buffer now,
|
|
|
9ae3a8 |
some internal buffers are still used for format control, which have no
|
|
|
9ae3a8 |
chance to be truncated. As a result, these two functions have no more issue
|
|
|
9ae3a8 |
of truncation, and they can be used by both qemu and qemu-img with correct
|
|
|
9ae3a8 |
parameter specified.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
|
|
|
9ae3a8 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
(cherry picked from commit 5b91704469c0f801e0219f26458356872c4145ab)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
block/qapi.c | 66 ++++++++++++++++++++++++++++------------------------
|
|
|
9ae3a8 |
include/block/qapi.h | 6 +++--
|
|
|
9ae3a8 |
qemu-img.c | 9 +++----
|
|
|
9ae3a8 |
savevm.c | 7 +++---
|
|
|
9ae3a8 |
4 files changed, 49 insertions(+), 39 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
block/qapi.c | 66 +++++++++++++++++++++++++++----------------------
|
|
|
9ae3a8 |
include/block/qapi.h | 6 +++-
|
|
|
9ae3a8 |
qemu-img.c | 9 ++++---
|
|
|
9ae3a8 |
savevm.c | 7 +++--
|
|
|
9ae3a8 |
4 files changed, 49 insertions(+), 39 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/block/qapi.c b/block/qapi.c
|
|
|
9ae3a8 |
index 155e77e..794dbf8 100644
|
|
|
9ae3a8 |
--- a/block/qapi.c
|
|
|
9ae3a8 |
+++ b/block/qapi.c
|
|
|
9ae3a8 |
@@ -259,7 +259,8 @@ static char *get_human_readable_size(char *buf, int buf_size, int64_t size)
|
|
|
9ae3a8 |
return buf;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn)
|
|
|
9ae3a8 |
+void bdrv_snapshot_dump(fprintf_function func_fprintf, void *f,
|
|
|
9ae3a8 |
+ QEMUSnapshotInfo *sn)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
char buf1[128], date_buf[128], clock_buf[128];
|
|
|
9ae3a8 |
struct tm tm;
|
|
|
9ae3a8 |
@@ -267,9 +268,9 @@ char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn)
|
|
|
9ae3a8 |
int64_t secs;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (!sn) {
|
|
|
9ae3a8 |
- snprintf(buf, buf_size,
|
|
|
9ae3a8 |
- "%-10s%-20s%7s%20s%15s",
|
|
|
9ae3a8 |
- "ID", "TAG", "VM SIZE", "DATE", "VM CLOCK");
|
|
|
9ae3a8 |
+ func_fprintf(f,
|
|
|
9ae3a8 |
+ "%-10s%-20s%7s%20s%15s",
|
|
|
9ae3a8 |
+ "ID", "TAG", "VM SIZE", "DATE", "VM CLOCK");
|
|
|
9ae3a8 |
} else {
|
|
|
9ae3a8 |
ti = sn->date_sec;
|
|
|
9ae3a8 |
localtime_r(&ti, &tm;;
|
|
|
9ae3a8 |
@@ -282,17 +283,18 @@ char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn)
|
|
|
9ae3a8 |
(int)((secs / 60) % 60),
|
|
|
9ae3a8 |
(int)(secs % 60),
|
|
|
9ae3a8 |
(int)((sn->vm_clock_nsec / 1000000) % 1000));
|
|
|
9ae3a8 |
- snprintf(buf, buf_size,
|
|
|
9ae3a8 |
- "%-10s%-20s%7s%20s%15s",
|
|
|
9ae3a8 |
- sn->id_str, sn->name,
|
|
|
9ae3a8 |
- get_human_readable_size(buf1, sizeof(buf1), sn->vm_state_size),
|
|
|
9ae3a8 |
- date_buf,
|
|
|
9ae3a8 |
- clock_buf);
|
|
|
9ae3a8 |
+ func_fprintf(f,
|
|
|
9ae3a8 |
+ "%-10s%-20s%7s%20s%15s",
|
|
|
9ae3a8 |
+ sn->id_str, sn->name,
|
|
|
9ae3a8 |
+ get_human_readable_size(buf1, sizeof(buf1),
|
|
|
9ae3a8 |
+ sn->vm_state_size),
|
|
|
9ae3a8 |
+ date_buf,
|
|
|
9ae3a8 |
+ clock_buf);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
- return buf;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-void bdrv_image_info_dump(ImageInfo *info)
|
|
|
9ae3a8 |
+void bdrv_image_info_dump(fprintf_function func_fprintf, void *f,
|
|
|
9ae3a8 |
+ ImageInfo *info)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
char size_buf[128], dsize_buf[128];
|
|
|
9ae3a8 |
if (!info->has_actual_size) {
|
|
|
9ae3a8 |
@@ -302,43 +304,46 @@ void bdrv_image_info_dump(ImageInfo *info)
|
|
|
9ae3a8 |
info->actual_size);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
get_human_readable_size(size_buf, sizeof(size_buf), info->virtual_size);
|
|
|
9ae3a8 |
- printf("image: %s\n"
|
|
|
9ae3a8 |
- "file format: %s\n"
|
|
|
9ae3a8 |
- "virtual size: %s (%" PRId64 " bytes)\n"
|
|
|
9ae3a8 |
- "disk size: %s\n",
|
|
|
9ae3a8 |
- info->filename, info->format, size_buf,
|
|
|
9ae3a8 |
- info->virtual_size,
|
|
|
9ae3a8 |
- dsize_buf);
|
|
|
9ae3a8 |
+ func_fprintf(f,
|
|
|
9ae3a8 |
+ "image: %s\n"
|
|
|
9ae3a8 |
+ "file format: %s\n"
|
|
|
9ae3a8 |
+ "virtual size: %s (%" PRId64 " bytes)\n"
|
|
|
9ae3a8 |
+ "disk size: %s\n",
|
|
|
9ae3a8 |
+ info->filename, info->format, size_buf,
|
|
|
9ae3a8 |
+ info->virtual_size,
|
|
|
9ae3a8 |
+ dsize_buf);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (info->has_encrypted && info->encrypted) {
|
|
|
9ae3a8 |
- printf("encrypted: yes\n");
|
|
|
9ae3a8 |
+ func_fprintf(f, "encrypted: yes\n");
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (info->has_cluster_size) {
|
|
|
9ae3a8 |
- printf("cluster_size: %" PRId64 "\n", info->cluster_size);
|
|
|
9ae3a8 |
+ func_fprintf(f, "cluster_size: %" PRId64 "\n",
|
|
|
9ae3a8 |
+ info->cluster_size);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (info->has_dirty_flag && info->dirty_flag) {
|
|
|
9ae3a8 |
- printf("cleanly shut down: no\n");
|
|
|
9ae3a8 |
+ func_fprintf(f, "cleanly shut down: no\n");
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (info->has_backing_filename) {
|
|
|
9ae3a8 |
- printf("backing file: %s", info->backing_filename);
|
|
|
9ae3a8 |
+ func_fprintf(f, "backing file: %s", info->backing_filename);
|
|
|
9ae3a8 |
if (info->has_full_backing_filename) {
|
|
|
9ae3a8 |
- printf(" (actual path: %s)", info->full_backing_filename);
|
|
|
9ae3a8 |
+ func_fprintf(f, " (actual path: %s)", info->full_backing_filename);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
- putchar('\n');
|
|
|
9ae3a8 |
+ func_fprintf(f, "\n");
|
|
|
9ae3a8 |
if (info->has_backing_filename_format) {
|
|
|
9ae3a8 |
- printf("backing file format: %s\n", info->backing_filename_format);
|
|
|
9ae3a8 |
+ func_fprintf(f, "backing file format: %s\n",
|
|
|
9ae3a8 |
+ info->backing_filename_format);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (info->has_snapshots) {
|
|
|
9ae3a8 |
SnapshotInfoList *elem;
|
|
|
9ae3a8 |
- char buf[256];
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- printf("Snapshot list:\n");
|
|
|
9ae3a8 |
- printf("%s\n", bdrv_snapshot_dump(buf, sizeof(buf), NULL));
|
|
|
9ae3a8 |
+ func_fprintf(f, "Snapshot list:\n");
|
|
|
9ae3a8 |
+ bdrv_snapshot_dump(func_fprintf, f, NULL);
|
|
|
9ae3a8 |
+ func_fprintf(f, "\n");
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/* Ideally bdrv_snapshot_dump() would operate on SnapshotInfoList but
|
|
|
9ae3a8 |
* we convert to the block layer's native QEMUSnapshotInfo for now.
|
|
|
9ae3a8 |
@@ -354,7 +359,8 @@ void bdrv_image_info_dump(ImageInfo *info)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
pstrcpy(sn.id_str, sizeof(sn.id_str), elem->value->id);
|
|
|
9ae3a8 |
pstrcpy(sn.name, sizeof(sn.name), elem->value->name);
|
|
|
9ae3a8 |
- printf("%s\n", bdrv_snapshot_dump(buf, sizeof(buf), &sn));
|
|
|
9ae3a8 |
+ bdrv_snapshot_dump(func_fprintf, f, &sn;;
|
|
|
9ae3a8 |
+ func_fprintf(f, "\n");
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
diff --git a/include/block/qapi.h b/include/block/qapi.h
|
|
|
9ae3a8 |
index 55d1848..e6e568d 100644
|
|
|
9ae3a8 |
--- a/include/block/qapi.h
|
|
|
9ae3a8 |
+++ b/include/block/qapi.h
|
|
|
9ae3a8 |
@@ -36,6 +36,8 @@ void bdrv_collect_image_info(BlockDriverState *bs,
|
|
|
9ae3a8 |
BlockInfo *bdrv_query_info(BlockDriverState *s);
|
|
|
9ae3a8 |
BlockStats *bdrv_query_stats(const BlockDriverState *bs);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn);
|
|
|
9ae3a8 |
-void bdrv_image_info_dump(ImageInfo *info);
|
|
|
9ae3a8 |
+void bdrv_snapshot_dump(fprintf_function func_fprintf, void *f,
|
|
|
9ae3a8 |
+ QEMUSnapshotInfo *sn);
|
|
|
9ae3a8 |
+void bdrv_image_info_dump(fprintf_function func_fprintf, void *f,
|
|
|
9ae3a8 |
+ ImageInfo *info);
|
|
|
9ae3a8 |
#endif
|
|
|
9ae3a8 |
diff --git a/qemu-img.c b/qemu-img.c
|
|
|
9ae3a8 |
index 0bc084d..97b4212 100644
|
|
|
9ae3a8 |
--- a/qemu-img.c
|
|
|
9ae3a8 |
+++ b/qemu-img.c
|
|
|
9ae3a8 |
@@ -1575,16 +1575,17 @@ static void dump_snapshots(BlockDriverState *bs)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
QEMUSnapshotInfo *sn_tab, *sn;
|
|
|
9ae3a8 |
int nb_sns, i;
|
|
|
9ae3a8 |
- char buf[256];
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
nb_sns = bdrv_snapshot_list(bs, &sn_tab);
|
|
|
9ae3a8 |
if (nb_sns <= 0)
|
|
|
9ae3a8 |
return;
|
|
|
9ae3a8 |
printf("Snapshot list:\n");
|
|
|
9ae3a8 |
- printf("%s\n", bdrv_snapshot_dump(buf, sizeof(buf), NULL));
|
|
|
9ae3a8 |
+ bdrv_snapshot_dump(fprintf, stdout, NULL);
|
|
|
9ae3a8 |
+ printf("\n");
|
|
|
9ae3a8 |
for(i = 0; i < nb_sns; i++) {
|
|
|
9ae3a8 |
sn = &sn_tab[i];
|
|
|
9ae3a8 |
- printf("%s\n", bdrv_snapshot_dump(buf, sizeof(buf), sn));
|
|
|
9ae3a8 |
+ bdrv_snapshot_dump(fprintf, stdout, sn);
|
|
|
9ae3a8 |
+ printf("\n");
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
g_free(sn_tab);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -1634,7 +1635,7 @@ static void dump_human_image_info_list(ImageInfoList *list)
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
delim = true;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- bdrv_image_info_dump(elem->value);
|
|
|
9ae3a8 |
+ bdrv_image_info_dump(fprintf, stdout, elem->value);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/savevm.c b/savevm.c
|
|
|
9ae3a8 |
index f126bff..4d12d92 100644
|
|
|
9ae3a8 |
--- a/savevm.c
|
|
|
9ae3a8 |
+++ b/savevm.c
|
|
|
9ae3a8 |
@@ -2540,7 +2540,6 @@ void do_info_snapshots(Monitor *mon, const QDict *qdict)
|
|
|
9ae3a8 |
int nb_sns, i, ret, available;
|
|
|
9ae3a8 |
int total;
|
|
|
9ae3a8 |
int *available_snapshots;
|
|
|
9ae3a8 |
- char buf[256];
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
bs = find_vmstate_bs();
|
|
|
9ae3a8 |
if (!bs) {
|
|
|
9ae3a8 |
@@ -2583,10 +2582,12 @@ void do_info_snapshots(Monitor *mon, const QDict *qdict)
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (total > 0) {
|
|
|
9ae3a8 |
- monitor_printf(mon, "%s\n", bdrv_snapshot_dump(buf, sizeof(buf), NULL));
|
|
|
9ae3a8 |
+ bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, NULL);
|
|
|
9ae3a8 |
+ monitor_printf(mon, "\n");
|
|
|
9ae3a8 |
for (i = 0; i < total; i++) {
|
|
|
9ae3a8 |
sn = &sn_tab[available_snapshots[i]];
|
|
|
9ae3a8 |
- monitor_printf(mon, "%s\n", bdrv_snapshot_dump(buf, sizeof(buf), sn));
|
|
|
9ae3a8 |
+ bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, sn);
|
|
|
9ae3a8 |
+ monitor_printf(mon, "\n");
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
} else {
|
|
|
9ae3a8 |
monitor_printf(mon, "There is no suitable snapshot available\n");
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.7.1
|
|
|
9ae3a8 |
|