Skip to content

Commit 4c0b8b7

Browse files
GaelanErik Schilling
authored and
Erik Schilling
committed
scsi: Add documentation
Co-developed-by: Erik Schilling <[email protected]> Signed-off-by: Erik Schilling <[email protected]> Signed-off-by: Gaelan Steele <[email protected]>
1 parent e1ff858 commit 4c0b8b7

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

crates/scsi/ARCHITECTURE.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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.

crates/scsi/README.md

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# vhost-user-scsi
2+
3+
This is a Rust implementation of a vhost-user-scsi daemon.
4+
5+
## Usage
6+
7+
Run the vhost-user-scsi daemon:
8+
9+
```
10+
vhost-user-scsi -r /tmp/vhost-user-scsi.sock /path/to/image.raw /path/to/second-image.raw ...
11+
```
12+
13+
Run QEMU:
14+
15+
```
16+
qemu-system-x86_64 ... \
17+
-device vhost-user-scsi-pci,num_queues=1,param_change=off,chardev=vus \
18+
-chardev socket,id=vus,path=/tmp/vhost-user-scsi.sock \
19+
# must match total guest meory
20+
-object memory-backend-memfd,id=mem,size=384M,share=on \
21+
-numa node,memdev=mem
22+
```
23+
24+
## Features
25+
26+
This crate is a work-in-progress. Currently, it's possible to mount and read
27+
up to 256 read-only raw disk images. Some features we might like to add
28+
at some point, roughly ordered from sooner to later:
29+
30+
- Write support. This should just be a matter of implementing the WRITE
31+
command, but there's a bit of complexity around writeback caching we
32+
need to make sure we get right.
33+
- Support more LUNs. virtio-scsi supports up to 16384 LUNs per target.
34+
After 256, the LUN encoding format is different; it's nothing too
35+
complicated, but I haven't gotten around to implementing it.
36+
- Concurrency. Currently, we process SCSI commands one at a time. Eventually,
37+
it'd be a good idea to use threads or some fancy async/io_uring stuff to
38+
concurrently handle multiple commands. virtio-scsi also allows for multiple
39+
request queues, allowing the guest to sumbit requests from multiple cores
40+
in parallel; we should support that.
41+
- iSCSI passthrough. This shouldn't be too bad, but it might be a good idea
42+
decide on a concurrency model (threads or async) before we spend too much
43+
time here.

0 commit comments

Comments
 (0)