From 1dbe52fac496405c06f1eb23df5a04a8be8221ea Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Wed, 15 Jun 2022 12:52:54 -0700 Subject: [PATCH] vm_control: clarify that USB attach only uses dev_path The bus/address and vendor/product IDs are unused internally; only the usbdevfs device path matters. Update the internal API parameters and documentation to match. The crosvm_control `crosvm_client_usb_attach()` function must keep the extra parameters to maintain API compatibility, but its documentation is updated to note that they are unused. BUG=None TEST=Attach USB device to Crostini on trogdor Change-Id: I7086f61a420be1dbf3dd1877fa86a5e82c0c5c77 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3708640 Tested-by: kokoro Reviewed-by: Dennis Kempin Commit-Queue: Daniel Verkamp --- crosvm_control/src/lib.rs | 20 +++++++++---------- .../host_backend_device_provider.rs | 2 +- src/main.rs | 3 +-- vm_control/src/client.rs | 12 +---------- vm_control/src/lib.rs | 4 ---- 5 files changed, 12 insertions(+), 29 deletions(-) diff --git a/crosvm_control/src/lib.rs b/crosvm_control/src/lib.rs index 8a75357570..41b41fd705 100644 --- a/crosvm_control/src/lib.rs +++ b/crosvm_control/src/lib.rs @@ -174,10 +174,10 @@ pub extern "C" fn crosvm_client_usb_list( /// # Arguments /// /// * `socket_path` - Path to the crosvm control socket -/// * `bus` - USB device bus ID -/// * `addr` - USB device address -/// * `vid` - USB device vendor ID -/// * `pid` - USB device product ID +/// * `bus` - USB device bus ID (unused) +/// * `addr` - USB device address (unused) +/// * `vid` - USB device vendor ID (unused) +/// * `pid` - USB device product ID (unused) /// * `dev_path` - Path to the USB device (Most likely `/dev/bus/usb//`). /// * `out_port` - (optional) internal port will be written here if provided. /// @@ -185,10 +185,10 @@ pub extern "C" fn crosvm_client_usb_list( #[no_mangle] pub extern "C" fn crosvm_client_usb_attach( socket_path: *const c_char, - bus: u8, - addr: u8, - vid: u16, - pid: u16, + _bus: u8, + _addr: u8, + _vid: u16, + _pid: u16, dev_path: *const c_char, out_port: *mut u8, ) -> bool { @@ -199,9 +199,7 @@ pub extern "C" fn crosvm_client_usb_attach( } let dev_path = Path::new(unsafe { CStr::from_ptr(dev_path) }.to_str().unwrap_or("")); - if let Ok(UsbControlResult::Ok { port }) = - do_usb_attach(&socket_path, bus, addr, vid, pid, dev_path) - { + if let Ok(UsbControlResult::Ok { port }) = do_usb_attach(&socket_path, dev_path) { if !out_port.is_null() { unsafe { *out_port = port }; } diff --git a/devices/src/usb/host_backend/host_backend_device_provider.rs b/devices/src/usb/host_backend/host_backend_device_provider.rs index 738495512c..9401efc7fe 100644 --- a/devices/src/usb/host_backend/host_backend_device_provider.rs +++ b/devices/src/usb/host_backend/host_backend_device_provider.rs @@ -263,7 +263,7 @@ impl ProviderInner { let tube = self.control_tube.lock(); let cmd = tube.recv().map_err(Error::ReadControlTube)?; let result = match cmd { - UsbControlCommand::AttachDevice { file, .. } => self.handle_attach_device(file), + UsbControlCommand::AttachDevice { file } => self.handle_attach_device(file), UsbControlCommand::DetachDevice { port } => self.handle_detach_device(port), UsbControlCommand::ListDevice { ports } => self.handle_list_devices(ports), }; diff --git a/src/main.rs b/src/main.rs index 5f9ce226a0..09a05a3123 100644 --- a/src/main.rs +++ b/src/main.rs @@ -366,10 +366,9 @@ fn make_rt(cmd: cmdline::MakeRTCommand) -> std::result::Result<(), ()> { } fn usb_attach(cmd: cmdline::UsbAttachCommand) -> ModifyUsbResult { - let (bus, addr, vid, pid) = cmd.addr; let dev_path = Path::new(&cmd.dev_path); - do_usb_attach(cmd.socket_path, bus, addr, vid, pid, dev_path) + do_usb_attach(cmd.socket_path, dev_path) } fn usb_detach(cmd: cmdline::UsbDetachCommand) -> ModifyUsbResult { diff --git a/vm_control/src/client.rs b/vm_control/src/client.rs index 6b7ff425ed..2a50e24d24 100644 --- a/vm_control/src/client.rs +++ b/vm_control/src/client.rs @@ -46,22 +46,12 @@ pub fn vms_request + std::fmt::Debug>( pub fn do_usb_attach + std::fmt::Debug>( socket_path: T, - bus: u8, - addr: u8, - vid: u16, - pid: u16, dev_path: &Path, ) -> ModifyUsbResult { let usb_file = open_file(dev_path, OpenOptions::new().read(true).write(true)) .map_err(|e| ModifyUsbError::FailedToOpenDevice(dev_path.into(), e))?; - let request = VmRequest::UsbCommand(UsbControlCommand::AttachDevice { - bus, - addr, - vid, - pid, - file: usb_file, - }); + let request = VmRequest::UsbCommand(UsbControlCommand::AttachDevice { file: usb_file }); let response = handle_request(&request, socket_path).map_err(|_| ModifyUsbError::SocketFailed)?; match response { diff --git a/vm_control/src/lib.rs b/vm_control/src/lib.rs index dc61c29370..e3cd5f876e 100644 --- a/vm_control/src/lib.rs +++ b/vm_control/src/lib.rs @@ -186,10 +186,6 @@ pub enum DiskControlResult { #[derive(Serialize, Deserialize, Debug)] pub enum UsbControlCommand { AttachDevice { - bus: u8, - addr: u8, - vid: u16, - pid: u16, #[serde(with = "with_as_descriptor")] file: File, },