1. 17 7月, 2017 1 次提交
  2. 11 7月, 2017 1 次提交
  3. 10 7月, 2017 5 次提交
    • E
      block: Make bdrv_is_allocated_above() byte-based · 51b0a488
      Eric Blake 提交于
      We are gradually moving away from sector-based interfaces, towards
      byte-based.  In the common case, allocation is unlikely to ever use
      values that are not naturally sector-aligned, but it is possible
      that byte-based values will let us be more precise about allocation
      at the end of an unaligned file that can do byte-based access.
      
      Changing the signature of the function to use int64_t *pnum ensures
      that the compiler enforces that all callers are updated.  For now,
      the io.c layer still assert()s that all callers are sector-aligned,
      but that can be relaxed when a later patch implements byte-based
      block status.  Therefore, for the most part this patch is just the
      addition of scaling at the callers followed by inverse scaling at
      bdrv_is_allocated().  But some code, particularly stream_run(),
      gets a lot simpler because it no longer has to mess with sectors.
      Leave comments where we can further simplify by switching to
      byte-based iterations, once later patches eliminate the need for
      sector-aligned operations.
      
      For ease of review, bdrv_is_allocated() was tackled separately.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      51b0a488
    • E
      block: Minimize raw use of bds->total_sectors · c00716be
      Eric Blake 提交于
      bdrv_is_allocated_above() was relying on intermediate->total_sectors,
      which is a field that can have stale contents depending on the value
      of intermediate->has_variable_length.  An audit shows that we are safe
      (we were first calling through bdrv_co_get_block_status() which in
      turn calls bdrv_nb_sectors() and therefore just refreshed the current
      length), but it's nicer to favor our accessor functions to avoid having
      to repeat such an audit, even if it means refresh_total_sectors() is
      called more frequently.
      Suggested-by: NJohn Snow <jsnow@redhat.com>
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NManos Pitsidianakis <el13635@mail.ntua.gr>
      Reviewed-by: NJeff Cody <jcody@redhat.com>
      Reviewed-by: NJohn Snow <jsnow@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      c00716be
    • E
      block: Make bdrv_is_allocated() byte-based · d6a644bb
      Eric Blake 提交于
      We are gradually moving away from sector-based interfaces, towards
      byte-based.  In the common case, allocation is unlikely to ever use
      values that are not naturally sector-aligned, but it is possible
      that byte-based values will let us be more precise about allocation
      at the end of an unaligned file that can do byte-based access.
      
      Changing the signature of the function to use int64_t *pnum ensures
      that the compiler enforces that all callers are updated.  For now,
      the io.c layer still assert()s that all callers are sector-aligned
      on input and that *pnum is sector-aligned on return to the caller,
      but that can be relaxed when a later patch implements byte-based
      block status.  Therefore, this code adds usages like
      DIV_ROUND_UP(,BDRV_SECTOR_SIZE) to callers that still want aligned
      values, where the call might reasonbly give non-aligned results
      in the future; on the other hand, no rounding is needed for callers
      that should just continue to work with byte alignment.
      
      For the most part this patch is just the addition of scaling at the
      callers followed by inverse scaling at bdrv_is_allocated().  But
      some code, particularly bdrv_commit(), gets a lot simpler because it
      no longer has to mess with sectors; also, it is now possible to pass
      NULL if the caller does not care how much of the image is allocated
      beyond the initial offset.  Leave comments where we can further
      simplify once a later patch eliminates the need for sector-aligned
      requests through bdrv_is_allocated().
      
      For ease of review, bdrv_is_allocated_above() will be tackled
      separately.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      d6a644bb
    • E
      block: Drop unused bdrv_round_sectors_to_clusters() · e8a81e9c
      Eric Blake 提交于
      Now that the last user [mirror_iteration()] has converted to using
      bytes, we no longer need a function to round sectors to clusters.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NJohn Snow <jsnow@redhat.com>
      Reviewed-by: NJeff Cody <jcody@redhat.com>
      Reviewed-by: NKevin Wolf <kwolf@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      e8a81e9c
    • E
      block: Guarantee that *file is set on bdrv_get_block_status() · 81c219ac
      Eric Blake 提交于
      We document that *file is valid if the return is not an error and
      includes BDRV_BLOCK_OFFSET_VALID, but forgot to obey this contract
      when a driver (such as blkdebug) lacks a callback.  Messed up in
      commit 67a0fd2a (v2.6), when we added the file parameter.
      
      Enhance qemu-iotest 177 to cover this, using a sequence that would
      print garbage or even SEGV, because it was dererefencing through
      uninitialized memory.  [The resulting test output shows that we
      have less-than-ideal block status from the blkdebug driver, but
      that's a separate fix coming up soon.]
      
      Setting *file on all paths that return BDRV_BLOCK_OFFSET_VALID is
      enough to fix the crash, but we can go one step further: always
      setting *file, even on error, means that a broken caller that
      blindly dereferences file without checking for error is now more
      likely to get a reliable SEGV instead of randomly acting on garbage,
      making it easier to diagnose such buggy callers.  Adding an
      assertion that file is set where expected doesn't hurt either.
      
      CC: qemu-stable@nongnu.org
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NFam Zheng <famz@redhat.com>
      Reviewed-by: NMax Reitz <mreitz@redhat.com>
      Reviewed-by: NJohn Snow <jsnow@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      81c219ac
  4. 30 6月, 2017 2 次提交
    • E
      block: Exploit BDRV_BLOCK_EOF for larger zero blocks · c61e684e
      Eric Blake 提交于
      When we have a BDS with unallocated clusters, but asking the status
      of its underlying bs->file or backing layer encounters an end-of-file
      condition, we know that the rest of the unallocated area will read as
      zeroes.  However, pre-patch, this required two separate calls to
      bdrv_get_block_status(), as the first call stops at the point where
      the underlying file ends.  Thanks to BDRV_BLOCK_EOF, we can now widen
      the results of the primary status if the secondary status already
      includes BDRV_BLOCK_ZERO.
      
      In turn, this fixes a TODO mentioned in iotest 154, where we can now
      see that all sectors in a partial cluster at the end of a file read
      as zero when coupling the shorter backing file's status along with our
      knowledge that the remaining sectors came from an unallocated cluster.
      
      Also, note that the loop in bdrv_co_get_block_status_above() had an
      inefficent exit: in cases where the active layer sets BDRV_BLOCK_ZERO
      but does NOT set BDRV_BLOCK_ALLOCATED (namely, where we know we read
      zeroes merely because our unallocated clusters lie beyond the backing
      file's shorter length), we still ended up probing the backing layer
      even though we already had a good answer.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <20170505021500.19315-3-eblake@redhat.com>
      Reviewed-by: NStefan Hajnoczi <stefanha@redhat.com>
      Signed-off-by: NFam Zheng <famz@redhat.com>
      c61e684e
    • E
      block: Add BDRV_BLOCK_EOF to bdrv_get_block_status() · fb0d8654
      Eric Blake 提交于
      Just as the block layer already sets BDRV_BLOCK_ALLOCATED as a
      shortcut for subsequent operations, there are also some optimizations
      that are made easier if we can quickly tell that *pnum will advance
      us to the end of a file, via a new BDRV_BLOCK_EOF which gets set
      by the block layer.
      
      This just plumbs up the new bit; subsequent patches will make use
      of it.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <20170505021500.19315-2-eblake@redhat.com>
      Reviewed-by: NStefan Hajnoczi <stefanha@redhat.com>
      Signed-off-by: NFam Zheng <famz@redhat.com>
      fb0d8654
  5. 26 6月, 2017 4 次提交
  6. 16 6月, 2017 8 次提交
  7. 25 5月, 2017 1 次提交
  8. 12 5月, 2017 1 次提交
  9. 27 4月, 2017 3 次提交
  10. 18 4月, 2017 1 次提交
    • F
      block: Walk bs->children carefully in bdrv_drain_recurse · 178bd438
      Fam Zheng 提交于
      The recursive bdrv_drain_recurse may run a block job completion BH that
      drops nodes. The coming changes will make that more likely and use-after-free
      would happen without this patch
      
      Stash the bs pointer and use bdrv_ref/bdrv_unref in addition to
      QLIST_FOREACH_SAFE to prevent such a case from happening.
      
      Since bdrv_unref accesses global state that is not protected by the AioContext
      lock, we cannot use bdrv_ref/bdrv_unref unconditionally.  Fortunately the
      protection is not needed in IOThread because only main loop can modify a graph
      with the AioContext lock held.
      Signed-off-by: NFam Zheng <famz@redhat.com>
      Message-Id: <20170418143044.12187-2-famz@redhat.com>
      Reviewed-by: NJeff Cody <jcody@redhat.com>
      Tested-by: NJeff Cody <jcody@redhat.com>
      Signed-off-by: NFam Zheng <famz@redhat.com>
      178bd438
  11. 11 4月, 2017 4 次提交
  12. 07 4月, 2017 1 次提交
  13. 13 3月, 2017 1 次提交
  14. 01 3月, 2017 3 次提交
  15. 21 2月, 2017 4 次提交