~/bend-docscommunity

src/virtio/blk.bend checks

raw source on the hub · import 0x81011db9256231154e908712080eb16d/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

Types

type Dseg source · line 152 · raw

Data

Definitions

def Blk.id source · line 33 · raw

String

def Blk.features source · line 38 · raw

@ro:Bool -> 0x81011db9256231154e908712080eb16d/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:0x81011db9256231154e908712080eb16d/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:0x81011db9256231154e908712080eb16d/src/lib/u64.U64 -> 0x81011db9256231154e908712080eb16d/src/lib/u64.U64

def Blk.offered source · line 70 · raw

@ro:Bool -> 0x81011db9256231154e908712080eb16d/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:0x81011db9256231154e908712080eb16d/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, 0x81011db9256231154e908712080eb16d/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:0x81011db9256231154e908712080eb16d/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:0x81011db9256231154e908712080eb16d/src/lib/u64.U64 -> @+sector:0x81011db9256231154e908712080eb16d/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:0x81011db9256231154e908712080eb16d/src/lib/u64.U64 -> 0x81011db9256231154e908712080eb16d/src/lib/u64.U64

The byte offset of a sector (sector * 512).

def Blk.discard_max_sectors source · line 128 · raw

U32

Discard (VIRTIO_BLK_F_DISCARD, bit 13), offered for a writable disk: the guest names sectors it no longer needs and the host frees them (a hole in a raw image: they then read as zeros; whole qcow2 clusters that are the image's alone, src/disk/store.bend). One request holds 1 to discard_max_seg segments of 16 bytes {sector u64, num_sectors u32, flags u32}; a segment covers at most discard_max_sectors (2 GiB); flags other than UNMAP (bit 0) answer UNSUPP, a segment past the end IOERR. The host frees whole 4 KiB blocks (discard_align sectors) inside each segment: a partial block stays. Config: after capacity, size_max and seg_max, geometry, blk_size, topology, writeback and num_queues are 0 (their features are not offered), then max_discard_sectors, max_discard_seg and discard_sector_alignment (offsets 36, 40, 44).

def Blk.discard_max_seg source · line 131 · raw

U32

def Blk.discard_align source · line 134 · raw

U32

def Blk.offered_dis.go source · line 137 · raw

@ro:Bool -> @f:0x81011db9256231154e908712080eb16d/src/lib/u64.U64 -> 0x81011db9256231154e908712080eb16d/src/lib/u64.U64

def Blk.offered_dis source · line 145 · raw

@+ro:Bool -> 0x81011db9256231154e908712080eb16d/src/lib/u64.U64

What the device offers: Blk.offered, plus DISCARD when writable.

def Blk.config_dis source · line 148 · raw

@sectors:0x81011db9256231154e908712080eb16d/src/lib/u64.U64 -> List<&2, U32>

def Blk.dis.segs source · line 156 · raw

@fuel:Nat -> @bs:List<&2, U32> -> List<&2, Dseg>

The segments of a discard request's data (16 bytes each).

def Blk.dis.ok1 source · line 169 · raw

@+sectors:0x81011db9256231154e908712080eb16d/src/lib/u64.U64 -> @d:Dseg -> U32

def Blk.dis.status source · line 177 · raw

@ds:List<&2, Dseg> -> @+sectors:0x81011db9256231154e908712080eb16d/src/lib/u64.U64 -> U32

A request's status before anything is freed: the first segment's that is not OK, else OK.

def Blk.dis.range source · line 186 · raw

@+sector:0x81011db9256231154e908712080eb16d/src/lib/u64.U64 -> @+num:U32 -> Pair(0x81011db9256231154e908712080eb16d/src/lib/u64.U64, 0x81011db9256231154e908712080eb16d/src/lib/u64.U64)

The whole 4 KiB blocks inside a segment: their offset and length (0: none).

def Blk.dis.free source · line 193 · raw

@-R:Type -> @st:0x81011db9256231154e908712080eb16d/src/disk/store.Store -> @r:Pair(0x81011db9256231154e908712080eb16d/src/lib/u64.U64, 0x81011db9256231154e908712080eb16d/src/lib/u64.U64) -> 0x81011db9256231154e908712080eb16d/src/vmm/abi.Op<R, Unit>

def Blk.dis.run source · line 198 · raw

@-R:Type -> @ds:List<&2, Dseg> -> @+st:0x81011db9256231154e908712080eb16d/src/disk/store.Store -> 0x81011db9256231154e908712080eb16d/src/vmm/abi.Op<R, Unit>

def Blk.offered_wz.go source · line 218 · raw

@ro:Bool -> @f:0x81011db9256231154e908712080eb16d/src/lib/u64.U64 -> 0x81011db9256231154e908712080eb16d/src/lib/u64.U64

Write zeroes (VIRTIO_BLK_F_WRITE_ZEROES, bit 14), offered for a writable raw image (BlkKind; a qcow2 image keeps DISCARD alone): the guest names sectors that must read as zeros (Linux: ext4's zero-out, fallocate's zero range, blkdiscard -z). Segments as DISCARD's; with UNMAP (bit 0) the host frees the whole 4 KiB blocks inside (holes: the space goes back to the host) and writes zeros in the partial ones at the ends; without it the range stays allocated (Op.disk_zero_keep). Config after discard's: max_write_zeroes_sectors, max_write_zeroes_seg and write_zeroes_may_unmap (offsets 48, 52, 56).

def Blk.offered_wz source · line 225 · raw

@+ro:Bool -> 0x81011db9256231154e908712080eb16d/src/lib/u64.U64

def Blk.config_wz source · line 228 · raw

@sectors:0x81011db9256231154e908712080eb16d/src/lib/u64.U64 -> List<&2, U32>

def Blk.wz.disk source · line 233 · raw

@st:0x81011db9256231154e908712080eb16d/src/disk/store.Store -> Maybe<&2, U32>

The raw image of a store (none for qcow2).

def Blk.wz.keep source · line 240 · raw

@-R:Type -> @+d:U32 -> @+off:0x81011db9256231154e908712080eb16d/src/lib/u64.U64 -> @+len:U32 -> 0x81011db9256231154e908712080eb16d/src/vmm/abi.Op<R, Unit>

def Blk.wz.unmap source · line 245 · raw

@-R:Type -> @+d:U32 -> @+off:0x81011db9256231154e908712080eb16d/src/lib/u64.U64 -> @+len:U32 -> @r:Pair(0x81011db9256231154e908712080eb16d/src/lib/u64.U64, 0x81011db9256231154e908712080eb16d/src/lib/u64.U64) -> 0x81011db9256231154e908712080eb16d/src/vmm/abi.Op<R, Unit>

One segment with UNMAP: the whole blocks inside (a, n) freed, zeros written before and after them.

def Blk.wz.one source · line 255 · raw

@-R:Type -> @+d:U32 -> @sg:Dseg -> 0x81011db9256231154e908712080eb16d/src/vmm/abi.Op<R, Unit>

def Blk.wz.run source · line 263 · raw

@-R:Type -> @ds:List<&2, Dseg> -> @+d:U32 -> 0x81011db9256231154e908712080eb16d/src/vmm/abi.Op<R, Unit>

def Blk.kind source · line 272 · raw

@+t:U32 -> Nat

The request kind of a type field: 0 IN, 1 OUT, 2 GET_ID, 3 FLUSH, 5 DISCARD (type 11), 6 WRITE_ZEROES (type 13), 4 unsupported.

def Blk.put source · line 281 · raw

@-R:Type -> @ds:List<&2, 0x81011db9256231154e908712080eb16d/src/virtio/queue.Desc> -> @+off:U32 -> @+b:U32 -> 0x81011db9256231154e908712080eb16d/src/vmm/abi.Op<R, Unit>

Writes byte b at offset off of the writable area ds.

def Blk.reply source · line 292 · raw

@-R:Type -> @+w:List<&2, 0x81011db9256231154e908712080eb16d/src/virtio/queue.Desc> -> @+room:U32 -> @res:Pair(U32, List<&2, U32>) -> 0x81011db9256231154e908712080eb16d/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 303 · 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 309 · raw

@-R:Type -> @+st:0x81011db9256231154e908712080eb16d/src/disk/store.Store -> @done:Bool -> 0x81011db9256231154e908712080eb16d/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 315 · raw

@-R:Type -> @ok:Bool -> @+st:0x81011db9256231154e908712080eb16d/src/disk/store.Store -> @sector:0x81011db9256231154e908712080eb16d/src/lib/u64.U64 -> @+w:List<&2, 0x81011db9256231154e908712080eb16d/src/virtio/queue.Desc> -> @+room:U32 -> 0x81011db9256231154e908712080eb16d/src/vmm/abi.Op<R, U32>

IN: the room before the status byte filled from the store at sector.

def Blk.out source · line 328 · raw

@-R:Type -> @ok:Bool -> @+st:0x81011db9256231154e908712080eb16d/src/disk/store.Store -> @sector:0x81011db9256231154e908712080eb16d/src/lib/u64.U64 -> @ss:List<&2, 0x81011db9256231154e908712080eb16d/src/vmm/abi.Iov> -> @+w:List<&2, 0x81011db9256231154e908712080eb16d/src/virtio/queue.Desc> -> @+room:U32 -> 0x81011db9256231154e908712080eb16d/src/vmm/abi.Op<R, U32>

OUT: the readable data after the header (ss) written at sector.

def Blk.out_ro source · line 339 · raw

@-R:Type -> @ro:Bool -> @st:0x81011db9256231154e908712080eb16d/src/disk/store.Store -> @+sectors:0x81011db9256231154e908712080eb16d/src/lib/u64.U64 -> @+sector:0x81011db9256231154e908712080eb16d/src/lib/u64.U64 -> @+r:List<&2, 0x81011db9256231154e908712080eb16d/src/virtio/queue.Desc> -> @+w:List<&2, 0x81011db9256231154e908712080eb16d/src/virtio/queue.Desc> -> @+room:U32 -> 0x81011db9256231154e908712080eb16d/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 349 · raw

@-R:Type -> @+st:0x81011db9256231154e908712080eb16d/src/disk/store.Store -> @+w:List<&2, 0x81011db9256231154e908712080eb16d/src/virtio/queue.Desc> -> @+room:U32 -> 0x81011db9256231154e908712080eb16d/src/vmm/abi.Op<R, U32>

FLUSH: makes earlier writes durable.

def Blk.discard.go source · line 357 · raw

@-R:Type -> @+bs:List<&2, U32> -> @st:0x81011db9256231154e908712080eb16d/src/disk/store.Store -> @+sectors:0x81011db9256231154e908712080eb16d/src/lib/u64.U64 -> @+w:List<&2, 0x81011db9256231154e908712080eb16d/src/virtio/queue.Desc> -> @+room:U32 -> 0x81011db9256231154e908712080eb16d/src/vmm/abi.Op<R, U32>

DISCARD: the readable data after the header, 1 to discard_max_seg segments; read through Bend (16 bytes each), checked, then freed.

def Blk.discard.read source · line 364 · raw

@-R:Type -> @ok:Bool -> @st:0x81011db9256231154e908712080eb16d/src/disk/store.Store -> @+sectors:0x81011db9256231154e908712080eb16d/src/lib/u64.U64 -> @+ss:List<&2, 0x81011db9256231154e908712080eb16d/src/vmm/abi.Iov> -> @+w:List<&2, 0x81011db9256231154e908712080eb16d/src/virtio/queue.Desc> -> @+room:U32 -> 0x81011db9256231154e908712080eb16d/src/vmm/abi.Op<R, U32>

def Blk.discard source · line 371 · raw

@-R:Type -> @ro:Bool -> @st:0x81011db9256231154e908712080eb16d/src/disk/store.Store -> @+sectors:0x81011db9256231154e908712080eb16d/src/lib/u64.U64 -> @+r:List<&2, 0x81011db9256231154e908712080eb16d/src/virtio/queue.Desc> -> @+w:List<&2, 0x81011db9256231154e908712080eb16d/src/virtio/queue.Desc> -> @+room:U32 -> 0x81011db9256231154e908712080eb16d/src/vmm/abi.Op<R, U32>

def Blk.wz.go source · line 382 · raw

@-R:Type -> @+bs:List<&2, U32> -> @md:Maybe<&2, U32> -> @+st:0x81011db9256231154e908712080eb16d/src/disk/store.Store -> @+sectors:0x81011db9256231154e908712080eb16d/src/lib/u64.U64 -> @+w:List<&2, 0x81011db9256231154e908712080eb16d/src/virtio/queue.Desc> -> @+room:U32 -> 0x81011db9256231154e908712080eb16d/src/vmm/abi.Op<R, U32>

WRITE_ZEROES: segments as DISCARD's, checked, then zeroed on the raw image (UNSUPP on a read-only or qcow2 store: not offered there).

def Blk.wz.read source · line 394 · raw

@-R:Type -> @ok:Bool -> @+st:0x81011db9256231154e908712080eb16d/src/disk/store.Store -> @+sectors:0x81011db9256231154e908712080eb16d/src/lib/u64.U64 -> @+ss:List<&2, 0x81011db9256231154e908712080eb16d/src/vmm/abi.Iov> -> @+w:List<&2, 0x81011db9256231154e908712080eb16d/src/virtio/queue.Desc> -> @+room:U32 -> 0x81011db9256231154e908712080eb16d/src/vmm/abi.Op<R, U32>

def Blk.write_zeroes source · line 401 · raw

@-R:Type -> @ro:Bool -> @+st:0x81011db9256231154e908712080eb16d/src/disk/store.Store -> @+sectors:0x81011db9256231154e908712080eb16d/src/lib/u64.U64 -> @+r:List<&2, 0x81011db9256231154e908712080eb16d/src/virtio/queue.Desc> -> @+w:List<&2, 0x81011db9256231154e908712080eb16d/src/virtio/queue.Desc> -> @+room:U32 -> 0x81011db9256231154e908712080eb16d/src/vmm/abi.Op<R, U32>

def Blk.exec.kind source · line 410 · raw

@-R:Type -> @k:Nat -> @ro:Bool -> @st:0x81011db9256231154e908712080eb16d/src/disk/store.Store -> @+sectors:0x81011db9256231154e908712080eb16d/src/lib/u64.U64 -> @+sector:0x81011db9256231154e908712080eb16d/src/lib/u64.U64 -> @+r:List<&2, 0x81011db9256231154e908712080eb16d/src/virtio/queue.Desc> -> @+w:List<&2, 0x81011db9256231154e908712080eb16d/src/virtio/queue.Desc> -> @+room:U32 -> 0x81011db9256231154e908712080eb16d/src/vmm/abi.Op<R, U32>

def Blk.exec.go source · line 432 · raw

@-R:Type -> @short:Bool -> @+hdr:List<&2, U32> -> @ro:Bool -> @st:0x81011db9256231154e908712080eb16d/src/disk/store.Store -> @sectors:0x81011db9256231154e908712080eb16d/src/lib/u64.U64 -> @r:List<&2, 0x81011db9256231154e908712080eb16d/src/virtio/queue.Desc> -> @+w:List<&2, 0x81011db9256231154e908712080eb16d/src/virtio/queue.Desc> -> @+room:U32 -> 0x81011db9256231154e908712080eb16d/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 443 · raw

@-R:Type -> @+hdr:List<&2, U32> -> @ro:Bool -> @st:0x81011db9256231154e908712080eb16d/src/disk/store.Store -> @sectors:0x81011db9256231154e908712080eb16d/src/lib/u64.U64 -> @r:List<&2, 0x81011db9256231154e908712080eb16d/src/virtio/queue.Desc> -> @+w:List<&2, 0x81011db9256231154e908712080eb16d/src/virtio/queue.Desc> -> @+room:U32 -> 0x81011db9256231154e908712080eb16d/src/vmm/abi.Op<R, U32>

def Blk.answer_chain source · line 448 · raw

@-R:Type -> @empty:Bool -> @ro:Bool -> @st:0x81011db9256231154e908712080eb16d/src/disk/store.Store -> @sectors:0x81011db9256231154e908712080eb16d/src/lib/u64.U64 -> @+r:List<&2, 0x81011db9256231154e908712080eb16d/src/virtio/queue.Desc> -> @+w:List<&2, 0x81011db9256231154e908712080eb16d/src/virtio/queue.Desc> -> @+room:U32 -> 0x81011db9256231154e908712080eb16d/src/vmm/abi.Op<R, U32>

def Blk.serve_chain source · line 463 · raw

@-R:Type -> @ro:Bool -> @st:0x81011db9256231154e908712080eb16d/src/disk/store.Store -> @sectors:0x81011db9256231154e908712080eb16d/src/lib/u64.U64 -> @q:0x81011db9256231154e908712080eb16d/src/virtio/queue.Vq -> @c:0x81011db9256231154e908712080eb16d/src/virtio/queue.Chain -> 0x81011db9256231154e908712080eb16d/src/vmm/abi.Op<R, 0x81011db9256231154e908712080eb16d/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 473 · raw

@-R:Type -> @ro:Bool -> @st:0x81011db9256231154e908712080eb16d/src/disk/store.Store -> @sectors:0x81011db9256231154e908712080eb16d/src/lib/u64.U64 -> @r:Pair(0x81011db9256231154e908712080eb16d/src/virtio/queue.Vq, Maybe<&2, 0x81011db9256231154e908712080eb16d/src/virtio/queue.Chain>) -> @used:Bool -> @k:(@_:0x81011db9256231154e908712080eb16d/src/virtio/queue.Vq -> 0x81011db9256231154e908712080eb16d/src/vmm/abi.Op<R, Pair(0x81011db9256231154e908712080eb16d/src/virtio/queue.Vq, Bool)>) -> 0x81011db9256231154e908712080eb16d/src/vmm/abi.Op<R, Pair(0x81011db9256231154e908712080eb16d/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 484 · raw

@fuel:Nat -> @-R:Type -> @+ro:Bool -> @+st:0x81011db9256231154e908712080eb16d/src/disk/store.Store -> @+sectors:0x81011db9256231154e908712080eb16d/src/lib/u64.U64 -> @q:0x81011db9256231154e908712080eb16d/src/virtio/queue.Vq -> @used:Bool -> 0x81011db9256231154e908712080eb16d/src/vmm/abi.Op<R, Pair(0x81011db9256231154e908712080eb16d/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 496 · raw

@-R:Type -> @st:0x81011db9256231154e908712080eb16d/src/disk/store.Store -> @sectors:0x81011db9256231154e908712080eb16d/src/lib/u64.U64 -> @ro:Bool -> @q:0x81011db9256231154e908712080eb16d/src/virtio/queue.Vq -> 0x81011db9256231154e908712080eb16d/src/vmm/abi.Op<R, Pair(0x81011db9256231154e908712080eb16d/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 502 · raw

@-R:Type -> @disk:U32 -> @sectors:0x81011db9256231154e908712080eb16d/src/lib/u64.U64 -> @ro:Bool -> @q:0x81011db9256231154e908712080eb16d/src/virtio/queue.Vq -> 0x81011db9256231154e908712080eb16d/src/vmm/abi.Op<R, Pair(0x81011db9256231154e908712080eb16d/src/virtio/queue.Vq, Bool)>

Blk.serve_store on a raw disk image.

def Blk.process source · line 506 · raw

@-R:Type -> @disk:U32 -> @sectors:0x81011db9256231154e908712080eb16d/src/lib/u64.U64 -> @q:0x81011db9256231154e908712080eb16d/src/virtio/queue.Vq -> 0x81011db9256231154e908712080eb16d/src/vmm/abi.Op<R, Pair(0x81011db9256231154e908712080eb16d/src/virtio/queue.Vq, Bool)>

Blk.serve on a read-write disk.