serial device hotplug patch series.
Hi,
This patch series tackles serial device hotplug.
The first four patches have been on the list before, they implement pci-serial devices featuring a hot-pluggable 16550 uart and got some minor tweaks only.
The next two patches update the usb-serial device. It will only show up in the guest when the chardev is open. You'll see the difference with socket chardevs: If you open the chardev (by connecting to the socket) the device will show up in the guest, on close (disconnect) it will disappear.
Final patch adds chardev hotplug to the mix, which makes the other patches alot more useful. It is the missing bit needed to really hotplug serial devices:
(qemu) chardev_add pciserial file /root/hotchardev.log (qemu) device_add pci-serial,chardev=pciserial,id=pciserial
And the reverse:
(qemu) device_del pciserial
(qemu) chardev_del pciserial
please review & pull,
Gerd
The following changes since commit b4ae3cfa57b8c1bdbbd7b7d420971e9171203ade:
ssi: Add slave autoconnect helper (2012-10-10 11:13:32 +1000)
are available in the git repository at:
git://git.kraxel.org/qemu serial.1
Gerd Hoffmann (7):
serial: split serial.c
serial: add pci variant
serial: add windows inf file for the pci card to docs
serial: add 2x + 4x pci variant
usb-serial: don't magically zap chardev on umplug
usb-serial: only expose device in guest when the chardev is open
chardev: add hotplug support.
default-configs/pci.mak | 2 + docs/qemupciserial.inf | 109 ++++++++++++++++++ hmp-commands.hx | 49 ++++++++ hmp.c | 39 +++++++ hmp.h | 2 + hw/Makefile.objs | 3 +- hw/alpha_dp264.c | 1 + hw/kzm.c | 2 +- hw/mips_fulong2e.c | 1 + hw/mips_jazz.c | 1 + hw/mips_malta.c | 1 + hw/mips_mipssim.c | 2 +- hw/mips_r4k.c | 1 + hw/musicpal.c | 2 +- hw/omap_uart.c | 3 +- hw/openrisc_sim.c | 3 +- hw/pc.c | 1 + hw/pc.h | 27 ----- hw/pci_ids.h | 1 + hw/petalogix_ml605_mmu.c | 2 +- hw/ppc/e500.c | 2 +- hw/ppc405_uc.c | 2 +- hw/ppc440_bamboo.c | 2 +- hw/ppc_prep.c | 1 + hw/pxa2xx.c | 2 +- hw/serial-isa.c | 130 ++++++++++++++++++++++ hw/serial-pci.c | 272 ++++++++++++++++++++++++++++++++++++++++++++++ hw/serial.c | 149 ++----------------------- hw/serial.h | 74 +++++++++++++ hw/sm501.c | 2 +- hw/sun4u.c | 1 + hw/usb/dev-serial.c | 21 +++- hw/virtex_ml507.c | 2 +- hw/xtensa_lx60.c | 3 +- qapi-schema.json | 46 ++++++++ qemu-char.c | 74 +++++++++++++ qmp-commands.hx | 61 ++++++++++ 37 files changed, 913 insertions(+), 183 deletions(-) create mode 100644 docs/qemupciserial.inf create mode 100644 hw/serial-isa.c create mode 100644 hw/serial-pci.c create mode 100644 hw/serial.h
PATCH 1/7 serial: split serial.c
Split serial.c into serial.c, serial.h and serial-isa.c. While being at creating a serial.h header file move the serial prototypes from pc.h to the new serial.h. The latter leads to s/pc.h/serial.h/ in tons of boards which just want the serial bits from pc.h
--- hw/Makefile.objs | 2 +- hw/alpha_dp264.c | 1 + hw/kzm.c | 2 +- hw/mips_fulong2e.c | 1 + hw/mips_jazz.c | 1 + hw/mips_malta.c | 1 + hw/mips_mipssim.c | 2 +- hw/mips_r4k.c | 1 + hw/musicpal.c | 2 +- hw/omap_uart.c | 3 +- hw/openrisc_sim.c | 3 +- hw/pc.c | 1 + hw/pc.h | 27 --------- hw/petalogix_ml605_mmu.c | 2 +- hw/ppc/e500.c | 2 +- hw/ppc405_uc.c | 2 +- hw/ppc440_bamboo.c | 2 +- hw/ppc_prep.c | 1 + hw/pxa2xx.c | 2 +- hw/serial-isa.c | 130 +++++++++++++++++++++++++++++++++++++++++ hw/serial.c | 143 ++-------------------------------------------- hw/serial.h | 73 +++++++++++++++++++++++ hw/sm501.c | 2 +- hw/sun4u.c | 1 + hw/virtex_ml507.c | 2 +- hw/xtensa_lx60.c | 3 +- 26 files changed, 232 insertions(+), 180 deletions(-) create mode 100644 hw/serial-isa.c create mode 100644 hw/serial.h
hw/Makefile.objs +1 -1
@@ -20,7 +20,7 @@ common-obj-$(CONFIG_M48T59) += m48t59.o common-obj-$(CONFIG_ESCC) += escc.o common-obj-$(CONFIG_EMPTY_SLOT) += empty_slot.o -common-obj-$(CONFIG_SERIAL) += serial.o +common-obj-$(CONFIG_SERIAL) += serial.o serial-isa.o common-obj-$(CONFIG_PARALLEL) += parallel.o common-obj-$(CONFIG_I8254) += i8254_common.o i8254.o common-obj-$(CONFIG_PCSPK) += pcspk.o
hw/alpha_dp264.c +1 -0
@@ -15,6 +15,7 @@#include "mc146818rtc.h" #include "ide.h" #include "i8254.h" +#include "serial.h" #define MAX_IDE_BUS 2
hw/kzm.c +1 -1
@@ -21,7 +21,7 @@#include "net.h" #include "sysemu.h" #include "boards.h" -#include "pc.h" /* for the FPGA UART that emulates a 16550 */ +#include "serial.h" #include "imx.h" /* Memory map for Kzm Emulation Baseboard:
hw/mips_fulong2e.c +1 -0
@@ -20,6 +20,7 @@#include "hw.h" #include "pc.h" +#include "serial.h" #include "fdc.h" #include "net.h" #include "boards.h"
hw/mips_jazz.c +1 -0
@@ -26,6 +26,7 @@#include "mips.h" #include "mips_cpudevs.h" #include "pc.h" +#include "serial.h" #include "isa.h" #include "fdc.h" #include "sysemu.h"
hw/mips_malta.c +1 -0
@@ -24,6 +24,7 @@#include "hw.h" #include "pc.h" +#include "serial.h" #include "fdc.h" #include "net.h" #include "boards.h"
hw/mips_mipssim.c +1 -1
@@ -27,7 +27,7 @@#include "hw.h" #include "mips.h" #include "mips_cpudevs.h" -#include "pc.h" +#include "serial.h" #include "isa.h" #include "net.h" #include "sysemu.h"
hw/mips_r4k.c +1 -0
@@ -11,6 +11,7 @@#include "mips.h" #include "mips_cpudevs.h" #include "pc.h" +#include "serial.h" #include "isa.h" #include "net.h" #include "sysemu.h"
hw/musicpal.c +1 -1
@@ -15,7 +15,7 @@#include "net.h" #include "sysemu.h" #include "boards.h" -#include "pc.h" +#include "serial.h" #include "qemu-timer.h" #include "ptimer.h" #include "block.h"
hw/omap_uart.c +1 -2
@@ -20,8 +20,7 @@#include "qemu-char.h" #include "hw.h" #include "omap.h" -/* We use pc-style serial ports. */ -#include "pc.h" +#include "serial.h" #include "exec-memory.h" /* UARTs */
hw/openrisc_sim.c +2 -1
@@ -21,7 +21,8 @@#include "hw.h" #include "boards.h" #include "elf.h" -#include "pc.h" +#include "serial.h" +#include "net.h" #include "loader.h" #include "exec-memory.h" #include "sysemu.h"
hw/pc.c +1 -0
@@ -23,6 +23,7 @@*/ #include "hw.h" #include "pc.h" +#include "serial.h" #include "apic.h" #include "fdc.h" #include "ide.h"
hw/pc.h +0 -27
@@ -12,33 +12,6 @@/* PC-style peripherals (also used by other machines). */ -/* serial.c */ - -SerialState *serial_init (int base,qemu_irq irq,int baudbase, -CharDriverState *chr); -SerialState *serial_mm_init (MemoryRegion *address_space, -target_phys_addr_t base,int it_shift, -qemu_irq irq,int baudbase, -CharDriverState *chr,enum device_endian ); -static inline bool serial_isa_init (ISABus *bus,int index, -CharDriverState *chr) -{ -ISADevice *dev; - - dev =isa_try_create (bus,"isa-serial" ); -if (!dev) { -return false; - } -qdev_prop_set_uint32 (&dev->qdev,"index" , index); -qdev_prop_set_chr (&dev->qdev,"chardev" , chr); -if (qdev_init (&dev->qdev) <0 ) { -return false; - } -return true; -} - -void serial_set_frequency (SerialState *s,uint32_t frequency); -/* parallel.c */ static inline bool parallel_init (ISABus *bus,int index,CharDriverState *chr) {
hw/petalogix_ml605_mmu.c +1 -1
@@ -34,7 +34,7 @@#include "boards.h" #include "xilinx.h" #include "blockdev.h" -#include "pc.h" +#include "serial.h" #include "exec-memory.h" #include "ssi.h"
hw/ppc/e500.c +1 -1
@@ -19,7 +19,7 @@#include "e500.h" #include "net.h" #include "hw/hw.h" -#include "hw/pc.h" +#include "hw/serial.h" #include "hw/pci.h" #include "hw/boards.h" #include "sysemu.h"
hw/ppc405_uc.c +1 -1
@@ -24,7 +24,7 @@#include "hw.h" #include "ppc.h" #include "ppc405.h" -#include "pc.h" +#include "serial.h" #include "qemu-timer.h" #include "sysemu.h" #include "qemu-log.h"
hw/ppc440_bamboo.c +1 -1
@@ -23,7 +23,7 @@#include "loader.h" #include "elf.h" #include "exec-memory.h" -#include "pc.h" +#include "serial.h" #include "ppc.h" #include "ppc405.h" #include "sysemu.h"
hw/ppc_prep.c +1 -0
@@ -24,6 +24,7 @@#include "hw.h" #include "nvram.h" #include "pc.h" +#include "serial.h" #include "fdc.h" #include "net.h" #include "sysemu.h"
hw/pxa2xx.c +1 -1
@@ -10,7 +10,7 @@#include "sysbus.h" #include "pxa.h" #include "sysemu.h" -#include "pc.h" +#include "serial.h" #include "i2c.h" #include "ssi.h" #include "qemu-char.h"
hw/serial-isa.c new file +130 -0
130 lines not on this page · raw message
hw/serial.c +5 -138
192 lines not on this page · raw message
hw/serial.h new file +73 -0
73 lines not on this page · raw message
hw/sm501.c +1 -1
@@ -24,7 +24,7 @@#include <stdio.h> #include "hw.h" -#include "pc.h" +#include "serial.h" #include "console.h" #include "devices.h" #include "sysbus.h"
hw/sun4u.c +1 -0
@@ -25,6 +25,7 @@#include "pci.h" #include "apb_pci.h" #include "pc.h" +#include "serial.h" #include "nvram.h" #include "fdc.h" #include "net.h"
hw/virtex_ml507.c +1 -1
@@ -24,7 +24,7 @@#include "sysbus.h" #include "hw.h" -#include "pc.h" +#include "serial.h" #include "net.h" #include "flash.h" #include "sysemu.h"
hw/xtensa_lx60.c +2 -1
@@ -31,7 +31,8 @@#include "elf.h" #include "memory.h" #include "exec-memory.h" -#include "pc.h" +#include "serial.h" +#include "net.h" #include "sysbus.h" #include "flash.h" #include "blockdev.h"
Signature · 1 line
1.7.1
PATCH 2/7 serial: add pci variant
In reply to Gerd HoffmannSo we get a hot-pluggable 16550 uart.
--- default-configs/pci.mak | 2 + hw/Makefile.objs | 1 + hw/pci_ids.h | 1 + hw/serial-pci.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++ hw/serial.c | 6 +++ hw/serial.h | 1 + 6 files changed, 126 insertions(+), 0 deletions(-) create mode 100644 hw/serial-pci.c
default-configs/pci.mak +2 -0
@@ -19,3 +19,5 @@ CONFIG_IDE_PCI=y CONFIG_AHCI=y CONFIG_ESP=y CONFIG_ESP_PCI=y +CONFIG_SERIAL=y +CONFIG_SERIAL_PCI=y
hw/Makefile.objs +1 -0
@@ -21,6 +21,7 @@ common-obj-$(CONFIG_ESCC) += escc.o common-obj-$(CONFIG_EMPTY_SLOT) += empty_slot.o common-obj-$(CONFIG_SERIAL) += serial.o serial-isa.o +common-obj-$(CONFIG_SERIAL_PCI) += serial-pci.o common-obj-$(CONFIG_PARALLEL) += parallel.o common-obj-$(CONFIG_I8254) += i8254_common.o i8254.o common-obj-$(CONFIG_PCSPK) += pcspk.o
hw/pci_ids.h +1 -0
@@ -37,6 +37,7 @@#define PCI_CLASS_BRIDGE_PCI 0x0604#define PCI_CLASS_BRIDGE_OTHER 0x0680 +#define PCI_CLASS_COMMUNICATION_SERIAL 0x0700#define PCI_CLASS_COMMUNICATION_OTHER 0x0780#define PCI_CLASS_PROCESSOR_CO 0x0b40
hw/serial-pci.c new file +115 -0
115 lines not on this page · raw message
hw/serial.c +6 -0
@@ -692,6 +692,12 @@ void serial_init_core(SerialState *s) serial_event, s); } +void serial_exit_core (SerialState *s) +{ +qemu_chr_add_handlers (s->chr,NULL ,NULL ,NULL ,NULL ); +qemu_unregister_reset (serial_reset, s); +} +/* Change the main reference oscillator frequency. */ void serial_set_frequency (SerialState *s,uint32_t frequency) {
hw/serial.h +1 -0
@@ -59,6 +59,7 @@ extern const VMStateDescription vmstate_serial;extern const MemoryRegionOps serial_io_ops;void serial_init_core (SerialState *s); +void serial_exit_core (SerialState *s);void serial_set_frequency (SerialState *s,uint32_t frequency);/* legacy pre qom */
Signature · 1 line
1.7.1
PATCH 3/7 serial: add windows inf file for the pci card to docs
In reply to Gerd Hoffmann--- docs/qemupciserial.inf | 107 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 107 insertions(+), 0 deletions(-) create mode 100644 docs/qemupciserial.inf
docs/qemupciserial.inf new file +107 -0
@@ -0,0 +1,107 @@ +; qemupciserial.inf for QEMU, based on MSPORTS.INF + +; The driver itself is shipped with Windows (serial.sys). This is +; just a inf file to tell windows which pci id the serial pci card +; emulated by qemu has, and to apply a name tag to it which windows +; will show in the device manager. + +; Installing the driver: Go to device manager. You should find a "pci +; serial card" tagged with a yellow question mark. Open properties. +; Pick "update driver". Then "select driver manually". Pick "Ports +; (Com+Lpt)" from the list. Click "Have a disk". Select this file. +; Procedure may vary a bit depending on the windows version. + +[Version] +Signature="$CHICAGO$" +Class=Ports +ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318} +Provider=%QEMU% +DriverVer=09/24/2012,1.3.0 + +[SourceDisksNames] +3426=windows cd + +[SourceDisksFiles] +serial.sys = 3426 +serenum.sys = 3426 + +[DestinationDirs] +DefaultDestDir = 11 ;LDID_SYS +ComPort.NT.Copy = 12 ;DIRID_DRIVERS +SerialEnumerator.NT.Copy=12 ;DIRID_DRIVERS + +; Drivers +;---------------------------------------------------------- +[Manufacturer] +%QEMU%=QEMU,NTx86 + +[QEMU.NTx86] +%QEMU-PCI_SERIAL.DeviceDesc% = ComPort, "PCI\VEN_1b36&DEV_0002&CC_0700" + +; COM sections +;---------------------------------------------------------- +[ComPort.AddReg] +HKR,,PortSubClass,1,01 + +[ComPort.NT] +AddReg=ComPort.AddReg, ComPort.NT.AddReg +LogConfig=caa +SyssetupPnPFlags = 1 + +[ComPort.NT.HW] +AddReg=ComPort.NT.HW.AddReg + +[ComPort.NT.AddReg] +HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" + +[ComPort.NT.HW.AddReg] +HKR,,"UpperFilters",0x00010000,"serenum" + +;-------------- Service installation +; Port Driver (function driver for this device) +[ComPort.NT.Services] +AddService = Serial, 0x00000002, Serial_Service_Inst, Serial_EventLog_Inst +AddService = Serenum,,Serenum_Service_Inst + +; -------------- Serial Port Driver install sections +[Serial_Service_Inst] +DisplayName = %Serial.SVCDESC% +ServiceType = 1 ; SERVICE_KERNEL_DRIVER +StartType = 1 ; SERVICE_SYSTEM_START (this driver may do detection) +ErrorControl = 0 ; SERVICE_ERROR_IGNORE +ServiceBinary = %12%\serial.sys +LoadOrderGroup = Extended base + +; -------------- Serenum Driver install section +[Serenum_Service_Inst] +DisplayName = %Serenum.SVCDESC% +ServiceType = 1 ; SERVICE_KERNEL_DRIVER +StartType = 3 ; SERVICE_DEMAND_START +ErrorControl = 1 ; SERVICE_ERROR_NORMAL +ServiceBinary = %12%\serenum.sys +LoadOrderGroup = PNP Filter + +[Serial_EventLog_Inst] +AddReg = Serial_EventLog_AddReg + +[Serial_EventLog_AddReg] +HKR,,EventMessageFile,0x00020000,"%%SystemRoot%%\System32\IoLogMsg.dll;%%SystemRoot%%\System32\drivers\serial.sys" +HKR,,TypesSupported,0x00010001,7 + +; The following sections are COM port resource configs. +; Section name format means: +; Char 1 = c (COM port) +; Char 2 = I/O config: 1 (3f8), 2 (2f8), 3 (3e8), 4 (2e8), a (any) +; Char 3 = IRQ config: #, a (any) + +[caa] ; Any base, any IRQ +ConfigPriority=HARDRECONFIG +IOConfig=8@100-ffff%fff8(3ff::) +IRQConfig=S:3,4,5,7,9,10,11,12,14,15 + +[Strings] +QEMU="QEMU" +QEMU-PCI_SERIAL.DeviceDesc="QEMU Serial PCI Card" + +Serial.SVCDESC = "Serial port driver" +Serenum.SVCDESC = "Serenum Filter Driver"
Signature · 1 line
1.7.1
PATCH 4/7 serial: add 2x + 4x pci variant
In reply to Gerd HoffmannAdd multiport serial card implementation, with two variants, one featuring two and one featuring four ports.
--- docs/qemupciserial.inf | 2 + hw/serial-pci.c | 157 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 159 insertions(+), 0 deletions(-)
docs/qemupciserial.inf +2 -0
@@ -11,6 +11,8 @@ ; (Com+Lpt)" from the list. Click "Have a disk". Select this file. ; Procedure may vary a bit depending on the windows version. +; FIXME: This file covers the single port version only. + [Version] Signature="$CHICAGO$" Class=Ports
hw/serial-pci.c +157 -0
212 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 5/7 usb-serial: don't magically zap chardev on umplug
In reply to Gerd Hoffmann--- hw/usb/dev-serial.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
hw/usb/dev-serial.c +1 -1
@@ -421,7 +421,7 @@ static void usb_serial_handle_destroy(USBDevice *dev) {USBSerialState *s = (USBSerialState *)dev; -qemu_chr_delete (s->cs); +qemu_chr_add_handlers (s->cs,NULL ,NULL ,NULL ,NULL ); }static int usb_serial_can_read (void *opaque)
Signature · 1 line
1.7.1
PATCH 6/7 usb-serial: only expose device in guest when the chardev is open
In reply to Gerd Hoffmann--- hw/usb/dev-serial.c | 19 +++++++++++++++++-- 1 files changed, 17 insertions(+), 2 deletions(-)
hw/usb/dev-serial.c +17 -2
@@ -427,6 +427,10 @@ static void usb_serial_handle_destroy(USBDevice *dev)static int usb_serial_can_read (void *opaque) {USBSerialState *s = opaque; + +if (!s->dev.attached) { +return 0 ; + }return RECV_BUF - s->recv_used; }
@@ -469,8 +473,14 @@ static void usb_serial_event(void *opaque, int event)case CHR_EVENT_FOCUS :break ;case CHR_EVENT_OPENED : -usb_serial_reset (s); -/* TODO: Reset USB port */ +if (!s->dev.attached) { +usb_device_attach (&s->dev); + } +break ; +case CHR_EVENT_CLOSED : +if (s->dev.attached) { +usb_device_detach (&s->dev); + }break ; } }
@@ -481,6 +491,7 @@ static int usb_serial_initfn(USBDevice *dev)usb_desc_create_serial (dev);usb_desc_init (dev); + dev->auto_attach =0 ;if (!s->cs) {error_report ("Property chardev is required" );
@@ -490,6 +501,10 @@ static int usb_serial_initfn(USBDevice *dev)qemu_chr_add_handlers (s->cs, usb_serial_can_read, usb_serial_read, usb_serial_event, s);usb_serial_handle_reset (dev); + +if (s->cs->opened && !dev->attached) { +usb_device_attach (dev); + }return 0 ; }
Signature · 1 line
1.7.1
PATCH 7/7 chardev: add hotplug support.
In reply to Gerd HoffmannThis patch adds chardev_add and chardev_del monitor commands.
chardev_del is pretty straight forward, it just takes an id argument and zaps the chardev specified.
chardev_add is more tricky as there are tons of arguments for the different backends. The hmp version limited to the most common use cases, especially when it comes to sockets: You can only specify port (tcp) or path (unix) and qemu will create a listening socket. For example this ...
(qemu) chardev_add foo socket 42
... will do the same as ...
-chardev socket,id=foo,port=42,server,nowait
on the qemu command line.
The qmp version has full support for everything the -chardev command line switch can handle. The implementation is pretty straight
forward: It just puts all arguments it got into a QemuOpts, then goes call qemu_chr_new_from_opts().
--- hmp-commands.hx | 49 +++++++++++++++++++++++++++++++++++ hmp.c | 39 ++++++++++++++++++++++++++++ hmp.h | 2 + qapi-schema.json | 46 +++++++++++++++++++++++++++++++++ qemu-char.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 61 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 271 insertions(+), 0 deletions(-)
hmp-commands.hx +49 -0
@@ -1404,6 +1404,55 @@ passed since 1970, i.e. unix epoch. ETEXI { + .name = "chardev_add", + .args_type = "id:s,backend:s,arg:s?", + .params = "id backend [ name | port | path ]", + .help = "add chardev", + .mhandler.cmd = hmp_chardev_add, + }, + +STEXI +@item chardev_add id backend [ name | port | path ] +@findex chardev_add + +Create chardev with the specified @var{id} and @var{backend}. The hmp +version is limited to a commonly used subset, if you need more control +use qmp instead. + +If @var{backend} is 'spicevmc' @var{arg} is assumed to be the spice +channel name. + +If @var{backend} is 'udp' @var{arg} is assumed to be a port number. + +If @var{backend} is 'socket' and @var{arg} starts with a digit the +argument is assumed to be a port number and a tcp socket is created +(in server mode). + +If @var{backend} is 'socket' and @var{arg} doesn't start with a digit +@var{arg} is assumed to be a path and a unix socket is created (in +server mode). + +In all other cases @var{arg} is assumed to be a path. + +ETEXI + + { + .name = "chardev_del", + .args_type = "id:s", + .params = "id", + .help = "del chardev", + .mhandler.cmd = hmp_chardev_del, + }, + +STEXI +@item chardev_del id +@findex chardev_del + +Removes the chardev @var{id}. + +ETEXI + + { .name = "info", .args_type = "item:s?", .params = "[subcommand]",
hmp.c +39 -0
@@ -1209,3 +1209,42 @@ void hmp_screen_dump(Monitor *mon, const QDict *qdict)qmp_screendump (filename, &err);hmp_handle_error (mon, &err); } + +void hmp_chardev_add (Monitor *mon,const QDict *qdict) +{ +const char *backend =qdict_get_str (qdict,"backend" ); +const char *arg =qdict_get_str (qdict,"arg" ); +const char *id =qdict_get_str (qdict,"id" ); +const char *path =NULL , *name =NULL , *port =NULL , *host =NULL ; +Error *err =NULL ; + +if (arg) { +if (strcmp (backend,"spicevmc" ) ==0 ) { + name = arg; + }else if (strcmp (backend,"udp" ) ==0 ) { + port = arg; + }else if (strcmp (backend,"socket" ) ==0 &&isdigit (arg[0 ])) { + port = arg; + }else { + path = arg; + } + } + +qmp_chardev_add (id, backend, + path, name, host, port, + true,/* server */ + false,/* wait */ + false,/* ipv4 (only) */ + false,/* ipv6 (only) */ + false,/* telnet */ + &err); +hmp_handle_error (mon, &err); +} + +void hmp_chardev_del (Monitor *mon,const QDict *qdict) +{ +Error *err =NULL ; +qmp_chardev_del (qdict_get_str (qdict,"id" ), + &err); +hmp_handle_error (mon, &err); +}
hmp.h +2 -0
@@ -75,5 +75,7 @@ void hmp_getfd(Monitor *mon, const QDict *qdict);void hmp_closefd (Monitor *mon,const QDict *qdict);void hmp_send_key (Monitor *mon,const QDict *qdict);void hmp_screen_dump (Monitor *mon,const QDict *qdict); +void hmp_chardev_add (Monitor *mon,const QDict *qdict); +void hmp_chardev_del (Monitor *mon,const QDict *qdict);#endif
qapi-schema.json +46 -0
49 lines not on this page · raw message
qemu-char.c +74 -0
77 lines not on this page · raw message
qmp-commands.hx +61 -0
64 lines not on this page · raw message
Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH 7/7] chardev: add hotplug support.
Il 12/10/2012 11:26, Gerd Hoffmann ha scritto:
Quoted 11 lines
This patch adds
chardev_addandchardev_delmonitor commands.
chardev_delis pretty straight forward, it just takes an id argument and zaps the chardev specified.
chardev_addis more tricky as there are tons of arguments for the different backends. The hmp version limited to the most common use cases, especially when it comes to sockets: You can only specify port (tcp) or path (unix) and qemu will create a listening socket. For example this ...
Quoted 5 lines
(qemu)
chardev_addfoo socket 42... will do the same as ...
-chardev socket,id=foo,port=42,server,nowait
Why not
chardev_add socket,id=foo,port=42,server,nowait
?
qapi-schema.json line 2826
Quoted 6 lines
qapi-schema.json +6
-0+{ 'command': 'chardev_add', 'data': {'id' : 'str', + 'backend' : 'str', + 'path' : 'str', + 'name' : 'str', + 'host' : 'str', + 'port' : 'str',
You cannot pass NULLs via QMP, so these need to be optional.
I suggest that you implement the commands in a similar way as netdev_add.
Paolo
Quoted 170 lines
qapi-schema.json +18
-0+ 'server' : 'bool', + 'wait' : 'bool', + 'ipv4' : 'bool', + 'ipv6' : 'bool', + 'telnet' : 'bool' } } + +## +# @chardev_del: +# +# Remove a chardev +# +# @id: the chardev's ID, must exist and not be in use +# +# Returns: Nothing on success +# +# Since: 1.3.0 +## +{ 'command': 'chardev_del', 'data': {'id': 'str'} }qemu-char.c +74
-0@@ -2900,3 +2900,77 @@ CharDriverState *qemu_char_get_next_serial(void)return serial_hds[next_serial++]; } +void qmp_chardev_add (const char *id,const char *backend, +const char *path,const char *name, +const char *host,const char *port, +bool server,bool wait, +bool ipv4,bool ipv6, +bool telnet,Error **errp) +{ +CharDriverState *chr; +QemuOpts *opts; + + chr =qemu_chr_find (id); +if (NULL != chr) { +error_setg (errp,"Chardev id '%s' exists already\n" , id); +return ; + } + + opts =qemu_opts_create (qemu_find_opts ("chardev" ), id,1 , errp); +if (error_is_set (errp)) { +return ; + } +qemu_opt_set (opts,"backend" , backend); +if (path) { +qemu_opt_set (opts,"path" , path); + } +if (name) { +qemu_opt_set (opts,"name" , name); + } +if (host) { +qemu_opt_set (opts,"host" , host); + } +if (port) { +qemu_opt_set (opts,"port" , port); + } +if (server) { +qemu_opt_set (opts,"server" ,"on" ); + } +if (!wait) { +qemu_opt_set (opts,"wait" ,"off" ); + } +if (ipv4) { +qemu_opt_set (opts,"ipv4" ,"on" ); + } +if (ipv6) { +qemu_opt_set (opts,"ipv6" ,"on" ); + } +if (telnet) { +qemu_opt_set (opts,"telnet" ,"on" ); + } + + chr =qemu_chr_new_from_opts (opts,NULL ); +qemu_opts_del (opts); + +if (chr ==NULL ) { +error_setg (errp,"Creating chardev failed\n" ); +return ; + } +} + +void qmp_chardev_del (const char *id,Error **errp) +{ +CharDriverState *chr; + + chr =qemu_chr_find (id); +if (NULL == chr) { +error_setg (errp,"Chardev '%s' not found\n" , id); +return ; + } +if (chr->chr_can_read || chr->chr_read || + chr->chr_event || chr->handler_opaque) { +error_setg (errp,"Chardev '%s' is busy\n" , id); +return ; + } +qemu_chr_delete (chr); +}qmp-commands.hx +61
-0@@ -2576,3 +2576,64 @@ EQMP .args_type = "", .mhandler.cmd_new = qmp_marshal_input_query_target, }, + + { + .name = "chardev_add", + .args_type = "", + .mhandler.cmd_new = qmp_marshal_input_chardev_add, + }, + +SQMP +chardev_add +----------- + +Add a chardev. + +Arguments: + +- "id": the chardev's ID, must be unique (json-string) +- "backend": the chardev backend: "file", "socket", ... (json-string) +- "path": file / device / unix socket path (json-string, optional) +- "name": spice channel name (json-string, optional) +- "host": host name (json-string, optional) +- "port": port number (json-string, optional) +- "server": create socket in server mode (json-bool, optional) +- "wait": wait for connect (json-bool, optional) +- "ipv4": force ipv4-only (json-bool, optional) +- "ipv6": force ipv6-only (json-bool, optional) +- "telnet": telnet negotiation (json-bool, optional) + +Example: + +-> { "execute": "chardev_add", "arguments": { "id" : "foo", + "backend" : "socket", + "path" : "/tmp/foo", + "server" : "on", + "wait" : "off" } } +<- { "return": {} } + +EQMP + + { + .name = "chardev_del", + .args_type = "", + .mhandler.cmd_new = qmp_marshal_input_chardev_del, + }, + + +SQMP +chardev_del +----------- + +Remove a chardev. + +Arguments: + +- "id": the chardev's ID, must exist and not be in use (json-string) + +Example: + +-> { "execute": "chardev_del", "arguments": { "id" : "foo" } } +<- { "return": {} } + +EQMP
Re: [Qemu-devel] [PATCH 7/7] chardev: add hotplug support.
Quoted 16 lines · Paolo Bonzini
Il 12/10/2012 11:26, Gerd Hoffmann ha scritto:
Quoted 15 lines
This patch adds
chardev_addandchardev_delmonitor commands.
chardev_delis pretty straight forward, it just takes an id argument and zaps the chardev specified.
chardev_addis more tricky as there are tons of arguments for the different backends. The hmp version limited to the most common use cases, especially when it comes to sockets: You can only specify port (tcp) or path (unix) and qemu will create a listening socket. For example this ...(qemu)
chardev_addfoo socket 42... will do the same as ...
Quoted 7 lines
Quoted 1 line
-chardev socket,id=foo,port=42,server,nowait
Why not
chardev_addsocket,id=foo,port=42,server,nowait?
Yea, maybe, but see below.
Quoted 8 lines
qapi-schema.json line 2826
Quoted 6 lines
qapi-schema.json +6
-0+{ 'command': 'chardev_add', 'data': {'id' : 'str', + 'backend' : 'str', + 'path' : 'str', + 'name' : 'str', + 'host' : 'str', + 'port' : 'str',You cannot pass NULLs via QMP, so these need to be optional.
Fixed.
Quoted 1 line
I suggest that you implement the commands in a similar way as
netdev_add.
Why? Isn't the whole point of using josn is that you'll get the stuff from the josn parser & marshaller in a usable form instead of having it to feed into yet another parser? I think the only reason netdev_add exists in the current form is that it predates qmp.
cheers,
Gerd
Re: [Qemu-devel] [PATCH 7/7] chardev: add hotplug support.
Il 12/10/2012 12:23, Gerd Hoffmann ha scritto:
Quoted 6 lines
Quoted 1 line
I suggest that you implement the commands in a similar way as
netdev_add.Why? Isn't the whole point of using josn is that you'll get the stuff from the josn parser & marshaller in a usable form instead of having it to feed into yet another parser? I think the only reason
netdev_addexists in the current form is that it predates qmp.
In principle you're right, but I think it's ugly that adding another chardev argument needs changes in 3 places instead of just one. (And I'd like to add another argument soon enough...).
Paolo
Re: [Qemu-devel] [PATCH 7/7] chardev: add hotplug support.
Quoted 10 lines · Paolo Bonzini
Il 12/10/2012 12:23, Gerd Hoffmann ha scritto:
Quoted 6 lines
Quoted 1 line
I suggest that you implement the commands in a similar way as
netdev_add.Why? Isn't the whole point of using josn is that you'll get the stuff from the josn parser & marshaller in a usable form instead of having it to feed into yet another parser? I think the only reason
netdev_addexists in the current form is that it predates qmp.In principle you're right, but I think it's ugly that adding another chardev argument needs changes in 3 places instead of just one.
Hmm, I don't have to use the generated marshaller, right? With direct access to the QDict I could just transform it into a QemuOpts. A new parameter wouldn't need code changes then. And the code would be reusable and probably also be simpler. The qapi schema still needs an update though.
HMP is more tricky, but I think we should sort QMP first.
cheers,
Gerd
Re: [Qemu-devel] [PATCH 7/7] chardev: add hotplug support.
Il 12/10/2012 13:15, Gerd Hoffmann ha scritto:
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
In principle you're right, but I think it's ugly that adding another chardev argument needs changes in 3 places instead of just one.
Hmm, I don't have to use the generated marshaller, right? With direct access to the QDict I could just transform it into a QemuOpts.
That's exactly what I was suggesting. :P
Quoted 3 lines
A new parameter wouldn't need code changes then. And the code would be reusable and probably also be simpler. The qapi schema still needs an update though.
The QAPI schema is only used by the generated marshaller.
Quoted 1 line
HMP is more tricky, but I think we should sort QMP first.
HMP can just take a string, parse it into QemuOpts, and call a small wrapper that calls qemu_chr_new_from_opts and returns errors via Error.
Paolo
Re: [Qemu-devel] [PATCH 7/7] chardev: add hotplug support.
Quoted 7 lines · Paolo Bonzini
Il 12/10/2012 13:15, Gerd Hoffmann ha scritto:
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
In principle you're right, but I think it's ugly that adding another chardev argument needs changes in 3 places instead of just one.
Hmm, I don't have to use the generated marshaller, right? With direct access to the QDict I could just transform it into a QemuOpts.
That's exactly what I was suggesting. :P
Ah, ok. I actually looked at netdev_add but obviously not close enougth. On a quick glance it looked to me like @params is a single string, not a varargs-style construct. Guess we are on the same page then.
cheers,
Gerd
PATCH v2 1/1 chardev: add hotplug support.
This patch adds chardev_add and chardev_del monitor commands.
chardev_del is pretty straight forward, it just takes an id argument and zaps the chardev specified.
chardev_add is more tricky as there are tons of arguments for the different backends. The hmp version limited to the most common use cases, especially when it comes to sockets: You can only specify port (tcp) or path (unix) and qemu will create a listening socket. For example this ...
(qemu) chardev_add foo socket 42
... will do the same as ...
-chardev socket,id=foo,port=42,server,nowait
on the qemu command line.
The qmp version has full support for everything the -chardev command line switch can handle. The implementation is pretty straight
forward: It just puts all arguments it got into a QemuOpts, then goes call qemu_chr_new_from_opts().
--- hmp-commands.hx | 32 ++++++++++++++++++++++++++++ hmp.c | 31 +++++++++++++++++++++++++++ hmp.h | 2 + qapi-schema.json | 39 ++++++++++++++++++++++++++++++++++ qemu-char.c | 50 +++++++++++++++++++++++++++++++++++++++++++- qemu-char.h | 2 + qmp-commands.hx | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 216 insertions(+), 1 deletions(-)
hmp-commands.hx +32 -0
@@ -1404,6 +1404,38 @@ passed since 1970, i.e. unix epoch. ETEXI { + .name = "chardev_add", + .args_type = "args:s", + .params = "args", + .help = "add chardev", + .mhandler.cmd = hmp_chardev_add, + }, + +STEXI +@item chardev_add args +@findex chardev_add + +chardev_add accepts the same parameters as the -chardev command line switch. + +ETEXI + + { + .name = "chardev_del", + .args_type = "id:s", + .params = "id", + .help = "del chardev", + .mhandler.cmd = hmp_chardev_del, + }, + +STEXI +@item chardev_del id +@findex chardev_del + +Removes the chardev @var{id}. + +ETEXI + + { .name = "info", .args_type = "item:s?", .params = "[subcommand]",
hmp.c +31 -0
@@ -1209,3 +1209,34 @@ void hmp_screen_dump(Monitor *mon, const QDict *qdict)qmp_screendump (filename, &err);hmp_handle_error (mon, &err); } + +void hmp_chardev_add (Monitor *mon,const QDict *qdict) +{ +const char *args =qdict_get_str (qdict,"args" ); +CharDriverState *chr; +Error *err =NULL ; +QemuOpts *opts; + + opts =qemu_opts_parse (qemu_find_opts ("chardev" ), args,1 ); +if (opts ==NULL ) { +error_setg (&err,"Parsing chardev args failed\n" ); + goto out; + } + + chr =qemu_chr_new_from_opts (opts,NULL ); +if (chr ==NULL ) { +qemu_opts_del (opts); +error_setg (&err,"Creating chardev failed\n" ); + } + +out: +hmp_handle_error (mon, &err); +} + +void hmp_chardev_del (Monitor *mon,const QDict *qdict) +{ +Error *err =NULL ; +qmp_chardev_del (qdict_get_str (qdict,"id" ), + &err); +hmp_handle_error (mon, &err); +}
hmp.h +2 -0
@@ -75,5 +75,7 @@ void hmp_getfd(Monitor *mon, const QDict *qdict);void hmp_closefd (Monitor *mon,const QDict *qdict);void hmp_send_key (Monitor *mon,const QDict *qdict);void hmp_screen_dump (Monitor *mon,const QDict *qdict); +void hmp_chardev_add (Monitor *mon,const QDict *qdict); +void hmp_chardev_del (Monitor *mon,const QDict *qdict);#endif
qapi-schema.json +39 -0
@@ -2796,3 +2796,42 @@ # Since: 0.14.0 ## { 'command': 'screendump', 'data': {'filename': 'str'} } + +## +# @chardev_add: +# +# Add a chardev +# +# @id: the chardev's ID, must be unique +# @backend: the chardev backend: "file", "socket", ... +# @path: file / device / unix socket path +# @name: spice channel name +# @host: host name +# @port: port number +# @server: create socket in server mode +# @wait: wait for connect +# @ipv4: force ipv4-only +# @ipv6: force ipv6-only +# @telnet: telnet negotiation +# +# Returns: Nothing on success +# +# Since: 1.3.0 +## +{ 'command': 'chardev_add', 'data': {'id' : 'str', + 'backend' : 'str', + '*props' : '**' }, + 'gen': 'no' } + +## +# @chardev_del: +# +# Remove a chardev +# +# @id: the chardev's ID, must exist and not be in use +# +# Returns: Nothing on success +# +# Since: 1.3.0 +## +{ 'command': 'chardev_del', 'data': {'id': 'str'} }
qemu-char.c +49 -1
71 lines not on this page · raw message
qemu-char.h +2 -0
@@ -74,6 +74,7 @@ struct CharDriverState {char *filename;int opened;int avail_connections; +QemuOpts *opts;QTAILQ_ENTRY (CharDriverState) next; };
@@ -236,6 +237,7 @@ void qemu_chr_info(Monitor *mon, QObject **ret_data);CharDriverState *qemu_chr_find (const char *name);QemuOpts *qemu_chr_parse_compat (const char *label,const char *filename); +int qmp_chardev_add (Monitor *mon,const QDict *qdict,QObject **ret);/* add an eventfd to the qemu devices that are polled */ CharDriverState *qemu_chr_open_eventfd (int eventfd);
qmp-commands.hx +61 -0
64 lines not on this page · raw message
Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH v2] chardev: add hotplug support.
Quoted 6 lines · Gerd Hoffmann
This patch adds
chardev_addandchardev_delmonitor commands.
chardev_delis pretty straight forward, it just takes an id argument and zaps the chardev specified.
chardev_addis more tricky as there are tons of arguments for the
Oops. Ignore the commit message for now, it obviously needs to be updated to reflect the changes, will fix for v3, awaiting code reviews meanwhile.
cheers,
Gerd
Re: [Qemu-devel] [PATCH v2] chardev: add hotplug support.
In reply to Gerd HoffmannIl 12/10/2012 14:39, Gerd Hoffmann ha scritto:
qemu-char.c CharDriverState *qemu_char_get_next_serial(void) · line 2928
Quoted 8 lines
qemu-char.c +8
-0+ chr =qemu_chr_new_from_opts (opts,NULL ); +if (chr ==NULL ) { +qemu_opts_del (opts); +error_setg (&err,"Creating chardev failed\n" ); + goto exit_err; + } +return 0 ; +
Since you have to do a v3, please make this part (which is common between HMP and QMP) a separate function.
Paolo
Re: [Qemu-devel] [PATCH v2] chardev: add hotplug support.
Il 12/10/2012 18:54, Paolo Bonzini ha scritto:
Quoted 10 lines
Il 12/10/2012 14:39, Gerd Hoffmann ha scritto:
qemu-char.c CharDriverState *qemu_char_get_next_serial(void) · line 2928
Quoted 8 lines
qemu-char.c +8
-0+ chr =qemu_chr_new_from_opts (opts,NULL ); +if (chr ==NULL ) { +qemu_opts_del (opts); +error_setg (&err,"Creating chardev failed\n" ); + goto exit_err; + } +return 0 ; +
Quoted 2 lines
Since you have to do a v3, please make this part (which is common between HMP and QMP) a separate function.
Also please make qemu_chr_new_from_opts use an Error ** at least for the error that are reported from that function itself (no need to add propagation to all of qemu-char.c, and it would conflict badly with the series that does so for qemu-sockets.c).
Paolo
Re: [Qemu-devel] [PATCH v2] chardev: add hotplug support.
In reply to Gerd HoffmannQuoted 236 lines · Gerd Hoffmann
This patch adds
chardev_addandchardev_delmonitor commands.
chardev_delis pretty straight forward, it just takes an id argument and zaps the chardev specified.
chardev_addis more tricky as there are tons of arguments for the different backends. The hmp version limited to the most common use cases, especially when it comes to sockets: You can only specify port (tcp) or path (unix) and qemu will create a listening socket. For example this ...(qemu)
chardev_addfoo socket 42... will do the same as ...
-chardev socket,id=foo,port=42,server,nowait
on the qemu command line.
The qmp version has full support for everything the -chardev command line switch can handle. The implementation is pretty straight
forward: It just puts all arguments it got into a QemuOpts, then goes callqemu_chr_new_from_opts().Signed-off-by Gerd Hoffmann <[email protected]>--- hmp-commands.hx | 32 ++++++++++++++++++++++++++++ hmp.c | 31 +++++++++++++++++++++++++++ hmp.h | 2 + qapi-schema.json | 39 ++++++++++++++++++++++++++++++++++ qemu-char.c | 50 +++++++++++++++++++++++++++++++++++++++++++- qemu-char.h | 2 + qmp-commands.hx | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 216 insertions(+), 1 deletions(-)hmp-commands.hx +32
-0@@ -1404,6 +1404,38 @@ passed since 1970, i.e. unix epoch. ETEXI { + .name = "chardev_add", + .args_type = "args:s", + .params = "args", + .help = "add chardev", + .mhandler.cmd = hmp_chardev_add, + }, + +STEXI +@item chardev_add args +@findex chardev_add + +chardev_add accepts the same parameters as the -chardev command line switch. + +ETEXI + + { + .name = "chardev_del", + .args_type = "id:s", + .params = "id", + .help = "del chardev", + .mhandler.cmd = hmp_chardev_del, + }, + +STEXI +@item chardev_del id +@findex chardev_del + +Removes the chardev @var{id}. + +ETEXI + + { .name = "info", .args_type = "item:s?", .params = "[subcommand]",hmp.c +31
-0@@ -1209,3 +1209,34 @@ void hmp_screen_dump(Monitor *mon, const QDict *qdict)qmp_screendump (filename, &err);hmp_handle_error (mon, &err); } + +void hmp_chardev_add (Monitor *mon,const QDict *qdict) +{ +const char *args =qdict_get_str (qdict,"args" ); +CharDriverState *chr; +Error *err =NULL ; +QemuOpts *opts; + + opts =qemu_opts_parse (qemu_find_opts ("chardev" ), args,1 ); +if (opts ==NULL ) { +error_setg (&err,"Parsing chardev args failed\n" ); + goto out; + } + + chr =qemu_chr_new_from_opts (opts,NULL ); +if (chr ==NULL ) { +qemu_opts_del (opts); +error_setg (&err,"Creating chardev failed\n" ); + } + +out: +hmp_handle_error (mon, &err); +} + +void hmp_chardev_del (Monitor *mon,const QDict *qdict) +{ +Error *err =NULL ; +qmp_chardev_del (qdict_get_str (qdict,"id" ), + &err); +hmp_handle_error (mon, &err); +}hmp.h +2
-0@@ -75,5 +75,7 @@ void hmp_getfd(Monitor *mon, const QDict *qdict);void hmp_closefd (Monitor *mon,const QDict *qdict);void hmp_send_key (Monitor *mon,const QDict *qdict);void hmp_screen_dump (Monitor *mon,const QDict *qdict); +void hmp_chardev_add (Monitor *mon,const QDict *qdict); +void hmp_chardev_del (Monitor *mon,const QDict *qdict);#endif qapi-schema.json +39
-0@@ -2796,3 +2796,42 @@ # Since: 0.14.0 ## { 'command': 'screendump', 'data': {'filename': 'str'} } + +## +# @chardev_add: +# +# Add a chardev +# +# @id: the chardev's ID, must be unique +# @backend: the chardev backend: "file", "socket", ... +# @path: file / device / unix socket path +# @name: spice channel name +# @host: host name +# @port: port number +# @server: create socket in server mode +# @wait: wait for connect +# @ipv4: force ipv4-only +# @ipv6: force ipv6-only +# @telnet: telnet negotiation +# +# Returns: Nothing on success +# +# Since: 1.3.0 +## +{ 'command': 'chardev_add', 'data': {'id' : 'str', + 'backend' : 'str', + '*props' : '**' }, + 'gen': 'no' } + +## +# @chardev_del: +# +# Remove a chardev +# +# @id: the chardev's ID, must exist and not be in use +# +# Returns: Nothing on success +# +# Since: 1.3.0 +## +{ 'command': 'chardev_del', 'data': {'id': 'str'} }qemu-char.c +30
-1@@ -2805,6 +2805,7 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts, chr->avail_connections =1 ; } chr->label =g_strdup (qemu_opts_id (opts)); + chr->opts = opts;return chr; }@@ -2826,7 +2827,6 @@ CharDriverState *qemu_chr_new(const char *label, const char *filename, void (*inif (chr &&qemu_opt_get_bool (opts,"mux" ,0 )) {monitor_init (chr,MONITOR_USE_READLINE ); } -qemu_opts_del (opts);return chr; }@@ -2856,6 +2856,7 @@ void qemu_chr_delete(CharDriverState *chr)QTAILQ_REMOVE (&chardevs, chr, next);if (chr->chr_close) chr->chr_close (chr); +qemu_opts_del (chr->opts);g_free (chr->filename);g_free (chr->label);g_free (chr);@@ -2900,3 +2901,50 @@ CharDriverState *qemu_char_get_next_serial(void)return serial_hds[next_serial++]; } +int qmp_chardev_add (Monitor *mon,const QDict *qdict,QObject **ret) +{ +CharDriverState *chr; +Error *err =NULL ; +QemuOptsList *opts_list; +QemuOpts *opts; + + opts_list =qemu_find_opts_err ("chardev" , &err); +if (error_is_set (&err)) { + goto exit_err; + } + + opts =qemu_opts_from_qdict (opts_list, qdict, &err); +if (error_is_set (&err)) { + goto exit_err; + } + + chr =qemu_chr_new_from_opts (opts,NULL ); +if (chr ==NULL ) { +qemu_opts_del (opts); +error_setg (&err,"Creating chardev failed\n" ); + goto exit_err; + } +return 0 ; + +exit_err: +qerror_report_err (err); +error_free (err);
qemu-char.c CharDriverState *qemu_char_get_next_serial(void) · line 2941
Quoted 10 lines
qemu-char.c +10
-0+return -1 ; +} + +void qmp_chardev_del (const char *id,Error **errp) +{ +CharDriverState *chr; + + chr =qemu_chr_find (id); +if (NULL == chr) { +error_setg (errp,"Chardev '%s' not found\n" , id);
Maybe this should be replaced by QERR_ macros to keep compatibility since this one is listed in ErrorClass in the schema, like:
error_set(errp, QERR_DEVICE_NOT_FOUND, id);
Quoted 54 lines
qemu-char.c +9
-0+return ; + } +if (chr->chr_can_read || chr->chr_read || + chr->chr_event || chr->handler_opaque) { +error_setg (errp,"Chardev '%s' is busy\n" , id); +return ; + } +qemu_chr_delete (chr); +}qemu-char.h +2
-0@@ -74,6 +74,7 @@ struct CharDriverState {char *filename;int opened;int avail_connections; +QemuOpts *opts;QTAILQ_ENTRY (CharDriverState) next; };@@ -236,6 +237,7 @@ void qemu_chr_info(Monitor *mon, QObject **ret_data);CharDriverState *qemu_chr_find (const char *name);QemuOpts *qemu_chr_parse_compat (const char *label,const char *filename); +int qmp_chardev_add (Monitor *mon,const QDict *qdict,QObject **ret);/* add an eventfd to the qemu devices that are polled */ CharDriverState *qemu_chr_open_eventfd (int eventfd);qmp-commands.hx +17
-0@@ -2576,3 +2576,64 @@ EQMP .args_type = "", .mhandler.cmd_new = qmp_marshal_input_query_target, }, + + { + .name = "chardev_add", + .args_type = "", + .mhandler.cmd_new = qmp_chardev_add, + }, + +SQMP +chardev_add +----------- + +Add a chardev. + +Arguments: + +- "id": the chardev's ID, must be unique (json-string) +- "backend": the chardev backend: "file", "socket", ... (json-string)
qmp-commands.hx EQMP · line 2605
Quoted 10 lines
qmp-commands.hx +10
-0+- "path": file / device / unix socket path (json-string, optional) +- "name": spice channel name (json-string, optional) +- "host": host name (json-string, optional) +- "port": port number (json-string, optional) +- "server": create socket in server mode (json-bool, optional) +- "wait": wait for connect (json-bool, optional) +- "ipv4": force ipv4-only (json-bool, optional) +- "ipv6": force ipv6-only (json-bool, optional) +- "telnet": telnet negotiation (json-bool, optional) +
Should it support the option "mux" to enable multiplexing mode?
Quoted 34 lines
qmp-commands.hx +34
-0+Example: + +-> { "execute": "chardev_add", "arguments": { "id" : "foo", + "backend" : "socket", + "path" : "/tmp/foo", + "server" : "on", + "wait" : "off" } } +<- { "return": {} } + +EQMP + + { + .name = "chardev_del", + .args_type = "", + .mhandler.cmd_new = qmp_marshal_input_chardev_del, + }, + + +SQMP +chardev_del +----------- + +Remove a chardev. + +Arguments: + +- "id": the chardev's ID, must exist and not be in use (json-string) + +Example: + +-> { "execute": "chardev_del", "arguments": { "id" : "foo" } } +<- { "return": {} } + +EQMP
Signature · 1 line
Lei
Re: [Qemu-devel] [PATCH v2] chardev: add hotplug support.
Am 15.10.2012 08:51, schrieb Lei Li:
Quoted 13 lines · Gerd Hoffmann
qemu-char.c CharDriverState *qemu_char_get_next_serial(void) · line 2941
Quoted 7 lines
qemu-char.c +7
-0+void qmp_chardev_del (const char *id,Error **errp) +{ +CharDriverState *chr; + + chr =qemu_chr_find (id); +if (NULL == chr) { +error_setg (errp,"Chardev '%s' not found\n" , id);Maybe this should be replaced by
QERR_macros to keep compatibility since this one is listed in ErrorClass in the schema, like:
Quoted 1 line
error_set(errp, QERR_DEVICE_NOT_FOUND, id);
No, error_setg() is the new replacement, QERR_* is deprecated.
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Re: [Qemu-devel] [PATCH v2] chardev: add hotplug support.
Quoted 14 lines · On Mon, 15 Oct 2012 13:09:55 +0200 Andreas Färber <[email protected]> wrote:
Am 15.10.2012 08:51, schrieb Lei Li:
Quoted 13 lines · Gerd Hoffmann
qemu-char.c CharDriverState *qemu_char_get_next_serial(void) · line 2941
Quoted 7 lines
qemu-char.c +7
-0+void qmp_chardev_del (const char *id,Error **errp) +{ +CharDriverState *chr; + + chr =qemu_chr_find (id); +if (NULL == chr) { +error_setg (errp,"Chardev '%s' not found\n" , id);Maybe this should be replaced by
QERR_macros to keep compatibility since this one is listed in ErrorClass in the schema, like:
Quoted 3 lines
Quoted 1 line
error_set(errp, QERR_DEVICE_NOT_FOUND, id);No,
error_setg()is the new replacement, QERR_* is deprecated.
This is a case where the error appears in the ErrorClass enum, in this case we're supposed to use the QERR_ macro for compatibility in the wire.
On the other hand, this is a new command so I'm not completely sure this matters (in doubt we should do it though).
Re: [Qemu-devel] [PATCH v2] chardev: add hotplug support.
In reply to Lei LiQuoted 27 lines · Lei Li
Quoted 25 lines · Gerd Hoffmann
This patch adds
chardev_addandchardev_delmonitor commands.
chardev_delis pretty straight forward, it just takes an id argument and zaps the chardev specified.
chardev_addis more tricky as there are tons of arguments for the different backends. The hmp version limited to the most common use cases, especially when it comes to sockets: You can only specify port (tcp) or path (unix) and qemu will create a listening socket. For example this ...(qemu)
chardev_addfoo socket 42... will do the same as ...
-chardev socket,id=foo,port=42,server,nowait
on the qemu command line.
The qmp version has full support for everything the -chardev command line switch can handle. The implementation is pretty straight
forward: It just puts all arguments it got into a QemuOpts, then goes callqemu_chr_new_from_opts().Signed-off-by Gerd Hoffmann <[email protected]>
Quoted 8 lines
qapi-schema.json line 2801
Quoted 8 lines
+++
b/qapi-schema.jsonqapi-schema.json +3
-0@@ -2796,3 +2796,42 @@ # Since: 0.14.0 ## { 'command': 'screendump', 'data': {'filename': 'str'} } + +## +# @chardev_add:
The QMP command should be named 'chardev-add'.
Quoted 5 lines
qapi-schema.json line 2806
Quoted 5 lines
qapi-schema.json +5
-0+# +# Add a chardev +# +# @id: the chardev's ID, must be unique +# @backend: the chardev backend: "file", "socket", ...
Rather than making this an open-coded string, should it instead be a QMP enum value?
Quoted 2 lines
Review line 2808
Quoted 2 lines
(quoted diff) +2
-0+## +# @chardev_del:
And this should be 'chardev-del' or even 'chardev-remove', as QMP commands tend to favor legibility over abbreviations.
Signature · 2 lines
Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v2] chardev: add hotplug support.
Il 15/10/2012 19:36, Eric Blake ha scritto:
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+## +# @chardev_del:And this should be 'chardev-del' or even 'chardev-remove', as QMP commands tend to favor legibility over abbreviations.
In doubt we should favor consistency though (with netdev_add and netdev_del). I'm for keeping this as Gerd did, and perhaps implement automatic _ <-> - conversion for QMP.
Paolo
Il 12/10/2012 11:25, Gerd Hoffmann ha scritto:
Quoted 7 lines
Final patch adds chardev hotplug to the mix, which makes the other patches alot more useful. It is the missing bit needed to really hotplug serial devices:
(qemu)
chardev_addpciserial file/root/hotchardev.log(qemu)device_addpci-serial,chardev=pciserial,id=pciserial
Quoted 6 lines
And the reverse:
(qemu)
device_delpciserial
(qemu)chardev_delpciserialplease review & pull,
I think the last patch is not ready, please wait for Luiz's review too.
Quoted 17 lines
Gerd
The following changes since commit
b4ae3cfa57b8c1bdbbd7b7d420971e9171203ade:ssi: Add slave autoconnect helper (2012-10-10 11:13:32 +1000)
are available in the git repository at:
git://git.kraxel.org/qemuserial.1Gerd Hoffmann (7):
serial: splitserial.c
serial: add pci variant
serial: add windows inf file for the pci card to docs
serial: add 2x + 4x pci variant
usb-serial: don't magically zap chardev on umplug
usb-serial: only expose device in guest when the chardev is open
chardev: add hotplug support.