src/virtio/blk.bend checks
raw source on the hub · import 0xbf40d3526dc09381022cc668b5b4f316/src/virtio/blk.bend as Blk
6 imports
import Base import ../lib/u64.bend as U import ../lib/bytes.bend as B import ../vmm/abi.bend as V import ./queue.bend as Q import ../disk/store.bend as S
Definitions
def Blk.id source · line 33 · raw
String
def Blk.features source · line 38 · raw
@ro:Bool -> 0xbf40d3526dc09381022cc668b5b4f316/src/lib/u64.U64
The offered features: VIRTIO_F_VERSION_1 (bit 32, bit 0 of the high word), VIRTIO_BLK_F_FLUSH (bit 9) and, when ro, VIRTIO_BLK_F_RO (bit 5).
def Blk.config source · line 41 · raw
@sectors:0xbf40d3526dc09381022cc668b5b4f316/src/lib/u64.U64 -> List<&2, U32>
def Blk.max_len source · line 47 · raw
U32
The most data one request moves (16 MiB): a longer one is IOERR, the disk untouched. A guest's lengths must not size the store walk (Blk.fuel steps, a cluster at a time).
def Blk.len_ok source · line 50 · raw
@+len:U32 -> Bool
def Blk.size_max source · line 58 · raw
U32
What the device offers so that Linux never builds a request past Blk.max_len(): VIRTIO_BLK_F_SIZE_MAX (bit 1) with size_max 128 KiB per segment and VIRTIO_BLK_F_SEG_MAX (bit 2) with seg_max 128 segments (128 * 128 KiB = 16 MiB; with the header and the status, 130 descriptors fit a queue of 256).
def Blk.seg_max source · line 61 · raw
U32
def Blk.offered.go source · line 64 · raw
@f:0xbf40d3526dc09381022cc668b5b4f316/src/lib/u64.U64 -> 0xbf40d3526dc09381022cc668b5b4f316/src/lib/u64.U64
def Blk.offered source · line 70 · raw
@ro:Bool -> 0xbf40d3526dc09381022cc668b5b4f316/src/lib/u64.U64
Blk.features, plus SIZE_MAX and SEG_MAX: what the device offers.
def Blk.config_limits source · line 74 · raw
@sectors:0xbf40d3526dc09381022cc668b5b4f316/src/lib/u64.U64 -> List<&2, U32>
The config space with the limits: capacity, size_max, seg_max.
def Blk.s_ok source · line 78 · raw
U32
Status codes.
def Blk.s_ioerr source · line 81 · raw
U32
def Blk.s_unsupp source · line 84 · raw
U32
def Blk.room source · line 88 · raw
@ds:List<&2, 0xbf40d3526dc09381022cc668b5b4f316/src/virtio/queue.Desc> -> U32
The total length of a chain's writable descriptors.
def Blk.id_bytes source · line 96 · raw
List<&2, U32>
The id string, NUL-padded (or cut) to 20 bytes.
def Blk.fits.rem source · line 102 · raw
@rem:0xbf40d3526dc09381022cc668b5b4f316/src/lib/u64.U64 -> @+len:U32 -> Bool
Whether len bytes fit before the end of the disk when rem sectors remain after the start sector. Past 2^23 sectors any U32 length fits, and below it rem * 512 does not overflow a U32.
def Blk.fits source · line 108 · raw
@+sectors:0xbf40d3526dc09381022cc668b5b4f316/src/lib/u64.U64 -> @+sector:0xbf40d3526dc09381022cc668b5b4f316/src/lib/u64.U64 -> @len:U32 -> Bool
Whether the access of len bytes at sector ends within capacity sectors.
def Blk.offset source · line 112 · raw
@sector:0xbf40d3526dc09381022cc668b5b4f316/src/lib/u64.U64 -> 0xbf40d3526dc09381022cc668b5b4f316/src/lib/u64.U64
The byte offset of a sector (sector * 512).
def Blk.kind source · line 117 · raw
@+t:U32 -> Nat
The request kind of a type field: 0 IN, 1 OUT, 2 GET_ID, 3 FLUSH, 4 unsupported.
def Blk.put source · line 124 · raw
@-R:Type -> @ds:List<&2, 0xbf40d3526dc09381022cc668b5b4f316/src/virtio/queue.Desc> -> @+off:U32 -> @+b:U32 -> 0xbf40d3526dc09381022cc668b5b4f316/src/vmm/abi.Op<R, Unit>
Writes byte b at offset off of the writable area ds.
def Blk.reply source · line 135 · raw
@-R:Type -> @+w:List<&2, 0xbf40d3526dc09381022cc668b5b4f316/src/virtio/queue.Desc> -> @+room:U32 -> @res:Pair(U32, List<&2, U32>) -> 0xbf40d3526dc09381022cc668b5b4f316/src/vmm/abi.Op<R, U32>
Scatters the data (cut to the room before the status byte), then writes the status into the last writable byte. Answers the bytes written.
def Blk.fuel source · line 146 · raw
Nat
The steps a request's store walk may take: a cluster at a time (512 bytes at least) down a chain of images.
def Blk.status source · line 152 · raw
@-R:Type -> @+st:0xbf40d3526dc09381022cc668b5b4f316/src/disk/store.Store -> @done:Bool -> 0xbf40d3526dc09381022cc668b5b4f316/src/vmm/abi.Op<R, U32>
The status after the host moved a request's data: IOERR when the store refused it (done false) or a host operation on its images failed (S.Store.status: a full host disk, an I/O error), else OK.
def Blk.in source · line 158 · raw
@-R:Type -> @ok:Bool -> @+st:0xbf40d3526dc09381022cc668b5b4f316/src/disk/store.Store -> @sector:0xbf40d3526dc09381022cc668b5b4f316/src/lib/u64.U64 -> @+w:List<&2, 0xbf40d3526dc09381022cc668b5b4f316/src/virtio/queue.Desc> -> @+room:U32 -> 0xbf40d3526dc09381022cc668b5b4f316/src/vmm/abi.Op<R, U32>
IN: the room before the status byte filled from the store at sector.
def Blk.out source · line 171 · raw
@-R:Type -> @ok:Bool -> @+st:0xbf40d3526dc09381022cc668b5b4f316/src/disk/store.Store -> @sector:0xbf40d3526dc09381022cc668b5b4f316/src/lib/u64.U64 -> @ss:List<&2, 0xbf40d3526dc09381022cc668b5b4f316/src/vmm/abi.Iov> -> @+w:List<&2, 0xbf40d3526dc09381022cc668b5b4f316/src/virtio/queue.Desc> -> @+room:U32 -> 0xbf40d3526dc09381022cc668b5b4f316/src/vmm/abi.Op<R, U32>
OUT: the readable data after the header (ss) written at sector.
def Blk.out_ro source · line 182 · raw
@-R:Type -> @ro:Bool -> @st:0xbf40d3526dc09381022cc668b5b4f316/src/disk/store.Store -> @+sectors:0xbf40d3526dc09381022cc668b5b4f316/src/lib/u64.U64 -> @+sector:0xbf40d3526dc09381022cc668b5b4f316/src/lib/u64.U64 -> @+r:List<&2, 0xbf40d3526dc09381022cc668b5b4f316/src/virtio/queue.Desc> -> @+w:List<&2, 0xbf40d3526dc09381022cc668b5b4f316/src/virtio/queue.Desc> -> @+room:U32 -> 0xbf40d3526dc09381022cc668b5b4f316/src/vmm/abi.Op<R, U32>
OUT on a store that may be read-only: IOERR without writing when ro.
def Blk.flush source · line 192 · raw
@-R:Type -> @+st:0xbf40d3526dc09381022cc668b5b4f316/src/disk/store.Store -> @+w:List<&2, 0xbf40d3526dc09381022cc668b5b4f316/src/virtio/queue.Desc> -> @+room:U32 -> 0xbf40d3526dc09381022cc668b5b4f316/src/vmm/abi.Op<R, U32>
FLUSH: makes earlier writes durable.
def Blk.exec.kind source · line 198 · raw
@-R:Type -> @k:Nat -> @ro:Bool -> @st:0xbf40d3526dc09381022cc668b5b4f316/src/disk/store.Store -> @+sectors:0xbf40d3526dc09381022cc668b5b4f316/src/lib/u64.U64 -> @+sector:0xbf40d3526dc09381022cc668b5b4f316/src/lib/u64.U64 -> @+r:List<&2, 0xbf40d3526dc09381022cc668b5b4f316/src/virtio/queue.Desc> -> @+w:List<&2, 0xbf40d3526dc09381022cc668b5b4f316/src/virtio/queue.Desc> -> @+room:U32 -> 0xbf40d3526dc09381022cc668b5b4f316/src/vmm/abi.Op<R, U32>
def Blk.exec.go source · line 216 · raw
@-R:Type -> @short:Bool -> @+hdr:List<&2, U32> -> @ro:Bool -> @st:0xbf40d3526dc09381022cc668b5b4f316/src/disk/store.Store -> @sectors:0xbf40d3526dc09381022cc668b5b4f316/src/lib/u64.U64 -> @r:List<&2, 0xbf40d3526dc09381022cc668b5b4f316/src/virtio/queue.Desc> -> @+w:List<&2, 0xbf40d3526dc09381022cc668b5b4f316/src/virtio/queue.Desc> -> @+room:U32 -> 0xbf40d3526dc09381022cc668b5b4f316/src/vmm/abi.Op<R, U32>
Runs a request whose first 16 readable bytes are hdr {type, reserved, sector}; a shorter header is an IOERR.
def Blk.exec source · line 227 · raw
@-R:Type -> @+hdr:List<&2, U32> -> @ro:Bool -> @st:0xbf40d3526dc09381022cc668b5b4f316/src/disk/store.Store -> @sectors:0xbf40d3526dc09381022cc668b5b4f316/src/lib/u64.U64 -> @r:List<&2, 0xbf40d3526dc09381022cc668b5b4f316/src/virtio/queue.Desc> -> @+w:List<&2, 0xbf40d3526dc09381022cc668b5b4f316/src/virtio/queue.Desc> -> @+room:U32 -> 0xbf40d3526dc09381022cc668b5b4f316/src/vmm/abi.Op<R, U32>
def Blk.answer_chain source · line 232 · raw
@-R:Type -> @empty:Bool -> @ro:Bool -> @st:0xbf40d3526dc09381022cc668b5b4f316/src/disk/store.Store -> @sectors:0xbf40d3526dc09381022cc668b5b4f316/src/lib/u64.U64 -> @+r:List<&2, 0xbf40d3526dc09381022cc668b5b4f316/src/virtio/queue.Desc> -> @+w:List<&2, 0xbf40d3526dc09381022cc668b5b4f316/src/virtio/queue.Desc> -> @+room:U32 -> 0xbf40d3526dc09381022cc668b5b4f316/src/vmm/abi.Op<R, U32>
def Blk.serve_chain source · line 247 · raw
@-R:Type -> @ro:Bool -> @st:0xbf40d3526dc09381022cc668b5b4f316/src/disk/store.Store -> @sectors:0xbf40d3526dc09381022cc668b5b4f316/src/lib/u64.U64 -> @q:0xbf40d3526dc09381022cc668b5b4f316/src/virtio/queue.Vq -> @c:0xbf40d3526dc09381022cc668b5b4f316/src/virtio/queue.Chain -> 0xbf40d3526dc09381022cc668b5b4f316/src/vmm/abi.Op<R, 0xbf40d3526dc09381022cc668b5b4f316/src/virtio/queue.Vq>
Serves one request chain and pushes it used. A chain without a writable byte has no status to answer in: it is returned untouched, used length 0. The header is read through Bend; the data moves between the disk and the chain's memory on the host (Op.disk_to_ram, Op.ram_to_disk).
def Blk.step source · line 257 · raw
@-R:Type -> @ro:Bool -> @st:0xbf40d3526dc09381022cc668b5b4f316/src/disk/store.Store -> @sectors:0xbf40d3526dc09381022cc668b5b4f316/src/lib/u64.U64 -> @r:Pair(0xbf40d3526dc09381022cc668b5b4f316/src/virtio/queue.Vq, Maybe<&2, 0xbf40d3526dc09381022cc668b5b4f316/src/virtio/queue.Chain>) -> @used:Bool -> @k:(@_:0xbf40d3526dc09381022cc668b5b4f316/src/virtio/queue.Vq -> 0xbf40d3526dc09381022cc668b5b4f316/src/vmm/abi.Op<R, Pair(0xbf40d3526dc09381022cc668b5b4f316/src/virtio/queue.Vq, Bool)>) -> 0xbf40d3526dc09381022cc668b5b4f316/src/vmm/abi.Op<R, Pair(0xbf40d3526dc09381022cc668b5b4f316/src/virtio/queue.Vq, Bool)>
After a pop: stops on an empty queue, else serves the chain and continues with k.
def Blk.go source · line 268 · raw
@fuel:Nat -> @-R:Type -> @+ro:Bool -> @+st:0xbf40d3526dc09381022cc668b5b4f316/src/disk/store.Store -> @+sectors:0xbf40d3526dc09381022cc668b5b4f316/src/lib/u64.U64 -> @q:0xbf40d3526dc09381022cc668b5b4f316/src/virtio/queue.Vq -> @used:Bool -> 0xbf40d3526dc09381022cc668b5b4f316/src/vmm/abi.Op<R, Pair(0xbf40d3526dc09381022cc668b5b4f316/src/virtio/queue.Vq, Bool)>
Pops and serves requests, at most fuel of them; used tells whether any was.
def Blk.serve_store source · line 280 · raw
@-R:Type -> @st:0xbf40d3526dc09381022cc668b5b4f316/src/disk/store.Store -> @sectors:0xbf40d3526dc09381022cc668b5b4f316/src/lib/u64.U64 -> @ro:Bool -> @q:0xbf40d3526dc09381022cc668b5b4f316/src/virtio/queue.Vq -> 0xbf40d3526dc09381022cc668b5b4f316/src/vmm/abi.Op<R, Pair(0xbf40d3526dc09381022cc668b5b4f316/src/virtio/queue.Vq, Bool)>
Serves every available request of the queue (at most num per call) on a store (a raw image, or qcow2 over its backing files) that is read-only when ro. Answers the queue and whether any chain was used.
def Blk.serve source · line 286 · raw
@-R:Type -> @disk:U32 -> @sectors:0xbf40d3526dc09381022cc668b5b4f316/src/lib/u64.U64 -> @ro:Bool -> @q:0xbf40d3526dc09381022cc668b5b4f316/src/virtio/queue.Vq -> 0xbf40d3526dc09381022cc668b5b4f316/src/vmm/abi.Op<R, Pair(0xbf40d3526dc09381022cc668b5b4f316/src/virtio/queue.Vq, Bool)>
Blk.serve_store on a raw disk image.
def Blk.process source · line 290 · raw
@-R:Type -> @disk:U32 -> @sectors:0xbf40d3526dc09381022cc668b5b4f316/src/lib/u64.U64 -> @q:0xbf40d3526dc09381022cc668b5b4f316/src/virtio/queue.Vq -> 0xbf40d3526dc09381022cc668b5b4f316/src/vmm/abi.Op<R, Pair(0xbf40d3526dc09381022cc668b5b4f316/src/virtio/queue.Vq, Bool)>
Blk.serve on a read-write disk.