mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-09-01 08:56:32 +00:00
Merge pull request #861 from likebreath/clh_vfio_unplug
clh: Support VFIO device unplug
This commit is contained in:
@@ -429,15 +429,12 @@ func (clh *cloudHypervisor) hotplugAddBlockDevice(drive *config.BlockDrive) erro
|
|||||||
" using '%v' but only support '%v'", clh.config.BlockDeviceDriver, config.VirtioBlock)
|
" using '%v' but only support '%v'", clh.config.BlockDeviceDriver, config.VirtioBlock)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
|
|
||||||
cl := clh.client()
|
cl := clh.client()
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), clhHotPlugAPITimeout*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), clhHotPlugAPITimeout*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
_, _, err := cl.VmmPingGet(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return openAPIClientError(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
driveID := clhDriveIndexToID(drive.Index)
|
driveID := clhDriveIndexToID(drive.Index)
|
||||||
|
|
||||||
//Explicitly set PCIAddr to NULL, so that VirtPath can be used
|
//Explicitly set PCIAddr to NULL, so that VirtPath can be used
|
||||||
@@ -466,12 +463,7 @@ func (clh *cloudHypervisor) hotPlugVFIODevice(device config.VFIODev) error {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), clhHotPlugAPITimeout*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), clhHotPlugAPITimeout*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
_, _, err := cl.VmmPingGet(ctx)
|
_, _, err := cl.VmAddDevicePut(ctx, chclient.VmAddDevice{Path: device.SysfsDev, Id: device.ID})
|
||||||
if err != nil {
|
|
||||||
return openAPIClientError(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
_, _, err = cl.VmAddDevicePut(ctx, chclient.VmAddDevice{Path: device.SysfsDev})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("Failed to hotplug device %+v %s", device, openAPIClientError(err))
|
err = fmt.Errorf("Failed to hotplug device %+v %s", device, openAPIClientError(err))
|
||||||
}
|
}
|
||||||
@@ -515,6 +507,20 @@ func (clh *cloudHypervisor) hotplugRemoveBlockDevice(drive *config.BlockDrive) e
|
|||||||
return err
|
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) {
|
func (clh *cloudHypervisor) hotplugRemoveDevice(devInfo interface{}, devType deviceType) (interface{}, error) {
|
||||||
span, _ := clh.trace("hotplugRemoveDevice")
|
span, _ := clh.trace("hotplugRemoveDevice")
|
||||||
defer span.Finish()
|
defer span.Finish()
|
||||||
@@ -522,6 +528,8 @@ func (clh *cloudHypervisor) hotplugRemoveDevice(devInfo interface{}, devType dev
|
|||||||
switch devType {
|
switch devType {
|
||||||
case blockDev:
|
case blockDev:
|
||||||
return nil, clh.hotplugRemoveBlockDevice(devInfo.(*config.BlockDrive))
|
return nil, clh.hotplugRemoveBlockDevice(devInfo.(*config.BlockDrive))
|
||||||
|
case vfioDev:
|
||||||
|
return nil, clh.hotplugRemoveVfioDevice(devInfo.(*config.VFIODev))
|
||||||
default:
|
default:
|
||||||
clh.Logger().WithFields(log.Fields{"devInfo": devInfo,
|
clh.Logger().WithFields(log.Fields{"devInfo": devInfo,
|
||||||
"deviceType": devType}).Error("hotplugRemoveDevice: unsupported device")
|
"deviceType": devType}).Error("hotplugRemoveDevice: unsupported device")
|
||||||
|
@@ -828,7 +828,7 @@ components:
|
|||||||
default: false
|
default: false
|
||||||
type: boolean
|
type: boolean
|
||||||
host_numa_node:
|
host_numa_node:
|
||||||
format: uint32
|
format: int32
|
||||||
type: integer
|
type: integer
|
||||||
hotplug_size:
|
hotplug_size:
|
||||||
format: int64
|
format: int64
|
||||||
@@ -896,7 +896,7 @@ components:
|
|||||||
default: false
|
default: false
|
||||||
type: boolean
|
type: boolean
|
||||||
balloon_size:
|
balloon_size:
|
||||||
format: uint64
|
format: int64
|
||||||
type: integer
|
type: integer
|
||||||
zones:
|
zones:
|
||||||
items:
|
items:
|
||||||
@@ -1172,10 +1172,10 @@ components:
|
|||||||
destination: 3
|
destination: 3
|
||||||
properties:
|
properties:
|
||||||
destination:
|
destination:
|
||||||
format: uint32
|
format: int32
|
||||||
type: integer
|
type: integer
|
||||||
distance:
|
distance:
|
||||||
format: uint8
|
format: int32
|
||||||
type: integer
|
type: integer
|
||||||
required:
|
required:
|
||||||
- destination
|
- destination
|
||||||
@@ -1197,11 +1197,11 @@ components:
|
|||||||
guest_numa_id: 9
|
guest_numa_id: 9
|
||||||
properties:
|
properties:
|
||||||
guest_numa_id:
|
guest_numa_id:
|
||||||
format: uint32
|
format: int32
|
||||||
type: integer
|
type: integer
|
||||||
cpus:
|
cpus:
|
||||||
items:
|
items:
|
||||||
format: uint8
|
format: int32
|
||||||
type: integer
|
type: integer
|
||||||
type: array
|
type: array
|
||||||
distances:
|
distances:
|
||||||
@@ -1248,9 +1248,16 @@ components:
|
|||||||
VmAddDevice:
|
VmAddDevice:
|
||||||
example:
|
example:
|
||||||
path: path
|
path: path
|
||||||
|
iommu: false
|
||||||
|
id: id
|
||||||
properties:
|
properties:
|
||||||
path:
|
path:
|
||||||
type: string
|
type: string
|
||||||
|
iommu:
|
||||||
|
default: false
|
||||||
|
type: boolean
|
||||||
|
id:
|
||||||
|
type: string
|
||||||
type: object
|
type: object
|
||||||
VmRemoveDevice:
|
VmRemoveDevice:
|
||||||
example:
|
example:
|
||||||
|
@@ -12,7 +12,7 @@ Name | Type | Description | Notes
|
|||||||
**Shared** | **bool** | | [optional] [default to false]
|
**Shared** | **bool** | | [optional] [default to false]
|
||||||
**Hugepages** | **bool** | | [optional] [default to false]
|
**Hugepages** | **bool** | | [optional] [default to false]
|
||||||
**Balloon** | **bool** | | [optional] [default to false]
|
**Balloon** | **bool** | | [optional] [default to false]
|
||||||
**BalloonSize** | **int32** | | [optional]
|
**BalloonSize** | **int64** | | [optional]
|
||||||
**Zones** | [**[]MemoryZoneConfig**](MemoryZoneConfig.md) | | [optional]
|
**Zones** | [**[]MemoryZoneConfig**](MemoryZoneConfig.md) | | [optional]
|
||||||
|
|
||||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||||
|
@@ -5,6 +5,8 @@
|
|||||||
Name | Type | Description | Notes
|
Name | Type | Description | Notes
|
||||||
------------ | ------------- | ------------- | -------------
|
------------ | ------------- | ------------- | -------------
|
||||||
**Path** | **string** | | [optional]
|
**Path** | **string** | | [optional]
|
||||||
|
**Iommu** | **bool** | | [optional] [default to false]
|
||||||
|
**Id** | **string** | | [optional]
|
||||||
|
|
||||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
@@ -18,6 +18,6 @@ type MemoryConfig struct {
|
|||||||
Shared bool `json:"shared,omitempty"`
|
Shared bool `json:"shared,omitempty"`
|
||||||
Hugepages bool `json:"hugepages,omitempty"`
|
Hugepages bool `json:"hugepages,omitempty"`
|
||||||
Balloon bool `json:"balloon,omitempty"`
|
Balloon bool `json:"balloon,omitempty"`
|
||||||
BalloonSize int32 `json:"balloon_size,omitempty"`
|
BalloonSize int64 `json:"balloon_size,omitempty"`
|
||||||
Zones []MemoryZoneConfig `json:"zones,omitempty"`
|
Zones []MemoryZoneConfig `json:"zones,omitempty"`
|
||||||
}
|
}
|
||||||
|
@@ -11,4 +11,6 @@ package openapi
|
|||||||
// VmAddDevice struct for VmAddDevice
|
// VmAddDevice struct for VmAddDevice
|
||||||
type VmAddDevice struct {
|
type VmAddDevice struct {
|
||||||
Path string `json:"path,omitempty"`
|
Path string `json:"path,omitempty"`
|
||||||
|
Iommu bool `json:"iommu,omitempty"`
|
||||||
|
Id string `json:"id,omitempty"`
|
||||||
}
|
}
|
||||||
|
@@ -492,7 +492,7 @@ components:
|
|||||||
default: false
|
default: false
|
||||||
host_numa_node:
|
host_numa_node:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint32
|
format: int32
|
||||||
hotplug_size:
|
hotplug_size:
|
||||||
type: integer
|
type: integer
|
||||||
format: int64
|
format: int64
|
||||||
@@ -532,7 +532,7 @@ components:
|
|||||||
default: false
|
default: false
|
||||||
balloon_size:
|
balloon_size:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint64
|
format: int64
|
||||||
zones:
|
zones:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
@@ -754,10 +754,10 @@ components:
|
|||||||
properties:
|
properties:
|
||||||
destination:
|
destination:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint32
|
format: int32
|
||||||
distance:
|
distance:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint8
|
format: int32
|
||||||
|
|
||||||
NumaConfig:
|
NumaConfig:
|
||||||
required:
|
required:
|
||||||
@@ -766,12 +766,12 @@ components:
|
|||||||
properties:
|
properties:
|
||||||
guest_numa_id:
|
guest_numa_id:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint32
|
format: int32
|
||||||
cpus:
|
cpus:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint8
|
format: int32
|
||||||
distances:
|
distances:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
@@ -811,6 +811,11 @@ components:
|
|||||||
properties:
|
properties:
|
||||||
path:
|
path:
|
||||||
type: string
|
type: string
|
||||||
|
iommu:
|
||||||
|
type: boolean
|
||||||
|
default: false
|
||||||
|
id:
|
||||||
|
type: string
|
||||||
|
|
||||||
VmRemoveDevice:
|
VmRemoveDevice:
|
||||||
type: object
|
type: object
|
||||||
|
@@ -75,7 +75,7 @@ assets:
|
|||||||
url: "https://github.com/cloud-hypervisor/cloud-hypervisor"
|
url: "https://github.com/cloud-hypervisor/cloud-hypervisor"
|
||||||
uscan-url: >-
|
uscan-url: >-
|
||||||
https://github.com/cloud-hypervisor/cloud-hypervisor/tags.*/v?(\d\S+)\.tar\.gz
|
https://github.com/cloud-hypervisor/cloud-hypervisor/tags.*/v?(\d\S+)\.tar\.gz
|
||||||
version: "c54452c08a467a3e35d8d72f2a91d424e9718c57"
|
version: "6d30fe05e4febd930d91bb36294f0219faf2254c"
|
||||||
|
|
||||||
firecracker:
|
firecracker:
|
||||||
description: "Firecracker micro-VMM"
|
description: "Firecracker micro-VMM"
|
||||||
|
Reference in New Issue
Block a user