Skip to content

Commit

Permalink
Bump nix to 0.27.1 and use new safer Fd APIs (#1110)
Browse files Browse the repository at this point in the history
This replaces the Renovate PR (#914) for bumping nix to 0.27.1
  • Loading branch information
mkeeter authored Feb 6, 2024
1 parent 147ae59 commit 2bf0c0e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 35 deletions.
30 changes: 15 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ itertools = "0.12.1"
libc = "0.2"
mime_guess = "2.0.4"
nbd = "0.2.3"
nix = { version = "0.26", features = [ "feature", "uio" ] }
nix = { version = "0.27", features = [ "feature", "uio" ] }
num_enum = "0.7"
num-derive = "0.4"
num-traits = "0.2"
Expand Down
28 changes: 14 additions & 14 deletions downstairs/src/extent_inner_raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use slog::{error, Logger};
use std::collections::HashSet;
use std::fs::{File, OpenOptions};
use std::io::{BufReader, IoSliceMut, Read};
use std::os::fd::AsRawFd;
use std::os::fd::AsFd;
use std::path::Path;

/// Equivalent to `DownstairsBlockContext`, but without one's own block number
Expand Down Expand Up @@ -249,7 +249,7 @@ impl ExtentInner for RawInner {
// bytes. We could do more robust error handling here (e.g.
// retrying in a loop), but for now, simply bailing out seems wise.
let num_bytes = nix::sys::uio::preadv(
self.file.as_raw_fd(),
self.file.as_fd(),
&mut iovecs,
first_req.offset.value as i64 * block_size as i64,
)
Expand Down Expand Up @@ -645,7 +645,7 @@ impl RawInner {
let block_size = self.extent_size.block_size_in_bytes();
let mut buf = vec![0; block_size as usize];
pread_all(
self.file.as_raw_fd(),
self.file.as_fd(),
&mut buf,
(block_size as u64 * block) as i64,
)
Expand Down Expand Up @@ -837,7 +837,7 @@ impl RawInner {
) -> Result<(), CrucibleError> {
// Now, batch writes into iovecs and use pwritev to write them all out.
let mut batched_pwritev = BatchedPwritev::new(
self.file.as_raw_fd(),
self.file.as_fd(),
writes.len(),
self.extent_size.block_size_in_bytes().into(),
iov_max,
Expand Down Expand Up @@ -1207,7 +1207,7 @@ impl RawLayout {
/// changed.
fn set_dirty(&self, file: &File) -> Result<(), CrucibleError> {
let offset = self.metadata_offset();
pwrite_all(file.as_raw_fd(), &[1u8], offset as i64).map_err(|e| {
pwrite_all(file.as_fd(), &[1u8], offset as i64).map_err(|e| {
CrucibleError::IoError(format!("writing dirty byte failed: {e}",))
})?;
Ok(())
Expand Down Expand Up @@ -1268,7 +1268,7 @@ impl RawLayout {
fn get_metadata(&self, file: &File) -> Result<OnDiskMeta, CrucibleError> {
let mut buf = [0u8; BLOCK_META_SIZE_BYTES as usize];
let offset = self.metadata_offset();
pread_all(file.as_raw_fd(), &mut buf, offset as i64).map_err(|e| {
pread_all(file.as_fd(), &mut buf, offset as i64).map_err(|e| {
CrucibleError::IoError(format!("reading metadata failed: {e}"))
})?;
let out: OnDiskMeta = bincode::deserialize(&buf)
Expand Down Expand Up @@ -1298,7 +1298,7 @@ impl RawLayout {
bincode::serialize_into(&mut buf[n..], &d).unwrap();
}
let offset = self.context_slot_offset(block_start, slot);
pwrite_all(file.as_raw_fd(), &buf, offset as i64).map_err(|e| {
pwrite_all(file.as_fd(), &buf, offset as i64).map_err(|e| {
CrucibleError::IoError(format!("writing context slots failed: {e}"))
})?;
Ok(())
Expand All @@ -1315,7 +1315,7 @@ impl RawLayout {
vec![0u8; (BLOCK_CONTEXT_SLOT_SIZE_BYTES * block_count) as usize];

let offset = self.context_slot_offset(block_start, slot);
pread_all(file.as_raw_fd(), &mut buf, offset as i64).map_err(|e| {
pread_all(file.as_fd(), &mut buf, offset as i64).map_err(|e| {
CrucibleError::IoError(format!("reading context slots failed: {e}"))
})?;

Expand Down Expand Up @@ -1376,7 +1376,7 @@ impl RawLayout {

let offset = self.active_context_offset();

pwrite_all(file.as_raw_fd(), &buf, offset as i64).map_err(|e| {
pwrite_all(file.as_fd(), &buf, offset as i64).map_err(|e| {
CrucibleError::IoError(format!("writing metadata failed: {e}"))
})?;

Expand All @@ -1392,7 +1392,7 @@ impl RawLayout {
) -> Result<Vec<ContextSlot>, CrucibleError> {
let mut buf = vec![0u8; self.active_context_size() as usize];
let offset = self.active_context_offset();
pread_all(file.as_raw_fd(), &mut buf, offset as i64).map_err(|e| {
pread_all(file.as_fd(), &mut buf, offset as i64).map_err(|e| {
CrucibleError::IoError(format!(
"could not read active contexts: {e}"
))
Expand Down Expand Up @@ -1428,8 +1428,8 @@ impl RawLayout {
///
/// We don't have to worry about most of these conditions, but it may be
/// possible for Crucible to be interrupted by a signal, so let's play it safe.
fn pread_all(
fd: std::os::fd::RawFd,
fn pread_all<F: AsFd + Copy>(
fd: F,
mut buf: &mut [u8],
mut offset: i64,
) -> Result<(), nix::errno::Errno> {
Expand All @@ -1444,8 +1444,8 @@ fn pread_all(
/// Call `pwrite` repeatedly to write an entire buffer
///
/// See details for why this is necessary in [`pread_all`]
fn pwrite_all(
fd: std::os::fd::RawFd,
fn pwrite_all<F: AsFd + Copy>(
fd: F,
mut buf: &[u8],
mut offset: i64,
) -> Result<(), nix::errno::Errno> {
Expand Down
6 changes: 3 additions & 3 deletions downstairs/src/extent_inner_sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use slog::{error, Logger};
use std::collections::{BTreeMap, HashSet};
use std::fs::{File, OpenOptions};
use std::io::{BufReader, IoSliceMut, Read, Seek, SeekFrom};
use std::os::fd::AsRawFd;
use std::os::fd::AsFd;
use std::path::Path;

#[derive(Debug)]
Expand Down Expand Up @@ -217,7 +217,7 @@ impl ExtentInner for SqliteInner {
});

nix::sys::uio::preadv(
self.file.as_raw_fd(),
self.file.as_fd(),
&mut iovecs,
first_req.offset.value as i64 * block_size as i64,
)
Expand Down Expand Up @@ -437,7 +437,7 @@ impl ExtentInner for SqliteInner {

// Now, batch writes into iovecs and use pwritev to write them all out.
let mut batched_pwritev = BatchedPwritev::new(
self.file.as_raw_fd(),
self.file.as_fd(),
writes.len(),
self.extent_size.block_size_in_bytes() as u64,
iov_max,
Expand Down
4 changes: 2 additions & 2 deletions downstairs/src/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ struct BatchedPwritevState<'a> {
}

pub(crate) struct BatchedPwritev<'a> {
fd: std::os::fd::RawFd,
fd: std::os::fd::BorrowedFd<'a>,
capacity: usize,
state: Option<BatchedPwritevState<'a>>,
block_size: u64,
Expand All @@ -1082,7 +1082,7 @@ pub(crate) struct BatchedPwritev<'a> {

impl<'a> BatchedPwritev<'a> {
pub fn new(
fd: std::os::fd::RawFd,
fd: std::os::fd::BorrowedFd<'a>,
capacity: usize,
block_size: u64,
iov_max: usize,
Expand Down

0 comments on commit 2bf0c0e

Please sign in to comment.