Add mount_actor

Synit utility for mounting file systems.
This commit is contained in:
Emery Hemingway 2023-11-29 22:22:58 +02:00
parent 72f5d04030
commit 3c8b485d32
5 changed files with 124 additions and 2 deletions

View File

@ -34,6 +34,49 @@ Do not send messages immediately to the dataspace passed `json_socket_translator
A utility for minting [Sturdyrefs](https://synit.org/book/operation/builtin/gatekeeper.html#sturdyrefs).
## mount_actor
Actor for mounting filesystems on Linux.
Sample Syndicate server script:
```
# Assert a file-system we want to mount.
<mount "/dev/sda3" "/boot" "vfat">
# Transform mount assertions into mount status observations.
? <mount ?source ?target ?fs> [
? <mount $source $target $fs _> [ ]
]
# Assert mounting succeded.
? <mount _ ?target _ #t> [
<service-state <mountpoint $target> ready>
]
# Assert mount failed.
? <mount _ ?target _ <failure _>> [
<service-state <mountpoint $target> failed>
]
# Assert the details into the machine dataspace.
? <machine-dataspace ?machine> [
$config ? <mount ?source ?target ?fs ?status> [
$machine <mount $source $target $fs $status>
]
]
# Require the mount_actor daemon.
<require-service <daemon mount_actor>>
<daemon mount_actor {
argv: ["/home/emery/src/bin/mount_actor"]
protocol: application/syndicate
}>
# Pass the daemon the config dataspace.
? <service-object <daemon mount_actor> ?cap> [
$cap { dataspace: $config }
]
```
## msg
A utility that sends messages to `$SYNDICATE_ROUTE`.

5
mountpoints.prs Normal file
View File

@ -0,0 +1,5 @@
version 1.
Mountpoint = <mount @source string @target string @type string @status Status> .
Status = Failure / #t.
Failure = <failure @msg string> .

44
src/mount_actor.nim Normal file
View File

@ -0,0 +1,44 @@
# SPDX-FileCopyrightText: ☭ Emery Hemingway
# SPDX-License-Identifier: Unlicense
## An actor for Linux file-system mounting.
when not defined(linux):
{.error: "this component only tested for Linux".}
import std/oserrors
import preserves
import syndicate, syndicate/relays
import ./schema/mountpoints
type BootArgs {.preservesDictionary.} = object
dataspace: Cap
proc mount(source, target, fsType: cstring; flags: culong; data: pointer): cint {.importc, header: "<sys/mount.h>".}
## `mount(2)`
proc umount(target: cstring): cint {.importc, header: "<sys/mount.h>".}
## `umount(2)`
runActor("mount_actor") do (turn: var Turn; root: Cap):
let
targetPat = ?Observe(pattern: !Mountpoint) ?? { 1: grabLit() }
sourcePat = ?Observe(pattern: !Mountpoint) ?? { 0: grabLit(), 2: grabLit() }
connectStdio(turn, root)
during(turn, root, ?BootArgs) do (ds: Cap):
during(turn, ds, targetPat) do (target: string):
during(turn, ds, sourcePat) do (source: string, fsType: string):
var mountpoint = Mountpoint(
source: source,
target: target,
`type`: fsType,
)
var rc = mount(source, target, fsType, 0, nil)
if rc == 0:
mountpoint.status = Status(orKind: StatusKind.true)
else:
mountpoint.status = Status(orKind: StatusKind.Failure)
mountpoint.status.failure.msg = osErrorMsg(osLastError())
discard publish(turn, ds, mountpoint)
do:
discard umount(target)

View File

@ -0,0 +1,30 @@
import
preserves
type
Failure* {.preservesRecord: "failure".} = object
`msg`*: string
Mountpoint* {.preservesRecord: "mount".} = object
`source`*: string
`target`*: string
`type`*: string
`status`*: Status
StatusKind* {.pure.} = enum
`Failure`, `true`
`Status`* {.preservesOr.} = object
case orKind*: StatusKind
of StatusKind.`Failure`:
`failure`*: Failure
of StatusKind.`true`:
`true`* {.preservesLiteral: "#t".}: bool
proc `$`*(x: Failure | Mountpoint | Status): string =
`$`(toPreserve(x))
proc encode*(x: Failure | Mountpoint | Status): seq[byte] =
encode(toPreserve(x))

View File

@ -1,11 +1,11 @@
# Package
version = "20231108"
version = "20231129"
author = "Emery Hemingway"
description = "Utilites for Syndicated Actors and Synit"
license = "unlicense"
srcDir = "src"
bin = @["cache_actor", "json_socket_translator", "json_translator", "mintsturdyref", "msg", "net_mapper", "preserve_process_environment", "syndex_card", "syndump"]
bin = @["cache_actor", "json_socket_translator", "json_translator", "mintsturdyref", "mount_actor", "msg", "net_mapper", "preserve_process_environment", "syndex_card", "syndump"]
# Dependencies