runtime: device/persist: drop persist dependency from device pkgs

Rather than have device package depend on persist, let's define the
(almost duplicate) structures within device itself, and have the Kata
Container's persist pkg import these.

This'll help avoid unecessary dependencies within our core packages.

Signed-off-by: Eric Ernst <eric_ernst@apple.com>
This commit is contained in:
Eric Ernst
2022-06-16 00:24:04 -07:00
parent f9e96c6506
commit f97d9b45c8
11 changed files with 37 additions and 43 deletions

View File

@@ -8,8 +8,9 @@ package virtcontainers
import (
"errors"
hv "github.com/kata-containers/kata-containers/src/runtime/pkg/hypervisors"
"github.com/kata-containers/kata-containers/src/runtime/pkg/device/api"
devconfig "github.com/kata-containers/kata-containers/src/runtime/pkg/device/config"
hv "github.com/kata-containers/kata-containers/src/runtime/pkg/hypervisors"
exp "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/experimental"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist"
persistapi "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist/api"
@@ -65,7 +66,7 @@ func (s *Sandbox) dumpHypervisor(ss *persistapi.SandboxState) {
ss.HypervisorState.BlockIndexMap = s.state.BlockIndexMap
}
func deviceToDeviceState(devices []api.Device) (dss []persistapi.DeviceState) {
func deviceToDeviceState(devices []api.Device) (dss []devconfig.DeviceState) {
for _, dev := range devices {
dss = append(dss, dev.Save())
}
@@ -323,7 +324,7 @@ func (s *Sandbox) loadAgent(as persistapi.AgentState) {
}
}
func (s *Sandbox) loadDevices(devStates []persistapi.DeviceState) {
func (s *Sandbox) loadDevices(devStates []devconfig.DeviceState) {
s.devManager.LoadDevices(devStates)
}

View File

@@ -1,124 +0,0 @@
// Copyright (c) 2016 Intel Corporation
// Copyright (c) 2019 Huawei Corporation
//
// SPDX-License-Identifier: Apache-2.0
//
package persistapi
import vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
// ============= sandbox level resources =============
// BlockDrive represents a block storage drive which may be used in case the storage
// driver has an underlying block storage device.
type BlockDrive struct {
// File is the path to the disk-image/device which will be used with this drive
File string
// Format of the drive
Format string
// ID is used to identify this drive in the hypervisor options.
ID string
// MmioAddr is used to identify the slot at which the drive is attached (order?).
MmioAddr string
// SCSI Address of the block device, in case the device is attached using SCSI driver
// SCSI address is in the format SCSI-Id:LUN
SCSIAddr string
// NvdimmID is the nvdimm id inside the VM
NvdimmID string
// VirtPath at which the device appears inside the VM, outside of the container mount namespace
VirtPath string
// DevNo
DevNo string
// PCIPath is the PCI path used to identify the slot at which the drive is attached.
PCIPath vcTypes.PciPath
// Index assigned to the drive. In case of virtio-scsi, this is used as SCSI LUN index
Index int
// Pmem enabled persistent memory. Use File as backing file
// for a nvdimm device in the guest.
Pmem bool
}
// VFIODev represents a VFIO drive used for hotplugging
type VFIODev struct {
// ID is used to identify this drive in the hypervisor options.
ID string
// BDF (Bus:Device.Function) of the PCI address
BDF string
// Sysfsdev of VFIO mediated device
SysfsDev string
// Type of VFIO device
Type uint32
}
// VhostUserDeviceAttrs represents data shared by most vhost-user devices
type VhostUserDeviceAttrs struct {
DevID string
SocketPath string
Type string
// MacAddress is only meaningful for vhost user net device
MacAddress string
// PCIPath is the PCI path used to identify the slot at which the drive is attached.
// It is only meaningful for vhost user block devices
PCIPath vcTypes.PciPath
// Block index of the device if assigned
Index int
}
// DeviceState is sandbox level resource which represents host devices
// plugged to hypervisor, one Device can be shared among containers in POD
// Refs: virtcontainers/device/drivers/generic.go:GenericDevice
type DeviceState struct {
// DriverOptions is specific options for each device driver
// for example, for BlockDevice, we can set DriverOptions["block-driver"]="virtio-blk"
DriverOptions map[string]string
// VhostUserDeviceAttrs is specific for vhost-user device driver
VhostUserDev *VhostUserDeviceAttrs `json:",omitempty"`
// BlockDrive is specific for block device driver
BlockDrive *BlockDrive `json:",omitempty"`
ID string
// Type is used to specify driver type
// Refs: virtcontainers/device/config/config.go:DeviceType
Type string
// Type of device: c, b, u or p
// c , u - character(unbuffered)
// p - FIFO
// b - block(buffered) special file
// More info in mknod(1).
DevType string
// VFIODev is specific VFIO device driver
VFIODevs []*VFIODev `json:",omitempty"`
RefCount uint
AttachCount uint
// Major, minor numbers for device.
Major int64
Minor int64
// ColdPlug specifies whether the device must be cold plugged (true)
// or hot plugged (false).
ColdPlug bool
}

View File

@@ -7,6 +7,7 @@
package persistapi
import (
dev "github.com/kata-containers/kata-containers/src/runtime/pkg/device/config"
hv "github.com/kata-containers/kata-containers/src/runtime/pkg/hypervisors"
)
@@ -26,7 +27,7 @@ type SandboxState struct {
CgroupPaths map[string]string
// Devices plugged to sandbox(hypervisor)
Devices []DeviceState
Devices []dev.DeviceState
// State is sandbox running status
State string