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

Method resize

block/src/raw_disk.rs:88–113  ·  view source on GitHub ↗
(&mut self, size: u64)

Source from the content-addressed store, hash-verified

86
87impl disk_file::Resizable for RawDisk {
88 fn resize(&mut self, size: u64) -> BlockResult<()> {
89 let fd_metadata = self
90 .file
91 .metadata()
92 .map_err(|e| BlockError::new(BlockErrorKind::Io, DiskFileError::ResizeError(e)))?;
93
94 if fd_metadata.file_type().is_block_device() {
95 // Block devices cannot be resized via ftruncate; they are resized
96 // externally (LVM, losetup, etc.). Verify the size matches.
97 let (actual_size, _) = query_device_size(&self.file)
98 .map_err(|e| BlockError::new(BlockErrorKind::Io, DiskFileError::ResizeError(e)))?;
99 if actual_size != size {
100 return Err(BlockError::new(
101 BlockErrorKind::Io,
102 DiskFileError::ResizeError(io::Error::other(format!(
103 "Block device size {actual_size} does not match requested size {size}"
104 ))),
105 ));
106 }
107 Ok(())
108 } else {
109 self.file
110 .set_len(size)
111 .map_err(|e| BlockError::new(BlockErrorKind::Io, DiskFileError::ResizeError(e)))
112 }
113 }
114}
115
116impl disk_file::DiskFile for RawDisk {}

Callers 1

resize_changes_file_sizeFunction · 0.45

Calls 5

newFunction · 0.85
query_device_sizeFunction · 0.85
metadataMethod · 0.80
is_block_deviceMethod · 0.80
set_lenMethod · 0.45

Tested by 1

resize_changes_file_sizeFunction · 0.36