Re: [PATCH] cramfs: generate unique inode number for better inode cache usage

Linus Torvalds
2010-12-14T23:44:46Z

On Tue, Dec 14, 2010 at 3:32 PM, Linus Torvalds
<torvalds@linux-foundation.org> wrote:
> Why do you repeat that
>
>    inode = iget_locked(sb, cramino(cramfs_inode, offset));
>    if (inode && (inode->i_state & I_NEW)) {
>
> so many times?
>
> Wouldn't it be nicer to just do it once at the top?

Oh, and I think it's probably nicer to then do the if-statements as a

switch (cram_inode->mode & S_IFMT) {
case S_IFREG:
..

but what I objected to in the previous patch was doing it multiple
times, and moving the nice separate helper function into the caller.

So I _think_ you should be able to just do something like this:

ino = cramino(cramfs_inode, offset);
switch (cram_inode->mode & S_IFMT) {
case S_IFREG:
fops = generic_ro_fops;
aops = &cramfs_aops;
break;
case S_IFDIR:
...
default:
ino = CRAMINO_UNIQ(offset);
}
inode = iget_locked(sb, ino);
if (inode && (inode->i_state & I_NEW)) {
inode->i_ops = iops;
inode->i_fops = fops;
inode->i_data.a_ops = aops;
setup_inode(inode, cramfs_inode, cramfs_inode->size);
}

or whatever?

Linus