aboutsummaryrefslogtreecommitdiff
path: root/blockdev.c
diff options
context:
space:
mode:
authorStefan Hajnoczi <stefanha@linux.vnet.ibm.com>2012-01-18 14:40:49 +0000
committerKevin Wolf <kwolf@redhat.com>2012-01-26 14:49:18 +0100
commitfb5458cd10a199e55e622a906b24f8085d922c0f (patch)
treee2de2dfca92c204c38fc35efdd1574e035029c94 /blockdev.c
parent370521a1d6f5537ea7271c119f3fbb7b0fa57063 (diff)
qmp: add query-block-jobs
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>
Diffstat (limited to 'blockdev.c')
-rw-r--r--blockdev.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/blockdev.c b/blockdev.c
index d3d6718056..d026cd4fda 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;
+}