~/bend-docscommunity

host/api.bend relies on unsafe/foreign

raw source on the hub · import 0x57252a008df878fb1dc2300a80550c94/host/api.bend as Api

11 imports
import Base
import ./hvf.bend as H
import ../src/vmm/snapdir.bend as Sd
import ../src/vmm/cmds.bend as Cm
import ../src/vmm/disksnap.bend as Ds
import ../src/vmm/opts.bend as Op
import ../src/vmm/hostfiles.bend as Hf
import ../src/vmm/cli.bend as Cli
import ../src/lib/u64.bend as U
import ../src/disk/ext4free.bend as Ex
import ../src/disk/access.bend as Ac

Types

type Err source · line 24 · raw

Data

Why a call failed. ENoSocket: no socket there (a folder: no VM ever ran); ENotRunning: a socket nobody answers on (the VM stopped); ETimeout: no reply in time; EBadName, EExists, ENoSnapshot: snapshot names; ENoVm: not a VM folder; EFailed: the VM answered an error, or the host failed.

type Status source · line 55 · raw

Data

A VM's state: running, paused or stopped, and its forwards (vm.conf's --forward; "" for a socket).

type Vm source · line 60 · raw

Data

A VM as a call reaches it: its control socket, and its folder ("" when named by its socket).

Definitions

def Err.text source · line 34 · raw

@e:Err -> String

def Api.fail source · line 63 · raw

@-A:Type -> @e:Err -> IO(Result<&1, &1, Err, A>)

def Api.done source · line 66 · raw

@-A:Type -> @x:A -> IO(Result<&1, &1, Err, A>)

def Api.vm.of source · line 69 · raw

@+path:String -> @+ws:List<&2, U32> -> Vm

def Api.vm source · line 73 · raw

@+path:String -> IO(Vm)

A socket path is the VM's socket; anything else its folder.

def Api.sock source · line 78 · raw

@v:Vm -> String

def Api.dir source · line 83 · raw

@v:Vm -> String

def Api.read.got source · line 89 · raw

@got:Pair(File, Result<&1, &1, Pair(U32, String), String>) -> IO(String)

Text files (vm.conf, a snapshot's info): "" when missing.

def Api.read.opened source · line 100 · raw

@r:Result<&1, &1, Pair(U32, String), File> -> IO(String)

def Api.read source · line 109 · raw

@path:String -> IO(String)

def Api.write.got source · line 114 · raw

@got:Pair(File, Result<&1, &1, Pair(U32, String), Unit>) -> IO(Bool)

def Api.write.opened source · line 125 · raw

@r:Result<&1, &1, Pair(U32, String), File> -> @+text:String -> IO(Bool)

def Api.write source · line 134 · raw

@path:String -> @+text:String -> IO(Bool)

def Api.chars source · line 139 · raw

@bs:List<&2, U32> -> String

def Api.reply source · line 148 · raw

@+ws:List<&2, U32> -> Result<&1, &1, Err, String>

The VM's answer to one control line. ENOENT (2): no socket; any other connect error (ECONNREFUSED): a socket nobody answers on.

def Api.call.at source · line 157 · raw

@+sock:String -> @+line:String -> @+ms:U32 -> IO(Result<&1, &1, Err, String>)

def Vmm.ctl source · line 163 · raw

@+vm:String -> @+line:String -> IO(Result<&1, &1, Err, String>)

One control line to a VM (its folder or socket), its reply.

def Vmm.pause source · line 168 · raw

@+vm:String -> IO(Result<&1, &1, Err, String>)

def Vmm.resume source · line 171 · raw

@+vm:String -> IO(Result<&1, &1, Err, String>)

def Vmm.stop source · line 175 · raw

@+vm:String -> IO(Result<&1, &1, Err, String>)

stop ends the VM at once (quit); powerdown asks the guest to shut down.

def Vmm.powerdown source · line 178 · raw

@+vm:String -> IO(Result<&1, &1, Err, String>)

def Api.conf source · line 182 · raw

@+dir:String -> IO(List<&2, String>)

The folder's VM options (vm.conf, paths made the folder's).

def Api.status.of source · line 187 · raw

@r:Result<&1, &1, Err, String> -> @+fw:String -> Result<&1, &1, Err, Status>

def Vmm.status source · line 212 · raw

@+vm:String -> IO(Result<&1, &1, Err, Status>)

running, paused or stopped (a VM that is not running is stopped, not an error), with its forwards.

def Api.names source · line 223 · raw

@xs:List<&1, String> -> List<&2, String>

def Api.has source · line 231 · raw

@xs:List<&2, String> -> @+n:String -> Bool

def Api.rm_files source · line 239 · raw

@xs:List<&1, String> -> @+dir:String -> IO(Unit)

A folder and everything in it (snapshot folders hold only files).

def Api.rm_dir source · line 248 · raw

@+dir:String -> IO(U32)

def Api.disk_kib source · line 256 · raw

@xs:List<&1, String> -> @+dir:String -> IO(U32)

The KiB a snapshot's disk copies hold on their own (Hvf.size_kib: blocks not shared with the disk they were cloned from, nor other copies).

def Api.info.now source · line 271 · raw

@i:0x57252a008df878fb1dc2300a80550c94/src/vmm/snapdir.Info -> @+mk:U32 -> @+dk:U32 -> 0x57252a008df878fb1dc2300a80550c94/src/vmm/snapdir.Info

A snapshot's info with what its memory and disks hold now, on their own: a disk copy cloned from the disk, and a memory file cloned from the snapshot before it (Snapf.rebase), share nearly all of it at first and take more as the VM moves on (the space removing the snapshot gives back).

def Api.infos source · line 276 · raw

@ns:List<&2, String> -> @+dir:String -> IO(List<&2, 0x57252a008df878fb1dc2300a80550c94/src/vmm/snapdir.Info>)

def Api.no_dir source · line 290 · raw

Err

def Api.snapshots.in source · line 294 · raw

@none:Bool -> @+d:String -> IO(Result<&1, &1, Err, List<&2, 0x57252a008df878fb1dc2300a80550c94/src/vmm/snapdir.Info>>)

The VM's snapshots, oldest first.

def Vmm.snapshots source · line 304 · raw

@+vm:String -> IO(Result<&1, &1, Err, List<&2, 0x57252a008df878fb1dc2300a80550c94/src/vmm/snapdir.Info>>)

def Api.rm.go source · line 309 · raw

@ok:Bool -> @+d:String -> @+name:String -> IO(Result<&1, &1, Err, String>)

def Api.rm.in source · line 318 · raw

@none:Bool -> @+d:String -> @+name:String -> IO(Result<&1, &1, Err, String>)

def Vmm.snapshot_rm source · line 327 · raw

@+vm:String -> @+name:String -> IO(Result<&1, &1, Err, String>)

def Api.prune.go source · line 332 · raw

@ns:List<&2, String> -> @+d:String -> IO(List<&2, String>)

def Api.prune.in source · line 343 · raw

@none:Bool -> @+d:String -> @+keep:U32 -> IO(Result<&1, &1, Err, List<&2, String>>)

prune --keep N: removes the oldest past the newest N; their names.

def Vmm.prune source · line 354 · raw

@+vm:String -> @+keep:U32 -> IO(Result<&1, &1, Err, List<&2, String>>)

def Api.step source · line 360 · raw

@s:0x57252a008df878fb1dc2300a80550c94/src/vmm/disksnap.Step -> IO(U32)

disksnap's steps, in order, until one fails (0, or its errno).

def Api.steps source · line 371 · raw

@ss:List<&1, 0x57252a008df878fb1dc2300a80550c94/src/vmm/disksnap.Step> -> @+rc:U32 -> IO(U32)

def Api.copy_disks source · line 382 · raw

@+tmp:String -> @+d:String -> IO(U32)

The disks of a stopped VM copied into a snapshot folder (its memory is not running anywhere: a snapshot of a stopped VM is its disks).

def Api.stopped source · line 388 · raw

@e:Err -> Bool

def Api.snap.renamed source · line 397 · raw

@+rc:U32 -> @+info:0x57252a008df878fb1dc2300a80550c94/src/vmm/snapdir.Info -> @+dst:String -> Result<&1, &1, Err, 0x57252a008df878fb1dc2300a80550c94/src/vmm/snapdir.Info>

def Api.snap.place source · line 402 · raw

@ok:Bool -> @+rc:U32 -> @+d:String -> @+name:String -> @+note:String -> @+t:U32 -> @+tmp:String -> IO(Result<&1, &1, Err, 0x57252a008df878fb1dc2300a80550c94/src/vmm/snapdir.Info>)

A snapshot folder written whole: its info, then renamed into place; the VM's current snapshot (the next one's parent) is now this one.

def Api.snap.failed source · line 423 · raw

@stopped:Bool -> @+e:Err -> @+d:String -> @+name:String -> @+note:String -> @+t:U32 -> @+tmp:String -> IO(Result<&1, &1, Err, 0x57252a008df878fb1dc2300a80550c94/src/vmm/snapdir.Info>)

The VM's answer to snapshot TMP/; a VM that is not running has its disks copied instead.

def Api.snap.after source · line 434 · raw

@r:Result<&1, &1, Err, String> -> @+d:String -> @+name:String -> @+note:String -> @+t:U32 -> @+tmp:String -> IO(Result<&1, &1, Err, 0x57252a008df878fb1dc2300a80550c94/src/vmm/snapdir.Info>)

def Api.snap.take source · line 441 · raw

@+d:String -> @+name:String -> @+note:String -> @+t:U32 -> IO(Result<&1, &1, Err, 0x57252a008df878fb1dc2300a80550c94/src/vmm/snapdir.Info>)

def Api.snap.check source · line 450 · raw

@valid:Bool -> @exists:Bool -> @+d:String -> @+name:String -> @+note:String -> @+t:U32 -> IO(Result<&1, &1, Err, 0x57252a008df878fb1dc2300a80550c94/src/vmm/snapdir.Info>)

def Api.snap.in source · line 462 · raw

@none:Bool -> @+d:String -> @+base:String -> @+gen:Bool -> @+note:String -> @+t:U32 -> IO(Result<&1, &1, Err, 0x57252a008df878fb1dc2300a80550c94/src/vmm/snapdir.Info>)

A snapshot of the VM in its folder: name "" takes the time's (Sname.of_time). A running VM keeps its memory and disks; a stopped one its disks. Answers what was saved.

def Vmm.snapshot source · line 476 · raw

@+vm:String -> @+name0:String -> @+note:String -> IO(Result<&1, &1, Err, 0x57252a008df878fb1dc2300a80550c94/src/vmm/snapdir.Info>)

A snapshot of the VM in its folder: name "" takes the time's (Sname.of_time; with -2, -3 ... when taken). A running VM keeps its memory and disks; a stopped one its disks. Answers what was saved.

def Vmm.snapshot_undo source · line 485 · raw

@+vm:String -> @+note:String -> IO(Result<&1, &1, Err, 0x57252a008df878fb1dc2300a80550c94/src/vmm/snapdir.Info>)

The snapshot a restore takes first (Sname.undo, unique).

def Api.create.go source · line 494 · raw

@+why:String -> @there:Bool -> @+dir:String -> @+text:String -> IO(Result<&1, &1, Err, String>)

A VM folder: DIR/vm.conf with these options (checked as the command line would be); refused when DIR has one already.

def Vmm.create source · line 504 · raw

@+dir:String -> @+flags:List<&2, String> -> IO(Result<&1, &1, Err, String>)

def vmdir.undo_said source · line 510 · raw

@r:Result<&1, &1, Err, 0x57252a008df878fb1dc2300a80550c94/src/vmm/snapdir.Info> -> IO(Unit)

The command line's commands: their results printed (host/main.bend's cli)

def cli.kib source · line 517 · raw

@+k:U32 -> String

def cli.info source · line 520 · raw

@i:0x57252a008df878fb1dc2300a80550c94/src/vmm/snapdir.Info -> String

def cli.infos source · line 526 · raw

@xs:List<&2, 0x57252a008df878fb1dc2300a80550c94/src/vmm/snapdir.Info> -> IO(Unit)

def cli.lines source · line 535 · raw

@xs:List<&2, String> -> @+pre:String -> IO(Unit)

def cli.die source · line 544 · raw

@e:Err -> IO(Unit)

def cli.text source · line 547 · raw

@r:Result<&1, &1, Err, String> -> @+pre:String -> IO(Unit)

def cli.snap source · line 554 · raw

@r:Result<&1, &1, Err, 0x57252a008df878fb1dc2300a80550c94/src/vmm/snapdir.Info> -> IO(Unit)

def cli.snaps source · line 561 · raw

@r:Result<&1, &1, Err, List<&2, 0x57252a008df878fb1dc2300a80550c94/src/vmm/snapdir.Info>> -> IO(Unit)

def cli.names source · line 568 · raw

@r:Result<&1, &1, Err, List<&2, String>> -> IO(Unit)

def cli.status source · line 575 · raw

@r:Result<&1, &1, Err, Status> -> IO(Unit)

def cli.created source · line 582 · raw

@r:Result<&1, &1, Err, String> -> IO(Unit)

def cli.ctl source · line 589 · raw

@+vm:String -> @+line:String -> IO(Unit)

def cli.none source · line 593 · raw

@s:0x57252a008df878fb1dc2300a80550c94/src/vmm/cmds.Sub -> Bool

def die_if source · line 603 · raw

@bad:Bool -> @what:String -> IO(Unit)

def vmdir.sock source · line 609 · raw

@+dir:String -> String

def vmdir.stopped source · line 619 · raw

@st:Result<&1, &1, Err, Status> -> Bool

def vmdir.wait_stop source · line 627 · raw

@fuel:Nat -> @+vm:String -> IO(Unit)

Waits (at most fuel x 100 ms) for the VM to stop.

def Spr.punch source · line 671 · raw

@+id:U32 -> @rg:Pair(0x57252a008df878fb1dc2300a80550c94/src/lib/u64.U64, 0x57252a008df878fb1dc2300a80550c94/src/lib/u64.U64) -> IO(0x57252a008df878fb1dc2300a80550c94/src/lib/u64.U64)

def Spr.runs source · line 678 · raw

@rs:List<&2, 0x57252a008df878fb1dc2300a80550c94/src/disk/ext4free.Run> -> @+id:U32 -> @+f:0x57252a008df878fb1dc2300a80550c94/src/disk/ext4free.Fs -> @+acc:0x57252a008df878fb1dc2300a80550c94/src/lib/u64.U64 -> IO(0x57252a008df878fb1dc2300a80550c94/src/lib/u64.U64)

Group g's free runs punched; the bytes freed so far.

def Spr.group source · line 687 · raw

@m:Maybe<&2, U32> -> @+id:U32 -> @+f:0x57252a008df878fb1dc2300a80550c94/src/disk/ext4free.Fs -> @+g:U32 -> IO(0x57252a008df878fb1dc2300a80550c94/src/lib/u64.U64)

def Spr.groups source · line 696 · raw

@fuel:Nat -> @+id:U32 -> @+f:0x57252a008df878fb1dc2300a80550c94/src/disk/ext4free.Fs -> @+ds:List<&2, U32> -> @+g:U32 -> @+acc:0x57252a008df878fb1dc2300a80550c94/src/lib/u64.U64 -> IO(0x57252a008df878fb1dc2300a80550c94/src/lib/u64.U64)

def Spr.fs.go source · line 706 · raw

@+id:U32 -> @+f:0x57252a008df878fb1dc2300a80550c94/src/disk/ext4free.Fs -> IO(0x57252a008df878fb1dc2300a80550c94/src/lib/u64.U64)

One file system at base: (found, bytes freed); "skipped" when it is ext4 but not cleanly unmounted (or has errors, needs recovery, or META_BG).

def Spr.mib source · line 711 · raw

@+n:0x57252a008df878fb1dc2300a80550c94/src/lib/u64.U64 -> String

def Spr.at source · line 714 · raw

@+base:0x57252a008df878fb1dc2300a80550c94/src/lib/u64.U64 -> String

def Spr.fs source · line 717 · raw

@+id:U32 -> @+base:0x57252a008df878fb1dc2300a80550c94/src/lib/u64.U64 -> IO(String)

def Spr.bases source · line 725 · raw

@bs:List<&2, 0x57252a008df878fb1dc2300a80550c94/src/lib/u64.U64> -> @+id:U32 -> IO(String)

def Spr.gpt.entries source · line 735 · raw

@+id:U32 -> @t:0x57252a008df878fb1dc2300a80550c94/src/disk/ext4free.GptTab -> IO(List<&2, 0x57252a008df878fb1dc2300a80550c94/src/lib/u64.U64>)

def Spr.gpt source · line 743 · raw

@+id:U32 -> @gpt:Bool -> IO(List<&2, 0x57252a008df878fb1dc2300a80550c94/src/lib/u64.U64>)

The partitions: an MBR's, or a GPT's (its header at sector 1).

def Spr.image.go source · line 752 · raw

@+id:U32 -> @+path:String -> IO(String)

def Spr.image source · line 762 · raw

@+path:String -> IO(String)

def Spr.images source · line 767 · raw

@ps:List<&2, String> -> IO(String)

def Spr.paths source · line 778 · raw

@ds:List<&1, 0x57252a008df878fb1dc2300a80550c94/src/vmm/disksnap.DiskAt> -> List<&2, String>

The images named, or the writable --disk images of the VM folder.

def Vmm.sparsify source · line 787 · raw

@+vm:String -> @+paths:List<&2, String> -> IO(String)

def cli.sparsified.go source · line 792 · raw

@+t:String -> IO(Unit)

def cli.sparsified source · line 795 · raw

@t:String -> IO(Unit)

def Fs.mkdir_p.ok source · line 831 · raw

@+rc:U32 -> Bool

mkdir -p: each directory of path that is not there yet (17, EEXIST, is no error); the first other errno stops it.

def Fs.mkdir_p.go source · line 834 · raw

@dirs:List<&2, String> -> @+mode:U32 -> @+prev:U32 -> IO(U32)

def Fs.mkdir_p source · line 843 · raw

@+path:String -> @+mode:U32 -> IO(U32)

def Fs.facts source · line 846 · raw

@+path:String -> IO(0x57252a008df878fb1dc2300a80550c94/src/vmm/hostfiles.Facts)

def Fs.set_mtime source · line 851 · raw

@+path:String -> @t:0x57252a008df878fb1dc2300a80550c94/src/lib/u64.U64 -> IO(U32)

Unsafe

unsafe Vmm.run_dir source · line 613 · raw

@run:(@_:List<&1, String> -> @_:List<&1, String> -> IO(Unit)) -> @+prog:List<&1, String> -> @+dir:String -> IO(Unit)

Runs the VM of a folder: its vm.conf's options, its control socket in it.

unsafe vmdir.restore.go source · line 639 · raw

@mem:Bool -> @run:(@_:List<&1, String> -> @_:List<&1, String> -> IO(Unit)) -> @+prog:List<&1, String> -> @+vm:String -> @+snap:String -> @+flags:List<&2, String> -> IO(Unit)

Runs a folder's VM from one of its snapshots. A snapshot with memory restores (its disks set back from its copies, src/vmm/disksnap.bend); one of disks only sets them back and boots.

unsafe Vmm.restore source · line 652 · raw

@run:(@_:List<&1, String> -> @_:List<&1, String> -> IO(Unit)) -> @+prog:List<&1, String> -> @+vm:String -> @+name:String -> IO(Unit)

bend-vmm restore NAME: the current state is saved first (memory and disks when running, disks when stopped: Sname.undo), the VM stopped, then run from NAME in this process.

unsafe cli source · line 798 · raw

@run:(@_:List<&1, String> -> @_:List<&1, String> -> IO(Unit)) -> @+prog:List<&1, String> -> @s:0x57252a008df878fb1dc2300a80550c94/src/vmm/cmds.Sub -> IO(Unit)