Unionfs: pass nameidata intent information to lower level file systems
authorErez_Zadok <ezk@cs.sunysb.edu>
Sun, 18 Nov 2007 02:22:54 +0000 (21:22 -0500)
committerRachita Kothiyal <rachita@dewey.fsl.cs.sunysb.edu>
Thu, 1 May 2008 23:03:00 +0000 (19:03 -0400)
As of 2.6.23-rc1, nfs2 and nfs3, like nfs4 before them, begin relying on the
struct nameidata and especially the intent information, which is passed to
vfs_create() and others.  So, as of now, unionfs properly creates and passes
that intent data to the lower level file system.  Currently supported are
LOOKUP_CREATE open intents.  Others can be supported in the future
incrementally.

Signed-off-by: Erez Zadok <ezk@cs.sunysb.edu>
fs/unionfs/copyup.c
fs/unionfs/lookup.c
fs/unionfs/rename.c
fs/unionfs/union.h

index c8e6e2d57114762e4c1b05f0b0fd909198a973ef..094bad4a154978e49face87b8a40aa59d504de64 100644 (file)
@@ -177,19 +177,26 @@ static int __copyup_ndentry(struct dentry *old_lower_dentry,
                run_sioq(__unionfs_mknod, &args);
                err = args.err;
        } else if (S_ISREG(old_mode)) {
+               struct nameidata *nd = alloc_lower_nd(LOOKUP_CREATE);
+               if (!nd) {
+                       err = -ENOMEM;
+                       goto out;
+               }
+               args.create.nd = nd;
                args.create.parent = new_lower_parent_dentry->d_inode;
                args.create.dentry = new_lower_dentry;
                args.create.mode = old_mode;
-               args.create.nd = NULL;
 
                run_sioq(__unionfs_create, &args);
                err = args.err;
+               free_lower_nd(nd, err);
        } else {
                printk(KERN_ERR "unionfs: unknown inode type %d\n",
                       old_mode);
                BUG();
        }
 
+out:
        return err;
 }
 
index 36f6bc033abed29811d59303b4cbd6f0cfe31882..45ac9767fdf4c92af07fd4de3e030a3d55e20052 100644 (file)
@@ -524,3 +524,65 @@ void update_bstart(struct dentry *dentry)
                unionfs_set_lower_dentry_idx(dentry, bindex, NULL);
        }
 }
+
+
+/*
+ * Allocate and fill in a nameidata structure (the intent part) we can pass
+ * to a lower file system.  Returns NULL on error (only -ENOMEM possible),
+ * or a valid allocated nameidata structure.  Inside that structure, this
+ * function may also return an allocated struct file (for open intents).
+ * The caller, when done with this nd, must kfree both the intent file and
+ * the entire nd.
+ */
+struct nameidata *alloc_lower_nd(unsigned int flags)
+{
+       struct nameidata *nd;
+#ifdef ALLOC_LOWER_ND_FILE
+       /*
+        * XXX: one day we may need to have the lower return an open file
+        * for us.  It is not needed in 2.6.23-rc1 for nfs2/nfs3, but may
+        * very well be needed for nfs4.
+        */
+       struct file *file;
+#endif /* ALLOC_LOWER_ND_FILE */
+
+       nd = kzalloc(sizeof(struct nameidata), GFP_KERNEL);
+       if (!nd)
+               goto out;
+
+       switch (flags) {
+       case LOOKUP_CREATE:
+               nd->flags = LOOKUP_CREATE;
+               nd->intent.open.flags = FMODE_READ | FMODE_WRITE | O_CREAT;
+#ifdef ALLOC_LOWER_ND_FILE
+               file = kzalloc(sizeof(struct file), GFP_KERNEL);
+               if (!file) {
+                       kfree(nd);
+                       nd = NULL;
+                       goto out;
+               }
+               nd->intent.open.file = file;
+#endif /* ALLOC_LOWER_ND_FILE */
+               break;
+       default:
+               /*
+                * We should never get here, for now.
+                * We can add new cases here later on.
+                */
+               BUG();
+               break;
+       }
+out:
+       return nd;
+}
+
+void free_lower_nd(struct nameidata *nd, int err)
+{
+       if (nd->intent.open.file) {
+               if (!err)
+                       fput(nd->intent.open.file); /* XXX: open file not needed? */
+               kfree(nd->intent.open.file);
+       }
+       kfree(nd);
+}
+
index 0121a95c4ae0af8e049b53559d5d5078f721e36e..e75b5d98fc016127d30f8d562c3f697862485854 100644 (file)
@@ -228,6 +228,7 @@ static int do_unionfs_rename(struct inode *old_dir,
                        if (err)
                                goto revert;
                }
+               free_lower_nd(nd, local_err);
        }
        else if (err && old_bstart == 0) {
                if (bindex == 0)
index dfd3931e72ce2bee6dbf3d5214bdf6ff6c69b072..bd7714cbad3d4b036dba01c43bad773660e60644 100644 (file)
@@ -266,6 +266,8 @@ static inline void unionfs_double_lock_dentry(struct dentry *d1,
 extern int new_dentry_private_data(struct dentry *dentry);
 extern void free_dentry_private_data(struct dentry *dentry);
 extern void update_bstart(struct dentry *dentry);
+extern struct nameidata *alloc_lower_nd(unsigned int flags);
+extern void free_lower_nd(struct nameidata *nd, int err);
 
 /*
  * EXTERNALS: