"Fossies" - the Fresh Open Source Software Archive

Member "glusterfs-8.6/tests/basic/fencing/afr-lock-heal-basic.t" (20 Aug 2021, 4074 Bytes) of package /linux/misc/glusterfs-8.6.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "afr-lock-heal-basic.t": 8.5_vs_8.6.

    1 #!/bin/bash
    2 
    3 . $(dirname $0)/../../include.rc
    4 . $(dirname $0)/../../volume.rc
    5 
    6 cleanup;
    7 
    8 function is_gfapi_program_alive()
    9 {
   10         pid=$1
   11         ps -p $pid
   12         if [ $? -eq 0 ]
   13         then
   14                 echo "Y"
   15         else
   16                 echo "N"
   17         fi
   18 }
   19 
   20 function fill_lock_info()
   21 {
   22     local -n info=$1
   23     local brick=$2
   24     pattern="ACTIVE.*client-${brick: -1}"
   25 
   26     brick_sdump=$(generate_brick_statedump $V0 $H0 $brick)
   27     info="$(egrep "$inode" $brick_sdump -A3| egrep "$pattern" | uniq | awk '{print $1,$2,$3,S4,$5,$6,$7,$8}'|tr -d '(,), ,')"
   28 
   29     if [ -n "$info" ]
   30     then
   31         echo "success"
   32     else
   33         echo "failure"
   34     fi
   35 }
   36 
   37 TEST glusterd
   38 TEST pidof glusterd
   39 TEST $CLI volume info;
   40 
   41 TEST $CLI volume create $V0 replica 3 $H0:$B0/${V0}{0,1,2}
   42 EXPECT 'Created' volinfo_field $V0 'Status';
   43 TEST $CLI volume set $V0 performance.write-behind off
   44 TEST $CLI volume set $V0 performance.open-behind off
   45 TEST $CLI volume set $V0 locks.mandatory-locking forced
   46 TEST $CLI volume set $V0 enforce-mandatory-lock on
   47 TEST $CLI volume start $V0;
   48 EXPECT 'Started' volinfo_field $V0 'Status';
   49 
   50 logdir=`gluster --print-logdir`
   51 TEST build_tester $(dirname $0)/afr-lock-heal-basic.c -lgfapi -ggdb
   52 
   53 $(dirname $0)/afr-lock-heal-basic $H0 $V0 "/FILE" $logdir C1&
   54 client1_pid=$!
   55 TEST [ $client1_pid ]
   56 
   57 $(dirname $0)/afr-lock-heal-basic $H0 $V0 "/FILE" $logdir C2&
   58 client2_pid=$!
   59 TEST [ $client2_pid ]
   60 
   61 TEST sleep 5 # By now, the 2 clients would  have opened an fd on FILE and waiting for a SIGUSR1.
   62 EXPECT "Y" is_gfapi_program_alive $client1_pid
   63 EXPECT "Y" is_gfapi_program_alive $client2_pid
   64 
   65 gfid_str=$(gf_gfid_xattr_to_str $(gf_get_gfid_xattr $B0/${V0}0/FILE))
   66 inode="FILE|gfid:$gfid_str"
   67 
   68 # Kill brick-3 and let client-1 take lock on the file.
   69 TEST kill_brick $V0 $H0 $B0/${V0}2
   70 TEST kill -SIGUSR1 $client1_pid
   71 # If program is still alive, glfs_file_lock() was a success.
   72 EXPECT "Y" is_gfapi_program_alive $client1_pid
   73 
   74 # Check lock is present on brick-1 and brick-2
   75 EXPECT_WITHIN $PROCESS_UP_TIMEOUT "success" fill_lock_info c1_lock_on_b1 $B0/${V0}0
   76 EXPECT_WITHIN $PROCESS_UP_TIMEOUT "success" fill_lock_info c1_lock_on_b2 $B0/${V0}1
   77 TEST [ "$c1_lock_on_b1" == "$c1_lock_on_b2" ]
   78 
   79 # Restart brick-3 and check that the lock has healed on it.
   80 TEST $CLI volume start $V0 force
   81 EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" brick_up_status $V0 $H0 $B0/${V0}2
   82 
   83 # Note: We need to wait for client to re-open the fd. Otherwise client_pre_lk_v2() fails with EBADFD for remote-fd. Also wait for lock heal.
   84 # So we may need to check the statedump for locks multiple times.
   85 EXPECT_WITHIN $PROCESS_UP_TIMEOUT "success" fill_lock_info c1_lock_on_b3 $B0/${V0}2 
   86 TEST [ "$c1_lock_on_b1" == "$c1_lock_on_b3" ]
   87 
   88 # Kill brick-1 and let client-2 preempt the lock on bricks 2 and 3.
   89 TEST kill_brick $V0 $H0 $B0/${V0}0
   90 TEST kill -SIGUSR1 $client2_pid
   91 # If program is still alive, glfs_file_lock() was a success.
   92 EXPECT "Y" is_gfapi_program_alive $client2_pid
   93 
   94 # Restart brick-1 and let lock healing complete.
   95 TEST $CLI volume start $V0 force
   96 EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" brick_up_status $V0 $H0 $B0/${V0}0
   97 
   98 # Check that all bricks now have locks from client 2 only.
   99 # Note: We need to wait for client to re-open the fd. Otherwise client_pre_lk_v2() fails with EBADFD for remote-fd. Also wait for lock heal.
  100 # So we may need to check the statedump for locks multiple times.
  101 EXPECT_WITHIN $PROCESS_UP_TIMEOUT "success" fill_lock_info c2_lock_on_b1 $B0/${V0}0
  102 EXPECT_WITHIN $PROCESS_UP_TIMEOUT "success" fill_lock_info c2_lock_on_b2 $B0/${V0}1
  103 EXPECT_WITHIN $PROCESS_UP_TIMEOUT "success" fill_lock_info c2_lock_on_b3 $B0/${V0}2
  104 TEST [ "$c2_lock_on_b1" == "$c2_lock_on_b2" ]
  105 TEST [ "$c2_lock_on_b1" == "$c2_lock_on_b3" ]
  106 TEST [ "$c2_lock_on_b1" != "$c1_lock_on_b1" ]
  107 
  108 #Let the client programs run and exit.
  109 TEST kill -SIGUSR1 $client1_pid
  110 EXPECT_WITHIN $PROCESS_UP_TIMEOUT "N" is_gfapi_program_alive $client1_pid
  111 TEST kill -SIGUSR1 $client2_pid
  112 EXPECT_WITHIN $PROCESS_UP_TIMEOUT "N" is_gfapi_program_alive $client2_pid
  113 
  114 cleanup_tester $(dirname $0)/afr-lock-heal-basic
  115 cleanup;