Merge "libsnapshot: Add a compression bit to SnapshotStatus."

This commit is contained in:
David Anderson 2020-11-19 20:50:52 +00:00 committed by Gerrit Code Review
commit 3bb971dcc3
2 changed files with 17 additions and 5 deletions

View file

@ -34,7 +34,7 @@ enum SnapshotState {
MERGE_COMPLETED = 3;
}
// Next: 9
// Next: 10
message SnapshotStatus {
// Name of the snapshot. This is usually the name of the snapshotted
// logical partition; for example, "system_b".
@ -84,6 +84,9 @@ message SnapshotStatus {
// the merge process.
// This is non-zero when |state| == MERGING or MERGE_COMPLETED.
uint64 metadata_sectors = 8;
// True if compression is enabled, false otherwise.
bool compression_enabled = 9;
}
// Next: 8

View file

@ -280,7 +280,7 @@ bool SnapshotManager::FinishedSnapshotWrites(bool wipe) {
return false;
}
if (!IsCompressionEnabled() && !EnsureNoOverflowSnapshot(lock.get())) {
if (!EnsureNoOverflowSnapshot(lock.get())) {
LOG(ERROR) << "Cannot ensure there are no overflow snapshots.";
return false;
}
@ -349,6 +349,7 @@ bool SnapshotManager::CreateSnapshot(LockedFile* lock, SnapshotStatus* status) {
status->set_state(SnapshotState::CREATED);
status->set_sectors_allocated(0);
status->set_metadata_sectors(0);
status->set_compression_enabled(IsCompressionEnabled());
if (!WriteSnapshotStatus(lock, *status)) {
PLOG(ERROR) << "Could not write snapshot status: " << status->name();
@ -1914,13 +1915,13 @@ bool SnapshotManager::MapPartitionWithSnapshot(LockedFile* lock,
remaining_time = GetRemainingTime(params.timeout_ms, begin);
if (remaining_time.count() < 0) return false;
if (context == SnapshotContext::Update && IsCompressionEnabled()) {
if (context == SnapshotContext::Update && live_snapshot_status->compression_enabled()) {
// Stop here, we can't run dm-user yet, the COW isn't built.
created_devices.Release();
return true;
}
if (IsCompressionEnabled()) {
if (live_snapshot_status->compression_enabled()) {
auto name = GetDmUserCowName(params.GetPartitionName());
// :TODO: need to force init to process uevents for these in first-stage.
@ -2750,7 +2751,7 @@ Return SnapshotManager::InitializeUpdateSnapshots(
return Return::Error();
}
if (IsCompressionEnabled()) {
if (it->second.compression_enabled()) {
unique_fd fd(open(cow_path.c_str(), O_RDWR | O_CLOEXEC));
if (fd < 0) {
PLOG(ERROR) << "open " << cow_path << " failed for snapshot "
@ -3169,6 +3170,14 @@ bool SnapshotManager::EnsureNoOverflowSnapshot(LockedFile* lock) {
auto& dm = DeviceMapper::Instance();
for (const auto& snapshot : snapshots) {
SnapshotStatus status;
if (!ReadSnapshotStatus(lock, snapshot, &status)) {
return false;
}
if (status.compression_enabled()) {
continue;
}
std::vector<DeviceMapper::TargetInfo> targets;
if (!dm.GetTableStatus(snapshot, &targets)) {
LOG(ERROR) << "Could not read snapshot device table: " << snapshot;