OSDN Git Service

Increase asec image size for reflecting ext4 reserved clusters
authorDaniel Rosenberg <drosen@google.com>
Wed, 11 Jun 2014 00:16:03 +0000 (17:16 -0700)
committerDaniel Rosenberg <drosen@google.com>
Wed, 11 Jun 2014 00:50:53 +0000 (00:50 +0000)
From Shawn Heo's patch:

Ext4 introduced reserved clusters to prevent costly zeroout, or
unexpected ENOSPC. The size is 2% or 4096 clusters, whichever
is smaller (http://lwn.net/Articles/546473/).

So, we need to allocate additionally this amount of free space
to asecs when vold create asec images. This is required when
Android runs on Linux kernel 3.10 or later.

see: https://android-review.git.corp.google.com/#/c/96160

Change-Id: Iacff16b8cf0314493c355fa741bcfa519f744d6c
Signed-off-by: Daniel Rosenberg <drosen@google.com>
VolumeManager.cpp

index 796cb11..3a2b559 100644 (file)
@@ -82,6 +82,12 @@ static int writeSuperBlock(const char* name, struct asec_superblock *sb, unsigne
 }
 
 static int adjustSectorNumExt4(unsigned numSectors) {
+    // Ext4 started to reserve 2% or 4096 clusters, whichever is smaller for
+    // preventing costly operations or unexpected ENOSPC error.
+    // Ext4::format() uses default block size without clustering.
+    unsigned clusterSectors = 4096 / 512;
+    unsigned reservedSectors = (numSectors * 2)/100 + (numSectors % 50 > 0);
+    numSectors += reservedSectors > (4096 * clusterSectors) ? (4096 * clusterSectors) : reservedSectors;
     return ROUND_UP_POWER_OF_2(numSectors, 3);
 }