Skip to content

Commit

Permalink
Updated tools for managing binding, nvme, and lvm (#15)
Browse files Browse the repository at this point in the history
* Updated tools for managing binding, nvme, and lvm

Signed-off-by: Nate Roiger <[email protected]>
  • Loading branch information
Nate Roiger authored Jul 21, 2022
1 parent 4fb0436 commit efc0b12
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 46 deletions.
39 changes: 27 additions & 12 deletions tools/bind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,35 @@
# limitations under the License.

usage() {
cat <<-EOF
Perform bind or unbind operation for NNF hardware.
Usage: $0 COMMAND
cat <<EOF
Run bind or unbind operations
Usage: $0 [-p] COMMAND
Commands:
bind bind the drives to the rabbit
unbind unbind the drives from the rabbit
bind bind all drives to the rabbit
unbind unbind all drives from the rabbit
Options:
-p Bind physical function (EXPERIMENTAL)
EOF
}

if [ $# -lt 1 ]; then
usage
exit 1
fi

FUNCTION=1
while getopts "ph" OPTION
do
case "${OPTION}" in
'p')
echo "WARNING: Binding of Physical Function is not advised"
FUNCTION=0
;;
'h')
usage
exit 0
;;
esac
done
shift $((OPTIND - 1))

SWITCHES=("/dev/switchtec0" "/dev/switchtec1")

Expand All @@ -40,7 +55,7 @@ case $1 in
for SWITCH in ${SWITCHES[@]};
do
HOST_SW_INDEX=$(switchtec fabric gfms-dump $SWITCH | head -n1 | grep "PAX ID" | awk '{print $3}')
PDFIDS=( $(switchtec fabric gfms-dump $SWITCH | grep "Function 1 " -A1 | grep PDFID | awk '{print $2}') )
PDFIDS=( $(switchtec fabric gfms-dump $SWITCH | grep "Function $FUNCTION " -A1 | grep PDFID | awk '{print $2}') )
for INDEX in "${!PDFIDS[@]}";
do
echo "Performing Bind Operation $SWITCH $HOST_SW_INDEX $INDEX ${PDFIDS[$INDEX]}"
Expand All @@ -52,7 +67,7 @@ case $1 in
for SWITCH in ${SWITCHES[@]};
do
HOST_SW_INDEX=$(switchtec fabric gfms-dump $SWITCH | head -n1 | grep "PAX ID" | awk '{print $3}')
PDFIDS=( $(switchtec fabric gfms-dump $SWITCH | grep "Function 1 " -A1 | grep PDFID | awk '{print $2}') )
PDFIDS=( $(switchtec fabric gfms-dump $SWITCH | grep "Function $FUNCTION " -A1 | grep PDFID | awk '{print $2}') )
for INDEX in "${!PDFIDS[@]}";
do
echo "Performing Unbind Operation $SWITCH $HOST_SW_INDEX $INDEX ${PDFIDS[$INDEX]}"
Expand All @@ -64,4 +79,4 @@ case $1 in
usage
exit 1
;;
esac
esac
102 changes: 102 additions & 0 deletions tools/lvm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/bin/bash

# Copyright 2022 Hewlett Packard Enterprise Development LP
# Other additional copyright holders may be indicated within.
#
# The entirety of this work is licensed under the Apache License,
# Version 2.0 (the "License"); you may not use this file except
# in compliance with the License.
#
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

usage() {
cat <<EOF
Manage LVM volumes on Rabbit
Usage: $0 COMMAND [ARGS...]
Commands:
list-drives list the drives used in create/delete
create [NAME] [NAMESPACE-ID] create an LVM volume all drives
delete [NAME] delete an LVM volume
EOF
}

DRIVES=()

drives() {
local NAMESPACE=$1
for DRIVE in $(ls /dev/nvme* | grep -E "nvme[[:digit:]]+n[[:digit:]]+$");
do
if [ "$(nvme id-ctrl ${DRIVE} | grep KIOXIA)" != "" ];
then
echo " Found Kioxia drive ${DRIVE}"
NAMESPACEID=$(nvme id-ns ${DRIVE} | grep -E '^NVME Identify Namespace [[:digit:]]+' | awk '{print $4}')
if [ "${NAMESPACEID::-1}" == "$NAMESPACE" ];
then
echo " Found Namespace ${NAMESPACE}"

DRIVES+="${DRIVE} "
fi
fi
done

echo "DRIVES: ${DRIVES[@]}"
}

NAME=${2:-"rabbit"}
NAMESPACE=${3:-"1"}

case $1 in
list-drives)
drives $NAMESPACE
;;
create)
drives $NAMESPACE
for DRIVE in ${DRIVES[@]};
do
echo "Creating Physical Volume '${DRIVE}'"
pvcreate ${DRIVE}
done

echo "Creating Volume Group '${NAME}'"
vgcreate ${NAME} ${DRIVES[@]}

echo "Creating Logical Volume '${NAME}'"
lvcreate -Zn --extents 100%VG --stripes ${#DRIVES[@]} --stripesize 32KiB --name ${NAME} ${NAME}

echo "Activate Volume Group '${NAME}'"
vgchange --activate y ${NAME}

echo "DONE! Access the volume at /dev/${NAME}/${NAME}"
;;
delete)
echo "Removing Logical Volume '${NAME}'"
lvremove --yes /dev/{$NAME}/${NAME}

echo "Deactivate Volume Group '${NAME}'"
vgchange --activate n ${NAME}

echo "Removing Volume Group'${NAME}'"
vgremove --yes ${NAME}

drives $NAMESPACE
for DRIVE in ${DRIVES};
do
echo "Remove Physical Volume '${DRIVE}'"
pvremove --yes ${DRIVE}
done
;;
*)
usage
exit 1
;;
esac

49 changes: 18 additions & 31 deletions tools/ns.sh → tools/nvme.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
#
# Copyright 2020, 2021, 2022 Hewlett Packard Enterprise Development LP

# Copyright 2022 Hewlett Packard Enterprise Development LP
# Other additional copyright holders may be indicated within.
#
# The entirety of this work is licensed under the Apache License,
Expand All @@ -19,32 +19,20 @@

usage() {
cat <<EOF
Example NVMe Namespace commands running against switchtec managed devices.
Usage: $0 COMMAND
Run various NVMe Namespace commands
Usage: $0 COMMAND [ARGS...]
Commands:
create-ns create two namespaces on all drives
attach-ns attach two namespaces to the controller
delete-ns delete two namespaces on all drives
create create an nvme namespace on each drive
attach [NAMESPACE-ID] [CONTROLLER] attach namespaces from each drive to a controller
delete [NAMESPACE-ID] delete an nvme namespace on each drive
EOF
}

if [ $# -lt 1 ]; then
usage
exit 1
fi

SWITCHES=("/dev/switchtec0" "/dev/switchtec1")
for SWITCH in ${SWITCHES[@]}
do
if [ ! -f $SWITCH ]; then
echo "Switch $SWITCH does not exists. Are you running from the Rabbit? Is the switch up?"
exit 1
fi
done

case $1 in
create-ns)
create)
SIZE=97670000
for SWITCH in ${SWITCHES[@]};
do
Expand All @@ -53,37 +41,36 @@ case $1 in
do
echo "Creating Namespaces on ${PDFIDS[$INDEX]}"
switchtec-nvme create-ns ${PDFIDS[$INDEX]}@$SWITCH --nsze=$SIZE --ncap=$SIZE --block-size=4096
switchtec-nvme create-ns ${PDFIDS[$INDEX]}@$SWITCH --nsze=$SIZE --ncap=$SIZE --block-size=4096
done
done
;;
attach-ns)
SWITCHES=("/dev/switchtec0" "/dev/switchtec1")
attach)
NAMESPACE=${2:-"1"}
CONTROLLER=${3:-"3"}
for SWITCH in ${SWITCHES[@]};
do
PDFIDS=( $(switchtec fabric gfms-dump $SWITCH | grep "Function 0 " -A1 | grep PDFID | awk '{print $2}') )
for INDEX in "${!PDFIDS[@]}";
do
echo "Attaching Namespaces on ${PDFIDS[$INDEX]}"
switchtec-nvme attach-ns ${PDFIDS[$INDEX]}@$SWITCH --namespace-id=1 --controllers=1
switchtec-nvme attach-ns ${PDFIDS[$INDEX]}@$SWITCH --namespace-id=2 --controllers=1
echo "Attaching Namespace $NAMESPACE on ${PDFIDS[$INDEX]} to Controller $CONTROLLER"
switchtec-nvme attach-ns ${PDFIDS[$INDEX]}@$SWITCH --namespace-id=$NAMESPACE --controllers=$CONTROLLER
done
done
;;
delete-ns)
delete)
NAMESPACE=${2:-"1"}
for SWITCH in ${SWITCHES[@]};
do
PDFIDS=( $(switchtec fabric gfms-dump $SWITCH | grep "Function 0 " -A1 | grep PDFID | awk '{print $2}') )
for INDEX in "${!PDFIDS[@]}";
do
echo "Deleting Namespaces on ${PDFIDS[$INDEX]}"
switchtec-nvme delete-ns ${PDFIDS[$INDEX]}@$SWITCH --namespace-id=1
switchtec-nvme delete-ns ${PDFIDS[$INDEX]}@$SWITCH --namespace-id=2
echo "Deleting Namespaces $NAMESPACE on ${PDFIDS[$INDEX]}"
switchtec-nvme delete-ns ${PDFIDS[$INDEX]}@$SWITCH --namespace-id=$NAMESPACE
done
done
;;
*)
usage
exit 1
;;
esac
esac
22 changes: 19 additions & 3 deletions tools/rabbit-s.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ case $CMD in
PAX=$(echo $DEVICE | cut -w -f1)

echo "Enabling Logging on $PAX"
$SSHPASS ssh root@$SYSTEM <<-EOF
$SSHPASS ssh -T root@$SYSTEM <<-EOF
[ "$(screen -ls | grep $PAX)" == "" ] &&
screen -dmS $DEVICE 230400 &&
screen -S $PAX -X colon "logfile $PAX.log^M" &&
Expand Down Expand Up @@ -109,11 +109,27 @@ EOF
screen -S $SESSION -X stuff "fabdbg -c fio\n"
EOF
done
;;
;;
additional-logs)
for SESSION in "${SESSIONS[@]}"
do
$SSHPASS ssh root@$SYSTEM <<-EOF
screen -S $SESSION -X stuff "log -p on\nlog -m 0x54 -s3 -p on\nlog -m 0x82 -s3 -p on\nlog -m 0x84 -s3 -p on\n"
EOF
done
;;
additional-logs-off)
for SESSION in "${SESSIONS[@]}"
do
$SSHPASS ssh root@$SYSTEM <<-EOF
screen -S $SESSION -X stuff "log -p off\nlog -m 0x54 -s3 -p off\nlog -m 0x82 -s3 -p off\nlog -m 0x84 -s3 -p off\n"
EOF
done
;;
quit-sessions)
for SESSION in "${SESSIONS[@]}"
do
$SSHPASS ssh root@$SYSTEM "screen -S $SESSION -X quit"
$SSHPASS ssh -T root@$SYSTEM "screen -S $SESSION -X quit"
done
;;
lnkstat)
Expand Down

0 comments on commit efc0b12

Please sign in to comment.