From 4919a5ef4913700b9294b6331786d36b5316afc5 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Tue, 3 Nov 2026 16:58:18 +0900 Subject: cmd/earlyinit: optionally mount host directory Useful for sharing a directory during integration testing. Signed-off-by: Ophestra --- cmd/earlyinit/main.go | 16 ++++++++++++++ cmd/earlyinit/modprobe.go | 53 ++++++++++++++++++++++++++--------------------- 2 files changed, 45 insertions(+), 24 deletions(-) (limited to 'cmd') diff --git a/cmd/earlyinit/main.go b/cmd/earlyinit/main.go index 30588067..f0baa265 100644 --- a/cmd/earlyinit/main.go +++ b/cmd/earlyinit/main.go @@ -96,6 +96,8 @@ const ( flagNoRecover = "no_recover" // flagMountTmp arranges for /tmp/ to be made available. flagMountTmp = "mount_tmp" + // flag9P arranges for a host directory to be mounted at /host/. + flag9P = "9p" ) func main() { @@ -265,6 +267,20 @@ func main() { mustMountSystem(ctx, s, devpath) } + if slices.Contains(flags, flag9P) { + // avoid having to wait for the uevent loop + modprobe("-a", "9p", "9pnet_virtio", "virtio_pci") + + must(os.Mkdir("/host/", 0)) + mustSyscall("mount host directory", Mount( + "rosa", + "/host/", + "9p", + MS_NOSUID|MS_NODEV, + "trans=virtio", + )) + } + // after top level has been set up mustSyscall("remount root", Mount( "", diff --git a/cmd/earlyinit/modprobe.go b/cmd/earlyinit/modprobe.go index 8194c150..a7d1546f 100644 --- a/cmd/earlyinit/modprobe.go +++ b/cmd/earlyinit/modprobe.go @@ -15,10 +15,10 @@ import ( // ModprobeError describes an unsuccessful modprobe invocation. type ModprobeError struct { - ModAlias string `json:"modalias"` - Stdout string `json:"stdout"` - Stderr string `json:"stderr"` - ExitCode int `json:"exit_code"` + Args []string `json:"args"` + Stdout string `json:"stdout"` + Stderr string `json:"stderr"` + ExitCode int `json:"exit_code"` } var _ report.RepresentableError = ModprobeError{} @@ -32,6 +32,30 @@ func (e ModprobeError) Error() string { ) } +// modprobe invokes /system/sbin/modprobe and dispatches an error on failure. +func modprobe(arg ...string) { + stdout, err := exec.Command("/system/sbin/modprobe", arg...).Output() + if err == nil { + if len(stdout) > 0 { + log.Println(string(stdout)) + } + return + } + + exitError, ok := errors.AsType[*exec.ExitError](err) + if !ok || exitError == nil { + r.Dispatch(report.Degraded, "invoke modprobe", err) + return + } + + r.Dispatch(report.Trivial, "load device driver", ModprobeError{ + Args: arg, + Stdout: string(stdout), + Stderr: string(exitError.Stderr), + ExitCode: exitError.ExitCode(), + }) +} + // dispatchModprobe invokes modprobe for [uevent.KOBJ_ADD] events raising new // MODALIAS strings. func dispatchModprobe( @@ -50,25 +74,6 @@ func dispatchModprobe( }() for alias := range aliases { - stdout, err := exec.Command("/system/sbin/modprobe", alias).Output() - if err == nil { - if len(stdout) > 0 { - log.Println(string(stdout)) - } - continue - } - - exitError, ok := errors.AsType[*exec.ExitError](err) - if !ok || exitError == nil { - r.Dispatch(report.Degraded, "invoke modprobe", err) - continue - } - - r.Dispatch(report.Trivial, "load device driver", ModprobeError{ - ModAlias: alias, - Stdout: string(stdout), - Stderr: string(exitError.Stderr), - ExitCode: exitError.ExitCode(), - }) + modprobe(alias) } } -- cgit v1.3.1