mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
block: Add supports_zero_flag trait method
Add supports_zero_flag() to DiskFile trait to indicate whether a disk format can mark clusters/blocks as reading zeros without deallocating storage. QCOW2 supports this via the zero flag in L2 entries. VHDX also has PAYLOAD_BLOCK_ZERO state for this, though it's not yet implemented in cloud-hypervisor. This enables DISCARD to be advertised even with sparse=false for formats with zero-flag support, since they can mark regions as zeros (keeps storage allocated) instead of requiring full deallocation. Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
committed by
Rob Bradford
parent
7dfcbff309
commit
46e6ecddfe
@@ -84,6 +84,12 @@ pub trait DiskFile: Send {
|
||||
false
|
||||
}
|
||||
|
||||
/// Indicates support for zero flag optimization in WRITE_ZEROES. Override
|
||||
/// to return true when supported.
|
||||
fn supports_zero_flag(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
/// Returns the file descriptor of the underlying disk image file.
|
||||
///
|
||||
/// The file descriptor is supposed to be used for `fcntl()` calls but no
|
||||
|
||||
@@ -80,6 +80,10 @@ impl DiskFile for QcowDiskSync {
|
||||
true
|
||||
}
|
||||
|
||||
fn supports_zero_flag(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn fd(&mut self) -> BorrowedDiskFd<'_> {
|
||||
BorrowedDiskFd::new(self.qcow_file.lock().unwrap().as_raw_fd())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user