diff --git a/pkg/katautils/config-settings.go b/pkg/katautils/config-settings.go index 7c13339552..673aa4b10b 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 = "" 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 64ee309855..187f7c4405 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.Path == "" { + p = defaultHypervisorCtlPath + } + + return ResolvePath(p) +} + func (h hypervisor) kernel() (string, error) { p := h.Kernel @@ -602,6 +614,91 @@ 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 + } + + machineAccelerators := h.machineAccelerators() + kernelParams := h.kernelParams() + machineType := h.machineType() + + blockDriver, err := h.blockDeviceDriver() + if err != nil { + return vc.HypervisorConfig{}, err + } + + useVSock := false + if h.useVSock() { + if utils.SupportsVsocks() { + kataUtilsLogger.Info("vsock supported") + useVSock = true + } else { + kataUtilsLogger.Warn("No vsock support, falling back to legacy serial port") + } + } + + //TODO: Need to trim this config specific to ACRN + return vc.HypervisorConfig{ + HypervisorPath: hypervisor, + KernelPath: kernel, + ImagePath: image, + HypervisorCtlPath: hypervisorctl, + FirmwarePath: firmware, + MachineAccelerators: machineAccelerators, + KernelParams: vc.DeserializeParams(strings.Fields(kernelParams)), + HypervisorMachineType: machineType, + NumVCPUs: h.defaultVCPUs(), + DefaultMaxVCPUs: h.defaultMaxVCPUs(), + MemorySize: h.defaultMemSz(), + MemSlots: h.defaultMemSlots(), + EntropySource: h.GetEntropySource(), + DefaultBridges: h.defaultBridges(), + DisableBlockDeviceUse: h.DisableBlockDeviceUse, + MemPrealloc: h.MemPrealloc, + HugePages: h.HugePages, + Mlock: !h.Swap, + Debug: h.Debug, + DisableNestingChecks: h.DisableNestingChecks, + BlockDeviceDriver: blockDriver, + BlockDeviceCacheSet: h.BlockDeviceCacheSet, + BlockDeviceCacheDirect: h.BlockDeviceCacheDirect, + BlockDeviceCacheNoflush: h.BlockDeviceCacheNoflush, + EnableIOThreads: h.EnableIOThreads, + Msize9p: h.msize9p(), + UseVSock: useVSock, + HotplugVFIOOnRootBus: h.HotplugVFIOOnRootBus, + DisableVhostNet: h.DisableVhostNet, + GuestHookPath: h.guestHookPath(), + }, nil +} + func newFactoryConfig(f factory) (oci.FactoryConfig, error) { if f.TemplatePath == "" { f.TemplatePath = defaultTemplatePath @@ -642,11 +739,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 266c409838..dc12130cbd 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" ) @@ -198,6 +201,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