Encryptedstore: allow discard for freed sectors
Allow discard from both the mounted ext4 filesystem & the devicemapper
target. This allows discard commands to be forwarded to underlying
virtio-blk device resulting in punching holes in the backing sparse disk
img. This is how recompaction is achieved when encryptedstore usage
decreases.
Test: Start udroid VM &&
Find the underlying block device (ls -l/dev/block/mapper/cryptdev) &&
ensure /sys/block/dm-3/queue/discard_max_byte > 0 (2199023255040)
Test: Fill up the encryptedstore & then empty it, observe the size of
backing img. Ensure it decreases.
Bug: 391340596
Change-Id: I17e278fac82c07ec41fa55ee0b65924b9ea1ea6f
diff --git a/guest/encryptedstore/src/main.rs b/guest/encryptedstore/src/main.rs
index 983e3e9..dd4ee3b 100644
--- a/guest/encryptedstore/src/main.rs
+++ b/guest/encryptedstore/src/main.rs
@@ -120,6 +120,7 @@
.key(&key)
.opt_param("sector_size:4096")
.opt_param("iv_large_sectors")
+ .opt_param("allow_discards") // This allows re-compaction of underlying disk img in host
.build()
.context("Couldn't build the DMCrypt target")?;
let dm = dm::DeviceMapper::new()?;
@@ -176,7 +177,7 @@
fn mount(source: &Path, mountpoint: &Path) -> Result<()> {
create_dir_all(mountpoint).with_context(|| format!("Failed to create {:?}", &mountpoint))?;
let mount_options = CString::new(
- "fscontext=u:object_r:encryptedstore_fs:s0,context=u:object_r:encryptedstore_file:s0",
+ "fscontext=u:object_r:encryptedstore_fs:s0,context=u:object_r:encryptedstore_file:s0,discard",
)
.unwrap();
let source = CString::new(source.as_os_str().as_bytes())?;