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

Commit 39108690 authored by Alessio Balsini's avatar Alessio Balsini
Browse files

libsnapshot: MapCowImage returns the COW device path



When a device is not dm-mapped, the whole path of the newly generated
COW device is required.
This was causing some of the libsnapshot_test cases to fail.
Fix by making MapCowImage() optionally return the COW device path.

Fixes: 142800685
Test: libsnapshot_test
Change-Id: I9570b4254d47b2d8fc942053590a320dcb20f7d5
Signed-off-by: default avatarAlessio Balsini <balsini@google.com>
parent 405e67b6
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
#include <chrono>
#include <map>
#include <memory>
#include <optional>
#include <ostream>
#include <string>
#include <string_view>
@@ -285,7 +286,8 @@ class SnapshotManager final {
                     std::string* dev_path);

    // Map a COW image that was previous created with CreateCowImage.
    bool MapCowImage(const std::string& name, const std::chrono::milliseconds& timeout_ms);
    std::optional<std::string> MapCowImage(const std::string& name,
                                           const std::chrono::milliseconds& timeout_ms);

    // Remove the backing copy-on-write image and snapshot states for the named snapshot. The
    // caller is responsible for ensuring that the snapshot is unmapped.
+7 −7
Original line number Diff line number Diff line
@@ -418,9 +418,9 @@ bool SnapshotManager::MapSnapshot(LockedFile* lock, const std::string& name,
    return true;
}

bool SnapshotManager::MapCowImage(const std::string& name,
                                  const std::chrono::milliseconds& timeout_ms) {
    if (!EnsureImageManager()) return false;
std::optional<std::string> SnapshotManager::MapCowImage(
        const std::string& name, const std::chrono::milliseconds& timeout_ms) {
    if (!EnsureImageManager()) return std::nullopt;
    auto cow_image_name = GetCowImageDeviceName(name);

    bool ok;
@@ -436,10 +436,10 @@ bool SnapshotManager::MapCowImage(const std::string& name,

    if (ok) {
        LOG(INFO) << "Mapped " << cow_image_name << " to " << cow_dev;
    } else {
        LOG(ERROR) << "Could not map image device: " << cow_image_name;
        return cow_dev;
    }
    return ok;
    LOG(ERROR) << "Could not map image device: " << cow_image_name;
    return std::nullopt;
}

bool SnapshotManager::UnmapSnapshot(LockedFile* lock, const std::string& name) {
@@ -1411,7 +1411,7 @@ bool SnapshotManager::MapCowDevices(LockedFile* lock, const CreateLogicalPartiti
        auto remaining_time = GetRemainingTime(params.timeout_ms, begin);
        if (remaining_time.count() < 0) return false;

        if (!MapCowImage(partition_name, remaining_time)) {
        if (!MapCowImage(partition_name, remaining_time).has_value()) {
            LOG(ERROR) << "Could not map cow image for partition: " << partition_name;
            return false;
        }
+3 −4
Original line number Diff line number Diff line
@@ -254,12 +254,11 @@ class SnapshotTest : public ::testing::Test {

    AssertionResult MapCowImage(const std::string& name,
                                const std::chrono::milliseconds& timeout_ms, std::string* path) {
        if (!sm->MapCowImage(name, timeout_ms)) {
        auto cow_image_path = sm->MapCowImage(name, timeout_ms);
        if (!cow_image_path.has_value()) {
            return AssertionFailure() << "Cannot map cow image " << name;
        }
        if (!dm_.GetDmDevicePathByName(name + "-cow-img"s, path)) {
            return AssertionFailure() << "No path for " << name << "-cow-img";
        }
        *path = *cow_image_path;
        return AssertionSuccess();
    }