~/bend-docscommunity

src/vmm/snapfile.bend checks

raw source on the hub · import 0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/vmm/snapfile.bend as Snapfile

3 imports
import Base
import ../lib/u64.bend as U
import ../lib/bytes.bend as B

Types

type Part source · line 57 · raw

Data

A part of the file: its offset and length.

type Layout source · line 62 · raw

Data

Where each part lies in the file: argv, the machine words, the GIC state and each vCPU's blob as (offset, length), and RAM's offset.

type Piece source · line 68 · raw

Data

One write of the plan the host carries out, at a file offset: bytes given here, or a part the host holds (the machine words, the GIC state, vCPU i's register blob, guest RAM, argv).

type Need source · line 78 · raw

Data

A step of reading a file's layout: read the u64 length at off next, the file is bad, or the layout is known.

Definitions

def Snapf.magic source · line 25 · raw

List<&2, U32>

def Snapf.max_cpus source · line 29 · raw

U32

def Snapf.max_args source · line 32 · raw

0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64

def Snapf.max_words source · line 36 · raw

0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64

def Snapf.max_gic source · line 40 · raw

0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64

def Snapf.max_cpu source · line 44 · raw

0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64

def Snapf.max_ram source · line 48 · raw

0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64

def Snapf.len source · line 86 · raw

@-A:Data -> @+xs:List<&2, A> -> 0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64

def Snapf.after source · line 90 · raw

@a:0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64 -> @n:0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64 -> 0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64

a past b by n bytes and an 8-byte length prefix

def Snapf.within source · line 93 · raw

@+a:0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64 -> @+max:0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64 -> Bool

def Snapf.cpus_within source · line 96 · raw

@cs:List<&2, 0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64> -> Bool

def Snapf.ram_ok source · line 103 · raw

@+ram:0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64 -> Bool

def Snapf.head_bytes source · line 107 · raw

@h:Head -> List<&2, U32>

The header's 40 bytes.

def Head.nargs source · line 116 · raw

@h:Head -> 0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64

def Head.ncpus source · line 121 · raw

@h:Head -> U32

def Snapf.words_at source · line 126 · raw

@+h:Head -> 0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64

def Snapf.gic_at source · line 129 · raw

@+h:Head -> @+nw:0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64 -> 0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64

def Snapf.plan.cpus source · line 135 · raw

@cs:List<&2, 0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64> -> @+i:U32 -> @+at:0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64 -> List<&2, Piece>

The vCPU blobs from offset at: each one's length, then the blob; RAM at the next 16 KiB boundary after the last.

def Snapf.plan.pieces source · line 142 · raw

@+h:Head -> @+nwords:0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64 -> @+ngic:0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64 -> @cs:List<&2, 0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64> -> List<&2, Piece>

def Snapf.plan.pick source · line 153 · raw

@ok:Bool -> @ps:List<&2, Piece> -> Maybe<&2, List<&2, Piece>>

def Snapf.plan source · line 163 · raw

@ver:U32 -> @base:0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64 -> @+ram:0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64 -> @+nargs:0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64 -> @+nwords:0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64 -> @+ngic:0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64 -> @+cs:List<&2, 0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64> -> Maybe<&2, List<&2, Piece>>

The writes of a snapshot of a VM with this hypervisor version, RAM base and size, argv length, machine word count, GIC state length and vCPU blob lengths; None when a loader would refuse the file.

def Snapf.word.got source · line 169 · raw

@m:Maybe<&2, U32> -> U32

def Snapf.word source · line 176 · raw

@+ws:List<&2, U32> -> @k:Nat -> U32

def Snapf.u64_at source · line 179 · raw

@+ws:List<&2, U32> -> @+k:Nat -> 0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64

def Snapf.lens source · line 182 · raw

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

def Snapf.plan_of.pick source · line 189 · raw

@ok:Bool -> @p:Maybe<&2, List<&2, Piece>> -> Maybe<&2, List<&2, Piece>>

def Snapf.plan_of source · line 199 · raw

@+ws:List<&2, U32> -> Maybe<&2, List<&2, Piece>>

The plan for the sizes the host answers (Hvf.snap_save): [version, RAM base, RAM size, argv length, word count, GIC length (each hi, lo), vCPUs, then each vCPU's blob length (hi, lo)].

def Snapf.tmp source · line 211 · raw

@path:String -> String

A snapshot is written to a file of its own next to path, then renamed over path: a failed write leaves what path held (the host removes its file), and the snapshot a VM was restored from, whose RAM is mapped, can be replaced.

def Snapf.head.pick source · line 217 · raw

@ok:Bool -> @h:Head -> Maybe<&2, Head>

def Snapf.magic_is source · line 224 · raw

@a:List<&2, U32> -> @b:List<&2, U32> -> Bool

def Snapf.head source · line 234 · raw

@+ver:U32 -> @+bs:List<&2, U32> -> Maybe<&2, Head>

The first 40 bytes of a snapshot from a host whose version is ver.

def Snapf.need.cpus source · line 245 · raw

@left:Nat -> @lens:List<&2, 0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64> -> @+h:Head -> @+nw:0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64 -> @+ng:0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64 -> @+at:0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64 -> @acc:List<&2, Part> -> Need

The vCPU blobs: left more to read from at, with lens the lengths read so far past the GIC's (each within its bound, or the file is bad).

def Snapf.need.gic source · line 263 · raw

@rest:List<&2, 0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64> -> @+h:Head -> @+nw:0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64 -> Need

def Snapf.need source · line 274 · raw

@+h:Head -> @lens:List<&2, 0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64> -> Need

What to read next, given the header and the length prefixes read so far (the machine words', the GIC's, then each vCPU's, in file order).

def Snapf.fits source · line 283 · raw

@l:Layout -> @+size:0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64 -> Bool

The file holds all of RAM (it is mapped from the file: a short one would fault on the first touch past its end).

def Snapf.mem_mib source · line 291 · raw

@l:Layout -> U32

The machine a restore makes is the header's: its RAM (in MiB) and at least its vCPUs (a snapshot of a restored VM saves the restore's command line, which names neither), at the most the saved --cpus asked for.

def Snapf.cpus source · line 296 · raw

@l:Layout -> @+asked:U32 -> U32

def Snapf.agrees source · line 304 · raw

@l:Layout -> @+base:0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64 -> Bool

The header describes a machine this host makes: RAM at base, a whole number of MiB below 2^40 (Snapf.head bounds it). A snapshot is a file from elsewhere: the host maps RAM by the header.

def Snapf.rebase source · line 315 · raw

Bool

After a snapshot is written, guest RAM maps it (Hvf.snap_rebase): the pages the guest has not written since are the file's, clean (the host may drop them and read them back: they leave the VMM's footprint), and the next snapshot begins as the file's clone and writes only the chunks written since. The file then backs the running VM: removing it frees its space only when the next snapshot (or the VM's exit) lets it go.

def Snapf.ram_at source · line 319 · raw

@ps:List<&2, Piece> -> Maybe<&2, 0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64>

Where a plan puts guest RAM (none when it has none).

def Snapf.plan_ram source · line 330 · raw

@m:Maybe<&2, List<&2, Piece>> -> Maybe<&2, 0xee7f0dd7e7a8915ce966ea5d2ce153b5/src/lib/u64.U64>

def Snapf.w64 source · line 340 · raw

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

def Snapf.piece.wire source · line 348 · raw

@p:Piece -> List<&2, U32>

A piece for the host: [kind, offset hi, lo, ...]: 0 bytes (count, then the bytes), 1 the machine words, 2 the GIC state, 3 vCPU i's blob (i), 4 guest RAM, 5 argv.

def Snapf.pieces.wire source · line 363 · raw

@ps:List<&2, Piece> -> List<&2, U32>

def Snapf.cpus.wire source · line 373 · raw

@cs:List<&2, Part> -> List<&2, U32>

The host's load: [RAM base, RAM size, RAM offset, argv offset, argv length, words offset, words length in bytes, GIC offset, GIC length (each hi, lo), vCPUs, then per vCPU offset and length].

def Snapf.load.wire source · line 380 · raw

@l:Layout -> List<&2, U32>

def Snapf.version source · line 393 · raw

@+hv:U32 -> U32

The snapshot format each hypervisor writes and reads, from the host's fact (the first word Hvf.snap_save answers, the second of Hvf.snap_open's: 0 Hypervisor.framework, 1 KVM, 2 KVM on x86_64): version 1 holds Hypervisor.framework's register entries and hv_gic_state, version 2 KVM's register list and its vGIC replay, version 3 KVM's x86 state structures (src/x86/layout.bend's plans). A snapshot restores only where its version is this host's; another hypervisor has no version (0, which no header carries).

def Snapf.sizes source · line 398 · raw

@ws:List<&2, U32> -> List<&2, U32>

The sizes Hvf.snap_save answers, with its hypervisor word made the format's version (Snapf.plan_of reads a version there).