Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
pkg/katautils: Add support for ACRN hypervisor config
Browse files Browse the repository at this point in the history
This patch adds support for,
1. Extracting and configuring ACRN hypervisor from toml.
2. Add ACRN hypervisor ctl for controlling ACRN hypervisor.
This will be used for updating virtio-blk based
container rootfs using blk rescan feature.

Fixes: #1778

Signed-off-by: Vijay Dhanraj <[email protected]>
  • Loading branch information
vijaydhanraj committed Jun 9, 2019
1 parent 3f62180 commit 9df39c6
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/katautils/config-settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
101 changes: 101 additions & 0 deletions pkg/katautils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const (
// supported hypervisor component types
firecrackerHypervisorTableType = "firecracker"
qemuHypervisorTableType = "qemu"
acrnHypervisorTableType = "acrn"

// supported proxy component types
kataProxyTableType = "kata"
Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
6 changes: 6 additions & 0 deletions virtcontainers/hypervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9df39c6

Please sign in to comment.