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

Commit fdff9a34 authored by Randall Huang's avatar Randall Huang
Browse files

[DO NOT MERGE] Retry to unmount /data



If we fail to umount /data, device won't boot up at all.

Bug: 208161227
Bug: 214203920
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@google.com>
Change-Id: I92d34a253039eb677d4df9fad8a0821fbc684f57
Merged-In: I92d34a253039eb677d4df9fad8a0821fbc684f57
parent ae5fe46e
Loading
Loading
Loading
Loading
+24 −22
Original line number Diff line number Diff line
@@ -170,6 +170,22 @@ static bool should_force_check(int fs_stat) {
            FS_STAT_SET_RESERVED_BLOCKS_FAILED | FS_STAT_ENABLE_ENCRYPTION_FAILED);
}

static bool umount_retry(const std::string& mount_point) {
    int retry_count = 5;
    bool umounted = false;

    while (retry_count-- > 0) {
        umounted = umount(mount_point.c_str()) == 0;
        if (umounted) {
            LINFO << __FUNCTION__ << "(): unmount(" << mount_point << ") succeeded";
            break;
        }
        PERROR << __FUNCTION__ << "(): umount(" << mount_point << ") failed";
        if (retry_count) sleep(1);
    }
    return umounted;
}

static void check_fs(const std::string& blk_device, const std::string& fs_type,
                     const std::string& target, int* fs_stat) {
    int status;
@@ -209,26 +225,13 @@ static void check_fs(const std::string& blk_device, const std::string& fs_type,
                        tmpmnt_opts.c_str());
            PINFO << __FUNCTION__ << "(): mount(" << blk_device << "," << target << "," << fs_type
                  << ")=" << ret;
            if (!ret) {
                bool umounted = false;
                int retry_count = 5;
                while (retry_count-- > 0) {
                    umounted = umount(target.c_str()) == 0;
                    if (umounted) {
                        LINFO << __FUNCTION__ << "(): unmount(" << target << ") succeeded";
                        break;
                    }
                    PERROR << __FUNCTION__ << "(): umount(" << target << ") failed";
                    if (retry_count) sleep(1);
                }
                if (!umounted) {
            if (ret) {
                *fs_stat |= FS_STAT_RO_MOUNT_FAILED;
            } else if (!umount_retry(target)) {
                // boot may fail but continue and leave it to later stage for now.
                PERROR << __FUNCTION__ << "(): umount(" << target << ") timed out";
                *fs_stat |= FS_STAT_RO_UNMOUNT_FAILED;
            }
            } else {
                *fs_stat |= FS_STAT_RO_MOUNT_FAILED;
            }
        }

        /*
@@ -1029,12 +1032,11 @@ static int handle_encryptable(const FstabEntry& entry) {
            return FS_MGR_MNTALL_DEV_NOT_ENCRYPTED;
        }
    } else if (should_use_metadata_encryption(entry)) {
        if (umount(entry.mount_point.c_str()) == 0) {
        if (umount_retry(entry.mount_point)) {
            return FS_MGR_MNTALL_DEV_NEEDS_METADATA_ENCRYPTION;
        } else {
        }
        PERROR << "Could not umount " << entry.mount_point << " - fail since can't encrypt";
        return FS_MGR_MNTALL_FAIL;
        }
    } else if (entry.fs_mgr_flags.file_encryption || entry.fs_mgr_flags.force_fde_or_fbe) {
        LINFO << entry.mount_point << " is file encrypted";
        return FS_MGR_MNTALL_DEV_FILE_ENCRYPTED;