mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
block: qcow: Port internal tests to QcowDisk
Port the internal/mod.rs tests from QcowFile to QcowDisk so the surviving tests exercise the code paths that are hit when used via QcowDisk (and thus virtio-block). Assisted-by: Claude:claude-opus-4-7 Signed-off-by: Rob Bradford <rbradford@meta.com>
This commit is contained in:
@@ -351,6 +351,24 @@ impl QcowMetadata {
|
||||
pub fn decoder(&self) -> Arc<dyn Decoder> {
|
||||
Arc::clone(&self.decoder)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub fn header(&self) -> QcowHeader {
|
||||
self.inner.read().unwrap().header.clone()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub fn cluster_refcount(&self, address: u64) -> io::Result<u64> {
|
||||
let mut inner = self.inner.write().unwrap();
|
||||
let QcowState {
|
||||
refcounts,
|
||||
raw_file,
|
||||
..
|
||||
} = &mut *inner;
|
||||
refcounts
|
||||
.get_cluster_refcount(raw_file, address)
|
||||
.map_err(|e| io::Error::other(format!("get_cluster_refcount: {e}")))
|
||||
}
|
||||
}
|
||||
|
||||
impl QcowState {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -123,6 +123,27 @@ impl QcowDisk {
|
||||
.unwrap();
|
||||
while async_io.next_completed_request().is_some() {}
|
||||
}
|
||||
|
||||
/// Synchronous read convenience for tests and benchmarks.
|
||||
#[cfg(test)]
|
||||
pub fn read_all_at(&self, offset: u64, len: usize) -> Vec<u8> {
|
||||
let mut async_io = self.create_async_io(1).unwrap();
|
||||
let mem = Arc::new(GuestMemoryMmap::<()>::from_ranges(&[(GuestAddress(0), len)]).unwrap());
|
||||
let range = [(GuestAddress(0), len as u32)];
|
||||
let target = GuestMemoryTarget::new(Arc::clone(&mem), &range).unwrap();
|
||||
async_io
|
||||
.read_to_memory(offset as libc::off_t, target, 0)
|
||||
.unwrap();
|
||||
while async_io.next_completed_request().is_some() {}
|
||||
let mut buf = vec![0u8; len];
|
||||
mem.read_slice(&mut buf, GuestAddress(0)).unwrap();
|
||||
buf
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn metadata(&self) -> &QcowMetadata {
|
||||
&self.metadata
|
||||
}
|
||||
}
|
||||
|
||||
/// Writes a fresh qcow2 layout into `file`
|
||||
|
||||
Reference in New Issue
Block a user