Skip to content

Commit

Permalink
clh: Support VFIO device unplug
Browse files Browse the repository at this point in the history
This patch adds the support of VFIO device unplug when using
cloud-hypervisor.

Fixes: #860

Signed-off-by: Bo Chen <chen.bo@intel.com>
  • Loading branch information
likebreath committed Oct 5, 2020
1 parent 1f4dfa3 commit c33ee54
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/runtime/virtcontainers/clh.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ func (clh *cloudHypervisor) hotPlugVFIODevice(device config.VFIODev) error {
ctx, cancel := context.WithTimeout(context.Background(), clhHotPlugAPITimeout*time.Second)
defer cancel()

_, _, err := cl.VmAddDevicePut(ctx, chclient.VmAddDevice{Path: device.SysfsDev})
_, _, err := cl.VmAddDevicePut(ctx, chclient.VmAddDevice{Path: device.SysfsDev, Id: device.ID})
if err != nil {
err = fmt.Errorf("Failed to hotplug device %+v %s", device, openAPIClientError(err))
}
Expand Down Expand Up @@ -507,13 +507,29 @@ func (clh *cloudHypervisor) hotplugRemoveBlockDevice(drive *config.BlockDrive) e
return err
}

func (clh *cloudHypervisor) hotplugRemoveVfioDevice(device *config.VFIODev) error {
cl := clh.client()
ctx, cancel := context.WithTimeout(context.Background(), clhHotPlugAPITimeout*time.Second)
defer cancel()

_, err := cl.VmRemoveDevicePut(ctx, chclient.VmRemoveDevice{Id: device.ID})

if err != nil {
err = fmt.Errorf("failed to hotplug remove vfio device %+v %s", device, openAPIClientError(err))
}

return err
}

func (clh *cloudHypervisor) hotplugRemoveDevice(devInfo interface{}, devType deviceType) (interface{}, error) {
span, _ := clh.trace("hotplugRemoveDevice")
defer span.Finish()

switch devType {
case blockDev:
return nil, clh.hotplugRemoveBlockDevice(devInfo.(*config.BlockDrive))
case vfioDev:
return nil, clh.hotplugRemoveVfioDevice(devInfo.(*config.VFIODev))
default:
clh.Logger().WithFields(log.Fields{"devInfo": devInfo,
"deviceType": devType}).Error("hotplugRemoveDevice: unsupported device")
Expand Down

0 comments on commit c33ee54

Please sign in to comment.