block: Avoid unchecked casts for AIOCBs

Use container_of for one direction and &acb->common for the other one.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
Kevin Wolf 2010-05-05 11:44:39 +02:00
parent 7a6f391376
commit b666d23950
5 changed files with 7 additions and 6 deletions

View File

@ -2108,7 +2108,8 @@ typedef struct BlockDriverAIOCBSync {
static void bdrv_aio_cancel_em(BlockDriverAIOCB *blockacb) static void bdrv_aio_cancel_em(BlockDriverAIOCB *blockacb)
{ {
BlockDriverAIOCBSync *acb = (BlockDriverAIOCBSync *)blockacb; BlockDriverAIOCBSync *acb =
container_of(blockacb, BlockDriverAIOCBSync, common);
qemu_bh_delete(acb->bh); qemu_bh_delete(acb->bh);
acb->bh = NULL; acb->bh = NULL;
qemu_aio_release(acb); qemu_aio_release(acb);

View File

@ -320,7 +320,7 @@ static void error_callback_bh(void *opaque)
static void blkdebug_aio_cancel(BlockDriverAIOCB *blockacb) static void blkdebug_aio_cancel(BlockDriverAIOCB *blockacb)
{ {
BlkdebugAIOCB *acb = (BlkdebugAIOCB*) blockacb; BlkdebugAIOCB *acb = container_of(blockacb, BlkdebugAIOCB, common);
qemu_aio_release(acb); qemu_aio_release(acb);
} }
@ -347,7 +347,7 @@ static BlockDriverAIOCB *inject_error(BlockDriverState *bs,
acb->bh = bh; acb->bh = bh;
qemu_bh_schedule(bh); qemu_bh_schedule(bh);
return (BlockDriverAIOCB*) acb; return &acb->common;
} }
static BlockDriverAIOCB *blkdebug_aio_readv(BlockDriverState *bs, static BlockDriverAIOCB *blkdebug_aio_readv(BlockDriverState *bs,

View File

@ -502,7 +502,7 @@ typedef struct QCowAIOCB {
static void qcow_aio_cancel(BlockDriverAIOCB *blockacb) static void qcow_aio_cancel(BlockDriverAIOCB *blockacb)
{ {
QCowAIOCB *acb = (QCowAIOCB *)blockacb; QCowAIOCB *acb = container_of(blockacb, QCowAIOCB, common);
if (acb->hd_aiocb) if (acb->hd_aiocb)
bdrv_aio_cancel(acb->hd_aiocb); bdrv_aio_cancel(acb->hd_aiocb);
qemu_aio_release(acb); qemu_aio_release(acb);

View File

@ -338,7 +338,7 @@ typedef struct QCowAIOCB {
static void qcow_aio_cancel(BlockDriverAIOCB *blockacb) static void qcow_aio_cancel(BlockDriverAIOCB *blockacb)
{ {
QCowAIOCB *acb = (QCowAIOCB *)blockacb; QCowAIOCB *acb = container_of(blockacb, QCowAIOCB, common);
if (acb->hd_aiocb) if (acb->hd_aiocb)
bdrv_aio_cancel(acb->hd_aiocb); bdrv_aio_cancel(acb->hd_aiocb);
qemu_aio_release(acb); qemu_aio_release(acb);

View File

@ -469,7 +469,7 @@ static int vdi_is_allocated(BlockDriverState *bs, int64_t sector_num,
static void vdi_aio_cancel(BlockDriverAIOCB *blockacb) static void vdi_aio_cancel(BlockDriverAIOCB *blockacb)
{ {
/* TODO: This code is untested. How can I get it executed? */ /* TODO: This code is untested. How can I get it executed? */
VdiAIOCB *acb = (VdiAIOCB *)blockacb; VdiAIOCB *acb = container_of(blockacb, VdiAIOCB, common);
logout("\n"); logout("\n");
if (acb->hd_aiocb) { if (acb->hd_aiocb) {
bdrv_aio_cancel(acb->hd_aiocb); bdrv_aio_cancel(acb->hd_aiocb);