host/api.bend relies on unsafe/foreign
raw source on the hub · import 0x2cb44898b57f05c48f38583063e077bf/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.
ENoSocketErr
ENotRunningErr
ETimeoutErr
EBadName@name:String -> Err
EExists@name:String -> Err
ENoSnapshot@name:String -> Err
ENoVm@path:String -> Err
EFailed@why:String -> Err
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).
Status@state:String -> @forwards:String -> Status
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).
Vm@sock:String -> @dir:String -> Vm
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.hibernate source · line 176 · raw
@+vm:String -> @+path:String -> IO(Result<&1, &1, Err, String>)
The VM paused, its RAM moved into a file at path that guest RAM maps (the file removed at once; no disks kept): resume continues it.
def Vmm.stop source · line 180 · 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 183 · raw
@+vm:String -> IO(Result<&1, &1, Err, String>)
def Api.conf source · line 187 · raw
@+dir:String -> IO(List<&2, String>)
The folder's VM options (vm.conf, paths made the folder's).
def Api.state_of source · line 194 · raw
@+t:String -> String
A status json reply's state: running, paused, or hibernated (paused with its RAM in a file: hibernate PATH).
def Api.status.of source · line 198 · raw
@r:Result<&1, &1, Err, String> -> @+fw:String -> Result<&1, &1, Err, Status>
def Vmm.status source · line 223 · 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 234 · raw
@xs:List<&1, String> -> List<&2, String>
def Api.has source · line 242 · raw
@xs:List<&2, String> -> @+n:String -> Bool
def Api.rm_files source · line 250 · 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 259 · raw
@+dir:String -> IO(U32)
def Api.disk_kib source · line 267 · 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 282 · raw
@i:0x2cb44898b57f05c48f38583063e077bf/src/vmm/snapdir.Info -> @+mk:U32 -> @+dk:U32 -> 0x2cb44898b57f05c48f38583063e077bf/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 287 · raw
@ns:List<&2, String> -> @+dir:String -> IO(List<&2, 0x2cb44898b57f05c48f38583063e077bf/src/vmm/snapdir.Info>)
def Api.no_dir source · line 301 · raw
Err
def Api.snapshots.in source · line 305 · raw
@none:Bool -> @+d:String -> IO(Result<&1, &1, Err, List<&2, 0x2cb44898b57f05c48f38583063e077bf/src/vmm/snapdir.Info>>)
The VM's snapshots, oldest first.
def Vmm.snapshots source · line 315 · raw
@+vm:String -> IO(Result<&1, &1, Err, List<&2, 0x2cb44898b57f05c48f38583063e077bf/src/vmm/snapdir.Info>>)
def Api.rm.go source · line 320 · raw
@ok:Bool -> @+d:String -> @+name:String -> IO(Result<&1, &1, Err, String>)
def Api.rm.in source · line 329 · raw
@none:Bool -> @+d:String -> @+name:String -> IO(Result<&1, &1, Err, String>)
def Vmm.snapshot_rm source · line 338 · raw
@+vm:String -> @+name:String -> IO(Result<&1, &1, Err, String>)
def Api.prune.go source · line 343 · raw
@ns:List<&2, String> -> @+d:String -> IO(List<&2, String>)
def Api.prune.in source · line 354 · 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 365 · raw
@+vm:String -> @+keep:U32 -> IO(Result<&1, &1, Err, List<&2, String>>)
def Api.step source · line 371 · raw
@s:0x2cb44898b57f05c48f38583063e077bf/src/vmm/disksnap.Step -> IO(U32)
disksnap's steps, in order, until one fails (0, or its errno).
def Api.steps source · line 382 · raw
@ss:List<&1, 0x2cb44898b57f05c48f38583063e077bf/src/vmm/disksnap.Step> -> @+rc:U32 -> IO(U32)
def Api.copy_disks source · line 393 · 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 399 · raw
@e:Err -> Bool
def Api.snap.renamed source · line 408 · raw
@+rc:U32 -> @+info:0x2cb44898b57f05c48f38583063e077bf/src/vmm/snapdir.Info -> @+dst:String -> Result<&1, &1, Err, 0x2cb44898b57f05c48f38583063e077bf/src/vmm/snapdir.Info>
def Api.snap.place source · line 413 · raw
@ok:Bool -> @+rc:U32 -> @+d:String -> @+name:String -> @+note:String -> @+t:U32 -> @+tmp:String -> IO(Result<&1, &1, Err, 0x2cb44898b57f05c48f38583063e077bf/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 434 · raw
@stopped:Bool -> @+e:Err -> @+d:String -> @+name:String -> @+note:String -> @+t:U32 -> @+tmp:String -> IO(Result<&1, &1, Err, 0x2cb44898b57f05c48f38583063e077bf/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 445 · raw
@r:Result<&1, &1, Err, String> -> @+d:String -> @+name:String -> @+note:String -> @+t:U32 -> @+tmp:String -> IO(Result<&1, &1, Err, 0x2cb44898b57f05c48f38583063e077bf/src/vmm/snapdir.Info>)
def Api.snap.take source · line 452 · raw
@+d:String -> @+name:String -> @+note:String -> @+t:U32 -> IO(Result<&1, &1, Err, 0x2cb44898b57f05c48f38583063e077bf/src/vmm/snapdir.Info>)
def Api.snap.check source · line 461 · raw
@valid:Bool -> @exists:Bool -> @+d:String -> @+name:String -> @+note:String -> @+t:U32 -> IO(Result<&1, &1, Err, 0x2cb44898b57f05c48f38583063e077bf/src/vmm/snapdir.Info>)
def Api.snap.in source · line 473 · raw
@none:Bool -> @+d:String -> @+base:String -> @+gen:Bool -> @+note:String -> @+t:U32 -> IO(Result<&1, &1, Err, 0x2cb44898b57f05c48f38583063e077bf/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 487 · raw
@+vm:String -> @+name0:String -> @+note:String -> IO(Result<&1, &1, Err, 0x2cb44898b57f05c48f38583063e077bf/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 496 · raw
@+vm:String -> @+note:String -> IO(Result<&1, &1, Err, 0x2cb44898b57f05c48f38583063e077bf/src/vmm/snapdir.Info>)
The snapshot a restore takes first (Sname.undo, unique).
def Api.create.go source · line 505 · 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 515 · raw
@+dir:String -> @+flags:List<&2, String> -> IO(Result<&1, &1, Err, String>)
def vmdir.undo_said source · line 521 · raw
@r:Result<&1, &1, Err, 0x2cb44898b57f05c48f38583063e077bf/src/vmm/snapdir.Info> -> IO(Unit)
The command line's commands: their results printed (host/main.bend's cli)
def cli.kib source · line 528 · raw
@+k:U32 -> String
def cli.info source · line 531 · raw
@i:0x2cb44898b57f05c48f38583063e077bf/src/vmm/snapdir.Info -> String
def cli.infos source · line 537 · raw
@xs:List<&2, 0x2cb44898b57f05c48f38583063e077bf/src/vmm/snapdir.Info> -> IO(Unit)
def cli.lines source · line 546 · raw
@xs:List<&2, String> -> @+pre:String -> IO(Unit)
def cli.die source · line 555 · raw
@e:Err -> IO(Unit)
def cli.text source · line 558 · raw
@r:Result<&1, &1, Err, String> -> @+pre:String -> IO(Unit)
def cli.snap source · line 565 · raw
@r:Result<&1, &1, Err, 0x2cb44898b57f05c48f38583063e077bf/src/vmm/snapdir.Info> -> IO(Unit)
def cli.snaps source · line 572 · raw
@r:Result<&1, &1, Err, List<&2, 0x2cb44898b57f05c48f38583063e077bf/src/vmm/snapdir.Info>> -> IO(Unit)
def cli.names source · line 579 · raw
@r:Result<&1, &1, Err, List<&2, String>> -> IO(Unit)
def cli.status source · line 586 · raw
@r:Result<&1, &1, Err, Status> -> IO(Unit)
def cli.created source · line 593 · raw
@r:Result<&1, &1, Err, String> -> IO(Unit)
def cli.ctl source · line 600 · raw
@+vm:String -> @+line:String -> IO(Unit)
def cli.none source · line 604 · raw
@s:0x2cb44898b57f05c48f38583063e077bf/src/vmm/cmds.Sub -> Bool
def die_if source · line 614 · raw
@bad:Bool -> @what:String -> IO(Unit)
def vmdir.sock source · line 620 · raw
@+dir:String -> String
def vmdir.stopped source · line 630 · raw
@st:Result<&1, &1, Err, Status> -> Bool
def vmdir.wait_stop source · line 638 · raw
@fuel:Nat -> @+vm:String -> IO(Unit)
Waits (at most fuel x 100 ms) for the VM to stop.
def Spr.punch source · line 682 · raw
@+id:U32 -> @rg:Pair(0x2cb44898b57f05c48f38583063e077bf/src/lib/u64.U64, 0x2cb44898b57f05c48f38583063e077bf/src/lib/u64.U64) -> IO(0x2cb44898b57f05c48f38583063e077bf/src/lib/u64.U64)
def Spr.runs source · line 689 · raw
@rs:List<&2, 0x2cb44898b57f05c48f38583063e077bf/src/disk/ext4free.Run> -> @+id:U32 -> @+f:0x2cb44898b57f05c48f38583063e077bf/src/disk/ext4free.Fs -> @+acc:0x2cb44898b57f05c48f38583063e077bf/src/lib/u64.U64 -> IO(0x2cb44898b57f05c48f38583063e077bf/src/lib/u64.U64)
Group g's free runs punched; the bytes freed so far.
def Spr.group source · line 698 · raw
@m:Maybe<&2, U32> -> @+id:U32 -> @+f:0x2cb44898b57f05c48f38583063e077bf/src/disk/ext4free.Fs -> @+g:U32 -> IO(0x2cb44898b57f05c48f38583063e077bf/src/lib/u64.U64)
def Spr.groups source · line 707 · raw
@fuel:Nat -> @+id:U32 -> @+f:0x2cb44898b57f05c48f38583063e077bf/src/disk/ext4free.Fs -> @+ds:List<&2, U32> -> @+g:U32 -> @+acc:0x2cb44898b57f05c48f38583063e077bf/src/lib/u64.U64 -> IO(0x2cb44898b57f05c48f38583063e077bf/src/lib/u64.U64)
def Spr.fs.go source · line 717 · raw
@+id:U32 -> @+f:0x2cb44898b57f05c48f38583063e077bf/src/disk/ext4free.Fs -> IO(0x2cb44898b57f05c48f38583063e077bf/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 722 · raw
@+n:0x2cb44898b57f05c48f38583063e077bf/src/lib/u64.U64 -> String
def Spr.at source · line 725 · raw
@+base:0x2cb44898b57f05c48f38583063e077bf/src/lib/u64.U64 -> String
def Spr.fs source · line 728 · raw
@+id:U32 -> @+base:0x2cb44898b57f05c48f38583063e077bf/src/lib/u64.U64 -> IO(String)
def Spr.bases source · line 736 · raw
@bs:List<&2, 0x2cb44898b57f05c48f38583063e077bf/src/lib/u64.U64> -> @+id:U32 -> IO(String)
def Spr.gpt.entries source · line 746 · raw
@+id:U32 -> @t:0x2cb44898b57f05c48f38583063e077bf/src/disk/ext4free.GptTab -> IO(List<&2, 0x2cb44898b57f05c48f38583063e077bf/src/lib/u64.U64>)
def Spr.gpt source · line 754 · raw
@+id:U32 -> @gpt:Bool -> IO(List<&2, 0x2cb44898b57f05c48f38583063e077bf/src/lib/u64.U64>)
The partitions: an MBR's, or a GPT's (its header at sector 1).
def Spr.image.go source · line 763 · raw
@+id:U32 -> @+path:String -> IO(String)
def Spr.image source · line 773 · raw
@+path:String -> IO(String)
def Spr.images source · line 778 · raw
@ps:List<&2, String> -> IO(String)
def Spr.paths source · line 789 · raw
@ds:List<&1, 0x2cb44898b57f05c48f38583063e077bf/src/vmm/disksnap.DiskAt> -> List<&2, String>
The images named, or the writable --disk images of the VM folder.
def Vmm.sparsify source · line 798 · raw
@+vm:String -> @+paths:List<&2, String> -> IO(String)
def cli.sparsified.go source · line 803 · raw
@+t:String -> IO(Unit)
def cli.sparsified source · line 806 · raw
@t:String -> IO(Unit)
def Fs.mkdir_p.ok source · line 842 · 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 845 · raw
@dirs:List<&2, String> -> @+mode:U32 -> @+prev:U32 -> IO(U32)
def Fs.mkdir_p source · line 854 · raw
@+path:String -> @+mode:U32 -> IO(U32)
def Fs.facts source · line 857 · raw
@+path:String -> IO(0x2cb44898b57f05c48f38583063e077bf/src/vmm/hostfiles.Facts)
def Fs.set_mtime source · line 862 · raw
@+path:String -> @t:0x2cb44898b57f05c48f38583063e077bf/src/lib/u64.U64 -> IO(U32)
def Fs.fsync source · line 869 · raw
@+path:String -> IO(U32)
Writes path's data to the disk (a file), or its entries (a directory, as after a rename into it): a publish that survives a crash.
def Fs.fsync_dir source · line 872 · raw
@+path:String -> IO(U32)
def Fs.chmod source · line 875 · raw
@+path:String -> @+mode:U32 -> IO(U32)
def Fs.no_symlinks.go source · line 882 · raw
@dirs:List<&2, String> -> @+ok:Bool -> IO(Bool)
True when no directory along path, nor path itself, is a symlink (each looked at with lstat, outermost first; a part not there yet is no symlink). A check before acting, so a path someone can change between the check and the act is no stronger than its directories' permissions.
def Fs.no_symlinks source · line 891 · raw
@+path:String -> IO(Bool)
Unsafe
unsafe Vmm.run_dir source · line 624 · 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 650 · 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 663 · 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 809 · raw
@run:(@_:List<&1, String> -> @_:List<&1, String> -> IO(Unit)) -> @+prog:List<&1, String> -> @s:0x2cb44898b57f05c48f38583063e077bf/src/vmm/cmds.Sub -> IO(Unit)