From a0a5718b420c73ca233802aa1b775178509eca5b Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Thu, 12 Mar 2026 20:24:11 +0100 Subject: [PATCH] block: disk_file: Add SparseCapable trait Sparse and zero flag support for thin provisioned disk images. Two methods with false defaults: sparse operations (punch hole, write zeroes, discard) and zero flag optimization in WRITE_ZEROES. Signed-off-by: Anatol Belski --- block/src/disk_file.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/block/src/disk_file.rs b/block/src/disk_file.rs index 9dd52be6d..3b3aa0fec 100644 --- a/block/src/disk_file.rs +++ b/block/src/disk_file.rs @@ -65,3 +65,19 @@ pub trait Geometry: Send + Debug { DiskTopology::default() } } + +/// Sparse and zero flag support for thin provisioned disk images. +pub trait SparseCapable: Send + Debug { + /// Indicates support for sparse operations (punch hole, write zeroes, discard). + fn supports_sparse_operations(&self) -> bool { + false + } + + /// Indicates support for a metadata level zero flag optimization in + /// virtio `VIRTIO_BLK_T_WRITE_ZEROES` requests. When true, the format + /// can mark regions as reading zeros via a metadata bit rather than + /// writing actual zero bytes to disk. + fn supports_zero_flag(&self) -> bool { + false + } +}