From 6523ee9dadfe075a42668a29652a8b4fe0e7dff4 Mon Sep 17 00:00:00 2001 From: nathan Date: Thu, 20 Aug 2009 18:15:14 +0000 Subject: [PATCH] b=19053 i=w.li i=adilger path2fid for softlinks and character special nodes --- lustre/llite/dir.c | 2 +- lustre/llite/file.c | 2 +- lustre/tests/sanity.sh | 21 ++++++++++++++++----- lustre/utils/liblustreapi.c | 27 ++++++++++++++++++++++++--- 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/lustre/llite/dir.c b/lustre/llite/dir.c index d4f808e..33c7963 100644 --- a/lustre/llite/dir.c +++ b/lustre/llite/dir.c @@ -1217,7 +1217,7 @@ static int ll_dir_ioctl(struct inode *inode, struct file *file, RETURN(0); } case LL_IOC_PATH2FID: - if (copy_to_user((void *)arg, &ll_i2info(inode)->lli_fid, + if (copy_to_user((void *)arg, ll_inode2fid(inode), sizeof(struct lu_fid))) RETURN(-EFAULT); RETURN(0); diff --git a/lustre/llite/file.c b/lustre/llite/file.c index cd94c7d..c5d6702 100644 --- a/lustre/llite/file.c +++ b/lustre/llite/file.c @@ -1932,7 +1932,7 @@ error: case LL_IOC_FLUSHCTX: RETURN(ll_flush_ctx(inode)); case LL_IOC_PATH2FID: { - if (copy_to_user((void *)arg, &ll_i2info(inode)->lli_fid, + if (copy_to_user((void *)arg, ll_inode2fid(inode), sizeof(struct lu_fid))) RETURN(-EFAULT); diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 8a59744..493ee2c 100644 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -6363,22 +6363,33 @@ test_162() { touch $DIR/$tdir/d2/x2 mkdir -p $DIR/$tdir/d2/a/b/c mkdir -p $DIR/$tdir/d2/p/q/r + # regular file FID=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[') check_path "/$tdir/d2/$tfile" $DIR $FID --link 0 + + # softlink + ln -s $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/slink + FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink | tr -d '[') + check_path "/$tdir/d2/p/q/r/slink" $DIR $FID --link 0 + + # hardlink ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file FID=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[') # fid2path dir/fsname should both work check_path "/$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 1 check_path "/$tdir/d2/p/q/r/hlink" $DIR $FID --link 0 - # check that there are 2 links - ${LFS} fid2path $DIR $FID | wc -l | grep -q 2 || \ - err17935 "expected 2 links" + # hardlink count: check that there are 2 links + # Doesnt work with CMD yet: 17935 + ${LFS} fid2path $DIR $FID | wc -l | grep -q 2 || \ + err17935 "expected 2 links" + + # hardlink indexing: remove the first link rm $DIR/$tdir/d2/p/q/r/hlink check_path "/$tdir/d2/a/b/c/new_file" $DIR $FID --link 0 - # Doesnt work with CMD yet: 17935 - return 0 + + return 0 } run_test 162 "path lookup sanity" diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index 1532078..7a315c7 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -58,6 +58,7 @@ #include #include #include +#include #include #include #ifdef HAVE_LINUX_UNISTD_H @@ -2879,15 +2880,35 @@ int llapi_fid2path(const char *device, const char *fidstr, char *buf, return rc; } +static int path2fid_from_lma(const char *path, lustre_fid *fid) +{ + char buf[512]; + struct lustre_mdt_attrs *lma; + int rc; + + rc = lgetxattr(path, XATTR_NAME_LMA, buf, sizeof(buf)); + if (rc < 0) + return -errno; + lma = (struct lustre_mdt_attrs *)buf; + fid_be_to_cpu(fid, &lma->lma_self_fid); + return 0; +} + int llapi_path2fid(const char *path, lustre_fid *fid) { int fd, rc; - fd = open(path, O_RDONLY); - if (fd < 0) + memset(fid, 0, sizeof(*fid)); + fd = open(path, O_RDONLY | O_NONBLOCK | O_NOFOLLOW); + if (fd < 0) { + if (errno == ELOOP) /* symbolic link */ + return path2fid_from_lma(path, fid); return -errno; + } - rc = ioctl(fd, LL_IOC_PATH2FID, fid); + rc = ioctl(fd, LL_IOC_PATH2FID, fid) < 0 ? -errno : 0; + if (rc == -EINVAL) /* char special device */ + rc = path2fid_from_lma(path, fid); close(fd); return rc; -- 1.8.3.1