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 basic create named attr for file object using runat, expect OK
29 # b: Test basic remove of file object w/named attr using runat, 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 # XXX 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 basic create named attr for file object using attr commands, \
44 #expect OK
45 ASSERTION="Test basic create named attr for file object using runat \
46 command"
47 ASSERTION="$ASSERTION, expect successful"
48 echo "$NAME{a}: $ASSERTION"
49
50 #Check mount point works
51 ls $MNTPTR > /dev/null 2> $TMPDIR/$NAME.out.$$
52 ret=$?
53 ckreturn $ret "mount point $MNTPTR not accessible (ret=$ret)" \
54 $TMPDIR/$NAME.out.$$ UNINITIATED
55 [ $? -ne 0 ] && cleanup $UNINITIATED
56
57 sleep 1
58 #Ensure that test file doesn't already exist
59 [ -f $MNTPTR/$TESTFILE ] && rm -f $MNTPTR/$TESTFILE > /dev/null 2>&1
60
61 sleep 1
62 # Create a test file
63 echo "This is a file" > $MNTPTR/$TESTFILE 2> $TMPDIR/$NAME.out.$$
64 ret=$?
65 ckreturn $ret "Cannot create testfile [$TESTFILE], returned $ret." \
66 $TMPDIR/$NAME.out.$$ UNINITIATED
67 [ $? -ne 0 ] && cleanup $UNINITIATED
68
69 sleep 1
70 # Verify test file was created with extended attribute dir
71 $LSAT $MNTPTR/$TESTFILE > $TMPDIR/$NAME.out.$$ 2>&1
72 ret=$?
73 ckreturn $ret "Cannot access testfile [$TESTFILE], returned $ret." \
74 $TMPDIR/$NAME.out.$$
75 [ $? -ne 0 ] && cleanup $FAIL
76
77 # Now Create named attribute for file object
78 echo "This is an attribute" | runat $MNTPTR/$TESTFILE "cat > attr" \
79 > $TMPDIR/$NAME.out.$$ 2>&1
80 ret=$?
81 ckreturn $ret "Cannot create attr dir, returned $ret." $TMPDIR/$NAME.out.$$
82 [ $? -ne 0 ] && cleanup $FAIL
83
84 # Verify test file still accessible
85 RESULT=$($LSAT $MNTPTR/$TESTFILE | awk '{print $1}' | cut -c11 \
86 2> $TMPDIR/$NAME.out.$$)
87 ret=0 && [ "$RESULT" != "@" ] && ret=1
88 ckreturn $ret "$LSAT command cannot access attr (res=$RESULT)" \
89 $TMPDIR/$NAME.out.$$
90 [ $? -ne 0 ] && cleanup $FAIL
91
92 sleep 1
93 # Verify attr file accessible by runat command
94 runat $MNTPTR/$TESTFILE ls -l > $TMPDIR/runat01.out.$$ 2>&1
95 ret=$?
96 ckreturn $ret "'runat $MNTPTR/$TESTFILE ls -l' failed, returned $ret." \
97 $TMPDIR/runat01.out.$$
98 [ $? -ne 0 ] && cleanup $FAIL
99
100 # Verify can view an attribute created in file's attribute directory
101 runat $MNTPTR/$TESTFILE cat attr > $TMPDIR/runat01.out.$$ 2>&1
102 ret=$?
103 ckreturn $ret "Cannot read access testfile [$TESTFILE attr], returned $ret." \
104 $TMPDIR/runat01.out.$$
105 [ $? -ne 0 ] && cleanup $FAIL
106
107 echo "\tTest PASS"
108
109 cleanup $PASS
110
111 # --------------------------------------------------------------------
112 # b: Test basic remove of file object w/named attr using attr commands, \
113 #expect OK
114 ASSERTION="Test basic remove of file object w/named attr using runat command"
115 ASSERTION="$ASSERTION, expect successful"
116 echo "$NAME{b}: $ASSERTION"
117
118 # Verify file doesn't exist before test started
119 [ -f $MNTPTR/$TESTFILE ] && rm -f $MNTPTR/$TESTFILE > /dev/null 2>&1
120
121 sleep 1
122 # Create a test file
123 echo "This is a file" > $MNTPTR/$TESTFILE 2> $TMPDIR/$NAME.out.$$
124 ret=$?
125 ckreturn $ret "Cannot create [$TESTFILE], returned $ret." $TMPDIR/$NAME.out.$$ \
126 UNINITIATED
127 [ $? -ne 0 ] && cleanup $UNINITIATED
128
129 sleep 1
130 # Verify test file was created with extended attribute dir
131 $LSAT $MNTPTR/$TESTFILE > $TMPDIR/$NAME.out.$$ 2>&1
132 ret=$?
133 ckreturn $ret "Cannot create [$TESTFILE], returned $ret." $TMPDIR/$NAME.out.$$
134 [ $? -ne 0 ] && cleanup $FAIL
135
136 sleep 1
137 # Now Create named attribute for file object
138 echo "This is an attribute for remove" | runat $MNTPTR/$TESTFILE "cat > attrb" \
139 > $TMPDIR/$NAME.out.$$ 2>&1
140 ret=$?
141 ckreturn $ret "Cannot create attr dir, returned $ret." $TMPDIR/$NAME.out.$$
142 [ $? -ne 0 ] && cleanup $FAIL
143
144 sleep 1
145 # Verify test file still accessible
146 RESULT=$($LSAT $MNTPTR/$TESTFILE | awk '{print $1}' | cut -c11 \
147 2> $TMPDIR/$NAME.out.$$)
148 ret=0 && [ "$RESULT" != "@" ] && ret=1
149 ckreturn $ret "$LSAT command didn't get attr (res=$RESULT)" $TMPDIR/$NAME.out.$$
150 [ $? -ne 0 ] && cleanup $FAIL
151
152 sleep 1
153 # Verify attr dir accessible by runat command
154 runat $MNTPTR/$TESTFILE ls -l > $TMPDIR/runat01.out.$$ 2>&1
155 ret=$?
156 ckreturn $ret "'runat $MNTPTR/$TESTFILE ls -l' failed, returned $ret." \
157 $TMPDIR/runat01.out.$$
158 [ $? -ne 0 ] && cleanup $FAIL
159
160 # Remove file and it's attr dir using basic "rm" command
161 rm -f $MNTPTR/$TESTFILE > $TMPDIR/rm01.out.$$ 2>&1
162 ret=$?
163 ckreturn $ret "[$TESTFILE attr dir] was not removed, returned $ret." \
164 $TMPDIR/rm01.out.$$
165 [ $? -ne 0 ] && cleanup $FAIL
166
167 # Verify test file not accessible
168 $LSAT $MNTPTR/$TESTFILE > $TMPDIR/$NAME.out.$$ 2>&1
169 ret=$?
170 ckreturn -r $ret "[$TESTFILE] still accessible, returned $ret." \
171 $TMPDIR/$NAME.out.$$
172 [ $? -eq 0 ] && cleanup $FAIL
173
174 # Verify attr nolonger accessible by runat command
175 runat $MNTPTR/$TESTFILE ls -l > $TMPDIR/runat01.out.$$ 2>&1
176 ret=$?
177 ckreturn -r $ret "[$TESTFILE attr dir] was not removed, returned $ret." \
178 $TMPDIR/runat01.out.$$
179 [ $? -eq 0 ] && cleanup $FAIL
180
181 echo "\tTest PASS"
182
183 cleanup $PASS
184
185 exit $PASS