From 71808a004d751eaa3b6d1504a49f6346804cc8c5 Mon Sep 17 00:00:00 2001 From: Omar Ramadan Date: Tue, 27 Nov 2018 09:24:11 -0800 Subject: [PATCH] Add qemu USB devices Signed-off-by: Omar Ramadan --- src/cmd/linuxkit/run_qemu.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/cmd/linuxkit/run_qemu.go b/src/cmd/linuxkit/run_qemu.go index cc9178108..6836f7724 100644 --- a/src/cmd/linuxkit/run_qemu.go +++ b/src/cmd/linuxkit/run_qemu.go @@ -47,6 +47,8 @@ type QemuConfig struct { PublishedPorts []string NetdevConfig string UUID uuid.UUID + USB bool + Devices []string } const ( @@ -180,6 +182,11 @@ func runQemu(args []string) { publishFlags := multipleFlag{} flags.Var(&publishFlags, "publish", "Publish a vm's port(s) to the host (default [])") + // USB devices + usbEnabled := flags.Bool("usb", false, "Enable USB controller") + deviceFlags := multipleFlag{} + flags.Var(&deviceFlags, "device", "Add USB host device(s). Format driver[,prop=value][,...] -- add device, like -device on the qemu command line.") + if err := flags.Parse(args); err != nil { log.Fatal("Unable to parse args") } @@ -332,6 +339,8 @@ func runQemu(args []string) { PublishedPorts: publishFlags, NetdevConfig: netdevConfig, UUID: vmUUID, + USB: *usbEnabled, + Devices: deviceFlags, } config = discoverBackend(config) @@ -663,6 +672,13 @@ func buildQemuCmdline(config QemuConfig) (QemuConfig, []string) { qemuArgs = append(qemuArgs, "-nographic") } + if config.USB == true { + qemuArgs = append(qemuArgs, "-usb") + } + for _, d := range config.Devices { + qemuArgs = append(qemuArgs, "-device", d) + } + return config, qemuArgs }