Re: [Libguestfs] [nbdkit PATCH] nbd: Add new nbd forwarding plugin

Eric Blake
2017-11-12T03:26:04Z

On 11/11/2017 08:33 PM, Eric Blake wrote:
> This is a minimal implementation of an NBD forwarder; it lets us
> convert between old and newstyle connections (great if a client
> expects one style but the real server only provides the other),
> or add TLS safety on top of a server without having to rewrite
> that server.  Right now, the real server is expected to live
> on a named Unix socket, and the transactions are serialized
> rather than interleaved; further enhancements could be made to
> also permit TCP servers or more efficient transmission.
>
> I also envision the possibility of enhancing our testsuite to
> use NBD forwarding as a great test of our server.
>
> Signed-off-by: Eric Blake <eblake@redhat.com>
>

> +
> +/* Free up the per-connection handle. */
> +static void
> +nbd_close (void *handle)
> +{
> +  struct handle *h = handle;
> +
> +  close (h->fd);
> +  free (h);
> +}

Oh, I just realized: prior to dropping the socket, this should do:

if (!h->dead)
  nbd_request (h, NBD_CMD_DISC, 0, 0, &cookie);

to let the real server get a cleaner shutdown.

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