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

Commit 21feb62e authored by Jonglin Lee's avatar Jonglin Lee
Browse files

Revert "libsnapshot: Fix checks for compression to work with new..."

Revert submission 1926977

Reason for revert: suspect cause of b/211025818
Reverted Changes:
I215635645:libsnapshot: Fix libsnapshot_fuzzer_test.
I2afd64446:libsnapshot: Fix checks for compression to work wi...

Bug: 211025818
Change-Id: I16741798f6e7409ee98a2cb58d070938811e1697
parent ca005558
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -143,7 +143,7 @@ void WriteExtent(DmSnapCowSizeCalculator* sc, const chromeos_update_engine::Exte
}
}


std::optional<uint64_t> PartitionCowCreator::GetCowSize() {
std::optional<uint64_t> PartitionCowCreator::GetCowSize() {
    if (compression_enabled || userspace_snapshots_enabled) {
    if (compression_enabled) {
        if (update == nullptr || !update->has_estimate_cow_size()) {
        if (update == nullptr || !update->has_estimate_cow_size()) {
            LOG(ERROR) << "Update manifest does not include a COW size";
            LOG(ERROR) << "Update manifest does not include a COW size";
            return std::nullopt;
            return std::nullopt;
+0 −1
Original line number Original line Diff line number Diff line
@@ -58,7 +58,6 @@ struct PartitionCowCreator {
    std::vector<ChromeOSExtent> extra_extents = {};
    std::vector<ChromeOSExtent> extra_extents = {};
    // True if compression is enabled.
    // True if compression is enabled.
    bool compression_enabled = false;
    bool compression_enabled = false;
    bool userspace_snapshots_enabled = false;
    std::string compression_algorithm;
    std::string compression_algorithm;


    struct Return {
    struct Return {
+65 −83
Original line number Original line Diff line number Diff line
@@ -1329,7 +1329,7 @@ MergeFailureCode SnapshotManager::CheckMergeConsistency(LockedFile* lock, const
                                                        const SnapshotStatus& status) {
                                                        const SnapshotStatus& status) {
    CHECK(lock);
    CHECK(lock);


    if (!status.compression_enabled() && !UpdateUsesUserSnapshots(lock)) {
    if (!status.compression_enabled()) {
        // Do not try to verify old-style COWs yet.
        // Do not try to verify old-style COWs yet.
        return MergeFailureCode::Ok;
        return MergeFailureCode::Ok;
    }
    }
@@ -2345,15 +2345,13 @@ bool SnapshotManager::MapPartitionWithSnapshot(LockedFile* lock,
    remaining_time = GetRemainingTime(params.timeout_ms, begin);
    remaining_time = GetRemainingTime(params.timeout_ms, begin);
    if (remaining_time.count() < 0) return false;
    if (remaining_time.count() < 0) return false;


    if (context == SnapshotContext::Update) {
    if (context == SnapshotContext::Update && live_snapshot_status->compression_enabled()) {
        if (UpdateUsesUserSnapshots(lock) || live_snapshot_status->compression_enabled()) {
        // Stop here, we can't run dm-user yet, the COW isn't built.
        // Stop here, we can't run dm-user yet, the COW isn't built.
        created_devices.Release();
        created_devices.Release();
        return true;
        return true;
    }
    }
    }


    if (UpdateUsesUserSnapshots(lock) || live_snapshot_status->compression_enabled()) {
    if (live_snapshot_status->compression_enabled()) {
        // Get the source device (eg the view of the partition from before it was resized).
        // Get the source device (eg the view of the partition from before it was resized).
        std::string source_device_path;
        std::string source_device_path;
        if (live_snapshot_status->old_partition_size() > 0) {
        if (live_snapshot_status->old_partition_size() > 0) {
@@ -3134,11 +3132,57 @@ Return SnapshotManager::CreateUpdateSnapshots(const DeltaArchiveManifest& manife
            .compression_algorithm = compression_algorithm,
            .compression_algorithm = compression_algorithm,
    };
    };


    auto ret = CreateUpdateSnapshotsInternal(lock.get(), manifest, &cow_creator, &created_devices,
                                             &all_snapshot_status);
    if (!ret.is_ok()) return ret;

    auto exported_target_metadata = target_metadata->Export();
    if (exported_target_metadata == nullptr) {
        LOG(ERROR) << "Cannot export target metadata";
        return Return::Error();
    }

    ret = InitializeUpdateSnapshots(lock.get(), target_metadata.get(),
                                    exported_target_metadata.get(), target_suffix,
                                    all_snapshot_status);
    if (!ret.is_ok()) return ret;

    if (!UpdatePartitionTable(opener, device_->GetSuperDevice(target_slot),
                              *exported_target_metadata, target_slot)) {
        LOG(ERROR) << "Cannot write target metadata";
        return Return::Error();
    }

    // If compression is enabled, we need to retain a copy of the old metadata
    // so we can access original blocks in case they are moved around. We do
    // not want to rely on the old super metadata slot because we don't
    // guarantee its validity after the slot switch is successful.
    if (cow_creator.compression_enabled) {
        auto metadata = current_metadata->Export();
        if (!metadata) {
            LOG(ERROR) << "Could not export current metadata";
            return Return::Error();
        }

        auto path = GetOldPartitionMetadataPath();
        if (!android::fs_mgr::WriteToImageFile(path, *metadata.get())) {
            LOG(ERROR) << "Cannot write old metadata to " << path;
            return Return::Error();
        }
    }

    SnapshotUpdateStatus status = ReadSnapshotUpdateStatus(lock.get());
    status.set_state(update_state);
    status.set_compression_enabled(cow_creator.compression_enabled);
    if (cow_creator.compression_enabled) {
        if (!device()->IsTestDevice()) {
        if (!device()->IsTestDevice()) {
        cow_creator.userspace_snapshots_enabled = IsUserspaceSnapshotsEnabled();
            // Userspace snapshots is enabled only if compression is enabled
        if (cow_creator.userspace_snapshots_enabled) {
            status.set_userspace_snapshots(IsUserspaceSnapshotsEnabled());
            if (IsUserspaceSnapshotsEnabled()) {
                is_snapshot_userspace_ = true;
                LOG(INFO) << "User-space snapshots enabled";
                LOG(INFO) << "User-space snapshots enabled";
            } else {
            } else {
                is_snapshot_userspace_ = false;
                LOG(INFO) << "User-space snapshots disabled";
                LOG(INFO) << "User-space snapshots disabled";
            }
            }


@@ -3157,64 +3201,16 @@ Return SnapshotManager::CreateUpdateSnapshots(const DeltaArchiveManifest& manife
                snapuserd_client_ = nullptr;
                snapuserd_client_ = nullptr;
            }
            }
        } else {
        } else {
        cow_creator.userspace_snapshots_enabled = !IsDmSnapshotTestingEnabled();
            status.set_userspace_snapshots(!IsDmSnapshotTestingEnabled());
        if (cow_creator.userspace_snapshots_enabled) {
            if (IsDmSnapshotTestingEnabled()) {
                is_snapshot_userspace_ = false;
                LOG(INFO) << "User-space snapshots disabled for testing";
                LOG(INFO) << "User-space snapshots disabled for testing";
            } else {
            } else {
                is_snapshot_userspace_ = true;
                LOG(INFO) << "User-space snapshots enabled for testing";
                LOG(INFO) << "User-space snapshots enabled for testing";
            }
            }
        }
        }

    is_snapshot_userspace_ = cow_creator.userspace_snapshots_enabled;

    // If compression is enabled, we need to retain a copy of the old metadata
    // so we can access original blocks in case they are moved around. We do
    // not want to rely on the old super metadata slot because we don't
    // guarantee its validity after the slot switch is successful.
    //
    // Note that we do this for userspace merges even if compression is
    // disabled, since the code path expects it even if the source device will
    // be unused.
    if (cow_creator.compression_enabled || cow_creator.userspace_snapshots_enabled) {
        auto metadata = current_metadata->Export();
        if (!metadata) {
            LOG(ERROR) << "Could not export current metadata";
            return Return::Error();
        }

        auto path = GetOldPartitionMetadataPath();
        if (!android::fs_mgr::WriteToImageFile(path, *metadata.get())) {
            LOG(ERROR) << "Cannot write old metadata to " << path;
            return Return::Error();
        }
    }

    auto ret = CreateUpdateSnapshotsInternal(lock.get(), manifest, &cow_creator, &created_devices,
                                             &all_snapshot_status);
    if (!ret.is_ok()) return ret;

    auto exported_target_metadata = target_metadata->Export();
    if (exported_target_metadata == nullptr) {
        LOG(ERROR) << "Cannot export target metadata";
        return Return::Error();
    }

    ret = InitializeUpdateSnapshots(lock.get(), target_metadata.get(),
                                    exported_target_metadata.get(), target_suffix,
                                    all_snapshot_status);
    if (!ret.is_ok()) return ret;

    if (!UpdatePartitionTable(opener, device_->GetSuperDevice(target_slot),
                              *exported_target_metadata, target_slot)) {
        LOG(ERROR) << "Cannot write target metadata";
        return Return::Error();
    }
    }

    SnapshotUpdateStatus status = ReadSnapshotUpdateStatus(lock.get());
    status.set_state(update_state);
    status.set_compression_enabled(cow_creator.compression_enabled);
    status.set_userspace_snapshots(cow_creator.userspace_snapshots_enabled);

    if (!WriteSnapshotUpdateStatus(lock.get(), status)) {
    if (!WriteSnapshotUpdateStatus(lock.get(), status)) {
        LOG(ERROR) << "Unable to write new update state";
        LOG(ERROR) << "Unable to write new update state";
        return Return::Error();
        return Return::Error();
@@ -3378,8 +3374,6 @@ Return SnapshotManager::InitializeUpdateSnapshots(
        const std::map<std::string, SnapshotStatus>& all_snapshot_status) {
        const std::map<std::string, SnapshotStatus>& all_snapshot_status) {
    CHECK(lock);
    CHECK(lock);


    bool userspace_merges = UpdateUsesUserSnapshots(lock);

    CreateLogicalPartitionParams cow_params{
    CreateLogicalPartitionParams cow_params{
            .block_device = LP_METADATA_DEFAULT_PARTITION_NAME,
            .block_device = LP_METADATA_DEFAULT_PARTITION_NAME,
            .metadata = exported_target_metadata,
            .metadata = exported_target_metadata,
@@ -3409,7 +3403,7 @@ Return SnapshotManager::InitializeUpdateSnapshots(
            return Return::Error();
            return Return::Error();
        }
        }


        if (userspace_merges || it->second.compression_enabled()) {
        if (it->second.compression_enabled()) {
            unique_fd fd(open(cow_path.c_str(), O_RDWR | O_CLOEXEC));
            unique_fd fd(open(cow_path.c_str(), O_RDWR | O_CLOEXEC));
            if (fd < 0) {
            if (fd < 0) {
                PLOG(ERROR) << "open " << cow_path << " failed for snapshot "
                PLOG(ERROR) << "open " << cow_path << " failed for snapshot "
@@ -3455,8 +3449,8 @@ bool SnapshotManager::MapUpdateSnapshot(const CreateLogicalPartitionParams& para
    if (!ReadSnapshotStatus(lock.get(), params.GetPartitionName(), &status)) {
    if (!ReadSnapshotStatus(lock.get(), params.GetPartitionName(), &status)) {
        return false;
        return false;
    }
    }
    if (status.compression_enabled() || UpdateUsesUserSnapshots(lock.get())) {
    if (status.compression_enabled()) {
        LOG(ERROR) << "Cannot use MapUpdateSnapshot with user snapshots";
        LOG(ERROR) << "Cannot use MapUpdateSnapshot with compressed snapshots";
        return false;
        return false;
    }
    }


@@ -3513,7 +3507,7 @@ std::unique_ptr<ISnapshotWriter> SnapshotManager::OpenSnapshotWriter(
        return nullptr;
        return nullptr;
    }
    }


    if (status.compression_enabled() || UpdateUsesUserSnapshots(lock.get())) {
    if (status.compression_enabled()) {
        return OpenCompressedSnapshotWriter(lock.get(), source_device, params.GetPartitionName(),
        return OpenCompressedSnapshotWriter(lock.get(), source_device, params.GetPartitionName(),
                                            status, paths);
                                            status, paths);
    }
    }
@@ -3653,7 +3647,6 @@ bool SnapshotManager::Dump(std::ostream& os) {
       << (access(GetForwardMergeIndicatorPath().c_str(), F_OK) == 0 ? "exists" : strerror(errno))
       << (access(GetForwardMergeIndicatorPath().c_str(), F_OK) == 0 ? "exists" : strerror(errno))
       << std::endl;
       << std::endl;
    ss << "Source build fingerprint: " << update_status.source_build_fingerprint() << std::endl;
    ss << "Source build fingerprint: " << update_status.source_build_fingerprint() << std::endl;
    ss << "Using userspace snapshots: " << UpdateUsesUserSnapshots(file.get()) << std::endl;


    bool ok = true;
    bool ok = true;
    std::vector<std::string> snapshots;
    std::vector<std::string> snapshots;
@@ -3854,10 +3847,6 @@ UpdateState SnapshotManager::ProcessUpdateStateOnDataWipe(bool allow_forward_mer
bool SnapshotManager::EnsureNoOverflowSnapshot(LockedFile* lock) {
bool SnapshotManager::EnsureNoOverflowSnapshot(LockedFile* lock) {
    CHECK(lock);
    CHECK(lock);


    if (UpdateUsesUserSnapshots(lock)) {
        return true;
    }

    std::vector<std::string> snapshots;
    std::vector<std::string> snapshots;
    if (!ListSnapshots(lock, &snapshots)) {
    if (!ListSnapshots(lock, &snapshots)) {
        LOG(ERROR) << "Could not list snapshots.";
        LOG(ERROR) << "Could not list snapshots.";
@@ -3870,7 +3859,6 @@ bool SnapshotManager::EnsureNoOverflowSnapshot(LockedFile* lock) {
            return false;
            return false;
        }
        }
        if (status.compression_enabled()) {
        if (status.compression_enabled()) {
            // Compressed snapshots are never written through dm-snapshot.
            continue;
            continue;
        }
        }


@@ -4034,10 +4022,7 @@ bool SnapshotManager::IsSnapuserdRequired() {
    if (!lock) return false;
    if (!lock) return false;


    auto status = ReadSnapshotUpdateStatus(lock.get());
    auto status = ReadSnapshotUpdateStatus(lock.get());
    if (status.state() != UpdateState::None && status.compression_enabled()) {
    return status.state() != UpdateState::None && status.compression_enabled();
        return true;
    }
    return UpdateUsesUserSnapshots(lock.get());
}
}


bool SnapshotManager::DetachSnapuserdForSelinux(std::vector<std::string>* snapuserd_argv) {
bool SnapshotManager::DetachSnapuserdForSelinux(std::vector<std::string>* snapuserd_argv) {
@@ -4063,9 +4048,6 @@ const LpMetadata* SnapshotManager::ReadOldPartitionMetadata(LockedFile* lock) {
}
}


MergePhase SnapshotManager::DecideMergePhase(const SnapshotStatus& status) {
MergePhase SnapshotManager::DecideMergePhase(const SnapshotStatus& status) {
    // Note: disabling compression disables move operations, so we don't need
    // separate phases when compression is disabled (irrespective of userspace
    // merges).
    if (status.compression_enabled() && status.device_size() < status.old_partition_size()) {
    if (status.compression_enabled() && status.device_size() < status.old_partition_size()) {
        return MergePhase::FIRST_PHASE;
        return MergePhase::FIRST_PHASE;
    }
    }
+5 −5
Original line number Original line Diff line number Diff line
@@ -357,7 +357,7 @@ class SnapshotTest : public ::testing::Test {
        DeltaArchiveManifest manifest;
        DeltaArchiveManifest manifest;


        auto dynamic_partition_metadata = manifest.mutable_dynamic_partition_metadata();
        auto dynamic_partition_metadata = manifest.mutable_dynamic_partition_metadata();
        dynamic_partition_metadata->set_vabc_enabled(ShouldUseCompression());
        dynamic_partition_metadata->set_vabc_enabled(IsCompressionEnabled());
        dynamic_partition_metadata->set_cow_version(android::snapshot::kCowVersionMajor);
        dynamic_partition_metadata->set_cow_version(android::snapshot::kCowVersionMajor);


        auto group = dynamic_partition_metadata->add_groups();
        auto group = dynamic_partition_metadata->add_groups();
@@ -396,7 +396,7 @@ class SnapshotTest : public ::testing::Test {
            if (!res) {
            if (!res) {
                return res;
                return res;
            }
            }
        } else if (!ShouldUseUserspaceSnapshots()) {
        } else if (!IsCompressionEnabled()) {
            std::string ignore;
            std::string ignore;
            if (!MapUpdateSnapshot("test_partition_b", &ignore)) {
            if (!MapUpdateSnapshot("test_partition_b", &ignore)) {
                return AssertionFailure() << "Failed to map test_partition_b";
                return AssertionFailure() << "Failed to map test_partition_b";
@@ -1030,7 +1030,7 @@ class SnapshotUpdateTest : public SnapshotTest {
    }
    }


    AssertionResult MapOneUpdateSnapshot(const std::string& name) {
    AssertionResult MapOneUpdateSnapshot(const std::string& name) {
        if (ShouldUseUserspaceSnapshots()) {
        if (ShouldUseCompression()) {
            std::unique_ptr<ISnapshotWriter> writer;
            std::unique_ptr<ISnapshotWriter> writer;
            return MapUpdateSnapshot(name, &writer);
            return MapUpdateSnapshot(name, &writer);
        } else {
        } else {
@@ -1040,7 +1040,7 @@ class SnapshotUpdateTest : public SnapshotTest {
    }
    }


    AssertionResult WriteSnapshotAndHash(const std::string& name) {
    AssertionResult WriteSnapshotAndHash(const std::string& name) {
        if (ShouldUseUserspaceSnapshots()) {
        if (ShouldUseCompression()) {
            std::unique_ptr<ISnapshotWriter> writer;
            std::unique_ptr<ISnapshotWriter> writer;
            auto res = MapUpdateSnapshot(name, &writer);
            auto res = MapUpdateSnapshot(name, &writer);
            if (!res) {
            if (!res) {
@@ -2072,7 +2072,7 @@ TEST_F(SnapshotUpdateTest, Hashtree) {


// Test for overflow bit after update
// Test for overflow bit after update
TEST_F(SnapshotUpdateTest, Overflow) {
TEST_F(SnapshotUpdateTest, Overflow) {
    if (ShouldUseUserspaceSnapshots()) {
    if (ShouldUseCompression()) {
        GTEST_SKIP() << "No overflow bit set for userspace COWs";
        GTEST_SKIP() << "No overflow bit set for userspace COWs";
    }
    }