1 #! /usr/bin/ksh -p
2 #
3 # CDDL HEADER START
4 #
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
8 #
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
13 #
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 #
20 # CDDL HEADER END
21 #
22
23 #
24 # Copyright 2006 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26 #
27 # NFSv4 named attributes:
28 # a: Test copy/rename of file w/named attrs using attr cp command, expect OK
29 # b: Test creating hardlink in a file's attrdir, expect OK
30 #
31
32 funcs="./attrcmds_funcs"
33 [ ! -r $funcs ] && echo "$0 ERROR: cannot source $funcs" && exit $UNINITIATED
34 . $funcs
35
36 setup
37
38 # Assume that xattr mount option is set by default on UFS filesystems
39 # Use pre-mounted filesystem previously setup by nfs4_gen framework
40
41 # Start test
42 # -----------------------------------------------------------------------
43 # a: Test copy/rename of file w/named attrs using attr cp \
44 # command, expect OK
45 ASSERTION="Test copy/rename of file w/named attrs using attr cp command"
46 ASSERTION="$ASSERTION, expect OK"
47 echo "$NAME{a}: $ASSERTION"
48
49 #Ensure that test file doesn't already exist
50 rm -f $MNTPTR/$TESTFILE > /dev/null 2>&1
51
52 #Check mount point works
53 ls $MNTPTR > /dev/null 2> $TMPDIR/$NAME.out.$$
54 ret=$?
55 ckreturn $ret "mount point $MNTPTR not accessible (ret=$ret)" \
56 $TMPDIR/$NAME.out.$$ UNINITIATED
57 [ $? -ne 0 ] && cleanup $UNINITIATED
58
59 # Create a test file
60 echo "This is a file" > $MNTPTR/$TESTFILE 2> $TMPDIR/$NAME.out.$$
61 ret=$?
62 ckreturn $ret "Cannot create testfile $TESTFILE, returned $ret." \
63 $TMPDIR/$NAME.out.$$ UNINITIATED
64 [ $? -ne 0 ] && cleanup $UNINITIATED
65
66 # Verify test file is accessible
67 $LSAT $MNTPTR/$TESTFILE > $TMPDIR/$NAME.out.$$ 2>&1
68 ret=$?
69 ckreturn $ret "$LSAT cannot access testfile $TESTFILE, returned $ret." \
70 $TMPDIR/$NAME.out.$$
71 [ $? -ne 0 ] && cleanup $FAIL
72
73 sleep 1
74 # Now Create named attribute for file object
75 echo "This is an attribute" | runat $MNTPTR/$TESTFILE "cat > attrfile" \
76 > $TMPDIR/$NAME.out.$$ 2>&1
77 ret=$?
78 ckreturn $ret "Cannot create named attr on [$TESTFILE], returned $ret." \
79 $TMPDIR/$NAME.out.$$
80 [ $? -ne 0 ] && cleanup $FAIL
81
82 sleep 1
83 # Verify test file and new attrdir still accessible
84 RESULT=$($LSAT $MNTPTR/$TESTFILE | awk '{print $1}' | cut -c11 \
85 2> $TMPDIR/$NAME.out.$$)
86 ret=0 && [ "$RESULT" != "@" ] && ret=1
87 ckreturn $ret "$LSAT command cannot access attr (res=$RESULT)" \
88 $TMPDIR/$NAME.out.$$
89 [ $? -ne 0 ] && cleanup $FAIL
90
91 sleep 1
92 runat $MNTPTR/$TESTFILE ls -l > $TMPDIR/$NAME.out.$$ 2>&1
93 ret=$?
94 ckreturn $ret "'runat $MNTPTR/$TESTFILE ls -l' failed, returned $ret." \
95 $TMPDIR/$NAME.out.$$
96 [ $? -ne 0 ] && cleanup $FAIL
97
98 sleep 1
99 # Verify can use named attr cp command in named attr space
100 $CPAT $MNTPTR/$TESTFILE $MNTPTR/$NEWFILE > $TMPDIR/$NAME.out.$$ 2>&1
101 ret=$?
102 ckreturn $ret \
103 "'$CPAT $MNTPTR/$TESTFILE $MNTPTR/$NEWFILE' failed, returned $ret" \
104 $TMPDIR/$NAME.out.$$
105 [ $? -ne 0 ] && cleanup $FAIL
106
107 sleep 1
108 # Verify new file still accessible
109 RESULT=$($LSAT $MNTPTR/$NEWFILE | awk '{print $1}' | cut -c11 \
110 2> $TMPDIR/$NAME.out.$$)
111 ret=0 && [ "$RESULT" != "@" ] && ret=1
112 ckreturn $ret "'$LSAT $MNTPTR/$NEWFILE' failed (res=$RESULT)" \
113 $TMPDIR/$NAME.out.$$
114 [ $? -ne 0 ] && cleanup $FAIL
115
116 # Verify can view named attr of new file created with cp command
117 runat $MNTPTR/$NEWFILE cat attrfile > $TMPDIR/$NAME.out.$$ 2>&1
118 ret=$?
119 ckreturn $ret "Cannot access attr using runat on NEWFILE, returned $ret." \
120 $TMPDIR/$NAME.out.$$
121 [ $? -ne 0 ] && cleanup $FAIL
122
123 echo "\tTest PASS"
124
125 # cleanup here
126 rm -f $TMPDIR/*.out.$$
127
128 # --------------------------------------------------------------------
129 # b: Test creating hardlink in a file's attrdir, expect OK
130 ASSERTION="Test creating hardlink in a file's attrdir, \
131 expect OK"
132 ASSERTION="$ASSERTION, expect OK"
133 echo "$NAME{b}: $ASSERTION"
134
135 #Ensure that test file doesn't already exist
136 rm -f $MNTPTR/$TESTFILE > /dev/null 2>&1
137
138 # Create a test file
139 echo "This is a file" > $MNTPTR/$TESTFILE 2> $TMPDIR/$NAME.out.$$
140 ret=$?
141 ckreturn $ret "Cannot create testfile $TESTFILE, returned $ret." \
142 $TMPDIR/$NAME.out.$$ UNINITIATED
143 [ $? -ne 0 ] && cleanup $UNINITIATED
144
145 sleep 1
146 # Verify test file was created with extended attribute dir
147 $LSAT $MNTPTR/$TESTFILE > $TMPDIR/$NAME.out.$$ 2>&1
148 ret=$?
149 ckreturn $ret "$LSAT on [$TESTFILE w/attr] failed, returned $ret." \
150 $TMPDIR/$NAME.out.$$
151 [ $? -ne 0 ] && cleanup $FAIL
152
153 sleep 1
154 # Now Create named attribute for file object
155 echo "This is an attribute" | runat $MNTPTR/$TESTFILE "cat > attrdirname2" \
156 > $TMPDIR/$NAME.out.$$ 2>&1
157 ret=$?
158 ckreturn $ret "Cannot create named attr on [$TESTFILE], returned $ret." \
159 $TMPDIR/$NAME.out.$$
160 [ $? -ne 0 ] && cleanup $FAIL
161
162 sleep 1
163 # Verify attr was created on test file
164 RESULT=$($LSAT $MNTPTR/$TESTFILE | awk '{print $1}' | cut -c11 \
165 2> $TMPDIR/$NAME.out.$$)
166 ret=0 && [ "$RESULT" != "@" ] && ret=1
167 ckreturn $ret "'$LSAT $MNTPTR/$TESTFILE' failed (res=$RESULT)" $TMPDIR/$NAME.out.$$
168 [ $? -ne 0 ] && cleanup $FAIL
169
170 sleep 1
171 # Verify attr dir accessible by runat command
172 runat $MNTPTR/$TESTFILE ls -l > $TMPDIR/$NAME.out.$$ 2>&1
173 ret=$?
174 ckreturn $ret "cannot access attr using runat on $TESTFILE, returned $ret." \
175 $TMPDIR/$NAME.out.$$
176 [ $? -ne 0 ] && cleanup $FAIL
177
178 # Get inode number of $TESTFILE
179 ATTRDIR=attrdirname2
180 INODE=$(runat $MNTPTR/$TESTFILE ls -i $ATTRDIR 2> $TMPDIR/$NAME.out.$$)
181 ret=$?
182 ckreturn $ret "[$TESTFILE attr dir $ATTRDIR] cannot get inode, returned $ret." \
183 $TMPDIR/$NAME.out.$$
184 [ $? -ne 0 ] && cleanup $FAIL
185 mv $TMPDIR/$NAME.out.$$ $TMPDIR/${NAME}_1.out.$$
186
187 INODE1=`echo $INODE | awk '{print $1}'`
188
189 sleep 1
190 # Create hardlink in attrdir of $TESTFILE
191 runat $MNTPTR/$TESTFILE ln $ATTRDIR $HLNK1 > $TMPDIR/$NAME.out.$$ 2>&1
192 ret=$?
193 ckreturn $ret \
194 "Cannot create link $HLNK1 to $ATTRDIR on $TESTFILE, returned $ret." \
195 $TMPDIR/$NAME.out.$$
196 [ $? -ne 0 ] && cleanup $FAIL
197
198 sleep 1
199 # Get inode number of new $HLNK1
200 INODE=$(runat $MNTPTR/$TESTFILE ls -i $HLNK1 2> $TMPDIR/$NAME.out.$$)
201 ret=$?
202 ckreturn $ret "[$TESTFILE attr link $HLNK1] cannot get inode, returned $ret." \
203 $TMPDIR/$NAME.out.$$
204 [ $? -ne 0 ] && cleanup $FAIL
205 mv $TMPDIR/$NAME.out.$$ $TMPDIR/${NAME}_2.out.$$
206
207 INODE2=`echo $INODE | awk '{print $1}'`
208
209 # add output for INODEs for debugging purposes
210 echo "INODE information from attrdir $ATTRDIR:\n" > $TMPDIR/${NAME}.out.$$
211 cat $TMPDIR/${NAME}_1.out.$$ >> $TMPDIR/${NAME}.out.$$ 2>/dev/null
212
213 echo "\n\nINODE information from link $HLNK1:\n" >> $TMPDIR/${NAME}.out.$$
214 cat $TMPDIR/${NAME}_2.out.$$ >> $TMPDIR/${NAME}.out.$$ 2>/dev/null
215
216 sleep 1
217 # Verify inodes of $TESTFILE and $HLNK1 are the same
218 ret=0 && [ $INODE1 -ne $INODE2 ] && ret=1
219 ckreturn $ret "inodes of $ATTRDIR and $HLNK1 are not the same" \
220 $TMPDIR/${NAME}.out.$$
221 [ $? -ne 0 ] && cleanup $FAIL
222
223 echo "\tTest PASS"
224
225 # cleanup here
226 cleanup $PASS
227
228 exit $PASS