yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
26ba25
From 736bcac80123ee6415953277449359722ae93d37 Mon Sep 17 00:00:00 2001
26ba25
From: Kevin Wolf <kwolf@redhat.com>
26ba25
Date: Wed, 10 Oct 2018 13:50:54 +0100
26ba25
Subject: [PATCH 4/5] commit: Add top-node/base-node options
26ba25
26ba25
RH-Author: Kevin Wolf <kwolf@redhat.com>
26ba25
Message-id: <20181010135055.3874-2-kwolf@redhat.com>
26ba25
Patchwork-id: 82569
26ba25
O-Subject: [RHEL-8 qemu-kvm PATCH 1/2] commit: Add top-node/base-node options
26ba25
Bugzilla: 1637970
26ba25
RH-Acked-by: John Snow <jsnow@redhat.com>
26ba25
RH-Acked-by: Fam Zheng <famz@redhat.com>
26ba25
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
26ba25
26ba25
The block-commit QMP command required specifying the top and base nodes
26ba25
of the commit jobs using the file name of that node. While this works
26ba25
in simple cases (local files with absolute paths), the file names
26ba25
generated for more complicated setups can be hard to predict.
26ba25
26ba25
The block-commit command has more problems than just this, so we want to
26ba25
replace it altogether in the long run, but libvirt needs a reliable way
26ba25
to address nodes now. So we don't want to wait for a new, cleaner
26ba25
command, but just add the minimal thing needed right now.
26ba25
26ba25
This adds two new options top-node and base-node to the command, which
26ba25
allow specifying node names instead. They are mutually exclusive with
26ba25
the old options.
26ba25
26ba25
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
26ba25
(cherry picked from commit 3c605f4074ebeb97970eb660fb56a9cb06525923)
26ba25
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
26ba25
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
26ba25
---
26ba25
 blockdev.c           | 32 ++++++++++++++++++++++++++++++--
26ba25
 qapi/block-core.json | 24 ++++++++++++++++++------
26ba25
 2 files changed, 48 insertions(+), 8 deletions(-)
26ba25
26ba25
diff --git a/blockdev.c b/blockdev.c
26ba25
index b8e4b0d..70af034 100644
26ba25
--- a/blockdev.c
26ba25
+++ b/blockdev.c
26ba25
@@ -3325,7 +3325,9 @@ out:
26ba25
 }
26ba25
 
26ba25
 void qmp_block_commit(bool has_job_id, const char *job_id, const char *device,
26ba25
+                      bool has_base_node, const char *base_node,
26ba25
                       bool has_base, const char *base,
26ba25
+                      bool has_top_node, const char *top_node,
26ba25
                       bool has_top, const char *top,
26ba25
                       bool has_backing_file, const char *backing_file,
26ba25
                       bool has_speed, int64_t speed,
26ba25
@@ -3386,7 +3388,20 @@ void qmp_block_commit(bool has_job_id, const char *job_id, const char *device,
26ba25
     /* default top_bs is the active layer */
26ba25
     top_bs = bs;
26ba25
 
26ba25
-    if (has_top && top) {
26ba25
+    if (has_top_node && has_top) {
26ba25
+        error_setg(errp, "'top-node' and 'top' are mutually exclusive");
26ba25
+        goto out;
26ba25
+    } else if (has_top_node) {
26ba25
+        top_bs = bdrv_lookup_bs(NULL, top_node, errp);
26ba25
+        if (top_bs == NULL) {
26ba25
+            goto out;
26ba25
+        }
26ba25
+        if (!bdrv_chain_contains(bs, top_bs)) {
26ba25
+            error_setg(errp, "'%s' is not in this backing file chain",
26ba25
+                       top_node);
26ba25
+            goto out;
26ba25
+        }
26ba25
+    } else if (has_top && top) {
26ba25
         if (strcmp(bs->filename, top) != 0) {
26ba25
             top_bs = bdrv_find_backing_image(bs, top);
26ba25
         }
26ba25
@@ -3399,7 +3414,20 @@ void qmp_block_commit(bool has_job_id, const char *job_id, const char *device,
26ba25
 
26ba25
     assert(bdrv_get_aio_context(top_bs) == aio_context);
26ba25
 
26ba25
-    if (has_base && base) {
26ba25
+    if (has_base_node && has_base) {
26ba25
+        error_setg(errp, "'base-node' and 'base' are mutually exclusive");
26ba25
+        goto out;
26ba25
+    } else if (has_base_node) {
26ba25
+        base_bs = bdrv_lookup_bs(NULL, base_node, errp);
26ba25
+        if (base_bs == NULL) {
26ba25
+            goto out;
26ba25
+        }
26ba25
+        if (!bdrv_chain_contains(top_bs, base_bs)) {
26ba25
+            error_setg(errp, "'%s' is not in this backing file chain",
26ba25
+                       base_node);
26ba25
+            goto out;
26ba25
+        }
26ba25
+    } else if (has_base && base) {
26ba25
         base_bs = bdrv_find_backing_image(top_bs, base);
26ba25
     } else {
26ba25
         base_bs = bdrv_find_base(top_bs);
26ba25
diff --git a/qapi/block-core.json b/qapi/block-core.json
26ba25
index 602c028..5fb7983 100644
26ba25
--- a/qapi/block-core.json
26ba25
+++ b/qapi/block-core.json
26ba25
@@ -1434,12 +1434,23 @@
26ba25
 #
26ba25
 # @device:  the device name or node-name of a root node
26ba25
 #
26ba25
-# @base:   The file name of the backing image to write data into.
26ba25
-#                    If not specified, this is the deepest backing image.
26ba25
+# @base-node: The node name of the backing image to write data into.
26ba25
+#             If not specified, this is the deepest backing image.
26ba25
+#             (since: 3.1)
26ba25
 #
26ba25
-# @top:    The file name of the backing image within the image chain,
26ba25
-#                    which contains the topmost data to be committed down. If
26ba25
-#                    not specified, this is the active layer.
26ba25
+# @base: Same as @base-node, except that it is a file name rather than a node
26ba25
+#        name. This must be the exact filename string that was used to open the
26ba25
+#        node; other strings, even if addressing the same file, are not
26ba25
+#        accepted (deprecated, use @base-node instead)
26ba25
+#
26ba25
+# @top-node: The node name of the backing image within the image chain
26ba25
+#            which contains the topmost data to be committed down. If
26ba25
+#            not specified, this is the active layer. (since: 3.1)
26ba25
+#
26ba25
+# @top: Same as @top-node, except that it is a file name rather than a node
26ba25
+#       name. This must be the exact filename string that was used to open the
26ba25
+#       node; other strings, even if addressing the same file, are not
26ba25
+#       accepted (deprecated, use @base-node instead)
26ba25
 #
26ba25
 # @backing-file:  The backing file string to write into the overlay
26ba25
 #                           image of 'top'.  If 'top' is the active layer,
26ba25
@@ -1508,7 +1519,8 @@
26ba25
 #
26ba25
 ##
26ba25
 { 'command': 'block-commit',
26ba25
-  'data': { '*job-id': 'str', 'device': 'str', '*base': 'str', '*top': 'str',
26ba25
+  'data': { '*job-id': 'str', 'device': 'str', '*base-node': 'str',
26ba25
+            '*base': 'str', '*top-node': 'str', '*top': 'str',
26ba25
             '*backing-file': 'str', '*speed': 'int',
26ba25
             '*filter-node-name': 'str',
26ba25
             '*auto-finalize': 'bool', '*auto-dismiss': 'bool' } }
26ba25
-- 
26ba25
1.8.3.1
26ba25