~/bend-docscommunity

host/api.bend relies on unsafe/foreign

raw source on the hub · import 0xcc60967bebc4a874a86f388a1bbb7c9c/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.disk_kib source · line 254 · 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 267 · raw

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

A snapshot's info with what its disks hold now: a copy cloned from the disk shares nearly all of it at first and takes more as the disk moves on (the space removing the snapshot gives back).

def Api.infos source · line 272 · raw

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

def Api.no_dir source · line 285 · raw

Err

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

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

The VM's snapshots, oldest first.

def Vmm.snapshots source · line 299 · raw

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

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

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

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

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

def Vmm.snapshot_rm source · line 322 · raw

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

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

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

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

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

def Api.step source · line 355 · raw

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

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

def Api.steps source · line 366 · raw

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

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

@e:Err -> Bool

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

def vmdir.undo_said source · line 505 · raw

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

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

def cli.kib source · line 512 · raw

@+k:U32 -> String

def cli.info source · line 515 · raw

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

def cli.infos source · line 521 · raw

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

def cli.lines source · line 530 · raw

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

def cli.die source · line 539 · raw

@e:Err -> IO(Unit)

def cli.text source · line 542 · raw

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

def cli.snap source · line 549 · raw

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

def cli.snaps source · line 556 · raw

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

def cli.names source · line 563 · raw

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

def cli.status source · line 570 · raw

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

def cli.created source · line 577 · raw

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

def cli.ctl source · line 584 · raw

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

def cli.none source · line 588 · raw

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

def die_if source · line 598 · raw

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

def vmdir.sock source · line 604 · raw

@+dir:String -> String

def vmdir.stopped source · line 614 · raw

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

def vmdir.wait_stop source · line 622 · 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 608 · 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 634 · 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 647 · 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 662 · raw

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