mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-03 02:26:37 +00:00
virtcontainers: Add Capabilities to the types package
In order to move the hypervisor implementations into their own package, we need to put the capabilities type into the types package. Fixes: #1119 Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
parent
67e696bf62
commit
b25f43e865
@ -137,7 +137,7 @@ type agent interface {
|
||||
|
||||
// capabilities should return a structure that specifies the capabilities
|
||||
// supported by the agent.
|
||||
capabilities() capabilities
|
||||
capabilities() types.Capabilities
|
||||
|
||||
// check will check the agent liveness
|
||||
check() error
|
||||
|
@ -1,58 +0,0 @@
|
||||
// Copyright (c) 2017 Intel Corporation
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
package virtcontainers
|
||||
|
||||
const (
|
||||
blockDeviceSupport = 1 << iota
|
||||
blockDeviceHotplugSupport
|
||||
multiQueueSupport
|
||||
fsSharingUnsupported
|
||||
)
|
||||
|
||||
type capabilities struct {
|
||||
flags uint
|
||||
}
|
||||
|
||||
func (caps *capabilities) isBlockDeviceSupported() bool {
|
||||
if caps.flags&blockDeviceSupport != 0 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (caps *capabilities) setBlockDeviceSupport() {
|
||||
caps.flags = caps.flags | blockDeviceSupport
|
||||
}
|
||||
|
||||
func (caps *capabilities) isBlockDeviceHotplugSupported() bool {
|
||||
if caps.flags&blockDeviceHotplugSupport != 0 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (caps *capabilities) setBlockDeviceHotplugSupport() {
|
||||
caps.flags |= blockDeviceHotplugSupport
|
||||
}
|
||||
|
||||
func (caps *capabilities) isMultiQueueSupported() bool {
|
||||
if caps.flags&multiQueueSupport != 0 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (caps *capabilities) setMultiQueueSupport() {
|
||||
caps.flags |= multiQueueSupport
|
||||
}
|
||||
|
||||
func (caps *capabilities) isFsSharingSupported() bool {
|
||||
return caps.flags&fsSharingUnsupported == 0
|
||||
}
|
||||
|
||||
func (caps *capabilities) setFsSharingUnsupported() {
|
||||
caps.flags |= fsSharingUnsupported
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
// Copyright (c) 2017 Intel Corporation
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
package virtcontainers
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestBlockDeviceCapability(t *testing.T) {
|
||||
var caps capabilities
|
||||
|
||||
if caps.isBlockDeviceSupported() {
|
||||
t.Fatal()
|
||||
}
|
||||
|
||||
caps.setBlockDeviceSupport()
|
||||
|
||||
if !caps.isBlockDeviceSupported() {
|
||||
t.Fatal()
|
||||
}
|
||||
}
|
||||
|
||||
func TestBlockDeviceHotplugCapability(t *testing.T) {
|
||||
var caps capabilities
|
||||
|
||||
if caps.isBlockDeviceHotplugSupported() {
|
||||
t.Fatal()
|
||||
}
|
||||
|
||||
caps.setBlockDeviceHotplugSupport()
|
||||
|
||||
if !caps.isBlockDeviceHotplugSupported() {
|
||||
t.Fatal()
|
||||
}
|
||||
}
|
||||
|
||||
func TestFsSharingCapability(t *testing.T) {
|
||||
var caps capabilities
|
||||
|
||||
if !caps.isFsSharingSupported() {
|
||||
t.Fatal()
|
||||
}
|
||||
|
||||
caps.setFsSharingUnsupported()
|
||||
|
||||
if caps.isFsSharingSupported() {
|
||||
t.Fatal()
|
||||
}
|
||||
}
|
@ -445,7 +445,7 @@ func (c *Container) shareFiles(m Mount, idx int, hostSharedDir, guestSharedDir s
|
||||
// copy file to contaier's rootfs if filesystem sharing is not supported, otherwise
|
||||
// bind mount it in the shared directory.
|
||||
caps := c.sandbox.hypervisor.capabilities()
|
||||
if !caps.isFsSharingSupported() {
|
||||
if !caps.IsFsSharingSupported() {
|
||||
c.Logger().Debug("filesystem sharing is not supported, files will be copied")
|
||||
|
||||
fileInfo, err := os.Stat(m.Source)
|
||||
@ -713,7 +713,7 @@ func (c *Container) checkBlockDeviceSupport() bool {
|
||||
agentCaps := c.sandbox.agent.capabilities()
|
||||
hypervisorCaps := c.sandbox.hypervisor.capabilities()
|
||||
|
||||
if agentCaps.isBlockDeviceSupported() && hypervisorCaps.isBlockDeviceHotplugSupported() {
|
||||
if agentCaps.IsBlockDeviceSupported() && hypervisorCaps.IsBlockDeviceHotplugSupported() {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import (
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/kata-containers/runtime/virtcontainers/device/config"
|
||||
"github.com/kata-containers/runtime/virtcontainers/types"
|
||||
|
||||
"net"
|
||||
"net/http"
|
||||
@ -656,12 +657,12 @@ func (fc *firecracker) disconnect() {
|
||||
}
|
||||
|
||||
// Adds all capabilities supported by firecracker implementation of hypervisor interface
|
||||
func (fc *firecracker) capabilities() capabilities {
|
||||
func (fc *firecracker) capabilities() types.Capabilities {
|
||||
span, _ := fc.trace("capabilities")
|
||||
defer span.Finish()
|
||||
var caps capabilities
|
||||
caps.setFsSharingUnsupported()
|
||||
caps.setBlockDeviceHotplugSupport()
|
||||
var caps types.Capabilities
|
||||
caps.SetFsSharingUnsupported()
|
||||
caps.SetBlockDeviceHotplugSupport()
|
||||
|
||||
return caps
|
||||
}
|
||||
|
@ -330,11 +330,11 @@ func (h *hyper) createSandbox(sandbox *Sandbox) (err error) {
|
||||
return h.configure(sandbox.hypervisor, "", h.getSharePath(sandbox.id), false, nil)
|
||||
}
|
||||
|
||||
func (h *hyper) capabilities() capabilities {
|
||||
var caps capabilities
|
||||
func (h *hyper) capabilities() types.Capabilities {
|
||||
var caps types.Capabilities
|
||||
|
||||
// add all capabilities supported by agent
|
||||
caps.setBlockDeviceSupport()
|
||||
caps.SetBlockDeviceSupport()
|
||||
|
||||
return caps
|
||||
}
|
||||
|
@ -604,7 +604,7 @@ type hypervisor interface {
|
||||
resizeVCPUs(vcpus uint32) (uint32, uint32, error)
|
||||
getSandboxConsole(sandboxID string) (string, error)
|
||||
disconnect()
|
||||
capabilities() capabilities
|
||||
capabilities() types.Capabilities
|
||||
hypervisorConfig() HypervisorConfig
|
||||
getThreadIDs() (*threadIDs, error)
|
||||
cleanup() error
|
||||
|
@ -211,11 +211,11 @@ func (k *kataAgent) agentURL() (string, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (k *kataAgent) capabilities() capabilities {
|
||||
var caps capabilities
|
||||
func (k *kataAgent) capabilities() types.Capabilities {
|
||||
var caps types.Capabilities
|
||||
|
||||
// add all capabilities supported by agent
|
||||
caps.setBlockDeviceSupport()
|
||||
caps.SetBlockDeviceSupport()
|
||||
|
||||
return caps
|
||||
}
|
||||
@ -261,7 +261,7 @@ func (k *kataAgent) configure(h hypervisor, id, sharePath string, builtin bool,
|
||||
// Neither create shared directory nor add 9p device if hypervisor
|
||||
// doesn't support filesystem sharing.
|
||||
caps := h.capabilities()
|
||||
if !caps.isFsSharingSupported() {
|
||||
if !caps.IsFsSharingSupported() {
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -629,7 +629,7 @@ func (k *kataAgent) startSandbox(sandbox *Sandbox) error {
|
||||
caps := sandbox.hypervisor.capabilities()
|
||||
|
||||
// append 9p shared volume to storages only if filesystem sharing is supported
|
||||
if caps.isFsSharingSupported() {
|
||||
if caps.IsFsSharingSupported() {
|
||||
sharedDir9pOptions = append(sharedDir9pOptions, fmt.Sprintf("msize=%d", sandbox.config.HypervisorConfig.Msize9p))
|
||||
|
||||
// We mount the shared directory in a predefined location
|
||||
|
@ -8,13 +8,15 @@ package virtcontainers
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
|
||||
"github.com/kata-containers/runtime/virtcontainers/types"
|
||||
)
|
||||
|
||||
type mockHypervisor struct {
|
||||
}
|
||||
|
||||
func (m *mockHypervisor) capabilities() capabilities {
|
||||
return capabilities{}
|
||||
func (m *mockHypervisor) capabilities() types.Capabilities {
|
||||
return types.Capabilities{}
|
||||
}
|
||||
|
||||
func (m *mockHypervisor) hypervisorConfig() HypervisorConfig {
|
||||
|
@ -511,7 +511,7 @@ func xConnectVMNetwork(endpoint Endpoint, h hypervisor) error {
|
||||
|
||||
queues := 0
|
||||
caps := h.capabilities()
|
||||
if caps.isMultiQueueSupported() {
|
||||
if caps.IsMultiQueueSupported() {
|
||||
queues = int(h.hypervisorConfig().NumVCPUs)
|
||||
}
|
||||
|
||||
|
@ -37,8 +37,8 @@ func (n *noopAgent) createSandbox(sandbox *Sandbox) error {
|
||||
}
|
||||
|
||||
// capabilities returns empty capabilities, i.e no capabilties are supported.
|
||||
func (n *noopAgent) capabilities() capabilities {
|
||||
return capabilities{}
|
||||
func (n *noopAgent) capabilities() types.Capabilities {
|
||||
return types.Capabilities{}
|
||||
}
|
||||
|
||||
// disconnect is the Noop agent connection closer. It does nothing.
|
||||
|
@ -162,7 +162,7 @@ func (q *qemu) kernelParameters() string {
|
||||
}
|
||||
|
||||
// Adds all capabilities supported by qemu implementation of hypervisor interface
|
||||
func (q *qemu) capabilities() capabilities {
|
||||
func (q *qemu) capabilities() types.Capabilities {
|
||||
span, _ := q.trace("capabilities")
|
||||
defer span.Finish()
|
||||
|
||||
|
@ -8,6 +8,8 @@ package virtcontainers
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/kata-containers/runtime/virtcontainers/types"
|
||||
|
||||
govmmQemu "github.com/intel/govmm/qemu"
|
||||
)
|
||||
|
||||
@ -101,16 +103,16 @@ func newQemuArch(config HypervisorConfig) qemuArch {
|
||||
return q
|
||||
}
|
||||
|
||||
func (q *qemuAmd64) capabilities() capabilities {
|
||||
var caps capabilities
|
||||
func (q *qemuAmd64) capabilities() types.Capabilities {
|
||||
var caps types.Capabilities
|
||||
|
||||
if q.machineType == QemuPC ||
|
||||
q.machineType == QemuQ35 ||
|
||||
q.machineType == QemuVirt {
|
||||
caps.setBlockDeviceHotplugSupport()
|
||||
caps.SetBlockDeviceHotplugSupport()
|
||||
}
|
||||
|
||||
caps.setMultiQueueSupport()
|
||||
caps.SetMultiQueueSupport()
|
||||
|
||||
return caps
|
||||
}
|
||||
|
@ -27,11 +27,11 @@ func TestQemuAmd64Capabilities(t *testing.T) {
|
||||
|
||||
amd64 := newTestQemu(QemuPC)
|
||||
caps := amd64.capabilities()
|
||||
assert.True(caps.isBlockDeviceHotplugSupported())
|
||||
assert.True(caps.IsBlockDeviceHotplugSupported())
|
||||
|
||||
amd64 = newTestQemu(QemuQ35)
|
||||
caps = amd64.capabilities()
|
||||
assert.True(caps.isBlockDeviceHotplugSupported())
|
||||
assert.True(caps.IsBlockDeviceHotplugSupported())
|
||||
}
|
||||
|
||||
func TestQemuAmd64Bridges(t *testing.T) {
|
||||
|
@ -45,7 +45,7 @@ type qemuArch interface {
|
||||
kernelParameters(debug bool) []Param
|
||||
|
||||
//capabilities returns the capabilities supported by QEMU
|
||||
capabilities() capabilities
|
||||
capabilities() types.Capabilities
|
||||
|
||||
// bridges returns the number bridges for the machine type
|
||||
bridges(number uint32) []Bridge
|
||||
@ -228,10 +228,10 @@ func (q *qemuArchBase) kernelParameters(debug bool) []Param {
|
||||
return params
|
||||
}
|
||||
|
||||
func (q *qemuArchBase) capabilities() capabilities {
|
||||
var caps capabilities
|
||||
caps.setBlockDeviceHotplugSupport()
|
||||
caps.setMultiQueueSupport()
|
||||
func (q *qemuArchBase) capabilities() types.Capabilities {
|
||||
var caps types.Capabilities
|
||||
caps.SetBlockDeviceHotplugSupport()
|
||||
caps.SetMultiQueueSupport()
|
||||
return caps
|
||||
}
|
||||
|
||||
|
@ -138,7 +138,7 @@ func TestQemuArchBaseCapabilities(t *testing.T) {
|
||||
qemuArchBase := newQemuArchBase()
|
||||
|
||||
c := qemuArchBase.capabilities()
|
||||
assert.True(c.isBlockDeviceHotplugSupported())
|
||||
assert.True(c.IsBlockDeviceHotplugSupported())
|
||||
}
|
||||
|
||||
func TestQemuArchBaseBridges(t *testing.T) {
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
|
||||
govmmQemu "github.com/intel/govmm/qemu"
|
||||
deviceConfig "github.com/kata-containers/runtime/virtcontainers/device/config"
|
||||
"github.com/kata-containers/runtime/virtcontainers/types"
|
||||
"github.com/kata-containers/runtime/virtcontainers/utils"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
@ -90,15 +91,15 @@ func newQemuArch(config HypervisorConfig) qemuArch {
|
||||
return q
|
||||
}
|
||||
|
||||
func (q *qemuPPC64le) capabilities() capabilities {
|
||||
var caps capabilities
|
||||
func (q *qemuPPC64le) capabilities() types.Capabilities {
|
||||
var caps types.Capabilities
|
||||
|
||||
// pseries machine type supports hotplugging drives
|
||||
if q.machineType == QemuPseries {
|
||||
caps.setBlockDeviceHotplugSupport()
|
||||
caps.SetBlockDeviceHotplugSupport()
|
||||
}
|
||||
|
||||
caps.setMultiQueueSupport()
|
||||
caps.SetMultiQueueSupport()
|
||||
|
||||
return caps
|
||||
}
|
||||
|
@ -306,7 +306,7 @@ func TestQemuCapabilities(t *testing.T) {
|
||||
}
|
||||
|
||||
caps := q.capabilities()
|
||||
if !caps.isBlockDeviceHotplugSupported() {
|
||||
if !caps.IsBlockDeviceHotplugSupported() {
|
||||
t.Fatal("Block device hotplug should be supported")
|
||||
}
|
||||
}
|
||||
|
68
virtcontainers/types/capabilities.go
Normal file
68
virtcontainers/types/capabilities.go
Normal file
@ -0,0 +1,68 @@
|
||||
// Copyright (c) 2017 Intel Corporation
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
package types
|
||||
|
||||
const (
|
||||
blockDeviceSupport = 1 << iota
|
||||
blockDeviceHotplugSupport
|
||||
multiQueueSupport
|
||||
fsSharingUnsupported
|
||||
)
|
||||
|
||||
// Capabilities describe a virtcontainers hypervisor capabilities
|
||||
// through a bit mask.
|
||||
type Capabilities struct {
|
||||
flags uint
|
||||
}
|
||||
|
||||
// IsBlockDeviceSupported tells if an hypervisor supports block devices.
|
||||
func (caps *Capabilities) IsBlockDeviceSupported() bool {
|
||||
if caps.flags&blockDeviceSupport != 0 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// SetBlockDeviceSupport sets the block device support capability to true.
|
||||
func (caps *Capabilities) SetBlockDeviceSupport() {
|
||||
caps.flags = caps.flags | blockDeviceSupport
|
||||
}
|
||||
|
||||
// IsBlockDeviceHotplugSupported tells if an hypervisor supports hotplugging block devices.
|
||||
func (caps *Capabilities) IsBlockDeviceHotplugSupported() bool {
|
||||
if caps.flags&blockDeviceHotplugSupport != 0 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// SetBlockDeviceHotplugSupport sets the block device hotplugging capability to true.
|
||||
func (caps *Capabilities) SetBlockDeviceHotplugSupport() {
|
||||
caps.flags |= blockDeviceHotplugSupport
|
||||
}
|
||||
|
||||
// IsMultiQueueSupported tells if an hypervisor supports device multi queue support.
|
||||
func (caps *Capabilities) IsMultiQueueSupported() bool {
|
||||
if caps.flags&multiQueueSupport != 0 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// SetMultiQueueSupport sets the device multi queue capability to true.
|
||||
func (caps *Capabilities) SetMultiQueueSupport() {
|
||||
caps.flags |= multiQueueSupport
|
||||
}
|
||||
|
||||
// IsFsSharingSupported tells if an hypervisor supports host filesystem sharing.
|
||||
func (caps *Capabilities) IsFsSharingSupported() bool {
|
||||
return caps.flags&fsSharingUnsupported == 0
|
||||
}
|
||||
|
||||
// SetFsSharingUnsupported sets the host filesystem sharing capability to true.
|
||||
func (caps *Capabilities) SetFsSharingUnsupported() {
|
||||
caps.flags |= fsSharingUnsupported
|
||||
}
|
50
virtcontainers/types/capabilities_test.go
Normal file
50
virtcontainers/types/capabilities_test.go
Normal file
@ -0,0 +1,50 @@
|
||||
// Copyright (c) 2017 Intel Corporation
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
package types
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestBlockDeviceCapability(t *testing.T) {
|
||||
var caps Capabilities
|
||||
|
||||
if caps.IsBlockDeviceSupported() {
|
||||
t.Fatal()
|
||||
}
|
||||
|
||||
caps.SetBlockDeviceSupport()
|
||||
|
||||
if !caps.IsBlockDeviceSupported() {
|
||||
t.Fatal()
|
||||
}
|
||||
}
|
||||
|
||||
func TestBlockDeviceHotplugCapability(t *testing.T) {
|
||||
var caps Capabilities
|
||||
|
||||
if caps.IsBlockDeviceHotplugSupported() {
|
||||
t.Fatal()
|
||||
}
|
||||
|
||||
caps.SetBlockDeviceHotplugSupport()
|
||||
|
||||
if !caps.IsBlockDeviceHotplugSupported() {
|
||||
t.Fatal()
|
||||
}
|
||||
}
|
||||
|
||||
func TestFsSharingCapability(t *testing.T) {
|
||||
var caps Capabilities
|
||||
|
||||
if !caps.IsFsSharingSupported() {
|
||||
t.Fatal()
|
||||
}
|
||||
|
||||
caps.SetFsSharingUnsupported()
|
||||
|
||||
if caps.IsFsSharingSupported() {
|
||||
t.Fatal()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user