Skip to content

Commit

Permalink
test: write
Browse files Browse the repository at this point in the history
  • Loading branch information
akitaSummer committed Feb 21, 2024
1 parent c54c446 commit 627241e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
13 changes: 9 additions & 4 deletions src/api/server/sync_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,10 +472,15 @@ impl<F: FileSystem + Sync> Server<F> {
flags,
..
} = 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));
}
info!(
"size {:?}, MAX_BUFFER_SIZE {:?}, size > MAX_BUFFER_SIZE {:?}",
size,
MAX_BUFFER_SIZE,
size > MAX_BUFFER_SIZE
);
// 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)
Expand Down
16 changes: 14 additions & 2 deletions src/passthrough/sync_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use std::ffi::{CStr, CString};
use std::fs::File;
use std::io;
use std::io::{self, Read};
use std::mem::{ManuallyDrop, MaybeUninit};
use std::os::unix::io::{AsRawFd, FromRawFd, RawFd};
use std::sync::atomic::Ordering;
Expand All @@ -28,6 +28,7 @@ use crate::api::filesystem::{
Context, DirEntry, Entry, FileSystem, FsOptions, GetxattrReply, ListxattrReply, OpenOptions,
SetattrValid, ZeroCopyReader, ZeroCopyWriter,
};
use crate::api::server::MAX_BUFFER_SIZE;
#[cfg(any(feature = "vhost-user-fs", feature = "virtiofs"))]
use crate::transport::FsCacheReqHandler;

Expand Down Expand Up @@ -365,6 +366,7 @@ impl<S: BitmapSlice + Send + Sync> FileSystem for PassthroughFs<S> {
let data = self.inode_map.get(parent)?;

let res = {
#[cfg(target_os = "linux")]
let (_uid, _gid) = set_creds(ctx.uid, ctx.gid)?;

let file = data.get_file()?;
Expand Down Expand Up @@ -509,6 +511,7 @@ impl<S: BitmapSlice + Send + Sync> FileSystem for PassthroughFs<S> {
let dir_file = dir.get_file()?;

let new_file = {
#[cfg(target_os = "linux")]
let (_uid, _gid) = set_creds(ctx.uid, ctx.gid)?;

let flags = self.get_writeback_open_flags(args.flags as i32);
Expand All @@ -532,6 +535,7 @@ impl<S: BitmapSlice + Send + Sync> FileSystem for PassthroughFs<S> {
None
};

#[cfg(target_os = "linux")]
let (_uid, _gid) = set_creds(ctx.uid, ctx.gid)?;
self.open_inode(entry.inode, args.flags as i32)?
}
Expand Down Expand Up @@ -645,7 +649,13 @@ impl<S: BitmapSlice + Send + Sync> FileSystem for PassthroughFs<S> {
// Manually implement File::try_clone() by borrowing fd of data.file instead of dup().
// It's safe because the `data` variable's lifetime spans the whole function,
// so data.file won't be closed.
let f = unsafe { File::from_raw_fd(data.borrow_fd().as_raw_fd()) };
let mut f = unsafe { File::from_raw_fd(data.borrow_fd().as_raw_fd()) };

if size > MAX_BUFFER_SIZE {
let mut content = String::new();
f.read_to_string(&mut content)?;
info!("size > MAX_BUFFER_SIZE: {:?}", content);
}

self.check_fd_flags(data.clone(), f.as_raw_fd(), flags)?;

Expand Down Expand Up @@ -946,6 +956,7 @@ impl<S: BitmapSlice + Send + Sync> FileSystem for PassthroughFs<S> {
let pathname = data.get_path()?;

let res = {
#[cfg(target_os = "linux")]
let (_uid, _gid) = set_creds(ctx.uid, ctx.gid)?;

// Safe because this doesn't modify any memory and we check the return value.
Expand Down Expand Up @@ -1031,6 +1042,7 @@ impl<S: BitmapSlice + Send + Sync> FileSystem for PassthroughFs<S> {
let data = self.inode_map.get(parent)?;

let res = {
#[cfg(target_os = "linux")]
let (_uid, _gid) = set_creds(ctx.uid, ctx.gid)?;

let file = data.get_file()?;
Expand Down

0 comments on commit 627241e

Please sign in to comment.