-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
machine: qemu: add usb host passthrough
QEMU usb-host driver which is the one for passthrough, supports two options for selecting an USB devices in the host to provide it to the VM: - Bus and Device number the device is plugged - Vendor and Product information of the USB devices https://qemu-project.gitlab.io/qemu/system/devices/usb.html This commit allows a user to configure podman machine with either of options, with new --usb command line option for podman machine init. Examples podman machine init tosovm4 --usb vendor=13d3,product=5406 podman machine init tosovm3 --usb bus=1,devnum=4 --usb bus=1,devnum=3 This commit also allows a user to change the USBs configured with --usb command line option for podman machine set. Note that this commit does not handle host device permissions nor verify that the USB devices exists. Signed-off-by: Victor Toso <victortoso@redhat.com>
- Loading branch information
1 parent
6bb2edd
commit c23963d
Showing
15 changed files
with
260 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package qemu | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/containers/podman/v4/pkg/machine" | ||
) | ||
|
||
func TestUSBParsing(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
args []string | ||
result []machine.USBConfig | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "Good vendor and product", | ||
args: []string{"vendor=13d3,product=5406", "vendor=08ec,product=0016"}, | ||
result: []machine.USBConfig{ | ||
{ | ||
Vendor: 5075, | ||
Product: 21510, | ||
}, | ||
{ | ||
Vendor: 2284, | ||
Product: 22, | ||
}, | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "Good bus and device number", | ||
args: []string{"bus=1,devnum=4", "bus=1,devnum=3"}, | ||
result: []machine.USBConfig{ | ||
{ | ||
Bus: "1", | ||
DevNumber: "4", | ||
}, | ||
{ | ||
Bus: "1", | ||
DevNumber: "3", | ||
}, | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "Bad vendor and product, not hexa", | ||
args: []string{"vendor=13dk,product=5406"}, | ||
result: []machine.USBConfig{}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "Bad vendor and product, bad separator", | ||
args: []string{"vendor=13d3:product=5406"}, | ||
result: []machine.USBConfig{}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "Bad vendor and product, missing equal", | ||
args: []string{"vendor=13d3:product-5406"}, | ||
result: []machine.USBConfig{}, | ||
wantErr: true, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
got, err := parseUSBs(test.args) | ||
if (err != nil) != test.wantErr { | ||
t.Errorf("parseUUBs error = %v, wantErr %v", err, test.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(got, test.result) { | ||
t.Errorf("parseUUBs got %v, want %v", got, test.result) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.