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

[#6012] feat (gvfs-fuse): Support Gravitino S3 fileset filesystem operation in gvfs fuse #6013

Open
wants to merge 83 commits into
base: branch-gvfs-fuse-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 69 commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
f025216
Add SimpleFilesystem
diqiu50 Dec 17, 2024
97e066d
Update
diqiu50 Dec 17, 2024
d0b6958
Add uts
diqiu50 Dec 17, 2024
3769400
Fix test error
diqiu50 Dec 17, 2024
3ecb980
Update comments
diqiu50 Dec 17, 2024
4fe58f2
Fix ci error
diqiu50 Dec 17, 2024
a55bff8
Add description of gvfs-fuse filesystem struct
diqiu50 Dec 18, 2024
58922e1
Update
diqiu50 Dec 18, 2024
cda8275
Update
diqiu50 Dec 18, 2024
5f93717
Update
diqiu50 Dec 18, 2024
39e55fe
Update for review
diqiu50 Dec 18, 2024
366c77a
Update
diqiu50 Dec 18, 2024
33dc3bd
Update
diqiu50 Dec 18, 2024
865f213
Update
diqiu50 Dec 18, 2024
2570eb8
Update
diqiu50 Dec 18, 2024
bfd3945
Update
diqiu50 Dec 19, 2024
4fb77e1
Update
diqiu50 Dec 19, 2024
8cf0c4a
Update
diqiu50 Dec 19, 2024
21b080d
Update
diqiu50 Dec 19, 2024
4fe5fe3
Update
diqiu50 Dec 19, 2024
2517afa
Update
diqiu50 Dec 19, 2024
d32cd6a
Add
diqiu50 Dec 19, 2024
53e4c4e
remove unused mod
diqiu50 Dec 19, 2024
568fefe
Update
diqiu50 Dec 20, 2024
76305a9
Update
diqiu50 Dec 20, 2024
5459622
Update path interface
diqiu50 Dec 20, 2024
1ea53ef
Merge branch 'gvfs-pr2' into gvfs-pr3
diqiu50 Dec 20, 2024
dbca557
Fix error
diqiu50 Dec 20, 2024
d444ad3
Fix
diqiu50 Dec 20, 2024
2570f54
Update
diqiu50 Dec 23, 2024
f6ce011
Update
diqiu50 Dec 23, 2024
8fb13bb
Update
diqiu50 Dec 23, 2024
e23a589
Update
diqiu50 Dec 23, 2024
e8c74f6
Update
diqiu50 Dec 23, 2024
b99af10
Update
diqiu50 Dec 24, 2024
4dd5bf4
Update
diqiu50 Dec 24, 2024
01d90a6
Update
diqiu50 Dec 24, 2024
14609cf
Update
diqiu50 Dec 24, 2024
127cb41
Update
diqiu50 Dec 24, 2024
df48db4
Update
diqiu50 Dec 24, 2024
37a46d6
Update
diqiu50 Dec 24, 2024
2bd05da
Merge branch 'gvfs-pr2' into gvfs-pr3
diqiu50 Dec 24, 2024
364ce34
Merge remote-tracking branch 'gt/branch-gvfs-fuse-dev' into gvfs-pr3
diqiu50 Dec 24, 2024
3a863ed
Update
diqiu50 Dec 24, 2024
406641b
Update
diqiu50 Dec 24, 2024
0e512fc
Update
diqiu50 Dec 24, 2024
da02b01
Add testers
diqiu50 Dec 24, 2024
c043b95
Fix test
diqiu50 Dec 24, 2024
d4da504
Add testers
diqiu50 Dec 24, 2024
3b12f11
Change v1
diqiu50 Dec 25, 2024
252d399
Temp
diqiu50 Dec 25, 2024
1debe02
Merge remote-tracking branch 'gt/branch-gvfs-fuse-dev' into gvfs-pr4
diqiu50 Dec 25, 2024
573c80b
Update
diqiu50 Dec 25, 2024
f9c4546
refact config
diqiu50 Dec 26, 2024
40d1543
Update
diqiu50 Dec 26, 2024
7071618
Add error handling
diqiu50 Dec 26, 2024
81f5e71
fix testers
diqiu50 Dec 26, 2024
4fcd913
Update
diqiu50 Dec 26, 2024
757a486
Udpate
diqiu50 Dec 26, 2024
01e6f6e
Fix error
diqiu50 Dec 26, 2024
0677f2f
Add comments
diqiu50 Dec 26, 2024
0eecbd8
Fix some errors
diqiu50 Dec 26, 2024
f78adee
Support s3
diqiu50 Dec 26, 2024
e702a88
split fs creator
diqiu50 Dec 26, 2024
33e1588
Update conf
diqiu50 Dec 26, 2024
97ff491
Merge branch 'gvfs-pr4' into gvfs-pr5
diqiu50 Dec 26, 2024
b6d6201
Add opendal error
diqiu50 Dec 26, 2024
5fa74f6
Add
diqiu50 Dec 26, 2024
17ddd8f
Add
diqiu50 Dec 26, 2024
05ef46a
Update clients/filesystem-fuse/src/config.rs
diqiu50 Dec 27, 2024
254627d
Update clients/filesystem-fuse/src/gvfs_fuse.rs
diqiu50 Dec 27, 2024
b2558fc
Update clients/filesystem-fuse/src/config.rs
diqiu50 Dec 27, 2024
16437c3
Update for review
diqiu50 Dec 27, 2024
8296ea0
Update
diqiu50 Dec 27, 2024
2223415
Merge branch 'gvfs-pr4' into gvfs-pr5
diqiu50 Dec 27, 2024
def5957
Fix config error
diqiu50 Dec 27, 2024
86e5308
Fix error
diqiu50 Dec 27, 2024
bdd0928
Fix error
diqiu50 Dec 27, 2024
b2564cc
Fix config error
diqiu50 Dec 27, 2024
c0c4a72
Fix
diqiu50 Dec 27, 2024
671afca
Merge branch 'gvfs-pr4' into gvfs-pr5
diqiu50 Dec 27, 2024
06f5c23
Update main
diqiu50 Dec 27, 2024
fd78faf
Update
diqiu50 Dec 27, 2024
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
8 changes: 8 additions & 0 deletions clients/filesystem-fuse/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,19 @@ name = "gvfs_fuse"
[dependencies]
async-trait = "0.1"
bytes = "1.6.0"
config = "0.13"
dashmap = "6.1.0"
fuse3 = { version = "0.8.1", "features" = ["tokio-runtime", "unprivileged"] }
futures-util = "0.3.30"
libc = "0.2.168"
log = "0.4.22"
once_cell = "1.20.2"
opendal = { version = "0.46.0", features = ["services-s3"] }
reqwest = { version = "0.12.9", features = ["json"] }
serde = { version = "1.0.216", features = ["derive"] }
tokio = { version = "1.38.0", features = ["full"] }
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
urlencoding = "2.1.3"

[dev-dependencies]
mockito = "0.31"
39 changes: 39 additions & 0 deletions clients/filesystem-fuse/conf/gvfs_fuse.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# 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.

# fuse settings
[fuse]
default_mask = 0o600
fs_type = "memory"

[fuse.properties]
key1 = "value1"
key2 = "value2"
diqiu50 marked this conversation as resolved.
Show resolved Hide resolved

# filesystem settings
[filesystem]
block_size = 8192

# Gravitino settings
[gravitino]
gravitino_url = "http://localhost:8090"
metalake = "test"
diqiu50 marked this conversation as resolved.
Show resolved Hide resolved

# extent settings
[extent_config]
access_key = "XXX_access_key"
secret_key = "XXX_secret_key"
diqiu50 marked this conversation as resolved.
Show resolved Hide resolved
324 changes: 324 additions & 0 deletions clients/filesystem-fuse/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,324 @@
/*
* 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.
*/
use crate::error::ErrorCode::{ConfigNotFound, InvalidConfig};
use crate::utils::GvfsResult;
use config::{builder, Config};
use log::{info, warn};
use serde::Deserialize;
use std::collections::HashMap;
use std::fs;

const FUSE_DEFAULT_FILE_MASK: ConfigEntity<u32> = ConfigEntity::new(
FuseConfig::MODULE_NAME,
"default_file_mask",
"The default file mask for the FUSE filesystem",
0o600,
);

const FUSE_DEFAULT_DIR_MASK: ConfigEntity<u32> = ConfigEntity::new(
FuseConfig::MODULE_NAME,
"default_dir_mask",
"The default directory mask for the FUSE filesystem",
0o700,
);

const FUSE_FS_TYPE: ConfigEntity<&'static str> = ConfigEntity::new(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For naming conventions, I'd suggest we remove FUSE_ from the constant names and add DEFAULT_ to all default values for clarity.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's config entity. the default value is a member data. so the entity name use default is not good

FuseConfig::MODULE_NAME,
"fs_type",
"The type of the FUSE filesystem",
"memory",
);

const FUSE_CONFIG_PATH: ConfigEntity<&'static str> = ConfigEntity::new(
FuseConfig::MODULE_NAME,
"config_path",
"The path of the FUSE configuration file",
"/etc/gvfs/gvfs.toml",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Writing this file needs a root account, is that okay?

Copy link
Contributor Author

@diqiu50 diqiu50 Dec 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need to write the file

);

const FILESYSTEM_BLOCK_SIZE: ConfigEntity<u32> = ConfigEntity::new(
FilesystemConfig::MODULE_NAME,
"block_size",
"The block size of the gvfs fuse filesystem",
4096,
);

const GRAVITINO_URL: ConfigEntity<&'static str> = ConfigEntity::new(
GravitinoConfig::MODULE_NAME,
"gravitino_url",
"The URL of the Gravitino server",
"http://localhost:8090",
);

const GRAVITINO_METALAKE: ConfigEntity<&'static str> = ConfigEntity::new(
GravitinoConfig::MODULE_NAME,
"metalake",
"The metalake of the Gravitino server",
"",
);

struct ConfigEntity<T: 'static> {
module: &'static str,
name: &'static str,
description: &'static str,
default: T,
}

impl<T> ConfigEntity<T> {
const fn new(
module: &'static str,
name: &'static str,
description: &'static str,
default: T,
) -> Self {
ConfigEntity {
module: module,
name: name,
description: description,
default: default,
}
}
}

enum ConfigValue {
I32(ConfigEntity<i32>),
U32(ConfigEntity<u32>),
String(ConfigEntity<&'static str>),
Bool(ConfigEntity<bool>),
Float(ConfigEntity<f64>),
}

struct DefaultConfig {
configs: HashMap<String, ConfigValue>,
}

impl Default for DefaultConfig {
fn default() -> Self {
let mut configs = HashMap::new();

configs.insert(
Self::compose_key(FUSE_DEFAULT_FILE_MASK),
ConfigValue::U32(FUSE_DEFAULT_FILE_MASK),
);
configs.insert(
Self::compose_key(FUSE_DEFAULT_DIR_MASK),
ConfigValue::U32(FUSE_DEFAULT_DIR_MASK),
);
configs.insert(
Self::compose_key(FUSE_FS_TYPE),
ConfigValue::String(FUSE_FS_TYPE),
);
configs.insert(
Self::compose_key(FUSE_CONFIG_PATH),
ConfigValue::String(FUSE_CONFIG_PATH),
);
configs.insert(
Self::compose_key(GRAVITINO_URL),
ConfigValue::String(GRAVITINO_URL),
);
configs.insert(
Self::compose_key(GRAVITINO_METALAKE),
ConfigValue::String(GRAVITINO_METALAKE),
);
configs.insert(
Self::compose_key(FILESYSTEM_BLOCK_SIZE),
ConfigValue::U32(FILESYSTEM_BLOCK_SIZE),
);

DefaultConfig { configs }
}
}

impl DefaultConfig {
fn compose_key<T>(entity: ConfigEntity<T>) -> String {
format!("{}.{}", entity.module, entity.name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implies that we have some constraints on the values of entity.module, entity.name, right?
For example, they cannot contain ..

Copy link
Contributor Author

@diqiu50 diqiu50 Dec 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no such restriction. In our configuration class, we can set the configuration name corresponding to the variable name.

}
}

#[derive(Debug, Deserialize)]
pub struct AppConfig {
#[serde(default)]
pub fuse: FuseConfig,
#[serde(default)]
pub filesystem: FilesystemConfig,
#[serde(default)]
pub gravitino: GravitinoConfig,
#[serde(default)]
pub extent_config: HashMap<String, String>,
diqiu50 marked this conversation as resolved.
Show resolved Hide resolved
}

impl Default for AppConfig {
fn default() -> Self {
let builder = Self::crete_default_config_builder();
let conf = builder
.build()
.expect("Failed to build default configuration");
conf.try_deserialize::<AppConfig>()
.expect("Failed to deserialize default AppConfig")
}
}

type ConfigBuilder = builder::ConfigBuilder<builder::DefaultState>;

impl AppConfig {
fn crete_default_config_builder() -> ConfigBuilder {
let default = DefaultConfig::default();

default
.configs
.values()
.fold(
Config::builder(),
|builder, config_entity| match config_entity {
ConfigValue::I32(entity) => Self::add_config(builder, entity),
ConfigValue::U32(entity) => Self::add_config(builder, entity),
ConfigValue::String(entity) => Self::add_config(builder, entity),
ConfigValue::Bool(entity) => Self::add_config(builder, entity),
ConfigValue::Float(entity) => Self::add_config(builder, entity),
},
)
}

fn add_config<T: Clone + Into<config::Value>>(
builder: ConfigBuilder,
entity: &ConfigEntity<T>,
) -> ConfigBuilder {
let name = format!("{}.{}", entity.module, entity.name);
builder
.set_default(&name, entity.default.clone().into())
.unwrap_or_else(|e| panic!("Failed to set default for {}: {}", entity.name, e))
}

pub fn from_file(config_file_path: Option<&str>) -> GvfsResult<AppConfig> {
let builder = Self::crete_default_config_builder();

let config_path = {
if config_file_path.is_some() {
let path = config_file_path.unwrap();
//check config file exists
if fs::metadata(path).is_err() {
return Err(
ConfigNotFound.to_error("The configuration file not found".to_string())
);
}
info!("Use configuration file: {}", path);
path
} else {
//use default config
if fs::metadata(FUSE_CONFIG_PATH.default).is_err() {
warn!(
"The default configuration file not found, use the default configuration"
diqiu50 marked this conversation as resolved.
Show resolved Hide resolved
);
return Ok(AppConfig::default());
} else {
warn!(
"Use the default config file of {}",
diqiu50 marked this conversation as resolved.
Show resolved Hide resolved
FUSE_CONFIG_PATH.default
);
}
FUSE_CONFIG_PATH.default
}
};
let config = builder
.add_source(config::File::with_name(config_path).required(true))
.build();
if config.is_err() {
return Err(InvalidConfig.to_error("Failed to build configuration".to_string()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this error message more actionable?

}

let conf = config.unwrap();
let app_config = conf.try_deserialize::<AppConfig>();

if app_config.is_err() {
return Err(InvalidConfig.to_error("Failed to deserialize configuration".to_string()));
}
Ok(app_config.unwrap())
}
}

#[derive(Debug, Deserialize, Default)]
pub struct FuseConfig {
#[serde(default)]
pub default_file_mask: u32,
#[serde(default)]
pub default_dir_mask: u32,
#[serde(default)]
pub fs_type: String,
#[serde(default)]
pub config_path: String,
#[serde(default)]
pub properties: HashMap<String, String>,
}

impl FuseConfig {
const MODULE_NAME: &'static str = "fuse";
}

#[derive(Debug, Deserialize, Default)]
pub struct FilesystemConfig {
#[serde(default)]
pub block_size: u32,
}

impl FilesystemConfig {
const MODULE_NAME: &'static str = "filesystem";
}

#[derive(Debug, Deserialize, Default)]
pub struct GravitinoConfig {
#[serde(default)]
pub gravitino_url: String,
#[serde(default)]
pub metalake: String,
}

impl GravitinoConfig {
const MODULE_NAME: &'static str = "gravitino";
}

#[cfg(test)]
mod test {
use crate::config::AppConfig;

#[test]
fn test_config_from_file() {
let config = AppConfig::from_file(Some("tests/conf/gvfs_fuse_test.toml")).unwrap();
assert_eq!(config.fuse.default_file_mask, 0o600);
assert_eq!(config.filesystem.block_size, 8192);
assert_eq!(config.gravitino.gravitino_url, "http://localhost:8090");
assert_eq!(config.gravitino.metalake, "test");
assert_eq!(
config.extent_config.get("access_key"),
Some(&"XXX_access_key".to_string())
);
assert_eq!(
config.extent_config.get("secret_key"),
Some(&"XXX_secret_key".to_string())
);
}

#[test]
fn test_default_config() {
let config = AppConfig::default();
assert_eq!(config.fuse.default_file_mask, 0o600);
assert_eq!(config.filesystem.block_size, 4096);
assert_eq!(config.gravitino.gravitino_url, "http://localhost:8090");
assert_eq!(config.gravitino.metalake, "");
}
}
Loading
Loading