Skip to content

Commit

Permalink
feat: macos overlay impl
Browse files Browse the repository at this point in the history
  • Loading branch information
akitaSummer committed Feb 19, 2024
1 parent ee5bf6d commit 6895e3b
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 27 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock

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

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ xattr = "1.0.1"
vmm-sys-util = "0.11.0"

[patch.crates-io]
fuse-backend-rs = { git = 'https://github.com/weizhang555/fuse-backend-rs.git', branch = 'overlay-impl' }

# fuse-backend-rs = { git = 'https://github.com/weizhang555/fuse-backend-rs.git', branch = 'overlay-impl' }
fuse-backend-rs = { git = "https://github.com/cnpm/fuse-backend-rs.git", branch = "overlay-impl", features = [
"fuse-t",
] }
[features]
default = [
"fuse-backend-rs/fusedev",
Expand Down
50 changes: 45 additions & 5 deletions api/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,47 @@ impl FromStr for ConfigV2 {
Err(Error::new(ErrorKind::InvalidInput, "invalid configuration"))
};
}
if let Ok(v) = serde_json::from_str::<RafsConfig>(s) {
if let Ok(v) = ConfigV2::try_from(v) {
if v.validate() {
return Ok(v);
}
// if let Ok(v) = serde_json::from_str::<RafsConfig>(s) {
// if let Ok(v) = ConfigV2::try_from(v) {
// if v.validate() {
// return Ok(v);
// }
// }
// }
if let Ok(v) = serde_json::from_str::<NewRafsConfig>(s) {
// if let Ok(v) = ConfigV2::try_from(v) {
// if v.validate() {
// return Ok(v);
// }
// }
let o = v.overlay;
let v = v.rafs;

let backend: BackendConfigV2 = (&v.device.backend).try_into()?;
let mut cache: CacheConfigV2 = (&v.device.cache).try_into()?;
let rafs = RafsConfigV2 {
mode: v.mode,
user_io_batch_size: v.user_io_batch_size,
validate: v.digest_validate,
enable_xattr: v.enable_xattr,
iostats_files: v.iostats_files,
access_pattern: v.access_pattern,
latest_read_files: v.latest_read_files,
prefetch: v.fs_prefetch.into(),
};
if !cache.prefetch.enable && rafs.prefetch.enable {
cache.prefetch = rafs.prefetch.clone();
}

return Ok(ConfigV2 {
version: 2,
id: v.device.id,
backend: Some(backend),
cache: Some(cache),
rafs: Some(rafs),
overlay: o,
internal: ConfigV2Internal::default(),
});
}
Err(Error::new(
ErrorKind::InvalidInput,
Expand Down Expand Up @@ -1343,6 +1378,11 @@ struct FactoryConfig {
pub cache: CacheConfig,
}

#[derive(Clone, Default, Deserialize)]
struct NewRafsConfig {
pub rafs: RafsConfig,
pub overlay: Option<OverlayConfig>,
}
/// Rafs storage backend configuration information.
#[derive(Clone, Default, Deserialize)]
struct RafsConfig {
Expand Down
2 changes: 1 addition & 1 deletion clib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ crate-type = ["cdylib", "staticlib"]
[dependencies]
libc = "0.2.137"
log = "0.4.17"
fuse-backend-rs = "^0.11.0"
fuse-backend-rs = { version = "^0.11.0", features = ["fuse-t"] }
nydus-api = { version = "0.3", path = "../api" }
nydus-rafs = { version = "0.3.1", path = "../rafs" }
nydus-storage = { version = "0.6.3", path = "../storage" }
Expand Down
2 changes: 1 addition & 1 deletion rafs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ nix = "0.24"
serde = { version = "1.0.110", features = ["serde_derive", "rc"] }
serde_json = "1.0.53"
vm-memory = "0.10"
fuse-backend-rs = "^0.11.0"
fuse-backend-rs = { version = "^0.11.0", features = ["fuse-t"] }
thiserror = "1"

nydus-api = { version = "0.3", path = "../api" }
Expand Down
1 change: 0 additions & 1 deletion rafs/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,6 @@ impl FileSystem for Rafs {
}
}

#[cfg(target_os = "linux")]
// Let Rafs works as an OverlayFs layer.
impl Layer for Rafs {
fn root_inode(&self) -> Self::Inode {
Expand Down
2 changes: 1 addition & 1 deletion service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ resolver = "2"
[dependencies]
bytes = { version = "1", optional = true }
dbs-allocator = { version = "0.1.1", optional = true }
fuse-backend-rs = { version = "^0.11.0", features = ["persist"] }
fuse-backend-rs = { version = "^0.11.0", features = ["persist", 'fuse-t'] }
libc = "0.2"
log = "0.4.8"
mio = { version = "0.8", features = ["os-poll", "os-ext"] }
Expand Down
29 changes: 16 additions & 13 deletions service/src/fs_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@ use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::sync::{Arc, MutexGuard};

#[cfg(target_os = "linux")]
use fuse_backend_rs::api::filesystem::{FileSystem, FsOptions, Layer};
use fuse_backend_rs::api::vfs::VfsError;
use fuse_backend_rs::api::{BackFileSystem, Vfs};
#[cfg(target_os = "linux")]
use fuse_backend_rs::overlayfs::{config::Config as overlay_config, OverlayFs};
#[cfg(target_os = "linux")]
use fuse_backend_rs::passthrough::{CachePolicy, Config as passthrough_config, PassthroughFs};
use nydus_api::ConfigV2;
use nydus_rafs::fs::Rafs;
Expand Down Expand Up @@ -256,11 +253,11 @@ fn fs_backend_factory(cmd: &FsBackendMountCmd) -> Result<BackFileSystem> {
// TODO: check workdir and upperdir params.

// Create an overlay upper layer with passthroughfs.
#[cfg(target_os = "macos")]
return Err(Error::InvalidArguments(String::from(
"OverlayFs isn't supported since passthroughfs isn't supported",
)));
#[cfg(target_os = "linux")]
// #[cfg(target_os = "macos")]
// return Err(Error::InvalidArguments(String::from(
// "OverlayFs isn't supported since passthroughfs isn't supported",
// )));
// #[cfg(target_os = "linux")]
{
let fs_cfg = passthrough_config {
// Use upper_dir as root_dir as rw layer.
Expand All @@ -273,10 +270,16 @@ fn fs_backend_factory(cmd: &FsBackendMountCmd) -> Result<BackFileSystem> {
cache_policy: CachePolicy::Always,
..Default::default()
};
#[cfg(target_os = "linux")]
let fsopts = FsOptions::WRITEBACK_CACHE
| FsOptions::ZERO_MESSAGE_OPEN
| FsOptions::ZERO_MESSAGE_OPENDIR;

#[cfg(target_os = "macos")]
let fsopts: FsOptions = FsOptions::ASYNC_READ
| FsOptions::BIG_WRITES
| FsOptions::ATOMIC_O_TRUNC;

let passthrough_fs = PassthroughFs::<()>::new(fs_cfg)
.map_err(|e| Error::InvalidConfig(format!("{}", e)))?;
passthrough_fs.init(fsopts).map_err(Error::PassthroughFs)?;
Expand Down Expand Up @@ -318,11 +321,11 @@ fn fs_backend_factory(cmd: &FsBackendMountCmd) -> Result<BackFileSystem> {
}
}
FsBackendType::PassthroughFs => {
#[cfg(target_os = "macos")]
return Err(Error::InvalidArguments(String::from(
"not support passthroughfs",
)));
#[cfg(target_os = "linux")]
// #[cfg(target_os = "macos")]
// return Err(Error::InvalidArguments(String::from(
// "not support passthroughfs",
// )));
// #[cfg(target_os = "linux")]
{
// Vfs by default enables no_open and writeback, passthroughfs
// needs to specify them explicitly.
Expand Down
7 changes: 5 additions & 2 deletions storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ leaky-bucket = { version = "0.12.1", optional = true }
libc = "0.2"
log = "0.4.8"
nix = "0.24"
reqwest = { version = "0.11.14", features = ["blocking", "json"], optional = true }
reqwest = { version = "0.11.14", features = [
"blocking",
"json",
], optional = true }
rusqlite = { version = "0.30", features = ["bundled"], optional = true }
r2d2 = { version = "0.8", optional = true }
r2d2_sqlite = { version = "0.23", optional = true }
Expand All @@ -42,7 +45,7 @@ tokio = { version = "1.19.0", features = [
] }
url = { version = "2.1.1", optional = true }
vm-memory = "0.10"
fuse-backend-rs = "^0.11.0"
fuse-backend-rs = { version = "^0.11.0", features = ["fuse-t"] }
gpt = { version = "3.1.0", optional = true }

nydus-api = { version = "0.3", path = "../api" }
Expand Down

0 comments on commit 6895e3b

Please sign in to comment.