meson.build: Make keyutils independent from keyring
[qemu/kevin.git] / tests / avocado / virtiofs_submounts.py.data / guest.sh
blob59ba40fde17949005bf4e912f7d6eae5b04b415a
1 #!/bin/bash
3 function print_usage()
5 if [ -n "$2" ]; then
6 echo "Error: $2"
7 echo
8 fi
9 echo "Usage: $1 <shared dir>"
10 echo '(The shared directory is the "share" directory in the scratch' \
11 'directory)'
14 shared_dir=$1
15 if [ -z "$shared_dir" ]; then
16 print_usage "$0" 'Shared dir not given' >&2
17 exit 1
20 cd "$shared_dir"
22 # FIXME: This should not be necessary, but it is. In order for all
23 # submounts to be proper mount points, we need to visit them.
24 # (Before we visit them, they will not be auto-mounted, and so just
25 # appear as normal directories, with the catch that their st_ino will
26 # be the st_ino of the filesystem they host, while the st_dev will
27 # still be the st_dev of the parent.)
28 # `find` does not work, because it will refuse to touch the mount
29 # points as long as they are not mounted; their st_dev being shared
30 # with the parent and st_ino just being the root node's inode ID
31 # will practically ensure that this node exists elsewhere on the
32 # filesystem, and `find` is required to recognize loops and not to
33 # follow them.
34 # Thus, we have to manually visit all nodes first.
36 mnt_i=0
38 function recursively_visit()
40 pushd "$1" >/dev/null
41 for entry in *; do
42 if [[ "$entry" == mnt* ]]; then
43 mnt_i=$((mnt_i + 1))
44 printf "Triggering auto-mount $mnt_i...\r"
47 if [ -d "$entry" ]; then
48 recursively_visit "$entry"
50 done
51 popd >/dev/null
54 recursively_visit .
55 echo
58 if [ -n "$(find -name not-mounted)" ]; then
59 echo "Error: not-mounted files visible on mount points:" >&2
60 find -name not-mounted >&2
61 exit 1
64 if [ ! -f some-file -o "$(cat some-file)" != 'root' ]; then
65 echo "Error: Bad file in the share root" >&2
66 exit 1
69 shopt -s nullglob
71 function check_submounts()
73 local base_path=$1
75 for mp in mnt*; do
76 printf "Checking submount %i...\r" "$((${#devs[@]} + 1))"
78 mp_i=$(echo "$mp" | sed -e 's/mnt//')
79 dev=$(stat -c '%D' "$mp")
81 if [ -n "${devs[mp_i]}" ]; then
82 echo "Error: $mp encountered twice" >&2
83 exit 1
85 devs[mp_i]=$dev
87 pushd "$mp" >/dev/null
88 path="$base_path$mp"
89 while true; do
90 expected_content="$(printf '%s\n%s\n' "$mp_i" "$path")"
91 if [ ! -f some-file ]; then
92 echo "Error: $PWD/some-file does not exist" >&2
93 exit 1
96 if [ "$(cat some-file)" != "$expected_content" ]; then
97 echo "Error: Bad content in $PWD/some-file:" >&2
98 echo '--- found ---'
99 cat some-file
100 echo '--- expected ---'
101 echo "$expected_content"
102 exit 1
104 if [ "$(stat -c '%D' some-file)" != "$dev" ]; then
105 echo "Error: $PWD/some-file has the wrong device ID" >&2
106 exit 1
109 if [ -d sub ]; then
110 if [ "$(stat -c '%D' sub)" != "$dev" ]; then
111 echo "Error: $PWD/some-file has the wrong device ID" >&2
112 exit 1
114 cd sub
115 path="$path/sub"
116 else
117 if [ -n "$(echo mnt*)" ]; then
118 check_submounts "$path/"
120 break
122 done
123 popd >/dev/null
124 done
127 root_dev=$(stat -c '%D' some-file)
128 devs=()
129 check_submounts ''
130 echo
132 reused_devs=$(echo "$root_dev ${devs[@]}" | tr ' ' '\n' | sort | uniq -d)
133 if [ -n "$reused_devs" ]; then
134 echo "Error: Reused device IDs: $reused_devs" >&2
135 exit 1
138 echo "Test passed for ${#devs[@]} submounts."