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 hardlink object using runat, expect OK
  29 # b: Test basic remove of hardlink 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 # 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 hardlink object using attr \
  44 # commands, expect OK
  45 ASSERTION="Test basic create named attr for hardlink object using \
  46 attr commands"
  47 ASSERTION="$ASSERTION, expect successful"
  48 echo "$NAME{a}: $ASSERTION"
  49 
  50 #Ensure that test file doesn't already exist
  51 rm -f $MNTPTR/$TESTFILE $MNTPTR/$HLNK1 $MNTPTR/$HLNK2 > /dev/null 2>&1
  52 
  53 #Check mount point works
  54 ls $MNTPTR > /dev/null 2> $TMPDIR/$NAME.out.$$
  55 ret=$?
  56 ckreturn $ret "mount point $MNTPTR not accessible (ret=$ret)" \
  57         $TMPDIR/$NAME.out.$$ UNINITIATED
  58 [ $? -ne 0 ] && cleanup $UNINITIATED
  59 
  60 sleep 1
  61 # Create a test file
  62 echo "This is a testfile" > $MNTPTR/$TESTFILE 2> $TMPDIR/$NAME.out.$$
  63 ret=$?
  64 ckreturn $? "Cannot create testfile [$TESTFILE], returned $ret." \
  65         $TMPDIR/$NAME.out.$$ UNINITIATED
  66 [ $? -ne 0 ] && cleanup $UNINITIATED
  67 
  68 sleep 1
  69 # Verify test file created is accessible
  70 $LSAT $MNTPTR/$TESTFILE > $TMPDIR/$NAME.out.$$ 2>&1
  71 ret=$?
  72 ckreturn $ret "$LSAT cannot access $MNTPTR/$TESTFILE, returned $ret." \
  73         $TMPDIR/$NAME.out.$$
  74 [ $? -ne 0 ] && cleanup $FAIL
  75 
  76 sleep 1
  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 file in $MNTPTR/$TESTFILE, returned $ret." \
  82         $TMPDIR/$NAME.out.$$
  83 [ $? -ne 0 ] && cleanup $FAIL
  84 
  85 sleep 1
  86 # Create a hardlink referencing test file
  87 ln $MNTPTR/$TESTFILE $MNTPTR/$HLNK1 > $TMPDIR/ln1.out.$$ 2>&1
  88 ret=$?
  89 ckreturn $ret "Cannot create link $HLNK1 to $TESTFILE, returned $ret" \
  90         $TMPDIR/ln1.out.$$
  91 [ $? -ne 0 ] && cleanup $FAIL
  92 
  93 sleep 1
  94 # Verify hardlink is accessible
  95 RESULT=$($LSAT $MNTPTR/$HLNK1 | awk '{print $1}' | cut -c11 \
  96         2> $TMPDIR/$NAME.out.$$)
  97 ret=0 && [ "$RESULT" != "@" ] && ret=1
  98 ckreturn $ret "$LSAT command failed when using link $HLNK1 (res=$RESULT)" \
  99         $TMPDIR/$NAME.out.$$
 100 [ $? -ne 0 ] && cleanup $FAIL
 101 
 102 sleep 1
 103 # Verify attr dir space is  accessible by hardlink using runat command
 104 runat $MNTPTR/$HLNK1 ls -l > $TMPDIR/runat03.out.$$ 2>&1
 105 ret=$?
 106 ckreturn $ret \
 107         "'runat $MNTPTR/$HLNK1 ls -l' (link) not accessible, returned $ret." \
 108         $TMPDIR/runat03.out.$$
 109 [ $? -ne 0 ] && cleanup $FAIL
 110 
 111 sleep 1
 112 # Verify can view an attribute created in originial file's 
 113 # attribute directory
 114 runat $MNTPTR/$HLNK1 cat attr > $TMPDIR/runat03.out.$$ 2>&1
 115 ret=$?
 116 ckreturn $ret "Cannot access attring link $HLNK1, returned $ret" \
 117         $TMPDIR/runat03.out.$$
 118 [ $? -ne 0 ] && cleanup $FAIL
 119 
 120 echo "\tTest PASS"
 121 
 122 # cleanup here
 123 rm -f $MNTPTR/$HLNK1 $TMPDIR/*.out.$$
 124 
 125 # --------------------------------------------------------------------
 126 # b: Test basic remove of hardlink object w/named attr using attr \
 127 # commands, expect OK
 128 ASSERTION="Test basic remove of hardlink object w/named attr using \
 129 attr commands"
 130 ASSERTION="$ASSERTION, expect successful"
 131 echo "$NAME{b}: $ASSERTION"
 132 
 133 #Ensure that test file doesn't already exist
 134 rm -f $MNTPTR/$TESTFILE2 $MNTPTR/$HLNK1 $MNTPTR/$HLNK2 > /dev/null 2>&1
 135 
 136 sleep 1
 137 # Create a test file
 138 echo "This is a testfile" > $MNTPTR/$TESTFILE2 2> $TMPDIR/$NAME.out.$$
 139 ret=$?
 140 ckreturn $ret "Cannot create testfile $TESTFILE2, returned $ret." \
 141         $TMPDIR/$NAME.out.$$ UNINITIATED
 142 [ $? -ne 0 ] && cleanup $UNINITIATED
 143 
 144 sleep 1
 145 # Verify test file was created with extended attribute dir
 146 $LSAT $MNTPTR/$TESTFILE2 > $TMPDIR/$NAME.out.$$ 2>&1
 147 ret=$?
 148 ckreturn $ret "$LSAT cannot access $TESTFILE2, returned $ret." \
 149         $TMPDIR/$NAME.out.$$
 150 [ $? -ne 0 ] && cleanup $FAIL
 151 
 152 sleep 1
 153 # Now Create named attribute for file object
 154 echo "This is an attribute" | runat $MNTPTR/$TESTFILE2 "cat > attr" \
 155         > $TMPDIR/runat01.out.$$ 2>&1
 156 ret=$?
 157 ckreturn $ret "Cannot create attr on $MNTPTR/$TESTFILE2, returned $ret." \
 158         $TMPDIR/runat01.out.$$
 159 [ $? -ne 0 ] && cleanup $FAIL
 160 
 161 sleep 1
 162 # Create a hardlink referencing test file
 163 ln $MNTPTR/$TESTFILE2 $MNTPTR/$HLNK2 > $TMPDIR/ln2.out.$$ 2>&1
 164 ret=$?
 165 ckreturn $ret "Cannot create link $HLNK2 to testfile, returned $ret." \
 166         $TMPDIR/ln2.out.$$
 167 [ $? -ne 0 ] && cleanup $FAIL
 168 
 169 sleep 1
 170 # Verify hardlink is accessible
 171 RESULT=$($LSAT $MNTPTR/$HLNK2 | awk '{print $1}' | cut -c11 \
 172         2> $TMPDIR/$NAME.out.$$)
 173 ret=0 && [ "$RESULT" != "@" ] && ret=1
 174 ckreturn $ret "$LSAT command canot access attr (res=$RESULT)" \
 175         $TMPDIR/$NAME.out.$$
 176 [ $? -ne 0 ] && cleanup $FAIL 
 177 
 178 sleep 1
 179 # Verify attr dir space accessible by hardlink using runat command
 180 runat $MNTPTR/$HLNK2 ls -l > $TMPDIR/runat03.out.$$ 2>&1
 181 ret=$?
 182 ckreturn $ret "'runat $MNTPTR/$HLNK2 ls -l' (link) failed, returned $ret." \
 183         $TMPDIR/runat03.out.$$
 184 [ $? -ne 0 ] && cleanup $FAIL
 185 
 186 sleep 1
 187 # Verify can view an attribute created in originial file's attribute directory
 188 runat $MNTPTR/$HLNK2 cat attr > $TMPDIR/runat03.out.$$ 2>&1
 189 ret=$?
 190 ckreturn $ret "Cannot access attr using link $HLNK2, returned $ret." \
 191         $TMPDIR/runat03.out.$$
 192 [ $? -ne 0 ] && cleanup $FAIL
 193 
 194 sleep 1
 195 # Remove hardlink
 196 rm -f $MNTPTR/$HLNK2 > $TMPDIR/rm03.out.$$  2>&1
 197 ret=$?
 198 ckreturn $ret "Failed to remove link $HLNK2, returned $ret." $TMPDIR/rm03.out.$$
 199 [ $? -ne 0 ] && cleanup $FAIL
 200 
 201 sleep 1
 202 # Verify that can still access original file
 203 runat $MNTPTR/$TESTFILE2 ls -l > $TMPDIR/runat03.out.$$  2>&1
 204 ret=$?
 205 ckreturn $ret \
 206         "Cannot access testfile $TESTFILE2 after removing link, returned $ret."\
 207         $TMPDIR/runat03.out.$$
 208 [ $? -ne 0 ] && cleanup $FAIL
 209 
 210 sleep 1
 211 # Verify can still view original file named attr
 212 runat $MNTPTR/$TESTFILE2 cat attr > $TMPDIR/runat_cat03.out.$$ 2>&1
 213 ret=$?
 214 ckreturn $ret "Cannot access attr using runat with $TESTFILE2, returned $ret." \
 215         $TMPDIR/runat_cat03.out.$$
 216 [ $? -ne 0 ] && cleanup $FAIL
 217 
 218 echo "\tTest PASS"
 219 
 220 cleanup $PASS
 221 
 222 exit $PASS