|
| 1 | +# vhost-user-scsi architecture |
| 2 | + |
| 3 | +Rough outline of the different pieces and how they fit together: |
| 4 | + |
| 5 | +## `scsi/mod.rs` |
| 6 | + |
| 7 | +This defines the `Target` trait, which represents a SCSI target. The code in |
| 8 | +this file is independent from: |
| 9 | + |
| 10 | +- A particular SCSI implementation: Currently, we have one implementation of |
| 11 | + `Target`, which emulates the SCSI commands itself; but future implementations |
| 12 | + could provide pass-through to an iSCSI target or SCSI devices attached to the |
| 13 | + host. |
| 14 | +- A particular SCSI transport: Nothing in `src/scsi/*` knows anything about |
| 15 | + virtio; this is helpful for maintainability, and also allows our SCSI |
| 16 | + emulation code to be reusable as, for example, an iSCSI target. To this end, |
| 17 | + the `Target` trait is generic over a `Read` and `Write` that it uses for SCSI |
| 18 | + data transfer. This makes testing easy: we can just provide a `Vec<u8>` to |
| 19 | + write into. |
| 20 | + |
| 21 | +## `scsi/emulation/*.rs` |
| 22 | + |
| 23 | +This is the SCSI emulation code, which forms the bulk of the crate. It provides |
| 24 | +`EmulatedTarget`, an implementation of `Target`. `EmulatedTarget`, in turn, |
| 25 | +looks at the LUN and delegates commands to an implementation of `LogicalUnit`. |
| 26 | +In most cases, this will be `BlockDevice`; there's also `MissingLun`, which is |
| 27 | +used for responding to commands to invalid LUNs. |
| 28 | + |
| 29 | +Currently, there is no separation between commands defined in the SPC standard |
| 30 | +(commands shared by all device types) and the SBC standard (block-device |
| 31 | +specific commands). If we ever implemented another device type (CD/DVD seems |
| 32 | +most likely), we'd want to separate those out. |
| 33 | + |
| 34 | +As noted above, the emulation code knows nothing about virtio. |
| 35 | + |
| 36 | +## `src/{main,virtio}.rs` |
| 37 | + |
| 38 | +This code handles vhost-user, virtio, and virtio-scsi; it's the only part of |
| 39 | +the crate that knows about these protocols. |
0 commit comments