diff mbox

[v5,4/6] commit: support commit active layer

Message ID 1381295983-18945-5-git-send-email-famz@redhat.com
State New
Headers show

Commit Message

Fam Zheng Oct. 9, 2013, 5:19 a.m. UTC
If active is top, it will be mirrored to base, (with block/mirror.c
code), then the image is switched when user completes the block job.

QMP documentation is updated.

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 block/mirror.c   | 11 +++++++++++
 blockdev.c       |  9 +++++++--
 qapi-schema.json |  5 +++--
 3 files changed, 21 insertions(+), 4 deletions(-)

Comments

Stefan Hajnoczi Nov. 25, 2013, 10:28 a.m. UTC | #1
On Wed, Oct 09, 2013 at 01:19:41PM +0800, Fam Zheng wrote:
> diff --git a/qapi-schema.json b/qapi-schema.json
> index 381ffbf..eb13707 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -1910,9 +1910,11 @@
>  #
>  # @top:              The file name of the backing image within the image chain,
>  #                    which contains the topmost data to be committed down.
> -#                    Note, the active layer as 'top' is currently unsupported.
>  #
>  #                    If top == base, that is an error.
> +#                    If top == active, the job will not be completed by itself,
> +#                    user need to complete the job with block-job-complete

s/need/needs/
s/with block-job-complete/with the block-job-complete/

> +#                    command after getting the ready event. (Since 1.7)

s/1.7/1.8/
diff mbox

Patch

diff --git a/block/mirror.c b/block/mirror.c
index 9be741a..86ffac8 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -478,6 +478,13 @@  immediate_exit:
             bdrv_reopen(s->target, bdrv_get_flags(s->common.bs), NULL);
         }
         bdrv_swap(s->target, s->common.bs);
+        if (s->common.driver->job_type == BLOCK_JOB_TYPE_COMMIT) {
+            /* drop the bs loop chain formed by the swap: break the loop then
+             * trigger the unref from the top one */
+            BlockDriverState *p = s->base->backing_hd;
+            s->base->backing_hd = NULL;
+            bdrv_unref(p);
+        }
     }
     bdrv_unref(s->target);
     block_job_completed(&s->common, ret);
@@ -619,6 +626,10 @@  void commit_active_start(BlockDriverState *bs, BlockDriverState *base,
                          BlockDriverCompletionFunc *cb,
                          void *opaque, Error **errp)
 {
+    if (bdrv_reopen(base, bs->open_flags, errp)) {
+        return;
+    }
+    bdrv_ref(base);
     mirror_start_job(bs, base, speed, 0, 0,
                      on_error, on_error, cb, opaque, errp,
                      &commit_active_job_driver, false, base);
diff --git a/blockdev.c b/blockdev.c
index 8aa66a9..77cbd1d 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1710,8 +1710,13 @@  void qmp_block_commit(const char *device,
         return;
     }
 
-    commit_start(bs, base_bs, top_bs, speed, on_error, block_job_cb, bs,
-                &local_err);
+    if (top_bs == bs) {
+        commit_active_start(bs, base_bs, speed, on_error, block_job_cb,
+                            bs, &local_err);
+    } else {
+        commit_start(bs, base_bs, top_bs, speed, on_error, block_job_cb, bs,
+                    &local_err);
+    }
     if (local_err != NULL) {
         error_propagate(errp, local_err);
         return;
diff --git a/qapi-schema.json b/qapi-schema.json
index 381ffbf..eb13707 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -1910,9 +1910,11 @@ 
 #
 # @top:              The file name of the backing image within the image chain,
 #                    which contains the topmost data to be committed down.
-#                    Note, the active layer as 'top' is currently unsupported.
 #
 #                    If top == base, that is an error.
+#                    If top == active, the job will not be completed by itself,
+#                    user need to complete the job with block-job-complete
+#                    command after getting the ready event. (Since 1.7)
 #
 #
 # @speed:  #optional the maximum speed, in bytes per second
@@ -1922,7 +1924,6 @@ 
 #          If @device does not exist, DeviceNotFound
 #          If image commit is not supported by this device, NotSupported
 #          If @base or @top is invalid, a generic error is returned
-#          If @top is the active layer, or omitted, a generic error is returned
 #          If @speed is invalid, InvalidParameter
 #
 # Since: 1.3