From: Kevin Wolf <kwolf@redhat.com>
To: anthony@codemonkey.ws
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 12/22] qmp: add query-block-jobs
Date: Thu, 26 Jan 2012 17:38:06 +0100 [thread overview]
Message-ID: <1327595896-19623-13-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1327595896-19623-1-git-send-email-kwolf@redhat.com>
From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Add query-block-jobs, which shows the progress of ongoing block device
operations.
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Acked-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
blockdev.c | 33 +++++++++++++++++++++++++++++++++
hmp.c | 36 ++++++++++++++++++++++++++++++++++++
hmp.h | 1 +
monitor.c | 7 +++++++
qapi-schema.json | 32 ++++++++++++++++++++++++++++++++
qmp-commands.hx | 6 ++++++
6 files changed, 115 insertions(+), 0 deletions(-)
diff --git a/blockdev.c b/blockdev.c
index d3d6718..d026cd4 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1006,3 +1006,36 @@ void qmp_block_job_cancel(const char *device, Error **errp)
trace_qmp_block_job_cancel(job);
block_job_cancel(job);
}
+
+static void do_qmp_query_block_jobs_one(void *opaque, BlockDriverState *bs)
+{
+ BlockJobInfoList **prev = opaque;
+ BlockJob *job = bs->job;
+
+ if (job) {
+ BlockJobInfoList *elem;
+ BlockJobInfo *info = g_new(BlockJobInfo, 1);
+ *info = (BlockJobInfo){
+ .type = g_strdup(job->job_type->job_type),
+ .device = g_strdup(bdrv_get_device_name(bs)),
+ .len = job->len,
+ .offset = job->offset,
+ .speed = job->speed,
+ };
+
+ elem = g_new0(BlockJobInfoList, 1);
+ elem->value = info;
+
+ (*prev)->next = elem;
+ *prev = elem;
+ }
+}
+
+BlockJobInfoList *qmp_query_block_jobs(Error **errp)
+{
+ /* Dummy is a fake list element for holding the head pointer */
+ BlockJobInfoList dummy = {};
+ BlockJobInfoList *prev = &dummy;
+ bdrv_iterate(do_qmp_query_block_jobs_one, &prev);
+ return dummy.next;
+}
diff --git a/hmp.c b/hmp.c
index 867c338..8ff8c94 100644
--- a/hmp.c
+++ b/hmp.c
@@ -509,6 +509,42 @@ void hmp_info_pci(Monitor *mon)
qapi_free_PciInfoList(info_list);
}
+void hmp_info_block_jobs(Monitor *mon)
+{
+ BlockJobInfoList *list;
+ Error *err = NULL;
+
+ list = qmp_query_block_jobs(&err);
+ assert(!err);
+
+ if (!list) {
+ monitor_printf(mon, "No active jobs\n");
+ return;
+ }
+
+ while (list) {
+ if (strcmp(list->value->type, "stream") == 0) {
+ monitor_printf(mon, "Streaming device %s: Completed %" PRId64
+ " of %" PRId64 " bytes, speed limit %" PRId64
+ " bytes/s\n",
+ list->value->device,
+ list->value->offset,
+ list->value->len,
+ list->value->speed);
+ } else {
+ monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
+ " of %" PRId64 " bytes, speed limit %" PRId64
+ " bytes/s\n",
+ list->value->type,
+ list->value->device,
+ list->value->offset,
+ list->value->len,
+ list->value->speed);
+ }
+ list = list->next;
+ }
+}
+
void hmp_quit(Monitor *mon, const QDict *qdict)
{
monitor_suspend(mon);
diff --git a/hmp.h b/hmp.h
index eb4ca82..18eecbd 100644
--- a/hmp.h
+++ b/hmp.h
@@ -32,6 +32,7 @@ void hmp_info_vnc(Monitor *mon);
void hmp_info_spice(Monitor *mon);
void hmp_info_balloon(Monitor *mon);
void hmp_info_pci(Monitor *mon);
+void hmp_info_block_jobs(Monitor *mon);
void hmp_quit(Monitor *mon, const QDict *qdict);
void hmp_stop(Monitor *mon, const QDict *qdict);
void hmp_system_reset(Monitor *mon, const QDict *qdict);
diff --git a/monitor.c b/monitor.c
index 9424c31..aadbdcb 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2318,6 +2318,13 @@ static mon_cmd_t info_cmds[] = {
.mhandler.info = hmp_info_blockstats,
},
{
+ .name = "block-jobs",
+ .args_type = "",
+ .params = "",
+ .help = "show progress of ongoing block device operations",
+ .mhandler.info = hmp_info_block_jobs,
+ },
+ {
.name = "registers",
.args_type = "",
.params = "",
diff --git a/qapi-schema.json b/qapi-schema.json
index 02c4e22..3f72c2c 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -845,6 +845,38 @@
{ 'command': 'query-pci', 'returns': ['PciInfo'] }
##
+# @BlockJobInfo:
+#
+# Information about a long-running block device operation.
+#
+# @type: the job type ('stream' for image streaming)
+#
+# @device: the block device name
+#
+# @len: the maximum progress value
+#
+# @offset: the current progress value
+#
+# @speed: the rate limit, bytes per second
+#
+# Since: 1.1
+##
+{ 'type': 'BlockJobInfo',
+ 'data': {'type': 'str', 'device': 'str', 'len': 'int',
+ 'offset': 'int', 'speed': 'int'} }
+
+##
+# @query-block-jobs:
+#
+# Return information about long-running block device operations.
+#
+# Returns: a list of @BlockJobInfo for each active block job
+#
+# Since: 1.1
+##
+{ 'command': 'query-block-jobs', 'returns': ['BlockJobInfo'] }
+
+##
# @quit:
#
# This command will cause the QEMU process to exit gracefully. While every
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 0795c5d..bd6b641 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -2014,6 +2014,12 @@ EQMP
},
{
+ .name = "query-block-jobs",
+ .args_type = "",
+ .mhandler.cmd_new = qmp_marshal_input_query_block_jobs,
+ },
+
+ {
.name = "qom-list",
.args_type = "path:s",
.mhandler.cmd_new = qmp_marshal_input_qom_list,
--
1.7.6.5
next prev parent reply other threads:[~2012-01-26 16:35 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-26 16:37 [Qemu-devel] [PULL 00/22] Block patches Kevin Wolf
2012-01-26 16:37 ` [Qemu-devel] [PATCH 01/22] rbd: wire up snapshot removal and rollback functionality Kevin Wolf
2012-01-26 16:37 ` [Qemu-devel] [PATCH 02/22] block: replace unchecked strdup/malloc/calloc with glib Kevin Wolf
2012-01-26 16:37 ` [Qemu-devel] [PATCH 03/22] coroutine: add co_sleep_ns() coroutine sleep function Kevin Wolf
2012-01-26 16:37 ` [Qemu-devel] [PATCH 04/22] block: check bdrv_in_use() before blockdev operations Kevin Wolf
2012-01-26 16:37 ` [Qemu-devel] [PATCH 05/22] block: make copy-on-read a per-request flag Kevin Wolf
2012-01-26 16:38 ` [Qemu-devel] [PATCH 06/22] block: add BlockJob interface for long-running operations Kevin Wolf
2012-01-26 16:38 ` [Qemu-devel] [PATCH 07/22] block: add image streaming block job Kevin Wolf
2012-01-26 16:38 ` [Qemu-devel] [PATCH 08/22] block: rate-limit streaming operations Kevin Wolf
2012-01-26 16:38 ` [Qemu-devel] [PATCH 09/22] qmp: add block_stream command Kevin Wolf
2012-01-26 16:38 ` [Qemu-devel] [PATCH 10/22] qmp: add block_job_set_speed command Kevin Wolf
2012-01-26 16:38 ` [Qemu-devel] [PATCH 11/22] qmp: add block_job_cancel command Kevin Wolf
2012-01-26 16:38 ` Kevin Wolf [this message]
2012-01-26 16:38 ` [Qemu-devel] [PATCH 13/22] blockdev: make image streaming safe across hotplug Kevin Wolf
2012-01-26 16:38 ` [Qemu-devel] [PATCH 14/22] block: add bdrv_find_backing_image Kevin Wolf
2012-01-26 16:38 ` [Qemu-devel] [PATCH 15/22] add QERR_BASE_NOT_FOUND Kevin Wolf
2012-01-26 16:38 ` [Qemu-devel] [PATCH 16/22] block: add support for partial streaming Kevin Wolf
2012-01-26 16:38 ` [Qemu-devel] [PATCH 17/22] docs: describe live block operations Kevin Wolf
2012-01-26 16:38 ` [Qemu-devel] [PATCH 18/22] virtio-blk: add virtio_blk_handle_read trace event Kevin Wolf
2012-01-26 16:38 ` [Qemu-devel] [PATCH 19/22] block/vdi: Zero unused parts when allocating a new block (fix #919242) Kevin Wolf
2012-01-26 16:38 ` [Qemu-devel] [PATCH 20/22] qcow: Return real error code in qcow_open Kevin Wolf
2012-01-26 16:38 ` [Qemu-devel] [PATCH 21/22] qcow: Use bdrv functions to replace file operation Kevin Wolf
2012-01-26 16:38 ` [Qemu-devel] [PATCH 22/22] scsi: Guard against buflen exceeding req->cmd.xfer in scsi_disk_emulate_command Kevin Wolf
2012-01-27 17:33 ` [Qemu-devel] [PULL 00/22] Block patches Anthony Liguori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1327595896-19623-13-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=anthony@codemonkey.ws \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).