Add 'maxqdepth' as an option to tty character devices.
PATCH v4 1/1 Add 'maxqdepth' as an option to tty character devices.
From: "John V. Baboval" <[email protected]>
This parameter will cause writes to tty backed chardevs to return -EAGAIN if the backing tty has buffered more than the specified number of characters. When data is sent, the TIOCOUTQ ioctl is invoked to determine the current TTY output buffer depth.
Background:
Some devices use DTR/DSR as flow control. (eg. Check/Receipt printers with some POS software). When the device de-asserts DTR, the guest OS notifies the application and new data is blocked. When running on a QEMU serial port backed by a TTY, though the guest stops transmitting, all the characters in the TTY output buffer are still sent. The device buffer overflows and data is lost. In this case the user could set maxqdepth=1.
---
Includes changes recommended by Eric Blake and Paolo Bonzini:
Parameter documentation includes a (since 1.6)
Documentation for stale @type parameter was removed
maxqdepth parameter is now optional
Patch passes style checks
qemu_chr_parse_serial sets has_maxqdepth as appropriate
include/sysemu/char.h | 2 ++ qapi-schema.json | 7 +++++-- qemu-char.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- qemu-options.hx | 4 ++-- 4 files changed, 54 insertions(+), 5 deletions(-)
include/sysemu/char.h +2 -0
@@ -43,6 +43,7 @@ typedef struct {#define CHR_IOCTL_SERIAL_SET_TIOCM 13#define CHR_IOCTL_SERIAL_GET_TIOCM 14 +#define CHR_IOCTL_SERIAL_TIOCOUTQ 15#define CHR_TIOCM_CTS 0x020#define CHR_TIOCM_CAR 0x040
@@ -77,6 +78,7 @@ struct CharDriverState {int fe_open;int explicit_fe_open;int avail_connections; +uint32_t maxqdepth;QemuOpts *opts;QTAILQ_ENTRY (CharDriverState) next; };
qapi-schema.json +5 -2
@@ -3182,11 +3182,14 @@ # # @device: The name of the special file for the device, # i.e. /dev/ttyS0 on Unix or COM1: on Windows -# @type: What kind of device this is. +# +# @maxqdepth: #optional The maximum depth of the underlying tty +# output queue (Unix) (Since 1.6) # # Since: 1.4 ## -{ 'type': 'ChardevHostdev', 'data': { 'device' : 'str' } } +{ 'type': 'ChardevHostdev', 'data': { 'device' : 'str', + '*maxqdepth' : 'int' } } ## # @ChardevSocket:
qemu-char.c +45 -1
94 lines not on this page · raw message
qemu-options.hx +2 -2
@@ -1792,8 +1792,8 @@ DEF("chardev", HAS_ARG, QEMU_OPTION_chardev, #endif #if defined(__linux__) || defined(__sun__) || defined(__FreeBSD__) \ || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) - "-chardev serial,id=id,path=path[,mux=on|off]\n" - "-chardev tty,id=id,path=path[,mux=on|off]\n" + "-chardev serial,id=id,path=path[,mux=on|off][,maxqdepth=count]\n" + "-chardev tty,id=id,path=path[,mux=on|off][,maxqdepth=count]\n" #endif #if defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__) "-chardev parallel,id=id,path=path[,mux=on|off]\n"
Signature · 1 line
1.7.9.5
Quoted 14 lines · John Baboval
From: "John V. Baboval" <[email protected]>
This parameter will cause writes to tty backed chardevs to return
-EAGAINif the backing tty has buffered more than the specified number of characters. When data is sent, the TIOCOUTQ ioctl is invoked to determine the current TTY output buffer depth.+++
b/qapi-schema.jsonqapi-schema.json +0
-1@@ -3182,11 +3182,14 @@ # # @device: The name of the special file for the device, # i.e. /dev/ttyS0 on Unix or COM1: on Windows -# @type: What kind of device this is.
qapi-schema.json line 3193
Quoted 10 lines
qapi-schema.json +5
-1+# +# @maxqdepth: #optional The maximum depth of the underlying tty +# output queue (Unix) (Since 1.6) # # Since: 1.4 ## -{ 'type': 'ChardevHostdev', 'data': { 'device' : 'str' } } +{ 'type': 'ChardevHostdev', 'data': { 'device' : 'str', + '*maxqdepth' : 'int' } }
Thanks; this interface change looks better (I'd still like to see someone working on introspection, but it doesn't have to be you). I'll still leave the implementation details to others more qualified for that part of the review. In particular, since you are claiming this optional attribute is Linux-only, that means we'd need introspection to know whether a given qemu build supports the field (compiled on Linux) or not (compiled on mingw), not just whether the qemu is new enough (1.6) or older (1.4).
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 24 lines · Eric Blake
Quoted 13 lines · John Baboval
From: "John V. Baboval" <[email protected]>
This parameter will cause writes to tty backed chardevs to return
-EAGAINif the backing tty has buffered more than the specified number of characters. When data is sent, the TIOCOUTQ ioctl is invoked to determine the current TTY output buffer depth.+++
b/qapi-schema.jsonqapi-schema.json +0
-1@@ -3182,11 +3182,14 @@ # # @device: The name of the special file for the device, # i.e. /dev/ttyS0 on Unix or COM1: on Windows -# @type: What kind of device this is.qapi-schema.json line 3193
Quoted 10 lines
qapi-schema.json +5
-1+# +# @maxqdepth: #optional The maximum depth of the underlying tty +# output queue (Unix) (Since 1.6) # # Since: 1.4 ## -{ 'type': 'ChardevHostdev', 'data': { 'device' : 'str' } } +{ 'type': 'ChardevHostdev', 'data': { 'device' : 'str', + '*maxqdepth' : 'int' } }
Quoted 9 lines
Thanks; this interface change looks better (I'd still like to see someone working on introspection, but it doesn't have to be you). I'll still leave the implementation details to others more qualified for that part of the review. In particular, since you are claiming this optional attribute is Linux-only, that means we'd need introspection to know whether a given qemu build supports the field (compiled on Linux) or not (compiled on mingw), not just whether the qemu is new enough (1.6) or older (1.4).
I believe (though I haven't tested on Windows) that the option at least does no harm there. You can still set it - It's just a no-op.