Handle failures after partial mounts
When we try mounting an EmulatedVolume, we may mount sdcardfs but fail
in any of the FUSE mounts, in this case we should unmount whatever
mounts we made during the mount.
Test: Intentionally causing a partial failure, verified that sdcardfs
gets unmounted
Bug: 147610762
Change-Id: I29ed044ed8ab8aa3dd83bc97a49eb3140ce4fe27
diff --git a/model/EmulatedVolume.cpp b/model/EmulatedVolume.cpp
index 054a58b..082dea5 100644
--- a/model/EmulatedVolume.cpp
+++ b/model/EmulatedVolume.cpp
@@ -245,12 +245,19 @@
bool is_ready = false;
callback->onVolumeChecking(std::move(fd), getPath(), getInternalPath(), &is_ready);
if (!is_ready) {
+ fd.reset();
+ doUnmount();
return -EIO;
}
}
// Only do the bind-mounts when we know for sure the FUSE daemon can resolve the path.
- return mountFuseBindMounts();
+ status_t res = mountFuseBindMounts();
+ if (res != OK) {
+ fd.reset();
+ doUnmount();
+ }
+ return res;
}
return OK;