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

Method scatter_read_sync

block/src/qcow_async.rs:390–474  ·  view source on GitHub ↗

Scatter-read cluster mappings synchronously into iovec buffers.

(
        mappings: Vec<ClusterReadMapping>,
        iovecs: &[libc::iovec],
        data_file: &QcowRawFile,
        backing_file: &Option<Arc<dyn BackingRead>>,
        alignment: usize,
        clu

Source from the content-addressed store, hash-verified

388
389 /// Scatter-read cluster mappings synchronously into iovec buffers.
390 fn scatter_read_sync(
391 mappings: Vec<ClusterReadMapping>,
392 iovecs: &[libc::iovec],
393 data_file: &QcowRawFile,
394 backing_file: &Option<Arc<dyn BackingRead>>,
395 alignment: usize,
396 cluster_size: u64,
397 decoder: &dyn Decoder,
398 ) -> AsyncIoResult<()> {
399 let mut buf_offset = 0usize;
400 for mapping in mappings {
401 match mapping {
402 ClusterReadMapping::Zero { length } => {
403 // SAFETY: iovecs point to valid guest memory buffers.
404 unsafe {
405 zero_fill_iovecs(iovecs, buf_offset, length as usize);
406 }
407 buf_offset += length as usize;
408 }
409 ClusterReadMapping::Allocated {
410 offset: host_offset,
411 length,
412 } => {
413 let len = length as usize;
414 if alignment > 0 {
415 let mut abuf =
416 AlignedBuf::new(len, alignment).map_err(AsyncIoError::ReadVectored)?;
417 aligned_pread(
418 data_file.as_raw_fd(),
419 abuf.as_mut_slice(len),
420 host_offset,
421 alignment,
422 )
423 .map_err(AsyncIoError::ReadVectored)?;
424 // SAFETY: iovecs point to valid guest memory buffers.
425 unsafe { scatter_to_iovecs(iovecs, buf_offset, abuf.as_slice(len)) };
426 } else {
427 let mut buf = vec![0u8; len];
428 pread_exact(data_file.as_raw_fd(), &mut buf, host_offset)
429 .map_err(AsyncIoError::ReadVectored)?;
430 // SAFETY: iovecs point to valid guest memory buffers.
431 unsafe { scatter_to_iovecs(iovecs, buf_offset, &buf) };
432 }
433 buf_offset += len;
434 }
435 ClusterReadMapping::Compressed {
436 host_offset,
437 compressed_size,
438 cluster_offset,
439 length,
440 } => {
441 let compressed =
442 pread_alloc(data_file.as_raw_fd(), host_offset, compressed_size)
443 .map_err(AsyncIoError::ReadVectored)?;
444 let decompressed =
445 decompress_cluster(&compressed, cluster_size as usize, decoder)
446 .map_err(AsyncIoError::ReadVectored)?;
447 // SAFETY: iovecs point to valid guest memory buffers.

Callers

nothing calls this directly

Calls 11

zero_fill_iovecsFunction · 0.85
newFunction · 0.85
aligned_preadFunction · 0.85
scatter_to_iovecsFunction · 0.85
pread_exactFunction · 0.85
pread_allocFunction · 0.85
decompress_clusterFunction · 0.85
as_mut_sliceMethod · 0.80
as_sliceMethod · 0.80
as_raw_fdMethod · 0.45
read_atMethod · 0.45

Tested by

no test coverage detected