Skip to content

Commit

Permalink
feat(ofs): implement ofs based on fuse3 (#3857)
Browse files Browse the repository at this point in the history
  • Loading branch information
Inokinoki committed Dec 31, 2023
1 parent 86e7852 commit 51b3760
Show file tree
Hide file tree
Showing 3 changed files with 276 additions and 18 deletions.
82 changes: 64 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions bin/ofs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ repository.workspace = true
rust-version.workspace = true

[dependencies]
async-trait = "0.1.75"
fuse3 = { "version" = "0.6.1", "features" = ["tokio-runtime"] }
futures-util = "0.3.30"
libc = "0.2.151"
log = "0.4.20"
opendal.workspace = true
207 changes: 207 additions & 0 deletions bin/ofs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,210 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

use fuse3::path::prelude::*;
use fuse3::Result;

use async_trait::async_trait;
use futures_util::stream::{Empty, Iter};
use std::ffi::OsStr;
use std::vec::IntoIter;

use opendal::Operator;

pub struct Ofs {
pub op: Operator,
}

#[async_trait]
impl PathFilesystem for Ofs {
type DirEntryStream = Empty<Result<DirectoryEntry>>;
type DirEntryPlusStream = Iter<IntoIter<Result<DirectoryEntryPlus>>>;

// Init a fuse filesystem
async fn init(&self, _req: Request) -> Result<()> {
Ok(())
}

// Callback when fs is being destroyed
async fn destroy(&self, _req: Request) {}

async fn lookup(&self, _req: Request, _parent: &OsStr, _name: &OsStr) -> Result<ReplyEntry> {
// TODO
Err(libc::ENOSYS.into())
}

async fn getattr(
&self,
_req: Request,
path: Option<&OsStr>,
_fh: Option<u64>,
_flags: u32,
) -> Result<ReplyAttr> {
// TODO
log::debug!("getattr(path={:?})", path);

Err(libc::ENOSYS.into())
}

async fn read(
&self,
_req: Request,
path: Option<&OsStr>,
fh: u64,
offset: u64,
size: u32,
) -> Result<ReplyData> {
// TODO
log::debug!(
"read(path={:?}, fh={}, offset={}, size={})",
path,
fh,
offset,
size
);

Err(libc::ENOSYS.into())
}

async fn mkdir(
&self,
_req: Request,
parent: &OsStr,
name: &OsStr,
mode: u32,
_umask: u32,
) -> Result<ReplyEntry> {
// TODO
log::debug!(
"mkdir(parent={:?}, name={:?}, mode=0o{:o})",
parent,
name,
mode
);

Err(libc::ENOSYS.into())
}

async fn readdir(
&self,
_req: Request,
path: &OsStr,
fh: u64,
offset: i64,
) -> Result<ReplyDirectory<Self::DirEntryStream>> {
// TODO
log::debug!("readdir(path={:?}, fh={}, offset={})", path, fh, offset);

Err(libc::ENOSYS.into())
}

async fn mknod(
&self,
_req: Request,
parent: &OsStr,
name: &OsStr,
mode: u32,
_rdev: u32,
) -> Result<ReplyEntry> {
// TODO
log::debug!(
"mknod(parent={:?}, name={:?}, mode=0o{:o})",
parent,
name,
mode
);

Err(libc::ENOSYS.into())
}

async fn open(&self, _req: Request, path: &OsStr, flags: u32) -> Result<ReplyOpen> {
// TODO
log::debug!("open(path={:?}, flags=0x{:x})", path, flags);

Err(libc::ENOSYS.into())
}

async fn setattr(
&self,
_req: Request,
path: Option<&OsStr>,
_fh: Option<u64>,
_set_attr: SetAttr,
) -> Result<ReplyAttr> {
// TODO
log::debug!("setattr(path={:?})", path);

Err(libc::ENOSYS.into())
}

async fn write(
&self,
_req: Request,
path: Option<&OsStr>,
fh: u64,
offset: u64,
data: &[u8],
flags: u32,
) -> Result<ReplyWrite> {
// TODO
log::debug!(
"write(path={:?}, fh={}, offset={}, len={}, flags=0x{:x})",
path,
fh,
offset,
data.len(),
flags
);

Err(libc::ENOSYS.into())
}

async fn release(
&self,
_req: Request,
path: Option<&OsStr>,
fh: u64,
flags: u32,
_lock_owner: u64,
flush: bool,
) -> Result<()> {
// TODO
log::debug!(
"release(path={:?}, fh={}, flags={}, flush={})",
path,
fh,
flags,
flush
);

Err(libc::ENOSYS.into())
}

async fn rename(
&self,
_req: Request,
origin_parent: &OsStr,
origin_name: &OsStr,
parent: &OsStr,
name: &OsStr,
) -> Result<()> {
// TODO
log::debug!(
"rename(p={:?}, name={:?}, newp={:?}, newname={:?})",
origin_parent,
origin_name,
parent,
name
);

Err(libc::ENOSYS.into())
}

async fn unlink(&self, _req: Request, parent: &OsStr, name: &OsStr) -> Result<()> {
// TODO
log::debug!("unlink(parent={:?}, name={:?})", parent, name);

Err(libc::ENOSYS.into())
}
}

0 comments on commit 51b3760

Please sign in to comment.