Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor error handling on read requests #750

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 6 additions & 16 deletions mountpoint-s3/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ 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;

use crate::inode::{Inode, InodeError, InodeKind, LookedUp, 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 @@ -848,20 +847,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,8 +1,10 @@
//! 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::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 @@ -110,6 +112,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
Loading