aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-08-20 01:11:24 +0900
committerOphestra <cat@gensokyo.uk>2025-08-20 01:11:24 +0900
commit339e4080dce73d372f6111773066b9c84308b6b7 (patch)
tree2dc656d1c9d1dfa2deee58eb9518842e64eface8
parente0533aaa684ecdc80c6542233570c30f0fcec06a (diff)
container/ops: move Op type to init file
This helps with the eventual separation of all setup ops into individual files. Signed-off-by: Ophestra <cat@gensokyo.uk>
-rw-r--r--container/init.go34
-rw-r--r--container/ops.go30
2 files changed, 34 insertions, 30 deletions
diff --git a/container/init.go b/container/init.go
index 0f888fad..d516a3c2 100644
--- a/container/init.go
+++ b/container/init.go
@@ -9,6 +9,7 @@ import (
"os/signal"
"path"
"runtime"
+ "slices"
"strconv"
. "syscall"
"time"
@@ -37,6 +38,39 @@ const (
setupEnv = "HAKUREI_SETUP"
)
+type (
+ // Ops is a collection of [Op].
+ Ops []Op
+
+ // Op is a generic setup step ran inside the container init.
+ // Implementations of this interface are sent as a stream of gobs.
+ Op interface {
+ // early is called in host root.
+ early(state *setupState) error
+ // apply is called in intermediate root.
+ apply(state *setupState) error
+
+ prefix() string
+ Is(op Op) bool
+ fmt.Stringer
+ }
+
+ // setupState persists context between Ops.
+ setupState struct {
+ nonrepeatable uintptr
+ *Params
+ }
+)
+
+// Grow grows the slice Ops points to using [slices.Grow].
+func (f *Ops) Grow(n int) { *f = slices.Grow(*f, n) }
+
+const (
+ nrAutoEtc = 1 << iota
+ nrAutoRoot
+)
+
+// initParams are params passed from parent.
type initParams struct {
Params
diff --git a/container/ops.go b/container/ops.go
index a08a12ff..f67968bb 100644
--- a/container/ops.go
+++ b/container/ops.go
@@ -24,36 +24,6 @@ const (
intermediatePatternTmpfile = "tmp.*"
)
-const (
- nrAutoEtc = 1 << iota
- nrAutoRoot
-)
-
-type (
- Ops []Op
-
- // Op is a generic setup step ran inside the container init.
- // Implementations of this interface are sent as a stream of gobs.
- Op interface {
- // early is called in host root.
- early(state *setupState) error
- // apply is called in intermediate root.
- apply(state *setupState) error
-
- prefix() string
- Is(op Op) bool
- fmt.Stringer
- }
-
- setupState struct {
- nonrepeatable uintptr
- *Params
- }
-)
-
-// Grow grows the slice Ops points to using [slices.Grow].
-func (f *Ops) Grow(n int) { *f = slices.Grow(*f, n) }
-
func init() { gob.Register(new(RemountOp)) }
// Remount appends an [Op] that applies [RemountOp.Flags] on container path [RemountOp.Target].