integ/base/cluster-resource-agents/debian/patches/lvm_vg_activation.patch
Yue Tao fcfb04d621 Add debian package for cluster-resource-agents
Except for Do-not-log-at-debug-log-level-when-HA_debug-is-unset.patch,
which is merged upstream, others local patches have been ported.

Depends-On: https://review.opendev.org/c/starlingx/tools/+/817010

Story: 2009221
Task: 43310

Signed-off-by: Yue Tao <yue.tao@windriver.com>
Change-Id: Id602f7b9dac55b06e46337fb800a865d3a82d701
2021-11-09 16:12:44 +08:00

163 lines
4.3 KiB
Diff

From 2f1a14bd8e6cc7b5d32c87a2e176567105f4f23d Mon Sep 17 00:00:00 2001
From: Scott Little <scott.little@windriver.com>
Date: Mon, 2 Oct 2017 15:12:54 -0400
Subject: [PATCH] WRS: Patch1110: lvm_vg_activation.patch
Porting the patch from StarlingX master branch.
BTW, change the /bin/sh to /bin/bash to fix syntax error, due to the
/bin/sh in debian links to /bin/dash
Signed-off-by: Yue Tao <Yue.Tao@windriver.com>
---
heartbeat/LVM | 119 +++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 117 insertions(+), 2 deletions(-)
diff --git a/heartbeat/LVM b/heartbeat/LVM
index a9f89a6..38f7c6b 100755
--- a/heartbeat/LVM
+++ b/heartbeat/LVM
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
#
#
# LVM
@@ -222,6 +222,81 @@ LVM_status() {
return $rc
}
+#
+# Activate one volume explicitly.
+#
+activate_volume() {
+ ocf_run lvchange $1 /dev/${2}/$3
+ if [ $? -eq 0 ] ; then
+ ocf_log info "Succesfully activated $LV."
+ else
+ ocf_log err "Problem activating $LV."
+ fi
+}
+
+#
+# Kick off parallel activation of all volumes
+#
+activate_all_volumes() {
+ VG=$1
+ shift
+ lvchange_args="$*"
+
+ # Get the list of volumes, without the first line which is column headings.
+ VOLS=`lvs $VG |tail -n +2`
+
+ while read -r LINE; do
+ # Convert the line into an array.
+ LINE_ARRAY=($LINE)
+
+ # First array element is the volume/snapshot name.
+ LV=${LINE_ARRAY[0]}
+
+ # Third array element is the attributes.
+ ATTR=${LINE_ARRAY[2]}
+
+ # Fifth character in the attributes is "a" if it's active.
+ ACTIVE=${ATTR:4:1}
+ if [ "$ACTIVE" == "a" ]; then
+ ocf_log info "$LV is already active."
+ continue
+ fi
+
+ SNAPSHOT_ORIGIN=${LINE_ARRAY[4]}
+ if [ "$SNAPSHOT_ORIGIN" != "" ] ; then
+ # If this is a snapshot, don't activate it.
+ continue
+ fi
+
+ ( activate_volume "$*" $VG $LV ) &
+ done <<< "$VOLS"
+}
+
+#
+# Scan for inactive volumes and log any that are found.
+#
+log_inactive_volumes() {
+ # Get the list of volumes, without the first line which is column headings.
+ VOLS=`lvs $1 |tail -n +2`
+
+ while read -r LINE; do
+ # Convert the line into an array.
+ LINE_ARRAY=($LINE)
+
+ # First array element is the volume/snapshot name.
+ LV=${LINE_ARRAY[0]}
+
+ # Third array element is the attributes.
+ ATTR=${LINE_ARRAY[2]}
+
+ # Fifth character in the attributes is "a" if it's active.
+ ACTIVE=${ATTR:4:1}
+ if [ "$ACTIVE" != "a" ]; then
+ ocf_log err "Volume $LV is not active after expiry of timeout."
+ fi
+ done <<< "$VOLS"
+}
+
#
# Enable LVM volume
#
@@ -242,10 +317,50 @@ LVM_start() {
ocf_run vgscan
fi
+ # Kick off activation of all volumes. If it doesn't complete within
+ # the timeout period, then we'll log the not-yet-activated volumes and
+ # continue on.
lvm_pre_activate || exit
- ocf_run vgchange $vgchange_activate_options $vg
+ (ocf_run vgchange $vgchange_activate_options $1) & PID=$!
lvm_post_activate $?
+ # Check every second for up to TIMEOUT seconds whether the vgchange has
+ # completed.
+ TIMEOUT=300
+ TIMED_OUT=true
+ SECONDS=0;
+ PARALLEL_ACTIVATE_DELAY=10
+ PARALLEL_ACTIVATE_DONE=false
+ while [ $SECONDS -lt $TIMEOUT ] ; do
+ kill -0 $PID &> /dev/null
+ if [ $? -eq 1 ] ; then
+ # process with pid of $PID doesn't exist, vgchange command completed
+ TIMED_OUT=false
+ break
+ fi
+ if [ $SECONDS -ge $PARALLEL_ACTIVATE_DELAY ] && \
+ [ "$PARALLEL_ACTIVATE_DONE" != true ] && \
+ [ "$1" == "cinder-volumes" ] ; then
+ # This will kick off parallel activation of all LVs in the VG.
+ # The delay is to ensure the VG is activated first.
+ PARALLEL_ACTIVATE_DONE=true
+ ocf_log info Explicitly activating all volumes in $1 with: $vgchange_activate_options
+ activate_all_volumes $1 $vgchange_activate_options
+ fi
+ sleep 1
+ done
+
+ if [ "$TIMED_OUT" = true ] ; then
+ ocf_log err "Timed out running ocf_run vgchange $vgchange_activate_options $1"
+ log_inactive_volumes $1
+ else
+ # Child process completed, get its status.
+ wait $PID
+ if [ $? -ne 0 ] ; then
+ return $OCF_ERR_GENERIC
+ fi
+ fi
+
if LVM_status $vg; then
: OK Volume $vg activated just fine!
return $OCF_SUCCESS
--
2.17.1