Skip to content
Snippets Groups Projects
  1. May 12, 2022
    • Eric Blake's avatar
      qemu-nbd: Pass max connections to blockdev layer · a5fced40
      Eric Blake authored
      
      The next patch wants to adjust whether the NBD server code advertises
      MULTI_CONN based on whether it is known if the server limits to
      exactly one client.  For a server started by QMP, this information is
      obtained through nbd_server_start (which can support more than one
      export); but for qemu-nbd (which supports exactly one export), it is
      controlled only by the command-line option -e/--shared.  Since we
      already have a hook function used by qemu-nbd, it's easiest to just
      alter its signature to fit our needs.
      
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <20220512004924.417153-2-eblake@redhat.com>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      a5fced40
  2. May 03, 2022
  3. Apr 26, 2022
    • Vladimir Sementsov-Ogievskiy's avatar
      qapi: nbd-export: allow select bitmaps by node/name pair · e5fb29d5
      Vladimir Sementsov-Ogievskiy authored
      
      Hi all! Current logic of relying on search through backing chain is not
      safe neither convenient.
      
      Sometimes it leads to necessity of extra bitmap copying. Also, we are
      going to add "snapshot-access" driver, to access some snapshot state
      through NBD. And this driver is not formally a filter, and of course
      it's not a COW format driver. So, searching through backing chain will
      not work. Instead of widening the workaround of bitmap searching, let's
      extend the interface so that user can select bitmap precisely.
      
      Note, that checking for bitmap active status is not copied to the new
      API, I don't see a reason for it, user should understand the risks. And
      anyway, bitmap from other node is unrelated to this export being
      read-only or read-write.
      
      Signed-off-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@openvz.org>
      Message-Id: <20220314213226.362217-3-v.sementsov-og@mail.ru>
      [eblake: Adjust S-o-b to Vladimir's new email, with permission]
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      e5fb29d5
  4. Apr 21, 2022
  5. Apr 20, 2022
  6. Mar 07, 2022
  7. Nov 16, 2021
    • Richard W.M. Jones's avatar
      nbd/server: Add --selinux-label option · 3d212b41
      Richard W.M. Jones authored
      Under SELinux, Unix domain sockets have two labels.  One is on the
      disk and can be set with commands such as chcon(1).  There is a
      different label stored in memory (called the process label).  This can
      only be set by the process creating the socket.  When using SELinux +
      SVirt and wanting qemu to be able to connect to a qemu-nbd instance,
      you must set both labels correctly first.
      
      For qemu-nbd the options to set the second label are awkward.  You can
      create the socket in a wrapper program and then exec into qemu-nbd.
      Or you could try something with LD_PRELOAD.
      
      This commit adds the ability to set the label straightforwardly on the
      command line, via the new --selinux-label flag.  (The name of the flag
      is the same as the equivalent nbdkit option.)
      
      A worked example showing how to use the new option can be found in
      this bug: https://bugzilla.redhat.com/show_bug.cgi?id=1984938
      
      Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1984938
      
      
      Signed-off-by: default avatarRichard W.M. Jones <rjones@redhat.com>
      Reviewed-by: default avatarDaniel P. Berrangé <berrange@redhat.com>
      
      [eblake: rebase to configure changes, reject --selinux-label if it is
      not compiled in or not used on a Unix socket]
      Note that we may relax some of these restrictions at a later date,
      such as making it possible to label a TCP socket, although it may be
      smarter to do so as a generic QMP action rather than more one-off
      command lines in qemu-nbd.
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <20211115202944.615966-1-eblake@redhat.com>
      Reviewed-by: default avatarThomas Huth <thuth@redhat.com>
      [eblake: adjust meson output as suggested by thuth]
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      3d212b41
  8. Sep 29, 2021
    • Nir Soffer's avatar
      qemu-nbd: Change default cache mode to writeback · 09615257
      Nir Soffer authored
      Both qemu and qemu-img use writeback cache mode by default, which is
      already documented in qemu(1). qemu-nbd uses writethrough cache mode by
      default, and the default cache mode is not documented.
      
      According to the qemu-nbd(8):
      
         --cache=CACHE
                The  cache  mode  to be used with the file.  See the
                documentation of the emulator's -drive cache=... option for
                allowed values.
      
      qemu(1) says:
      
          The default mode is cache=writeback.
      
      So users have no reason to assume that qemu-nbd is using writethough
      cache mode. The only hint is the painfully slow writing when using the
      defaults.
      
      Looking in git history, it seems that qemu used writethrough in the past
      to support broken guests that did not flush data properly, or could not
      flush due to limitations in qemu. But qemu-nbd clients can use
      NBD_CMD_FLUSH to flush data, so using writethrough does not help anyone.
      
      Change the default cache mode to writback, and document the default and
      available values properly in the online help and manual.
      
      With this change converting image via qemu-nbd is 3.5 times faster.
      
          $ qemu-img create dst.img 50g
          $ qemu-nbd -t -f raw -k /tmp/nbd.sock dst.img
      
      Before this change:
      
          $ hyperfine -r3 "./qemu-img convert -p -f raw -O raw -T none -W fedora34.img nbd+unix:///?socket=/tmp/nbd.sock"
          Benchmark #1: ./qemu-img convert -p -f raw -O raw -T none -W fedora34.img nbd+unix:///?socket=/tmp/nbd.sock
            Time (mean ± σ):     83.639 s ±  5.970 s    [User: 2.733 s, System: 6.112 s]
            Range (min … max):   76.749 s … 87.245 s    3 runs
      
      After this change:
      
          $ hyperfine -r3 "./qemu-img convert -p -f raw -O raw -T none -W fedora34.img nbd+unix:///?socket=/tmp/nbd.sock"
          Benchmark #1: ./qemu-img convert -p -f raw -O raw -T none -W fedora34.img nbd+unix:///?socket=/tmp/nbd.sock
            Time (mean ± σ):     23.522 s ±  0.433 s    [User: 2.083 s, System: 5.475 s]
            Range (min … max):   23.234 s … 24.019 s    3 runs
      
      Users can avoid the issue by using --cache=writeback[1] but the defaults
      should give good performance for the common use case.
      
      [1] https://bugzilla.redhat.com/1990656
      
      
      
      Signed-off-by: default avatarNir Soffer <nsoffer@redhat.com>
      Message-Id: <20210813205519.50518-1-nsoffer@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      CC: qemu-stable@nongnu.org
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      09615257
  9. Aug 26, 2021
  10. Jun 29, 2021
  11. Mar 19, 2021
  12. Feb 12, 2021
    • Eric Blake's avatar
      qemu-nbd: Permit --shared=0 for unlimited clients · 3dcf56e6
      Eric Blake authored
      
      This gives us better feature parity with QMP nbd-server-start, where
      max-connections defaults to 0 for unlimited.
      
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <20210209152759.209074-3-eblake@redhat.com>
      Reviewed-by: default avatarDaniel P. Berrangé <berrange@redhat.com>
      3dcf56e6
    • Eric Blake's avatar
      qemu-nbd: Use SOMAXCONN for socket listen() backlog · 582d4210
      Eric Blake authored
      Our default of a backlog of 1 connection is rather puny; it gets in
      the way when we are explicitly allowing multiple clients (such as
      qemu-nbd -e N [--shared], or nbd-server-start with its default
      "max-connections":0 for unlimited), but is even a problem when we
      stick to qemu-nbd's default of only 1 active client but use -t
      [--persistent] where a second client can start using the server once
      the first finishes.  While the effects are less noticeable on TCP
      sockets (since the client can poll() to learn when the server is ready
      again), it is definitely observable on Unix sockets, where on Linux, a
      client will fail with EAGAIN and no recourse but to sleep an arbitrary
      amount of time before retrying if the server backlog is already full.
      
      Since QMP nbd-server-start is always persistent, it now always
      requests a backlog of SOMAXCONN; meanwhile, qemu-nbd will request
      SOMAXCONN if persistent, otherwise its backlog should be based on the
      expected number of clients.
      
      See https://bugzilla.redhat.com/1925045
      
       for a demonstration of where
      our low backlog prevents libnbd from connecting as many parallel
      clients as it wants.
      
      Reported-by: default avatarRichard W.M. Jones <rjones@redhat.com>
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      CC: qemu-stable@nongnu.org
      Message-Id: <20210209152759.209074-2-eblake@redhat.com>
      Tested-by: default avatarRichard W.M. Jones <rjones@redhat.com>
      Reviewed-by: default avatarDaniel P. Berrangé <berrange@redhat.com>
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      582d4210
  13. Feb 02, 2021
  14. Jan 20, 2021
  15. Nov 11, 2020
  16. Oct 30, 2020
    • Eric Blake's avatar
      nbd: Add 'qemu-nbd -A' to expose allocation depth · dbc7b014
      Eric Blake authored
      
      Allow the server to expose an additional metacontext to be requested
      by savvy clients.  qemu-nbd adds a new option -A to expose the
      qemu:allocation-depth metacontext through NBD_CMD_BLOCK_STATUS; this
      can also be set via QMP when using block-export-add.
      
      qemu as client is hacked into viewing the key aspects of this new
      context by abusing the already-experimental x-dirty-bitmap option to
      collapse all depths greater than 2, which results in a tri-state value
      visible in the output of 'qemu-img map --output=json' (yes, that means
      x-dirty-bitmap is now a bit of a misnomer, but I didn't feel like
      renaming it as it would introduce a needless break of back-compat,
      even though we make no compat guarantees with x- members):
      
      unallocated (depth 0) => "zero":false, "data":true
      local (depth 1)       => "zero":false, "data":false
      backing (depth 2+)    => "zero":true,  "data":true
      
      libnbd as client is probably a nicer way to get at the information
      without having to decipher such hacks in qemu as client. ;)
      
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <20201027050556.269064-11-eblake@redhat.com>
      Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      dbc7b014
    • Eric Blake's avatar
      nbd: Update qapi to support exporting multiple bitmaps · cbad81ce
      Eric Blake authored
      
      Since 'block-export-add' is new to 5.2, we can still tweak the
      interface; there, allowing 'bitmaps':['str'] is nicer than
      'bitmap':'str'.  This wires up the qapi and qemu-nbd changes to permit
      passing multiple bitmaps as distinct metadata contexts that the NBD
      client may request, but the actual support for more than one will
      require a further patch to the server.
      
      Note that there are no changes made to the existing deprecated
      'nbd-server-add' command; this required splitting the QAPI type
      BlockExportOptionsNbd, which fortunately does not affect QMP
      introspection.
      
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <20201027050556.269064-5-eblake@redhat.com>
      Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Reviewed-by: default avatarPeter Krempa <pkrempa@redhat.com>
      cbad81ce
  17. Oct 23, 2020
    • Stefan Hajnoczi's avatar
      block: move block exports to libblockdev · cbc20bfb
      Stefan Hajnoczi authored
      
      Block exports are used by softmmu, qemu-storage-daemon, and qemu-nbd.
      They are not used by other programs and are not otherwise needed in
      libblock.
      
      Undo the recent move of blockdev-nbd.c from blockdev_ss into block_ss.
      Since bdrv_close_all() (libblock) calls blk_exp_close_all()
      (libblockdev) a stub function is required..
      
      Make qemu-nbd.c use signal handling utility functions instead of
      duplicating the code. This helps because os-posix.c is in libblockdev
      and it depends on a qemu_system_killed() symbol that qemu-nbd.c lacks.
      Once we use the signal handling utility functions we also end up
      providing the necessary symbol.
      
      Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      Reviewed-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Message-id: 20200929125516.186715-4-stefanha@redhat.com
      [Fixed s/ndb/nbd/ typo in commit description as suggested by Eric Blake
      --Stefan]
      Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      cbc20bfb
  18. Oct 09, 2020
  19. Oct 02, 2020
  20. Sep 23, 2020
    • Stefan Hajnoczi's avatar
      qemu/atomic.h: rename atomic_ to qatomic_ · d73415a3
      Stefan Hajnoczi authored
      
      clang's C11 atomic_fetch_*() functions only take a C11 atomic type
      pointer argument. QEMU uses direct types (int, etc) and this causes a
      compiler error when a QEMU code calls these functions in a source file
      that also included <stdatomic.h> via a system header file:
      
        $ CC=clang CXX=clang++ ./configure ... && make
        ../util/async.c:79:17: error: address argument to atomic operation must be a pointer to _Atomic type ('unsigned int *' invalid)
      
      Avoid using atomic_*() names in QEMU's atomic.h since that namespace is
      used by <stdatomic.h>. Prefix QEMU's APIs with 'q' so that atomic.h
      and <stdatomic.h> can co-exist. I checked /usr/include on my machine and
      searched GitHub for existing "qatomic_" users but there seem to be none.
      
      This patch was generated using:
      
        $ git grep -h -o '\<atomic\(64\)\?_[a-z0-9_]\+' include/qemu/atomic.h | \
          sort -u >/tmp/changed_identifiers
        $ for identifier in $(</tmp/changed_identifiers); do
              sed -i "s%\<$identifier\>%q$identifier%g" \
                  $(git grep -I -l "\<$identifier\>")
          done
      
      I manually fixed line-wrap issues and misaligned rST tables.
      
      Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      Reviewed-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      Acked-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Message-Id: <20200923105646.47864-1-stefanha@redhat.com>
      d73415a3
  21. Sep 02, 2020
  22. May 27, 2020
  23. May 18, 2020
  24. Feb 05, 2020
  25. Jan 30, 2020
  26. Nov 18, 2019
    • Eric Blake's avatar
      nbd: Don't send oversize strings · 93676c88
      Eric Blake authored
      
      Qemu as server currently won't accept export names larger than 256
      bytes, nor create dirty bitmap names longer than 1023 bytes, so most
      uses of qemu as client or server have no reason to get anywhere near
      the NBD spec maximum of a 4k limit per string.
      
      However, we weren't actually enforcing things, ignoring when the
      remote side violates the protocol on input, and also having several
      code paths where we send oversize strings on output (for example,
      qemu-nbd --description could easily send more than 4k).  Tighten
      things up as follows:
      
      client:
      - Perform bounds check on export name and dirty bitmap request prior
        to handing it to server
      - Validate that copied server replies are not too long (ignoring
        NBD_INFO_* replies that are not copied is not too bad)
      server:
      - Perform bounds check on export name and description prior to
        advertising it to client
      - Reject client name or metadata query that is too long
      - Adjust things to allow full 4k name limit rather than previous
        256 byte limit
      
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <20191114024635.11363-4-eblake@redhat.com>
      Reviewed-by: default avatarMaxim Levitsky <mlevitsk@redhat.com>
      Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      93676c88
  27. Oct 14, 2019
Loading