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

Commit d2f8d514 authored by David Anderson's avatar David Anderson
Browse files

libsnapshot: Fix unmapping getting skipped for userspace snapshots.

When the dm-user device isn't shut down, COW files cannot be deleted.

Bug: 208944665
Test: vts_libsnapshot_test
Change-Id: I350c8c88c69f9b151032635b0229d281a4bb47ce
parent 266f57d6
Loading
Loading
Loading
Loading
+15 −17
Original line number Diff line number Diff line
@@ -668,10 +668,16 @@ bool SnapshotManager::MapSourceDevice(LockedFile* lock, const std::string& name,
bool SnapshotManager::UnmapSnapshot(LockedFile* lock, const std::string& name) {
    CHECK(lock);

    if (UpdateUsesUserSnapshots(lock)) {
        if (!UnmapUserspaceSnapshotDevice(lock, name)) {
            return false;
        }
    } else {
        if (!DeleteDeviceIfExists(name)) {
            LOG(ERROR) << "Could not delete snapshot device: " << name;
            return false;
        }
    }
    return true;
}

@@ -2429,11 +2435,9 @@ bool SnapshotManager::UnmapPartitionWithSnapshot(LockedFile* lock,
                                                 const std::string& target_partition_name) {
    CHECK(lock);

    if (!UpdateUsesUserSnapshots(lock)) {
    if (!UnmapSnapshot(lock, target_partition_name)) {
        return false;
    }
    }

    if (!UnmapCowDevices(lock, target_partition_name)) {
        return false;
@@ -2530,18 +2534,12 @@ bool SnapshotManager::UnmapCowDevices(LockedFile* lock, const std::string& name)
    CHECK(lock);
    if (!EnsureImageManager()) return false;

    if (UpdateUsesCompression(lock)) {
        if (UpdateUsesUserSnapshots(lock)) {
            if (!UnmapUserspaceSnapshotDevice(lock, name)) {
                return false;
            }
        } else {
    if (UpdateUsesCompression(lock) && !UpdateUsesUserSnapshots(lock)) {
        auto dm_user_name = GetDmUserCowName(name, GetSnapshotDriver(lock));
        if (!UnmapDmUserDevice(dm_user_name)) {
            return false;
        }
    }
    }

    if (!DeleteDeviceIfExists(GetCowName(name), 4000ms)) {
        LOG(ERROR) << "Cannot unmap: " << GetCowName(name);