BTRFS file corruption on SanDisk SD cards (potential fix)

Just making a note for anyone else running Raspbian 11 Bullseye: I was experiencing repeated crashes and found lots of btrfs “mmc_erase” errors in syslog. Long story short it appears there is a lowlevel issue with btrfs discard and some SD cards. The fix that appears (so far) to work is to add “nodiscard” to the btrfs options in fstab:

proc            /proc           proc    defaults          0       0
PARTUUID=123xyzpdq-01  /boot/efi           vfat    defaults          0       2
PARTUUID=123xyzpdq-02  /               btrfs    defaults,noatime,nodiscard  0       1

Ref: [PATCH 5.10 77/79] mmc: core: Add SD card quirk for broken discard - Greg Kroah-Hartman
Ref: btrfs file corruption with pci-e sd card reader with discard mount option(likely a driver bug?) : btrfs