summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2010-01-20 15:03:01 +0100
committerAnthony Liguori <aliguori@us.ibm.com>2010-01-27 07:51:35 -0600
commitd0d888bc6d1a106609b9af42ecb552c6c34a85c5 (patch)
treef9968d00795c3662ba6c7dd9a8f7765981d14fcc /block/qcow2.c
parentqcow2: Return 0/-errno in get_cluster_table (diff)
downloadqemu-kvm-d0d888bc6d1a106609b9af42ecb552c6c34a85c5.tar.gz
qemu-kvm-d0d888bc6d1a106609b9af42ecb552c6c34a85c5.tar.bz2
qemu-kvm-d0d888bc6d1a106609b9af42ecb552c6c34a85c5.zip
qcow2: Return 0/-errno in qcow2_alloc_cluster_offset
Returning 0/-errno allows it to distingush different errors classes. The cluster offset of newly allocated clusters is now returned in the QCowL2Meta struct. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit 148da7ea9d66bad0d5b6512074fbedc4e2640e8f)
Diffstat (limited to 'block/qcow2.c')
-rw-r--r--block/qcow2.c36
1 files changed, 19 insertions, 17 deletions
diff --git a/block/qcow2.c b/block/qcow2.c
index 6485d8f2f..4ae8f193d 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -561,7 +561,7 @@ static void qcow_aio_write_cb(void *opaque, int ret)
acb->hd_aiocb = NULL;
if (ret >= 0) {
- ret = qcow2_alloc_cluster_link_l2(bs, acb->cluster_offset, &acb->l2meta);
+ ret = qcow2_alloc_cluster_link_l2(bs, &acb->l2meta);
}
run_dependent_requests(&acb->l2meta);
@@ -585,21 +585,23 @@ static void qcow_aio_write_cb(void *opaque, int ret)
n_end > QCOW_MAX_CRYPT_CLUSTERS * s->cluster_sectors)
n_end = QCOW_MAX_CRYPT_CLUSTERS * s->cluster_sectors;
- acb->cluster_offset = qcow2_alloc_cluster_offset(bs, acb->sector_num << 9,
- index_in_cluster,
- n_end, &acb->n, &acb->l2meta);
+ ret = qcow2_alloc_cluster_offset(bs, acb->sector_num << 9,
+ index_in_cluster, n_end, &acb->n, &acb->l2meta);
+ if (ret < 0) {
+ goto done;
+ }
+
+ acb->cluster_offset = acb->l2meta.cluster_offset;
/* Need to wait for another request? If so, we are done for now. */
- if (!acb->cluster_offset && acb->l2meta.depends_on != NULL) {
+ if (acb->l2meta.nb_clusters == 0 && acb->l2meta.depends_on != NULL) {
QLIST_INSERT_HEAD(&acb->l2meta.depends_on->dependent_requests,
acb, next_depend);
return;
}
- if (!acb->cluster_offset || (acb->cluster_offset & 511) != 0) {
- ret = -EIO;
- goto done;
- }
+ assert((acb->cluster_offset & 511) == 0);
+
if (s->crypt_method) {
if (!acb->cluster_data) {
acb->cluster_data = qemu_mallocz(QCOW_MAX_CRYPT_CLUSTERS *
@@ -683,27 +685,27 @@ static int get_bits_from_size(size_t size)
static int preallocate(BlockDriverState *bs)
{
BDRVQcowState *s = bs->opaque;
- uint64_t cluster_offset = 0;
uint64_t nb_sectors;
uint64_t offset;
int num;
+ int ret;
QCowL2Meta meta;
nb_sectors = bdrv_getlength(bs) >> 9;
offset = 0;
QLIST_INIT(&meta.dependent_requests);
+ meta.cluster_offset = 0;
while (nb_sectors) {
num = MIN(nb_sectors, INT_MAX >> 9);
- cluster_offset = qcow2_alloc_cluster_offset(bs, offset, 0, num, &num,
- &meta);
+ ret = qcow2_alloc_cluster_offset(bs, offset, 0, num, &num, &meta);
- if (cluster_offset == 0) {
+ if (ret < 0) {
return -1;
}
- if (qcow2_alloc_cluster_link_l2(bs, cluster_offset, &meta) < 0) {
- qcow2_free_any_clusters(bs, cluster_offset, meta.nb_clusters);
+ if (qcow2_alloc_cluster_link_l2(bs, &meta) < 0) {
+ qcow2_free_any_clusters(bs, meta.cluster_offset, meta.nb_clusters);
return -1;
}
@@ -722,10 +724,10 @@ static int preallocate(BlockDriverState *bs)
* all of the allocated clusters (otherwise we get failing reads after
* EOF). Extend the image to the last allocated sector.
*/
- if (cluster_offset != 0) {
+ if (meta.cluster_offset != 0) {
uint8_t buf[512];
memset(buf, 0, 512);
- bdrv_write(s->hd, (cluster_offset >> 9) + num - 1, buf, 1);
+ bdrv_write(s->hd, (meta.cluster_offset >> 9) + num - 1, buf, 1);
}
return 0;