Revert "Revert "oran-shell-release: release image for F""
[pti/rtp.git] / meta-starlingx / meta-stx-cloud / recipes-support / cluster-resource-agents / resource-agents / stx / lvm_vg_activation.patch
1 From 577055560d55b388d479ef398ffd839792dc1996 Mon Sep 17 00:00:00 2001
2 From: Scott Little <scott.little@windriver.com>
3 Date: Mon, 2 Oct 2017 15:12:54 -0400
4 Subject: [PATCH 06/13] WRS: Patch1110: lvm_vg_activation.patch
5
6 ---
7  heartbeat/LVM | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
8  1 file changed, 116 insertions(+), 1 deletion(-)
9
10 diff --git a/heartbeat/LVM b/heartbeat/LVM
11 index b0ca87a..38092f9 100755
12 --- a/heartbeat/LVM
13 +++ b/heartbeat/LVM
14 @@ -222,6 +222,81 @@ LVM_status() {
15  }
16  
17  #
18 +#    Activate one volume explicitly.
19 +#
20 +activate_volume() {
21 +        ocf_run lvchange $1 /dev/${2}/$3
22 +        if [ $? -eq 0 ] ; then
23 +            ocf_log info "Succesfully activated $LV."
24 +        else
25 +            ocf_log err "Problem activating $LV."
26 +        fi
27 +}
28 +
29 +#
30 +#    Kick off parallel activation of all volumes
31 +#
32 +activate_all_volumes() {
33 +   VG=$1
34 +   shift
35 +   lvchange_args="$*"
36 +
37 +   # Get the list of volumes, without the first line which is column headings.
38 +   VOLS=`lvs $VG |tail -n +2`
39 +
40 +   while read -r LINE; do
41 +       # Convert the line into an array.
42 +       LINE_ARRAY=($LINE)
43 +
44 +       # First array element is the volume/snapshot name.
45 +       LV=${LINE_ARRAY[0]}
46 +
47 +       # Third array element is the attributes.
48 +       ATTR=${LINE_ARRAY[2]}
49 +
50 +       # Fifth character in the attributes is "a" if it's active.
51 +       ACTIVE=${ATTR:4:1}
52 +       if [ "$ACTIVE" == "a" ]; then
53 +         ocf_log info "$LV is already active."
54 +         continue
55 +       fi
56 +
57 +       SNAPSHOT_ORIGIN=${LINE_ARRAY[4]}
58 +       if [ "$SNAPSHOT_ORIGIN" != "" ] ; then
59 +         # If this is a snapshot, don't activate it.
60 +         continue
61 +       fi
62 +
63 +       ( activate_volume "$*" $VG $LV ) &
64 +    done <<< "$VOLS"
65 +}
66 +
67 +#
68 +#    Scan for inactive volumes and log any that are found.
69 +#
70 +log_inactive_volumes() {
71 +    # Get the list of volumes, without the first line which is column headings.
72 +    VOLS=`lvs $1 |tail -n +2`
73 +
74 +    while read -r LINE; do
75 +        # Convert the line into an array.
76 +        LINE_ARRAY=($LINE)
77 +
78 +        # First array element is the volume/snapshot name.
79 +        LV=${LINE_ARRAY[0]}
80 +
81 +        # Third array element is the attributes.
82 +        ATTR=${LINE_ARRAY[2]}
83 +
84 +        # Fifth character in the attributes is "a" if it's active.
85 +        ACTIVE=${ATTR:4:1}
86 +        if [ "$ACTIVE" != "a" ]; then
87 +            ocf_log err "Volume $LV is not active after expiry of timeout."
88 +        fi
89 +    done <<< "$VOLS"
90 +}
91 +
92 +#
93  #      Enable LVM volume
94  #
95  LVM_start() {
96 @@ -241,10 +316,50 @@ LVM_start() {
97                 ocf_run vgscan
98         fi
99  
100 +        # Kick off activation of all volumes.  If it doesn't complete within
101 +       # the timeout period, then we'll log the not-yet-activated volumes and
102 +       # continue on.
103         lvm_pre_activate || exit
104 -       ocf_run vgchange $vgchange_activate_options $vg
105 +       (ocf_run vgchange $vgchange_activate_options $1) & PID=$!
106         lvm_post_activate $?
107  
108 +       # Check every second for up to TIMEOUT seconds whether the vgchange has
109 +       # completed.
110 +       TIMEOUT=300
111 +       TIMED_OUT=true
112 +       SECONDS=0;
113 +       PARALLEL_ACTIVATE_DELAY=10
114 +       PARALLEL_ACTIVATE_DONE=false
115 +       while [ $SECONDS -lt $TIMEOUT ] ; do
116 +               kill -0 $PID &> /dev/null
117 +               if [ $? -eq 1 ] ; then
118 +               # process with pid of $PID doesn't exist, vgchange command completed
119 +                       TIMED_OUT=false
120 +                       break
121 +               fi
122 +               if [ $SECONDS -ge $PARALLEL_ACTIVATE_DELAY ] && \
123 +                       [ "$PARALLEL_ACTIVATE_DONE" != true ] && \
124 +                       [ "$1" == "cinder-volumes" ] ; then
125 +                       # This will kick off parallel activation of all LVs in the VG.
126 +                       # The delay is to ensure the VG is activated first.
127 +                       PARALLEL_ACTIVATE_DONE=true
128 +                       ocf_log info Explicitly activating all volumes in $1 with: $vgchange_activate_options
129 +                       activate_all_volumes $1 $vgchange_activate_options
130 +               fi
131 +               sleep 1
132 +       done
133 +
134 +       if [ "$TIMED_OUT" = true ] ; then
135 +               ocf_log err "Timed out running ocf_run vgchange $vgchange_activate_options $1"
136 +               log_inactive_volumes $1
137 +       else
138 +               # Child process completed, get its status.
139 +               wait $PID
140 +               if [ $? -ne 0 ] ; then
141 +                       return $OCF_ERR_GENERIC
142 +               fi
143 +       fi
144 +
145         if LVM_status $vg; then
146                 : OK Volume $vg activated just fine!
147                 return $OCF_SUCCESS 
148 -- 
149 2.7.4
150