From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LWDw7-0007gu-Sd for qemu-devel@nongnu.org; Sun, 08 Feb 2009 12:59:19 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LWDw5-0007eF-Go for qemu-devel@nongnu.org; Sun, 08 Feb 2009 12:59:19 -0500 Received: from [199.232.76.173] (port=33231 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LWDw5-0007dt-4c for qemu-devel@nongnu.org; Sun, 08 Feb 2009 12:59:17 -0500 Received: from mx2.redhat.com ([66.187.237.31]:32859) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LWDw4-0008Gv-1a for qemu-devel@nongnu.org; Sun, 08 Feb 2009 12:59:16 -0500 From: Avi Kivity Date: Sun, 8 Feb 2009 19:59:06 +0200 Message-Id: <1234115947-31622-3-git-send-email-avi@redhat.com> In-Reply-To: <1234115947-31622-1-git-send-email-avi@redhat.com> References: <1234115947-31622-1-git-send-email-avi@redhat.com> Subject: [Qemu-devel] [PATCH 2/3] Add internal scsi generic block API Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori , qemu-devel@nongnu.org Add an internal API for the generic block layer to send scsi generic commands to block format driver. This means block format drivers no longer need to consider overloaded nb_sectors parameters. Signed-off-by: Avi Kivity --- block-raw-posix.c | 30 ++++++++++++++++++++++++++++++ block.c | 8 ++++---- block_int.h | 10 ++++++++++ 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/block-raw-posix.c b/block-raw-posix.c index 620791b..6b8adc4 100644 --- a/block-raw-posix.c +++ b/block-raw-posix.c @@ -1164,6 +1164,32 @@ static int raw_ioctl(BlockDriverState *bs, unsigned long int req, void *buf) } #endif /* !linux */ +static int raw_sg_send_command(BlockDriverState *bs, void *buf, int count) +{ + return raw_pwrite(bs, -1, buf, count); +} + +static int raw_sg_recv_response(BlockDriverState *bs, void *buf, int count) +{ + return raw_pread(bs, -1, buf, count); +} + +static BlockDriverAIOCB *raw_sg_aio_read(BlockDriverState *bs, + void *buf, int count, + BlockDriverCompletionFunc *cb, + void *opaque) +{ + return raw_aio_read(bs, 0, buf, -(int64_t)count, cb, opaque); +} + +static BlockDriverAIOCB *raw_sg_aio_write(BlockDriverState *bs, + void *buf, int count, + BlockDriverCompletionFunc *cb, + void *opaque) +{ + return raw_aio_write(bs, 0, buf, -(int64_t)count, cb, opaque); +} + BlockDriver bdrv_host_device = { "host_device", sizeof(BDRVRawState), @@ -1193,4 +1219,8 @@ BlockDriver bdrv_host_device = { .bdrv_set_locked = raw_set_locked, /* generic scsi device */ .bdrv_ioctl = raw_ioctl, + .bdrv_sg_send_command = raw_sg_send_command, + .bdrv_sg_recv_response = raw_sg_recv_response, + .bdrv_sg_aio_read = raw_sg_aio_read, + .bdrv_sg_aio_write = raw_sg_aio_write, }; diff --git a/block.c b/block.c index 774ac2d..4aaea09 100644 --- a/block.c +++ b/block.c @@ -1597,22 +1597,22 @@ int bdrv_ioctl(BlockDriverState *bs, unsigned long int req, void *buf) int bdrv_sg_send_command(BlockDriverState *bs, void *buf, int count) { - return bdrv_pwrite(bs, -1, buf, count); + return bs->drv->bdrv_sg_send_command(bs, buf, count); } int bdrv_sg_recv_response(BlockDriverState *bs, void *buf, int count) { - return bdrv_pread(bs, -1, buf, count); + return bs->drv->bdrv_sg_recv_response(bs, buf, count); } BlockDriverAIOCB *bdrv_sg_aio_read(BlockDriverState *bs, void *buf, int count, BlockDriverCompletionFunc *cb, void *opaque) { - return bdrv_aio_read(bs, 0, buf, -(int64_t)count, cb, opaque); + return bs->drv->bdrv_sg_aio_read(bs, buf, count, cb, opaque); } BlockDriverAIOCB *bdrv_sg_aio_write(BlockDriverState *bs, void *buf, int count, BlockDriverCompletionFunc *cb, void *opaque) { - return bdrv_aio_write(bs, 0, buf, -(int64_t)count, cb, opaque); + return bs->drv->bdrv_sg_aio_write(bs, buf, count, cb, opaque); } diff --git a/block_int.h b/block_int.h index e83fd2c..e4630f0 100644 --- a/block_int.h +++ b/block_int.h @@ -84,6 +84,16 @@ struct BlockDriver { /* to control generic scsi devices */ int (*bdrv_ioctl)(BlockDriverState *bs, unsigned long int req, void *buf); + int (*bdrv_sg_send_command)(BlockDriverState *bs, void *buf, int count); + int (*bdrv_sg_recv_response)(BlockDriverState *bs, void *buf, int count); + BlockDriverAIOCB *(*bdrv_sg_aio_read)(BlockDriverState *bs, + void *buf, int count, + BlockDriverCompletionFunc *cb, + void *opaque); + BlockDriverAIOCB *(*bdrv_sg_aio_write)(BlockDriverState *bs, + void *buf, int count, + BlockDriverCompletionFunc *cb, + void *opaque); BlockDriverAIOCB *free_aiocb; struct BlockDriver *next; -- 1.6.1.1