[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 10/14] qcow2: Change l2_load to return 0/-errno
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 10/14] qcow2: Change l2_load to return 0/-errno |
Date: |
Fri, 28 May 2010 18:46:09 +0200 |
Provide the error code to the caller instead of just indicating success/error.
Signed-off-by: Kevin Wolf <address@hidden>
---
block/qcow2-cluster.c | 38 ++++++++++++++++++++++----------------
1 files changed, 22 insertions(+), 16 deletions(-)
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index ea98afc..03a9f25 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -157,31 +157,36 @@ static uint64_t *seek_l2_table(BDRVQcowState *s, uint64_t
l2_offset)
* the image file failed.
*/
-static uint64_t *l2_load(BlockDriverState *bs, uint64_t l2_offset)
+static int l2_load(BlockDriverState *bs, uint64_t l2_offset,
+ uint64_t **l2_table)
{
BDRVQcowState *s = bs->opaque;
int min_index;
- uint64_t *l2_table;
+ int ret;
/* seek if the table for the given offset is in the cache */
- l2_table = seek_l2_table(s, l2_offset);
- if (l2_table != NULL)
- return l2_table;
+ *l2_table = seek_l2_table(s, l2_offset);
+ if (*l2_table != NULL) {
+ return 0;
+ }
/* not found: load a new entry in the least used one */
min_index = l2_cache_new_entry(bs);
- l2_table = s->l2_cache + (min_index << s->l2_bits);
+ *l2_table = s->l2_cache + (min_index << s->l2_bits);
BLKDBG_EVENT(bs->file, BLKDBG_L2_LOAD);
- if (bdrv_pread(bs->file, l2_offset, l2_table, s->l2_size *
sizeof(uint64_t)) !=
- s->l2_size * sizeof(uint64_t))
- return NULL;
+ ret = bdrv_pread(bs->file, l2_offset, *l2_table,
+ s->l2_size * sizeof(uint64_t));
+ if (ret < 0) {
+ return ret;
+ }
+
s->l2_cache_offsets[min_index] = l2_offset;
s->l2_cache_counts[min_index] = 1;
- return l2_table;
+ return 0;
}
/*
@@ -440,6 +445,7 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t
offset,
int l1_bits, c;
unsigned int index_in_cluster, nb_clusters;
uint64_t nb_available, nb_needed;
+ int ret;
index_in_cluster = (offset >> 9) & (s->cluster_sectors - 1);
nb_needed = *num + index_in_cluster;
@@ -478,9 +484,9 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t
offset,
/* load the l2 table in memory */
l2_offset &= ~QCOW_OFLAG_COPIED;
- l2_table = l2_load(bs, l2_offset);
- if (l2_table == NULL) {
- return -EIO;
+ ret = l2_load(bs, l2_offset, &l2_table);
+ if (ret < 0) {
+ return ret;
}
/* find the cluster offset for the given disk offset */
@@ -547,9 +553,9 @@ static int get_cluster_table(BlockDriverState *bs, uint64_t
offset,
if (l2_offset & QCOW_OFLAG_COPIED) {
/* load the l2 table in memory */
l2_offset &= ~QCOW_OFLAG_COPIED;
- l2_table = l2_load(bs, l2_offset);
- if (l2_table == NULL) {
- return -EIO;
+ ret = l2_load(bs, l2_offset, &l2_table);
+ if (ret < 0) {
+ return ret;
}
} else {
if (l2_offset)
--
1.6.6.1
- [Qemu-devel] [PULL 00/14] Block patches, Kevin Wolf, 2010/05/28
- [Qemu-devel] [PATCH 01/14] qcow2: Clear L2 table cache after write error, Kevin Wolf, 2010/05/28
- [Qemu-devel] [PATCH 02/14] qcow2: Fix error handling in l2_allocate, Kevin Wolf, 2010/05/28
- [Qemu-devel] [PATCH 03/14] block: Fix multiwrite with overlapping requests, Kevin Wolf, 2010/05/28
- [Qemu-devel] [PATCH 04/14] qemu-io: Add multiwrite command, Kevin Wolf, 2010/05/28
- [Qemu-devel] [PATCH 05/14] add support for protocol driver create_options, Kevin Wolf, 2010/05/28
- [Qemu-devel] [PATCH 06/14] drive: allow rerror, werror and readonly for if=none, Kevin Wolf, 2010/05/28
- [Qemu-devel] [PATCH 07/14] posix-aio-compat: Expand tabs that have crept in, Kevin Wolf, 2010/05/28
- [Qemu-devel] [PATCH 08/14] block.h: Make BDRV_SECTOR_SIZE 64 bit safe, Kevin Wolf, 2010/05/28
- [Qemu-devel] [PATCH 09/14] qcow2: Allow qcow2_get_cluster_offset to return errors, Kevin Wolf, 2010/05/28
- [Qemu-devel] [PATCH 10/14] qcow2: Change l2_load to return 0/-errno,
Kevin Wolf <=
- [Qemu-devel] [PATCH 11/14] qcow2: Return right error code in write_refcount_block_entries, Kevin Wolf, 2010/05/28
- [Qemu-devel] [PATCH 12/14] qcow2: Fix corruption after refblock allocation, Kevin Wolf, 2010/05/28
- [Qemu-devel] [PATCH 13/14] qcow2: Fix corruption after error in update_refcount, Kevin Wolf, 2010/05/28
- [Qemu-devel] [PATCH 14/14] block: Add missing bdrv_delete() for SG_IO BlockDriver in find_image_format(), Kevin Wolf, 2010/05/28
- [Qemu-devel] Re: [PULL 00/14] Block patches, Anthony Liguori, 2010/05/28