Skip to contentSkip to conversation

scsi-disk: Factor out SCSI command emulation

PATCH In review Hannes Reinecke 2 participants 5 messages Oct 27, 2009 – Oct 28, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 3/4 scsi-disk: Factor out SCSI command emulation

Other drives might want to use SCSI command emulation without going through the SCSI disk abstraction, as this imposes too many limits on the emulation.

---
 block.c        |   15 ++
 block.h        |    3 +
 block_int.h    |    1 +
 hw/scsi-disk.c |  610 ++++++++++++++++++++++++++++++--------------------------
 hw/scsi-disk.h |    3 +
 5 files changed, 346 insertions(+), 286 deletions(-)
block.c +15 -0
index 33f3d65..06f92c4 100644
@@ -930,6 +930,21 @@ int bdrv_is_sg(BlockDriverState *bs)
     return bs->sg;
 }
 
+void bdrv_set_sg(BlockDriverState *bs, int set)
+{
+    bs->sg = set;
+}
+
+int bdrv_get_tcq(BlockDriverState *bs)
+{
+    return bs->tcq;
+}
+
+void bdrv_set_tcq(BlockDriverState *bs, int set)
+{
+    bs->tcq = set;
+}
+
 int bdrv_enable_write_cache(BlockDriverState *bs)
 {
     return bs->enable_write_cache;
block.h +3 -0
index a966afb..7862fa0 100644
@@ -134,9 +134,12 @@ void bdrv_get_geometry_hint(BlockDriverState *bs,
                             int *pcyls, int *pheads, int *psecs);
 int bdrv_get_type_hint(BlockDriverState *bs);
 int bdrv_get_translation_hint(BlockDriverState *bs);
+int bdrv_get_tcq(BlockDriverState *bs);
+void bdrv_set_tcq(BlockDriverState *bs, int set);
 int bdrv_is_removable(BlockDriverState *bs);
 int bdrv_is_read_only(BlockDriverState *bs);
 int bdrv_is_sg(BlockDriverState *bs);
+void bdrv_set_sg(BlockDriverState *bs, int set);
 int bdrv_enable_write_cache(BlockDriverState *bs);
 int bdrv_is_inserted(BlockDriverState *bs);
 int bdrv_media_changed(BlockDriverState *bs);
block_int.h +1 -0
index 8e72abe..e5ee57b 100644
@@ -129,6 +129,7 @@ struct BlockDriverState {
     int encrypted; /* if true, the media is encrypted */
     int valid_key; /* if true, a valid encryption key has been set */
     int sg;        /* if true, the device is a /dev/sg* */
+    int tcq;       /* if true, the device supports tagged command queueing */
     /* event callback when inserting/removing */
     void (*change_cb)(void *opaque);
     void *change_opaque;
hw/scsi-disk.c +324 -286

972 lines not on this page · raw message

hw/scsi-disk.h +3 -0
index 5b54272..4ac8ac6 100644
@@ -80,6 +80,9 @@ static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d)
 
 SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, DriveInfo *dinfo, int unit);
 void scsi_bus_legacy_handle_cmdline(SCSIBus *bus);
+int32_t scsi_emulate_command(BlockDriverState *bdrv,
+                             int lun, uint8_t *cdb, int datalen,
+                             uint8_t *outbuf, uint32_t *out_len);
 int32_t scsi_build_sense(uint8_t *sense_buf, uint32_t sense);
 
 #endif
Signature · 1 line
1.6.0.2
#1 lore raw
Quoted 4 lines · Hannes Reinecke

Other drives might want to use SCSI command emulation without going through the SCSI disk abstraction, as this imposes too many limits on the emulation.

Might be a good idea to move something like this first into the series and share the CDB decoder between scsi and ide (atapi) as a start. A little bit of refactoring of the CDB decoder, e.g. into one function per opcode (-family) won't hurt either.

#2 lore raw
In reply to Hannes Reinecke
Quoted 4 lines · Hannes Reinecke

Other drives might want to use SCSI command emulation without going through the SCSI disk abstraction, as this imposes too many limits on the emulation.

Might be a good idea to move something like this first into the series and share the CDB decoder between scsi and ide (atapi) as a start. A little bit of refactoring of the CDB decoder, e.g. into one function per opcode (-family) won't hurt either.

#3 lore raw

Am Wed 28 Oct 2009 09:42:47 AM CET schrieb Christoph Hellwig <[email protected]>:

Quoted 11 lines · Hannes Reinecke
Quoted 4 lines

Other drives might want to use SCSI command emulation without going through the SCSI disk abstraction, as this imposes too many limits on the emulation.

Might be a good idea to move something like this first into the series and share the CDB decoder between scsi and ide (atapi) as a start. A little bit of refactoring of the CDB decoder, e.g. into one function per opcode (-family) won't hurt either.

Yes, that was on my to-do list, as well.
Eg even the megasas already emulates REPORT LUNs, as we certainly don't want to pass the original LUN information back to the guest. And it would make sense to trap some other commands (like INQUIRY), too, to
strip it off any unwanted information.

Cheers,

Hannes
---
No .sig today as this is from my laptop.

#4 lore raw
In reply to Christoph Hellwig

Am Wed 28 Oct 2009 09:42:47 AM CET schrieb Christoph Hellwig <[email protected]>:

Quoted 11 lines · Hannes Reinecke
Quoted 4 lines

Other drives might want to use SCSI command emulation without going through the SCSI disk abstraction, as this imposes too many limits on the emulation.

Might be a good idea to move something like this first into the series and share the CDB decoder between scsi and ide (atapi) as a start. A little bit of refactoring of the CDB decoder, e.g. into one function per opcode (-family) won't hurt either.

Yes, that was on my to-do list, as well.
Eg even the megasas already emulates REPORT LUNs, as we certainly don't want to pass the original LUN information back to the guest. And it would make sense to trap some other commands (like INQUIRY), too, to strip it off any unwanted information.

Cheers,

Hannes
---
No .sig today as this is from my laptop.