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
diff --git a/fs_mgr/libsnapshot/partition_cow_creator.cpp b/fs_mgr/libsnapshot/partition_cow_creator.cpp
index 0c81146..da6fc9d 100644
--- a/fs_mgr/libsnapshot/partition_cow_creator.cpp
+++ b/fs_mgr/libsnapshot/partition_cow_creator.cpp
@@ -35,6 +35,8 @@
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 @@
// 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