]> git.neil.brown.name Git - LaFS.git/commitdiff
Add export operations for NFS export.
authorNeil Brown <neilb@nbeee.brown>
Wed, 14 Jul 2010 10:30:42 +0000 (20:30 +1000)
committerNeilBrown <neilb@suse.de>
Sun, 25 Jul 2010 05:34:26 +0000 (15:34 +1000)
Signed-off-by: NeilBrown <neilb@suse.de>
super.c

diff --git a/super.c b/super.c
index e3104da5517be9dddf1d4a72db2bb4cf561679d1..6179855413f0b58f3039ba99077c8d408e401add 100644 (file)
--- a/super.c
+++ b/super.c
 #include       <linux/crc32.h>
 #include       <linux/statfs.h>
 #include       <linux/mount.h>
+#include       <linux/exportfs.h>
 
 static struct super_operations lafs_sops;
+static const struct export_operations lafs_export_ops;
 
 /*---------------------------------------------------------------------
  * Write out state and super blocks
@@ -620,6 +622,7 @@ lafs_load(struct options *op, int newest)
                        dv->stateaddr[j] = le64_to_cpu(dv->devblk->stateaddr[j]);
 
                dv->sb->s_op = &lafs_sops;
+               dv->sb->s_export_op = &lafs_export_ops;
                dv->sb->s_root = NULL;
        }
        return fs;
@@ -936,6 +939,57 @@ static void __exit lafs_exit(void)
        lafs_ihash_free();
 }
 
+static struct inode *lafs_nfs_get_inode(struct super_block *sb,
+                                       u64 ino, u32 generation)
+{
+       struct inode *inode;
+
+       inode = lafs_iget(sb, ino, SYNC);
+       if (IS_ERR(inode))
+               return ERR_CAST(inode);
+       if (generation && inode->i_generation != generation) {
+               iput(inode);
+               return ERR_PTR(-ESTALE);
+       }
+
+       return inode;
+}
+
+static struct dentry *lafs_fh_to_dentry(struct super_block *sb, struct fid *fid,
+                                       int fh_len, int fh_type)
+{
+       return generic_fh_to_dentry(sb, fid, fh_len, fh_type,
+                                   lafs_nfs_get_inode);
+}
+
+static struct dentry *lafs_fh_to_parent(struct super_block *sb, struct fid *fid,
+                                       int fh_len, int fh_type)
+{
+       return generic_fh_to_parent(sb, fid, fh_len, fh_type,
+                                   lafs_nfs_get_inode);
+}
+
+static struct dentry *lafs_get_parent(struct dentry *child)
+{
+       ino_t inum = LAFSI(child->d_inode)->md.file.parent;
+       struct inode *inode = lafs_iget(child->d_inode->i_sb, inum, SYNC);
+       struct dentry *parent;
+       if (IS_ERR(inode))
+               return ERR_CAST(inode);
+       parent = d_alloc_anon(inode);
+       if (!parent) {
+               iput(inode);
+               parent = ERR_PTR(-ENOMEM);
+       }
+       return parent;
+}
+
+static const struct export_operations lafs_export_ops = {
+       .fh_to_dentry = lafs_fh_to_dentry,
+       .fh_to_parent = lafs_fh_to_parent,
+       .get_parent = lafs_get_parent,
+};
+
 static struct inode *lafs_alloc_inode(struct super_block *sb)
 {
        struct lafs_inode *li;