mirror of https://github.com/xemu-project/xemu.git
block: Return original error codes in bdrv_pread/write
Don't assume -EIO but return the real error. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
148da7ea9d
commit
9a8c4cceaf
34
block.c
34
block.c
|
@ -717,6 +717,7 @@ int bdrv_pread(BlockDriverState *bs, int64_t offset,
|
||||||
uint8_t tmp_buf[BDRV_SECTOR_SIZE];
|
uint8_t tmp_buf[BDRV_SECTOR_SIZE];
|
||||||
int len, nb_sectors, count;
|
int len, nb_sectors, count;
|
||||||
int64_t sector_num;
|
int64_t sector_num;
|
||||||
|
int ret;
|
||||||
|
|
||||||
count = count1;
|
count = count1;
|
||||||
/* first read to align to sector start */
|
/* first read to align to sector start */
|
||||||
|
@ -725,8 +726,8 @@ int bdrv_pread(BlockDriverState *bs, int64_t offset,
|
||||||
len = count;
|
len = count;
|
||||||
sector_num = offset >> BDRV_SECTOR_BITS;
|
sector_num = offset >> BDRV_SECTOR_BITS;
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
if (bdrv_read(bs, sector_num, tmp_buf, 1) < 0)
|
if ((ret = bdrv_read(bs, sector_num, tmp_buf, 1)) < 0)
|
||||||
return -EIO;
|
return ret;
|
||||||
memcpy(buf, tmp_buf + (offset & (BDRV_SECTOR_SIZE - 1)), len);
|
memcpy(buf, tmp_buf + (offset & (BDRV_SECTOR_SIZE - 1)), len);
|
||||||
count -= len;
|
count -= len;
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
|
@ -738,8 +739,8 @@ int bdrv_pread(BlockDriverState *bs, int64_t offset,
|
||||||
/* read the sectors "in place" */
|
/* read the sectors "in place" */
|
||||||
nb_sectors = count >> BDRV_SECTOR_BITS;
|
nb_sectors = count >> BDRV_SECTOR_BITS;
|
||||||
if (nb_sectors > 0) {
|
if (nb_sectors > 0) {
|
||||||
if (bdrv_read(bs, sector_num, buf, nb_sectors) < 0)
|
if ((ret = bdrv_read(bs, sector_num, buf, nb_sectors)) < 0)
|
||||||
return -EIO;
|
return ret;
|
||||||
sector_num += nb_sectors;
|
sector_num += nb_sectors;
|
||||||
len = nb_sectors << BDRV_SECTOR_BITS;
|
len = nb_sectors << BDRV_SECTOR_BITS;
|
||||||
buf += len;
|
buf += len;
|
||||||
|
@ -748,8 +749,8 @@ int bdrv_pread(BlockDriverState *bs, int64_t offset,
|
||||||
|
|
||||||
/* add data from the last sector */
|
/* add data from the last sector */
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
if (bdrv_read(bs, sector_num, tmp_buf, 1) < 0)
|
if ((ret = bdrv_read(bs, sector_num, tmp_buf, 1)) < 0)
|
||||||
return -EIO;
|
return ret;
|
||||||
memcpy(buf, tmp_buf, count);
|
memcpy(buf, tmp_buf, count);
|
||||||
}
|
}
|
||||||
return count1;
|
return count1;
|
||||||
|
@ -761,6 +762,7 @@ int bdrv_pwrite(BlockDriverState *bs, int64_t offset,
|
||||||
uint8_t tmp_buf[BDRV_SECTOR_SIZE];
|
uint8_t tmp_buf[BDRV_SECTOR_SIZE];
|
||||||
int len, nb_sectors, count;
|
int len, nb_sectors, count;
|
||||||
int64_t sector_num;
|
int64_t sector_num;
|
||||||
|
int ret;
|
||||||
|
|
||||||
count = count1;
|
count = count1;
|
||||||
/* first write to align to sector start */
|
/* first write to align to sector start */
|
||||||
|
@ -769,11 +771,11 @@ int bdrv_pwrite(BlockDriverState *bs, int64_t offset,
|
||||||
len = count;
|
len = count;
|
||||||
sector_num = offset >> BDRV_SECTOR_BITS;
|
sector_num = offset >> BDRV_SECTOR_BITS;
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
if (bdrv_read(bs, sector_num, tmp_buf, 1) < 0)
|
if ((ret = bdrv_read(bs, sector_num, tmp_buf, 1)) < 0)
|
||||||
return -EIO;
|
return ret;
|
||||||
memcpy(tmp_buf + (offset & (BDRV_SECTOR_SIZE - 1)), buf, len);
|
memcpy(tmp_buf + (offset & (BDRV_SECTOR_SIZE - 1)), buf, len);
|
||||||
if (bdrv_write(bs, sector_num, tmp_buf, 1) < 0)
|
if ((ret = bdrv_write(bs, sector_num, tmp_buf, 1)) < 0)
|
||||||
return -EIO;
|
return ret;
|
||||||
count -= len;
|
count -= len;
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
return count1;
|
return count1;
|
||||||
|
@ -784,8 +786,8 @@ int bdrv_pwrite(BlockDriverState *bs, int64_t offset,
|
||||||
/* write the sectors "in place" */
|
/* write the sectors "in place" */
|
||||||
nb_sectors = count >> BDRV_SECTOR_BITS;
|
nb_sectors = count >> BDRV_SECTOR_BITS;
|
||||||
if (nb_sectors > 0) {
|
if (nb_sectors > 0) {
|
||||||
if (bdrv_write(bs, sector_num, buf, nb_sectors) < 0)
|
if ((ret = bdrv_write(bs, sector_num, buf, nb_sectors)) < 0)
|
||||||
return -EIO;
|
return ret;
|
||||||
sector_num += nb_sectors;
|
sector_num += nb_sectors;
|
||||||
len = nb_sectors << BDRV_SECTOR_BITS;
|
len = nb_sectors << BDRV_SECTOR_BITS;
|
||||||
buf += len;
|
buf += len;
|
||||||
|
@ -794,11 +796,11 @@ int bdrv_pwrite(BlockDriverState *bs, int64_t offset,
|
||||||
|
|
||||||
/* add data from the last sector */
|
/* add data from the last sector */
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
if (bdrv_read(bs, sector_num, tmp_buf, 1) < 0)
|
if ((ret = bdrv_read(bs, sector_num, tmp_buf, 1)) < 0)
|
||||||
return -EIO;
|
return ret;
|
||||||
memcpy(tmp_buf, buf, count);
|
memcpy(tmp_buf, buf, count);
|
||||||
if (bdrv_write(bs, sector_num, tmp_buf, 1) < 0)
|
if ((ret = bdrv_write(bs, sector_num, tmp_buf, 1)) < 0)
|
||||||
return -EIO;
|
return ret;
|
||||||
}
|
}
|
||||||
return count1;
|
return count1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue