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);
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);
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"
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/syscall.h>
+#include <sys/xattr.h>
#include <fnmatch.h>
#include <glob.h>
#ifdef HAVE_LINUX_UNISTD_H
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;