thebeanogamer / rpms / qemu-kvm

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