Skip to content

Commit

Permalink
Merge pull request kubevirt#10015 from victortoso/hostdev-usb
Browse files Browse the repository at this point in the history
USB host pass through
  • Loading branch information
kubevirt-bot authored Sep 30, 2023
2 parents a108591 + ca09f95 commit 2c8b697
Show file tree
Hide file tree
Showing 37 changed files with 1,456 additions and 40 deletions.
30 changes: 22 additions & 8 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -1783,20 +1783,18 @@ rpm(
)

rpm(
name = "kernel-headers-0__5.14.0-362.el9.aarch64",
sha256 = "a5b1e12e2518cb492357278fe9d560c4daa8a2feefe9a04a74745bee61da4049",
name = "kernel-headers-0__5.14.0-364.el9.aarch64",
sha256 = "80896565b489078aa16387cc15fc3e33124da317df32ca760a18246a73527bed",
urls = [
"http://mirror.stream.centos.org/9-stream/AppStream/aarch64/os/Packages/kernel-headers-5.14.0-362.el9.aarch64.rpm",
"https://storage.googleapis.com/builddeps/a5b1e12e2518cb492357278fe9d560c4daa8a2feefe9a04a74745bee61da4049",
"http://mirror.stream.centos.org/9-stream/AppStream/aarch64/os/Packages/kernel-headers-5.14.0-364.el9.aarch64.rpm",
],
)

rpm(
name = "kernel-headers-0__5.14.0-362.el9.x86_64",
sha256 = "58d39770426f835b72ad12500be4ff71d270a5f44310cc547bc2f4115f64b443",
name = "kernel-headers-0__5.14.0-364.el9.x86_64",
sha256 = "30795c050f07f3d6168f90cccf32968cfdc20e008f299df3355b8619fbddc804",
urls = [
"http://mirror.stream.centos.org/9-stream/AppStream/x86_64/os/Packages/kernel-headers-5.14.0-362.el9.x86_64.rpm",
"https://storage.googleapis.com/builddeps/58d39770426f835b72ad12500be4ff71d270a5f44310cc547bc2f4115f64b443",
"http://mirror.stream.centos.org/9-stream/AppStream/x86_64/os/Packages/kernel-headers-5.14.0-364.el9.x86_64.rpm",
],
)

Expand Down Expand Up @@ -4410,6 +4408,22 @@ rpm(
],
)

rpm(
name = "qemu-kvm-device-usb-host-17__8.0.0-13.el9.aarch64",
sha256 = "6766a8164e99c82cd985bd96f2653381564dada2ecb373ff8fc462733ce75ee8",
urls = [
"http://mirror.stream.centos.org/9-stream/AppStream/aarch64/os/Packages/qemu-kvm-device-usb-host-8.0.0-13.el9.aarch64.rpm",
],
)

rpm(
name = "qemu-kvm-device-usb-host-17__8.0.0-13.el9.x86_64",
sha256 = "b42fbf8706a056377b87bd82c298d81261a89200e2768e90be84b3773491e59e",
urls = [
"http://mirror.stream.centos.org/9-stream/AppStream/x86_64/os/Packages/qemu-kvm-device-usb-host-8.0.0-13.el9.x86_64.rpm",
],
)

rpm(
name = "qemu-kvm-device-usb-redirect-17__8.0.0-13.el9.x86_64",
sha256 = "6de8f93673068504e702035ea064070663a3c8e7e91366e9b39a4ca8c8829597",
Expand Down
46 changes: 46 additions & 0 deletions api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -18408,6 +18408,14 @@
"$ref": "#/definitions/v1.PciHostDevice"
},
"x-kubernetes-list-type": "atomic"
},
"usb": {
"type": "array",
"items": {
"default": {},
"$ref": "#/definitions/v1.USBHostDevice"
},
"x-kubernetes-list-type": "atomic"
}
}
},
Expand Down Expand Up @@ -19177,6 +19185,44 @@
}
}
},
"v1.USBHostDevice": {
"type": "object",
"required": [
"resourceName"
],
"properties": {
"resourceName": {
"description": "Identifies the list of USB host devices. e.g: kubevirt.io/storage, kubevirt.io/bootable-usb, etc",
"type": "string",
"default": ""
},
"selectors": {
"type": "array",
"items": {
"default": {},
"$ref": "#/definitions/v1.USBSelector"
},
"x-kubernetes-list-type": "atomic"
}
}
},
"v1.USBSelector": {
"type": "object",
"required": [
"vendor",
"product"
],
"properties": {
"product": {
"type": "string",
"default": ""
},
"vendor": {
"type": "string",
"default": ""
}
}
},
"v1.UnpauseOptions": {
"description": "UnpauseOptions may be provided on unpause request.",
"type": "object",
Expand Down
39 changes: 39 additions & 0 deletions examples/vmi-usb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
apiVersion: kubevirt.io/v1
kind: VirtualMachineInstance
metadata:
labels:
special: vmi-usb
name: vmi-usb
spec:
domain:
devices:
disks:
- disk:
bus: virtio
name: containerdisk
- disk:
bus: virtio
name: cloudinitdisk
hostDevices:
- deviceName: kubevirt.io/storage
name: node-usb-to-vmi-storage
rng: {}
resources:
requests:
memory: 1024M
terminationGracePeriodSeconds: 0
volumes:
- containerDisk:
image: registry:5000/kubevirt/fedora-with-test-tooling-container-disk:devel
name: containerdisk
- cloudInitNoCloud:
userData: |-
#cloud-config
password: fedora
chpasswd: { expire: False }
packages:
- nginx
runcmd:
- [ "systemctl", "enable", "--now", "nginx" ]
name: cloudinitdisk
2 changes: 1 addition & 1 deletion hack/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ KUBEVIRT_NO_BAZEL=${KUBEVIRT_NO_BAZEL:-false}
HOST_ARCHITECTURE="$(uname -m)"

sandbox_root=${SANDBOX_DIR}/default/root
sandbox_hash="8befce554e9cbd5a873531d06fa7d9b3f39f1b45"
sandbox_hash="efe043bfc797b7ddacf24a7d9b36faf971835212"

function kubevirt::bootstrap::regenerate() {
(
Expand Down
1 change: 1 addition & 0 deletions hack/rpm-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ launcherbase_main="
libvirt-daemon-driver-qemu-${LIBVIRT_VERSION}
passt-${PASST_VERSION}
qemu-kvm-core-${QEMU_VERSION}
qemu-kvm-device-usb-host-${QEMU_VERSION}
swtpm-tools-${SWTPM_VERSION}
"
launcherbase_x86_64="
Expand Down
52 changes: 52 additions & 0 deletions manifests/generated/kv-resource.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,32 @@ spec:
type: object
type: array
x-kubernetes-list-type: atomic
usb:
items:
properties:
resourceName:
description: 'Identifies the list of USB host devices.
e.g: kubevirt.io/storage, kubevirt.io/bootable-usb,
etc'
type: string
selectors:
items:
properties:
product:
type: string
vendor:
type: string
required:
- product
- vendor
type: object
type: array
x-kubernetes-list-type: atomic
required:
- resourceName
type: object
type: array
x-kubernetes-list-type: atomic
type: object
seccompConfiguration:
description: SeccompConfiguration holds Seccomp configuration
Expand Down Expand Up @@ -3714,6 +3740,32 @@ spec:
type: object
type: array
x-kubernetes-list-type: atomic
usb:
items:
properties:
resourceName:
description: 'Identifies the list of USB host devices.
e.g: kubevirt.io/storage, kubevirt.io/bootable-usb,
etc'
type: string
selectors:
items:
properties:
product:
type: string
vendor:
type: string
required:
- product
- vendor
type: object
type: array
x-kubernetes-list-type: atomic
required:
- resourceName
type: object
type: array
x-kubernetes-list-type: atomic
type: object
seccompConfiguration:
description: SeccompConfiguration holds Seccomp configuration
Expand Down
3 changes: 3 additions & 0 deletions pkg/virt-controller/services/renderresources.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,9 @@ func validatePermittedHostDevices(spec *v1.VirtualMachineInstanceSpec, config *v
for _, dev := range hostDevs.MediatedDevices {
supportedHostDevicesMap[dev.ResourceName] = true
}
for _, dev := range hostDevs.USB {
supportedHostDevicesMap[dev.ResourceName] = true
}
for _, hostDev := range spec.Domain.Devices.GPUs {
if _, exist := supportedHostDevicesMap[hostDev.DeviceName]; !exist {
errors = append(errors, fmt.Sprintf("GPU %s is not permitted in permittedHostDevices configuration", hostDev.DeviceName))
Expand Down
2 changes: 2 additions & 0 deletions pkg/virt-handler/device-manager/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ go_library(
"mediated_devices_types.go",
"pci_device.go",
"socket_device.go",
"usb_device.go",
],
importpath = "kubevirt.io/kubevirt/pkg/virt-handler/device-manager",
visibility = ["//visibility:public"],
Expand All @@ -30,6 +31,7 @@ go_library(
"//vendor/github.com/golang/mock/gomock:go_default_library",
"//vendor/golang.org/x/net/context:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/rand:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/uuid:go_default_library",
"//vendor/k8s.io/client-go/kubernetes/typed/core/v1:go_default_library",
"//vendor/k8s.io/client-go/tools/cache:go_default_library",
Expand Down
7 changes: 6 additions & 1 deletion pkg/virt-handler/device-manager/device_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func NewDeviceController(
host: host,
maxDevices: maxDevices,
permissions: permissions,
backoff: []time.Duration{1 * time.Second, 2 * time.Second, 5 * time.Second, 10 * time.Second},
backoff: defaultBackoffTime,
virtConfig: clusterConfig,
mdevTypesManager: NewMDEVTypesManager(),
clientset: clientset,
Expand Down Expand Up @@ -236,6 +236,11 @@ func (c *DeviceController) updatePermittedHostDevicePlugins() []Device {
permittedDevices = append(permittedDevices, NewMediatedDevicePlugin(mdevUUIDs, mdevResourceName))
}
}

for resourceName, pluginDevices := range discoverAllowedUSBDevices(hostDevs.USB) {
permittedDevices = append(permittedDevices, NewUSBDevicePlugin(resourceName, pluginDevices))
}

return permittedDevices
}

Expand Down
4 changes: 0 additions & 4 deletions pkg/virt-handler/device-manager/device_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ func (fp *FakePlugin) Start(_ <-chan struct{}) (err error) {
return fp.Error
}

func (fp *FakePlugin) GetDevicePath() string {
return fp.devicePath
}

func (fp *FakePlugin) GetDeviceName() string {
return fp.deviceName
}
Expand Down
5 changes: 0 additions & 5 deletions pkg/virt-handler/device-manager/generic_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ const (

type Device interface {
Start(stop <-chan struct{}) (err error)
GetDevicePath() string
GetDeviceName() string
GetInitialized() bool
}
Expand Down Expand Up @@ -97,10 +96,6 @@ func NewGenericDevicePlugin(deviceName string, devicePath string, maxDevices int
return dpi
}

func (dpi *GenericDevicePlugin) GetDevicePath() string {
return dpi.devicePath
}

func (dpi *GenericDevicePlugin) GetDeviceName() string {
return dpi.deviceName
}
Expand Down
4 changes: 0 additions & 4 deletions pkg/virt-handler/device-manager/mediated_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,6 @@ func (dpi *MediatedDevicePlugin) Start(stop <-chan struct{}) (err error) {
return err
}

func (dpi *MediatedDevicePlugin) GetDevicePath() string {
return dpi.devicePath
}

func (dpi *MediatedDevicePlugin) GetDeviceName() string {
return dpi.resourceName
}
Expand Down
4 changes: 0 additions & 4 deletions pkg/virt-handler/device-manager/pci_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,6 @@ func (dpi *PCIDevicePlugin) healthCheck() error {
}
}

func (dpi *PCIDevicePlugin) GetDevicePath() string {
return dpi.devicePath
}

func (dpi *PCIDevicePlugin) GetDeviceName() string {
return dpi.resourceName
}
Expand Down
4 changes: 0 additions & 4 deletions pkg/virt-handler/device-manager/socket_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ func NewSocketDevicePlugin(socketName, socketDir, socket string, maxDevices int)
return dpi
}

func (dpi *SocketDevicePlugin) GetDevicePath() string {
return dpi.socketDir
}

func (dpi *SocketDevicePlugin) GetDeviceName() string {
return dpi.socketName
}
Expand Down
Loading

0 comments on commit 2c8b697

Please sign in to comment.