[Libguestfs] [libnbd PATCH 2/2] poll: Improve our interface

Eric Blake eblake at redhat.com
Thu Jun 27 05:03:11 UTC 2019


On 6/26/19 11:29 PM, Eric Blake wrote:
> Make nbd_poll slightly more like poll(), allowing a user to detect
> timeouts by returning 0 on timeout and 1 when we made progress. It
> turns out that none of our internal uses ever expect a timeout (we
> only call nbd_internal_poll with timeout==-1 because we expect a reply
> from the server), but the public function might as well be nicer.
> 
> Also handle POLLERR (server closed its read end, so our writes will
> fail) and POLLNVAL (the fd itself is closed) as outright errors, and
> POLLHUP the same as POLLIN (the server closed its write end, so read()
> will eventually see EOF even if we have to drain a buffer first).
> 
> Perhaps we also want to add an nbd_aio_notify_err() that can inform
> the machine of any externally-detected error on the fd to the server,
> where the poll loop invokes that on POLLERR, and where we tweak the
> generator to permit that external event in any other public state.
> But that's a bigger patch.
> ---
>  generator/generator | 18 +++++++++++++-----
>  lib/poll.c          | 13 ++++++++++---
>  2 files changed, 23 insertions(+), 8 deletions(-)
> 

> +++ b/lib/poll.c
> @@ -57,21 +57,28 @@ nbd_unlocked_poll (struct nbd_handle *h, int timeout)
>      set_error (errno, "poll");
>      return -1;
>    }

I also need to squash in this, to fix our use of an uninitialized
variable when nbd_aio_get_direction returns 0 (such as when we are
already DEAD):

diff --git i/lib/poll.c w/lib/poll.c
index d356afe..fc6aae5 100644
--- i/lib/poll.c
+++ w/lib/poll.c
@@ -45,6 +45,8 @@ nbd_unlocked_poll (struct nbd_handle *h, int timeout)
   case LIBNBD_AIO_DIRECTION_BOTH:
     fds[0].events = POLLIN|POLLOUT;
     break;
+  default:
+    fds[0].events = 0;
   }
   fds[0].revents = 0;

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20190627/ca09a45d/attachment.sig>


More information about the Libguestfs mailing list