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

service: add a functoin to help create fuse vfs backend #1218

Merged
merged 1 commit into from
Apr 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 31 additions & 1 deletion service/src/fusedev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use crate::daemon::{
};
use crate::fs_service::{FsBackendCollection, FsBackendMountCmd, FsService};
use crate::upgrade::{self, FailoverPolicy, UpgradeManager};
use crate::{Error as NydusError, Result as NydusResult};
use crate::{Error as NydusError, FsBackendType, Result as NydusResult};

#[derive(Serialize)]
struct FuseOp {
Expand Down Expand Up @@ -614,3 +614,33 @@ pub fn create_fuse_daemon(

Ok(daemon)
}

/// Create vfs backend with rafs or passthrough as the fuse filesystem driver
pub fn create_vfs_backend(
fs_type: FsBackendType,
is_fuse: bool,
hybrid_mode: bool,
) -> Result<Arc<Vfs>> {
let mut opts = fuse_backend_rs::api::VfsOptions::default();
match fs_type {
FsBackendType::PassthroughFs => {
// passthroughfs requires !no_open
opts.no_open = false;
opts.no_opendir = false;
opts.killpriv_v2 = true;
}
FsBackendType::Rafs => {
// rafs can be readonly and skip open
opts.no_open = true;
}
};

if !is_fuse && hybrid_mode {
opts.no_open = false;
opts.no_opendir = false;
opts.killpriv_v2 = true;
}

let vfs = fuse_backend_rs::api::Vfs::new(opts);
Ok(Arc::new(vfs))
}
2 changes: 1 addition & 1 deletion service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub mod upgrade;

pub use blob_cache::BlobCacheMgr;
pub use fs_service::{FsBackendCollection, FsBackendMountCmd, FsBackendUmountCmd, FsService};
pub use fusedev::{create_fuse_daemon, FusedevDaemon};
pub use fusedev::{create_fuse_daemon, create_vfs_backend, FusedevDaemon};
pub use singleton::create_daemon;

#[cfg(target_os = "linux")]
Expand Down
25 changes: 5 additions & 20 deletions src/bin/nydusd/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ extern crate nydus_error;

use std::convert::TryInto;
use std::io::{Error, ErrorKind, Result};
use std::sync::Arc;

use clap::{Arg, ArgAction, ArgMatches, Command};
use nix::sys::signal;
Expand All @@ -25,8 +24,8 @@ use nydus_api::BuildTimeInfo;
use nydus_app::{dump_program_info, setup_logging};
use nydus_service::daemon::DaemonController;
use nydus_service::{
create_daemon, create_fuse_daemon, validate_threads_configuration, Error as NydusError,
FsBackendMountCmd, FsBackendType, ServiceArgs,
create_daemon, create_fuse_daemon, create_vfs_backend, validate_threads_configuration,
Error as NydusError, FsBackendMountCmd, FsBackendType, ServiceArgs,
};

use crate::api_server_glue::ApiServerController;
Expand Down Expand Up @@ -378,7 +377,7 @@ fn process_fs_service(
// safe as virtual_mountpoint default to "/"
let virtual_mnt = args.value_of("virtual-mountpoint").unwrap();

let mut opts = fuse_backend_rs::api::VfsOptions::default();
let mut fs_type = FsBackendType::PassthroughFs;
let mount_cmd = if let Some(shared_dir) = shared_dir {
let cmd = FsBackendMountCmd {
fs_type: FsBackendType::PassthroughFs,
Expand All @@ -388,11 +387,6 @@ fn process_fs_service(
prefetch_files: None,
};

// passthroughfs requires !no_open
opts.no_open = false;
opts.no_opendir = false;
opts.killpriv_v2 = true;

Some(cmd)
} else if let Some(b) = bootstrap {
let config = match args.value_of("localfs-dir") {
Expand Down Expand Up @@ -467,23 +461,14 @@ fn process_fs_service(
prefetch_files,
};

// rafs can be readonly and skip open
opts.no_open = true;
fs_type = FsBackendType::Rafs;

Some(cmd)
} else {
None
};

// Enable all options required by passthroughfs
if !is_fuse && args.is_present("hybrid-mode") {
opts.no_open = false;
opts.no_opendir = false;
opts.killpriv_v2 = true;
}

let vfs = fuse_backend_rs::api::Vfs::new(opts);
let vfs = Arc::new(vfs);
let vfs = create_vfs_backend(fs_type, is_fuse, args.is_present("hybrid-mode"))?;
// Basically, below two arguments are essential for live-upgrade/failover/ and external management.
let daemon_id = args.value_of("id").map(|id| id.to_string());
let supervisor = args.value_of("supervisor").map(|s| s.to_string());
Expand Down