- if ! btrfs dev stats -c $mnt >$tmp; then
- if diff -q $mnt/btrfs-dev-stats $tmp; then
- diff -u $mnt/btrfs-dev-stats $tmp | mail -s "$HOSTNAME: error: btrfs dev stats -c $mnt" root@localhost
- cat $tmp >$mnt/btrfs-dev-stats
+ #### begin look for diff in stats, eg: increasing error count ####
+
+ # Only run for $check, since it runs in parallel to non-check, avoid
+ # race condition.
+ if $check; then
+ if ! btrfs dev stats -c $mnt >$tmp; then
+ if diff -q $mnt/btrfs-dev-stats $tmp; then
+ diff -u $mnt/btrfs-dev-stats $tmp | mail -s "$HOSTNAME: error: btrfs dev stats -c $mnt" root@localhost
+ cat $tmp >$mnt/btrfs-dev-stats
+ fi