Unionfs: stop using iget() and read_inode()
authorDavid Howells <dhowells@redhat.com>
Fri, 15 Feb 2008 22:18:48 +0000 (17:18 -0500)
committerErez Zadok <ezk@cs.sunysb.edu>
Fri, 12 Aug 2011 02:37:41 +0000 (22:37 -0400)
Replace unionfs_read_inode() with unionfs_iget(), and call that instead of
iget().  unionfs_iget() then uses iget_locked() directly and returns a
proper error code instead of an inode in the event of an error.

unionfs_fill_super() returns any error incurred when getting the root inode
instead of EINVAL.

Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Erez Zadok <ezk@cs.sunysb.edu>
fs/unionfs/main.c
fs/unionfs/super.c
fs/unionfs/union.h

index ba3471dc6279ee9ad1bdfaffab78ea2d024cf34c..4bc2c66039a29766907a5131d535c3f4767d4b89 100644 (file)
@@ -104,9 +104,8 @@ struct dentry *unionfs_interpose(struct dentry *dentry, struct super_block *sb,
        BUG_ON(is_negative_dentry);
 
        /*
-        * We allocate our new inode below, by calling iget.
-        * iget will call our read_inode which will initialize some
-        * of the new inode's fields
+        * We allocate our new inode below by calling unionfs_iget,
+        * which will initialize some of the new inode's fields
         */
 
        /*
@@ -128,9 +127,9 @@ struct dentry *unionfs_interpose(struct dentry *dentry, struct super_block *sb,
                }
        } else {
                /* get unique inode number for unionfs */
-               inode = iget(sb, iunique(sb, UNIONFS_ROOT_INO));
-               if (!inode) {
-                       err = -EACCES;
+               inode = unionfs_iget(sb, iunique(sb, UNIONFS_ROOT_INO));
+               if (IS_ERR(inode)) {
+                       err = PTR_ERR(inode);
                        goto out;
                }
                if (atomic_read(&inode->i_count) > 1)
index 175840f0162f3be63be1e026965246fb164128dd..b71fc2ad86ed4b1397723fb8e9b72b07dbda6ab3 100644 (file)
  */
 static struct kmem_cache *unionfs_inode_cachep;
 
-static void unionfs_read_inode(struct inode *inode)
+struct inode *unionfs_iget(struct super_block *sb, unsigned long ino)
 {
        int size;
-       struct unionfs_inode_info *info = UNIONFS_I(inode);
+       struct unionfs_inode_info *info;
+       struct inode *inode;
 
+       inode = iget_locked(sb, ino);
+       if (!inode)
+               return ERR_PTR(-ENOMEM);
+       if (!(inode->i_state & I_NEW))
+               return inode;
+
+       info = UNIONFS_I(inode);
        memset(info, 0, offsetof(struct unionfs_inode_info, vfs_inode));
        info->bstart = -1;
        info->bend = -1;
@@ -44,7 +52,8 @@ static void unionfs_read_inode(struct inode *inode)
        if (unlikely(!info->lower_inodes)) {
                printk(KERN_CRIT "unionfs: no kernel memory when allocating "
                       "lower-pointer array!\n");
-               BUG();
+               iget_failed(inode);
+               return ERR_PTR(-ENOMEM);
        }
 
        inode->i_version++;
@@ -60,7 +69,8 @@ static void unionfs_read_inode(struct inode *inode)
        inode->i_atime.tv_sec = inode->i_atime.tv_nsec = 0;
        inode->i_mtime.tv_sec = inode->i_mtime.tv_nsec = 0;
        inode->i_ctime.tv_sec = inode->i_ctime.tv_nsec = 0;
-
+       unlock_new_inode(inode);
+       return inode;
 }
 
 /*
@@ -1025,7 +1035,6 @@ out:
 }
 
 struct super_operations unionfs_sops = {
-       .read_inode     = unionfs_read_inode,
        .delete_inode   = unionfs_delete_inode,
        .put_super      = unionfs_put_super,
        .statfs         = unionfs_statfs,
index eca67bc1f7dd70b651385d6925fe3e39601db61b..a7f05387e3a469a409bd9590077eac95b17cab32 100644 (file)
@@ -371,6 +371,7 @@ extern int unionfs_fsync(struct file *file, struct dentry *dentry,
 extern int unionfs_fasync(int fd, struct file *file, int flag);
 
 /* Inode operations */
+extern struct inode *unionfs_iget(struct super_block *sb, unsigned long ino);
 extern int unionfs_rename(struct inode *old_dir, struct dentry *old_dentry,
                          struct inode *new_dir, struct dentry *new_dentry);
 extern int unionfs_unlink(struct inode *dir, struct dentry *dentry);