summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Salyzyn <salyzyn@google.com>2018-10-12 09:33:44 -0700
committerMark Salyzyn <salyzyn@google.com>2018-10-26 20:57:14 +0000
commit044f04baedc4b35be4145aecdf38b7280496c218 (patch)
tree39ed2925b996a0d98a042bf0e7e9a59f5ad7e2d9
parentdd85c74655400347aee5f6bfecd827a311f16ca4 (diff)
downloadsystem_core-044f04baedc4b35be4145aecdf38b7280496c218.tar.gz
system_core-044f04baedc4b35be4145aecdf38b7280496c218.tar.bz2
system_core-044f04baedc4b35be4145aecdf38b7280496c218.zip
fastboot: wipe overlayfs for partition
Arrange to delete the overlayfs backing when a specified partition has been flashed. Test: manual Bug: 109821005 Bug: 117605276 Change-Id: I1c6a0341c6cd2ecfbb7c71bec5679a74d579aadd
-rw-r--r--fastboot/device/flashing.cpp32
-rwxr-xr-xfs_mgr/tests/adb-remount-test.sh27
2 files changed, 56 insertions, 3 deletions
diff --git a/fastboot/device/flashing.cpp b/fastboot/device/flashing.cpp
index 2347496b9..16443c097 100644
--- a/fastboot/device/flashing.cpp
+++ b/fastboot/device/flashing.cpp
@@ -21,10 +21,15 @@
#include <algorithm>
#include <memory>
+#include <set>
+#include <string>
+#include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/strings.h>
#include <ext4_utils/ext4_utils.h>
+#include <fs_mgr_overlayfs.h>
+#include <fstab/fstab.h>
#include <liblp/builder.h>
#include <liblp/liblp.h>
#include <sparse/sparse.h>
@@ -32,13 +37,35 @@
#include "fastboot_device.h"
#include "utility.h"
+using namespace android::fs_mgr;
+using namespace std::literals;
+
namespace {
constexpr uint32_t SPARSE_HEADER_MAGIC = 0xed26ff3a;
-} // namespace
+void WipeOverlayfsForPartition(FastbootDevice* device, const std::string& partition_name) {
+ // May be called, in the case of sparse data, multiple times so cache/skip.
+ static std::set<std::string> wiped;
+ if (wiped.find(partition_name) != wiped.end()) return;
+ wiped.insert(partition_name);
+ // Following appears to have a first time 2% impact on flashing speeds.
+
+ // Convert partition_name to a validated mount point and wipe.
+ std::unique_ptr<fstab, decltype(&fs_mgr_free_fstab)> fstab(fs_mgr_read_fstab_default(),
+ fs_mgr_free_fstab);
+ for (auto i = 0; i < fstab->num_entries; i++) {
+ const auto mount_point = fstab->recs[i].mount_point;
+ if (!mount_point) continue;
+ auto partition = android::base::Basename(mount_point);
+ if ("/"s == mount_point) partition = "system";
+ if ((partition + device->GetCurrentSlot()) == partition_name) {
+ fs_mgr_overlayfs_teardown(mount_point);
+ }
+ }
+}
-using namespace android::fs_mgr;
+} // namespace
int FlashRawDataChunk(int fd, const char* data, size_t len) {
size_t ret = 0;
@@ -101,6 +128,7 @@ int Flash(FastbootDevice* device, const std::string& partition_name) {
} else if (data.size() > get_block_device_size(handle.fd())) {
return -EOVERFLOW;
}
+ WipeOverlayfsForPartition(device, partition_name);
return FlashBlockDevice(handle.fd(), data);
}
diff --git a/fs_mgr/tests/adb-remount-test.sh b/fs_mgr/tests/adb-remount-test.sh
index d4ca57496..5ef479452 100755
--- a/fs_mgr/tests/adb-remount-test.sh
+++ b/fs_mgr/tests/adb-remount-test.sh
@@ -251,8 +251,33 @@ adb_root &&
B="`adb_cat /vendor/hello`" ||
die "re-read vendor hello after reboot"
check_eq "${A}" "${B}" vendor after reboot
+
+adb reboot-fastboot &&
+ fastboot flash vendor &&
+ fastboot reboot ||
+ die "fastbootd flash vendor"
+adb_wait &&
+ adb_root &&
+ adb_wait &&
+ adb_sh df -k </dev/null | head -1 &&
+ adb_sh df -k </dev/null | grep "^overlay " &&
+ adb_sh df -k </dev/null | grep "^overlay .* /system\$" >/dev/null ||
+ die "overlay system takeover after flash vendor"
+adb_sh df -k </dev/null | grep "^overlay .* /vendor\$" >/dev/null &&
+ die "overlay minus vendor takeover after flash vendor"
+B="`adb_cat /system/hello`" ||
+ die "re-read system hello after flash vendor"
+check_eq "${A}" "${B}" system after flash vendor
+adb_root &&
+ adb_wait ||
+ die "adb root"
+B="`adb_cat /vendor/hello`" &&
+ die "re-read vendor hello after flash vendor"
+check_eq "cat: /vendor/hello: No such file or directory" "${B}" vendor after flash vendor
+
adb remount &&
- adb_sh rm /system/hello /vendor/hello </dev/null ||
+ ( adb_sh rm /vendor/hello </dev/null 2>/dev/null || true ) &&
+ adb_sh rm /system/hello </dev/null ||
die "cleanup hello"
B="`adb_cat /system/hello`" &&
die "re-read system hello after rm"