container/ops: move Op type to init file
All checks were successful
Test / Create distribution (push) Successful in 34s
Test / Sandbox (push) Successful in 2m17s
Test / Hakurei (push) Successful in 3m9s
Test / Hpkg (push) Successful in 4m8s
Test / Sandbox (race detector) (push) Successful in 4m22s
Test / Hakurei (race detector) (push) Successful in 5m2s
Test / Flake checks (push) Successful in 1m28s

This helps with the eventual separation of all setup ops into individual files.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
Ophestra 2025-08-20 01:11:24 +09:00
parent e0533aaa68
commit 339e4080dc
Signed by: cat
SSH Key Fingerprint: SHA256:gQ67O0enBZ7UdZypgtspB2FDM1g3GVw8nX0XSdcFw8Q
2 changed files with 34 additions and 30 deletions

View File

@ -9,6 +9,7 @@ import (
"os/signal" "os/signal"
"path" "path"
"runtime" "runtime"
"slices"
"strconv" "strconv"
. "syscall" . "syscall"
"time" "time"
@ -37,6 +38,39 @@ const (
setupEnv = "HAKUREI_SETUP" 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 { type initParams struct {
Params Params

View File

@ -24,36 +24,6 @@ const (
intermediatePatternTmpfile = "tmp.*" 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)) } func init() { gob.Register(new(RemountOp)) }
// Remount appends an [Op] that applies [RemountOp.Flags] on container path [RemountOp.Target]. // Remount appends an [Op] that applies [RemountOp.Flags] on container path [RemountOp.Target].