mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-28 21:03:54 -06:00
dma-helpers: change BlockBackend to opaque value in DMAIOFunc
Callers of dma_blk_io have no way to pass extra data to the DMAIOFunc, because the original callback and opaque are gone by the time DMAIOFunc is called. On the other hand, the BlockBackend is usually derived from those extra data that you could pass to the DMAIOFunc (in the next patch, that would be the SCSIRequest). So change DMAIOFunc's prototype, decoupling it from blk_aio_readv and blk_aio_writev's. The new prototype loses the BlockBackend and gains an extra opaque value which, in the case of dma_blk_readv and dma_blk_writev, is of course used for the BlockBackend. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
cbe0ed6247
commit
8a8e63ebdd
5 changed files with 53 additions and 29 deletions
|
@ -70,7 +70,7 @@ void qemu_sglist_destroy(QEMUSGList *qsg)
|
|||
|
||||
typedef struct {
|
||||
BlockAIOCB common;
|
||||
BlockBackend *blk;
|
||||
AioContext *ctx;
|
||||
BlockAIOCB *acb;
|
||||
QEMUSGList *sg;
|
||||
uint64_t offset;
|
||||
|
@ -80,6 +80,7 @@ typedef struct {
|
|||
QEMUIOVector iov;
|
||||
QEMUBH *bh;
|
||||
DMAIOFunc *io_func;
|
||||
void *io_func_opaque;
|
||||
} DMAAIOCB;
|
||||
|
||||
static void dma_blk_cb(void *opaque, int ret);
|
||||
|
@ -154,8 +155,7 @@ static void dma_blk_cb(void *opaque, int ret)
|
|||
|
||||
if (dbs->iov.size == 0) {
|
||||
trace_dma_map_wait(dbs);
|
||||
dbs->bh = aio_bh_new(blk_get_aio_context(dbs->blk),
|
||||
reschedule_dma, dbs);
|
||||
dbs->bh = aio_bh_new(dbs->ctx, reschedule_dma, dbs);
|
||||
cpu_register_map_client(dbs->bh);
|
||||
return;
|
||||
}
|
||||
|
@ -164,8 +164,8 @@ static void dma_blk_cb(void *opaque, int ret)
|
|||
qemu_iovec_discard_back(&dbs->iov, dbs->iov.size & ~BDRV_SECTOR_MASK);
|
||||
}
|
||||
|
||||
dbs->acb = dbs->io_func(dbs->blk, dbs->offset, &dbs->iov, 0,
|
||||
dma_blk_cb, dbs);
|
||||
dbs->acb = dbs->io_func(dbs->offset, &dbs->iov,
|
||||
dma_blk_cb, dbs, dbs->io_func_opaque);
|
||||
assert(dbs->acb);
|
||||
}
|
||||
|
||||
|
@ -191,23 +191,25 @@ static const AIOCBInfo dma_aiocb_info = {
|
|||
.cancel_async = dma_aio_cancel,
|
||||
};
|
||||
|
||||
BlockAIOCB *dma_blk_io(
|
||||
BlockBackend *blk, QEMUSGList *sg, uint64_t offset,
|
||||
DMAIOFunc *io_func, BlockCompletionFunc *cb,
|
||||
BlockAIOCB *dma_blk_io(AioContext *ctx,
|
||||
QEMUSGList *sg, uint64_t offset,
|
||||
DMAIOFunc *io_func, void *io_func_opaque,
|
||||
BlockCompletionFunc *cb,
|
||||
void *opaque, DMADirection dir)
|
||||
{
|
||||
DMAAIOCB *dbs = blk_aio_get(&dma_aiocb_info, blk, cb, opaque);
|
||||
DMAAIOCB *dbs = qemu_aio_get(&dma_aiocb_info, NULL, cb, opaque);
|
||||
|
||||
trace_dma_blk_io(dbs, blk, offset, (dir == DMA_DIRECTION_TO_DEVICE));
|
||||
trace_dma_blk_io(dbs, io_func_opaque, offset, (dir == DMA_DIRECTION_TO_DEVICE));
|
||||
|
||||
dbs->acb = NULL;
|
||||
dbs->blk = blk;
|
||||
dbs->sg = sg;
|
||||
dbs->ctx = ctx;
|
||||
dbs->offset = offset;
|
||||
dbs->sg_cur_index = 0;
|
||||
dbs->sg_cur_byte = 0;
|
||||
dbs->dir = dir;
|
||||
dbs->io_func = io_func;
|
||||
dbs->io_func_opaque = io_func_opaque;
|
||||
dbs->bh = NULL;
|
||||
qemu_iovec_init(&dbs->iov, sg->nsg);
|
||||
dma_blk_cb(dbs, 0);
|
||||
|
@ -215,19 +217,39 @@ BlockAIOCB *dma_blk_io(
|
|||
}
|
||||
|
||||
|
||||
static
|
||||
BlockAIOCB *dma_blk_read_io_func(int64_t offset, QEMUIOVector *iov,
|
||||
BlockCompletionFunc *cb, void *cb_opaque,
|
||||
void *opaque)
|
||||
{
|
||||
BlockBackend *blk = opaque;
|
||||
return blk_aio_preadv(blk, offset, iov, 0, cb, cb_opaque);
|
||||
}
|
||||
|
||||
BlockAIOCB *dma_blk_read(BlockBackend *blk,
|
||||
QEMUSGList *sg, uint64_t offset,
|
||||
void (*cb)(void *opaque, int ret), void *opaque)
|
||||
{
|
||||
return dma_blk_io(blk, sg, offset, blk_aio_preadv, cb, opaque,
|
||||
return dma_blk_io(blk_get_aio_context(blk),
|
||||
sg, offset, dma_blk_read_io_func, blk, cb, opaque,
|
||||
DMA_DIRECTION_FROM_DEVICE);
|
||||
}
|
||||
|
||||
static
|
||||
BlockAIOCB *dma_blk_write_io_func(int64_t offset, QEMUIOVector *iov,
|
||||
BlockCompletionFunc *cb, void *cb_opaque,
|
||||
void *opaque)
|
||||
{
|
||||
BlockBackend *blk = opaque;
|
||||
return blk_aio_pwritev(blk, offset, iov, 0, cb, cb_opaque);
|
||||
}
|
||||
|
||||
BlockAIOCB *dma_blk_write(BlockBackend *blk,
|
||||
QEMUSGList *sg, uint64_t offset,
|
||||
void (*cb)(void *opaque, int ret), void *opaque)
|
||||
{
|
||||
return dma_blk_io(blk, sg, offset, blk_aio_pwritev, cb, opaque,
|
||||
return dma_blk_io(blk_get_aio_context(blk),
|
||||
sg, offset, dma_blk_write_io_func, blk, cb, opaque,
|
||||
DMA_DIRECTION_TO_DEVICE);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue