qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Richard W.M. Jones" <rjones@redhat.com>
To: pbonzini@redhat.com
Cc: qemu-devel@nongnu.org, den@openvz.org, rkagan@virtuozzo.com,
	dplotnikov@virtuozzo.com, berrange@redhat.com,
	stefanha@gmail.com
Subject: [Qemu-devel] [PATCH v2] qemu-nbd: Implement socket activation.
Date: Thu,  2 Feb 2017 17:16:24 +0000	[thread overview]
Message-ID: <20170202171625.28502-1-rjones@redhat.com> (raw)

v2:

 - A few small fixed identified by Dan Berrange.

The original cover letter is below.

Rich.


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 patch partially implements socket activation.

The limitation of this implementation is that qemu-nbd can only listen
on a single file descriptor, and so if LISTEN_FDS > 1 (eg. for
listening on multiple interfaces or ports) socket activation will
fail.  However for the simple case of listening on a single port, and
either all interfaces with IPv4+IPv6, or just a loopback interface,
the current implementation works fine.  Fixing this properly would
require considerable changes throughout qemu, since qemu's currently
handling of getaddrinfo is plainly wrong.

To use qemu-nbd from systemd, you create
/etc/systemd/system/nbd.socket:

  [Unit]
  Description=QEMU Network Block Device server
  [Socket]
  ListenStream=10809
  [Install]
  WantedBy=sockets.target

and /etc/systemd/system/nbd.service:

  [Service]
  ExecStart=/usr/sbin/qemu-nbd -v -t /path/to/file

and enable the socket service (only):

  systemctl enable nbd.socket
  systemctl start nbd.socket

and then connecting to port 10809 will start qemu-nbd and service the
file, with systemd opening the listening socket.

In the ExecStart line, the qemu-nbd -v option is only needed if you
want enhanced debugging.  The -t option is required unless you want to
fiddle with systemd settings for rate-limiting.

If you try to use the -p and similar options with socket activation
then qemu-nbd will give an error.

(I wasn't sure where to document this -- there is no obvious
documentation for qemu-nbd beyond the simple list of command line
arguments)

This is based on the implementations in
libvirt (src/util/virutil.c:virGetListenFDs) and
nbdkit (src/main.c:get_socket_activation), and also on Denis Plotnikov's
implementation of --server-sock-fd
(https://lists.gnu.org/archive/html/qemu-devel/2016-09/msg07781.html).

             reply	other threads:[~2017-02-02 17:16 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-02 17:16 Richard W.M. Jones [this message]
2017-02-02 17:16 ` [Qemu-devel] [PATCH v2] qemu-nbd: Implement socket activation Richard W.M. Jones
2017-02-02 17:30   ` Daniel P. Berrange
2017-02-03 15:16   ` Stefan Hajnoczi
2017-02-03 16:52     ` Richard W.M. Jones
2017-02-04  9:58       ` Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170202171625.28502-1-rjones@redhat.com \
    --to=rjones@redhat.com \
    --cc=berrange@redhat.com \
    --cc=den@openvz.org \
    --cc=dplotnikov@virtuozzo.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rkagan@virtuozzo.com \
    --cc=stefanha@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).