Skip to content

Commit

Permalink
Merge changes I51628abe,I412d62b7 into rvc-dev
Browse files Browse the repository at this point in the history
* changes:
  Wrap flock with TEMP_FAILURE_RETRY.
  Try locking after mounting metadata


Former-commit-id: 82e0c384f3f3391b73f6bb23ba8605cb5c142599
  • Loading branch information
Yifan Hong authored and Android (Google) Code Review committed Jul 8, 2020
2 parents e4b8d1a + d632833 commit 3e9b9e8
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions fs_mgr/libsnapshot/snapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1846,7 +1846,7 @@ auto SnapshotManager::OpenFile(const std::string& file, int lock_flags)
PLOG(ERROR) << "Open failed: " << file;
return nullptr;
}
if (lock_flags != 0 && flock(fd, lock_flags) < 0) {
if (lock_flags != 0 && TEMP_FAILURE_RETRY(flock(fd, lock_flags)) < 0) {
PLOG(ERROR) << "Acquire flock failed: " << file;
return nullptr;
}
Expand All @@ -1857,7 +1857,7 @@ auto SnapshotManager::OpenFile(const std::string& file, int lock_flags)
}

SnapshotManager::LockedFile::~LockedFile() {
if (flock(fd_, LOCK_UN) < 0) {
if (TEMP_FAILURE_RETRY(flock(fd_, LOCK_UN)) < 0) {
PLOG(ERROR) << "Failed to unlock file: " << path_;
}
}
Expand Down Expand Up @@ -2516,7 +2516,19 @@ std::unique_ptr<AutoDevice> SnapshotManager::EnsureMetadataMounted() {
LOG(INFO) << "EnsureMetadataMounted does nothing in Android mode.";
return std::unique_ptr<AutoUnmountDevice>(new AutoUnmountDevice());
}
return AutoUnmountDevice::New(device_->GetMetadataDir());
auto ret = AutoUnmountDevice::New(device_->GetMetadataDir());
if (ret == nullptr) return nullptr;

// In rescue mode, it is possible to erase and format metadata, but /metadata/ota is not
// created to execute snapshot updates. Hence, subsequent calls is likely to fail because
// Lock*() fails. By failing early and returning nullptr here, update_engine_sideload can
// treat this case as if /metadata is not mounted.
if (!LockShared()) {
LOG(WARNING) << "/metadata is mounted, but errors occur when acquiring a shared lock. "
"Subsequent calls to SnapshotManager will fail. Unmounting /metadata now.";
return nullptr;
}
return ret;
}

bool SnapshotManager::HandleImminentDataWipe(const std::function<void()>& callback) {
Expand Down

0 comments on commit 3e9b9e8

Please sign in to comment.