[PATCH 7/9] qemu: monitor: Add functions for object hot-add/remove

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



To allow live modification of device backends in qemu libvirt needs to
be able to hot-add/remove "objects". Add monitor backend functions to
allow this.
---
 src/qemu/qemu_monitor.c      | 48 +++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_monitor.h      |  8 +++++++
 src/qemu/qemu_monitor_json.c | 56 ++++++++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_monitor_json.h |  8 +++++++
 4 files changed, 120 insertions(+)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 5dff9ff..dfcd4ed 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -3132,6 +3132,54 @@ int qemuMonitorAddDevice(qemuMonitorPtr mon,
     return qemuMonitorAddDeviceWithFd(mon, devicestr, -1, NULL);
 }

+
+/**
+ * qemuMonitorAddObject:
+ * @mon: Pointer to monitor object
+ * @type: Type of object to add
+ * @objalias: Alias of the new object
+ * @props: Optional arguments for the given type. The object is consumed and
+ *         should not be referenced by the caller after this function returs.
+ *
+ * Returns 0 on success -1 on error.
+ */
+int
+qemuMonitorAddObject(qemuMonitorPtr mon,
+                     const char *type,
+                     const char *objalias,
+                     virJSONValuePtr props)
+{
+    VIR_DEBUG("mon=%p type=%s objalias=%s props=%p",
+              mon, type, objalias, props);
+    int ret = -1;
+
+    if (mon->json)
+        ret = qemuMonitorJSONAddObject(mon, type, objalias, props);
+    else
+        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
+                       _("object adding requires JSON monitor"));
+
+    return ret;
+}
+
+
+int
+qemuMonitorDelObject(qemuMonitorPtr mon,
+                     const char *objalias)
+{
+    VIR_DEBUG("mon=%p objalias=%s", mon, objalias);
+    int ret = -1;
+
+    if (mon->json)
+        ret = qemuMonitorJSONDelObject(mon, objalias);
+    else
+        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
+                       _("object deletion requires JSON monitor"));
+
+    return ret;
+}
+
+
 int qemuMonitorAddDrive(qemuMonitorPtr mon,
                         const char *drivestr)
 {
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index fd145a7..750b3dc 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -672,6 +672,14 @@ int qemuMonitorAddDeviceWithFd(qemuMonitorPtr mon,
 int qemuMonitorDelDevice(qemuMonitorPtr mon,
                          const char *devalias);

+int qemuMonitorAddObject(qemuMonitorPtr mon,
+                         const char *type,
+                         const char *objalias,
+                         virJSONValuePtr props);
+
+int qemuMonitorDelObject(qemuMonitorPtr mon,
+                         const char *objalias);
+
 int qemuMonitorAddDrive(qemuMonitorPtr mon,
                         const char *drivestr);

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 2967193..ff1fa45 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -3561,6 +3561,62 @@ int qemuMonitorJSONAddDevice(qemuMonitorPtr mon,
 }


+int qemuMonitorJSONAddObject(qemuMonitorPtr mon,
+                             const char *type,
+                             const char *objalias,
+                             virJSONValuePtr props)
+{
+    int ret = -1;
+    virJSONValuePtr cmd;
+    virJSONValuePtr reply = NULL;
+
+    cmd = qemuMonitorJSONMakeCommand("object-add",
+                                     "s:qom-type", type,
+                                     "s:id", objalias,
+                                     "A:props", props,
+                                     NULL);
+    if (!cmd)
+        goto cleanup;
+
+    props = NULL;
+
+    ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+
+    if (ret == 0)
+        ret = qemuMonitorJSONCheckError(cmd, reply);
+
+ cleanup:
+    virJSONValueFree(cmd);
+    virJSONValueFree(reply);
+    virJSONValueFree(props);
+    return ret;
+}
+
+
+int qemuMonitorJSONDelObject(qemuMonitorPtr mon,
+                             const char *objalias)
+{
+    int ret;
+    virJSONValuePtr cmd;
+    virJSONValuePtr reply = NULL;
+
+    cmd = qemuMonitorJSONMakeCommand("object-del",
+                                     "s:id", objalias,
+                                     NULL);
+    if (!cmd)
+        return -1;
+
+    ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+
+    if (ret == 0)
+        ret = qemuMonitorJSONCheckError(cmd, reply);
+
+    virJSONValueFree(cmd);
+    virJSONValueFree(reply);
+    return ret;
+}
+
+
 int qemuMonitorJSONAddDrive(qemuMonitorPtr mon,
                             const char *drivestr)
 {
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index c898382..6cdaf18 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -229,6 +229,14 @@ int qemuMonitorJSONAddDevice(qemuMonitorPtr mon,
 int qemuMonitorJSONDelDevice(qemuMonitorPtr mon,
                              const char *devalias);

+int qemuMonitorJSONAddObject(qemuMonitorPtr mon,
+                             const char *type,
+                             const char *objalias,
+                             virJSONValuePtr props);
+
+int qemuMonitorJSONDelObject(qemuMonitorPtr mon,
+                             const char *objalias);
+
 int qemuMonitorJSONAddDrive(qemuMonitorPtr mon,
                             const char *drivestr);

-- 
2.1.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]