simplify get_cramfs_inode()
authorAl Viro <viro@zeniv.linux.org.uk>
Sat, 5 Jun 2010 01:19:01 +0000 (21:19 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Mon, 9 Aug 2010 20:47:51 +0000 (16:47 -0400)
simply don't hash the inodes that don't have real inumber instead of
skipping them during iget5_locked(); as the result, simple iget_locked()
would do and we can get rid of cramfs ->drop_inode() as well.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/cramfs/inode.c

index dd3634e4c967983f2024221b33c34b81e51ad2ad..a53b130b366c738c654a7ec71a3e4b01ee6d8ec7 100644 (file)
@@ -39,66 +39,55 @@ static DEFINE_MUTEX(read_mutex);
 #define CRAMINO(x)     (((x)->offset && (x)->size)?(x)->offset<<2:1)
 #define OFFSET(x)      ((x)->i_ino)
 
-
-static int cramfs_iget5_test(struct inode *inode, void *opaque)
-{
-       struct cramfs_inode *cramfs_inode = opaque;
-       return inode->i_ino == CRAMINO(cramfs_inode) && inode->i_ino != 1;
-}
-
-static int cramfs_iget5_set(struct inode *inode, void *opaque)
+static void setup_inode(struct inode *inode, struct cramfs_inode * cramfs_inode)
 {
-       struct cramfs_inode *cramfs_inode = opaque;
-       inode->i_ino = CRAMINO(cramfs_inode);
-       return 0;
+       static struct timespec zerotime;
+       inode->i_mode = cramfs_inode->mode;
+       inode->i_uid = cramfs_inode->uid;
+       inode->i_size = cramfs_inode->size;
+       inode->i_blocks = (cramfs_inode->size - 1) / 512 + 1;
+       inode->i_gid = cramfs_inode->gid;
+       /* Struct copy intentional */
+       inode->i_mtime = inode->i_atime = inode->i_ctime = zerotime;
+       /* inode->i_nlink is left 1 - arguably wrong for directories,
+          but it's the best we can do without reading the directory
+          contents.  1 yields the right result in GNU find, even
+          without -noleaf option. */
+       if (S_ISREG(inode->i_mode)) {
+               inode->i_fop = &generic_ro_fops;
+               inode->i_data.a_ops = &cramfs_aops;
+       } else if (S_ISDIR(inode->i_mode)) {
+               inode->i_op = &cramfs_dir_inode_operations;
+               inode->i_fop = &cramfs_directory_operations;
+       } else if (S_ISLNK(inode->i_mode)) {
+               inode->i_op = &page_symlink_inode_operations;
+               inode->i_data.a_ops = &cramfs_aops;
+       } else {
+               init_special_inode(inode, inode->i_mode,
+                       old_decode_dev(cramfs_inode->size));
+       }
 }
 
 static struct inode *get_cramfs_inode(struct super_block *sb,
                                struct cramfs_inode * cramfs_inode)
 {
-       struct inode *inode = iget5_locked(sb, CRAMINO(cramfs_inode),
-                                           cramfs_iget5_test, cramfs_iget5_set,
-                                           cramfs_inode);
-       static struct timespec zerotime;
-
-       if (inode && (inode->i_state & I_NEW)) {
-               inode->i_mode = cramfs_inode->mode;
-               inode->i_uid = cramfs_inode->uid;
-               inode->i_size = cramfs_inode->size;
-               inode->i_blocks = (cramfs_inode->size - 1) / 512 + 1;
-               inode->i_gid = cramfs_inode->gid;
-               /* Struct copy intentional */
-               inode->i_mtime = inode->i_atime = inode->i_ctime = zerotime;
-               /* inode->i_nlink is left 1 - arguably wrong for directories,
-                  but it's the best we can do without reading the directory
-                  contents.  1 yields the right result in GNU find, even
-                  without -noleaf option. */
-               if (S_ISREG(inode->i_mode)) {
-                       inode->i_fop = &generic_ro_fops;
-                       inode->i_data.a_ops = &cramfs_aops;
-               } else if (S_ISDIR(inode->i_mode)) {
-                       inode->i_op = &cramfs_dir_inode_operations;
-                       inode->i_fop = &cramfs_directory_operations;
-               } else if (S_ISLNK(inode->i_mode)) {
-                       inode->i_op = &page_symlink_inode_operations;
-                       inode->i_data.a_ops = &cramfs_aops;
-               } else {
-                       init_special_inode(inode, inode->i_mode,
-                               old_decode_dev(cramfs_inode->size));
+       struct inode *inode;
+       if (CRAMINO(cramfs_inode) == 1) {
+               inode = new_inode(sb);
+               if (inode) {
+                       inode->i_ino = 1;
+                       setup_inode(inode, cramfs_inode);
+               }
+       } else {
+               inode = iget_locked(sb, CRAMINO(cramfs_inode));
+               if (inode) {
+                       setup_inode(inode, cramfs_inode);
+                       unlock_new_inode(inode);
                }
-               unlock_new_inode(inode);
        }
        return inode;
 }
 
-static void cramfs_drop_inode(struct inode *inode)
-{
-       if (inode->i_ino == 1)
-               generic_delete_inode(inode);
-       else
-               generic_drop_inode(inode);
-}
-
 /*
  * We have our own block cache: don't fill up the buffer cache
  * with the rom-image, because the way the filesystem is set
@@ -542,7 +531,6 @@ static const struct super_operations cramfs_ops = {
        .put_super      = cramfs_put_super,
        .remount_fs     = cramfs_remount,
        .statfs         = cramfs_statfs,
-       .drop_inode     = cramfs_drop_inode,
 };
 
 static int cramfs_get_sb(struct file_system_type *fs_type,