]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: monitor: Add monitor backend for 'blockdev-set-active'
authorPeter Krempa <pkrempa@redhat.com>
Mon, 10 Feb 2025 16:51:31 +0000 (17:51 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 12 Feb 2025 15:22:56 +0000 (16:22 +0100)
The command will be used to re-activate block nodes after migration when
we're leaving the VM paused so that blockjobs can be used.

As the 'node-name' field is optional the 'qemumonitorjsontest' case
tests both variants.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
src/qemu/qemu_monitor.c
src/qemu/qemu_monitor.h
src/qemu/qemu_monitor_json.c
src/qemu/qemu_monitor_json.h
tests/qemumonitorjsontest.c

index 830ecbad1cdf373df65c10841738ba138b52e381..c069d172654f6b5ffb9e37ce2d45540953419209 100644 (file)
@@ -4552,3 +4552,24 @@ qemuMonitorDisplayReload(qemuMonitor *mon,
 
     return qemuMonitorJSONDisplayReload(mon, type, tlsCerts);
 }
+
+
+/**
+ * qemuMonitorBlockdevSetActive:
+ * @mon: monitor object
+ * @nodename: optional nodename to (de)activate
+ * @active: requested state
+ *
+ * Activate or deactivate @nodename based on @active. If @nodename is NULL,
+ * qemu will act on all block nodes.
+ */
+int
+qemuMonitorBlockdevSetActive(qemuMonitor *mon,
+                             const char *nodename,
+                             bool active)
+{
+    QEMU_CHECK_MONITOR(mon);
+    VIR_DEBUG("nodename='%s', active='%d'", NULLSTR(nodename), active);
+
+    return qemuMonitorJSONBlockdevSetActive(mon, nodename, active);
+}
index 072f452e795dbc5d81ebc858c76c202f0b297b93..f7b9263b645edff2a57d359a832d17ea5ecd3fa0 100644 (file)
@@ -1651,3 +1651,8 @@ qemuMonitorSnapshotDelete(qemuMonitor *mon,
                           const char *jobname,
                           const char *snapshotname,
                           const char **disks);
+
+int
+qemuMonitorBlockdevSetActive(qemuMonitor *mon,
+                             const char *nodename,
+                             bool active);
index 890d9b7dfdea45c5fdc1bd559b92bead22d62b22..554572b13dd13c12838808accb52a1cd87e0adbf 100644 (file)
@@ -8883,3 +8883,24 @@ qemuMonitorJSONSnapshotDelete(qemuMonitor *mon,
 
     return qemuMonitorJSONCheckError(cmd, reply);
 }
+
+
+int
+qemuMonitorJSONBlockdevSetActive(qemuMonitor *mon,
+                                 const char *nodename,
+                                 bool active)
+{
+    g_autoptr(virJSONValue) cmd = NULL;
+    g_autoptr(virJSONValue) reply = NULL;
+
+    if (!(cmd = qemuMonitorJSONMakeCommand("blockdev-set-active",
+                                           "S:node-name", nodename,
+                                           "b:active", active,
+                                           NULL)))
+        return -1;
+
+    if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+        return -1;
+
+    return qemuMonitorJSONCheckError(cmd, reply);
+}
index 2f5a021f5614c7ee385fd052174adf8bfe643fbf..25e3ae2cbb766acf584a955ebfc2ae501cef2268 100644 (file)
@@ -817,3 +817,8 @@ qemuMonitorJSONSnapshotDelete(qemuMonitor *mon,
                               const char *jobname,
                               const char *snapshotname,
                               const char **disks);
+
+int
+qemuMonitorJSONBlockdevSetActive(qemuMonitor *mon,
+                                 const char *nodename,
+                                 bool active);
index f7fe0fb6f40d47afb6f5975de076f474d8de7702..f0f6a329c88232115ed5fef48e5a336ab47c3718 100644 (file)
@@ -1249,6 +1249,36 @@ testQemuMonitorJSONqemuMonitorJSONSnapshot(const void *opaque)
 }
 
 
+static int
+testQemuMonitorJSONqemuMonitorJSONBlockdevSetActive(const void *opaque)
+{
+    const testGenericData *data = opaque;
+    virDomainXMLOption *xmlopt = data->xmlopt;
+    g_autoptr(qemuMonitorTest) test = NULL;
+
+    if (!(test = qemuMonitorTestNewSchema(xmlopt, data->schema)))
+        return -1;
+
+    if (qemuMonitorTestAddItem(test, "blockdev-set-active",
+                               "{\"return\":{}}") < 0)
+        return -1;
+
+    if (qemuMonitorTestAddItem(test, "blockdev-set-active",
+                               "{\"return\":{}}") < 0)
+        return -1;
+
+    if (qemuMonitorJSONBlockdevSetActive(qemuMonitorTestGetMonitor(test),
+                                         NULL, true) < 0)
+        return -1;
+
+    if (qemuMonitorJSONBlockdevSetActive(qemuMonitorTestGetMonitor(test),
+                                         "testnode", false) < 0)
+        return -1;
+
+    return 0;
+}
+
+
 static bool
 testQemuMonitorJSONqemuMonitorJSONQueryCPUsEqual(struct qemuMonitorQueryCpusEntry *a,
                                                  struct qemuMonitorQueryCpusEntry *b)
@@ -2989,6 +3019,7 @@ mymain(void)
     DO_TEST(qemuMonitorJSONSendKeyHoldtime);
     DO_TEST(qemuMonitorJSONNBDServerStart);
     DO_TEST(qemuMonitorJSONSnapshot);
+    DO_TEST(qemuMonitorJSONBlockdevSetActive);
 
     DO_TEST_CPU_DATA("host");
     DO_TEST_CPU_DATA("full");