fbe740
From 0ca4a633af46f2e06d3ef831919ca75387f42103 Mon Sep 17 00:00:00 2001
fbe740
Message-Id: <0ca4a633af46f2e06d3ef831919ca75387f42103@dist-git>
fbe740
From: Peter Krempa <pkrempa@redhat.com>
fbe740
Date: Mon, 16 Mar 2020 22:12:34 +0100
fbe740
Subject: [PATCH] rhel: Enable usage of x-blockdev-reopen
fbe740
MIME-Version: 1.0
fbe740
Content-Type: text/plain; charset=UTF-8
fbe740
Content-Transfer-Encoding: 8bit
fbe740
fbe740
RHEL-only
fbe740
fbe740
Introduce a new capability QEMU_CAPS_BLOCKDEV_REOPEN_COM_REDHAT_AV_8_2_0_API
fbe740
based on the presence of '__com.redhat_rhel-av-8_2_0-api' feature for
fbe740
'x-blockdev-reopen' which states that reopen works for what libvirt
fbe740
is going to use it and wire up code to call the x- prefixed command.
fbe740
fbe740
This implementation will become dormant once qemu starts supporting
fbe740
upstream-stable blockdev-reopen.
fbe740
fbe740
https://bugzilla.redhat.com/show_bug.cgi?id=1799013
fbe740
Message-Id: <098dc0e73e1b561af991f2a9ecf13436dde3b33d.1584391727.git.pkrempa@redhat.com>
fbe740
Reviewed-by: Ján Tomko <jtomko@redhat.com>
fbe740
---
fbe740
 src/qemu/qemu_block.c        |  3 ++-
fbe740
 src/qemu/qemu_capabilities.c | 13 +++++++++++++
fbe740
 src/qemu/qemu_capabilities.h |  3 +++
fbe740
 src/qemu/qemu_monitor.c      |  5 +++--
fbe740
 src/qemu/qemu_monitor.h      |  3 ++-
fbe740
 src/qemu/qemu_monitor_json.c | 12 +++++++++---
fbe740
 src/qemu/qemu_monitor_json.h |  3 ++-
fbe740
 7 files changed, 34 insertions(+), 8 deletions(-)
fbe740
fbe740
diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
fbe740
index 21c1ad9618..099ceeb802 100644
fbe740
--- a/src/qemu/qemu_block.c
fbe740
+++ b/src/qemu/qemu_block.c
fbe740
@@ -3225,6 +3225,7 @@ qemuBlockReopenFormat(virDomainObjPtr vm,
fbe740
     qemuDomainObjPrivatePtr priv = vm->privateData;
fbe740
     virQEMUDriverPtr driver = priv->driver;
fbe740
     g_autoptr(virJSONValue) reopenprops = NULL;
fbe740
+    bool downstream = virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV_REOPEN_COM_REDHAT_AV_8_2_0_API);
fbe740
     int rc;
fbe740
 
fbe740
     /* If we are lacking the object here, qemu might have opened an image with
fbe740
@@ -3241,7 +3242,7 @@ qemuBlockReopenFormat(virDomainObjPtr vm,
fbe740
     if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
fbe740
         return -1;
fbe740
 
fbe740
-    rc = qemuMonitorBlockdevReopen(priv->mon, &reopenprops);
fbe740
+    rc = qemuMonitorBlockdevReopen(priv->mon, &reopenprops, downstream);
fbe740
 
fbe740
     if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0)
fbe740
         return -1;
fbe740
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
fbe740
index a4046b09d6..0b4ed4253c 100644
fbe740
--- a/src/qemu/qemu_capabilities.c
fbe740
+++ b/src/qemu/qemu_capabilities.c
fbe740
@@ -561,6 +561,9 @@ VIR_ENUM_IMPL(virQEMUCaps,
fbe740
               "vhost-user-fs",
fbe740
               "blockdev-snapshot.allow-write-only-overlay",
fbe740
               "blockdev-reopen",
fbe740
+
fbe740
+              /* 355 */
fbe740
+              "blockdev-reopen.__com.redhat_rhel-av-8_2_0-api"
fbe740
     );
fbe740
 
fbe740
 
fbe740
@@ -1419,6 +1422,7 @@ static struct virQEMUCapsStringFlags virQEMUCapsDevicePropsNVDIMM[] = {
fbe740
 
fbe740
 /* see documentation for virQEMUQAPISchemaPathGet for the query format */
fbe740
 static struct virQEMUCapsStringFlags virQEMUCapsQMPSchemaQueries[] = {
fbe740
+    { "x-blockdev-reopen/$__com.redhat_rhel-av-8_2_0-api", QEMU_CAPS_BLOCKDEV_REOPEN_COM_REDHAT_AV_8_2_0_API },
fbe740
     { "blockdev-add/arg-type/options/+gluster/debug-level", QEMU_CAPS_GLUSTER_DEBUG_LEVEL},
fbe740
     { "blockdev-add/arg-type/+gluster/debug", QEMU_CAPS_GLUSTER_DEBUG_LEVEL},
fbe740
     { "blockdev-add/arg-type/+vxhs", QEMU_CAPS_VXHS},
fbe740
@@ -4861,6 +4865,15 @@ virQEMUCapsInitProcessCaps(virQEMUCapsPtr qemuCaps)
fbe740
         virQEMUCapsGet(qemuCaps, QEMU_CAPS_SAVEVM_MONITOR_NODES))
fbe740
         virQEMUCapsSet(qemuCaps, QEMU_CAPS_BLOCKDEV);
fbe740
 
fbe740
+    /* RHEL-only:
fbe740
+     * - if upstream blockdev-reopen is enabled, clear the downstream flag
fbe740
+     * - if the downstream flag is present but not the upstream, assert the upstream flag too
fbe740
+     */
fbe740
+    if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV_REOPEN))
fbe740
+        virQEMUCapsClear(qemuCaps, QEMU_CAPS_BLOCKDEV_REOPEN_COM_REDHAT_AV_8_2_0_API);
fbe740
+    if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV_REOPEN_COM_REDHAT_AV_8_2_0_API))
fbe740
+        virQEMUCapsSet(qemuCaps, QEMU_CAPS_BLOCKDEV_REOPEN);
fbe740
+
fbe740
     virQEMUCapsInitProcessCapsInterlock(qemuCaps);
fbe740
 }
fbe740
 
fbe740
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
fbe740
index 8fdbe05638..0f7c586703 100644
fbe740
--- a/src/qemu/qemu_capabilities.h
fbe740
+++ b/src/qemu/qemu_capabilities.h
fbe740
@@ -543,6 +543,9 @@ typedef enum { /* virQEMUCapsFlags grouping marker for syntax-check */
fbe740
     QEMU_CAPS_BLOCKDEV_SNAPSHOT_ALLOW_WRITE_ONLY, /* blockdev-snapshot has the 'allow-write-only-overlay' feature */
fbe740
     QEMU_CAPS_BLOCKDEV_REOPEN, /* 'blockdev-reopen' qmp command is supported */
fbe740
 
fbe740
+    /* 355 */
fbe740
+    QEMU_CAPS_BLOCKDEV_REOPEN_COM_REDHAT_AV_8_2_0_API, /* downstream support for blockdev reopen in rhel-av-8.2.0 */
fbe740
+
fbe740
     QEMU_CAPS_LAST /* this must always be the last item */
fbe740
 } virQEMUCapsFlags;
fbe740
 
fbe740
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
fbe740
index c4202d59af..5915035589 100644
fbe740
--- a/src/qemu/qemu_monitor.c
fbe740
+++ b/src/qemu/qemu_monitor.c
fbe740
@@ -4409,14 +4409,15 @@ qemuMonitorBlockdevAdd(qemuMonitorPtr mon,
fbe740
 
fbe740
 int
fbe740
 qemuMonitorBlockdevReopen(qemuMonitorPtr mon,
fbe740
-                          virJSONValuePtr *props)
fbe740
+                          virJSONValuePtr *props,
fbe740
+                          bool downstream)
fbe740
 {
fbe740
     VIR_DEBUG("props=%p (node-name=%s)", *props,
fbe740
               NULLSTR(virJSONValueObjectGetString(*props, "node-name")));
fbe740
 
fbe740
     QEMU_CHECK_MONITOR(mon);
fbe740
 
fbe740
-    return qemuMonitorJSONBlockdevReopen(mon, props);
fbe740
+    return qemuMonitorJSONBlockdevReopen(mon, props, downstream);
fbe740
 }
fbe740
 
fbe740
 
fbe740
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
fbe740
index 481fc8e12e..ca975d084c 100644
fbe740
--- a/src/qemu/qemu_monitor.h
fbe740
+++ b/src/qemu/qemu_monitor.h
fbe740
@@ -1326,7 +1326,8 @@ int qemuMonitorBlockdevAdd(qemuMonitorPtr mon,
fbe740
                            virJSONValuePtr *props);
fbe740
 
fbe740
 int qemuMonitorBlockdevReopen(qemuMonitorPtr mon,
fbe740
-                              virJSONValuePtr *props);
fbe740
+                              virJSONValuePtr *props,
fbe740
+                              bool downstream);
fbe740
 
fbe740
 int qemuMonitorBlockdevDel(qemuMonitorPtr mon,
fbe740
                            const char *nodename);
fbe740
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
fbe740
index 0122b77259..92d7317a82 100644
fbe740
--- a/src/qemu/qemu_monitor_json.c
fbe740
+++ b/src/qemu/qemu_monitor_json.c
fbe740
@@ -8832,14 +8832,20 @@ qemuMonitorJSONBlockdevAdd(qemuMonitorPtr mon,
fbe740
 
fbe740
 int
fbe740
 qemuMonitorJSONBlockdevReopen(qemuMonitorPtr mon,
fbe740
-                              virJSONValuePtr *props)
fbe740
+                              virJSONValuePtr *props,
fbe740
+                              bool downstream)
fbe740
 {
fbe740
     g_autoptr(virJSONValue) cmd = NULL;
fbe740
     g_autoptr(virJSONValue) reply = NULL;
fbe740
     virJSONValuePtr pr = g_steal_pointer(props);
fbe740
 
fbe740
-    if (!(cmd = qemuMonitorJSONMakeCommandInternal("blockdev-reopen", pr)))
fbe740
-        return -1;
fbe740
+    if (downstream) {
fbe740
+        if (!(cmd = qemuMonitorJSONMakeCommandInternal("x-blockdev-reopen", pr)))
fbe740
+            return -1;
fbe740
+    } else {
fbe740
+        if (!(cmd = qemuMonitorJSONMakeCommandInternal("blockdev-reopen", pr)))
fbe740
+            return -1;
fbe740
+    }
fbe740
 
fbe740
     if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
fbe740
         return -1;
fbe740
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
fbe740
index 801babef97..38c61a5661 100644
fbe740
--- a/src/qemu/qemu_monitor_json.h
fbe740
+++ b/src/qemu/qemu_monitor_json.h
fbe740
@@ -601,7 +601,8 @@ int qemuMonitorJSONBlockdevAdd(qemuMonitorPtr mon,
fbe740
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
fbe740
 
fbe740
 int qemuMonitorJSONBlockdevReopen(qemuMonitorPtr mon,
fbe740
-                                  virJSONValuePtr *props)
fbe740
+                                  virJSONValuePtr *props,
fbe740
+                                  bool downstream)
fbe740
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
fbe740
 
fbe740
 int qemuMonitorJSONBlockdevDel(qemuMonitorPtr mon,
fbe740
-- 
fbe740
2.25.1
fbe740