Home | History | Annotate | Download | only in fsck_lfs
History log of /src/sbin/fsck_lfs/pass5.c
RevisionDateAuthorComments
 1.38  14-Sep-2025  perseant Add -a flag to suppress warnings about discrepancies in avail accounting,
which is common with the -i flag.

Expand the computation of avail if the -d flag is given. The computation
itself is not changed.

Do not offer to roll forward if the -n flag was given.

Exit with FSCK_EXIT_UNRESOLVED if the -n flag was given and any questions
were asked. This is helpful when using fsck_lfs as a diagnostic in scripts.
 1.37  03-Apr-2020  joerg Avoid common symbols for fsck_lfs.
 1.36  01-Sep-2015  dholland branches: 1.36.16;
Use daddr_t, not ulfs_daddr_t, as the latter's 32 bits wide.
Don't use either for on-disk items.
Declare external data in header files.
Part 3 of 3.
 1.35  03-Aug-2015  dholland Use intmax_t to print daddr_t; from sevan@.
 1.34  02-Aug-2015  dholland Use accessor functions for the version field of the lfs superblock.
I thought at first maybe the cases that test the version should be
rolled into the accessors, but on the whole I think the conclusion on
that is no.
 1.33  02-Aug-2015  dholland Fix assorted 64 -> 32 truncations in lfs. Also, some minor tidyups and
corrections in passing.
 1.32  28-Jul-2015  dholland Add a new lfs header file: lfs_accessors.h.

This contains all the accessor functions and macros out of lfs.h.
Add an include of lfs_accessors.h after all uses of lfs.h... except
for code that wants to define its own struct lfs-alike that the
accessors are supposed to play along with. For these, set STRUCT_LFS
and include lfs_accessors.h after the necessary structure has been
defined, so that lfs_accessors.h can emit functions in terms of it.
 1.31  24-Jul-2015  dholland More lfs superblock accessors.
(This changes the rest of the code over; all the accessors were
already added.)

The difference between this commit and the previous one is arbitrary,
but the previous one passed the regression tests on its own so I'm
keeping it separate to help with any bisections that might be needed
in the future.
 1.30  24-Jul-2015  dholland Switch to accessor functions for elements of the LFS on-disk
superblock. This will allow switching between 32/64 bit forms on the
fly; it will also allow handling LFS_EI reasonably tidily. (That
currently doesn't work on the superblock.)

It also gets rid of cpp abuse in the form of fake structure member
macros.

Also, instead of doing sleep/wakeup on &lfs_avail and &lfs_nextseg
inside the on-disk superblock, add extra elements to the in-memory
struct lfs for this. (XXX: these should be changed to condvars, but
not right now)

XXX: this migrates a structure needed by the lfs code in libsa (struct
salfs) into lfs.h, where it doesn't belong, but for the time being
this is necessary in order to allow the accessors (and the various
lfs macros and other goop that relies on them) to compile.
 1.29  31-May-2015  hannken Use VFS_PROTOS() for lfs.
Rename conflicting struct lfs field "lfs_start" to "lfs_s0addr".

No functional change.
 1.28  18-Jun-2013  christos Prefix most of the cpp macros with lfs_ and LFS_ to avoid conflicts with ffs.
This was done so that boot blocks that want to compile both FFS and LFS in
the same file work.
 1.27  08-Jun-2013  dholland Tidy up the LFS userland build hacks.
Don't use -I${NETBSDSRCDIR}/sys; don't include files other than the
exported LFS headers, which are lfs.h, lfs_inode.h, and (for now)
lfs_extern.h.
 1.26  06-Jun-2013  dholland Cleanups and hacks to make lfs userland stuff build:
- lfs_cksum.c doesn't actually need ulfs_inode.h any more.
- neither does lfs_itimes.c.
- add hacks to fsck_lfs to make it compile.
- add hacks to newfs_lfs to make it compile.
- fix warning in ulfs_quota.c when quotas are fully disabled
(as I guess is happening with the rumpity version)

XXX: This commit adds -I${NETBSDSRCDIR}/sys to the Makefiles for
XXX: fsck_lfs, newfs_lfs, and lfs_cleanerd. This needs to be cleaned
XXX: up ASAP; but I consider this less problematic in the short term
XXX: than spewing ulfs_*.h into /usr/include.
 1.25  06-Jun-2013  dholland ufs -> ulfs for fsck_lfs.
 1.24  28-Apr-2008  martin branches: 1.24.20; 1.24.26;
Remove clause 3 and 4 from TNF licenses
 1.23  08-Oct-2007  ad branches: 1.23.8; 1.23.10;
Give brelse() a second argument so that it matches the kernel.
fsck_lfs now compiles again.
 1.22  16-Oct-2006  christos branches: 1.22.8;
comment out/delete impossible code
 1.21  01-Sep-2006  perseant Several fixes to improve the reliability of the roll-forward agent.
Also, note "properly orphaned" files as distinct from corrupted files.
 1.20  13-Aug-2006  bjh21 Fix typos in messages: SHOULE -> SHOULD
 1.19  18-Jul-2006  perseant Various improvements to fsck_lfs, to wit:

* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
 1.18  17-Apr-2006  perseant Remove the free list ordering/disordering code, since the kernel now keeps
the list in order (ordering it on mount).

Regularize error messages: these are now all in ALL CAPS, with all hex
numbers (not reported in caps) prefixed by 0x. (The non-fsck-specific
messages are an exception to this all-caps rule.)
 1.17  13-Sep-2005  christos rename lfs.h to lfs_user.h so that it does not conflict.
 1.16  23-Apr-2005  perseant Check parts of pass 5 even if only rolling forward. We can't check the true
segment holdings against the blocks held by the inodes, but we can still
check the cleanerinfo data against the segment table.
 1.15  11-Apr-2005  perseant Be more efficient with the hash tables for the buffer and vnode caches.

Note that roll-forward can add more inodes to the filesystem; don't overflow
the tables but reallocate them.
 1.14  19-Jan-2005  xtraeme branches: 1.14.2;
ANSIfy, WARNS=2
 1.13  14-May-2004  yamt pass5: dereference of an uninitialized pointer.
 1.12  28-Mar-2003  perseant Add working writing ability to fsck_lfs, including roll-forward, based on
a partial-segment writer ported from the kernel.
 1.11  23-Feb-2003  perseant Make the "-O" (start filesystem offset) flag to newfs_lfs work correctly,
and update fsck_lfs and dumplfs to deal with it. Note that while the argument
to -O is given in disk sectors, it must be a multiple of the fragment size,
and although it can be lower than the label or superblock, it can't intersect
either.
 1.10  23-May-2002  perseant Re-checksum the superblock whenever it is marked dirty.

Tested on alpha.
 1.9  13-Jul-2001  perseant branches: 1.9.2;
Merge the short-lived perseant-lfsv2 branch into the trunk.

Kernels and tools understand both v1 and v2 filesystems; newfs_lfs
generates v2 by default. Changes for the v2 layout include:

- Segments of non-PO2 size and arbitrary block offset, so these can be
matched to convenient physical characteristics of the partition (e.g.,
stripe or track size and offset).

- Address by fragment instead of by disk sector, paving the way for
non-512-byte-sector devices. In theory fragments can be as large
as you like, though in reality they must be smaller than MAXBSIZE in size.

- Use serial number and filesystem identifier to ensure that roll-forward
doesn't get old data and think it's new. Roll-forward is enabled for
v2 filesystems, though not for v1 filesystems by default.

- The inode free list is now a tailq, paving the way for undelete (undelete
is not yet implemented, but can be without further non-backwards-compatible
changes to disk structures).

- Inode atime information is kept in the Ifile, instead of on the inode;
that is, the inode is never written *just* because atime was changed.
Because of this the inodes remain near the file data on the disk, rather
than wandering all over as the disk is read repeatedly. This speeds up
repeated reads by a small but noticeable amount.

Other changes of note include:

- The ifile written by newfs_lfs can now be of arbitrary length, it is no
longer restricted to a single indirect block.

- Fixed an old bug where ctime was changed every time a vnode was created.
I need to look more closely to make sure that the times are only updated
during write(2) and friends, not after-the-fact during a segment write,
and certainly not by the cleaner.
 1.8  21-Nov-2000  perseant branches: 1.8.2;
Check/fix accounting of lfs_dmeta. Patch from Jesse Off
<joff@gci-net.com> (PR #11534).
 1.7  13-Nov-2000  perseant Report, and detect and correct inconsistencies in, the number of clean
segments. Patches from Jesse Off <joff@gci-net.com> (PR #11470).
 1.6  09-Sep-2000  perseant Various bug-fixes to LFS, to wit:


Kernel:

* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.

If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.

* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.

* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.

* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().

lfs_cleanerd:

* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.

* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.

* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.

* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).

fsck_lfs:

* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.

newfs_lfs:

* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.

* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).

* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.

mount_lfs:

* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.

* Default to calling lfs_cleanerd with "-b -n 4".


[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
 1.5  30-May-2000  perseant branches: 1.5.2;
Check for cycles in the inode free list, and for free inodes not on the free
list.
 1.4  23-May-2000  perseant branches: 1.4.2;
Convert to NetBSD source code style
 1.3  16-May-2000  perseant fsck_lfs can now write to the filesystem, allowing it to correct most
(though still not all) errors in a damaged lfs. Segment byte accounting
is corrected in pass 5. "fsck_lfs -p" will do a partial roll-forward,
verifying the checkpoint from the newer superblock. fscknames[] is
updated so that fsck knows about fsck_lfs.
 1.2  03-Jul-1999  kleink RCS Id police.
 1.1  18-Mar-1999  perseant Initial checkin of fsck_lfs. This version cannot do any repair (-p flag
does nothing, and one of -p or -n is required) but can be useful as a
diagnostic tool.
 1.4.2.1  22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.5.2.2  03-Feb-2001  he Pull up revisions 1.7-1.8 (requested by perseant):
Report/fix lfs_nclean inconsistencies.
Report/fix lfs_dmeta inconsistencies.
 1.5.2.1  14-Sep-2000  perseant Pull up LFS userland changes to correspond with the previous commit's
kernel changes (approved by thorpej):

[basesrc/libexec/lfs_cleanerd:]
cleanerd.c, 1.20--1.22 (MIN_FREE_SEG -> lfs_minfreeseg ;
read bfree/avail from CLEANERINFO ;
changes to definition of -n and -b)
lfs_cleanerd.8, 1.7 (update man page to current behavior)
library.c, 1.16 (fix comment)

[basesrc/sbin/fsck_lfs:]
pass5.c, 1.6 (calculate/fix lfs_avail and lfs_bfree)

[basesrc/sbin/newfs_lfs:]
config.h, 1.2--1.5 (MINFREE=20, remove FFS cruft ;
add DFL_MIN_FREE_SEGS=8 and MINFREE=10 ;
set DFL_MIN_FREE_SEGS=10 ;
set DFL_MIN_FREE_SEGS=20)
extern.h, 1.2 (correct function declaration for make_lfs)
newfs.c, 1.4 (add -M flag)
lfs.c, 1.13--1.14, 1.16--1.18 (change lfs_bfree initialization ;
MIN_FREE_SEG -> lfs_minfreeseg ;
only 10 superblocks and print nicely ;
correct init calculation of
lfs_bfree/lfs_avail to allow fs to
fill ;
make -N dtrt)

[basesrc/sbin/mount_lfs:]
mount_lfs.8, 1.7 (document -N, -b flags)
mount_lfs.c, 1.10 (default cleanerd to -b -n 4; add -N,
-b flags)

[basesrc/usr.sbin/dumplfs:]
dumplfs.c, 1.15 (print only the SEGUSEs specified with -s)
 1.8.2.2  02-Jul-2001  perseant Change disk addressing unit to be the fragment, instead of the disk sector.
All quantities in the superblock, inodes, indirect blocks, etc. refer now
to this abstract unit (called "fsb" as it is in FFS) instead of disk sectors;
as a consequence segment summary blocks have to be multiples of a fragment in
size. In v1 filesystems, compatibility code ensures that 1 fsb == 1 sector,
regardless of fragment size.

Fragments can now range in size between 512 and 32k; in the event that
LFS_LABELPAD (8k) is smaller than the disk address unit size, an extra
proto-superblock is kept at 8k from the beginning of the disk, to be used
*only* to locate the real superblocks. (Not all of the userland knows about
this yet.)

Almost all of this was done not by me, but by joff.
 1.8.2.1  27-Jun-2001  perseant Import of what I've been calling "LFSv2", that is, LFS with some features
added that require changes to the on-disk data structures. These include:

- 64-bit time in everything but inodes
- User-specified segment offset, and segment size no longer
restricted to PO2.
- Serial number on segment summaries in addition to timestamp, and
a new volume identifier, to make roll-forward feasible without
fear of finding old data and thinking it was new.

Although I think this version works at least as well as what's on the trunk,
we're not done yet; hence this commit is going in on a branch and not on
the trunk. Enhancements that are not here yet include fragment addressing,
like FFS does, instead of block addressing.
 1.9.2.1  02-Jun-2002  tv Pull up revision 1.10 (requested by perseant in ticket #131):
Re-checksum the superblock whenever it is marked dirty.
Tested on alpha.
 1.14.2.1  07-May-2005  tron Apply patch (requested by perseant in ticket #242):
* fsck_lfs buffer cache fixes, including PR #29151
* Change fsck_lfs phase 0 message to reflect reality
* fsck_lfs: check phase 5 (cleanerinfo accounting) even on
roll-forward
* Keep better track of the free list during roll-forward, avoiding
a core dump
* Improve hash table use for fsck_lfs buffer and vnode cache
* Document fsck_lfs flag -f, and implement -q
* Add resize_lfs, including kernel support
* Add LFS to mountd's list of exportable filesystem types
* Make the LFS lkm work again [christos@]
* Add MP locking to the LFS kernel subsystem
* Fix pager_map deadlock in lfs_putpages()
* Avoid incomplete file extension that looks like "partial
truncation" to fsck
* Use lfs_malloc for cleaner malloc, since the cleaner often runs
in low-memory conditions.
* Use splay trees, not hash table, to track page allocation for
write.
* Fix mkdir panic on full fs
* Fix page accounting leak by counting differently.
* Use rightly named structure for lfs_getattr [skrll@]
* Cosmetic changes for readability.
 1.22.8.1  06-Nov-2007  matt sync with HEAD
 1.23.10.1  18-May-2008  yamt sync with head.
 1.23.8.1  02-Jun-2008  mjf Sync with HEAD.
 1.24.26.1  23-Jun-2013  tls resync from head
 1.24.20.1  22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.36.16.1  08-Apr-2020  martin Merge changes from current as of 20200406

RSS XML Feed