Merge "fs_mgr_overlayfs: De-dup common methods" into main

This commit is contained in:
Yi-Yo Chiang 2023-11-27 11:16:51 +00:00 committed by Gerrit Code Review
commit 455fb82bf9
3 changed files with 30 additions and 68 deletions

View file

@ -347,33 +347,6 @@ static std::string GetDsuScratchDevice() {
return "";
}
// This returns the scratch device that was detected during early boot (first-
// stage init). If the device was created later, for example during setup for
// the adb remount command, it can return an empty string since it does not
// query ImageManager. (Note that ImageManager in first-stage init will always
// use device-mapper, since /data is not available to use loop devices.)
static std::string GetBootScratchDevice() {
// Note: fs_mgr_is_dsu_running() always returns false in recovery or fastbootd.
if (fs_mgr_is_dsu_running()) {
return GetDsuScratchDevice();
}
auto& dm = DeviceMapper::Instance();
// If there is a scratch partition allocated in /data or on super, we
// automatically prioritize that over super_other or system_other.
// Some devices, for example, have a write-protected eMMC and the
// super partition cannot be used even if it exists.
std::string device;
auto partition_name = android::base::Basename(kScratchMountPoint);
if (dm.GetState(partition_name) != DmDeviceState::INVALID &&
dm.GetDmDevicePathByName(partition_name, &device)) {
return device;
}
return "";
}
bool MakeScratchFilesystem(const std::string& scratch_device) {
// Force mkfs by design for overlay support of adb remount, simplify and
// thus do not rely on fsck to correct problems that could creep in.
@ -922,6 +895,33 @@ void CleanupOldScratchFiles() {
}
}
// This returns the scratch device that was detected during early boot (first-
// stage init). If the device was created later, for example during setup for
// the adb remount command, it can return an empty string since it does not
// query ImageManager. (Note that ImageManager in first-stage init will always
// use device-mapper, since /data is not available to use loop devices.)
std::string GetBootScratchDevice() {
// Note: fs_mgr_is_dsu_running() always returns false in recovery or fastbootd.
if (fs_mgr_is_dsu_running()) {
return GetDsuScratchDevice();
}
auto& dm = DeviceMapper::Instance();
// If there is a scratch partition allocated in /data or on super, we
// automatically prioritize that over super_other or system_other.
// Some devices, for example, have a write-protected eMMC and the
// super partition cannot be used even if it exists.
std::string device;
auto partition_name = android::base::Basename(kScratchMountPoint);
if (dm.GetState(partition_name) != DmDeviceState::INVALID &&
dm.GetDmDevicePathByName(partition_name, &device)) {
return device;
}
return "";
}
void TeardownAllOverlayForMountPoint(const std::string& mount_point) {
if (!OverlayfsTeardownAllowed()) {
return;

View file

@ -38,5 +38,7 @@ namespace fs_mgr {
void CleanupOldScratchFiles();
std::string GetBootScratchDevice();
} // namespace fs_mgr
} // namespace android

View file

@ -42,15 +42,14 @@
#include <fs_mgr/file_wait.h>
#include <fs_mgr_overlayfs.h>
#include <fstab/fstab.h>
#include <libdm/dm.h>
#include <libgsi/libgsi.h>
#include <storage_literals/storage_literals.h>
#include "fs_mgr_overlayfs_control.h"
#include "fs_mgr_overlayfs_mount.h"
#include "fs_mgr_priv.h"
using namespace std::literals;
using namespace android::dm;
using namespace android::fs_mgr;
using namespace android::storage_literals;
@ -593,45 +592,6 @@ bool MountScratch(const std::string& device_path, bool readonly) {
return true;
}
// Note: The scratch partition of DSU is managed by gsid, and should be initialized during
// first-stage-mount. Just check if the DM device for DSU scratch partition is created or not.
static std::string GetDsuScratchDevice() {
auto& dm = DeviceMapper::Instance();
std::string device;
if (dm.GetState(android::gsi::kDsuScratch) != DmDeviceState::INVALID &&
dm.GetDmDevicePathByName(android::gsi::kDsuScratch, &device)) {
return device;
}
return "";
}
// This returns the scratch device that was detected during early boot (first-
// stage init). If the device was created later, for example during setup for
// the adb remount command, it can return an empty string since it does not
// query ImageManager. (Note that ImageManager in first-stage init will always
// use device-mapper, since /data is not available to use loop devices.)
static std::string GetBootScratchDevice() {
// Note: fs_mgr_is_dsu_running() always returns false in recovery or fastbootd.
if (fs_mgr_is_dsu_running()) {
return GetDsuScratchDevice();
}
auto& dm = DeviceMapper::Instance();
// If there is a scratch partition allocated in /data or on super, we
// automatically prioritize that over super_other or system_other.
// Some devices, for example, have a write-protected eMMC and the
// super partition cannot be used even if it exists.
std::string device;
auto partition_name = android::base::Basename(kScratchMountPoint);
if (dm.GetState(partition_name) != DmDeviceState::INVALID &&
dm.GetDmDevicePathByName(partition_name, &device)) {
return device;
}
return "";
}
// NOTE: OverlayfsSetupAllowed() must be "stricter" than OverlayfsTeardownAllowed().
// Setup is allowed only if teardown is also allowed.
bool OverlayfsSetupAllowed(bool verbose) {