host/api.bend relies on unsafe/foreign
raw source on the hub · import 0x8cced805dd17b3296cb7aabd2fa292bb/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.status.of source · line 192 · raw
@r:Result<&1, &1, Err, String> -> @+fw:String -> Result<&1, &1, Err, Status>
def Vmm.status source · line 217 · 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 228 · raw
@xs:List<&1, String> -> List<&2, String>
def Api.has source · line 236 · raw
@xs:List<&2, String> -> @+n:String -> Bool
def Api.rm_files source · line 244 · 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 253 · raw
@+dir:String -> IO(U32)
def Api.disk_kib source · line 261 · 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 276 · raw
@i:0x8cced805dd17b3296cb7aabd2fa292bb/src/vmm/snapdir.Info -> @+mk:U32 -> @+dk:U32 -> 0x8cced805dd17b3296cb7aabd2fa292bb/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 281 · raw
@ns:List<&2, String> -> @+dir:String -> IO(List<&2, 0x8cced805dd17b3296cb7aabd2fa292bb/src/vmm/snapdir.Info>)
def Api.no_dir source · line 295 · raw
Err
def Api.snapshots.in source · line 299 · raw
@none:Bool -> @+d:String -> IO(Result<&1, &1, Err, List<&2, 0x8cced805dd17b3296cb7aabd2fa292bb/src/vmm/snapdir.Info>>)
The VM's snapshots, oldest first.
def Vmm.snapshots source · line 309 · raw
@+vm:String -> IO(Result<&1, &1, Err, List<&2, 0x8cced805dd17b3296cb7aabd2fa292bb/src/vmm/snapdir.Info>>)
def Api.rm.go source · line 314 · raw
@ok:Bool -> @+d:String -> @+name:String -> IO(Result<&1, &1, Err, String>)
def Api.rm.in source · line 323 · raw
@none:Bool -> @+d:String -> @+name:String -> IO(Result<&1, &1, Err, String>)
def Vmm.snapshot_rm source · line 332 · raw
@+vm:String -> @+name:String -> IO(Result<&1, &1, Err, String>)
def Api.prune.go source · line 337 · raw
@ns:List<&2, String> -> @+d:String -> IO(List<&2, String>)
def Api.prune.in source · line 348 · 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 359 · raw
@+vm:String -> @+keep:U32 -> IO(Result<&1, &1, Err, List<&2, String>>)
def Api.step source · line 365 · raw
@s:0x8cced805dd17b3296cb7aabd2fa292bb/src/vmm/disksnap.Step -> IO(U32)
disksnap's steps, in order, until one fails (0, or its errno).
def Api.steps source · line 376 · raw
@ss:List<&1, 0x8cced805dd17b3296cb7aabd2fa292bb/src/vmm/disksnap.Step> -> @+rc:U32 -> IO(U32)
def Api.copy_disks source · line 387 · 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 393 · raw
@e:Err -> Bool
def Api.snap.renamed source · line 402 · raw
@+rc:U32 -> @+info:0x8cced805dd17b3296cb7aabd2fa292bb/src/vmm/snapdir.Info -> @+dst:String -> Result<&1, &1, Err, 0x8cced805dd17b3296cb7aabd2fa292bb/src/vmm/snapdir.Info>
def Api.snap.place source · line 407 · raw
@ok:Bool -> @+rc:U32 -> @+d:String -> @+name:String -> @+note:String -> @+t:U32 -> @+tmp:String -> IO(Result<&1, &1, Err, 0x8cced805dd17b3296cb7aabd2fa292bb/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 428 · raw
@stopped:Bool -> @+e:Err -> @+d:String -> @+name:String -> @+note:String -> @+t:U32 -> @+tmp:String -> IO(Result<&1, &1, Err, 0x8cced805dd17b3296cb7aabd2fa292bb/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 439 · raw
@r:Result<&1, &1, Err, String> -> @+d:String -> @+name:String -> @+note:String -> @+t:U32 -> @+tmp:String -> IO(Result<&1, &1, Err, 0x8cced805dd17b3296cb7aabd2fa292bb/src/vmm/snapdir.Info>)
def Api.snap.take source · line 446 · raw
@+d:String -> @+name:String -> @+note:String -> @+t:U32 -> IO(Result<&1, &1, Err, 0x8cced805dd17b3296cb7aabd2fa292bb/src/vmm/snapdir.Info>)
def Api.snap.check source · line 455 · raw
@valid:Bool -> @exists:Bool -> @+d:String -> @+name:String -> @+note:String -> @+t:U32 -> IO(Result<&1, &1, Err, 0x8cced805dd17b3296cb7aabd2fa292bb/src/vmm/snapdir.Info>)
def Api.snap.in source · line 467 · raw
@none:Bool -> @+d:String -> @+base:String -> @+gen:Bool -> @+note:String -> @+t:U32 -> IO(Result<&1, &1, Err, 0x8cced805dd17b3296cb7aabd2fa292bb/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 481 · raw
@+vm:String -> @+name0:String -> @+note:String -> IO(Result<&1, &1, Err, 0x8cced805dd17b3296cb7aabd2fa292bb/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 490 · raw
@+vm:String -> @+note:String -> IO(Result<&1, &1, Err, 0x8cced805dd17b3296cb7aabd2fa292bb/src/vmm/snapdir.Info>)
The snapshot a restore takes first (Sname.undo, unique).
def Api.create.go source · line 499 · 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 509 · raw
@+dir:String -> @+flags:List<&2, String> -> IO(Result<&1, &1, Err, String>)
def vmdir.undo_said source · line 515 · raw
@r:Result<&1, &1, Err, 0x8cced805dd17b3296cb7aabd2fa292bb/src/vmm/snapdir.Info> -> IO(Unit)
The command line's commands: their results printed (host/main.bend's cli)
def cli.kib source · line 522 · raw
@+k:U32 -> String
def cli.info source · line 525 · raw
@i:0x8cced805dd17b3296cb7aabd2fa292bb/src/vmm/snapdir.Info -> String
def cli.infos source · line 531 · raw
@xs:List<&2, 0x8cced805dd17b3296cb7aabd2fa292bb/src/vmm/snapdir.Info> -> IO(Unit)
def cli.lines source · line 540 · raw
@xs:List<&2, String> -> @+pre:String -> IO(Unit)
def cli.die source · line 549 · raw
@e:Err -> IO(Unit)
def cli.text source · line 552 · raw
@r:Result<&1, &1, Err, String> -> @+pre:String -> IO(Unit)
def cli.snap source · line 559 · raw
@r:Result<&1, &1, Err, 0x8cced805dd17b3296cb7aabd2fa292bb/src/vmm/snapdir.Info> -> IO(Unit)
def cli.snaps source · line 566 · raw
@r:Result<&1, &1, Err, List<&2, 0x8cced805dd17b3296cb7aabd2fa292bb/src/vmm/snapdir.Info>> -> IO(Unit)
def cli.names source · line 573 · raw
@r:Result<&1, &1, Err, List<&2, String>> -> IO(Unit)
def cli.status source · line 580 · raw
@r:Result<&1, &1, Err, Status> -> IO(Unit)
def cli.created source · line 587 · raw
@r:Result<&1, &1, Err, String> -> IO(Unit)
def cli.ctl source · line 594 · raw
@+vm:String -> @+line:String -> IO(Unit)
def cli.none source · line 598 · raw
@s:0x8cced805dd17b3296cb7aabd2fa292bb/src/vmm/cmds.Sub -> Bool
def die_if source · line 608 · raw
@bad:Bool -> @what:String -> IO(Unit)
def vmdir.sock source · line 614 · raw
@+dir:String -> String
def vmdir.stopped source · line 624 · raw
@st:Result<&1, &1, Err, Status> -> Bool
def vmdir.wait_stop source · line 632 · raw
@fuel:Nat -> @+vm:String -> IO(Unit)
Waits (at most fuel x 100 ms) for the VM to stop.
def Spr.punch source · line 676 · raw
@+id:U32 -> @rg:Pair(0x8cced805dd17b3296cb7aabd2fa292bb/src/lib/u64.U64, 0x8cced805dd17b3296cb7aabd2fa292bb/src/lib/u64.U64) -> IO(0x8cced805dd17b3296cb7aabd2fa292bb/src/lib/u64.U64)
def Spr.runs source · line 683 · raw
@rs:List<&2, 0x8cced805dd17b3296cb7aabd2fa292bb/src/disk/ext4free.Run> -> @+id:U32 -> @+f:0x8cced805dd17b3296cb7aabd2fa292bb/src/disk/ext4free.Fs -> @+acc:0x8cced805dd17b3296cb7aabd2fa292bb/src/lib/u64.U64 -> IO(0x8cced805dd17b3296cb7aabd2fa292bb/src/lib/u64.U64)
Group g's free runs punched; the bytes freed so far.
def Spr.group source · line 692 · raw
@m:Maybe<&2, U32> -> @+id:U32 -> @+f:0x8cced805dd17b3296cb7aabd2fa292bb/src/disk/ext4free.Fs -> @+g:U32 -> IO(0x8cced805dd17b3296cb7aabd2fa292bb/src/lib/u64.U64)
def Spr.groups source · line 701 · raw
@fuel:Nat -> @+id:U32 -> @+f:0x8cced805dd17b3296cb7aabd2fa292bb/src/disk/ext4free.Fs -> @+ds:List<&2, U32> -> @+g:U32 -> @+acc:0x8cced805dd17b3296cb7aabd2fa292bb/src/lib/u64.U64 -> IO(0x8cced805dd17b3296cb7aabd2fa292bb/src/lib/u64.U64)
def Spr.fs.go source · line 711 · raw
@+id:U32 -> @+f:0x8cced805dd17b3296cb7aabd2fa292bb/src/disk/ext4free.Fs -> IO(0x8cced805dd17b3296cb7aabd2fa292bb/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 716 · raw
@+n:0x8cced805dd17b3296cb7aabd2fa292bb/src/lib/u64.U64 -> String
def Spr.at source · line 719 · raw
@+base:0x8cced805dd17b3296cb7aabd2fa292bb/src/lib/u64.U64 -> String
def Spr.fs source · line 722 · raw
@+id:U32 -> @+base:0x8cced805dd17b3296cb7aabd2fa292bb/src/lib/u64.U64 -> IO(String)
def Spr.bases source · line 730 · raw
@bs:List<&2, 0x8cced805dd17b3296cb7aabd2fa292bb/src/lib/u64.U64> -> @+id:U32 -> IO(String)
def Spr.gpt.entries source · line 740 · raw
@+id:U32 -> @t:0x8cced805dd17b3296cb7aabd2fa292bb/src/disk/ext4free.GptTab -> IO(List<&2, 0x8cced805dd17b3296cb7aabd2fa292bb/src/lib/u64.U64>)
def Spr.gpt source · line 748 · raw
@+id:U32 -> @gpt:Bool -> IO(List<&2, 0x8cced805dd17b3296cb7aabd2fa292bb/src/lib/u64.U64>)
The partitions: an MBR's, or a GPT's (its header at sector 1).
def Spr.image.go source · line 757 · raw
@+id:U32 -> @+path:String -> IO(String)
def Spr.image source · line 767 · raw
@+path:String -> IO(String)
def Spr.images source · line 772 · raw
@ps:List<&2, String> -> IO(String)
def Spr.paths source · line 783 · raw
@ds:List<&1, 0x8cced805dd17b3296cb7aabd2fa292bb/src/vmm/disksnap.DiskAt> -> List<&2, String>
The images named, or the writable --disk images of the VM folder.
def Vmm.sparsify source · line 792 · raw
@+vm:String -> @+paths:List<&2, String> -> IO(String)
def cli.sparsified.go source · line 797 · raw
@+t:String -> IO(Unit)
def cli.sparsified source · line 800 · raw
@t:String -> IO(Unit)
def Fs.mkdir_p.ok source · line 836 · 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 839 · raw
@dirs:List<&2, String> -> @+mode:U32 -> @+prev:U32 -> IO(U32)
def Fs.mkdir_p source · line 848 · raw
@+path:String -> @+mode:U32 -> IO(U32)
def Fs.facts source · line 851 · raw
@+path:String -> IO(0x8cced805dd17b3296cb7aabd2fa292bb/src/vmm/hostfiles.Facts)
def Fs.set_mtime source · line 856 · raw
@+path:String -> @t:0x8cced805dd17b3296cb7aabd2fa292bb/src/lib/u64.U64 -> IO(U32)
def Fs.fsync source · line 863 · 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 866 · raw
@+path:String -> IO(U32)
def Fs.chmod source · line 869 · raw
@+path:String -> @+mode:U32 -> IO(U32)
def Fs.no_symlinks.go source · line 876 · 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 885 · raw
@+path:String -> IO(Bool)
Unsafe
unsafe Vmm.run_dir source · line 618 · 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 644 · 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 657 · 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 803 · raw
@run:(@_:List<&1, String> -> @_:List<&1, String> -> IO(Unit)) -> @+prog:List<&1, String> -> @s:0x8cced805dd17b3296cb7aabd2fa292bb/src/vmm/cmds.Sub -> IO(Unit)