@@ -17,7 +17,7 @@ use slog::{error, Logger};
17
17
use std:: collections:: HashSet ;
18
18
use std:: fs:: { File , OpenOptions } ;
19
19
use std:: io:: { BufReader , IoSliceMut , Read } ;
20
- use std:: os:: fd:: AsRawFd ;
20
+ use std:: os:: fd:: AsFd ;
21
21
use std:: path:: Path ;
22
22
23
23
/// Equivalent to `DownstairsBlockContext`, but without one's own block number
@@ -249,7 +249,7 @@ impl ExtentInner for RawInner {
249
249
// bytes. We could do more robust error handling here (e.g.
250
250
// retrying in a loop), but for now, simply bailing out seems wise.
251
251
let num_bytes = nix:: sys:: uio:: preadv (
252
- self . file . as_raw_fd ( ) ,
252
+ self . file . as_fd ( ) ,
253
253
& mut iovecs,
254
254
first_req. offset . value as i64 * block_size as i64 ,
255
255
)
@@ -645,7 +645,7 @@ impl RawInner {
645
645
let block_size = self . extent_size . block_size_in_bytes ( ) ;
646
646
let mut buf = vec ! [ 0 ; block_size as usize ] ;
647
647
pread_all (
648
- self . file . as_raw_fd ( ) ,
648
+ self . file . as_fd ( ) ,
649
649
& mut buf,
650
650
( block_size as u64 * block) as i64 ,
651
651
)
@@ -837,7 +837,7 @@ impl RawInner {
837
837
) -> Result < ( ) , CrucibleError > {
838
838
// Now, batch writes into iovecs and use pwritev to write them all out.
839
839
let mut batched_pwritev = BatchedPwritev :: new (
840
- self . file . as_raw_fd ( ) ,
840
+ self . file . as_fd ( ) ,
841
841
writes. len ( ) ,
842
842
self . extent_size . block_size_in_bytes ( ) . into ( ) ,
843
843
iov_max,
@@ -1207,7 +1207,7 @@ impl RawLayout {
1207
1207
/// changed.
1208
1208
fn set_dirty ( & self , file : & File ) -> Result < ( ) , CrucibleError > {
1209
1209
let offset = self . metadata_offset ( ) ;
1210
- pwrite_all ( file. as_raw_fd ( ) , & [ 1u8 ] , offset as i64 ) . map_err ( |e| {
1210
+ pwrite_all ( file. as_fd ( ) , & [ 1u8 ] , offset as i64 ) . map_err ( |e| {
1211
1211
CrucibleError :: IoError ( format ! ( "writing dirty byte failed: {e}" , ) )
1212
1212
} ) ?;
1213
1213
Ok ( ( ) )
@@ -1268,7 +1268,7 @@ impl RawLayout {
1268
1268
fn get_metadata ( & self , file : & File ) -> Result < OnDiskMeta , CrucibleError > {
1269
1269
let mut buf = [ 0u8 ; BLOCK_META_SIZE_BYTES as usize ] ;
1270
1270
let offset = self . metadata_offset ( ) ;
1271
- pread_all ( file. as_raw_fd ( ) , & mut buf, offset as i64 ) . map_err ( |e| {
1271
+ pread_all ( file. as_fd ( ) , & mut buf, offset as i64 ) . map_err ( |e| {
1272
1272
CrucibleError :: IoError ( format ! ( "reading metadata failed: {e}" ) )
1273
1273
} ) ?;
1274
1274
let out: OnDiskMeta = bincode:: deserialize ( & buf)
@@ -1298,7 +1298,7 @@ impl RawLayout {
1298
1298
bincode:: serialize_into ( & mut buf[ n..] , & d) . unwrap ( ) ;
1299
1299
}
1300
1300
let offset = self . context_slot_offset ( block_start, slot) ;
1301
- pwrite_all ( file. as_raw_fd ( ) , & buf, offset as i64 ) . map_err ( |e| {
1301
+ pwrite_all ( file. as_fd ( ) , & buf, offset as i64 ) . map_err ( |e| {
1302
1302
CrucibleError :: IoError ( format ! ( "writing context slots failed: {e}" ) )
1303
1303
} ) ?;
1304
1304
Ok ( ( ) )
@@ -1315,7 +1315,7 @@ impl RawLayout {
1315
1315
vec ! [ 0u8 ; ( BLOCK_CONTEXT_SLOT_SIZE_BYTES * block_count) as usize ] ;
1316
1316
1317
1317
let offset = self . context_slot_offset ( block_start, slot) ;
1318
- pread_all ( file. as_raw_fd ( ) , & mut buf, offset as i64 ) . map_err ( |e| {
1318
+ pread_all ( file. as_fd ( ) , & mut buf, offset as i64 ) . map_err ( |e| {
1319
1319
CrucibleError :: IoError ( format ! ( "reading context slots failed: {e}" ) )
1320
1320
} ) ?;
1321
1321
@@ -1376,7 +1376,7 @@ impl RawLayout {
1376
1376
1377
1377
let offset = self . active_context_offset ( ) ;
1378
1378
1379
- pwrite_all ( file. as_raw_fd ( ) , & buf, offset as i64 ) . map_err ( |e| {
1379
+ pwrite_all ( file. as_fd ( ) , & buf, offset as i64 ) . map_err ( |e| {
1380
1380
CrucibleError :: IoError ( format ! ( "writing metadata failed: {e}" ) )
1381
1381
} ) ?;
1382
1382
@@ -1392,7 +1392,7 @@ impl RawLayout {
1392
1392
) -> Result < Vec < ContextSlot > , CrucibleError > {
1393
1393
let mut buf = vec ! [ 0u8 ; self . active_context_size( ) as usize ] ;
1394
1394
let offset = self . active_context_offset ( ) ;
1395
- pread_all ( file. as_raw_fd ( ) , & mut buf, offset as i64 ) . map_err ( |e| {
1395
+ pread_all ( file. as_fd ( ) , & mut buf, offset as i64 ) . map_err ( |e| {
1396
1396
CrucibleError :: IoError ( format ! (
1397
1397
"could not read active contexts: {e}"
1398
1398
) )
@@ -1428,8 +1428,8 @@ impl RawLayout {
1428
1428
///
1429
1429
/// We don't have to worry about most of these conditions, but it may be
1430
1430
/// possible for Crucible to be interrupted by a signal, so let's play it safe.
1431
- fn pread_all (
1432
- fd : std :: os :: fd :: RawFd ,
1431
+ fn pread_all < F : AsFd + Copy > (
1432
+ fd : F ,
1433
1433
mut buf : & mut [ u8 ] ,
1434
1434
mut offset : i64 ,
1435
1435
) -> Result < ( ) , nix:: errno:: Errno > {
@@ -1444,8 +1444,8 @@ fn pread_all(
1444
1444
/// Call `pwrite` repeatedly to write an entire buffer
1445
1445
///
1446
1446
/// See details for why this is necessary in [`pread_all`]
1447
- fn pwrite_all (
1448
- fd : std :: os :: fd :: RawFd ,
1447
+ fn pwrite_all < F : AsFd + Copy > (
1448
+ fd : F ,
1449
1449
mut buf : & [ u8 ] ,
1450
1450
mut offset : i64 ,
1451
1451
) -> Result < ( ) , nix:: errno:: Errno > {
0 commit comments