- if ! $idle; then
- if $dryrun; then
- echo "$0: not idle. if this wasnt a dry run, btrfs scrub cancel $mnt"
- else
- btrfs scrub cancel $mnt &>/dev/null ||:
- continue
+ # Only run for $check, since it runs in parallel to non-check, avoid
+ # race condition.
+ if $check; then
+ tmp=$(mktemp)
+ # if mnt is /, avoid making a buggy looking path
+ stats_path=${mnt%/}/btrfs-dev-stats
+ if [[ ! -e $stats_path ]]; then
+ btrfs dev stats -c $mnt >$stats_path ||: # populate initial reading
+ elif ! btrfs dev stats -c $mnt >$tmp; then
+ if ! diff -q $stats_path $tmp; then
+ exim -t <<EOF
+From: root@$HOSTNAME.b8.nz
+To: alerts@iankelling.org
+Subject: btrfsmaintstop: btrfs dev stats -c $mnt
+
+$(diff -u $stats_path $tmp ||:)
+EOF
+ mv $stats_path $stats_path.1
+ cat $tmp >$stats_path
+ fi