3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
6 # Run test by setting NOSETUP=true when ltest has setup env for us
13 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/utils:$PATH:/sbin
16 SANITY_HSM_EXCEPT=${SANITY_HSM_EXCEPT:-""}
17 ALWAYS_EXCEPT="$SANITY_HSM_EXCEPT"
18 # bug number for skipped test:
19 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
21 [ "$ALWAYS_EXCEPT$EXCEPT" ] &&
22 echo "Skipping tests: `echo $ALWAYS_EXCEPT $EXCEPT`"
28 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
29 . $LUSTRE/tests/test-framework.sh
31 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
34 SANITYLOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
37 [ "$SANITYLOG" ] && rm -f $SANITYLOG || true
38 check_and_setup_lustre
40 if [ $MDSCOUNT -ge 2 ]; then
41 skip_env "Only run with single MDT for now" && exit
44 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.61) ]; then
45 skip_env "Need MDS version at least 2.3.61" && exit
57 TESTFILE=$DIR/$tdir/file
58 $RUNAS touch $TESTFILE
61 $RUNAS $LFS hsm_state $TESTFILE | grep -q "(0x00000000)" ||
62 error "wrong initial hsm state"
63 $RUNAS $LFS hsm_set --norelease $TESTFILE ||
64 error "user could not change hsm flags"
65 $RUNAS $LFS hsm_state $TESTFILE | grep -q "(0x00000010)" ||
66 error "wrong hsm state, should be: --norelease"
67 $RUNAS $LFS hsm_clear --norelease $TESTFILE ||
68 error "user could not clear hsm flags"
69 $RUNAS $LFS hsm_state $TESTFILE | grep -q "(0x00000000)" ||
70 error "wrong hsm state, should be empty"
72 # User could not change those flags...
73 $RUNAS $LFS hsm_set --exists $TESTFILE &&
74 error "user should not set this flag"
75 $RUNAS $LFS hsm_state $TESTFILE | grep -q "(0x00000000)" ||
76 error "wrong hsm state, should be empty"
79 $LFS hsm_set --exists $TESTFILE ||
80 error "root could not change hsm flags"
81 $LFS hsm_state $TESTFILE | grep -q "(0x00000001)" ||
82 error "wrong hsm state, should be: --exists"
83 $LFS hsm_clear --exists $TESTFILE ||
84 error "root could not clear hsm state"
85 $LFS hsm_state $TESTFILE | grep -q "(0x00000000)" ||
86 error "wrong hsm state, should be empty"
88 run_test 1 "lfs hsm flags root/non-root access"
92 TESTFILE=$DIR/$tdir/file
95 # New files are not dirty
96 $LFS hsm_state $TESTFILE | grep -q " (0x00000000)" ||
97 error "wrong hsm state: !0x0"
99 # For test, we simulate an archived file.
100 $LFS hsm_set --exists $TESTFILE || error "user could not change hsm flags"
101 $LFS hsm_state $TESTFILE | grep -q " (0x00000001)" ||
102 error "wrong hsm state: !0x1"
104 # chmod do not put the file dirty
105 chmod 600 $TESTFILE || error "could not chmod test file"
106 $LFS hsm_state $TESTFILE | grep -q " (0x00000001)" ||
107 error "wrong hsm state: !0x1"
109 # chown do not put the file dirty
110 chown $RUNAS_ID $TESTFILE || error "could not chown test file"
111 $LFS hsm_state $TESTFILE | grep -q " (0x00000001)" ||
112 error "wrong hsm state: !0x1"
114 # truncate put the file dirty
115 ./truncate $TESTFILE 1 || error "could not truncate test file"
116 $LFS hsm_state $TESTFILE | grep -q " (0x00000003)" ||
117 error "wrong hsm state: !0x3"
118 $LFS hsm_clear --dirty $TESTFILE || error "could not clear hsm flags"
119 $LFS hsm_state $TESTFILE | grep -q " (0x00000001)" ||
120 error "wrong hsm state: !0x1"
122 run_test 2 "Check file dirtyness when doing setattr"
126 TESTFILE=$DIR/$tdir/file
128 # New files are not dirty
129 cp -p /etc/passwd $TESTFILE
130 $LFS hsm_state $TESTFILE | grep -q " (0x00000000)" ||
131 error "wrong hsm state: !0x0"
133 # For test, we simulate an archived file.
134 $LFS hsm_set --exists $TESTFILE ||
135 error "user could not change hsm flags"
136 $LFS hsm_state $TESTFILE | grep -q " (0x00000001)" ||
137 error "wrong hsm state: !0x1"
139 # Reading a file, does not set dirty
140 cat $TESTFILE > /dev/null || error "could not read file"
141 $LFS hsm_state $TESTFILE | grep -q " (0x00000001)" ||
142 error "wrong hsm state: !0x1"
144 # Open for write without modifying data, does not set dirty
145 openfile -f O_WRONLY $TESTFILE || error "could not open test file"
146 $LFS hsm_state $TESTFILE | grep -q " (0x00000001)" ||
147 error "wrong hsm state: !0x1"
149 # Append to a file sets it dirty
150 cp -p /etc/passwd $TESTFILE.append || error "could not create file"
151 $LFS hsm_set --exists $TESTFILE.append ||
152 error "user could not change hsm flags"
153 dd if=/etc/passwd of=$TESTFILE.append bs=1 count=3 \
154 conv=notrunc oflag=append status=noxfer ||
155 error "could not append to test file"
156 $LFS hsm_state $TESTFILE.append | grep -q " (0x00000003)" ||
157 error "wrong hsm state: !0x3"
159 # Modify a file sets it dirty
160 cp -p /etc/passwd $TESTFILE.modify || error "could not create file"
161 $LFS hsm_set --exists $TESTFILE.modify ||
162 error "user could not change hsm flags"
163 dd if=/dev/zero of=$TESTFILE.modify bs=1 count=3 \
164 conv=notrunc status=noxfer ||
165 error "could not modify test file"
166 $LFS hsm_state $TESTFILE.modify | grep -q " (0x00000003)" ||
167 error "wrong hsm state: !0x3"
169 # Open O_TRUNC sets dirty
170 cp -p /etc/passwd $TESTFILE.trunc || error "could not create file"
171 $LFS hsm_set --exists $TESTFILE.trunc ||
172 error "user could not change hsm flags"
173 cp /etc/group $TESTFILE.trunc || error "could not override a file"
174 $LFS hsm_state $TESTFILE.trunc | grep -q " (0x00000003)" ||
175 error "wrong hsm state: !0x3"
177 # Mmapped a file sets dirty
178 cp -p /etc/passwd $TESTFILE.mmap || error "could not create file"
179 $LFS hsm_set --exists $TESTFILE.mmap ||
180 error "user could not change hsm flags"
181 multiop $TESTFILE.mmap OSMWUc || error "could not mmap a file"
182 $LFS hsm_state $TESTFILE.mmap | grep -q " (0x00000003)" ||
183 error "wrong hsm state: !0x3"
185 run_test 3 "Check file dirtyness when opening for write"
187 log "cleanup: ======================================================"
189 check_and_cleanup_lustre
190 echo '=========================== finished ==============================='
191 [ -f "$SANITYLOG" ] && cat $SANITYLOG && grep -q FAIL $SANITYLOG && exit 1 ||