Skip to contentSkip to conversation

multi-process: Extend monitor commands to remove device from remote process

RFC PATCH Superseded [email protected] 1 participant 1 message Jun 17, 2019

v2 of 15 Superseded Latest is v15 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH v2 22/35 multi-process: Extend monitor commands to remove device from remote process

From: Jagannathan Raman <[email protected]>

Extend device_del QMP & HMP commands to hot-unplug device from remote process.

---
 hmp.c                   |  9 +++++++++
 hw/proxy/monitor.c      | 15 ++++++++++++++
 include/hw/qdev-core.h  |  1 +
 include/io/proxy-link.h |  2 ++
 include/monitor/qdev.h  |  1 +
 qdev-monitor.c          | 15 ++++++++++++--
 remote/remote-main.c    | 45 +++++++++++++++++++++++++++++++++++++++++
 stubs/monitor.c         |  4 ++++
 8 files changed, 90 insertions(+), 2 deletions(-)
hmp.c +9 -0
index ccc95d3feb..89cdaebfde 100644
@@ -54,6 +54,7 @@
 #include "hw/rdma/rdma.h"
 #include "migration/snapshot.h"
 #include "migration/misc.h"
+#include "hw/boards.h"
 
 #ifdef CONFIG_SPICE
 #include <spice/enums.h>
@@ -2178,9 +2179,17 @@ void hmp_device_add(Monitor *mon, const QDict *qdict)
 
 void hmp_device_del(Monitor *mon, const QDict *qdict)
 {
+    MachineState *ms = MACHINE(current_machine);
     const char *id = qdict_get_str(qdict, "id");
     Error *err = NULL;
 
+#ifdef CONFIG_MPQEMU
+    if (g_hash_table_lookup(ms->remote_devs, id)) {
+        qmp_rdevice_del(id, &err);
+        return;
+    }
+#endif
+
     qmp_device_del(id, &err);
     hmp_handle_error(mon, &err);
 }
hw/proxy/monitor.c +15 -0
index 400c83c0d5..c4d0ff1213 100644
@@ -172,6 +172,8 @@ static void rdevice_add_del(QDict *qdict, proc_cmd_t cmd, Error **errp)
     if (cmd == DEVICE_ADD) {
         (void)g_hash_table_insert(ms->remote_devs, (gpointer)g_strdup(id),
                                   (gpointer)pdev);
+    } else {
+        (void)g_hash_table_remove(ms->remote_devs, (gpointer)id);
     }
 }
 
@@ -179,3 +181,16 @@ void qmp_rdevice_add(QDict *qdict, QObject **ret_data, Error **errp)
 {
     rdevice_add_del(qdict, DEVICE_ADD, errp);
 }
+
+void qmp_rdevice_del(const char *id, Error **errp)
+{
+    QDict *qdict = qdict_new();
+
+    qdict_put_str(qdict, "id", id);
+
+    qdict_put_str(qdict, "rid", id);
+
+    rdevice_add_del(qdict, DEVICE_DEL, errp);
+
+    qobject_unref(qdict);
+}
include/hw/qdev-core.h +1 -0
index 33ed3b8dde..cea42a92ab 100644
@@ -358,6 +358,7 @@ BusState *qdev_get_parent_bus(DeviceState *dev);
 /*** BUS API. ***/
 
 DeviceState *qdev_find_recursive(BusState *bus, const char *id);
+DeviceState *find_device_state(const char *id, Error **errp);
 
 /* Returns 0 to walk children, > 0 to skip walk, < 0 to terminate walk. */
 typedef int (qbus_walkerfn)(BusState *bus, void *opaque);
include/io/proxy-link.h +2 -0
index 07a08a9175..bf2555c97e 100644
@@ -61,6 +61,7 @@ typedef struct ProxyLinkState ProxyLinkState;
  * SET_IRQFD        Sets the IRQFD to be used to raise interrupts directly
  *                  from remote device
  * DEVICE_ADD       QMP/HMP command to hotplug device
+ * DEVICE_DEL       QMP/HMP command to hot-unplug device
  *
  */
 typedef enum {
@@ -72,6 +73,7 @@ typedef enum {
     BAR_READ,
     SET_IRQFD,
     DEVICE_ADD,
+    DEVICE_DEL,
     MAX,
 } proc_cmd_t;
 
include/monitor/qdev.h +1 -0
index e21692677e..c7642f7c2d 100644
@@ -11,6 +11,7 @@ void hmp_info_qom_tree(Monitor *mon, const QDict *dict);
 void qmp_device_add(QDict *qdict, QObject **ret_data, Error **errp);
 
 void qmp_rdevice_add(QDict *qdict, QObject **ret_data, Error **errp);
+void qmp_rdevice_del(const char *id, Error **errp);
 
 int qdev_device_help(QemuOpts *opts);
 DeviceState *qdev_device_add(QemuOpts *opts, Error **errp);
qdev-monitor.c +13 -2
index 80d570263f..744c807b0f 100644
@@ -34,6 +34,7 @@
 #include "qemu/qemu-print.h"
 #include "sysemu/block-backend.h"
 #include "migration/misc.h"
+#include "hw/boards.h"
 
 /*
  * Aliases were a bad idea from the start.  Let's keep them
@@ -827,7 +828,7 @@ void qmp_device_add(QDict *qdict, QObject **ret_data, Error **errp)
     object_unref(OBJECT(dev));
 }
 
-static DeviceState *find_device_state(const char *id, Error **errp)
+DeviceState *find_device_state(const char *id, Error **errp)
 {
     Object *obj;
 
@@ -902,7 +903,17 @@ void qdev_unplug(DeviceState *dev, Error **errp)
 
 void qmp_device_del(const char *id, Error **errp)
 {
-    DeviceState *dev = find_device_state(id, errp);
+    MachineState *ms = MACHINE(current_machine);
+    DeviceState *dev;
+
+#ifdef CONFIG_MPQEMU
+    if (g_hash_table_lookup(ms->remote_devs, id)) {
+        qmp_rdevice_del(id, errp);
+        return;
+    }
+#endif
+
+    dev = find_device_state(id, errp);
     if (dev != NULL) {
         qdev_unplug(dev, errp);
     }
remote/remote-main.c +45 -0

63 lines not on this page · raw message

stubs/monitor.c +4 -0
index a55b674777..ac24eeb5d4 100644
@@ -51,3 +51,7 @@ ObjectPropertyInfoList *qmp_device_list_properties(const char *typename,
 void qmp_rdevice_add(QDict *qdict, QObject **ret_data, Error **errp)
 {
 }
+
+void qmp_rdevice_del(const char *id, Error **errp)
+{
+}
Signature · 1 line
2.17.1