Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
diqiu50 committed Dec 27, 2024
1 parent 33e1588 commit 8296ea0
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 71 deletions.
13 changes: 6 additions & 7 deletions clients/filesystem-fuse/conf/gvfs_fuse.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@

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

[fuse.properties]
key1 = "value1"
key2 = "value2"

# filesystem settings
[filesystem]
Expand All @@ -31,9 +30,9 @@ block_size = 8192
# Gravitino settings
[gravitino]
gravitino_url = "http://localhost:8090"
metalake = "test"
metalake = "your_metalake"

# extent settings
[extent_config]
access_key = "XXX_access_key"
secret_key = "XXX_secret_key"
[extend_config]
access_key = "your access_key"
secret_key = "your_secret_key"
90 changes: 48 additions & 42 deletions clients/filesystem-fuse/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,65 +19,65 @@
use crate::error::ErrorCode::{ConfigNotFound, InvalidConfig};
use crate::utils::GvfsResult;
use config::{builder, Config};
use log::{info, warn};
use log::{error, info, warn};
use serde::Deserialize;
use std::collections::HashMap;
use std::fs;

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

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

const FUSE_FS_TYPE: ConfigEntity<&'static str> = ConfigEntity::new(
pub(crate) const CONF_FUSE_FS_TYPE: ConfigEntity<&'static str> = ConfigEntity::new(
FuseConfig::MODULE_NAME,
"fs_type",
"The type of the FUSE filesystem",
"memory",
);

const FUSE_CONFIG_PATH: ConfigEntity<&'static str> = ConfigEntity::new(
pub(crate) const CONF_FUSE_CONFIG_PATH: ConfigEntity<&'static str> = ConfigEntity::new(
FuseConfig::MODULE_NAME,
"config_path",
"The path of the FUSE configuration file",
"/etc/gvfs/gvfs.toml",
);

const FILESYSTEM_BLOCK_SIZE: ConfigEntity<u32> = ConfigEntity::new(
pub(crate) const CONF_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(
pub(crate) const CONF_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(
pub(crate) const CONF_GRAVITINO_METALAKE: ConfigEntity<&'static str> = ConfigEntity::new(
GravitinoConfig::MODULE_NAME,
"metalake",
"The metalake of the Gravitino server",
"",
);

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

impl<T> ConfigEntity<T> {
Expand Down Expand Up @@ -113,32 +113,32 @@ impl Default for DefaultConfig {
let mut configs = HashMap::new();

configs.insert(
Self::compose_key(FUSE_DEFAULT_FILE_MASK),
ConfigValue::U32(FUSE_DEFAULT_FILE_MASK),
Self::compose_key(CONF_FUSE_FILE_MASK),
ConfigValue::U32(CONF_FUSE_FILE_MASK),
);
configs.insert(
Self::compose_key(FUSE_DEFAULT_DIR_MASK),
ConfigValue::U32(FUSE_DEFAULT_DIR_MASK),
Self::compose_key(CONF_FUSE_DIR_MASK),
ConfigValue::U32(CONF_FUSE_DIR_MASK),
);
configs.insert(
Self::compose_key(FUSE_FS_TYPE),
ConfigValue::String(FUSE_FS_TYPE),
Self::compose_key(CONF_FUSE_FS_TYPE),
ConfigValue::String(CONF_FUSE_FS_TYPE),
);
configs.insert(
Self::compose_key(FUSE_CONFIG_PATH),
ConfigValue::String(FUSE_CONFIG_PATH),
Self::compose_key(CONF_FUSE_CONFIG_PATH),
ConfigValue::String(CONF_FUSE_CONFIG_PATH),
);
configs.insert(
Self::compose_key(GRAVITINO_URL),
ConfigValue::String(GRAVITINO_URL),
Self::compose_key(CONF_GRAVITINO_URL),
ConfigValue::String(CONF_GRAVITINO_URL),
);
configs.insert(
Self::compose_key(GRAVITINO_METALAKE),
ConfigValue::String(GRAVITINO_METALAKE),
Self::compose_key(CONF_GRAVITINO_METALAKE),
ConfigValue::String(CONF_GRAVITINO_METALAKE),
);
configs.insert(
Self::compose_key(FILESYSTEM_BLOCK_SIZE),
ConfigValue::U32(FILESYSTEM_BLOCK_SIZE),
Self::compose_key(CONF_FILESYSTEM_BLOCK_SIZE),
ConfigValue::U32(CONF_FILESYSTEM_BLOCK_SIZE),
);

DefaultConfig { configs }
Expand All @@ -160,7 +160,7 @@ pub struct AppConfig {
#[serde(default)]
pub gravitino: GravitinoConfig,
#[serde(default)]
pub extent_config: HashMap<String, String>,
pub extend_config: HashMap<String, String>,
}

impl Default for AppConfig {
Expand Down Expand Up @@ -221,32 +221,36 @@ impl AppConfig {
path
} else {
//use default config
if fs::metadata(FUSE_CONFIG_PATH.default).is_err() {
if fs::metadata(CONF_FUSE_CONFIG_PATH.default).is_err() {
warn!(
"The default configuration file not found, use the default configuration"
"The default configuration file is not found, using the default configuration"
);
return Ok(AppConfig::default());
} else {
warn!(
"Use the default config file of {}",
FUSE_CONFIG_PATH.default
"Using the default config file {}",
CONF_FUSE_CONFIG_PATH.default
);
}
FUSE_CONFIG_PATH.default
CONF_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()));
if let Err(e) = config {
let msg = format!("Failed to build configuration: {}", e);
error!("{}", msg);
return Err(InvalidConfig.to_error(msg));
}

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()));
if let Err(e) = app_config {
let msg = format!("Failed to deserialize configuration: {}", e);
error!("{}", msg);
return Err(InvalidConfig.to_error(msg));
}
Ok(app_config.unwrap())
}
Expand All @@ -255,9 +259,9 @@ impl AppConfig {
#[derive(Debug, Deserialize, Default)]
pub struct FuseConfig {
#[serde(default)]
pub default_file_mask: u32,
pub file_mask: u32,
#[serde(default)]
pub default_dir_mask: u32,
pub dir_mask: u32,
#[serde(default)]
pub fs_type: String,
#[serde(default)]
Expand Down Expand Up @@ -299,24 +303,26 @@ mod test {
#[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.fuse.file_mask, 0o644);
assert_eq!(config.fuse.dir_mask, 0o755);
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"),
config.extend_config.get("access_key"),
Some(&"XXX_access_key".to_string())
);
assert_eq!(
config.extent_config.get("secret_key"),
config.extend_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.fuse.file_mask, 0o600);
assert_eq!(config.fuse.dir_mask, 0o700);
assert_eq!(config.filesystem.block_size, 4096);
assert_eq!(config.gravitino.gravitino_url, "http://localhost:8090");
assert_eq!(config.gravitino.metalake, "");
Expand Down
17 changes: 10 additions & 7 deletions clients/filesystem-fuse/src/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
use crate::config::{
AppConfig, CONF_FILESYSTEM_BLOCK_SIZE, CONF_FUSE_DIR_MASK, CONF_FUSE_FILE_MASK,
};
use crate::opened_file::{FileHandle, OpenFileFlags, OpenedFile};
use async_trait::async_trait;
use bytes::Bytes;
Expand Down Expand Up @@ -152,23 +155,23 @@ pub(crate) struct FileSystemContext {
}

impl FileSystemContext {
pub(crate) fn new(uid: u32, gid: u32) -> Self {
pub(crate) fn new(uid: u32, gid: u32, config: &AppConfig) -> Self {
FileSystemContext {
uid,
gid,
default_file_perm: 0o644,
default_dir_perm: 0o755,
block_size: 4 * 1024,
default_file_perm: config.fuse.file_mask as u16,
default_dir_perm: config.fuse.dir_mask as u16,
block_size: config.filesystem.block_size,
}
}

pub(crate) fn default() -> Self {
FileSystemContext {
uid: 0,
gid: 0,
default_file_perm: 0o644,
default_dir_perm: 0o755,
block_size: 4 * 1024,
default_file_perm: CONF_FUSE_FILE_MASK.default as u16,
default_dir_perm: CONF_FUSE_DIR_MASK.default as u16,
block_size: CONF_FILESYSTEM_BLOCK_SIZE.default,
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions clients/filesystem-fuse/src/gravitino_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ pub(crate) struct Fileset {

#[derive(Debug, Deserialize)]
struct FilesetResponse {
code: i32,
code: u32,
fileset: Fileset,
}

#[derive(Debug, Deserialize)]
struct FileLocationResponse {
code: i32,
code: u32,
#[serde(rename = "fileLocation")]
location: String,
}
Expand All @@ -52,15 +52,15 @@ pub(crate) struct GravitinoClient {
gravitino_uri: String,
metalake: String,

http_client: Client,
client: Client,
}

impl GravitinoClient {
pub fn new(config: &GravitinoConfig) -> Self {
Self {
gravitino_uri: config.gravitino_url.clone(),
metalake: config.metalake.clone(),
http_client: Client::new(),
client: Client::new(),
}
}

Expand Down Expand Up @@ -94,7 +94,7 @@ impl GravitinoClient {
T: for<'de> Deserialize<'de>,
{
let http_resp =
self.http_client.get(url).send().await.map_err(|e| {
self.client.get(url).send().await.map_err(|e| {
GvfsError::RestError(format!("Failed to send request to {}", url), e)
})?;

Expand Down
8 changes: 1 addition & 7 deletions clients/filesystem-fuse/src/gvfs_fuse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,7 @@ pub(crate) async fn create_fuse_fs(
) -> GvfsResult<CreateFsResult> {
let uid = unsafe { libc::getuid() };
let gid = unsafe { libc::getgid() };
let fs_context = FileSystemContext {
uid: uid,
gid: gid,
default_file_perm: 0o644,
default_dir_perm: 0o755,
block_size: 4 * 1024,
};
let fs_context = FileSystemContext::new(uid, gid, config);
let fs = create_path_fs(mount_from, config, &fs_context).await?;
create_raw_fs(fs, config, fs_context).await
}
Expand Down
1 change: 1 addition & 0 deletions clients/filesystem-fuse/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use tokio::signal;
async fn main() -> fuse3::Result<()> {
tracing_subscriber::fmt().init();

//todo(read config file from args)
let config = AppConfig::from_file(Some("conf/gvfs_fuse.toml)"));
if let Err(e) = &config {
error!("Failed to load config: {:?}", e);
Expand Down
3 changes: 2 additions & 1 deletion clients/filesystem-fuse/tests/conf/gvfs_fuse_memory.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

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

[fuse.properties]
Expand Down
5 changes: 3 additions & 2 deletions clients/filesystem-fuse/tests/conf/gvfs_fuse_test.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

# fuse settings
[fuse]
default_mask = 0o600
file_mask= 0o644
dir_mask= 0o755
fs_type = "memory"

[fuse.properties]
Expand All @@ -34,6 +35,6 @@ gravitino_url = "http://localhost:8090"
metalake = "test"

# extent settings
[extent_config]
[extend_config]
access_key = "XXX_access_key"
secret_key = "XXX_secret_key"

0 comments on commit 8296ea0

Please sign in to comment.