From b9706aa6f851af6e18fdffd333bbdbc53465ce5d Mon Sep 17 00:00:00 2001 From: Manohar Castelino Date: Wed, 5 Dec 2018 18:03:20 -0800 Subject: [PATCH] virtio-mmio: Add support for virtio-mmio Start adding support for virtio-mmio devices starting with block. The devices show within the vm as vda, vdb,... based on order of insertion and such within the VM resemble virtio-blk devices. They need to be explicitly differentiated to ensure that the agent logic within the VM can discover and mount them appropropriately. The agent uses PCI location to discover them for virtio-blk. For virtio-mmio we need to use the predicted device name for now. Signed-off-by: Manohar Castelino --- pkg/katautils/config.go | 4 ++-- virtcontainers/device/config/config.go | 3 +++ virtcontainers/device/manager/manager.go | 6 +++++- virtcontainers/hyperstart_agent.go | 3 ++- virtcontainers/kata_agent.go | 6 +++++- virtcontainers/qemu_arch_base.go | 4 ++++ 6 files changed, 21 insertions(+), 5 deletions(-) diff --git a/pkg/katautils/config.go b/pkg/katautils/config.go index ea6ce16740..46e48233ea 100644 --- a/pkg/katautils/config.go +++ b/pkg/katautils/config.go @@ -294,8 +294,8 @@ func (h hypervisor) blockDeviceDriver() (string, error) { return defaultBlockDeviceDriver, nil } - if h.BlockDeviceDriver != vc.VirtioSCSI && h.BlockDeviceDriver != vc.VirtioBlock { - return "", fmt.Errorf("Invalid value %s provided for hypervisor block storage driver, can be either %s or %s", h.BlockDeviceDriver, vc.VirtioSCSI, vc.VirtioBlock) + if h.BlockDeviceDriver != vc.VirtioSCSI && h.BlockDeviceDriver != vc.VirtioBlock && h.BlockDeviceDriver != vc.VirtioMmio { + return "", fmt.Errorf("Invalid value %s provided for hypervisor block storage driver, can be either %s or %s or %s", h.BlockDeviceDriver, vc.VirtioSCSI, vc.VirtioBlock, vc.VirtioMmio) } return h.BlockDeviceDriver, nil diff --git a/virtcontainers/device/config/config.go b/virtcontainers/device/config/config.go index 5895512f35..aaa3e5e585 100644 --- a/virtcontainers/device/config/config.go +++ b/virtcontainers/device/config/config.go @@ -98,6 +98,9 @@ type BlockDrive struct { // Index assigned to the drive. In case of virtio-scsi, this is used as SCSI LUN index Index int + // MmioAddr is used to identify the slot at which the drive is attached (order?). + MmioAddr string + // PCIAddr is the PCI address used to identify the slot at which the drive is attached. PCIAddr string diff --git a/virtcontainers/device/manager/manager.go b/virtcontainers/device/manager/manager.go index 5841b938da..066c30581c 100644 --- a/virtcontainers/device/manager/manager.go +++ b/virtcontainers/device/manager/manager.go @@ -20,6 +20,8 @@ import ( ) const ( + // VirtioMmio indicates block driver is virtio-mmio based + VirtioMmio string = "virtio-mmio" // VirtioBlock indicates block driver is virtio-blk based VirtioBlock string = "virtio-blk" // VirtioSCSI indicates block driver is virtio-scsi based @@ -55,7 +57,9 @@ func NewDeviceManager(blockDriver string, devices []api.Device) api.DeviceManage dm := &deviceManager{ devices: make(map[string]api.Device), } - if blockDriver == VirtioBlock { + if blockDriver == VirtioMmio { + dm.blockDriver = VirtioMmio + } else if blockDriver == VirtioBlock { dm.blockDriver = VirtioBlock } else { dm.blockDriver = VirtioSCSI diff --git a/virtcontainers/hyperstart_agent.go b/virtcontainers/hyperstart_agent.go index 9e16720a53..b6a3a15122 100644 --- a/virtcontainers/hyperstart_agent.go +++ b/virtcontainers/hyperstart_agent.go @@ -522,7 +522,8 @@ func (h *hyper) startOneContainer(sandbox *Sandbox, c *Container) error { if c.state.Fstype != "" { // Pass a drive name only in case of block driver - if sandbox.config.HypervisorConfig.BlockDeviceDriver == VirtioBlock { + if (sandbox.config.HypervisorConfig.BlockDeviceDriver == VirtioBlock) || + (sandbox.config.HypervisorConfig.BlockDeviceDriver == VirtioMmio) { driveName, err := utils.GetVirtDriveName(c.state.BlockIndex) if err != nil { return err diff --git a/virtcontainers/kata_agent.go b/virtcontainers/kata_agent.go index 8abc95278e..eb8536ae60 100644 --- a/virtcontainers/kata_agent.go +++ b/virtcontainers/kata_agent.go @@ -58,6 +58,7 @@ var ( // CAP_NET_BIND_SERVICE capability may bind to these port numbers. vSockPort = 1024 kata9pDevType = "9p" + kataMmioBlkDevType = "mmioblk" kataBlkDevType = "blk" kataSCSIDevType = "scsi" sharedDir9pOptions = []string{"trans=virtio,version=9p2000.L,cache=mmap", "nodev"} @@ -906,7 +907,10 @@ func (k *kataAgent) buildContainerRootfs(sandbox *Sandbox, c *Container, rootPat return nil, fmt.Errorf("malformed block drive") } - if sandbox.config.HypervisorConfig.BlockDeviceDriver == VirtioBlock { + if sandbox.config.HypervisorConfig.BlockDeviceDriver == VirtioMmio { + rootfs.Driver = kataMmioBlkDevType + rootfs.Source = blockDrive.MmioAddr + } else if sandbox.config.HypervisorConfig.BlockDeviceDriver == VirtioBlock { rootfs.Driver = kataBlkDevType rootfs.Source = blockDrive.PCIAddr } else { diff --git a/virtcontainers/qemu_arch_base.go b/virtcontainers/qemu_arch_base.go index a0f8f84e78..904957e06f 100644 --- a/virtcontainers/qemu_arch_base.go +++ b/virtcontainers/qemu_arch_base.go @@ -125,7 +125,11 @@ const ( // 0 is reserved. const bridgePCIStartAddr = 2 +//TODO: This should be a hypervisor agnostic definition const ( + // VirtioMmio means use virtio-mmio for mmio based drives + VirtioMmio = "virtio-mmio" + // VirtioBlock means use virtio-blk for hotplugging drives VirtioBlock = "virtio-blk"