Merge tag 'stable/for-linus-3.15-rc5-tag' of git://git.kernel.org/pub/scm/linux/kerne...
[firefly-linux-kernel-4.4.55.git] / fs / ceph / export.c
index 9c28b6abe885223df78857c12bff491515ca63b7..00d6af6a32ec9a37f204705da091122e7ddd7151 100644 (file)
@@ -181,49 +181,64 @@ struct dentry *ceph_get_parent(struct dentry *child)
 }
 
 /*
- * get parent, if possible.
- *
- * FIXME: we could do better by querying the mds to discover the
- * parent.
+ * convert regular fh to parent
  */
 static struct dentry *ceph_fh_to_parent(struct super_block *sb,
-                                        struct fid *fid,
+                                       struct fid *fid,
                                        int fh_len, int fh_type)
 {
        struct ceph_nfs_confh *cfh = (void *)fid->raw;
-       struct ceph_vino vino;
-       struct inode *inode;
        struct dentry *dentry;
-       int err;
 
-       if (fh_type == 1)
-               return ERR_PTR(-ESTALE);
+       if (fh_type != FILEID_INO32_GEN_PARENT)
+               return NULL;
        if (fh_len < sizeof(*cfh) / 4)
-               return ERR_PTR(-ESTALE);
+               return NULL;
 
-       pr_debug("fh_to_parent %llx/%d\n", cfh->parent_ino,
-                cfh->parent_name_hash);
+       dout("fh_to_parent %llx\n", cfh->parent_ino);
+       dentry = __get_parent(sb, NULL, cfh->ino);
+       if (IS_ERR(dentry) && PTR_ERR(dentry) == -ENOENT)
+               dentry = __fh_to_dentry(sb, cfh->parent_ino);
+       return dentry;
+}
 
-       vino.ino = cfh->ino;
-       vino.snap = CEPH_NOSNAP;
-       inode = ceph_find_inode(sb, vino);
-       if (!inode)
-               return ERR_PTR(-ESTALE);
+static int ceph_get_name(struct dentry *parent, char *name,
+                        struct dentry *child)
+{
+       struct ceph_mds_client *mdsc;
+       struct ceph_mds_request *req;
+       int err;
 
-       dentry = d_obtain_alias(inode);
-       if (IS_ERR(dentry)) {
-               pr_err("fh_to_parent %llx -- inode %p but ENOMEM\n",
-                      cfh->ino, inode);
-               iput(inode);
-               return dentry;
-       }
-       err = ceph_init_dentry(dentry);
-       if (err < 0) {
-               iput(inode);
-               return ERR_PTR(err);
+       mdsc = ceph_inode_to_client(child->d_inode)->mdsc;
+       req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_LOOKUPNAME,
+                                      USE_ANY_MDS);
+       if (IS_ERR(req))
+               return PTR_ERR(req);
+
+       mutex_lock(&parent->d_inode->i_mutex);
+
+       req->r_inode = child->d_inode;
+       ihold(child->d_inode);
+       req->r_ino2 = ceph_vino(parent->d_inode);
+       req->r_locked_dir = parent->d_inode;
+       req->r_num_caps = 2;
+       err = ceph_mdsc_do_request(mdsc, NULL, req);
+
+       mutex_unlock(&parent->d_inode->i_mutex);
+
+       if (!err) {
+               struct ceph_mds_reply_info_parsed *rinfo = &req->r_reply_info;
+               memcpy(name, rinfo->dname, rinfo->dname_len);
+               name[rinfo->dname_len] = 0;
+               dout("get_name %p ino %llx.%llx name %s\n",
+                    child, ceph_vinop(child->d_inode), name);
+       } else {
+               dout("get_name %p ino %llx.%llx err %d\n",
+                    child, ceph_vinop(child->d_inode), err);
        }
-       dout("fh_to_parent %llx %p dentry %p\n", cfh->ino, inode, dentry);
-       return dentry;
+
+       ceph_mdsc_put_request(req);
+       return err;
 }
 
 const struct export_operations ceph_export_ops = {
@@ -231,4 +246,5 @@ const struct export_operations ceph_export_ops = {
        .fh_to_dentry = ceph_fh_to_dentry,
        .fh_to_parent = ceph_fh_to_parent,
        .get_parent = ceph_get_parent,
+       .get_name = ceph_get_name,
 };