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

Commit c5d321b3 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Reland Skip F2FS formatting for dev option enabled devices" into main...

Merge "Reland Skip F2FS formatting for dev option enabled devices" into main am: 06e83237 am: bacf172f

Original change: https://android-review.googlesource.com/c/platform/system/core/+/3257851



Change-Id: Ic7b983726c84fc08a9ba394472177d6d667dd9f3
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 868da9b5 bacf172f
Loading
Loading
Loading
Loading
+49 −18
Original line number Original line Diff line number Diff line
@@ -38,10 +38,8 @@


#include <array>
#include <array>
#include <chrono>
#include <chrono>
#include <functional>
#include <map>
#include <map>
#include <memory>
#include <memory>
#include <numeric>
#include <string>
#include <string>
#include <string_view>
#include <string_view>
#include <thread>
#include <thread>
@@ -66,6 +64,7 @@
#include <fs_mgr/file_wait.h>
#include <fs_mgr/file_wait.h>
#include <fs_mgr_overlayfs.h>
#include <fs_mgr_overlayfs.h>
#include <fscrypt/fscrypt.h>
#include <fscrypt/fscrypt.h>
#include <fstab/fstab.h>
#include <libdm/dm.h>
#include <libdm/dm.h>
#include <libdm/loop_control.h>
#include <libdm/loop_control.h>
#include <liblp/metadata_format.h>
#include <liblp/metadata_format.h>
@@ -138,8 +137,8 @@ enum FsStatFlags {
static void log_fs_stat(const std::string& blk_device, int fs_stat) {
static void log_fs_stat(const std::string& blk_device, int fs_stat) {
    std::string msg =
    std::string msg =
            android::base::StringPrintf("\nfs_stat,%s,0x%x\n", blk_device.c_str(), fs_stat);
            android::base::StringPrintf("\nfs_stat,%s,0x%x\n", blk_device.c_str(), fs_stat);
    android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(FSCK_LOG_FILE, O_WRONLY | O_CLOEXEC |
    android::base::unique_fd fd(TEMP_FAILURE_RETRY(
                                                        O_APPEND | O_CREAT, 0664)));
            open(FSCK_LOG_FILE, O_WRONLY | O_CLOEXEC | O_APPEND | O_CREAT, 0664)));
    if (fd == -1 || !android::base::WriteStringToFd(msg, fd)) {
    if (fd == -1 || !android::base::WriteStringToFd(msg, fd)) {
        LWARNING << __FUNCTION__ << "() cannot log " << msg;
        LWARNING << __FUNCTION__ << "() cannot log " << msg;
    }
    }
@@ -1430,6 +1429,37 @@ bool WasMetadataEncryptionInterrupted(const FstabEntry& entry) {
    return access(fs_mgr_metadata_encryption_in_progress_file_name(entry).c_str(), R_OK) == 0;
    return access(fs_mgr_metadata_encryption_in_progress_file_name(entry).c_str(), R_OK) == 0;
}
}


static FstabEntry* LocateFormattableEntry(FstabEntry* const begin, FstabEntry* const end) {
    if (begin == end) {
        return nullptr;
    }
    const bool dev_option_enabled =
            android::base::GetBoolProperty("ro.product.build.16k_page.enabled", false);
    FstabEntry* f2fs_entry = nullptr;
    for (auto iter = begin; iter != end && iter->blk_device == begin->blk_device; iter++) {
        if (iter->fs_mgr_flags.formattable) {
            if (getpagesize() != 4096 && is_f2fs(iter->fs_type) && dev_option_enabled) {
                f2fs_entry = iter;
                continue;
            }
            if (f2fs_entry) {
                LOG(INFO) << "Skipping F2FS format for block device " << iter->blk_device << " @ "
                          << iter->mount_point
                          << " in non-4K mode for dev option enabled devices, "
                             "as these devices need to toggle between 4K/16K mode, and F2FS does "
                             "not support page_size != block_size configuration.";
            }
            return iter;
        }
    }
    if (f2fs_entry) {
        LOG(INFO) << "Using F2FS for " << f2fs_entry->blk_device << " @ " << f2fs_entry->mount_point
                  << " even though we are in non-4K mode. Device might require a data wipe after "
                     "going back to 4K mode, as F2FS does not support page_size != block_size";
    }
    return f2fs_entry;
}

// When multiple fstab records share the same mount_point, it will try to mount each
// When multiple fstab records share the same mount_point, it will try to mount each
// one in turn, and ignore any duplicates after a first successful mount.
// one in turn, and ignore any duplicates after a first successful mount.
// Returns -1 on error, and  FS_MGR_MNTALL_* otherwise.
// Returns -1 on error, and  FS_MGR_MNTALL_* otherwise.
@@ -1540,8 +1570,8 @@ int fs_mgr_mount_all(Fstab* fstab, int mount_mode) {
            }
            }
        }
        }


        int last_idx_inspected;
        int last_idx_inspected = -1;
        int top_idx = i;
        const int top_idx = i;
        int attempted_idx = -1;
        int attempted_idx = -1;


        bool encryption_interrupted = WasMetadataEncryptionInterrupted(current_entry);
        bool encryption_interrupted = WasMetadataEncryptionInterrupted(current_entry);
@@ -1591,7 +1621,8 @@ int fs_mgr_mount_all(Fstab* fstab, int mount_mode) {
            // Success!  Go get the next one.
            // Success!  Go get the next one.
            continue;
            continue;
        }
        }

        auto formattable_entry =
                LocateFormattableEntry(fstab->data() + top_idx, fstab->data() + fstab->size());
        // Mounting failed, understand why and retry.
        // Mounting failed, understand why and retry.
        wiped = partition_wiped(current_entry.blk_device.c_str());
        wiped = partition_wiped(current_entry.blk_device.c_str());
        if (mount_errno != EBUSY && mount_errno != EACCES &&
        if (mount_errno != EBUSY && mount_errno != EACCES &&
@@ -1619,12 +1650,12 @@ int fs_mgr_mount_all(Fstab* fstab, int mount_mode) {
                encryptable = FS_MGR_MNTALL_DEV_IS_METADATA_ENCRYPTED;
                encryptable = FS_MGR_MNTALL_DEV_IS_METADATA_ENCRYPTED;
                set_type_property(encryptable);
                set_type_property(encryptable);


                if (!call_vdc({"cryptfs", "encryptFstab", current_entry.blk_device,
                if (!call_vdc({"cryptfs", "encryptFstab", formattable_entry->blk_device,
                               current_entry.mount_point, "true" /* shouldFormat */,
                               formattable_entry->mount_point, "true" /* shouldFormat */,
                               current_entry.fs_type,
                               formattable_entry->fs_type,
                               current_entry.fs_mgr_flags.is_zoned ? "true" : "false",
                               formattable_entry->fs_mgr_flags.is_zoned ? "true" : "false",
                               std::to_string(current_entry.length),
                               std::to_string(formattable_entry->length),
                               android::base::Join(current_entry.user_devices, ' ')},
                               android::base::Join(formattable_entry->user_devices, ' ')},
                              nullptr)) {
                              nullptr)) {
                    LERROR << "Encryption failed";
                    LERROR << "Encryption failed";
                } else {
                } else {
@@ -1633,7 +1664,7 @@ int fs_mgr_mount_all(Fstab* fstab, int mount_mode) {
                }
                }
            }
            }


            if (fs_mgr_do_format(current_entry) == 0) {
            if (fs_mgr_do_format(*formattable_entry) == 0) {
                // Let's replay the mount actions.
                // Let's replay the mount actions.
                i = top_idx - 1;
                i = top_idx - 1;
                continue;
                continue;