cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
0a122b
From b55e2f4749d2e4ebfc7dfc8782de85391c1026e8 Mon Sep 17 00:00:00 2001
0a122b
From: Fam Zheng <famz@redhat.com>
0a122b
Date: Fri, 17 Jan 2014 03:08:00 +0100
0a122b
Subject: [PATCH 17/34] commit: Support commit active layer
0a122b
0a122b
RH-Author: Fam Zheng <famz@redhat.com>
0a122b
Message-id: <1389928083-8921-16-git-send-email-famz@redhat.com>
0a122b
Patchwork-id: 56777
0a122b
O-Subject: [RHEL-7 qemu-kvm PATCH 15/18] commit: Support commit active layer
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
If active is top, it will be mirrored to base, (with block/mirror.c
0a122b
code), then the image is switched when user completes the block job.
0a122b
0a122b
QMP documentation is updated.
0a122b
0a122b
Signed-off-by: Fam Zheng <famz@redhat.com>
0a122b
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
(cherry picked from commit 20a63d2cec838c2dde4d246c4d7abe747d9b7a11)
0a122b
Signed-off-by: Fam Zheng <famz@redhat.com>
0a122b
---
0a122b
 block/mirror.c   | 11 +++++++++++
0a122b
 blockdev.c       |  9 +++++++--
0a122b
 qapi-schema.json |  5 +++--
0a122b
 3 files changed, 21 insertions(+), 4 deletions(-)
0a122b
0a122b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
0a122b
---
0a122b
 block/mirror.c   |   11 +++++++++++
0a122b
 blockdev.c       |    9 +++++++--
0a122b
 qapi-schema.json |    5 +++--
0a122b
 3 files changed, 21 insertions(+), 4 deletions(-)
0a122b
0a122b
diff --git a/block/mirror.c b/block/mirror.c
0a122b
index 01fe379..6e1f9b1 100644
0a122b
--- a/block/mirror.c
0a122b
+++ b/block/mirror.c
0a122b
@@ -478,6 +478,13 @@ immediate_exit:
0a122b
             bdrv_reopen(s->target, bdrv_get_flags(s->common.bs), NULL);
0a122b
         }
0a122b
         bdrv_swap(s->target, s->common.bs);
0a122b
+        if (s->common.driver->job_type == BLOCK_JOB_TYPE_COMMIT) {
0a122b
+            /* drop the bs loop chain formed by the swap: break the loop then
0a122b
+             * trigger the unref from the top one */
0a122b
+            BlockDriverState *p = s->base->backing_hd;
0a122b
+            s->base->backing_hd = NULL;
0a122b
+            bdrv_unref(p);
0a122b
+        }
0a122b
     }
0a122b
     bdrv_unref(s->target);
0a122b
     block_job_completed(&s->common, ret);
0a122b
@@ -620,6 +627,10 @@ void commit_active_start(BlockDriverState *bs, BlockDriverState *base,
0a122b
                          BlockDriverCompletionFunc *cb,
0a122b
                          void *opaque, Error **errp)
0a122b
 {
0a122b
+    if (bdrv_reopen(base, bs->open_flags, errp)) {
0a122b
+        return;
0a122b
+    }
0a122b
+    bdrv_ref(base);
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
diff --git a/blockdev.c b/blockdev.c
0a122b
index d795af2..33a5f5f 100644
0a122b
--- a/blockdev.c
0a122b
+++ b/blockdev.c
0a122b
@@ -1510,8 +1510,13 @@ void qmp_block_commit(const char *device,
0a122b
         return;
0a122b
     }
0a122b
 
0a122b
-    commit_start(bs, base_bs, top_bs, speed, on_error, block_job_cb, bs,
0a122b
-                &local_err);
0a122b
+    if (top_bs == bs) {
0a122b
+        commit_active_start(bs, base_bs, speed, on_error, block_job_cb,
0a122b
+                            bs, &local_err);
0a122b
+    } else {
0a122b
+        commit_start(bs, base_bs, top_bs, speed, on_error, block_job_cb, bs,
0a122b
+                    &local_err);
0a122b
+    }
0a122b
     if (local_err != NULL) {
0a122b
         error_propagate(errp, local_err);
0a122b
         return;
0a122b
diff --git a/qapi-schema.json b/qapi-schema.json
0a122b
index b0bd53c..a783e8e 100644
0a122b
--- a/qapi-schema.json
0a122b
+++ b/qapi-schema.json
0a122b
@@ -1837,9 +1837,11 @@
0a122b
 #
0a122b
 # @top:              The file name of the backing image within the image chain,
0a122b
 #                    which contains the topmost data to be committed down.
0a122b
-#                    Note, the active layer as 'top' is currently unsupported.
0a122b
 #
0a122b
 #                    If top == base, that is an error.
0a122b
+#                    If top == active, the job will not be completed by itself,
0a122b
+#                    user needs to complete the job with the block-job-complete
0a122b
+#                    command after getting the ready event. (Since 2.0)
0a122b
 #
0a122b
 #
0a122b
 # @speed:  #optional the maximum speed, in bytes per second
0a122b
@@ -1849,7 +1851,6 @@
0a122b
 #          If @device does not exist, DeviceNotFound
0a122b
 #          If image commit is not supported by this device, NotSupported
0a122b
 #          If @base or @top is invalid, a generic error is returned
0a122b
-#          If @top is the active layer, or omitted, a generic error is returned
0a122b
 #          If @speed is invalid, InvalidParameter
0a122b
 #
0a122b
 # Since: 1.3
0a122b
-- 
0a122b
1.7.1
0a122b