Skip to content

chardev: refactoring & many bugfixes related tcp_chr_wait_connected

Daniel P. Berrangé qemu-devel 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest16 patches 2 repliesIn review
  2. v216 patches 7 repliesSuperseded
  3. v112 patches 26 repliesSuperseded

Changes in v3 from the cover letter

- Fix thread between qio_task_thread_worker unlocking mutex and qio_task_thread_result free'ing mutex (Peter)
- Ensure tcp_chr_wait_connected destroys any pending reconnect_timer GSource
- Use g_setenv/g_unsetenv instead of setenv/unsetenv for platform portability

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/16io: store reference to thread information in the QIOTask structio/task.c+34 -300 replies
2/16io: add qio_task_wait_thread to join with a background threadinclude/io/task.h io/task.c io/trace-events+67 -50 replies
3/16chardev: fix validation of options for QMP created chardevschardev/char-socket.c+66 -260 replies
4/16chardev: forbid 'reconnect' option with server socketschardev/char-socket.c+8 -10 replies
5/16chardev: forbid 'wait' option with client socketschardev/char-socket.c tests/ivshmem-test.c tests/libqtest.c +1 more+16 -60 replies
6/16chardev: remove many local variables in qemu_chr_parse_socketchardev/char-socket.c+18 -220 replies
7/16chardev: ensure qemu_chr_parse_compat reports missing driver errorchardev/char.c tests/test-char.c+4 -10 replies
8/16chardev: remove unused 'sioc' variable & cleanup pathschardev/char-socket.c+7 -150 replies
9/16chardev: split tcp_chr_wait_connected into two methodschardev/char-socket.c+37 -220 replies
10/16chardev: split up qmp_chardev_open_socket connection codechardev/char-socket.c+60 -360 replies
11/16chardev: use a state machine for socket connection statechardev/char-socket.c+49 -140 replies
12/16chardev: honour the reconnect setting in tcp_chr_wait_connectedchardev/char-socket.c+9 -20 replies
13/16chardev: disallow TLS/telnet/websocket with tcp_chr_wait_connectedchardev/char-socket.c+14 -20 replies
14/16chardev: fix race with client connections in tcp_chr_wait_connectedchardev/char-socket.c+86 -40 replies
15/16tests: expand coverage of socket chardev testtests/test-char.c+475 -1650 replies
16/16chardev: ensure termios is fully initializedchardev/char-serial.c+1 -10 replies

Reviews trailers per patch

10 of 16 patches have a Reviewed-by or Acked-by.

PatchMarc-André LureauThomas Huth
1/16
2/16
3/16R-b
4/16R-b R-b
5/16R-b R-b
6/16R-b
7/16
8/16R-b R-b
9/16R-b
10/16R-b
11/16R-b
12/16R-b
13/16R-b
14/16
15/16
16/16

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [Qemu-devel] [PATCH v3 00/16] chardev: refactoring & many bugfixes related tcp_chr_wait_connected

This is a followup to

v1: https://lists.gnu.org/archive/html/qemu-devel/2019-01/msg03344.html
v2: http://lists.nongnu.org/archive/html/qemu-devel/2019-01/msg05947.html

This series comes out of a discussion between myself & Yongji Xie in:

https://lists.gnu.org/archive/html/qemu-devel/2019-01/msg01881.html

I eventually understood that the problem faced was that tcp_chr_wait_connected was racing with the background connection attempt previously started, causing two connections to be established. This broke because some vhost user servers only allow a single connection.

After messing around with the code alot the final solution was in fact very easy. We simply have to delay the first background connection attempt until the main loop is running. It will then automatically turn into a no-op if tcp_chr_wait_connected has been run. This is dealt with in the last patch in this series

I believe this should solve the problem Yongji Xie faced, and thus not require us to add support for "nowait" option with client sockets at all. The reconnect=1 option effectively already implements nowait semantics, and now plays nicely with tcp_chr_wait_connected.

In investigating this I found various other bugs that needed fixing and identified some useful refactoring to simplify / clarify the code, hence this very long series.

This series passes make check-unit & check-qtest (for x86_64 target).

I did a test with tests/vhost-user-bridge too, which was in fact already broken for the same reason Yongji Xie found - it only accepts a single connection. This series fixes use of reconnect=1 with vhost-user-bridge.

Changed in v3:

- Fix thread between qio_task_thread_worker unlocking mutex and qio_task_thread_result free'ing mutex (Peter)
- Ensure tcp_chr_wait_connected destroys any pending reconnect_timer GSource
- Use g_setenv/g_unsetenv instead of setenv/unsetenv for platform portability

Changed in v2:

- Rewrite the way we synchronize in tcp_chr_wait_connected again to cope with chardev+device hotplug scenario
- Add extensive unit test coverage
- Resolve conflicts with git master

Daniel P. Berrangé (16):
io: store reference to thread information in the QIOTask struct
io: add qio_task_wait_thread to join with a background thread
chardev: fix validation of options for QMP created chardevs
chardev: forbid 'reconnect' option with server sockets
chardev: forbid 'wait' option with client sockets
chardev: remove many local variables in qemu_chr_parse_socket
chardev: ensure qemu_chr_parse_compat reports missing driver error
chardev: remove unused 'sioc' variable & cleanup paths
chardev: split tcp_chr_wait_connected into two methods
chardev: split up qmp_chardev_open_socket connection code
chardev: use a state machine for socket connection state
chardev: honour the reconnect setting in tcp_chr_wait_connected
chardev: disallow TLS/telnet/websocket with tcp_chr_wait_connected
chardev: fix race with client connections in tcp_chr_wait_connected
tests: expand coverage of socket chardev test
chardev: ensure termios is fully initialized

 chardev/char-serial.c          |   2 +-
 chardev/char-socket.c          | 490 ++++++++++++++++++-------
 chardev/char.c                 |   2 +
 include/io/task.h              |  29 +-
 io/task.c                      | 101 ++++--
 io/trace-events                |   2 +
 tests/ivshmem-test.c           |   2 +-
 tests/libqtest.c               |   4 +-
 tests/test-char.c              | 643 ++++++++++++++++++++++++---------
 tests/test-filter-redirector.c |   4 +-
 10 files changed, 939 insertions(+), 340 deletions(-)
Signature · 1 line
2.20.1