|
|
9ae3a8 |
From 9bba35d273d094e206e29f5a328f21834a838471 Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
From: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
Date: Thu, 7 Nov 2013 12:59:07 +0100
|
|
|
9ae3a8 |
Subject: [PATCH 68/87] block: move qmp and info dump related code to block/qapi.c
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
RH-Author: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
Message-id: <1383756824-6921-3-git-send-email-mreitz@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 55557
|
|
|
9ae3a8 |
O-Subject: [RHEL-7.0 qemu-kvm PATCH v2 02/21] block: move qmp and info dump related code to block/qapi.c
|
|
|
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 is a pure code move patch, except following modification:
|
|
|
9ae3a8 |
1 get_human_readable_size() is changed to static function.
|
|
|
9ae3a8 |
2 dump_human_image_info() is renamed to bdrv_image_info_dump().
|
|
|
9ae3a8 |
3 in qmp_query_block() and qmp_query_blockstats, use bdrv_next(bs)
|
|
|
9ae3a8 |
instead of direct traverse of global array 'bdrv_states'.
|
|
|
9ae3a8 |
4 collect_snapshots() and collect_image_info() are renamed, unused parameter
|
|
|
9ae3a8 |
*fmt in collect_image_info() is removed.
|
|
|
9ae3a8 |
5 code style fix.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
To avoid conflict and tip better, macro in header file is BLOCK_QAPI_H
|
|
|
9ae3a8 |
instead of QAPI_H. Now block.h and snapshot.h are at the same level in
|
|
|
9ae3a8 |
include path, block_int.h and qapi.h will both include them.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
|
|
|
9ae3a8 |
Reviewed-by: Eric Blake <eblake@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
(cherry picked from commit f364ec65b56b69c55b674cb6560aa1fbbea9e013)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
block.c | 185 -----------------------
|
|
|
9ae3a8 |
block/Makefile.objs | 2 +-
|
|
|
9ae3a8 |
block/qapi.c | 360 +++++++++++++++++++++++++++++++++++++++++++++
|
|
|
9ae3a8 |
include/block/block.h | 9 -
|
|
|
9ae3a8 |
include/block/block_int.h | 1 +
|
|
|
9ae3a8 |
include/block/qapi.h | 41 +++++
|
|
|
9ae3a8 |
qemu-img.c | 156 +-------------------
|
|
|
9ae3a8 |
savevm.c | 1 +
|
|
|
9ae3a8 |
8 files changed, 408 insertions(+), 347 deletions(-)
|
|
|
9ae3a8 |
create mode 100644 block/qapi.c
|
|
|
9ae3a8 |
create mode 100644 include/block/qapi.h
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/block.c b/block.c
|
|
|
9ae3a8 |
index dccdb2c..e4885da 100644
|
|
|
9ae3a8 |
--- a/block.c
|
|
|
9ae3a8 |
+++ b/block.c
|
|
|
9ae3a8 |
@@ -3266,128 +3266,6 @@ int bdrv_is_allocated_above(BlockDriverState *top,
|
|
|
9ae3a8 |
return 0;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-BlockInfo *bdrv_query_info(BlockDriverState *bs)
|
|
|
9ae3a8 |
-{
|
|
|
9ae3a8 |
- BlockInfo *info = g_malloc0(sizeof(*info));
|
|
|
9ae3a8 |
- info->device = g_strdup(bs->device_name);
|
|
|
9ae3a8 |
- info->type = g_strdup("unknown");
|
|
|
9ae3a8 |
- info->locked = bdrv_dev_is_medium_locked(bs);
|
|
|
9ae3a8 |
- info->removable = bdrv_dev_has_removable_media(bs);
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- if (bdrv_dev_has_removable_media(bs)) {
|
|
|
9ae3a8 |
- info->has_tray_open = true;
|
|
|
9ae3a8 |
- info->tray_open = bdrv_dev_is_tray_open(bs);
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- if (bdrv_iostatus_is_enabled(bs)) {
|
|
|
9ae3a8 |
- info->has_io_status = true;
|
|
|
9ae3a8 |
- info->io_status = bs->iostatus;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- if (bs->dirty_bitmap) {
|
|
|
9ae3a8 |
- info->has_dirty = true;
|
|
|
9ae3a8 |
- info->dirty = g_malloc0(sizeof(*info->dirty));
|
|
|
9ae3a8 |
- info->dirty->count = bdrv_get_dirty_count(bs) * BDRV_SECTOR_SIZE;
|
|
|
9ae3a8 |
- info->dirty->granularity =
|
|
|
9ae3a8 |
- ((int64_t) BDRV_SECTOR_SIZE << hbitmap_granularity(bs->dirty_bitmap));
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- if (bs->drv) {
|
|
|
9ae3a8 |
- info->has_inserted = true;
|
|
|
9ae3a8 |
- info->inserted = g_malloc0(sizeof(*info->inserted));
|
|
|
9ae3a8 |
- info->inserted->file = g_strdup(bs->filename);
|
|
|
9ae3a8 |
- info->inserted->ro = bs->read_only;
|
|
|
9ae3a8 |
- info->inserted->drv = g_strdup(bs->drv->format_name);
|
|
|
9ae3a8 |
- info->inserted->encrypted = bs->encrypted;
|
|
|
9ae3a8 |
- info->inserted->encryption_key_missing = bdrv_key_required(bs);
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- if (bs->backing_file[0]) {
|
|
|
9ae3a8 |
- info->inserted->has_backing_file = true;
|
|
|
9ae3a8 |
- info->inserted->backing_file = g_strdup(bs->backing_file);
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- info->inserted->backing_file_depth = bdrv_get_backing_file_depth(bs);
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- if (bs->io_limits_enabled) {
|
|
|
9ae3a8 |
- info->inserted->bps =
|
|
|
9ae3a8 |
- bs->io_limits.bps[BLOCK_IO_LIMIT_TOTAL];
|
|
|
9ae3a8 |
- info->inserted->bps_rd =
|
|
|
9ae3a8 |
- bs->io_limits.bps[BLOCK_IO_LIMIT_READ];
|
|
|
9ae3a8 |
- info->inserted->bps_wr =
|
|
|
9ae3a8 |
- bs->io_limits.bps[BLOCK_IO_LIMIT_WRITE];
|
|
|
9ae3a8 |
- info->inserted->iops =
|
|
|
9ae3a8 |
- bs->io_limits.iops[BLOCK_IO_LIMIT_TOTAL];
|
|
|
9ae3a8 |
- info->inserted->iops_rd =
|
|
|
9ae3a8 |
- bs->io_limits.iops[BLOCK_IO_LIMIT_READ];
|
|
|
9ae3a8 |
- info->inserted->iops_wr =
|
|
|
9ae3a8 |
- bs->io_limits.iops[BLOCK_IO_LIMIT_WRITE];
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- return info;
|
|
|
9ae3a8 |
-}
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
-BlockInfoList *qmp_query_block(Error **errp)
|
|
|
9ae3a8 |
-{
|
|
|
9ae3a8 |
- BlockInfoList *head = NULL, **p_next = &head;
|
|
|
9ae3a8 |
- BlockDriverState *bs;
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- QTAILQ_FOREACH(bs, &bdrv_states, list) {
|
|
|
9ae3a8 |
- BlockInfoList *info = g_malloc0(sizeof(*info));
|
|
|
9ae3a8 |
- info->value = bdrv_query_info(bs);
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- *p_next = info;
|
|
|
9ae3a8 |
- p_next = &info->next;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- return head;
|
|
|
9ae3a8 |
-}
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
-BlockStats *bdrv_query_stats(const BlockDriverState *bs)
|
|
|
9ae3a8 |
-{
|
|
|
9ae3a8 |
- BlockStats *s;
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- s = g_malloc0(sizeof(*s));
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- if (bs->device_name[0]) {
|
|
|
9ae3a8 |
- s->has_device = true;
|
|
|
9ae3a8 |
- s->device = g_strdup(bs->device_name);
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- s->stats = g_malloc0(sizeof(*s->stats));
|
|
|
9ae3a8 |
- s->stats->rd_bytes = bs->nr_bytes[BDRV_ACCT_READ];
|
|
|
9ae3a8 |
- s->stats->wr_bytes = bs->nr_bytes[BDRV_ACCT_WRITE];
|
|
|
9ae3a8 |
- s->stats->rd_operations = bs->nr_ops[BDRV_ACCT_READ];
|
|
|
9ae3a8 |
- s->stats->wr_operations = bs->nr_ops[BDRV_ACCT_WRITE];
|
|
|
9ae3a8 |
- s->stats->wr_highest_offset = bs->wr_highest_sector * BDRV_SECTOR_SIZE;
|
|
|
9ae3a8 |
- s->stats->flush_operations = bs->nr_ops[BDRV_ACCT_FLUSH];
|
|
|
9ae3a8 |
- s->stats->wr_total_time_ns = bs->total_time_ns[BDRV_ACCT_WRITE];
|
|
|
9ae3a8 |
- s->stats->rd_total_time_ns = bs->total_time_ns[BDRV_ACCT_READ];
|
|
|
9ae3a8 |
- s->stats->flush_total_time_ns = bs->total_time_ns[BDRV_ACCT_FLUSH];
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- if (bs->file) {
|
|
|
9ae3a8 |
- s->has_parent = true;
|
|
|
9ae3a8 |
- s->parent = bdrv_query_stats(bs->file);
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- return s;
|
|
|
9ae3a8 |
-}
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
-BlockStatsList *qmp_query_blockstats(Error **errp)
|
|
|
9ae3a8 |
-{
|
|
|
9ae3a8 |
- BlockStatsList *head = NULL, **p_next = &head;
|
|
|
9ae3a8 |
- BlockDriverState *bs;
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- QTAILQ_FOREACH(bs, &bdrv_states, list) {
|
|
|
9ae3a8 |
- BlockStatsList *info = g_malloc0(sizeof(*info));
|
|
|
9ae3a8 |
- info->value = bdrv_query_stats(bs);
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- *p_next = info;
|
|
|
9ae3a8 |
- p_next = &info->next;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- return head;
|
|
|
9ae3a8 |
-}
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
const char *bdrv_get_encrypted_filename(BlockDriverState *bs)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
if (bs->backing_hd && bs->backing_hd->encrypted)
|
|
|
9ae3a8 |
@@ -3623,69 +3501,6 @@ BlockDriverState *bdrv_find_base(BlockDriverState *bs)
|
|
|
9ae3a8 |
return curr_bs;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-#define NB_SUFFIXES 4
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
-char *get_human_readable_size(char *buf, int buf_size, int64_t size)
|
|
|
9ae3a8 |
-{
|
|
|
9ae3a8 |
- static const char suffixes[NB_SUFFIXES] = "KMGT";
|
|
|
9ae3a8 |
- int64_t base;
|
|
|
9ae3a8 |
- int i;
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- if (size <= 999) {
|
|
|
9ae3a8 |
- snprintf(buf, buf_size, "%" PRId64, size);
|
|
|
9ae3a8 |
- } else {
|
|
|
9ae3a8 |
- base = 1024;
|
|
|
9ae3a8 |
- for(i = 0; i < NB_SUFFIXES; i++) {
|
|
|
9ae3a8 |
- if (size < (10 * base)) {
|
|
|
9ae3a8 |
- snprintf(buf, buf_size, "%0.1f%c",
|
|
|
9ae3a8 |
- (double)size / base,
|
|
|
9ae3a8 |
- suffixes[i]);
|
|
|
9ae3a8 |
- break;
|
|
|
9ae3a8 |
- } else if (size < (1000 * base) || i == (NB_SUFFIXES - 1)) {
|
|
|
9ae3a8 |
- snprintf(buf, buf_size, "%" PRId64 "%c",
|
|
|
9ae3a8 |
- ((size + (base >> 1)) / base),
|
|
|
9ae3a8 |
- suffixes[i]);
|
|
|
9ae3a8 |
- break;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- base = base * 1024;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- return buf;
|
|
|
9ae3a8 |
-}
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
-char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn)
|
|
|
9ae3a8 |
-{
|
|
|
9ae3a8 |
- char buf1[128], date_buf[128], clock_buf[128];
|
|
|
9ae3a8 |
- struct tm tm;
|
|
|
9ae3a8 |
- time_t ti;
|
|
|
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 |
- } else {
|
|
|
9ae3a8 |
- ti = sn->date_sec;
|
|
|
9ae3a8 |
- localtime_r(&ti, &tm;;
|
|
|
9ae3a8 |
- strftime(date_buf, sizeof(date_buf),
|
|
|
9ae3a8 |
- "%Y-%m-%d %H:%M:%S", &tm;;
|
|
|
9ae3a8 |
- secs = sn->vm_clock_nsec / 1000000000;
|
|
|
9ae3a8 |
- snprintf(clock_buf, sizeof(clock_buf),
|
|
|
9ae3a8 |
- "%02d:%02d:%02d.%03d",
|
|
|
9ae3a8 |
- (int)(secs / 3600),
|
|
|
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 |
- }
|
|
|
9ae3a8 |
- return buf;
|
|
|
9ae3a8 |
-}
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
/**************************************************************/
|
|
|
9ae3a8 |
/* async I/Os */
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/block/Makefile.objs b/block/Makefile.objs
|
|
|
9ae3a8 |
index 162f270..3db1839 100644
|
|
|
9ae3a8 |
--- a/block/Makefile.objs
|
|
|
9ae3a8 |
+++ b/block/Makefile.objs
|
|
|
9ae3a8 |
@@ -4,7 +4,7 @@ block-obj-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o
|
|
|
9ae3a8 |
block-obj-y += qed-check.o
|
|
|
9ae3a8 |
block-obj-y += vhdx.o
|
|
|
9ae3a8 |
block-obj-y += parallels.o blkdebug.o blkverify.o
|
|
|
9ae3a8 |
-block-obj-y += snapshot.o
|
|
|
9ae3a8 |
+block-obj-y += snapshot.o qapi.o
|
|
|
9ae3a8 |
block-obj-$(CONFIG_WIN32) += raw-win32.o win32-aio.o
|
|
|
9ae3a8 |
block-obj-$(CONFIG_POSIX) += raw-posix.o
|
|
|
9ae3a8 |
block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
|
|
|
9ae3a8 |
diff --git a/block/qapi.c b/block/qapi.c
|
|
|
9ae3a8 |
new file mode 100644
|
|
|
9ae3a8 |
index 0000000..155e77e
|
|
|
9ae3a8 |
--- /dev/null
|
|
|
9ae3a8 |
+++ b/block/qapi.c
|
|
|
9ae3a8 |
@@ -0,0 +1,360 @@
|
|
|
9ae3a8 |
+/*
|
|
|
9ae3a8 |
+ * Block layer qmp and info dump related functions
|
|
|
9ae3a8 |
+ *
|
|
|
9ae3a8 |
+ * Copyright (c) 2003-2008 Fabrice Bellard
|
|
|
9ae3a8 |
+ *
|
|
|
9ae3a8 |
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
9ae3a8 |
+ * of this software and associated documentation files (the "Software"), to deal
|
|
|
9ae3a8 |
+ * in the Software without restriction, including without limitation the rights
|
|
|
9ae3a8 |
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
9ae3a8 |
+ * copies of the Software, and to permit persons to whom the Software is
|
|
|
9ae3a8 |
+ * furnished to do so, subject to the following conditions:
|
|
|
9ae3a8 |
+ *
|
|
|
9ae3a8 |
+ * The above copyright notice and this permission notice shall be included in
|
|
|
9ae3a8 |
+ * all copies or substantial portions of the Software.
|
|
|
9ae3a8 |
+ *
|
|
|
9ae3a8 |
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
9ae3a8 |
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
9ae3a8 |
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
9ae3a8 |
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
9ae3a8 |
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
9ae3a8 |
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
9ae3a8 |
+ * THE SOFTWARE.
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+#include "block/qapi.h"
|
|
|
9ae3a8 |
+#include "block/block_int.h"
|
|
|
9ae3a8 |
+#include "qmp-commands.h"
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+void bdrv_collect_snapshots(BlockDriverState *bs , ImageInfo *info)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ int i, sn_count;
|
|
|
9ae3a8 |
+ QEMUSnapshotInfo *sn_tab = NULL;
|
|
|
9ae3a8 |
+ SnapshotInfoList *info_list, *cur_item = NULL;
|
|
|
9ae3a8 |
+ sn_count = bdrv_snapshot_list(bs, &sn_tab);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ for (i = 0; i < sn_count; i++) {
|
|
|
9ae3a8 |
+ info->has_snapshots = true;
|
|
|
9ae3a8 |
+ info_list = g_new0(SnapshotInfoList, 1);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ info_list->value = g_new0(SnapshotInfo, 1);
|
|
|
9ae3a8 |
+ info_list->value->id = g_strdup(sn_tab[i].id_str);
|
|
|
9ae3a8 |
+ info_list->value->name = g_strdup(sn_tab[i].name);
|
|
|
9ae3a8 |
+ info_list->value->vm_state_size = sn_tab[i].vm_state_size;
|
|
|
9ae3a8 |
+ info_list->value->date_sec = sn_tab[i].date_sec;
|
|
|
9ae3a8 |
+ info_list->value->date_nsec = sn_tab[i].date_nsec;
|
|
|
9ae3a8 |
+ info_list->value->vm_clock_sec = sn_tab[i].vm_clock_nsec / 1000000000;
|
|
|
9ae3a8 |
+ info_list->value->vm_clock_nsec = sn_tab[i].vm_clock_nsec % 1000000000;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* XXX: waiting for the qapi to support qemu-queue.h types */
|
|
|
9ae3a8 |
+ if (!cur_item) {
|
|
|
9ae3a8 |
+ info->snapshots = cur_item = info_list;
|
|
|
9ae3a8 |
+ } else {
|
|
|
9ae3a8 |
+ cur_item->next = info_list;
|
|
|
9ae3a8 |
+ cur_item = info_list;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ g_free(sn_tab);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+void bdrv_collect_image_info(BlockDriverState *bs,
|
|
|
9ae3a8 |
+ ImageInfo *info,
|
|
|
9ae3a8 |
+ const char *filename)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ uint64_t total_sectors;
|
|
|
9ae3a8 |
+ char backing_filename[1024];
|
|
|
9ae3a8 |
+ char backing_filename2[1024];
|
|
|
9ae3a8 |
+ BlockDriverInfo bdi;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ bdrv_get_geometry(bs, &total_sectors);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ info->filename = g_strdup(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 |
+ info->has_actual_size = info->actual_size >= 0;
|
|
|
9ae3a8 |
+ if (bdrv_is_encrypted(bs)) {
|
|
|
9ae3a8 |
+ info->encrypted = true;
|
|
|
9ae3a8 |
+ info->has_encrypted = true;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ if (bdrv_get_info(bs, &bdi) >= 0) {
|
|
|
9ae3a8 |
+ if (bdi.cluster_size != 0) {
|
|
|
9ae3a8 |
+ info->cluster_size = bdi.cluster_size;
|
|
|
9ae3a8 |
+ info->has_cluster_size = true;
|
|
|
9ae3a8 |
+ }
|
|
|
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 |
+ if (backing_filename[0] != '\0') {
|
|
|
9ae3a8 |
+ info->backing_filename = g_strdup(backing_filename);
|
|
|
9ae3a8 |
+ info->has_backing_filename = true;
|
|
|
9ae3a8 |
+ bdrv_get_full_backing_filename(bs, backing_filename2,
|
|
|
9ae3a8 |
+ sizeof(backing_filename2));
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (strcmp(backing_filename, backing_filename2) != 0) {
|
|
|
9ae3a8 |
+ info->full_backing_filename =
|
|
|
9ae3a8 |
+ g_strdup(backing_filename2);
|
|
|
9ae3a8 |
+ info->has_full_backing_filename = true;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (bs->backing_format[0]) {
|
|
|
9ae3a8 |
+ info->backing_filename_format = g_strdup(bs->backing_format);
|
|
|
9ae3a8 |
+ info->has_backing_filename_format = true;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+BlockInfo *bdrv_query_info(BlockDriverState *bs)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ BlockInfo *info = g_malloc0(sizeof(*info));
|
|
|
9ae3a8 |
+ info->device = g_strdup(bs->device_name);
|
|
|
9ae3a8 |
+ info->type = g_strdup("unknown");
|
|
|
9ae3a8 |
+ info->locked = bdrv_dev_is_medium_locked(bs);
|
|
|
9ae3a8 |
+ info->removable = bdrv_dev_has_removable_media(bs);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (bdrv_dev_has_removable_media(bs)) {
|
|
|
9ae3a8 |
+ info->has_tray_open = true;
|
|
|
9ae3a8 |
+ info->tray_open = bdrv_dev_is_tray_open(bs);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (bdrv_iostatus_is_enabled(bs)) {
|
|
|
9ae3a8 |
+ info->has_io_status = true;
|
|
|
9ae3a8 |
+ info->io_status = bs->iostatus;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (bs->dirty_bitmap) {
|
|
|
9ae3a8 |
+ info->has_dirty = true;
|
|
|
9ae3a8 |
+ info->dirty = g_malloc0(sizeof(*info->dirty));
|
|
|
9ae3a8 |
+ info->dirty->count = bdrv_get_dirty_count(bs) * BDRV_SECTOR_SIZE;
|
|
|
9ae3a8 |
+ info->dirty->granularity =
|
|
|
9ae3a8 |
+ ((int64_t) BDRV_SECTOR_SIZE << hbitmap_granularity(bs->dirty_bitmap));
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (bs->drv) {
|
|
|
9ae3a8 |
+ info->has_inserted = true;
|
|
|
9ae3a8 |
+ info->inserted = g_malloc0(sizeof(*info->inserted));
|
|
|
9ae3a8 |
+ info->inserted->file = g_strdup(bs->filename);
|
|
|
9ae3a8 |
+ info->inserted->ro = bs->read_only;
|
|
|
9ae3a8 |
+ info->inserted->drv = g_strdup(bs->drv->format_name);
|
|
|
9ae3a8 |
+ info->inserted->encrypted = bs->encrypted;
|
|
|
9ae3a8 |
+ info->inserted->encryption_key_missing = bdrv_key_required(bs);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (bs->backing_file[0]) {
|
|
|
9ae3a8 |
+ info->inserted->has_backing_file = true;
|
|
|
9ae3a8 |
+ info->inserted->backing_file = g_strdup(bs->backing_file);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ info->inserted->backing_file_depth = bdrv_get_backing_file_depth(bs);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (bs->io_limits_enabled) {
|
|
|
9ae3a8 |
+ info->inserted->bps =
|
|
|
9ae3a8 |
+ bs->io_limits.bps[BLOCK_IO_LIMIT_TOTAL];
|
|
|
9ae3a8 |
+ info->inserted->bps_rd =
|
|
|
9ae3a8 |
+ bs->io_limits.bps[BLOCK_IO_LIMIT_READ];
|
|
|
9ae3a8 |
+ info->inserted->bps_wr =
|
|
|
9ae3a8 |
+ bs->io_limits.bps[BLOCK_IO_LIMIT_WRITE];
|
|
|
9ae3a8 |
+ info->inserted->iops =
|
|
|
9ae3a8 |
+ bs->io_limits.iops[BLOCK_IO_LIMIT_TOTAL];
|
|
|
9ae3a8 |
+ info->inserted->iops_rd =
|
|
|
9ae3a8 |
+ bs->io_limits.iops[BLOCK_IO_LIMIT_READ];
|
|
|
9ae3a8 |
+ info->inserted->iops_wr =
|
|
|
9ae3a8 |
+ bs->io_limits.iops[BLOCK_IO_LIMIT_WRITE];
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ return info;
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+BlockStats *bdrv_query_stats(const BlockDriverState *bs)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ BlockStats *s;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ s = g_malloc0(sizeof(*s));
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (bs->device_name[0]) {
|
|
|
9ae3a8 |
+ s->has_device = true;
|
|
|
9ae3a8 |
+ s->device = g_strdup(bs->device_name);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ s->stats = g_malloc0(sizeof(*s->stats));
|
|
|
9ae3a8 |
+ s->stats->rd_bytes = bs->nr_bytes[BDRV_ACCT_READ];
|
|
|
9ae3a8 |
+ s->stats->wr_bytes = bs->nr_bytes[BDRV_ACCT_WRITE];
|
|
|
9ae3a8 |
+ s->stats->rd_operations = bs->nr_ops[BDRV_ACCT_READ];
|
|
|
9ae3a8 |
+ s->stats->wr_operations = bs->nr_ops[BDRV_ACCT_WRITE];
|
|
|
9ae3a8 |
+ s->stats->wr_highest_offset = bs->wr_highest_sector * BDRV_SECTOR_SIZE;
|
|
|
9ae3a8 |
+ s->stats->flush_operations = bs->nr_ops[BDRV_ACCT_FLUSH];
|
|
|
9ae3a8 |
+ s->stats->wr_total_time_ns = bs->total_time_ns[BDRV_ACCT_WRITE];
|
|
|
9ae3a8 |
+ s->stats->rd_total_time_ns = bs->total_time_ns[BDRV_ACCT_READ];
|
|
|
9ae3a8 |
+ s->stats->flush_total_time_ns = bs->total_time_ns[BDRV_ACCT_FLUSH];
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (bs->file) {
|
|
|
9ae3a8 |
+ s->has_parent = true;
|
|
|
9ae3a8 |
+ s->parent = bdrv_query_stats(bs->file);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ return s;
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+BlockInfoList *qmp_query_block(Error **errp)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ BlockInfoList *head = NULL, **p_next = &head;
|
|
|
9ae3a8 |
+ BlockDriverState *bs = NULL;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ while ((bs = bdrv_next(bs))) {
|
|
|
9ae3a8 |
+ BlockInfoList *info = g_malloc0(sizeof(*info));
|
|
|
9ae3a8 |
+ info->value = bdrv_query_info(bs);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ *p_next = info;
|
|
|
9ae3a8 |
+ p_next = &info->next;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ return head;
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+BlockStatsList *qmp_query_blockstats(Error **errp)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ BlockStatsList *head = NULL, **p_next = &head;
|
|
|
9ae3a8 |
+ BlockDriverState *bs = NULL;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ while ((bs = bdrv_next(bs))) {
|
|
|
9ae3a8 |
+ BlockStatsList *info = g_malloc0(sizeof(*info));
|
|
|
9ae3a8 |
+ info->value = bdrv_query_stats(bs);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ *p_next = info;
|
|
|
9ae3a8 |
+ p_next = &info->next;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ return head;
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+#define NB_SUFFIXES 4
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static char *get_human_readable_size(char *buf, int buf_size, int64_t size)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ static const char suffixes[NB_SUFFIXES] = "KMGT";
|
|
|
9ae3a8 |
+ int64_t base;
|
|
|
9ae3a8 |
+ int i;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (size <= 999) {
|
|
|
9ae3a8 |
+ snprintf(buf, buf_size, "%" PRId64, size);
|
|
|
9ae3a8 |
+ } else {
|
|
|
9ae3a8 |
+ base = 1024;
|
|
|
9ae3a8 |
+ for (i = 0; i < NB_SUFFIXES; i++) {
|
|
|
9ae3a8 |
+ if (size < (10 * base)) {
|
|
|
9ae3a8 |
+ snprintf(buf, buf_size, "%0.1f%c",
|
|
|
9ae3a8 |
+ (double)size / base,
|
|
|
9ae3a8 |
+ suffixes[i]);
|
|
|
9ae3a8 |
+ break;
|
|
|
9ae3a8 |
+ } else if (size < (1000 * base) || i == (NB_SUFFIXES - 1)) {
|
|
|
9ae3a8 |
+ snprintf(buf, buf_size, "%" PRId64 "%c",
|
|
|
9ae3a8 |
+ ((size + (base >> 1)) / base),
|
|
|
9ae3a8 |
+ suffixes[i]);
|
|
|
9ae3a8 |
+ break;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ base = base * 1024;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ return buf;
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ char buf1[128], date_buf[128], clock_buf[128];
|
|
|
9ae3a8 |
+ struct tm tm;
|
|
|
9ae3a8 |
+ time_t ti;
|
|
|
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 |
+ } else {
|
|
|
9ae3a8 |
+ ti = sn->date_sec;
|
|
|
9ae3a8 |
+ localtime_r(&ti, &tm;;
|
|
|
9ae3a8 |
+ strftime(date_buf, sizeof(date_buf),
|
|
|
9ae3a8 |
+ "%Y-%m-%d %H:%M:%S", &tm;;
|
|
|
9ae3a8 |
+ secs = sn->vm_clock_nsec / 1000000000;
|
|
|
9ae3a8 |
+ snprintf(clock_buf, sizeof(clock_buf),
|
|
|
9ae3a8 |
+ "%02d:%02d:%02d.%03d",
|
|
|
9ae3a8 |
+ (int)(secs / 3600),
|
|
|
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 |
+ }
|
|
|
9ae3a8 |
+ return buf;
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+void bdrv_image_info_dump(ImageInfo *info)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ char size_buf[128], dsize_buf[128];
|
|
|
9ae3a8 |
+ if (!info->has_actual_size) {
|
|
|
9ae3a8 |
+ snprintf(dsize_buf, sizeof(dsize_buf), "unavailable");
|
|
|
9ae3a8 |
+ } else {
|
|
|
9ae3a8 |
+ get_human_readable_size(dsize_buf, sizeof(dsize_buf),
|
|
|
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 |
+
|
|
|
9ae3a8 |
+ if (info->has_encrypted && info->encrypted) {
|
|
|
9ae3a8 |
+ printf("encrypted: yes\n");
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (info->has_cluster_size) {
|
|
|
9ae3a8 |
+ printf("cluster_size: %" PRId64 "\n", info->cluster_size);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (info->has_dirty_flag && info->dirty_flag) {
|
|
|
9ae3a8 |
+ printf("cleanly shut down: no\n");
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (info->has_backing_filename) {
|
|
|
9ae3a8 |
+ printf("backing file: %s", info->backing_filename);
|
|
|
9ae3a8 |
+ if (info->has_full_backing_filename) {
|
|
|
9ae3a8 |
+ printf(" (actual path: %s)", info->full_backing_filename);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ putchar('\n');
|
|
|
9ae3a8 |
+ if (info->has_backing_filename_format) {
|
|
|
9ae3a8 |
+ printf("backing file format: %s\n", 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 |
+
|
|
|
9ae3a8 |
+ /* Ideally bdrv_snapshot_dump() would operate on SnapshotInfoList but
|
|
|
9ae3a8 |
+ * we convert to the block layer's native QEMUSnapshotInfo for now.
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+ for (elem = info->snapshots; elem; elem = elem->next) {
|
|
|
9ae3a8 |
+ QEMUSnapshotInfo sn = {
|
|
|
9ae3a8 |
+ .vm_state_size = elem->value->vm_state_size,
|
|
|
9ae3a8 |
+ .date_sec = elem->value->date_sec,
|
|
|
9ae3a8 |
+ .date_nsec = elem->value->date_nsec,
|
|
|
9ae3a8 |
+ .vm_clock_nsec = elem->value->vm_clock_sec * 1000000000ULL +
|
|
|
9ae3a8 |
+ elem->value->vm_clock_nsec,
|
|
|
9ae3a8 |
+ };
|
|
|
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 |
+ }
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
diff --git a/include/block/block.h b/include/block/block.h
|
|
|
9ae3a8 |
index fac1282..7695cae 100644
|
|
|
9ae3a8 |
--- a/include/block/block.h
|
|
|
9ae3a8 |
+++ b/include/block/block.h
|
|
|
9ae3a8 |
@@ -7,11 +7,6 @@
|
|
|
9ae3a8 |
#include "block/coroutine.h"
|
|
|
9ae3a8 |
#include "qapi/qmp/qobject.h"
|
|
|
9ae3a8 |
#include "qapi-types.h"
|
|
|
9ae3a8 |
-/*
|
|
|
9ae3a8 |
- * snapshot.h is needed since bdrv_snapshot_dump(), it can be removed when the
|
|
|
9ae3a8 |
- * function is moved to other file.
|
|
|
9ae3a8 |
- */
|
|
|
9ae3a8 |
-#include "block/snapshot.h"
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/* block.c */
|
|
|
9ae3a8 |
typedef struct BlockDriver BlockDriver;
|
|
|
9ae3a8 |
@@ -353,12 +348,8 @@ void bdrv_get_backing_filename(BlockDriverState *bs,
|
|
|
9ae3a8 |
char *filename, int filename_size);
|
|
|
9ae3a8 |
void bdrv_get_full_backing_filename(BlockDriverState *bs,
|
|
|
9ae3a8 |
char *dest, size_t sz);
|
|
|
9ae3a8 |
-BlockInfo *bdrv_query_info(BlockDriverState *s);
|
|
|
9ae3a8 |
-BlockStats *bdrv_query_stats(const BlockDriverState *bs);
|
|
|
9ae3a8 |
int bdrv_is_snapshot(BlockDriverState *bs);
|
|
|
9ae3a8 |
-char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-char *get_human_readable_size(char *buf, int buf_size, int64_t size);
|
|
|
9ae3a8 |
int path_is_absolute(const char *path);
|
|
|
9ae3a8 |
void path_combine(char *dest, int dest_size,
|
|
|
9ae3a8 |
const char *base_path,
|
|
|
9ae3a8 |
diff --git a/include/block/block_int.h b/include/block/block_int.h
|
|
|
9ae3a8 |
index 696bbb9..9348238 100644
|
|
|
9ae3a8 |
--- a/include/block/block_int.h
|
|
|
9ae3a8 |
+++ b/include/block/block_int.h
|
|
|
9ae3a8 |
@@ -33,6 +33,7 @@
|
|
|
9ae3a8 |
#include "qapi/qmp/qerror.h"
|
|
|
9ae3a8 |
#include "monitor/monitor.h"
|
|
|
9ae3a8 |
#include "qemu/hbitmap.h"
|
|
|
9ae3a8 |
+#include "block/snapshot.h"
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
#define BLOCK_FLAG_ENCRYPT 1
|
|
|
9ae3a8 |
#define BLOCK_FLAG_COMPAT6 4
|
|
|
9ae3a8 |
diff --git a/include/block/qapi.h b/include/block/qapi.h
|
|
|
9ae3a8 |
new file mode 100644
|
|
|
9ae3a8 |
index 0000000..55d1848
|
|
|
9ae3a8 |
--- /dev/null
|
|
|
9ae3a8 |
+++ b/include/block/qapi.h
|
|
|
9ae3a8 |
@@ -0,0 +1,41 @@
|
|
|
9ae3a8 |
+/*
|
|
|
9ae3a8 |
+ * Block layer qmp and info dump related functions
|
|
|
9ae3a8 |
+ *
|
|
|
9ae3a8 |
+ * Copyright (c) 2003-2008 Fabrice Bellard
|
|
|
9ae3a8 |
+ *
|
|
|
9ae3a8 |
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
9ae3a8 |
+ * of this software and associated documentation files (the "Software"), to deal
|
|
|
9ae3a8 |
+ * in the Software without restriction, including without limitation the rights
|
|
|
9ae3a8 |
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
9ae3a8 |
+ * copies of the Software, and to permit persons to whom the Software is
|
|
|
9ae3a8 |
+ * furnished to do so, subject to the following conditions:
|
|
|
9ae3a8 |
+ *
|
|
|
9ae3a8 |
+ * The above copyright notice and this permission notice shall be included in
|
|
|
9ae3a8 |
+ * all copies or substantial portions of the Software.
|
|
|
9ae3a8 |
+ *
|
|
|
9ae3a8 |
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
9ae3a8 |
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
9ae3a8 |
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
9ae3a8 |
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
9ae3a8 |
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
9ae3a8 |
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
9ae3a8 |
+ * THE SOFTWARE.
|
|
|
9ae3a8 |
+ */
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+#ifndef BLOCK_QAPI_H
|
|
|
9ae3a8 |
+#define BLOCK_QAPI_H
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+#include "qapi-types.h"
|
|
|
9ae3a8 |
+#include "block/block.h"
|
|
|
9ae3a8 |
+#include "block/snapshot.h"
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+void bdrv_collect_snapshots(BlockDriverState *bs , ImageInfo *info);
|
|
|
9ae3a8 |
+void bdrv_collect_image_info(BlockDriverState *bs,
|
|
|
9ae3a8 |
+ ImageInfo *info,
|
|
|
9ae3a8 |
+ const char *filename);
|
|
|
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 |
+#endif
|
|
|
9ae3a8 |
diff --git a/qemu-img.c b/qemu-img.c
|
|
|
9ae3a8 |
index 0f869f3..0bc084d 100644
|
|
|
9ae3a8 |
--- a/qemu-img.c
|
|
|
9ae3a8 |
+++ b/qemu-img.c
|
|
|
9ae3a8 |
@@ -30,6 +30,7 @@
|
|
|
9ae3a8 |
#include "qemu/osdep.h"
|
|
|
9ae3a8 |
#include "sysemu/sysemu.h"
|
|
|
9ae3a8 |
#include "block/block_int.h"
|
|
|
9ae3a8 |
+#include "block/qapi.h"
|
|
|
9ae3a8 |
#include <getopt.h>
|
|
|
9ae3a8 |
#include <stdio.h>
|
|
|
9ae3a8 |
#include <stdarg.h>
|
|
|
9ae3a8 |
@@ -1605,39 +1606,6 @@ static void dump_json_image_info_list(ImageInfoList *list)
|
|
|
9ae3a8 |
QDECREF(str);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-static void collect_snapshots(BlockDriverState *bs , ImageInfo *info)
|
|
|
9ae3a8 |
-{
|
|
|
9ae3a8 |
- int i, sn_count;
|
|
|
9ae3a8 |
- QEMUSnapshotInfo *sn_tab = NULL;
|
|
|
9ae3a8 |
- SnapshotInfoList *info_list, *cur_item = NULL;
|
|
|
9ae3a8 |
- sn_count = bdrv_snapshot_list(bs, &sn_tab);
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- for (i = 0; i < sn_count; i++) {
|
|
|
9ae3a8 |
- info->has_snapshots = true;
|
|
|
9ae3a8 |
- info_list = g_new0(SnapshotInfoList, 1);
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- info_list->value = g_new0(SnapshotInfo, 1);
|
|
|
9ae3a8 |
- info_list->value->id = g_strdup(sn_tab[i].id_str);
|
|
|
9ae3a8 |
- info_list->value->name = g_strdup(sn_tab[i].name);
|
|
|
9ae3a8 |
- info_list->value->vm_state_size = sn_tab[i].vm_state_size;
|
|
|
9ae3a8 |
- info_list->value->date_sec = sn_tab[i].date_sec;
|
|
|
9ae3a8 |
- info_list->value->date_nsec = sn_tab[i].date_nsec;
|
|
|
9ae3a8 |
- info_list->value->vm_clock_sec = sn_tab[i].vm_clock_nsec / 1000000000;
|
|
|
9ae3a8 |
- info_list->value->vm_clock_nsec = sn_tab[i].vm_clock_nsec % 1000000000;
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- /* XXX: waiting for the qapi to support qemu-queue.h types */
|
|
|
9ae3a8 |
- if (!cur_item) {
|
|
|
9ae3a8 |
- info->snapshots = cur_item = info_list;
|
|
|
9ae3a8 |
- } else {
|
|
|
9ae3a8 |
- cur_item->next = info_list;
|
|
|
9ae3a8 |
- cur_item = info_list;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- g_free(sn_tab);
|
|
|
9ae3a8 |
-}
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
static void dump_json_image_info(ImageInfo *info)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
Error *errp = NULL;
|
|
|
9ae3a8 |
@@ -1655,122 +1623,6 @@ static void dump_json_image_info(ImageInfo *info)
|
|
|
9ae3a8 |
QDECREF(str);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-static void collect_image_info(BlockDriverState *bs,
|
|
|
9ae3a8 |
- ImageInfo *info,
|
|
|
9ae3a8 |
- const char *filename,
|
|
|
9ae3a8 |
- const char *fmt)
|
|
|
9ae3a8 |
-{
|
|
|
9ae3a8 |
- uint64_t total_sectors;
|
|
|
9ae3a8 |
- char backing_filename[1024];
|
|
|
9ae3a8 |
- char backing_filename2[1024];
|
|
|
9ae3a8 |
- BlockDriverInfo bdi;
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- bdrv_get_geometry(bs, &total_sectors);
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- info->filename = g_strdup(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 |
- info->has_actual_size = info->actual_size >= 0;
|
|
|
9ae3a8 |
- if (bdrv_is_encrypted(bs)) {
|
|
|
9ae3a8 |
- info->encrypted = true;
|
|
|
9ae3a8 |
- info->has_encrypted = true;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- if (bdrv_get_info(bs, &bdi) >= 0) {
|
|
|
9ae3a8 |
- if (bdi.cluster_size != 0) {
|
|
|
9ae3a8 |
- info->cluster_size = bdi.cluster_size;
|
|
|
9ae3a8 |
- info->has_cluster_size = true;
|
|
|
9ae3a8 |
- }
|
|
|
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 |
- if (backing_filename[0] != '\0') {
|
|
|
9ae3a8 |
- info->backing_filename = g_strdup(backing_filename);
|
|
|
9ae3a8 |
- info->has_backing_filename = true;
|
|
|
9ae3a8 |
- bdrv_get_full_backing_filename(bs, backing_filename2,
|
|
|
9ae3a8 |
- sizeof(backing_filename2));
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- if (strcmp(backing_filename, backing_filename2) != 0) {
|
|
|
9ae3a8 |
- info->full_backing_filename =
|
|
|
9ae3a8 |
- g_strdup(backing_filename2);
|
|
|
9ae3a8 |
- info->has_full_backing_filename = true;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- if (bs->backing_format[0]) {
|
|
|
9ae3a8 |
- info->backing_filename_format = g_strdup(bs->backing_format);
|
|
|
9ae3a8 |
- info->has_backing_filename_format = true;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-}
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
-static void dump_human_image_info(ImageInfo *info)
|
|
|
9ae3a8 |
-{
|
|
|
9ae3a8 |
- char size_buf[128], dsize_buf[128];
|
|
|
9ae3a8 |
- if (!info->has_actual_size) {
|
|
|
9ae3a8 |
- snprintf(dsize_buf, sizeof(dsize_buf), "unavailable");
|
|
|
9ae3a8 |
- } else {
|
|
|
9ae3a8 |
- get_human_readable_size(dsize_buf, sizeof(dsize_buf),
|
|
|
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 |
-
|
|
|
9ae3a8 |
- if (info->has_encrypted && info->encrypted) {
|
|
|
9ae3a8 |
- printf("encrypted: yes\n");
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- if (info->has_cluster_size) {
|
|
|
9ae3a8 |
- printf("cluster_size: %" PRId64 "\n", info->cluster_size);
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- if (info->has_dirty_flag && info->dirty_flag) {
|
|
|
9ae3a8 |
- printf("cleanly shut down: no\n");
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- if (info->has_backing_filename) {
|
|
|
9ae3a8 |
- printf("backing file: %s", info->backing_filename);
|
|
|
9ae3a8 |
- if (info->has_full_backing_filename) {
|
|
|
9ae3a8 |
- printf(" (actual path: %s)", info->full_backing_filename);
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- putchar('\n');
|
|
|
9ae3a8 |
- if (info->has_backing_filename_format) {
|
|
|
9ae3a8 |
- printf("backing file format: %s\n", 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 |
-
|
|
|
9ae3a8 |
- /* Ideally bdrv_snapshot_dump() would operate on SnapshotInfoList but
|
|
|
9ae3a8 |
- * we convert to the block layer's native QEMUSnapshotInfo for now.
|
|
|
9ae3a8 |
- */
|
|
|
9ae3a8 |
- for (elem = info->snapshots; elem; elem = elem->next) {
|
|
|
9ae3a8 |
- QEMUSnapshotInfo sn = {
|
|
|
9ae3a8 |
- .vm_state_size = elem->value->vm_state_size,
|
|
|
9ae3a8 |
- .date_sec = elem->value->date_sec,
|
|
|
9ae3a8 |
- .date_nsec = elem->value->date_nsec,
|
|
|
9ae3a8 |
- .vm_clock_nsec = elem->value->vm_clock_sec * 1000000000ULL +
|
|
|
9ae3a8 |
- elem->value->vm_clock_nsec,
|
|
|
9ae3a8 |
- };
|
|
|
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 |
- }
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-}
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
static void dump_human_image_info_list(ImageInfoList *list)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
ImageInfoList *elem;
|
|
|
9ae3a8 |
@@ -1782,7 +1634,7 @@ static void dump_human_image_info_list(ImageInfoList *list)
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
delim = true;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- dump_human_image_info(elem->value);
|
|
|
9ae3a8 |
+ bdrv_image_info_dump(elem->value);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -1832,8 +1684,8 @@ static ImageInfoList *collect_image_info_list(const char *filename,
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
info = g_new0(ImageInfo, 1);
|
|
|
9ae3a8 |
- collect_image_info(bs, info, filename, fmt);
|
|
|
9ae3a8 |
- collect_snapshots(bs, info);
|
|
|
9ae3a8 |
+ bdrv_collect_image_info(bs, info, filename);
|
|
|
9ae3a8 |
+ bdrv_collect_snapshots(bs, info);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
elem = g_new0(ImageInfoList, 1);
|
|
|
9ae3a8 |
elem->value = info;
|
|
|
9ae3a8 |
diff --git a/savevm.c b/savevm.c
|
|
|
9ae3a8 |
index 005bf35..f126bff 100644
|
|
|
9ae3a8 |
--- a/savevm.c
|
|
|
9ae3a8 |
+++ b/savevm.c
|
|
|
9ae3a8 |
@@ -41,6 +41,7 @@
|
|
|
9ae3a8 |
#include "qemu/bitops.h"
|
|
|
9ae3a8 |
#include "qemu/iov.h"
|
|
|
9ae3a8 |
#include "block/snapshot.h"
|
|
|
9ae3a8 |
+#include "block/qapi.h"
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
#define SELF_ANNOUNCE_ROUNDS 5
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.7.1
|
|
|
9ae3a8 |
|