1717//! request via [`StdIoBackend::execute`](struct.StdIoBackend.html#method.execute) method.
1818//! The `StdIoBackend` is wrapping the block device backend and keeps the number of sectors of the
1919//! backing file and its negotiated features too. This backend has to be, at least for now,
20- //! `io::Read ` and `io::Write`. In the future, we might add some abstraction for the file access
21- //! operations.
20+ //! `vm_memory::ReadVolatile ` and `vm_memory::WriteVolatile`.
21+ //! In the future, we might add some abstraction for the file access operations.
2222//!
2323//! For more complex executors, that need asynchronous dispatch of requests for example, we can
2424//! add separate modules for those abstractions as well.
2525
2626use std:: fmt:: { self , Display } ;
27- use std:: io:: { Read , Seek , SeekFrom , Write } ;
27+ use std:: io:: { Seek , SeekFrom } ;
2828use std:: { io, mem, result} ;
2929
3030use log:: { error, warn} ;
3131
32- use vm_memory:: { Address , ByteValued , Bytes , GuestMemory , GuestMemoryError } ;
32+ use vm_memory:: {
33+ Address , ByteValued , Bytes , GuestMemory , GuestMemoryError , ReadVolatile , WriteVolatile ,
34+ } ;
3335use vmm_sys_util:: file_traits:: FileSync ;
3436use vmm_sys_util:: write_zeroes:: { PunchHole , WriteZeroesAt } ;
3537
@@ -43,9 +45,12 @@ use virtio_bindings::bindings::virtio_blk::{
4345
4446/// Trait that keeps as supertraits the ones that are necessary for the `StdIoBackend` abstraction
4547/// used for the virtio block request execution.
46- pub trait Backend : Read + Write + Seek + FileSync + PunchHole + WriteZeroesAt { }
48+ pub trait Backend :
49+ ReadVolatile + WriteVolatile + Seek + FileSync + PunchHole + WriteZeroesAt
50+ {
51+ }
4752
48- impl < B : Read + Write + Seek + FileSync + PunchHole + WriteZeroesAt > Backend for B { }
53+ impl < B : ReadVolatile + WriteVolatile + Seek + FileSync + PunchHole + WriteZeroesAt > Backend for B { }
4954
5055/// One or more `DiscardWriteZeroes` structs are used to describe the data for
5156/// discard or write zeroes command.
@@ -326,7 +331,7 @@ impl<B: Backend> StdIoBackend<B> {
326331 return Err ( Error :: InvalidDataLength ) ;
327332 }
328333 for ( data_addr, data_len) in request. data ( ) {
329- mem. read_exact_from ( * data_addr, & mut self . inner , * data_len as usize )
334+ mem. read_exact_volatile_from ( * data_addr, & mut self . inner , * data_len as usize )
330335 . map_err ( |e| {
331336 if let GuestMemoryError :: PartialBuffer {
332337 completed,
@@ -347,7 +352,7 @@ impl<B: Backend> StdIoBackend<B> {
347352 RequestType :: Out => {
348353 self . check_access ( total_len / SECTOR_SIZE , request. sector ( ) ) ?;
349354 for ( data_addr, data_len) in request. data ( ) {
350- mem. write_all_to ( * data_addr, & mut self . inner , * data_len as usize )
355+ mem. write_all_volatile_to ( * data_addr, & mut self . inner , * data_len as usize )
351356 . map_err ( Error :: Write ) ?;
352357 }
353358 }
@@ -364,7 +369,7 @@ impl<B: Backend> StdIoBackend<B> {
364369 for ( data_addr, data_len) in request. data ( ) {
365370 // The device_id accesses are safe because we checked that the total data length
366371 // is VIRTIO_BLK_ID_BYTES, which is the size of the id as well.
367- mem. read_exact_from (
372+ mem. read_exact_volatile_from (
368373 * data_addr,
369374 & mut & device_id[ bytes_to_mem as usize ..( * data_len + bytes_to_mem) as usize ] ,
370375 * data_len as usize ,
@@ -475,6 +480,8 @@ impl<B: Backend> StdIoBackend<B> {
475480mod tests {
476481 use super :: * ;
477482
483+ use std:: io:: { Read , Write } ;
484+
478485 use vm_memory:: guest_memory:: Error :: { InvalidGuestAddress , PartialBuffer } ;
479486 use vm_memory:: { GuestAddress , GuestMemoryMmap } ;
480487 use vmm_sys_util:: tempfile:: TempFile ;
0 commit comments