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

Commit 384b22ce authored by David Anderson's avatar David Anderson
Browse files

snapuserd: Add an IBlockServerFactory abstraction.

To avoid SnapshotHandler hardcoding specifics about dm-user, this patch
adds a factory interface, responsible for providing IBlockServerOpener
objects.

The test harness will use this to facilitate dm-user-less testing on
host devices.

Bug: 288273605
Test: snapuserd_test
Change-Id: Ifd33c28ee7076f30a8a90f745353893188f97a08
parent 2cffe186
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -142,5 +142,11 @@ std::unique_ptr<IBlockServer> DmUserBlockServerOpener::Open(IBlockServer::Delega
    return std::make_unique<DmUserBlockServer>(misc_name_, std::move(fd), delegate, buffer_size);
}

std::shared_ptr<IBlockServerOpener> DmUserBlockServerFactory::CreateOpener(
        const std::string& misc_name) {
    auto dm_path = "/dev/dm-user/" + misc_name;
    return std::make_shared<DmUserBlockServerOpener>(misc_name, dm_path);
}

}  // namespace snapshot
}  // namespace android
+8 −0
Original line number Diff line number Diff line
@@ -83,5 +83,13 @@ class IBlockServerOpener {
                                               size_t buffer_size) = 0;
};

class IBlockServerFactory {
  public:
    virtual ~IBlockServerFactory() {}

    // Return a new IBlockServerOpener given a unique device name.
    virtual std::shared_ptr<IBlockServerOpener> CreateOpener(const std::string& misc_name) = 0;
};

}  // namespace snapshot
}  // namespace android
+5 −0
Original line number Diff line number Diff line
@@ -59,5 +59,10 @@ class DmUserBlockServerOpener : public IBlockServerOpener {
    std::string dm_user_path_;
};

class DmUserBlockServerFactory : public IBlockServerFactory {
  public:
    std::shared_ptr<IBlockServerOpener> CreateOpener(const std::string& misc_name) override;
};

}  // namespace snapshot
}  // namespace android
+3 −2
Original line number Diff line number Diff line
@@ -50,9 +50,10 @@ SnapshotHandlerManager::SnapshotHandlerManager() {
std::shared_ptr<HandlerThread> SnapshotHandlerManager::AddHandler(
        const std::string& misc_name, const std::string& cow_device_path,
        const std::string& backing_device, const std::string& base_path_merge,
        int num_worker_threads, bool use_iouring, bool perform_verification) {
        std::shared_ptr<IBlockServerOpener> opener, int num_worker_threads, bool use_iouring,
        bool perform_verification) {
    auto snapuserd = std::make_shared<SnapshotHandler>(misc_name, cow_device_path, backing_device,
                                                       base_path_merge, num_worker_threads,
                                                       base_path_merge, opener, num_worker_threads,
                                                       use_iouring, perform_verification);
    if (!snapuserd->InitCowDevice()) {
        LOG(ERROR) << "Failed to initialize Snapuserd";
+3 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@
#include <vector>

#include <android-base/unique_fd.h>
#include <snapuserd/block_server.h>

namespace android {
namespace snapshot {
@@ -55,6 +56,7 @@ class ISnapshotHandlerManager {
                                                      const std::string& cow_device_path,
                                                      const std::string& backing_device,
                                                      const std::string& base_path_merge,
                                                      std::shared_ptr<IBlockServerOpener> opener,
                                                      int num_worker_threads, bool use_iouring,
                                                      bool perform_verification) = 0;

@@ -91,6 +93,7 @@ class SnapshotHandlerManager final : public ISnapshotHandlerManager {
                                              const std::string& cow_device_path,
                                              const std::string& backing_device,
                                              const std::string& base_path_merge,
                                              std::shared_ptr<IBlockServerOpener> opener,
                                              int num_worker_threads, bool use_iouring,
                                              bool perform_verification) override;
    bool StartHandler(const std::string& misc_name) override;
Loading