MCPcopy Create free account
hub / github.com/cloud-hypervisor/cloud-hypervisor / lock_granularity

Method lock_granularity

virtio-devices/src/block.rs:901–927  ·  view source on GitHub ↗

Returns the granularity for the advisory lock for this disk.

(&mut self)

Source from the content-addressed store, hash-verified

899
900 /// Returns the granularity for the advisory lock for this disk.
901 fn lock_granularity(&mut self) -> LockGranularity {
902 match self.lock_granularity_choice {
903 LockGranularityChoice::Full => LockGranularity::WholeFile,
904 LockGranularityChoice::ByteRange => {
905 // Byte range lock covering [0, max(logical, physical))
906 // logical > physical for sparse files, physical > logical
907 // for small dense files due to filesystem block rounding.
908 let logical = self.disk_image.logical_size();
909 let physical = self.disk_image.physical_size();
910 match (logical, physical) {
911 (Ok(l), Ok(p)) => LockGranularity::ByteRange(0, max(l, p)),
912 (Ok(l), Err(_)) => LockGranularity::ByteRange(0, l),
913 (Err(_), Ok(p)) => LockGranularity::ByteRange(0, p),
914 (Err(e), Err(_)) => {
915 let fallback = LockGranularity::WholeFile;
916 warn!(
917 "Can't get disk size for id={},path={}, falling back to {:?}: error: {e}",
918 self.id,
919 self.disk_path.display(),
920 fallback
921 );
922 fallback
923 }
924 }
925 }
926 }
927 }
928
929 /// Tries to set an advisory lock for the corresponding disk image.
930 pub fn try_lock_image(&mut self) -> Result<()> {

Callers 2

try_lock_imageMethod · 0.80
unlock_imageMethod · 0.80

Calls 2

logical_sizeMethod · 0.45
physical_sizeMethod · 0.45

Tested by

no test coverage detected