~/bend-docscommunity

host/api.bend relies on unsafe/foreign

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

9 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

Types

type Err source · line 22 · 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 53 · raw

Data

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

type Vm source · line 58 · 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 32 · raw

@e:Err -> String

def Api.fail source · line 61 · raw

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

def Api.done source · line 64 · raw

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

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

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

def Api.vm source · line 71 · raw

@+path:String -> IO(Vm)

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

def Api.sock source · line 76 · raw

@v:Vm -> String

def Api.dir source · line 81 · raw

@v:Vm -> String

def Api.read.got source · line 87 · 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 98 · raw

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

def Api.read source · line 107 · raw

@path:String -> IO(String)

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

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

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

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

def Api.write source · line 132 · raw

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

def Api.chars source · line 137 · raw

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

def Api.reply source · line 146 · 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 155 · raw

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

def Vmm.ctl source · line 161 · 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 166 · raw

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

def Vmm.resume source · line 169 · raw

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

def Vmm.stop source · line 173 · 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 176 · raw

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

def Api.conf source · line 180 · 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 185 · raw

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

def Vmm.status source · line 210 · 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 221 · raw

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

def Api.has source · line 229 · raw

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

def Api.rm_files source · line 237 · 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 246 · raw

@+dir:String -> IO(U32)

def Api.infos source · line 252 · raw

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

def Api.no_dir source · line 262 · raw

Err

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

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

The VM's snapshots, oldest first.

def Vmm.snapshots source · line 276 · raw

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

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

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

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

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

def Vmm.snapshot_rm source · line 299 · raw

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

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

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

def Api.prune.in source · line 315 · 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 326 · raw

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

def Api.step source · line 332 · raw

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

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

def Api.steps source · line 343 · raw

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

def Api.copy_disks source · line 354 · 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 360 · raw

@e:Err -> Bool

def Api.disk_kib source · line 369 · raw

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

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

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

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

@ok:Bool -> @+rc:U32 -> @+d:String -> @+name:String -> @+note:String -> @+t:U32 -> @+tmp:String -> IO(Result<&1, &1, Err, 0x52665ac86ffabb948213a4975b350ccb/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 405 · raw

@stopped:Bool -> @+e:Err -> @+d:String -> @+name:String -> @+note:String -> @+t:U32 -> @+tmp:String -> IO(Result<&1, &1, Err, 0x52665ac86ffabb948213a4975b350ccb/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 416 · raw

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

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

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

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

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

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

@none:Bool -> @+d:String -> @+base:String -> @+gen:Bool -> @+note:String -> @+t:U32 -> IO(Result<&1, &1, Err, 0x52665ac86ffabb948213a4975b350ccb/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 458 · raw

@+vm:String -> @+name0:String -> @+note:String -> IO(Result<&1, &1, Err, 0x52665ac86ffabb948213a4975b350ccb/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 467 · raw

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

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

def Api.create.go source · line 476 · 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 486 · raw

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

def vmdir.undo_said source · line 492 · raw

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

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

def cli.kib source · line 499 · raw

@+k:U32 -> String

def cli.info source · line 502 · raw

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

def cli.infos source · line 508 · raw

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

def cli.lines source · line 517 · raw

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

def cli.die source · line 526 · raw

@e:Err -> IO(Unit)

def cli.text source · line 529 · raw

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

def cli.snap source · line 536 · raw

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

def cli.snaps source · line 543 · raw

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

def cli.names source · line 550 · raw

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

def cli.status source · line 557 · raw

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

def cli.created source · line 564 · raw

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

def cli.ctl source · line 571 · raw

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

def cli.none source · line 575 · raw

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

def die_if source · line 585 · raw

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

def vmdir.sock source · line 591 · raw

@+dir:String -> String

def vmdir.stopped source · line 601 · raw

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

def vmdir.wait_stop source · line 609 · raw

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

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

Unsafe

unsafe Vmm.run_dir source · line 595 · 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 621 · 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 634 · 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 649 · raw

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