Skip to content

Commit

Permalink
devices: rename VFIODrive to VFIODev
Browse files Browse the repository at this point in the history
Rename VFIODrive to VFIODev, also rename device interface "GetDeviceDrive()" to
"GetDeviceInfo()".

Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
  • Loading branch information
WeiZhang555 committed Jul 31, 2018
1 parent 7d9d66d commit 44c37bf
Show file tree
Hide file tree
Showing 15 changed files with 40 additions and 40 deletions.
6 changes: 3 additions & 3 deletions virtcontainers/device/api/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ type Device interface {
// DeviceType indicates which kind of device it is
// e.g. block, vfio or vhost user
DeviceType() config.DeviceType
// GetDeviceDrive returns device specific data used for hotplugging by hypervisor
// GetDeviceInfo returns device specific data used for hotplugging by hypervisor
// Caller could cast the return value to device specific struct
// e.g. Block device returns *config.BlockDrive and
// vfio device returns *config.VFIODrive
GetDeviceDrive() interface{}
// vfio device returns []*config.VFIODev
GetDeviceInfo() interface{}
// IsAttached checks if the device is attached
IsAttached() bool
}
Expand Down
4 changes: 2 additions & 2 deletions virtcontainers/device/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ type BlockDrive struct {
VirtPath string
}

// VFIODrive represents a VFIO drive used for hotplugging
type VFIODrive struct {
// 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
Expand Down
4 changes: 2 additions & 2 deletions virtcontainers/device/drivers/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (device *BlockDevice) DeviceID() string {
return device.ID
}

// GetDeviceDrive returns device information used for creating
func (device *BlockDevice) GetDeviceDrive() interface{} {
// GetDeviceInfo returns device information used for creating
func (device *BlockDevice) GetDeviceInfo() interface{} {
return device.BlockDrive
}
4 changes: 2 additions & 2 deletions virtcontainers/device/drivers/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (device *GenericDevice) DeviceType() config.DeviceType {
return config.DeviceGeneric
}

// GetDeviceDrive returns device information used for creating
func (device *GenericDevice) GetDeviceDrive() interface{} {
// GetDeviceInfo returns device information used for creating
func (device *GenericDevice) GetDeviceInfo() interface{} {
return device.DeviceInfo
}
12 changes: 6 additions & 6 deletions virtcontainers/device/drivers/vfio.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const (
type VFIODevice struct {
ID string
DeviceInfo *config.DeviceInfo
vfioDrives []*config.VFIODrive
vfioDevs []*config.VFIODev
}

// NewVFIODevice create a new VFIO device
Expand Down Expand Up @@ -61,11 +61,11 @@ func (device *VFIODevice) Attach(devReceiver api.DeviceReceiver) error {
if err != nil {
return err
}
vfio := &config.VFIODrive{
vfio := &config.VFIODev{
ID: utils.MakeNameID("vfio", device.DeviceInfo.ID, maxDevIDSize),
BDF: deviceBDF,
}
device.vfioDrives = append(device.vfioDrives, vfio)
device.vfioDevs = append(device.vfioDevs, vfio)
}

// hotplug a VFIO device is actually hotplugging a group of iommu devices
Expand Down Expand Up @@ -104,9 +104,9 @@ func (device *VFIODevice) DeviceID() string {
return device.ID
}

// GetDeviceDrive returns device information used for creating
func (device *VFIODevice) GetDeviceDrive() interface{} {
return device.vfioDrives
// GetDeviceInfo returns device information used for creating
func (device *VFIODevice) GetDeviceInfo() interface{} {
return device.vfioDevs
}

// getBDF returns the BDF of pci device
Expand Down
4 changes: 2 additions & 2 deletions virtcontainers/device/drivers/vhost_user_blk.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ func (device *VhostUserBlkDevice) DeviceType() config.DeviceType {
return config.VhostUserBlk
}

// GetDeviceDrive returns device information used for creating
func (device *VhostUserBlkDevice) GetDeviceDrive() interface{} {
// GetDeviceInfo returns device information used for creating
func (device *VhostUserBlkDevice) GetDeviceInfo() interface{} {
device.Type = device.DeviceType()
return &device.VhostUserDeviceAttrs
}
4 changes: 2 additions & 2 deletions virtcontainers/device/drivers/vhost_user_net.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ func (device *VhostUserNetDevice) DeviceType() config.DeviceType {
return config.VhostUserNet
}

// GetDeviceDrive returns device information used for creating
func (device *VhostUserNetDevice) GetDeviceDrive() interface{} {
// GetDeviceInfo returns device information used for creating
func (device *VhostUserNetDevice) GetDeviceInfo() interface{} {
device.Type = device.DeviceType()
return &device.VhostUserDeviceAttrs
}
4 changes: 2 additions & 2 deletions virtcontainers/device/drivers/vhost_user_scsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ func (device *VhostUserSCSIDevice) DeviceType() config.DeviceType {
return config.VhostUserSCSI
}

// GetDeviceDrive returns device information used for creating
func (device *VhostUserSCSIDevice) GetDeviceDrive() interface{} {
// GetDeviceInfo returns device information used for creating
func (device *VhostUserSCSIDevice) GetDeviceInfo() interface{} {
device.Type = device.DeviceType()
return &device.VhostUserDeviceAttrs
}
2 changes: 1 addition & 1 deletion virtcontainers/hyperstart_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func fsMapFromDevices(c *Container) ([]*hyperstart.FsmapDescriptor, error) {
return nil, fmt.Errorf("can't find device: %#v", dev)
}

d, ok := device.GetDeviceDrive().(*config.BlockDrive)
d, ok := device.GetDeviceInfo().(*config.BlockDrive)
if !ok || d == nil {
return nil, fmt.Errorf("can't retrieve block device information")
}
Expand Down
4 changes: 2 additions & 2 deletions virtcontainers/kata_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ func (k *kataAgent) appendDevices(deviceList []*grpc.Device, c *Container) []*gr
continue
}

d, ok := device.GetDeviceDrive().(*config.BlockDrive)
d, ok := device.GetDeviceInfo().(*config.BlockDrive)
if !ok || d == nil {
k.Logger().WithField("device", device).Error("malformed block drive")
continue
Expand Down Expand Up @@ -988,7 +988,7 @@ func (k *kataAgent) handleBlockVolumes(c *Container) []*grpc.Storage {
k.Logger().WithField("device", id).Error("failed to find device by id")
return nil
}
blockDrive, ok := device.GetDeviceDrive().(*config.BlockDrive)
blockDrive, ok := device.GetDeviceInfo().(*config.BlockDrive)
if !ok || blockDrive == nil {
k.Logger().Error("malformed block drive")
continue
Expand Down
2 changes: 1 addition & 1 deletion virtcontainers/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ func (endpoint *PhysicalEndpoint) Attach(h hypervisor) error {
}

// TODO: use device manager as general device management entrance
d := config.VFIODrive{
d := config.VFIODev{
BDF: endpoint.BDF,
}

Expand Down
6 changes: 3 additions & 3 deletions virtcontainers/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ func (q *qemu) hotplugBlockDevice(drive *config.BlockDrive, op operation) error
return nil
}

func (q *qemu) hotplugVFIODevice(device *config.VFIODrive, op operation) error {
func (q *qemu) hotplugVFIODevice(device *config.VFIODev, op operation) error {
err := q.qmpSetup()
if err != nil {
return err
Expand Down Expand Up @@ -755,7 +755,7 @@ func (q *qemu) hotplugDevice(devInfo interface{}, devType deviceType, op operati
vcpus := devInfo.(uint32)
return q.hotplugCPUs(vcpus, op)
case vfioDev:
device := devInfo.(*config.VFIODrive)
device := devInfo.(*config.VFIODev)
return nil, q.hotplugVFIODevice(device, op)
case memoryDev:
memdev := devInfo.(*memoryDevice)
Expand Down Expand Up @@ -952,7 +952,7 @@ func (q *qemu) addDevice(devInfo interface{}, devType deviceType) error {
q.qemuConfig.Devices = q.arch.appendBlockDevice(q.qemuConfig.Devices, v)
case config.VhostUserDeviceAttrs:
q.qemuConfig.Devices = q.arch.appendVhostUserDevice(q.qemuConfig.Devices, v)
case config.VFIODrive:
case config.VFIODev:
q.qemuConfig.Devices = q.arch.appendVFIODevice(q.qemuConfig.Devices, v)
default:
break
Expand Down
8 changes: 4 additions & 4 deletions virtcontainers/qemu_arch_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type qemuArch interface {
appendVhostUserDevice(devices []govmmQemu.Device, drive config.VhostUserDeviceAttrs) []govmmQemu.Device

// appendVFIODevice appends a VFIO device to devices
appendVFIODevice(devices []govmmQemu.Device, vfioDevice config.VFIODrive) []govmmQemu.Device
appendVFIODevice(devices []govmmQemu.Device, vfioDevice config.VFIODev) []govmmQemu.Device

// handleImagePath handles the Hypervisor Config image path
handleImagePath(config HypervisorConfig)
Expand Down Expand Up @@ -475,14 +475,14 @@ func (q *qemuArchBase) appendVhostUserDevice(devices []govmmQemu.Device, attr co
return devices
}

func (q *qemuArchBase) appendVFIODevice(devices []govmmQemu.Device, vfioDrive config.VFIODrive) []govmmQemu.Device {
if vfioDrive.BDF == "" {
func (q *qemuArchBase) appendVFIODevice(devices []govmmQemu.Device, vfioDev config.VFIODev) []govmmQemu.Device {
if vfioDev.BDF == "" {
return devices
}

devices = append(devices,
govmmQemu.VFIODevice{
BDF: vfioDrive.BDF,
BDF: vfioDev.BDF,
},
)

Expand Down
4 changes: 2 additions & 2 deletions virtcontainers/qemu_arch_base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func testQemuArchBaseAppend(t *testing.T, structure interface{}, expected []govm
devices = qemuArchBase.appendSocket(devices, s)
case config.BlockDrive:
devices = qemuArchBase.appendBlockDevice(devices, s)
case config.VFIODrive:
case config.VFIODev:
devices = qemuArchBase.appendVFIODevice(devices, s)
case config.VhostUserDeviceAttrs:
devices = qemuArchBase.appendVhostUserDevice(devices, s)
Expand Down Expand Up @@ -406,7 +406,7 @@ func TestQemuArchBaseAppendVFIODevice(t *testing.T) {
},
}

vfDevice := config.VFIODrive{
vfDevice := config.VFIODev{
BDF: bdf,
}

Expand Down
12 changes: 6 additions & 6 deletions virtcontainers/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -1455,11 +1455,11 @@ func togglePauseSandbox(sandboxID string, pause bool) (*Sandbox, error) {
func (s *Sandbox) HotplugAddDevice(device api.Device, devType config.DeviceType) error {
switch devType {
case config.DeviceVFIO:
vfioDevices, ok := device.GetDeviceDrive().([]*config.VFIODrive)
vfioDevices, ok := device.GetDeviceInfo().([]*config.VFIODev)
if !ok {
return fmt.Errorf("device type mismatch, expect device type to be %s", devType)
}
addedDev := []*config.VFIODrive{}
addedDev := []*config.VFIODev{}
var err error
defer func() {
// if err happens,roll back and remove added device!
Expand Down Expand Up @@ -1511,11 +1511,11 @@ func (s *Sandbox) HotplugAddDevice(device api.Device, devType config.DeviceType)
func (s *Sandbox) HotplugRemoveDevice(device api.Device, devType config.DeviceType) error {
switch devType {
case config.DeviceVFIO:
vfioDevices, ok := device.GetDeviceDrive().([]*config.VFIODrive)
vfioDevices, ok := device.GetDeviceInfo().([]*config.VFIODev)
if !ok {
return fmt.Errorf("device type mismatch, expect device type to be %s", devType)
}
removedDev := []*config.VFIODrive{}
removedDev := []*config.VFIODev{}
var err error
defer func() {
// if err happens,roll back and add the removed devices back!
Expand Down Expand Up @@ -1549,7 +1549,7 @@ func (s *Sandbox) HotplugRemoveDevice(device api.Device, devType config.DeviceTy
}
return nil
case config.DeviceBlock:
blockDrive, ok := device.GetDeviceDrive().(*config.BlockDrive)
blockDrive, ok := device.GetDeviceInfo().(*config.BlockDrive)
if !ok {
return fmt.Errorf("device type mismatch, expect device type to be %s", devType)
}
Expand Down Expand Up @@ -1580,7 +1580,7 @@ func (s *Sandbox) DecrementSandboxBlockIndex() error {
func (s *Sandbox) AppendDevice(device api.Device) error {
switch device.DeviceType() {
case config.VhostUserSCSI, config.VhostUserNet, config.VhostUserBlk:
return s.hypervisor.addDevice(device.GetDeviceDrive().(*config.VhostUserDeviceAttrs), vhostuserDev)
return s.hypervisor.addDevice(device.GetDeviceInfo().(*config.VhostUserDeviceAttrs), vhostuserDev)
}
return fmt.Errorf("unsupported device type")
}

0 comments on commit 44c37bf

Please sign in to comment.