chardev: qom-ify
cover chardev: qom-ify
qemu-char.c is quite a large file (~130k, 5000 loc) with many chardev and a lot of #ifdef. It doesn't use qemu Object. Using qemu Object hopefully brings cleaner, more consitent code base. It helps to split the various backends in different files. Eventually, we could also allow or switch to -object-add CLI option instead of -chardev.
This series is the first of a pretty large chardev refactoring series that I keep here:
https://github.com/elmarco/qemu/commits/chrfe
It is based on Gerd's pull-ui-20170104-1 tag. Furthermore, for "spice-char: improve error reporting" to not introduce a regression, "error: report hints on stderr when no monitor" is required (sent earlier in the ML).
Since WIP:
- took most of Eric review comments, they were mostly about style
Marc-André Lureau (20):
tests: fix linking test-char on win32
qemu-options: stdio is available on win32
char: add qemu_chr_fe_add_watch() Returns description
doc: fix spelling
char: use a const CharDriver
char: use a static array for backends
char: move callbacks in CharDriver
char: fold single-user functions in caller
char: introduce generic qemu_chr_get_kind()
char: use a feature bit for replay
char: allocate CharDriverState as a single object
bt: use qemu_chr_alloc()
char: rename CharDriverState Chardev
char: rename TCPChardev and NetChardev
spice-char: improve error reporting
char: use error_report()
gtk: overwrite the console.c char driver
baum: use a common prefix for chr callbacks
vc: use a common prefix for chr callbacks
chardev: qom-ify
hw/lm32/lm32.h | 4 +- hw/lm32/milkymist-hw.h | 2 +- include/hw/arm/exynos4210.h | 2 +- include/hw/arm/omap.h | 6 +- include/hw/bt.h | 4 +- include/hw/char/cadence_uart.h | 2 +- include/hw/char/escc.h | 2 +- include/hw/char/pl011.h | 4 +- include/hw/char/serial.h | 4 +- include/hw/char/xilinx_uartlite.h | 2 +- include/hw/cris/etraxfs.h | 2 +- include/hw/devices.h | 2 +- include/hw/i386/pc.h | 2 +- include/hw/m68k/mcf.h | 4 +- include/hw/ppc/spapr_vio.h | 2 +- include/hw/qdev-properties.h | 2 +- include/hw/sh4/sh.h | 2 +- include/hw/sparc/grlib.h | 2 +- include/hw/xen/xen.h | 2 +- include/monitor/monitor.h | 2 +- include/qemu/typedefs.h | 2 +- include/sysemu/char.h | 155 +-- include/sysemu/replay.h | 4 +- include/sysemu/sysemu.h | 4 +- include/ui/console.h | 2 + include/ui/gtk.h | 2 +- include/ui/qemu-spice.h | 2 +- backends/baum.c | 102 +- backends/msmouse.c | 77 +- backends/rng-egd.c | 4 +- backends/testdev.c | 53 +- gdbstub.c | 45 +- hw/arm/fsl-imx25.c | 2 +- hw/arm/fsl-imx31.c | 2 +- hw/arm/fsl-imx6.c | 2 +- hw/arm/nseries.c | 2 +- hw/arm/omap2.c | 2 +- hw/arm/pxa2xx.c | 2 +- hw/arm/virt.c | 2 +- hw/bt/hci-csr.c | 64 +- hw/char/escc.c | 2 +- hw/char/exynos4210_uart.c | 2 +- hw/char/imx_serial.c | 2 +- hw/char/mcf_uart.c | 4 +- hw/char/omap_uart.c | 6 +- hw/char/parallel.c | 2 +- hw/char/serial-isa.c | 2 +- hw/char/serial.c | 4 +- hw/char/sh_serial.c | 2 +- hw/char/spapr_vty.c | 2 +- hw/char/virtio-console.c | 2 +- hw/core/qdev-properties-system.c | 4 +- hw/display/milkymist-tmu2.c | 2 +- hw/display/sm501.c | 2 +- hw/isa/isa-bus.c | 2 +- hw/isa/pc87312.c | 2 +- hw/mips/mips_malta.c | 4 +- hw/misc/ivshmem.c | 2 +- hw/misc/milkymist-pfpu.c | 2 +- hw/usb/ccid-card-passthru.c | 2 +- hw/usb/dev-serial.c | 6 +- hw/usb/redirect.c | 4 +- monitor.c | 6 +- net/colo-compare.c | 4 +- net/filter-mirror.c | 4 +- net/slirp.c | 2 +- net/vhost-user.c | 10 +- qemu-char.c | 1912 ++++++++++++++++++++----------------- qmp.c | 2 +- qtest.c | 2 +- replay/replay-char.c | 8 +- spice-qemu-char.c | 231 +++-- stubs/get-next-serial.c | 2 +- stubs/monitor-init.c | 2 +- stubs/replay.c | 4 +- tests/test-char.c | 10 +- tests/vhost-user-test.c | 4 +- ui/console.c | 111 ++- ui/gtk.c | 86 +- vl.c | 12 +- xen-common-stub.c | 2 +- xen-common.c | 4 +- qemu-options.hx | 4 +- tests/Makefile.include | 2 +- 84 files changed, 1730 insertions(+), 1340 deletions(-)
Signature · 1 line
2.11.0
PATCH 1/20 tests: fix linking test-char on win32
test-char.exe needs main-loop.o symbols, among others. Linking with $(test-block-obj-y) brings what's necessary. We could try to eventually strip to the minimum if needed.
--- tests/Makefile.include | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/Makefile.include +1 -1
@@ -489,7 +489,7 @@ tests/check-qjson$(EXESUF): tests/check-qjson.o $(test-util-obj-y) tests/check-qom-interface$(EXESUF): tests/check-qom-interface.o $(test-qom-obj-y) tests/check-qom-proplist$(EXESUF): tests/check-qom-proplist.o $(test-qom-obj-y) -tests/test-char$(EXESUF): tests/test-char.o qemu-char.o qemu-timer.o $(test-util-obj-y) $(qtest-obj-y) $(test-io-obj-y) +tests/test-char$(EXESUF): tests/test-char.o qemu-char.o qemu-timer.o $(test-util-obj-y) $(qtest-obj-y) $(test-block-obj-y) tests/test-coroutine$(EXESUF): tests/test-coroutine.o $(test-block-obj-y) tests/test-aio$(EXESUF): tests/test-aio.o $(test-block-obj-y) tests/test-throttle$(EXESUF): tests/test-throttle.o $(test-block-obj-y)
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH 01/20] tests: fix linking test-char on win32
Quoted 8 lines · Marc-André Lureau
test-char.exe needs main-loop.o symbols, among others. Linking with $(test-block-obj-y) brings what's necessary. We could try to eventually strip to the minimum if needed.
Signed-off-by Marc-André Lureau <[email protected]>--- tests/Makefile.include | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Can I have a bit more background? I'm guessing this doesn't fix an actual failure at the moment (probably due to one of the other files dragging in stuff indirectly), but rather cleans up a latent problem that would otherwise be exposed with patches later in the series (where splitting files means the stuff is no longer dragged in indirectly, so we need to mention it explicitly)?
Even mentioning _which_ main-loop.o symbol to be grepping for in test-char.c might be helpful to the review.
tests/Makefile.include tests/check-qjson$(EXESUF): tests/check-qjson.o $(test-util-obj-y) · line 492
Quoted 11 lines
tests/Makefile.include +1
-1@@ -489,7 +489,7 @@ tests/check-qjson$(EXESUF): tests/check-qjson.o $(test-util-obj-y) tests/check-qom-interface$(EXESUF): tests/check-qom-interface.o $(test-qom-obj-y) tests/check-qom-proplist$(EXESUF): tests/check-qom-proplist.o $(test-qom-obj-y) -tests/test-char$(EXESUF): tests/test-char.o qemu-char.o qemu-timer.o $(test-util-obj-y) $(qtest-obj-y) $(test-io-obj-y) +tests/test-char$(EXESUF): tests/test-char.o qemu-char.o qemu-timer.o $(test-util-obj-y) $(qtest-obj-y) $(test-block-obj-y)
At any rate, test-block-obj-y is simply test-io-obj-y plus the additional block-obj-y, so you're merely adding an additional dependency on block-obj-y files. While a nicer commit message may help, I don't see any technical problem in the change, so here's a weak:
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 01/20] tests: fix linking test-char on win32
Hi
----- Original Message -----
Quoted 10 lines · Marc-André Lureau
Quoted 8 lines
test-char.exe needs main-loop.o symbols, among others. Linking with $(test-block-obj-y) brings what's necessary. We could try to eventually strip to the minimum if needed.
Signed-off-by Marc-André Lureau <[email protected]>--- tests/Makefile.include | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 6 lines
Can I have a bit more background? I'm guessing this doesn't fix an actual failure at the moment (probably due to one of the other files dragging in stuff indirectly), but rather cleans up a latent problem that would otherwise be exposed with patches later in the series (where splitting files means the stuff is no longer dragged in indirectly, so we need to mention it explicitly)?
It does fix current linking failure:
x86_64-w64-mingw32-g++ -I/usr/x86_64-w64-mingw32/sys-root/mingw/include/pixman-1 -I/home/elmarco/src/qemu/dtc/libfdt -Werror -mms-bitfields -I/usr/x86_64-w64-mingw32/sys-root/mingw/include/glib-2.0 -I/usr/x86_64-w64-mingw32/sys-root/mingw/lib/glib-2.0/include -I/usr/x86_64-w64-mingw32/sys-root/mingw/include -m64 -mcx16 -mthreads -D__USE_MINGW_ANSI_STDIO=1 -DWIN32_LEAN_AND_MEAN -DWINVER=0x501 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -Wendif-labels -Wno-shift-negative-value -Wmissing-include-dirs -Wempty-body -Wnested-externs -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wold-style-declaration -Wold-style-definition -Wtype-limits -fstack-protector-strong -I/usr/x86_64-w64-mingw32/sys-root/mingw/include/libpng16 -I/home/elmarco/src/qemu/tests -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -g -Wl,--nxcompat -Wl,--no-seh -Wl,--dynamicbase -Wl,--warn-common -m64 -g -o tests/test-char.exe tests/test-char.o qemu-char.o qemu-timer.o io/channel.o io/channel-buffer.o io/channel-command.o io/channel-file.o io/channel-socket.o io/channel-tls.o io/channel-watch.o io/channel-websock.o io/channel-util.o io/task.o crypto/init.o crypto/hash.o crypto/hash-glib.o crypto/hmac.o crypto/hmac-glib.o crypto/aes.o crypto/desrfb.o crypto/cipher.o crypto/tlscreds.o crypto/tlscredsanon.o crypto/tlscredsx509.o crypto/tlssession.o crypto/secret.o crypto/random-platform.o crypto/pbkdf.o crypto/ivgen.o crypto/ivgen-essiv.o crypto/ivgen-plain.o crypto/ivgen-plain64.o crypto/afsplit.o crypto/xts.o crypto/block.o crypto/block-qcow.o crypto/block-luks.o qom/object.o qom/container.o qom/qom-qobject.o qom/object_interfaces.o libqemuutil.a libqemustub.a /home/elmarco/src/qemu/winb/version.o -L/usr/x86_64-w64-mingw32/sys-root/mingw/lib -lgthread-2.0 -lglib-2.0 -lintl -lwinmm -lws2_32 -liphlpapi -lz -lz qemu-char.o: In function `win_chr_free':/home/elmarco/src/qemu/qemu-char.c:2149: undefined reference to `qemu_del_polling_cb'/home/elmarco/src/qemu/qemu-char.c:2151: undefined reference to `qemu_del_polling_cb'
qemu-char.o: In function `win_stdio_thread':/home/elmarco/src/qemu/qemu-char.c:2568: undefined reference to `qemu_del_wait_object'
qemu-char.o: In function `qemu_chr_open_stdio':/home/elmarco/src/qemu/qemu-char.c:2661: undefined reference to `qemu_add_wait_object'/home/elmarco/src/qemu/qemu-char.c:2646: undefined reference to `qemu_add_wait_object'/home/elmarco/src/qemu/qemu-char.c:2696: undefined reference to `qemu_del_wait_object'/home/elmarco/src/qemu/qemu-char.c:2691: undefined reference to `qemu_del_wait_object'
qemu-char.o: In function `win_chr_pipe_init':/home/elmarco/src/qemu/qemu-char.c:2413: undefined reference to `qemu_add_polling_cb'
qemu-char.o: In function `win_chr_init':/home/elmarco/src/qemu/qemu-char.c:2215: undefined reference to `qemu_add_polling_cb'
qemu-char.o: In function `win_stdio_wait_func':/home/elmarco/src/qemu/qemu-char.c:2512: undefined reference to `qemu_del_wait_object'
collect2: error: ld returned 1 exit status/home/elmarco/src/qemu/rules.mak:109: recipe for target 'tests/test-char.exe' failed
make: *** [tests/test-char.exe] Error 1
I can add this linking error to the commit log if it helps.
Quoted 3 lines
Even mentioning _which_ main-loop.o symbol to be grepping for in
test-char.cmight be helpful to the review.
It's from qemu-char.c.
Quoted 30 lines
Quoted 14 lines
tests/Makefile.include +0
-1@@ -489,7 +489,7 @@ tests/check-qjson$(EXESUF): tests/check-qjson.o $(test-util-obj-y) tests/check-qom-interface$(EXESUF): tests/check-qom-interface.o $(test-qom-obj-y) tests/check-qom-proplist$(EXESUF): tests/check-qom-proplist.o $(test-qom-obj-y) -tests/test-char$(EXESUF): tests/test-char.o qemu-char.o qemu-timer.oQuoted 3 lines
$(test-util-obj-y) $(qtest-obj-y) $(test-io-obj-y) +tests/test-char$(EXESUF):
tests/test-char.oqemu-char.o qemu-timer.o $(test-util-obj-y) $(qtest-obj-y) $(test-block-obj-y)At any rate, test-block-obj-y is simply test-io-obj-y plus the additional block-obj-y, so you're merely adding an additional dependency on block-obj-y files. While a nicer commit message may help, I don't see any technical problem in the change, so here's a weak:
Reviewed-by Eric Blake <[email protected]>--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 01/20] tests: fix linking test-char on win32
Quoted 20 lines · Marc-André Lureau
Hi
----- Original Message -----
Quoted 10 lines · Marc-André Lureau
Quoted 8 lines
test-char.exe needs main-loop.o symbols, among others. Linking with $(test-block-obj-y) brings what's necessary. We could try to eventually strip to the minimum if needed.
Signed-off-by Marc-André Lureau <[email protected]>--- tests/Makefile.include | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 6 lines
Can I have a bit more background? I'm guessing this doesn't fix an actual failure at the moment (probably due to one of the other files dragging in stuff indirectly), but rather cleans up a latent problem that would otherwise be exposed with patches later in the series (where splitting files means the stuff is no longer dragged in indirectly, so we need to mention it explicitly)?
Quoted 4 lines
It does fix current linking failure:
x86_64-w64-mingw32-g++ -I/usr/x86_64-w64-mingw32/sys-root/mingw/include/pixman-1 -I/home/elmarco/src/qemu/dtc/libfdt -Werror -mms-bitfields -I/usr/x86_64-w64-mingw32/sys-root/mingw/include/glib-2.0 -I/usr/x86_64-w64-mingw32/sys-root/mingw/lib/glib-2.0/include -I/usr/x86_64-w64-mingw32/sys-root/mingw/include -m64 -mcx16 -mthreads -D__USE_MINGW_ANSI_STDIO=1 -DWIN32_LEAN_AND_MEAN -DWINVER=0x501 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -Wendif-labels -Wno-shift-negative-value -Wmissing-include-dirs -Wempty-body -Wnested-externs -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wold-style-declaration -Wold-style-definition -Wtype-limits -fstack-protector-strong -I/usr/x86_64-w64-mingw32/sys-root/mingw/include/libpng16 -I/home/elmarco/src/qemu/tests -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -g -Wl,--nxcompat -Wl,--no-seh -Wl,--dynamicbase -Wl,--warn-common -m64 -g -o tests/test-char.exetests/test-char.oqemu-char.o qemu-timer.oio/channel.oio/channel-buffer.oio/channel-command.oio/channel-file.oio/channel-socket.oio/channel-tls.oio/channel-watch.oio/channel-websock.oio/channel-util.oio/task.ocrypto/init.ocrypto/hash.ocrypto/hash-glib.ocrypto/hmac.ocrypto/hmac-glib.ocrypto/aes.ocrypto/desrfb.ocrypto/cipher.ocrypto/tlscreds.ocrypto/tlscredsanon.ocrypto/tlscredsx509.ocrypto/tlssession.ocrypto/secret.ocrypto/random-platform.ocrypto/pbkdf.ocrypto/ivgen.ocrypto/ivgen-essiv.ocrypto/ivgen-plain.ocrypto/ivgen-plain64.ocrypto/afsplit.ocrypto/xts.ocrypto/block.ocrypto/block-qcow.ocrypto/block-luks.oqom/object.oqom/container.oqom/qom-qobject.oqom/object_interfaces.olibqemuutil.a libqemustub.a/home/elmarco/src/qemu/winb/version.o-L/usr/x86_64-w64-mingw32/sys-root/mingw/lib -lgthread-2.0 -lglib-2.0 -lintl -lwinmm -lws2_32 -liphlpapi -lz -lz qemu-char.o: In function `win_chr_free':/home/elmarco/src/qemu/qemu-char.c:2149: undefined reference to `qemu_del_polling_cb'
Ah, so it's an existing problem in mingw compilation (I missed that part; I assumed that because it links fine on Linux that there was no problem - without realizing that the mingw implementation of char devices drags in more requirements thanks to the #ifdef's char drivers).
Quoted 1 line
I can add this linking error to the commit log if it helps.
Yes, listing the link failure in the commit message (either just those two lines above, or the whole she-bang) helps tremendously.
Quoted 5 lines
Quoted 3 lines
Even mentioning _which_ main-loop.o symbol to be grepping for in
test-char.cmight be helpful to the review.It's from
qemu-char.c.
Yep, all clear now.
Quoted 6 lines
Quoted 6 lines
At any rate, test-block-obj-y is simply test-io-obj-y plus the additional block-obj-y, so you're merely adding an additional dependency on block-obj-y files. While a nicer commit message may help, I don't see any technical problem in the change, so here's a weak:
Reviewed-by Eric Blake <[email protected]>
And with the commit message improvement, it is now a strong R-b.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 2/20 qemu-options: stdio is available on win32
In reply to Marc-André LureauAvailable since commit db418a0a7ef5887ea0f3d167584e6f500bb0c4c5 (October 2011, qemu 1.0)
--- qemu-options.hx | 2 -- 1 file changed, 2 deletions(-)
qemu-options.hx +0 -2
@@ -2431,8 +2431,6 @@ Connect to standard input and standard output of the QEMU process. exiting QEMU with the key sequence @key{Control-c}. This option is enabled by default, use @option{signal=off} to disable it. -@option{stdio} is not available on Windows hosts. - @item -chardev braille ,id=@var{id} Connect to a local BrlAPI server. @option{braille} does not take any options.
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH 02/20] qemu-options: stdio is available on win32
Quoted 7 lines · Marc-André Lureau
Available since commit
db418a0a7ef5887ea0f3d167584e6f500bb0c4c5(October 2011, qemu 1.0)Signed-off-by Marc-André Lureau <[email protected]>--- qemu-options.hx | 2 -- 1 file changed, 2 deletions(-)
(Isn't git history fun!)
Quoted 15 lines
qemu-options.hx +0
-2@@ -2431,8 +2431,6 @@ Connect to standard input and standard output of the QEMU process. exiting QEMU with the key sequence @key{Control-c}. This option is enabled by default, use @option{signal=off} to disable it. -@option{stdio} is not available on Windows hosts. - @item -chardev braille ,id=@var{id} Connect to a local BrlAPI server. @option{braille} does not take any options.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 3/20 char: add qemu_chr_fe_add_watch() Returns description
In reply to Marc-André Lureau--- include/sysemu/char.h | 2 ++ 1 file changed, 2 insertions(+)
include/sysemu/char.h +2 -0
@@ -258,6 +258,8 @@ void qemu_chr_fe_printf(CharBackend *be, const char *fmt, ...)* @cond the condition to poll for * @func the function to call when the condition happens * @user_data the opaque pointer to pass to @func +* +* Returns: the source tag */ guint qemu_chr_fe_add_watch (CharBackend *be,GIOCondition cond,GIOFunc func,void *user_data);
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH 03/20] char: add qemu_chr_fe_add_watch() Returns description
Quoted 5 lines · Marc-André Lureau
Signed-off-by Marc-André Lureau <[email protected]>--- include/sysemu/char.h | 2 ++ 1 file changed, 2 insertions(+)
Quoted 14 lines
include/sysemu/char.h +2
-0@@ -258,6 +258,8 @@ void qemu_chr_fe_printf(CharBackend *be, const char *fmt, ...)* @cond the condition to poll for * @func the function to call when the condition happens * @user_data the opaque pointer to pass to @func +* +* Returns: the source tag */ guint qemu_chr_fe_add_watch (CharBackend *be,GIOCondition cond,GIOFunc func,void *user_data);
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 4/20 doc: fix spelling
In reply to Marc-André LureauI am pretty sure that's the word Fabrice Bellard intended to write.
--- qemu-options.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
qemu-options.hx +1 -1
@@ -3016,7 +3016,7 @@ udp::4555@@:4556} to QEMU. Another approach is to use a patched version of netcat which can listen to a TCP port and send and receive characters via udp. If you have a patched version of netcat which activates telnet remote echo and single char transfer, then you can -use the following options to step up a netcat redirector to allow +use the following options to set up a netcat redirector to allow telnet on port 5555 to access the QEMU port. @table @code @item QEMU Options:
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH 04/20] doc: fix spelling
Quoted 6 lines · Marc-André Lureau
I am pretty sure that's the word Fabrice Bellard intended to write.
Signed-off-by Marc-André Lureau <[email protected]>--- qemu-options.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Spell-checkers don't flag everything :)
Quoted 15 lines
qemu-options.hx +1
-1@@ -3016,7 +3016,7 @@ udp::4555@@:4556} to QEMU. Another approach is to use a patched version of netcat which can listen to a TCP port and send and receive characters via udp. If you have a patched version of netcat which activates telnet remote echo and single char transfer, then you can -use the following options to step up a netcat redirector to allow +use the following options to set up a netcat redirector to allow telnet on port 5555 to access the QEMU port. @table @code @item QEMU Options:
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 5/20 char: use a const CharDriver
In reply to Marc-André LureauNo need to allocate & copy fields, let's use static const struct instead.
--- include/sysemu/char.h | 19 +++---- backends/baum.c | 8 ++- backends/msmouse.c | 7 ++- backends/testdev.c | 7 ++- qemu-char.c | 141 +++++++++++++++++++++++++++++++------------------- spice-qemu-char.c | 16 ++++-- ui/console.c | 10 ++-- 7 files changed, 134 insertions(+), 74 deletions(-)
include/sysemu/char.h +10 -9
@@ -475,15 +475,16 @@ void qemu_chr_set_feature(CharDriverState *chr, CharDriverFeature feature);QemuOpts *qemu_chr_parse_compat (const char *label,const char *filename); -typedef void CharDriverParse (QemuOpts *opts,ChardevBackend *backend, -Error **errp); -typedef CharDriverState *CharDriverCreate (const char *id, -ChardevBackend *backend, -ChardevReturn *ret,bool *be_opened, -Error **errp); - -void register_char_driver (const char *name,ChardevBackendKind kind, -CharDriverParse *parse,CharDriverCreate *create); +typedef struct CharDriver { +ChardevBackendKind kind; +void (*parse)(QemuOpts *opts,ChardevBackend *backend,Error **errp); +CharDriverState *(*create)(const char *id, +ChardevBackend *backend, +ChardevReturn *ret,bool *be_opened, +Error **errp); +}CharDriver ; + +void register_char_driver (const CharDriver *driver);extern int term_escape_char;
backends/baum.c +6 -2
@@ -671,8 +671,12 @@ fail_handle:static void register_types (void ) { -register_char_driver ("braille" ,CHARDEV_BACKEND_KIND_BRAILLE ,NULL , - chr_baum_init); +static const CharDriver driver = { + .kind =CHARDEV_BACKEND_KIND_BRAILLE , + .create = chr_baum_init, + }; + +register_char_driver (&driver); }type_init (register_types);
backends/msmouse.c +5 -2
@@ -179,8 +179,11 @@ static CharDriverState *qemu_chr_open_msmouse(const char *id,static void register_types (void ) { -register_char_driver ("msmouse" ,CHARDEV_BACKEND_KIND_MSMOUSE ,NULL , - qemu_chr_open_msmouse); +static const CharDriver driver = { + .kind =CHARDEV_BACKEND_KIND_MSMOUSE , + .create = qemu_chr_open_msmouse, + }; +register_char_driver (&driver); }type_init (register_types);
backends/testdev.c +5 -2
@@ -130,8 +130,11 @@ static CharDriverState *chr_testdev_init(const char *id,static void register_types (void ) { -register_char_driver ("testdev" ,CHARDEV_BACKEND_KIND_TESTDEV ,NULL , - chr_testdev_init); +static const CharDriver driver = { + .kind =CHARDEV_BACKEND_KIND_TESTDEV , + .create = chr_testdev_init, + }; +register_char_driver (&driver); }type_init (register_types);
qemu-char.c +89 -52
182 lines not on this page · raw message
spice-qemu-char.c +12 -4
@@ -389,10 +389,18 @@ static void qemu_chr_parse_spice_port(QemuOpts *opts, ChardevBackend *backend,static void register_types (void ) { -register_char_driver ("spicevmc" ,CHARDEV_BACKEND_KIND_SPICEVMC , - qemu_chr_parse_spice_vmc, qemu_chr_open_spice_vmc); -register_char_driver ("spiceport" ,CHARDEV_BACKEND_KIND_SPICEPORT , - qemu_chr_parse_spice_port, qemu_chr_open_spice_port); +static const CharDriver vmc_driver = { + .kind =CHARDEV_BACKEND_KIND_SPICEVMC , + .parse = qemu_chr_parse_spice_vmc, + .create = qemu_chr_open_spice_vmc, + }; +static const CharDriver port_driver = { + .kind =CHARDEV_BACKEND_KIND_SPICEPORT , + .parse = qemu_chr_parse_spice_port, + .create = qemu_chr_open_spice_port, + }; +register_char_driver (&vmc_driver); +register_char_driver (&port_driver); }type_init (register_types);
ui/console.c +7 -3
@@ -2191,12 +2191,16 @@ static const TypeInfo qemu_console_info = { .class_size = sizeof(QemuConsoleClass), }; -static void register_types (void ) { +static const CharDriver vc_driver = { + .kind =CHARDEV_BACKEND_KIND_VC , + .parse = qemu_chr_parse_vc, + .create = vc_init, + }; +type_register_static (&qemu_console_info); -register_char_driver ("vc" ,CHARDEV_BACKEND_KIND_VC , qemu_chr_parse_vc, - vc_init); +register_char_driver (&vc_driver); }type_init (register_types);
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH 05/20] char: use a const CharDriver
Quoted 21 lines · Marc-André Lureau
No need to allocate & copy fields, let's use static const struct instead.
Signed-off-by Marc-André Lureau <[email protected]>--- include/sysemu/char.h | 19 +++---- backends/baum.c | 8 ++- backends/msmouse.c | 7 ++- backends/testdev.c | 7 ++- qemu-char.c | 141 +++++++++++++++++++++++++++++++------------------- spice-qemu-char.c | 16 ++++-- ui/console.c | 10 ++-- 7 files changed, 134 insertions(+), 74 deletions(-)include/sysemu/char.h +0
-0@@ -475,15 +475,16 @@ void qemu_chr_set_feature(CharDriverState *chr, CharDriverFeature feature);QemuOpts *qemu_chr_parse_compat (const char *label,const char *filename);
include/sysemu/char.h void qemu_chr_set_feature(CharDriverState *chr, · line 486
Quoted 10 lines
include/sysemu/char.h +0
-9-typedef void CharDriverParse (QemuOpts *opts,ChardevBackend *backend, -Error **errp); -typedef CharDriverState *CharDriverCreate (const char *id, -ChardevBackend *backend, -ChardevReturn *ret,bool *be_opened, -Error **errp); - -void register_char_driver (const char *name,ChardevBackendKind kind, -CharDriverParse *parse,CharDriverCreate *create);
The old code takes a name...
include/sysemu/char.h void qemu_chr_set_feature(CharDriverState *chr, · line 487
Quoted 10 lines
include/sysemu/char.h +10
-0+typedef struct CharDriver { +ChardevBackendKind kind; +void (*parse)(QemuOpts *opts,ChardevBackend *backend,Error **errp); +CharDriverState *(*create)(const char *id, +ChardevBackend *backend, +ChardevReturn *ret,bool *be_opened, +Error **errp); +}CharDriver ; + +void register_char_driver (const CharDriver *driver);
...the new code does not. Let's see why:
include/sysemu/char.h static void qemu_chr_parse_udp(QemuOpts *opts, ChardevBackend *backend, · line 4102
Quoted 11 lines
include/sysemu/char.h +1
-6+++ b/qemu-char.c@@ -4094,27 +4094,12 @@ static void qemu_chr_parse_udp(QemuOpts *opts, ChardevBackend *backend, } } -typedef struct CharDriver { -const char *name; -ChardevBackendKind kind; -CharDriverParse *parse; -CharDriverCreate *create; -}CharDriver ;
In fact, you are moving the struct from private to public, AND dropping a member at the same time.
include/sysemu/char.h static void qemu_chr_parse_udp(QemuOpts *opts, ChardevBackend *backend, · line 4112
Quoted 11 lines
include/sysemu/char.h +1
-7-static GSList *backends; -void register_char_driver (const char *name,ChardevBackendKind kind, -CharDriverParse *parse,CharDriverCreate *create) +void register_char_driver (const CharDriver *driver) { -CharDriver *s; - - s =g_malloc0 (sizeof (*s)); - s->name =g_strdup (name);
The old code copies the name, the new code has no name to copy.
Quoted 11 lines
include/sysemu/char.h +2
-5- s->kind = kind; - s->parse = parse; - s->create = create; - - backends =g_slist_append (backends, s); +/* casting away const */ + backends =g_slist_append (backends, (void *)driver); } CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,
include/sysemu/char.h CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts, · line 4127
Quoted 5 lines
include/sysemu/char.h +1
-1@@ -4139,7 +4124,7 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,fprintf (stderr,"Available chardev backend types:\n" );for (i = backends; i; i = i->next) { cd = i->data; -fprintf (stderr,"%s\n" , cd->name); +fprintf (stderr,"%s\n" , ChardevBackendKind_lookup[cd->kind]);
The old code reused the name copied during registration, the new code uses kind to look up the name from the QAPI enum type. That means the output changes: it now outputs the canonical name instead of the alias name. I can live with that (even if the output is temporarily weird for listing a canonical name more than once).
include/sysemu/char.h CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts, · line 4141
Quoted 7 lines
include/sysemu/char.h +2
-1@@ -4152,7 +4137,8 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,for (i = backends; i; i = i->next) { cd = i->data; -if (strcmp (cd->name,qemu_opt_get (opts,"backend" )) ==0 ) { +if (strcmp (ChardevBackendKind_lookup[cd->kind], +qemu_opt_get (opts,"backend" )) ==0 ) {
But this change means any driver that does NOT have a name in the QAPI enum type CANNOT be constructed from the command line, at least for the duration of this patch. Let's see what is impacted by this:
include/sysemu/char.h CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,
Quoted 5 lines
include/sysemu/char.h +0
-4#if definedHAVE_CHARDEV_SERIAL -register_char_driver ("serial" ,CHARDEV_BACKEND_KIND_SERIAL , - qemu_chr_parse_serial, qmp_chardev_open_serial); -register_char_driver ("tty" ,CHARDEV_BACKEND_KIND_SERIAL , - qemu_chr_parse_serial, qmp_chardev_open_serial);
The old code registered two different names for a serial driver;
include/sysemu/char.h
Quoted 10 lines
include/sysemu/char.h +10
-0+ { + .kind = CHARDEV_BACKEND_KIND_SERIAL, + .parse = qemu_chr_parse_serial, + .create = qmp_chardev_open_serial, + }, + { + .kind = CHARDEV_BACKEND_KIND_SERIAL, + .parse = qemu_chr_parse_serial, + .create = qmp_chardev_open_serial, + },
the new code just registers the SAME driver contents twice, but both tied to the QAPI name "serial". Either we want _this_ patch to keep the "tty" name around (but that's churn, because it does go away later in the series when we add aliasing), or we can drop the second registration as redundant, and just document that we temporarily lose access to the aliased name until fixed in a later patch.
Quoted 6 lines
#endif
#ifdefHAVE_CHARDEV_PARPORTinclude/sysemu/char.h +0
-4-register_char_driver ("parallel" ,CHARDEV_BACKEND_KIND_PARALLEL , - qemu_chr_parse_parallel, qmp_chardev_open_parallel); -register_char_driver ("parport" ,CHARDEV_BACKEND_KIND_PARALLEL , - qemu_chr_parse_parallel, qmp_chardev_open_parallel);
include/sysemu/char.h
Quoted 10 lines
include/sysemu/char.h +10
-0+ { + .kind = CHARDEV_BACKEND_KIND_PARALLEL, + .parse = qemu_chr_parse_parallel, + .create = qmp_chardev_open_parallel, + }, + { + .kind = CHARDEV_BACKEND_KIND_PARALLEL, + .parse = qemu_chr_parse_parallel, + .create = qmp_chardev_open_parallel, + },
And again.
Quoted 5 lines
include/sysemu/char.h +5
-0+ { + .kind = CHARDEV_BACKEND_KIND_PIPE, + .parse = qemu_chr_parse_pipe, + .create = qemu_chr_open_pipe, + },
include/sysemu/char.h
Quoted 10 lines
include/sysemu/char.h +10
-0+ { + .kind = CHARDEV_BACKEND_KIND_MUX, + .parse = qemu_chr_parse_mux, + .create = qemu_chr_open_mux, + }, +/* Bug-compatibility: */ + { + .kind = CHARDEV_BACKEND_KIND_MEMORY, + .parse = qemu_chr_parse_ringbuf, + .create = qemu_chr_open_ringbuf,
What's weird here is that CHARDEV_BACKEND_KIND_MEMORY and CHARDEV_BACKEND_KIND_RINGBUF are also using the same callbacks, but this time appear as separate names in the QAPI enum. A different approach would be to modify qapi-schema.json to add 'tty':'ChardevHostdev' and 'parport':'ChardevHostdev' aliases, the way it already has a 'memory':ChardevRingbuf' alias, so that the above registrations that I complained were duplicates could use the right enum values. But is it really worth dirtying the QAPI with an enum value we don't want? Conversely, should we remove 'memory' from QAPI as no longer supported (yes, it breaks back-compat, but we've documented that new code should not be using it)?
I still think you need more in the commit message to justify this code. Option 1, minimizing code churn, documenting the temporary regression:
=====
No need to allocate & copy fields, let's use static const struct instead.
Note that this promotes CharDriver to a public struct, but eliminates the 'name' parameter in the process; this is because in most cases, we can use the QAPI enum for ChardevBackend to come up with the same names, with the only exceptions being older aliases 'tty' (for 'serial') and 'parport' (for 'parallel') where outputting the canonical name is better anyways. This causes a temporary regression in the ability to create a char driver from the command line using the older spellings, but that will be fixed in a later patch that cleans up how aliases are handled.
=====
along with this patch squashed in:
=====
qemu-char.c +2 -10
@@ -4930,11 +4930,7 @@ static void register_types(void) .parse = qemu_chr_parse_serial, .create = qmp_chardev_open_serial, }, - { - .kind = CHARDEV_BACKEND_KIND_SERIAL, - .parse = qemu_chr_parse_serial, - .create = qmp_chardev_open_serial, - }, +/* FIXME: Need a "tty" alias */ #endif #ifdef HAVE_CHARDEV_PARPORT {
@@ -4942,11 +4938,7 @@ static void register_types(void) .parse = qemu_chr_parse_parallel, .create = qmp_chardev_open_parallel, }, - { - .kind = CHARDEV_BACKEND_KIND_PARALLEL, - .parse = qemu_chr_parse_parallel, - .create = qmp_chardev_open_parallel, - }, +/* FIXME: Need a "parport" alias */ #endif #ifdef HAVE_CHARDEV_PTY {
=====
Option 2, hoisting part of 6/20 earlier in the series to avoid the temporary regression altogether:
=====
No need to allocate & copy fields, let's use static const struct instead.
Note that this promotes CharDriver to a public struct, and replaces a 'name' parameter with an 'alias' field to handle the fact that we were previously registering the 'serial' and 'parallel' drivers twice to pick up their older 'tty' and 'parport' aliases (we still register the 'memory' driver as an alias for 'ringbuf', but that's because that alias is public in the ChardevBackend QAPI type).
=====
along with this patch squashed in:
=====
include/sysemu/char.h +0 -0
@@ -477,6 +477,7 @@ QemuOpts *qemu_chr_parse_compat(const char *label,
const char *filename);
typedef struct CharDriver {
ChardevBackendKind kind;+ const char *alias;
void (*parse)(QemuOpts *opts, ChardevBackend *backend, Error **errp); CharDriverState *(*create)(const char *id,
ChardevBackend *backend,
qemu-char.c +0 -0
@@ -4111,22 +4111,27 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts
*opts,
GSList *i;
ChardevReturn *ret = NULL;
ChardevBackend *backend;
+ const char *name;
const char *id = qemu_opts_id(opts);
char *bid = NULL;- if (qemu_opt_get(opts, "backend") == NULL) {
+ name = qemu_opt_get(opts, "backend");
+ if (name == NULL) {
error_setg(errp, "chardev: \"%s\" missing backend",
qemu_opts_id(opts));
goto err;
}- if (is_help_option(qemu_opt_get(opts, "backend"))) {
+ if (is_help_option(name)) {
fprintf(stderr, "Available chardev backend types:\n");
for (i = backends; i; i = i->next) {
cd = i->data;
fprintf(stderr, "%s\n", ChardevBackendKind_lookup[cd->kind]);
+ if (cd->alias) {
+ fprintf(stderr, "%s\n", cd->alias);
+ }
}
- exit(!is_help_option(qemu_opt_get(opts, "backend")));
+ exit(0);
}
if (id == NULL) {
@@ -4137,14 +4142,13 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts
*opts,
for (i = backends; i; i = i->next) {
cd = i->data;- if (strcmp(ChardevBackendKind_lookup[cd->kind],
- qemu_opt_get(opts, "backend")) == 0) {
+ if (strcmp(ChardevBackendKind_lookup[cd->kind], name) == 0 ||
+ g_strcmp0(cd->alias, name) == 0) {
break;
}
}
if (i == NULL) {
- error_setg(errp, "chardev: backend \"%s\" not found",
- qemu_opt_get(opts, "backend"));
+ error_setg(errp, "chardev: backend \"%s\" not found", name);
goto err;
}@@ -4927,11 +4931,7 @@ static void register_types(void)
#if defined HAVE_CHARDEV_SERIAL
{
.kind = CHARDEV_BACKEND_KIND_SERIAL,
- .parse = qemu_chr_parse_serial,
- .create = qmp_chardev_open_serial,
- },
- {
- .kind = CHARDEV_BACKEND_KIND_SERIAL,
+ .alias = "tty",
.parse = qemu_chr_parse_serial, .create = qmp_chardev_open_serial,
},
@@ -4939,11 +4939,7 @@ static void register_types(void)
#ifdef HAVE_CHARDEV_PARPORT
{
.kind = CHARDEV_BACKEND_KIND_PARALLEL,
- .parse = qemu_chr_parse_parallel,
- .create = qmp_chardev_open_parallel,
- },
- {
- .kind = CHARDEV_BACKEND_KIND_PARALLEL,
+ .alias = "parport",
.parse = qemu_chr_parse_parallel, .create = qmp_chardev_open_parallel,
},
=====
If you agree with either of those options, then you can add:
If anyone else has a strong opinion (such as changing qapi to add the aliases 'tty' and 'parport', or even cleaning up qapi to remove 'memory' in favor of 'ringbuf') on which of my two options is preferred, or even going with a third option, then speak up now.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 05/20] char: use a const CharDriver
Hi
----- Original Message -----
Quoted 91 lines · Marc-André Lureau
Quoted 24 lines
No need to allocate & copy fields, let's use static const struct instead.
Signed-off-by Marc-André Lureau <[email protected]>--- include/sysemu/char.h | 19 +++---- backends/baum.c | 8 ++- backends/msmouse.c | 7 ++- backends/testdev.c | 7 ++- qemu-char.c | 141 +++++++++++++++++++++++++++++++------------------- spice-qemu-char.c | 16 ++++-- ui/console.c | 10 ++-- 7 files changed, 134 insertions(+), 74 deletions(-)include/sysemu/char.h +0
-1@@ -475,15 +475,16 @@ void qemu_chr_set_feature(CharDriverState *chr, CharDriverFeature feature);QemuOpts *qemu_chr_parse_compat (const char *label,const char *filename); -typedef void CharDriverParse(QemuOpts *opts, ChardevBackend *backend,include/sysemu/char.h void qemu_chr_set_feature(CharDriverState *chr, · line 479
Quoted 10 lines
include/sysemu/char.h +0
-8- Error **errp); -typedef CharDriverState *CharDriverCreate (const char *id, -ChardevBackend *backend, -ChardevReturn *ret,bool *be_opened, -Error **errp); - -void register_char_driver (const char *name,ChardevBackendKind kind, -CharDriverParse *parse,CharDriverCreate *create);The old code takes a name...
include/sysemu/char.h void qemu_chr_set_feature(CharDriverState *chr, · line 489
Quoted 10 lines
include/sysemu/char.h +10
-0+typedef struct CharDriver { +ChardevBackendKind kind; +void (*parse)(QemuOpts *opts,ChardevBackend *backend,Error **errp); +CharDriverState *(*create)(const char *id, +ChardevBackend *backend, +ChardevReturn *ret,bool *be_opened, +Error **errp); +}CharDriver ; + +void register_char_driver (const CharDriver *driver);...the new code does not. Let's see why:
include/sysemu/char.h static void qemu_chr_parse_udp(QemuOpts *opts, · line 4103
Quoted 12 lines
include/sysemu/char.h +1
-6+++ b/qemu-char.c@@ -4094,27 +4094,12 @@ static void qemu_chr_parse_udp(QemuOpts *opts, ChardevBackend *backend, } } -typedef struct CharDriver { -const char *name; -ChardevBackendKind kind; -CharDriverParse *parse; -CharDriverCreate *create; -}CharDriver ;In fact, you are moving the struct from private to public, AND dropping a member at the same time.
include/sysemu/char.h static void qemu_chr_parse_udp(QemuOpts *opts, · line 4114
Quoted 12 lines
include/sysemu/char.h +1
-7-static GSList *backends; -void register_char_driver (const char *name,ChardevBackendKind kind, -CharDriverParse *parse,CharDriverCreate *create) +void register_char_driver (const CharDriver *driver) { -CharDriver *s; - - s =g_malloc0 (sizeof (*s)); - s->name =g_strdup (name);The old code copies the name, the new code has no name to copy.
Quoted 9 lines
include/sysemu/char.h +2
-5- s->kind = kind; - s->parse = parse; - s->create = create; - - backends =g_slist_append (backends, s); +/* casting away const */ + backends =g_slist_append (backends, (void *)driver); }
Quoted 14 lines
include/sysemu/char.h CharDriverState *qemu_chr_new_from_opts(QemuOpts · line 4128
Quoted 8 lines
CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,
include/sysemu/char.h +1
-1@@ -4139,7 +4124,7 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,fprintf (stderr,"Available chardev backend types:\n" );for (i = backends; i; i = i->next) { cd = i->data; -fprintf (stderr,"%s\n" , cd->name); +fprintf (stderr,"%s\n" , ChardevBackendKind_lookup[cd->kind]);The old code reused the name copied during registration, the new code uses kind to look up the name from the QAPI enum type. That means the output changes: it now outputs the canonical name instead of the alias name. I can live with that (even if the output is temporarily weird for listing a canonical name more than once).
Hmm good catch, I didn't realize that, the next patch fixes most of it, right?
Quoted 33 lines
include/sysemu/char.h CharDriverState *qemu_chr_new_from_opts(QemuOpts · line 4142
Quoted 9 lines
include/sysemu/char.h +2
-1@@ -4152,7 +4137,8 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts, for (i = backends; i; i = i->next) { cd = i->data; -if (strcmp (cd->name,qemu_opt_get (opts,"backend" )) ==0 ) { +if (strcmp (ChardevBackendKind_lookup[cd->kind], +qemu_opt_get (opts,"backend" )) ==0 ) {But this change means any driver that does NOT have a name in the QAPI enum type CANNOT be constructed from the command line, at least for the duration of this patch. Let's see what is impacted by this:
include/sysemu/char.h CharDriverState *qemu_chr_new_from_opts(QemuOpts
Quoted 5 lines
include/sysemu/char.h +0
-4#if definedHAVE_CHARDEV_SERIAL -register_char_driver ("serial" ,CHARDEV_BACKEND_KIND_SERIAL , - qemu_chr_parse_serial, qmp_chardev_open_serial); -register_char_driver ("tty" ,CHARDEV_BACKEND_KIND_SERIAL , - qemu_chr_parse_serial, qmp_chardev_open_serial);The old code registered two different names for a serial driver;
include/sysemu/char.h
Quoted 10 lines
include/sysemu/char.h +10
-0+ { + .kind = CHARDEV_BACKEND_KIND_SERIAL, + .parse = qemu_chr_parse_serial, + .create = qmp_chardev_open_serial, + }, + { + .kind = CHARDEV_BACKEND_KIND_SERIAL, + .parse = qemu_chr_parse_serial, + .create = qmp_chardev_open_serial, + },
Quoted 6 lines
the new code just registers the SAME driver contents twice, but both tied to the QAPI name "serial". Either we want _this_ patch to keep the "tty" name around (but that's churn, because it does go away later in the series when we add aliasing), or we can drop the second registration as redundant, and just document that we temporarily lose access to the aliased name until fixed in a later patch.
Hmm, bad patch split.
Quoted 38 lines
Quoted 9 lines
#endif
#ifdefHAVE_CHARDEV_PARPORTinclude/sysemu/char.h +0
-2- register_char_driver("parallel", CHARDEV_BACKEND_KIND_PARALLEL, - qemu_chr_parse_parallel,
qmp_chardev_open_parallel);include/sysemu/char.h +0
-2- register_char_driver("parport", CHARDEV_BACKEND_KIND_PARALLEL, - qemu_chr_parse_parallel,
qmp_chardev_open_parallel);include/sysemu/char.h
Quoted 10 lines
include/sysemu/char.h +10
-0+ { + .kind = CHARDEV_BACKEND_KIND_PARALLEL, + .parse = qemu_chr_parse_parallel, + .create = qmp_chardev_open_parallel, + }, + { + .kind = CHARDEV_BACKEND_KIND_PARALLEL, + .parse = qemu_chr_parse_parallel, + .create = qmp_chardev_open_parallel, + },And again.
Quoted 5 lines
include/sysemu/char.h +5
-0+ { + .kind = CHARDEV_BACKEND_KIND_PIPE, + .parse = qemu_chr_parse_pipe, + .create = qemu_chr_open_pipe, + },include/sysemu/char.h
Quoted 10 lines
include/sysemu/char.h +10
-0+ { + .kind = CHARDEV_BACKEND_KIND_MUX, + .parse = qemu_chr_parse_mux, + .create = qemu_chr_open_mux, + }, +/* Bug-compatibility: */ + { + .kind = CHARDEV_BACKEND_KIND_MEMORY, + .parse = qemu_chr_parse_ringbuf, + .create = qemu_chr_open_ringbuf,
Quoted 8 lines
What's weird here is that
CHARDEV_BACKEND_KIND_MEMORYandCHARDEV_BACKEND_KIND_RINGBUFare also using the same callbacks, but this time appear as separate names in the QAPI enum. A different approach would be to modify qapi-schema.json to add 'tty':'ChardevHostdev' and 'parport':'ChardevHostdev' aliases, the way it already has a 'memory':ChardevRingbuf' alias, so that the above registrations that I complained were duplicates could use the right enum values. But is it really worth dirtying the QAPI with an enum value we don't want?
No
Quoted 11 lines
Conversely, should we remove 'memory' from QAPI as no longer supported (yes, it breaks back-compat, but we've documented that new code should not be using it)?
I still think you need more in the commit message to justify this code. Option 1, minimizing code churn, documenting the temporary regression:
=====
No need to allocate & copy fields, let's use static const struct instead.
Quoted 8 lines
Note that this promotes CharDriver to a public struct, but eliminates the 'name' parameter in the process; this is because in most cases, we can use the QAPI enum for ChardevBackend to come up with the same names, with the only exceptions being older aliases 'tty' (for 'serial') and 'parport' (for 'parallel') where outputting the canonical name is better anyways. This causes a temporary regression in the ability to create a char driver from the command line using the older spellings, but that will be fixed in a later patch that cleans up how aliases are handled.
I think your option 2 is better
Quoted 52 lines
=====
along with this patch squashed in:
=====qemu-char.c +2
-10@@ -4930,11 +4930,7 @@ static void register_types(void) .parse = qemu_chr_parse_serial, .create = qmp_chardev_open_serial, }, - { - .kind = CHARDEV_BACKEND_KIND_SERIAL, - .parse = qemu_chr_parse_serial, - .create = qmp_chardev_open_serial, - }, +/* FIXME: Need a "tty" alias */ #endif #ifdef HAVE_CHARDEV_PARPORT {@@ -4942,11 +4938,7 @@ static void register_types(void) .parse = qemu_chr_parse_parallel, .create = qmp_chardev_open_parallel, }, - { - .kind = CHARDEV_BACKEND_KIND_PARALLEL, - .parse = qemu_chr_parse_parallel, - .create = qmp_chardev_open_parallel, - }, +/* FIXME: Need a "parport" alias */ #endif #ifdef HAVE_CHARDEV_PTY {=====
Option 2, hoisting part of 6/20 earlier in the series to avoid the temporary regression altogether:
=====
No need to allocate & copy fields, let's use static const struct instead.Note that this promotes CharDriver to a public struct, and replaces a 'name' parameter with an 'alias' field to handle the fact that we were previously registering the 'serial' and 'parallel' drivers twice to pick up their older 'tty' and 'parport' aliases (we still register the 'memory' driver as an alias for 'ringbuf', but that's because that alias is public in the ChardevBackend QAPI type).
=====
Quoted 1 line
along with this patch squashed in:
ok
Quoted 98 lines
=====
include/sysemu/char.h +1
-0@@ -477,6 +477,7 @@ QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename); typedef struct CharDriver { ChardevBackendKind kind; + const char *alias; void (*parse)(QemuOpts *opts, ChardevBackend *backend, Error **errp); CharDriverState *(*create)(const char *id,ChardevBackend *backend,
qemu-char.c +8
-3@@ -4111,22 +4111,27 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts, GSList *i;ChardevReturn *ret =NULL ;ChardevBackend *backend; +const char *name;const char *id =qemu_opts_id (opts);char *bid =NULL ; -if (qemu_opt_get (opts,"backend" ) ==NULL ) { + name =qemu_opt_get (opts,"backend" ); +if (name ==NULL ) {error_setg (errp,"chardev: \"%s\" missing backend" ,qemu_opts_id (opts)); goto err; } -if (is_help_option (qemu_opt_get (opts,"backend" ))) { +if (is_help_option (name)) {fprintf (stderr,"Available chardev backend types:\n" );for (i = backends; i; i = i->next) { cd = i->data;fprintf (stderr,"%s\n" , ChardevBackendKind_lookup[cd->kind]); +if (cd->alias) { +fprintf (stderr,"%s\n" , cd->alias); + } } -exit (!is_help_option (qemu_opt_get (opts,"backend" ))); +exit (0 ); }if (id == NULL) {qemu-char.c +5
-14@@ -4137,14 +4142,13 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts, for (i = backends; i; i = i->next) { cd = i->data; -if (strcmp (ChardevBackendKind_lookup[cd->kind], -qemu_opt_get (opts,"backend" )) ==0 ) { +if (strcmp (ChardevBackendKind_lookup[cd->kind], name) ==0 || +g_strcmp0 (cd->alias, name) ==0 ) {break ; } }if (i ==NULL ) { -error_setg (errp,"chardev: backend \"%s\" not found" , -qemu_opt_get (opts,"backend" )); +error_setg (errp,"chardev: backend \"%s\" not found" , name); goto err; }@@ -4927,11 +4931,7 @@ static void register_types(void) #if defined HAVE_CHARDEV_SERIAL { .kind = CHARDEV_BACKEND_KIND_SERIAL, - .parse = qemu_chr_parse_serial, - .create = qmp_chardev_open_serial, - }, - { - .kind = CHARDEV_BACKEND_KIND_SERIAL, + .alias = "tty", .parse = qemu_chr_parse_serial, .create = qmp_chardev_open_serial, },@@ -4939,11 +4939,7 @@ static void register_types(void) #ifdef HAVE_CHARDEV_PARPORT { .kind = CHARDEV_BACKEND_KIND_PARALLEL, - .parse = qemu_chr_parse_parallel, - .create = qmp_chardev_open_parallel, - }, - { - .kind = CHARDEV_BACKEND_KIND_PARALLEL, + .alias = "parport", .parse = qemu_chr_parse_parallel, .create = qmp_chardev_open_parallel, },=====
Quoted 4 lines
If you agree with either of those options, then you can add:
Reviewed-by Eric Blake <[email protected]>
Thanks, I took option 2, and fixed the remaining issues mentionned in patch 6.
Quoted 10 lines
If anyone else has a strong opinion (such as changing qapi to add the aliases 'tty' and 'parport', or even cleaning up qapi to remove 'memory' in favor of 'ringbuf') on which of my two options is preferred, or even going with a third option, then speak up now.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
PATCH 6/20 char: use a static array for backends
In reply to Marc-André LureauNumber and kinds of backends is known at compile-time, use a fixed-sized static array to simplify iterations & lookups. Add an alias field to the CharDriver structure to cover the cases where we previously registered a driver twice under two names.
--- include/sysemu/char.h | 1 + qemu-char.c | 98 ++++++++++++++++++++++++++++++--------------------- 2 files changed, 59 insertions(+), 40 deletions(-)
include/sysemu/char.h +1 -0
@@ -476,6 +476,7 @@ void qemu_chr_set_feature(CharDriverState *chr,QemuOpts *qemu_chr_parse_compat (const char *label,const char *filename); typedef struct CharDriver { + const char *alias; ChardevBackendKind kind; void (*parse)(QemuOpts *opts, ChardevBackend *backend, Error **errp); CharDriverState *(*create)(const char *id,
qemu-char.c +58 -40
171 lines not on this page · raw message
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH 06/20] char: use a static array for backends
Quoted 4 lines · Marc-André Lureau
Number and kinds of backends is known at compile-time, use a fixed-sized static array to simplify iterations & lookups. Add an alias field to the CharDriver structure to cover the cases where we previously registered a driver twice under two names.
Except that 5/20 didn't register twice under two names, so my option 2 on that patch was floating that portion of this patch earlier.
Quoted 8 lines
Signed-off-by Marc-André Lureau <[email protected]>--- include/sysemu/char.h | 1 + qemu-char.c | 98 ++++++++++++++++++++++++++++++--------------------- 2 files changed, 59 insertions(+), 40 deletions(-)
qemu-char.c CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts, · line 4142
Quoted 6 lines
qemu-char.c +1
-2@@ -4134,17 +4139,20 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts, goto err; } -for (i = backends; i; i = i->next) { - cd = i->data; + cd =NULL ;
Dead assignment, since backends is a non-empty array so it will always be overwritten by the first iteration of the following loop.
Quoted 7 lines
qemu-char.c +4
-2+for (i =0 ; i <ARRAY_SIZE (backends); i++) { + cd = backends[i]; -if (strcmp (ChardevBackendKind_lookup[cd->kind], -qemu_opt_get (opts,"backend" )) ==0 ) { +if (!cd) { +continue ;
qemu-char.c CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts, · line 4154
Quoted 10 lines
qemu-char.c +4
-3+ } +if (g_str_equal (ChardevBackendKind_lookup[cd->kind], name) || + (g_strcmp0 (cd->alias, name) ==0 )) {break ; } } -if (i ==NULL ) { -error_setg (errp,"chardev: backend \"%s\" not found" , -qemu_opt_get (opts,"backend" )); +if (cd ==NULL || i >=ARRAY_SIZE (backends)) {
Simplify: 'if (i == ARRAY_SIZE(backends))' (whether cd is NULL at the end of the loop is irrelevant, you know it is non-NULL if you broke early on a match, but it is ALSO non-null if the last element of the array was non-NULL; and right now, our last element of the array is the 'memory' alias which is unconditionally present and thus non-NULL; also, i cannot grow greater than ARRAY_SIZE(), so == suffices rather than >=).
Quoted 16 lines
qemu-char.c +5
-7ChardevBackendInfoList *qmp_query_chardev_backends (Error **errp) {ChardevBackendInfoList *backend_list =NULL ; -CharDriver *c =NULL ; -GSList *i =NULL ; +const CharDriver *c; +int i; -for (i = backends; i; i = i->next) { -ChardevBackendInfoList *info =g_malloc0 (sizeof (*info)); - c = i->data; - info->value =g_malloc0 (sizeof (*info->value)); - info->value->name =g_strdup (ChardevBackendKind_lookup[c->kind]); +for (i =0 ; i <ARRAY_SIZE (backends); i++) { + c = backends[i]; +if (!c) {
qemu-char.c ChardevInfoList *qmp_query_chardev(Error **errp) · line 4386
Quoted 10 lines
qemu-char.c +7
-2+continue ; + } - info->next = backend_list; - backend_list = info; + backend_list =qmp_prepend_backend (backend_list, c, + ChardevBackendKind_lookup[c->kind]); +if (c->alias) { + backend_list =qmp_prepend_backend (backend_list, c, c->alias); + }
Hmm, I didn't account for this in the changes I suggested for option 2 of 5/20 (which means unless you further tweak it, I temporarily regressed the command to omit the aliases - but then again, taking your 5/20 as-is without either of my options omits the aliases and lists the canonical name twice).
Quoted 9 lines
qemu-char.c +0
-5@@ -4827,22 +4849,16 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend, goto out_error; } -for (i = backends; i; i = i->next) { - cd = i->data; - -if (cd->kind == backend->type) { - chr = cd->create (id, backend, ret, &be_opened, &local_err);
qemu-char.c ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend, · line 4855
Quoted 10 lines
qemu-char.c +4
-6-if (local_err) { -error_propagate (errp, local_err); - goto out_error; - } -break ; - } + cd = (int )backend->type >=0 && backend->type <ARRAY_SIZE (backends) ? + backends[backend->type] :NULL ; +if (cd ==NULL ) { +error_setg (errp,"chardev backend not available" );
Worth including %s and the user-provided name that failed lookup?
qemu-char.c static void register_types(void) · line 4949
Quoted 8 lines
qemu-char.c +1
-0@@ -4927,6 +4943,7 @@ static void register_types(void) #if defined HAVE_CHARDEV_SERIAL { .kind = CHARDEV_BACKEND_KIND_SERIAL, + .alias = "tty", .parse = qemu_chr_parse_serial, .create = qmp_chardev_open_serial, },
Unless you get rid of the duplicates (both my option 1 and option 2 of 5/20 did so), then you are registering 'serial/tty' once, and 'serial/NULL' a second time, where the second registration overwrites the first, and so the alias doesn't work.
qemu-char.c static void register_types(void) · line 4962
Quoted 8 lines
qemu-char.c +1
-0@@ -4939,6 +4956,7 @@ static void register_types(void) #ifdef HAVE_CHARDEV_PARPORT { .kind = CHARDEV_BACKEND_KIND_PARALLEL, + .alias = "parport", .parse = qemu_chr_parse_parallel, .create = qmp_chardev_open_parallel, },
And again.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 06/20] char: use a static array for backends
Hi
----- Original Message -----
Quoted 22 lines · Marc-André Lureau
Quoted 4 lines
Number and kinds of backends is known at compile-time, use a fixed-sized static array to simplify iterations & lookups. Add an alias field to the CharDriver structure to cover the cases where we previously registered a driver twice under two names.
Except that 5/20 didn't register twice under two names, so my option 2 on that patch was floating that portion of this patch earlier.
Quoted 13 lines
Signed-off-by Marc-André Lureau <[email protected]>--- include/sysemu/char.h | 1 + qemu-char.c | 98 ++++++++++++++++++++++++++++++--------------------- 2 files changed, 59 insertions(+), 40 deletions(-)qemu-char.c +0
-0@@ -4134,17 +4139,20 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts, goto err; }
Quoted 6 lines
qemu-char.c CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts, · line 4142
Quoted 3 lines
qemu-char.c +1
-2-for (i = backends; i; i = i->next) { - cd = i->data; + cd =NULL ;Dead assignment, since backends is a non-empty array so it will always be overwritten by the first iteration of the following loop.
ok, it feels more correct. I'll move it at declaration instead if you don't mind.
Quoted 19 lines
Quoted 8 lines
qemu-char.c +4
-2+for (i =0 ; i <ARRAY_SIZE (backends); i++) { + cd = backends[i]; -if (strcmp (ChardevBackendKind_lookup[cd->kind], -qemu_opt_get (opts,"backend" )) ==0 ) { +if (!cd) { +continue ;qemu-char.c CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts, · line 4154
Quoted 10 lines
qemu-char.c +4
-3+ } +if (g_str_equal (ChardevBackendKind_lookup[cd->kind], name) || + (g_strcmp0 (cd->alias, name) ==0 )) {break ; } } -if (i ==NULL ) { -error_setg (errp,"chardev: backend \"%s\" not found" , -qemu_opt_get (opts,"backend" )); +if (cd ==NULL || i >=ARRAY_SIZE (backends)) {
Quoted 6 lines
Simplify: 'if (i ==
ARRAY_SIZE(backends))' (whether cd is NULL at the end of the loop is irrelevant, you know it is non-NULL if you broke early on a match, but it is ALSO non-null if the last element of the array was non-NULL; and right now, our last element of the array is the 'memory' alias which is unconditionally present and thus non-NULL; also, i cannot grow greater thanARRAY_SIZE(), so == suffices rather than >=).
ok
Quoted 29 lines
Quoted 25 lines
qemu-char.c +9
-9ChardevBackendInfoList *qmp_query_chardev_backends (Error **errp) {ChardevBackendInfoList *backend_list =NULL ; -CharDriver *c =NULL ; -GSList *i =NULL ; +const CharDriver *c; +int i; -for (i = backends; i; i = i->next) { -ChardevBackendInfoList *info =g_malloc0 (sizeof (*info)); - c = i->data; - info->value =g_malloc0 (sizeof (*info->value)); - info->value->name =g_strdup (ChardevBackendKind_lookup[c->kind]); +for (i =0 ; i <ARRAY_SIZE (backends); i++) { + c = backends[i]; +if (!c) { +continue ; + } - info->next = backend_list; - backend_list = info; + backend_list = qmp_prepend_backend(backend_list, c, +ChardevBackendKind_lookup[c->kind]);
qemu-char.c ChardevInfoList *qmp_query_chardev(Error **errp) · line 4386
Quoted 3 lines
qemu-char.c +3
-0+if (c->alias) { + backend_list =qmp_prepend_backend (backend_list, c, c->alias); + }
Quoted 5 lines
Hmm, I didn't account for this in the changes I suggested for option 2 of 5/20 (which means unless you further tweak it, I temporarily regressed the command to omit the aliases - but then again, taking your 5/20 as-is without either of my options omits the aliases and lists the canonical name twice).
fixed in patch 5
Quoted 15 lines
Quoted 15 lines
qemu-char.c +0
-9@@ -4827,22 +4849,16 @@ ChardevReturn *qmp_chardev_add(const char *id,ChardevBackend *backend, goto out_error; } -for (i = backends; i; i = i->next) { - cd = i->data; - -if (cd->kind == backend->type) { - chr = cd->create (id, backend, ret, &be_opened, &local_err); -if (local_err) { -error_propagate (errp, local_err); - goto out_error; - }
Quoted 8 lines
qemu-char.c ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend, · line 4855
Quoted 6 lines
qemu-char.c +4
-2-break ; - } + cd = (int )backend->type >=0 && backend->type <ARRAY_SIZE (backends) ? + backends[backend->type] :NULL ; +if (cd ==NULL ) { +error_setg (errp,"chardev backend not available" );Worth including %s and the user-provided name that failed lookup?
It's improved with qom-ify patch
Quoted 14 lines
qemu-char.c static void register_types(void) · line 4949
Quoted 9 lines
qemu-char.c +1
-0@@ -4927,6 +4943,7 @@ static void register_types(void) #if defined HAVE_CHARDEV_SERIAL { .kind = CHARDEV_BACKEND_KIND_SERIAL, + .alias = "tty", .parse = qemu_chr_parse_serial, .create = qmp_chardev_open_serial, },Unless you get rid of the duplicates (both my option 1 and option 2 of 5/20 did so), then you are registering 'serial/tty' once, and 'serial/NULL' a second time, where the second registration overwrites the first, and so the alias doesn't work.
bad patch split :)
Quoted 11 lines
qemu-char.c static void register_types(void) · line 4962
Quoted 9 lines
qemu-char.c +1
-0@@ -4939,6 +4956,7 @@ static void register_types(void) #ifdef HAVE_CHARDEV_PARPORT { .kind = CHARDEV_BACKEND_KIND_PARALLEL, + .alias = "parport", .parse = qemu_chr_parse_parallel, .create = qmp_chardev_open_parallel, },And again.
thanks
PATCH 7/20 char: move callbacks in CharDriver
In reply to Marc-André LureauThis makes the code more declarative, and avoids duplicating the information on all instances.
--- include/sysemu/char.h | 46 ++--- backends/baum.c | 11 +- backends/msmouse.c | 11 +- backends/testdev.c | 8 +- gdbstub.c | 7 +- hw/bt/hci-csr.c | 8 +- qemu-char.c | 489 +++++++++++++++++++++++++++++--------------------- spice-qemu-char.c | 32 ++-- ui/console.c | 28 +-- ui/gtk.c | 11 +- 10 files changed, 381 insertions(+), 270 deletions(-)
include/sysemu/char.h +26 -20
@@ -85,24 +85,11 @@ typedef struct CharBackend {int fe_open; } CharBackend; +typedef struct CharDriver CharDriver ; +struct CharDriverState { +const CharDriver *driver;QemuMutex chr_write_lock; -int (*chr_write)(struct CharDriverState *s,const uint8_t *buf,int len); -int (*chr_sync_read)(struct CharDriverState *s, -const uint8_t *buf,int len); -GSource *(*chr_add_watch)(struct CharDriverState *s,GIOCondition cond); -void (*chr_update_read_handler)(struct CharDriverState *s, -GMainContext *context); -int (*chr_ioctl)(struct CharDriverState *s,int cmd,void *arg); -int (*get_msgfds)(struct CharDriverState *s,int * fds,int num); -int (*set_msgfds)(struct CharDriverState *s,int *fds,int num); -int (*chr_add_client)(struct CharDriverState *chr,int fd); -int (*chr_wait_connected)(struct CharDriverState *chr,Error **errp); -void (*chr_free)(struct CharDriverState *chr); -void (*chr_disconnect)(struct CharDriverState *chr); -void (*chr_accept_input)(struct CharDriverState *chr); -void (*chr_set_echo)(struct CharDriverState *chr,bool echo); -void (*chr_set_fe_open)(struct CharDriverState *chr,int fe_open);CharBackend *be;void *opaque;char *label;
@@ -125,7 +112,8 @@ struct CharDriverState {* * Returns: a newly allocated CharDriverState, or NULL on error. */ -CharDriverState *qemu_chr_alloc (ChardevCommon *backend,Error **errp); +CharDriverState *qemu_chr_alloc (const CharDriver *driver, +ChardevCommon *backend,Error **errp);/** * @qemu_chr_new_from_opts:
@@ -475,15 +463,33 @@ void qemu_chr_set_feature(CharDriverState *chr, CharDriverFeature feature);QemuOpts *qemu_chr_parse_compat (const char *label,const char *filename); -typedef struct CharDriver { +struct CharDriver {const char *alias;ChardevBackendKind kind;void (*parse)(QemuOpts *opts,ChardevBackend *backend,Error **errp); -CharDriverState *(*create)(const char *id, +CharDriverState *(*create)(const CharDriver *driver, +const char *id,ChardevBackend *backend,ChardevReturn *ret,bool *be_opened,Error **errp); -}CharDriver ; + +int (*chr_write)(struct CharDriverState *s,const uint8_t *buf,int len); +int (*chr_sync_read)(struct CharDriverState *s, +const uint8_t *buf,int len); +GSource *(*chr_add_watch)(struct CharDriverState *s,GIOCondition cond); +void (*chr_update_read_handler)(struct CharDriverState *s, +GMainContext *context); +int (*chr_ioctl)(struct CharDriverState *s,int cmd,void *arg); +int (*get_msgfds)(struct CharDriverState *s,int * fds,int num); +int (*set_msgfds)(struct CharDriverState *s,int *fds,int num); +int (*chr_add_client)(struct CharDriverState *chr,int fd); +int (*chr_wait_connected)(struct CharDriverState *chr,Error **errp); +void (*chr_free)(struct CharDriverState *chr); +void (*chr_disconnect)(struct CharDriverState *chr); +void (*chr_accept_input)(struct CharDriverState *chr); +void (*chr_set_echo)(struct CharDriverState *chr,bool echo); +void (*chr_set_fe_open)(struct CharDriverState *chr,int fe_open); +};void register_char_driver (const CharDriver *driver);
backends/baum.c +6 -5
@@ -622,7 +622,8 @@ static void baum_free(struct CharDriverState *chr)g_free (baum); } -static CharDriverState *chr_baum_init(const char *id, +static CharDriverState *chr_baum_init(const CharDriver *driver, + const char *id, ChardevBackend *backend, ChardevReturn *ret, bool *be_opened,
@@ -633,7 +634,7 @@ static CharDriverState *chr_baum_init(const char *id,CharDriverState *chr;brlapi_handle_t *handle; - chr =qemu_chr_alloc (common, errp); + chr =qemu_chr_alloc (driver, common, errp);if (!chr) {return NULL ; }
@@ -641,9 +642,6 @@ static CharDriverState *chr_baum_init(const char *id, baum->chr = chr; chr->opaque = baum; - chr->chr_write = baum_write; - chr->chr_accept_input = baum_accept_input; - chr->chr_free = baum_free; handle =g_malloc0 (brlapi_getHandleSize ()); baum->brlapi = handle;
@@ -674,6 +672,9 @@ static void register_types(void)static const CharDriver driver = { .kind =CHARDEV_BACKEND_KIND_BRAILLE , .create = chr_baum_init, + .chr_write = baum_write, + .chr_accept_input = baum_accept_input, + .chr_free = baum_free, };register_char_driver (&driver);
backends/msmouse.c +6 -5
@@ -148,7 +148,8 @@ static QemuInputHandler msmouse_handler = { .sync = msmouse_input_sync, }; -static CharDriverState *qemu_chr_open_msmouse(const char *id, +static CharDriverState *qemu_chr_open_msmouse(const CharDriver *driver, + const char *id, ChardevBackend *backend, ChardevReturn *ret, bool *be_opened,
@@ -158,13 +159,10 @@ static CharDriverState *qemu_chr_open_msmouse(const char *id,MouseState *mouse;CharDriverState *chr; - chr =qemu_chr_alloc (common, errp); + chr =qemu_chr_alloc (driver, common, errp);if (!chr) {return NULL ; } - chr->chr_write = msmouse_chr_write; - chr->chr_free = msmouse_chr_free; - chr->chr_accept_input = msmouse_chr_accept_input; *be_opened = false; mouse =g_new0 (MouseState,1 );
@@ -182,6 +180,9 @@ static void register_types(void)static const CharDriver driver = { .kind =CHARDEV_BACKEND_KIND_MSMOUSE , .create = qemu_chr_open_msmouse, + .chr_write = msmouse_chr_write, + .chr_accept_input = msmouse_chr_accept_input, + .chr_free = msmouse_chr_free, };register_char_driver (&driver); }
backends/testdev.c +5 -3
@@ -109,7 +109,8 @@ static void testdev_free(struct CharDriverState *chr)g_free (testdev); } -static CharDriverState *chr_testdev_init(const char *id, +static CharDriverState *chr_testdev_init(const CharDriver *driver, + const char *id, ChardevBackend *backend, ChardevReturn *ret, bool *be_opened,
@@ -121,9 +122,8 @@ static CharDriverState *chr_testdev_init(const char *id, testdev =g_new0 (TestdevCharState,1 ); testdev->chr = chr =g_new0 (CharDriverState,1 ); + chr->driver = driver; chr->opaque = testdev; - chr->chr_write = testdev_write; - chr->chr_free = testdev_free;return chr; }
@@ -133,6 +133,8 @@ static void register_types(void)static const CharDriver driver = { .kind =CHARDEV_BACKEND_KIND_TESTDEV , .create = chr_testdev_init, + .chr_write = testdev_write, + .chr_free = testdev_free, };register_char_driver (&driver); }
gdbstub.c +5 -2
@@ -1730,6 +1730,10 @@ int gdbserver_start(const char *device)CharDriverState *chr =NULL ;CharDriverState *mon_chr;ChardevCommon common = {0 }; +static const CharDriver driver = { + .kind =-1 , + .chr_write = gdb_monitor_write + };if (!device)return -1 ;
@@ -1762,8 +1766,7 @@ int gdbserver_start(const char *device)qemu_add_vm_change_state_handler (gdb_vm_state_change,NULL );/* Initialize a monitor terminal for gdb */ - mon_chr =qemu_chr_alloc (&common, &error_abort); - mon_chr->chr_write = gdb_monitor_write; + mon_chr =qemu_chr_alloc (&driver, &common, &error_abort);monitor_init (mon_chr,0 ); }else {if (qemu_chr_fe_get_driver (&s->chr)) {
hw/bt/hci-csr.c +6 -2
@@ -462,12 +462,16 @@ qemu_irq *csrhci_pins_get(CharDriverState *chr)CharDriverState *uart_hci_init (void ) { +static const CharDriver hci_driver = { + .kind =-1 , + .chr_write = csrhci_write, + .chr_ioctl = csrhci_ioctl, + };struct csrhci_s *s = (struct csrhci_s *)g_malloc0 (sizeof (struct csrhci_s )); s->chr.opaque = s; - s->chr.chr_write = csrhci_write; - s->chr.chr_ioctl = csrhci_ioctl; + s->chr.driver = &hci_driver; s->hci =qemu_next_hci (); s->hci->opaque = s;
qemu-char.c +284 -205
1,037 lines not on this page · raw message
spice-qemu-char.c +19 -13
@@ -260,16 +260,15 @@ static void spice_chr_accept_input(struct CharDriverState *chr)spice_server_char_device_wakeup (&s->sin); } -static CharDriverState *chr_open (const char *subtype, -void (*set_fe_open)(struct CharDriverState *, -int ), +static CharDriverState *chr_open (const CharDriver *driver, +const char *subtype,ChardevCommon *backend,Error **errp) {CharDriverState *chr;SpiceCharDriver *s; - chr =qemu_chr_alloc (backend, errp); + chr =qemu_chr_alloc (driver, backend, errp);if (!chr) {return NULL ; }
@@ -278,18 +277,14 @@ static CharDriverState *chr_open(const char *subtype, s->active = false; s->sin.subtype =g_strdup (subtype); chr->opaque = s; - chr->chr_write = spice_chr_write; - chr->chr_add_watch = spice_chr_add_watch; - chr->chr_free = spice_chr_free; - chr->chr_set_fe_open = set_fe_open; - chr->chr_accept_input = spice_chr_accept_input;QLIST_INSERT_HEAD (&spice_chars, s, next);return chr; } -static CharDriverState *qemu_chr_open_spice_vmc(const char *id, +static CharDriverState *qemu_chr_open_spice_vmc(const CharDriver *driver, + const char *id, ChardevBackend *backend, ChardevReturn *ret, bool *be_opened,
@@ -312,11 +307,12 @@ static CharDriverState *qemu_chr_open_spice_vmc(const char *id, } *be_opened = false; -return chr_open (type, spice_vmc_set_fe_open, common, errp); +return chr_open (driver, type, common, errp); }#if SPICE_SERVER_VERSION >=0x000c02 -static CharDriverState *qemu_chr_open_spice_port(const char *id, +static CharDriverState *qemu_chr_open_spice_port(const CharDriver *driver, + const char *id, ChardevBackend *backend, ChardevReturn *ret, bool *be_opened,
@@ -333,7 +329,7 @@ static CharDriverState *qemu_chr_open_spice_port(const char *id,return NULL ; } - chr =chr_open ("port" , spice_port_set_fe_open, common, errp); + chr =chr_open (driver,"port" , common, errp);if (!chr) {return NULL ; }
@@ -393,11 +389,21 @@ static void register_types(void) .kind = CHARDEV_BACKEND_KIND_SPICEVMC, .parse = qemu_chr_parse_spice_vmc, .create = qemu_chr_open_spice_vmc, + .chr_write = spice_chr_write, + .chr_add_watch = spice_chr_add_watch, + .chr_set_fe_open = spice_vmc_set_fe_open, + .chr_accept_input = spice_chr_accept_input, + .chr_free = spice_chr_free, };static const CharDriver port_driver = { .kind =CHARDEV_BACKEND_KIND_SPICEPORT , .parse = qemu_chr_parse_spice_port, .create = qemu_chr_open_spice_port, + .chr_write = spice_chr_write, + .chr_add_watch = spice_chr_add_watch, + .chr_set_fe_open = spice_port_set_fe_open, + .chr_accept_input = spice_chr_accept_input, + .chr_free = spice_chr_free, };register_char_driver (&vmc_driver);register_char_driver (&port_driver);
ui/console.c +17 -11
@@ -1051,6 +1051,10 @@ static int console_puts(CharDriverState *chr, const uint8_t *buf, int len)QemuConsole *s = chr->opaque;int i; +if (!s->ds) { +return 0 ; + } + s->update_x0 = s->width *FONT_WIDTH ; s->update_y0 = s->height *FONT_HEIGHT ; s->update_x1 =0 ;
@@ -2000,8 +2004,6 @@ static void text_console_do_init(CharDriverState *chr, DisplayState *ds) s = chr->opaque; - chr->chr_write = console_puts; - s->out_fifo.buf = s->out_fifo_buf; s->out_fifo.buf_size =sizeof (s->out_fifo_buf); s->kbd_timer =timer_new_ms (QEMU_CLOCK_REALTIME , kbd_send_chars, s);
@@ -2048,6 +2050,8 @@ static void text_console_do_init(CharDriverState *chr, DisplayState *ds)qemu_chr_be_generic_open (chr); } +static const CharDriver vc_driver; +static CharDriverState *text_console_init (ChardevVC *vc,Error **errp) {ChardevCommon *common =qapi_ChardevVC_base (vc);
@@ -2056,7 +2060,7 @@ static CharDriverState *text_console_init(ChardevVC *vc, Error **errp)unsigned width =0 ;unsigned height =0 ; - chr =qemu_chr_alloc (common, errp); + chr =qemu_chr_alloc (&vc_driver, common, errp);if (!chr) {return NULL ; }
@@ -2089,7 +2093,6 @@ static CharDriverState *text_console_init(ChardevVC *vc, Error **errp) s->chr = chr; chr->opaque = s; - chr->chr_set_echo = text_console_set_echo;if (display_state) {text_console_do_init (chr, display_state);
@@ -2099,7 +2102,8 @@ static CharDriverState *text_console_init(ChardevVC *vc, Error **errp)static VcHandler *vc_handler = text_console_init; -static CharDriverState *vc_init (const char *id,ChardevBackend *backend, +static CharDriverState *vc_init (const CharDriver *driver, +const char *id,ChardevBackend *backend,ChardevReturn *ret,bool *be_opened,Error **errp) {
@@ -2191,14 +2195,16 @@ static const TypeInfo qemu_console_info = { .class_size = sizeof(QemuConsoleClass), }; +static const CharDriver vc_driver = { + .kind =CHARDEV_BACKEND_KIND_VC , + .parse = qemu_chr_parse_vc, + .create = vc_init, + .chr_write = console_puts, + .chr_set_echo = text_console_set_echo, +}; +static void register_types (void ) { -static const CharDriver vc_driver = { - .kind =CHARDEV_BACKEND_KIND_VC , - .parse = qemu_chr_parse_vc, - .create = vc_init, - }; -type_register_static (&qemu_console_info);register_char_driver (&vc_driver); }
ui/gtk.c +7 -4
@@ -1703,6 +1703,12 @@ static CharDriverState *vcs[MAX_VCS];static CharDriverState *gd_vc_handler (ChardevVC *vc,Error **errp) { +static const CharDriver gd_vc_driver = { + .kind =CHARDEV_BACKEND_KIND_VC , + .chr_write = gd_vc_chr_write, + .chr_set_echo = gd_vc_chr_set_echo, + }; +ChardevCommon *common =qapi_ChardevVC_base (vc);CharDriverState *chr;
@@ -1711,14 +1717,11 @@ static CharDriverState *gd_vc_handler(ChardevVC *vc, Error **errp)return NULL ; } - chr =qemu_chr_alloc (common, errp); + chr =qemu_chr_alloc (&gd_vc_driver, common, errp);if (!chr) {return NULL ; } - chr->chr_write = gd_vc_chr_write; - chr->chr_set_echo = gd_vc_chr_set_echo; -/* Temporary, until gd_vc_vte_init runs. */ chr->opaque =g_new0 (VirtualConsole,1 );
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH 07/20] char: move callbacks in CharDriver
Quoted 20 lines · Marc-André Lureau
This makes the code more declarative, and avoids duplicating the information on all instances.
Signed-off-by Marc-André Lureau <[email protected]>--- include/sysemu/char.h | 46 ++--- backends/baum.c | 11 +- backends/msmouse.c | 11 +- backends/testdev.c | 8 +- gdbstub.c | 7 +- hw/bt/hci-csr.c | 8 +- qemu-char.c | 489 +++++++++++++++++++++++++++++--------------------- spice-qemu-char.c | 32 ++-- ui/console.c | 28 +-- ui/gtk.c | 11 +- 10 files changed, 381 insertions(+), 270 deletions(-)+++
b/gdbstub.c
gdbstub.c int gdbserver_start(const char *device) · line 1735
Quoted 6 lines
gdbstub.c +3
-0@@ -1730,6 +1730,10 @@ int gdbserver_start(const char *device)CharDriverState *chr =NULL ;CharDriverState *mon_chr;ChardevCommon common = {0 }; +static const CharDriver driver = { + .kind =-1 , + .chr_write = gdb_monitor_write
Missing a trailing comma.
qemu-char.c static CharDriverState *qemu_chr_open_stdio(const char *id, · line 2642
Quoted 6 lines
qemu-char.c +1
-1@@ -2624,7 +2639,7 @@ static CharDriverState *qemu_chr_open_stdio(const char *id,int is_console =0 ;ChardevCommon *common =qapi_ChardevStdio_base (backend->u.stdio.data); - chr =qemu_chr_alloc (common, errp); + chr =qemu_chr_alloc (driver, common, errp);
Minor, but it looks like there's not much to align to anymore, and we could trim it to one space while touching it. But I don't care if it stays the same, either, given the weird alignment on is_console a bit earlier.
Quoted 6 lines
qemu-char.c +6
-0+static const CharDriver ringbuf_driver = { + .kind =CHARDEV_BACKEND_KIND_RINGBUF , + .parse = qemu_chr_parse_ringbuf, + .create = qemu_chr_open_ringbuf, + .chr_write = ringbuf_chr_write, + .chr_free = ringbuf_chr_free,
qemu-char.c static void qemu_chr_parse_ringbuf(QemuOpts *opts, ChardevBackend *backend, · line 4011
Quoted 10 lines
qemu-char.c +10
-0+}; + +/* Bug-compatibility: */ +static const CharDriver memory_driver = { + .kind =CHARDEV_BACKEND_KIND_MEMORY , + .parse = qemu_chr_parse_ringbuf, + .create = qemu_chr_open_ringbuf, + .chr_write = ringbuf_chr_write, + .chr_free = ringbuf_chr_free, +};
Again, depending on what we decide to do about the QAPI, we could delete the 'memory' value from QMP and use .alias to still support it from the command line, for just one driver instead of two here, if desired. But not a show-stopper if we don't make that decision before this patch, though.
Quoted 12 lines
qemu-char.c +0
-12-#if defined HAVE_CHARDEV_SERIAL - { - .kind = CHARDEV_BACKEND_KIND_SERIAL, - .alias = "tty", - .parse = qemu_chr_parse_serial, - .create = qmp_chardev_open_serial, - }, - { - .kind = CHARDEV_BACKEND_KIND_SERIAL, - .parse = qemu_chr_parse_serial, - .create = qmp_chardev_open_serial, - },
qemu-char.c void qemu_chr_cleanup(void) · line 5063
Quoted 10 lines
qemu-char.c +9
-0+static const CharDriver *drivers[] = { + &null_driver, + &socket_driver, + &udp_driver, + &ringbuf_driver, + &file_driver, + &stdio_driver, +#ifdef HAVE_CHARDEV_SERIAL + &serial_driver, #endif
Will be some rebase churn here as you deal with my comments on earlier patches, but they should be obvious enough that it shouldn't affect my review.
With nits fixed,
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 8/20 char: fold single-user functions in caller
In reply to Marc-André LureauThis shortens the code a bit.
--- qemu-char.c | 95 +++++++++++++++++++------------------------------------------ 1 file changed, 29 insertions(+), 66 deletions(-)
qemu-char.c +29 -66
@@ -1886,22 +1886,6 @@ static void qemu_chr_free_tty(CharDriverState *chr) {fd_chr_free (chr); } - -static CharDriverState *qemu_chr_open_tty_fd (const CharDriver *driver, -int fd, -ChardevCommon *backend, -bool *be_opened, -Error **errp) -{ -CharDriverState *chr; - -tty_serial_init (fd,115200 ,'N' ,8 ,1 ); - chr =qemu_chr_open_fd (driver, fd, fd, backend, errp); -if (!chr) { -return NULL ; - } -return chr; -}#endif /* __linux__ || __sun__ */ #if defined(__linux__)
@@ -2322,29 +2306,6 @@ static int win_chr_poll(void *opaque)return 0 ; } -static CharDriverState *qemu_chr_open_win_path (const CharDriver *driver, -const char *filename, -ChardevCommon *backend, -Error **errp) -{ -CharDriverState *chr; -WinCharState *s; - - chr =qemu_chr_alloc (driver, backend, errp); -if (!chr) { -return NULL ; - } - s =g_new0 (WinCharState,1 ); - chr->opaque = s; - -if (win_chr_init (chr, filename, errp) <0 ) { -g_free (s); -qemu_chr_free_common (chr); -return NULL ; - } -return chr; -} -static int win_chr_pipe_poll (void *opaque) {CharDriverState *chr = opaque;
@@ -2801,30 +2762,6 @@ static void udp_chr_free(CharDriverState *chr)qemu_chr_be_event (chr,CHR_EVENT_CLOSED ); } -static CharDriverState *qemu_chr_open_udp (const CharDriver *driver, -QIOChannelSocket *sioc, -ChardevCommon *backend, -bool *be_opened, -Error **errp) -{ -CharDriverState *chr =NULL ; -NetCharDriver *s =NULL ; - - chr =qemu_chr_alloc (driver, backend, errp); -if (!chr) { -return NULL ; - } - s =g_new0 (NetCharDriver,1 ); - - s->ioc =QIO_CHANNEL (sioc); - s->bufcnt =0 ; - s->bufptr =0 ; - chr->opaque = s; -/* be isn't opened until we get a connection */ - *be_opened = false; -return chr; -} -/***********************************************************/ /* TCP Net console */
@@ -4611,8 +4548,23 @@ static CharDriverState *qmp_chardev_open_serial(const CharDriver *driver, {ChardevHostdev *serial = backend->u.serial.data;ChardevCommon *common =qapi_ChardevHostdev_base (serial); +CharDriverState *chr; +WinCharState *s; + + chr =qemu_chr_alloc (driver, common, errp); +if (!chr) { +return NULL ; + } -return qemu_chr_open_win_path (driver, serial->device, common, errp); + s =g_new0 (WinCharState,1 ); + chr->opaque = s; +if (win_chr_init (chr, serial->device, errp) <0 ) { +g_free (s); +qemu_chr_free_common (chr); +return NULL ; + } + +return chr; }#else /* WIN32 */
@@ -4681,8 +4633,9 @@ static CharDriverState *qmp_chardev_open_serial(const CharDriver *driver, return NULL; }qemu_set_nonblock (fd); +tty_serial_init (fd,115200 ,'N' ,8 ,1 ); -return qemu_chr_open_tty_fd (driver, fd, common, be_opened, errp); +return qemu_chr_open_fd (driver, fd, fd, common, errp); }#endif
@@ -4938,6 +4891,7 @@ static CharDriverState *qmp_chardev_open_udp(const CharDriver *driver,QIOChannelSocket *sioc =qio_channel_socket_new ();char *name;CharDriverState *chr; +NetCharDriver *s; if (qio_channel_socket_dgram_sync(sioc, udp->local, udp->remote,
@@ -4946,12 +4900,21 @@ static CharDriverState *qmp_chardev_open_udp(const CharDriver *driver,return NULL ; } - chr =qemu_chr_open_udp (driver, sioc, common, be_opened, errp); + chr =qemu_chr_alloc (driver, common, errp); +if (!chr) { +return NULL ; + } name =g_strdup_printf ("chardev-udp-%s" , chr->label);qio_channel_set_name (QIO_CHANNEL (sioc), name);g_free (name); + s =g_new0 (NetCharDriver,1 ); + s->ioc =QIO_CHANNEL (sioc); + chr->opaque = s; +/* be isn't opened until we get a connection */ + *be_opened = false; +return chr; }
Signature · 1 line
2.11.0
PATCH 9/20 char: introduce generic qemu_chr_get_kind()
In reply to Marc-André LureauThis allows to remove the "is_mux" field from CharDriverState.
--- include/sysemu/char.h | 15 +++++++++++++-- monitor.c | 2 +- qemu-char.c | 21 ++++++++++----------- 3 files changed, 24 insertions(+), 14 deletions(-)
include/sysemu/char.h +13 -2
@@ -96,7 +96,6 @@ struct CharDriverState {char *filename;int logfd;int be_open; -int is_mux;guint fd_in_tag;bool replay;DECLARE_BITMAP (features,QEMU_CHAR_FEATURE_LAST );
@@ -455,7 +454,19 @@ void qemu_chr_be_generic_open(CharDriverState *s);void qemu_chr_fe_accept_input (CharBackend *be);int qemu_chr_add_client (CharDriverState *s,int fd);CharDriverState *qemu_chr_find (const char *name); -bool chr_is_ringbuf (const CharDriverState *chr); + +/** +* @qemu_chr_get_kind: +* +* Returns the kind of char backend, or -1 if unspecified. +*/ +ChardevBackendKind qemu_chr_get_kind (const CharDriverState *chr); + +static inline bool qemu_chr_is_ringbuf (const CharDriverState *chr) +{ +return qemu_chr_get_kind (chr) ==CHARDEV_BACKEND_KIND_RINGBUF || +qemu_chr_get_kind (chr) ==CHARDEV_BACKEND_KIND_MEMORY ; +}bool qemu_chr_has_feature (CharDriverState *chr,CharDriverFeature feature);
monitor.c +1 -1
@@ -3194,7 +3194,7 @@ static void ringbuf_completion(ReadLineState *rs, const char *str)if (!strncmp (chr_info->label, str, len)) {CharDriverState *chr =qemu_chr_find (chr_info->label); -if (chr &&chr_is_ringbuf (chr)) { +if (chr &&qemu_chr_is_ringbuf (chr)) {readline_add_completion (rs, chr_info->label); } }
qemu-char.c +10 -11
@@ -781,7 +781,7 @@ static void muxes_realize_done(Notifier *notifier, void *unused)CharDriverState *chr; QTAILQ_FOREACH(chr, &chardevs, next) { -if (chr->is_mux) { +if (qemu_chr_get_kind (chr) ==CHARDEV_BACKEND_KIND_MUX ) {MuxDriver *d = chr->opaque;int i;
@@ -885,7 +885,6 @@ static CharDriverState *qemu_chr_open_mux(const CharDriver *driver,* set of muxes */ *be_opened = muxes_realized; - chr->is_mux =1 ;if (!qemu_chr_fe_init (&d->chr, drv, errp)) {qemu_chr_free (chr);return NULL ;
@@ -903,7 +902,7 @@ bool qemu_chr_fe_init(CharBackend *b, CharDriverState *s, Error **errp) {int tag =0 ; -if (s->is_mux) { +if (qemu_chr_get_kind (s) ==CHARDEV_BACKEND_KIND_MUX ) {MuxDriver *d = s->opaque;if (d->mux_cnt >=MAX_MUX ) {
@@ -930,7 +929,7 @@ unavailable:static bool qemu_chr_is_busy (CharDriverState *s) { -if (s->is_mux) { +if (qemu_chr_get_kind (s) ==CHARDEV_BACKEND_KIND_MUX ) {MuxDriver *d = s->opaque;return d->mux_cnt >=0 ; }else {
@@ -945,7 +944,7 @@ void qemu_chr_fe_deinit(CharBackend *b)if (b->chr) {qemu_chr_fe_set_handlers (b,NULL ,NULL ,NULL ,NULL ,NULL , true); b->chr->be =NULL ; -if (b->chr->is_mux) { +if (qemu_chr_get_kind (b->chr) ==CHARDEV_BACKEND_KIND_MUX ) {MuxDriver *d = b->chr->opaque; d->backends[b->tag] =NULL ; }
@@ -996,7 +995,7 @@ void qemu_chr_fe_set_handlers(CharBackend *b, } } -if (s->is_mux) { +if (qemu_chr_get_kind (s) ==CHARDEV_BACKEND_KIND_MUX ) {mux_chr_set_handlers (s, context); } }
@@ -1007,7 +1006,7 @@ void qemu_chr_fe_take_focus(CharBackend *b)return ; } -if (b->chr->is_mux) { +if (qemu_chr_get_kind (b->chr) ==CHARDEV_BACKEND_KIND_MUX ) {mux_set_focus (b->chr->opaque, b->tag); } }
@@ -3552,9 +3551,9 @@ fail:return NULL ; } -bool chr_is_ringbuf (const CharDriverState *chr) +ChardevBackendKind qemu_chr_get_kind (const CharDriverState *chr) { -return chr->driver->chr_write == ringbuf_chr_write; +return chr->driver->kind; } void qmp_ringbuf_write(const char *device, const char *data,
@@ -3572,7 +3571,7 @@ void qmp_ringbuf_write(const char *device, const char *data,return ; } -if (!chr_is_ringbuf (chr)) { +if (!qemu_chr_is_ringbuf (chr)) {error_setg (errp,"%s is not a ringbuf device" , device);return ; }
@@ -3616,7 +3615,7 @@ char *qmp_ringbuf_read(const char *device, int64_t size,return NULL ; } -if (!chr_is_ringbuf (chr)) { +if (!qemu_chr_is_ringbuf (chr)) {error_setg (errp,"%s is not a ringbuf device" , device);return NULL ; }
Signature · 1 line
2.11.0
PATCH 10/20 char: use a feature bit for replay
In reply to Marc-André LureauUse a feature flag rather than a structure field for "replay".
--- include/sysemu/char.h | 3 ++- qemu-char.c | 33 ++++++++++++++++++++------------- 2 files changed, 22 insertions(+), 14 deletions(-)
include/sysemu/char.h +2 -1
@@ -69,6 +69,8 @@ typedef enum {/* Whether it is possible to send/recv file descriptors * over the data channel */ QEMU_CHAR_FEATURE_FD_PASS , +/* Whether replay or record mode is enabled */ +QEMU_CHAR_FEATURE_REPLAY ,QEMU_CHAR_FEATURE_LAST , } CharDriverFeature;
@@ -97,7 +99,6 @@ struct CharDriverState {int logfd;int be_open;guint fd_in_tag; -bool replay;DECLARE_BITMAP (features,QEMU_CHAR_FEATURE_LAST );QTAILQ_ENTRY (CharDriverState) next; };
qemu-char.c +20 -13
@@ -277,6 +277,11 @@ static int qemu_chr_fe_write_buffer(CharDriverState *s, const uint8_t *buf, intreturn res; } +static bool qemu_chr_replay (CharDriverState *chr) +{ +return qemu_chr_has_feature (chr,QEMU_CHAR_FEATURE_REPLAY ); +} +int qemu_chr_fe_write (CharBackend *be,const uint8_t *buf,int len) {CharDriverState *s = be->chr;
@@ -286,7 +291,7 @@ int qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, int len)return 0 ; } -if (s->replay && replay_mode ==REPLAY_MODE_PLAY ) { +if (qemu_chr_replay (s) && replay_mode ==REPLAY_MODE_PLAY ) {int offset;replay_char_write_event_load (&ret, &offset);assert (offset <= len);
@@ -303,7 +308,7 @@ int qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, int len)qemu_mutex_unlock (&s->chr_write_lock); -if (s->replay && replay_mode ==REPLAY_MODE_RECORD ) { +if (qemu_chr_replay (s) && replay_mode ==REPLAY_MODE_RECORD ) {replay_char_write_event_save (ret, ret <0 ?0 : ret); }
@@ -315,7 +320,7 @@ static int qemu_chr_write_all(CharDriverState *s, const uint8_t *buf, int len)int offset;int res; -if (s->replay && replay_mode ==REPLAY_MODE_PLAY ) { +if (qemu_chr_replay (s) && replay_mode ==REPLAY_MODE_PLAY ) {replay_char_write_event_load (&res, &offset);assert (offset <= len);qemu_chr_fe_write_buffer (s, buf, offset, &offset);
@@ -324,7 +329,7 @@ static int qemu_chr_write_all(CharDriverState *s, const uint8_t *buf, int len) res =qemu_chr_fe_write_buffer (s, buf, len, &offset); -if (s->replay && replay_mode ==REPLAY_MODE_RECORD ) { +if (qemu_chr_replay (s) && replay_mode ==REPLAY_MODE_RECORD ) {replay_char_write_event_save (res, offset); }
@@ -355,7 +360,7 @@ int qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf, int len)return 0 ; } -if (s->replay && replay_mode ==REPLAY_MODE_PLAY ) { +if (qemu_chr_replay (s) && replay_mode ==REPLAY_MODE_PLAY ) {return replay_char_read_all_load (buf); }
@@ -372,7 +377,7 @@ int qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf, int len) }if (res <0 ) { -if (s->replay && replay_mode ==REPLAY_MODE_RECORD ) { +if (qemu_chr_replay (s) && replay_mode ==REPLAY_MODE_RECORD ) {replay_char_read_all_save_error (res); }return res;
@@ -385,7 +390,7 @@ int qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf, int len) } } -if (s->replay && replay_mode ==REPLAY_MODE_RECORD ) { +if (qemu_chr_replay (s) && replay_mode ==REPLAY_MODE_RECORD ) {replay_char_read_all_save_buf (buf, offset); }return offset;
@@ -396,7 +401,7 @@ int qemu_chr_fe_ioctl(CharBackend *be, int cmd, void *arg)CharDriverState *s = be->chr;int res; -if (!s || !s->driver->chr_ioctl || s->replay) { +if (!s || !s->driver->chr_ioctl ||qemu_chr_replay (s)) { res = -ENOTSUP ; }else { res = s->driver->chr_ioctl (s, cmd, arg);
@@ -427,7 +432,7 @@ void qemu_chr_be_write_impl(CharDriverState *s, uint8_t *buf, int len)void qemu_chr_be_write (CharDriverState *s,uint8_t *buf,int len) { -if (s->replay) { +if (qemu_chr_replay (s)) {if (replay_mode ==REPLAY_MODE_PLAY ) {return ; }
@@ -442,7 +447,7 @@ int qemu_chr_fe_get_msgfd(CharBackend *be)CharDriverState *s = be->chr;int fd;int res = (qemu_chr_fe_get_msgfds (be, &fd,1 ) ==1 ) ? fd :-1 ; -if (s && s->replay) { +if (s &&qemu_chr_replay (s)) {fprintf (stderr,"Replay: get msgfd is not supported for serial devices yet\n" );exit (1 );
@@ -4244,8 +4249,10 @@ CharDriverState *qemu_chr_new(const char *label, const char *filename)CharDriverState *chr; chr =qemu_chr_new_noreplay (label, filename);if (chr) { - chr->replay = replay_mode !=REPLAY_MODE_NONE ; -if (chr->replay && chr->driver->chr_ioctl) { +if (replay_mode !=REPLAY_MODE_NONE ) { +qemu_chr_set_feature (chr,QEMU_CHAR_FEATURE_REPLAY ); + } +if (qemu_chr_replay (chr) && chr->driver->chr_ioctl) {fprintf (stderr,"Replay: ioctl is not supported for serial devices yet\n" ); }
@@ -4994,7 +5001,7 @@ void qmp_chardev_remove(const char *id, Error **errp)error_setg (errp,"Chardev '%s' is busy" , id);return ; } -if (chr->replay) { +if (qemu_chr_replay (chr)) {error_setg (errp,"Chardev '%s' cannot be unplugged in record/replay mode" , id);return ;
Signature · 1 line
2.11.0
PATCH 11/20 char: allocate CharDriverState as a single object
In reply to Marc-André LureauUse a single allocation for CharDriverState, this avoids extra allocations & pointers, and is a step towards more object-oriented CharDriver.
Gtk console is a bit peculiar, gd_vc_chr_set_echo() used to have a temporary VirtualConsole to save the echo bit. Instead now, we consider whether vcd->console is set or not, and restore the echo bit saved in VCDriverState when calling gd_vc_vte_init().
The casts added are temporary, they are replaced with QOM type-safe macros in a later patch in this series.
--- include/sysemu/char.h | 2 +- backends/baum.c | 23 ++--- backends/msmouse.c | 16 +-- backends/testdev.c | 22 ++-- gdbstub.c | 1 + hw/bt/hci-csr.c | 10 +- qemu-char.c | 280 ++++++++++++++++++++++++++------------------------ spice-qemu-char.c | 39 +++---- ui/console.c | 21 ++-- ui/gtk.c | 30 ++++-- 10 files changed, 230 insertions(+), 214 deletions(-)
include/sysemu/char.h +1 -1
@@ -93,7 +93,6 @@ struct CharDriverState {const CharDriver *driver;QemuMutex chr_write_lock;CharBackend *be; -void *opaque;char *label;char *filename;int logfd;
@@ -484,6 +483,7 @@ struct CharDriver { ChardevBackend *backend, ChardevReturn *ret, bool *be_opened, Error **errp); +size_t instance_size;int (*chr_write)(struct CharDriverState *s,const uint8_t *buf,int len); int (*chr_sync_read)(struct CharDriverState *s,
backends/baum.c +10 -13
@@ -85,7 +85,7 @@#define BUF_SIZE 256 typedef struct { - CharDriverState *chr; + CharDriverState parent; brlapi_handle_t *brlapi; int brlapi_fd;
@@ -255,7 +255,7 @@ static int baum_deferred_init(BaumDriverState *baum)/* The serial port can receive more of our data */ static void baum_accept_input (struct CharDriverState *chr) { -BaumDriverState *baum = chr->opaque; +BaumDriverState *baum = (BaumDriverState *)chr;int room, first;if (!baum->out_buf_used)
@@ -281,22 +281,23 @@ static void baum_accept_input(struct CharDriverState *chr)/* We want to send a packet */ static void baum_write_packet (BaumDriverState *baum,const uint8_t *buf,int len) { +CharDriverState *chr = (CharDriverState *)baum;uint8_t io_buf[1 +2 * len], *cur = io_buf;int room; *cur++ =ESC ;while (len--)if ((*cur++ = *buf++) ==ESC ) *cur++ =ESC ; - room =qemu_chr_be_can_write (baum->chr); + room =qemu_chr_be_can_write (chr); len = cur - io_buf;if (len <= room) {/* Fits */ -qemu_chr_be_write (baum->chr, io_buf, len); +qemu_chr_be_write (chr, io_buf, len); }else {int first;uint8_t out;/* Can't fit all, send what can be, and store the rest. */ -qemu_chr_be_write (baum->chr, io_buf, room); +qemu_chr_be_write (chr, io_buf, room); len -= room; cur = io_buf + room;if (len >BUF_SIZE - baum->out_buf_used) {
@@ -471,7 +472,7 @@ static int baum_eat_packet(BaumDriverState *baum, const uint8_t *buf, int len)/* The other end is writing some data. Store it and try to interpret */ static int baum_write (CharDriverState *chr,const uint8_t *buf,int len) { -BaumDriverState *baum = chr->opaque; +BaumDriverState *baum = (BaumDriverState *)chr;int tocopy, cur, eaten, orig_len = len;if (!len)
@@ -612,14 +613,13 @@ static void baum_chr_read(void *opaque)static void baum_free (struct CharDriverState *chr) { -BaumDriverState *baum = chr->opaque; +BaumDriverState *baum = (BaumDriverState *)chr;timer_free (baum->cellCount_timer);if (baum->brlapi) {brlapi__closeConnection (baum->brlapi);g_free (baum->brlapi); } -g_free (baum); } static CharDriverState *chr_baum_init(const CharDriver *driver,
@@ -638,10 +638,7 @@ static CharDriverState *chr_baum_init(const CharDriver *driver,if (!chr) {return NULL ; } - baum =g_malloc0 (sizeof (BaumDriverState)); - baum->chr = chr; - - chr->opaque = baum; + baum = (BaumDriverState *)chr; handle =g_malloc0 (brlapi_getHandleSize ()); baum->brlapi = handle;
@@ -663,13 +660,13 @@ static CharDriverState *chr_baum_init(const CharDriver *driver, fail_handle:g_free (handle);g_free (chr); -g_free (baum);return NULL ; }static void register_types (void ) {static const CharDriver driver = { + .instance_size =sizeof (BaumDriverState), .kind =CHARDEV_BACKEND_KIND_BRAILLE , .create = chr_baum_init, .chr_write = baum_write,
backends/msmouse.c +8 -8
@@ -31,7 +31,8 @@#define MSMOUSE_HI2 (n) (((n) & 0xc0) >> 6) typedef struct { - CharDriverState *chr; + CharDriverState parent; + QemuInputHandlerState *hs; int axis[INPUT_AXIS__MAX]; bool btns[INPUT_BUTTON__MAX];
@@ -42,7 +43,7 @@ typedef struct {static void msmouse_chr_accept_input (CharDriverState *chr) { -MouseState *mouse = chr->opaque; +MouseState *mouse = (MouseState *)chr;int len; len =qemu_chr_be_can_write (chr);
@@ -122,9 +123,10 @@ static void msmouse_input_event(DeviceState *dev, QemuConsole *src,static void msmouse_input_sync (DeviceState *dev) {MouseState *mouse = (MouseState *)dev; +CharDriverState *chr = (CharDriverState *)dev;msmouse_queue_event (mouse); -msmouse_chr_accept_input (mouse->chr); +msmouse_chr_accept_input (chr); }static int msmouse_chr_write (struct CharDriverState *s,const uint8_t *buf,int len)
@@ -135,10 +137,9 @@ static int msmouse_chr_write (struct CharDriverState *s, const uint8_t *buf, intstatic void msmouse_chr_free (struct CharDriverState *chr) { -MouseState *mouse = chr->opaque; +MouseState *mouse = (MouseState *)chr;qemu_input_handler_unregister (mouse->hs); -g_free (mouse); }static QemuInputHandler msmouse_handler = {
@@ -165,12 +166,10 @@ static CharDriverState *qemu_chr_open_msmouse(const CharDriver *driver, } *be_opened = false; - mouse =g_new0 (MouseState,1 ); + mouse = (MouseState *)chr; mouse->hs =qemu_input_handler_register ((DeviceState *)mouse, &msmouse_handler); - mouse->chr = chr; - chr->opaque = mouse;return chr; }
@@ -178,6 +177,7 @@ static CharDriverState *qemu_chr_open_msmouse(const CharDriver *driver,static void register_types (void ) {static const CharDriver driver = { + .instance_size =sizeof (MouseState), .kind =CHARDEV_BACKEND_KIND_MSMOUSE , .create = qemu_chr_open_msmouse, .chr_write = msmouse_chr_write,
backends/testdev.c +6 -16
@@ -30,7 +30,8 @@#define BUF_SIZE 32typedef struct { -CharDriverState *chr; +CharDriverState parent; +uint8_t in_buf[32 ];int in_buf_used; }TestdevCharState ;
@@ -79,7 +80,7 @@ static int testdev_eat_packet(TestdevCharState *testdev)/* The other end is writing some data. Store it and try to interpret */ static int testdev_write (CharDriverState *chr,const uint8_t *buf,int len) { -TestdevCharState *testdev = chr->opaque; +TestdevCharState *testdev = (TestdevCharState *)chr;int tocopy, eaten, orig_len = len;while (len) {
@@ -102,13 +103,6 @@ static int testdev_write(CharDriverState *chr, const uint8_t *buf, int len)return orig_len; } -static void testdev_free (struct CharDriverState *chr) -{ -TestdevCharState *testdev = chr->opaque; - -g_free (testdev); -} - static CharDriverState *chr_testdev_init(const CharDriver *driver, const char *id, ChardevBackend *backend,
@@ -116,14 +110,10 @@ static CharDriverState *chr_testdev_init(const CharDriver *driver,bool *be_opened, Error **errp) { - TestdevCharState *testdev; -CharDriverState *chr; - - testdev =g_new0 (TestdevCharState,1 ); - testdev->chr = chr =g_new0 (CharDriverState,1 ); + TestdevCharState *testdev = g_new0(TestdevCharState, 1);; +CharDriverState *chr = (CharDriverState *)testdev; chr->driver = driver; - chr->opaque = testdev;return chr; }
@@ -131,10 +121,10 @@ static CharDriverState *chr_testdev_init(const CharDriver *driver,static void register_types (void ) {static const CharDriver driver = { + .instance_size =sizeof (TestdevCharState), .kind =CHARDEV_BACKEND_KIND_TESTDEV , .create = chr_testdev_init, .chr_write = testdev_write, - .chr_free = testdev_free, };register_char_driver (&driver); }
gdbstub.c +1 -0
@@ -1731,6 +1731,7 @@ int gdbserver_start(const char *device)CharDriverState *mon_chr;ChardevCommon common = {0 };static const CharDriver driver = { + .instance_size =sizeof (CharDriverState), .kind =-1 , .chr_write = gdb_monitor_write };
hw/bt/hci-csr.c +5 -5
@@ -28,11 +28,11 @@#include "hw/bt.h" struct csrhci_s { +CharDriverState chr;int enable;qemu_irq *pins;int pin_state;int modem_state; -CharDriverState chr;#define FIFO_LEN 4096int out_start;int out_len;
@@ -314,7 +314,7 @@ static void csrhci_ready_for_next_inpkt(struct csrhci_s *s)static int csrhci_write (struct CharDriverState *chr,const uint8_t *buf,int len) { -struct csrhci_s *s = (struct csrhci_s *) chr->opaque; +struct csrhci_s *s = (struct csrhci_s *)chr;int total =0 ;if (!s->enable)
@@ -387,7 +387,7 @@ static void csrhci_out_hci_packet_acl(void *opaque,static int csrhci_ioctl (struct CharDriverState *chr,int cmd,void *arg) {QEMUSerialSetParams *ssp; -struct csrhci_s *s = (struct csrhci_s *) chr->opaque; +struct csrhci_s *s = (struct csrhci_s *) chr;int prev_state = s->modem_state;switch (cmd) {
@@ -455,7 +455,7 @@ static void csrhci_pins(void *opaque, int line, int level)qemu_irq *csrhci_pins_get (CharDriverState *chr) { -struct csrhci_s *s = (struct csrhci_s *) chr->opaque; +struct csrhci_s *s = (struct csrhci_s *) chr;return s->pins; }
@@ -463,6 +463,7 @@ qemu_irq *csrhci_pins_get(CharDriverState *chr)CharDriverState *uart_hci_init (void ) {static const CharDriver hci_driver = { + .instance_size =sizeof (struct csrhci_s ), .kind =-1 , .chr_write = csrhci_write, .chr_ioctl = csrhci_ioctl,
@@ -470,7 +471,6 @@ CharDriverState *uart_hci_init(void)struct csrhci_s *s = (struct csrhci_s *)g_malloc0 (sizeof (struct csrhci_s )); - s->chr.opaque = s; s->chr.driver = &hci_driver; s->hci =qemu_next_hci ();
qemu-char.c +144 -136
1,101 lines not on this page · raw message
spice-qemu-char.c +21 -18
@@ -7,7 +7,8 @@ typedef struct SpiceCharDriver { - CharDriverState* chr; + CharDriverState parent; + SpiceCharDeviceInstance sin; bool active; bool blocked;
@@ -27,17 +28,18 @@ static QLIST_HEAD(, SpiceCharDriver) spice_chars =static int vmc_write (SpiceCharDeviceInstance *sin,const uint8_t *buf,int len) {SpiceCharDriver *scd =container_of (sin, SpiceCharDriver, sin); +CharDriverState *chr = (CharDriverState *)scd;ssize_t out =0 ;ssize_t last_out;uint8_t * p = (uint8_t *)buf;while (len >0 ) { -int can_write =qemu_chr_be_can_write (scd->chr); +int can_write =qemu_chr_be_can_write (chr); last_out =MIN (len, can_write);if (last_out <=0 ) {break ; } -qemu_chr_be_write (scd->chr, p, last_out); +qemu_chr_be_write (chr, p, last_out); out += last_out; len -= last_out; p += last_out;
@@ -70,6 +72,7 @@ static int vmc_read(SpiceCharDeviceInstance *sin, uint8_t *buf, int len)static void vmc_event (SpiceCharDeviceInstance *sin,uint8_t event) {SpiceCharDriver *scd =container_of (sin, SpiceCharDriver, sin); +CharDriverState *chr = (CharDriverState *)scd;int chr_event;switch (event) {
@@ -81,20 +84,21 @@ static void vmc_event(SpiceCharDeviceInstance *sin, uint8_t event) }trace_spice_vmc_event (chr_event); -qemu_chr_be_event (scd->chr, chr_event); +qemu_chr_be_event (chr, chr_event); }#endif static void vmc_state (SpiceCharDeviceInstance *sin,int connected) {SpiceCharDriver *scd =container_of (sin, SpiceCharDriver, sin); +CharDriverState *chr = (CharDriverState *)scd; -if ((scd->chr->be_open && connected) || - (!scd->chr->be_open && !connected)) { +if ((chr->be_open && connected) || + (!chr->be_open && !connected)) {return ; } -qemu_chr_be_event (scd->chr, +qemu_chr_be_event (chr, connected ?CHR_EVENT_OPENED :CHR_EVENT_CLOSED ); }
@@ -168,7 +172,7 @@ static GSourceFuncs SpiceCharSourceFuncs = {static GSource *spice_chr_add_watch (CharDriverState *chr,GIOCondition cond) { -SpiceCharDriver *scd = chr->opaque; +SpiceCharDriver *scd = (SpiceCharDriver *)chr;SpiceCharSource *src;assert (cond &G_IO_OUT );
@@ -182,7 +186,7 @@ static GSource *spice_chr_add_watch(CharDriverState *chr, GIOCondition cond)static int spice_chr_write (CharDriverState *chr,const uint8_t *buf,int len) { -SpiceCharDriver *s = chr->opaque; +SpiceCharDriver *s = (SpiceCharDriver *)chr;int read_bytes;assert (s->datalen ==0 );
@@ -201,7 +205,7 @@ static int spice_chr_write(CharDriverState *chr, const uint8_t *buf, int len)static void spice_chr_free (struct CharDriverState *chr) { -SpiceCharDriver *s = chr->opaque; +SpiceCharDriver *s = (SpiceCharDriver *)chr;vmc_unregister_interface (s);QLIST_REMOVE (s, next);
@@ -210,12 +214,11 @@ static void spice_chr_free(struct CharDriverState *chr)#if SPICE_SERVER_VERSION >=0x000c02 g_free ((char *)s->sin.portname);#endif -g_free (s); }static void spice_vmc_set_fe_open (struct CharDriverState *chr,int fe_open) { -SpiceCharDriver *s = chr->opaque; +SpiceCharDriver *s = (SpiceCharDriver *)chr;if (fe_open) {vmc_register_interface (s); }else {
@@ -226,7 +229,7 @@ static void spice_vmc_set_fe_open(struct CharDriverState *chr, int fe_open)static void spice_port_set_fe_open (struct CharDriverState *chr,int fe_open) {#if SPICE_SERVER_VERSION >=0x000c02 -SpiceCharDriver *s = chr->opaque; +SpiceCharDriver *s = (SpiceCharDriver *)chr;if (fe_open) {spice_server_port_event (&s->sin,SPICE_PORT_EVENT_OPENED );
@@ -255,7 +258,7 @@ static void print_allowed_subtypes(void)static void spice_chr_accept_input (struct CharDriverState *chr) { -SpiceCharDriver *s = chr->opaque; +SpiceCharDriver *s = (SpiceCharDriver *)chr;spice_server_char_device_wakeup (&s->sin); }
@@ -272,11 +275,9 @@ static CharDriverState *chr_open(const CharDriver *driver,if (!chr) {return NULL ; } - s =g_malloc0 (sizeof (SpiceCharDriver)); - s->chr = chr; + s = (SpiceCharDriver *)chr; s->active = false; s->sin.subtype =g_strdup (subtype); - chr->opaque = s;QLIST_INSERT_HEAD (&spice_chars, s, next);
@@ -334,7 +335,7 @@ static CharDriverState *qemu_chr_open_spice_port(const CharDriver *driver,return NULL ; } *be_opened = false; - s = chr->opaque; + s = (SpiceCharDriver *)chr; s->sin.portname =g_strdup (name);return chr;
@@ -386,6 +387,7 @@ static void qemu_chr_parse_spice_port(QemuOpts *opts, ChardevBackend *backend,static void register_types (void ) {static const CharDriver vmc_driver = { + .instance_size =sizeof (SpiceCharDriver), .kind =CHARDEV_BACKEND_KIND_SPICEVMC , .parse = qemu_chr_parse_spice_vmc, .create = qemu_chr_open_spice_vmc,
@@ -396,6 +398,7 @@ static void register_types(void) .chr_free = spice_chr_free, };static const CharDriver port_driver = { + .instance_size =sizeof (SpiceCharDriver), .kind =CHARDEV_BACKEND_KIND_SPICEPORT , .parse = qemu_chr_parse_spice_port, .create = qemu_chr_open_spice_port,
ui/console.c +15 -6
@@ -1046,9 +1046,15 @@ void console_select(unsigned int index) } } +typedef struct VCDriverState { +CharDriverState parent; +QemuConsole *console; +}VCDriverState ; +static int console_puts (CharDriverState *chr,const uint8_t *buf,int len) { -QemuConsole *s = chr->opaque; +VCDriverState *drv = (VCDriverState *)chr; +QemuConsole *s = drv->console;int i;if (!s->ds) {
@@ -1958,7 +1964,8 @@ int qemu_console_get_height(QemuConsole *con, int fallback)static void text_console_set_echo (CharDriverState *chr,bool echo) { -QemuConsole *s = chr->opaque; +VCDriverState *drv = (VCDriverState *)chr; +QemuConsole *s = drv->console; s->echo = echo; }
@@ -1998,12 +2005,11 @@ static const GraphicHwOps text_console_ops = {static void text_console_do_init (CharDriverState *chr,DisplayState *ds) { -QemuConsole *s; +VCDriverState *drv = (VCDriverState *)chr; +QemuConsole *s = drv->console;int g_width =80 *FONT_WIDTH ;int g_height =24 *FONT_HEIGHT ; - s = chr->opaque; - s->out_fifo.buf = s->out_fifo_buf; s->out_fifo.buf_size =sizeof (s->out_fifo_buf); s->kbd_timer =timer_new_ms (QEMU_CLOCK_REALTIME , kbd_send_chars, s);
@@ -2056,6 +2062,7 @@ static CharDriverState *text_console_init(ChardevVC *vc, Error **errp) {ChardevCommon *common =qapi_ChardevVC_base (vc);CharDriverState *chr; +VCDriverState *drv;QemuConsole *s;unsigned width =0 ;unsigned height =0 ;
@@ -2092,7 +2099,8 @@ static CharDriverState *text_console_init(ChardevVC *vc, Error **errp) } s->chr = chr; - chr->opaque = s; + drv = (VCDriverState *)chr; + drv->console = s;if (display_state) {text_console_do_init (chr, display_state);
@@ -2196,6 +2204,7 @@ static const TypeInfo qemu_console_info = { };static const CharDriver vc_driver = { + .instance_size =sizeof (VCDriverState), .kind =CHARDEV_BACKEND_KIND_VC , .parse = qemu_chr_parse_vc, .create = vc_init,
ui/gtk.c +19 -11
@@ -181,6 +181,12 @@ struct GtkDisplayState {bool ignore_keys; }; +typedef struct VCDriverState { +CharDriverState parent; +VirtualConsole *console; +bool echo; +}VCDriverState ; +static void gd_grab_pointer (VirtualConsole *vc,const char *reason);static void gd_ungrab_pointer (GtkDisplayState *s);static void gd_grab_keyboard (VirtualConsole *vc,const char *reason);
@@ -1685,7 +1691,8 @@ static void gd_vc_adjustment_changed(GtkAdjustment *adjustment, void *opaque)static int gd_vc_chr_write (CharDriverState *chr,const uint8_t *buf,int len) { -VirtualConsole *vc = chr->opaque; +VCDriverState *vcd = (VCDriverState *)chr; +VirtualConsole *vc = vcd->console;vte_terminal_feed (VTE_TERMINAL (vc->vte.terminal), (const char *)buf, len);return len;
@@ -1693,9 +1700,14 @@ static int gd_vc_chr_write(CharDriverState *chr, const uint8_t *buf, int len)static void gd_vc_chr_set_echo (CharDriverState *chr,bool echo) { -VirtualConsole *vc = chr->opaque; +VCDriverState *vcd = (VCDriverState *)chr; +VirtualConsole *vc = vcd->console; - vc->vte.echo = echo; +if (vc) { + vc->vte.echo = echo; + }else { + vcd->echo = echo; + } }static int nb_vcs;
@@ -1704,6 +1716,7 @@ static CharDriverState *vcs[MAX_VCS];static CharDriverState *gd_vc_handler (ChardevVC *vc,Error **errp) {static const CharDriver gd_vc_driver = { + .instance_size =sizeof (VCDriverState), .kind =CHARDEV_BACKEND_KIND_VC , .chr_write = gd_vc_chr_write, .chr_set_echo = gd_vc_chr_set_echo,
@@ -1722,9 +1735,6 @@ static CharDriverState *gd_vc_handler(ChardevVC *vc, Error **errp)return NULL ; } -/* Temporary, until gd_vc_vte_init runs. */ - chr->opaque =g_new0 (VirtualConsole,1 ); - vcs[nb_vcs++] = chr;return chr;
@@ -1765,14 +1775,12 @@ static GSList *gd_vc_vte_init(GtkDisplayState *s, VirtualConsole *vc,GtkWidget *box;GtkWidget *scrollbar;GtkAdjustment *vadjustment; -VirtualConsole *tmp_vc = chr->opaque; +VCDriverState *vcd = (VCDriverState *)chr; vc->s = s; - vc->vte.echo = tmp_vc->vte.echo; - + vc->vte.echo = vcd->echo; vc->vte.chr = chr; - chr->opaque = vc; -g_free (tmp_vc); + vcd->console = vc;snprintf (buffer,sizeof (buffer),"vc%d" , idx); vc->label = g_strdup_printf("%s", vc->vte.chr->label
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH 11/20] char: allocate CharDriverState as a single object
Quoted 11 lines · Marc-André Lureau
Use a single allocation for CharDriverState, this avoids extra allocations & pointers, and is a step towards more object-oriented CharDriver.
Gtk console is a bit peculiar,
gd_vc_chr_set_echo()used to have a temporary VirtualConsole to save the echo bit. Instead now, we consider whethervcd->consoleis set or not, and restore the echo bit saved in VCDriverState when callinggd_vc_vte_init().The casts added are temporary, they are replaced with QOM type-safe macros in a later patch in this series.
Thanks; that commit message addition helps.
Quoted 3 lines
Signed-off-by Marc-André Lureau <[email protected]>Reviewed-by Eric Blake <[email protected]>
R-b stands.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 12/20 bt: use qemu_chr_alloc()
In reply to Marc-André LureauUse common allocator for CharDriverState.
Rename the now untouched parent field.
The casts added are temporary, they are replaced with QOM type-safe macros in a later patch in this series.
--- hw/bt/hci-csr.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
hw/bt/hci-csr.c +13 -6
@@ -26,9 +26,10 @@#include "hw/irq.h" #include "sysemu/bt.h" #include "hw/bt.h" +#include "qapi/error.h" struct csrhci_s { -CharDriverState chr; +CharDriverState parent;int enable;qemu_irq *pins;int pin_state;
@@ -78,7 +79,8 @@ enum {static inline void csrhci_fifo_wake (struct csrhci_s *s) { -CharBackend *be = s->chr.be; +CharDriverState *chr = (CharDriverState *)s; +CharBackend *be = chr->be;if (!s->enable || !s->out_len)return ;
@@ -468,10 +470,15 @@ CharDriverState *uart_hci_init(void) .chr_write = csrhci_write, .chr_ioctl = csrhci_ioctl, }; -struct csrhci_s *s = (struct csrhci_s *) -g_malloc0 (sizeof (struct csrhci_s )); +Error *err =NULL ; +ChardevCommon common = {0 , }; +CharDriverState *chr =qemu_chr_alloc (&hci_driver, &common, &err); +struct csrhci_s *s = (struct csrhci_s *)chr; - s->chr.driver = &hci_driver; +if (err) { +error_report_err (err); +return NULL ; + } s->hci =qemu_next_hci (); s->hci->opaque = s;
@@ -482,5 +489,5 @@ CharDriverState *uart_hci_init(void) s->pins =qemu_allocate_irqs (csrhci_pins, s, __csrhci_pins);csrhci_reset (s); -return &s->chr; +return chr; }
Signature · 1 line
2.11.0
PATCH 13/20 char: rename CharDriverState Chardev
In reply to Marc-André LureauPick a uniform chardev type name.
--- hw/lm32/lm32.h | 4 +- hw/lm32/milkymist-hw.h | 2 +- include/hw/arm/exynos4210.h | 2 +- include/hw/arm/omap.h | 6 +- include/hw/bt.h | 4 +- include/hw/char/cadence_uart.h | 2 +- include/hw/char/escc.h | 2 +- include/hw/char/pl011.h | 4 +- include/hw/char/serial.h | 4 +- include/hw/char/xilinx_uartlite.h | 2 +- include/hw/cris/etraxfs.h | 2 +- include/hw/devices.h | 2 +- include/hw/i386/pc.h | 2 +- include/hw/m68k/mcf.h | 4 +- include/hw/ppc/spapr_vio.h | 2 +- include/hw/qdev-properties.h | 2 +- include/hw/sh4/sh.h | 2 +- include/hw/sparc/grlib.h | 2 +- include/hw/xen/xen.h | 2 +- include/monitor/monitor.h | 2 +- include/qemu/typedefs.h | 2 +- include/sysemu/char.h | 94 ++--- include/sysemu/replay.h | 4 +- include/sysemu/sysemu.h | 4 +- include/ui/gtk.h | 2 +- include/ui/qemu-spice.h | 2 +- backends/baum.c | 56 +-- backends/msmouse.c | 42 +- backends/rng-egd.c | 4 +- backends/testdev.c | 28 +- gdbstub.c | 12 +- hw/arm/fsl-imx25.c | 2 +- hw/arm/fsl-imx31.c | 2 +- hw/arm/fsl-imx6.c | 2 +- hw/arm/nseries.c | 2 +- hw/arm/omap2.c | 2 +- hw/arm/pxa2xx.c | 2 +- hw/arm/virt.c | 2 +- hw/bt/hci-csr.c | 14 +- hw/char/escc.c | 2 +- hw/char/exynos4210_uart.c | 2 +- hw/char/imx_serial.c | 2 +- hw/char/mcf_uart.c | 4 +- hw/char/omap_uart.c | 6 +- hw/char/parallel.c | 2 +- hw/char/serial-isa.c | 2 +- hw/char/serial.c | 4 +- hw/char/sh_serial.c | 2 +- hw/char/spapr_vty.c | 2 +- hw/char/virtio-console.c | 2 +- hw/core/qdev-properties-system.c | 4 +- hw/display/milkymist-tmu2.c | 2 +- hw/display/sm501.c | 2 +- hw/isa/isa-bus.c | 2 +- hw/isa/pc87312.c | 2 +- hw/mips/mips_malta.c | 4 +- hw/misc/ivshmem.c | 2 +- hw/misc/milkymist-pfpu.c | 2 +- hw/usb/ccid-card-passthru.c | 2 +- hw/usb/dev-serial.c | 6 +- hw/usb/redirect.c | 4 +- monitor.c | 4 +- net/colo-compare.c | 4 +- net/filter-mirror.c | 4 +- net/slirp.c | 2 +- net/vhost-user.c | 10 +- qemu-char.c | 839 +++++++++++++++++++------------------- qmp.c | 2 +- qtest.c | 2 +- replay/replay-char.c | 8 +- spice-qemu-char.c | 80 ++-- stubs/get-next-serial.c | 2 +- stubs/monitor-init.c | 2 +- stubs/replay.c | 4 +- tests/test-char.c | 10 +- tests/vhost-user-test.c | 4 +- ui/console.c | 40 +- ui/gtk.c | 26 +- vl.c | 10 +- xen-common-stub.c | 2 +- xen-common.c | 4 +- 81 files changed, 728 insertions(+), 725 deletions(-)
hw/lm32/lm32.h +2 -2
@@ -16,7 +16,7 @@ static inline DeviceState *lm32_pic_init(qemu_irq cpu_irq)return dev; } -static inline DeviceState *lm32_juart_init (CharDriverState *chr) +static inline DeviceState *lm32_juart_init (Chardev *chr) {DeviceState *dev;
@@ -29,7 +29,7 @@ static inline DeviceState *lm32_juart_init(CharDriverState *chr)static inline DeviceState *lm32_uart_create (hwaddr addr,qemu_irq irq, -CharDriverState *chr) +Chardev *chr) {DeviceState *dev;SysBusDevice *s;
hw/lm32/milkymist-hw.h +1 -1
@@ -6,7 +6,7 @@static inline DeviceState *milkymist_uart_create (hwaddr base,qemu_irq irq, -CharDriverState *chr) +Chardev *chr) {DeviceState *dev;
include/hw/arm/exynos4210.h +1 -1
@@ -131,7 +131,7 @@ void exynos4210_combiner_get_gpioin(Exynos4210Irq *irqs, DeviceState *dev,DeviceState *exynos4210_uart_create (hwaddr addr,int fifo_size,int channel, -CharDriverState *chr, +Chardev *chr,qemu_irq irq);#endif /* EXYNOS4210_H */
include/hw/arm/omap.h +3 -3
@@ -664,14 +664,14 @@ struct omap_uart_s;struct omap_uart_s *omap_uart_init (hwaddr base,qemu_irq irq,omap_clk fclk,omap_clk iclk,qemu_irq txdma,qemu_irq rxdma, -const char *label,CharDriverState *chr); +const char *label,Chardev *chr);struct omap_uart_s *omap2_uart_init (MemoryRegion *sysmem,struct omap_target_agent_s *ta,qemu_irq irq,omap_clk fclk,omap_clk iclk,qemu_irq txdma,qemu_irq rxdma, -const char *label,CharDriverState *chr); +const char *label,Chardev *chr);void omap_uart_reset (struct omap_uart_s *s); -void omap_uart_attach (struct omap_uart_s *s,CharDriverState *chr); +void omap_uart_attach (struct omap_uart_s *s,Chardev *chr);struct omap_mpuio_s ;qemu_irq *omap_mpuio_in_get (struct omap_mpuio_s *s);
include/hw/bt.h +2 -2
@@ -127,8 +127,8 @@ enum { csrhci_pin_wakeup, __csrhci_pins, }; -qemu_irq *csrhci_pins_get (CharDriverState *chr); -CharDriverState *uart_hci_init (void ); +qemu_irq *csrhci_pins_get (Chardev *chr); +Chardev *uart_hci_init (void );/* bt-l2cap.c */ struct bt_l2cap_device_s ;
include/hw/char/cadence_uart.h +1 -1
@@ -51,7 +51,7 @@ typedef struct {static inline DeviceState *cadence_uart_create (hwaddr addr,qemu_irq irq, -CharDriverState *chr) +Chardev *chr) {DeviceState *dev;SysBusDevice *s;
include/hw/char/escc.h +1 -1
@@ -5,7 +5,7 @@#define TYPE_ESCC "escc"#define ESCC_SIZE 4MemoryRegion *escc_init (hwaddr base,qemu_irq irqA,qemu_irq irqB, -CharDriverState *chrA,CharDriverState *chrB, +Chardev *chrA,Chardev *chrB,int clock,int it_shift); void slavio_serial_ms_kbd_init(hwaddr base, qemu_irq irq,
include/hw/char/pl011.h +2 -2
@@ -17,7 +17,7 @@static inline DeviceState *pl011_create (hwaddr addr,qemu_irq irq, -CharDriverState *chr) +Chardev *chr) {DeviceState *dev;SysBusDevice *s;
@@ -34,7 +34,7 @@ static inline DeviceState *pl011_create(hwaddr addr,static inline DeviceState *pl011_luminary_create (hwaddr addr,qemu_irq irq, -CharDriverState *chr) +Chardev *chr) {DeviceState *dev;SysBusDevice *s;
include/hw/char/serial.h +2 -2
@@ -88,11 +88,11 @@ void serial_set_frequency(SerialState *s, uint32_t frequency);/* legacy pre qom */ SerialState *serial_init (int base,qemu_irq irq,int baudbase, -CharDriverState *chr,MemoryRegion *system_io); +Chardev *chr,MemoryRegion *system_io);SerialState *serial_mm_init (MemoryRegion *address_space,hwaddr base,int it_shift,qemu_irq irq,int baudbase, -CharDriverState *chr,enum device_endian end); +Chardev *chr,enum device_endian end);/* serial-isa.c */ #define TYPE_ISA_SERIAL "isa-serial"
include/hw/char/xilinx_uartlite.h +1 -1
@@ -17,7 +17,7 @@static inline DeviceState *xilinx_uartlite_create (hwaddr addr,qemu_irq irq, -CharDriverState *chr) +Chardev *chr) {DeviceState *dev;SysBusDevice *s;
include/hw/cris/etraxfs.h +1 -1
@@ -48,7 +48,7 @@ etraxfs_eth_init(NICInfo *nd, hwaddr base, int phyaddr,static inline DeviceState *etraxfs_ser_create (hwaddr addr,qemu_irq irq, -CharDriverState *chr) +Chardev *chr) {DeviceState *dev;SysBusDevice *s;
include/hw/devices.h +1 -1
@@ -65,6 +65,6 @@ qemu_irq tc6393xb_l3v_get(TC6393xbState *s);/* sm501.c */ void sm501_init (struct MemoryRegion *address_space_mem,uint32_t base,uint32_t local_mem_bytes,qemu_irq irq, -CharDriverState *chr); +Chardev *chr);#endif
include/hw/i386/pc.h +1 -1
@@ -181,7 +181,7 @@ void parallel_hds_isa_init(ISABus *bus, int n);bool parallel_mm_init (MemoryRegion *address_space,hwaddr base,int it_shift,qemu_irq irq, -CharDriverState *chr); +Chardev *chr);/* i8259.c */
include/hw/m68k/mcf.h +2 -2
@@ -11,10 +11,10 @@ uint64_t mcf_uart_read(void *opaque, hwaddr addr, unsigned size);void mcf_uart_write (void *opaque,hwaddr addr,uint64_t val,unsigned size); -void *mcf_uart_init (qemu_irq irq,CharDriverState *chr); +void *mcf_uart_init (qemu_irq irq,Chardev *chr);void mcf_uart_mm_init (struct MemoryRegion *sysmem,hwaddr base, -qemu_irq irq,CharDriverState *chr); +qemu_irq irq,Chardev *chr);/* mcf_intc.c */ qemu_irq *mcf_intc_init(struct MemoryRegion *sysmem,
include/hw/ppc/spapr_vio.h +1 -1
@@ -127,7 +127,7 @@ int spapr_vio_send_crq(VIOsPAPRDevice *dev, uint8_t *crq);VIOsPAPRDevice *vty_lookup (sPAPRMachineState *spapr,target_ulong reg);void vty_putchars (VIOsPAPRDevice *sdev,uint8_t *buf,int len); -void spapr_vty_create (VIOsPAPRBus *bus,CharDriverState *chardev); +void spapr_vty_create (VIOsPAPRBus *bus,Chardev *chardev);void spapr_vlan_create (VIOsPAPRBus *bus,NICInfo *nd);void spapr_vscsi_create (VIOsPAPRBus *bus);
include/hw/qdev-properties.h +1 -1
@@ -184,7 +184,7 @@ void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value);void qdev_prop_set_int32 (DeviceState *dev,const char *name,int32_t value);void qdev_prop_set_uint64 (DeviceState *dev,const char *name,uint64_t value);void qdev_prop_set_string (DeviceState *dev,const char *name,const char *value); -void qdev_prop_set_chr (DeviceState *dev,const char *name,CharDriverState *value); +void qdev_prop_set_chr (DeviceState *dev,const char *name,Chardev *value);void qdev_prop_set_netdev (DeviceState *dev,const char *name,NetClientState *value);void qdev_prop_set_drive (DeviceState *dev,const char *name,BlockBackend *value,Error **errp);
include/hw/sh4/sh.h +1 -1
@@ -42,7 +42,7 @@ void tmu012_init(struct MemoryRegion *sysmem, hwaddr base,#define SH_SERIAL_FEAT_SCIF (1 << 0) void sh_serial_init(MemoryRegion *sysmem, hwaddr base, int feat, - uint32_t freq, CharDriverState *chr, + uint32_t freq, Chardev *chr, qemu_irq eri_source, qemu_irq rxi_source, qemu_irq txi_source,
include/hw/sparc/grlib.h +1 -1
@@ -100,7 +100,7 @@ DeviceState *grlib_gptimer_create(hwaddr base,static inline DeviceState *grlib_apbuart_create (hwaddr base, -CharDriverState *serial, +Chardev *serial,qemu_irq irq) {DeviceState *dev;
include/hw/xen/xen.h +1 -1
@@ -37,7 +37,7 @@ int xen_is_pirq_msi(uint32_t msi_data);qemu_irq *xen_interrupt_controller_init (void ); -void xenstore_store_pv_console_info (int i,struct CharDriverState *chr); +void xenstore_store_pv_console_info (int i,struct Chardev *chr);void xen_hvm_init (PCMachineState *pcms,MemoryRegion **ram_memory);
include/monitor/monitor.h +1 -1
@@ -16,7 +16,7 @@ extern Monitor *cur_mon;bool monitor_cur_is_qmp (void ); -void monitor_init (CharDriverState *chr,int flags); +void monitor_init (Chardev *chr,int flags);void monitor_cleanup (void );int monitor_suspend (Monitor *mon);
include/qemu/typedefs.h +1 -1
@@ -17,7 +17,7 @@ typedef struct BlockBackendRootState BlockBackendRootState;typedef struct BlockDriverState BlockDriverState ;typedef struct BusClass BusClass ;typedef struct BusState BusState ; -typedef struct CharDriverState CharDriverState ; +typedef struct Chardev Chardev ;typedef struct CompatProperty CompatProperty ;typedef struct CPUAddressSpace CPUAddressSpace ;typedef struct CPUState CPUState ;
include/sysemu/char.h +47 -47
223 lines not on this page · raw message
include/sysemu/replay.h +2 -2
@@ -123,9 +123,9 @@ uint64_t blkreplay_next_id(void);/* Character device */ /*! Registers char driver to save it's events */ -void replay_register_char_driver (struct CharDriverState *chr); +void replay_register_char_driver (struct Chardev *chr);/*! Saves write to char device event to the log */ -void replay_chr_be_write (struct CharDriverState *s,uint8_t *buf,int len); +void replay_chr_be_write (struct Chardev *s,uint8_t *buf,int len);/*! Writes char write return value to the replay log. */ void replay_char_write_event_save (int res,int offset);/*! Reads char write return value from the replay log. */
include/sysemu/sysemu.h +2 -2
@@ -197,13 +197,13 @@ void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict);#define MAX_SERIAL_PORTS 4 -extern CharDriverState *serial_hds[MAX_SERIAL_PORTS ]; +extern Chardev *serial_hds[MAX_SERIAL_PORTS ];/* parallel ports */ #define MAX_PARALLEL_PORTS 3 -extern CharDriverState *parallel_hds[MAX_PARALLEL_PORTS ]; +extern Chardev *parallel_hds[MAX_PARALLEL_PORTS ];void hmp_usb_add (Monitor *mon,const QDict *qdict);void hmp_usb_del (Monitor *mon,const QDict *qdict);
include/ui/gtk.h +1 -1
@@ -64,7 +64,7 @@ typedef struct VirtualVteConsole {GtkWidget *box;GtkWidget *scrollbar;GtkWidget *terminal; -CharDriverState *chr; +Chardev *chr; bool echo; } VirtualVteConsole;#endif
include/ui/qemu-spice.h +1 -1
@@ -51,7 +51,7 @@ int qemu_spice_migrate_info(const char *hostname, int port, int tls_port,#if SPICE_SERVER_VERSION >=0x000c02 void qemu_spice_register_ports (void );#else -static inline CharDriverState *qemu_chr_open_spice_port (const char *name) +static inline Chardev *qemu_chr_open_spice_port (const char *name) {return NULL ; }#endif
backends/baum.c +29 -27
151 lines not on this page · raw message
backends/msmouse.c +21 -21
105 lines not on this page · raw message
backends/rng-egd.c +2 -2
@@ -86,7 +86,7 @@ static void rng_egd_chr_read(void *opaque, const uint8_t *buf, int size)static void rng_egd_opened (RngBackend *b,Error **errp) {RngEgd *s =RNG_EGD (b); -CharDriverState *chr; +Chardev *chr;if (s->chr_name ==NULL ) { error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
@@ -125,7 +125,7 @@ static void rng_egd_set_chardev(Object *obj, const char *value, Error **errp)static char *rng_egd_get_chardev (Object *obj,Error **errp) {RngEgd *s =RNG_EGD (obj); -CharDriverState *chr =qemu_chr_fe_get_driver (&s->chr); +Chardev *chr =qemu_chr_fe_get_driver (&s->chr);if (chr && chr->label) {return g_strdup (chr->label);
backends/testdev.c +14 -14
@@ -30,14 +30,14 @@#define BUF_SIZE 32typedef struct { -CharDriverState parent; +Chardev parent;uint8_t in_buf[32 ];int in_buf_used; -}TestdevCharState ; +}TestdevChardev ;/* Try to interpret a whole incoming packet */ -static int testdev_eat_packet (TestdevCharState *testdev) +static int testdev_eat_packet (TestdevChardev *testdev) {const uint8_t *cur = testdev->in_buf;int len = testdev->in_buf_used;
@@ -78,9 +78,9 @@ static int testdev_eat_packet(TestdevCharState *testdev) }/* The other end is writing some data. Store it and try to interpret */ -static int testdev_write (CharDriverState *chr,const uint8_t *buf,int len) +static int testdev_write (Chardev *chr,const uint8_t *buf,int len) { -TestdevCharState *testdev = (TestdevCharState *)chr; +TestdevChardev *testdev = (TestdevChardev *)chr;int tocopy, eaten, orig_len = len;while (len) {
@@ -103,15 +103,15 @@ static int testdev_write(CharDriverState *chr, const uint8_t *buf, int len)return orig_len; } -static CharDriverState *chr_testdev_init (const CharDriver *driver, -const char *id, -ChardevBackend *backend, -ChardevReturn *ret, -bool *be_opened, -Error **errp) +static Chardev *chr_testdev_init (const CharDriver *driver, +const char *id, +ChardevBackend *backend, +ChardevReturn *ret, +bool *be_opened, +Error **errp) { -TestdevCharState *testdev =g_new0 (TestdevCharState,1 );; -CharDriverState *chr = (CharDriverState *)testdev; +TestdevChardev *testdev =g_new0 (TestdevChardev,1 );; +Chardev *chr = (Chardev *)testdev; chr->driver = driver;
@@ -121,7 +121,7 @@ static CharDriverState *chr_testdev_init(const CharDriver *driver,static void register_types (void ) {static const CharDriver driver = { - .instance_size =sizeof (TestdevCharState), + .instance_size =sizeof (TestdevChardev), .kind =CHARDEV_BACKEND_KIND_TESTDEV , .create = chr_testdev_init, .chr_write = testdev_write,
gdbstub.c +6 -6
@@ -303,7 +303,7 @@ typedef struct GDBState {int running_state;#else CharBackend chr; -CharDriverState *mon_chr; +Chardev *mon_chr;#endif char syscall_buf[256 ];gdb_syscall_complete_cb current_syscall_cb;
@@ -1471,7 +1471,7 @@ void gdb_exit(CPUArchState *env, int code)GDBState *s;char buf[4 ];#ifndef CONFIG_USER_ONLY -CharDriverState *chr; +Chardev *chr;#endif s = gdbserver_state;
@@ -1696,7 +1696,7 @@ static void gdb_monitor_output(GDBState *s, const char *msg, int len)put_packet (s, buf); } -static int gdb_monitor_write (CharDriverState *chr,const uint8_t *buf,int len) +static int gdb_monitor_write (Chardev *chr,const uint8_t *buf,int len) {const char *p = (const char *)buf;int max_sz;
@@ -1727,11 +1727,11 @@ int gdbserver_start(const char *device) {GDBState *s;char gdbstub_device_name[128 ]; -CharDriverState *chr =NULL ; -CharDriverState *mon_chr; +Chardev *chr =NULL ; +Chardev *mon_chr;ChardevCommon common = {0 };static const CharDriver driver = { - .instance_size =sizeof (CharDriverState), + .instance_size =sizeof (Chardev), .kind =-1 , .chr_write = gdb_monitor_write };
hw/arm/fsl-imx25.c +1 -1
@@ -118,7 +118,7 @@ static void fsl_imx25_realize(DeviceState *dev, Error **errp) };if (i <MAX_SERIAL_PORTS ) { -CharDriverState *chr; +Chardev *chr; chr = serial_hds[i];
hw/arm/fsl-imx31.c +1 -1
@@ -107,7 +107,7 @@ static void fsl_imx31_realize(DeviceState *dev, Error **errp) };if (i <MAX_SERIAL_PORTS ) { -CharDriverState *chr; +Chardev *chr; chr = serial_hds[i];
hw/arm/fsl-imx6.c +1 -1
@@ -187,7 +187,7 @@ static void fsl_imx6_realize(DeviceState *dev, Error **errp) };if (i <MAX_SERIAL_PORTS ) { -CharDriverState *chr; +Chardev *chr; chr = serial_hds[i];
hw/arm/nseries.c +1 -1
@@ -786,7 +786,7 @@ static void n8x0_cbus_setup(struct n800_s *s)static void n8x0_uart_setup (struct n800_s *s) { -CharDriverState *radio =uart_hci_init (); +Chardev *radio =uart_hci_init ();qdev_connect_gpio_out (s->mpu->gpio,N8X0_BT_RESET_GPIO ,csrhci_pins_get (radio)[csrhci_pin_reset]);
hw/arm/omap2.c +1 -1
@@ -792,7 +792,7 @@ static const MemoryRegionOps omap_sti_fifo_ops = {static struct omap_sti_s *omap_sti_init (struct omap_target_agent_s *ta,MemoryRegion *sysmem,hwaddr channel_base,qemu_irq irq,omap_clk clk, -CharDriverState *chr) +Chardev *chr) { struct omap_sti_s *s = g_new0(struct omap_sti_s, 1);
hw/arm/pxa2xx.c +1 -1
@@ -2022,7 +2022,7 @@ static PXA2xxFIrState *pxa2xx_fir_init(MemoryRegion *sysmem,hwaddr base, qemu_irq irq, qemu_irq rx_dma, qemu_irq tx_dma, - CharDriverState *chr) + Chardev *chr) { DeviceState *dev;SysBusDevice *sbd;
hw/arm/virt.c +1 -1
@@ -626,7 +626,7 @@ static void create_gic(VirtBoardInfo *vbi, qemu_irq *pic, int type, }static void create_uart (const VirtBoardInfo *vbi,qemu_irq *pic,int uart, -MemoryRegion *mem,CharDriverState *chr) +MemoryRegion *mem,Chardev *chr) {char *nodename;hwaddr base = vbi->memmap[uart].base;
hw/bt/hci-csr.c +7 -7
@@ -29,7 +29,7 @@#include "qapi/error.h" struct csrhci_s { -CharDriverState parent; +Chardev parent;int enable;qemu_irq *pins;int pin_state;
@@ -79,7 +79,7 @@ enum {static inline void csrhci_fifo_wake (struct csrhci_s *s) { -CharDriverState *chr = (CharDriverState *)s; +Chardev *chr = (Chardev *)s;CharBackend *be = chr->be;if (!s->enable || !s->out_len)
@@ -313,7 +313,7 @@ static void csrhci_ready_for_next_inpkt(struct csrhci_s *s) s->in_hdr =INT_MAX ; } -static int csrhci_write (struct CharDriverState *chr, +static int csrhci_write (struct Chardev *chr,const uint8_t *buf,int len) {struct csrhci_s *s = (struct csrhci_s *)chr;
@@ -386,7 +386,7 @@ static void csrhci_out_hci_packet_acl(void *opaque,csrhci_fifo_wake (s); } -static int csrhci_ioctl (struct CharDriverState *chr,int cmd,void *arg) +static int csrhci_ioctl (struct Chardev *chr,int cmd,void *arg) {QEMUSerialSetParams *ssp;struct csrhci_s *s = (struct csrhci_s *) chr;
@@ -455,14 +455,14 @@ static void csrhci_pins(void *opaque, int line, int level) } } -qemu_irq *csrhci_pins_get (CharDriverState *chr) +qemu_irq *csrhci_pins_get (Chardev *chr) {struct csrhci_s *s = (struct csrhci_s *) chr;return s->pins; } -CharDriverState *uart_hci_init (void ) +Chardev *uart_hci_init (void ) {static const CharDriver hci_driver = { .instance_size =sizeof (struct csrhci_s ),
@@ -472,7 +472,7 @@ CharDriverState *uart_hci_init(void) };Error *err =NULL ;ChardevCommon common = {0 , }; -CharDriverState *chr =qemu_chr_alloc (&hci_driver, &common, &err); +Chardev *chr =qemu_chr_alloc (&hci_driver, &common, &err);struct csrhci_s *s = (struct csrhci_s *)chr;if (err) {
hw/char/escc.c +1 -1
@@ -689,7 +689,7 @@ static const VMStateDescription vmstate_escc = { };MemoryRegion *escc_init (hwaddr base,qemu_irq irqA,qemu_irq irqB, -CharDriverState *chrA,CharDriverState *chrB, +Chardev *chrA,Chardev *chrB,int clock,int it_shift) {DeviceState *dev;
hw/char/exynos4210_uart.c +1 -1
@@ -586,7 +586,7 @@ static const VMStateDescription vmstate_exynos4210_uart = {DeviceState *exynos4210_uart_create (hwaddr addr,int fifo_size,int channel, -CharDriverState *chr, +Chardev *chr,qemu_irq irq) {DeviceState *dev;
hw/char/imx_serial.c +1 -1
@@ -170,7 +170,7 @@ static void imx_serial_write(void *opaque, hwaddr offset, uint64_t value, unsigned size) {IMXSerialState *s = (IMXSerialState *)opaque; -CharDriverState *chr =qemu_chr_fe_get_driver (&s->chr); +Chardev *chr =qemu_chr_fe_get_driver (&s->chr);unsigned char ch; DPRINTF("write(offset=0x%" HWADDR_PRIx ", value = 0x%x) to %s\n",
hw/char/mcf_uart.c +2 -2
@@ -275,7 +275,7 @@ static void mcf_uart_receive(void *opaque, const uint8_t *buf, int size)mcf_uart_push_byte (s, buf[0 ]); } -void *mcf_uart_init (qemu_irq irq,CharDriverState *chr) +void *mcf_uart_init (qemu_irq irq,Chardev *chr) {mcf_uart_state *s;
@@ -300,7 +300,7 @@ static const MemoryRegionOps mcf_uart_ops = {void mcf_uart_mm_init (MemoryRegion *sysmem,hwaddr base,qemu_irq irq, -CharDriverState *chr) +Chardev *chr) {mcf_uart_state *s;
hw/char/omap_uart.c +3 -3
@@ -54,7 +54,7 @@ void omap_uart_reset(struct omap_uart_s *s)struct omap_uart_s *omap_uart_init (hwaddr base,qemu_irq irq,omap_clk fclk,omap_clk iclk,qemu_irq txdma,qemu_irq rxdma, -const char *label,CharDriverState *chr) +const char *label,Chardev *chr) { struct omap_uart_s *s = g_new0(struct omap_uart_s, 1);
@@ -163,7 +163,7 @@ struct omap_uart_s *omap2_uart_init(MemoryRegion *sysmem,struct omap_target_agent_s *ta, qemu_irq irq, omap_clk fclk, omap_clk iclk, qemu_irq txdma, qemu_irq rxdma, - const char *label, CharDriverState *chr) + const char *label, Chardev *chr) { hwaddr base = omap_l4_attach(ta, 0, NULL); struct omap_uart_s *s = omap_uart_init(base, irq,
@@ -178,7 +178,7 @@ struct omap_uart_s *omap2_uart_init(MemoryRegion *sysmem,return s; } -void omap_uart_attach (struct omap_uart_s *s,CharDriverState *chr) +void omap_uart_attach (struct omap_uart_s *s,Chardev *chr) {/* TODO: Should reuse or destroy current s->serial */ s->serial = serial_mm_init(get_system_memory(), s->base, 2, s->irq,
hw/char/parallel.c +1 -1
@@ -603,7 +603,7 @@ static const MemoryRegionOps parallel_mm_ops = {/* If fd is zero, it means that the parallel device uses the console */ bool parallel_mm_init (MemoryRegion *address_space,hwaddr base,int it_shift,qemu_irq irq, -CharDriverState *chr) +Chardev *chr) {ParallelState *s;
hw/char/serial-isa.c +1 -1
@@ -121,7 +121,7 @@ static void serial_register_types(void)type_init (serial_register_types) -static void serial_isa_init(ISABus *bus, int index, CharDriverState *chr) +static void serial_isa_init(ISABus *bus, int index, Chardev *chr) {DeviceState *dev;ISADevice *isadev;
hw/char/serial.c +2 -2
@@ -927,7 +927,7 @@ const MemoryRegionOps serial_io_ops = { };SerialState *serial_init (int base,qemu_irq irq,int baudbase, -CharDriverState *chr,MemoryRegion *system_io) +Chardev *chr,MemoryRegion *system_io) {SerialState *s;
@@ -983,7 +983,7 @@ static const MemoryRegionOps serial_mm_ops[3] = {SerialState *serial_mm_init (MemoryRegion *address_space,hwaddr base,int it_shift,qemu_irq irq,int baudbase, -CharDriverState *chr,enum device_endian end) +Chardev *chr,enum device_endian end) {SerialState *s;
hw/char/sh_serial.c +1 -1
@@ -356,7 +356,7 @@ static const MemoryRegionOps sh_serial_ops = { void sh_serial_init(MemoryRegion *sysmem, hwaddr base, int feat, - uint32_t freq, CharDriverState *chr, + uint32_t freq, Chardev *chr, qemu_irq eri_source, qemu_irq rxi_source, qemu_irq txi_source,
hw/char/spapr_vty.c +1 -1
@@ -141,7 +141,7 @@ static target_ulong h_get_term_char(PowerPCCPU *cpu, sPAPRMachineState *spapr,return H_SUCCESS ; } -void spapr_vty_create (VIOsPAPRBus *bus,CharDriverState *chardev) +void spapr_vty_create (VIOsPAPRBus *bus,Chardev *chardev) {DeviceState *dev;
hw/char/virtio-console.c +1 -1
@@ -168,7 +168,7 @@ static void virtconsole_realize(DeviceState *dev, Error **errp)VirtIOSerialPort *port =VIRTIO_SERIAL_PORT (dev);VirtConsole *vcon =VIRTIO_CONSOLE (dev);VirtIOSerialPortClass *k =VIRTIO_SERIAL_PORT_GET_CLASS (dev); -CharDriverState *chr =qemu_chr_fe_get_driver (&vcon->chr); +Chardev *chr =qemu_chr_fe_get_driver (&vcon->chr);if (port->id ==0 && !k->is_console) { error_setg(errp, "Port number 0 on virtio-serial devices reserved "
hw/core/qdev-properties-system.c +2 -2
@@ -179,7 +179,7 @@ static void set_chr(Object *obj, Visitor *v, const char *name, void *opaque,Error *local_err =NULL ;Property *prop = opaque;CharBackend *be =qdev_get_prop_ptr (dev, prop); -CharDriverState *s; +Chardev *s;char *str;if (dev->realized) {
@@ -411,7 +411,7 @@ void qdev_prop_set_drive(DeviceState *dev, const char *name, }void qdev_prop_set_chr (DeviceState *dev,const char *name, -CharDriverState *value) +Chardev *value) {assert (!value || value->label); object_property_set_str(OBJECT(dev),
hw/display/milkymist-tmu2.c +1 -1
@@ -85,7 +85,7 @@ struct MilkymistTMU2State {SysBusDevice parent_obj;MemoryRegion regs_region; -CharDriverState *chr; +Chardev *chr;qemu_irq irq;uint32_t regs[R_MAX ];
hw/display/sm501.c +1 -1
@@ -1392,7 +1392,7 @@ static const GraphicHwOps sm501_ops = { };void sm501_init (MemoryRegion *address_space_mem,uint32_t base, -uint32_t local_mem_bytes,qemu_irq irq,CharDriverState *chr) +uint32_t local_mem_bytes,qemu_irq irq,Chardev *chr) {SM501State * s;DeviceState *dev;
hw/isa/isa-bus.c +1 -1
@@ -287,7 +287,7 @@ MemoryRegion *isa_address_space_io(ISADevice *dev)type_init (isabus_register_types) -static void parallel_init(ISABus *bus, int index, CharDriverState *chr) +static void parallel_init(ISABus *bus, int index, Chardev *chr) {DeviceState *dev;ISADevice *isadev;
hw/isa/pc87312.c +1 -1
@@ -268,7 +268,7 @@ static void pc87312_realize(DeviceState *dev, Error **errp)DeviceState *d;ISADevice *isa;ISABus *bus; -CharDriverState *chr; +Chardev *chr;DriveInfo *drive;char name[5 ];int i;
hw/mips/mips_malta.c +2 -2
@@ -551,10 +551,10 @@ static void malta_fgpa_display_event(void *opaque, int event) }static MaltaFPGAState *malta_fpga_init (MemoryRegion *address_space, -hwaddr base,qemu_irq uart_irq,CharDriverState *uart_chr) +hwaddr base,qemu_irq uart_irq,Chardev *uart_chr) {MaltaFPGAState *s; -CharDriverState *chr; +Chardev *chr; s = (MaltaFPGAState *)g_malloc0 (sizeof (MaltaFPGAState));
hw/misc/ivshmem.c +1 -1
@@ -868,7 +868,7 @@ static void ivshmem_common_realize(PCIDevice *dev, Error **errp) s->ivshmem_bar2 =host_memory_backend_get_memory (s->hostmem, &error_abort); }else { -CharDriverState *chr =qemu_chr_fe_get_driver (&s->server_chr); +Chardev *chr =qemu_chr_fe_get_driver (&s->server_chr);assert (chr); IVSHMEM_DPRINTF("using shared memory server (socket = %s)\n",
hw/misc/milkymist-pfpu.c +1 -1
@@ -125,7 +125,7 @@ struct MilkymistPFPUState {SysBusDevice parent_obj;MemoryRegion regs_region; -CharDriverState *chr; +Chardev *chr;qemu_irq irq;uint32_t regs[R_MAX ];
hw/usb/ccid-card-passthru.c +1 -1
@@ -264,7 +264,7 @@ static void ccid_card_vscard_handle_message(PassthruState *card,static void ccid_card_vscard_drop_connection (PassthruState *card) { -CharDriverState *chr =qemu_chr_fe_get_driver (&card->cs); +Chardev *chr =qemu_chr_fe_get_driver (&card->cs);qemu_chr_fe_deinit (&card->cs);qemu_chr_delete (chr);
hw/usb/dev-serial.c +3 -3
@@ -483,7 +483,7 @@ static void usb_serial_realize(USBDevice *dev, Error **errp) {USBSerialState *s =USB_SERIAL_DEV (dev);Error *local_err =NULL ; -CharDriverState *chr =qemu_chr_fe_get_driver (&s->cs); +Chardev *chr =qemu_chr_fe_get_driver (&s->cs);usb_desc_create_serial (dev);usb_desc_init (dev);
@@ -512,7 +512,7 @@ static void usb_serial_realize(USBDevice *dev, Error **errp)static USBDevice *usb_serial_init (USBBus *bus,const char *filename) {USBDevice *dev; -CharDriverState *cdrv; +Chardev *cdrv;uint32_t vendorid =0 , productid =0 ;char label[32 ];static int index;
@@ -564,7 +564,7 @@ static USBDevice *usb_serial_init(USBBus *bus, const char *filename)static USBDevice *usb_braille_init (USBBus *bus,const char *unused) {USBDevice *dev; -CharDriverState *cdrv; +Chardev *cdrv; cdrv =qemu_chr_new ("braille" ,"braille" );if (!cdrv)
hw/usb/redirect.c +2 -2
@@ -284,7 +284,7 @@ static gboolean usbredir_write_unblocked(GIOChannel *chan, GIOCondition cond,static int usbredir_write (void *priv,uint8_t *data,int count) {USBRedirDevice *dev = priv; -CharDriverState *chr =qemu_chr_fe_get_driver (&dev->cs); +Chardev *chr =qemu_chr_fe_get_driver (&dev->cs);int r;if (!chr->be_open) {
@@ -1430,7 +1430,7 @@ static void usbredir_cleanup_device_queues(USBRedirDevice *dev)static void usbredir_handle_destroy (USBDevice *udev) {USBRedirDevice *dev =USB_REDIRECT (udev); -CharDriverState *chr =qemu_chr_fe_get_driver (&dev->cs); +Chardev *chr =qemu_chr_fe_get_driver (&dev->cs);qemu_chr_fe_deinit (&dev->cs);qemu_chr_delete (chr);
monitor.c +2 -2
@@ -3193,7 +3193,7 @@ static void ringbuf_completion(ReadLineState *rs, const char *str)ChardevInfo *chr_info = list->value;if (!strncmp (chr_info->label, str, len)) { -CharDriverState *chr =qemu_chr_find (chr_info->label); +Chardev *chr =qemu_chr_find (chr_info->label);if (chr &&qemu_chr_is_ringbuf (chr)) {readline_add_completion (rs, chr_info->label); }
@@ -3981,7 +3981,7 @@ static void __attribute__((constructor)) monitor_lock_init(void)qemu_mutex_init (&monitor_lock); } -void monitor_init (CharDriverState *chr,int flags) +void monitor_init (Chardev *chr,int flags) {static int is_first_init =1 ;Monitor *mon;
net/colo-compare.c +2 -2
@@ -564,7 +564,7 @@ static void compare_sec_rs_finalize(SocketReadState *sec_rs)* Return 0 is success. * Return 1 is failed. */ -static int find_and_check_chardev (CharDriverState **chr, +static int find_and_check_chardev (Chardev **chr,char *chr_name,Error **errp) {
@@ -611,7 +611,7 @@ static void check_old_packet_regular(void *opaque)static void colo_compare_complete (UserCreatable *uc,Error **errp) {CompareState *s =COLO_COMPARE (uc); -CharDriverState *chr; +Chardev *chr;char thread_name[64 ];static int compare_id;
net/filter-mirror.c +2 -2
@@ -191,7 +191,7 @@ static void filter_redirector_cleanup(NetFilterState *nf)static void filter_mirror_setup (NetFilterState *nf,Error **errp) {MirrorState *s =FILTER_MIRROR (nf); -CharDriverState *chr; +Chardev *chr;if (!s->outdev) { error_setg(errp, "filter mirror needs 'outdev' "
@@ -220,7 +220,7 @@ static void redirector_rs_finalize(SocketReadState *rs)static void filter_redirector_setup (NetFilterState *nf,Error **errp) {MirrorState *s =FILTER_REDIRECTOR (nf); -CharDriverState *chr; +Chardev *chr;if (!s->indev && !s->outdev) { error_setg(errp, "filter redirector needs 'indev' or "
net/slirp.c +1 -1
@@ -748,7 +748,7 @@ static int slirp_guestfwd(SlirpState *s, const char *config_str, } }else {Error *err =NULL ; -CharDriverState *chr =qemu_chr_new (buf, p); +Chardev *chr =qemu_chr_new (buf, p);if (!chr) {error_report ("could not open guest forwarding device '%s'" , buf);
net/vhost-user.c +5 -5
@@ -195,7 +195,7 @@ static void net_vhost_user_event(void *opaque, int event)const char *name = opaque;NetClientState *ncs[MAX_QUEUE_NUM ];VhostUserState *s; -CharDriverState *chr; +Chardev *chr;Error *err =NULL ;int queues;
@@ -232,7 +232,7 @@ static void net_vhost_user_event(void *opaque, int event) }static int net_vhost_user_init (NetClientState *peer,const char *device, -const char *name,CharDriverState *chr, +const char *name,Chardev *chr,int queues) {Error *err =NULL ;
@@ -274,10 +274,10 @@ static int net_vhost_user_init(NetClientState *peer, const char *device,return 0 ; } -static CharDriverState *net_vhost_claim_chardev ( +static Chardev *net_vhost_claim_chardev (const NetdevVhostUserOptions *opts,Error **errp) { -CharDriverState *chr =qemu_chr_find (opts->chardev); +Chardev *chr =qemu_chr_find (opts->chardev);if (chr ==NULL ) {error_setg (errp,"chardev \"%s\" not found" , opts->chardev);
@@ -324,7 +324,7 @@ int net_init_vhost_user(const Netdev *netdev, const char *name, {int queues;const NetdevVhostUserOptions *vhost_user_opts; -CharDriverState *chr; +Chardev *chr;assert (netdev->type ==NET_CLIENT_DRIVER_VHOST_USER ); vhost_user_opts = &netdev->u.vhost_user;
qemu-char.c +420 -419
1,715 lines not on this page · raw message
spice-qemu-char.c +40 -40
80 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.11.0
Part of the diff is not shown here. View the raw message.
PATCH 14/20 char: rename TCPChardev and NetChardev
In reply to Marc-André LureauRename the types to follow the name of the chardev kind.
- socket: TCPChardev -> SocketChardev
- udp: NetChardev -> UdpChardev
--- qemu-char.c | 74 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 37 insertions(+), 37 deletions(-)
qemu-char.c +37 -37
@@ -2686,12 +2686,12 @@ typedef struct {int bufcnt;int bufptr;int max_size; -} NetChardev; +} UdpChardev;/* Called with chr_write_lock held. */ static int udp_chr_write (Chardev *chr,const uint8_t *buf,int len) { -NetChardev *s = (NetChardev *)chr; +UdpChardev *s = (UdpChardev *)chr;return qio_channel_write ( s->ioc, (const char *)buf, len,NULL );
@@ -2700,7 +2700,7 @@ static int udp_chr_write(Chardev *chr, const uint8_t *buf, int len)static int udp_chr_read_poll (void *opaque) {Chardev *chr = opaque; -NetChardev *s = opaque; +UdpChardev *s = opaque; s->max_size =qemu_chr_be_can_write (chr);
@@ -2718,7 +2718,7 @@ static int udp_chr_read_poll(void *opaque)static gboolean udp_chr_read (QIOChannel *chan,GIOCondition cond,void *opaque) {Chardev *chr = opaque; -NetChardev *s = opaque; +UdpChardev *s = opaque;ssize_t ret;if (s->max_size ==0 ) {
@@ -2745,7 +2745,7 @@ static gboolean udp_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque)static void udp_chr_update_read_handler (Chardev *chr,GMainContext *context) { -NetChardev *s = (NetChardev *)chr; +UdpChardev *s = (UdpChardev *)chr;remove_fd_in_watch (chr);if (s->ioc) {
@@ -2758,7 +2758,7 @@ static void udp_chr_update_read_handler(Chardev *chr,static void udp_chr_free (Chardev *chr) { -NetChardev *s = (NetChardev *)chr; +UdpChardev *s = (UdpChardev *)chr;remove_fd_in_watch (chr);if (s->ioc) {
@@ -2794,13 +2794,13 @@ typedef struct {guint reconnect_timer;int64_t reconnect_time;bool connect_err_reported; -} TCPChardev; +} SocketChardev;static gboolean socket_reconnect_timeout (gpointer opaque);static void qemu_chr_socket_restart_timer (Chardev *chr) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;char *name;assert (s->connected ==0 );
@@ -2814,7 +2814,7 @@ static void qemu_chr_socket_restart_timer(Chardev *chr)static void check_report_connect_error (Chardev *chr,Error *err) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;if (!s->connect_err_reported) { error_report("Unable to connect character device %s: %s",
@@ -2831,7 +2831,7 @@ static gboolean tcp_chr_accept(QIOChannel *chan,/* Called with chr_write_lock held. */ static int tcp_chr_write (Chardev *chr,const uint8_t *buf,int len) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;if (s->connected) { int ret = io_channel_send_full(s->ioc, buf, len,
@@ -2855,7 +2855,7 @@ static int tcp_chr_write(Chardev *chr, const uint8_t *buf, int len)static int tcp_chr_read_poll (void *opaque) {Chardev *chr = opaque; -TCPChardev *s = opaque; +SocketChardev *s = opaque;if (!s->connected)return 0 ; s->max_size =qemu_chr_be_can_write (chr);
@@ -2865,7 +2865,7 @@ static int tcp_chr_read_poll(void *opaque)#define IAC 255#define IAC_BREAK 243static void tcp_chr_process_IAC_bytes (Chardev *chr, -TCPChardev *s, +SocketChardev *s,uint8_t *buf,int *size) {/* Handle any telnet client's basic IAC options to satisfy char by
@@ -2914,7 +2914,7 @@ static void tcp_chr_process_IAC_bytes(Chardev *chr,static int tcp_get_msgfds (Chardev *chr,int *fds,int num) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;int to_copy = (s->read_msgfds_num < num) ? s->read_msgfds_num : num;
@@ -2940,7 +2940,7 @@ static int tcp_get_msgfds(Chardev *chr, int *fds, int num)static int tcp_set_msgfds (Chardev *chr,int *fds,int num) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;/* clear old pending fd array */ g_free (s->write_msgfds);
@@ -2965,7 +2965,7 @@ static int tcp_set_msgfds(Chardev *chr, int *fds, int num)static ssize_t tcp_chr_recv (Chardev *chr,char *buf,size_t len) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;struct iovec iov = { .iov_base = buf, .iov_len = len };int ret;size_t i;
@@ -3022,13 +3022,13 @@ static ssize_t tcp_chr_recv(Chardev *chr, char *buf, size_t len)static GSource *tcp_chr_add_watch (Chardev *chr,GIOCondition cond) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;return qio_channel_create_watch (s->ioc, cond); }static void tcp_chr_free_connection (Chardev *chr) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;int i;if (!s->connected) {
@@ -3057,7 +3057,7 @@ static void tcp_chr_free_connection(Chardev *chr)static void tcp_chr_disconnect (Chardev *chr) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;if (!s->connected) {return ;
@@ -3080,7 +3080,7 @@ static void tcp_chr_disconnect(Chardev *chr)static gboolean tcp_chr_read (QIOChannel *chan,GIOCondition cond,void *opaque) {Chardev *chr = opaque; -TCPChardev *s = opaque; +SocketChardev *s = opaque;uint8_t buf[READ_BUF_LEN ];int len, size;
@@ -3106,7 +3106,7 @@ static gboolean tcp_chr_read(QIOChannel *chan, GIOCondition cond, void *opaque)static int tcp_chr_sync_read (Chardev *chr,const uint8_t *buf,int len) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;int size;if (!s->connected) {
@@ -3125,7 +3125,7 @@ static int tcp_chr_sync_read(Chardev *chr, const uint8_t *buf, int len)static void tcp_chr_connect (void *opaque) {Chardev *chr = opaque; -TCPChardev *s = opaque; +SocketChardev *s = opaque;g_free (chr->filename); chr->filename = sockaddr_to_str(
@@ -3146,7 +3146,7 @@ static void tcp_chr_connect(void *opaque)static void tcp_chr_update_read_handler (Chardev *chr,GMainContext *context) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;if (!s->connected) {return ;
@@ -3197,7 +3197,7 @@ static gboolean tcp_chr_telnet_init_io(QIOChannel *ioc,static void tcp_chr_telnet_init (Chardev *chr) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;TCPCharDriverTelnetInit *init =g_new0 (TCPCharDriverTelnetInit,1 );size_t n =0 ;
@@ -3233,7 +3233,7 @@ static void tcp_chr_tls_handshake(Object *source, gpointer user_data) {Chardev *chr = user_data; -TCPChardev *s = user_data; +SocketChardev *s = user_data;if (err) {tcp_chr_disconnect (chr);
@@ -3249,7 +3249,7 @@ static void tcp_chr_tls_handshake(Object *source,static void tcp_chr_tls_init (Chardev *chr) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;QIOChannelTLS *tioc;Error *err =NULL ;gchar *name;
@@ -3288,7 +3288,7 @@ static void tcp_chr_tls_init(Chardev *chr)static void tcp_chr_set_client_ioc_name (Chardev *chr,QIOChannelSocket *sioc) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;char *name; name = g_strdup_printf("chardev-tcp-%s-%s", s->is_listen ? "server" : "client",
@@ -3300,7 +3300,7 @@ static void tcp_chr_set_client_ioc_name(Chardev *chr,static int tcp_chr_new_client (Chardev *chr,QIOChannelSocket *sioc) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;if (s->ioc !=NULL ) {return -1 ;
@@ -3372,7 +3372,7 @@ static gboolean tcp_chr_accept(QIOChannel *channel,static int tcp_chr_wait_connected (Chardev *chr,Error **errp) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;QIOChannelSocket *sioc;/* It can't wait on s->connected, since it is set asynchronously
@@ -3420,7 +3420,7 @@ int qemu_chr_fe_wait_connected(CharBackend *be, Error **errp)static void tcp_chr_free (Chardev *chr) { -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;tcp_chr_free_connection (chr);
@@ -3448,7 +3448,7 @@ static void qemu_chr_socket_connected(Object *src, Error *err, void *opaque) {QIOChannelSocket *sioc =QIO_CHANNEL_SOCKET (src);Chardev *chr = opaque; -TCPChardev *s = (TCPChardev *)chr; +SocketChardev *s = (SocketChardev *)chr;if (err) {check_report_connect_error (chr, err);
@@ -4730,7 +4730,7 @@ static const CharDriver serial_driver = {static gboolean socket_reconnect_timeout (gpointer opaque) {Chardev *chr = opaque; -TCPChardev *s = opaque; +SocketChardev *s = opaque;QIOChannelSocket *sioc; s->reconnect_timer =0 ;
@@ -4756,7 +4756,7 @@ static Chardev *qmp_chardev_open_socket(const CharDriver *driver, Error **errp) {Chardev *chr; -TCPChardev *s; +SocketChardev *s;ChardevSocket *sock = backend->u.socket.data;SocketAddress *addr = sock->addr;bool do_nodelay = sock->has_nodelay ? sock->nodelay : false;
@@ -4771,7 +4771,7 @@ static Chardev *qmp_chardev_open_socket(const CharDriver *driver,if (!chr) {return NULL ; } - s = (TCPChardev *)chr; + s = (SocketChardev *)chr; s->is_unix = addr->type ==SOCKET_ADDRESS_KIND_UNIX ; s->is_listen = is_listen;
@@ -4878,7 +4878,7 @@ static Chardev *qmp_chardev_open_socket(const CharDriver *driver, }static const CharDriver socket_driver = { - .instance_size =sizeof (TCPChardev), + .instance_size =sizeof (SocketChardev), .kind =CHARDEV_BACKEND_KIND_SOCKET , .parse = qemu_chr_parse_socket, .create = qmp_chardev_open_socket,
@@ -4906,7 +4906,7 @@ static Chardev *qmp_chardev_open_udp(const CharDriver *driver,QIOChannelSocket *sioc =qio_channel_socket_new ();char *name;Chardev *chr; -NetChardev *s; +UdpChardev *s; if (qio_channel_socket_dgram_sync(sioc, udp->local, udp->remote,
@@ -4924,7 +4924,7 @@ static Chardev *qmp_chardev_open_udp(const CharDriver *driver,qio_channel_set_name (QIO_CHANNEL (sioc), name);g_free (name); - s = (NetChardev *)chr; + s = (UdpChardev *)chr; s->ioc =QIO_CHANNEL (sioc);/* be isn't opened until we get a connection */ *be_opened = false;
@@ -4933,7 +4933,7 @@ static Chardev *qmp_chardev_open_udp(const CharDriver *driver, }static const CharDriver udp_driver = { - .instance_size =sizeof (NetChardev), + .instance_size =sizeof (UdpChardev), .kind =CHARDEV_BACKEND_KIND_UDP , .parse = qemu_chr_parse_udp, .create = qmp_chardev_open_udp,
Signature · 1 line
2.11.0
PATCH 15/20 spice-char: improve error reporting
In reply to Marc-André LureauSet errp to report errors up to the right monitor.
Use error_append_hint() to give hints about parameters on !qmp monitors, instead of a direct fprintf() call.
--- spice-qemu-char.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-)
spice-qemu-char.c +10 -20
@@ -2,6 +2,7 @@#include "trace.h" #include "ui/qemu-spice.h" #include "sysemu/char.h" +#include "qemu/error-report.h" #include <spice.h> #include <spice/protocol.h>
@@ -239,23 +240,6 @@ static void spice_port_set_fe_open(struct Chardev *chr, int fe_open)#endif } -static void print_allowed_subtypes (void ) -{ -const char ** psubtype; -int i; - -fprintf (stderr,"allowed names: " ); -for (i=0 , psubtype =spice_server_char_device_recognized_subtypes (); - *psubtype !=NULL ; ++psubtype, ++i) { -if (i ==0 ) { -fprintf (stderr,"%s" , *psubtype); - }else { -fprintf (stderr,", %s" , *psubtype); - } - } -fprintf (stderr,"\n" ); -} -static void spice_chr_accept_input (struct Chardev *chr) {SpiceChardev *s = (SpiceChardev *)chr;
@@ -302,8 +286,14 @@ static Chardev *qemu_chr_open_spice_vmc(const CharDriver *driver, } }if (*psubtype ==NULL ) { -fprintf (stderr,"spice-qemu-char: unsupported type: %s\n" , type); -print_allowed_subtypes (); +char *subtypes =g_strjoinv (", " , + (gchar **)spice_server_char_device_recognized_subtypes ()); + +error_setg (errp,"unsupported type name: %s" , type); +error_append_hint (errp,"allowed spice char type names: %s\n" , + subtypes); + +g_free (subtypes);return NULL ; }
@@ -326,7 +316,7 @@ static Chardev *qemu_chr_open_spice_port(const CharDriver *driver,SpiceChardev *s;if (name ==NULL ) { -fprintf (stderr,"spice-qemu-char: missing name parameter\n" ); +error_setg (errp,"missing name parameter" );return NULL ; }
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH 15/20] spice-char: improve error reporting
Quoted 10 lines · Marc-André Lureau
Set errp to report errors up to the right monitor.
Use
error_append_hint()to give hints about parameters on !qmp monitors, instead of a directfprintf()call.Signed-off-by Marc-André Lureau <[email protected]>--- spice-qemu-char.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 16/20 char: use error_report()
In reply to Marc-André LureauPrefer error_report() over fprintf(stderr..)
--- qemu-char.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-)
qemu-char.c +15 -12
@@ -451,8 +451,8 @@ int qemu_chr_fe_get_msgfd(CharBackend *be)int fd;int res = (qemu_chr_fe_get_msgfds (be, &fd,1 ) ==1 ) ? fd :-1 ;if (s &&qemu_chr_replay (s)) { -fprintf (stderr, -"Replay: get msgfd is not supported for serial devices yet\n" ); +error_report ("Replay: get msgfd is not supported " +"for serial devices yet" );exit (1 ); }return res;
@@ -1675,8 +1675,8 @@ static Chardev *qemu_chr_open_pty(const CharDriver *driver, ret->pty =g_strdup (pty_name); ret->has_pty = true; -fprintf (stderr,"char device redirected to %s (label %s)\n" , - pty_name, id); +error_report ("char device redirected to %s (label %s)" , + pty_name, id); s = (PtyChardev *)chr; s->ioc =QIO_CHANNEL (qio_channel_file_new_fd (master_fd));
@@ -3379,8 +3379,8 @@ static int tcp_chr_wait_connected(Chardev *chr, Error **errp)* in TLS and telnet cases, only wait for an accepted socket */ while (!s->ioc) {if (s->is_listen) { -fprintf (stderr,"QEMU waiting for connection on: %s\n" , - chr->filename); +error_report ("QEMU waiting for connection on: %s" , + chr->filename);qio_channel_set_blocking (QIO_CHANNEL (s->listen_ioc), true,NULL );tcp_chr_accept (QIO_CHANNEL (s->listen_ioc),G_IO_IN , chr);qio_channel_set_blocking (QIO_CHANNEL (s->listen_ioc), false,NULL );
@@ -4139,17 +4139,20 @@ Chardev *qemu_chr_new_from_opts(QemuOpts *opts, }if (is_help_option (qemu_opt_get (opts,"backend" ))) { -fprintf (stderr,"Available chardev backend types:\n" ); +GString *str =g_string_new ("" );for (i =0 ; i <ARRAY_SIZE (backends); i++) { cd = backends[i];if (cd) { -fprintf (stderr,"%s\n" , ChardevBackendKind_lookup[cd->kind]); +g_string_append_printf (str,"\n%s" , ChardevBackendKind_lookup[cd->kind]);if (cd->alias) { -fprintf (stderr,"%s\n" , cd->alias); +g_string_append_printf (str,"\n%s" , cd->alias); } } } -exit (!is_help_option (qemu_opt_get (opts,"backend" ))); + +error_report ("Available chardev backend types: %s" , str->str); +g_string_free (str, true); +exit (0 ); }if (id ==NULL ) {
@@ -4262,8 +4265,8 @@ Chardev *qemu_chr_new(const char *label, const char *filename)qemu_chr_set_feature (chr,QEMU_CHAR_FEATURE_REPLAY ); }if (qemu_chr_replay (chr) && chr->driver->chr_ioctl) { -fprintf (stderr, -"Replay: ioctl is not supported for serial devices yet\n" ); +error_report ("Replay: ioctl is not supported " +"for serial devices yet" ); }replay_register_char_driver (chr); }
Signature · 1 line
2.11.0
PATCH 17/20 gtk: overwrite the console.c char driver
In reply to Marc-André LureauInstead of registering a vc handler to allocate the Gtk VC Chardev, overwrite the console.c char driver.
A later patch, when switching to QOM, will register a default console vc QOM class if none has been registered before.
--- include/sysemu/char.h | 4 +--- ui/console.c | 24 +++++++----------------- ui/gtk.c | 30 +++++++++++++++++++++--------- 3 files changed, 29 insertions(+), 29 deletions(-)
include/sysemu/char.h +1 -3
@@ -507,9 +507,7 @@ void register_char_driver(const CharDriver *driver);extern int term_escape_char; -/* console.c */ -typedef Chardev *(VcHandler )(ChardevVC *vc,Error **errp); -void register_vc_handler (VcHandler *handler); +void qemu_chr_parse_vc (QemuOpts *opts,ChardevBackend *backend,Error **errp);#endif
ui/console.c +7 -17
@@ -2058,8 +2058,12 @@ static void text_console_do_init(Chardev *chr, DisplayState *ds)static const CharDriver vc_driver; -static Chardev *text_console_init (ChardevVC *vc,Error **errp) +static Chardev *vc_init (const CharDriver *driver, +const char *id,ChardevBackend *backend, +ChardevReturn *ret,bool *be_opened, +Error **errp) { +ChardevVC *vc = backend->u.vc.data;ChardevCommon *common =qapi_ChardevVC_base (vc);Chardev *chr;VCChardev *drv;
@@ -2105,26 +2109,13 @@ static Chardev *text_console_init(ChardevVC *vc, Error **errp)if (display_state) {text_console_do_init (chr, display_state); } -return chr; -} -static VcHandler *vc_handler = text_console_init; - -static Chardev *vc_init (const CharDriver *driver, -const char *id,ChardevBackend *backend, -ChardevReturn *ret,bool *be_opened, -Error **errp) -{/* console/chardev init sometimes completes elsewhere in a 2nd * stage, so defer OPENED events until they are fully initialized */ *be_opened = false; -return vc_handler (backend->u.vc.data, errp); -} -void register_vc_handler (VcHandler *handler) -{ - vc_handler = handler; +return chr; }void qemu_console_resize (QemuConsole *s,int width,int height)
@@ -2162,8 +2153,7 @@ PixelFormat qemu_default_pixelformat(int bpp)return pf; } -static void qemu_chr_parse_vc (QemuOpts *opts,ChardevBackend *backend, -Error **errp) +void qemu_chr_parse_vc (QemuOpts *opts,ChardevBackend *backend,Error **errp) {int val;ChardevVC *vc;
ui/gtk.c +21 -9
@@ -1712,16 +1712,14 @@ static void gd_vc_chr_set_echo(Chardev *chr, bool echo)static int nb_vcs;static Chardev *vcs[MAX_VCS ]; +static const CharDriver gd_vc_driver; -static Chardev *gd_vc_handler (ChardevVC *vc,Error **errp) +static Chardev *vc_init (const CharDriver *driver, +const char *id,ChardevBackend *backend, +ChardevReturn *ret,bool *be_opened, +Error **errp) { -static const CharDriver gd_vc_driver = { - .instance_size =sizeof (VCChardev), - .kind =CHARDEV_BACKEND_KIND_VC , - .chr_write = gd_vc_chr_write, - .chr_set_echo = gd_vc_chr_set_echo, - }; - +ChardevVC *vc = backend->u.vc.data;ChardevCommon *common =qapi_ChardevVC_base (vc);Chardev *chr;
@@ -1737,9 +1735,22 @@ static Chardev *gd_vc_handler(ChardevVC *vc, Error **errp) vcs[nb_vcs++] = chr; +/* console/chardev init sometimes completes elsewhere in a 2nd +* stage, so defer OPENED events until they are fully initialized +*/ + *be_opened = false; +return chr; } +static const CharDriver gd_vc_driver = { + .instance_size =sizeof (VCChardev), + .kind =CHARDEV_BACKEND_KIND_VC , + .parse = qemu_chr_parse_vc, .create = vc_init, + .chr_write = gd_vc_chr_write, + .chr_set_echo = gd_vc_chr_set_echo, +}; +static gboolean gd_vc_in (VteTerminal *terminal,gchar *text,guint size,gpointer user_data) {
@@ -2336,6 +2347,7 @@ void early_gtk_display_init(int opengl) }#if defined(CONFIG_VTE ) -register_vc_handler (gd_vc_handler); +/* overwrite the console.c vc driver */ +register_char_driver (&gd_vc_driver);#endif }
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH 17/20] gtk: overwrite the console.c char driver
Quoted 16 lines · Marc-André Lureau
Instead of registering a vc handler to allocate the Gtk VC Chardev, overwrite the
console.cchar driver.A later patch, when switching to QOM, will register a default console vc QOM class if none has been registered before.
Signed-off-by Marc-André Lureau <[email protected]>Reviewed-by Eric Blake <[email protected]>--- include/sysemu/char.h | 4 +--- ui/console.c | 24 +++++++----------------- ui/gtk.c | 30 +++++++++++++++++++++--------- 3 files changed, 29 insertions(+), 29 deletions(-)
ui/gtk.c static Chardev *gd_vc_handler(ChardevVC *vc, Error **errp) · line 1749
Quoted 4 lines
ui/gtk.c +4
-0+static const CharDriver gd_vc_driver = { + .instance_size =sizeof (VCChardev), + .kind =CHARDEV_BACKEND_KIND_VC , + .parse = qemu_chr_parse_vc, .create = vc_init,
Might be worth a tweak to split this to two lines. Either way, R-b stands.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 18/20 baum: use a common prefix for chr callbacks
In reply to Marc-André Lureau--- backends/baum.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
backends/baum.c +8 -8
@@ -253,7 +253,7 @@ static int baum_deferred_init(BaumChardev *baum) }/* The serial port can receive more of our data */ -static void baum_accept_input (struct Chardev *chr) +static void baum_chr_accept_input (struct Chardev *chr) {BaumChardev *baum = (BaumChardev *)chr;int room, first;
@@ -470,7 +470,7 @@ static int baum_eat_packet(BaumChardev *baum, const uint8_t *buf, int len) }/* The other end is writing some data. Store it and try to interpret */ -static int baum_write (Chardev *chr,const uint8_t *buf,int len) +static int baum_chr_write (Chardev *chr,const uint8_t *buf,int len) {BaumChardev *baum = (BaumChardev *)chr;int tocopy, cur, eaten, orig_len = len;
@@ -613,7 +613,7 @@ static void baum_chr_read(void *opaque) } } -static void baum_free (struct Chardev *chr) +static void baum_chr_free (struct Chardev *chr) {BaumChardev *baum = (BaumChardev *)chr;
@@ -624,7 +624,7 @@ static void baum_free(struct Chardev *chr) } } -static Chardev *chr_baum_init(const CharDriver *driver, +static Chardev *baum_chr_init(const CharDriver *driver, const char *id, ChardevBackend *backend, ChardevReturn *ret,
@@ -670,10 +670,10 @@ static void register_types(void)static const CharDriver driver = { .instance_size =sizeof (BaumChardev), .kind =CHARDEV_BACKEND_KIND_BRAILLE , - .create = chr_baum_init, - .chr_write = baum_write, - .chr_accept_input = baum_accept_input, - .chr_free = baum_free, + .create = baum_chr_init, + .chr_write = baum_chr_write, + .chr_accept_input = baum_chr_accept_input, + .chr_free = baum_chr_free, };register_char_driver (&driver);
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH 18/20] baum: use a common prefix for chr callbacks
Quoted 5 lines · Marc-André Lureau
Signed-off-by Marc-André Lureau <[email protected]>--- backends/baum.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 19/20 vc: use a common prefix for chr callbacks
In reply to Marc-André Lureauvc_chr_write() is more appropriate than _puts() since no newline is appended, even though it's not used only as a callback.
Keep "qemu_chr_parse" prefix, most chardev parse functions use this prefix atm.
--- ui/console.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
ui/console.c +12 -12
@@ -1051,7 +1051,7 @@ typedef struct VCChardev {QemuConsole *console; } VCChardev; -static int console_puts (Chardev *chr,const uint8_t *buf,int len) +static int vc_chr_write (Chardev *chr,const uint8_t *buf,int len) {VCChardev *drv = (VCChardev *)chr;QemuConsole *s = drv->console;
@@ -1139,13 +1139,13 @@ void kbd_put_keysym_console(QemuConsole *s, int keysym) *q++ ='[' ; *q++ = keysym &0xff ; }else if (s->echo && (keysym =='\r' || keysym =='\n' )) { -console_puts (s->chr, (const uint8_t *)"\r" ,1 ); +vc_chr_write (s->chr, (const uint8_t *)"\r" ,1 ); *q++ ='\n' ; }else { *q++ = keysym; }if (s->echo) { -console_puts (s->chr, buf, q - buf); +vc_chr_write (s->chr, buf, q - buf); } be = s->chr->be;if (be && be->chr_read) {
@@ -1962,7 +1962,7 @@ int qemu_console_get_height(QemuConsole *con, int fallback)return con ?surface_height (con->surface) : fallback; } -static void text_console_set_echo (Chardev *chr,bool echo) +static void vc_chr_set_echo (Chardev *chr,bool echo) {VCChardev *drv = (VCChardev *)chr;QemuConsole *s = drv->console;
@@ -2049,7 +2049,7 @@ static void text_console_do_init(Chardev *chr, DisplayState *ds) s->t_attrib.bgcol =QEMU_COLOR_BLUE ; len =snprintf (msg,sizeof (msg),"%s console\r\n" , chr->label); -console_puts (chr, (uint8_t *)msg, len); +vc_chr_write (chr, (uint8_t *)msg, len); s->t_attrib = s->t_attrib_default; }
@@ -2058,10 +2058,10 @@ static void text_console_do_init(Chardev *chr, DisplayState *ds)static const CharDriver vc_driver; -static Chardev *vc_init (const CharDriver *driver, -const char *id,ChardevBackend *backend, -ChardevReturn *ret,bool *be_opened, -Error **errp) +static Chardev *vc_chr_init (const CharDriver *driver, +const char *id,ChardevBackend *backend, +ChardevReturn *ret,bool *be_opened, +Error **errp) {ChardevVC *vc = backend->u.vc.data;ChardevCommon *common =qapi_ChardevVC_base (vc);
@@ -2197,9 +2197,9 @@ static const CharDriver vc_driver = { .instance_size = sizeof(VCChardev), .kind = CHARDEV_BACKEND_KIND_VC, .parse = qemu_chr_parse_vc, - .create = vc_init, - .chr_write = console_puts, - .chr_set_echo = text_console_set_echo, + .create = vc_chr_init, + .chr_write = vc_chr_write, + .chr_set_echo = vc_chr_set_echo, };static void register_types (void )
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH 19/20] vc: use a common prefix for chr callbacks
Quoted 10 lines · Marc-André Lureau
vc_chr_write()is more appropriate than_puts()since no newline is appended, even though it's not used only as a callback.Keep "
qemu_chr_parse" prefix, most chardev parse functions use this prefix atm.Signed-off-by Marc-André Lureau <[email protected]>--- ui/console.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 20/20 chardev: qom-ify
In reply to Marc-André LureauTurn Chardev into Object.
qemu_chr_alloc() is replaced by the qemu_chardev_new() constructor. It will call qemu_char_open() to open/intialize the chardev with the ChardevCommon *backend settings.
The CharDriver::create() callback is turned into a ChardevClass::open() which is called from the newly introduced qemu_chardev_open().
"chardev-gdb" and "chardev-hci" are internal chardev and aren't creatable directly with -chardev. Use a new internal flag to disable them. We may want to use TYPE_USER_CREATABLE interface instead, or perhaps allow -chardev usage.
Although in general we keep typename and macros private, unless the type is being used by some other file, in this patch, all types and common helper macros for qemu-char.c are in char.h. This is to help transition now (some types must be declared early, while some aren't shared) and when splitting in several units. This is to be improved later.
--- include/sysemu/char.h | 107 ++-- include/ui/console.h | 2 + backends/baum.c | 66 +-- backends/msmouse.c | 57 ++- backends/testdev.c | 34 +- gdbstub.c | 39 +- hw/bt/hci-csr.c | 55 +- monitor.c | 2 +- qemu-char.c | 1327 ++++++++++++++++++++++++++----------------------- spice-qemu-char.c | 142 +++--- ui/console.c | 62 ++- ui/gtk.c | 51 +- vl.c | 2 + 13 files changed, 1073 insertions(+), 873 deletions(-)
include/sysemu/char.h +58 -49
@@ -10,6 +10,7 @@#include "qapi/qmp/qstring.h" #include "qemu/main-loop.h" #include "qemu/bitmap.h" +#include "qom/object.h" /* character device */
@@ -90,7 +91,8 @@ typedef struct CharBackend {typedef struct CharDriver CharDriver ;struct Chardev { -const CharDriver *driver; +Object parent_obj; +QemuMutex chr_write_lock;CharBackend *be;char *label;
@@ -102,18 +104,6 @@ struct Chardev {QTAILQ_ENTRY (Chardev) next; }; -/** -* qemu_chr_alloc: -* @backend: the common backend config -* @errp: pointer to a NULL-initialized error object -* -* Allocate and initialize a new Chardev. -* -* Returns: a newly allocated Chardev, or NULL on error. -*/ -Chardev *qemu_chr_alloc (const CharDriver *driver, -ChardevCommon *backend,Error **errp); -/** * @qemu_chr_new_from_opts: *
@@ -455,54 +445,73 @@ void qemu_chr_fe_accept_input(CharBackend *be);int qemu_chr_add_client (Chardev *s,int fd);Chardev *qemu_chr_find (const char *name); -/** -* @qemu_chr_get_kind: -* -* Returns the kind of char backend, or -1 if unspecified. -*/ -ChardevBackendKind qemu_chr_get_kind (const Chardev *chr); - -static inline bool qemu_chr_is_ringbuf (const Chardev *chr) -{ -return qemu_chr_get_kind (chr) ==CHARDEV_BACKEND_KIND_RINGBUF || -qemu_chr_get_kind (chr) ==CHARDEV_BACKEND_KIND_MEMORY ; -} -bool qemu_chr_has_feature (Chardev *chr,CharDriverFeature feature);void qemu_chr_set_feature (Chardev *chr,CharDriverFeature feature);QemuOpts *qemu_chr_parse_compat (const char *label,const char *filename); +#define TYPE_CHARDEV "chardev" +#define CHARDEV (obj) OBJECT_CHECK(Chardev, (obj), TYPE_CHARDEV) +#define CHARDEV_CLASS (klass) \ + OBJECT_CLASS_CHECK(ChardevClass, (klass), TYPE_CHARDEV) +#define CHARDEV_GET_CLASS (obj) \ + OBJECT_GET_CLASS(ChardevClass, (obj), TYPE_CHARDEV) + +#define TYPE_CHARDEV_NULL "chardev-null" +#define TYPE_CHARDEV_MUX "chardev-mux" +#define TYPE_CHARDEV_RINGBUF "chardev-ringbuf" +#define TYPE_CHARDEV_PTY "chardev-pty" +#define TYPE_CHARDEV_CONSOLE "chardev-console" +#define TYPE_CHARDEV_STDIO "chardev-stdio" +#define TYPE_CHARDEV_PIPE "chardev-pipe" +#define TYPE_CHARDEV_MEMORY "chardev-memory" +#define TYPE_CHARDEV_PARALLEL "chardev-parallel" +#define TYPE_CHARDEV_FILE "chardev-file" +#define TYPE_CHARDEV_SERIAL "chardev-serial" +#define TYPE_CHARDEV_SOCKET "chardev-socket" +#define TYPE_CHARDEV_UDP "chardev-udp" + +#define CHARDEV_IS_MUX (chr) \ + object_dynamic_cast(OBJECT(chr), TYPE_CHARDEV_MUX) +#define CHARDEV_IS_RINGBUF (chr) \ + object_dynamic_cast(OBJECT(chr), TYPE_CHARDEV_RINGBUF) +#define CHARDEV_IS_PTY (chr) \ + object_dynamic_cast(OBJECT(chr), TYPE_CHARDEV_PTY) + +typedef struct ChardevClass { +ObjectClass parent_class; + +bool internal;/* TODO: eventually use TYPE_USER_CREATABLE */ + +void (*open)(Chardev *chr,ChardevBackend *backend, +bool *be_opened,Error **errp); + +int (*chr_write)(Chardev *s,const uint8_t *buf,int len); +int (*chr_sync_read)(Chardev *s,const uint8_t *buf,int len); +GSource *(*chr_add_watch)(Chardev *s,GIOCondition cond); +void (*chr_update_read_handler)(Chardev *s,GMainContext *context); +int (*chr_ioctl)(Chardev *s,int cmd,void *arg); +int (*get_msgfds)(Chardev *s,int * fds,int num); +int (*set_msgfds)(Chardev *s,int *fds,int num); +int (*chr_add_client)(Chardev *chr,int fd); +int (*chr_wait_connected)(Chardev *chr,Error **errp); +void (*chr_free)(Chardev *chr); +void (*chr_disconnect)(Chardev *chr); +void (*chr_accept_input)(Chardev *chr); +void (*chr_set_echo)(Chardev *chr,bool echo); +void (*chr_set_fe_open)(Chardev *chr,int fe_open); +}ChardevClass ; +struct CharDriver {const char *alias;ChardevBackendKind kind;void (*parse)(QemuOpts *opts,ChardevBackend *backend,Error **errp); -Chardev *(*create)(const CharDriver *driver, -const char *id, -ChardevBackend *backend, -ChardevReturn *ret,bool *be_opened, -Error **errp); -size_t instance_size; - -int (*chr_write)(struct Chardev *s,const uint8_t *buf,int len); -int (*chr_sync_read)(struct Chardev *s, -const uint8_t *buf,int len); -GSource *(*chr_add_watch)(struct Chardev *s,GIOCondition cond); -void (*chr_update_read_handler)(struct Chardev *s, -GMainContext *context); -int (*chr_ioctl)(struct Chardev *s,int cmd,void *arg); -int (*get_msgfds)(struct Chardev *s,int * fds,int num); -int (*set_msgfds)(struct Chardev *s,int *fds,int num); -int (*chr_add_client)(struct Chardev *chr,int fd); -int (*chr_wait_connected)(struct Chardev *chr,Error **errp); -void (*chr_free)(struct Chardev *chr); -void (*chr_disconnect)(struct Chardev *chr); -void (*chr_accept_input)(struct Chardev *chr); -void (*chr_set_echo)(struct Chardev *chr,bool echo); -void (*chr_set_fe_open)(struct Chardev *chr,int fe_open); }; +Chardev *qemu_chardev_new (const char *id,const char *typename, +ChardevBackend *backend,Error **errp); +void register_char_driver (const CharDriver *driver);extern int term_escape_char;
include/ui/console.h +2 -0
@@ -380,6 +380,8 @@ void graphic_hw_invalidate(QemuConsole *con);void graphic_hw_text_update (QemuConsole *con,console_ch_t *chardata);void graphic_hw_gl_block (QemuConsole *con,bool block); +void qemu_console_early_init (void ); +QemuConsole *qemu_console_lookup_by_index (unsigned int index);QemuConsole *qemu_console_lookup_by_device (DeviceState *dev,uint32_t head); QemuConsole *qemu_console_lookup_by_device_name(const char *device_id,
backends/baum.c +33 -33
141 lines not on this page · raw message
backends/msmouse.c +31 -26
104 lines not on this page · raw message
backends/testdev.c +18 -16
@@ -36,6 +36,10 @@ typedef struct {int in_buf_used; } TestdevChardev; +#define TYPE_CHARDEV_TESTDEV "chardev-testdev" +#define TESTDEV_CHARDEV (obj) \ + OBJECT_CHECK(TestdevChardev, (obj), TYPE_CHARDEV_TESTDEV) +/* Try to interpret a whole incoming packet */ static int testdev_eat_packet (TestdevChardev *testdev) {
@@ -78,9 +82,9 @@ static int testdev_eat_packet(TestdevChardev *testdev) }/* The other end is writing some data. Store it and try to interpret */ -static int testdev_write (Chardev *chr,const uint8_t *buf,int len) +static int testdev_chr_write (Chardev *chr,const uint8_t *buf,int len) { -TestdevChardev *testdev = (TestdevChardev *)chr; +TestdevChardev *testdev =TESTDEV_CHARDEV (chr);int tocopy, eaten, orig_len = len;while (len) {
@@ -103,30 +107,28 @@ static int testdev_write(Chardev *chr, const uint8_t *buf, int len)return orig_len; } -static Chardev *chr_testdev_init (const CharDriver *driver, -const char *id, -ChardevBackend *backend, -ChardevReturn *ret, -bool *be_opened, -Error **errp) +static void char_testdev_class_init (ObjectClass *oc,void *data) { -TestdevChardev *testdev =g_new0 (TestdevChardev,1 );; -Chardev *chr = (Chardev *)testdev; - - chr->driver = driver; +ChardevClass *cc =CHARDEV_CLASS (oc); -return chr; + cc->chr_write = testdev_chr_write; } +static const TypeInfo char_testdev_type_info = { + .name =TYPE_CHARDEV_TESTDEV , + .parent =TYPE_CHARDEV , + .instance_size =sizeof (TestdevChardev), + .class_init = char_testdev_class_init, +}; +static void register_types (void ) {static const CharDriver driver = { - .instance_size =sizeof (TestdevChardev), .kind =CHARDEV_BACKEND_KIND_TESTDEV , - .create = chr_testdev_init, - .chr_write = testdev_write, }; +register_char_driver (&driver); +type_register_static (&char_testdev_type_info); }type_init (register_types);
gdbstub.c +32 -7
@@ -1723,18 +1723,35 @@ static void gdb_sigterm_handler(int signal) }#endif +static void gdb_monitor_open (Chardev *chr,ChardevBackend *backend, +bool *be_opened,Error **errp) +{ + *be_opened = false; +} + +static void char_gdb_class_init (ObjectClass *oc,void *data) +{ +ChardevClass *cc =CHARDEV_CLASS (oc); + + cc->internal = true; + cc->open = gdb_monitor_open; + cc->chr_write = gdb_monitor_write; +} + +#define TYPE_CHARDEV_GDB "chardev-gdb" + +static const TypeInfo char_gdb_type_info = { + .name =TYPE_CHARDEV_GDB , + .parent =TYPE_CHARDEV , + .class_init = char_gdb_class_init, +}; +int gdbserver_start (const char *device) {GDBState *s;char gdbstub_device_name[128 ];Chardev *chr =NULL ;Chardev *mon_chr; -ChardevCommon common = {0 }; -static const CharDriver driver = { - .instance_size =sizeof (Chardev), - .kind =-1 , - .chr_write = gdb_monitor_write - };if (!device)return -1 ;
@@ -1767,7 +1784,8 @@ int gdbserver_start(const char *device)qemu_add_vm_change_state_handler (gdb_vm_state_change,NULL );/* Initialize a monitor terminal for gdb */ - mon_chr =qemu_chr_alloc (&driver, &common, &error_abort); + mon_chr =qemu_chardev_new (NULL ,TYPE_CHARDEV_GDB , +NULL , &error_abort);monitor_init (mon_chr,0 ); }else {if (qemu_chr_fe_get_driver (&s->chr)) {
@@ -1790,4 +1808,11 @@ int gdbserver_start(const char *device) return 0; } + +static void register_types (void ) +{ +type_register_static (&char_gdb_type_info); +} + +type_init (register_types);#endif
hw/bt/hci-csr.c +38 -17
73 lines not on this page · raw message
monitor.c +1 -1
@@ -3194,7 +3194,7 @@ static void ringbuf_completion(ReadLineState *rs, const char *str)if (!strncmp (chr_info->label, str, len)) {Chardev *chr =qemu_chr_find (chr_info->label); -if (chr &&qemu_chr_is_ringbuf (chr)) { +if (chr &&CHARDEV_IS_RINGBUF (chr)) {readline_add_completion (rs, chr_info->label); } }
qemu-char.c +712 -615
2,399 lines not on this page · raw message
spice-qemu-char.c +81 -61
142 lines not on this page · raw message
ui/console.c +37 -25
62 lines not on this page · raw message
ui/gtk.c +28 -23
51 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.11.0
Part of the diff is not shown here. View the raw message.
Quoted 26 lines · Marc-André Lureau
Turn Chardev into Object.
qemu_chr_alloc()is replaced by theqemu_chardev_new()constructor. It will callqemu_char_open()to open/intialize the chardev with the ChardevCommon *backend settings.The
CharDriver::create()callback is turned into aChardevClass::open()which is called from the newly introducedqemu_chardev_open()."chardev-gdb" and "chardev-hci" are internal chardev and aren't creatable directly with -chardev. Use a new internal flag to disable them. We may want to use
TYPE_USER_CREATABLEinterface instead, or perhaps allow -chardev usage.Although in general we keep typename and macros private, unless the type is being used by some other file, in this patch, all types and common helper macros for
qemu-char.care inchar.h. This is to help transition now (some types must be declared early, while some aren't shared) and when splitting in several units. This is to be improved later.Signed-off-by Marc-André Lureau <[email protected]>---
+++
b/qemu-char.c
qemu-char.c int qemu_chr_fe_get_msgfds(CharBackend *be, int *fds, int len) · line 437
Quoted 6 lines
qemu-char.c +2
-1@@ -466,7 +433,8 @@ int qemu_chr_fe_get_msgfds(CharBackend *be, int *fds, int len)return -1 ; } -return s->driver->get_msgfds ? s->driver->get_msgfds (s, fds, len) :-1 ; +return CHARDEV_GET_CLASS (s)->get_msgfds ? +CHARDEV_GET_CLASS (s)->get_msgfds (s, fds, len) :-1 ;
I'm not familiar enough with the Object hierarchy to know if there is any significant runtime cost to CHARDEV_GET_CLASS() that would warrant capturing the output in a temporary variable, or if it is simple enough that a compiler can already figure out that it is a reusable value rather than computing it twice. Probably not worrying about, though, unless it actually shows up in a hot spot on a trace.
Quoted 4 lines
qemu-char.c +0
-0@@ -4957,47 +4994,96 @@ void qemu_chr_set_feature(Chardev *chr,return set_bit (feature, chr->features); }
qemu-char.c void qemu_chr_set_feature(Chardev *chr, · line 5004
Quoted 10 lines
qemu-char.c +8
-2-ChardevReturn *qmp_chardev_add (const char *id,ChardevBackend *backend, -Error **errp) +static const ChardevClass *char_get_class (const char *driver,Error **errp) +{ +ObjectClass *oc; +const ChardevClass *cc; +char *typename =g_strdup_printf ("chardev-%s" , driver); + + oc =object_class_by_name (typename); +g_free (typename);
char_get_class("tty", NULL) will fail, because that's merely an alias name rather than the canonical "serial" name. Will that matter to any of the code? I didn't spot anything, so I'm not letting it stop my review.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org