I had a think about this.
nbd_connect_systemd_socket_activation uses SSA to pass in a listening
socket (not a connected socket), so it is expected that the child
calls accept(2) at least once on the socket passed in, and presumably
anticipated that the child could call accept(2) multiple times.
It therefore makes sense that other clients might use the SSA socket.
But using nbd_get_uri to obtain this "secret" socket is an unexpected
side effect of adding that API.
Since it's a listening socket, that rules out future use of socketpair(2)
(because that only creates connected sockets, and as far as I can tell
there is no way to pass connected sockets through SSA).
We might possibly change the implementation in future to use an
abstract socket (a Linux extension). Those are in theory expressible
as NBD URIs, although it's unlikely that any C library can handle such
URIs properly, certainly not libxml2.
So I think we can do this as proposed, BUT:
- It needs to be documented in the nbd_connect_systemd_socket_activation
man page.
- Documentation needs to state that if nbd_get_uri() returns NULL or
nbd_can_multi_conn() returns <= 0, then multi-conn isn't supported.
- Need to also document how to close these shared sockets without
deadlocking.
I'm still wondering if some kind of nbd_share_systemd_socket_activation()
call might be implemented. It would return the "secret" socket path,
plus perhaps set a flag on the handle to note that the handle is
shared and somehow fix the shutdown path. But I'm not sure how to
make that work, and if it's just a more clumsy version of the above.
Rich.
--
Richard Jones, Virtualization Group, Red Hat
http://people.redhat.com/~rjones
Read my programming and virtualization blog:
http://rwmj.wordpress.com
Fedora Windows cross-compiler. Compile Windows programs, test, and
build Windows installers. Over 100 libraries supported.
http://fedoraproject.org/wiki/MinGW