[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v9 06/13] qcow2: Assert that cluster operations are
From: |
Eric Blake |
Subject: |
[Qemu-devel] [PATCH v9 06/13] qcow2: Assert that cluster operations are aligned |
Date: |
Mon, 10 Apr 2017 20:17:11 -0500 |
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: Eric Blake <address@hidden>
---
v9: rebase to master, by asserting that only tail cluster is unaligned
v7, v8: only earlier half of series submitted for 2.9
v6: avoid assertion on non-cluster-aligned image, use s->cluster_sectors
to avoid a shift, drop R-b
v5: no change
v4: new patch
---
block/qcow2-cluster.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index 12f44b2..362a855 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -1519,11 +1519,10 @@ int qcow2_discard_clusters(BlockDriverState *bs,
uint64_t offset,
end_offset = offset + (nb_sectors << BDRV_SECTOR_BITS);
- /* The caller must cluster-align start; round end down except at EOF */
+ /* Caller must pass aligned values, except at image end */
assert(QEMU_IS_ALIGNED(offset, s->cluster_size));
- if (end_offset != bs->total_sectors * BDRV_SECTOR_SIZE) {
- end_offset = start_of_cluster(s, end_offset);
- }
+ assert(QEMU_IS_ALIGNED(end_offset, s->cluster_size) ||
+ end_offset == bs->total_sectors << BDRV_SECTOR_BITS);
nb_clusters = size_to_clusters(s, end_offset - offset);
@@ -1596,9 +1595,17 @@ int qcow2_zero_clusters(BlockDriverState *bs, uint64_t
offset, int nb_sectors,
int flags)
{
BDRVQcow2State *s = bs->opaque;
+ uint64_t end_offset;
uint64_t nb_clusters;
int ret;
+ end_offset = offset + (nb_sectors << BDRV_SECTOR_BITS);
+
+ /* Caller must pass aligned values, except at image end */
+ assert(QEMU_IS_ALIGNED(offset, s->cluster_size));
+ assert(QEMU_IS_ALIGNED(end_offset, s->cluster_size) ||
+ end_offset == bs->total_sectors << BDRV_SECTOR_BITS);
+
/* The zero flag is only supported by version 3 and newer; we
* require the use of that flag if there is a backing file or if
* we are not allowed to unmap. */
--
2.9.3
- [Qemu-devel] [PATCH for-2.10 v9 00/13] add blkdebug tests, Eric Blake, 2017/04/10
- [Qemu-devel] [PATCH v9 04/13] qemu-io: Switch 'map' output to byte-based reporting, Eric Blake, 2017/04/10
- [Qemu-devel] [PATCH v9 02/13] iotests: Add test 179 to cover write zeroes with unmap, Eric Blake, 2017/04/10
- [Qemu-devel] [PATCH v9 06/13] qcow2: Assert that cluster operations are aligned,
Eric Blake <=
- [Qemu-devel] [PATCH v9 09/13] blkdebug: Refactor error injection, Eric Blake, 2017/04/10
- [Qemu-devel] [PATCH v9 03/13] qemu-io: Switch 'alloc' command to byte-based length, Eric Blake, 2017/04/10
- [Qemu-devel] [PATCH v9 01/13] qcow2: Unallocate unmapped zero clusters if no backing file, Eric Blake, 2017/04/10
- [Qemu-devel] [PATCH v9 05/13] qcow2: Optimize write zero of unaligned tail cluster, Eric Blake, 2017/04/10
- [Qemu-devel] [PATCH v9 07/13] qcow2: Discard/zero clusters by byte count, Eric Blake, 2017/04/10