devices: vhost-vsock: improve open error message
Include the vhost vsock device path in the error message if opening it
fails, and remove the now-redundant file exists check.
BUG=None
TEST=crosvm run --vhost-vsock-device /does/not/exist ...
Change-Id: I1f66c03df8b7b7ad68339b1c151b19ce8fa37a5e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3806077
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
diff --git a/devices/src/virtio/vhost/vsock.rs b/devices/src/virtio/vhost/vsock.rs
index 6984caa..92510a3 100644
--- a/devices/src/virtio/vhost/vsock.rs
+++ b/devices/src/virtio/vhost/vsock.rs
@@ -55,17 +55,24 @@
impl Vsock {
/// Create a new virtio-vsock device with the given VM cid.
pub fn new(base_features: u64, vhost_config: &VhostVsockConfig) -> anyhow::Result<Vsock> {
+ let vhost_vsock_device_default = PathBuf::from(VHOST_VSOCK_DEFAULT_PATH);
+ let vhost_vsock_device = vhost_config
+ .device
+ .as_ref()
+ .unwrap_or(&vhost_vsock_device_default);
let device_file = open_file(
- vhost_config
- .device
- .as_ref()
- .unwrap_or(&PathBuf::from(VHOST_VSOCK_DEFAULT_PATH)),
+ vhost_vsock_device,
OpenOptions::new()
.read(true)
.write(true)
.custom_flags(libc::O_CLOEXEC | libc::O_NONBLOCK),
)
- .context("failed to open virtual socket device")?;
+ .with_context(|| {
+ format!(
+ "failed to open virtual socket device {}",
+ vhost_vsock_device.display(),
+ )
+ })?;
let kill_evt = Event::new().map_err(Error::CreateKillEvent)?;
let handle = VhostVsockHandle::new(device_file);
diff --git a/src/crosvm/sys/unix/config.rs b/src/crosvm/sys/unix/config.rs
index 2e4f817..c9a2e67 100644
--- a/src/crosvm/sys/unix/config.rs
+++ b/src/crosvm/sys/unix/config.rs
@@ -113,7 +113,6 @@
}
pub fn validate_config(cfg: &mut Config) -> std::result::Result<(), String> {
- crate::crosvm::check_opt_path!(cfg.vhost_vsock_device);
if cfg.host_ip.is_some() || cfg.netmask.is_some() || cfg.mac_address.is_some() {
if cfg.host_ip.is_none() {
return Err("`host-ip` missing from network config".to_string());