Skip to content

Commit 14ae4d1

Browse files
committed
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
1 parent 56850e1 commit 14ae4d1

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

fs_mgr/libsnapshot/partition_cow_creator.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ using RepeatedPtrField = google::protobuf::RepeatedPtrField<T>;
3535
namespace android {
3636
namespace snapshot {
3737

38+
static constexpr uint64_t kBlockSize = 4096;
39+
3840
using namespace android::storage_literals;
3941

4042
// Intersect two linear extents. If no intersection, return an extent with length 0.
@@ -149,7 +151,12 @@ uint64_t PartitionCowCreator::GetCowSize() {
149151

150152
// Add an extra 2MB of wiggle room for any minor differences in labels/metadata
151153
// that might come up.
152-
return update->estimate_cow_size() + 2_MiB;
154+
auto size = update->estimate_cow_size() + 2_MiB;
155+
156+
// Align to nearest block.
157+
size += kBlockSize - 1;
158+
size &= ~(kBlockSize - 1);
159+
return size;
153160
}
154161

155162
// WARNING: The origin partition should be READ-ONLY

0 commit comments

Comments
 (0)