Skip to content

Commit

Permalink
Fix batch forget can't handle too large msg
Browse files Browse the repository at this point in the history
error: cannot process fuse message: Value too large for defined data type

By default, when fuse sever reads the batch forget request, the bufsize given
is MAX_BUFFER_SIZE + BUFFER_HEADER_SIZE, and the fuse kernel will
fill this buffer as much as possible, so the size of the data that batch forget
can fill should be the total buffer size - fuse header - batch forget header

Here's the code for the fuse kernel to fill the batch forget request.

```
	struct fuse_batch_forget_in arg = { .count = 0 };
	struct fuse_in_header ih = {
		.opcode = FUSE_BATCH_FORGET,
		.unique = fuse_get_unique(fiq),
		.len = sizeof(ih) + sizeof(arg),
	};

	if (nbytes < ih.len) {
		spin_unlock(&fiq->lock);
		return -EINVAL;
	}

	max_forgets = (nbytes - ih.len) / sizeof(struct fuse_forget_one);
	head = fuse_dequeue_forget(fiq, max_forgets, &count);
	spin_unlock(&fiq->lock);

	arg.count = count;
	ih.len += count * sizeof(struct fuse_forget_one);
```

so fuse_batch_forget_in.count *  sizeof(struct fuse_forget_one)
should less than or equal to bufsize - sizeof(fuse_in_header) - sizeof(fuse_batch_forget_in)

Signed-off-by: zyfjeff <[email protected]>
  • Loading branch information
zyfjeff authored and jiangliu committed Nov 29, 2023
1 parent d925e47 commit be90837
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/api/server/sync_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,11 @@ impl<F: FileSystem + Sync> Server<F> {
let BatchForgetIn { count, .. } = ctx.r.read_obj().map_err(Error::DecodeMessage)?;

if let Some(size) = (count as usize).checked_mul(size_of::<ForgetOne>()) {
if size > MAX_BUFFER_SIZE as usize {
if size
> (MAX_BUFFER_SIZE + BUFFER_HEADER_SIZE
- size_of::<BatchForgetIn>() as u32
- size_of::<InHeader>() as u32) as usize
{
return Err(Error::InvalidMessage(io::Error::from_raw_os_error(
libc::EOVERFLOW,
)));
Expand Down

0 comments on commit be90837

Please sign in to comment.