mirror of https://github.com/xemu-project/xemu.git
block/io: refactor coroutine wrappers
Most of our coroutine wrappers already follow this convention: We have 'coroutine_fn bdrv_co_<something>(<normal argument list>)' as the core function, and a wrapper 'bdrv_<something>(<same argument list>)' which does parameter packing and calls bdrv_run_co(). The only outsiders are the bdrv_prwv_co and bdrv_common_block_status_above wrappers. Let's refactor them to behave as the others, it simplifies further conversion of coroutine wrappers. This patch adds an indirection layer, but it will be compensated by a further commit, which will drop bdrv_co_prwv together with the is_write logic, to keep the read and write paths separate. Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Message-Id: <20200924185414.28642-3-vsementsov@virtuozzo.com>
This commit is contained in:
parent
5416645fcf
commit
f9e694cb32
60
block/io.c
60
block/io.c
|
@ -933,27 +933,31 @@ typedef struct RwCo {
|
||||||
BdrvRequestFlags flags;
|
BdrvRequestFlags flags;
|
||||||
} RwCo;
|
} RwCo;
|
||||||
|
|
||||||
|
static int coroutine_fn bdrv_co_prwv(BdrvChild *child, int64_t offset,
|
||||||
|
QEMUIOVector *qiov, bool is_write,
|
||||||
|
BdrvRequestFlags flags)
|
||||||
|
{
|
||||||
|
if (is_write) {
|
||||||
|
return bdrv_co_pwritev(child, offset, qiov->size, qiov, flags);
|
||||||
|
} else {
|
||||||
|
return bdrv_co_preadv(child, offset, qiov->size, qiov, flags);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int coroutine_fn bdrv_rw_co_entry(void *opaque)
|
static int coroutine_fn bdrv_rw_co_entry(void *opaque)
|
||||||
{
|
{
|
||||||
RwCo *rwco = opaque;
|
RwCo *rwco = opaque;
|
||||||
|
|
||||||
if (!rwco->is_write) {
|
return bdrv_co_prwv(rwco->child, rwco->offset, rwco->qiov,
|
||||||
return bdrv_co_preadv(rwco->child, rwco->offset,
|
rwco->is_write, rwco->flags);
|
||||||
rwco->qiov->size, rwco->qiov,
|
|
||||||
rwco->flags);
|
|
||||||
} else {
|
|
||||||
return bdrv_co_pwritev(rwco->child, rwco->offset,
|
|
||||||
rwco->qiov->size, rwco->qiov,
|
|
||||||
rwco->flags);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Process a vectored synchronous request using coroutines
|
* Process a vectored synchronous request using coroutines
|
||||||
*/
|
*/
|
||||||
static int bdrv_prwv_co(BdrvChild *child, int64_t offset,
|
static int bdrv_prwv(BdrvChild *child, int64_t offset,
|
||||||
QEMUIOVector *qiov, bool is_write,
|
QEMUIOVector *qiov, bool is_write,
|
||||||
BdrvRequestFlags flags)
|
BdrvRequestFlags flags)
|
||||||
{
|
{
|
||||||
RwCo rwco = {
|
RwCo rwco = {
|
||||||
.child = child,
|
.child = child,
|
||||||
|
@ -971,8 +975,7 @@ int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset,
|
||||||
{
|
{
|
||||||
QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, NULL, bytes);
|
QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, NULL, bytes);
|
||||||
|
|
||||||
return bdrv_prwv_co(child, offset, &qiov, true,
|
return bdrv_prwv(child, offset, &qiov, true, BDRV_REQ_ZERO_WRITE | flags);
|
||||||
BDRV_REQ_ZERO_WRITE | flags);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1021,7 +1024,7 @@ int bdrv_preadv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = bdrv_prwv_co(child, offset, qiov, false, 0);
|
ret = bdrv_prwv(child, offset, qiov, false, 0);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -1045,7 +1048,7 @@ int bdrv_pwritev(BdrvChild *child, int64_t offset, QEMUIOVector *qiov)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = bdrv_prwv_co(child, offset, qiov, true, 0);
|
ret = bdrv_prwv(child, offset, qiov, true, 0);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -2449,14 +2452,15 @@ early_out:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int coroutine_fn bdrv_co_block_status_above(BlockDriverState *bs,
|
static int coroutine_fn
|
||||||
BlockDriverState *base,
|
bdrv_co_common_block_status_above(BlockDriverState *bs,
|
||||||
bool want_zero,
|
BlockDriverState *base,
|
||||||
int64_t offset,
|
bool want_zero,
|
||||||
int64_t bytes,
|
int64_t offset,
|
||||||
int64_t *pnum,
|
int64_t bytes,
|
||||||
int64_t *map,
|
int64_t *pnum,
|
||||||
BlockDriverState **file)
|
int64_t *map,
|
||||||
|
BlockDriverState **file)
|
||||||
{
|
{
|
||||||
BlockDriverState *p;
|
BlockDriverState *p;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
@ -2494,10 +2498,10 @@ static int coroutine_fn bdrv_block_status_above_co_entry(void *opaque)
|
||||||
{
|
{
|
||||||
BdrvCoBlockStatusData *data = opaque;
|
BdrvCoBlockStatusData *data = opaque;
|
||||||
|
|
||||||
return bdrv_co_block_status_above(data->bs, data->base,
|
return bdrv_co_common_block_status_above(data->bs, data->base,
|
||||||
data->want_zero,
|
data->want_zero,
|
||||||
data->offset, data->bytes,
|
data->offset, data->bytes,
|
||||||
data->pnum, data->map, data->file);
|
data->pnum, data->map, data->file);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue