nbd: Use non-blocking pipe-to-self
commite0d324683c86455a2fe62e97d57f1313cad9c9f3
authorEric Blake <eblake@redhat.com>
Thu, 20 Jun 2019 19:03:18 +0000 (20 14:03 -0500)
committerEric Blake <eblake@redhat.com>
Thu, 20 Jun 2019 19:28:29 +0000 (20 14:28 -0500)
treef28bb93c31653d422df437597c20193f3f5dcabb
parent44c823e483546eb0e97575befd65f79815fe0989
nbd: Use non-blocking pipe-to-self

Although unlikely, if a user scales up operations by increasing the
number of threads beyond the limits of what a pipe can buffer, then
attempting to write to the pipe-to-self could stall, while the lock is
held. Better is to use a non-blocking pipe-to-self, and ignore EAGAIN
failures (the pipe was full, but that still means poll will see POLLIN
thanks to some other thread, and we didn't need to kick after all), as
well as to drain the pipe without intervening polls if there is a
backlog.

Besides, https://cr.yp.to/docs/selfpipe.html is a fairly canonical
description of pipe-to-self, and mentions that it should be
"non-blocking, just in case". :)

Signed-off-by: Eric Blake <eblake@redhat.com>
plugins/nbd/nbd.c