|
| 1 | +//go:build !darwin |
| 2 | + |
1 | 3 | package command
|
2 | 4 |
|
3 | 5 | import (
|
|
6 | 8 | "io/fs"
|
7 | 9 | "os"
|
8 | 10 | "strconv"
|
9 |
| - "strings" |
10 | 11 | "time"
|
11 | 12 |
|
12 | 13 | "github.com/containers/podman/v5/pkg/machine/define"
|
@@ -58,7 +59,7 @@ func (q *QemuCmd) SetNetwork() {
|
58 | 59 | }
|
59 | 60 |
|
60 | 61 | // SetNetwork adds a network device to the machine
|
61 |
| -func (q *QemuCmd) SetUSBHostPassthrough(usbs []USBConfig) { |
| 62 | +func (q *QemuCmd) SetUSBHostPassthrough(usbs []define.USBConfig) { |
62 | 63 | if len(usbs) == 0 {
|
63 | 64 | return
|
64 | 65 | }
|
@@ -115,76 +116,6 @@ func (q *QemuCmd) Build() []string {
|
115 | 116 | return *q
|
116 | 117 | }
|
117 | 118 |
|
118 |
| -type USBConfig struct { |
119 |
| - Bus string |
120 |
| - DevNumber string |
121 |
| - Vendor int |
122 |
| - Product int |
123 |
| -} |
124 |
| - |
125 |
| -func ParseUSBs(usbs []string) ([]USBConfig, error) { |
126 |
| - configs := []USBConfig{} |
127 |
| - for _, str := range usbs { |
128 |
| - if str == "" { |
129 |
| - // Ignore --usb="" as it can be used to reset USBConfigs |
130 |
| - continue |
131 |
| - } |
132 |
| - |
133 |
| - vals := strings.Split(str, ",") |
134 |
| - if len(vals) != 2 { |
135 |
| - return configs, fmt.Errorf("usb: fail to parse: missing ',': %s", str) |
136 |
| - } |
137 |
| - |
138 |
| - left := strings.Split(vals[0], "=") |
139 |
| - if len(left) != 2 { |
140 |
| - return configs, fmt.Errorf("usb: fail to parse: missing '=': %s", str) |
141 |
| - } |
142 |
| - |
143 |
| - right := strings.Split(vals[1], "=") |
144 |
| - if len(right) != 2 { |
145 |
| - return configs, fmt.Errorf("usb: fail to parse: missing '=': %s", str) |
146 |
| - } |
147 |
| - |
148 |
| - option := left[0] + "_" + right[0] |
149 |
| - |
150 |
| - switch option { |
151 |
| - case "bus_devnum", "devnum_bus": |
152 |
| - bus, devnumber := left[1], right[1] |
153 |
| - if right[0] == "bus" { |
154 |
| - bus, devnumber = devnumber, bus |
155 |
| - } |
156 |
| - |
157 |
| - configs = append(configs, USBConfig{ |
158 |
| - Bus: bus, |
159 |
| - DevNumber: devnumber, |
160 |
| - }) |
161 |
| - case "vendor_product", "product_vendor": |
162 |
| - vendorStr, productStr := left[1], right[1] |
163 |
| - if right[0] == "vendor" { |
164 |
| - vendorStr, productStr = productStr, vendorStr |
165 |
| - } |
166 |
| - |
167 |
| - vendor, err := strconv.ParseInt(vendorStr, 16, 0) |
168 |
| - if err != nil { |
169 |
| - return configs, fmt.Errorf("usb: fail to convert vendor of %s: %s", str, err) |
170 |
| - } |
171 |
| - |
172 |
| - product, err := strconv.ParseInt(productStr, 16, 0) |
173 |
| - if err != nil { |
174 |
| - return configs, fmt.Errorf("usb: fail to convert product of %s: %s", str, err) |
175 |
| - } |
176 |
| - |
177 |
| - configs = append(configs, USBConfig{ |
178 |
| - Vendor: int(vendor), |
179 |
| - Product: int(product), |
180 |
| - }) |
181 |
| - default: |
182 |
| - return configs, fmt.Errorf("usb: fail to parse: %s", str) |
183 |
| - } |
184 |
| - } |
185 |
| - return configs, nil |
186 |
| -} |
187 |
| - |
188 | 119 | type Monitor struct {
|
189 | 120 | // Address portion of the qmp monitor (/tmp/tmp.sock)
|
190 | 121 | Address define.VMFile
|
|
0 commit comments