• Kent Overstreet's avatar
    bcachefs: Update btree ptrs after every write · 9f1833ca
    Kent Overstreet authored
    This closes a significant hole (and last known hole) in our ability to
    verify metadata. Previously, since btree nodes are log structured, we
    couldn't detect lost btree writes that weren't the first write to a
    given node. Additionally, this seems to have lead to some significant
    metadata corruption on multi device filesystems with metadata
    replication: since a write may have made it to one device and not
    another, if we read that btree node back from the replica that did have
    that write and started appending after that point, the other replica
    would have a gap in the bset entries and reading from that replica
    wouldn't find the rest of the bsets.
    
    But, since updates to interior btree nodes are now journalled, we can
    close this hole by updating pointers to btree nodes after every write
    with the currently written number of sectors, without negatively
    affecting performance. This means we will always detect lost or corrupt
    metadata - it also means that our btree is now a curious hybrid of COW
    and non COW btrees, with all the benefits of both (excluding
    complexity).
    Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
    9f1833ca
recovery.c 32.9 KB