Wrapfs: support NFS exports
authorErez Zadok <ezk@cs.sunysb.edu>
Sun, 22 May 2016 05:27:13 +0000 (01:27 -0400)
committerErez Zadok <ezk@cs.sunysb.edu>
Tue, 27 Dec 2016 03:11:42 +0000 (22:11 -0500)
Based on patch from Sandeep Joshi <sanjos100@gmail.com>.

Signed-off-by: Erez Zadok <ezk@cs.sunysb.edu>
fs/wrapfs/lookup.c
fs/wrapfs/main.c
fs/wrapfs/super.c
fs/wrapfs/wrapfs.h

index 2edbeb59ffb9da109be1d46ff80bec8cf4084429..afa5063727af562bec0d49265d042aeb4d62ecf4 100644 (file)
@@ -279,7 +279,7 @@ setup_lower:
         * the VFS will continue the process of making this negative dentry
         * into a positive one.
         */
-       if (flags & (LOOKUP_CREATE|LOOKUP_RENAME_TARGET))
+       if (err == -ENOENT || (flags & (LOOKUP_CREATE|LOOKUP_RENAME_TARGET)))
                err = 0;
 
 out:
index b3042b62a1ade64a4053786bf8e9c9577afe0f41..71d11cf1a5946130c92783df0a19ca4072b30e1f 100644 (file)
@@ -64,6 +64,8 @@ static int wrapfs_read_super(struct super_block *sb, void *raw_data, int silent)
 
        sb->s_op = &wrapfs_sops;
 
+       sb->s_export_op = &wrapfs_export_ops; /* adding NFS support */
+
        /* get a new inode and allocate our root dentry */
        inode = wrapfs_iget(sb, lower_path.dentry->d_inode);
        if (IS_ERR(inode)) {
index dc9d25280db6450e685d709aed8379e4542fa01a..61ccd67e06d7858b3ab556cb6a0b1601e6e21e93 100644 (file)
@@ -166,3 +166,43 @@ const struct super_operations wrapfs_sops = {
        .destroy_inode  = wrapfs_destroy_inode,
        .drop_inode     = generic_delete_inode,
 };
+
+/* NFS support */
+
+static struct inode *wrapfs_nfs_get_inode(struct super_block *sb, u64 ino,
+                                         u32 generation)
+{
+       struct super_block *lower_sb;
+       struct inode *inode;
+       struct inode *lower_inode;
+
+       lower_sb = wrapfs_lower_super(sb);
+       lower_inode = ilookup(lower_sb, ino);
+       inode = wrapfs_iget(sb, lower_inode);
+       return inode;
+}
+
+static struct dentry *wrapfs_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,
+                                   wrapfs_nfs_get_inode);
+}
+
+static struct dentry *wrapfs_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,
+                                   wrapfs_nfs_get_inode);
+}
+
+/*
+ * all other funcs are default as defined in exportfs/expfs.c
+ */
+
+const struct export_operations wrapfs_export_ops = {
+       .fh_to_dentry      = wrapfs_fh_to_dentry,
+       .fh_to_parent      = wrapfs_fh_to_parent
+};
index 4cdf88463c347a59e98eb940bc2f72a2318b75d7..93d2643f360920a82915a8d846b07c3907388859 100644 (file)
@@ -27,6 +27,7 @@
 #include <linux/slab.h>
 #include <linux/sched.h>
 #include <linux/xattr.h>
+#include <linux/exportfs.h>
 
 /* the file system name */
 #define WRAPFS_NAME "wrapfs"
@@ -47,6 +48,7 @@ extern const struct super_operations wrapfs_sops;
 extern const struct dentry_operations wrapfs_dops;
 extern const struct address_space_operations wrapfs_aops, wrapfs_dummy_aops;
 extern const struct vm_operations_struct wrapfs_vm_ops;
+extern const struct export_operations wrapfs_export_ops;
 
 extern int wrapfs_init_inode_cache(void);
 extern void wrapfs_destroy_inode_cache(void);