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 2009 Sun Microsystems, Inc.  All rights reserved.
  25 # Use is subject to license terms.
  26 #
  27 
  28 #
  29 # NFSv4 client recovery:
  30 # a: Verify conflicting lock from process2 is granted after
  31 #    lease expires and process1 gets killed, should succeed.
  32 # b: Verify conflicting lock from process1 or process2 is granted after
  33 #    lease expires and process2 or process1 releases the lock, should succeed.
  34 # c: Verify conflicting lock from process2 is granted after
  35 #    lease expires and process1 releases the lock, should succeed.
  36 #
  37 
  38 . ${STF_SUITE}/include/nfsgen.kshlib
  39 
  40 NAME=$(basename $0)
  41 
  42 [[ :$NFSGEN_DEBUG: = *:${NAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
  43 
  44 DIR=$(dirname $0)
  45 PATH=/usr/bin:$PATH
  46 
  47 prog=$STF_SUITE/bin/file_operator
  48 TESTFILE="openfile.$$"
  49 timeout=200
  50 
  51 if [[ -n $ZONE_PATH ]]; then
  52         echo "\n\tThis test hits CR#6749743 which causes the server panic\n"
  53         exit $STF_UNTESTED
  54 fi
  55 
  56 if [[ ! -x $prog ]]; then
  57         echo "$NAME:the executable program '$prog' not found."
  58         echo "\t Test FAIL"
  59         return $STF_FAIL
  60 fi
  61 
  62 
  63 # First check this test is not started before previous tests
  64 # grace period ends.
  65 echo "xxx" > $MNTDIR/wait_for_grace
  66 rm -rf $MNTDIR/wait_for_grace > /dev/null 2>&1
  67 
  68 # Start test
  69 # --------------------------------------------------------------------
  70 # a: Verify conflicting lock from localhost is granted after
  71 # lease expires and process2 gets killed, should succeed.
  72 function assertion_a 
  73 {
  74    [[ :$NFSGEN_DEBUG: = *:${NAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
  75    ASSERTION="Verify conflicting lock from process2 is granted after \
  76         lease expires and process1 gets killed"
  77 
  78    ASSERTION="$ASSERTION, expect successful"
  79    echo "$NAME{a}: $ASSERTION"
  80 
  81    # First write lock the file in a process and hold for a long time:
  82    $prog -W -c -u -o 4 -s $REBOOTIMER -L "1 1 0 0" -B "0 0 0" $MNTDIR/$TESTFILE \
  83         > $STF_TMPDIR/$NAME.out.c2.$$ 2>&1 &
  84    pid1=$!
  85    wait_now 200 \
  86    "grep \"got exclusive lock\" $STF_TMPDIR/$NAME.out.c2.$$ > /dev/null 2>&1"
  87    if (( $? != 0 )); then
  88         echo "$NAME: the process with pid=$pid1 did not get the write lock ..."
  89         cat $STF_TMPDIR/$NAME.out.c2.$$
  90         kill $pid1
  91         echo "\t Test FAIL"
  92         return $STF_FAIL
  93    fi
  94 
  95    # Now write lock the same file on localhost; should be block
  96    $prog -W -c -u -o 4 -s 10 -L "1 1 0 0" -B "0 0 -1" $MNTDIR2/$TESTFILE \
  97         > $STF_TMPDIR/$NAME.out.$$ 2>&1 &
  98    pid2=$!
  99    wait_now 5 \
 100    "grep \"got exclusive lock\" $STF_TMPDIR/$NAME.out.$$ > /dev/null 2>&1" \
 101         > /dev/null
 102    if (( $? == 0 )); then
 103         echo "$NAME: the process with pid=$pid2 also got the write lock before \
 104         process with pid=$pid2 releasing it, it is unexpected."
 105         cat $STF_TMPDIR/$NAME.out.$$
 106         kill $pid1
 107         kill $pid2
 108         echo "\t Test FAIL"
 109         return $STF_FAIL
 110    fi
 111 
 112    # kill the first process to clear the blocked lock...
 113    kill $pid1
 114    sleep 5 
 115    # check the first process already killed
 116    kill -0 $pid1 > $STF_TMPDIR/$NAME.out.ps.$$ 2>&1
 117    grep "o such process" $STF_TMPDIR/$NAME.out.ps.$$ > /dev/null 2>&1
 118    if (( $? != 0 )); then
 119         echo "$NAMW: failed to kill the first process with pid=$pid1"
 120         cat $STF_TMPDIR/$NAME.out.ps.$$
 121         kill $pid1
 122         kill $pid2
 123         echo "\t Test FAIL"
 124         return $STF_FAIL
 125    fi
 126 
 127    # the second process should get the write lock now ...
 128    wait_now $timeout \
 129    "grep \"got exclusive lock\" $STF_TMPDIR/$NAME.out.$$ > /dev/null 2>&1"
 130    if (( $? != 0 )); then
 131         echo "$NAME: the second process with pid=$pid2 still did not get the write lock \
 132         even waiting for $timeout seconds after the first process killed."
 133         cat $STF_TMPDIR/$NAME.out.$$
 134         kill $pid2
 135         echo "\t Test FAIL"
 136         return $STF_FAIL
 137    fi
 138 
 139    wait $pid2
 140    if (( $? != 0 )); then
 141         echo "wait the second process with pid=$pid2 failed"
 142         echo "\t Test FAIL"
 143         return $STF_FAIL
 144    else
 145         echo "\tTest PASS"
 146         return $STF_PASS
 147    fi
 148 }
 149 
 150 # --------------------------------------------------------------------
 151 # b: Verify conflicting lock from process1 or process2 is granted after
 152 # lease expires and process2 or process1 releases the lock, should succeed.
 153 #
 154 # It implements the following scenarios to make sure server is not confused
 155 # with the processs and the locks, and process can recover the states:
 156 # - process1 write lock the file
 157 # - process2 try write lock the file, block
 158 # - process1 release the lock
 159 # - process2 gets the lock, then release it
 160 # - process1 read lock the file
 161 # - process2 try write lock the file, block
 162 # - process1 release the lock
 163 # - process2 gets the lock
 164 # - process1 try read lock some offset, block
 165 # - process2 release the lock; then set read lock
 166 # - server calls clear_locks to both processs
 167 # - verify both process1 and process2 still have the read lock
 168 # 
 169 function assertion_b 
 170 {
 171    [[ :$NFSGEN_DEBUG: = *:${NAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
 172    ASSERTION="Verify conflicting lock from localhost or process2 is granted \
 173         after lease expires and another process releases the lock"
 174    ASSERTION="$ASSERTION, expect successful"
 175    echo "$NAME{b}: $ASSERTION"
 176 
 177    # First check this test is not started before previous tests
 178    # grace period ends.
 179    echo "xxx" > $MNTDIR/wait_for_grace
 180    rm -rf $MNTDIR/wait_for_grace > /dev/null 2>&1
 181 
 182    # First write lock the file in process1 and hold for a period of time:
 183    $prog -W -c -u -o 4 -s 30 -L "1 1 0 0" -B "0 0 0" $MNTDIR/$TESTFILE \
 184          > $STF_TMPDIR/$NAME.out.c1.$$ 2>&1 &
 185    pid1=$!
 186    wait_now $timeout \
 187    "grep \"got exclusive lock\" $STF_TMPDIR/$NAME.out.c1.$$ > /dev/null 2>&1"
 188    if (( $? != 0 )); then
 189         echo "$NAME: the process1 with pid=$pid1 did not get the write lock ..."
 190         cat $STF_TMPDIR/$NAME.out.c1.$$
 191         kill $pid1
 192         echo "\t Test FAIL"
 193         return $STF_FAIL
 194    fi
 195 
 196    # Now write lock the same file in process2; should be block
 197    $prog -W -c -u -o 4 -s 20 -L "1 1 0 0" -B "0 0 -1" $MNTDIR2/$TESTFILE \
 198         > $STF_TMPDIR/$NAME.out.c2.$$ 2>&1 &
 199    pid2=$!
 200    wait_now 10 \
 201    "grep \"got exclusive lock\" $STF_TMPDIR/$NAME.out.c2.$$ > /dev/null 2>&1" \
 202    > /dev/null
 203    if (( $? == 0 )); then
 204         echo "$NAME: the process2 with pid=$pid2 also got the write lock before \
 205         localhost releasing it, it is unexpected."
 206         cat $STF_TMPDIR/$NAME.out.c2.$$
 207         kill $pid1
 208         kill $pid2
 209         echo "\t Test FAIL"
 210         return $STF_FAIL
 211    fi
 212 
 213    # send SIGUSR1 to first process1, process1 will release the lock
 214    kill -16 $pid1
 215 
 216    # the process2 should get the write lock now ...
 217    wait_now $timeout \
 218    "grep \"got exclusive lock\" $STF_TMPDIR/$NAME.out.c2.$$ > /dev/null 2>&1"
 219    if (( $? != 0 )); then
 220         echo "$NAME: the process2 with pid=$pid2 still did not get the write lock \
 221         even waiting for $timeout seconds after process1 released it."
 222         cat $STF_TMPDIR/$NAME.out.c2.$$
 223         kill $pid1
 224         kill $pid2
 225         echo "\t Test FAIL"
 226         return $STF_FAIL
 227    fi
 228 
 229    wait $pid1
 230    if (( $? != 0 )); then
 231         echo "wait process1 with pid=$pid1 finish failed"
 232         cat $STF_TMPDIR/$NAME.out.c1.$$
 233         kill $pid1
 234         kill $pid2
 235         return $STF_FAIL
 236    fi
 237    wait $pid2
 238    if (( $? != 0 )); then
 239         echo "wait process2 with pid=$pid2 finish failed"
 240         cat $STF_TMPDIR/$NAME.out.c2.$$
 241         kill $pid2
 242         return $STF_FAIL
 243    fi
 244    sleep 5 
 245 
 246    # Read lock the file in process1 and hold for a period of time:
 247    $prog -R -c -u -o 4 -L "0 1 0 0" -B "0 0 0" $MNTDIR/$TESTFILE \
 248         > $STF_TMPDIR/$NAME.out.c1r.$$ 2>&1 &
 249    pid1=$!
 250    wait_now $timeout \
 251    "grep \"got shared lock\" $STF_TMPDIR/$NAME.out.c1r.$$ > /dev/null 2>&1"
 252    if (( $? != 0 )); then
 253         echo "$NAME: the process1 did not get the read lock ..."
 254         cat $STF_TMPDIR/$NAME.out.c1r.$$
 255         kill $pid1
 256         echo "\t Test FAIL"
 257         return $STF_FAIL
 258    fi
 259 
 260    # Try to write lock the same file in process2; should be block
 261    $prog -W -c -u -o 4 -L "1 1 0 0" -B "0 0 0" $MNTDIR2/$TESTFILE \
 262         > $STF_TMPDIR/$NAME.out.c2w.$$ 2>&1 &
 263    pid2=$!
 264    wait_now 5 \
 265    "grep \"got exclusive lock\" $STF_TMPDIR/$NAME.out.c2w.$$ > /dev/null 2>&1" \
 266            > /dev/null
 267    if (( $? == 0 )); then
 268         echo "$NAME: the process2 with pid=$pid2 has got the write lock before \
 269         localhost releasing it, it is unexpected."
 270         cat $STF_TMPDIR/$NAME.out.c2w.$$
 271         kill $pid1
 272         kill $pid2
 273         echo "\t Test FAIL"
 274         return $STF_FAIL
 275    fi
 276 
 277    # send SIGUSR1 to first process1, process1 will release the lock
 278    kill -16 $pid1
 279 
 280    # the process2 should get the write lock now ...
 281    wait_now $timeout \
 282    "grep \"got exclusive lock\" $STF_TMPDIR/$NAME.out.c2w.$$ > /dev/null 2>&1"
 283    if (( $? != 0 )); then
 284         echo "$NAME: the process2 with pid=$pid2 still did not get the write lock \
 285         even waiting for $timeout seconds after localhost released it."
 286         cat $STF_TMPDIR/$NAME.out.c2w.$$
 287         kill $pid2
 288         echo "\t Test FAIL"
 289         return $STF_FAIL
 290    fi
 291 
 292    wait $pid1
 293    if (( $? != 0 )); then
 294         echo "wait process1 with pid=$pid1 finish failed"
 295         cat $STF_TMPDIR/$NAME.out.c1r.$$
 296         kill $pid1
 297         kill $pid2
 298         return $STF_FAIL
 299    fi
 300 
 301    # process1 try to read lock the file with offset 0 and length 20 bytes;
 302    # should be block
 303    $prog -R -c -u -o 4 -s 80 -L "0 1 0 20" -B "0 0 0" $MNTDIR/$TESTFILE > \
 304         $STF_TMPDIR/$NAME.out.c1o.$$ 2>&1 &
 305    pid1=$!
 306    wait_now 10 \
 307    "grep \"got shared lock\" $STF_TMPDIR/$NAME.out.c1o.$$ > /dev/null 2>&1" \
 308    > /dev/null
 309    if (( $? == 0 )); then
 310         echo "$NAME: the process1 has got the read lock before \
 311         process2 releasing it, it is unexpected."
 312         cat $STF_TMPDIR/$NAME.out.c1o.$$
 313         kill $pid1
 314         kill $pid2
 315         echo "\t Test FAIL"
 316         return $STF_FAIL
 317    fi
 318 
 319    # send SIGUSR1 to first process2, process2 will release the lock
 320    kill -16 $pid2
 321 
 322    # the localhost should get the read lock now ...
 323    wait_now $timeout \
 324    "grep \"got shared lock\" $STF_TMPDIR/$NAME.out.c1o.$$ > /dev/null 2>&1"
 325    if (( $? != 0 )); then
 326         echo "$NAME: the localhost still did not get the read lock \
 327         even waiting for $timeout seconds after process2 with pid=$pid2 released it."
 328         cat $STF_TMPDIR/$NAME.out.c1o.$$
 329         kill $pid1
 330         echo "\t Test FAIL"
 331         return $STF_FAIL
 332    fi
 333 
 334    # process2 try to read lock the same file also:
 335    $prog -R -c -u -o 4 -s 80 -L "0 1 0 0" -B "0 0 0" $MNTDIR2/$TESTFILE \
 336         > $STF_TMPDIR/$NAME.out.c2r.$$ 2>&1 &
 337    pid2=$!
 338    wait_now $timeout \
 339    "grep \"got shared lock\" $STF_TMPDIR/$NAME.out.c2r.$$ > /dev/null 2>&1"
 340    if (( $? != 0 )); then
 341         echo "$NAME: the process2 with pid=$pid2 did not get the read lock ..."
 342         cat $STF_TMPDIR/$NAME.out.c2r.$$
 343         kill $pid1
 344         kill $pid2
 345         echo "\t Test FAIL"
 346         return $STF_FAIL
 347    fi
 348 
 349    # SERVER calls clear_locks to both processs to make sure process can recovery
 350    # the states:
 351    RSH root $SERVER "clear_locks $CLIENT" > $STF_TMPDIR/$NAME.out.c1c.$$ 2>&1
 352 
 353    # send SIGUSR1 to both process1 and process2
 354    kill -16 $pid1
 355    kill -16 $pid2
 356 
 357    wait $pid1
 358    if (( $? != 0 )); then
 359         echo "wait process1 with pid=$pid1 finish failed"
 360         cat $STF_TMPDIR/$NAME.out.c1o.$$
 361         kill $pid1
 362         kill $pid2
 363         return $STF_FAIL
 364    fi
 365    wait $pid2
 366    if (( $? != 0 )); then
 367         echo "wait process2 with pid=$pid2 finish failed"
 368         cat $STF_TMPDIR/$NAME.out.c2r.$$
 369         kill $pid2
 370         return $STF_FAIL
 371    fi
 372 
 373    echo "\tTest PASS"
 374    return $STF_PASS
 375 }
 376 
 377 # --------------------------------------------------------------------
 378 # c: Verify conflicting lock from process2 is granted after
 379 # lease expires and process1 releases the lock, should succeed.
 380 #
 381 # It implements the following scenarios to make sure server is not confused
 382 # with the processes and the locks, and process can recover the states:
 383 # - process1 write lock the file
 384 # - process2 try write lock the file, block
 385 # - process1 release the lock
 386 # - process2 gets the lock, then release it
 387 # - process1 read lock the file
 388 # - process2 try write lock the file, block
 389 # - process1 release the lock
 390 # - process2 gets the lock
 391 # - process1 try read lock some offset, block
 392 # - process2 release the lock; then set read lock
 393 # - server calls clear_locks to both processes
 394 # - verify both process1/process2 still have the read lock
 395 # 
 396 function assertion_c 
 397 {
 398    [[ :$NFSGEN_DEBUG: = *:${NAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
 399    ASSERTION="Verify conflicting lock from process2 is granted \
 400         after lease expires and process1 releases the lock"
 401    ASSERTION="$ASSERTION, expect successful"
 402    echo "$NAME{c}: $ASSERTION"
 403 
 404    # First check this test is not started before previous tests
 405    # grace period ends.
 406    echo "xxx" > $MNTDIR/wait_for_grace
 407    rm -rf $MNTDIR/wait_for_grace > /dev/null 2>&1
 408 
 409    # First write lock the file in process1 and hold for a period of time:
 410    $prog -W -c -u -o 4 -s 30 -L "1 1 0 0" -B "0 0 0" $MNTDIR/$TESTFILE \
 411         > $STF_TMPDIR/$NAME.out.c1.$$ 2>&1 &
 412    pid1_1=$!
 413    wait_now $timeout \
 414    "grep \"got exclusive lock\" $STF_TMPDIR/$NAME.out.c1.$$ > /dev/null 2>&1"
 415    if (( $? != 0 )); then
 416         echo "$NAME: the 1st process did not get the write lock ..."
 417         cat $STF_TMPDIR/$NAME.out.c1.$$
 418         kill $pid1_1
 419         echo "\t Test FAIL"
 420         return $STF_FAIL
 421    fi
 422 
 423    # Now write lock the same file again on localhost; should be block
 424    $prog -W -c -u -o 4 -s 20 -L "1 1 0 0" -B "0 0 0" $MNTDIR2/$TESTFILE \
 425         > $STF_TMPDIR/$NAME.out.c2.$$ 2>&1 &
 426    pid1_2=$!
 427    wait_now 10 \
 428    "grep \"got exclusive lock\" $STF_TMPDIR/$NAME.out.c2.$$ > /dev/null 2>&1" \
 429    > /dev/null
 430    if (( $? == 0 )); then
 431         echo "$NAME: the 2nd process also got the write lock before \
 432         the 1st process releasing it, it is unexpected."
 433         cat $STF_TMPDIR/$NAME.out.c2.$$
 434         kill $pid1_1
 435         kill $pid1_2
 436         echo "\t Test FAIL"
 437         return $STF_FAIL
 438    fi
 439 
 440    # send SIGUSR1 to 1st holdlock process
 441    kill -16 $pid1_1
 442 
 443    # the 2nd process should get the write lock now ...
 444    wait_now $timeout \
 445    "grep \"got exclusive lock\" $STF_TMPDIR/$NAME.out.c2.$$ > /dev/null 2>&1"
 446    if (( $? != 0 )); then
 447         echo "$NAME: the 2nd process still did not get the write lock \
 448         even waiting for $timeout seconds after the 1st process released it."
 449         cat $STF_TMPDIR/$NAME.out.c2.$$
 450         kill $pid1_2
 451         echo "\t Test FAIL"
 452         return $STF_FAIL
 453    fi
 454 
 455    # send SIGUSR1 to 2nd holdlock process
 456    kill -16 $pid1_2
 457 
 458    wait $pid1_1
 459    if (( $? != 0 )); then
 460         echo "wait process1 with pid=$pid1_1 finish failed"
 461         cat $STF_TMPDIR/$NAME.out.c1.$$
 462         kill $pid1_1
 463         kill $pid1_2
 464         return $STF_FAIL
 465    fi
 466    wait $pid1_2
 467    if (( $? != 0 )); then
 468         echo "wait process2 with pid=$pid1_2 finish failed"
 469         cat $STF_TMPDIR/$NAME.out.c2.$$
 470         kill $pid1_2
 471         return $STF_FAIL
 472    fi
 473 
 474    # Read lock the file on localhost and hold for a period of time:
 475    $prog -R -c -u -o 4 -s 30 -L "0 1 0 0" -B "0 0 0" $MNTDIR/$TESTFILE \
 476         > $STF_TMPDIR/$NAME.out.c1r.$$ 2>&1 &
 477    pid1_1=$!
 478    wait_now $timeout \
 479    "grep \"got shared lock\" $STF_TMPDIR/$NAME.out.c1r.$$ > /dev/null 2>&1"
 480    if (( $? != 0 )); then
 481         echo "$NAME: the 1st process did not get the read lock ..."
 482         cat $STF_TMPDIR/$NAME.out.c1r.$$
 483         kill $pid1_1
 484         echo "\t Test FAIL"
 485         return $STF_FAIL
 486    fi
 487 
 488    # Try to write lock the same file on localhost; should be block
 489    $prog -W -c -u -o 4 -s 30 -L "1 1 0 0" -B "0 0 0" $MNTDIR2/$TESTFILE \
 490         > $STF_TMPDIR/$NAME.out.c2w.$$ 2>&1 &
 491    pid1_2=$!
 492    wait_now 10 \
 493    "grep \"got exclusive lock\" $STF_TMPDIR/$NAME.out.c2w.$$ > /dev/null 2>&1" \
 494          > /dev/null
 495    if (( $? == 0 )); then
 496         echo "$NAME: the 2nd process has got the write lock before \
 497         the 1st process releasing it, it is unexpected."
 498         cat $STF_TMPDIR/$NAME.out.c2w.$$
 499         kill $pid1_1
 500         kill $pid1_2
 501         echo "\t Test FAIL"
 502         return $STF_FAIL
 503    fi
 504 
 505    kill -16 $pid1_1
 506 
 507    # the 2nd process should get the write lock now ...
 508    wait_now $timeout \
 509    "grep \"got exclusive lock\" $STF_TMPDIR/$NAME.out.c2w.$$ > /dev/null 2>&1"
 510    if (( $? != 0 )); then
 511         echo "$NAME: the 2nd process still did not get the write lock \
 512         even waiting for $timeout seconds after the 1st process released it."
 513         cat $STF_TMPDIR/$NAME.out.c2w.$$
 514         kill $pid1_2
 515         echo "\t Test FAIL"
 516         return $STF_FAIL
 517    fi
 518 
 519    wait $pid1_1
 520    if (( $? != 0 )); then
 521         echo "wait process1 with pid=$pid1_1 finish failed"
 522         cat $STF_TMPDIR/$NAME.out.c1r.$$
 523         kill $pid1_1
 524         kill $pid1_2
 525         return $STF_FAIL
 526    fi
 527 
 528    # try to read lock the file again with offset 0 and length 20 bytes;
 529    # should be block
 530    $prog -R -c -u -o 4 -s 80 -L "0 1 0 20" -B "0 0 0" $MNTDIR/$TESTFILE \
 531         > $STF_TMPDIR/$NAME.out.c1o.$$ 2>&1 &
 532    pid1_1=$!
 533    wait_now 5 \
 534    "grep \"got shared lock\" $STF_TMPDIR/$NAME.out.c1o.$$ > /dev/null 2>&1" \
 535         > /dev/null
 536    if (( $? == 0 )); then
 537         echo "$NAME: the 1st process has got the read lock before \
 538         the 2nd process releasing it, it is unexpected."
 539         cat $STF_TMPDIR/$NAME.out.c1o.$$
 540         kill $pid1_1
 541         kill $pid1_2
 542         echo "\t Test FAIL"
 543         return $STF_FAIL
 544    fi
 545 
 546    kill -16 $pid1_2
 547 
 548    # the localhost should get the read lock now ...
 549    wait_now $timeout \
 550    "grep \"got shared lock\" $STF_TMPDIR/$NAME.out.c1o.$$ > /dev/null 2>&1"
 551    if (( $? != 0 )); then
 552         echo "$NAME: the 1st process still did not get the read lock \
 553         even waiting for $timeout seconds after the 2nd process released it."
 554         cat $STF_TMPDIR/$NAME.out.c1o.$$
 555         kill $pid1_1
 556         echo "\t Test FAIL"
 557         return $STF_FAIL
 558    fi
 559 
 560    wait $pid1_2
 561    if (( $? != 0 )); then
 562         echo "wait process2 with pid=$pid1_2 finish failed"
 563         cat $STF_TMPDIR/$NAME.out.c2w.$$
 564         kill $pid1_2
 565         return $STF_FAIL
 566    fi
 567 
 568    # try to read lock the same file also:
 569    $prog -R -c -u -o 4 -s 80 -L "0 1 0 0" -B "0 0 -1" $MNTDIR2/$TESTFILE \
 570         > $STF_TMPDIR/$NAME.out.c2r.$$ 2>&1 &
 571    pid1_2=$!
 572    wait_now $timeout \
 573    "grep \"got shared lock\" $STF_TMPDIR/$NAME.out.c2r.$$ > /dev/null 2>&1"
 574    if (( $? != 0 )); then
 575         echo "$NAME: the 2nd process did not get the read lock ..."
 576         cat $STF_TMPDIR/$NAME.out.c2r.$$
 577         kill $pid1_1
 578         kill $pid1_2
 579         echo "\t Test FAIL"
 580         return $STF_FAIL
 581    fi
 582 
 583    # SERVER calls clear_locks to localhost to make sure process can recovery
 584    # the states:
 585    RSH root $SERVER "clear_locks $CLIENT" > $STF_TMPDIR/$NAME.out.c1c.$$ 2>&1
 586 
 587    kill -16 $pid1_1
 588 
 589    wait $pid1_1
 590    if (( $? != 0 )); then
 591         echo "wait process1 with pid=$pid1_1 finish failed"
 592         cat $STF_TMPDIR/$NAME.out.c1o.$$
 593         kill $pid1
 594         kill $pid2
 595         return $STF_FAIL
 596    fi
 597    wait $pid1_2
 598    if (( $? != 0 )); then
 599         echo "wait process2 with pid=$pid1_2 finish failed"
 600         cat $STF_TMPDIR/$NAME.out.c2r.$$
 601         kill $pid1_2
 602         return $STF_FAIL
 603    fi
 604 
 605 
 606    echo "\tTest PASS"
 607    return $STF_PASS
 608 }
 609 
 610 # Start main program here:
 611 # ----------------------------------------------------------------------
 612 assertion_a
 613 retcode=$?
 614 
 615 assertion_b
 616 retcode=$(($retcode+$?))
 617 
 618 assertion_c
 619 retcode=$(($retcode+$?))
 620 
 621 (( $retcode == $STF_PASS )) \
 622         && cleanup $STF_PASS "" "$MNTDIR/$TESTFILE $STF_TMPDIR/$NAME*.$$" \
 623         || cleanup $STF_FAIL "" "$MNTDIR/$TESTFILE $STF_TMPDIR/$NAME*.$$"