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

Commit 2c82c81f authored by Daniel Zheng's avatar Daniel Zheng
Browse files

libsnapshot: use compression_factor in ota

Parse manifest compression_factor and set CowOptions appropriately. This
allows v3 writer to use compression factor in OTA. Updating some
comments about supported compression algorithms

Test: th
Change-Id: I88f254087e536d9e5925064f85317f0acce280ee
parent 81f49ed2
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -103,7 +103,7 @@ message SnapshotStatus {
    // The old partition size (if none existed, this will be zero).
    uint64 old_partition_size = 10;

    // Compression algorithm (none, gz, or brotli).
    // Compression algorithm (none, gz, lz4, zstd, or brotli).
    string compression_algorithm = 11;

    // Estimated COW size from OTA manifest.
@@ -117,6 +117,9 @@ message SnapshotStatus {

    // Size of v3 operation buffer. Needs to be determined during writer initialization
    uint64 estimated_ops_buffer_size = 15;

    // Max bytes to be compressed at once (4k, 8k, 16k, 32k, 64k, 128k)
    uint64 compression_factor = 16;
}

// Next: 8
+3 −0
Original line number Diff line number Diff line
@@ -60,6 +60,9 @@ struct CowOptions {

    // Size of the cow operation buffer; used in v3 only.
    uint64_t op_count_max = 0;

    // Compression factor
    uint64_t compression_factor = 4096;
};

// Interface for writing to a snapuserd COW. All operations are ordered; merges
+1 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ struct PartitionCowCreator {
    // True if snapuserd COWs are enabled.
    bool using_snapuserd = false;
    std::string compression_algorithm;
    uint64_t compression_factor;

    // True if multi-threaded compression should be enabled
    bool enable_threading;
+7 −0
Original line number Diff line number Diff line
@@ -420,6 +420,7 @@ bool SnapshotManager::CreateSnapshot(LockedFile* lock, PartitionCowCreator* cow_
    status->set_metadata_sectors(0);
    status->set_using_snapuserd(cow_creator->using_snapuserd);
    status->set_compression_algorithm(cow_creator->compression_algorithm);
    status->set_compression_factor(cow_creator->compression_factor);
    if (cow_creator->enable_threading) {
        status->set_enable_threading(cow_creator->enable_threading);
    }
@@ -3233,8 +3234,10 @@ Return SnapshotManager::CreateUpdateSnapshots(const DeltaArchiveManifest& manife
    }

    std::string compression_algorithm;
    uint64_t compression_factor{};
    if (using_snapuserd) {
        compression_algorithm = dap_metadata.vabc_compression_param();
        compression_factor = dap_metadata.compression_factor();
        if (compression_algorithm.empty()) {
            // Older OTAs don't set an explicit compression type, so default to gz.
            compression_algorithm = "gz";
@@ -3251,7 +3254,9 @@ Return SnapshotManager::CreateUpdateSnapshots(const DeltaArchiveManifest& manife
            .extra_extents = {},
            .using_snapuserd = using_snapuserd,
            .compression_algorithm = compression_algorithm,
            .compression_factor = compression_factor,
    };

    if (dap_metadata.vabc_feature_set().has_threaded()) {
        cow_creator.enable_threading = dap_metadata.vabc_feature_set().threaded();
    }
@@ -3666,6 +3671,7 @@ std::unique_ptr<ICowWriter> SnapshotManager::OpenCompressedSnapshotWriter(
    cow_options.batch_write = status.batched_writes();
    cow_options.num_compress_threads = status.enable_threading() ? 2 : 1;
    cow_options.op_count_max = status.estimated_ops_buffer_size();
    cow_options.compression_factor = status.compression_factor();
    // Disable scratch space for vts tests
    if (device()->IsTestDevice()) {
        cow_options.scratch_space = false;
@@ -3793,6 +3799,7 @@ bool SnapshotManager::Dump(std::ostream& os) {
        ss << "    allocated sectors: " << status.sectors_allocated() << std::endl;
        ss << "    metadata sectors: " << status.metadata_sectors() << std::endl;
        ss << "    compression: " << status.compression_algorithm() << std::endl;
        ss << "    compression factor: " << status.compression_factor() << std::endl;
        ss << "    merge phase: " << DecideMergePhase(status) << std::endl;
    }
    os << ss.rdbuf();