Skip to content

Commit

Permalink
refactor(ofs): Split fuse3 impl into fuse3_opendal (#4721)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xuanwo authored Jun 12, 2024
1 parent babbfe2 commit e1e430d
Show file tree
Hide file tree
Showing 10 changed files with 297 additions and 305 deletions.
15 changes: 15 additions & 0 deletions bin/ofs/Cargo.lock

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

3 changes: 2 additions & 1 deletion bin/ofs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ chrono = "0.4.34"
clap = { version = "4.5.1", features = ["derive", "env"] }
env_logger = "0.11.2"
fuse3 = { "version" = "0.7.2", "features" = ["tokio-runtime", "unprivileged"] }
fuse3_opendal = { version = "0.1.0", path = "../../integrations/fuse3" }
futures-util = "0.3.30"
libc = "0.2.154"
log = "0.4.21"
Expand All @@ -57,9 +58,9 @@ services-fs = ["opendal/services-fs"]
services-s3 = ["opendal/services-s3"]

[dev-dependencies]
opendal = { version = "0.47.0", path = "../../core", features = ["tests"] }
tempfile = "3.10.1"
test-context = "0.3.0"
urlencoding = "2.1.3"
uuid = "1.7.0"
walkdir = "2.5.0"
opendal = { version = "0.47.0", path = "../../core", features = ["tests"] }
134 changes: 0 additions & 134 deletions bin/ofs/src/fuse/mod.rs

This file was deleted.

32 changes: 23 additions & 9 deletions bin/ofs/src/bin/ofs.rs → bin/ofs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

use anyhow::Result;
use clap::Parser;
use fuse3::path::Session;
use fuse3::MountOptions;
use url::Url;

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -48,7 +50,6 @@ async fn execute(cfg: Config) -> Result<()> {
use std::str::FromStr;

use anyhow::anyhow;
use ofs::fuse::Fuse;
use opendal::Operator;
use opendal::Scheme;

Expand All @@ -69,25 +70,38 @@ async fn execute(cfg: Config) -> Result<()> {
}?;
let backend = Operator::via_map(scheme, op_args)?;

let mut mount_options = MountOptions::default();
let mut gid = nix::unistd::getgid().into();
mount_options.gid(gid);
let mut uid = nix::unistd::getuid().into();
mount_options.uid(uid);

#[cfg(target_os = "linux")]
let mut mount_handle = if nix::unistd::getuid().is_root() {
let mut fuse = Fuse::new();
if let Some(gid) = env::var("SUDO_GID")
if let Some(sudo_gid) = env::var("SUDO_GID")
.ok()
.and_then(|gid_str| gid_str.parse::<u32>().ok())
{
fuse = fuse.gid(gid);
mount_options.gid(sudo_gid);
gid = sudo_gid;
}
if let Some(uid) = env::var("SUDO_UID")

if let Some(sudo_uid) = env::var("SUDO_UID")
.ok()
.and_then(|gid_str| gid_str.parse::<u32>().ok())
{
fuse = fuse.uid(uid);
mount_options.uid(uid);
uid = sudo_uid;
}
fuse.mount(cfg.mount_path, backend).await?

let fs = fuse3_opendal::Filesystem::new(backend, uid, gid);
Session::new(mount_options)
.mount(fs, cfg.mount_path)
.await?
} else {
Fuse::new()
.mount_with_unprivileged(cfg.mount_path, backend)
let fs = fuse3_opendal::Filesystem::new(backend, uid, gid);
Session::new(mount_options)
.mount_with_unprivileged(fs, cfg.mount_path)
.await?
};

Expand Down
27 changes: 20 additions & 7 deletions bin/ofs/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
// specific language governing permissions and limitations
// under the License.

use fuse3::path::Session;
use fuse3::MountOptions;
use std::sync::OnceLock;

use fuse3::raw::MountHandle;
use opendal::raw::tests;
use opendal::Capability;
use tempfile::TempDir;
Expand All @@ -30,7 +33,7 @@ static RUNTIME: OnceLock<Runtime> = OnceLock::new();
pub struct OfsTestContext {
pub mount_point: TempDir,
pub capability: Capability,
mount_handle: ofs::fuse::MountHandle,
mount_handle: MountHandle,
}

impl TestContext for OfsTestContext {
Expand All @@ -51,12 +54,22 @@ impl TestContext for OfsTestContext {
.build()
.expect("build runtime")
})
.block_on(async move {
ofs::fuse::Fuse::new()
.mount_with_unprivileged(mount_point_str, backend)
.await
})
.unwrap();
.block_on(
#[allow(clippy::async_yields_async)]
async move {
let mut mount_options = MountOptions::default();
let gid = nix::unistd::getgid().into();
mount_options.gid(gid);
let uid = nix::unistd::getuid().into();
mount_options.uid(uid);

let fs = fuse3_opendal::Filesystem::new(backend, uid, gid);
Session::new(mount_options)
.mount_with_unprivileged(fs, mount_point_str)
.await
.unwrap()
},
);

OfsTestContext {
mount_point,
Expand Down
1 change: 1 addition & 0 deletions integrations/fuse3/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cargo.lock
40 changes: 40 additions & 0 deletions integrations/fuse3/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

[package]
description = "fuse3 integration for Apache OpenDAL"
name = "fuse3_opendal"

authors = ["Apache OpenDAL <[email protected]>"]
edition = "2021"
homepage = "https://opendal.apache.org/"
license = "Apache-2.0"
repository = "https://github.com/apache/opendal"
rust-version = "1.75"
version = "0.1.0"

[dependencies]
bytes = "1.6.0"
fuse3 = { version = "0.7.2", "features" = ["tokio-runtime", "unprivileged"] }
futures-util = "0.3.30"
libc = "0.2.155"
log = "0.4.21"
opendal = { version = "0.47.0", path = "../../core" }
sharded-slab = "0.1.7"
tokio = "1.38.0"

[dev-dependencies]
Loading

0 comments on commit e1e430d

Please sign in to comment.