On 5/25/19 1:10 PM, Richard W.M. Jones wrote:
Try doing:
$ nbdsh nbd> h.connect_command (["nbdkit", "-s", "null"])
At this point you may observe your laptop fan starts to spin and nbdkit is consuming 100% of CPU. In all other respects everything works fine, you can send commands etc.
Anyway I tracked the issue down. nbdkit sits in a loop continuously reading stdin, each read(2) call returning EAGAIN.
The reason for that is because libnbd opens a socketpair with the SOCK_NONBLOCK option and passes one half directly to the forked subprocess.
It's obviously a bug, but I'm not sure if libnbd should be unsetting the SOCK_NONBLOCK option or if nbdkit should be doing it. Maybe both!
Both wouldn't hurt for robustness, but it is more common to fix the process sending in the non-blocking fd to an unsuspecting child than to write child processes designed to be robust against parents that forgot. So I see that you followed precedent and posted a patch for libnbd first :) -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org