88use std:: fs:: File ;
99use std:: io:: { Read , Seek , SeekFrom , Write } ;
1010use std:: mem:: ManuallyDrop ;
11- use std:: os:: fd:: { AsFd , AsRawFd } ;
11+ use std:: os:: fd:: AsRawFd ;
1212use std:: ptr:: null_mut;
1313use std:: sync:: Arc ;
1414
@@ -106,7 +106,7 @@ impl<T, const N: usize> MaybeBounce<T, N> {
106106}
107107
108108// FIXME: replace AsFd with ReadVolatile once &File: ReadVolatile in vm-memory.
109- impl < T : Read + AsFd , const N : usize > ReadVolatile for MaybeBounce < T , N > {
109+ impl < T : ReadVolatile , const N : usize > ReadVolatile for MaybeBounce < T , N > {
110110 fn read_volatile < B : BitmapSlice > (
111111 & mut self ,
112112 buf : & mut VolatileSlice < B > ,
@@ -121,8 +121,7 @@ impl<T: Read + AsFd, const N: usize> ReadVolatile for MaybeBounce<T, N> {
121121 let how_much = buf. len ( ) . min ( bbuf. len ( ) ) ;
122122 let n = self
123123 . target
124- . read ( & mut bbuf[ ..how_much] )
125- . map_err ( VolatileMemoryError :: IOError ) ?;
124+ . read_volatile ( & mut VolatileSlice :: from ( & mut bbuf[ ..how_much] ) ) ?;
126125 buf. copy_from ( & bbuf[ ..n] ) ;
127126
128127 buf = buf. offset ( n) ?;
@@ -135,12 +134,12 @@ impl<T: Read + AsFd, const N: usize> ReadVolatile for MaybeBounce<T, N> {
135134
136135 Ok ( total)
137136 } else {
138- self . target . as_fd ( ) . read_volatile ( buf)
137+ self . target . read_volatile ( buf)
139138 }
140139 }
141140}
142141
143- impl < T : Write + AsFd , const N : usize > WriteVolatile for MaybeBounce < T , N > {
142+ impl < T : WriteVolatile , const N : usize > WriteVolatile for MaybeBounce < T , N > {
144143 fn write_volatile < B : BitmapSlice > (
145144 & mut self ,
146145 buf : & VolatileSlice < B > ,
@@ -155,8 +154,7 @@ impl<T: Write + AsFd, const N: usize> WriteVolatile for MaybeBounce<T, N> {
155154 let how_much = buf. copy_to ( bbuf) ;
156155 let n = self
157156 . target
158- . write ( & bbuf[ ..how_much] )
159- . map_err ( VolatileMemoryError :: IOError ) ?;
157+ . write_volatile ( & VolatileSlice :: from ( & mut bbuf[ ..how_much] ) ) ?;
160158 buf = buf. offset ( n) ?;
161159 total += n;
162160
@@ -167,7 +165,7 @@ impl<T: Write + AsFd, const N: usize> WriteVolatile for MaybeBounce<T, N> {
167165
168166 Ok ( total)
169167 } else {
170- self . target . as_fd ( ) . write_volatile ( buf)
168+ self . target . write_volatile ( buf)
171169 }
172170 }
173171}
@@ -652,6 +650,7 @@ mod tests {
652650
653651 use std:: collections:: HashMap ;
654652 use std:: io:: { Read , Seek } ;
653+ use std:: os:: fd:: AsFd ;
655654
656655 use itertools:: Itertools ;
657656 use vmm_sys_util:: tempfile:: TempFile ;
@@ -1030,13 +1029,13 @@ mod tests {
10301029
10311030 let mut data = ( 0 ..=255 ) . collect_vec ( ) ;
10321031
1033- MaybeBounce :: new ( file_direct. as_file ( ) , false )
1032+ MaybeBounce :: new ( file_direct. as_file ( ) . as_fd ( ) , false )
10341033 . write_all_volatile ( & VolatileSlice :: from ( data. as_mut_slice ( ) ) )
10351034 . unwrap ( ) ;
1036- MaybeBounce :: new ( file_bounced. as_file ( ) , true )
1035+ MaybeBounce :: new ( file_bounced. as_file ( ) . as_fd ( ) , true )
10371036 . write_all_volatile ( & VolatileSlice :: from ( data. as_mut_slice ( ) ) )
10381037 . unwrap ( ) ;
1039- MaybeBounce :: < _ , 7 > :: new_persistent ( file_persistent_bounced. as_file ( ) , true )
1038+ MaybeBounce :: < _ , 7 > :: new_persistent ( file_persistent_bounced. as_file ( ) . as_fd ( ) , true )
10401039 . write_all_volatile ( & VolatileSlice :: from ( data. as_mut_slice ( ) ) )
10411040 . unwrap ( ) ;
10421041
@@ -1051,13 +1050,13 @@ mod tests {
10511050 . seek ( SeekFrom :: Start ( 0 ) )
10521051 . unwrap ( ) ;
10531052
1054- MaybeBounce :: new ( file_direct. as_file ( ) , false )
1053+ MaybeBounce :: new ( file_direct. as_file ( ) . as_fd ( ) , false )
10551054 . read_exact_volatile ( & mut VolatileSlice :: from ( data_direct. as_mut_slice ( ) ) )
10561055 . unwrap ( ) ;
1057- MaybeBounce :: new ( file_bounced. as_file ( ) , true )
1056+ MaybeBounce :: new ( file_bounced. as_file ( ) . as_fd ( ) , true )
10581057 . read_exact_volatile ( & mut VolatileSlice :: from ( data_bounced. as_mut_slice ( ) ) )
10591058 . unwrap ( ) ;
1060- MaybeBounce :: < _ , 7 > :: new_persistent ( file_persistent_bounced. as_file ( ) , true )
1059+ MaybeBounce :: < _ , 7 > :: new_persistent ( file_persistent_bounced. as_file ( ) . as_fd ( ) , true )
10611060 . read_exact_volatile ( & mut VolatileSlice :: from (
10621061 data_persistent_bounced. as_mut_slice ( ) ,
10631062 ) )
0 commit comments