This might not be the final solution, but it certainly seems to solve a deadlock for me that I could trigger by using 'nbdkit --filter=noparallel memory 512k' and calling nbd_aio_pread for a request larger than 256k (enough for the Linux kernel to block the server until libnbd read()s), immediately followed by nbd_aio_pwrite for a request larger than 256k (enough to block libnbd until the server read()s, but the serialized server won't read until we parse off the reply). My solution was to allow a notifyread at any time we are in the middle of writing a request, at which point we pause the current write, force the state machine to completely receive the reply, then resume where we left off writing the request. Eric Blake (3): commands: Preserve FIFO ordering states: Split ISSUE_COMMAND.SEND_REQUEST states: Allow in-flight read while writing next command generator/generator | 34 +++++++++++++++- generator/states-issue-command.c | 68 ++++++++++++++++++++++++-------- generator/states-reply.c | 18 +++++++-- lib/internal.h | 1 + lib/rw.c | 13 ++++-- 5 files changed, 108 insertions(+), 26 deletions(-) -- 2.20.1