Patchwork [2/2] qdev: Allow chardevs to be hot-plugged

login
register
mail settings
Submitter Amit Shah
Date Feb. 10, 2011, 10:16 a.m.
Message ID <980c101a9dc5db30a911b07294d6cf55a3ca22e8.1297332970.git.amit.shah@redhat.com>
Download mbox | patch
Permalink /patch/82590/
State New
Headers show

Comments

Amit Shah - Feb. 10, 2011, 10:16 a.m.
This commit enables chardevs to be hot-plugged to a running qemu
machine.  The syntax is similar to the -chardev command line:

(qemu) chardev_add socket,path=/tmp/foo,server,nowait,id=char0

Signed-off-by: Amit Shah <amit.shah@redhat.com>
---
 hmp-commands.hx |   16 ++++++++++++++++
 hw/qdev.c       |   15 +++++++++++++++
 hw/qdev.h       |    1 +
 qmp-commands.hx |   23 +++++++++++++++++++++++
 4 files changed, 55 insertions(+), 0 deletions(-)

Patch

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 38e1eb7..e0e6fc8 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -554,6 +554,22 @@  command @code{info usb} to see the devices you can remove.
 ETEXI
 
     {
+        .name       = "chardev_add",
+        .args_type  = "chardev:O",
+        .params     = "backend[,prop=value][,...],id=str",
+        .help       = "add chardev, like -chardev on the command line",
+        .user_print = monitor_user_noop,
+        .mhandler.cmd_new = do_chardev_add,
+    },
+
+STEXI
+@item chardev_add @var{config}
+@findex chardev_add
+
+Add chardev.
+ETEXI
+
+    {
         .name       = "device_add",
         .args_type  = "device:O",
         .params     = "driver[,prop=value][,...]",
diff --git a/hw/qdev.c b/hw/qdev.c
index c7fec44..1e24f58 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -861,6 +861,21 @@  void do_info_qdm(Monitor *mon)
     }
 }
 
+int do_chardev_add(Monitor *mon, const QDict *qdict, QObject **ret_data)
+{
+    QemuOpts *opts;
+
+    opts = qemu_opts_from_qdict(qemu_find_opts("chardev"), qdict);
+    if (!opts) {
+        return -1;
+    }
+    if (!qemu_chr_open_opts(opts, NULL)) {
+        qemu_opts_del(opts);
+        return -1;
+    }
+    return 0;
+}
+
 int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data)
 {
     QemuOpts *opts;
diff --git a/hw/qdev.h b/hw/qdev.h
index 9808f85..5698713 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -212,6 +212,7 @@  BusState *sysbus_get_default(void);
 
 void do_info_qtree(Monitor *mon);
 void do_info_qdm(Monitor *mon);
+int do_chardev_add(Monitor *mon, const QDict *qdict, QObject **ret_data);
 int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data);
 int do_device_del(Monitor *mon, const QDict *qdict, QObject **ret_data);
 
diff --git a/qmp-commands.hx b/qmp-commands.hx
index df40a3d..255da9a 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -275,6 +275,29 @@  Example:
 EQMP
 
     {
+        .name       = "chardev_add",
+        .args_type  = "device:O",
+        .params     = "backend[,prop=value][,...],id=str",
+        .help       = "add chardev, like -chardev on the command line",
+        .user_print = monitor_user_noop,
+        .mhandler.cmd_new = do_chardev_add,
+    },
+
+SQMP
+chardev_add
+----------
+
+Add a chardev.
+
+Arguments:
+
+- "backend": the backend of the new chardev (json-string)
+- "id": the chardev's ID, must be unique (json-string)
+- chardev properties
+
+EQMP
+
+    {
         .name       = "device_add",
         .args_type  = "device:O",
         .params     = "driver[,prop=value][,...]",