mirror of
https://github.com/getcompanion-ai/computer-host.git
synced 2026-04-15 12:03:48 +00:00
feat: nvme disk on m6
This commit is contained in:
parent
54a4c423a6
commit
eb9d2a76df
9 changed files with 240 additions and 22 deletions
|
|
@ -66,9 +66,8 @@ func configureMachine(ctx context.Context, client *apiClient, paths machinePaths
|
|||
return nil
|
||||
}
|
||||
|
||||
func launchJailedFirecracker(paths machinePaths, machineID MachineID, firecrackerBinaryPath string, jailerBinaryPath string) (*exec.Cmd, error) {
|
||||
command := exec.Command(
|
||||
jailerBinaryPath,
|
||||
func launchJailedFirecracker(paths machinePaths, machineID MachineID, firecrackerBinaryPath string, jailerBinaryPath string, enablePCI bool) (*exec.Cmd, error) {
|
||||
args := []string{
|
||||
"--id", string(machineID),
|
||||
"--uid", strconv.Itoa(os.Getuid()),
|
||||
"--gid", strconv.Itoa(os.Getgid()),
|
||||
|
|
@ -83,7 +82,11 @@ func launchJailedFirecracker(paths machinePaths, machineID MachineID, firecracke
|
|||
"--level", defaultFirecrackerLogLevel,
|
||||
"--show-level",
|
||||
"--show-log-origin",
|
||||
)
|
||||
}
|
||||
if enablePCI {
|
||||
args = append(args, "--enable-pci")
|
||||
}
|
||||
command := exec.Command(jailerBinaryPath, args...)
|
||||
if err := command.Start(); err != nil {
|
||||
return nil, fmt.Errorf("start jailer: %w", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ func TestLaunchJailedFirecrackerPassesDaemonAndLoggingFlags(t *testing.T) {
|
|||
t.Fatalf("create log dir: %v", err)
|
||||
}
|
||||
|
||||
if _, err := launchJailedFirecracker(paths, "vm-1", "/usr/bin/firecracker", jailerPath); err != nil {
|
||||
if _, err := launchJailedFirecracker(paths, "vm-1", "/usr/bin/firecracker", jailerPath, false); err != nil {
|
||||
t.Fatalf("launch jailed firecracker: %v", err)
|
||||
}
|
||||
|
||||
|
|
@ -45,6 +45,33 @@ func TestLaunchJailedFirecrackerPassesDaemonAndLoggingFlags(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestLaunchJailedFirecrackerPassesEnablePCIWhenConfigured(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
argsPath := filepath.Join(root, "args.txt")
|
||||
jailerPath := filepath.Join(root, "fake-jailer.sh")
|
||||
script := "#!/bin/sh\nprintf '%s\n' \"$@\" > " + shellQuote(argsPath) + "\n"
|
||||
if err := os.WriteFile(jailerPath, []byte(script), 0o755); err != nil {
|
||||
t.Fatalf("write fake jailer: %v", err)
|
||||
}
|
||||
|
||||
paths, err := buildMachinePaths(root, "vm-1", "/usr/bin/firecracker")
|
||||
if err != nil {
|
||||
t.Fatalf("build machine paths: %v", err)
|
||||
}
|
||||
if err := os.MkdirAll(paths.LogDir, 0o755); err != nil {
|
||||
t.Fatalf("create log dir: %v", err)
|
||||
}
|
||||
|
||||
if _, err := launchJailedFirecracker(paths, "vm-1", "/usr/bin/firecracker", jailerPath, true); err != nil {
|
||||
t.Fatalf("launch jailed firecracker: %v", err)
|
||||
}
|
||||
|
||||
args := waitForFileContents(t, argsPath)
|
||||
if !containsLine(args, "--enable-pci") {
|
||||
t.Fatalf("missing launch argument %q in %v", "--enable-pci", args)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWaitForPIDFileReadsPID(t *testing.T) {
|
||||
pidFilePath := filepath.Join(t.TempDir(), "firecracker.pid")
|
||||
if err := os.WriteFile(pidFilePath, []byte("4321\n"), 0o644); err != nil {
|
||||
|
|
|
|||
|
|
@ -24,12 +24,14 @@ type RuntimeConfig struct {
|
|||
EgressInterface string
|
||||
FirecrackerBinaryPath string
|
||||
JailerBinaryPath string
|
||||
EnablePCI bool
|
||||
}
|
||||
|
||||
type Runtime struct {
|
||||
rootDir string
|
||||
firecrackerBinaryPath string
|
||||
jailerBinaryPath string
|
||||
enablePCI bool
|
||||
networkAllocator *NetworkAllocator
|
||||
networkProvisioner NetworkProvisioner
|
||||
}
|
||||
|
|
@ -69,6 +71,7 @@ func NewRuntime(cfg RuntimeConfig) (*Runtime, error) {
|
|||
rootDir: rootDir,
|
||||
firecrackerBinaryPath: firecrackerBinaryPath,
|
||||
jailerBinaryPath: jailerBinaryPath,
|
||||
enablePCI: cfg.EnablePCI,
|
||||
networkAllocator: allocator,
|
||||
networkProvisioner: NewIPTapProvisioner(defaultNetworkCIDR, egressInterface),
|
||||
}, nil
|
||||
|
|
@ -110,7 +113,7 @@ func (r *Runtime) Boot(ctx context.Context, spec MachineSpec, usedNetworks []Net
|
|||
return nil, err
|
||||
}
|
||||
|
||||
command, err := launchJailedFirecracker(paths, spec.ID, r.firecrackerBinaryPath, r.jailerBinaryPath)
|
||||
command, err := launchJailedFirecracker(paths, spec.ID, r.firecrackerBinaryPath, r.jailerBinaryPath, r.enablePCI)
|
||||
if err != nil {
|
||||
cleanup(network, paths, nil, 0)
|
||||
return nil, err
|
||||
|
|
@ -277,7 +280,7 @@ func (r *Runtime) RestoreBoot(ctx context.Context, loadSpec SnapshotLoadSpec, us
|
|||
return nil, err
|
||||
}
|
||||
|
||||
command, err := launchJailedFirecracker(paths, loadSpec.ID, r.firecrackerBinaryPath, r.jailerBinaryPath)
|
||||
command, err := launchJailedFirecracker(paths, loadSpec.ID, r.firecrackerBinaryPath, r.jailerBinaryPath, r.enablePCI)
|
||||
if err != nil {
|
||||
cleanup(network, paths, nil, 0)
|
||||
return nil, err
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue