Unionfs: pass nameidata intent information to lower level file systems 2.6.23-rc1-u1
authorErez_Zadok <ezk@cs.sunysb.edu>
Mon, 23 Jul 2007 07:13:01 +0000 (03:13 -0400)
committerErez_Zadok <ezk@cs.sunysb.edu>
Mon, 23 Jul 2007 07:13:01 +0000 (03:13 -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/subr.c
fs/unionfs/union.h

index eb5d5a0d50203a576c22ea17d352dfa1318f6eea..868923a434e7fd395d5c0283e6f4f47b933b377c 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 2045a437d66d2af1cf1de47a91ee9e988eebed0a..f21a9f3e8ff1ba88d18733dc5e2396919dc71e22 100644 (file)
@@ -573,3 +573,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 1761f8b6ae48fb1a0ee241db8641c36967778ba8..d6b0215343dcdf7ffd6fbc4c00400f023d52f1fc 100644 (file)
@@ -256,6 +256,7 @@ static int do_unionfs_rename(struct inode *old_dir,
         */
        if ((old_bstart != old_bend) || (do_copyup != -1)) {
                struct dentry *lower_parent;
+               struct nameidata *nd;
                if (!wh_old || wh_old->d_inode || bwh_old < 0) {
                        printk(KERN_ERR "unionfs: rename error "
                               "(wh_old=%p/%p bwh_old=%d)\n", wh_old,
@@ -263,9 +264,14 @@ static int do_unionfs_rename(struct inode *old_dir,
                        err = -EIO;
                        goto out;
                }
+               nd = alloc_lower_nd(LOOKUP_CREATE);
+               if (!nd) {
+                       err = -ENOMEM;
+                       goto out;
+               }
                lower_parent = lock_parent(wh_old);
                local_err = vfs_create(lower_parent->d_inode, wh_old, S_IRUGO,
-                                      NULL);
+                                      nd);
                unlock_dir(lower_parent);
                if (!local_err)
                        set_dbopaque(old_dentry, bwh_old);
@@ -278,6 +284,7 @@ static int do_unionfs_rename(struct inode *old_dir,
                               "the source in rename!\n");
                        err = -EIO;
                }
+               free_lower_nd(nd, local_err);
        }
 
 out:
index 5db9e6204a475a289878a4f37ff729dd87bc2c42..3b7673739da5a027110fbb5bfe97b4f0553089ae 100644 (file)
@@ -29,6 +29,7 @@ int create_whiteout(struct dentry *dentry, int start)
        struct dentry *lower_dir_dentry;
        struct dentry *lower_dentry;
        struct dentry *lower_wh_dentry;
+       struct nameidata *nd;
        char *name = NULL;
        int err = -EINVAL;
 
@@ -82,14 +83,20 @@ int create_whiteout(struct dentry *dentry, int start)
                        goto out;
                }
 
+               nd = alloc_lower_nd(LOOKUP_CREATE);
+               if (!nd) {
+                       err = -ENOMEM;
+                       goto out;
+               }
                lower_dir_dentry = lock_parent(lower_wh_dentry);
                if (!(err = is_robranch_super(dentry->d_sb, bindex)))
                        err = vfs_create(lower_dir_dentry->d_inode,
                                         lower_wh_dentry,
                                         ~current->fs->umask & S_IRWXUGO,
-                                        NULL);
+                                        nd);
                unlock_dir(lower_dir_dentry);
                dput(lower_wh_dentry);
+               free_lower_nd(nd, err);
 
                if (!err || !IS_COPYUP_ERR(err))
                        break;
@@ -151,6 +158,7 @@ int make_dir_opaque(struct dentry *dentry, int bindex)
        int err = 0;
        struct dentry *lower_dentry, *diropq;
        struct inode *lower_dir;
+       struct nameidata *nd;
 
        lower_dentry = unionfs_lower_dentry_idx(dentry, bindex);
        lower_dir = lower_dentry->d_inode;
@@ -165,10 +173,16 @@ int make_dir_opaque(struct dentry *dentry, int bindex)
                goto out;
        }
 
+       nd = alloc_lower_nd(LOOKUP_CREATE);
+       if (!nd) {
+               err = -ENOMEM;
+               goto out;
+       }
        if (!diropq->d_inode)
-               err = vfs_create(lower_dir, diropq, S_IRUGO, NULL);
+               err = vfs_create(lower_dir, diropq, S_IRUGO, nd);
        if (!err)
                set_dbopaque(dentry, bindex);
+       free_lower_nd(nd, err);
 
        dput(diropq);
 
index cd1f37c1026151a145fd31f3aaf6e0da3f867b01..00f2b3679cf479f4168e0f8b88339f0bd425e4e0 100644 (file)
@@ -252,6 +252,8 @@ extern int realloc_dentry_private_data(struct dentry *dentry);
 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: