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

Commit 43b64966 authored by David Anderson's avatar David Anderson Committed by Automerger Merge Worker
Browse files

Merge "snapuserd: Move GetNumSectors call to snapuserd_server." into main am: bcb34d2c

parents 64f76a44 bcb34d2c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ static constexpr uint32_t SNAPSHOT_VALID = 1;
 * multiple of 512 bytes. Hence these two constants.
 */
static constexpr uint32_t SECTOR_SHIFT = 9;
static constexpr uint64_t SECTOR_SIZE = (1ULL << SECTOR_SHIFT);

static constexpr size_t BLOCK_SZ = 4096;
static constexpr size_t BLOCK_SHIFT = (__builtin_ffs(BLOCK_SZ) - 1);
+16 −14
Original line number Diff line number Diff line
@@ -280,20 +280,6 @@ bool SnapshotHandler::InitCowDevice() {
        return false;
    }

    unique_fd fd(TEMP_FAILURE_RETRY(open(base_path_merge_.c_str(), O_RDONLY | O_CLOEXEC)));
    if (fd < 0) {
        SNAP_LOG(ERROR) << "Cannot open block device";
        return false;
    }

    uint64_t dev_sz = get_block_device_size(fd.get());
    if (!dev_sz) {
        SNAP_LOG(ERROR) << "Failed to find block device size: " << base_path_merge_;
        return false;
    }

    num_sectors_ = dev_sz >> SECTOR_SHIFT;

    return ReadMetadata();
}

@@ -460,5 +446,21 @@ void SnapshotHandler::FreeResources() {
    merge_thread_ = nullptr;
}

uint64_t SnapshotHandler::GetNumSectors() const {
    unique_fd fd(TEMP_FAILURE_RETRY(open(base_path_merge_.c_str(), O_RDONLY | O_CLOEXEC)));
    if (fd < 0) {
        SNAP_LOG(ERROR) << "Cannot open base path: " << base_path_merge_;
        return false;
    }

    uint64_t dev_sz = get_block_device_size(fd.get());
    if (!dev_sz) {
        SNAP_LOG(ERROR) << "Failed to find block device size: " << base_path_merge_;
        return false;
    }

    return dev_sz / SECTOR_SIZE;
}

}  // namespace snapshot
}  // namespace android
+1 −3
Original line number Diff line number Diff line
@@ -109,7 +109,7 @@ class SnapshotHandler : public std::enable_shared_from_this<SnapshotHandler> {

    const std::string& GetControlDevicePath() { return control_device_; }
    const std::string& GetMiscName() { return misc_name_; }
    const uint64_t& GetNumSectors() { return num_sectors_; }
    uint64_t GetNumSectors() const;
    const bool& IsAttached() const { return attached_; }
    void AttachControlDevice() { attached_ = true; }

@@ -202,8 +202,6 @@ class SnapshotHandler : public std::enable_shared_from_this<SnapshotHandler> {

    unique_fd cow_fd_;

    uint64_t num_sectors_;

    std::unique_ptr<CowReader> reader_;

    // chunk_vec stores the pseudo mapping of sector
+6 −1
Original line number Diff line number Diff line
@@ -130,7 +130,12 @@ bool UserSnapshotServer::Receivemsg(android::base::borrowed_fd fd, const std::st
            return Sendmsg(fd, "fail");
        }

        auto retval = "success," + std::to_string(handler->snapuserd()->GetNumSectors());
        auto num_sectors = handler->snapuserd()->GetNumSectors();
        if (!num_sectors) {
            return Sendmsg(fd, "fail");
        }

        auto retval = "success," + std::to_string(num_sectors);
        return Sendmsg(fd, retval);
    } else if (cmd == "start") {
        // Message format:
+2 −0
Original line number Diff line number Diff line
@@ -540,7 +540,9 @@ void SnapuserdTest::InitCowDevice() {
                                 base_loop_->device(), 1, use_iouring, false);
    ASSERT_NE(handler, nullptr);
    ASSERT_NE(handler->snapuserd(), nullptr);
#ifdef __ANDROID__
    ASSERT_NE(handler->snapuserd()->GetNumSectors(), 0);
#endif
}

void SnapuserdTest::SetDeviceControlName() {