Patchwork [RFC,04/36] block: add block_job_query

login
register
mail settings
Submitter Paolo Bonzini
Date June 15, 2012, 3:05 p.m.
Message ID <1339772759-31004-5-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/165185/
State New
Headers show

Comments

Paolo Bonzini - June 15, 2012, 3:05 p.m.
Extract it out of the implementation of info block-jobs.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 blockdev.c |   15 ++-------------
 blockjob.c |   10 ++++++++++
 blockjob.h |    8 ++++++++
 3 files changed, 20 insertions(+), 13 deletions(-)

Patch

diff --git a/blockdev.c b/blockdev.c
index fe270cd..3dba4b8 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1170,19 +1170,8 @@  static void do_qmp_query_block_jobs_one(void *opaque, BlockDriverState *bs)
     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;
-
+        BlockJobInfoList *elem = g_new0(BlockJobInfoList, 1);
+        elem->value = block_job_query(bs->job);
         (*prev)->next = elem;
         *prev = elem;
     }
diff --git a/blockjob.c b/blockjob.c
index accd646..a947a6e 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -162,3 +162,13 @@  void block_job_sleep_ns(BlockJob *job, QEMUClock *clock, int64_t ns)
     }
 }
 
+BlockJobInfo *block_job_query(BlockJob *job)
+{
+    BlockJobInfo *info = g_new(BlockJobInfo, 1);
+    info->type   = g_strdup(job->job_type->job_type);
+    info->device = g_strdup(bdrv_get_device_name(job->bs));
+    info->len    = job->len;
+    info->offset = job->offset;
+    info->speed  = job->speed;
+    return info;
+}
diff --git a/blockjob.h b/blockjob.h
index abcb2ee..32854b8 100644
--- a/blockjob.h
+++ b/blockjob.h
@@ -165,6 +165,14 @@  void block_job_cancel(BlockJob *job);
 bool block_job_is_cancelled(BlockJob *job);
 
 /**
+ * block_job_query:
+ * @job: The job to get information about.
+ *
+ * Return information about a job.
+ */
+BlockJobInfo *block_job_query(BlockJob *job);
+
+/**
  * block_job_cancel_sync:
  * @job: The job to be canceled.
  *