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

[#6357] feat (gvfs-fuse): Passing file type argument in the Filesystem::stat() to improve the performance of open_dal_filesystem #6358

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
2 changes: 2 additions & 0 deletions clients/filesystem-fuse/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ name = "gvfs_fuse"
[dependencies]
async-trait = "0.1"
bytes = "1.6.0"
clap = { version = "4.5.24", features = ["derive"] }
config = "0.13"
daemonize = "0.5.0"
dashmap = "6.1.0"
fuse3 = { version = "0.8.1", "features" = ["tokio-runtime", "unprivileged"] }
futures-util = "0.3.30"
Expand Down
1 change: 1 addition & 0 deletions clients/filesystem-fuse/conf/gvfs_fuse.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
file_mask = 0o600
dir_mask = 0o700
fs_type = "memory"
data_path = "target/gvfs-fuse"

[fuse.properties]

Expand Down
57 changes: 57 additions & 0 deletions clients/filesystem-fuse/src/command_args.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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 clap::{Parser, Subcommand};

#[derive(Parser, Debug)]
#[command(
name = "gvfs-fuse",
version = "1.0",
about = "A FUSE-based file system client"
)]
pub(crate) struct Arguments {
#[command(subcommand)]
pub(crate) command: Commands,
}

#[derive(Subcommand, Debug)]
pub(crate) enum Commands {
Mount {
#[arg(help = "Mount point for the filesystem")]
mount_point: String,

#[arg(help = "The URI of the GVFS fileset")]
location: String,

#[arg(short, long)]
config: Option<String>,

#[arg(short, long, help = "Debug level", default_value_t = 0)]
debug: u8,

#[arg(short, long, default_value_t = false, help = "Run in foreground")]
foreground: bool,
},
Umount {
#[arg(help = "Mount point to umount")]
mount_point: String,

#[arg(short, long, help = "Force umount")]
force: bool,
},
}
72 changes: 54 additions & 18 deletions clients/filesystem-fuse/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use serde::Deserialize;
use std::collections::HashMap;
use std::fs;

// FuseConfig
pub(crate) const CONF_FUSE_FILE_MASK: ConfigEntity<u32> = ConfigEntity::new(
FuseConfig::MODULE_NAME,
"file_mask",
Expand All @@ -45,20 +46,36 @@ pub(crate) const CONF_FUSE_FS_TYPE: ConfigEntity<&'static str> = ConfigEntity::n
"memory",
);

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

pub(crate) const CONF_FUSE_DATA_DIR: ConfigEntity<&'static str> = ConfigEntity::new(
FuseConfig::MODULE_NAME,
"data_dir",
"The data path of GVFS FUSE",
"/var/data/gvfs-fuse",
);

pub(crate) const CONF_FUSE_LOG_DIR: ConfigEntity<&'static str> = ConfigEntity::new(
FuseConfig::MODULE_NAME,
"log_dir",
"The log path of GVFS FUSE",
"logs", //relative to the data path
);

// FilesystemConfig
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,
);

// GravitinoConfig
pub(crate) const CONF_GRAVITINO_URI: ConfigEntity<&'static str> = ConfigEntity::new(
GravitinoConfig::MODULE_NAME,
"uri",
Expand Down Expand Up @@ -125,22 +142,32 @@ impl Default for DefaultConfig {
ConfigValue::String(CONF_FUSE_FS_TYPE),
);
configs.insert(
Self::compose_key(CONF_FUSE_CONFIG_PATH),
ConfigValue::String(CONF_FUSE_CONFIG_PATH),
Self::compose_key(CONF_FUSE_CONFIG_FILE_PATH),
ConfigValue::String(CONF_FUSE_CONFIG_FILE_PATH),
);
configs.insert(
Self::compose_key(CONF_GRAVITINO_URI),
ConfigValue::String(CONF_GRAVITINO_URI),
Self::compose_key(CONF_FUSE_DATA_DIR),
ConfigValue::String(CONF_FUSE_DATA_DIR),
);
configs.insert(
Self::compose_key(CONF_GRAVITINO_METALAKE),
ConfigValue::String(CONF_GRAVITINO_METALAKE),
Self::compose_key(CONF_FUSE_LOG_DIR),
ConfigValue::String(CONF_FUSE_LOG_DIR),
);

configs.insert(
Self::compose_key(CONF_FILESYSTEM_BLOCK_SIZE),
ConfigValue::U32(CONF_FILESYSTEM_BLOCK_SIZE),
);

configs.insert(
Self::compose_key(CONF_GRAVITINO_URI),
ConfigValue::String(CONF_GRAVITINO_URI),
);
configs.insert(
Self::compose_key(CONF_GRAVITINO_METALAKE),
ConfigValue::String(CONF_GRAVITINO_METALAKE),
);

DefaultConfig { configs }
}
}
Expand Down Expand Up @@ -205,38 +232,39 @@ impl AppConfig {
.unwrap_or_else(|e| panic!("Failed to set default for {}: {}", entity.name, e))
}

pub fn from_file(config_file_path: Option<&str>) -> GvfsResult<AppConfig> {
pub fn from_file(config_file_path: Option<String>) -> 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() {
if fs::metadata(&path).is_err() {
return Err(
ConfigNotFound.to_error("The configuration file not found".to_string())
);
}
info!("Use configuration file: {}", path);
info!("Use configuration file: {}", &path);
path
} else {
//use default config
if fs::metadata(CONF_FUSE_CONFIG_PATH.default).is_err() {
if fs::metadata(CONF_FUSE_CONFIG_FILE_PATH.default).is_err() {
//use default config
warn!(
"The default configuration file is not found, using the default configuration"
);
return Ok(AppConfig::default());
} else {
//use the default configuration file
warn!(
"Using the default config file {}",
CONF_FUSE_CONFIG_PATH.default
CONF_FUSE_CONFIG_FILE_PATH.default
);
}
CONF_FUSE_CONFIG_PATH.default
CONF_FUSE_CONFIG_FILE_PATH.default.to_string()
}
};
let config = builder
.add_source(config::File::with_name(config_path).required(true))
.add_source(config::File::with_name(&config_path).required(true))
.build();
if let Err(e) = config {
let msg = format!("Failed to build configuration: {}", e);
Expand Down Expand Up @@ -265,7 +293,11 @@ pub struct FuseConfig {
#[serde(default)]
pub fs_type: String,
#[serde(default)]
pub config_path: String,
pub config_file_path: String,
#[serde(default)]
pub data_dir: String,
#[serde(default)]
pub log_dir: String,
#[serde(default)]
pub properties: HashMap<String, String>,
}
Expand Down Expand Up @@ -302,9 +334,11 @@ mod test {

#[test]
fn test_config_from_file() {
let config = AppConfig::from_file(Some("tests/conf/config_test.toml")).unwrap();
let config = AppConfig::from_file(Some("tests/conf/config_test.toml".to_string())).unwrap();
assert_eq!(config.fuse.file_mask, 0o644);
assert_eq!(config.fuse.dir_mask, 0o755);
assert_eq!(config.fuse.data_dir, "/target/gvfs-fuse");
assert_eq!(config.fuse.log_dir, "/target/gvfs-fuse/logs");
assert_eq!(config.filesystem.block_size, 8192);
assert_eq!(config.gravitino.uri, "http://localhost:8090");
assert_eq!(config.gravitino.metalake, "test");
Expand All @@ -323,6 +357,8 @@ mod test {
let config = AppConfig::default();
assert_eq!(config.fuse.file_mask, 0o600);
assert_eq!(config.fuse.dir_mask, 0o700);
assert_eq!(config.fuse.data_dir, "/var/data/gvfs-fuse");
assert_eq!(config.fuse.log_dir, "logs");
assert_eq!(config.filesystem.block_size, 4096);
assert_eq!(config.gravitino.uri, "http://localhost:8090");
assert_eq!(config.gravitino.metalake, "");
Expand Down
33 changes: 25 additions & 8 deletions clients/filesystem-fuse/src/default_raw_filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use crate::opened_file::{FileHandle, OpenFileFlags, OpenedFile};
use crate::opened_file_manager::OpenedFileManager;
use async_trait::async_trait;
use bytes::Bytes;
use fuse3::FileType::{Directory, RegularFile};
use fuse3::{Errno, FileType};
use std::collections::HashMap;
use std::ffi::OsStr;
Expand Down Expand Up @@ -86,7 +87,12 @@ impl<T: PathFileSystem> DefaultRawFileSystem<T> {
None => {
// allocate new file id
file_stat.set_file_id(parent_file_id, self.next_file_id());
file_manager.insert(file_stat.parent_file_id, file_stat.file_id, &file_stat.path);
file_manager.insert(
file_stat.parent_file_id,
file_stat.file_id,
&file_stat.path,
file_stat.kind,
);
}
Some(file) => {
// use the exist file id
Expand Down Expand Up @@ -130,9 +136,15 @@ impl<T: PathFileSystem> DefaultRawFileSystem<T> {
file_manager.remove(path);
}

async fn insert_file_entry_locked(&self, parent_file_id: u64, file_id: u64, path: &Path) {
async fn insert_file_entry_locked(
&self,
parent_file_id: u64,
file_id: u64,
path: &Path,
kind: FileType,
) {
let mut file_manager = self.file_entry_manager.write().await;
file_manager.insert(parent_file_id, file_id, path);
file_manager.insert(parent_file_id, file_id, path, kind);
}

fn get_meta_file_stat(&self) -> FileStat {
Expand All @@ -159,13 +171,15 @@ impl<T: PathFileSystem> RawFileSystem for DefaultRawFileSystem<T> {
ROOT_DIR_PARENT_FILE_ID,
ROOT_DIR_FILE_ID,
Path::new(ROOT_DIR_PATH),
Directory,
)
.await;

self.insert_file_entry_locked(
ROOT_DIR_FILE_ID,
FS_META_FILE_ID,
Path::new(FS_META_FILE_PATH),
RegularFile,
)
.await;
self.fs.init().await
Expand Down Expand Up @@ -197,7 +211,7 @@ impl<T: PathFileSystem> RawFileSystem for DefaultRawFileSystem<T> {
}

let file_entry = self.get_file_entry(file_id).await?;
let mut file_stat = self.fs.stat(&file_entry.path).await?;
let mut file_stat = self.fs.stat(&file_entry.path, file_entry.kind).await?;
file_stat.set_file_id(file_entry.parent_file_id, file_entry.file_id);
Ok(file_stat)
}
Expand All @@ -209,7 +223,7 @@ impl<T: PathFileSystem> RawFileSystem for DefaultRawFileSystem<T> {

let parent_file_entry = self.get_file_entry(parent_file_id).await?;
let path = parent_file_entry.path.join(name);
let mut file_stat = self.fs.stat(&path).await?;
let mut file_stat = self.fs.lookup(&path).await?;
// fill the file id to file stat
self.resolve_file_id_to_filestat(&mut file_stat, parent_file_id)
.await;
Expand Down Expand Up @@ -270,6 +284,7 @@ impl<T: PathFileSystem> RawFileSystem for DefaultRawFileSystem<T> {
parent_file_id,
file_without_id.file_stat.file_id,
&file_without_id.file_stat.path,
RegularFile,
)
.await;

Expand All @@ -287,7 +302,7 @@ impl<T: PathFileSystem> RawFileSystem for DefaultRawFileSystem<T> {
filestat.set_file_id(parent_file_id, self.next_file_id());

// insert the new file to file entry manager
self.insert_file_entry_locked(parent_file_id, filestat.file_id, &filestat.path)
self.insert_file_entry_locked(parent_file_id, filestat.file_id, &filestat.path, Directory)
.await;
Ok(filestat.file_id)
}
Expand Down Expand Up @@ -401,6 +416,7 @@ struct FileEntry {
file_id: u64,
parent_file_id: u64,
path: PathBuf,
kind: FileType,
}

/// FileEntryManager is manage all the file entries in memory. it is used manger the file relationship and name mapping.
Expand Down Expand Up @@ -428,11 +444,12 @@ impl FileEntryManager {
self.file_path_map.get(path).cloned()
}

fn insert(&mut self, parent_file_id: u64, file_id: u64, path: &Path) {
fn insert(&mut self, parent_file_id: u64, file_id: u64, path: &Path, kind: FileType) {
let file_entry = FileEntry {
file_id,
parent_file_id,
path: path.into(),
kind: kind,
};
self.file_id_map.insert(file_id, file_entry.clone());
self.file_path_map.insert(path.into(), file_entry);
Expand All @@ -452,7 +469,7 @@ mod tests {
#[test]
fn test_file_entry_manager() {
let mut manager = FileEntryManager::new();
manager.insert(1, 2, Path::new("a/b"));
manager.insert(1, 2, Path::new("a/b"), Directory);
let file = manager.get_file_entry_by_id(2).unwrap();
assert_eq!(file.file_id, 2);
assert_eq!(file.parent_file_id, 1);
Expand Down
Loading
Loading