Skip to content

fix request size too large when use direct io #191

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

Merged
merged 1 commit into from
Apr 11, 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
6 changes: 0 additions & 6 deletions src/api/server/async_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,12 +322,6 @@ impl<F: AsyncFileSystem + Sync> Server<F> {
..
} = ctx.r.read_obj().map_err(Error::DecodeMessage)?;

if size > MAX_BUFFER_SIZE {
return ctx
.async_reply_error_explicit(io::Error::from_raw_os_error(libc::ENOMEM))
.await;
}

let owner = if read_flags & READ_LOCKOWNER != 0 {
Some(lock_owner)
} else {
Expand Down
19 changes: 0 additions & 19 deletions src/api/server/sync_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,10 +436,6 @@ impl<F: FileSystem + Sync> Server<F> {
..
} = ctx.r.read_obj().map_err(Error::DecodeMessage)?;

if size > MAX_BUFFER_SIZE {
return ctx.reply_error_explicit(io::Error::from_raw_os_error(libc::ENOMEM));
}

let owner = if read_flags & READ_LOCKOWNER != 0 {
Some(lock_owner)
} else {
Expand Down Expand Up @@ -495,10 +491,6 @@ impl<F: FileSystem + Sync> Server<F> {
..
} = ctx.r.read_obj().map_err(Error::DecodeMessage)?;

if size > MAX_BUFFER_SIZE {
return ctx.reply_error_explicit(io::Error::from_raw_os_error(libc::ENOMEM));
}

let owner = if fuse_flags & WRITE_LOCKOWNER != 0 {
Some(lock_owner)
} else {
Expand Down Expand Up @@ -618,9 +610,6 @@ impl<F: FileSystem + Sync> Server<F> {

pub(super) fn getxattr<S: BitmapSlice>(&self, mut ctx: SrvContext<'_, F, S>) -> Result<usize> {
let GetxattrIn { size, .. } = ctx.r.read_obj().map_err(Error::DecodeMessage)?;
if size > MAX_BUFFER_SIZE {
return ctx.reply_error_explicit(io::Error::from_raw_os_error(libc::ENOMEM));
}

let buf =
ServerUtil::get_message_body(&mut ctx.r, &ctx.in_header, size_of::<GetxattrIn>())?;
Expand All @@ -647,10 +636,6 @@ impl<F: FileSystem + Sync> Server<F> {
pub(super) fn listxattr<S: BitmapSlice>(&self, mut ctx: SrvContext<'_, F, S>) -> Result<usize> {
let GetxattrIn { size, .. } = ctx.r.read_obj().map_err(Error::DecodeMessage)?;

if size > MAX_BUFFER_SIZE {
return ctx.reply_error_explicit(io::Error::from_raw_os_error(libc::ENOMEM));
}

match self.fs.listxattr(ctx.context(), ctx.nodeid(), size) {
Ok(ListxattrReply::Names(val)) => ctx.reply_ok(None::<u8>, Some(&val)),
Ok(ListxattrReply::Count(count)) => {
Expand Down Expand Up @@ -820,10 +805,6 @@ impl<F: FileSystem + Sync> Server<F> {
fh, offset, size, ..
} = ctx.r.read_obj().map_err(Error::DecodeMessage)?;

if size > MAX_BUFFER_SIZE {
return ctx.reply_error_explicit(io::Error::from_raw_os_error(libc::ENOMEM));
}

let available_bytes = ctx.w.available_bytes();
if available_bytes < size as usize {
return ctx.reply_error_explicit(io::Error::from_raw_os_error(libc::ENOMEM));
Expand Down
15 changes: 14 additions & 1 deletion src/transport/fusedev/linux_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,12 +434,25 @@ fn fuse_kern_mount(
let meta = mountpoint
.metadata()
.map_err(|e| SessionFailure(format!("stat {mountpoint:?}: {e}")))?;
// the current implementation of fuse-backend-rs uses a fixed buffer to store the fuse response,
// the default value of this buffer is as follows, but in fact, the kernel in the direct io path,
// the size of the request may be larger than the length of this buffer (this is determined by
// the max_read option to determine the maximum size of kernel requests, the default value is
// a very large number), which leads to the buffer is not enough to fill the read content,
// resulting in read failure. so here we limit the size of max_read to the length of our buffer,
// so that the fuse kernel will not send requests that exceed the length of the buffer.
// in virtiofs scene max_read can't be adjusted, his default is UINT_MAX, but we don't have to
// worry about it, because the buffer is allocated by the kernel driver, we just use this buffer
// to fill the response, so we don't need to do any adjustment.
let max_read = FUSE_KERN_BUF_PAGES * pagesize() + FUSE_HEADER_SIZE;

let mut opts = format!(
"default_permissions,fd={},rootmode={:o},user_id={},group_id={}",
"default_permissions,fd={},rootmode={:o},user_id={},group_id={},max_read={}",
file.as_raw_fd(),
meta.permissions().mode() & libc::S_IFMT,
getuid(),
getgid(),
max_read
);
if allow_other {
opts.push_str(",allow_other");
Expand Down
Loading