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

[scorpio]: Readonly dictionary FUSE initial runnable version COMPLETED. #494

Merged
merged 1 commit into from
Aug 2, 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
12 changes: 6 additions & 6 deletions scorpio/src/dicfuse/fuse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ const BLOCK_SIZE: u32 = 512;
fn default_stat64(inode:u64) -> stat64 {
let t = Attr{
ino: inode, // Default inode number
size: 0, // Default file size
blocks: 0, // Default number of blocks
size: 512 , // Default file size
blocks: 8, // Default number of blocks
atime: 0, // Default last access time
mtime: 0, // Default last modification time
ctime: 0, // Default last status change time
atimensec: 0, // Default nanoseconds of last access time
mtimensec: 0, // Default nanoseconds of last modification time
ctimensec: 0, // Default nanoseconds of last status change time
mode: 0o444, // Default file mode (r--r--r--)
//mode: 0o555, // Default file mode (r-xr-xr-x)
nlink: 1, // Default number of hard links
mode: 0o100444, // Default file mode (r--r--r--)
//mode: 0o0040755, // Default file mode (r-xr-xr-x)
nlink: 2, // Default number of hard links
uid: 1000, // Default user ID
gid: 1000, // Default group ID
rdev: 0, // Default device ID
Expand All @@ -39,7 +39,7 @@ pub fn default_file_entry(inode:u64) -> Entry {

pub fn default_dic_entry(inode:u64) -> Entry {
let mut d = default_stat64(inode);
d.st_mode = 0o555;
d.st_mode = 0o0040755;
Entry{
inode,
generation: 0,
Expand Down
47 changes: 39 additions & 8 deletions scorpio/src/dicfuse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,24 @@ impl FileSystem for Dicfuse{
fn destroy(&self) {}

fn lookup(&self, ctx: &Context, parent: Self::Inode, name: &std::ffi::CStr) -> Result<Entry> {
println!("[lookup]: ctx:{}, parnet inode:{},name :{:?}",ctx.pid,parent,name);
let store = self.store.clone();
let mut ppath = store.find_path(parent).ok_or_else(|| std::io::Error::from_raw_os_error(libc::ENODATA))?;
let pitem = store.get_inode(parent)?;
ppath.push(name.to_string_lossy().into_owned());
let chil = store.get_by_path(&ppath.to_string())?;
Ok(chil.into_entry())
let ree = chil.into_entry();
println!("[lookup-out]: entry:{:?}",ree);
Ok(ree)
}


fn forget(&self, ctx: &Context, inode: Self::Inode, count: u64) {}
fn forget(&self, ctx: &Context, inode: Self::Inode, count: u64) {
println!("[forget]: ctx:{}, inode:{},count :{}",ctx.pid,inode,count);
}

fn batch_forget(&self, ctx: &Context, requests: Vec<(Self::Inode, u64)>) {
println!("[batch-forget]: ctx:{}",ctx.pid);
for (inode, count) in requests {
self.forget(ctx, inode, count)
}
Expand All @@ -72,10 +78,14 @@ impl FileSystem for Dicfuse{
inode: Self::Inode,
handle: Option<Self::Handle>,
) -> std::io::Result<(libc::stat64, std::time::Duration)> {
println!("[getattr]: ctx:{}, inode:{},handle :{:?}",ctx.pid,inode ,handle);
let store = self.store.clone();
let i = store.find_path(inode).ok_or_else(|| std::io::Error::from_raw_os_error(libc::ENODATA))?;
let entry = fuse::default_file_entry(inode);
Ok((entry.attr,Duration::from_secs(u64::MAX)))
let item = store.get_inode(inode)?;
let mut entry = item.get_stat();

println!("[getattr-out]:entry ->{:?}",entry.attr);
Ok((entry.attr,Duration::from_secs(0)))
}

fn setattr(
Expand All @@ -86,6 +96,7 @@ impl FileSystem for Dicfuse{
handle: Option<Self::Handle>,
valid: fuse_backend_rs::abi::fuse_abi::SetattrValid,
) -> std::io::Result<(libc::stat64, std::time::Duration)> {
println!("[setattr]: not implement.");
Err(std::io::Error::from_raw_os_error(libc::ENOSYS))
}

Expand All @@ -99,6 +110,7 @@ impl FileSystem for Dicfuse{
rdev: u32,
umask: u32,
) -> std::io::Result<Entry> {
println!("[mknod]: not implement.");
Err(std::io::Error::from_raw_os_error(libc::ENOSYS))
}

Expand All @@ -110,14 +122,17 @@ impl FileSystem for Dicfuse{
mode: u32,
umask: u32,
) -> std::io::Result<Entry> {
println!("[mkdir]: not implement.");
Err(std::io::Error::from_raw_os_error(libc::ENOSYS))
}

fn unlink(&self, ctx: &Context, parent: Self::Inode, name: &std::ffi::CStr) -> std::io::Result<()> {
println!("[unlink]: not implement.");
Err(std::io::Error::from_raw_os_error(libc::ENOSYS))
}

fn rmdir(&self, ctx: &Context, parent: Self::Inode, name: &std::ffi::CStr) -> std::io::Result<()> {
println!("[rmdir]: not implement.");
Err(std::io::Error::from_raw_os_error(libc::ENOSYS))
}

Expand All @@ -130,6 +145,7 @@ impl FileSystem for Dicfuse{
newname: &std::ffi::CStr,
flags: u32,
) -> std::io::Result<()> {
println!("[rename]: not implement.");
Err(std::io::Error::from_raw_os_error(libc::ENOSYS))
}

Expand All @@ -140,6 +156,7 @@ impl FileSystem for Dicfuse{
newparent: Self::Inode,
newname: &std::ffi::CStr,
) -> std::io::Result<Entry> {
println!("[link]: not implement.");
Err(std::io::Error::from_raw_os_error(libc::ENOSYS))
}

Expand All @@ -150,6 +167,7 @@ impl FileSystem for Dicfuse{
flags: u32,
fuse_flags: u32,
) -> std::io::Result<(Option<Self::Handle>, fuse_backend_rs::abi::fuse_abi::OpenOptions, Option<u32>)> {
println!("[open]: not implement.");
// Matches the behavior of libfuse.
Ok((None, fuse_backend_rs::abi::fuse_abi::OpenOptions::empty(), None))
}
Expand All @@ -161,6 +179,7 @@ impl FileSystem for Dicfuse{
name: &std::ffi::CStr,
args: fuse_backend_rs::abi::fuse_abi::CreateIn,
) -> std::io::Result<(Entry, Option<Self::Handle>, fuse_backend_rs::abi::fuse_abi::OpenOptions, Option<u32>)> {
println!("[create]: not implement.");
Err(std::io::Error::from_raw_os_error(libc::ENOSYS))
}

Expand All @@ -171,6 +190,7 @@ impl FileSystem for Dicfuse{
handle: Self::Handle,
lock_owner: u64,
) -> std::io::Result<()> {
println!("[flush]: not implement.");
Err(std::io::Error::from_raw_os_error(libc::ENOSYS))
}

Expand All @@ -181,6 +201,7 @@ impl FileSystem for Dicfuse{
datasync: bool,
handle: Self::Handle,
) -> std::io::Result<()> {
println!("[fsync]: not implement.");
Err(std::io::Error::from_raw_os_error(libc::ENOSYS))
}

Expand All @@ -193,6 +214,7 @@ impl FileSystem for Dicfuse{
offset: u64,
length: u64,
) -> std::io::Result<()> {
println!("[fallocate]: not implement.");
Err(std::io::Error::from_raw_os_error(libc::ENOSYS))
}

Expand All @@ -206,10 +228,12 @@ impl FileSystem for Dicfuse{
flock_release: bool,
lock_owner: Option<u64>,
) -> std::io::Result<()> {
println!("[release]: not implement.");
Err(std::io::Error::from_raw_os_error(libc::ENOSYS))
}

fn statfs(&self, ctx: &Context, inode: Self::Inode) -> std::io::Result<libc::statvfs64> {
println!("[statfs]: not implement.");
// Safe because we are zero-initializing a struct with only POD fields.
let mut st: libc::statvfs64 = unsafe { std::mem::zeroed() };
// This matches the behavior of libfuse as it returns these values if the
Expand All @@ -227,6 +251,7 @@ impl FileSystem for Dicfuse{
value: &[u8],
flags: u32,
) -> std::io::Result<()> {
println!("[setxattr]: not implement.");
Err(std::io::Error::from_raw_os_error(libc::ENOSYS))
}

Expand All @@ -237,6 +262,7 @@ impl FileSystem for Dicfuse{
name: &std::ffi::CStr,
size: u32,
) -> std::io::Result<fuse_backend_rs::api::filesystem::GetxattrReply> {
println!("[getxattr]: not implement.");
Err(std::io::Error::from_raw_os_error(libc::ENOSYS))
}

Expand All @@ -246,6 +272,7 @@ impl FileSystem for Dicfuse{
inode: Self::Inode,
size: u32,
) -> std::io::Result<fuse_backend_rs::api::filesystem::ListxattrReply> {
println!("[listxattr]: not implement.");
Err(std::io::Error::from_raw_os_error(libc::ENOSYS))
}

Expand All @@ -256,7 +283,8 @@ impl FileSystem for Dicfuse{
flags: u32,
) -> std::io::Result<(Option<Self::Handle>, fuse_backend_rs::abi::fuse_abi::OpenOptions)> {
// Matches the behavior of libfuse.
Ok((None, fuse_backend_rs::abi::fuse_abi::OpenOptions::empty()))
println!("[opendir]: not implement.");
Ok((Some(inode), fuse_backend_rs::abi::fuse_abi::OpenOptions::empty()))
}

fn readdir(
Expand All @@ -268,7 +296,8 @@ impl FileSystem for Dicfuse{
offset: u64,
add_entry: &mut dyn FnMut(fuse_backend_rs::api::filesystem::DirEntry) -> std::io::Result<usize>,
) -> std::io::Result<()> {
Err(std::io::Error::from_raw_os_error(libc::ENOSYS))
println!("[readdir]: inode:{},handle:{},size:{},offset:{}",inode,handle,size,offset);
self.store.do_readdir(ctx, inode, handle, size, offset, add_entry)
}

fn readdirplus(
Expand All @@ -280,11 +309,13 @@ impl FileSystem for Dicfuse{
offset: u64,
add_entry: &mut dyn FnMut(fuse_backend_rs::api::filesystem::DirEntry, Entry) -> std::io::Result<usize>,
) -> std::io::Result<()> {
println!("[readdirplus]: not implement.");
Err(std::io::Error::from_raw_os_error(libc::ENOSYS))
}

fn access(&self, ctx: &Context, inode: Self::Inode, mask: u32) -> std::io::Result<()> {
Err(std::io::Error::from_raw_os_error(libc::ENOSYS))
println!("[access]: not implement.");
Ok(())
}


Expand Down Expand Up @@ -344,7 +375,7 @@ mod tests {
let dicfuse = Arc::new(Dicfuse::new());
// dicfuse.init(FsOptions::empty()).unwrap();
// Create fuse session
let mut se = FuseSession::new(Path::new(&"/home/luxian/ccode/mega/dictest"), "dic", "", true).unwrap();
let mut se = FuseSession::new(Path::new(&"/tmp/dictest"), "dic", "", true).unwrap();
se.mount().unwrap();
let ch: FuseChannel = se.new_channel().unwrap();
println!("start fs servers");
Expand Down
16 changes: 15 additions & 1 deletion scorpio/src/dicfuse/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ impl GPath{
}

impl From<String> for GPath{
fn from(s: String) -> GPath {
fn from(mut s: String) -> GPath {
if s.starts_with('/'){
s.remove(0);
}
GPath {
path: s.split('/').map(String::from).collect(),
}
Expand All @@ -38,3 +41,14 @@ impl Display for GPath{
}
}

#[cfg(test)]
mod tests{
use super::GPath;

#[test]
fn test_from_string(){
let path = String::from("/release");
let gapth = GPath::from(path);
assert_eq!(gapth.to_string(),String::from("release"))
}
}
Loading
Loading