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

Commit caaf9a61 authored by Yifan Hong's avatar Yifan Hong
Browse files

libsnapshot: require ex lock for {Create}{CowImage,Snapshot} / DeleteSnapshot

Create / Deleting the COW image / snapshot changes states, so it makes
sense to require an exclusive lock before doing so. If caller doesn't hold
an exclusive lock, parallel calls to MapCowImage / MapSnapshot / UnmapCowImage /
UnmapSnapshot may have weird results.

Test: libsnapshot_test

Change-Id: I4be660df1059ec24144f8baf43a1c8c05d9e372b
parent 27fb95de
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -183,6 +183,7 @@ bool SnapshotManager::FinishedSnapshotWrites() {
bool SnapshotManager::CreateSnapshot(LockedFile* lock, const std::string& name,
                                     SnapshotManager::SnapshotStatus status) {
    CHECK(lock);
    CHECK(lock->lock_mode() == LOCK_EX);
    // Sanity check these sizes. Like liblp, we guarantee the partition size
    // is respected, which means it has to be sector-aligned. (This guarantee
    // is useful for locating avb footers correctly). The COW size, however,
@@ -215,6 +216,7 @@ bool SnapshotManager::CreateSnapshot(LockedFile* lock, const std::string& name,

bool SnapshotManager::CreateCowImage(LockedFile* lock, const std::string& name) {
    CHECK(lock);
    CHECK(lock->lock_mode() == LOCK_EX);
    if (!EnsureImageManager()) return false;

    SnapshotStatus status;
@@ -415,6 +417,7 @@ bool SnapshotManager::UnmapCowImage(const std::string& name) {

bool SnapshotManager::DeleteSnapshot(LockedFile* lock, const std::string& name) {
    CHECK(lock);
    CHECK(lock->lock_mode() == LOCK_EX);
    if (!EnsureImageManager()) return false;

    auto cow_image_name = GetCowImageDeviceName(name);