Why do some ufs i-node fields have 2 copies?

Rick C. Petty rick-freebsd2008 at kiwi-computer.com
Mon Apr 27 13:52:02 UTC 2009


On Sun, Apr 26, 2009 at 06:26:14PM -0400, Rick Macklem wrote:
> 
> 
> >The reason is that the first set (the "copies") are what are referenced by
> >the ffs/ufs code.  The real copies are what came from the disk (hence the
> >"on-disk").  Because UFS1 & UFS2 have such different dinode structures, the
> >copies are moved to/from the dinode structures when the inode is read to or
> >written from the disk.  At all other times, the "copies" are used.
> >
> Righto. However some fields like i_mtime are just accessed using the
> DIP() and DIP_SET() macros.
> 
> Are you just saying that it was easier to not bother using the macros for 
> frequently referenced fields? (Or, to put it another way, "when support
> for UFS2 was added, the code would have looked really grotty if DIP() and
> DIP_SET() were used for frequently used fields?".)

No, it is silly to chase up the link to the superblock just to check for
the UFS version for every single access to these items.  Instead, all
accesses should be made to the copies *except* the ones which assemble the
dinode and store (or load) to disk.  In those cases, you already have to
access other items in the superblock of the cylinder group.

> The question came up because I had proposed a patch with:
> 
> 	DIP_SET(ip, i_modrev, DIP(ip, i_modrev) + 1);
> 
> in it and it was suggested that i_modrev might be more appropriate with
> a "shadow copy". Since I realized I didn't know why there were "shadow 
> copies" of some fields and not others, it lead to the original question.
> (This is the only place i_modrev gets manipulated by the patch.)

Yes, it would be.

> If my interpretation of your answer is correct, I'd say that a "shadow
> copy" doesn't really add anything to the code? What do others think?

It adds plenty-- you don't have to dereference more than the inode pointer.
If you don't use the shadows, you have to dereference the superblock (i_fs)
to get the UFS version as well as dereference the dinode itself.  It
doesn't make sense to change all the macros to not use the shadows.

-- Rick C. Petty


More information about the freebsd-fs mailing list