Note that this code is generally not running in coroutine context, so
this is an actual blocking synchronous operation. We'll fix this in a
moment.
Signed-off-by: Kevin Wolf <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Reviewed-by: Stefan Hajnoczi <[email protected]>
* This function reads qiov->size bytes starting at pos from the backing file.
* If there is no backing file then zeroes are read.
*/
* This function reads qiov->size bytes starting at pos from the backing file.
* If there is no backing file then zeroes are read.
*/
-static void qed_read_backing_file(BDRVQEDState *s, uint64_t pos,
- QEMUIOVector *qiov,
- QEMUIOVector **backing_qiov,
- BlockCompletionFunc *cb, void *opaque)
+static int qed_read_backing_file(BDRVQEDState *s, uint64_t pos,
+ QEMUIOVector *qiov,
+ QEMUIOVector **backing_qiov)
{
uint64_t backing_length = 0;
size_t size;
{
uint64_t backing_length = 0;
size_t size;
/* If there is a backing file, get its length. Treat the absence of a
* backing file like a zero length backing file.
/* If there is a backing file, get its length. Treat the absence of a
* backing file like a zero length backing file.
if (s->bs->backing) {
int64_t l = bdrv_getlength(s->bs->backing->bs);
if (l < 0) {
if (s->bs->backing) {
int64_t l = bdrv_getlength(s->bs->backing->bs);
if (l < 0) {
- cb(opaque, l);
- return;
/* Complete now if there are no backing file sectors to read */
if (pos >= backing_length) {
/* Complete now if there are no backing file sectors to read */
if (pos >= backing_length) {
- cb(opaque, 0);
- return;
}
/* If the read straddles the end of the backing file, shorten it */
}
/* If the read straddles the end of the backing file, shorten it */
qemu_iovec_concat(*backing_qiov, qiov, 0, size);
BLKDBG_EVENT(s->bs->file, BLKDBG_READ_BACKING_AIO);
qemu_iovec_concat(*backing_qiov, qiov, 0, size);
BLKDBG_EVENT(s->bs->file, BLKDBG_READ_BACKING_AIO);
- bdrv_aio_readv(s->bs->backing, pos / BDRV_SECTOR_SIZE,
- *backing_qiov, size / BDRV_SECTOR_SIZE, cb, opaque);
+ ret = bdrv_preadv(s->bs->backing, pos, *backing_qiov);
+ if (ret < 0) {
+ return ret;
+ }
+ return 0;
void *opaque)
{
CopyFromBackingFileCB *copy_cb;
void *opaque)
{
CopyFromBackingFileCB *copy_cb;
/* Skip copy entirely if there is no work to do */
if (len == 0) {
/* Skip copy entirely if there is no work to do */
if (len == 0) {
copy_cb->iov.iov_len = len;
qemu_iovec_init_external(©_cb->qiov, ©_cb->iov, 1);
copy_cb->iov.iov_len = len;
qemu_iovec_init_external(©_cb->qiov, ©_cb->iov, 1);
- qed_read_backing_file(s, pos, ©_cb->qiov, ©_cb->backing_qiov,
- qed_copy_from_backing_file_write, copy_cb);
+ ret = qed_read_backing_file(s, pos, ©_cb->qiov,
+ ©_cb->backing_qiov);
+ qed_copy_from_backing_file_write(copy_cb, ret);
qed_aio_start_io(acb);
return;
} else if (ret != QED_CLUSTER_FOUND) {
qed_aio_start_io(acb);
return;
} else if (ret != QED_CLUSTER_FOUND) {
- qed_read_backing_file(s, acb->cur_pos, &acb->cur_qiov,
- &acb->backing_qiov, qed_aio_next_io_cb, acb);
+ ret = qed_read_backing_file(s, acb->cur_pos, &acb->cur_qiov,
+ &acb->backing_qiov);
+ qed_aio_next_io(acb, ret);