mirror of
https://github.com/xemu-project/xemu.git
synced 2024-11-24 12:09:58 +00:00
vdi: Implement .bdrv_co_preadv() interface
Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Fam Zheng <famz@redhat.com>
This commit is contained in:
parent
3edf1e73d5
commit
0865bb6f04
57
block/vdi.c
57
block/vdi.c
@ -557,48 +557,57 @@ static int64_t coroutine_fn vdi_co_get_block_status(BlockDriverState *bs,
|
||||
return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | offset;
|
||||
}
|
||||
|
||||
static int vdi_co_read(BlockDriverState *bs,
|
||||
int64_t sector_num, uint8_t *buf, int nb_sectors)
|
||||
static int coroutine_fn
|
||||
vdi_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
|
||||
QEMUIOVector *qiov, int flags)
|
||||
{
|
||||
BDRVVdiState *s = bs->opaque;
|
||||
QEMUIOVector local_qiov;
|
||||
uint32_t bmap_entry;
|
||||
uint32_t block_index;
|
||||
uint32_t sector_in_block;
|
||||
uint32_t n_sectors;
|
||||
uint32_t offset_in_block;
|
||||
uint32_t n_bytes;
|
||||
uint64_t bytes_done = 0;
|
||||
int ret = 0;
|
||||
|
||||
logout("\n");
|
||||
|
||||
while (ret >= 0 && nb_sectors > 0) {
|
||||
block_index = sector_num / s->block_sectors;
|
||||
sector_in_block = sector_num % s->block_sectors;
|
||||
n_sectors = s->block_sectors - sector_in_block;
|
||||
if (n_sectors > nb_sectors) {
|
||||
n_sectors = nb_sectors;
|
||||
}
|
||||
qemu_iovec_init(&local_qiov, qiov->niov);
|
||||
|
||||
logout("will read %u sectors starting at sector %" PRIu64 "\n",
|
||||
n_sectors, sector_num);
|
||||
while (ret >= 0 && bytes > 0) {
|
||||
block_index = offset / s->block_size;
|
||||
offset_in_block = offset % s->block_size;
|
||||
n_bytes = MIN(bytes, s->block_size - offset_in_block);
|
||||
|
||||
logout("will read %u bytes starting at offset %" PRIu64 "\n",
|
||||
n_bytes, offset);
|
||||
|
||||
/* prepare next AIO request */
|
||||
bmap_entry = le32_to_cpu(s->bmap[block_index]);
|
||||
if (!VDI_IS_ALLOCATED(bmap_entry)) {
|
||||
/* Block not allocated, return zeros, no need to wait. */
|
||||
memset(buf, 0, n_sectors * SECTOR_SIZE);
|
||||
qemu_iovec_memset(qiov, bytes_done, 0, n_bytes);
|
||||
ret = 0;
|
||||
} else {
|
||||
uint64_t offset = s->header.offset_data / SECTOR_SIZE +
|
||||
(uint64_t)bmap_entry * s->block_sectors +
|
||||
sector_in_block;
|
||||
ret = bdrv_read(bs->file->bs, offset, buf, n_sectors);
|
||||
}
|
||||
logout("%u sectors read\n", n_sectors);
|
||||
uint64_t data_offset = s->header.offset_data +
|
||||
(uint64_t)bmap_entry * s->block_size +
|
||||
offset_in_block;
|
||||
|
||||
nb_sectors -= n_sectors;
|
||||
sector_num += n_sectors;
|
||||
buf += n_sectors * SECTOR_SIZE;
|
||||
qemu_iovec_reset(&local_qiov);
|
||||
qemu_iovec_concat(&local_qiov, qiov, bytes_done, n_bytes);
|
||||
|
||||
ret = bdrv_co_preadv(bs->file->bs, data_offset, n_bytes,
|
||||
&local_qiov, 0);
|
||||
}
|
||||
logout("%u bytes read\n", n_bytes);
|
||||
|
||||
bytes -= n_bytes;
|
||||
offset += n_bytes;
|
||||
bytes_done += n_bytes;
|
||||
}
|
||||
|
||||
qemu_iovec_destroy(&local_qiov);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -903,7 +912,7 @@ static BlockDriver bdrv_vdi = {
|
||||
.bdrv_co_get_block_status = vdi_co_get_block_status,
|
||||
.bdrv_make_empty = vdi_make_empty,
|
||||
|
||||
.bdrv_read = vdi_co_read,
|
||||
.bdrv_co_preadv = vdi_co_preadv,
|
||||
#if defined(CONFIG_VDI_WRITE)
|
||||
.bdrv_write = vdi_co_write,
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user