Merge "fs_mgr: Add OverlayMountPoints() to get the list of overlayfs backing storage" am: ec1b09fca9 am: 9a2bf07d51
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1585166 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: I0b369a25d64eaf7005c2b3d7478530bc53fdb814
This commit is contained in:
commit
cd369c3cec
1 changed files with 33 additions and 24 deletions
|
|
@ -125,10 +125,38 @@ void TeardownAllOverlayForMountPoint(const std::string&) {}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
bool fs_mgr_in_recovery() {
|
||||||
|
// Check the existence of recovery binary instead of using the compile time
|
||||||
|
// macro, because first-stage-init is compiled with __ANDROID_RECOVERY__
|
||||||
|
// defined, albeit not in recovery. More details: system/core/init/README.md
|
||||||
|
return fs_mgr_access("/system/bin/recovery");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool fs_mgr_is_dsu_running() {
|
||||||
|
// Since android::gsi::CanBootIntoGsi() or android::gsi::MarkSystemAsGsi() is
|
||||||
|
// never called in recovery, the return value of android::gsi::IsGsiRunning()
|
||||||
|
// is not well-defined. In this case, just return false as being in recovery
|
||||||
|
// implies not running a DSU system.
|
||||||
|
if (fs_mgr_in_recovery()) return false;
|
||||||
|
auto saved_errno = errno;
|
||||||
|
auto ret = android::gsi::IsGsiRunning();
|
||||||
|
errno = saved_errno;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
// list of acceptable overlayfs backing storage
|
// list of acceptable overlayfs backing storage
|
||||||
const auto kScratchMountPoint = "/mnt/scratch"s;
|
const auto kScratchMountPoint = "/mnt/scratch"s;
|
||||||
const auto kCacheMountPoint = "/cache"s;
|
const auto kCacheMountPoint = "/cache"s;
|
||||||
const std::vector<const std::string> kOverlayMountPoints = {kScratchMountPoint, kCacheMountPoint};
|
|
||||||
|
std::vector<const std::string> OverlayMountPoints() {
|
||||||
|
// Never fallback to legacy cache mount point if within a DSU system,
|
||||||
|
// because running a DSU system implies the device supports dynamic
|
||||||
|
// partitions, which means legacy cache mustn't be used.
|
||||||
|
if (fs_mgr_is_dsu_running()) {
|
||||||
|
return {kScratchMountPoint};
|
||||||
|
}
|
||||||
|
return {kScratchMountPoint, kCacheMountPoint};
|
||||||
|
}
|
||||||
|
|
||||||
// Return true if everything is mounted, but before adb is started. Right
|
// Return true if everything is mounted, but before adb is started. Right
|
||||||
// after 'trigger load_persist_props_action' is done.
|
// after 'trigger load_persist_props_action' is done.
|
||||||
|
|
@ -169,25 +197,6 @@ bool fs_mgr_filesystem_has_space(const std::string& mount_point) {
|
||||||
(vst.f_bfree * vst.f_bsize) >= kSizeThreshold;
|
(vst.f_bfree * vst.f_bsize) >= kSizeThreshold;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fs_mgr_in_recovery() {
|
|
||||||
// Check the existence of recovery binary instead of using the compile time
|
|
||||||
// macro, because first-stage-init is compiled with __ANDROID_RECOVERY__
|
|
||||||
// defined, albeit not in recovery. More details: system/core/init/README.md
|
|
||||||
return fs_mgr_access("/system/bin/recovery");
|
|
||||||
}
|
|
||||||
|
|
||||||
bool fs_mgr_is_dsu_running() {
|
|
||||||
// Since android::gsi::CanBootIntoGsi() or android::gsi::MarkSystemAsGsi() is
|
|
||||||
// never called in recovery, the return value of android::gsi::IsGsiRunning()
|
|
||||||
// is not well-defined. In this case, just return false as being in recovery
|
|
||||||
// implies not running a DSU system.
|
|
||||||
if (fs_mgr_in_recovery()) return false;
|
|
||||||
auto saved_errno = errno;
|
|
||||||
auto ret = android::gsi::IsGsiRunning();
|
|
||||||
errno = saved_errno;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto kPhysicalDevice = "/dev/block/by-name/"s;
|
const auto kPhysicalDevice = "/dev/block/by-name/"s;
|
||||||
constexpr char kScratchImageMetadata[] = "/metadata/gsi/remount/lp_metadata";
|
constexpr char kScratchImageMetadata[] = "/metadata/gsi/remount/lp_metadata";
|
||||||
|
|
||||||
|
|
@ -300,7 +309,7 @@ const auto kOverlayTopDir = "/overlay"s;
|
||||||
std::string fs_mgr_get_overlayfs_candidate(const std::string& mount_point) {
|
std::string fs_mgr_get_overlayfs_candidate(const std::string& mount_point) {
|
||||||
if (!fs_mgr_is_dir(mount_point)) return "";
|
if (!fs_mgr_is_dir(mount_point)) return "";
|
||||||
const auto base = android::base::Basename(mount_point) + "/";
|
const auto base = android::base::Basename(mount_point) + "/";
|
||||||
for (const auto& overlay_mount_point : kOverlayMountPoints) {
|
for (const auto& overlay_mount_point : OverlayMountPoints()) {
|
||||||
auto dir = overlay_mount_point + kOverlayTopDir + "/" + base;
|
auto dir = overlay_mount_point + kOverlayTopDir + "/" + base;
|
||||||
auto upper = dir + kUpperName;
|
auto upper = dir + kUpperName;
|
||||||
if (!fs_mgr_is_dir(upper)) continue;
|
if (!fs_mgr_is_dir(upper)) continue;
|
||||||
|
|
@ -1344,7 +1353,7 @@ bool fs_mgr_overlayfs_setup(const char* backing, const char* mount_point, bool*
|
||||||
if (candidates.empty()) return ret;
|
if (candidates.empty()) return ret;
|
||||||
|
|
||||||
std::string dir;
|
std::string dir;
|
||||||
for (const auto& overlay_mount_point : kOverlayMountPoints) {
|
for (const auto& overlay_mount_point : OverlayMountPoints()) {
|
||||||
if (backing && backing[0] && (overlay_mount_point != backing)) continue;
|
if (backing && backing[0] && (overlay_mount_point != backing)) continue;
|
||||||
if (overlay_mount_point == kScratchMountPoint) {
|
if (overlay_mount_point == kScratchMountPoint) {
|
||||||
if (!fs_mgr_overlayfs_setup_scratch(fstab, change)) continue;
|
if (!fs_mgr_overlayfs_setup_scratch(fstab, change)) continue;
|
||||||
|
|
@ -1465,7 +1474,7 @@ bool fs_mgr_overlayfs_teardown(const char* mount_point, bool* change) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool should_destroy_scratch = false;
|
bool should_destroy_scratch = false;
|
||||||
for (const auto& overlay_mount_point : kOverlayMountPoints) {
|
for (const auto& overlay_mount_point : OverlayMountPoints()) {
|
||||||
ret &= fs_mgr_overlayfs_teardown_one(
|
ret &= fs_mgr_overlayfs_teardown_one(
|
||||||
overlay_mount_point, mount_point ? fs_mgr_mount_point(mount_point) : "", change,
|
overlay_mount_point, mount_point ? fs_mgr_mount_point(mount_point) : "", change,
|
||||||
overlay_mount_point == kScratchMountPoint ? &should_destroy_scratch : nullptr);
|
overlay_mount_point == kScratchMountPoint ? &should_destroy_scratch : nullptr);
|
||||||
|
|
@ -1569,7 +1578,7 @@ void TeardownAllOverlayForMountPoint(const std::string& mount_point) {
|
||||||
constexpr bool* ignore_change = nullptr;
|
constexpr bool* ignore_change = nullptr;
|
||||||
|
|
||||||
// Teardown legacy overlay mount points that's not backed by a scratch device.
|
// Teardown legacy overlay mount points that's not backed by a scratch device.
|
||||||
for (const auto& overlay_mount_point : kOverlayMountPoints) {
|
for (const auto& overlay_mount_point : OverlayMountPoints()) {
|
||||||
if (overlay_mount_point == kScratchMountPoint) {
|
if (overlay_mount_point == kScratchMountPoint) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue