From 04ae0a59154c7cd60be5bde52d7be68914712aeb Mon Sep 17 00:00:00 2001 From: Kevin Wolf <kwolf@redhat.com> Date: Thu, 21 Jan 2010 14:03:03 -0200 Subject: [PATCH 05/10] block: Return original error codes in bdrv_pread/write_em RH-Author: Kevin Wolf <kwolf@redhat.com> Message-id: <1264082588-10273-6-git-send-email-kwolf@redhat.com> Patchwork-id: 6514 O-Subject: [RHEL-5.5 KVM PATCH 05/10] block: Return original error codes in bdrv_pread/write_em Bugzilla: 537077 RH-Acked-by: Christoph Hellwig <chellwig@redhat.com> RH-Acked-by: Juan Quintela <quintela@redhat.com> RH-Acked-by: Gleb Natapov <gleb@redhat.com> RH-Acked-by: Markus Armbruster <armbru@redhat.com> Bugzilla: 537077 Upstream status: Submitted Don't assume -EIO but return the real error. Signed-off-by: Kevin Wolf <kwolf@redhat.com> --- qemu/block.c | 34 ++++++++++++++++++---------------- 1 files changed, 18 insertions(+), 16 deletions(-) Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> --- qemu/block.c | 34 ++++++++++++++++++---------------- 1 files changed, 18 insertions(+), 16 deletions(-) diff --git a/qemu/block.c b/qemu/block.c index d596941..4fe7bc8 100644 --- a/qemu/block.c +++ b/qemu/block.c @@ -739,6 +739,7 @@ static int bdrv_pread_em(BlockDriverState *bs, int64_t offset, uint8_t tmp_buf[SECTOR_SIZE]; int len, nb_sectors, count; int64_t sector_num; + int ret; count = count1; /* first read to align to sector start */ @@ -747,8 +748,8 @@ static int bdrv_pread_em(BlockDriverState *bs, int64_t offset, len = count; sector_num = offset >> SECTOR_BITS; if (len > 0) { - if (bdrv_read(bs, sector_num, tmp_buf, 1) < 0) - return -EIO; + if ((ret = bdrv_read(bs, sector_num, tmp_buf, 1)) < 0) + return ret; memcpy(buf, tmp_buf + (offset & (SECTOR_SIZE - 1)), len); count -= len; if (count == 0) @@ -760,8 +761,8 @@ static int bdrv_pread_em(BlockDriverState *bs, int64_t offset, /* read the sectors "in place" */ nb_sectors = count >> SECTOR_BITS; if (nb_sectors > 0) { - if (bdrv_read(bs, sector_num, buf, nb_sectors) < 0) - return -EIO; + if ((ret = bdrv_read(bs, sector_num, buf, nb_sectors)) < 0) + return ret; sector_num += nb_sectors; len = nb_sectors << SECTOR_BITS; buf += len; @@ -770,8 +771,8 @@ static int bdrv_pread_em(BlockDriverState *bs, int64_t offset, /* add data from the last sector */ if (count > 0) { - if (bdrv_read(bs, sector_num, tmp_buf, 1) < 0) - return -EIO; + if ((ret = bdrv_read(bs, sector_num, tmp_buf, 1)) < 0) + return ret; memcpy(buf, tmp_buf, count); } return count1; @@ -783,6 +784,7 @@ static int bdrv_pwrite_em(BlockDriverState *bs, int64_t offset, uint8_t tmp_buf[SECTOR_SIZE]; int len, nb_sectors, count; int64_t sector_num; + int ret; count = count1; /* first write to align to sector start */ @@ -791,11 +793,11 @@ static int bdrv_pwrite_em(BlockDriverState *bs, int64_t offset, len = count; sector_num = offset >> SECTOR_BITS; if (len > 0) { - if (bdrv_read(bs, sector_num, tmp_buf, 1) < 0) - return -EIO; + if ((ret = bdrv_read(bs, sector_num, tmp_buf, 1)) < 0) + return ret; memcpy(tmp_buf + (offset & (SECTOR_SIZE - 1)), buf, len); - if (bdrv_write(bs, sector_num, tmp_buf, 1) < 0) - return -EIO; + if ((ret = bdrv_write(bs, sector_num, tmp_buf, 1)) < 0) + return ret; count -= len; if (count == 0) return count1; @@ -806,8 +808,8 @@ static int bdrv_pwrite_em(BlockDriverState *bs, int64_t offset, /* write the sectors "in place" */ nb_sectors = count >> SECTOR_BITS; if (nb_sectors > 0) { - if (bdrv_write(bs, sector_num, buf, nb_sectors) < 0) - return -EIO; + if ((ret = bdrv_write(bs, sector_num, buf, nb_sectors)) < 0) + return ret; sector_num += nb_sectors; len = nb_sectors << SECTOR_BITS; buf += len; @@ -816,11 +818,11 @@ static int bdrv_pwrite_em(BlockDriverState *bs, int64_t offset, /* add data from the last sector */ if (count > 0) { - if (bdrv_read(bs, sector_num, tmp_buf, 1) < 0) - return -EIO; + if ((ret = bdrv_read(bs, sector_num, tmp_buf, 1)) < 0) + return ret; memcpy(tmp_buf, buf, count); - if (bdrv_write(bs, sector_num, tmp_buf, 1) < 0) - return -EIO; + if ((ret = bdrv_write(bs, sector_num, tmp_buf, 1)) < 0) + return ret; } return count1; } -- 1.6.3.rc4.29.g8146