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

Commit 4067c7e1 authored by David Anderson's avatar David Anderson
Browse files

libsnapshot: Ensure dm-user devices are destroyed after a merge.

Also, make sure snapuserd has closed its references. This is preventing
the merge from completing until a reboot.

Bug: N/A
Test: vts_libsnapshot_test
Change-Id: Iba18f887bdb262c630ec44461871e19fe64dbf3c
parent 2147cc56
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -630,6 +630,9 @@ class SnapshotManager final : public ISnapshotManager {
    // The reverse of MapPartitionWithSnapshot.
    bool UnmapPartitionWithSnapshot(LockedFile* lock, const std::string& target_partition_name);

    // Unmap a dm-user device through snapuserd.
    bool UnmapDmUserDevice(const std::string& snapshot_name);

    // If there isn't a previous update, return true. |needs_merge| is set to false.
    // If there is a previous update but the device has not boot into it, tries to cancel the
    //   update and delete any snapshots. Return true if successful. |needs_merge| is set to false.
+37 −21
Original line number Diff line number Diff line
@@ -1247,6 +1247,10 @@ bool SnapshotManager::CollapseSnapshotDevice(const std::string& name,
        return false;
    }

    if (status.compression_enabled()) {
        UnmapDmUserDevice(name);
    }

    // Cleanup the base device as well, since it is no longer used. This does
    // not block cleanup.
    auto base_name = GetBaseDeviceName(name);
@@ -2063,11 +2067,36 @@ bool SnapshotManager::UnmapCowDevices(LockedFile* lock, const std::string& name)

    auto& dm = DeviceMapper::Instance();

    auto dm_user_name = GetDmUserCowName(name);
    if (IsCompressionEnabled() && dm.GetState(dm_user_name) != DmDeviceState::INVALID) {
    if (IsCompressionEnabled() && !UnmapDmUserDevice(name)) {
        return false;
    }

    auto cow_name = GetCowName(name);
    if (!dm.DeleteDeviceIfExists(cow_name)) {
        LOG(ERROR) << "Cannot unmap " << cow_name;
        return false;
    }

    std::string cow_image_name = GetCowImageDeviceName(name);
    if (!images_->UnmapImageIfExists(cow_image_name)) {
        LOG(ERROR) << "Cannot unmap image " << cow_image_name;
        return false;
    }
    return true;
}

bool SnapshotManager::UnmapDmUserDevice(const std::string& snapshot_name) {
    auto& dm = DeviceMapper::Instance();

    if (!EnsureSnapuserdConnected()) {
        return false;
    }

    auto dm_user_name = GetDmUserCowName(snapshot_name);
    if (dm.GetState(dm_user_name) == DmDeviceState::INVALID) {
        return true;
    }

    if (!dm.DeleteDeviceIfExists(dm_user_name)) {
        LOG(ERROR) << "Cannot unmap " << dm_user_name;
        return false;
@@ -2084,19 +2113,6 @@ bool SnapshotManager::UnmapCowDevices(LockedFile* lock, const std::string& name)
        LOG(ERROR) << "Timed out waiting for " << control_device << " to unlink";
        return false;
    }
    }

    auto cow_name = GetCowName(name);
    if (!dm.DeleteDeviceIfExists(cow_name)) {
        LOG(ERROR) << "Cannot unmap " << cow_name;
        return false;
    }

    std::string cow_image_name = GetCowImageDeviceName(name);
    if (!images_->UnmapImageIfExists(cow_image_name)) {
        LOG(ERROR) << "Cannot unmap image " << cow_image_name;
        return false;
    }
    return true;
}