Skip to content
Snippets Groups Projects
  1. Sep 08, 2023
  2. Jul 27, 2023
    • Denis V. Lunev's avatar
      qemu-nbd: regression with arguments passing into nbd_client_thread() · e5b815b0
      Denis V. Lunev authored
      
      Unfortunately
          commit 03b67621
          Author: Denis V. Lunev <den@openvz.org>
          Date:   Mon Jul 17 16:55:40 2023 +0200
          qemu-nbd: pass structure into nbd_client_thread instead of plain char*
      has introduced a regression. struct NbdClientOpts resides on stack inside
      'if' block. This specifically means that this stack space could be reused
      once the execution will leave that block of the code.
      
      This means that parameters passed into nbd_client_thread could be
      overwritten at any moment.
      
      The patch moves the data to the namespace of main() function effectively
      preserving it for the whole process lifetime.
      
      Signed-off-by: default avatarDenis V. Lunev <den@openvz.org>
      CC: Eric Blake <eblake@redhat.com>
      CC: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
      CC: <qemu-stable@nongnu.org>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Message-ID: <20230727105828.324314-1-den@openvz.org>
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      e5b815b0
  3. Jul 19, 2023
  4. May 30, 2023
  5. Dec 14, 2022
    • Markus Armbruster's avatar
      qapi block: Elide redundant has_FOO in generated C · 54fde4ff
      Markus Armbruster authored
      
      The has_FOO for pointer-valued FOO are redundant, except for arrays.
      They are also a nuisance to work with.  Recent commit "qapi: Start to
      elide redundant has_FOO in generated C" provided the means to elide
      them step by step.  This is the step for qapi/block*.json.
      
      Said commit explains the transformation in more detail.
      
      There is one instance of the invariant violation mentioned there:
      qcow2_signal_corruption() passes false, "" when node_name is an empty
      string.  Take care to pass NULL then.
      
      The previous two commits cleaned up two more.
      
      Additionally, helper bdrv_latency_histogram_stats() loses its output
      parameters and returns a value instead.
      
      Cc: Kevin Wolf <kwolf@redhat.com>
      Cc: Hanna Reitz <hreitz@redhat.com>
      Cc: qemu-block@nongnu.org
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20221104160712.3005652-11-armbru@redhat.com>
      [Fixes for #ifndef LIBRBD_SUPPORTS_ENCRYPTION and MacOS squashed in]
      54fde4ff
  6. 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
  7. May 03, 2022
  8. 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
  9. Apr 21, 2022
  10. Apr 20, 2022
  11. Mar 07, 2022
  12. 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
  13. 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
  14. Aug 26, 2021
  15. Jun 29, 2021
  16. Mar 19, 2021
  17. 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
  18. Feb 02, 2021
  19. Jan 20, 2021
  20. Nov 11, 2020
  21. 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
  22. 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
  23. Oct 09, 2020
  24. Oct 02, 2020
Loading