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

Commit

Permalink
virtcontainers: Add Capabilities to the types package
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Samuel Ortiz committed Jan 14, 2019
1 parent 67e696b commit b25f43e
Show file tree
Hide file tree
Showing 20 changed files with 163 additions and 147 deletions.
2 changes: 1 addition & 1 deletion virtcontainers/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
58 changes: 0 additions & 58 deletions virtcontainers/capabilities.go

This file was deleted.

50 changes: 0 additions & 50 deletions virtcontainers/capabilities_test.go

This file was deleted.

4 changes: 2 additions & 2 deletions virtcontainers/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
}
Expand Down
9 changes: 5 additions & 4 deletions virtcontainers/fc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions virtcontainers/hyperstart_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion virtcontainers/hypervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions virtcontainers/kata_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions virtcontainers/mock_hypervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion virtcontainers/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions virtcontainers/noop_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion virtcontainers/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
10 changes: 6 additions & 4 deletions virtcontainers/qemu_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ package virtcontainers
import (
"os"

"github.com/kata-containers/runtime/virtcontainers/types"

govmmQemu "github.com/intel/govmm/qemu"
)

Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions virtcontainers/qemu_amd64_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions virtcontainers/qemu_arch_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion virtcontainers/qemu_arch_base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 5 additions & 4 deletions virtcontainers/qemu_ppc64le.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion virtcontainers/qemu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Expand Down
Loading

0 comments on commit b25f43e

Please sign in to comment.