Skip to content

Commit

Permalink
fix cntrfs example
Browse files Browse the repository at this point in the history
  • Loading branch information
Mic92 committed Jun 15, 2018
1 parent 25a5d8d commit 967464a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 26 deletions.
21 changes: 12 additions & 9 deletions examples/cntrfs.rs
Expand Up @@ -51,15 +51,18 @@ fn main() {
}
#[cfg(feature = "profiling")] PROFILER.lock().unwrap().start("./cntrfs.profile").unwrap();

let cntr = CntrFs::new(&CntrMountOptions {
prefix: &args[1],
splice_read: cfg!(feature = "splice_read"),
splice_write: cfg!(feature = "splice_write"),
uid_map: cntr::DEFAULT_ID_MAP,
gid_map: cntr::DEFAULT_ID_MAP,
effective_uid: None,
effective_gid: None,
}).unwrap();
let cntr = CntrFs::new(
&CntrMountOptions {
prefix: &args[1],
splice_read: cfg!(feature = "splice_read"),
splice_write: cfg!(feature = "splice_write"),
uid_map: cntr::DEFAULT_ID_MAP,
gid_map: cntr::DEFAULT_ID_MAP,
effective_uid: None,
effective_gid: None,
},
None,
).unwrap();

cntr.mount(Path::new(&args[2]), &None).unwrap();
let guard = MountGuard { mount_point: args[2].clone() };
Expand Down
2 changes: 1 addition & 1 deletion src/attach/mod.rs
Expand Up @@ -62,7 +62,6 @@ pub fn attach(opts: &AttachOptions) -> Result<Void> {

let cntrfs = tryfmt!(
fs::CntrFs::new(
dotcntr,
&fs::CntrMountOptions {
prefix: "/",
splice_read: cfg!(feature = "splice_read"),
Expand All @@ -72,6 +71,7 @@ pub fn attach(opts: &AttachOptions) -> Result<Void> {
effective_uid,
effective_gid,
},
Some(dotcntr),
),
"cannot mount filesystem"
);
Expand Down
35 changes: 19 additions & 16 deletions src/fs.rs
Expand Up @@ -77,7 +77,7 @@ struct InodeCounter {
pub struct CntrFs {
prefix: String,
root_inode: Arc<Inode>,
dotcntr: Arc<DotcntrDir>,
dotcntr: Arc<Option<DotcntrDir>>,
inode_mapping: Arc<Mutex<HashMap<InodeKey, u64>>>,
inodes: Arc<ConcHashMap<u64, Arc<Inode>>>,
inode_counter: Arc<RwLock<InodeCounter>>,
Expand Down Expand Up @@ -186,7 +186,7 @@ fn open_static_dnode(static_ino: u64, path: &Path) -> Result<Arc<Inode>> {


impl CntrFs {
pub fn new(dotcntr: DotcntrDir, options: &CntrMountOptions) -> Result<CntrFs> {
pub fn new(options: &CntrMountOptions, dotcntr: Option<DotcntrDir>) -> Result<CntrFs> {
let fuse_fd = tryfmt!(fusefd::open(), "failed to initialize fuse");

let limit = resource::Rlimit {
Expand Down Expand Up @@ -542,25 +542,28 @@ impl CntrFs {
Ok((attr, generation))
}


pub fn lookup_inode(&mut self, parent: u64, name: &OsStr) -> nix::Result<(FileAttr, u64)> {
fsuid::set_root();

if parent == fuse::FUSE_ROOT_ID && name == ".cntr" {
let d = Arc::clone(&self.dotcntr);
self.lookup_from_fd(LookupFile::Borrow(&d.file))
} else {
let parent_inode = try!(self.inode(&parent));
let parent_fd = parent_inode.fd.read();
let fd = try!(fcntl::openat(
parent_fd.raw(),
name,
OFlag::O_PATH | OFlag::O_NOFOLLOW | OFlag::O_CLOEXEC,
stat::Mode::empty(),
));
let file = unsafe { File::from_raw_fd(fd) };

self.lookup_from_fd(LookupFile::Donate(file))
let dotcntr = Arc::clone(&self.dotcntr);
if let Some(ref dotcntr) = *dotcntr {
return self.lookup_from_fd(LookupFile::Borrow(&dotcntr.file));
}
}

let parent_inode = try!(self.inode(&parent));
let parent_fd = parent_inode.fd.read();
let fd = try!(fcntl::openat(
parent_fd.raw(),
name,
OFlag::O_PATH | OFlag::O_NOFOLLOW | OFlag::O_CLOEXEC,
stat::Mode::empty(),
));
let file = unsafe { File::from_raw_fd(fd) };

self.lookup_from_fd(LookupFile::Donate(file))
}
}

Expand Down

0 comments on commit 967464a

Please sign in to comment.