]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuBlockExportAddNBD: Use 'block-export-add' when available
authorPeter Krempa <pkrempa@redhat.com>
Wed, 14 Oct 2020 09:49:50 +0000 (11:49 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 19 Oct 2020 11:36:58 +0000 (13:36 +0200)
Switch to the new QMP command once it becomes available. Since the code
was refactored to have just one central location to do this we can
contain the ugly bits to just this one function.

Since we now use the replacement for 'nbd-server-add' mark the test case
as being OK with removal of the command.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_block.c
tests/qemumonitorjsontest.c

index 85a0320520eb3f8a5e8754819431650707593075..f1cd12a95041217072f157362789870a671d2610 100644 (file)
@@ -3414,15 +3414,27 @@ qemuBlockExportAddNBD(virDomainObjPtr vm,
                       const char *bitmap)
 {
     qemuDomainObjPrivatePtr priv = vm->privateData;
-    const char *exportsrc = drivealias;
 
     if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV)) {
-        exportsrc = src->nodeformat;
+        if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCK_EXPORT_ADD)) {
+            g_autoptr(virJSONValue) nbdprops = NULL;
+
+            if (!(nbdprops = qemuBlockExportGetNBDProps(src->nodeformat,
+                                                        exportname,
+                                                        writable,
+                                                        bitmap)))
+                return -1;
+
+            return qemuMonitorBlockExportAdd(priv->mon, &nbdprops);
+        } else {
+            return qemuMonitorNBDServerAdd(priv->mon, src->nodeformat,
+                                           exportname, writable, bitmap);
+        }
     } else {
         /* older qemu versions didn't support configuring the exportname and
          * took the 'drivealias' as the export name */
-        exportname = NULL;
+        return qemuMonitorNBDServerAdd(priv->mon, drivealias, NULL, writable, NULL);
     }
 
-    return qemuMonitorNBDServerAdd(priv->mon, exportsrc, exportname, writable, bitmap);
+    return 0;
 }
index d65af6fadceb9fa21078bd94f8f80987f650c9ef..0611fdfd345815d26ffe60a5ecc1c95f586a4be6 100644 (file)
@@ -3299,7 +3299,7 @@ mymain(void)
     DO_TEST_GEN(qemuMonitorJSONDrivePivot);
     DO_TEST_GEN(qemuMonitorJSONScreendump);
     DO_TEST_GEN(qemuMonitorJSONOpenGraphics);
-    DO_TEST_GEN_DEPRECATED(qemuMonitorJSONNBDServerAdd, false);
+    DO_TEST_GEN_DEPRECATED(qemuMonitorJSONNBDServerAdd, true);
     DO_TEST_GEN(qemuMonitorJSONDetachCharDev);
     DO_TEST_GEN(qemuMonitorJSONBlockdevTrayOpen);
     DO_TEST_GEN(qemuMonitorJSONBlockdevTrayClose);