mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2024-11-24 20:48:55 +00:00
vm_control: Factor net tap removal to vm_control
This CL factors out do_net_remove to vm_control from main.rs. do_net_remove sends a VmRequest to remove a tap device. Test= presubmit tests. Bug=b:294777126 Change-Id: I82e2741a044b1144f04424deacc905fbe079560c Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4846021 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Alexandre Courbot <acourbot@chromium.org> Commit-Queue: Ningyuan Wang <ningyuan@google.com>
This commit is contained in:
parent
236b5167d2
commit
9c031a9840
2 changed files with 20 additions and 4 deletions
10
src/main.rs
10
src/main.rs
|
@ -59,6 +59,8 @@ use vm_control::client::do_gpu_display_remove;
|
|||
use vm_control::client::do_modify_battery;
|
||||
#[cfg(feature = "pci-hotplug")]
|
||||
use vm_control::client::do_net_add;
|
||||
#[cfg(feature = "pci-hotplug")]
|
||||
use vm_control::client::do_net_remove;
|
||||
use vm_control::client::do_swap_status;
|
||||
use vm_control::client::do_usb_attach;
|
||||
use vm_control::client::do_usb_detach;
|
||||
|
@ -74,8 +76,6 @@ use vm_control::BalloonControlCommand;
|
|||
use vm_control::DiskControlCommand;
|
||||
use vm_control::HotPlugDeviceInfo;
|
||||
use vm_control::HotPlugDeviceType;
|
||||
#[cfg(feature = "pci-hotplug")]
|
||||
use vm_control::NetControlCommand;
|
||||
use vm_control::RestoreCommand;
|
||||
use vm_control::SnapshotCommand;
|
||||
use vm_control::SwapCommand;
|
||||
|
@ -324,8 +324,10 @@ fn modify_virtio_net(cmd: cmdline::VirtioNetCommand) -> std::result::Result<(),
|
|||
info!("Tap device {} plugged to PCI bus {}", &c.tap_name, bus_num);
|
||||
}
|
||||
cmdline::VirtioNetSubCommand::RemoveTap(c) => {
|
||||
let request = VmRequest::HotPlugNetCommand(NetControlCommand::RemoveTap(c.bus));
|
||||
vms_request(&request, c.socket_path)?;
|
||||
do_net_remove(c.bus, &c.socket_path).map_err(|e| {
|
||||
error!("Tap device remove failed: {:?}", &e);
|
||||
})?;
|
||||
info!("Tap device removed from PCI bus {}", &c.bus);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -73,6 +73,20 @@ pub fn do_net_add<T: AsRef<Path> + std::fmt::Debug>(
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "pci-hotplug")]
|
||||
/// Send a `VmRequest` for removing hotplugged PCI device that expects `VmResponse::Ok`
|
||||
pub fn do_net_remove<T: AsRef<Path> + std::fmt::Debug>(
|
||||
bus_num: u8,
|
||||
socket_path: T,
|
||||
) -> AnyHowResult<()> {
|
||||
let request = VmRequest::HotPlugNetCommand(NetControlCommand::RemoveTap(bus_num));
|
||||
let response = handle_request(&request, socket_path).map_err(|()| anyhow!("socket error: "))?;
|
||||
match response {
|
||||
VmResponse::Ok => Ok(()),
|
||||
e => Err(anyhow!("Unexpected response: {:#}", e)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn do_usb_attach<T: AsRef<Path> + std::fmt::Debug>(
|
||||
socket_path: T,
|
||||
dev_path: &Path,
|
||||
|
|
Loading…
Reference in a new issue