Skip to content

Commit

Permalink
Add internal scsi generic block API (Avi Kivity)
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Anthony Liguori <[email protected]>


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6823 c046a42c-6fe2-441c-8c8c-71466251a162
  • Loading branch information
aliguori committed Mar 12, 2009
1 parent 7d78066 commit 04eeb8b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
30 changes: 30 additions & 0 deletions block-raw-posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,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 = {
.format_name = "host_device",
.instance_size = sizeof(BDRVRawState),
Expand All @@ -1204,4 +1230,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,
};
8 changes: 4 additions & 4 deletions block.c
Original file line number Diff line number Diff line change
Expand Up @@ -1678,22 +1678,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);
}
10 changes: 10 additions & 0 deletions block_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 04eeb8b

Please sign in to comment.