Skip to content

Commit

Permalink
block: Introduce bdrv_preadv()
Browse files Browse the repository at this point in the history
We already have a byte-based bdrv_pwritev(), but the read counterpart
was still missing. This commit adds it.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
  • Loading branch information
kevmw committed Jun 16, 2016
1 parent 48bea96 commit f1e8474
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
20 changes: 13 additions & 7 deletions block/io.c
Expand Up @@ -700,26 +700,32 @@ int bdrv_make_zero(BlockDriverState *bs, BdrvRequestFlags flags)
}
}

int bdrv_preadv(BlockDriverState *bs, int64_t offset, QEMUIOVector *qiov)
{
int ret;

ret = bdrv_prwv_co(bs, offset, qiov, false, 0);
if (ret < 0) {
return ret;
}

return qiov->size;
}

int bdrv_pread(BlockDriverState *bs, int64_t offset, void *buf, int bytes)
{
QEMUIOVector qiov;
struct iovec iov = {
.iov_base = (void *)buf,
.iov_len = bytes,
};
int ret;

if (bytes < 0) {
return -EINVAL;
}

qemu_iovec_init_external(&qiov, &iov, 1);
ret = bdrv_prwv_co(bs, offset, &qiov, false, 0);
if (ret < 0) {
return ret;
}

return bytes;
return bdrv_preadv(bs, offset, &qiov);
}

int bdrv_pwritev(BlockDriverState *bs, int64_t offset, QEMUIOVector *qiov)
Expand Down
1 change: 1 addition & 0 deletions include/block/block.h
Expand Up @@ -235,6 +235,7 @@ int bdrv_pwrite_zeroes(BlockDriverState *bs, int64_t offset,
int bdrv_make_zero(BlockDriverState *bs, BdrvRequestFlags flags);
int bdrv_pread(BlockDriverState *bs, int64_t offset,
void *buf, int count);
int bdrv_preadv(BlockDriverState *bs, int64_t offset, QEMUIOVector *qiov);
int bdrv_pwrite(BlockDriverState *bs, int64_t offset,
const void *buf, int count);
int bdrv_pwritev(BlockDriverState *bs, int64_t offset, QEMUIOVector *qiov);
Expand Down

0 comments on commit f1e8474

Please sign in to comment.