Skip to content

Commit

Permalink
Move mapping of PrefetchReadErrors into the fs::error module (#750)
Browse files Browse the repository at this point in the history
Signed-off-by: Alessandro Passaro <alexpax@amazon.co.uk>
  • Loading branch information
passaro authored Jul 5, 2024
1 parent 805c501 commit becbd55
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
22 changes: 6 additions & 16 deletions mountpoint-s3/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use tracing::{debug, error, trace, Level};

use fuser::consts::FOPEN_DIRECT_IO;
use fuser::{FileAttr, KernelConfig};
use mountpoint_s3_client::error::{GetObjectError, ObjectClientError};
use mountpoint_s3_client::types::ETag;
use mountpoint_s3_client::ObjectClient;

Expand All @@ -22,7 +21,7 @@ use crate::inode::{
Inode, InodeError, InodeKind, LookedUp, ReadHandle, ReaddirHandle, Superblock, SuperblockConfig, WriteHandle,
};
use crate::logging;
use crate::prefetch::{Prefetch, PrefetchReadError, PrefetchResult};
use crate::prefetch::{Prefetch, PrefetchResult};
use crate::prefix::Prefix;
use crate::s3::S3Personality;
use crate::sync::atomic::{AtomicI64, AtomicU64, Ordering};
Expand Down Expand Up @@ -857,20 +856,11 @@ where
FileHandleState::Write(_) => return Err(err!(libc::EBADF, "file handle is not open for reads")),
};

match request.read(offset as u64, size as usize).await {
Ok(checksummed_bytes) => checksummed_bytes
.into_bytes()
.map_err(|e| err!(libc::EIO, source:e, "integrity error")),
Err(PrefetchReadError::GetRequestFailed(ObjectClientError::ServiceError(
GetObjectError::PreconditionFailed,
))) => Err(err!(libc::ESTALE, "object was mutated remotely")),
Err(PrefetchReadError::Integrity(e)) => Err(err!(libc::EIO, source:e, "integrity error")),
Err(e @ PrefetchReadError::GetRequestFailed(_))
| Err(e @ PrefetchReadError::GetRequestTerminatedUnexpectedly)
| Err(e @ PrefetchReadError::GetRequestReturnedWrongOffset { .. }) => {
Err(err!(libc::EIO, source:e, "get request failed"))
}
}
request
.read(offset as u64, size as usize)
.await?
.into_bytes()
.map_err(|e| err!(libc::EIO, source:e, "integrity error"))
}

pub async fn mknod(
Expand Down
18 changes: 18 additions & 0 deletions mountpoint-s3/src/fs/error.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//! Utilities for handling errors generated by the `fs` module and mapping them to FUSE errors

use mountpoint_s3_client::error::{GetObjectError, ObjectClientError};
use tracing::Level;

use crate::fs::error_metadata::ErrorMetadata;
use crate::inode::InodeError;
use crate::prefetch::PrefetchReadError;
use crate::upload::UploadWriteError;

/// Generate an error that includes a conversion to a libc errno for use in replies to FUSE.
Expand Down Expand Up @@ -120,6 +122,22 @@ impl<E: std::error::Error + Send + Sync + 'static> From<UploadWriteError<E>> for
}
}

impl<E: std::error::Error + Send + Sync + 'static> From<PrefetchReadError<E>> for Error {
fn from(err: PrefetchReadError<E>) -> Self {
match err {
PrefetchReadError::GetRequestFailed(ObjectClientError::ServiceError(
GetObjectError::PreconditionFailed,
)) => err!(libc::ESTALE, "object was mutated remotely"),
PrefetchReadError::Integrity(e) => err!(libc::EIO, source:e, "integrity error"),
PrefetchReadError::GetRequestFailed(_)
| PrefetchReadError::GetRequestTerminatedUnexpectedly
| PrefetchReadError::GetRequestReturnedWrongOffset { .. } => {
err!(libc::EIO, source:err, "get request failed")
}
}
}
}

/// Errors that can be converted to a raw OS error (errno)
pub trait ToErrno {
fn to_errno(&self) -> libc::c_int;
Expand Down

0 comments on commit becbd55

Please sign in to comment.