qdev: disassociate chardev from device on device exit
v2 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.
v2:
- actually remove virtconsole_exitfn()
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 | 17 ----------------- 2 files changed, 11 insertions(+), 17 deletions(-)
Signature · 1 line
1.7.7.5
PATCH v2 1/2 qdev: Add a 'free' method to disassociate chardev from qdev device
When 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
PATCH v2 2/2 virtio-console: no need to remove char handlers explicitly
In reply to Amit Shahqdev 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 | 17 ----------------- 1 files changed, 0 insertions(+), 17 deletions(-)
hw/virtio-console.c +0 -17
@@ -125,27 +125,11 @@ static int virtconsole_initfn(VirtIOSerialPort *port)return 0 ; } -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 ; -} -static VirtIOSerialPortInfo virtconsole_info = { .qdev.name ="virtconsole" , .qdev.size =sizeof (VirtConsole), .is_console = true, .init = virtconsole_initfn, - .exit = virtconsole_exitfn, .have_data = flush_buf, .guest_open = guest_open, .guest_close = guest_close,
@@ -165,7 +149,6 @@ static VirtIOSerialPortInfo virtserialport_info = { .qdev.name = "virtserialport", .qdev.size = sizeof(VirtConsole), .init = virtconsole_initfn, - .exit = virtconsole_exitfn, .have_data = flush_buf, .guest_open = guest_open, .guest_close = guest_close,
Signature · 1 line
1.7.7.5
Anthony Liguori
AppliedQuoted 5 lines · Amit Shah
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.
Applied. Thanks.
Regards,
Anthony Liguori
Quoted 12 lines
v2:
- actually removevirtconsole_exitfn()Amit Shah (2):
qdev: Add a 'free' method to disassociate chardev from qdev device
virtio-console: no need to remove char handlers explicitlyhw/qdev-properties.c | 11 +++++++++++ hw/virtio-console.c | 17 ----------------- 2 files changed, 11 insertions(+), 17 deletions(-)