From a7e25d9feb97d748a9bc67718fbaa400a6893ccc Mon Sep 17 00:00:00 2001 From: Nazarii Hnydyn Date: Mon, 10 Jun 2024 14:00:02 +0300 Subject: [PATCH] [Mellanox] Improve FW upgrade: add locking mechanism. (#18925) User implications: On cold/warm/fast reboot if there is a syncd service start ongoing, the target procedure will stay blocked until the original call is done. This may delay the action in time. - Why I did it Improve the upgrade fw script avoiding errors in the logs when cold reboot is executed during service restart Work item tracking - How I did it Added locking mechanism for Mellanox FW upgrade - How to verify it Run cold reboot after DUT first install Signed-off-by: Nazarii Hnydyn --- platform/mellanox/mlnx-fw-upgrade.j2 | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/platform/mellanox/mlnx-fw-upgrade.j2 b/platform/mellanox/mlnx-fw-upgrade.j2 index eb288624982c..e4c567c1b76e 100755 --- a/platform/mellanox/mlnx-fw-upgrade.j2 +++ b/platform/mellanox/mlnx-fw-upgrade.j2 @@ -20,6 +20,8 @@ declare -r SCRIPT_NAME="$(basename "$0")" declare -r SCRIPT_PATH="$(readlink -f "$0")" declare -r SCRIPT_DIR="$(dirname "$SCRIPT_PATH")" +declare -r LOCKFILE="/tmp/mlxfwmanager-lock" + declare -r YES_PARAM="yes" declare -r NO_PARAM="no" @@ -163,6 +165,20 @@ function ExitSuccess() { exit "${EXIT_SUCCESS}" } +function LockStateChange() { + LogInfo "Locking ${LOCKFILE} from ${SCRIPT_NAME}" + + exec {LOCKFD}>${LOCKFILE} + /usr/bin/flock -x ${LOCKFD} + + LogInfo "Locked ${LOCKFILE} (${LOCKFD}) from ${SCRIPT_NAME}" +} + +function UnlockStateChange() { + LogInfo "Unlocking ${LOCKFILE} (${LOCKFD}) from ${SCRIPT_NAME}" + /usr/bin/flock -u ${LOCKFD} +} + function WaitForDevice() { local -i QUERY_RETRY_COUNT_MAX="10" local -i QUERY_RETRY_COUNT="0" @@ -372,10 +388,20 @@ function ExitIfQEMU() { fi } +function Cleanup() { + if [[ -n "${LOCKFD}" ]]; then + UnlockStateChange + fi +} + +trap Cleanup EXIT + ParseArguments "$@" ExitIfQEMU +LockStateChange + WaitForDevice if [ "${IMAGE_UPGRADE}" != "${YES_PARAM}" ]; then