[lxc-devel] [lxd/master] lxd/instance/drivers: Add USB controller to VMs

monstermunchkin on Github lxc-bot at linuxcontainers.org
Thu Oct 8 08:16:47 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20201008/253a0d20/attachment.bin>
-------------- next part --------------
From 87e44ddcf8dfaa843b7375601aba550182217020 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Thu, 8 Oct 2020 09:22:56 +0200
Subject: [PATCH 1/2] lxd/instance/drivers: Enable USB for VMs

This enables USB for VMs.

Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
 lxd/instance/drivers/driver_qemu_templates.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lxd/instance/drivers/driver_qemu_templates.go b/lxd/instance/drivers/driver_qemu_templates.go
index 6950919840..2e825176b0 100644
--- a/lxd/instance/drivers/driver_qemu_templates.go
+++ b/lxd/instance/drivers/driver_qemu_templates.go
@@ -23,7 +23,7 @@ type = "pseries"
 type = "s390-ccw-virtio"
 {{end -}}
 accel = "kvm"
-usb = "off"
+usb = "on"
 graphics = "off"
 
 {{if eq .architecture "x86_64" -}}

From a6c11f1114c67cb1c18a2c9ba83a5feeb92e5820 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Thu, 8 Oct 2020 10:06:49 +0200
Subject: [PATCH 2/2] lxd/instance/drivers: Add USB controller to QEMU config

This adds a USB controller to the QEMU config.

Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
 lxd/instance/drivers/driver_qemu.go           | 11 +++++++++++
 lxd/instance/drivers/driver_qemu_templates.go | 11 +++++++++++
 2 files changed, 22 insertions(+)

diff --git a/lxd/instance/drivers/driver_qemu.go b/lxd/instance/drivers/driver_qemu.go
index 62c1de7117..0b697cbf58 100644
--- a/lxd/instance/drivers/driver_qemu.go
+++ b/lxd/instance/drivers/driver_qemu.go
@@ -1749,6 +1749,17 @@ func (vm *qemu) generateQemuConfigFile(busName string, devConfs []*deviceConfig.
 		return "", err
 	}
 
+	devBus, devAddr, multi = bus.allocate(busFunctionGroupGeneric)
+	err = qemuUSB.Execute(sb, map[string]interface{}{
+		"bus":           bus.name,
+		"devBus":        devBus,
+		"devAddr":       devAddr,
+		"multifunction": multi,
+	})
+	if err != nil {
+		return "", err
+	}
+
 	devBus, devAddr, multi = bus.allocate(busFunctionGroupNone)
 	err = qemuSCSI.Execute(sb, map[string]interface{}{
 		"bus":           bus.name,
diff --git a/lxd/instance/drivers/driver_qemu_templates.go b/lxd/instance/drivers/driver_qemu_templates.go
index 2e825176b0..c1b383bc6b 100644
--- a/lxd/instance/drivers/driver_qemu_templates.go
+++ b/lxd/instance/drivers/driver_qemu_templates.go
@@ -497,3 +497,14 @@ x-vga = "on"
 multifunction = "on"
 {{- end }}
 `))
+
+var qemuUSB = template.Must(template.New("qemuUSB").Parse(`
+# USB controller
+[device "qemu_usb"]
+driver = "qemu-xhci"
+bus = "{{.devBus}}"
+addr = "{{.devAddr}}"
+{{if .multifunction -}}
+multifunction = "on"
+{{- end }}
+`))


More information about the lxc-devel mailing list