[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL v2 40/40] qcow2: Fix qcow2_get_cluster_offset() for z
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL v2 40/40] qcow2: Fix qcow2_get_cluster_offset() for zero clusters |
Date: |
Tue, 10 Nov 2015 15:09:40 +0100 |
When searching for contiguous zero clusters, we only need to check the
cluster type. Before this patch, an increasing offset (L2E_OFFSET_MASK)
was expected, so that the function never returned more than a single
zero cluster in practice. This patch fixes it to actually return as many
contiguous zero clusters as it can.
Cc: address@hidden
Signed-off-by: Kevin Wolf <address@hidden>
Message-id: address@hidden
Signed-off-by: Max Reitz <address@hidden>
---
block/qcow2-cluster.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index 67be0ce..24a60e2 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -312,7 +312,7 @@ static int count_contiguous_clusters(int nb_clusters, int
cluster_size,
if (!offset)
return 0;
- assert(qcow2_get_cluster_type(first_entry) != QCOW2_CLUSTER_COMPRESSED);
+ assert(qcow2_get_cluster_type(first_entry) == QCOW2_CLUSTER_NORMAL);
for (i = 0; i < nb_clusters; i++) {
uint64_t l2_entry = be64_to_cpu(l2_table[i]) & mask;
@@ -324,14 +324,16 @@ static int count_contiguous_clusters(int nb_clusters, int
cluster_size,
return i;
}
-static int count_contiguous_free_clusters(int nb_clusters, uint64_t *l2_table)
+static int count_contiguous_clusters_by_type(int nb_clusters,
+ uint64_t *l2_table,
+ int wanted_type)
{
int i;
for (i = 0; i < nb_clusters; i++) {
int type = qcow2_get_cluster_type(be64_to_cpu(l2_table[i]));
- if (type != QCOW2_CLUSTER_UNALLOCATED) {
+ if (type != wanted_type) {
break;
}
}
@@ -554,13 +556,14 @@ int qcow2_get_cluster_offset(BlockDriverState *bs,
uint64_t offset,
ret = -EIO;
goto fail;
}
- c = count_contiguous_clusters(nb_clusters, s->cluster_size,
- &l2_table[l2_index], QCOW_OFLAG_ZERO);
+ c = count_contiguous_clusters_by_type(nb_clusters, &l2_table[l2_index],
+ QCOW2_CLUSTER_ZERO);
*cluster_offset = 0;
break;
case QCOW2_CLUSTER_UNALLOCATED:
/* how many empty clusters ? */
- c = count_contiguous_free_clusters(nb_clusters, &l2_table[l2_index]);
+ c = count_contiguous_clusters_by_type(nb_clusters, &l2_table[l2_index],
+ QCOW2_CLUSTER_UNALLOCATED);
*cluster_offset = 0;
break;
case QCOW2_CLUSTER_NORMAL:
--
1.8.3.1
- [Qemu-devel] [PULL v2 25/40] qemu-img: add check for zero-length job len, (continued)
- [Qemu-devel] [PULL v2 25/40] qemu-img: add check for zero-length job len, Kevin Wolf, 2015/11/10
- [Qemu-devel] [PULL v2 32/40] qemu-io: Check for trailing chars, Kevin Wolf, 2015/11/10
- [Qemu-devel] [PULL v2 27/40] throttle: Use bs->throttle_state instead of bs->io_limits_enabled, Kevin Wolf, 2015/11/10
- [Qemu-devel] [PULL v2 33/40] qemu-io: Correct error messages, Kevin Wolf, 2015/11/10
- [Qemu-devel] [PULL v2 36/40] mirror: block all operations on the target image during the job, Kevin Wolf, 2015/11/10
- [Qemu-devel] [PULL v2 35/40] qemu-iotests: fix -valgrind option for check, Kevin Wolf, 2015/11/10
- [Qemu-devel] [PULL v2 30/40] block: test 'blockdev-snapshot' using a file BDS as the overlay, Kevin Wolf, 2015/11/10
- [Qemu-devel] [PULL v2 34/40] qemu-iotests: fix cleanup of background processes, Kevin Wolf, 2015/11/10
- [Qemu-devel] [PULL v2 37/40] block: Add blk_get_refcnt(), Kevin Wolf, 2015/11/10
- [Qemu-devel] [PULL v2 31/40] qemu-io: fix cvtnum lval types, Kevin Wolf, 2015/11/10
- [Qemu-devel] [PULL v2 40/40] qcow2: Fix qcow2_get_cluster_offset() for zero clusters,
Kevin Wolf <=
- [Qemu-devel] [PULL v2 38/40] block: Add 'x-blockdev-del' QMP command, Kevin Wolf, 2015/11/10
- [Qemu-devel] [PULL v2 39/40] iotests: Add tests for the x-blockdev-del command, Kevin Wolf, 2015/11/10
- Re: [Qemu-devel] [PULL v2 00/40] Block layer patches, Peter Maydell, 2015/11/10