|
|
0a122b |
From 68066d2b824a88a45b3263dd1ceb18307c92581f Mon Sep 17 00:00:00 2001
|
|
|
0a122b |
From: Max Reitz <mreitz@redhat.com>
|
|
|
0a122b |
Date: Sat, 15 Feb 2014 16:03:47 +0100
|
|
|
0a122b |
Subject: [PATCH 2/5] qcow2: remove n_start and n_end of qcow2_alloc_cluster_offset()
|
|
|
0a122b |
|
|
|
0a122b |
RH-Author: Max Reitz <mreitz@redhat.com>
|
|
|
0a122b |
Message-id: <1392480230-24011-2-git-send-email-mreitz@redhat.com>
|
|
|
0a122b |
Patchwork-id: 57292
|
|
|
0a122b |
O-Subject: [RHEL-7.0 qemu-kvm PATCH 1/4] qcow2: remove n_start and n_end of qcow2_alloc_cluster_offset()
|
|
|
0a122b |
Bugzilla: 1049176
|
|
|
0a122b |
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
0a122b |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
0a122b |
RH-Acked-by: Fam Zheng <famz@redhat.com>
|
|
|
0a122b |
|
|
|
0a122b |
From: Hu Tao <hutao@cn.fujitsu.com>
|
|
|
0a122b |
|
|
|
0a122b |
BZ: 1049176
|
|
|
0a122b |
BZ: 1055848
|
|
|
0a122b |
|
|
|
0a122b |
n_start can be actually calculated from offset. The number of
|
|
|
0a122b |
sectors to be allocated(n_end - n_start) can be passed in in
|
|
|
0a122b |
num. By removing n_start and n_end, we can save two parameters.
|
|
|
0a122b |
|
|
|
0a122b |
The side effect is there is a bug in qcow2.c:preallocate() that
|
|
|
0a122b |
passes incorrect n_start to qcow2_alloc_cluster_offset() is
|
|
|
0a122b |
fixed. The bug can be triggerred by a larger cluster size than
|
|
|
0a122b |
the default value(65536), for example:
|
|
|
0a122b |
|
|
|
0a122b |
./qemu-img create -f qcow2 \
|
|
|
0a122b |
-o 'cluster_size=131072,preallocation=metadata' file.img 4G
|
|
|
0a122b |
|
|
|
0a122b |
Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
|
|
|
0a122b |
Reviewed-by: Max Reitz <mreitz@redhat.com>
|
|
|
0a122b |
Reviewed-by: Benoit Canet <benoit@irqsave.net>
|
|
|
0a122b |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
0a122b |
(cherry picked from commit 16f0587e0a5da5b1ad76cb7c3739491bc042201c)
|
|
|
0a122b |
|
|
|
0a122b |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
|
0a122b |
---
|
|
|
0a122b |
block/qcow2-cluster.c | 14 ++++++--------
|
|
|
0a122b |
block/qcow2.c | 13 +++++++------
|
|
|
0a122b |
block/qcow2.h | 2 +-
|
|
|
0a122b |
trace-events | 2 +-
|
|
|
0a122b |
4 files changed, 15 insertions(+), 16 deletions(-)
|
|
|
0a122b |
|
|
|
0a122b |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
0a122b |
---
|
|
|
0a122b |
block/qcow2-cluster.c | 14 ++++++--------
|
|
|
0a122b |
block/qcow2.c | 13 +++++++------
|
|
|
0a122b |
block/qcow2.h | 2 +-
|
|
|
0a122b |
trace-events | 2 +-
|
|
|
0a122b |
4 files changed, 15 insertions(+), 16 deletions(-)
|
|
|
0a122b |
|
|
|
0a122b |
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
|
|
|
0a122b |
index 79c3ae0..862df0f 100644
|
|
|
0a122b |
--- a/block/qcow2-cluster.c
|
|
|
0a122b |
+++ b/block/qcow2-cluster.c
|
|
|
0a122b |
@@ -1173,7 +1173,7 @@ fail:
|
|
|
0a122b |
* Return 0 on success and -errno in error cases
|
|
|
0a122b |
*/
|
|
|
0a122b |
int qcow2_alloc_cluster_offset(BlockDriverState *bs, uint64_t offset,
|
|
|
0a122b |
- int n_start, int n_end, int *num, uint64_t *host_offset, QCowL2Meta **m)
|
|
|
0a122b |
+ int *num, uint64_t *host_offset, QCowL2Meta **m)
|
|
|
0a122b |
{
|
|
|
0a122b |
BDRVQcowState *s = bs->opaque;
|
|
|
0a122b |
uint64_t start, remaining;
|
|
|
0a122b |
@@ -1181,15 +1181,13 @@ int qcow2_alloc_cluster_offset(BlockDriverState *bs, uint64_t offset,
|
|
|
0a122b |
uint64_t cur_bytes;
|
|
|
0a122b |
int ret;
|
|
|
0a122b |
|
|
|
0a122b |
- trace_qcow2_alloc_clusters_offset(qemu_coroutine_self(), offset,
|
|
|
0a122b |
- n_start, n_end);
|
|
|
0a122b |
+ trace_qcow2_alloc_clusters_offset(qemu_coroutine_self(), offset, *num);
|
|
|
0a122b |
|
|
|
0a122b |
- assert(n_start * BDRV_SECTOR_SIZE == offset_into_cluster(s, offset));
|
|
|
0a122b |
- offset = start_of_cluster(s, offset);
|
|
|
0a122b |
+ assert((offset & ~BDRV_SECTOR_MASK) == 0);
|
|
|
0a122b |
|
|
|
0a122b |
again:
|
|
|
0a122b |
- start = offset + (n_start << BDRV_SECTOR_BITS);
|
|
|
0a122b |
- remaining = (n_end - n_start) << BDRV_SECTOR_BITS;
|
|
|
0a122b |
+ start = offset;
|
|
|
0a122b |
+ remaining = *num << BDRV_SECTOR_BITS;
|
|
|
0a122b |
cluster_offset = 0;
|
|
|
0a122b |
*host_offset = 0;
|
|
|
0a122b |
cur_bytes = 0;
|
|
|
0a122b |
@@ -1275,7 +1273,7 @@ again:
|
|
|
0a122b |
}
|
|
|
0a122b |
}
|
|
|
0a122b |
|
|
|
0a122b |
- *num = (n_end - n_start) - (remaining >> BDRV_SECTOR_BITS);
|
|
|
0a122b |
+ *num -= remaining >> BDRV_SECTOR_BITS;
|
|
|
0a122b |
assert(*num > 0);
|
|
|
0a122b |
assert(*host_offset != 0);
|
|
|
0a122b |
|
|
|
0a122b |
diff --git a/block/qcow2.c b/block/qcow2.c
|
|
|
0a122b |
index 25a5b5e..fe950b4 100644
|
|
|
0a122b |
--- a/block/qcow2.c
|
|
|
0a122b |
+++ b/block/qcow2.c
|
|
|
0a122b |
@@ -1000,7 +1000,6 @@ static coroutine_fn int qcow2_co_writev(BlockDriverState *bs,
|
|
|
0a122b |
{
|
|
|
0a122b |
BDRVQcowState *s = bs->opaque;
|
|
|
0a122b |
int index_in_cluster;
|
|
|
0a122b |
- int n_end;
|
|
|
0a122b |
int ret;
|
|
|
0a122b |
int cur_nr_sectors; /* number of sectors in current iteration */
|
|
|
0a122b |
uint64_t cluster_offset;
|
|
|
0a122b |
@@ -1024,14 +1023,16 @@ static coroutine_fn int qcow2_co_writev(BlockDriverState *bs,
|
|
|
0a122b |
|
|
|
0a122b |
trace_qcow2_writev_start_part(qemu_coroutine_self());
|
|
|
0a122b |
index_in_cluster = sector_num & (s->cluster_sectors - 1);
|
|
|
0a122b |
- n_end = index_in_cluster + remaining_sectors;
|
|
|
0a122b |
+ cur_nr_sectors = remaining_sectors;
|
|
|
0a122b |
if (s->crypt_method &&
|
|
|
0a122b |
- n_end > QCOW_MAX_CRYPT_CLUSTERS * s->cluster_sectors) {
|
|
|
0a122b |
- n_end = QCOW_MAX_CRYPT_CLUSTERS * s->cluster_sectors;
|
|
|
0a122b |
+ cur_nr_sectors >
|
|
|
0a122b |
+ QCOW_MAX_CRYPT_CLUSTERS * s->cluster_sectors - index_in_cluster) {
|
|
|
0a122b |
+ cur_nr_sectors =
|
|
|
0a122b |
+ QCOW_MAX_CRYPT_CLUSTERS * s->cluster_sectors - index_in_cluster;
|
|
|
0a122b |
}
|
|
|
0a122b |
|
|
|
0a122b |
ret = qcow2_alloc_cluster_offset(bs, sector_num << 9,
|
|
|
0a122b |
- index_in_cluster, n_end, &cur_nr_sectors, &cluster_offset, &l2meta);
|
|
|
0a122b |
+ &cur_nr_sectors, &cluster_offset, &l2meta);
|
|
|
0a122b |
if (ret < 0) {
|
|
|
0a122b |
goto fail;
|
|
|
0a122b |
}
|
|
|
0a122b |
@@ -1408,7 +1409,7 @@ static int preallocate(BlockDriverState *bs)
|
|
|
0a122b |
|
|
|
0a122b |
while (nb_sectors) {
|
|
|
0a122b |
num = MIN(nb_sectors, INT_MAX >> 9);
|
|
|
0a122b |
- ret = qcow2_alloc_cluster_offset(bs, offset, 0, num, &num,
|
|
|
0a122b |
+ ret = qcow2_alloc_cluster_offset(bs, offset, &num,
|
|
|
0a122b |
&host_offset, &meta);
|
|
|
0a122b |
if (ret < 0) {
|
|
|
0a122b |
return ret;
|
|
|
0a122b |
diff --git a/block/qcow2.h b/block/qcow2.h
|
|
|
0a122b |
index 9749f03..4a653c5 100644
|
|
|
0a122b |
--- a/block/qcow2.h
|
|
|
0a122b |
+++ b/block/qcow2.h
|
|
|
0a122b |
@@ -463,7 +463,7 @@ void qcow2_encrypt_sectors(BDRVQcowState *s, int64_t sector_num,
|
|
|
0a122b |
int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset,
|
|
|
0a122b |
int *num, uint64_t *cluster_offset);
|
|
|
0a122b |
int qcow2_alloc_cluster_offset(BlockDriverState *bs, uint64_t offset,
|
|
|
0a122b |
- int n_start, int n_end, int *num, uint64_t *host_offset, QCowL2Meta **m);
|
|
|
0a122b |
+ int *num, uint64_t *host_offset, QCowL2Meta **m);
|
|
|
0a122b |
uint64_t qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs,
|
|
|
0a122b |
uint64_t offset,
|
|
|
0a122b |
int compressed_size);
|
|
|
0a122b |
diff --git a/trace-events b/trace-events
|
|
|
0a122b |
index 5d86cf3..b9144b2 100644
|
|
|
0a122b |
--- a/trace-events
|
|
|
0a122b |
+++ b/trace-events
|
|
|
0a122b |
@@ -485,7 +485,7 @@ qcow2_writev_done_part(void *co, int cur_nr_sectors) "co %p cur_nr_sectors %d"
|
|
|
0a122b |
qcow2_writev_data(void *co, uint64_t offset) "co %p offset %" PRIx64
|
|
|
0a122b |
|
|
|
0a122b |
# block/qcow2-cluster.c
|
|
|
0a122b |
-qcow2_alloc_clusters_offset(void *co, uint64_t offset, int n_start, int n_end) "co %p offet %" PRIx64 " n_start %d n_end %d"
|
|
|
0a122b |
+qcow2_alloc_clusters_offset(void *co, uint64_t offset, int num) "co %p offet %" PRIx64 " num %d"
|
|
|
0a122b |
qcow2_handle_copied(void *co, uint64_t guest_offset, uint64_t host_offset, uint64_t bytes) "co %p guest_offet %" PRIx64 " host_offset %" PRIx64 " bytes %" PRIx64
|
|
|
0a122b |
qcow2_handle_alloc(void *co, uint64_t guest_offset, uint64_t host_offset, uint64_t bytes) "co %p guest_offet %" PRIx64 " host_offset %" PRIx64 " bytes %" PRIx64
|
|
|
0a122b |
qcow2_do_alloc_clusters_offset(void *co, uint64_t guest_offset, uint64_t host_offset, int nb_clusters) "co %p guest_offet %" PRIx64 " host_offset %" PRIx64 " nb_clusters %d"
|
|
|
0a122b |
--
|
|
|
0a122b |
1.7.1
|
|
|
0a122b |
|