]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
libcephfs: add ceph_ll_lookup_inode
authorJohn Spray <john.spray@inktank.com>
Fri, 7 Mar 2014 18:16:54 +0000 (18:16 +0000)
committerJohn Spray <john.spray@inktank.com>
Thu, 13 Mar 2014 18:33:01 +0000 (18:33 +0000)
This is a wrapper to lookup_ino, lookup_parent
and lookup_name, to provide the
caller with the requested inode and its
dentry.  The result is suitable for traversing
the inode's path.

Fixes: #3863
Signed-off-by: John Spray <john.spray@inktank.com>
src/include/cephfs/libcephfs.h
src/libcephfs.cc

index e600605b36c4159662e3d95e980fe2f77f85df66..282f41b4f9b45ef0717c6550587f85344eae0c14 100644 (file)
@@ -86,6 +86,7 @@ typedef struct Fh Fh;
 
 #endif /* ! __cplusplus */
 
+struct inodeno_t;
 struct Inode;
 typedef struct Inode Inode;
 
@@ -1208,6 +1209,11 @@ int ceph_debug_get_file_caps(struct ceph_mount_info *cmount, const char *path);
 /* Low Level */
 struct Inode *ceph_ll_get_inode(struct ceph_mount_info *cmount,
                                vinodeno_t vino);
+int ceph_ll_lookup_inode(
+    struct ceph_mount_info *cmount,
+    struct inodeno_t ino,
+    Inode **inode);
+
 /**
  * Get the root inode of FS. Increase counter of references for root Inode. You must call ceph_ll_forget for it!
  *
index 74bd6c3cd054a28922b5a1672b1eb7a0e417e0a3..88e86ba8347068f10d35343b7c63314bc9d3dea0 100644 (file)
@@ -1169,6 +1169,51 @@ extern "C" struct Inode *ceph_ll_get_inode(class ceph_mount_info *cmount,
   return (cmount->get_client())->ll_get_inode(vino);
 }
 
+
+/**
+ * Populates the client cache with the requested inode, and its
+ * parent dentry.
+ */
+extern "C" int ceph_ll_lookup_inode(
+    struct ceph_mount_info *cmount,
+    struct inodeno_t ino,
+    Inode **inode)
+{
+  int r = (cmount->get_client())->lookup_ino(ino, inode);
+  if (r) {
+    return r;
+  }
+  if (inode) {
+    assert(*inode != NULL);
+  }
+
+  // Request the parent inode, so that we can look up the name
+  Inode *parent;
+  r = (cmount->get_client())->lookup_parent(*inode, &parent);
+  if (r && r != -EINVAL) {
+    // Unexpected error
+    (cmount->get_client())->ll_forget(*inode, 1);
+    return r;
+  } else if (r == -EINVAL) {
+    // EINVAL indicates node without parents (root), drop out now
+    // and don't try to look up the non-existent dentry.
+    return 0;
+  }
+  assert(parent != NULL);
+
+  // Finally, get the name (dentry) of the requested inode
+  r = (cmount->get_client())->lookup_name(*inode, parent);
+  if (r) {
+    // Unexpected error
+    (cmount->get_client())->ll_forget(parent, 1);
+    (cmount->get_client())->ll_forget(*inode, 1);
+    return r;
+  }
+
+  (cmount->get_client())->ll_forget(parent, 1);
+  return 0;
+}
+
 extern "C" int ceph_ll_lookup(class ceph_mount_info *cmount,
                              struct Inode *parent, const char *name,
                              struct stat *attr, Inode **out,