Merge "fastboot: Mount /metadata before overlayfs teardown."
This commit is contained in:
commit
38f3706ab3
4 changed files with 43 additions and 37 deletions
|
|
@ -31,7 +31,6 @@
|
||||||
#include <cutils/android_reboot.h>
|
#include <cutils/android_reboot.h>
|
||||||
#include <ext4_utils/wipe.h>
|
#include <ext4_utils/wipe.h>
|
||||||
#include <fs_mgr.h>
|
#include <fs_mgr.h>
|
||||||
#include <fs_mgr/roots.h>
|
|
||||||
#include <libgsi/libgsi.h>
|
#include <libgsi/libgsi.h>
|
||||||
#include <liblp/builder.h>
|
#include <liblp/builder.h>
|
||||||
#include <liblp/liblp.h>
|
#include <liblp/liblp.h>
|
||||||
|
|
@ -550,42 +549,6 @@ bool UpdateSuperHandler(FastbootDevice* device, const std::vector<std::string>&
|
||||||
return UpdateSuper(device, args[1], wipe);
|
return UpdateSuper(device, args[1], wipe);
|
||||||
}
|
}
|
||||||
|
|
||||||
class AutoMountMetadata {
|
|
||||||
public:
|
|
||||||
AutoMountMetadata() {
|
|
||||||
android::fs_mgr::Fstab proc_mounts;
|
|
||||||
if (!ReadFstabFromFile("/proc/mounts", &proc_mounts)) {
|
|
||||||
LOG(ERROR) << "Could not read /proc/mounts";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto iter = std::find_if(proc_mounts.begin(), proc_mounts.end(),
|
|
||||||
[](const auto& entry) { return entry.mount_point == "/metadata"; });
|
|
||||||
if (iter != proc_mounts.end()) {
|
|
||||||
mounted_ = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ReadDefaultFstab(&fstab_)) {
|
|
||||||
LOG(ERROR) << "Could not read default fstab";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mounted_ = EnsurePathMounted(&fstab_, "/metadata");
|
|
||||||
should_unmount_ = true;
|
|
||||||
}
|
|
||||||
~AutoMountMetadata() {
|
|
||||||
if (mounted_ && should_unmount_) {
|
|
||||||
EnsurePathUnmounted(&fstab_, "/metadata");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
explicit operator bool() const { return mounted_; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
android::fs_mgr::Fstab fstab_;
|
|
||||||
bool mounted_ = false;
|
|
||||||
bool should_unmount_ = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
bool GsiHandler(FastbootDevice* device, const std::vector<std::string>& args) {
|
bool GsiHandler(FastbootDevice* device, const std::vector<std::string>& args) {
|
||||||
if (args.size() != 2) {
|
if (args.size() != 2) {
|
||||||
return device->WriteFail("Invalid arguments");
|
return device->WriteFail("Invalid arguments");
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <optional>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|
@ -56,6 +57,7 @@ void WipeOverlayfsForPartition(FastbootDevice* device, const std::string& partit
|
||||||
Fstab fstab;
|
Fstab fstab;
|
||||||
ReadDefaultFstab(&fstab);
|
ReadDefaultFstab(&fstab);
|
||||||
|
|
||||||
|
std::optional<AutoMountMetadata> mount_metadata;
|
||||||
for (const auto& entry : fstab) {
|
for (const auto& entry : fstab) {
|
||||||
auto partition = android::base::Basename(entry.mount_point);
|
auto partition = android::base::Basename(entry.mount_point);
|
||||||
if ("/" == entry.mount_point) {
|
if ("/" == entry.mount_point) {
|
||||||
|
|
@ -63,6 +65,7 @@ void WipeOverlayfsForPartition(FastbootDevice* device, const std::string& partit
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((partition + device->GetCurrentSlot()) == partition_name) {
|
if ((partition + device->GetCurrentSlot()) == partition_name) {
|
||||||
|
mount_metadata.emplace();
|
||||||
fs_mgr_overlayfs_teardown(entry.mount_point.c_str());
|
fs_mgr_overlayfs_teardown(entry.mount_point.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@
|
||||||
#include <android-base/properties.h>
|
#include <android-base/properties.h>
|
||||||
#include <android-base/strings.h>
|
#include <android-base/strings.h>
|
||||||
#include <fs_mgr.h>
|
#include <fs_mgr.h>
|
||||||
|
#include <fs_mgr/roots.h>
|
||||||
#include <fs_mgr_dm_linear.h>
|
#include <fs_mgr_dm_linear.h>
|
||||||
#include <liblp/builder.h>
|
#include <liblp/builder.h>
|
||||||
#include <liblp/liblp.h>
|
#include <liblp/liblp.h>
|
||||||
|
|
@ -240,3 +241,29 @@ std::string GetSuperSlotSuffix(FastbootDevice* device, const std::string& partit
|
||||||
}
|
}
|
||||||
return current_slot_suffix;
|
return current_slot_suffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AutoMountMetadata::AutoMountMetadata() {
|
||||||
|
android::fs_mgr::Fstab proc_mounts;
|
||||||
|
if (!ReadFstabFromFile("/proc/mounts", &proc_mounts)) {
|
||||||
|
LOG(ERROR) << "Could not read /proc/mounts";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GetEntryForMountPoint(&proc_mounts, "/metadata")) {
|
||||||
|
mounted_ = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ReadDefaultFstab(&fstab_)) {
|
||||||
|
LOG(ERROR) << "Could not read default fstab";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mounted_ = EnsurePathMounted(&fstab_, "/metadata");
|
||||||
|
should_unmount_ = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
AutoMountMetadata::~AutoMountMetadata() {
|
||||||
|
if (mounted_ && should_unmount_) {
|
||||||
|
EnsurePathUnmounted(&fstab_, "/metadata");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
#include <android-base/unique_fd.h>
|
#include <android-base/unique_fd.h>
|
||||||
#include <android/hardware/boot/1.0/IBootControl.h>
|
#include <android/hardware/boot/1.0/IBootControl.h>
|
||||||
|
#include <fstab/fstab.h>
|
||||||
#include <liblp/liblp.h>
|
#include <liblp/liblp.h>
|
||||||
|
|
||||||
// Logical partitions are only mapped to a block device as needed, and
|
// Logical partitions are only mapped to a block device as needed, and
|
||||||
|
|
@ -51,6 +52,18 @@ class PartitionHandle {
|
||||||
std::function<void()> closer_;
|
std::function<void()> closer_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class AutoMountMetadata {
|
||||||
|
public:
|
||||||
|
AutoMountMetadata();
|
||||||
|
~AutoMountMetadata();
|
||||||
|
explicit operator bool() const { return mounted_; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
android::fs_mgr::Fstab fstab_;
|
||||||
|
bool mounted_ = false;
|
||||||
|
bool should_unmount_ = false;
|
||||||
|
};
|
||||||
|
|
||||||
class FastbootDevice;
|
class FastbootDevice;
|
||||||
|
|
||||||
// On normal devices, the super partition is always named "super". On retrofit
|
// On normal devices, the super partition is always named "super". On retrofit
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue