Skip to content

Commit 2bf0c0e

Browse files
authored
Bump nix to 0.27.1 and use new safer Fd APIs (#1110)
This replaces the Renovate PR (#914) for bumping nix to 0.27.1
1 parent 147ae59 commit 2bf0c0e

File tree

5 files changed

+35
-35
lines changed

5 files changed

+35
-35
lines changed

Cargo.lock

+15-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ itertools = "0.12.1"
5858
libc = "0.2"
5959
mime_guess = "2.0.4"
6060
nbd = "0.2.3"
61-
nix = { version = "0.26", features = [ "feature", "uio" ] }
61+
nix = { version = "0.27", features = [ "feature", "uio" ] }
6262
num_enum = "0.7"
6363
num-derive = "0.4"
6464
num-traits = "0.2"

downstairs/src/extent_inner_raw.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use slog::{error, Logger};
1717
use std::collections::HashSet;
1818
use std::fs::{File, OpenOptions};
1919
use std::io::{BufReader, IoSliceMut, Read};
20-
use std::os::fd::AsRawFd;
20+
use std::os::fd::AsFd;
2121
use std::path::Path;
2222

2323
/// Equivalent to `DownstairsBlockContext`, but without one's own block number
@@ -249,7 +249,7 @@ impl ExtentInner for RawInner {
249249
// bytes. We could do more robust error handling here (e.g.
250250
// retrying in a loop), but for now, simply bailing out seems wise.
251251
let num_bytes = nix::sys::uio::preadv(
252-
self.file.as_raw_fd(),
252+
self.file.as_fd(),
253253
&mut iovecs,
254254
first_req.offset.value as i64 * block_size as i64,
255255
)
@@ -645,7 +645,7 @@ impl RawInner {
645645
let block_size = self.extent_size.block_size_in_bytes();
646646
let mut buf = vec![0; block_size as usize];
647647
pread_all(
648-
self.file.as_raw_fd(),
648+
self.file.as_fd(),
649649
&mut buf,
650650
(block_size as u64 * block) as i64,
651651
)
@@ -837,7 +837,7 @@ impl RawInner {
837837
) -> Result<(), CrucibleError> {
838838
// Now, batch writes into iovecs and use pwritev to write them all out.
839839
let mut batched_pwritev = BatchedPwritev::new(
840-
self.file.as_raw_fd(),
840+
self.file.as_fd(),
841841
writes.len(),
842842
self.extent_size.block_size_in_bytes().into(),
843843
iov_max,
@@ -1207,7 +1207,7 @@ impl RawLayout {
12071207
/// changed.
12081208
fn set_dirty(&self, file: &File) -> Result<(), CrucibleError> {
12091209
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| {
12111211
CrucibleError::IoError(format!("writing dirty byte failed: {e}",))
12121212
})?;
12131213
Ok(())
@@ -1268,7 +1268,7 @@ impl RawLayout {
12681268
fn get_metadata(&self, file: &File) -> Result<OnDiskMeta, CrucibleError> {
12691269
let mut buf = [0u8; BLOCK_META_SIZE_BYTES as usize];
12701270
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| {
12721272
CrucibleError::IoError(format!("reading metadata failed: {e}"))
12731273
})?;
12741274
let out: OnDiskMeta = bincode::deserialize(&buf)
@@ -1298,7 +1298,7 @@ impl RawLayout {
12981298
bincode::serialize_into(&mut buf[n..], &d).unwrap();
12991299
}
13001300
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| {
13021302
CrucibleError::IoError(format!("writing context slots failed: {e}"))
13031303
})?;
13041304
Ok(())
@@ -1315,7 +1315,7 @@ impl RawLayout {
13151315
vec![0u8; (BLOCK_CONTEXT_SLOT_SIZE_BYTES * block_count) as usize];
13161316

13171317
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| {
13191319
CrucibleError::IoError(format!("reading context slots failed: {e}"))
13201320
})?;
13211321

@@ -1376,7 +1376,7 @@ impl RawLayout {
13761376

13771377
let offset = self.active_context_offset();
13781378

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| {
13801380
CrucibleError::IoError(format!("writing metadata failed: {e}"))
13811381
})?;
13821382

@@ -1392,7 +1392,7 @@ impl RawLayout {
13921392
) -> Result<Vec<ContextSlot>, CrucibleError> {
13931393
let mut buf = vec![0u8; self.active_context_size() as usize];
13941394
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| {
13961396
CrucibleError::IoError(format!(
13971397
"could not read active contexts: {e}"
13981398
))
@@ -1428,8 +1428,8 @@ impl RawLayout {
14281428
///
14291429
/// We don't have to worry about most of these conditions, but it may be
14301430
/// 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,
14331433
mut buf: &mut [u8],
14341434
mut offset: i64,
14351435
) -> Result<(), nix::errno::Errno> {
@@ -1444,8 +1444,8 @@ fn pread_all(
14441444
/// Call `pwrite` repeatedly to write an entire buffer
14451445
///
14461446
/// 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,
14491449
mut buf: &[u8],
14501450
mut offset: i64,
14511451
) -> Result<(), nix::errno::Errno> {

downstairs/src/extent_inner_sqlite.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use slog::{error, Logger};
1515
use std::collections::{BTreeMap, HashSet};
1616
use std::fs::{File, OpenOptions};
1717
use std::io::{BufReader, IoSliceMut, Read, Seek, SeekFrom};
18-
use std::os::fd::AsRawFd;
18+
use std::os::fd::AsFd;
1919
use std::path::Path;
2020

2121
#[derive(Debug)]
@@ -217,7 +217,7 @@ impl ExtentInner for SqliteInner {
217217
});
218218

219219
nix::sys::uio::preadv(
220-
self.file.as_raw_fd(),
220+
self.file.as_fd(),
221221
&mut iovecs,
222222
first_req.offset.value as i64 * block_size as i64,
223223
)
@@ -437,7 +437,7 @@ impl ExtentInner for SqliteInner {
437437

438438
// Now, batch writes into iovecs and use pwritev to write them all out.
439439
let mut batched_pwritev = BatchedPwritev::new(
440-
self.file.as_raw_fd(),
440+
self.file.as_fd(),
441441
writes.len(),
442442
self.extent_size.block_size_in_bytes() as u64,
443443
iov_max,

downstairs/src/region.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@ struct BatchedPwritevState<'a> {
10731073
}
10741074

10751075
pub(crate) struct BatchedPwritev<'a> {
1076-
fd: std::os::fd::RawFd,
1076+
fd: std::os::fd::BorrowedFd<'a>,
10771077
capacity: usize,
10781078
state: Option<BatchedPwritevState<'a>>,
10791079
block_size: u64,
@@ -1082,7 +1082,7 @@ pub(crate) struct BatchedPwritev<'a> {
10821082

10831083
impl<'a> BatchedPwritev<'a> {
10841084
pub fn new(
1085-
fd: std::os::fd::RawFd,
1085+
fd: std::os::fd::BorrowedFd<'a>,
10861086
capacity: usize,
10871087
block_size: u64,
10881088
iov_max: usize,

0 commit comments

Comments
 (0)