cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
9ae3a8
From d432da3600bfb48139ee10373122c250a9f5a003 Mon Sep 17 00:00:00 2001
9ae3a8
From: Fam Zheng <famz@redhat.com>
9ae3a8
Date: Fri, 17 Jan 2014 03:07:59 +0100
9ae3a8
Subject: [PATCH 16/34] block: Add commit_active_start()
9ae3a8
9ae3a8
RH-Author: Fam Zheng <famz@redhat.com>
9ae3a8
Message-id: <1389928083-8921-15-git-send-email-famz@redhat.com>
9ae3a8
Patchwork-id: 56776
9ae3a8
O-Subject: [RHEL-7 qemu-kvm PATCH 14/18] block: Add commit_active_start()
9ae3a8
Bugzilla: 1041301
9ae3a8
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
9ae3a8
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
9ae3a8
commit_active_start is implemented in block/mirror.c, It will create a
9ae3a8
job with "commit" type and designated base in block-commit command. This
9ae3a8
will be used for committing active layer of device.
9ae3a8
9ae3a8
Sync mode is removed from MirrorBlockJob because there's no proper type
9ae3a8
for commit. The used information is is_none_mode.
9ae3a8
9ae3a8
The common part of mirror_start and commit_active_start is moved to
9ae3a8
mirror_start_job().
9ae3a8
9ae3a8
Fix the comment wording for commit_start.
9ae3a8
9ae3a8
Signed-off-by: Fam Zheng <famz@redhat.com>
9ae3a8
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
(cherry picked from commit 03544a6e9ecc1be115e8a29bd929f83b467d4816)
9ae3a8
Signed-off-by: Fam Zheng <famz@redhat.com>
9ae3a8
---
9ae3a8
 block/mirror.c            | 66 +++++++++++++++++++++++++++++++++++------------
9ae3a8
 include/block/block_int.h | 22 +++++++++++++---
9ae3a8
 2 files changed, 69 insertions(+), 19 deletions(-)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 block/mirror.c            |   66 ++++++++++++++++++++++++++++++++++-----------
9ae3a8
 include/block/block_int.h |   22 +++++++++++++--
9ae3a8
 2 files changed, 69 insertions(+), 19 deletions(-)
9ae3a8
9ae3a8
diff --git a/block/mirror.c b/block/mirror.c
9ae3a8
index 8ccde2f..01fe379 100644
9ae3a8
--- a/block/mirror.c
9ae3a8
+++ b/block/mirror.c
9ae3a8
@@ -32,7 +32,7 @@ typedef struct MirrorBlockJob {
9ae3a8
     RateLimit limit;
9ae3a8
     BlockDriverState *target;
9ae3a8
     BlockDriverState *base;
9ae3a8
-    MirrorSyncMode mode;
9ae3a8
+    bool is_none_mode;
9ae3a8
     BlockdevOnError on_source_error, on_target_error;
9ae3a8
     bool synced;
9ae3a8
     bool should_complete;
9ae3a8
@@ -333,7 +333,7 @@ static void coroutine_fn mirror_run(void *opaque)
9ae3a8
     sectors_per_chunk = s->granularity >> BDRV_SECTOR_BITS;
9ae3a8
     mirror_free_init(s);
9ae3a8
 
9ae3a8
-    if (s->mode != MIRROR_SYNC_MODE_NONE) {
9ae3a8
+    if (!s->is_none_mode) {
9ae3a8
         /* First part, loop on the sectors and initialize the dirty bitmap.  */
9ae3a8
         BlockDriverState *base = s->base;
9ae3a8
         for (sector_num = 0; sector_num < end; ) {
9ae3a8
@@ -532,15 +532,26 @@ static const BlockJobDriver mirror_job_driver = {
9ae3a8
     .complete      = mirror_complete,
9ae3a8
 };
9ae3a8
 
9ae3a8
-void mirror_start(BlockDriverState *bs, BlockDriverState *target,
9ae3a8
-                  int64_t speed, int64_t granularity, int64_t buf_size,
9ae3a8
-                  MirrorSyncMode mode, BlockdevOnError on_source_error,
9ae3a8
-                  BlockdevOnError on_target_error,
9ae3a8
-                  BlockDriverCompletionFunc *cb,
9ae3a8
-                  void *opaque, Error **errp)
9ae3a8
+static const BlockJobDriver commit_active_job_driver = {
9ae3a8
+    .instance_size = sizeof(MirrorBlockJob),
9ae3a8
+    .job_type      = BLOCK_JOB_TYPE_COMMIT,
9ae3a8
+    .set_speed     = mirror_set_speed,
9ae3a8
+    .iostatus_reset
9ae3a8
+                   = mirror_iostatus_reset,
9ae3a8
+    .complete      = mirror_complete,
9ae3a8
+};
9ae3a8
+
9ae3a8
+static void mirror_start_job(BlockDriverState *bs, BlockDriverState *target,
9ae3a8
+                            int64_t speed, int64_t granularity,
9ae3a8
+                            int64_t buf_size,
9ae3a8
+                            BlockdevOnError on_source_error,
9ae3a8
+                            BlockdevOnError on_target_error,
9ae3a8
+                            BlockDriverCompletionFunc *cb,
9ae3a8
+                            void *opaque, Error **errp,
9ae3a8
+                            const BlockJobDriver *driver,
9ae3a8
+                            bool is_none_mode, BlockDriverState *base)
9ae3a8
 {
9ae3a8
     MirrorBlockJob *s;
9ae3a8
-    BlockDriverState *base = NULL;
9ae3a8
 
9ae3a8
     if (granularity == 0) {
9ae3a8
         /* Choose the default granularity based on the target file's cluster
9ae3a8
@@ -563,13 +574,8 @@ void mirror_start(BlockDriverState *bs, BlockDriverState *target,
9ae3a8
         return;
9ae3a8
     }
9ae3a8
 
9ae3a8
-    if (mode == MIRROR_SYNC_MODE_TOP) {
9ae3a8
-        base = bs->backing_hd;
9ae3a8
-    } else {
9ae3a8
-        base = NULL;
9ae3a8
-    }
9ae3a8
 
9ae3a8
-    s = block_job_create(&mirror_job_driver, bs, speed, cb, opaque, errp);
9ae3a8
+    s = block_job_create(driver, bs, speed, cb, opaque, errp);
9ae3a8
     if (!s) {
9ae3a8
         return;
9ae3a8
     }
9ae3a8
@@ -577,7 +583,7 @@ void mirror_start(BlockDriverState *bs, BlockDriverState *target,
9ae3a8
     s->on_source_error = on_source_error;
9ae3a8
     s->on_target_error = on_target_error;
9ae3a8
     s->target = target;
9ae3a8
-    s->mode = mode;
9ae3a8
+    s->is_none_mode = is_none_mode;
9ae3a8
     s->base = base;
9ae3a8
     s->granularity = granularity;
9ae3a8
     s->buf_size = MAX(buf_size, granularity);
9ae3a8
@@ -590,3 +596,31 @@ void mirror_start(BlockDriverState *bs, BlockDriverState *target,
9ae3a8
     trace_mirror_start(bs, s, s->common.co, opaque);
9ae3a8
     qemu_coroutine_enter(s->common.co, s);
9ae3a8
 }
9ae3a8
+
9ae3a8
+void mirror_start(BlockDriverState *bs, BlockDriverState *target,
9ae3a8
+                  int64_t speed, int64_t granularity, int64_t buf_size,
9ae3a8
+                  MirrorSyncMode mode, BlockdevOnError on_source_error,
9ae3a8
+                  BlockdevOnError on_target_error,
9ae3a8
+                  BlockDriverCompletionFunc *cb,
9ae3a8
+                  void *opaque, Error **errp)
9ae3a8
+{
9ae3a8
+    bool is_none_mode;
9ae3a8
+    BlockDriverState *base;
9ae3a8
+
9ae3a8
+    is_none_mode = mode == MIRROR_SYNC_MODE_NONE;
9ae3a8
+    base = mode == MIRROR_SYNC_MODE_TOP ? bs->backing_hd : NULL;
9ae3a8
+    mirror_start_job(bs, target, speed, granularity, buf_size,
9ae3a8
+                     on_source_error, on_target_error, cb, opaque, errp,
9ae3a8
+                     &mirror_job_driver, is_none_mode, base);
9ae3a8
+}
9ae3a8
+
9ae3a8
+void commit_active_start(BlockDriverState *bs, BlockDriverState *base,
9ae3a8
+                         int64_t speed,
9ae3a8
+                         BlockdevOnError on_error,
9ae3a8
+                         BlockDriverCompletionFunc *cb,
9ae3a8
+                         void *opaque, Error **errp)
9ae3a8
+{
9ae3a8
+    mirror_start_job(bs, base, speed, 0, 0,
9ae3a8
+                     on_error, on_error, cb, opaque, errp,
9ae3a8
+                     &commit_active_job_driver, false, base);
9ae3a8
+}
9ae3a8
diff --git a/include/block/block_int.h b/include/block/block_int.h
9ae3a8
index fbfdab7..c8f30fd 100644
9ae3a8
--- a/include/block/block_int.h
9ae3a8
+++ b/include/block/block_int.h
9ae3a8
@@ -374,8 +374,9 @@ void stream_start(BlockDriverState *bs, BlockDriverState *base,
9ae3a8
 
9ae3a8
 /**
9ae3a8
  * commit_start:
9ae3a8
- * @bs: Top Block device
9ae3a8
- * @base: Block device that will be written into, and become the new top
9ae3a8
+ * @bs: Active block device.
9ae3a8
+ * @top: Top block device to be committed.
9ae3a8
+ * @base: Block device that will be written into, and become the new top.
9ae3a8
  * @speed: The maximum speed, in bytes per second, or 0 for unlimited.
9ae3a8
  * @on_error: The action to take upon error.
9ae3a8
  * @cb: Completion function for the job.
9ae3a8
@@ -387,7 +388,22 @@ void commit_start(BlockDriverState *bs, BlockDriverState *base,
9ae3a8
                  BlockDriverState *top, int64_t speed,
9ae3a8
                  BlockdevOnError on_error, BlockDriverCompletionFunc *cb,
9ae3a8
                  void *opaque, Error **errp);
9ae3a8
-
9ae3a8
+/**
9ae3a8
+ * commit_active_start:
9ae3a8
+ * @bs: Active block device to be committed.
9ae3a8
+ * @base: Block device that will be written into, and become the new top.
9ae3a8
+ * @speed: The maximum speed, in bytes per second, or 0 for unlimited.
9ae3a8
+ * @on_error: The action to take upon error.
9ae3a8
+ * @cb: Completion function for the job.
9ae3a8
+ * @opaque: Opaque pointer value passed to @cb.
9ae3a8
+ * @errp: Error object.
9ae3a8
+ *
9ae3a8
+ */
9ae3a8
+void commit_active_start(BlockDriverState *bs, BlockDriverState *base,
9ae3a8
+                         int64_t speed,
9ae3a8
+                         BlockdevOnError on_error,
9ae3a8
+                         BlockDriverCompletionFunc *cb,
9ae3a8
+                         void *opaque, Error **errp);
9ae3a8
 /*
9ae3a8
  * mirror_start:
9ae3a8
  * @bs: Block device to operate on.
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8