From e382e70b8284b557265f889f11cc82bf716ebd90 Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Tue, 14 Feb 2012 11:14:08 +0100 Subject: [PATCH 43/99] block: Avoid unchecked casts for AIOCBs RH-Author: Kevin Wolf Message-id: <1329218101-24213-44-git-send-email-kwolf@redhat.com> Patchwork-id: 37240 O-Subject: [RHEL-6.3 qemu-kvm PATCH v2 43/96] block: Avoid unchecked casts for AIOCBs Bugzilla: 783950 RH-Acked-by: Paolo Bonzini RH-Acked-by: Marcelo Tosatti RH-Acked-by: Laszlo Ersek Bugzilla: 783950 Use container_of for one direction and &acb->common for the other one. Signed-off-by: Kevin Wolf (cherry picked from commit b666d239509a0855740444c254a65cbf567bfb90) --- block.c | 3 ++- block/blkdebug.c | 4 ++-- block/qcow.c | 2 +- block/qcow2.c | 2 +- block/vdi.c | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) Signed-off-by: Michal Novotny --- block.c | 3 ++- block/blkdebug.c | 4 ++-- block/qcow.c | 2 +- block/qcow2.c | 2 +- block/vdi.c | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/block.c b/block.c index 8fb2bc7..270ab41 100644 --- a/block.c +++ b/block.c @@ -2505,7 +2505,8 @@ typedef struct BlockDriverAIOCBSync { static void bdrv_aio_cancel_em(BlockDriverAIOCB *blockacb) { - BlockDriverAIOCBSync *acb = (BlockDriverAIOCBSync *)blockacb; + BlockDriverAIOCBSync *acb = + container_of(blockacb, BlockDriverAIOCBSync, common); qemu_bh_delete(acb->bh); acb->bh = NULL; qemu_aio_release(acb); diff --git a/block/blkdebug.c b/block/blkdebug.c index e36cd9e..ac6c36d 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -318,7 +318,7 @@ static void error_callback_bh(void *opaque) static void blkdebug_aio_cancel(BlockDriverAIOCB *blockacb) { - BlkdebugAIOCB *acb = (BlkdebugAIOCB*) blockacb; + BlkdebugAIOCB *acb = container_of(blockacb, BlkdebugAIOCB, common); qemu_aio_release(acb); } @@ -345,7 +345,7 @@ static BlockDriverAIOCB *inject_error(BlockDriverState *bs, acb->bh = bh; qemu_bh_schedule(bh); - return (BlockDriverAIOCB*) acb; + return &acb->common; } static BlockDriverAIOCB *blkdebug_aio_readv(BlockDriverState *bs, diff --git a/block/qcow.c b/block/qcow.c index 309c56e..0d69794 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -501,7 +501,7 @@ typedef struct QCowAIOCB { static void qcow_aio_cancel(BlockDriverAIOCB *blockacb) { - QCowAIOCB *acb = (QCowAIOCB *)blockacb; + QCowAIOCB *acb = container_of(blockacb, QCowAIOCB, common); if (acb->hd_aiocb) bdrv_aio_cancel(acb->hd_aiocb); qemu_aio_release(acb); diff --git a/block/qcow2.c b/block/qcow2.c index c9dfb6b..e672e2c 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -390,7 +390,7 @@ typedef struct QCowAIOCB { static void qcow2_aio_cancel(BlockDriverAIOCB *blockacb) { - QCowAIOCB *acb = (QCowAIOCB *)blockacb; + QCowAIOCB *acb = container_of(blockacb, QCowAIOCB, common); if (acb->hd_aiocb) bdrv_aio_cancel(acb->hd_aiocb); qemu_aio_release(acb); diff --git a/block/vdi.c b/block/vdi.c index 812fdfc..3b1d195 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -466,7 +466,7 @@ static int vdi_is_allocated(BlockDriverState *bs, int64_t sector_num, static void vdi_aio_cancel(BlockDriverAIOCB *blockacb) { /* TODO: This code is untested. How can I get it executed? */ - VdiAIOCB *acb = (VdiAIOCB *)blockacb; + VdiAIOCB *acb = container_of(blockacb, VdiAIOCB, common); logout("\n"); if (acb->hd_aiocb) { bdrv_aio_cancel(acb->hd_aiocb); -- 1.7.7.5