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

Commit 4d557131 authored by Akilesh Kailash's avatar Akilesh Kailash Committed by Automerger Merge Worker
Browse files

Merge "libsnapshot:snapuserd: Handle signals" am: c81477c5

Original change: https://android-review.googlesource.com/c/platform/system/core/+/1449996

Change-Id: I13a5e584bb8629e4ad3e918675cc454f9d7532b3
parents 5d0170c8 c81477c5
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -65,7 +65,7 @@ class Snapuserd final {
          backing_store_device_(in_backing_store_device),
          metadata_read_done_(false) {}

    int Init();
    bool Init();
    int Run();
    int ReadDmUserHeader();
    int WriteDmUserPayload(size_t size);
+0 −14
Original line number Diff line number Diff line
@@ -14,22 +14,8 @@

#pragma once

#include <arpa/inet.h>
#include <cutils/sockets.h>
#include <errno.h>
#include <netdb.h>
#include <netinet/in.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>

#include <chrono>
#include <cstring>
#include <iostream>
#include <sstream>
#include <string>
#include <thread>
#include <vector>
+7 −0
Original line number Diff line number Diff line
@@ -14,6 +14,8 @@

#pragma once

#include <poll.h>

#include <libsnapshot/snapuserd_server.h>

namespace android {
@@ -34,12 +36,17 @@ class Daemon {

  private:
    bool is_running_;
    std::unique_ptr<struct pollfd> poll_fd_;
    // Signal mask used with ppoll()
    sigset_t signal_mask_;

    Daemon();
    Daemon(Daemon const&) = delete;
    void operator=(Daemon const&) = delete;

    SnapuserdServer server_;
    void MaskAllSignalsExceptIntAndTerm();
    void MaskAllSignals();
    static void SignalHandler(int signal);
};

+2 −14
Original line number Diff line number Diff line
@@ -14,18 +14,6 @@

#pragma once

#include <stdint.h>

#include <arpa/inet.h>
#include <cutils/sockets.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>

#include <errno.h>
#include <cstdio>
#include <cstring>
#include <functional>
@@ -89,6 +77,7 @@ class SnapuserdServer : public Stoppable {
    android::base::unique_fd sockfd_;
    bool terminating_;
    std::vector<std::unique_ptr<Client>> clients_vec_;

    void ThreadStart(std::string cow_device, std::string backing_device) override;
    void ShutdownThreads();
    DaemonOperations Resolveop(std::string& input);
@@ -100,8 +89,6 @@ class SnapuserdServer : public Stoppable {
    bool IsTerminating() { return terminating_; }

  public:
    ~SnapuserdServer() { clients_vec_.clear(); }

    SnapuserdServer() { terminating_ = false; }

    int Start(std::string socketname);
@@ -109,6 +96,7 @@ class SnapuserdServer : public Stoppable {
    int Receivemsg(int fd);
    int Sendmsg(int fd, char* msg, size_t len);
    std::string Recvmsg(int fd, int* ret);
    android::base::borrowed_fd GetSocketFd() { return sockfd_; }
};

}  // namespace snapshot
+12 −7
Original line number Diff line number Diff line
@@ -485,17 +485,17 @@ int Snapuserd::WriteDmUserPayload(size_t size) {
    return sizeof(struct dm_user_header) + size;
}

int Snapuserd::Init() {
bool Snapuserd::Init() {
    backing_store_fd_.reset(open(backing_store_device_.c_str(), O_RDONLY));
    if (backing_store_fd_ < 0) {
        LOG(ERROR) << "Open Failed: " << backing_store_device_;
        return 1;
        return false;
    }

    cow_fd_.reset(open(cow_device_.c_str(), O_RDWR));
    if (cow_fd_ < 0) {
        LOG(ERROR) << "Open Failed: " << cow_device_;
        return 1;
        return false;
    }

    std::string str(cow_device_);
@@ -509,7 +509,7 @@ int Snapuserd::Init() {
    std::string uuid;
    if (!dm.GetDmDeviceUuidByName(device_name, &uuid)) {
        LOG(ERROR) << "Unable to find UUID for " << cow_device_;
        return 1;
        return false;
    }

    LOG(DEBUG) << "UUID: " << uuid;
@@ -518,7 +518,7 @@ int Snapuserd::Init() {
    ctrl_fd_.reset(open(t.control_path().c_str(), O_RDWR));
    if (ctrl_fd_ < 0) {
        LOG(ERROR) << "Unable to open " << t.control_path();
        return 1;
        return false;
    }

    // Allocate the buffer which is used to communicate between
@@ -528,7 +528,7 @@ int Snapuserd::Init() {
    size_t buf_size = sizeof(struct dm_user_header) + PAYLOAD_SIZE;
    bufsink_.Initialize(buf_size);

    return 0;
    return true;
}

int Snapuserd::Run() {
@@ -601,6 +601,11 @@ int Snapuserd::Run() {
                        ret = ReadData(chunk + num_chunks_read, read_size);
                        if (ret < 0) {
                            LOG(ERROR) << "ReadData failed";
                            // TODO: Bug 168259959: All the error paths from this function
                            // should send error code to dm-user thereby IO
                            // terminates with an error from dm-user. Returning
                            // here without sending error code will block the
                            // IO.
                            return ret;
                        }
                    }
@@ -622,7 +627,7 @@ int Snapuserd::Run() {
        }

        case DM_USER_MAP_WRITE: {
            // TODO: After merge operation is completed, kernel issues write
            // TODO: Bug: 168311203: After merge operation is completed, kernel issues write
            // to flush all the exception mappings where the merge is
            // completed. If dm-user routes the WRITE IO, we need to clear
            // in-memory data structures representing those exception
Loading