diff --git a/clients/filesystem-fuse/conf/gvfs_fuse.toml b/clients/filesystem-fuse/conf/gvfs_fuse.toml index ead80bce1f1..da153bea43a 100644 --- a/clients/filesystem-fuse/conf/gvfs_fuse.toml +++ b/clients/filesystem-fuse/conf/gvfs_fuse.toml @@ -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] @@ -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" diff --git a/clients/filesystem-fuse/src/config.rs b/clients/filesystem-fuse/src/config.rs index ad62975f4c0..a88bedf7bbd 100644 --- a/clients/filesystem-fuse/src/config.rs +++ b/clients/filesystem-fuse/src/config.rs @@ -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 = ConfigEntity::new( +pub(crate) const CONF_FUSE_FILE_MASK: ConfigEntity = 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 = ConfigEntity::new( +pub(crate) const CONF_FUSE_DIR_MASK: ConfigEntity = 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 = ConfigEntity::new( +pub(crate) const CONF_FILESYSTEM_BLOCK_SIZE: ConfigEntity = 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 { +pub(crate) struct ConfigEntity { module: &'static str, name: &'static str, description: &'static str, - default: T, + pub(crate) default: T, } impl ConfigEntity { @@ -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 } @@ -160,7 +160,7 @@ pub struct AppConfig { #[serde(default)] pub gravitino: GravitinoConfig, #[serde(default)] - pub extent_config: HashMap, + pub extend_config: HashMap, } impl Default for AppConfig { @@ -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::(); - 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()) } @@ -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)] @@ -299,16 +303,17 @@ 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()) ); } @@ -316,7 +321,8 @@ mod test { #[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, ""); diff --git a/clients/filesystem-fuse/src/filesystem.rs b/clients/filesystem-fuse/src/filesystem.rs index 4d843a5eb3d..646aebcfa4e 100644 --- a/clients/filesystem-fuse/src/filesystem.rs +++ b/clients/filesystem-fuse/src/filesystem.rs @@ -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; @@ -152,13 +155,13 @@ 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, } } @@ -166,9 +169,9 @@ impl FileSystemContext { 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, } } } diff --git a/clients/filesystem-fuse/src/gravitino_client.rs b/clients/filesystem-fuse/src/gravitino_client.rs index 94c4fcb4908..d624c913090 100644 --- a/clients/filesystem-fuse/src/gravitino_client.rs +++ b/clients/filesystem-fuse/src/gravitino_client.rs @@ -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, } @@ -52,7 +52,7 @@ pub(crate) struct GravitinoClient { gravitino_uri: String, metalake: String, - http_client: Client, + client: Client, } impl GravitinoClient { @@ -60,7 +60,7 @@ impl GravitinoClient { Self { gravitino_uri: config.gravitino_url.clone(), metalake: config.metalake.clone(), - http_client: Client::new(), + client: Client::new(), } } @@ -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) })?; diff --git a/clients/filesystem-fuse/src/gvfs_fuse.rs b/clients/filesystem-fuse/src/gvfs_fuse.rs index 31340ae3251..4b9ed13f480 100644 --- a/clients/filesystem-fuse/src/gvfs_fuse.rs +++ b/clients/filesystem-fuse/src/gvfs_fuse.rs @@ -83,13 +83,7 @@ pub(crate) async fn create_fuse_fs( ) -> GvfsResult { 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 } diff --git a/clients/filesystem-fuse/src/main.rs b/clients/filesystem-fuse/src/main.rs index 014d3ea4f3d..327234c8b41 100644 --- a/clients/filesystem-fuse/src/main.rs +++ b/clients/filesystem-fuse/src/main.rs @@ -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); diff --git a/clients/filesystem-fuse/tests/conf/gvfs_fuse_memory.toml b/clients/filesystem-fuse/tests/conf/gvfs_fuse_memory.toml index ead80bce1f1..71302a96ed1 100644 --- a/clients/filesystem-fuse/tests/conf/gvfs_fuse_memory.toml +++ b/clients/filesystem-fuse/tests/conf/gvfs_fuse_memory.toml @@ -17,7 +17,8 @@ # fuse settings [fuse] -default_mask = 0o600 +file_mask= 0o600 +dir_mask= 0o700 fs_type = "memory" [fuse.properties] diff --git a/clients/filesystem-fuse/tests/conf/gvfs_fuse_test.toml b/clients/filesystem-fuse/tests/conf/gvfs_fuse_test.toml index ead80bce1f1..7c32b388e9d 100644 --- a/clients/filesystem-fuse/tests/conf/gvfs_fuse_test.toml +++ b/clients/filesystem-fuse/tests/conf/gvfs_fuse_test.toml @@ -17,7 +17,8 @@ # fuse settings [fuse] -default_mask = 0o600 +file_mask= 0o644 +dir_mask= 0o755 fs_type = "memory" [fuse.properties] @@ -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"