提交 537a1d4b 编写于 作者: A aliguori

Fix regression introduced by r6824

The changes introduced by r6824 broke a subtle, and admittedly obscure, aspect
of the block API.  While bdrv_{pread,pwrite} return the number of bytes read
or written upon success, bdrv_{read,write} returns a zero upon success.

When using bdrv_pread for bdrv_read, special care must be taken to handle this
case.

This fixes certain guest images (notably linux-0.2 provided on the qemu
website).
Reported-by: Nmalc <av1474@comtv.ru>
Reported-by: NHerve Poussineau <hpoussin@reactos.org>
Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6828 c046a42c-6fe2-441c-8c8c-71466251a162
上级 610626af
......@@ -361,7 +361,12 @@ static int raw_pread(BlockDriverState *bs, int64_t offset,
static int raw_read(BlockDriverState *bs, int64_t sector_num,
uint8_t *buf, int nb_sectors)
{
return raw_pread(bs, sector_num * 512, buf, (uint64_t)nb_sectors * 512);
int ret;
ret = raw_pread(bs, sector_num * 512, buf, nb_sectors * 512);
if (ret == (nb_sectors * 512))
ret = 0;
return ret;
}
/*
......@@ -445,7 +450,11 @@ static int raw_pwrite(BlockDriverState *bs, int64_t offset,
static int raw_write(BlockDriverState *bs, int64_t sector_num,
const uint8_t *buf, int nb_sectors)
{
return raw_pwrite(bs, sector_num * 512, buf, (uint64_t)nb_sectors * 512);
int ret;
ret = raw_pwrite(bs, sector_num * 512, buf, nb_sectors * 512);
if (ret == (nb_sectors * 512))
ret = 0;
return ret;
}
#ifdef CONFIG_AIO
......
......@@ -145,6 +145,8 @@ static int raw_read(BlockDriverState *bs, int64_t sector_num,
#endif
return ret_count;
}
if (ret_count == count)
ret_count = 0;
return ret_count;
}
......@@ -171,6 +173,8 @@ static int raw_write(BlockDriverState *bs, int64_t sector_num,
#endif
return ret_count;
}
if (ret_count == count)
ret_count = 0;
return ret_count;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册