hw/usb: Introduce x-query-usbhost QMP command
v2 cover hw/usb: Introduce x-query-usbhost QMP command
Since v1:
- Consider modules (Daniel)
- Remove monitor_register_hmp
Philippe Mathieu-Daudé (3):
hw/usb: Remove unused 'host.h' header
hw/usb: Introduce x-query-usbhost QMP command
monitor: Remove monitor_register_hmp()
qapi/machine.json | 18 +++++++++++++++ hw/usb/host-libusb.h | 16 ++++++++++++++ hw/usb/host.h | 44 ------------------------------------- include/hw/usb.h | 3 --- include/monitor/monitor.h | 2 -- hw/usb/bus-stub.c | 7 +++++- hw/usb/host-libusb-common.c | 31 ++++++++++++++++++++++++++ hw/usb/host-libusb.c | 43 ++++++++++++++++++++++++------------ monitor/hmp-target.c | 16 -------------- tests/qtest/qmp-cmd-test.c | 3 +++ hmp-commands-info.hx | 2 ++ hw/usb/meson.build | 1 + 12 files changed, 106 insertions(+), 80 deletions(-) create mode 100644 hw/usb/host-libusb.h delete mode 100644 hw/usb/host.h create mode 100644 hw/usb/host-libusb-common.c
Signature · 1 line
2.41.0
PATCH v2 1/3 hw/usb: Remove unused 'host.h' header
Since commit 99761176ee ("usb: Remove legacy -usbdevice options (host, serial, disk and net)") hw/usb/host.h is not used, remove it.
---
Cc: Thomas Huth <[email protected]>
--- hw/usb/host.h | 44 -------------------------------------------- 1 file changed, 44 deletions(-) delete mode 100644 hw/usb/host.h
hw/usb/host.h deleted +0 -44
@@ -1,44 +0,0 @@ -/* -* Linux host USB redirector -* -* Copyright (c) 2005 Fabrice Bellard -* -* Copyright (c) 2008 Max Krasnyansky -* Support for host device auto connect & disconnect -* Major rewrite to support fully async operation -* -* Copyright 2008 TJ <[email protected]> -* Added flexible support for /dev/bus/usb /sys/bus/usb/devices in addition -* to the legacy /proc/bus/usb USB device discovery and handling -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -*/ - -#ifndef QEMU_USB_HOST_H -#define QEMU_USB_HOST_H - -struct USBAutoFilter { -uint32_t bus_num; -uint32_t addr; -char *port; -uint32_t vendor_id; -uint32_t product_id; -}; - -#endif /* QEMU_USB_HOST_H */
Signature · 1 line
2.41.0
Re: [PATCH v2 1/3] hw/usb: Remove unused 'host.h' header
Quoted 11 lines · Philippe Mathieu-Daudé
Since commit
99761176ee("usb: Remove legacy -usbdevice options (host, serial, disk and net)")hw/usb/host.his not used, remove it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
Cc: Thomas Huth <[email protected]>--- hw/usb/host.h | 44 -------------------------------------------- 1 file changed, 44 deletions(-) delete mode 100644 hw/usb/host.h
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH v2 2/3 hw/usb: Introduce x-query-usbhost QMP command
In reply to Philippe Mathieu-DaudéThis is a counterpart to the HMP "info usbhost" command. It is being added with an "x-" prefix because this QMP command is intended as an adhoc debugging tool and will thus not be modelled in QAPI as fully structured data, nor will it have long term guaranteed stability. The existing HMP command is rewritten to call the QMP command.
Since host-libusb.c can be built as part of the 'hw-usb' module, we introduce the libusb_register_hmp_info_hrt() helper to allow late registration when the module is loaded.
--- qapi/machine.json | 18 ++++++++++++++++ hw/usb/host-libusb.h | 16 ++++++++++++++ include/hw/usb.h | 3 --- hw/usb/bus-stub.c | 7 +++++- hw/usb/host-libusb-common.c | 31 ++++++++++++++++++++++++++ hw/usb/host-libusb.c | 43 +++++++++++++++++++++++++------------ tests/qtest/qmp-cmd-test.c | 3 +++ hmp-commands-info.hx | 2 ++ hw/usb/meson.build | 1 + 9 files changed, 106 insertions(+), 18 deletions(-) create mode 100644 hw/usb/host-libusb.h create mode 100644 hw/usb/host-libusb-common.c
qapi/machine.json +18 -0
@@ -1813,6 +1813,24 @@ 'returns': 'HumanReadableText', 'features': [ 'unstable' ] } +## +# @x-query-usbhost: +# +# Query information on host USB devices +# +# Features: +# +# @unstable: This command is meant for debugging. +# +# Returns: Host USB device information +# +# Since: 9.1 +## +{ 'command': 'x-query-usbhost', + 'returns': 'HumanReadableText', + 'features': [ 'unstable' ], + 'if': 'CONFIG_USB_LIBUSB' } + ## # @SmbiosEntryPointType: #
hw/usb/host-libusb.h new file +16 -0
@@ -0,0 +1,16 @@ +/* +* QEMU USB host redirector +* +* SPDX-FileContributor: Philippe Mathieu-Daudé <[email protected]> +* SPDX-FileCopyrightText: 2024 Linaro Ltd. +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef HW_USB_HOST_LIBUSB_H +#define HW_USB_HOST_LIBUSB_H + +#include "qapi/qapi-types-common.h" + +void libusb_register_hmp_info_hrt (HumanReadableText *(*handler)(Error **errp)); + +#endif
include/hw/usb.h +0 -3
@@ -465,9 +465,6 @@ void usb_device_reset(USBDevice *dev);void usb_wakeup (USBEndpoint *ep,unsigned int stream);void usb_generic_async_ctrl_complete (USBDevice *s,USBPacket *p); -/* usb-linux.c */ -void hmp_info_usbhost (Monitor *mon,const QDict *qdict); -/* usb ports of the VM */ #define VM_USB_HUB_SIZE 8
hw/usb/bus-stub.c +6 -1
@@ -11,7 +11,6 @@#include "qapi/error.h" #include "qapi/qapi-commands-machine.h" #include "sysemu/sysemu.h" -#include "monitor/monitor.h" #include "hw/usb.h" USBDevice *usbdevice_create (const char *driver)
@@ -26,3 +25,9 @@ HumanReadableText *qmp_x_query_usb(Error **errp)error_setg (errp,"Support for USB devices not built-in" );return NULL ; } + +HumanReadableText *qmp_x_query_usbhost (Error **errp) +{ +error_setg (errp,"Support for USB devices not built-in" ); +return NULL ; +}
hw/usb/host-libusb-common.c new file +31 -0
@@ -0,0 +1,31 @@ +/* +* QEMU USB host redirector helpers +* +* SPDX-FileContributor: Philippe Mathieu-Daudé <[email protected]> +* SPDX-FileCopyrightText: 2024 Linaro Ltd. +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "qemu/module.h" +#include "qapi/error.h" +#include "qapi/qapi-commands-machine.h" +#include "monitor/monitor.h" +#include "host-libusb.h" + +static HumanReadableText *(*qmp_x_query_usbhost_handler)(Error **errp); + +void libusb_register_hmp_info_hrt (HumanReadableText *(*handler)(Error **errp)) +{ + qmp_x_query_usbhost_handler = handler; +monitor_register_hmp_info_hrt ("usbhost" , handler); +} + +HumanReadableText *qmp_x_query_usbhost (Error **errp) +{ +if (module_load ("hw-usb-" ,"host" , errp) <=0 ) { +return NULL ; + } +assert (qmp_x_query_usbhost_handler); +return qmp_x_query_usbhost_handler (errp); +}
hw/usb/host-libusb.c +29 -14
98 lines not on this page · raw message
tests/qtest/qmp-cmd-test.c +3 -0
@@ -49,6 +49,9 @@ static int query_error_class(const char *cmd) { "query-vm-generation-id", ERROR_CLASS_GENERIC_ERROR },/* Only valid with a USB bus added */ { "x-query-usb", ERROR_CLASS_GENERIC_ERROR }, +#ifdef CONFIG_USB_LIBUSB + { "x-query-usbhost", ERROR_CLASS_GENERIC_ERROR }, +#endif /* Only valid with accel=tcg */ { "x-query-jit", ERROR_CLASS_GENERIC_ERROR }, { "x-query-opcount", ERROR_CLASS_GENERIC_ERROR },
hmp-commands-info.hx +2 -0
@@ -335,12 +335,14 @@ SRST Show guest USB devices. ERST +#ifdef CONFIG_USB_LIBUSB { .name = "usbhost", .args_type = "", .params = "", .help = "show host USB devices", }, +#endif SRST ``info usbhost``
hw/usb/meson.build +1 -0
@@ -7,6 +7,7 @@ system_ss.add(when: 'CONFIG_USB', if_true: files( 'core.c', 'desc.c', 'desc-msos.c', + 'host-libusb-common.c', 'libhw.c', 'pcap.c', ), if_false: files('bus-stub.c'))
Signature · 1 line
2.41.0
Quoted 12 lines · Philippe Mathieu-Daudé
This is a counterpart to the HMP "info usbhost" command. It is being added with an "x-" prefix because this QMP command is intended as an adhoc debugging tool and will thus not be modelled in QAPI as fully structured data, nor will it have long term guaranteed stability. The existing HMP command is rewritten to call the QMP command.
Since
host-libusb.ccan be built as part of the 'hw-usb' module, we introduce thelibusb_register_hmp_info_hrt()helper to allow late registration when the module is loaded.Suggested-by Daniel P. Berrangé <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 13 lines
--- qapi/machine.json | 18 ++++++++++++++++ hw/usb/host-libusb.h | 16 ++++++++++++++ include/hw/usb.h | 3 --- hw/usb/bus-stub.c | 7 +++++- hw/usb/host-libusb-common.c | 31 ++++++++++++++++++++++++++ hw/usb/host-libusb.c | 43 +++++++++++++++++++++++++------------ tests/qtest/qmp-cmd-test.c | 3 +++ hmp-commands-info.hx | 2 ++ hw/usb/meson.build | 1 + 9 files changed, 106 insertions(+), 18 deletions(-) create mode 100644 hw/usb/host-libusb.h create mode 100644 hw/usb/host-libusb-common.c
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 108 lines · Philippe Mathieu-Daudé
This is a counterpart to the HMP "info usbhost" command. It is being added with an "x-" prefix because this QMP command is intended as an adhoc debugging tool and will thus not be modelled in QAPI as fully structured data, nor will it have long term guaranteed stability. The existing HMP command is rewritten to call the QMP command.
Since
host-libusb.ccan be built as part of the 'hw-usb' module, we introduce thelibusb_register_hmp_info_hrt()helper to allow late registration when the module is loaded.Suggested-by Daniel P. Berrangé <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- qapi/machine.json | 18 ++++++++++++++++ hw/usb/host-libusb.h | 16 ++++++++++++++ include/hw/usb.h | 3 --- hw/usb/bus-stub.c | 7 +++++- hw/usb/host-libusb-common.c | 31 ++++++++++++++++++++++++++ hw/usb/host-libusb.c | 43 +++++++++++++++++++++++++------------ tests/qtest/qmp-cmd-test.c | 3 +++ hmp-commands-info.hx | 2 ++ hw/usb/meson.build | 1 + 9 files changed, 106 insertions(+), 18 deletions(-)create mode 100644
hw/usb/host-libusb.h
create mode 100644hw/usb/host-libusb-common.cinclude/hw/usb.h +0
-3@@ -465,9 +465,6 @@ void usb_device_reset(USBDevice *dev);void usb_wakeup (USBEndpoint *ep,unsigned int stream);void usb_generic_async_ctrl_complete (USBDevice *s,USBPacket *p); -/* usb-linux.c */ -void hmp_info_usbhost (Monitor *mon,const QDict *qdict); -/* usb ports of the VM */ #define VM_USB_HUB_SIZE 8hw/usb/bus-stub.c +6
-1@@ -11,7 +11,6 @@#include "qapi/error.h" #include "qapi/qapi-commands-machine.h" #include "sysemu/sysemu.h" -#include "monitor/monitor.h" #include "hw/usb.h" USBDevice *usbdevice_create (const char *driver)@@ -26,3 +25,9 @@ HumanReadableText *qmp_x_query_usb(Error **errp)error_setg (errp,"Support for USB devices not built-in" );return NULL ; } + +HumanReadableText *qmp_x_query_usbhost (Error **errp) +{ +error_setg (errp,"Support for USB devices not built-in" ); +return NULL ; +}hw/usb/host-libusb-common.c new file +31
-0@@ -0,0 +1,31 @@ +/* +* QEMU USB host redirector helpers +* +* SPDX-FileContributor: Philippe Mathieu-Daudé <[email protected]> +* SPDX-FileCopyrightText: 2024 Linaro Ltd. +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "qemu/module.h" +#include "qapi/error.h" +#include "qapi/qapi-commands-machine.h" +#include "monitor/monitor.h" +#include "host-libusb.h" + +static HumanReadableText *(*qmp_x_query_usbhost_handler)(Error **errp); + +void libusb_register_hmp_info_hrt (HumanReadableText *(*handler)(Error **errp)) +{ + qmp_x_query_usbhost_handler = handler; +monitor_register_hmp_info_hrt ("usbhost" , handler); +} + +HumanReadableText *qmp_x_query_usbhost (Error **errp) +{ +if (module_load ("hw-usb-" ,"host" , errp) <=0 ) { +return NULL ; + } +assert (qmp_x_query_usbhost_handler); +return qmp_x_query_usbhost_handler (errp); +}hw/usb/meson.build +0
-0
hw/usb/meson.build system_ss.add(when: 'CONFIG_USB', if_true: files( · line 13
Quoted 7 lines
hw/usb/meson.build +1
-0@@ -7,6 +7,7 @@ system_ss.add(when: 'CONFIG_USB', if_true: files( 'core.c', 'desc.c', 'desc-msos.c', + 'host-libusb-common.c', 'libhw.c', 'pcap.c', ), if_false: files('bus-stub.c'))
Since this files depends on libusb, squashing:
-- >8 --
hw/usb/meson.build +1 -1
@@ -9,3 +9,2 @@ system_ss.add(when: 'CONFIG_USB', if_true: files( 'desc-msos.c', - 'host-libusb-common.c', 'libhw.c',
@@ -86,2 +85,3 @@ endif if libusb.found() + system_ss.add(when: 'CONFIG_USB', if_true: files('host-libusb-common.c')) usbhost_ss = ss.source_set()
---
Quoted 28 lines · Philippe Mathieu-Daudé
Quoted 25 lines · Philippe Mathieu-Daudé
This is a counterpart to the HMP "info usbhost" command. It is being added with an "x-" prefix because this QMP command is intended as an adhoc debugging tool and will thus not be modelled in QAPI as fully structured data, nor will it have long term guaranteed stability. The existing HMP command is rewritten to call the QMP command.
Since
host-libusb.ccan be built as part of the 'hw-usb' module, we introduce thelibusb_register_hmp_info_hrt()helper to allow late registration when the module is loaded.Suggested-by Daniel P. Berrangé <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
qapi/machine.json | 18 ++++++++++++++++ hw/usb/host-libusb.h | 16 ++++++++++++++ include/hw/usb.h | 3 ---
hw/usb/bus-stub.c | 7 +++++-hw/usb/host-libusb-common.c| 31 ++++++++++++++++++++++++++ hw/usb/host-libusb.c | 43 +++++++++++++++++++++++++------------ tests/qtest/qmp-cmd-test.c | 3 +++
hmp-commands-info.hx | 2 ++
hw/usb/meson.build | 1 +9 files changed, 106 insertions(+), 18 deletions(-)create mode 100644
hw/usb/host-libusb.h
create mode 100644hw/usb/host-libusb-common.c
Quoted 15 lines
Quoted 12 lines
hw/usb/bus-stub.c +0
-1@@ -11,7 +11,6 @@ #include "qapi/error.h" #include "qapi/qapi-commands-machine.h" #include "sysemu/sysemu.h" -#include "monitor/monitor.h" #include "hw/usb.h" USBDevice *usbdevice_create(const char *driver)hw/usb/bus-stub.c HumanReadableText *qmp_x_query_usb(Error **errp) · line 27
Quoted 3 lines
hw/usb/bus-stub.c +0
-0@@ -26,3 +25,9 @@ HumanReadableText *qmp_x_query_usb(Error **errp) error_setg(errp, "Support for USB devices not built-in"); return NULL; }
Also missing:
#ifdef CONFIG_USB_LIBUSB
Quoted 5 lines
hw/usb/bus-stub.c HumanReadableText *qmp_x_query_usb(Error **errp) · line 32
Quoted 5 lines
hw/usb/bus-stub.c +5
-0+HumanReadableText *qmp_x_query_usbhost (Error **errp) +{ + error_setg(errp, "Support for USB devices not built-in"); + return NULL; +}
#endif
But still failing the build-without-defaults job:
▶ 59/61 /x86_64/qmp/x-query-usbhost - ERROR:../tests/qtest/qmp-cmd-test.c:88:test_query: assertion failed: (error) FAIL
So dropping patches 2 & 3 for now.
PATCH v2 3/3 monitor: Remove monitor_register_hmp()
In reply to Philippe Mathieu-DaudéPrevious commit removed the last use of monitor_register_hmp(), remove it so new commands are implemented using monitor_register_hmp_info_hrt().
--- include/monitor/monitor.h | 2 -- monitor/hmp-target.c | 16 ---------------- 2 files changed, 18 deletions(-)
include/monitor/monitor.h +0 -2
@@ -55,8 +55,6 @@ int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags);void monitor_fdset_dup_fd_remove (int dup_fd);int64_t monitor_fdset_dup_fd_find (int dup_fd); -void monitor_register_hmp (const char *name,bool info, -void (*cmd)(Monitor *mon,const QDict *qdict));void monitor_register_hmp_info_hrt (const char *name,HumanReadableText *(*handler)(Error **errp));
monitor/hmp-target.c +0 -16
@@ -145,22 +145,6 @@ static void __attribute__((__constructor__)) sortcmdlist(void) compare_mon_cmd); } -void monitor_register_hmp (const char *name,bool info, -void (*cmd)(Monitor *mon,const QDict *qdict)) -{ -HMPCommand *table = info ? hmp_info_cmds : hmp_cmds; - -while (table->name !=NULL ) { -if (strcmp (table->name, name) ==0 ) { -g_assert (table->cmd ==NULL && table->cmd_info_hrt ==NULL ); - table->cmd = cmd; -return ; - } - table++; - } -g_assert_not_reached (); -} -void monitor_register_hmp_info_hrt (const char *name,HumanReadableText *(*handler)(Error **errp)) {
Signature · 1 line
2.41.0
Re: [PATCH v2 3/3] monitor: Remove monitor_register_hmp()
Quoted 9 lines · Philippe Mathieu-Daudé
Previous commit removed the last use of
monitor_register_hmp(), remove it so new commands are implemented usingmonitor_register_hmp_info_hrt().Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/monitor/monitor.h | 2 -- monitor/hmp-target.c | 16 ---------------- 2 files changed, 18 deletions(-)
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 4 lines · Philippe Mathieu-Daudé
Philippe Mathieu-Daudé (3):
hw/usb: Remove unused 'host.h' header
hw/usb: Introduce x-query-usbhost QMP command
monitor: Removemonitor_register_hmp()
Series queued.