Skip to content

Commit

Permalink
neonvm-runner: explicit panic on unsupported arch
Browse files Browse the repository at this point in the history
Replace if-else statements with switch statements
with default panic case while handling cfg.architecture

Signed-off-by: Mikhail Sakhnov <[email protected]>
  • Loading branch information
mikhail-sakhnov committed Dec 12, 2024
1 parent 3580b7c commit d91a813
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions neonvm-runner/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -951,18 +951,20 @@ func buildQEMUCmd(
}
qemuCmd = append(qemuCmd, "-drive", fmt.Sprintf("id=%s,file=%s,if=virtio,media=disk,%s,discard=unmap", swapName, dPath, cfg.diskCacheSettings))
}

if cfg.architecture == architectureArm64 {
switch cfg.architecture {
case architectureArm64:
// add custom firmware to have ACPI working
qemuCmd = append(qemuCmd, "-bios", "/vm/QEMU_EFI_ARM.fd")
// arm virt has only one UART, setup virtio-serial to add more /dev/hvcX
qemuCmd = append(qemuCmd,
"-chardev", "stdio,id=virtio-console",
"-device", "virtconsole,chardev=virtio-console",
)
} else {
case architectureAmd64:
// on amd we have multiple UART ports so we can just use serial stdio
qemuCmd = append(qemuCmd, "-serial", "stdio")
default:
logger.Fatal("unsupported architecture", zap.String("architecture", cfg.architecture))
}

for _, disk := range vmSpec.Disks {
Expand Down Expand Up @@ -1072,7 +1074,7 @@ func buildQEMUCmd(
qemuCmd = append(
qemuCmd,
"-kernel", cfg.kernelPath,
"-append", makeKernelCmdline(cfg, vmSpec, vmStatus, hostname),
"-append", makeKernelCmdline(cfg, logger, vmSpec, vmStatus, hostname),
)

// should runner receive migration ?
Expand All @@ -1089,7 +1091,7 @@ const (
kernelCmdlineVirtioMemTmpl = "memhp_default_state=online memory_hotplug.online_policy=auto-movable memory_hotplug.auto_movable_ratio=%s"
)

func makeKernelCmdline(cfg *Config, vmSpec *vmv1.VirtualMachineSpec, vmStatus *vmv1.VirtualMachineStatus, hostname string) string {
func makeKernelCmdline(cfg *Config, logger *zap.Logger, vmSpec *vmv1.VirtualMachineSpec, vmStatus *vmv1.VirtualMachineStatus, hostname string) string {
cmdlineParts := []string{baseKernelCmdline}

switch cfg.memoryProvider {
Expand Down Expand Up @@ -1118,13 +1120,16 @@ func makeKernelCmdline(cfg *Config, vmSpec *vmv1.VirtualMachineSpec, vmStatus *v
cmdlineParts = append(cmdlineParts, fmt.Sprintf("maxcpus=%d", vmSpec.Guest.CPUs.Min.RoundedUp()))
}

if cfg.architecture == architectureArm64 {
switch cfg.architecture {
case architectureArm64:
// explicitly enable acpi if we run on arm
cmdlineParts = append(cmdlineParts, "acpi=on")
// use virtio-serial device kernel console
cmdlineParts = append(cmdlineParts, "console=hvc0")
} else {
case architectureAmd64:
cmdlineParts = append(cmdlineParts, "console=ttyS1")
default:
logger.Fatal("unsupported architecture", zap.String("architecture", cfg.architecture))
}

return strings.Join(cmdlineParts, " ")
Expand Down

0 comments on commit d91a813

Please sign in to comment.