|
| 1 | +#!/bin/bash |
| 2 | +# Basic test for mkfs.btrfs --inode-flags --rootdir. Create a dataset and use it as |
| 3 | +# rootdir, then various inode-flags and verify the flag is properly set. |
| 4 | + |
| 5 | +source "$TEST_TOP/common" || exit |
| 6 | + |
| 7 | +check_prereq mkfs.btrfs |
| 8 | +check_prereq btrfs |
| 9 | +check_global_prereq lsattr |
| 10 | + |
| 11 | +setup_root_helper |
| 12 | +prepare_test_dev |
| 13 | + |
| 14 | +tmp=$(_mktemp_dir mkfs-rootdir) |
| 15 | + |
| 16 | +write_file() |
| 17 | +{ |
| 18 | + local path="$1" |
| 19 | + local size="$2" |
| 20 | + |
| 21 | + run_check dd if=/dev/zero of="$path" bs="$size" count=1 status=noxfer > /dev/null 2>&1 |
| 22 | +} |
| 23 | + |
| 24 | +check_nodatacow() |
| 25 | +{ |
| 26 | + local path="$1" |
| 27 | + |
| 28 | + lsattr "$TEST_MNT"/"$path" | grep -q C || _fail "missing NODATACOW flag for $path" |
| 29 | +} |
| 30 | + |
| 31 | +write_file "$tmp/file1" 64K |
| 32 | +write_file "$tmp/file2" 64K |
| 33 | +run_check mkdir -p "$tmp/subv" "$tmp/nocow_subv" "$tmp/nocow_dir/dir2" |
| 34 | +write_file "$tmp/subv/file3" 64K |
| 35 | +write_file "$tmp/nocow_subv/file4" 64K |
| 36 | +write_file "$tmp/nocow_dir/dir2/file5" 64K |
| 37 | +write_file "$tmp/nocow_dir/file6" 64K |
| 38 | +write_file "$tmp/nocow_file1" 64K |
| 39 | + |
| 40 | +run_check_mkfs_test_dev --rootdir "$tmp" --inode-flags nodatacow:nocow_subv \ |
| 41 | + --subvol nocow_subv --inode-flags nodatacow:nocow_dir \ |
| 42 | + --inode-flags nodatacow:nocow_file1 |
| 43 | + |
| 44 | +run_check $SUDO_HELPER "$TOP/btrfs" check "$TEST_DEV" |
| 45 | + |
| 46 | +run_check_mount_test_dev |
| 47 | +check_nodatacow "nocow_subv" |
| 48 | +check_nodatacow "nocow_subv/file4" |
| 49 | +check_nodatacow "nocow_dir" |
| 50 | +check_nodatacow "nocow_dir/file6" |
| 51 | +check_nodatacow "nocow_dir/dir2/file5" |
| 52 | +check_nodatacow "nocow_file1" |
| 53 | +run_check lsattr -R "$TEST_MNT" |
| 54 | +run_check_umount_test_dev |
| 55 | +run_check rm -rf -- "$tmp" |
0 commit comments