qcow2: Assert that cluster operations are aligned
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 <eblake@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Message-id: 20170507000552.20847-12-eblake@redhat.com
Signed-off-by: Max Reitz <mreitz@redhat.com>
This commit is contained in:
parent
fbaa6bb3d3
commit
f10ee139ad
@ -1559,11 +1559,10 @@ int qcow2_discard_clusters(BlockDriverState *bs, uint64_t offset,
|
|||||||
|
|
||||||
end_offset = offset + (nb_sectors << BDRV_SECTOR_BITS);
|
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));
|
assert(QEMU_IS_ALIGNED(offset, s->cluster_size));
|
||||||
if (end_offset != bs->total_sectors * BDRV_SECTOR_SIZE) {
|
assert(QEMU_IS_ALIGNED(end_offset, s->cluster_size) ||
|
||||||
end_offset = start_of_cluster(s, end_offset);
|
end_offset == bs->total_sectors << BDRV_SECTOR_BITS);
|
||||||
}
|
|
||||||
|
|
||||||
nb_clusters = size_to_clusters(s, end_offset - offset);
|
nb_clusters = size_to_clusters(s, end_offset - offset);
|
||||||
|
|
||||||
@ -1646,9 +1645,17 @@ int qcow2_zero_clusters(BlockDriverState *bs, uint64_t offset, int nb_sectors,
|
|||||||
int flags)
|
int flags)
|
||||||
{
|
{
|
||||||
BDRVQcow2State *s = bs->opaque;
|
BDRVQcow2State *s = bs->opaque;
|
||||||
|
uint64_t end_offset;
|
||||||
uint64_t nb_clusters;
|
uint64_t nb_clusters;
|
||||||
int ret;
|
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 */
|
/* The zero flag is only supported by version 3 and newer */
|
||||||
if (s->qcow_version < 3) {
|
if (s->qcow_version < 3) {
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
|
Loading…
Reference in New Issue
Block a user