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

Commit aa453194 authored by David Anderson's avatar David Anderson Committed by Gerrit Code Review
Browse files

Merge changes Ie2f531bd,I7e418ffe

* changes:
  libsnapshot: Remove OnlineKernelSnapshotWriter.
  libsnapshot: Remove unused SupportsCopyOperation.
parents 8aee6d4a 95b26e1d
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -93,9 +93,6 @@ class ICowWriter {
    // Return number of bytes the cow image occupies on disk.
    virtual uint64_t GetCowSize() = 0;

    // Returns true if AddCopy() operations are supported.
    virtual bool SupportsCopyOperation() const { return true; }

    const CowOptions& options() { return options_; }

  protected:
+0 −3
Original line number Diff line number Diff line
@@ -31,9 +31,6 @@ class MockSnapshotWriter : public ISnapshotWriter {
    // Return number of bytes the cow image occupies on disk.
    MOCK_METHOD(uint64_t, GetCowSize, (), (override));

    // Returns true if AddCopy() operations are supported.
    MOCK_METHOD(bool, SupportsCopyOperation, (), (const override));

    MOCK_METHOD(bool, EmitCopy, (uint64_t, uint64_t, uint64_t), (override));
    MOCK_METHOD(bool, EmitRawBlocks, (uint64_t, const void*, size_t), (override));
    MOCK_METHOD(bool, EmitXorBlocks, (uint32_t, const void*, size_t, uint32_t, uint16_t),
+0 −4
Original line number Diff line number Diff line
@@ -697,10 +697,6 @@ class SnapshotManager final : public ISnapshotManager {
            LockedFile* lock, const std::optional<std::string>& source_device,
            const std::string& partition_name, const SnapshotStatus& status,
            const SnapshotPaths& paths);
    std::unique_ptr<ISnapshotWriter> OpenKernelSnapshotWriter(
            LockedFile* lock, const std::optional<std::string>& source_device,
            const std::string& partition_name, const SnapshotStatus& status,
            const SnapshotPaths& paths);

    // Map the base device, COW devices, and snapshot device.
    bool MapPartitionWithSnapshot(LockedFile* lock, CreateLogicalPartitionParams params,
+0 −33
Original line number Diff line number Diff line
@@ -89,38 +89,5 @@ class CompressedSnapshotWriter final : public ISnapshotWriter {
    std::unique_ptr<CowWriter> cow_;
};

// Write directly to a dm-snapshot device.
class OnlineKernelSnapshotWriter final : public ISnapshotWriter {
  public:
    OnlineKernelSnapshotWriter(const CowOptions& options);

    // Set the device used for all writes.
    void SetSnapshotDevice(android::base::unique_fd&& snapshot_fd, uint64_t cow_size);

    bool Initialize() override { return true; }
    bool InitializeAppend(uint64_t) override { return true; }

    bool Finalize() override;
    uint64_t GetCowSize() override { return cow_size_; }
    std::unique_ptr<FileDescriptor> OpenReader() override;

    // Online kernel snapshot writer doesn't care about merge sequences.
    // So ignore.
    bool VerifyMergeOps() const noexcept override { return true; }

  protected:
    bool EmitRawBlocks(uint64_t new_block_start, const void* data, size_t size) override;
    bool EmitZeroBlocks(uint64_t new_block_start, uint64_t num_blocks) override;
    bool EmitXorBlocks(uint32_t new_block_start, const void* data, size_t size, uint32_t old_block,
                       uint16_t offset) override;
    bool EmitCopy(uint64_t new_block, uint64_t old_block, uint64_t num_blocks = 1) override;
    bool EmitLabel(uint64_t label) override;
    bool EmitSequenceData(size_t num_ops, const uint32_t* data) override;

  private:
    android::base::unique_fd snapshot_fd_;
    uint64_t cow_size_ = 0;
};

}  // namespace snapshot
}  // namespace android
+6 −33
Original line number Diff line number Diff line
@@ -3647,12 +3647,13 @@ std::unique_ptr<ISnapshotWriter> SnapshotManager::OpenSnapshotWriter(
        return nullptr;
    }

    if (status.using_snapuserd()) {
    if (!status.using_snapuserd()) {
        LOG(ERROR) << "Can only create snapshot writers with userspace or compressed snapshots";
        return nullptr;
    }

    return OpenCompressedSnapshotWriter(lock.get(), source_device, params.GetPartitionName(),
                                        status, paths);
    }
    return OpenKernelSnapshotWriter(lock.get(), source_device, params.GetPartitionName(), status,
                                    paths);
#endif
}

@@ -3700,34 +3701,6 @@ std::unique_ptr<ISnapshotWriter> SnapshotManager::OpenCompressedSnapshotWriter(

    return writer;
}

std::unique_ptr<ISnapshotWriter> SnapshotManager::OpenKernelSnapshotWriter(
        LockedFile* lock, const std::optional<std::string>& source_device,
        [[maybe_unused]] const std::string& partition_name, const SnapshotStatus& status,
        const SnapshotPaths& paths) {
    CHECK(lock);

    CowOptions cow_options;
    cow_options.max_blocks = {status.device_size() / cow_options.block_size};

    auto writer = std::make_unique<OnlineKernelSnapshotWriter>(cow_options);

    std::string path = paths.snapshot_device.empty() ? paths.target_device : paths.snapshot_device;
    unique_fd fd(open(path.c_str(), O_RDWR | O_CLOEXEC));
    if (fd < 0) {
        PLOG(ERROR) << "open failed: " << path;
        return nullptr;
    }

    if (source_device) {
        writer->SetSourceDevice(*source_device);
    }

    uint64_t cow_size = status.cow_partition_size() + status.cow_file_size();
    writer->SetSnapshotDevice(std::move(fd), cow_size);

    return writer;
}
#endif  // !defined(LIBSNAPSHOT_NO_COW_WRITE)

bool SnapshotManager::UnmapUpdateSnapshot(const std::string& target_partition_name) {
Loading