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! Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v
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
Possibly Parallel Threads
- Re: [PATCH libnbd] states: connect_command: Don't set O_NONBLOCK on socket passed to child.
- [PATCH libnbd] states: connect_command: Don't set O_NONBLOCK on socket passed to child.
- [PATCH libnbd 0/2] api: Add support for AF_VSOCK.
- [LIBNBD SECURITY PATCH 0/1] NBD Protocol Downgrade Attack in libnbd
- Re: [PATCH libnbd] states: connect_command: Don't set O_NONBLOCK on socket passed to child.