* [Qemu-devel] [PATCH] qcow2: Fix qcow2_get_cluster_offset() for zero clusters
@ 2015-11-04 17:16 Kevin Wolf
2015-11-04 19:29 ` Max Reitz
0 siblings, 1 reply; 2+ messages in thread
From: Kevin Wolf @ 2015-11-04 17:16 UTC (permalink / raw)
To: qemu-block; +Cc: kwolf, qemu-stable, qemu-devel, mreitz
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: qemu-stable@nongnu.org
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH] qcow2: Fix qcow2_get_cluster_offset() for zero clusters
2015-11-04 17:16 [Qemu-devel] [PATCH] qcow2: Fix qcow2_get_cluster_offset() for zero clusters Kevin Wolf
@ 2015-11-04 19:29 ` Max Reitz
0 siblings, 0 replies; 2+ messages in thread
From: Max Reitz @ 2015-11-04 19:29 UTC (permalink / raw)
To: Kevin Wolf, qemu-block; +Cc: qemu-devel, qemu-stable
[-- Attachment #1: Type: text/plain, Size: 654 bytes --]
On 04.11.2015 18:16, Kevin Wolf wrote:
> 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: qemu-stable@nongnu.org
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
> block/qcow2-cluster.c | 15 +++++++++------
> 1 file changed, 9 insertions(+), 6 deletions(-)
Thanks, applied to my block tree:
https://github.com/XanClic/qemu/commits/block
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-11-04 19:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-04 17:16 [Qemu-devel] [PATCH] qcow2: Fix qcow2_get_cluster_offset() for zero clusters Kevin Wolf
2015-11-04 19:29 ` Max Reitz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).