Blame SOURCES/kvm-commit-Add-top-node-base-node-options.patch

1bdc94
From 1ac2f161e5585d1ed71b79e8279c9d78b2efe35e Mon Sep 17 00:00:00 2001
1bdc94
From: Kevin Wolf <kwolf@redhat.com>
1bdc94
Date: Mon, 17 Sep 2018 07:48:43 +0200
1bdc94
Subject: [PATCH 01/49] commit: Add top-node/base-node options
1bdc94
1bdc94
RH-Author: Kevin Wolf <kwolf@redhat.com>
1bdc94
Message-id: <20180911130704.6641-2-kwolf@redhat.com>
1bdc94
Patchwork-id: 82114
1bdc94
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH 1/2] commit: Add top-node/base-node options
1bdc94
Bugzilla: 1624012
1bdc94
RH-Acked-by: Max Reitz <mreitz@redhat.com>
1bdc94
RH-Acked-by: John Snow <jsnow@redhat.com>
1bdc94
RH-Acked-by: Fam Zheng <famz@redhat.com>
1bdc94
1bdc94
The block-commit QMP command required specifying the top and base nodes
1bdc94
of the commit jobs using the file name of that node. While this works
1bdc94
in simple cases (local files with absolute paths), the file names
1bdc94
generated for more complicated setups can be hard to predict.
1bdc94
1bdc94
The block-commit command has more problems than just this, so we want to
1bdc94
replace it altogether in the long run, but libvirt needs a reliable way
1bdc94
to address nodes now. So we don't want to wait for a new, cleaner
1bdc94
command, but just add the minimal thing needed right now.
1bdc94
1bdc94
This adds two new options top-node and base-node to the command, which
1bdc94
allow specifying node names instead. They are mutually exclusive with
1bdc94
the old options.
1bdc94
1bdc94
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
1bdc94
---
1bdc94
 blockdev.c           | 32 ++++++++++++++++++++++++++++++--
1bdc94
 qapi/block-core.json | 24 ++++++++++++++++++------
1bdc94
 2 files changed, 48 insertions(+), 8 deletions(-)
1bdc94
1bdc94
diff --git a/blockdev.c b/blockdev.c
1bdc94
index 0eb6bba..fb355c8 100644
1bdc94
--- a/blockdev.c
1bdc94
+++ b/blockdev.c
1bdc94
@@ -3371,7 +3371,9 @@ out:
1bdc94
 }
1bdc94
 
1bdc94
 void qmp_block_commit(bool has_job_id, const char *job_id, const char *device,
1bdc94
+                      bool has_base_node, const char *base_node,
1bdc94
                       bool has_base, const char *base,
1bdc94
+                      bool has_top_node, const char *top_node,
1bdc94
                       bool has_top, const char *top,
1bdc94
                       bool has_backing_file, const char *backing_file,
1bdc94
                       bool has_speed, int64_t speed,
1bdc94
@@ -3432,7 +3434,20 @@ void qmp_block_commit(bool has_job_id, const char *job_id, const char *device,
1bdc94
     /* default top_bs is the active layer */
1bdc94
     top_bs = bs;
1bdc94
 
1bdc94
-    if (has_top && top) {
1bdc94
+    if (has_top_node && has_top) {
1bdc94
+        error_setg(errp, "'top-node' and 'top' are mutually exclusive");
1bdc94
+        goto out;
1bdc94
+    } else if (has_top_node) {
1bdc94
+        top_bs = bdrv_lookup_bs(NULL, top_node, errp);
1bdc94
+        if (top_bs == NULL) {
1bdc94
+            goto out;
1bdc94
+        }
1bdc94
+        if (!bdrv_chain_contains(bs, top_bs)) {
1bdc94
+            error_setg(errp, "'%s' is not in this backing file chain",
1bdc94
+                       top_node);
1bdc94
+            goto out;
1bdc94
+        }
1bdc94
+    } else if (has_top && top) {
1bdc94
         if (strcmp(bs->filename, top) != 0) {
1bdc94
             top_bs = bdrv_find_backing_image(bs, top);
1bdc94
         }
1bdc94
@@ -3445,7 +3460,20 @@ void qmp_block_commit(bool has_job_id, const char *job_id, const char *device,
1bdc94
 
1bdc94
     assert(bdrv_get_aio_context(top_bs) == aio_context);
1bdc94
 
1bdc94
-    if (has_base && base) {
1bdc94
+    if (has_base_node && has_base) {
1bdc94
+        error_setg(errp, "'base-node' and 'base' are mutually exclusive");
1bdc94
+        goto out;
1bdc94
+    } else if (has_base_node) {
1bdc94
+        base_bs = bdrv_lookup_bs(NULL, base_node, errp);
1bdc94
+        if (base_bs == NULL) {
1bdc94
+            goto out;
1bdc94
+        }
1bdc94
+        if (!bdrv_chain_contains(top_bs, base_bs)) {
1bdc94
+            error_setg(errp, "'%s' is not in this backing file chain",
1bdc94
+                       base_node);
1bdc94
+            goto out;
1bdc94
+        }
1bdc94
+    } else if (has_base && base) {
1bdc94
         base_bs = bdrv_find_backing_image(top_bs, base);
1bdc94
     } else {
1bdc94
         base_bs = bdrv_find_base(top_bs);
1bdc94
diff --git a/qapi/block-core.json b/qapi/block-core.json
1bdc94
index 56937db..8da07cd 100644
1bdc94
--- a/qapi/block-core.json
1bdc94
+++ b/qapi/block-core.json
1bdc94
@@ -1440,12 +1440,23 @@
1bdc94
 #
1bdc94
 # @device:  the device name or node-name of a root node
1bdc94
 #
1bdc94
-# @base:   The file name of the backing image to write data into.
1bdc94
-#                    If not specified, this is the deepest backing image.
1bdc94
+# @base-node: The node name of the backing image to write data into.
1bdc94
+#             If not specified, this is the deepest backing image.
1bdc94
+#             (since: 3.1)
1bdc94
 #
1bdc94
-# @top:    The file name of the backing image within the image chain,
1bdc94
-#                    which contains the topmost data to be committed down. If
1bdc94
-#                    not specified, this is the active layer.
1bdc94
+# @base: Same as @base-node, except that it is a file name rather than a node
1bdc94
+#        name. This must be the exact filename string that was used to open the
1bdc94
+#        node; other strings, even if addressing the same file, are not
1bdc94
+#        accepted (deprecated, use @base-node instead)
1bdc94
+#
1bdc94
+# @top-node: The node name of the backing image within the image chain
1bdc94
+#            which contains the topmost data to be committed down. If
1bdc94
+#            not specified, this is the active layer. (since: 3.1)
1bdc94
+#
1bdc94
+# @top: Same as @top-node, except that it is a file name rather than a node
1bdc94
+#       name. This must be the exact filename string that was used to open the
1bdc94
+#       node; other strings, even if addressing the same file, are not
1bdc94
+#       accepted (deprecated, use @base-node instead)
1bdc94
 #
1bdc94
 # @backing-file:  The backing file string to write into the overlay
1bdc94
 #                           image of 'top'.  If 'top' is the active layer,
1bdc94
@@ -1514,7 +1525,8 @@
1bdc94
 #
1bdc94
 ##
1bdc94
 { 'command': 'block-commit',
1bdc94
-  'data': { '*job-id': 'str', 'device': 'str', '*base': 'str', '*top': 'str',
1bdc94
+  'data': { '*job-id': 'str', 'device': 'str', '*base-node': 'str',
1bdc94
+            '*base': 'str', '*top-node': 'str', '*top': 'str',
1bdc94
             '*backing-file': 'str', '*speed': 'int',
1bdc94
             '*filter-node-name': 'str',
1bdc94
             '*auto-finalize': 'bool', '*auto-dismiss': 'bool' } }
1bdc94
-- 
1bdc94
1.8.3.1
1bdc94