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

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

Merge changes I2b3f5b33,I464b683b,I8e97c543

* changes:
  libsnapshot: Remove the timeout on client recv().
  libsnapshot: Integrate with snapuserd.
  snapuserd: Add an API call to wait for device deletion.
parents 30d70441 6494a8ca
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -35,9 +35,11 @@ cc_defaults {
        "update_metadata-protos",
    ],
    whole_static_libs: [
        "libcutils",
        "libext2_uuid",
        "libext4_utils",
        "libfstab",
        "libsnapshot_snapuserd",
    ],
    header_libs: [
        "libchrome",
+10 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@
#include <libsnapshot/auto_device.h>
#include <libsnapshot/return.h>
#include <libsnapshot/snapshot_writer.h>
#include <libsnapshot/snapuserd_client.h>

#ifndef FRIEND_TEST
#define FRIEND_TEST(test_set_name, individual_test) \
@@ -358,6 +359,9 @@ class SnapshotManager final : public ISnapshotManager {
    // This is created lazily since it can connect via binder.
    bool EnsureImageManager();

    // Ensure we're connected to snapuserd.
    bool EnsureSnapuserdConnected();

    // Helper for first-stage init.
    bool ForceLocalImageManager();

@@ -414,6 +418,11 @@ class SnapshotManager final : public ISnapshotManager {
                     const std::string& cow_device, const std::chrono::milliseconds& timeout_ms,
                     std::string* dev_path);

    // Create a dm-user device for a given snapshot.
    bool MapDmUserCow(LockedFile* lock, const std::string& name, const std::string& cow_file,
                      const std::string& base_device, const std::chrono::milliseconds& timeout_ms,
                      std::string* path);

    // Map a COW image that was previous created with CreateCowImage.
    std::optional<std::string> MapCowImage(const std::string& name,
                                           const std::chrono::milliseconds& timeout_ms);
@@ -642,6 +651,7 @@ class SnapshotManager final : public ISnapshotManager {
    std::unique_ptr<IImageManager> images_;
    bool has_local_image_manager_ = false;
    bool in_factory_data_reset_ = false;
    std::unique_ptr<SnapuserdClient> snapuserd_client_;
};

}  // namespace snapshot
+1 −1
Original line number Diff line number Diff line
@@ -77,7 +77,7 @@ class Snapuserd final {
    int ReadDiskExceptions(chunk_t chunk, size_t size);
    int ReadData(chunk_t chunk, size_t size);

    std::string GetControlDevicePath() { return control_device_; }
    const std::string& GetControlDevicePath() { return control_device_; }

  private:
    int ProcessReplaceOp(const CowOperation* cow_op);
+4 −0
Original line number Diff line number Diff line
@@ -53,6 +53,10 @@ class SnapuserdClient {
    int RestartSnapuserd(std::vector<std::vector<std::string>>& vec);
    bool InitializeSnapuserd(const std::string& cow_device, const std::string& backing_device,
                             const std::string& control_device);

    // Wait for snapuserd to disassociate with a dm-user control device. This
    // must ONLY be called if the control device has already been deleted.
    bool WaitForDeviceDelete(const std::string& control_device);
};

}  // namespace snapshot
+22 −13
Original line number Diff line number Diff line
@@ -21,12 +21,14 @@
#include <functional>
#include <future>
#include <iostream>
#include <mutex>
#include <sstream>
#include <string>
#include <thread>
#include <vector>

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

namespace android {
namespace snapshot {
@@ -37,19 +39,23 @@ enum class DaemonOperations {
    START,
    QUERY,
    STOP,
    DELETE,
    INVALID,
};

class DmUserHandler {
  private:
    std::unique_ptr<std::thread> threadHandler_;
    std::thread thread_;
    std::unique_ptr<Snapuserd> snapuserd_;

  public:
    void SetThreadHandler(std::function<void(void)> func) {
        threadHandler_ = std::make_unique<std::thread>(func);
    }
    explicit DmUserHandler(std::unique_ptr<Snapuserd>&& snapuserd)
        : snapuserd_(std::move(snapuserd)) {}

    const std::unique_ptr<Snapuserd>& snapuserd() const { return snapuserd_; }
    std::thread& thread() { return thread_; }

    std::unique_ptr<std::thread>& GetThreadHandler() { return threadHandler_; }
    const std::string& GetControlDevice() const;
};

class Stoppable {
@@ -61,9 +67,6 @@ class Stoppable {

    virtual ~Stoppable() {}

    virtual void ThreadStart(std::string cow_device, std::string backing_device,
                             std::string control_device) = 0;

    bool StopRequested() {
        // checks if value in future object is available
        if (futureObj_.wait_for(std::chrono::milliseconds(0)) == std::future_status::timeout)
@@ -78,27 +81,33 @@ class SnapuserdServer : public Stoppable {
  private:
    android::base::unique_fd sockfd_;
    bool terminating_;
    std::vector<std::unique_ptr<DmUserHandler>> dm_users_;
    std::vector<struct pollfd> watched_fds_;

    std::mutex lock_;
    std::vector<std::unique_ptr<DmUserHandler>> dm_users_;

    void AddWatchedFd(android::base::borrowed_fd fd);
    void AcceptClient();
    bool HandleClient(android::base::borrowed_fd fd, int revents);
    bool Recv(android::base::borrowed_fd fd, std::string* data);
    bool Sendmsg(android::base::borrowed_fd fd, const std::string& msg);
    bool Receivemsg(android::base::borrowed_fd fd, const std::string& msg);
    bool Receivemsg(android::base::borrowed_fd fd, const std::string& str);

    void ThreadStart(std::string cow_device, std::string backing_device,
                     std::string control_device) override;
    void ShutdownThreads();
    bool WaitForDelete(const std::string& control_device);
    DaemonOperations Resolveop(std::string& input);
    std::string GetDaemonStatus();
    void Parsemsg(std::string const& msg, const char delim, std::vector<std::string>& out);

    void SetTerminating() { terminating_ = true; }

    bool IsTerminating() { return terminating_; }

    void RunThread(DmUserHandler* handler);

    // Remove a DmUserHandler from dm_users_, searching by its control device.
    // If none is found, return nullptr.
    std::unique_ptr<DmUserHandler> RemoveHandler(const std::string& control_device);

  public:
    SnapuserdServer() { terminating_ = false; }
    ~SnapuserdServer();
Loading