|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED. |
| 4 | +# |
| 5 | +# This software product is a proprietary product of Nvidia Corporation and its affiliates |
| 6 | +# (the "Company") and all right, title, and interest in and to the software |
| 7 | +# product, including all associated intellectual property rights, are and |
| 8 | +# shall remain exclusively with the Company. |
| 9 | +# |
| 10 | +# This software product is governed by the End User License Agreement |
| 11 | +# provided with the software product. |
| 12 | +# |
| 13 | + |
| 14 | +# Usage: ./nvme_checks.sh [<ns_dev> [<ctrl_dev>]] |
| 15 | +# Defaults: /dev/nvme0n1 (namespace), /dev/nvme0 (controller) |
| 16 | +# Override timeout/grace via env: TIMEOUT=10s KILL_DELAY=2s ./nvme_checks.sh |
| 17 | + |
| 18 | +NS_DEV=${1:-/dev/nvme0n1} |
| 19 | +CTRL_DEV=${2:-/dev/nvme0} |
| 20 | +TIMEOUT=${TIMEOUT:-5s} |
| 21 | +KILL_DELAY=${KILL_DELAY:-1s} |
| 22 | + |
| 23 | +run_nvme_cmd() { |
| 24 | + subcmd=$1 |
| 25 | + dev=$2 |
| 26 | + echo -e "\n\nRunning nvme $subcmd $dev (timeout $TIMEOUT)\n\n" |
| 27 | + if timeout -k "$KILL_DELAY" "$TIMEOUT" nvme "$subcmd" "$dev"; then |
| 28 | + echo "nvme $subcmd succeeded for $dev." |
| 29 | + else |
| 30 | + rc=$? |
| 31 | + if [[ $rc -eq 124 ]]; then |
| 32 | + echo "nvme $subcmd timed out after $TIMEOUT and was terminated." |
| 33 | + else |
| 34 | + echo "nvme $subcmd failed for $dev (exit code $rc)." |
| 35 | + fi |
| 36 | + fi |
| 37 | +} |
| 38 | + |
| 39 | +echo -e "Running nvme list --output=json \n\n" |
| 40 | +nvme_list_output=$(timeout ${TIMEOUT} nvme list --output=json) |
| 41 | +echo ${nvme_list_output} |
| 42 | + |
| 43 | +# Namespace-level commands (require block device like /dev/nvme0n1) |
| 44 | +if [[ -b "$NS_DEV" ]]; then |
| 45 | + for subcmd in smart-log error-log fw-log; do |
| 46 | + run_nvme_cmd "$subcmd" "$NS_DEV" |
| 47 | + done |
| 48 | +else |
| 49 | + echo "Namespace device $NS_DEV not found (skipping smart-log/error-log/fw-log)." |
| 50 | +fi |
| 51 | + |
| 52 | +# Controller-level command (requires controller device like /dev/nvme0, usually a char device) |
| 53 | +if [[ -c "$CTRL_DEV" || -b "$CTRL_DEV" ]]; then |
| 54 | + run_nvme_cmd "id-ctrl" "$CTRL_DEV" |
| 55 | +else |
| 56 | + echo "Controller device $CTRL_DEV not found (skipping id-ctrl)." |
| 57 | +fi |
| 58 | + |
| 59 | +if ! printf '%s' "$nvme_list_output" | jq -e . >/dev/null 2>&1; then |
| 60 | + echo "nvme list output is empty or invalid JSON" |
| 61 | +elif printf '%s' "$nvme_list_output" | jq -e '.Devices[] | select(.ModelNumber=="Virtium VTPM24CEXI080-BM110006")' >/dev/null; then |
| 62 | + echo "Found NVMe with ModelNumber VTPM24CEXI080-BM110006" |
| 63 | + echo -e "\n\nRunning /usr/local/bin/vtFA_RTK_5766_v2 ${CTRL_DEV}\n\n" |
| 64 | + #Create tmp directory to run vtFA_RTK_5766_v2, then get the output from that directory |
| 65 | + ssd_dump_generated_files=/tmp/ssd_dump_generated_files |
| 66 | + rm -rf ${ssd_dump_generated_files} |
| 67 | + mkdir -p ${ssd_dump_generated_files} |
| 68 | + cd ${ssd_dump_generated_files} |
| 69 | + # Try to run vtFA_RTK_5766_v2 with retry |
| 70 | + RETRIES="2" |
| 71 | + DELAY="2" |
| 72 | + attempt=1 |
| 73 | + rc=1 |
| 74 | + while [ "$attempt" -le "$RETRIES" ]; do |
| 75 | + echo "Attempt $attempt/$RETRIES: vtFA_RTK_5766_v2 $CTRL_DEV (timeout $TIMEOUT)" |
| 76 | + if timeout -k "$KILL_DELAY" "$TIMEOUT" /usr/local/bin/vtFA_RTK_5766_v2 "$CTRL_DEV"; then |
| 77 | + echo "vtFA_RTK_5766_v2 succeeded for $CTRL_DEV." |
| 78 | + rc=0 |
| 79 | + break |
| 80 | + else |
| 81 | + rc=$? |
| 82 | + if [ "$rc" -eq 124 ]; then |
| 83 | + echo "vtFA_RTK_5766_v2 timed out after $TIMEOUT and was terminated." |
| 84 | + else |
| 85 | + echo "vtFA_RTK_5766_v2 failed (exit code $rc)." |
| 86 | + fi |
| 87 | + if [ "$attempt" -lt "$RETRIES" ]; then |
| 88 | + echo "Retrying in $DELAY seconds..." |
| 89 | + sleep "$DELAY" |
| 90 | + fi |
| 91 | + fi |
| 92 | + attempt=$((attempt + 1)) |
| 93 | + done |
| 94 | + if [ "$rc" -ne 0 ]; then |
| 95 | + echo "Failed to run vtFA_RTK_5766_v2 after $RETRIES attempts." |
| 96 | + fi |
| 97 | + cd - >/dev/null |
| 98 | + # generate_dump script will collect files from ${ssd_dump_generated_files} and then remove the folder |
| 99 | +else |
| 100 | + echo "Skiping vtFA_RTK_5766_v2" |
| 101 | +fi |
0 commit comments