1. 26 6月, 2017 7 次提交
  2. 29 5月, 2017 1 次提交
  3. 11 5月, 2017 9 次提交
    • E
      qcow2: Discard/zero clusters by byte count · d2cb36af
      Eric Blake 提交于
      Passing a byte offset, but sector count, when we ultimately
      want to operate on cluster granularity, is madness.  Clean up
      the external interfaces to take both offset and count as bytes,
      while still keeping the assertion added previously that the
      caller must align the values to a cluster.  Then rename things
      to make sure backports don't get confused by changed units:
      instead of qcow2_discard_clusters() and qcow2_zero_clusters(),
      we now have qcow2_cluster_discard() and qcow2_cluster_zeroize().
      
      The internal functions still operate on clusters at a time, and
      return an int for number of cleared clusters; but on an image
      with 2M clusters, a single L2 table holds 256k entries that each
      represent a 2M cluster, totalling well over INT_MAX bytes if we
      ever had a request for that many bytes at once.  All our callers
      currently limit themselves to 32-bit bytes (and therefore fewer
      clusters), but by making this function 64-bit clean, we have one
      less place to clean up if we later improve the block layer to
      support 64-bit bytes through all operations (with the block layer
      auto-fragmenting on behalf of more-limited drivers), rather than
      the current state where some interfaces are artificially limited
      to INT_MAX at a time.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NMax Reitz <mreitz@redhat.com>
      Message-id: 20170507000552.20847-13-eblake@redhat.com
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      d2cb36af
    • E
      qcow2: Assert that cluster operations are aligned · f10ee139
      Eric Blake 提交于
      We already audited (in commit 0c1bd469) that qcow2_discard_clusters()
      is only passed cluster-aligned start values; but we can further
      tighten the assertion that the only unaligned end value is at EOF.
      
      Recent commits have taken advantage of an unaligned tail cluster,
      for both discard and write zeroes.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NMax Reitz <mreitz@redhat.com>
      Message-id: 20170507000552.20847-12-eblake@redhat.com
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      f10ee139
    • E
      qcow2: Optimize zero_single_l2() to minimize L2 churn · 06cc5e2b
      Eric Blake 提交于
      Similar to discard_single_l2(), we should try to avoid dirtying
      the L2 cache when the cluster we are changing already has the
      right characteristics.
      
      Note that by the time we get to zero_single_l2(), BDRV_REQ_MAY_UNMAP
      is a requirement to unallocate a cluster (this is because the block
      layer clears that flag if discard.* flags during open requested that
      we never punch holes - see the conversation around commit 170f4b2e,
      https://lists.gnu.org/archive/html/qemu-devel/2016-09/msg07306.html).
      Therefore, this patch can only reuse a zero cluster as-is if either
      unmapping is not requested, or if the zero cluster was not associated
      with an allocation.
      
      Technically, there are some cases where an unallocated cluster
      already reads as all zeroes (namely, when there is no backing file
      [easy: check bs->backing], or when the backing file also reads as
      zeroes [harder: we can't check bdrv_get_block_status since we are
      already holding the lock]), where the guest would not immediately see
      a difference if we left that cluster unallocated.  But if the user
      did not request unmapping, leaving an unallocated cluster is wrong;
      and even if the user DID request unmapping, keeping a cluster
      unallocated risks a subtle semantic change of guest-visible contents
      if a backing file is later added, and it is not worth auditing
      whether all internal uses such as mirror properly avoid an unmap
      request.  Thus, this patch is intentionally limited to just clusters
      that are already marked as zero.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NMax Reitz <mreitz@redhat.com>
      Message-id: 20170507000552.20847-8-eblake@redhat.com
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      06cc5e2b
    • E
      qcow2: Make distinction between zero cluster types obvious · fdfab37d
      Eric Blake 提交于
      Treat plain zero clusters differently from allocated ones, so that
      we can simplify the logic of checking whether an offset is present.
      Do this by splitting QCOW2_CLUSTER_ZERO into two new enums,
      QCOW2_CLUSTER_ZERO_PLAIN and QCOW2_CLUSTER_ZERO_ALLOC.
      
      I tried to arrange the enum so that we could use
      'ret <= QCOW2_CLUSTER_ZERO_PLAIN' for all unallocated types, and
      'ret >= QCOW2_CLUSTER_ZERO_ALLOC' for allocated types, although
      I didn't actually end up taking advantage of the layout.
      
      In many cases, this leads to simpler code, by properly combining
      cases (sometimes, both zero types pair together, other times,
      plain zero is more like unallocated while allocated zero is more
      like normal).
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-id: 20170507000552.20847-7-eblake@redhat.com
      Reviewed-by: NMax Reitz <mreitz@redhat.com>
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      fdfab37d
    • E
      qcow2: Name typedef for cluster type · 3ef95218
      Eric Blake 提交于
      Although it doesn't add all that much type safety (this is C, after
      all), it does add a bit of legibility to use the name QCow2ClusterType
      instead of a plain int.
      
      In particular, qcow2_get_cluster_offset() has an overloaded return
      type; a QCow2ClusterType on success, and -errno on failure; keeping
      the cluster type in a separate variable makes it slightly easier for
      the next patch to make further computations based on the type.
      Suggested-by: NMax Reitz <mreitz@redhat.com>
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-id: 20170507000552.20847-6-eblake@redhat.com
      [mreitz: Use the new type in two more places (one of them pulled from
               the next patch)]
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      3ef95218
    • E
      qcow2: Correctly report status of preallocated zero clusters · 4341df8a
      Eric Blake 提交于
      We were throwing away the preallocation information associated with
      zero clusters.  But we should be matching the well-defined semantics
      in bdrv_get_block_status(), where (BDRV_BLOCK_ZERO |
      BDRV_BLOCK_OFFSET_VALID) informs the user which offset is reserved,
      while still reminding the user that reading from that offset is
      likely to read garbage.
      
      count_contiguous_clusters_by_type() is now used only for unallocated
      cluster runs, hence it gets renamed and tightened.
      
      Making this change lets us see which portions of an image are zero
      but preallocated, when using qemu-img map --output=json.  The
      --output=human side intentionally ignores all zero clusters, whether
      or not they are preallocated.
      
      The fact that there is no change to qemu-iotests './check -qcow2'
      merely means that we aren't yet testing this aspect of qemu-img;
      a later patch will add a test.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NMax Reitz <mreitz@redhat.com>
      Message-id: 20170507000552.20847-5-eblake@redhat.com
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      4341df8a
    • E
      qcow2: Use consistent switch indentation · bbd995d8
      Eric Blake 提交于
      Fix a couple of inconsistent indentations, before an upcoming
      patch further tweaks the switch statements.
      (best viewed with 'git diff -b').
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NMax Reitz <mreitz@redhat.com>
      Message-id: 20170507000552.20847-3-eblake@redhat.com
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      bbd995d8
    • M
      qcow2: Discard preallocated zero clusters · 293073a5
      Max Reitz 提交于
      In discard_single_l2(), we completely discard normal clusters instead of
      simply turning them into preallocated zero clusters. That means we
      should probably do the same with such preallocated zero clusters:
      Discard them instead of keeping them allocated.
      Reported-by: NEric Blake <eblake@redhat.com>
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      293073a5
    • M
      qcow2: Reuse preallocated zero clusters · 564a6b69
      Max Reitz 提交于
      Instead of just freeing preallocated zero clusters and completely
      allocating them from scratch, reuse them.
      
      We cannot do this in handle_copied(), however, since this is a COW
      operation. Therefore, we have to add the new logic to handle_alloc() and
      simply return the existing offset if it exists. The only catch is that
      we have to convince qcow2_alloc_cluster_link_l2() not to free the old
      clusters (because we have reused them).
      Reported-by: NEric Blake <eblake@redhat.com>
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      564a6b69
  4. 03 4月, 2017 1 次提交
    • E
      qcow2: Discard unaligned tail when wiping image · 0c1bd469
      Eric Blake 提交于
      There is a subtle difference between the fast (qcow2v3 with no
      extra data) and slow path (qcow2v2 format [aka 0.10], or when a
      snapshot is present) of qcow2_make_empty().  The slow path fails
      to discard the final (partial) cluster of an unaligned image.
      
      The problem stems from the fact that qcow2_discard_clusters() was
      silently ignoring sub-cluster head and tail on unaligned requests.
      A quick audit of all callers shows that qcow2_snapshot_create() has
      always passed a cluster-aligned request since the call was added
      in commit 1ebf561c; qcow2_co_pdiscard() has passed a cluster-aligned
      request since commit ecdbead6 taught the block layer about preferred
      discard alignment; and qcow2_make_empty() was fixed to pass an
      aligned start (but not necessarily end) in commit a3e1505d.
      
      Asserting that the start is always aligned also points out that we
      now have a dead check: rounding the end offset down can never result
      in a value less than the aligned start offset (the check was rendered
      dead with commit ecdbead6).  Meanwhile, we do not want to round the
      end cluster down in the one case of the end offset matching the
      (unaligned) file size - that final partial cluster should still be
      discarded.
      
      With those fixes in place, the fast and slow paths are back in sync
      at discarding an entire image; the next patch will update
      qemu-iotests to ensure we don't regress.
      
      Note that bdrv_co_pdiscard ignores ALL partial cluster requests,
      including the partial cluster at the end of an image; it can be
      argued that the partial cluster at the end should be special-cased
      so that a guest issuing discard requests at proper alignments
      everywhere else can likewise empty the entire image.  But that
      optimization is left for another day.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-id: 20170331185356.2479-3-eblake@redhat.com
      Reviewed-by: NMax Reitz <mreitz@redhat.com>
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      0c1bd469
  5. 21 2月, 2017 1 次提交
  6. 24 10月, 2016 1 次提交
  7. 23 9月, 2016 1 次提交
    • D
      qcow2: fix encryption during cow of sectors · bb9f8dd0
      Daniel P. Berrange 提交于
      Broken in previous commit:
      
        commit aaa4d20b
        Author: Kevin Wolf <kwolf@redhat.com>
        Date:   Wed Jun 1 15:21:05 2016 +0200
      
            qcow2: Make copy_sectors() byte based
      
      The copy_sectors() code was originally using the 'sector'
      parameter for encryption, which was passed in by the caller
      from the QCowL2Meta.offset field (aka the guest logical
      offset).
      
      After the change, the code is using 'cluster_offset' which
      was passed in from QCow2L2Meta.alloc_offset field (aka the
      host physical offset).
      
      This would cause the data to be encrypted using an incorrect
      initialization vector which will in turn cause later reads
      to return garbage.
      
      Although current qcow2 built-in encryption is blocked from
      usage in the emulator, one could still hit this if writing
      to the file via qemu-{img,io,nbd} commands.
      
      Cc: qemu-stable@nongnu.org
      Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
      Signed-off-by: NKevin Wolf <kwolf@redhat.com>
      bb9f8dd0
  8. 13 9月, 2016 1 次提交
    • S
      qcow2: avoid memcpy(dst, NULL, len) · 0647d47c
      Stefan Hajnoczi 提交于
      Section "7.1.4 Use of library functions" in the C99 standard says:
      
        If an argument to a function has an invalid value (such as [...]
        a null pointer [...]) [...] the behavior is undefined.
      
      Additionally the "searching and sorting" functions are specified as
      requiring valid pointer values as described in 7.1.4.
      
      This patch fixes the following sanitizer errors:
      
        block/qcow2.c:1807:41: runtime error: null pointer passed as argument 2, which is declared to never be null
        block/qcow2-cluster.c:86:26: runtime error: null pointer passed as argument 2, which is declared to never be null
      Reported-by: NPeter Maydell <peter.maydell@linaro.org>
      Reviewed-by: NKevin Wolf <kwolf@redhat.com>
      Message-id: 1473758138-19260-1-git-send-email-stefanha@redhat.com
      Signed-off-by: NStefan Hajnoczi <stefanha@redhat.com>
      0647d47c
  9. 13 7月, 2016 2 次提交
    • M
      qcow2: Fix qcow2_get_cluster_offset() · c834cba9
      Max Reitz 提交于
      Recently, qcow2_get_cluster_offset() has been changed to work with bytes
      instead of sectors. This invalidated some assertions and introduced a
      possible integer multiplication overflow.
      
      This could be reproduced using e.g.
      
      $ qemu-img create -f qcow2 -o cluster_size=1M blub.qcow2 8G
      Formatting 'foo.qcow2', fmt=qcow2 size=8589934592 encryption=off
      cluster_size=1048576 lazy_refcounts=off refcount_bits=16
      $ qemu-io -c map blub.qcow2
      qemu-io: qemu/block/qcow2-cluster.c:504: qcow2_get_cluster_offset:
      Assertion `bytes_needed <= INT_MAX' failed.
      [1]    20775 abort (core dumped)  qemu-io -c map foo.qcow2
      
      This patch removes the now wrong assertion, adding comments and more
      assertions to prove its correctness (and fixing the overflow which would
      become apparent with the original assertion removed).
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      Message-id: 20160620142623.24471-3-mreitz@redhat.com
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      c834cba9
    • M
      qcow2: Avoid making the L1 table too big · 84c26520
      Max Reitz 提交于
      We refuse to open images whose L1 table we deem "too big". Consequently,
      we should not produce such images ourselves.
      
      Cc: qemu-stable@nongnu.org
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      Message-id: 20160615153630.2116-3-mreitz@redhat.com
      Reviewed-by: NEric Blake <eblake@redhat.com>
      [mreitz: Added QEMU_BUILD_BUG_ON()]
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      84c26520
  10. 05 7月, 2016 6 次提交
  11. 20 6月, 2016 1 次提交
    • E
      coccinelle: Remove unnecessary variables for function return value · 9be38598
      Eduardo Habkost 提交于
      Use Coccinelle script to replace 'ret = E; return ret' with
      'return E'. The script will do the substitution only when the
      function return type and variable type are the same.
      
      Manual fixups:
      
      * audio/audio.c: coding style of "read (...)" and "write (...)"
      * block/qcow2-cluster.c: wrap line to make it shorter
      * block/qcow2-refcount.c: change indentation of wrapped line
      * target-tricore/op_helper.c: fix coding style of
        "remainder|quotient"
      * target-mips/dsp_helper.c: reverted changes because I don't
        want to argue about checkpatch.pl
      * ui/qemu-pixman.c: fix line indentation
      * block/rbd.c: restore blank line between declarations and
        statements
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Signed-off-by: NEduardo Habkost <ehabkost@redhat.com>
      Message-Id: <1465855078-19435-4-git-send-email-ehabkost@redhat.com>
      Reviewed-by: NMarkus Armbruster <armbru@redhat.com>
      [Unused Coccinelle rule name dropped along with a redundant comment;
      whitespace touched up in block/qcow2-cluster.c; stale commit message
      paragraph deleted]
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      9be38598
  12. 16 6月, 2016 5 次提交
  13. 08 6月, 2016 1 次提交
  14. 07 6月, 2016 1 次提交
  15. 19 5月, 2016 1 次提交
  16. 23 3月, 2016 1 次提交
    • M
      include/qemu/osdep.h: Don't include qapi/error.h · da34e65c
      Markus Armbruster 提交于
      Commit 57cb38b3 included qapi/error.h into qemu/osdep.h to get the
      Error typedef.  Since then, we've moved to include qemu/osdep.h
      everywhere.  Its file comment explains: "To avoid getting into
      possible circular include dependencies, this file should not include
      any other QEMU headers, with the exceptions of config-host.h,
      compiler.h, os-posix.h and os-win32.h, all of which are doing a
      similar job to this file and are under similar constraints."
      qapi/error.h doesn't do a similar job, and it doesn't adhere to
      similar constraints: it includes qapi-types.h.  That's in excess of
      100KiB of crap most .c files don't actually need.
      
      Add the typedef to qemu/typedefs.h, and include that instead of
      qapi/error.h.  Include qapi/error.h in .c files that need it and don't
      get it now.  Include qapi-types.h in qom/object.h for uint16List.
      
      Update scripts/clean-includes accordingly.  Update it further to match
      reality: replace config.h by config-target.h, add sysemu/os-posix.h,
      sysemu/os-win32.h.  Update the list of includes in the qemu/osdep.h
      comment quoted above similarly.
      
      This reduces the number of objects depending on qapi/error.h from "all
      of them" to less than a third.  Unfortunately, the number depending on
      qapi-types.h shrinks only a little.  More work is needed for that one.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      [Fix compilation without the spice devel packages. - Paolo]
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      da34e65c