cryptospore / rpms / qemu-kvm

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