Skip to content
Snippets Groups Projects
  1. Nov 07, 2023
  2. Oct 12, 2023
  3. Jun 28, 2023
  4. May 30, 2023
  5. May 19, 2023
    • Kevin Wolf's avatar
      block: Call .bdrv_co_create(_opts) unlocked · 4db7ba3b
      Kevin Wolf authored
      
      These are functions that modify the graph, so they must be able to take
      a writer lock. This is impossible if they already hold the reader lock.
      If they need a reader lock for some of their operations, they should
      take it internally.
      
      Many of them go through blk_*(), which will always take the lock itself.
      Direct calls of bdrv_*() need to take the reader lock. Note that while
      locking for bdrv_co_*() calls is checked by TSA, this is not the case
      for the mixed_coroutine_fns bdrv_*(). Holding the lock is still required
      when they are called from coroutine context like here!
      
      This effectively reverts 4ec8df01, but adds some internal locking
      instead.
      
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      Message-Id: <20230510203601.418015-2-kwolf@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      4db7ba3b
  6. May 15, 2023
  7. May 10, 2023
  8. Apr 11, 2023
  9. Feb 23, 2023
  10. Feb 01, 2023
  11. Jan 20, 2023
    • Markus Armbruster's avatar
      include/block: Untangle inclusion loops · e2c1c34f
      Markus Armbruster authored
      
      We have two inclusion loops:
      
             block/block.h
          -> block/block-global-state.h
          -> block/block-common.h
          -> block/blockjob.h
          -> block/block.h
      
             block/block.h
          -> block/block-io.h
          -> block/block-common.h
          -> block/blockjob.h
          -> block/block.h
      
      I believe these go back to Emanuele's reorganization of the block API,
      merged a few months ago in commit d7e2fe4a.
      
      Fortunately, breaking them is merely a matter of deleting unnecessary
      includes from headers, and adding them back in places where they are
      now missing.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20221221133551.3967339-2-armbru@redhat.com>
      e2c1c34f
  12. Dec 15, 2022
  13. Oct 27, 2022
    • Vladimir Sementsov-Ogievskiy's avatar
      block: Manipulate bs->file / bs->backing pointers in .attach/.detach · 5bb04747
      Vladimir Sementsov-Ogievskiy authored
      
      bs->file and bs->backing are a kind of duplication of part of
      bs->children. But very useful diplication, so let's not drop them at
      all:)
      
      We should manage bs->file and bs->backing in same place, where we
      manage bs->children, to keep them in sync.
      
      Moreover, generic io paths are unprepared to BdrvChild without a bs, so
      it's double good to clear bs->file / bs->backing when we detach the
      child.
      
      Detach is simple: if we detach bs->file or bs->backing child, just
      set corresponding field to NULL.
      
      Attach is a bit more complicated. But we still can precisely detect
      should we set one of bs->file / bs->backing or not:
      
      - if role is BDRV_CHILD_COW, we definitely deal with bs->backing
      - else, if role is BDRV_CHILD_FILTERED (it must be also
        BDRV_CHILD_PRIMARY), it's a filtered child. Use
        bs->drv->filtered_child_is_backing to chose the pointer field to
        modify.
      - else, if role is BDRV_CHILD_PRIMARY, we deal with bs->file
      - in all other cases, it's neither bs->backing nor bs->file. It's some
        other child and we shouldn't care
      
      OK. This change brings one more good thing: we can (and should) get rid
      of all indirect pointers in the block-graph-change transactions:
      
      bdrv_attach_child_common() stores BdrvChild** into transaction to clear
      it on abort.
      
      bdrv_attach_child_common() has two callers: bdrv_attach_child_noperm()
      just pass-through this feature, bdrv_root_attach_child() doesn't need
      the feature.
      
      Look at bdrv_attach_child_noperm() callers:
        - bdrv_attach_child() doesn't need the feature
        - bdrv_set_file_or_backing_noperm() uses the feature to manage
          bs->file and bs->backing, we don't want it anymore
        - bdrv_append() uses the feature to manage bs->backing, again we
          don't want it anymore
      
      So, we should drop this stuff! Great!
      
      We could probably keep BdrvChild** argument to keep the int return
      value, but it seems not worth the complexity.
      
      Finally, we now set .file / .backing automatically in generic code and
      want to restring setting them by hand outside of .attach/.detach.
      So, this patch cleanups all remaining places where they were set.
      To find such places I use:
      
        git grep '\->file ='
        git grep '\->backing ='
        git grep '&.*\<backing\>'
        git grep '&.*\<file\>'
      
      Signed-off-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
      Reviewed-by: default avatarHanna Reitz <hreitz@redhat.com>
      Message-Id: <20220726201134.924743-14-vsementsov@yandex-team.ru>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      5bb04747
  14. Oct 26, 2022
    • Stefan Hajnoczi's avatar
      block: add BDRV_REQ_REGISTERED_BUF request flag · e8b65355
      Stefan Hajnoczi authored
      
      Block drivers may optimize I/O requests accessing buffers previously
      registered with bdrv_register_buf(). Checking whether all elements of a
      request's QEMUIOVector are within previously registered buffers is
      expensive, so we need a hint from the user to avoid costly checks.
      
      Add a BDRV_REQ_REGISTERED_BUF request flag to indicate that all
      QEMUIOVector elements in an I/O request are known to be within
      previously registered buffers.
      
      Always pass the flag through to driver read/write functions. There is
      little harm in passing the flag to a driver that does not use it.
      Passing the flag to drivers avoids changes across many block drivers.
      Filter drivers would need to explicitly support the flag and pass
      through to their children when the children support it. That's a lot of
      code changes and it's hard to remember to do that everywhere, leading to
      silent reduced performance when the flag is accidentally dropped.
      
      The only problematic scenario with the approach in this patch is when a
      driver passes the flag through to internal I/O requests that don't use
      the same I/O buffer. In that case the hint may be set when it should
      actually be clear. This is a rare case though so the risk is low.
      
      Some drivers have assert(!flags), which no longer works when
      BDRV_REQ_REGISTERED_BUF is passed in. These assertions aren't very
      useful anyway since the functions are called almost exclusively by
      bdrv_driver_preadv/pwritev() so if we get flags handling right there
      then the assertion is not needed.
      
      Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      Message-id: 20221013185908.1297568-7-stefanha@redhat.com
      Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      e8b65355
  15. Oct 07, 2022
  16. Sep 30, 2022
  17. Mar 07, 2022
  18. Sep 29, 2021
    • Vladimir Sementsov-Ogievskiy's avatar
      block: use int64_t instead of int in driver discard handlers · 0c802287
      Vladimir Sementsov-Ogievskiy authored
      
      We are generally moving to int64_t for both offset and bytes parameters
      on all io paths.
      
      Main motivation is realization of 64-bit write_zeroes operation for
      fast zeroing large disk chunks, up to the whole disk.
      
      We chose signed type, to be consistent with off_t (which is signed) and
      with possibility for signed return type (where negative value means
      error).
      
      So, convert driver discard handlers bytes parameter to int64_t.
      
      The only caller of all updated function is bdrv_co_pdiscard in
      block/io.c. It is already prepared to work with 64bit requests, but
      pass at most max(bs->bl.max_pdiscard, INT_MAX) to the driver.
      
      Let's look at all updated functions:
      
      blkdebug: all calculations are still OK, thanks to
        bdrv_check_qiov_request().
        both rule_check and bdrv_co_pdiscard are 64bit
      
      blklogwrites: pass to blk_loc_writes_co_log which is 64bit
      
      blkreplay, copy-on-read, filter-compress: pass to bdrv_co_pdiscard, OK
      
      copy-before-write: pass to bdrv_co_pdiscard which is 64bit and to
        cbw_do_copy_before_write which is 64bit
      
      file-posix: one handler calls raw_account_discard() is 64bit and both
        handlers calls raw_do_pdiscard(). Update raw_do_pdiscard, which pass
        to RawPosixAIOData::aio_nbytes, which is 64bit (and calls
        raw_account_discard())
      
      gluster: somehow, third argument of glfs_discard_async is size_t.
        Let's set max_pdiscard accordingly.
      
      iscsi: iscsi_allocmap_set_invalid is 64bit,
        !is_byte_request_lun_aligned is 64bit.
        list.num is uint32_t. Let's clarify max_pdiscard and
        pdiscard_alignment.
      
      mirror_top: pass to bdrv_mirror_top_do_write() which is
        64bit
      
      nbd: protocol limitation. max_pdiscard is alredy set strict enough,
        keep it as is for now.
      
      nvme: buf.nlb is uint32_t and we do shift. So, add corresponding limits
        to nvme_refresh_limits().
      
      preallocate: pass to bdrv_co_pdiscard() which is 64bit.
      
      rbd: pass to qemu_rbd_start_co() which is 64bit.
      
      qcow2: calculations are still OK, thanks to bdrv_check_qiov_request(),
        qcow2_cluster_discard() is 64bit.
      
      raw-format: raw_adjust_offset() is 64bit, bdrv_co_pdiscard too.
      
      throttle: pass to bdrv_co_pdiscard() which is 64bit and to
        throttle_group_co_io_limits_intercept() which is 64bit as well.
      
      test-block-iothread: bytes argument is unused
      
      Great! Now all drivers are prepared to handle 64bit discard requests,
      or else have explicit max_pdiscard limits.
      
      Signed-off-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Message-Id: <20210903102807.27127-11-vsementsov@virtuozzo.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      0c802287
    • Vladimir Sementsov-Ogievskiy's avatar
      block: use int64_t instead of int in driver write_zeroes handlers · f34b2bcf
      Vladimir Sementsov-Ogievskiy authored
      
      We are generally moving to int64_t for both offset and bytes parameters
      on all io paths.
      
      Main motivation is realization of 64-bit write_zeroes operation for
      fast zeroing large disk chunks, up to the whole disk.
      
      We chose signed type, to be consistent with off_t (which is signed) and
      with possibility for signed return type (where negative value means
      error).
      
      So, convert driver write_zeroes handlers bytes parameter to int64_t.
      
      The only caller of all updated function is bdrv_co_do_pwrite_zeroes().
      
      bdrv_co_do_pwrite_zeroes() itself is of course OK with widening of
      callee parameter type. Also, bdrv_co_do_pwrite_zeroes()'s
      max_write_zeroes is limited to INT_MAX. So, updated functions all are
      safe, they will not get "bytes" larger than before.
      
      Still, let's look through all updated functions, and add assertions to
      the ones which are actually unprepared to values larger than INT_MAX.
      For these drivers also set explicit max_pwrite_zeroes limit.
      
      Let's go:
      
      blkdebug: calculations can't overflow, thanks to
        bdrv_check_qiov_request() in generic layer. rule_check() and
        bdrv_co_pwrite_zeroes() both have 64bit argument.
      
      blklogwrites: pass to blk_log_writes_co_log() with 64bit argument.
      
      blkreplay, copy-on-read, filter-compress: pass to
        bdrv_co_pwrite_zeroes() which is OK
      
      copy-before-write: Calls cbw_do_copy_before_write() and
        bdrv_co_pwrite_zeroes, both have 64bit argument.
      
      file-posix: both handler calls raw_do_pwrite_zeroes, which is updated.
        In raw_do_pwrite_zeroes() calculations are OK due to
        bdrv_check_qiov_request(), bytes go to RawPosixAIOData::aio_nbytes
        which is uint64_t.
        Check also where that uint64_t gets handed:
        handle_aiocb_write_zeroes_block() passes a uint64_t[2] to
        ioctl(BLKZEROOUT), handle_aiocb_write_zeroes() calls do_fallocate()
        which takes off_t (and we compile to always have 64-bit off_t), as
        does handle_aiocb_write_zeroes_unmap. All look safe.
      
      gluster: bytes go to GlusterAIOCB::size which is int64_t and to
        glfs_zerofill_async works with off_t.
      
      iscsi: Aha, here we deal with iscsi_writesame16_task() that has
        uint32_t num_blocks argument and iscsi_writesame16_task() has
        uint16_t argument. Make comments, add assertions and clarify
        max_pwrite_zeroes calculation.
        iscsi_allocmap_() functions already has int64_t argument
        is_byte_request_lun_aligned is simple to update, do it.
      
      mirror_top: pass to bdrv_mirror_top_do_write which has uint64_t
        argument
      
      nbd: Aha, here we have protocol limitation, and NBDRequest::len is
        uint32_t. max_pwrite_zeroes is cleanly set to 32bit value, so we are
        OK for now.
      
      nvme: Again, protocol limitation. And no inherent limit for
        write-zeroes at all. But from code that calculates cdw12 it's obvious
        that we do have limit and alignment. Let's clarify it. Also,
        obviously the code is not prepared to handle bytes=0. Let's handle
        this case too.
        trace events already 64bit
      
      preallocate: pass to handle_write() and bdrv_co_pwrite_zeroes(), both
        64bit.
      
      rbd: pass to qemu_rbd_start_co() which is 64bit.
      
      qcow2: offset + bytes and alignment still works good (thanks to
        bdrv_check_qiov_request()), so tail calculation is OK
        qcow2_subcluster_zeroize() has 64bit argument, should be OK
        trace events updated
      
      qed: qed_co_request wants int nb_sectors. Also in code we have size_t
        used for request length which may be 32bit. So, let's just keep
        INT_MAX as a limit (aligning it down to pwrite_zeroes_alignment) and
        don't care.
      
      raw-format: Is OK. raw_adjust_offset and bdrv_co_pwrite_zeroes are both
        64bit.
      
      throttle: Both throttle_group_co_io_limits_intercept() and
        bdrv_co_pwrite_zeroes() are 64bit.
      
      vmdk: pass to vmdk_pwritev which is 64bit
      
      quorum: pass to quorum_co_pwritev() which is 64bit
      
      Hooray!
      
      At this point all block drivers are prepared to support 64bit
      write-zero requests, or have explicitly set max_pwrite_zeroes.
      
      Signed-off-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Message-Id: <20210903102807.27127-8-vsementsov@virtuozzo.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      [eblake: use <= rather than < in assertions relying on max_pwrite_zeroes]
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      f34b2bcf
    • Vladimir Sementsov-Ogievskiy's avatar
      block: use int64_t instead of uint64_t in copy_range driver handlers · 48535049
      Vladimir Sementsov-Ogievskiy authored
      
      We are generally moving to int64_t for both offset and bytes parameters
      on all io paths.
      
      Main motivation is realization of 64-bit write_zeroes operation for
      fast zeroing large disk chunks, up to the whole disk.
      
      We chose signed type, to be consistent with off_t (which is signed) and
      with possibility for signed return type (where negative value means
      error).
      
      So, convert driver copy_range handlers parameters which are already
      64bit to signed type.
      
      Now let's consider all callers. Simple
      
        git grep '\->bdrv_co_copy_range'
      
      shows the only caller:
      
        bdrv_co_copy_range_internal(), which does bdrv_check_request32(),
        so everything is OK.
      
      Still, the functions may be called directly, not only by drv->...
      Let's check:
      
      git grep '\.bdrv_co_copy_range_\(from\|to\)\s*=' | \
      awk '{print $4}' | sed 's/,//' | sed 's/&//' | sort | uniq | \
      while read func; do git grep "$func(" | \
      grep -v "$func(BlockDriverState"; done
      
      shows no more callers. So, we are done.
      
      Signed-off-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <20210903102807.27127-6-vsementsov@virtuozzo.com>
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      48535049
    • Vladimir Sementsov-Ogievskiy's avatar
      block: use int64_t instead of uint64_t in driver write handlers · e75abeda
      Vladimir Sementsov-Ogievskiy authored
      
      We are generally moving to int64_t for both offset and bytes parameters
      on all io paths.
      
      Main motivation is realization of 64-bit write_zeroes operation for
      fast zeroing large disk chunks, up to the whole disk.
      
      We chose signed type, to be consistent with off_t (which is signed) and
      with possibility for signed return type (where negative value means
      error).
      
      So, convert driver write handlers parameters which are already 64bit to
      signed type.
      
      While being here, convert also flags parameter to be BdrvRequestFlags.
      
      Now let's consider all callers. Simple
      
        git grep '\->bdrv_\(aio\|co\)_pwritev\(_part\)\?'
      
      shows that's there three callers of driver function:
      
       bdrv_driver_pwritev() and bdrv_driver_pwritev_compressed() in
       block/io.c, both pass int64_t, checked by bdrv_check_qiov_request() to
       be non-negative.
      
       qcow2_save_vmstate() does bdrv_check_qiov_request().
      
      Still, the functions may be called directly, not only by drv->...
      Let's check:
      
      git grep '\.bdrv_\(aio\|co\)_pwritev\(_part\)\?\s*=' | \
      awk '{print $4}' | sed 's/,//' | sed 's/&//' | sort | uniq | \
      while read func; do git grep "$func(" | \
      grep -v "$func(BlockDriverState"; done
      
      shows several callers:
      
      qcow2:
        qcow2_co_truncate() write at most up to @offset, which is checked in
          generic qcow2_co_truncate() by bdrv_check_request().
        qcow2_co_pwritev_compressed_task() pass the request (or part of the
          request) that already went through normal write path, so it should
          be OK
      
      qcow:
        qcow_co_pwritev_compressed() pass int64_t, it's updated by this patch
      
      quorum:
        quorum_co_pwrite_zeroes() pass int64_t and int - OK
      
      throttle:
        throttle_co_pwritev_compressed() pass int64_t, it's updated by this
        patch
      
      vmdk:
        vmdk_co_pwritev_compressed() pass int64_t, it's updated by this
        patch
      
      Signed-off-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Message-Id: <20210903102807.27127-5-vsementsov@virtuozzo.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      e75abeda
    • Vladimir Sementsov-Ogievskiy's avatar
      block: use int64_t instead of uint64_t in driver read handlers · f7ef38dd
      Vladimir Sementsov-Ogievskiy authored
      
      We are generally moving to int64_t for both offset and bytes parameters
      on all io paths.
      
      Main motivation is realization of 64-bit write_zeroes operation for
      fast zeroing large disk chunks, up to the whole disk.
      
      We chose signed type, to be consistent with off_t (which is signed) and
      with possibility for signed return type (where negative value means
      error).
      
      So, convert driver read handlers parameters which are already 64bit to
      signed type.
      
      While being here, convert also flags parameter to be BdrvRequestFlags.
      
      Now let's consider all callers. Simple
      
        git grep '\->bdrv_\(aio\|co\)_preadv\(_part\)\?'
      
      shows that's there three callers of driver function:
      
       bdrv_driver_preadv() in block/io.c, passes int64_t, checked by
         bdrv_check_qiov_request() to be non-negative.
      
       qcow2_load_vmstate() does bdrv_check_qiov_request().
      
       do_perform_cow_read() has uint64_t argument. And a lot of things in
       qcow2 driver are uint64_t, so converting it is big job. But we must
       not work with requests that don't satisfy bdrv_check_qiov_request(),
       so let's just assert it here.
      
      Still, the functions may be called directly, not only by drv->...
      Let's check:
      
      git grep '\.bdrv_\(aio\|co\)_preadv\(_part\)\?\s*=' | \
      awk '{print $4}' | sed 's/,//' | sed 's/&//' | sort | uniq | \
      while read func; do git grep "$func(" | \
      grep -v "$func(BlockDriverState"; done
      
      The only one such caller:
      
          QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, &data, 1);
          ...
          ret = bdrv_replace_test_co_preadv(bs, 0, 1, &qiov, 0);
      
      in tests/unit/test-bdrv-drain.c, and it's OK obviously.
      
      Signed-off-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Message-Id: <20210903102807.27127-4-vsementsov@virtuozzo.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      [eblake: fix typos]
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      f7ef38dd
  19. Sep 01, 2021
    • Stefan Hajnoczi's avatar
      raw-format: drop WRITE and RESIZE child perms when possible · b68ce824
      Stefan Hajnoczi authored
      
      The following command-line fails due to a permissions conflict:
      
        $ qemu-storage-daemon \
            --blockdev driver=nvme,node-name=nvme0,device=0000:08:00.0,namespace=1 \
            --blockdev driver=raw,node-name=l1-1,file=nvme0,offset=0,size=1073741824 \
            --blockdev driver=raw,node-name=l1-2,file=nvme0,offset=1073741824,size=1073741824 \
            --nbd-server addr.type=unix,addr.path=/tmp/nbd.sock,max-connections=2 \
            --export type=nbd,id=nbd-l1-1,node-name=l1-1,name=l1-1,writable=on \
            --export type=nbd,id=nbd-l1-2,node-name=l1-2,name=l1-2,writable=on
      
        qemu-storage-daemon: --export type=nbd,id=nbd-l1-1,node-name=l1-1,name=l1-1,writable=on: Permission conflict on node 'nvme0': permissions 'resize' are both required by node 'l1-1' (uses node 'nvme0' as 'file' child) and unshared by node 'l1-2' (uses node 'nvme0' as 'file' child).
      
      The problem is that block/raw-format.c relies on bdrv_default_perms() to
      set permissions on the nvme node. The default permissions add RESIZE in
      anticipation of a format driver like qcow2 that needs to grow the image
      file. This fails because RESIZE is unshared, so we cannot get the RESIZE
      permission.
      
      Max Reitz pointed out that block/crypto.c already handles this case by
      implementing a custom ->bdrv_child_perm() function that adjusts the
      result of bdrv_default_perms().
      
      This patch takes the same approach in block/raw-format.c so that RESIZE
      is only required if it's actually necessary (e.g. the parent is qcow2).
      
      Cc: Max Reitz <mreitz@redhat.com>
      Cc: Kevin Wolf <kwolf@redhat.com>
      Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      Message-Id: <20210726122839.822900-1-stefanha@redhat.com>
      Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Signed-off-by: default avatarHanna Reitz <hreitz@redhat.com>
      b68ce824
  20. Feb 12, 2021
  21. Jul 10, 2020
    • Markus Armbruster's avatar
      error: Eliminate error_propagate() with Coccinelle, part 2 · af175e85
      Markus Armbruster authored
      
      When all we do with an Error we receive into a local variable is
      propagating to somewhere else, we can just as well receive it there
      right away.  The previous commit did that with a Coccinelle script I
      consider fairly trustworthy.  This commit uses the same script with
      the matching of return taken out, i.e. we convert
      
          if (!foo(..., &err)) {
              ...
              error_propagate(errp, err);
              ...
          }
      
      to
      
          if (!foo(..., errp)) {
              ...
              ...
          }
      
      This is unsound: @err could still be read between afterwards.  I don't
      know how to express "no read of @err without an intervening write" in
      Coccinelle.  Instead, I manually double-checked for uses of @err.
      
      Suboptimal line breaks tweaked manually.  qdev_realize() simplified
      further to placate scripts/checkpatch.pl.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <20200707160613.848843-36-armbru@redhat.com>
      af175e85
    • Markus Armbruster's avatar
      qemu-option: Use returned bool to check for failure · 235e59cf
      Markus Armbruster authored
      
      The previous commit enables conversion of
      
          foo(..., &err);
          if (err) {
              ...
          }
      
      to
      
          if (!foo(..., &err)) {
              ...
          }
      
      for QemuOpts functions that now return true / false on success /
      error.  Coccinelle script:
      
          @@
          identifier fun = {
              opts_do_parse, parse_option_bool, parse_option_number,
              parse_option_size, qemu_opt_parse, qemu_opt_rename, qemu_opt_set,
              qemu_opt_set_bool, qemu_opt_set_number, qemu_opts_absorb_qdict,
              qemu_opts_do_parse, qemu_opts_from_qdict_entry, qemu_opts_set,
              qemu_opts_validate
          };
          expression list args, args2;
          typedef Error;
          Error *err;
          @@
          -    fun(args, &err, args2);
          -    if (err)
          +    if (!fun(args, &err, args2))
               {
                   ...
               }
      
      A few line breaks tidied up manually.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Message-Id: <20200707160613.848843-15-armbru@redhat.com>
      [Conflict with commit 0b6786a9 "block/amend: refactor qcow2 amend
      options" resolved by rerunning Coccinelle on master's version]
      235e59cf
  22. May 28, 2020
    • Eric Blake's avatar
      qcow2: Expose bitmaps' size during measure · 5d72c68b
      Eric Blake authored
      It's useful to know how much space can be occupied by qcow2 persistent
      bitmaps, even though such metadata is unrelated to the guest-visible
      data.  Report this value as an additional QMP field, present when
      measuring an existing image and output format that both support
      bitmaps.  Update iotest 178 and 190 to updated output, as well as new
      coverage in 190 demonstrating non-zero values made possible with the
      recently-added qemu-img bitmap command (see 3b51ab4b).
      
      The new 'bitmaps size:' field is displayed automatically as part of
      'qemu-img measure' any time it is present in QMP (that is, any time
      both the source image being measured and destination format support
      bitmaps, even if the measurement is 0 because there are no bitmaps
      present).  If the field is absent, it means that no bitmaps can be
      copied (source, destination, or both lack bitmaps, including when
      measuring based on size rather than on a source image).  This behavior
      is compatible with an upcoming patch adding 'qemu-img convert
      --bitmaps': that command will fail in the same situations where this
      patch omits the field.
      
      The addition of a new field demonstrates why we should always
      zero-initialize qapi C structs; while the qcow2 driver still fully
      populates all fields, the raw and crypto drivers had to be tweaked to
      avoid uninitialized data.
      
      Consideration was also given towards having a 'qemu-img measure
      --bitmaps' which errors out when bitmaps are not possible, and
      otherwise sums the bitmaps into the existing allocation totals rather
      than displaying as a separate field, as a potential convenience
      factor.  But this was ultimately decided to be more complexity than
      necessary when the QMP interface was sufficient enough with bitmaps
      remaining a separate field.
      
      See also: https://bugzilla.redhat.com/1779904
      
      
      
      Reported-by: default avatarNir Soffer <nsoffer@redhat.com>
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <20200521192137.1120211-3-eblake@redhat.com>
      Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      5d72c68b
Loading