summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2021-07-02 20:40:30 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2021-07-02 20:40:30 +0000
commitdc597ce8df5ae6efd2728a2d7ba7d92486028f79 (patch)
tree55b9e9257eba4579667f9522368aa29f5be6754a /scripts
parentInitial commit. (diff)
downloadnvme-cli-dc597ce8df5ae6efd2728a2d7ba7d92486028f79.tar.xz
nvme-cli-dc597ce8df5ae6efd2728a2d7ba7d92486028f79.zip
Adding upstream version 1.12.upstream/1.12
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/gen-hostnqn.sh42
-rwxr-xr-xscripts/latency114
2 files changed, 156 insertions, 0 deletions
diff --git a/scripts/gen-hostnqn.sh b/scripts/gen-hostnqn.sh
new file mode 100644
index 0000000..d8783cf
--- /dev/null
+++ b/scripts/gen-hostnqn.sh
@@ -0,0 +1,42 @@
+#!/bin/bash
+
+LC_ALL=C
+
+UUID=$(dmidecode -s system-uuid | tr -d '[:space:]')
+
+if [ -z "$UUID" ] ; then
+ >&2 echo "No UUID found, can't determine hostnqn."
+ exit 1
+fi
+
+# convert UUID to lower-case only:
+UUID=$(echo $UUID | tr '[:upper:]' '[:lower:]')
+
+# check UUID format, e.g.: 4c4c4544-0156-4a10-8134-b7d04f383232, so: 8-4-4-4-12
+if ! [[ $UUID =~ ^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$ ]] ; then
+ >&2 echo "UUID has invalid format."
+ >&2 echo "Invalid UUID: ${UUID}"
+ exit 2
+fi
+
+# HEURISTIC:
+# (1) if any one given character occurs more than 50% of the time, it is likely
+# that the UUID is fake.
+# (2) if the first or the last group consists of mostly the same character, it
+# is likely that the UUID is fake.
+FIRST_GROUP="$(echo $UUID | cut -d'-' -f1)"
+LAST_GROUP="$(echo $UUID | cut -d'-' -f5)"
+for i in {{0..9},{a..f}} ; do
+ COUNT_TOTAL="${UUID//[^$i]}"
+ COUNT_FIRST="${FIRST_GROUP//[^$i]}"
+ COUNT_LAST="${LAST_GROUP//[^$i]}"
+ if [ ${#COUNT_TOTAL} -ge 16 ] || [ ${#COUNT_FIRST} -ge 7 ] || [ ${#COUNT_LAST} -ge 11 ] ; then
+ >&2 echo "UUID is too repetitive. This may be a false alert."
+ >&2 echo "Repetitive UUID: ${UUID}"
+ exit 3
+ fi
+done
+
+HOSTNQN="nqn.2014-08.org.nvmexpress:uuid:${UUID}"
+
+echo $HOSTNQN
diff --git a/scripts/latency b/scripts/latency
new file mode 100755
index 0000000..908ae4a
--- /dev/null
+++ b/scripts/latency
@@ -0,0 +1,114 @@
+#!/bin/bash
+#
+# Copyright 2015 PMC-Sierra, Inc.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA.
+#
+# Author: Stephen Bates <stephen.bates@pmcs.com>
+#
+# Description:
+# A shell script that calls the NVMe CLI multiple times to gather
+# latency data. Consider this a poor man's iometer or fio for QD=1
+# analysis. Of course this is below the file-system and block
+# layer so is a best case measurement.
+#
+
+DEVICE=
+WRITE=false
+COUNT=10
+DATA_SIZE=4096
+METADATA_SIZE=64
+
+RAND_BASE=temp.rand
+RAND_WFILE=${RAND_BASE}.write
+RAND_RFILE=${RAND_BASE}.read
+OUTPUT=latency.dat
+
+green=$(tput bold)$(tput setaf 2)
+red=$(tput bold)$(tput setaf 1)
+rst=$(tput sgr0)
+
+while getopts ":d:n:w" opt; do
+ case $opt in
+ d)
+ DEVICE=${OPTARG}
+ ;;
+ n)
+ COUNT=${OPTARG}
+ ;;
+ w)
+ echo "WARNING: Write mode enabled, this might trash your drive!"
+ WRITE=true
+ ;;
+ \?)
+ echo "Invalid option: -$OPTARG" >&2
+ exit 1
+ ;;
+ :)
+ echo "Option -$OPTARG requires an argument." >&2
+ exit 1
+ ;;
+ esac
+done
+
+if [ "$COUNT" == "0" ]; then
+ echo "Count can not be 0"
+ exit 1
+fi
+
+if [ -z "$DEVICE" ]; then
+ echo "regress: You must specify a NVMe device using -d"
+ exit 1
+fi
+
+function run_test {
+ $* | grep -i latency >> ${OUTPUT} 2>&1
+ if (( $? )); then
+ echo ${red}"FAILED!"${rst}
+ echo "Failed running command: "
+ echo " $*"
+ exit 1
+ fi
+}
+
+rm -f ${OUTPUT} > /dev/null || exit -1
+make clean > /dev/null || exit -1
+make install > /dev/null || exit -1
+
+for i in `seq 1 ${COUNT}`;
+do
+ if $WRITE ; then
+ dd if=/dev/urandom of=${RAND_WFILE} bs=${DATA_SIZE} count=1
+ run_test nvme write ${DEVICE} --start-block=0 --block-count=0 \
+ --metadata-size=${METADATA_SIZE} --data-size=${DATA_SIZE} \
+ --data ${RAND_WFILE} --latency
+ rm ${RAND_WFILE} > /dev/null
+ else
+ run_test nvme read ${DEVICE} --start-block=0 --block-count=0 \
+ --metadata-size=${METADATA_SIZE} --data-size=${DATA_SIZE} \
+ --data ${RAND_RFILE} --latency
+ rm ${RAND_RFILE} > /dev/null
+ fi
+done
+
+# Calculate average latency
+SUM=0
+for i in `cat ${OUTPUT} | awk '{print $3}' | xargs`
+do
+ SUM=$(($SUM + $i))
+done
+AVERAGE=$(echo "scale=2; $SUM/$COUNT" | bc -l)
+echo "Average Latency: $AVERAGE us"