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

Commit 1ce6a7e4 authored by Akilesh Kailash's avatar Akilesh Kailash
Browse files

libsnapshot: Print merge completion ops



Once the daemon is terminated, print merge completion
ops and the total ops present in the COW file. This
will help to know if the merge operation was interrupted
and how many pending operations were done during
each reboot until merge is completed

Bug: 167409187
Test: Incremental and full OTA
Signed-off-by: default avatarAkilesh Kailash <akailash@google.com>
Change-Id: Ie33c840e80aaeca86f51adc8085cb4e306dca110
parent 3e455e3a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -237,6 +237,7 @@ void CowReader::InitializeMerge() {
                               [](CowOperation& op) { return IsMetadataOp(op); }),
                ops_.get()->end());

    set_total_data_ops(ops_->size());
    // We will re-arrange the vector in such a way that
    // kernel can batch merge. Ex:
    //
+5 −0
Original line number Diff line number Diff line
@@ -142,6 +142,10 @@ class CowReader : public ICowReader {

    void InitializeMerge();

    void set_total_data_ops(uint64_t size) { total_data_ops_ = size; }

    uint64_t total_data_ops() { return total_data_ops_; }

  private:
    bool ParseOps(std::optional<uint64_t> label);

@@ -152,6 +156,7 @@ class CowReader : public ICowReader {
    uint64_t fd_size_;
    std::optional<uint64_t> last_label_;
    std::shared_ptr<std::vector<CowOperation>> ops_;
    uint64_t total_data_ops_;
};

}  // namespace snapshot
+17 −1
Original line number Diff line number Diff line
@@ -424,6 +424,7 @@ bool Snapuserd::ProcessMergeComplete(chunk_t chunk, void* buffer) {
    }

    SNAP_LOG(DEBUG) << "Merge success: " << merged_ops_cur_iter << "chunk: " << chunk;
    merge_initiated_ = true;
    return true;
}

@@ -445,6 +446,19 @@ chunk_t Snapuserd::GetNextAllocatableChunkId(chunk_t chunk) {
    return next_chunk;
}

void Snapuserd::CheckMergeCompletionStatus() {
    CowHeader header;

    if (merge_initiated_) {
        reader_->GetHeader(&header);
        SNAP_LOG(INFO) << "Merge-status: Total-Merged-ops: " << header.num_merge_ops
                       << " Total-data-ops: " << reader_->total_data_ops();
    } else {
        SNAP_LOG(INFO) << "Merge was not initiated. Total-Merged-ops: " << header.num_merge_ops
                       << " Total-data-ops: " << reader_->total_data_ops();
    }
}

/*
 * Read the metadata from COW device and
 * construct the metadata as required by the kernel.
@@ -818,11 +832,13 @@ bool Snapuserd::ReadMetadata() {
                   << " Num Sector: " << ChunkToSector(data_chunk_id)
                   << " Replace-ops: " << replace_ops << " Zero-ops: " << zero_ops
                   << " Copy-ops: " << copy_ops << " Areas: " << vec_.size()
                   << " Num-ops-merged: " << header.num_merge_ops;
                   << " Num-ops-merged: " << header.num_merge_ops
                   << " Total-data-ops: " << reader_->total_data_ops();

    // Total number of sectors required for creating dm-user device
    num_sectors_ = ChunkToSector(data_chunk_id);
    metadata_read_done_ = true;
    merge_initiated_ = false;
    return true;
}

+2 −0
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@ class Snapuserd final {
    const std::string& GetMiscName() { return misc_name_; }
    uint64_t GetNumSectors() { return num_sectors_; }
    bool IsAttached() const { return ctrl_fd_ >= 0; }
    void CheckMergeCompletionStatus();
    void CloseFds() {
        ctrl_fd_ = {};
        cow_fd_ = {};
@@ -141,6 +142,7 @@ class Snapuserd final {
    std::map<sector_t, const CowOperation*> chunk_map_;

    bool metadata_read_done_ = false;
    bool merge_initiated_ = false;
    BufferSink bufsink_;
};

+1 −0
Original line number Diff line number Diff line
@@ -214,6 +214,7 @@ void SnapuserdServer::RunThread(std::shared_ptr<DmUserHandler> handler) {

    auto misc_name = handler->misc_name();
    LOG(INFO) << "Handler thread about to exit: " << misc_name;
    handler->snapuserd()->CheckMergeCompletionStatus();

    {
        std::lock_guard<std::mutex> lock(lock_);