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

Commit c2d5a19d authored by David Anderson's avatar David Anderson
Browse files

snapuserd: Move more fields out of Worker.

These fields are specific to either ReadWorker or MergeWorker, but not
both.

Bug: 288273605
Test: snapuserd_test
Change-Id: I2db9cfa2a8f034249879517bd90a40babe97bc64
parent ab57c8a5
Loading
Loading
Loading
Loading
+22 −1
Original line number Diff line number Diff line
@@ -25,11 +25,19 @@ using namespace android;
using namespace android::dm;
using android::base::unique_fd;

void ReadWorker::CloseFds() {
    ctrl_fd_ = {};
    backing_store_fd_ = {};
    Worker::CloseFds();
}

ReadWorker::ReadWorker(const std::string& cow_device, const std::string& backing_device,
                       const std::string& control_device, const std::string& misc_name,
                       const std::string& base_path_merge,
                       std::shared_ptr<SnapshotHandler> snapuserd)
    : Worker(cow_device, backing_device, control_device, misc_name, base_path_merge, snapuserd) {}
    : Worker(cow_device, misc_name, base_path_merge, snapuserd),
      backing_store_device_(backing_device),
      control_device_(control_device) {}

// Start the replace operation. This will read the
// internal COW format and if the block is compressed,
@@ -209,6 +217,19 @@ bool ReadWorker::Init() {
    if (!Worker::Init()) {
        return false;
    }

    backing_store_fd_.reset(open(backing_store_device_.c_str(), O_RDONLY));
    if (backing_store_fd_ < 0) {
        SNAP_PLOG(ERROR) << "Open Failed: " << backing_store_device_;
        return false;
    }

    ctrl_fd_.reset(open(control_device_.c_str(), O_RDWR));
    if (ctrl_fd_ < 0) {
        SNAP_PLOG(ERROR) << "Unable to open " << control_device_;
        return false;
    }

    xorsink_.Initialize(&bufsink_, BLOCK_SZ);
    return true;
}
+10 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ class ReadWorker : public Worker {

    bool Run();
    bool Init() override;
    void CloseFds() override;

  private:
    // Functions interacting with dm-user
@@ -50,6 +51,15 @@ class ReadWorker : public Worker {
    bool ReadFromSourceDevice(const CowOperation* cow_op);
    bool ReadDataFromBaseDevice(sector_t sector, size_t read_size);

    constexpr bool IsBlockAligned(size_t size) { return ((size & (BLOCK_SZ - 1)) == 0); }
    constexpr sector_t ChunkToSector(chunk_t chunk) { return chunk << CHUNK_SHIFT; }

    std::string backing_store_device_;
    unique_fd backing_store_fd_;

    std::string control_device_;
    unique_fd ctrl_fd_;

    XorSink xorsink_;
    bool header_response_ = false;
};
+2 −3
Original line number Diff line number Diff line
@@ -59,9 +59,8 @@ bool SnapshotHandler::InitializeWorkers() {
        worker_threads_.push_back(std::move(wt));
    }

    merge_thread_ =
            std::make_unique<MergeWorker>(cow_device_, backing_store_device_, control_device_,
                                          misc_name_, base_path_merge_, GetSharedPtr());
    merge_thread_ = std::make_unique<MergeWorker>(cow_device_, misc_name_, base_path_merge_,
                                                  GetSharedPtr());

    read_ahead_thread_ = std::make_unique<ReadAhead>(cow_device_, backing_store_device_, misc_name_,
                                                     GetSharedPtr());
+2 −3
Original line number Diff line number Diff line
@@ -24,11 +24,10 @@ using namespace android;
using namespace android::dm;
using android::base::unique_fd;

MergeWorker::MergeWorker(const std::string& cow_device, const std::string& backing_device,
                         const std::string& control_device, const std::string& misc_name,
MergeWorker::MergeWorker(const std::string& cow_device, const std::string& misc_name,
                         const std::string& base_path_merge,
                         std::shared_ptr<SnapshotHandler> snapuserd)
    : Worker(cow_device, backing_device, control_device, misc_name, base_path_merge, snapuserd) {}
    : Worker(cow_device, misc_name, base_path_merge, snapuserd) {}

int MergeWorker::PrepareMerge(uint64_t* source_offset, int* pending_ops,
                              std::vector<const CowOperation*>* replace_zero_vec) {
+2 −2
Original line number Diff line number Diff line
@@ -22,8 +22,7 @@ namespace snapshot {

class MergeWorker : public Worker {
  public:
    MergeWorker(const std::string& cow_device, const std::string& backing_device,
                const std::string& control_device, const std::string& misc_name,
    MergeWorker(const std::string& cow_device, const std::string& misc_name,
                const std::string& base_path_merge, std::shared_ptr<SnapshotHandler> snapuserd);
    bool Run();

@@ -40,6 +39,7 @@ class MergeWorker : public Worker {
    void FinalizeIouring();

  private:
    std::unique_ptr<ICowOpIter> cowop_iter_;
    std::unique_ptr<struct io_uring> ring_;
    size_t ra_block_index_ = 0;
    uint64_t blocks_merged_in_group_ = 0;
Loading