commit fe9b2c28da7296773f3dab0d751239c82cb0fa21
Author: Yiannis Pericleous <[EMAIL PROTECTED]>
Date:   Sun Feb 4 21:02:38 2007 -0500

    Some cleanup. Use odf_dentry_info instead of plain dentry in 
unionfs_dentry_info

diff --git a/fs/unionfs/lookup.c b/fs/unionfs/lookup.c
index b9c3c7b..830a4e5 100644
--- a/fs/unionfs/lookup.c
+++ b/fs/unionfs/lookup.c
@@ -333,7 +333,7 @@ out_positive:
        unionfs_mntput(first_dentry, first_dentry_offset);
 
        /* check odf */
-       UNIONFS_D(dentry)->dodf = odf_lookup(parent_dentry, dentry, 0);
+       UNIONFS_D(dentry)->odf_info = odf_lookup(parent_dentry, dentry, 0);
 
        /* Partial lookups need to reinterpose, or throw away older negs. */
        if (lookupmode == INTERPOSE_PARTIAL) {
@@ -428,9 +428,8 @@ void free_dentry_private_data(struct unionfs_dentry_info 
*udi)
 {
        if (!udi)
                return;
-       if ( udi->dodf ) 
-               dput(udi->dodf);
-
+       odf_clear_info(udi->odf_info);
+       udi->odf_info = NULL;
        kmem_cache_free(unionfs_dentry_cachep, udi);
 }
 
@@ -464,7 +463,7 @@ int new_dentry_private_data(struct dentry *dentry)
        info->bend = -1;
        info->bopaque = -1;
        info->bcount = sbmax(dentry->d_sb);
-       info->dodf = NULL;
+       info->odf_info = NULL;
        atomic_set(&info->generation,
                   atomic_read(&UNIONFS_SB(dentry->d_sb)->generation));
 
diff --git a/fs/unionfs/main.c b/fs/unionfs/main.c
index d18de43..b2dc55c 100644
--- a/fs/unionfs/main.c
+++ b/fs/unionfs/main.c
@@ -72,10 +72,10 @@ int unionfs_interpose(struct dentry *dentry, struct 
super_block *sb, int flag)
                ino_t ino;
 
                /* get unique inode number for unionfs */
-               if ( !UNIONFS_D(dentry)->dodf )
-                       UNIONFS_D(dentry)->dodf = odf_lookup(dentry->d_parent, 
dentry, odf_flag);
+               if ( !UNIONFS_D(dentry)->odf_info )
+                       UNIONFS_D(dentry)->odf_info = 
odf_lookup(dentry->d_parent, dentry, odf_flag);
 
-               ino = UNIONFS_D(dentry)->dodf->d_inode->i_ino;
+               ino = UNIONFS_D(dentry)->odf_info->inum;
 
                inode = iget(sb, ino);
                if (!inode) {
@@ -625,10 +625,10 @@ static int unionfs_read_super(struct super_block *sb, 
void *raw_data,
        set_dbend(sb->s_root, bend);
        
        /* save odf root dentry */
-       UNIONFS_D(sb->s_root)->dodf = odf_getns();
-       if ( IS_ERR(UNIONFS_D(sb->s_root)->dodf )) {
-               err = PTR_ERR(UNIONFS_D(sb->s_root)->dodf);
-               UNIONFS_D(sb->s_root)->dodf = NULL;
+       UNIONFS_D(sb->s_root)->odf_info = odf_getns();
+       if ( IS_ERR(UNIONFS_D(sb->s_root)->odf_info )) {
+               err = PTR_ERR(UNIONFS_D(sb->s_root)->odf_info);
+               UNIONFS_D(sb->s_root)->odf_info = NULL;
                goto out_freedpd;
        }
 
diff --git a/fs/unionfs/odf.c b/fs/unionfs/odf.c
index 4bf1352..4e2e576 100644
--- a/fs/unionfs/odf.c
+++ b/fs/unionfs/odf.c
@@ -10,14 +10,14 @@ struct vfsmount* odf_read_super(char *odffile)
        struct vfsmount *odfmnt = NULL;
        int err = 0;
        
-       if ( odffile == NULL ) {
+       if (odffile == NULL) {
                printk(KERN_WARNING "unionfs_odf: No odf mount specified\n");
                odfmnt = ERR_PTR(-EINVAL);
                goto out;
        }
        
        err = path_lookup(odffile, LOOKUP_FOLLOW, &nd); 
-       if ( err ) {    
+       if (err) {      
                printk(KERN_WARNING "unionfs_odf: Cannot access odf mount\n");
                odfmnt = ERR_PTR(err);
                goto out;
@@ -45,26 +45,24 @@ void odf_put_super(struct super_block *sb)
 /*
        Returns the dentry of /odf/ns
 */
-struct dentry* odf_getns(void)
+struct odf_dentry_info* odf_getns(void)
 {
        struct nameidata nd;
-       struct dentry* dentry = NULL;
+       struct odf_dentry_info* odi = NULL;
        int err = 0;
        
        err = path_lookup(ODF_NS, LOOKUP_FOLLOW, &nd);  
-       if ( err ) {    
+       if (err) {      
                printk(KERN_WARNING "unionfs_odf: Invalid odf\n");
-               dentry = ERR_PTR(err);
+               odi = ERR_PTR(err);
                goto out;
        }
        
-       dentry = nd.dentry;
-       dget(dentry);
+       odi = odf_fill_info(nd.dentry);
        path_release(&nd);
        
 out:
-       return dentry;
-
+       return odi;
 }
 
 /*
@@ -72,50 +70,54 @@ out:
        else check for whiteouts
        Handle hard links
 */
-struct dentry *odf_lookup(struct dentry *parent, struct dentry *dentry, int 
flags)
+struct odf_dentry_info *odf_lookup(struct dentry *parent, struct dentry 
*dentry, int flags)
 {
-       struct dentry *res = NULL;
+       struct dentry *odf_dentry = NULL;
+       struct odf_dentry_info *odi = NULL;
        int err = 0;
 
-       if ( UNIONFS_D(dentry)->dodf ) {
-               dput(UNIONFS_D(dentry)->dodf);
-               UNIONFS_D(dentry)->dodf = NULL;
+       if (UNIONFS_D(dentry)->odf_info) {
+               odf_clear_info(UNIONFS_D(dentry)->odf_info);
+               UNIONFS_D(dentry)->odf_info = NULL;
        }
 
-       res = lookup_one_len(dentry->d_name.name, 
-                               UNIONFS_D(parent)->dodf,
+       odf_dentry = lookup_one_len(dentry->d_name.name, 
+                               UNIONFS_D(parent)->odf_info->dentry,
                                dentry->d_name.len);
 
        /* create inode in odf if dont exist */
        /* XXX: should we fail if res is ERR? */
-       if (IS_ERR(res) || !res->d_inode) {
+       if (IS_ERR(odf_dentry) || !odf_dentry->d_inode) {
                
                /* FIXME need to check hardlinks before create */
                if (flags & ODF_LOOKUP_FILE)
-                       err = vfs_create(UNIONFS_D(parent)->dodf->d_inode, res, 
S_IRWXUGO, 0 );
+                       err = 
vfs_create(UNIONFS_D(parent)->odf_info->dentry->d_inode, odf_dentry, S_IRWXUGO, 
0 );
 
                else if (flags & ODF_LOOKUP_DIR)
-                       err = vfs_mkdir(UNIONFS_D(parent)->dodf->d_inode, res, 
S_IRWXUGO);
+                       err = 
vfs_mkdir(UNIONFS_D(parent)->odf_info->dentry->d_inode, odf_dentry, S_IRWXUGO);
 
                else {
-                       dput(res);
-                       res = NULL;
+                       dput(odf_dentry);
+                       goto out;
                }
 
                /* XXX */
-               if (err) {
+               if (err)
                        printk(KERN_WARNING "could not create odf dentry" );
-               }
        }
        else {
                /* FIXME check for whiteouts & hardlinks */
        }
-       return res;
+       
+       odi = odf_fill_info(odf_dentry);
+
+out:
+       return odi;
 }
 
 int odf_create_wh(struct dentry *dentry)
 {
-       struct inode *i = UNIONFS_D(dentry)->dodf->d_inode;
+       struct inode *i = UNIONFS_D(dentry)->odf_info->dentry->d_inode;
        int err = 0;
        EXT2_I(i)->i_flags |= ODF_WHITEOUT;
        err = ext2_write_inode(i, 1);
@@ -123,7 +125,7 @@ int odf_create_wh(struct dentry *dentry)
 }
 int odf_is_wh(struct dentry *dentry)
 {
-       struct inode *i = UNIONFS_D(dentry)->dodf->d_inode;
+       struct inode *i = UNIONFS_D(dentry)->odf_info->dentry->d_inode;
        return EXT2_I(i)->i_flags & ODF_WHITEOUT;
 }
 
@@ -136,7 +138,7 @@ char *odf_getoptions(void)
        char *options = NULL;
        char *branch_entry = NULL;
 
-       if ( !odf_is_new(0) ) {
+       if (!odf_is_new(0)) {
                int i  = 0;
                struct nameidata nd_br;
                struct file *file;
@@ -182,11 +184,9 @@ char *odf_getoptions(void)
                        path_release(&nd_br);
 
                        ptr+=len;
-                       if ( perms == MAY_READ )
+                       if (perms == MAY_READ)
                                sprintf(ptr,"=ro:");
-                       else if ( perms == (MAY_READ | MAY_NFSRO) )
-                               sprintf(ptr,"=nfsro:");
-                       else if ( perms == (MAY_READ | MAY_WRITE) )
+                       else if (perms == (MAY_READ | MAY_WRITE))
                                sprintf(ptr,"=rw:");
                        ptr+=strlen(ptr);
                        i++;
@@ -200,7 +200,6 @@ out_err:
 out:
        kfree(branch_entry);
        return options;
-
 }
 
 /* checks the newbit, unset is a boolean, whether to unset the bit if it set */
@@ -212,13 +211,13 @@ int odf_is_new(int unset)
        
        /* check the new bit, for now check if file newbit exists */
        err = path_lookup(ODF_NEWBIT, LOOKUP_FOLLOW, &nd);      
-       if ( err ) {
+       if (err) {
                return 0; /* is not new */
        }
        else {
                newbit = nd.dentry;
                path_release(&nd);
-               if ( unset )
+               if (unset)
                        vfs_unlink(newbit->d_parent->d_inode, newbit);
                return 1;
        }
@@ -241,15 +240,14 @@ int odf_putoptions(struct super_block* sb_union, struct 
unionfs_dentry_info *hid
        char *branch_path = kmalloc(255, GFP_KERNEL); /*XXX*/
        mm_segment_t oldfs;
 
-       if ( !branch_entry || !branch_path ) {
+       if (!branch_entry || !branch_path) {
                err = -ENOMEM;
                goto out;
        }
 
        err = path_lookup(ODF_SB, LOOKUP_FOLLOW, &nd_sb);       
-       if ( err ) {
+       if (err)
                goto out;       
-       }
 
        for (bindex = hidden_root->bstart;
                        bindex >= 0 && bindex <= hidden_root->bend;
@@ -321,3 +319,25 @@ out:
        return err;
 }
 
+
+/* Allocates an odi and fills it with inode and dentry */
+struct odf_dentry_info *odf_fill_info(struct dentry *odf_dentry)
+{
+       struct odf_dentry_info *odi = kzalloc(sizeof(struct 
odf_dentry_info),GFP_KERNEL);
+       odi->dentry = odf_dentry;
+       odi->inum = odf_dentry->d_inode->i_ino;
+       dget(odf_dentry);
+       return odi;
+}
+
+/* Clears the odf_info data */
+void odf_clear_info(struct odf_dentry_info *odi)
+{
+       if (odi) {
+               if (odi->dentry)
+                       dput(odi->dentry);
+               kfree(odi);
+       }
+}
+
+
diff --git a/fs/unionfs/odf.h b/fs/unionfs/odf.h
index d0e4db1..08f0cb0 100644
--- a/fs/unionfs/odf.h
+++ b/fs/unionfs/odf.h
@@ -17,14 +17,20 @@
 /* Inode flags */ 
 #define ODF_WHITEOUT 0x01000000
 
-
+/* super */
 struct vfsmount* odf_read_super(char *odffile);
 void odf_put_super(struct super_block *sb);
 int odf_is_new(int unset);
 char *odf_getoptions(void);
 int odf_putoptions(struct super_block* sb_union, struct unionfs_dentry_info 
*hidden_root);
-struct dentry *odf_lookup(struct dentry *parent, struct dentry *dentry, int 
flags);
-struct dentry *odf_getns(void);
+
+/* lookup */
+struct odf_dentry_info *odf_lookup(struct dentry *parent, struct dentry 
*dentry, int flags);
+struct odf_dentry_info *odf_getns(void);
+struct odf_dentry_info *odf_fill_info(struct dentry *odf_dentry);
+void odf_clear_info(struct odf_dentry_info *odi);
+
+/* whiteouts */
 int odf_create_wh(struct dentry *dentry);
 int odf_is_wh(struct dentry *dentry);
 
diff --git a/fs/unionfs/union.h b/fs/unionfs/union.h
index 18d1c82..bbd7238 100644
--- a/fs/unionfs/union.h
+++ b/fs/unionfs/union.h
@@ -107,6 +107,16 @@ struct unionfs_inode_info {
        struct inode vfs_inode;
 };
 
+/* odf dentry data */
+struct odf_dentry_info {
+       /* The odf dentry info should contain info on the location of 
+        * the data in the odf file. Right now i keep a dentry for easy
+        * lookup in the underlying ext2 
+        */
+       u64 inum;
+       struct dentry *dentry;
+};
+
 /* unionfs dentry data in memory */
 struct unionfs_dentry_info {
        /* The semaphore is used to lock the dentry as soon as we get into a
@@ -119,7 +129,7 @@ struct unionfs_dentry_info {
        int bopaque;
        int bcount;
        atomic_t generation;
-       struct dentry *dodf;
+       struct odf_dentry_info *odf_info;
        struct path *lower_paths;
 };
 
_______________________________________________
unionfs-cvs mailing list: http://unionfs.filesystems.org/
[email protected]
http://www.fsl.cs.sunysb.edu/mailman/listinfo/unionfs-cvs

Reply via email to