From: Neil Brown Date: Wed, 14 Jul 2010 10:30:42 +0000 (+1000) Subject: Add export operations for NFS export. X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=f99f8befed842079f9a11cba6f520b056150f7ce;p=LaFS.git Add export operations for NFS export. Signed-off-by: NeilBrown --- diff --git a/super.c b/super.c index e3104da..6179855 100644 --- a/super.c +++ b/super.c @@ -11,8 +11,10 @@ #include #include #include +#include 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;