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/19] ceph: nfs re-export support
Date: Wed, 22 Jul 2009 12:51:50 -0700 [thread overview]
Message-ID: <1248292313-31326-17-git-send-email-sage@newdream.net> (raw)
In-Reply-To: <1248292313-31326-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 | 222 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 222 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..20eba43
--- /dev/null
+++ b/fs/ceph/export.c
@@ -0,0 +1,222 @@
+#include <linux/exportfs.h>
+#include <asm/unaligned.h>
+
+#include "super.h"
+#include "ceph_debug.h"
+
+/*
+ * NFS export support
+ *
+ * NFS re-export of a ceph mount is, at present, only semireliable.
+ * The basic issue is that the Ceph architectures doesn't lend itself
+ * well to generating filehandles that will remain valid forever.
+ *
+ * So, we do our best. If you're lucky, your inode will be in the
+ * client's cache. If it's not, and you have a connectable fh, then
+ * the MDS server may be able to find it for you. Otherwise, you get
+ * ESTALE.
+ *
+ * There are ways to this more reliable, but in the non-connectable fh
+ * case, we won't every work perfectly, and in the connectable case,
+ * some changes are needed on the MDS side to work better.
+ */
+
+/*
+ * Basic fh
+ */
+struct ceph_nfs_fh {
+ u64 ino;
+} __attribute__ ((packed));
+
+/*
+ * Larger 'connectable' fh that includes parent ino and name hash.
+ * Use this whenever possible, as it works more reliably.
+ */
+struct ceph_nfs_confh {
+ u64 ino, parent_ino;
+ u32 parent_name_hash;
+} __attribute__ ((packed));
+
+static int ceph_encode_fh(struct dentry *dentry, u32 *rawfh, int *max_len,
+ int connectable)
+{
+ struct ceph_nfs_fh *fh = (void *)rawfh;
+ struct ceph_nfs_confh *cfh = (void *)rawfh;
+ struct dentry *parent = dentry->d_parent;
+ struct inode *inode = dentry->d_inode;
+ int type;
+
+ /* don't re-export snaps */
+ if (ceph_snap(inode) != CEPH_NOSNAP)
+ return -EINVAL;
+
+ if (*max_len >= sizeof(*cfh)) {
+ dout("encode_fh %p connectable\n", dentry);
+ cfh->ino = ceph_ino(dentry->d_inode);
+ cfh->parent_ino = ceph_ino(parent->d_inode);
+ cfh->parent_name_hash = parent->d_name.hash;
+ *max_len = sizeof(*cfh);
+ type = 2;
+ } else if (*max_len > sizeof(*fh)) {
+ if (connectable)
+ return -ENOSPC;
+ dout("encode_fh %p\n", dentry);
+ fh->ino = ceph_ino(dentry->d_inode);
+ *max_len = sizeof(*fh);
+ type = 1;
+ } else {
+ return -ENOSPC;
+ }
+ return type;
+}
+
+/*
+ * convert regular fh to dentry
+ *
+ * FIXME: we should try harder by querying the mds for the ino.
+ */
+static struct dentry *__fh_to_dentry(struct super_block *sb,
+ struct ceph_nfs_fh *fh)
+{
+ struct inode *inode;
+ struct dentry *dentry;
+ struct ceph_vino vino;
+ int err;
+
+ dout("__fh_to_dentry %llx\n", fh->ino);
+ vino.ino = fh->ino;
+ vino.snap = CEPH_NOSNAP;
+ inode = ceph_find_inode(sb, vino);
+ if (!inode)
+ return ERR_PTR(-ESTALE);
+
+ dentry = d_obtain_alias(inode);
+ if (!dentry) {
+ pr_err("ceph fh_to_dentry %llx -- inode %p but ENOMEM\n",
+ fh->ino, inode);
+ iput(inode);
+ return ERR_PTR(-ENOMEM);
+ }
+ err = ceph_init_dentry(dentry);
+
+ if (err < 0) {
+ iput(inode);
+ return ERR_PTR(err);
+ }
+ dout("__fh_to_dentry %llx %p dentry %p\n", fh->ino, inode, dentry);
+ return dentry;
+}
+
+/*
+ * convert connectable fh to dentry
+ */
+static struct dentry *__cfh_to_dentry(struct super_block *sb,
+ struct ceph_nfs_confh *cfh)
+{
+ struct ceph_mds_client *mdsc = &ceph_client(sb)->mdsc;
+ struct inode *inode;
+ struct dentry *dentry;
+ struct ceph_vino vino;
+ int err;
+
+ dout("__cfh_to_dentry %llx (%llx/%x)\n",
+ cfh->ino, cfh->parent_ino, cfh->parent_name_hash);
+
+ vino.ino = cfh->ino;
+ vino.snap = CEPH_NOSNAP;
+ inode = ceph_find_inode(sb, vino);
+ if (!inode) {
+ struct ceph_mds_request *req;
+
+ 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 = vino;
+ req->r_ino2.ino = cfh->parent_ino;
+ req->r_ino2.snap = CEPH_NOSNAP;
+ req->r_path2 = kmalloc(16, GFP_NOFS);
+ snprintf(req->r_path2, 16, "%d", cfh->parent_name_hash);
+ req->r_num_caps = 1;
+ err = ceph_mdsc_do_request(mdsc, NULL, req);
+ ceph_mdsc_put_request(req);
+ inode = ceph_find_inode(sb, vino);
+ if (!inode)
+ return ERR_PTR(err ? err : -ESTALE);
+ }
+
+ dentry = d_obtain_alias(inode);
+ if (!dentry) {
+ pr_err("ceph cfh_to_dentry %llx -- inode %p but ENOMEM\n",
+ cfh->ino, inode);
+ iput(inode);
+ return ERR_PTR(-ENOMEM);
+ }
+ err = ceph_init_dentry(dentry);
+ if (err < 0) {
+ iput(inode);
+ return ERR_PTR(err);
+ }
+ dout("__cfh_to_dentry %llx %p dentry %p\n", cfh->ino, inode, dentry);
+ return dentry;
+}
+
+static struct dentry *ceph_fh_to_dentry(struct super_block *sb, struct fid *fid,
+ int fh_len, int fh_type)
+{
+ if (fh_type == 1)
+ return __fh_to_dentry(sb, (struct ceph_nfs_fh *)fid->raw);
+ else
+ return __cfh_to_dentry(sb, (struct ceph_nfs_confh *)fid->raw);
+}
+
+/*
+ * get parent, if possible.
+ *
+ * FIXME: we could do better by querying the mds to discover the
+ * parent.
+ */
+static struct dentry *ceph_fh_to_parent(struct super_block *sb,
+ 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);
+
+ pr_debug("ceph_fh_to_parent %llx/%d\n", cfh->parent_ino,
+ cfh->parent_name_hash);
+
+ vino.ino = cfh->ino;
+ vino.snap = CEPH_NOSNAP;
+ inode = ceph_find_inode(sb, vino);
+ if (!inode)
+ return ERR_PTR(-ESTALE);
+
+ dentry = d_obtain_alias(inode);
+ if (!dentry) {
+ pr_err("ceph fh_to_parent %llx -- inode %p but ENOMEM\n",
+ cfh->ino, inode);
+ iput(inode);
+ return ERR_PTR(-ENOMEM);
+ }
+ err = ceph_init_dentry(dentry);
+ if (err < 0) {
+ iput(inode);
+ return ERR_PTR(err);
+ }
+ dout("fh_to_parent %llx %p dentry %p\n", cfh->ino, inode, dentry);
+ return dentry;
+}
+
+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
next prev parent reply other threads:[~2009-07-22 19:47 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-22 19:51 [PATCH 00/19] ceph: Ceph distributed file system client v0.11 Sage Weil
2009-07-22 19:51 ` [PATCH 01/19] ceph: documentation Sage Weil
2009-07-22 19:51 ` [PATCH 02/19] ceph: on-wire types Sage Weil
2009-07-22 19:51 ` [PATCH 03/19] ceph: client types Sage Weil
2009-07-22 19:51 ` [PATCH 04/19] ceph: super.c Sage Weil
2009-07-22 19:51 ` [PATCH 05/19] ceph: inode operations Sage Weil
2009-07-22 19:51 ` [PATCH 06/19] ceph: directory operations Sage Weil
2009-07-22 19:51 ` [PATCH 07/19] ceph: file operations Sage Weil
2009-07-22 19:51 ` [PATCH 08/19] ceph: address space operations Sage Weil
2009-07-22 19:51 ` [PATCH 09/19] ceph: MDS client Sage Weil
2009-07-22 19:51 ` [PATCH 10/19] ceph: OSD client Sage Weil
2009-07-22 19:51 ` [PATCH 11/19] ceph: CRUSH mapping algorithm Sage Weil
2009-07-22 19:51 ` [PATCH 12/19] ceph: monitor client Sage Weil
2009-07-22 19:51 ` [PATCH 13/19] ceph: capability management Sage Weil
2009-07-22 19:51 ` [PATCH 14/19] ceph: snapshot management Sage Weil
2009-07-22 19:51 ` [PATCH 15/19] ceph: messenger library Sage Weil
2009-07-22 19:51 ` Sage Weil [this message]
2009-07-22 19:51 ` [PATCH 17/19] ceph: ioctls Sage Weil
2009-07-22 19:51 ` [PATCH 18/19] ceph: debugfs Sage Weil
2009-07-22 19:51 ` [PATCH 19/19] ceph: Kconfig, Makefile Sage Weil
2009-07-25 5:31 ` [PATCH 18/19] ceph: debugfs Greg KH
2009-07-27 17:06 ` Sage Weil
2009-07-22 22:39 ` [PATCH 17/19] ceph: ioctls Andi Kleen
2009-07-22 23:52 ` Sage Weil
2009-07-23 6:24 ` Andi Kleen
2009-07-23 18:42 ` Sage Weil
2009-07-23 10:25 ` [PATCH 08/19] ceph: address space operations Andi Kleen
2009-07-23 18:22 ` Sage Weil
2009-07-23 19:16 ` Andi Kleen
2009-07-24 4:48 ` Sage Weil
2009-07-23 19:17 ` Andi Kleen
2009-07-23 18:26 ` Sage Weil
2009-07-23 18:47 ` Trond Myklebust
2009-07-24 4:44 ` Sage Weil
2009-07-24 6:56 ` Andi Kleen
2009-07-24 16:52 ` Sage Weil
2009-07-24 19:40 ` J. Bruce Fields
-- strict thread matches above, loose matches on Subject: below --
2009-08-05 22:30 [PATCH 00/19] ceph distributed file system client Sage Weil
2009-08-05 22:30 ` [PATCH 01/19] ceph: documentation Sage Weil
2009-08-05 22:30 ` [PATCH 02/19] ceph: on-wire types Sage Weil
2009-08-05 22:30 ` [PATCH 03/19] ceph: client types Sage Weil
2009-08-05 22:30 ` [PATCH 04/19] ceph: super.c Sage Weil
2009-08-05 22:30 ` [PATCH 05/19] ceph: inode operations Sage Weil
2009-08-05 22:30 ` [PATCH 06/19] ceph: directory operations Sage Weil
2009-08-05 22:30 ` [PATCH 07/19] ceph: file operations Sage Weil
2009-08-05 22:30 ` [PATCH 08/19] ceph: address space operations Sage Weil
2009-08-05 22:30 ` [PATCH 09/19] ceph: MDS client Sage Weil
2009-08-05 22:30 ` [PATCH 10/19] ceph: OSD client Sage Weil
2009-08-05 22:30 ` [PATCH 11/19] ceph: CRUSH mapping algorithm Sage Weil
2009-08-05 22:30 ` [PATCH 12/19] ceph: monitor client Sage Weil
2009-08-05 22:30 ` [PATCH 13/19] ceph: capability management Sage Weil
2009-08-05 22:30 ` [PATCH 14/19] ceph: snapshot management Sage Weil
2009-08-05 22:30 ` [PATCH 15/19] ceph: messenger library Sage Weil
2009-08-05 22:30 ` [PATCH 16/19] ceph: nfs re-export support Sage Weil
2008-11-14 0:55 [PATCH 00/19] ceph: Ceph distributed file system client Sage Weil
2008-11-14 0:56 ` [PATCH 01/19] ceph: documentation Sage Weil
2008-11-14 0:56 ` [PATCH 02/19] ceph: on-wire types Sage Weil
2008-11-14 0:56 ` [PATCH 03/19] ceph: client types Sage Weil
2008-11-14 0:56 ` [PATCH 04/19] ceph: super.c Sage Weil
2008-11-14 0:56 ` [PATCH 05/19] ceph: inode operations Sage Weil
2008-11-14 0:56 ` [PATCH 06/19] ceph: directory operations Sage Weil
2008-11-14 0:56 ` [PATCH 07/19] ceph: file operations Sage Weil
2008-11-14 0:56 ` [PATCH 08/19] ceph: address space operations Sage Weil
2008-11-14 0:56 ` [PATCH 09/19] ceph: MDS client Sage Weil
2008-11-14 0:56 ` [PATCH 10/19] ceph: OSD client Sage Weil
2008-11-14 0:56 ` [PATCH 11/19] ceph: CRUSH mapping algorithm Sage Weil
2008-11-14 0:56 ` [PATCH 12/19] ceph: monitor client Sage Weil
2008-11-14 0:56 ` [PATCH 13/19] ceph: capability management Sage Weil
2008-11-14 0:56 ` [PATCH 14/19] ceph: snapshot management Sage Weil
2008-11-14 0:56 ` [PATCH 15/19] ceph: messenger library Sage Weil
2008-11-14 0:56 ` [PATCH 16/19] 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=1248292313-31326-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;
as well as URLs for NNTP newsgroup(s).