mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-06 10:32:10 +00:00
crosvm: argh-ify vfio command
Usage: crosvm vfio <command> [<args>] add/remove host vfio pci device into guest Options: --help display usage information Commands: add ADD remove REMOVE Change-Id: I79d0b5205b1ae8d880b26cf12d61a2f70bb73756 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3680295 Reviewed-by: Dennis Kempin <denniskempin@google.com> Commit-Queue: Anton Romanov <romanton@google.com> Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
parent
9140f8d41c
commit
d19b575fd1
2 changed files with 57 additions and 38 deletions
|
@ -277,10 +277,44 @@ pub struct UsbCommand {
|
||||||
/// Show package version.
|
/// Show package version.
|
||||||
pub struct VersionCommand {}
|
pub struct VersionCommand {}
|
||||||
|
|
||||||
#[generate_catchall_args]
|
#[derive(FromArgs)]
|
||||||
|
#[argh(subcommand, name = "add")]
|
||||||
|
/// ADD
|
||||||
|
pub struct VfioAddSubCommand {
|
||||||
|
#[argh(positional)]
|
||||||
|
/// path to host's vfio sysfs
|
||||||
|
pub vfio_path: PathBuf,
|
||||||
|
#[argh(positional, arg_name = "VM_SOCKET")]
|
||||||
|
/// VM Socket path
|
||||||
|
pub socket_path: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(FromArgs)]
|
||||||
|
#[argh(subcommand, name = "remove")]
|
||||||
|
/// REMOVE
|
||||||
|
pub struct VfioRemoveSubCommand {
|
||||||
|
#[argh(positional)]
|
||||||
|
/// path to host's vfio sysfs
|
||||||
|
pub vfio_path: PathBuf,
|
||||||
|
#[argh(positional, arg_name = "VM_SOCKET")]
|
||||||
|
/// VM Socket path
|
||||||
|
pub socket_path: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(FromArgs)]
|
||||||
|
#[argh(subcommand)]
|
||||||
|
pub enum VfioSubCommand {
|
||||||
|
Add(VfioAddSubCommand),
|
||||||
|
Remove(VfioRemoveSubCommand),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(FromArgs)]
|
||||||
#[argh(subcommand, name = "vfio")]
|
#[argh(subcommand, name = "vfio")]
|
||||||
/// add/remove host vfio pci device into guest
|
/// add/remove host vfio pci device into guest
|
||||||
pub struct VfioCrosvmCommand {}
|
pub struct VfioCrosvmCommand {
|
||||||
|
#[argh(subcommand)]
|
||||||
|
pub command: VfioSubCommand,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(FromArgs)]
|
#[derive(FromArgs)]
|
||||||
#[argh(subcommand, name = "device")]
|
#[argh(subcommand, name = "device")]
|
||||||
|
|
57
src/main.rs
57
src/main.rs
|
@ -2779,44 +2779,29 @@ fn modify_battery(cmd: crosvm::BatteryCommand) -> std::result::Result<(), ()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn modify_vfio(cmd: crosvm::VfioCrosvmCommand) -> std::result::Result<(), ()> {
|
fn modify_vfio(cmd: crosvm::VfioCrosvmCommand) -> std::result::Result<(), ()> {
|
||||||
if cmd.args.len() < 3 {
|
let (request, socket_path, vfio_path) = match cmd.command {
|
||||||
print_help(
|
crosvm::VfioSubCommand::Add(c) => {
|
||||||
"crosvm vfio",
|
let request = VmRequest::VfioCommand {
|
||||||
"[add | remove host_vfio_sysfs] VM_SOCKET...",
|
vfio_path: c.vfio_path.clone(),
|
||||||
&[],
|
add: true,
|
||||||
);
|
hp_interrupt: true,
|
||||||
return Err(());
|
};
|
||||||
}
|
(request, c.socket_path, c.vfio_path)
|
||||||
|
}
|
||||||
let mut args = cmd.args.into_iter();
|
crosvm::VfioSubCommand::Remove(c) => {
|
||||||
// This unwrap will not panic because of the above length check.
|
let request = VmRequest::VfioCommand {
|
||||||
let command = args.next().unwrap();
|
vfio_path: c.vfio_path.clone(),
|
||||||
let path_str = args.next().unwrap();
|
add: true,
|
||||||
let vfio_path = PathBuf::from(&path_str);
|
hp_interrupt: true,
|
||||||
if !vfio_path.exists() || !vfio_path.is_dir() {
|
};
|
||||||
error!("Invalid host sysfs path: {}", path_str);
|
(request, c.socket_path, c.vfio_path)
|
||||||
return Err(());
|
|
||||||
}
|
|
||||||
|
|
||||||
let socket_path = args.next().unwrap();
|
|
||||||
let socket_path = Path::new(&socket_path);
|
|
||||||
|
|
||||||
let add = match command.as_ref() {
|
|
||||||
"add" => true,
|
|
||||||
"remove" => false,
|
|
||||||
other => {
|
|
||||||
error!("Invalid vfio command {}", other);
|
|
||||||
return Err(());
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
if !vfio_path.exists() || !vfio_path.is_dir() {
|
||||||
let hp_interrupt = true;
|
error!("Invalid host sysfs path: {:?}", vfio_path);
|
||||||
let request = VmRequest::VfioCommand {
|
return Err(());
|
||||||
vfio_path,
|
}
|
||||||
add,
|
handle_request(&request, Path::new(&socket_path))?;
|
||||||
hp_interrupt,
|
|
||||||
};
|
|
||||||
handle_request(&request, socket_path)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue