libsnapshot: Round compressed COW sizes to the nearest block.

This is needed to create and stack device-mapper devices. The kernel
complains (or rejects) the table otherwise.

Bug: N/A
Test: manual test
Change-Id: I2bb3e55b7d999522c4c990b4ab7c46bcb78553a8
This commit is contained in:
David Anderson 2020-11-06 00:46:01 -08:00
parent 56850e12e3
commit 14ae4d1dee
1 changed files with 8 additions and 1 deletions

View File

@ -35,6 +35,8 @@ using RepeatedPtrField = google::protobuf::RepeatedPtrField<T>;
namespace android {
namespace snapshot {
static constexpr uint64_t kBlockSize = 4096;
using namespace android::storage_literals;
// Intersect two linear extents. If no intersection, return an extent with length 0.
@ -149,7 +151,12 @@ uint64_t PartitionCowCreator::GetCowSize() {
// Add an extra 2MB of wiggle room for any minor differences in labels/metadata
// that might come up.
return update->estimate_cow_size() + 2_MiB;
auto size = update->estimate_cow_size() + 2_MiB;
// Align to nearest block.
size += kBlockSize - 1;
size &= ~(kBlockSize - 1);
return size;
}
// WARNING: The origin partition should be READ-ONLY