diff --git a/pkg/katautils/config-settings.go b/pkg/katautils/config-settings.go index 7c1333955..ac3c44c99 100644 --- a/pkg/katautils/config-settings.go +++ b/pkg/katautils/config-settings.go @@ -9,6 +9,7 @@ package katautils var defaultHypervisorPath = "/usr/bin/qemu-lite-system-x86_64" +var defaultHypervisorCtlPath = "/usr/bin/acrnctl" var defaultImagePath = "/usr/share/kata-containers/kata-containers.img" var defaultKernelPath = "/usr/share/kata-containers/vmlinuz.container" var defaultInitrdPath = "/usr/share/kata-containers/kata-containers-initrd.img" diff --git a/pkg/katautils/config.go b/pkg/katautils/config.go index 64ee30985..a7faacf31 100644 --- a/pkg/katautils/config.go +++ b/pkg/katautils/config.go @@ -50,6 +50,7 @@ const ( // supported hypervisor component types firecrackerHypervisorTableType = "firecracker" qemuHypervisorTableType = "qemu" + acrnHypervisorTableType = "acrn" // supported proxy component types kataProxyTableType = "kata" @@ -84,6 +85,7 @@ type factory struct { type hypervisor struct { Path string `toml:"path"` Kernel string `toml:"kernel"` + CtlPath string `toml:"ctlpath"` Initrd string `toml:"initrd"` Image string `toml:"image"` Firmware string `toml:"firmware"` @@ -163,6 +165,16 @@ func (h hypervisor) path() (string, error) { return ResolvePath(p) } +func (h hypervisor) ctlpath() (string, error) { + p := h.CtlPath + + if h.CtlPath == "" { + p = defaultHypervisorCtlPath + } + + return ResolvePath(p) +} + func (h hypervisor) kernel() (string, error) { p := h.Kernel @@ -602,6 +614,67 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) { }, nil } +func newAcrnHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) { + hypervisor, err := h.path() + if err != nil { + return vc.HypervisorConfig{}, err + } + + hypervisorctl, err := h.ctlpath() + if err != nil { + return vc.HypervisorConfig{}, err + } + + kernel, err := h.kernel() + if err != nil { + return vc.HypervisorConfig{}, err + } + + image, err := h.image() + if err != nil { + return vc.HypervisorConfig{}, err + } + + if image == "" { + return vc.HypervisorConfig{}, + errors.New("image must be defined in the configuration file") + } + + firmware, err := h.firmware() + if err != nil { + return vc.HypervisorConfig{}, err + } + + kernelParams := h.kernelParams() + + blockDriver, err := h.blockDeviceDriver() + if err != nil { + return vc.HypervisorConfig{}, err + } + + return vc.HypervisorConfig{ + HypervisorPath: hypervisor, + KernelPath: kernel, + ImagePath: image, + HypervisorCtlPath: hypervisorctl, + FirmwarePath: firmware, + KernelParams: vc.DeserializeParams(strings.Fields(kernelParams)), + NumVCPUs: h.defaultVCPUs(), + DefaultMaxVCPUs: h.defaultMaxVCPUs(), + MemorySize: h.defaultMemSz(), + MemSlots: h.defaultMemSlots(), + EntropySource: h.GetEntropySource(), + DefaultBridges: h.defaultBridges(), + HugePages: h.HugePages, + Mlock: !h.Swap, + Debug: h.Debug, + DisableNestingChecks: h.DisableNestingChecks, + BlockDeviceDriver: blockDriver, + DisableVhostNet: h.DisableVhostNet, + GuestHookPath: h.guestHookPath(), + }, nil +} + func newFactoryConfig(f factory) (oci.FactoryConfig, error) { if f.TemplatePath == "" { f.TemplatePath = defaultTemplatePath @@ -642,11 +715,15 @@ func updateRuntimeConfigHypervisor(configPath string, tomlConf tomlConfig, confi case qemuHypervisorTableType: config.HypervisorType = vc.QemuHypervisor hConfig, err = newQemuHypervisorConfig(hypervisor) + case acrnHypervisorTableType: + config.HypervisorType = vc.AcrnHypervisor + hConfig, err = newAcrnHypervisorConfig(hypervisor) } if err != nil { return fmt.Errorf("%v: %v", configPath, err) } + config.HypervisorConfig = hConfig } diff --git a/virtcontainers/hypervisor.go b/virtcontainers/hypervisor.go index 9ad51ff06..91b340748 100644 --- a/virtcontainers/hypervisor.go +++ b/virtcontainers/hypervisor.go @@ -31,6 +31,9 @@ const ( // QemuHypervisor is the QEMU hypervisor. QemuHypervisor HypervisorType = "qemu" + // AcrnHypervisor is the ACRN hypervisor. + AcrnHypervisor HypervisorType = "acrn" + // MockHypervisor is a mock hypervisor for testing purposes MockHypervisor HypervisorType = "mock" ) @@ -212,6 +215,9 @@ type HypervisorConfig struct { // HypervisorPath is the hypervisor executable host path. HypervisorPath string + // HypervisorCtlPath is the hypervisor ctl executable host path. + HypervisorCtlPath string + // BlockDeviceDriver specifies the driver to be used for block device // either VirtioSCSI or VirtioBlock with the default driver being defaultBlockDriver BlockDeviceDriver string