Patchwork [29/47] mirror: support querying target file

login
register
mail settings
Submitter Paolo Bonzini
Date July 24, 2012, 11:04 a.m.
Message ID <1343127865-16608-30-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/172864/
State New
Headers show

Comments

Paolo Bonzini - July 24, 2012, 11:04 a.m.
This lets query-block-jobs retrieve information and statistics on the
mirroring target.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 block/mirror.c |   11 +++++++++++
 blockjob.c     |    2 +-
 2 files changed, 12 insertions(+), 1 deletion(-)

Patch

diff --git a/block/mirror.c b/block/mirror.c
index f7d36f9..9c8ebd4 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -205,10 +205,21 @@  static void mirror_set_speed(BlockJob *job, int64_t speed, Error **errp)
     ratelimit_set_speed(&s->limit, speed / BDRV_SECTOR_SIZE, SLICE_TIME);
 }
 
+static void mirror_query(BlockJob *job, BlockJobInfo *info)
+{
+    MirrorBlockJob *s = container_of(job, MirrorBlockJob, common);
+
+    info->has_target = true;
+    info->target = g_new0(BlockJobTargetInfo, 1);
+    info->target->info = bdrv_query_info(s->target);
+    info->target->stats = bdrv_query_stats(s->target);
+}
+
 static BlockJobType mirror_job_type = {
     .instance_size = sizeof(MirrorBlockJob),
     .job_type      = "mirror",
     .set_speed     = mirror_set_speed,
+    .query         = mirror_query,
 };
 
 void mirror_start(BlockDriverState *bs, BlockDriverState *target,
diff --git a/blockjob.c b/blockjob.c
index b5a4033..42485bf 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -199,7 +199,7 @@  void block_job_sleep_ns(BlockJob *job, QEMUClock *clock, int64_t ns)
 
 BlockJobInfo *block_job_query(BlockJob *job)
 {
-    BlockJobInfo *info = g_new(BlockJobInfo, 1);
+    BlockJobInfo *info = g_new0(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;