Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 43d9f183 authored by David Anderson's avatar David Anderson
Browse files

remount: Refactor fs_mgr_overlayfs_teardown

This pulls code for mapping the scratch device into a separate function.
It also avoids implicitly failing by passing an empty device string.
Finally, it calls GetScratchDevice, to remove a caller of the deprecated
method fs_mgr_overlayfs_scratch_device().

Bug: 134949511
Test: adb remount and adb_remount_test.sh
Change-Id: If4a543d3fa26af3f8578ec8b236859c8e4d9bfd8
parent a3bf8478
Loading
Loading
Loading
Loading
+25 −13
Original line number Diff line number Diff line
@@ -1252,17 +1252,14 @@ bool fs_mgr_overlayfs_setup(const char* backing, const char* mount_point, bool*
    return ret;
}

// Returns false if teardown not permitted, errno set to last error.
// If something is altered, set *change.
bool fs_mgr_overlayfs_teardown(const char* mount_point, bool* change) {
    if (change) *change = false;
    auto ret = true;
    // If scratch exists, but is not mounted, lets gain access to clean
    // specific override entries.
    auto mount_scratch = false;
    if ((mount_point != nullptr) && !fs_mgr_overlayfs_already_mounted(kScratchMountPoint, false)) {
        auto scratch_device = fs_mgr_overlayfs_scratch_device();
        if (scratch_device.empty()) {
static bool GetAndMapScratchDeviceIfNeeded(std::string* device) {
    *device = GetScratchDevice();
    if (!device->empty()) {
        return true;
    }

    auto strategy = GetScratchStrategy();
    if (strategy == ScratchStrategy::kDynamicPartition) {
        auto metadata_slot = fs_mgr_overlayfs_slot_number();
        CreateLogicalPartitionParams params = {
                .block_device = fs_mgr_overlayfs_super_device(metadata_slot),
@@ -1271,11 +1268,26 @@ bool fs_mgr_overlayfs_teardown(const char* mount_point, bool* change) {
                .force_writable = true,
                .timeout_ms = 10s,
        };
            CreateLogicalPartition(params, &scratch_device);
        return CreateLogicalPartition(params, device);
    }
    return false;
}

// Returns false if teardown not permitted, errno set to last error.
// If something is altered, set *change.
bool fs_mgr_overlayfs_teardown(const char* mount_point, bool* change) {
    if (change) *change = false;
    auto ret = true;
    // If scratch exists, but is not mounted, lets gain access to clean
    // specific override entries.
    auto mount_scratch = false;
    if ((mount_point != nullptr) && !fs_mgr_overlayfs_already_mounted(kScratchMountPoint, false)) {
        std::string scratch_device;
        if (GetAndMapScratchDeviceIfNeeded(&scratch_device)) {
            mount_scratch = fs_mgr_overlayfs_mount_scratch(scratch_device,
                                                           fs_mgr_overlayfs_scratch_mount_type());
        }
    }
    for (const auto& overlay_mount_point : kOverlayMountPoints) {
        ret &= fs_mgr_overlayfs_teardown_one(
                overlay_mount_point, mount_point ? fs_mgr_mount_point(mount_point) : "", change);