Skip to content
Snippets Groups Projects
  1. 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
  2. Oct 02, 2020
  3. Mar 06, 2020
  4. Feb 05, 2020
  5. 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
  6. 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
  7. 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
  8. Sep 03, 2019
  9. 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
  10. 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
  11. 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
  12. 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
    • Eric Blake's avatar
      nbd: Remove x-nbd-server-add-bitmap · 7dc570b3
      Eric Blake authored
      
      Now that nbd-server-add can do the same functionality (well, other
      than making the exported bitmap name different than the underlying
      bitamp - but we argued that was not essential, since it is just as
      easy to create a new non-persistent bitmap with the desired name),
      we no longer need the experimental separate command.
      
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Message-Id: <20190111194720.15671-7-eblake@redhat.com>
      7dc570b3
    • Eric Blake's avatar
      nbd: Allow bitmap export during QMP nbd-server-add · 5fcbeb06
      Eric Blake authored
      With the experimental x-nbd-server-add-bitmap command, there was
      a window of time where an NBD client could see the export but not
      the associated dirty bitmap, which can cause a client that planned
      on using the dirty bitmap to be forced to treat the entire image
      as dirty as a safety fallback.  Furthermore, if the QMP client
      successfully exports a disk but then fails to add the bitmap, it
      has to take on the burden of removing the export.  Since we don't
      allow changing the exposed dirty bitmap (whether to a different
      bitmap, or removing advertisement of the bitmap), it is nicer to
      make the bitmap tied to the export at the time the export is
      created, with automatic failure to export if the bitmap is not
      available.
      
      The experimental command included an optional 'bitmap-export-name'
      field for remapping the name exposed over NBD to be different from
      the bitmap name stored on disk.  However, my libvirt demo code
      for implementing differential backups on top of persistent bitmaps
      did not need to take advantage of that feature (it is instead
      possible to create a new temporary bitmap with the desired name,
      use block-dirty-bitmap-merge to merge one or more persistent
      bitmaps into the temporary, then associate the temporary with the
      NBD export, if control is needed over the exported bitmap name).
      Hence, I'm not copying that part of the experiment over to the
      stable addition. For more details on the libvirt demo, see
      https://www.redhat.com/archives/libvir-list/2018-October/msg01254.html,
      https://kvmforum2018.sched.com/event/FzuB/facilitating-incremental-backup-eric-blake-red-hat
      
      
      
      This patch focuses on the user interface, and reduces (but does
      not completely eliminate) the window where an NBD client can see
      the export but not the dirty bitmap, with less work to clean up
      after errors.  Later patches will add further cleanups now that
      this interface is declared stable via a single QMP command,
      including removing the race window.
      
      Update test 223 to use the new interface.
      
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Message-Id: <20190111194720.15671-6-eblake@redhat.com>
      5fcbeb06
    • Eric Blake's avatar
      nbd: Merge nbd_export_set_name into nbd_export_new · 3fa4c765
      Eric Blake authored
      
      The existing NBD code had a weird split where nbd_export_new()
      created an export but did not add it to the list of exported
      names until a later nbd_export_set_name() came along and grabbed
      a second reference on the object; later, the first call to
      nbd_export_close() drops the second reference while removing
      the export from the list.  This is in part because the QAPI
      NbdServerRemoveNode enum documents the possibility of adding a
      mode where we could do a soft disconnect: preventing new clients,
      but waiting for existing clients to gracefully quit, based on
      the mode used when calling nbd_export_close().
      
      But in spite of all that, note that we never change the name of
      an NBD export while it is exposed, which means it is easier to
      just inline the process of setting the name as part of creating
      the export.
      
      Inline the contents of nbd_export_set_name() and
      nbd_export_set_description() into the two points in an export
      lifecycle where they matter, then adjust both callers to pass
      the name up front.  Note that for creation, all callers pass a
      non-NULL name, (passing NULL at creation was for old style
      servers, but we removed support for that in commit 7f7dfe2a),
      so we can add an assert and do things unconditionally; but for
      cleanup, because of the dual nature of nbd_export_close(), we
      still have to be careful to avoid use-after-free.  Along the
      way, add a comment reminding ourselves of the potential of
      adding a middle mode disconnect.
      
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Message-Id: <20190111194720.15671-5-eblake@redhat.com>
      3fa4c765
    • Eric Blake's avatar
      nbd: Forbid nbd-server-stop when server is not running · 7801c3a7
      Eric Blake authored
      
      Since we already forbid other nbd-server commands when not
      in the right state, it is unlikely that any caller was relying
      on a second stop to behave as a silent no-op.  Update iotest
      223 to show the improved behavior.
      
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <20190111194720.15671-3-eblake@redhat.com>
      Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      7801c3a7
  13. Oct 03, 2018
  14. Jun 21, 2018
  15. Mar 02, 2018
Loading