diff --git a/project/libfuse-fs/examples/passthrough_example.rs b/project/libfuse-fs/examples/passthrough_example.rs index b2f275222..e004c3e34 100644 --- a/project/libfuse-fs/examples/passthrough_example.rs +++ b/project/libfuse-fs/examples/passthrough_example.rs @@ -3,13 +3,9 @@ // Simple passthrough filesystem example for integration tests. use clap::Parser; -<<<<<<< HEAD -use libfuse_fs::passthrough::{BindMount, Config, PassthroughFs, newlogfs::LoggingFileSystem}; -======= use libfuse_fs::passthrough::{ - PassthroughArgs, new_passthroughfs_layer, newlogfs::LoggingFileSystem, + BindMount, Config, PassthroughFs, newlogfs::LoggingFileSystem, }; ->>>>>>> 6d942b83c139734849543209bf1acea0aa8a558f use rfuse3::{MountOptions, raw::Session}; use std::ffi::OsString; use std::path::PathBuf; @@ -32,12 +28,16 @@ struct Args { /// Use privileged mount instead of unprivileged (default false) #[arg(long, default_value_t = true)] privileged: bool, -<<<<<<< HEAD /// Bind mount: mount_point:host_path or mount_point:host_path:ro /// Can be specified multiple times. /// Example: --bind volumes:/tmp/host --bind data:/tmp/data:ro #[arg(long, value_parser = parse_bind_mount)] bind: Vec, + /// Options, currently contains uid/gid mapping info + #[arg(long, short)] + options: Option, + #[arg(long)] + allow_other: bool, } #[derive(Debug, Clone)] @@ -66,13 +66,6 @@ fn parse_bind_mount(s: &str) -> Result { host_path, readonly, }) -======= - /// Options, currently contains uid/gid mapping info - #[arg(long, short)] - options: Option, - #[arg(long)] - allow_other: bool, ->>>>>>> 6d942b83c139734849543209bf1acea0aa8a558f } #[tokio::main] @@ -83,15 +76,19 @@ async fn main() { let args = Args::parse(); -<<<<<<< HEAD - // Create configuration + // Create configuration with mapping support let mut config = Config { - root_dir: args.rootdir.clone(), + root_dir: args.rootdir.clone().into(), do_import: true, xattr: true, ..Default::default() }; + // Parse and apply mapping if provided + if let Some(ref mapping_str) = args.options { + config.mapping = mapping_str.parse().expect("Failed to parse mapping"); + } + // Add bind mounts from arguments for bind_arg in &args.bind { info!( @@ -120,14 +117,6 @@ async fn main() { info!("Initialized {} bind mount(s)", args.bind.len()); } -======= - let fs = new_passthroughfs_layer(PassthroughArgs { - root_dir: args.rootdir, - mapping: args.options, - }) - .await - .expect("Failed to init passthrough fs"); ->>>>>>> 6d942b83c139734849543209bf1acea0aa8a558f let fs = LoggingFileSystem::new(fs); let mount_path = OsString::from(&args.mountpoint); diff --git a/project/libfuse-fs/src/passthrough/async_io.rs b/project/libfuse-fs/src/passthrough/async_io.rs index c2ffce3f3..2e407b61e 100644 --- a/project/libfuse-fs/src/passthrough/async_io.rs +++ b/project/libfuse-fs/src/passthrough/async_io.rs @@ -954,32 +954,11 @@ impl Filesystem for PassthroughFs { mode: u32, umask: u32, ) -> Result { -<<<<<<< HEAD // Check if parent is readonly bind mount self.check_write_permission(parent).await?; - let name = osstr_to_cstr(name).unwrap(); - let name = name.as_ref(); - self.validate_path_component(name)?; - - let data = self.inode_map.get(parent).await?; - - let res = { - //let (_uid, _gid) = set_creds(req.uid, req.gid)?; - - let file = data.get_file()?; - // Safe because this doesn't modify any memory and we check the return value. - unsafe { libc::mkdirat(file.as_raw_fd(), name.as_ptr(), mode & !umask) } - }; - if res < 0 { - return Err(io::Error::last_os_error().into()); - } - - self.do_lookup(parent, name).await -======= self.do_mkdir_inner(req, parent, name, mode, umask, None, None) .await ->>>>>>> 6d942b83c139734849543209bf1acea0aa8a558f } /// remove a file. @@ -1648,72 +1627,11 @@ impl Filesystem for PassthroughFs { mode: u32, flags: u32, ) -> Result { -<<<<<<< HEAD // Check if parent is readonly bind mount self.check_write_permission(parent).await?; - let name = osstr_to_cstr(name).unwrap(); - let name = name.as_ref(); - self.validate_path_component(name)?; - - let dir = self.inode_map.get(parent).await?; - let dir_file = dir.get_file()?; - - let new_file = { - //let (_uid, _gid) = set_creds(req.uid, req.gid)?; - - let flags = self.get_writeback_open_flags(flags as i32).await; - Self::create_file_excl(&dir_file, name, flags, mode)? - }; - - let entry = self.do_lookup(parent, name).await?; - let file = match new_file { - // File didn't exist, now created by create_file_excl() - Some(f) => f, - // File exists, and args.flags doesn't contain O_EXCL. Now let's open it with - // open_inode(). - None => { - // Cap restored when _killpriv is dropped - // let _killpriv = if self.killpriv_v2.load().await - // && (args.fuse_flags & FOPEN_IN_KILL_SUIDGID != 0) - // { - // self::drop_cap_fsetid()? - // } else { - // None - // }; - - //let (_uid, _gid) = set_creds(req.uid, req.gid)?; - self.open_inode(entry.attr.ino, flags as i32).await? - } - }; - - let ret_handle = if !self.no_open.load(Ordering::Relaxed) { - let handle = self.next_handle.fetch_add(1, Ordering::Relaxed); - let data = HandleData::new(entry.attr.ino, file, flags); - self.handle_map.insert(handle, data).await; - handle - } else { - return Err(io::Error::from_raw_os_error(libc::EACCES).into()); - }; - - let mut opts = OpenOptions::empty(); - match self.cfg.cache_policy { - CachePolicy::Never => opts |= OpenOptions::DIRECT_IO, - CachePolicy::Metadata => opts |= OpenOptions::DIRECT_IO, - CachePolicy::Always => opts |= OpenOptions::KEEP_CACHE, - _ => {} - }; - Ok(ReplyCreated { - ttl: entry.ttl, - attr: entry.attr, - generation: entry.generation, - fh: ret_handle, - flags: opts.bits(), - }) -======= self.do_create_inner(req, parent, name, mode, flags, None, None) .await ->>>>>>> 6d942b83c139734849543209bf1acea0aa8a558f } /// handle interrupt. When a operation is interrupted, an interrupt request will send to fuse diff --git a/project/libfuse-fs/src/passthrough/config.rs b/project/libfuse-fs/src/passthrough/config.rs index 2e42aafbc..be0339b6a 100644 --- a/project/libfuse-fs/src/passthrough/config.rs +++ b/project/libfuse-fs/src/passthrough/config.rs @@ -4,7 +4,6 @@ use std::path::PathBuf; use std::str::FromStr; use std::time::Duration; -use std::path::PathBuf; use std::collections::HashMap; use crate::util::mapping::IdMappings; @@ -202,14 +201,12 @@ pub struct Config { /// The default is `1024 * 1024 * 1024` (1GB). pub max_mmap_size: u64, -<<<<<<< HEAD /// Bind mount configurations /// Map from mount point to bind mount config pub bind_mounts: HashMap, -======= + /// UID/GID mapping. Format: `uidmapping=H:T:L[:H2:T2:L2...],gidmapping=H:T:L[:H2:T2:L2...]` pub mapping: IdMappings, ->>>>>>> 6d942b83c139734849543209bf1acea0aa8a558f } impl Default for Config { @@ -235,11 +232,8 @@ impl Default for Config { allow_direct_io: true, use_mmap: false, max_mmap_size: 1024 * 1024 * 1024, -<<<<<<< HEAD bind_mounts: HashMap::new(), -======= mapping: IdMappings::default(), ->>>>>>> 6d942b83c139734849543209bf1acea0aa8a558f } } } diff --git a/project/libfuse-fs/src/passthrough/mod.rs b/project/libfuse-fs/src/passthrough/mod.rs index 497b35f14..c4649b914 100644 --- a/project/libfuse-fs/src/passthrough/mod.rs +++ b/project/libfuse-fs/src/passthrough/mod.rs @@ -31,7 +31,7 @@ use std::{ fd::{AsFd, AsRawFd, BorrowedFd, RawFd}, unix::ffi::OsStringExt, }, - path::{Path, PathBuf}, + path::PathBuf, sync::Arc, sync::atomic::{AtomicU64, Ordering}, time::Duration,