From f246a799aa2c71f2385fd859115705a991d0d1d3 Mon Sep 17 00:00:00 2001 From: Vijay Dhanraj Date: Tue, 11 Jun 2019 09:46:08 -0700 Subject: [PATCH] virtcontainers: Add support for updating virtio-blk based container rootfs Thist patch adds the following, 1. ACRN only supports virtio-blk and so the rootfs for the VM sits at /dev/vda. So to get the container rootfs increment the globalIndex by 1. 2. ACRN doesn't hot-plug container rootfs (but uses blkrescan) to update the container rootfs. So the agent can be provided the virtpath rather than the PCIaddr avoiding unneccessary rescaning to find the virthpath. v1->v2: Removed the workaround of incrementing index for virtio-blk device and addressed it acrn. Fixes: #1778 Signed-off-by: Vijay Dhanraj --- virtcontainers/device/api/interface.go | 4 ++-- virtcontainers/device/api/mockDeviceReceiver.go | 5 +++++ virtcontainers/kata_agent.go | 12 ++++++++---- virtcontainers/sandbox.go | 17 +++++++++++------ 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/virtcontainers/device/api/interface.go b/virtcontainers/device/api/interface.go index 828049c6f..f4060c046 100644 --- a/virtcontainers/device/api/interface.go +++ b/virtcontainers/device/api/interface.go @@ -7,10 +7,9 @@ package api import ( - "github.com/sirupsen/logrus" - "github.com/kata-containers/runtime/virtcontainers/device/config" persistapi "github.com/kata-containers/runtime/virtcontainers/persist/api" + "github.com/sirupsen/logrus" ) var devLogger = logrus.WithField("subsystem", "device") @@ -36,6 +35,7 @@ type DeviceReceiver interface { // this is only for virtio-blk and virtio-scsi support GetAndSetSandboxBlockIndex() (int, error) DecrementSandboxBlockIndex() error + GetHypervisorType() string // this is for appending device to hypervisor boot params AppendDevice(Device) error diff --git a/virtcontainers/device/api/mockDeviceReceiver.go b/virtcontainers/device/api/mockDeviceReceiver.go index c080d072d..e7d937ded 100644 --- a/virtcontainers/device/api/mockDeviceReceiver.go +++ b/virtcontainers/device/api/mockDeviceReceiver.go @@ -36,3 +36,8 @@ func (mockDC *MockDeviceReceiver) DecrementSandboxBlockIndex() error { func (mockDC *MockDeviceReceiver) AppendDevice(Device) error { return nil } + +// GetHypervisorType is used for getting Hypervisor name currently used. +func (mockDC *MockDeviceReceiver) GetHypervisorType() string { + return "" +} diff --git a/virtcontainers/kata_agent.go b/virtcontainers/kata_agent.go index 61e739d17..d11f65c21 100644 --- a/virtcontainers/kata_agent.go +++ b/virtcontainers/kata_agent.go @@ -19,6 +19,7 @@ import ( "syscall" "time" + "github.com/gogo/protobuf/proto" aTypes "github.com/kata-containers/agent/pkg/types" kataclient "github.com/kata-containers/agent/protocols/client" "github.com/kata-containers/agent/protocols/grpc" @@ -30,10 +31,8 @@ import ( "github.com/kata-containers/runtime/virtcontainers/store" "github.com/kata-containers/runtime/virtcontainers/types" "github.com/kata-containers/runtime/virtcontainers/utils" - opentracing "github.com/opentracing/opentracing-go" - - "github.com/gogo/protobuf/proto" "github.com/opencontainers/runtime-spec/specs-go" + opentracing "github.com/opentracing/opentracing-go" "github.com/sirupsen/logrus" "github.com/vishvananda/netlink" "golang.org/x/net/context" @@ -1084,7 +1083,12 @@ func (k *kataAgent) buildContainerRootfs(sandbox *Sandbox, c *Container, rootPat rootfs.Source = blockDrive.VirtPath } else if sandbox.config.HypervisorConfig.BlockDeviceDriver == config.VirtioBlock { rootfs.Driver = kataBlkDevType - rootfs.Source = blockDrive.PCIAddr + if blockDrive.PCIAddr == "" { + rootfs.Source = blockDrive.VirtPath + } else { + rootfs.Source = blockDrive.PCIAddr + } + } else { rootfs.Driver = kataSCSIDevType rootfs.Source = blockDrive.SCSIAddr diff --git a/virtcontainers/sandbox.go b/virtcontainers/sandbox.go index 8be04e9c0..e44e103e7 100644 --- a/virtcontainers/sandbox.go +++ b/virtcontainers/sandbox.go @@ -15,12 +15,6 @@ import ( "syscall" "github.com/containernetworking/plugins/pkg/ns" - specs "github.com/opencontainers/runtime-spec/specs-go" - opentracing "github.com/opentracing/opentracing-go" - "github.com/pkg/errors" - "github.com/sirupsen/logrus" - "github.com/vishvananda/netlink" - "github.com/kata-containers/agent/protocols/grpc" "github.com/kata-containers/runtime/virtcontainers/device/api" "github.com/kata-containers/runtime/virtcontainers/device/config" @@ -34,6 +28,11 @@ import ( "github.com/kata-containers/runtime/virtcontainers/store" "github.com/kata-containers/runtime/virtcontainers/types" "github.com/kata-containers/runtime/virtcontainers/utils" + specs "github.com/opencontainers/runtime-spec/specs-go" + opentracing "github.com/opentracing/opentracing-go" + "github.com/pkg/errors" + "github.com/sirupsen/logrus" + "github.com/vishvananda/netlink" ) const ( @@ -1842,3 +1841,9 @@ func (s *Sandbox) calculateSandboxCPUs() uint32 { } return utils.CalculateVCpusFromMilliCpus(mCPU) } + +// GetHypervisorType is used for getting Hypervisor name currently used. +// Sandbox implement DeviceReceiver interface from device/api/interface.go +func (s *Sandbox) GetHypervisorType() string { + return string(s.config.HypervisorType) +}