1. 19 5月, 2020 2 次提交
  2. 07 5月, 2020 1 次提交
    • M
      block: luks: better error message when creating too large files · 3d1900a4
      Maxim Levitsky 提交于
      Currently if you attampt to create too large file with luks you
      get the following error message:
      
      Formatting 'test.luks', fmt=luks size=17592186044416 key-secret=sec0
      qemu-img: test.luks: Could not resize file: File too large
      
      While for raw format the error message is
      qemu-img: test.img: The image size is too large for file format 'raw'
      
      The reason for this is that qemu-img checks for errono of the failure,
      and presents the later error when it is -EFBIG
      
      However crypto generic code 'swallows' the errno and replaces it
      with -EIO.
      
      As an attempt to make it better, we can make luks driver,
      detect -EFBIG and in this case present a better error message,
      which is what this patch does
      
      The new error message is:
      
      qemu-img: error creating test.luks: The requested file size is too large
      
      Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1534898Signed-off-by: NMaxim Levitsky <mlevitsk@redhat.com>
      Signed-off-by: NDaniel P. Berrangé <berrange@redhat.com>
      3d1900a4
  3. 05 5月, 2020 1 次提交
  4. 30 4月, 2020 3 次提交
  5. 26 3月, 2020 1 次提交
  6. 11 3月, 2020 2 次提交
    • D
      crypto.c: cleanup created file when block_crypto_co_create_opts_luks fails · 1bba30da
      Daniel Henrique Barboza 提交于
      When using a non-UTF8 secret to create a volume using qemu-img, the
      following error happens:
      
      $ qemu-img create -f luks --object secret,id=vol_1_encrypt0,file=vol_resize_pool.vol_1.secret.qzVQrI -o key-secret=vol_1_encrypt0 /var/tmp/pool_target/vol_1 10240K
      
      Formatting '/var/tmp/pool_target/vol_1', fmt=luks size=10485760 key-secret=vol_1_encrypt0
      qemu-img: /var/tmp/pool_target/vol_1: Data from secret vol_1_encrypt0 is not valid UTF-8
      
      However, the created file '/var/tmp/pool_target/vol_1' is left behind in the
      file system after the failure. This behavior can be observed when creating
      the volume using Libvirt, via 'virsh vol-create', and then getting "volume
      target path already exist" errors when trying to re-create the volume.
      
      The volume file is created inside block_crypto_co_create_opts_luks(), in
      block/crypto.c. If the bdrv_create_file() call is successful but any
      succeeding step fails*, the existing 'fail' label does not take into
      account the created file, leaving it behind.
      
      This patch changes block_crypto_co_create_opts_luks() to delete
      'filename' in case of failure. A failure in this point means that
      the volume is now truncated/corrupted, so even if 'filename' was an
      existing volume before calling qemu-img, it is now unusable. Deleting
      the file it is not much worse than leaving it in the filesystem in
      this scenario, and we don't have to deal with checking the file
      pre-existence in the code.
      
      * in our case, block_crypto_co_create_generic calls qcrypto_block_create,
      which calls qcrypto_block_luks_create, and this function fails when
      calling qcrypto_secret_lookup_as_utf8.
      Reported-by: NSrikanth Aithal <bssrikanth@in.ibm.com>
      Suggested-by: NKevin Wolf <kwolf@redhat.com>
      Signed-off-by: NDaniel Henrique Barboza <danielhb413@gmail.com>
      Message-Id: <20200130213907.2830642-4-danielhb413@gmail.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      1bba30da
    • S
      luks: implement .bdrv_measure() · a9da6e49
      Stefan Hajnoczi 提交于
      Add qemu-img measure support in the "luks" block driver.
      Signed-off-by: NStefan Hajnoczi <stefanha@redhat.com>
      Reviewed-by: NMax Reitz <mreitz@redhat.com>
      Message-Id: <20200221112522.1497712-3-stefanha@redhat.com>
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      a9da6e49
  7. 28 10月, 2019 2 次提交
    • M
      block: Let format drivers pass @exact · e61a28a9
      Max Reitz 提交于
      When truncating a format node, the @exact parameter is generally handled
      simply by virtue of the format storing the new size in the image
      metadata.  Such formats do not need to pass on the parameter to their
      file nodes.
      
      There are exceptions, though:
      - raw and crypto cannot store the image size, and thus must pass on
        @exact.
      
      - When using qcow2 with an external data file, it just makes sense to
        keep its size in sync with the qcow2 virtual disk (because the
        external data file is the virtual disk).  Therefore, we should pass
        @exact when truncating it.
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      Message-id: 20190918095144.955-7-mreitz@redhat.com
      Reviewed-by: NMaxim Levitsky <mlevitsk@redhat.com>
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      e61a28a9
    • M
      block: Add @exact parameter to bdrv_co_truncate() · c80d8b06
      Max Reitz 提交于
      We have two drivers (iscsi and file-posix) that (in some cases) return
      success from their .bdrv_co_truncate() implementation if the block
      device is larger than the requested offset, but cannot be shrunk.  Some
      callers do not want that behavior, so this patch adds a new parameter
      that they can use to turn off that behavior.
      
      This patch just adds the parameter and lets the block/io.c and
      block/block-backend.c functions pass it around.  All other callers
      always pass false and none of the implementations evaluate it, so that
      this patch does not change existing behavior.  Future patches take care
      of that.
      Suggested-by: NMaxim Levitsky <mlevitsk@redhat.com>
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      Message-id: 20190918095144.955-5-mreitz@redhat.com
      Reviewed-by: NMaxim Levitsky <mlevitsk@redhat.com>
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      c80d8b06
  8. 19 8月, 2019 1 次提交
  9. 12 6月, 2019 1 次提交
  10. 04 6月, 2019 1 次提交
    • K
      block: Add BlockBackend.ctx · d861ab3a
      Kevin Wolf 提交于
      This adds a new parameter to blk_new() which requires its callers to
      declare from which AioContext this BlockBackend is going to be used (or
      the locks of which AioContext need to be taken anyway).
      
      The given context is only stored and kept up to date when changing
      AioContexts. Actually applying the stored AioContext to the root node
      is saved for another commit.
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      d861ab3a
  11. 19 3月, 2019 1 次提交
  12. 25 2月, 2019 1 次提交
    • M
      block: Add strong_runtime_opts to BlockDriver · 2654267c
      Max Reitz 提交于
      This new field can be set by block drivers to list the runtime options
      they accept that may influence the contents of the respective BDS. As of
      a follow-up patch, this list will be used by the common
      bdrv_refresh_filename() implementation to decide which options to put
      into BDS.full_open_options (and consequently whether a JSON filename has
      to be created), thus freeing the drivers of having to implement that
      logic themselves.
      
      Additionally, this patch adds the field to all of the block drivers that
      need it and sets it accordingly.
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      Reviewed-by: NAlberto Garcia <berto@igalia.com>
      Message-id: 20190201192935.18394-22-mreitz@redhat.com
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      2654267c
  13. 12 2月, 2019 1 次提交
  14. 12 12月, 2018 1 次提交
  15. 15 8月, 2018 1 次提交
  16. 05 7月, 2018 1 次提交
  17. 29 6月, 2018 3 次提交
    • M
      block/crypto: Simplify block_crypto_{open,create}_opts_init() · 796d3239
      Markus Armbruster 提交于
      block_crypto_open_opts_init() and block_crypto_create_opts_init()
      contain a virtual visit of QCryptoBlockOptions and
      QCryptoBlockCreateOptions less member "format", respectively.
      
      Change their callers to put member "format" in the QDict, so they can
      use the generated visitors for these types instead.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      796d3239
    • K
      block: Convert .bdrv_truncate callback to coroutine_fn · 061ca8a3
      Kevin Wolf 提交于
      bdrv_truncate() is an operation that can block (even for a quite long
      time, depending on the PreallocMode) in I/O paths that shouldn't block.
      Convert it to a coroutine_fn so that we have the infrastructure for
      drivers to make their .bdrv_co_truncate implementation asynchronous.
      
      This change could potentially introduce new race conditions because
      bdrv_truncate() isn't necessarily executed atomically any more. Whether
      this is a problem needs to be evaluated for each block driver that
      supports truncate:
      
      * file-posix/win32, gluster, iscsi, nfs, rbd, ssh, sheepdog: The
        protocol drivers are trivially safe because they don't actually yield
        yet, so there is no change in behaviour.
      
      * copy-on-read, crypto, raw-format: Essentially just filter drivers that
        pass the request to a child node, no problem.
      
      * qcow2: The implementation modifies metadata, so it needs to hold
        s->lock to be safe with concurrent I/O requests. In order to avoid
        double locking, this requires pulling the locking out into
        preallocate_co() and using qcow2_write_caches() instead of
        bdrv_flush().
      
      * qed: Does a single header update, this is fine without locking.
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      Reviewed-by: NStefan Hajnoczi <stefanha@redhat.com>
      061ca8a3
    • M
      block/crypto: Pacify Coverity after commit f853465a · e6af90f3
      Markus Armbruster 提交于
      Coverity can't see that qobject_input_visitor_new_flat_confused()
      returns non-null when it doesn't set @local_err.  Check the return
      value instead, like all the other callers do.
      
      Fixes: CID 1393615
      Fixes: CID 1393616
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      e6af90f3
  18. 15 6月, 2018 1 次提交
    • M
      block: Make remaining uses of qobject input visitor more robust · f853465a
      Markus Armbruster 提交于
      Remaining uses of qobject_input_visitor_new_keyval() in the block
      subsystem:
      
      * block_crypto_open_opts_init()
        Currently doesn't visit any non-string scalars, thus safe.  It's
        called from
        - block_crypto_open_luks()
          Creates the QDict with qemu_opts_to_qdict_filtered(), which
          creates only string scalars, but has a TODO asking for other types.
        - qcow_open()
        - qcow2_open(), qcow2_co_invalidate_cache(), qcow2_reopen_prepare()
      
      * block_crypto_create_opts_init(), called from
        - block_crypto_co_create_opts_luks()
          Also creates the QDict with qemu_opts_to_qdict_filtered().
      
      * vdi_co_create_opts()
        Also creates the QDict with qemu_opts_to_qdict_filtered().
      
      Replace these uses by qobject_input_visitor_new_flat_confused() for
      robustness.  This adds crumpling.  Right now, that's a no-op, but if
      we ever extend these things in non-flat ways, crumpling will be
      needed.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      f853465a
  19. 31 5月, 2018 1 次提交
  20. 04 5月, 2018 1 次提交
  21. 26 3月, 2018 1 次提交
  22. 19 3月, 2018 5 次提交
  23. 09 3月, 2018 1 次提交
  24. 03 3月, 2018 2 次提交
  25. 10 2月, 2018 1 次提交
    • E
      block: Simplify bdrv_can_write_zeroes_with_unmap() · e24d813b
      Eric Blake 提交于
      We don't need the can_write_zeroes_with_unmap field in
      BlockDriverInfo, because it is redundant information with
      supported_zero_flags & BDRV_REQ_MAY_UNMAP.  Note that
      BlockDriverInfo and supported_zero_flags are both per-device
      settings, rather than global state about the driver as a
      whole, which means one or both of these bits of information
      can already be conditional.  Let's audit how they were set:
      
      crypto: always setting can_write_ to false is pointless (the
      struct starts life zero-initialized), no use of supported_
      
      nbd: just recently fixed to set can_write_ if supported_
      includes MAY_UNMAP (thus this commit effectively reverts
      bca80059e and solves the problem mentioned there in a more
      global way)
      
      file-posix, iscsi, qcow2: can_write_ is conditional, while
      supported_ was unconditional; but passing MAY_UNMAP would
      fail with ENOTSUP if the condition wasn't met
      
      qed: can_write_ is unconditional, but pwrite_zeroes lacks
      support for MAY_UNMAP and supported_ is not set. Perhaps
      support can be added later (since it would be similar to
      qcow2), but for now claiming false is no real loss
      
      all other drivers: can_write_ is not set, and supported_ is
      either unset or a passthrough
      
      Simplify the code by moving the conditional into
      supported_zero_flags for all drivers, then dropping the
      now-unused BDI field.  For callers that relied on
      bdrv_can_write_zeroes_with_unmap(), we return the same
      per-device settings for drivers that had conditions (no
      observable change in behavior there); and can now return
      true (instead of false) for drivers that support passthrough
      (for example, the commit driver) which gives those drivers
      the same fix as nbd just got in bca80059e.  For callers that
      relied on supported_zero_flags, we now have a few more places
      that can avoid a wasted call to pwrite_zeroes() that will
      just fail with ENOTSUP.
      Suggested-by: NPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <20180126193439.20219-1-eblake@redhat.com>
      Reviewed-by: NStefan Hajnoczi <stefanha@redhat.com>
      e24d813b
  26. 09 2月, 2018 2 次提交
  27. 06 10月, 2017 1 次提交