diff options
author | Kevin Wolf <kwolf@redhat.com> | 2010-01-20 15:03:01 +0100 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2010-01-26 14:59:19 -0600 |
commit | 148da7ea9d66bad0d5b6512074fbedc4e2640e8f (patch) | |
tree | ea363cd5a48a8abc6f478e5450df82d3ef0115ae /block/qcow2.c | |
parent | 1e3e8f1a437cafa3b23486aea36be3c9c0bd4e28 (diff) |
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>
Diffstat (limited to 'block/qcow2.c')
-rw-r--r-- | block/qcow2.c | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/block/qcow2.c b/block/qcow2.c index e06f4dd3c1..773d381870 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 * @@ -782,27 +784,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; } @@ -821,10 +823,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; |