mirror_zfs/module
Matthew Ahrens 6774931dfa
Extend zdb to print inconsistencies in livelists and metaslabs
Livelists and spacemaps are data structures that are logs of allocations
and frees.  Livelists entries are block pointers (blkptr_t). Spacemaps
entries are ranges of numbers, most often used as to track
allocated/freed regions of metaslabs/vdevs.

These data structures can become self-inconsistent, for example if a
block or range can be "double allocated" (two allocation records without
an intervening free) or "double freed" (two free records without an
intervening allocation).

ZDB (as well as zfs running in the kernel) can detect these
inconsistencies when loading livelists and metaslab.  However, it
generally halts processing when the error is detected.

When analyzing an on-disk problem, we often want to know the entire set
of inconsistencies, which is not possible with the current behavior.
This commit adds a new flag, `zdb -y`, which analyzes the livelist and
metaslab data structures and displays all of their inconsistencies.
Note that this is different from the leak detection performed by
`zdb -b`, which checks for inconsistencies between the spacemaps and the
tree of block pointers, but assumes the spacemaps are self-consistent.

The specific checks added are:

Verify livelists by iterating through each sublivelists and:
- report leftover FREEs
- report double ALLOCs and double FREEs
- record leftover ALLOCs together with their TXG [see Cross Check]

Verify spacemaps by iterating over each metaslab and:
- iterate over spacemap and then the metaslab's entries in the
  spacemap log, then report any double FREEs and double ALLOCs

Verify that livelists are consistenet with spacemaps.  The space
referenced by livelists (after using the FREE's to cancel out
corresponding ALLOCs) should be allocated, according to the spacemaps.

Reviewed-by: Serapheim Dimitropoulos <serapheim@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Co-authored-by: Sara Hartse <sara.hartse@delphix.com>
Signed-off-by: Matthew Ahrens <mahrens@delphix.com>
External-issue: DLPX-66031
Closes #10515
2020-07-14 17:51:05 -07:00
..
avl Cleanup linux module kbuild files 2020-06-10 09:24:15 -07:00
icp Make Skein_{Get,Put}64_LSB_First inline functions 2020-06-18 12:21:38 -07:00
lua Switch off -Wmissing-prototypes for libgcc math functions 2020-06-18 12:21:46 -07:00
nvpair Cleanup linux module kbuild files 2020-06-10 09:24:15 -07:00
os Fixing gang ABD child removal race condition 2020-07-14 11:04:35 -07:00
spl Cleanup linux module kbuild files 2020-06-10 09:24:15 -07:00
unicode Cleanup linux module kbuild files 2020-06-10 09:24:15 -07:00
zcommon Add device rebuild feature 2020-07-03 11:05:50 -07:00
zfs Extend zdb to print inconsistencies in livelists and metaslabs 2020-07-14 17:51:05 -07:00
.gitignore Cleanup linux module kbuild files 2020-06-10 09:24:15 -07:00
Kbuild.in Move zfs_gitrev.h to build directory 2020-06-24 18:19:28 -07:00
Makefile.bsd Add device rebuild feature 2020-07-03 11:05:50 -07:00
Makefile.in Include FreeBSD sources in module dist 2020-06-26 14:19:35 -07:00