mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sage Weil <sage@newdream.net>
To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Sage Weil <sage@newdream.net>
Subject: [PATCH 16/20] ceph: nfs re-export support
Date: Wed, 15 Jul 2009 14:24:46 -0700	[thread overview]
Message-ID: <1247693090-27796-17-git-send-email-sage@newdream.net> (raw)
In-Reply-To: <1247693090-27796-16-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/ceph/export.c |  155 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 155 insertions(+), 0 deletions(-)
 create mode 100644 fs/ceph/export.c

diff --git a/fs/ceph/export.c b/fs/ceph/export.c
new file mode 100644
index 0000000..6ec1629
--- /dev/null
+++ b/fs/ceph/export.c
@@ -0,0 +1,155 @@
+#include <linux/exportfs.h>
+#include <asm/unaligned.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;
+} __attribute__ ((packed));
+
+#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_ino1 = fh->ino;
+		snprintf(path2, BUF_SIZE, "%d", hash);
+		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 = get_unaligned((u64 *)fh);
+	u32 hash = fh[2];
+
+	derr(10, "fh_to_parent %llx.%x\n", (unsigned long long)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-07-15 21:21 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-15 21:24 [PATCH 00/20] ceph: Ceph distributed file system client v0.10 Sage Weil
2009-07-15 21:24 ` [PATCH 01/20] ceph: documentation Sage Weil
2009-07-15 21:24   ` [PATCH 02/20] ceph: on-wire types Sage Weil
2009-07-15 21:24     ` [PATCH 03/20] ceph: client types Sage Weil
2009-07-15 21:24       ` [PATCH 04/20] ceph: super.c Sage Weil
2009-07-15 21:24         ` [PATCH 05/20] ceph: inode operations Sage Weil
2009-07-15 21:24           ` [PATCH 06/20] ceph: directory operations Sage Weil
2009-07-15 21:24             ` [PATCH 07/20] ceph: file operations Sage Weil
2009-07-15 21:24               ` [PATCH 08/20] ceph: address space operations Sage Weil
2009-07-15 21:24                 ` [PATCH 09/20] ceph: MDS client Sage Weil
2009-07-15 21:24                   ` [PATCH 10/20] ceph: OSD client Sage Weil
2009-07-15 21:24                     ` [PATCH 11/20] ceph: CRUSH mapping algorithm Sage Weil
2009-07-15 21:24                       ` [PATCH 12/20] ceph: monitor client Sage Weil
2009-07-15 21:24                         ` [PATCH 13/20] ceph: capability management Sage Weil
2009-07-15 21:24                           ` [PATCH 14/20] ceph: snapshot management Sage Weil
2009-07-15 21:24                             ` [PATCH 15/20] ceph: messenger library Sage Weil
2009-07-15 21:24                               ` Sage Weil [this message]
2009-07-15 21:24                                 ` [PATCH 17/20] ceph: ioctls Sage Weil
2009-07-15 21:24                                   ` [PATCH 18/20] ceph: debugging Sage Weil
2009-07-15 21:24                                     ` [PATCH 19/20] ceph: debugfs Sage Weil
2009-07-15 21:24                                       ` [PATCH 20/20] ceph: Kconfig, Makefile Sage Weil
2009-07-16 12:27                                     ` [PATCH 18/20] ceph: debugging Andi Kleen
2009-07-16 17:17                                       ` Sage Weil
2009-07-17 18:07                                         ` Sage Weil
2009-07-17 18:56                                           ` Andi Kleen
2009-07-17 19:52                                             ` Sage Weil
2009-07-17 20:01                                               ` Andi Kleen
2009-07-17 21:35                                                 ` Sage Weil
2009-07-17 21:51                                                   ` Andi Kleen
2009-07-16 19:27                                 ` [PATCH 16/20] ceph: nfs re-export support J. Bruce Fields
2009-07-16 19:50                                   ` Sage Weil
2009-07-16 21:21                                     ` Trond Myklebust
2009-07-16 22:07                                       ` Sage Weil
2009-07-17 14:05                                         ` J. Bruce Fields
2009-07-17 16:49                                           ` Sage Weil
2009-07-17 16:57                                             ` J. Bruce Fields
2009-07-16 12:31     ` [PATCH 02/20] ceph: on-wire types Andi Kleen
2009-07-16 16:58       ` Sage Weil
2009-07-16  3:59 ` [PATCH 00/20] ceph: Ceph distributed file system client v0.10 Noah Watkins
2009-07-16 17:03   ` Sage Weil
2009-07-16 12:26 ` Andi Kleen
2009-07-16 17:11   ` Sage Weil
2009-07-18  1:28     ` Chris Wright
2009-07-18  4:39       ` Sage Weil
  -- strict thread matches above, loose matches on Subject: below --
2009-03-09 22:40 [PATCH 00/20] ceph: Ceph distributed file system client Sage Weil
2009-03-09 22:40 ` [PATCH 01/20] ceph: documentation Sage Weil
2009-03-09 22:40   ` [PATCH 02/20] ceph: on-wire types Sage Weil
2009-03-09 22:40     ` [PATCH 03/20] ceph: client types Sage Weil
2009-03-09 22:40       ` [PATCH 04/20] ceph: super.c Sage Weil
2009-03-09 22:40         ` [PATCH 05/20] ceph: inode operations Sage Weil
2009-03-09 22:40           ` [PATCH 06/20] ceph: directory operations Sage Weil
2009-03-09 22:40             ` [PATCH 07/20] ceph: file operations Sage Weil
2009-03-09 22:40               ` [PATCH 08/20] ceph: address space operations Sage Weil
2009-03-09 22:40                 ` [PATCH 09/20] ceph: MDS client Sage Weil
2009-03-09 22:40                   ` [PATCH 10/20] ceph: OSD client Sage Weil
2009-03-09 22:40                     ` [PATCH 11/20] ceph: CRUSH mapping algorithm Sage Weil
2009-03-09 22:40                       ` [PATCH 12/20] ceph: monitor client Sage Weil
2009-03-09 22:40                         ` [PATCH 13/20] ceph: capability management Sage Weil
2009-03-09 22:40                           ` [PATCH 14/20] ceph: snapshot management Sage Weil
2009-03-09 22:40                             ` [PATCH 15/20] ceph: messenger library Sage Weil
2009-03-09 22:40                               ` [PATCH 16/20] ceph: nfs re-export support Sage Weil

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=1247693090-27796-17-git-send-email-sage@newdream.net \
    --to=sage@newdream.net \
    --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

all inboxes | Powered by JetHome®