qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v2] qemu-nbd: Implement socket activation.


From: Stefan Hajnoczi
Subject: Re: [Qemu-devel] [PATCH v2] qemu-nbd: Implement socket activation.
Date: Fri, 3 Feb 2017 15:16:43 +0000
User-agent: Mutt/1.7.1 (2016-10-04)

On Thu, Feb 02, 2017 at 05:16:25PM +0000, Richard W.M. Jones wrote:
> Socket activation (sometimes known as systemd socket activation)
> allows an Internet superserver to pass a pre-opened listening socket
> to the process, instead of having qemu-nbd open a socket itself.  This
> is done via the LISTEN_FDS and LISTEN_PID environment variables, and a
> standard file descriptor range.
> 
> This change partially implements socket activation for qemu-nbd.  If
> the environment variables are set correctly, then socket activation
> will happen automatically, otherwise everything works as before.  The
> limitation is that LISTEN_FDS must be 1.
> 
> Signed-off-by: Richard W.M. Jones.
> ---
>  qemu-nbd.c | 172 
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
>  1 file changed, 163 insertions(+), 9 deletions(-)
> 
> diff --git a/qemu-nbd.c b/qemu-nbd.c
> index c734f62..b3088d0 100644
> --- a/qemu-nbd.c
> +++ b/qemu-nbd.c
> @@ -463,6 +463,135 @@ static QCryptoTLSCreds *nbd_get_tls_creds(const char 
> *id, Error **errp)
>      return creds;
>  }
>  
> +static void setup_address_and_port(const char **address, const char **port)
> +{
> +    if (*address == NULL) {
> +        *address = "0.0.0.0";
> +    }
> +
> +    if (*port == NULL) {
> +        *port = g_strdup_printf("%d", NBD_DEFAULT_PORT);;

Please stringify NBD_DEFAULT_PORT instead of using g_strdup_printf().
That avoids the memory leak.

> @@ -751,6 +881,19 @@ int main(int argc, char **argv)
>      trace_init_file(trace_file);
>      qemu_set_log(LOG_TRACE);
>  
> +    socket_activation = check_socket_activation();
> +    if (socket_activation == 0) {
> +        setup_address_and_port(&bindto, &port);
> +    } else {
> +        /* Using socket activation - check user didn't use -p etc. */
> +        const char *err_msg = socket_activation_validate_opts(device, 
> sockpath,
> +                                                              bindto, port);

Daemonizing is also incompatible with socket activation.  We've marked
the fds O_CLOEXEC so the child won't have access to them.  Please add an
error in case a user tries this.

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]