What actually happens when the checksum fails for a file using btrfs

btrfsflash-memorysd card

I'm testing using btrfs on my embedded Linux system. It uses a uSD card for the rfs. This system is remotely deployed so there's no human sysadmin to take care of it. My question is what happens when the checkum fails for reading a file? Is there any way of automatically detecting this and sending a message back to my central server?

Best Answer

Btrfs uses crc32c checksums to check the integrity of blocks. If the checksum doesn't match the block when it's read then an alternative block is read. This is assuming there is an alternative (RAID1). If that block also fails or if there is no alternative an EIO (error input/output) is returned.

I do not know of any way to automatically detecting errors, but all errors are logged to syslog. Try dmesg | grep btrfs. You should be looking for something like this:

[ 2993.114213] btrfs: sda2 checksum verify failed on 272228352 wanted 1A0FCFD3 found 119281BE level 0
[ 2993.114527] btrfs: sda2 checksum verify failed on 272228352 wanted 1A0FCFD3 found 119281BE level 0
[ 2993.114795] btrfs: sda2 checksum verify failed on 272228352 wanted 1A0FCFD3 found 119281BE level 0
[ 2993.115097] btrfs: sda2 checksum verify failed on 272228352 wanted 1A0FCFD3 found 119281BE level 0

You could probably make a script or a that looks through the logs and notifies you of errors at regular intervals. Or you could filter these log entries and trigger an rsyslog action.

Related Question