iget_locked [6/6]

iget_locked [6/6]

Post by Jan Harke » Sun, 12 May 2002 01:20:12



As of the previous patch the inode_hashtable doesn't really need to be
indexed by i_ino anymore, the only reason we still have to keep the
hashvalue and i_ino identical is because of insert_inode_hash.

Here we simply add an argument to insert_inode_hash. If at some point a
FS specific getattr method is implemented it will be possible to
completely remove all uses of i_ino in the VFS.

======

diff -urN iget_locked-5/fs/adfs/inode.c iget_locked-6/fs/adfs/inode.c
--- iget_locked-5/fs/adfs/inode.c       Mon Apr 22 23:04:15 2002
+++ iget_locked-6/fs/adfs/inode.c       Fri May 10 10:34:58 2002
@@ -284,7 +284,7 @@
                ADFS_I(inode)->mmu_private = inode->i_size;
        }

-       insert_inode_hash(inode);
+       insert_inode_hash(inode, inode->i_ino);

 out:
        return inode;
diff -urN iget_locked-5/fs/affs/inode.c iget_locked-6/fs/affs/inode.c
--- iget_locked-5/fs/affs/inode.c       Mon Apr 22 23:04:15 2002
+++ iget_locked-6/fs/affs/inode.c       Fri May 10 10:34:58 2002
@@ -345,7 +345,7 @@
        AFFS_I(inode)->i_extcnt = 1;
        AFFS_I(inode)->i_ext_last = ~1;

-       insert_inode_hash(inode);
+       insert_inode_hash(inode, inode->i_ino);

        return inode;

diff -urN iget_locked-5/fs/bfs/dir.c iget_locked-6/fs/bfs/dir.c
--- iget_locked-5/fs/bfs/dir.c  Wed May  1 00:27:34 2002
+++ iget_locked-6/fs/bfs/dir.c  Fri May 10 10:34:58 2002
@@ -110,7 +110,7 @@
        BFS_I(inode)->i_dsk_ino = ino;
        BFS_I(inode)->i_sblock = 0;
        BFS_I(inode)->i_eblock = 0;
-       insert_inode_hash(inode);
+       insert_inode_hash(inode, inode->i_ino);
         mark_inode_dirty(inode);
        dump_imap("create",s);

diff -urN iget_locked-5/fs/coda/cnode.c iget_locked-6/fs/coda/cnode.c
--- iget_locked-5/fs/coda/cnode.c       Fri May 10 10:34:32 2002
+++ iget_locked-6/fs/coda/cnode.c       Fri May 10 10:34:58 2002
@@ -74,16 +74,17 @@
        struct inode *inode;
        struct coda_inode_info *cii;
        struct coda_sb_info *sbi = coda_sbp(sb);
-       ino_t ino = coda_f2i(fid);
+       unsigned long hash = coda_f2i(fid);

-       inode = iget5_locked(sb, ino, coda_test_inode, coda_set_inode, fid);
+       inode = iget5_locked(sb, hash, coda_test_inode, coda_set_inode, fid);

        if (!inode)
                return ERR_PTR(-ENOMEM);

        if (inode->i_state & I_NEW) {
                cii = ITOC(inode);
-               inode->i_ino = ino;
+               /* we still need to set i_ino for things like stat(2) */
+               inode->i_ino = hash;
                list_add(&cii->c_cilist, &sbi->sbi_cihead);
                unlock_new_inode(inode);
        }
@@ -124,6 +125,7 @@
                      struct ViceFid *newfid)
 {
        struct coda_inode_info *cii;
+       unsigned long hash = coda_f2i(newfid);

        cii = ITOC(inode);

@@ -134,23 +136,22 @@
        /* XXX we probably need to hold some lock here! */
        remove_inode_hash(inode);
        cii->c_fid = *newfid;
-       inode->i_ino = coda_f2i(newfid);
-       insert_inode_hash(inode);
+       inode->i_ino = hash;
+       insert_inode_hash(inode, hash);
 }

 /* convert a fid to an inode. */
 struct inode *coda_fid_to_inode(ViceFid *fid, struct super_block *sb)
 {
-       ino_t nr;
        struct inode *inode;
+       unsigned long hash = coda_f2i(fid);

        if ( !sb ) {
                printk("coda_fid_to_inode: no sb!\n");
                return NULL;
        }

-       nr = coda_f2i(fid);
-       inode = iget5_locked(sb, nr, coda_test_inode, coda_fail_inode, fid);
+       inode = iget5_locked(sb, hash, coda_test_inode, coda_fail_inode, fid);
        if ( !inode )
                return NULL;

diff -urN iget_locked-5/fs/cramfs/inode.c iget_locked-6/fs/cramfs/inode.c
--- iget_locked-5/fs/cramfs/inode.c     Wed May  1 00:27:34 2002
+++ iget_locked-6/fs/cramfs/inode.c     Fri May 10 10:34:58 2002
@@ -55,7 +55,7 @@
                   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. */
-               insert_inode_hash(inode);
+               insert_inode_hash(inode, inode->i_ino);
                if (S_ISREG(inode->i_mode)) {
                        inode->i_fop = &generic_ro_fops;
                        inode->i_data.a_ops = &cramfs_aops;
diff -urN iget_locked-5/fs/ext2/ialloc.c iget_locked-6/fs/ext2/ialloc.c
--- iget_locked-5/fs/ext2/ialloc.c      Mon Apr 22 23:04:15 2002
+++ iget_locked-6/fs/ext2/ialloc.c      Fri May 10 10:34:58 2002
@@ -405,7 +405,7 @@
        if (ei->i_flags & EXT2_SYNC_FL)
                inode->i_flags |= S_SYNC;
        inode->i_generation = EXT2_SB(sb)->s_next_generation++;
-       insert_inode_hash(inode);
+       insert_inode_hash(inode, inode->i_ino);
        mark_inode_dirty(inode);

        unlock_super (sb);
diff -urN iget_locked-5/fs/ext3/ialloc.c iget_locked-6/fs/ext3/ialloc.c
--- iget_locked-5/fs/ext3/ialloc.c      Mon Apr 22 23:04:15 2002
+++ iget_locked-6/fs/ext3/ialloc.c      Fri May 10 10:34:58 2002
@@ -508,7 +508,7 @@
                inode->i_flags |= S_SYNC;
        if (IS_SYNC(inode))
                handle->h_sync = 1;
-       insert_inode_hash(inode);
+       insert_inode_hash(inode, inode->i_ino);
        inode->i_generation = sb->u.ext3_sb.s_next_generation++;

        ei->i_state = EXT3_STATE_NEW;
diff -urN iget_locked-5/fs/fat/inode.c iget_locked-6/fs/fat/inode.c
--- iget_locked-5/fs/fat/inode.c        Fri May 10 10:30:06 2002
+++ iget_locked-6/fs/fat/inode.c        Fri May 10 10:34:59 2002
@@ -143,7 +143,7 @@
                goto out;
        }
        fat_attach(inode, ino);
-       insert_inode_hash(inode);
+       insert_inode_hash(inode, inode->i_ino);
 out:
        return inode;
 }
@@ -896,7 +896,7 @@
        if (error < 0)
                goto out_fail;
        error = -ENOMEM;
-       insert_inode_hash(root_inode);
+       insert_inode_hash(root_inode, root_inode->i_ino);
        sb->s_root = d_alloc_root(root_inode);
        if (!sb->s_root) {
                printk("FAT: get root inode failed\n");
diff -urN iget_locked-5/fs/inode.c iget_locked-6/fs/inode.c
--- iget_locked-5/fs/inode.c    Fri May 10 10:34:32 2002
+++ iget_locked-6/fs/inode.c    Fri May 10 10:34:59 2002
@@ -627,9 +627,9 @@
        return inode;
 }

-static inline unsigned long hash(struct super_block *sb, unsigned long i_ino)
+static inline unsigned long hash(struct super_block *sb, unsigned long hashval)
 {
-       unsigned long tmp = i_ino + ((unsigned long) sb / L1_CACHE_BYTES);
+       unsigned long tmp = hashval + ((unsigned long) sb / L1_CACHE_BYTES);
        tmp = tmp + (tmp >> I_HASHBITS);
        return tmp & I_HASHMASK;
 }
@@ -695,9 +695,9 @@
  * the filesystem gets back a new locked and hashed inode and gets
  * to fill it in before unlocking it via unlock_new_inode().
  */
-struct inode *iget5_locked(struct super_block *sb, unsigned long ino, int (*test)(struct inode *, void *), int (*set)(struct inode *, void *), void *data)
+struct inode *iget5_locked(struct super_block *sb, unsigned long hashval, int (*test)(struct inode *, void *), int (*set)(struct inode *, void *), void *data)
 {
-       struct list_head * head = inode_hashtable + hash(sb,ino);
+       struct list_head * head = inode_hashtable + hash(sb, hashval);
        struct inode * inode;

        spin_lock(&inode_lock);
@@ -746,16 +746,17 @@
 /**
  *     insert_inode_hash - hash an inode
  *     @inode: unhashed inode
+ *     @hashval: unsigned long persistent object identifier
  *
  *     Add an inode to the inode hash for this superblock. If the inode
  *     has no superblock it is added to a separate anonymous chain.
  */

-void insert_inode_hash(struct inode *inode)
+void insert_inode_hash(struct inode *inode, unsigned long hashval)
 {
        struct list_head *head = &anon_hash_chain;
        if (inode->i_sb)
-               head = inode_hashtable + hash(inode->i_sb, inode->i_ino);
+               head = inode_hashtable + hash(inode->i_sb, hashval);
        spin_lock(&inode_lock);
        list_add(&inode->i_hash, head);
        spin_unlock(&inode_lock);
diff -urN iget_locked-5/fs/jffs/inode-v23.c iget_locked-6/fs/jffs/inode-v23.c
--- iget_locked-5/fs/jffs/inode-v23.c   Wed May  1 00:27:35 2002
+++ iget_locked-6/fs/jffs/inode-v23.c   Fri May 10 10:34:59 2002
@@ -374,7 +374,7 @@
        f = jffs_find_file(c, raw_inode->ino);

        inode->u.generic_ip = (void *)f;
-       insert_inode_hash(inode);
+       insert_inode_hash(inode, inode->i_ino);

        return inode;
 }
diff -urN iget_locked-5/fs/jffs2/fs.c iget_locked-6/fs/jffs2/fs.c
--- iget_locked-5/fs/jffs2/fs.c Wed Apr 24 18:28:43 2002
+++ iget_locked-6/fs/jffs2/fs.c Fri May 10 10:34:59 2002
@@ -390,7 +390,7 @@
        inode->i_blocks = 0;
        inode->i_size = 0;

-       insert_inode_hash(inode);
+       insert_inode_hash(inode, inode->i_ino);

        return inode;
 }
diff -urN iget_locked-5/fs/jfs/namei.c iget_locked-6/fs/jfs/namei.c
--- iget_locked-5/fs/jfs/namei.c        Wed May  1 00:27:35 2002
+++ iget_locked-6/fs/jfs/namei.c        Fri May 10 10:34:59 2002
@@ -133,7 +133,7 @@
        ip->i_fop = &jfs_file_operations;
        ip->i_mapping->a_ops = &jfs_aops;

-       insert_inode_hash(ip);
+       insert_inode_hash(ip, ip->i_ino);
        mark_inode_dirty(ip);
        d_instantiate(dentry, ip);

@@ -257,7 +257,7 @@
        ip->i_mapping->a_ops = &jfs_aops;
        ip->i_mapping->gfp_mask = GFP_NOFS;

-       insert_inode_hash(ip);
+       insert_inode_hash(ip, ip->i_ino);
        mark_inode_dirty(ip);
        d_instantiate(dentry, ip);

@@ -991,7 +991,7 @@
        }
        dip->i_version = ++event;

-       insert_inode_hash(ip);
+       insert_inode_hash(ip, ip->i_ino);
        mark_inode_dirty(ip);
        d_instantiate(dentry, ip);

@@ -1353,7 +1353,7 @@

        init_special_inode(ip, ip->i_mode, rdev);

-       insert_inode_hash(ip);
+       insert_inode_hash(ip, ip->i_ino);
        mark_inode_dirty(ip);
        d_instantiate(dentry, ip);

diff -urN iget_locked-5/fs/minix/bitmap.c iget_locked-6/fs/minix/bitmap.c
--- iget_locked-5/fs/minix/bitmap.c     Mon Apr 22 23:04:17 2002
+++ iget_locked-6/fs/minix/bitmap.c     Fri May 10 10:35:00 2002
@@ -252,7 +252,7 @@
        inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
        inode->i_blocks = inode->i_blksize = 0;
        memset(&minix_i(inode)->u, 0, sizeof(minix_i(inode)->u));
-       insert_inode_hash(inode);
+       insert_inode_hash(inode, inode->i_ino);
        mark_inode_dirty(inode);

        *error = 0;
diff -urN iget_locked-5/fs/ncpfs/inode.c iget_locked-6/fs/ncpfs/inode.c
--- iget_locked-5/fs/ncpfs/inode.c      Mon Apr 22 23:04:17 2002
+++ iget_locked-6/fs/ncpfs/inode.c      Fri May 10 10:35:02 2002
@@ -281,7 +281,7 @@
                        inode->i_data.a_ops = &ncp_symlink_aops;
 #endif
                }
-               insert_inode_hash(inode);
+               insert_inode_hash(inode, inode->i_ino);
        } else
                printk(KERN_ERR "ncp_iget: iget failed!\n");
        return inode;
diff -urN iget_locked-5/fs/nfs/inode.c iget_locked-6/fs/nfs/inode.c
--- iget_locked-5/fs/nfs/inode.c        Fri May 10 10:34:32 2002
+++ iget_locked-6/fs/nfs/inode.c        Fri May 10 10:35:02 2002
@@ -652,7 +652,7 @@
...

read more »

 
 
 

iget_locked [6/6]

Post by Alexander Vir » Sun, 12 May 2002 05:20:08



> As of the previous patch the inode_hashtable doesn't really need to be
> indexed by i_ino anymore, the only reason we still have to keep the
> hashvalue and i_ino identical is because of insert_inode_hash.

> Here we simply add an argument to insert_inode_hash. If at some point a
> FS specific getattr method is implemented it will be possible to
> completely remove all uses of i_ino in the VFS.

How about

static inline void insert_inode_hash(struct inode *inode)
{
        __insert_inode_hash(inode, inode->i_hash);

Quote:}

in fs.h and switching those who want something different to direct use
of __insert_inode_hash()?

It's going to remain a very common case and IMO it makes a lot of sense
to keep a simple helper for it.  That has a nice property of getting
patch way smaller ;-)

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/