Refactor fs_mgr_overlayfs_teardown()
Right now fs_mgr_overlayfs_teardown() does slightly different things
when called from the userspace or recovery. This is accomplished by many
runtime checks, runtime assumptions and conditional execution of code.
This makes the control flow of the function very hard to follow, and
assumptions becomes more fragile as the function becomes more complex.
This CL forks fs_mgr_overlayfs_teardown() and removes "recovery" bits
from it. A new entry point TeardownAllOverlayForMountPoint() is added
for recovery.
Recovery (fastbootd) should call TeardownAllOverlayForMountPoint() to
teardown overlays of all sources (cache dir, scratch device or DSU).
While fs_mgr_overlayfs_teardown() should only be called from the
userspace.
Also apply some linter suggestions.
Bug: 165925766
Test: adb-remount-test.sh
Change-Id: I7ff7e3409c910782e1ec207fcd02b967a9762bc1
diff --git a/fastboot/device/flashing.cpp b/fastboot/device/flashing.cpp
index 1bf4c9c..333ca50 100644
--- a/fastboot/device/flashing.cpp
+++ b/fastboot/device/flashing.cpp
@@ -67,7 +67,7 @@
if ((partition + device->GetCurrentSlot()) == partition_name) {
mount_metadata.emplace();
- fs_mgr_overlayfs_teardown(entry.mount_point.c_str());
+ android::fs_mgr::TeardownAllOverlayForMountPoint(entry.mount_point);
}
}
}
@@ -194,7 +194,7 @@
if (!FlashPartitionTable(super_name, *new_metadata.get())) {
return device->WriteFail("Unable to flash new partition table");
}
- fs_mgr_overlayfs_teardown();
+ android::fs_mgr::TeardownAllOverlayForMountPoint();
sync();
return device->WriteOkay("Successfully flashed partition table");
}
@@ -234,7 +234,7 @@
if (!UpdateAllPartitionMetadata(device, super_name, *new_metadata.get())) {
return device->WriteFail("Unable to write new partition table");
}
- fs_mgr_overlayfs_teardown();
+ android::fs_mgr::TeardownAllOverlayForMountPoint();
sync();
return device->WriteOkay("Successfully updated partition table");
}