Skip to content

Commit

Permalink
[Mellanox]: Improve FW upgrade: add locking mechanism.
Browse files Browse the repository at this point in the history
Signed-off-by: Nazarii Hnydyn <nazariig@nvidia.com>
  • Loading branch information
nazariig committed Apr 19, 2024
1 parent 406d0e4 commit fb16117
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions platform/mellanox/mlnx-fw-upgrade.j2
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,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"

Expand Down Expand Up @@ -159,6 +161,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"
Expand Down Expand Up @@ -356,10 +372,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
Expand Down

0 comments on commit fb16117

Please sign in to comment.