From d2f8d51444d2f9843b38ebe3d84870aa0fd4f2bb Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sun, 5 Dec 2021 19:36:50 -0800 Subject: [PATCH] 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 --- fs_mgr/libsnapshot/snapshot.cpp | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/fs_mgr/libsnapshot/snapshot.cpp b/fs_mgr/libsnapshot/snapshot.cpp index f4584d282..e6e17bdf3 100644 --- a/fs_mgr/libsnapshot/snapshot.cpp +++ b/fs_mgr/libsnapshot/snapshot.cpp @@ -668,9 +668,15 @@ bool SnapshotManager::MapSourceDevice(LockedFile* lock, const std::string& name, bool SnapshotManager::UnmapSnapshot(LockedFile* lock, const std::string& name) { CHECK(lock); - if (!DeleteDeviceIfExists(name)) { - LOG(ERROR) << "Could not delete snapshot device: " << name; - return false; + 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,10 +2435,8 @@ 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 (!UnmapSnapshot(lock, target_partition_name)) { + return false; } if (!UnmapCowDevices(lock, target_partition_name)) { @@ -2530,16 +2534,10 @@ 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 { - auto dm_user_name = GetDmUserCowName(name, GetSnapshotDriver(lock)); - if (!UnmapDmUserDevice(dm_user_name)) { - return false; - } + if (UpdateUsesCompression(lock) && !UpdateUsesUserSnapshots(lock)) { + auto dm_user_name = GetDmUserCowName(name, GetSnapshotDriver(lock)); + if (!UnmapDmUserDevice(dm_user_name)) { + return false; } }