Skip to content
This repository has been archived by the owner on Jul 25, 2022. It is now read-only.

Commit

Permalink
EX-1932 handle softlinks for llapi queries (#2325)
Browse files Browse the repository at this point in the history
* EX-1932 handle softlinks for llapi queries

When constructing an llapi instance from a random path
liblustreapi first resolves that path fully, including
symbolic links.  This causes a failure when trying to
get an llapi instance from a symbolic link that lives on
a lustre filesystem (ex /mnt/lustre/symbolic_link)

If the path passed into search_fsname is a link, use
the parent dir instead.

Signed-off-by: Ben Evans <beevans@whamcloud.com>

* Code review fixes

Signed-off-by: Ben Evans <beevans@whamcloud.com>

* Indent code correctly

Signed-off-by: Ben Evans <beevans@whamcloud.com>

* More review comments

Signed-off-by: Ben Evans <beevans@whamcloud.com>
  • Loading branch information
beevans authored Oct 14, 2020
1 parent 9e7fecf commit 721afa0
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion liblustreapi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::{
ffi::{CStr, CString},
fmt, io,
num::ParseIntError,
os::unix::ffi::OsStrExt,
path::PathBuf,
str::FromStr,
sync::Arc,
Expand Down Expand Up @@ -305,7 +306,13 @@ impl Llapi {
}

pub fn search_fsname(&self, pathname: &str) -> Result<String, LiblustreError> {
let fsc = CString::new(pathname.as_bytes())?;
let mut path = PathBuf::from(pathname);
let md = std::fs::symlink_metadata(&path)?;
if md.file_type().is_symlink() {
path.pop();
}

let fsc = CString::new(path.into_os_string().as_bytes())?;
let mut fsname: Vec<u8> = vec![0; std::mem::size_of::<u8>() * MAXFSNAME + 1];
let ptr = fsname.as_mut_ptr() as *mut libc::c_char;

Expand Down

0 comments on commit 721afa0

Please sign in to comment.