Re: [Ext2-devel] ext2/ialloc.c cleanup

Andreas Dilger
2001-11-07T19:38:07Z

On Nov 06, 2001 18:17 -0500, Alexander Viro wrote:
> Folks, promised cleanup of ialloc.c is on
> ftp.math.psu.edu:pub/viro/ialloc.c,v
>
> And yes, it's in RCS. The thing is split into _really_ small
> steps (commented in the log). Each is a trivial transformation
> and it should be very easy to verify correctness of any of
> them.
>
> Please, review. IMO it's cut fine enough to make the gradual merge
> possible for 2.4 - look and you'll see.

Minor nits, from my changes to this same function:
1) please replace use of "i" for best block group in find_cg_*, to
something better like "group", just for clarity.
2) in find_cg_*, when you fail the quadratic search, the linear search
should skip groups that were previously checked in the quadratic search,
with slight changes to both loops:

start = dir->u.ext2_i.i_block_group;

/* Use quadratic hash to find group with a free inode */
for (j = 1; j < count; j <<= 1) {
group = start + j;
if (group >= count)
group -= count;
cg = ext2_get_group_desc(sb, group, &bh);
if (cg && le16_to_cpu(cg->bg_free_inodes_count))
goto found;
}

/* That failed: try linear search for a free inode
* skipping groups we checked in the previous loop.
*/
for (j = 3; j < count; j++) {
if ((j & (j - 1)) == 0)
continue;
group = start + j;
if (group > count)
group -= count;
cg = ext2_get_group_desc(sb, group, &bh);
if (cg && le16_to_cpu(cg->bg_free_inodes_count))
goto found;
}
3) I know that "cylinder groups" were used in old FFS/whatever implementation,
but all of the ext2 code/documentation refers to these as block groups.
Can you stick with that for ext2 (e.g. gdp, not cg; bg_foo, not cg_foo)?
4) sbi can be gotten by "EXT2_SB(sb)".

Cheers, Andreas
--
Andreas Dilger