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 <noreply+kokoro@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
This commit is contained in:
Daniel Verkamp 2022-06-15 12:52:54 -07:00 committed by Chromeos LUCI
parent 7afb3be9ca
commit 1dbe52fac4
5 changed files with 12 additions and 29 deletions

View file

@ -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/<bus>/<addr>`).
/// * `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 };
}

View file

@ -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),
};

View file

@ -366,10 +366,9 @@ fn make_rt(cmd: cmdline::MakeRTCommand) -> std::result::Result<(), ()> {
}
fn usb_attach(cmd: cmdline::UsbAttachCommand) -> ModifyUsbResult<UsbControlResult> {
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<UsbControlResult> {

View file

@ -46,22 +46,12 @@ pub fn vms_request<T: AsRef<Path> + std::fmt::Debug>(
pub fn do_usb_attach<T: AsRef<Path> + std::fmt::Debug>(
socket_path: T,
bus: u8,
addr: u8,
vid: u16,
pid: u16,
dev_path: &Path,
) -> ModifyUsbResult<UsbControlResult> {
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 {

View file

@ -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,
},