/btrfs-unstable-atime-bug.sh
Last active Aug 29, 2015
a test to show that atimes are always updating on empty dirs in read-only snapshots which were subvol parents, unlike plain empty dirs, regardless of mounting with noatime
| #!/bin/sh | |
| set -e | |
| get_atime() { | |
| ls -lad --time=atime --time-style='+%Y-%m-%dT%H:%M:%S%z' "$1" | tail -n+1 \ | |
| | cut -d ' ' -f6 - | |
| } | |
| FAIL=0 | |
| test_atime_stable() { | |
| DIR="$1" | |
| FIRST=$(get_atime "$DIR") | |
| echo "Testing that '$DIR' has repeatable atime of" | |
| echo " ${FIRST}..." | |
| for i in 1 2; do | |
| sleep 2 | |
| TEST=$(get_atime "$DIR") | |
| echo "$i: $TEST" | |
| if [ "$FIRST" != "$TEST" ]; then FAIL=1; fi | |
| done | |
| if [ "$FAIL" = "1" ]; then | |
| echo " FAIL $DIR atime is unstable :(" | |
| else | |
| echo " pass $DIR atime is stable :)" | |
| fi | |
| } | |
| test_send_receive() { | |
| DIR="$1" | |
| SRC="$2" | |
| DST_PARENT="$DIR/snapshots" | |
| DST="$DST_PARENT/1" | |
| mkdir -p "$DST_PARENT" | |
| btrfs send "$SRC" | btrfs receive "$DST_PARENT/" | |
| NUM_SRC=$(find "$SRC" -type d |wc -l) | |
| NUM_DST=$(find "$DST" -type d |wc -l) | |
| if [ "$NUM_SRC" = "$NUM_DST" ]; then | |
| echo " pass number of dirs in '$SRC'='$DST' ($NUM_SRC=$NUM_DST)" | |
| else | |
| echo " FAIL number of dirs in '$SRC'!='$DST' ($NUM_SRC!=$NUM_DST)" | |
| FAIL=1 | |
| fi | |
| } | |
| IMG=$(mktemp) | |
| MNT=$(mktemp -d) | |
| truncate -s 20M "$IMG" | |
| mkfs.btrfs "$IMG" | |
| modprobe loop | |
| mount -v -o noatime "$IMG" "$MNT" | |
| echo "Showing mount:" | |
| mount |grep "$IMG" | |
| btrfs subvolume create "$MNT/subvol" | |
| mkdir -v "$MNT/snapshots" | |
| mkdir -v "$MNT/empty_dir" | |
| btrfs subvolume snapshot -r "$MNT" "$MNT/snapshots/1" | |
| echo "Testing that the subvol dir has stable atime on original parent FS:" | |
| test_atime_stable "$MNT/subvol" | |
| echo "Testing that a normal empty dir has stable atime on the snapshot:" | |
| test_atime_stable "$MNT/snapshots/1/empty_dir" | |
| echo "Testing that the subvol dir has stable atime on snapshot of parent FS:" | |
| test_atime_stable "$MNT/snapshots/1/subvol" | |
| echo "Testing that the same number of directories is received from btrfs send:" | |
| test_send_receive "$MNT/received" "$MNT/snapshots/1" | |
| if [ "$1" = "nocleanup" ]; then | |
| echo "'$0 nocleanup' specified so leaving our mess behind:" | |
| echo " btrfs filesystem image file: $IMG" | |
| echo " btrfs filesystem mountpoint: $MNT" | |
| else | |
| echo "'$0 nocleanup' not specified so cleaning up our mess:" | |
| umount -v "$MNT" | |
| rmdir -v "$MNT" | |
| rm -v "$IMG" | |
| fi | |
| exit "$FAIL" | |
| # on Debian Linux sid 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt9-1 (2015-04-08) x86_64 GNU/Linux | |
| # SMALL VOLUME: forcing mixed metadata/data groups | |
| # Btrfs v3.17 | |
| # See http://btrfs.wiki.kernel.org for more information. | |
| # | |
| # Turning ON incompat feature 'mixed-bg': mixed data and metadata block groups | |
| # Turning ON incompat feature 'extref': increased hardlink limit per file to 65536 | |
| # Created a data/metadata chunk of size 2097152 | |
| # ERROR: device scan failed '/tmp/tmp.vX7LBQhMRn' - Block device required | |
| # fs created label (null) on /tmp/tmp.vX7LBQhMRn | |
| # nodesize 4096 leafsize 4096 sectorsize 4096 size 20.00MiB | |
| # mount: /dev/loop3 mounted on /tmp/tmp.vkQaOOgI0T. | |
| # Showing mount: | |
| # /tmp/tmp.vX7LBQhMRn on /tmp/tmp.vkQaOOgI0T type btrfs (rw,noatime,space_cache) | |
| # Create subvolume '/tmp/tmp.vkQaOOgI0T/subvol' | |
| # mkdir: created directory ‘/tmp/tmp.vkQaOOgI0T/snapshots’ | |
| # mkdir: created directory ‘/tmp/tmp.vkQaOOgI0T/empty_dir’ | |
| # Create a readonly snapshot of '/tmp/tmp.vkQaOOgI0T' in '/tmp/tmp.vkQaOOgI0T/snapshots/1' | |
| # Testing that the subvol dir has stable atime on original parent FS: | |
| # Testing that '/tmp/tmp.vkQaOOgI0T/subvol' has repeatable atime of | |
| # 2015-04-23T13:58:45+1000... | |
| # 1: 2015-04-23T13:58:45+1000 | |
| # 2: 2015-04-23T13:58:45+1000 | |
| # pass /tmp/tmp.vkQaOOgI0T/subvol atime is stable :) | |
| # Testing that a normal empty dir has stable atime on the snapshot: | |
| # Testing that '/tmp/tmp.vkQaOOgI0T/snapshots/1/empty_dir' has repeatable atime of | |
| # 2015-04-23T13:58:45+1000... | |
| # 1: 2015-04-23T13:58:45+1000 | |
| # 2: 2015-04-23T13:58:45+1000 | |
| # pass /tmp/tmp.vkQaOOgI0T/snapshots/1/empty_dir atime is stable :) | |
| # Testing that the subvol dir has stable atime on snapshot of parent FS: | |
| # Testing that '/tmp/tmp.vkQaOOgI0T/snapshots/1/subvol' has repeatable atime of | |
| # 2015-04-23T13:58:53+1000... | |
| # 1: 2015-04-23T13:58:55+1000 | |
| # 2: 2015-04-23T13:58:57+1000 | |
| # FAIL /tmp/tmp.vkQaOOgI0T/snapshots/1/subvol atime is unstable :( | |
| # Testing that the same number of directories is received from btrfs send: | |
| # At subvol /tmp/tmp.vkQaOOgI0T/snapshots/1 | |
| # At subvol 1 | |
| # FAIL number of dirs in '/tmp/tmp.vkQaOOgI0T/snapshots/1'!='/tmp/tmp.vkQaOOgI0T/received/snapshots/1' (4!=3) | |
| # './btrfs-unstable-atime-bug.sh nocleanup' specified so leaving our mess behind: | |
| # btrfs filesystem image file: /tmp/tmp.vX7LBQhMRn | |
| # btrfs filesystem mountpoint: /tmp/tmp.vkQaOOgI0T |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment