Commit 04eeb8b6d68ed314746856c813ce6fa8bc1a95df

Authored by aliguori
1 parent 7d780669

Add internal scsi generic block API (Avi Kivity)

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 <avi@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6823 c046a42c-6fe2-441c-8c8c-71466251a162
block-raw-posix.c
... ... @@ -1179,6 +1179,32 @@ static int raw_ioctl(BlockDriverState *bs, unsigned long int req, void *buf)
1179 1179 }
1180 1180 #endif /* !linux */
1181 1181  
  1182 +static int raw_sg_send_command(BlockDriverState *bs, void *buf, int count)
  1183 +{
  1184 + return raw_pwrite(bs, -1, buf, count);
  1185 +}
  1186 +
  1187 +static int raw_sg_recv_response(BlockDriverState *bs, void *buf, int count)
  1188 +{
  1189 + return raw_pread(bs, -1, buf, count);
  1190 +}
  1191 +
  1192 +static BlockDriverAIOCB *raw_sg_aio_read(BlockDriverState *bs,
  1193 + void *buf, int count,
  1194 + BlockDriverCompletionFunc *cb,
  1195 + void *opaque)
  1196 +{
  1197 + return raw_aio_read(bs, 0, buf, -(int64_t)count, cb, opaque);
  1198 +}
  1199 +
  1200 +static BlockDriverAIOCB *raw_sg_aio_write(BlockDriverState *bs,
  1201 + void *buf, int count,
  1202 + BlockDriverCompletionFunc *cb,
  1203 + void *opaque)
  1204 +{
  1205 + return raw_aio_write(bs, 0, buf, -(int64_t)count, cb, opaque);
  1206 +}
  1207 +
1182 1208 BlockDriver bdrv_host_device = {
1183 1209 .format_name = "host_device",
1184 1210 .instance_size = sizeof(BDRVRawState),
... ... @@ -1204,4 +1230,8 @@ BlockDriver bdrv_host_device = {
1204 1230 .bdrv_set_locked = raw_set_locked,
1205 1231 /* generic scsi device */
1206 1232 .bdrv_ioctl = raw_ioctl,
  1233 + .bdrv_sg_send_command = raw_sg_send_command,
  1234 + .bdrv_sg_recv_response = raw_sg_recv_response,
  1235 + .bdrv_sg_aio_read = raw_sg_aio_read,
  1236 + .bdrv_sg_aio_write = raw_sg_aio_write,
1207 1237 };
... ...
... ... @@ -1678,22 +1678,22 @@ int bdrv_ioctl(BlockDriverState *bs, unsigned long int req, void *buf)
1678 1678  
1679 1679 int bdrv_sg_send_command(BlockDriverState *bs, void *buf, int count)
1680 1680 {
1681   - return bdrv_pwrite(bs, -1, buf, count);
  1681 + return bs->drv->bdrv_sg_send_command(bs, buf, count);
1682 1682 }
1683 1683  
1684 1684 int bdrv_sg_recv_response(BlockDriverState *bs, void *buf, int count)
1685 1685 {
1686   - return bdrv_pread(bs, -1, buf, count);
  1686 + return bs->drv->bdrv_sg_recv_response(bs, buf, count);
1687 1687 }
1688 1688  
1689 1689 BlockDriverAIOCB *bdrv_sg_aio_read(BlockDriverState *bs, void *buf, int count,
1690 1690 BlockDriverCompletionFunc *cb, void *opaque)
1691 1691 {
1692   - return bdrv_aio_read(bs, 0, buf, -(int64_t)count, cb, opaque);
  1692 + return bs->drv->bdrv_sg_aio_read(bs, buf, count, cb, opaque);
1693 1693 }
1694 1694  
1695 1695 BlockDriverAIOCB *bdrv_sg_aio_write(BlockDriverState *bs, void *buf, int count,
1696 1696 BlockDriverCompletionFunc *cb, void *opaque)
1697 1697 {
1698   - return bdrv_aio_write(bs, 0, buf, -(int64_t)count, cb, opaque);
  1698 + return bs->drv->bdrv_sg_aio_write(bs, buf, count, cb, opaque);
1699 1699 }
... ...
block_int.h
... ... @@ -84,6 +84,16 @@ struct BlockDriver {
84 84  
85 85 /* to control generic scsi devices */
86 86 int (*bdrv_ioctl)(BlockDriverState *bs, unsigned long int req, void *buf);
  87 + int (*bdrv_sg_send_command)(BlockDriverState *bs, void *buf, int count);
  88 + int (*bdrv_sg_recv_response)(BlockDriverState *bs, void *buf, int count);
  89 + BlockDriverAIOCB *(*bdrv_sg_aio_read)(BlockDriverState *bs,
  90 + void *buf, int count,
  91 + BlockDriverCompletionFunc *cb,
  92 + void *opaque);
  93 + BlockDriverAIOCB *(*bdrv_sg_aio_write)(BlockDriverState *bs,
  94 + void *buf, int count,
  95 + BlockDriverCompletionFunc *cb,
  96 + void *opaque);
87 97  
88 98 BlockDriverAIOCB *free_aiocb;
89 99 struct BlockDriver *next;
... ...