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}
35 SANITYLOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
38 [ "$SANITYLOG" ] && rm -f $SANITYLOG || true
39 check_and_setup_lustre
51 TESTFILE=$DIR/$tdir/file
52 $RUNAS touch $TESTFILE
55 $RUNAS $LFS hsm_state $TESTFILE | grep -q "(0x00000000)" ||
56 error "wrong initial hsm state"
57 $RUNAS $LFS hsm_set --norelease $TESTFILE ||
58 error "user could not change hsm flags"
59 $RUNAS $LFS hsm_state $TESTFILE | grep -q "(0x00000010)" ||
60 error "wrong hsm state, should be: --norelease"
61 $RUNAS $LFS hsm_clear --norelease $TESTFILE ||
62 error "user could not clear hsm flags"
63 $RUNAS $LFS hsm_state $TESTFILE | grep -q "(0x00000000)" ||
64 error "wrong hsm state, should be empty"
66 # User could not change those flags...
67 $RUNAS $LFS hsm_set --exists $TESTFILE &&
68 error "user should not set this flag"
69 $RUNAS $LFS hsm_state $TESTFILE | grep -q "(0x00000000)" ||
70 error "wrong hsm state, should be empty"
73 $LFS hsm_set --exists $TESTFILE ||
74 error "root could not change hsm flags"
75 $LFS hsm_state $TESTFILE | grep -q "(0x00000001)" ||
76 error "wrong hsm state, should be: --exists"
77 $LFS hsm_clear --exists $TESTFILE ||
78 error "root could not clear hsm state"
79 $LFS hsm_state $TESTFILE | grep -q "(0x00000000)" ||
80 error "wrong hsm state, should be empty"
83 run_test 1 "lfs hsm flags root/non-root access"
87 TESTFILE=$DIR/$tdir/file
90 # New files are not dirty
91 $LFS hsm_state $TESTFILE | grep -q " (0x00000000)" ||
92 error "wrong hsm state: !0x0"
94 # For test, we simulate an archived file.
95 $LFS hsm_set --exists $TESTFILE || error "user could not change hsm flags"
96 $LFS hsm_state $TESTFILE | grep -q " (0x00000001)" ||
97 error "wrong hsm state: !0x1"
99 # chmod do not put the file dirty
100 chmod 600 $TESTFILE || error "could not chmod test file"
101 $LFS hsm_state $TESTFILE | grep -q " (0x00000001)" ||
102 error "wrong hsm state: !0x1"
104 # chown do not put the file dirty
105 chown $RUNAS_ID $TESTFILE || error "could not chown test file"
106 $LFS hsm_state $TESTFILE | grep -q " (0x00000001)" ||
107 error "wrong hsm state: !0x1"
109 # truncate put the file dirty
110 ./truncate $TESTFILE 1 || error "could not truncate test file"
111 $LFS hsm_state $TESTFILE | grep -q " (0x00000003)" ||
112 error "wrong hsm state: !0x3"
113 $LFS hsm_clear --dirty $TESTFILE || error "could not clear hsm flags"
114 $LFS hsm_state $TESTFILE | grep -q " (0x00000001)" ||
115 error "wrong hsm state: !0x1"
117 run_test 2 "Check file dirtyness when doing setattr"
121 TESTFILE=$DIR/$tdir/file
123 # New files are not dirty
124 cp -p /etc/passwd $TESTFILE
125 $LFS hsm_state $TESTFILE | grep -q " (0x00000000)" ||
126 error "wrong hsm state: !0x0"
128 # For test, we simulate an archived file.
129 $LFS hsm_set --exists $TESTFILE ||
130 error "user could not change hsm flags"
131 $LFS hsm_state $TESTFILE | grep -q " (0x00000001)" ||
132 error "wrong hsm state: !0x1"
134 # Reading a file, does not set dirty
135 cat $TESTFILE > /dev/null || error "could not read file"
136 $LFS hsm_state $TESTFILE | grep -q " (0x00000001)" ||
137 error "wrong hsm state: !0x1"
139 # Open for write without modifying data, does not set dirty
140 openfile -f O_WRONLY $TESTFILE || error "could not open test file"
141 $LFS hsm_state $TESTFILE | grep -q " (0x00000001)" ||
142 error "wrong hsm state: !0x1"
144 # Append to a file sets it dirty
145 cp -p /etc/passwd $TESTFILE.append || error "could not create file"
146 $LFS hsm_set --exists $TESTFILE.append ||
147 error "user could not change hsm flags"
148 dd if=/etc/passwd of=$TESTFILE.append bs=1 count=3 \
149 conv=notrunc,fdatasync oflag=append status=noxfer ||
150 error "could not append to test file"
151 $LFS hsm_state $TESTFILE.append | grep -q " (0x00000003)" ||
152 error "wrong hsm state: !0x3"
154 # Modify a file sets it dirty
155 cp -p /etc/passwd $TESTFILE.modify || error "could not create file"
156 $LFS hsm_set --exists $TESTFILE.modify ||
157 error "user could not change hsm flags"
158 dd if=/dev/zero of=$TESTFILE.modify bs=1 count=3 \
159 conv=notrunc,fdatasync status=noxfer ||
160 error "could not modify test file"
161 $LFS hsm_state $TESTFILE.modify | grep -q " (0x00000003)" ||
162 error "wrong hsm state: !0x3"
164 # Open O_TRUNC sets dirty
165 cp -p /etc/passwd $TESTFILE.trunc || error "could not create file"
166 $LFS hsm_set --exists $TESTFILE.trunc ||
167 error "user could not change hsm flags"
168 cp /etc/group $TESTFILE.trunc || error "could not override a file"
169 $LFS hsm_state $TESTFILE.trunc | grep -q " (0x00000003)" ||
170 error "wrong hsm state: !0x3"
172 # Mmapped a file sets dirty
173 cp -p /etc/passwd $TESTFILE.mmap || error "could not create file"
174 $LFS hsm_set --exists $TESTFILE.mmap ||
175 error "user could not change hsm flags"
176 multiop $TESTFILE.mmap OSMWUc || error "could not mmap a file"
177 $LFS hsm_state $TESTFILE.mmap | grep -q " (0x00000003)" ||
178 error "wrong hsm state: !0x3"
180 run_test 3 "Check file dirtyness when opening for write"
183 log "cleanup: ======================================================"
185 check_and_cleanup_lustre
186 echo '=========================== finished ==============================='
187 [ -f "$SANITYLOG" ] && cat $SANITYLOG && grep -q FAIL $SANITYLOG && exit 1 ||