diff --git a/virtcontainers/device/api/interface.go b/virtcontainers/device/api/interface.go index 828049c6f6..f4060c046a 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 c080d072d9..e7d937deda 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 61e739d172..d11f65c217 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 8be04e9c05..e44e103e70 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) +}