Uploaded image for project: 'RHEL'
  1. RHEL
  2. RHEL-7347

[qemu-kvm] Support systemd socket activation in qemu-storage-daemon

    • rhel-sst-virtualization-storage
    • ssg_virtualization
    • None
    • False
    • Hide

      None

      Show
      None
    • None
    • None
    • None
    • None
    • If docs needed, set a value
    • None

      Description of problem:

      If I understand correctly new qemu-storage-daemon replace qemu-nbd. New features
      added to qemu-storage-daemon may not be available in qemu-nbd. Project using
      qemu-nbd (e.g. oVirt, virt-v2v, libnbd) should move to use qemu-storage-daemon.

      A very useful feature of qemu-nbd is systemd socket activation is missing in
      qemu-storage-daemon. We would like to have it.

      Using systemd socket activation eliminate the need to wait until the NBD server
      is ready. This can be done today with waiting for the pid file, but it requires
      polling when starting the server, and removing the pid file after the server
      is terminate. This has to be implemented in all clients using the server.

      Supporting systemd socket activation on the server side is relatively simple.

      However it seems that qemu-storage-daemon has a better solution - passing listen
      socket to the daemon:

      Launch the daemon with QMP monitor socket qmp.sock so clients can exe‐
      cute QMP commands:

      $ qemu-storage-daemon \
      --chardev socket,path=qmp.sock,server=on,wait=off,id=char1 \
      --monitor chardev=char1

      Launch the daemon from Python with a QMP monitor socket using file de‐
      scriptor passing so there is no need to busy wait for the QMP monitor
      to become available:

      #!/usr/bin/env python3
      import subprocess
      import socket

      sock_path = '/var/run/qmp.sock'

      with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as listen_sock:
      listen_sock.bind(sock_path)
      listen_sock.listen()

      fd = listen_sock.fileno()

      subprocess.Popen(
      ['qemu-storage-daemon',
      '--chardev', f'socket,fd=

      {fd}

      ,server=on,id=char1',
      '--monitor', 'chardev=char1'],
      pass_fds=[fd],
      )

      1. listen_sock was automatically closed when leaving the 'with' statement
      2. body. If the daemon process terminated early then the following connect()
      3. will fail with "Connection refused" because no process has the listen
      4. socket open anymore. Launch errors can be detected this way.

      qmp_sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
      qmp_sock.connect(sock_path)
      ...QMP interaction...

      The same socket spawning approach also works with the --nbd-server
      addr.type=fd,addr.str=<fd> and --export
      type=vhost-user-blk,addr.type=fd,addr.str=<fd> options.

      So I'm not sure systemd socket activation is really needed. Opening
      this bug for discussion.

              virt-maint virt-maint
              nsoffer@redhat.com Nir Soffer
              Eric Blake Eric Blake
              Tingting Mao Tingting Mao
              Votes:
              0 Vote for this issue
              Watchers:
              16 Start watching this issue

                Created:
                Updated: