Fix trivial device assignment bugs
1) unbind only when possible (if device is already unbound, we can't
unbind)
2) return eh device only when existing
Test: manual
Change-Id: I40b436ed74eca48688f9cd0d7fff3fa192b2eb05
diff --git a/virtualizationservice/vfio_handler/src/aidl.rs b/virtualizationservice/vfio_handler/src/aidl.rs
index f082aba..9952496 100644
--- a/virtualizationservice/vfio_handler/src/aidl.rs
+++ b/virtualizationservice/vfio_handler/src/aidl.rs
@@ -132,12 +132,15 @@
Some(format!("invalid filename {device:?}")),
));
};
- write(path.join("driver/unbind"), device_str.as_bytes()).map_err(|e| {
- Status::new_exception_str(
- ExceptionCode::SERVICE_SPECIFIC,
- Some(format!("could not unbind {device_str}: {e:?}")),
- )
- })?;
+ let unbind_path = path.join("driver/unbind");
+ if unbind_path.exists() {
+ write(&unbind_path, device_str.as_bytes()).map_err(|e| {
+ Status::new_exception_str(
+ ExceptionCode::SERVICE_SPECIFIC,
+ Some(format!("could not unbind {device_str}: {e:?}")),
+ )
+ })?;
+ }
// bind to VFIO
write(path.join("driver_override"), b"vfio-platform").map_err(|e| {