From 4faca8b80576e0747a01328e64acead8f4bb26d5 Mon Sep 17 00:00:00 2001 From: Kevin Wolf <kwolf@redhat.com> Date: Fri, 18 Jun 2010 15:22:26 -0300 Subject: [PATCH 08/18] qcow2: Change l2_load to return 0/-errno RH-Author: Kevin Wolf <kwolf@redhat.com> Message-id: <patch-9983-clone-for-rhel55-rhel55> Patchwork-id: 10057 O-Subject: [RHEL-5.6 KVM PATCH 08/16] qcow2: Change l2_load to return 0/-errno Bugzilla: 612508 RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com> RH-Acked-by: Juan Quintela <quintela@redhat.com> RH-Acked-by: Christoph Hellwig <chellwig@redhat.com> RH-Acked-by: Jes Sorensen <Jes.Sorensen@redhat.com> Bugzilla: 605701 Upstream commit: 55c17e9821c474d5fcdebdc82ed2fc096777d611 Provide the error code to the caller instead of just indicating success/error. Signed-off-by: Kevin Wolf <kwolf@redhat.com> --- qemu/block-qcow2.c | 38 ++++++++++++++++++++++---------------- 1 files changed, 22 insertions(+), 16 deletions(-) Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> --- qemu/block-qcow2.c | 38 ++++++++++++++++++++++---------------- 1 files changed, 22 insertions(+), 16 deletions(-) diff --git a/qemu/block-qcow2.c b/qemu/block-qcow2.c index ced586b..1a9a98d 100644 --- a/qemu/block-qcow2.c +++ b/qemu/block-qcow2.c @@ -632,29 +632,34 @@ 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); - if (bdrv_pread(s->hd, l2_offset, l2_table, s->l2_size * sizeof(uint64_t)) != - s->l2_size * sizeof(uint64_t)) - return NULL; + *l2_table = s->l2_cache + (min_index << s->l2_bits); + ret = bdrv_pread(s->hd, 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; } /* @@ -805,6 +810,7 @@ static int get_cluster_offset(BlockDriverState *bs, uint64_t offset, uint64_t l2_offset, *l2_table; int l1_bits, c; int index_in_cluster, nb_available, nb_needed, nb_clusters; + int ret; index_in_cluster = (offset >> 9) & (s->cluster_sectors - 1); nb_needed = *num + index_in_cluster; @@ -843,9 +849,9 @@ static int 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 */ @@ -939,9 +945,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.7.0.3