• Kent Overstreet's avatar
    bcachefs: Revert lockless buffered IO path · e3e69409
    Kent Overstreet authored
    We had a report of data corruption on nixos when building installer
    images.
    
    https://github.com/NixOS/nixpkgs/pull/321055#issuecomment-2184131334
    
    It seems that writes are being dropped, but only when issued by QEMU,
    and possibly only in snapshot mode. It's undetermined if it's write
    calls are being dropped or dirty folios.
    
    Further testing, via minimizing the original patch to just the change
    that skips the inode lock on non appends/truncates, reveals that it
    really is just not taking the inode lock that causes the corruption: it
    has nothing to do with the other logic changes for preserving write
    atomicity in corner cases.
    
    It's also kernel config dependent: it doesn't reproduce with the minimal
    kernel config that ktest uses, but it does reproduce with nixos's distro
    config. Bisection the kernel config initially pointer the finger at page
    migration or compaction, but it appears that was erroneous; we haven't
    yet determined what kernel config option actually triggers it.
    
    Sadly it appears this will have to be reverted since we're getting too
    close to release and my plate is full, but we'd _really_ like to fully
    debug it.
    
    My suspicion is that this patch is exposing a preexisting bug - the
    inode lock actually covers very little in IO paths, and we have a
    different lock (the pagecache add lock) that guards against races with
    truncate here.
    
    Fixes: 7e64c86c ("bcachefs: Buffered write path now can avoid the inode lock")
    Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
    e3e69409
fs-io-buffered.c 26 KB