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

Commit

Permalink
Merge pull request #2996 from likebreath/clh_vfio_unplug
Browse files Browse the repository at this point in the history
clh: Support VFIO device unplug
  • Loading branch information
likebreath authored Oct 2, 2020
2 parents cea5f17 + 18c1a7f commit 6da3662
Show file tree
Hide file tree
Showing 16 changed files with 64 additions and 132 deletions.
2 changes: 1 addition & 1 deletion versions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ assets:
url: "https://github.com/cloud-hypervisor/cloud-hypervisor"
uscan-url: >-
https://github.com/cloud-hypervisor/cloud-hypervisor/tags.*/v?(\d\S+)\.tar\.gz
version: "v0.10.0"
version: "6d30fe05e4febd930d91bb36294f0219faf2254c"

firecracker:
description: "Firecracker micro-VMM"
Expand Down
30 changes: 19 additions & 11 deletions virtcontainers/clh.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,15 +414,12 @@ func (clh *cloudHypervisor) hotplugAddBlockDevice(drive *config.BlockDrive) erro
" using '%v' but only support '%v'", clh.config.BlockDeviceDriver, config.VirtioBlock)
}

var err error

cl := clh.client()
ctx, cancel := context.WithTimeout(context.Background(), clhHotPlugAPITimeout*time.Second)
defer cancel()

_, _, err := cl.VmmPingGet(ctx)
if err != nil {
return openAPIClientError(err)
}

driveID := clhDriveIndexToID(drive.Index)

//Explicitly set PCIAddr to NULL, so that VirtPath can be used
Expand Down Expand Up @@ -451,12 +448,7 @@ func (clh *cloudHypervisor) hotPlugVFIODevice(device config.VFIODev) error {
ctx, cancel := context.WithTimeout(context.Background(), clhHotPlugAPITimeout*time.Second)
defer cancel()

_, _, err := cl.VmmPingGet(ctx)
if err != nil {
return openAPIClientError(err)
}

_, _, 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 @@ -500,13 +492,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
2 changes: 1 addition & 1 deletion virtcontainers/pkg/cloud-hypervisor/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ YQ := $(shell command -v yq 2> /dev/null)
generate-client-code: clean-generated-code
docker run --rm \
--user $$(id -u):$$(id -g) \
-v $${PWD}:/local openapitools/openapi-generator-cli generate \
-v $${PWD}:/local openapitools/openapi-generator-cli:v4.3.1 generate \
-i /local/cloud-hypervisor.yaml \
-g go \
-o /local/client
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.0.0-SNAPSHOT
4.3.1
23 changes: 15 additions & 8 deletions virtcontainers/pkg/cloud-hypervisor/client/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ components:
VmCounters:
additionalProperties:
additionalProperties:
format: uint64
format: int64
type: integer
type: object
type: object
Expand Down Expand Up @@ -828,7 +828,7 @@ components:
default: false
type: boolean
host_numa_node:
format: uint32
format: int32
type: integer
hotplug_size:
format: int64
Expand Down Expand Up @@ -896,7 +896,7 @@ components:
default: false
type: boolean
balloon_size:
format: uint64
format: int64
type: integer
zones:
items:
Expand Down Expand Up @@ -1158,7 +1158,7 @@ components:
size: 8
properties:
size:
format: uint64
format: int64
type: integer
prefault:
default: false
Expand All @@ -1172,10 +1172,10 @@ components:
destination: 3
properties:
destination:
format: uint32
format: int32
type: integer
distance:
format: uint8
format: int32
type: integer
required:
- destination
Expand All @@ -1197,11 +1197,11 @@ components:
guest_numa_id: 9
properties:
guest_numa_id:
format: uint32
format: int32
type: integer
cpus:
items:
format: uint8
format: int32
type: integer
type: array
distances:
Expand Down Expand Up @@ -1248,9 +1248,16 @@ components:
VmAddDevice:
example:
path: path
iommu: false
id: id
properties:
path:
type: string
iommu:
default: false
type: boolean
id:
type: string
type: object
VmRemoveDevice:
example:
Expand Down
Loading

0 comments on commit 6da3662

Please sign in to comment.