Skip to content

Commit

Permalink
[Mellanox] Improve FW upgrade: add locking mechanism. (#18925)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
nazariig authored and mssonicbld committed Jun 11, 2024
1 parent fc95e70 commit adf9b9c
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 adf9b9c

Please sign in to comment.