Skip to content

Commit

Permalink
service: add a functoin to get fuse backend vfs
Browse files Browse the repository at this point in the history
Add a function to get fuse backend vfs,
reduce explicit references to fuse_backend_rs.

Signed-off-by: taohong <taoohong@linux.alibaba.com>
  • Loading branch information
taoohong committed Apr 15, 2023
1 parent 80ede75 commit 826715d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 22 deletions.
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)
}

/// Prepare the backend vfs when using rafs or passthrough as the fuse filesystem driver
pub fn get_backend_vfs(
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, get_backend_vfs, 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, get_backend_vfs, 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 = get_backend_vfs(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

0 comments on commit 826715d

Please sign in to comment.