https://gitlab.com/qemu-project/qemu/-/issues/3169 was an excellent bug report of a deadlock scenario when qemu opens both the server and client end of an NBD intermediary in a qcow2 backing chain. It took me quite a bit of time to understand why the deadlock was even happening, and then some mental gymnastics on how best to break the deadlock. Ideally - we'd get rid of all nested event loops, and have the main loop do EVERYTHING event-driven. But that's a much bigger code change to the entire code base of QEMU, so I went with the next best thing of keeping the AioContext nested loop but ensuring that accepting NBD clients is now properly part of the AioContext rather than gated by only the main loop progress.
I have not researched how long the deadlock has been present, to determine if it has ever worked before earlier refactorings when we started using AioContext more heavily, or if it has always been broken until now to try and connect QEMU as a client to a self-served NBD server. But either way, I think this series should be part of the 10.2 release; I'm awfully close to soft freeze, but I think this counts as a bug fix worth having even if it doesn't make it in before -rc1. Eric Blake (8): qio: Add trace points to net_listener qio: Minor optimization when callback function is unchanged qio: Remember context of qio_net_listener_set_client_func_full qio: Factor out helpers qio_net_listener_[un]watch qio: Let listening sockets remember their owning QIONetListener qio: Hoist ref of listener outside loop qio: Use AioContext for default-context QIONetListener iotests: Add coverage of recent NBD qio deadlock fix include/io/channel-socket.h | 1 + include/io/net-listener.h | 1 + io/channel-socket.c | 1 + io/net-listener.c | 136 +++++++++++------- io/trace-events | 5 + tests/qemu-iotests/tests/nbd-in-qcow2-chain | 84 +++++++++++ .../qemu-iotests/tests/nbd-in-qcow2-chain.out | 56 ++++++++ tests/qemu-iotests/tests/vvfat.out | 0 8 files changed, 236 insertions(+), 48 deletions(-) create mode 100755 tests/qemu-iotests/tests/nbd-in-qcow2-chain create mode 100644 tests/qemu-iotests/tests/nbd-in-qcow2-chain.out mode change 100755 => 100644 tests/qemu-iotests/tests/vvfat.out -- 2.51.1
