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

Commit 6bbaccc4 authored by Daniel Zheng's avatar Daniel Zheng
Browse files

snapuserd: consolidate args to struct

Test: th
Change-Id: I46a1f0be5862a73e47435c39055b2d32d19de656
parent 82976544
Loading
Loading
Loading
Loading
+12 −8
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@
#include <snapuserd/snapuserd_client.h>

#include <storage_literals/storage_literals.h>
#include "user-space-merge/snapuserd_core.h"

#include "snapuserd_daemon.h"

@@ -35,7 +36,8 @@ DEFINE_bool(user_snapshot, false, "If true, user-space snapshots are used");
DEFINE_bool(io_uring, false, "If true, io_uring feature is enabled");
DEFINE_bool(o_direct, false, "If true, enable direct reads on source device");
DEFINE_int32(cow_op_merge_size, 0, "number of operations to be processed at once");
DEFINE_int32(worker_count, 4, "number of worker threads used to serve I/O requests to dm-user");
DEFINE_int32(worker_count, android::snapshot::kNumWorkerThreads,
             "number of worker threads used to serve I/O requests to dm-user");
DEFINE_int32(verify_block_size, 1_MiB, "block sized used during verification of snapshots");
DEFINE_int32(num_verify_threads, 3, "number of threads used during verification phase");

@@ -101,9 +103,6 @@ bool Daemon::StartServerForUserspaceSnapshots(int arg_start, int argc, char** ar
    MaskAllSignalsExceptIntAndTerm();

    user_server_.SetServerRunning();
    if (FLAGS_io_uring) {
        user_server_.SetIouringEnabled();
    }

    if (FLAGS_socket_handoff) {
        return user_server_.RunForSocketHandoff();
@@ -116,14 +115,19 @@ bool Daemon::StartServerForUserspaceSnapshots(int arg_start, int argc, char** ar
    }
    for (int i = arg_start; i < argc; i++) {
        auto parts = android::base::Split(argv[i], ",");

        if (parts.size() != 4) {
            LOG(ERROR) << "Malformed message, expected at least four sub-arguments.";
            return false;
        }
        auto handler = user_server_.AddHandler(
                parts[0], parts[1], parts[2], parts[3], FLAGS_worker_count, FLAGS_o_direct,
                FLAGS_cow_op_merge_size, FLAGS_verify_block_size, FLAGS_num_verify_threads);
        HandlerOptions options = {
                .num_worker_threads = FLAGS_worker_count,
                .use_iouring = FLAGS_io_uring,
                .o_direct = FLAGS_o_direct,
                .cow_op_merge_size = static_cast<uint32_t>(FLAGS_cow_op_merge_size),
                .verify_block_size = static_cast<uint32_t>(FLAGS_verify_block_size),
                .num_verification_threads = static_cast<uint32_t>(FLAGS_num_verify_threads),
        };
        auto handler = user_server_.AddHandler(parts[0], parts[1], parts[2], parts[3], options);
        if (!handler || !user_server_.StartHandler(parts[0])) {
            return false;
        }
+2 −1
Original line number Diff line number Diff line
@@ -40,8 +40,9 @@ Extractor::Extractor(const std::string& base_path, const std::string& cow_path)

bool Extractor::Init() {
    auto opener = factory_.CreateTestOpener(control_name_);
    HandlerOptions options;
    handler_ = std::make_shared<SnapshotHandler>(control_name_, cow_path_, base_path_, base_path_,
                                                 opener, 1, false, false, false, 0, 0, 0);
                                                 opener, options);
    if (!handler_->InitCowDevice()) {
        return false;
    }
+3 −7
Original line number Diff line number Diff line
@@ -52,13 +52,9 @@ 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,
        std::shared_ptr<IBlockServerOpener> opener, int num_worker_threads, bool use_iouring,
        bool o_direct, uint32_t cow_op_merge_size, uint32_t verify_block_size,
        uint32_t num_verification_threads) {
    auto snapuserd = std::make_shared<SnapshotHandler>(
            misc_name, cow_device_path, backing_device, base_path_merge, opener, num_worker_threads,
            use_iouring, perform_verification_, o_direct, cow_op_merge_size, verify_block_size,
            num_verification_threads);
        std::shared_ptr<IBlockServerOpener> opener, HandlerOptions options) {
    auto snapuserd = std::make_shared<SnapshotHandler>(misc_name, cow_device_path, backing_device,
                                                       base_path_merge, opener, options);
    if (!snapuserd->InitCowDevice()) {
        LOG(ERROR) << "Failed to initialize Snapuserd";
        return nullptr;
+21 −12
Original line number Diff line number Diff line
@@ -27,6 +27,15 @@
namespace android {
namespace snapshot {

struct HandlerOptions {
    int num_worker_threads{};
    bool use_iouring{};
    bool o_direct{};
    uint32_t cow_op_merge_size{};
    uint32_t verify_block_size{};
    uint32_t num_verification_threads{};
};

class SnapshotHandler;

class HandlerThread {
@@ -53,12 +62,12 @@ class ISnapshotHandlerManager {
    virtual ~ISnapshotHandlerManager() {}

    // Add a new snapshot handler but do not start serving requests yet.
    virtual std::shared_ptr<HandlerThread> AddHandler(
            const std::string& misc_name, 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 o_direct, uint32_t cow_op_merge_size, uint32_t verify_block_size,
            uint32_t num_verification_threads) = 0;
    virtual std::shared_ptr<HandlerThread> AddHandler(const std::string& misc_name,
                                                      const std::string& cow_device_path,
                                                      const std::string& backing_device,
                                                      const std::string& base_path_merge,
                                                      std::shared_ptr<IBlockServerOpener> opener,
                                                      HandlerOptions options) = 0;

    // Start serving requests on a snapshot handler.
    virtual bool StartHandler(const std::string& misc_name) = 0;
@@ -98,12 +107,12 @@ class ISnapshotHandlerManager {
class SnapshotHandlerManager final : public ISnapshotHandlerManager {
  public:
    SnapshotHandlerManager();
    std::shared_ptr<HandlerThread> AddHandler(
            const std::string& misc_name, 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 o_direct, uint32_t cow_op_merge_size, uint32_t verify_block_size,
            uint32_t num_verification_threads) override;
    std::shared_ptr<HandlerThread> AddHandler(const std::string& misc_name,
                                              const std::string& cow_device_path,
                                              const std::string& backing_device,
                                              const std::string& base_path_merge,
                                              std::shared_ptr<IBlockServerOpener> opener,
                                              HandlerOptions options) override;

    bool StartHandler(const std::string& misc_name) override;
    bool DeleteHandler(const std::string& misc_name) override;
+13 −19
Original line number Diff line number Diff line
@@ -37,29 +37,21 @@ using android::base::unique_fd;

SnapshotHandler::SnapshotHandler(std::string misc_name, std::string cow_device,
                                 std::string backing_device, std::string base_path_merge,
                                 std::shared_ptr<IBlockServerOpener> opener, int num_worker_threads,
                                 bool use_iouring, bool perform_verification, bool o_direct,
                                 uint32_t cow_op_merge_size, uint32_t verify_block_size,
                                 uint32_t num_verification_threads) {
                                 std::shared_ptr<IBlockServerOpener> opener,
                                 HandlerOptions options) {
    misc_name_ = std::move(misc_name);
    cow_device_ = std::move(cow_device);
    backing_store_device_ = std::move(backing_device);
    block_server_opener_ = std::move(opener);
    base_path_merge_ = std::move(base_path_merge);
    num_worker_threads_ = num_worker_threads;
    is_io_uring_enabled_ = use_iouring;
    perform_verification_ = perform_verification;
    o_direct_ = o_direct;
    cow_op_merge_size_ = cow_op_merge_size;
    verify_block_size_ = verify_block_size;
    num_verification_threads_ = num_verification_threads;
    handler_options_ = options;
}

bool SnapshotHandler::InitializeWorkers() {
    for (int i = 0; i < num_worker_threads_; i++) {
        auto wt = std::make_unique<ReadWorker>(cow_device_, backing_store_device_, misc_name_,
                                               base_path_merge_, GetSharedPtr(),
                                               block_server_opener_, o_direct_);
                                               block_server_opener_, handler_options_.o_direct);
        if (!wt->Init()) {
            SNAP_LOG(ERROR) << "Thread initialization failed";
            return false;
@@ -67,14 +59,16 @@ bool SnapshotHandler::InitializeWorkers() {

        worker_threads_.push_back(std::move(wt));
    }
    merge_thread_ = std::make_unique<MergeWorker>(cow_device_, misc_name_, base_path_merge_,
                                                  GetSharedPtr(), cow_op_merge_size_);
    merge_thread_ =
            std::make_unique<MergeWorker>(cow_device_, misc_name_, base_path_merge_, GetSharedPtr(),
                                          handler_options_.cow_op_merge_size);

    read_ahead_thread_ = std::make_unique<ReadAhead>(cow_device_, backing_store_device_, misc_name_,
                                                     GetSharedPtr(), cow_op_merge_size_);
    read_ahead_thread_ =
            std::make_unique<ReadAhead>(cow_device_, backing_store_device_, misc_name_,
                                        GetSharedPtr(), handler_options_.cow_op_merge_size);

    update_verify_ = std::make_unique<UpdateVerify>(misc_name_, verify_block_size_,
                                                    num_verification_threads_);
    update_verify_ = std::make_unique<UpdateVerify>(misc_name_, handler_options_.verify_block_size,
                                                    handler_options_.num_verification_threads);

    return true;
}
@@ -435,7 +429,7 @@ bool SnapshotHandler::IsIouringSupported() {
    // During selinux init transition, libsnapshot will propagate the
    // status of io_uring enablement. As properties are not initialized,
    // we cannot query system property.
    if (is_io_uring_enabled_) {
    if (handler_options_.use_iouring) {
        return true;
    }

Loading