Whamcloud - gitweb
b=19053
authornathan <nathan>
Thu, 20 Aug 2009 18:15:14 +0000 (18:15 +0000)
committernathan <nathan>
Thu, 20 Aug 2009 18:15:14 +0000 (18:15 +0000)
i=w.li
i=adilger
path2fid for softlinks and character special nodes

lustre/llite/dir.c
lustre/llite/file.c
lustre/tests/sanity.sh
lustre/utils/liblustreapi.c

index d4f808e..33c7963 100644 (file)
@@ -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);
index cd94c7d..c5d6702 100644 (file)
@@ -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);
 
index 8a59744..493ee2c 100644 (file)
@@ -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"
 
index 1532078..7a315c7 100644 (file)
@@ -58,6 +58,7 @@
 #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
@@ -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;