Skip to content
Snippets Groups Projects
  1. 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
  2. May 12, 2022
    • Eric Blake's avatar
      nbd/server: Allow MULTI_CONN for shared writable exports · 58a6fdcc
      Eric Blake authored
      
      According to the NBD spec, a server that advertises
      NBD_FLAG_CAN_MULTI_CONN promises that multiple client connections will
      not see any cache inconsistencies: when properly separated by a single
      flush, actions performed by one client will be visible to another
      client, regardless of which client did the flush.
      
      We always satisfy these conditions in qemu - even when we support
      multiple clients, ALL clients go through a single point of reference
      into the block layer, with no local caching.  The effect of one client
      is instantly visible to the next client.  Even if our backend were a
      network device, we argue that any multi-path caching effects that
      would cause inconsistencies in back-to-back actions not seeing the
      effect of previous actions would be a bug in that backend, and not the
      fault of caching in qemu.  As such, it is safe to unconditionally
      advertise CAN_MULTI_CONN for any qemu NBD server situation that
      supports parallel clients.
      
      Note, however, that we don't want to advertise CAN_MULTI_CONN when we
      know that a second client cannot connect (for historical reasons,
      qemu-nbd defaults to a single connection while nbd-server-add and QMP
      commands default to unlimited connections; but we already have
      existing means to let either style of NBD server creation alter those
      defaults).  This is visible by no longer advertising MULTI_CONN for
      'qemu-nbd -r' without -e, as in the iotest nbd-qemu-allocation.
      
      The harder part of this patch is setting up an iotest to demonstrate
      behavior of multiple NBD clients to a single server.  It might be
      possible with parallel qemu-io processes, but I found it easier to do
      in python with the help of libnbd, and help from Nir and Vladimir in
      writing the test.
      
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Suggested-by: default avatarNir Soffer <nsoffer@redhat.com>
      Suggested-by: default avatarVladimir Sementsov-Ogievskiy <v.sementsov-og@mail.ru>
      Message-Id: <20220512004924.417153-3-eblake@redhat.com>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      58a6fdcc
    • 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
  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. Mar 07, 2022
    • Daniel P. Berrangé's avatar
      block/nbd: don't restrict TLS usage to IP sockets · e8ae8b1a
      Daniel P. Berrangé authored
      
      The TLS usage for NBD was restricted to IP sockets because validating
      x509 certificates requires knowledge of the hostname that the client
      is connecting to.
      
      TLS does not have to use x509 certificates though, as PSK (pre-shared
      keys) provide an alternative credential option. These have no
      requirement for a hostname and can thus be trivially used for UNIX
      sockets.
      
      Furthermore, with the ability to overide the default hostname for
      TLS validation in the previous patch, it is now also valid to want
      to use x509 certificates with FD passing and UNIX sockets.
      
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Signed-off-by: default avatarDaniel P. Berrangé <berrange@redhat.com>
      Message-Id: <20220304193610.3293146-6-berrange@redhat.com>
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      e8ae8b1a
  5. Jun 29, 2021
  6. Feb 12, 2021
    • 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
  7. Oct 30, 2020
    • 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
    • Eric Blake's avatar
      nbd: Utilize QAPI_CLONE for type conversion · 8675cbd6
      Eric Blake authored
      
      Rather than open-coding the translation from the deprecated
      NbdServerAddOptions type to the preferred BlockExportOptionsNbd, it's
      better to utilize QAPI_CLONE_MEMBERS.  This solves a couple of issues:
      first, if we do any more refactoring of the base type (which an
      upcoming patch plans to do), we don't have to revisit the open-coding.
      Second, our assignment to arg->name is fishy: the generated QAPI code
      for qapi_free_NbdServerAddOptions does not visit arg->name if
      arg->has_name is false, but if it DID visit it, we would have
      introduced a double-free situation when arg is finally freed.
      
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Reviewed-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20201027050556.269064-4-eblake@redhat.com>
      8675cbd6
  8. Oct 02, 2020
  9. Mar 06, 2020
  10. Feb 05, 2020
  11. 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
  12. Sep 24, 2019
    • Eric Blake's avatar
      nbd: Grab aio context lock in more places · 61bc846d
      Eric Blake authored
      
      When iothreads are in use, the failure to grab the aio context results
      in an assertion failure when trying to unlock things during blk_unref,
      when trying to unlock a mutex that was not locked.  In short, all
      calls to nbd_export_put need to done while within the correct aio
      context.  But since nbd_export_put can recursively reach itself via
      nbd_export_close, and recursively grabbing the context would deadlock,
      we can't do the context grab directly in those functions, but must do
      so in their callers.
      
      Hoist the use of the correct aio_context from nbd_export_new() to its
      caller qmp_nbd_server_add().  Then tweak qmp_nbd_server_remove(),
      nbd_eject_notifier(), and nbd_esport_close_all() to grab the right
      context, so that all callers during qemu now own the context before
      nbd_export_put() can call blk_unref().
      
      Remaining uses in qemu-nbd don't matter (since that use case does not
      support iothreads).
      
      Suggested-by: default avatarKevin Wolf <kwolf@redhat.com>
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <20190917023917.32226-1-eblake@redhat.com>
      Reviewed-by: default avatarSergio Lopez <slp@redhat.com>
      61bc846d
  13. Sep 05, 2019
    • Eric Blake's avatar
      nbd: Improve per-export flag handling in server · dbb38caa
      Eric Blake authored
      
      When creating a read-only image, we are still advertising support for
      TRIM and WRITE_ZEROES to the client, even though the client should not
      be issuing those commands.  But seeing this requires looking across
      multiple functions:
      
      All callers to nbd_export_new() passed a single flag based solely on
      whether the export allows writes.  Later, we then pass a constant set
      of flags to nbd_negotiate_options() (namely, the set of flags which we
      always support, at least for writable images), which is then further
      dynamically modified with NBD_FLAG_SEND_DF based on client requests
      for structured options.  Finally, when processing NBD_OPT_EXPORT_NAME
      or NBD_OPT_EXPORT_GO we bitwise-or the original caller's flag with the
      runtime set of flags we've built up over several functions.
      
      Let's refactor things to instead compute a baseline of flags as soon
      as possible which gets shared between multiple clients, in
      nbd_export_new(), and changing the signature for the callers to pass
      in a simpler bool rather than having to figure out flags.  We can then
      get rid of the 'myflags' parameter to various functions, and instead
      refer to client for everything we need (we still have to perform a
      bitwise-OR for NBD_FLAG_SEND_DF during NBD_OPT_EXPORT_NAME and
      NBD_OPT_EXPORT_GO, but it's easier to see what is being computed).
      This lets us quit advertising senseless flags for read-only images, as
      well as making the next patch for exposing FAST_ZERO support easier to
      write.
      
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <20190823143726.27062-2-eblake@redhat.com>
      Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      [eblake: improve commit message, update iotest 223]
      dbb38caa
    • Eric Blake's avatar
      nbd: Advertise multi-conn for shared read-only connections · 61cc8724
      Eric Blake authored
      The NBD specification defines NBD_FLAG_CAN_MULTI_CONN, which can be
      advertised when the server promises cache consistency between
      simultaneous clients (basically, rules that determine what FUA and
      flush from one client are able to guarantee for reads from another
      client).  When we don't permit simultaneous clients (such as qemu-nbd
      without -e), the bit makes no sense; and for writable images, we
      probably have a lot more work before we can declare that actions from
      one client are cache-consistent with actions from another.  But for
      read-only images, where flush isn't changing any data, we might as
      well advertise multi-conn support.  What's more, advertisement of the
      bit makes it easier for clients to determine if 'qemu-nbd -e' was in
      use, where a second connection will succeed rather than hang until the
      first client goes away.
      
      This patch affects qemu as server in advertising the bit.  We may want
      to consider patches to qemu as client to attempt parallel connections
      for higher throughput by spreading the load over those connections
      when a server advertises multi-conn, but for now sticking to one
      connection per nbd:// BDS is okay.
      
      See also: https://bugzilla.redhat.com/1708300
      
      
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <20190815185024.7010-1-eblake@redhat.com>
      [eblake: tweak blockdev-nbd.c to not request shared when writable,
      fix iotest 233]
      Reviewed-by: default avatarJohn Snow <jsnow@redhat.com>
      61cc8724
  14. Sep 03, 2019
  15. Aug 16, 2019
    • Markus Armbruster's avatar
      Clean up inclusion of sysemu/sysemu.h · d5938f29
      Markus Armbruster authored
      
      In my "build everything" tree, changing sysemu/sysemu.h triggers a
      recompile of some 5400 out of 6600 objects (not counting tests and
      objects that don't depend on qemu/osdep.h).
      
      Almost a third of its inclusions are actually superfluous.  Delete
      them.  Downgrade two more to qapi/qapi-types-run-state.h, and move one
      from char/serial.h to char/serial.c.
      
      hw/semihosting/config.c, monitor/monitor.c, qdev-monitor.c, and
      stubs/semihost.c define variables declared in sysemu/sysemu.h without
      including it.  The compiler is cool with that, but include it anyway.
      
      This doesn't reduce actual use much, as it's still included into
      widely included headers.  The next commit will tackle that.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarAlistair Francis <alistair.francis@wdc.com>
      Message-Id: <20190812052359.30071-27-armbru@redhat.com>
      Reviewed-by: default avatarAlex Bennée <alex.bennee@linaro.org>
      d5938f29
  16. Mar 06, 2019
    • Daniel P. Berrangé's avatar
      nbd: allow authorization with nbd-server-start QMP command · 00019455
      Daniel P. Berrangé authored
      
      As with the previous patch to qemu-nbd, the nbd-server-start QMP command
      also needs to be able to specify authorization when enabling TLS encryption.
      
      First the client must create a QAuthZ object instance using the
      'object-add' command:
      
         {
           'execute': 'object-add',
           'arguments': {
             'qom-type': 'authz-list',
             'id': 'authz0',
             'parameters': {
               'policy': 'deny',
               'rules': [
                 {
                   'match': '*CN=fred',
                   'policy': 'allow'
                 }
               ]
             }
           }
         }
      
      They can then reference this in the new 'tls-authz' parameter when
      executing the 'nbd-server-start' command:
      
         {
           'execute': 'nbd-server-start',
           'arguments': {
             'addr': {
                 'type': 'inet',
                 'host': '127.0.0.1',
                 'port': '9000'
             },
             'tls-creds': 'tls0',
             'tls-authz': 'authz0'
           }
         }
      
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarJuan Quintela <quintela@redhat.com>
      Signed-off-by: default avatarDaniel P. Berrange <berrange@redhat.com>
      Message-Id: <20190227162035.18543-3-berrange@redhat.com>
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      00019455
  17. Jan 21, 2019
    • Eric Blake's avatar
      nbd/server: Hoist length check to qmp_nbd_server_add · 7596bbb3
      Eric Blake authored
      
      We only had two callers to nbd_export_new; qemu-nbd.c always
      passed a valid offset/length pair (because it already checked
      the file length, to ensure that offset was in bounds), while
      blockdev-nbd.c always passed 0/-1.  Then nbd_export_new reduces
      the size to a multiple of BDRV_SECTOR_SIZE (can only happen
      when offset is not sector-aligned, since bdrv_getlength()
      currently rounds up) (someday, it would be nice to have
      byte-accurate lengths - but not today).
      
      However, I'm finding it easier to work with the code if we are
      consistent on having both callers pass in a valid length, and
      just assert that things are sane in nbd_export_new, meaning
      that no negative values were passed, and that offset+size does
      not exceed 63 bits (as that really is a fundamental limit to
      later operations, whether we use off_t or uint64_t).
      
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <20190117193658.16413-6-eblake@redhat.com>
      Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      7596bbb3
  18. Jan 14, 2019
    • Eric Blake's avatar
      nbd: Merge nbd_export_bitmap into nbd_export_new · 678ba275
      Eric Blake authored
      
      We only have one caller that wants to export a bitmap name,
      which it does right after creation of the export. But there is
      still a brief window of time where an NBD client could see the
      export but not the dirty bitmap, which a robust client would
      have to interpret as meaning the entire image should be treated
      as dirty.  Better is to eliminate the window entirely, by
      inlining nbd_export_bitmap() into nbd_export_new(), and refusing
      to create the bitmap in the first place if the requested bitmap
      can't be located.
      
      We also no longer need logic for setting a different bitmap
      name compared to the bitmap being exported.
      
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Message-Id: <20190111194720.15671-8-eblake@redhat.com>
      678ba275
Loading