qdev: disassociate chardev from device on device exit
cover qdev: disassociate chardev from device on device exit
When the device is going away (e.g., hot-unplug), an associated chardev should be freed and made available for use for other devices.
An earlier hack did this for virtio serial ports, do it in a generic way and remove the virtio-serial specific hack.
Amit Shah (2):
qdev: Add a 'free' method to disassociate chardev from qdev device
virtio-console: no need to remove char handlers explicitly
hw/qdev-properties.c | 11 +++++++++++ hw/virtio-console.c | 10 ---------- 2 files changed, 11 insertions(+), 10 deletions(-)
Signature · 1 line
1.7.7.5
PATCH 2/2 virtio-console: no need to remove char handlers explicitly
qdev is now equipped (thanks to the last commit) to disassociate chardevs from the qdev devices on the devices going away. So doing it in the virtio-console driver is not necessary.
Since that was the only thing being done in the qdev exit method, drop it entirely.
--- hw/virtio-console.c | 10 ---------- 1 files changed, 0 insertions(+), 10 deletions(-)
hw/virtio-console.c +0 -10
@@ -127,16 +127,6 @@ static int virtconsole_initfn(VirtIOSerialPort *port)static int virtconsole_exitfn (VirtIOSerialPort *port) { -VirtConsole *vcon =DO_UPCAST (VirtConsole, port, port); - -if (vcon->chr) { -/* -* Instead of closing the chardev, free it so it can be used -* for other purposes. -*/ -qemu_chr_add_handlers (vcon->chr,NULL ,NULL ,NULL ,NULL ); - } -return 0 ; }
Signature · 1 line
1.7.7.5
PATCH 1/2 qdev: Add a 'free' method to disassociate chardev from qdev device
In reply to Amit ShahWhen a device is removed, remove the association with a chardev, if any, so that the chardev can be re-used later for other devices.
--- hw/qdev-properties.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)
hw/qdev-properties.c +11 -0
@@ -680,6 +680,16 @@ static int parse_chr(DeviceState *dev, Property *prop, const char *str)return 0 ; } +static void free_chr (DeviceState *dev,Property *prop) +{ +CharDriverState **ptr =qdev_get_prop_ptr (dev, prop); + +if (*ptr) { +qemu_chr_add_handlers (*ptr,NULL ,NULL ,NULL ,NULL ); + } +} + +static int print_chr (DeviceState *dev,Property *prop,char *dest,size_t len) {CharDriverState **ptr =qdev_get_prop_ptr (dev, prop);
@@ -699,6 +709,7 @@ PropertyInfo qdev_prop_chr = { .print = print_chr, .get = get_generic, .set = set_generic, + .free = free_chr, };/* --- netdev device --- */
Signature · 1 line
1.7.7.5
Re: [Qemu-devel] [PATCH 2/2] virtio-console: no need to remove char handlers explicitly
In reply to Amit ShahQuoted 6 lines · Amit Shah
qdev is now equipped (thanks to the last commit) to disassociate chardevs from the qdev devices on the devices going away. So doing it in the virtio-console driver is not necessary.
Since that was the only thing being done in the qdev exit method, drop it entirely.
Commit message is correct, patch is not. Updated patch coming soon..
Quoted 10 lines
hw/virtio-console.c +0
-2@@ -127,16 +127,6 @@ static int virtconsole_initfn(VirtIOSerialPort *port)static int virtconsole_exitfn (VirtIOSerialPort *port) { -VirtConsole *vcon =DO_UPCAST (VirtConsole, port, port); -
hw/virtio-console.c static int virtconsole_initfn(VirtIOSerialPort *port) · line 131
Quoted 10 lines
hw/virtio-console.c +0
-8-if (vcon->chr) { -/* -* Instead of closing the chardev, free it so it can be used -* for other purposes. -*/ -qemu_chr_add_handlers (vcon->chr,NULL ,NULL ,NULL ,NULL ); - } -return 0 ; }
Amit