Subject: Supporting sector size != DEV_BSIZE on lfs
To: None <tech-kern@netbsd.org>
From: Trevin Beattie <trevin@xmission.com>
List: tech-kern
Date: 06/19/2002 13:31:39
To sum up what I've been doing: since my last set of patches (6/13), I
fixed the ffs code so that di_blocks is in terms of the file system's
sector size, and then following Bill's suggestion I added a new field to
struct ufsmount (which I call um_sshift) to allow the ufs code to do the
same for i_ffs_blocks.  Since i_ffs_blocks is shared by the lfs file
system, I started working on modifying it to support sector size !=
DEV_BSIZE as well.

This is taking me a long time, partly because I'm not familiar with lfs at
all, and also because it looks like LFS uses a whole lot more data in
sectors.  (Contrast with FFS, where most fs data is in terms of fragments.)

On the surface in looks like everything in the lfs structure is already set
up to use disk sectors instead of DEV_BSIZE blocks through the fields
dlfs_blktodb and dlfs_fsbtodb.  However, the code I've read so far uses
values in 'disk blocks' in many places for both on-disk data and values
passed to other kernel functions, which are supposed to be in units of
DEV_BSIZE.  It's often difficult to follow all the places where these
values are being sent.

There was a point to all this... um.. Oh, yes! :^)  I followed one
particular value -- the size by which as lfs fragment is extended,
converted to a number of sectors -- to the function lfs_fits
(sys/ufs/lfs/lfs_bio.c:192).  This function threw me for a loop:

* The function is called from lfs_fragextend with the statement "if
(!lfs_fits(fs, bb)) {".  'bb' is computed in terms of sectors.
* The comment block preceding the function states: "Determine if there is
enough room currently available to write db disk blocks."
* The function prototype reads: "lfs_fits(struct lfs *fs, int fsb)".  There
is no variable named 'db' in the entire function.
* The first statement in the function consists of:
  needed = fsb + btofsb(...) + fsbtodb(...);
  Whatever the units of fsb are (expected to be), btofsb given a number of
frags, and fsbtodb gives a number of sectors.

Is the last item a bug?  Since the next statement compares 'needed' to
lfs_avail, which is in terms of sectors, I'm guessing that 'needed' is
supposed to be a number of sectors.  If that's true, the middle term of the
equation needs to be changed to the equivalent of fsbtodb(btofsb(...)).

-----------------------
Trevin Beattie          "Do not meddle in the affairs of wizards,
trevin@xmission.com     for you are crunchy and good with ketchup."
      {:->                                     --unknown