From abbe0c8cf0e5c418d46f0c6c4cabbd02b6702bd0 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Thu, 27 Sep 2018 13:47:31 -0700 Subject: sys_util: use PUNCH_HOLE to implement write_zeroes Some filesystems do not support FALLOC_FL_ZERO_RANGE; in particular, encrypted files on ext4 fail this request with -EOPNOTSUPP. Use fallocate with FALLOC_FL_PUNCH_HOLE instead, which is more widely supported. BUG=None TEST=strace crosvm using qcow files on encrypted ext4 and verify that fallocate(FALLOC_FL_PUNCH_HOLE) is issued when required. Change-Id: Idffabc75ea0e1153efbb13cec8b4a25570427235 Signed-off-by: Daniel Verkamp Reviewed-on: https://chromium-review.googlesource.com/1250022 Reviewed-by: Stephen Barber Reviewed-by: Dylan Reid --- sys_util/src/write_zeroes.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sys_util') diff --git a/sys_util/src/write_zeroes.rs b/sys_util/src/write_zeroes.rs index 31ea652..15e9344 100644 --- a/sys_util/src/write_zeroes.rs +++ b/sys_util/src/write_zeroes.rs @@ -17,9 +17,9 @@ pub trait WriteZeroes { impl WriteZeroes for File { fn write_zeroes(&mut self, length: usize) -> io::Result { - // Try to use fallocate(FALLOC_FL_ZERO_RANGE) first. + // Try to use fallocate(FALLOC_FL_PUNCH_HOLE) first. let offset = self.seek(SeekFrom::Current(0))?; - match fallocate(self, FallocateMode::ZeroRange, false, offset, length as u64) { + match fallocate(self, FallocateMode::PunchHole, true, offset, length as u64) { Ok(()) => { // Advance the seek cursor as if we had done a real write(). self.seek(SeekFrom::Current(length as i64))?; -- cgit 1.4.1