linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sage Weil <sage@newdream.net>
To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	greg@kroah.com
Cc: Sage Weil <sage@newdream.net>
Subject: [PATCH 17/21] ceph: nfs re-export support
Date: Fri, 19 Jun 2009 15:31:38 -0700	[thread overview]
Message-ID: <1245450702-31343-18-git-send-email-sage@newdream.net> (raw)
In-Reply-To: <1245450702-31343-17-git-send-email-sage@newdream.net>

Basic NFS re-export support is included.  This mostly works.  However,
Ceph's MDS design precludes the ability to generate a (small)
filehandle that will be valid forever, so this is of limited utility.

Signed-off-by: Sage Weil <sage@newdream.net>
---
 fs/staging/ceph/export.c |  156 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 156 insertions(+), 0 deletions(-)
 create mode 100644 fs/staging/ceph/export.c

diff --git a/fs/staging/ceph/export.c b/fs/staging/ceph/export.c
new file mode 100644
index 0000000..9e87065
--- /dev/null
+++ b/fs/staging/ceph/export.c
@@ -0,0 +1,156 @@
+#include <linux/exportfs.h>
+
+#include "super.h"
+#include "ceph_debug.h"
+
+int ceph_debug_export __read_mostly = -1;
+#define DOUT_MASK DOUT_MASK_EXPORT
+#define DOUT_VAR ceph_debug_export
+
+/*
+ * fh is N tuples of
+ *  <ino, parent's d_name.hash>
+ *
+ * This is only a semi-reliable strategy.  The fundamental issue is
+ * that ceph doesn't not have a way to locate an arbitrary inode by
+ * ino.  Keeping a few parents in the handle increases the probability
+ * that we'll find it in one of the MDS caches, but it is by no means
+ * a guarantee.
+ *
+ * Also, the FINDINODE request is currently directed at a single MDS.
+ * It should probably try all MDS's before giving up.  For a single MDS
+ * system that isn't a problem.
+ *
+ * In the meantime, this works reasonably well for basic usage.
+ */
+
+
+struct ceph_export_item {
+	struct ceph_vino ino;
+	struct ceph_vino parent_ino;
+	u32 parent_name_hash;
+};
+
+#define IPSZ ((sizeof(struct ceph_export_item) + sizeof(u32) + 1) / sizeof(u32))
+
+static int ceph_encode_fh(struct dentry *dentry, u32 *rawfh, int *max_len,
+		   int connectable)
+{
+	int type = 1;
+	struct ceph_export_item *fh =
+		(struct ceph_export_item *)rawfh;
+	int max = *max_len / IPSZ;
+	int len;
+	struct dentry *d_parent;
+
+	dout(10, "encode_fh %p max_len %d u32s (%d export items)%s\n", dentry,
+	     *max_len, max, connectable ? " connectable" : "");
+
+	if (max < 1 || (connectable && max < 2))
+		return -ENOSPC;
+
+	for (len = 0; len < max; len++) {
+		d_parent = dentry->d_parent;
+		fh[len].ino = ceph_vino(dentry->d_inode);
+		fh[len].parent_ino = ceph_vino(d_parent->d_inode);
+		fh[len].parent_name_hash = dentry->d_parent->d_name.hash;
+
+		if (IS_ROOT(dentry))
+			break;
+
+		dentry = dentry->d_parent;
+
+		if (!dentry)
+			break;
+	}
+
+	if (len > 1)
+		type = 2;
+
+	*max_len = len * IPSZ;
+	return type;
+}
+
+static struct dentry *__fh_to_dentry(struct super_block *sb,
+			      struct ceph_export_item *fh, int len)
+{
+	struct ceph_mds_client *mdsc = &ceph_client(sb)->mdsc;
+	struct inode *inode;
+	struct dentry *dentry;
+	int err;
+#define BUF_SIZE 16
+	char path2[BUF_SIZE];
+	u32 hash = fh->parent_name_hash;
+
+	inode = ceph_find_inode(sb, fh->ino);
+	if (!inode) {
+		struct ceph_mds_request *req;
+		derr(10, "fh_to_dentry %llx.%x -- no inode\n", fh->ino.ino,
+		     hash);
+		req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_LOOKUPHASH,
+					       USE_ANY_MDS);
+		if (IS_ERR(req))
+			return ERR_PTR(PTR_ERR(req));
+
+		req->r_path1 = "";
+		req->r_ino1 = fh->ino;
+		snprintf(path2, BUF_SIZE, "%d", hash);
+		req->r_path2 = "";
+		req->r_ino2 = fh->parent_ino;
+		req->r_num_caps = 1;
+		err = ceph_mdsc_do_request(mdsc, NULL, req);
+		ceph_mdsc_put_request(req);
+		inode = ceph_find_inode(sb, fh->ino);
+		if (!inode)
+			return ERR_PTR(err ? err : -ESTALE);
+	}
+
+	dentry = d_obtain_alias(inode);
+
+	if (!dentry) {
+		derr(10, "fh_to_dentry %llx.%x -- inode %p but ENOMEM\n",
+		     fh->ino.ino,
+		     hash, inode);
+		iput(inode);
+		return ERR_PTR(-ENOMEM);
+	}
+	err = ceph_init_dentry(dentry);
+
+	if (err < 0) {
+		iput(inode);
+		return ERR_PTR(err);
+	}
+	dout(10, "fh_to_dentry %llx.%x -- inode %p dentry %p\n", fh->ino.ino,
+	     hash, inode, dentry);
+	return dentry;
+
+}
+
+static struct dentry *ceph_fh_to_dentry(struct super_block *sb, struct fid *fid,
+				 int fh_len, int fh_type)
+{
+	u32 *fh = fid->raw;
+	return __fh_to_dentry(sb, (struct ceph_export_item *)fh, fh_len/IPSZ);
+}
+
+static struct dentry *ceph_fh_to_parent(struct super_block *sb, struct fid *fid,
+				 int fh_len, int fh_type)
+{
+	u32 *fh = fid->raw;
+	u64 ino = *(u64 *)fh;
+	u32 hash = fh[2];
+
+	derr(10, "fh_to_parent %llx.%x\n", ino, hash);
+
+	if (fh_len < 6)
+		return ERR_PTR(-ESTALE);
+
+	return __fh_to_dentry(sb, (struct ceph_export_item *)fh + 1,
+			      fh_len/IPSZ - 1);
+}
+
+const struct export_operations ceph_export_ops = {
+	.encode_fh = ceph_encode_fh,
+	.fh_to_dentry = ceph_fh_to_dentry,
+	.fh_to_parent = ceph_fh_to_parent,
+};
-- 
1.5.6.5


  reply	other threads:[~2009-06-19 22:31 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-19 22:31 [PATCH 00/21] ceph: Ceph distributed file system client v0.9 Sage Weil
2009-06-19 22:31 ` [PATCH 01/21] fs: add fs/staging directory Sage Weil
2009-06-19 22:31   ` [PATCH 02/21] ceph: documentation Sage Weil
2009-06-19 22:31     ` [PATCH 03/21] ceph: on-wire types Sage Weil
2009-06-19 22:31       ` [PATCH 04/21] ceph: client types Sage Weil
2009-06-19 22:31         ` [PATCH 05/21] ceph: super.c Sage Weil
2009-06-19 22:31           ` [PATCH 06/21] ceph: inode operations Sage Weil
2009-06-19 22:31             ` [PATCH 07/21] ceph: directory operations Sage Weil
2009-06-19 22:31               ` [PATCH 08/21] ceph: file operations Sage Weil
2009-06-19 22:31                 ` [PATCH 09/21] ceph: address space operations Sage Weil
2009-06-19 22:31                   ` [PATCH 10/21] ceph: MDS client Sage Weil
2009-06-19 22:31                     ` [PATCH 11/21] ceph: OSD client Sage Weil
2009-06-19 22:31                       ` [PATCH 12/21] ceph: CRUSH mapping algorithm Sage Weil
2009-06-19 22:31                         ` [PATCH 13/21] ceph: monitor client Sage Weil
2009-06-19 22:31                           ` [PATCH 14/21] ceph: capability management Sage Weil
2009-06-19 22:31                             ` [PATCH 15/21] ceph: snapshot management Sage Weil
2009-06-19 22:31                               ` [PATCH 16/21] ceph: messenger library Sage Weil
2009-06-19 22:31                                 ` Sage Weil [this message]
2009-06-19 22:31                                   ` [PATCH 18/21] ceph: ioctls Sage Weil
2009-06-19 22:31                                     ` [PATCH 19/21] ceph: debugging Sage Weil
2009-06-19 22:31                                       ` [PATCH 20/21] ceph: debugfs Sage Weil
2009-06-19 22:31                                         ` [PATCH 21/21] ceph: Kconfig, Makefile Sage Weil
2009-06-20  9:12                                   ` [PATCH 17/21] ceph: nfs re-export support Stefan Richter
2009-06-20 20:39                                     ` Sage Weil
2009-06-20 21:22                                       ` Stefan Richter
2009-06-19 22:44 ` [PATCH 00/21] ceph: Ceph distributed file system client v0.9 Greg KH
2009-06-19 23:15   ` Sage Weil
2009-06-19 23:20     ` Greg KH
2009-06-19 22:45 ` Greg KH
2009-06-19 22:54   ` Stephen Rothwell
2009-06-19 23:12   ` Sage Weil
2009-06-19 23:19     ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1245450702-31343-18-git-send-email-sage@newdream.net \
    --to=sage@newdream.net \
    --cc=greg@kroah.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).