mirror of
https://git.proxmox.com/git/qemu
synced 2025-08-07 14:59:10 +00:00
block: dump snapshot and image info to specified output
bdrv_snapshot_dump() and bdrv_image_info_dump() do not dump to a buffer now, some internal buffers are still used for format control, which have no chance to be truncated. As a result, these two functions have no more issue of truncation, and they can be used by both qemu and qemu-img with correct parameter specified. Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
f364ec65b5
commit
5b91704469
66
block/qapi.c
66
block/qapi.c
@ -259,7 +259,8 @@ static char *get_human_readable_size(char *buf, int buf_size, int64_t size)
|
|||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn)
|
void bdrv_snapshot_dump(fprintf_function func_fprintf, void *f,
|
||||||
|
QEMUSnapshotInfo *sn)
|
||||||
{
|
{
|
||||||
char buf1[128], date_buf[128], clock_buf[128];
|
char buf1[128], date_buf[128], clock_buf[128];
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
@ -267,9 +268,9 @@ char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn)
|
|||||||
int64_t secs;
|
int64_t secs;
|
||||||
|
|
||||||
if (!sn) {
|
if (!sn) {
|
||||||
snprintf(buf, buf_size,
|
func_fprintf(f,
|
||||||
"%-10s%-20s%7s%20s%15s",
|
"%-10s%-20s%7s%20s%15s",
|
||||||
"ID", "TAG", "VM SIZE", "DATE", "VM CLOCK");
|
"ID", "TAG", "VM SIZE", "DATE", "VM CLOCK");
|
||||||
} else {
|
} else {
|
||||||
ti = sn->date_sec;
|
ti = sn->date_sec;
|
||||||
localtime_r(&ti, &tm);
|
localtime_r(&ti, &tm);
|
||||||
@ -282,17 +283,18 @@ char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn)
|
|||||||
(int)((secs / 60) % 60),
|
(int)((secs / 60) % 60),
|
||||||
(int)(secs % 60),
|
(int)(secs % 60),
|
||||||
(int)((sn->vm_clock_nsec / 1000000) % 1000));
|
(int)((sn->vm_clock_nsec / 1000000) % 1000));
|
||||||
snprintf(buf, buf_size,
|
func_fprintf(f,
|
||||||
"%-10s%-20s%7s%20s%15s",
|
"%-10s%-20s%7s%20s%15s",
|
||||||
sn->id_str, sn->name,
|
sn->id_str, sn->name,
|
||||||
get_human_readable_size(buf1, sizeof(buf1), sn->vm_state_size),
|
get_human_readable_size(buf1, sizeof(buf1),
|
||||||
date_buf,
|
sn->vm_state_size),
|
||||||
clock_buf);
|
date_buf,
|
||||||
|
clock_buf);
|
||||||
}
|
}
|
||||||
return buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void bdrv_image_info_dump(ImageInfo *info)
|
void bdrv_image_info_dump(fprintf_function func_fprintf, void *f,
|
||||||
|
ImageInfo *info)
|
||||||
{
|
{
|
||||||
char size_buf[128], dsize_buf[128];
|
char size_buf[128], dsize_buf[128];
|
||||||
if (!info->has_actual_size) {
|
if (!info->has_actual_size) {
|
||||||
@ -302,43 +304,46 @@ void bdrv_image_info_dump(ImageInfo *info)
|
|||||||
info->actual_size);
|
info->actual_size);
|
||||||
}
|
}
|
||||||
get_human_readable_size(size_buf, sizeof(size_buf), info->virtual_size);
|
get_human_readable_size(size_buf, sizeof(size_buf), info->virtual_size);
|
||||||
printf("image: %s\n"
|
func_fprintf(f,
|
||||||
"file format: %s\n"
|
"image: %s\n"
|
||||||
"virtual size: %s (%" PRId64 " bytes)\n"
|
"file format: %s\n"
|
||||||
"disk size: %s\n",
|
"virtual size: %s (%" PRId64 " bytes)\n"
|
||||||
info->filename, info->format, size_buf,
|
"disk size: %s\n",
|
||||||
info->virtual_size,
|
info->filename, info->format, size_buf,
|
||||||
dsize_buf);
|
info->virtual_size,
|
||||||
|
dsize_buf);
|
||||||
|
|
||||||
if (info->has_encrypted && info->encrypted) {
|
if (info->has_encrypted && info->encrypted) {
|
||||||
printf("encrypted: yes\n");
|
func_fprintf(f, "encrypted: yes\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info->has_cluster_size) {
|
if (info->has_cluster_size) {
|
||||||
printf("cluster_size: %" PRId64 "\n", info->cluster_size);
|
func_fprintf(f, "cluster_size: %" PRId64 "\n",
|
||||||
|
info->cluster_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info->has_dirty_flag && info->dirty_flag) {
|
if (info->has_dirty_flag && info->dirty_flag) {
|
||||||
printf("cleanly shut down: no\n");
|
func_fprintf(f, "cleanly shut down: no\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info->has_backing_filename) {
|
if (info->has_backing_filename) {
|
||||||
printf("backing file: %s", info->backing_filename);
|
func_fprintf(f, "backing file: %s", info->backing_filename);
|
||||||
if (info->has_full_backing_filename) {
|
if (info->has_full_backing_filename) {
|
||||||
printf(" (actual path: %s)", info->full_backing_filename);
|
func_fprintf(f, " (actual path: %s)", info->full_backing_filename);
|
||||||
}
|
}
|
||||||
putchar('\n');
|
func_fprintf(f, "\n");
|
||||||
if (info->has_backing_filename_format) {
|
if (info->has_backing_filename_format) {
|
||||||
printf("backing file format: %s\n", info->backing_filename_format);
|
func_fprintf(f, "backing file format: %s\n",
|
||||||
|
info->backing_filename_format);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info->has_snapshots) {
|
if (info->has_snapshots) {
|
||||||
SnapshotInfoList *elem;
|
SnapshotInfoList *elem;
|
||||||
char buf[256];
|
|
||||||
|
|
||||||
printf("Snapshot list:\n");
|
func_fprintf(f, "Snapshot list:\n");
|
||||||
printf("%s\n", bdrv_snapshot_dump(buf, sizeof(buf), NULL));
|
bdrv_snapshot_dump(func_fprintf, f, NULL);
|
||||||
|
func_fprintf(f, "\n");
|
||||||
|
|
||||||
/* Ideally bdrv_snapshot_dump() would operate on SnapshotInfoList but
|
/* Ideally bdrv_snapshot_dump() would operate on SnapshotInfoList but
|
||||||
* we convert to the block layer's native QEMUSnapshotInfo for now.
|
* we convert to the block layer's native QEMUSnapshotInfo for now.
|
||||||
@ -354,7 +359,8 @@ void bdrv_image_info_dump(ImageInfo *info)
|
|||||||
|
|
||||||
pstrcpy(sn.id_str, sizeof(sn.id_str), elem->value->id);
|
pstrcpy(sn.id_str, sizeof(sn.id_str), elem->value->id);
|
||||||
pstrcpy(sn.name, sizeof(sn.name), elem->value->name);
|
pstrcpy(sn.name, sizeof(sn.name), elem->value->name);
|
||||||
printf("%s\n", bdrv_snapshot_dump(buf, sizeof(buf), &sn));
|
bdrv_snapshot_dump(func_fprintf, f, &sn);
|
||||||
|
func_fprintf(f, "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,8 @@ void bdrv_collect_image_info(BlockDriverState *bs,
|
|||||||
BlockInfo *bdrv_query_info(BlockDriverState *s);
|
BlockInfo *bdrv_query_info(BlockDriverState *s);
|
||||||
BlockStats *bdrv_query_stats(const BlockDriverState *bs);
|
BlockStats *bdrv_query_stats(const BlockDriverState *bs);
|
||||||
|
|
||||||
char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn);
|
void bdrv_snapshot_dump(fprintf_function func_fprintf, void *f,
|
||||||
void bdrv_image_info_dump(ImageInfo *info);
|
QEMUSnapshotInfo *sn);
|
||||||
|
void bdrv_image_info_dump(fprintf_function func_fprintf, void *f,
|
||||||
|
ImageInfo *info);
|
||||||
#endif
|
#endif
|
||||||
|
@ -1554,16 +1554,17 @@ static void dump_snapshots(BlockDriverState *bs)
|
|||||||
{
|
{
|
||||||
QEMUSnapshotInfo *sn_tab, *sn;
|
QEMUSnapshotInfo *sn_tab, *sn;
|
||||||
int nb_sns, i;
|
int nb_sns, i;
|
||||||
char buf[256];
|
|
||||||
|
|
||||||
nb_sns = bdrv_snapshot_list(bs, &sn_tab);
|
nb_sns = bdrv_snapshot_list(bs, &sn_tab);
|
||||||
if (nb_sns <= 0)
|
if (nb_sns <= 0)
|
||||||
return;
|
return;
|
||||||
printf("Snapshot list:\n");
|
printf("Snapshot list:\n");
|
||||||
printf("%s\n", bdrv_snapshot_dump(buf, sizeof(buf), NULL));
|
bdrv_snapshot_dump(fprintf, stdout, NULL);
|
||||||
|
printf("\n");
|
||||||
for(i = 0; i < nb_sns; i++) {
|
for(i = 0; i < nb_sns; i++) {
|
||||||
sn = &sn_tab[i];
|
sn = &sn_tab[i];
|
||||||
printf("%s\n", bdrv_snapshot_dump(buf, sizeof(buf), sn));
|
bdrv_snapshot_dump(fprintf, stdout, sn);
|
||||||
|
printf("\n");
|
||||||
}
|
}
|
||||||
g_free(sn_tab);
|
g_free(sn_tab);
|
||||||
}
|
}
|
||||||
@ -1613,7 +1614,7 @@ static void dump_human_image_info_list(ImageInfoList *list)
|
|||||||
}
|
}
|
||||||
delim = true;
|
delim = true;
|
||||||
|
|
||||||
bdrv_image_info_dump(elem->value);
|
bdrv_image_info_dump(fprintf, stdout, elem->value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
7
savevm.c
7
savevm.c
@ -2540,7 +2540,6 @@ void do_info_snapshots(Monitor *mon, const QDict *qdict)
|
|||||||
int nb_sns, i, ret, available;
|
int nb_sns, i, ret, available;
|
||||||
int total;
|
int total;
|
||||||
int *available_snapshots;
|
int *available_snapshots;
|
||||||
char buf[256];
|
|
||||||
|
|
||||||
bs = find_vmstate_bs();
|
bs = find_vmstate_bs();
|
||||||
if (!bs) {
|
if (!bs) {
|
||||||
@ -2583,10 +2582,12 @@ void do_info_snapshots(Monitor *mon, const QDict *qdict)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (total > 0) {
|
if (total > 0) {
|
||||||
monitor_printf(mon, "%s\n", bdrv_snapshot_dump(buf, sizeof(buf), NULL));
|
bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, NULL);
|
||||||
|
monitor_printf(mon, "\n");
|
||||||
for (i = 0; i < total; i++) {
|
for (i = 0; i < total; i++) {
|
||||||
sn = &sn_tab[available_snapshots[i]];
|
sn = &sn_tab[available_snapshots[i]];
|
||||||
monitor_printf(mon, "%s\n", bdrv_snapshot_dump(buf, sizeof(buf), sn));
|
bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, sn);
|
||||||
|
monitor_printf(mon, "\n");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
monitor_printf(mon, "There is no suitable snapshot available\n");
|
monitor_printf(mon, "There is no suitable snapshot available\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user