Different approach to NVMe subsystem handling #163
Replies: 7 comments 10 replies
-
For tracking purposes: #148 Thank you for continuing this dialogue. I will review shortly. |
Beta Was this translation helpful? Give feedback.
-
Thinking this through: why couldn't numbers 2 and 5 be together? For example:
|
Beta Was this translation helpful? Give feedback.
-
@pkoutoupis Eheheheheheheheehhe I can do it, if that's okay with you.! This time I did not went straight with the implementation, but I spent some time to realize the autocompletion script for the current shub@ubuserver:~$ source ./rapiddisk_autocomplete.sh If you have time, tell me what you think! :-) |
Beta Was this translation helpful? Give feedback.
-
#/usr/bin/env bash
# VERSION=0.0.1
# Copyright 2023 Matteo Tenca <[email protected]>
# License: GPL v2
_rapiddisk_completions()
{
local cur prev opts first second third fourth opt1 opt2
new_array=()
# Iterate over the original array
for item in "${COMP_WORDS[@]}"; do
if [[ "$item" != "-j" ]]; then
# Add the item to the new array if it's not "-j"
new_array+=("$item")
fi
done
first="${new_array[1]}"
opt1="${new_array[2]}"
second="${new_array[3]}"
opt2="${new_array[4]}"
third="${new_array[5]}"
opt3="${new_array[6]}"
fourth="${new_array[7]}"
opt4="${new_array[8]}"
# echo -e "\nfirst: '$first'\nsecond: '$second'\nthird: '$third'\nopt1: '$opt1'\nword being completed: '$2'\nprevious: '$prev'\nCOMP_CWORD: '$COMP_CWORD'\nCOMP_WORDS: '${COMP_WORDS[@]}'\ncur: '$cur'\n1: '$1'\n2: '$2'\n3: '$3'"
if [ $COMP_CWORD -eq 1 ] ; then
opts="-j -x -d -h -l -a -r -m -u -f -L -U -i -X -e -R -n -N"
else
case $3 in
-j)
if [ "${COMP_WORDS[1]}" = "-j" ] && [ $COMP_CWORD -eq 2 ] ; then
opts="-x -d -l -a -r -m -u -f -L -U -i -X -e -R -n -N"
fi
;;
-d|-r|-m|-f|-U|-L)
opts=`find /dev -maxdepth 1 -group disk |grep '/dev/rd' | grep -oP 'rd\d+'`
;;
-u)
opts=`ls /dev/mapper/rc-*| sed 's,/dev/mapper/,,g'`
;;
-R)
opts="-b"
;;
-i)
opts=`ip link|grep -oP '^\d+:\s+[^:]+'|grep -Pv '\slo$'|grep -oP '[^\s]+$'`" NULL"
;;
-b)
if [ "$first" = "-e" ] || [ "$first" = "-x" ] || [ "$first" = "-R" ] ; then
opts=`find /dev -maxdepth 1 -group disk |grep '/dev/rd' | grep -oP 'rd\d+'`
else
opts1=`find /dev -maxdepth 1 -group disk`
opts=${opts1}' '`ls /dev/mapper/rc-*`
fi
;;
-p)
opts="wt wa wb"
;;
-t)
if [ "$opt1" != "NULL" ] ; then
opts="tcp rdma"
else
opts="loop"
fi
;;
-X)
opts="-P"
;;
-e|-x)
opts="-b -P -H"
;;
-c)
;;
*)
if [ -n "$first" ] ; then
case $first in
-r)
opts="-c"
;;
-m)
if [ -z "$third" ] || [ "$third" = "-" ] ; then
case $second in
-b)
if [ "$2" = "-b" ] ; then opts="-b" ; else opts="-p" ; fi
;;
-p)
if [ "$2" = "-p" ] ; then opts="-p" ; else opts="-b" ; fi
;;
*)
opts="-b -p"
;;
esac
fi
;;
-i)
if [ -z "$third" ] || [ "$third" = "-" ] ; then
case $second in
-P)
if [ "$2" = "-P" ] ; then opts="-P" ; elif [ -n "$opt2" ] ; then opts="-t" ; fi
;;
-t)
if [ "$2" = "-t" ] ; then opts="-t" ; else opts="-P" ; fi
;;
*)
opts="-P -t"
;;
esac
fi
;;
-e|-x)
if [ -z "$opt2" ] || [ "$opt2" = "-" ] ; then
case $opt1 in
-P)
if [ "$2" = "-P" ] ; then opts="-P" ; elif [ -n "$second" ] ; then opts="-H -b" ; fi
;;
-H)
if [ "$2" = "-H" ] ; then opts="-H" ; elif [ -n "$second" ] ; then opts="-P -b" ; fi
;;
-b)
if [ "$2" = "-b" ] ; then opts="-b" ; elif [ -n "$second" ] ; then opts="-P -H " ; fi
;;
*)
;;
esac
fi
if [ -z "$opt3" ] || [ "$opt3" = "-" ] ; then
case $opt2 in
-P)
if [ "$2" = "-P" ] ; then opts="-P" ; elif [ -n "$third" ] ; then if [ "$opt1" = "-H" ] ; then opts="-b" ; else opts="-H"; fi ; fi
;;
-H)
if [ "$2" = "-H" ] ; then opts="-H" ; elif [ -n "$third" ] ; then if [ "$opt1" = "-P" ] ; then opts="-b" ; else opts="-P"; fi ; fi
;;
-b)
if [ "$2" = "-b" ] ; then opts="-b" ; elif [ -n "$third" ] ; then if [ "$opt1" = "-H" ] ; then opts="-P" ; else opts="-H"; fi ; fi
;;
*)
;;
esac
fi
;;
*)
;;
esac
fi
;;
esac
fi
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
COMPREPLY=( $(compgen -W "$opts" -- ${cur}) )
return 0
}
complete -F _rapiddisk_completions rapiddisk
|
Beta Was this translation helpful? Give feedback.
-
@pkoutoupis Here is a very first implementation: |
Beta Was this translation helpful? Give feedback.
-
@pkoutoupis I was out of town for a month now, I'll be back this weekend and I will manage to get the job done ASAP. Sorry for the long delay! |
Beta Was this translation helpful? Give feedback.
-
Hi @pkoutoupis !
I was thinking of a new set of switch to handle the creation/deletion of ports, allowed hosts and NQN, and to link them to each other independently.
A switch to create/remove a port, which require to specify the ip OR the network interface AND the port number AND the protocol on creation, just the port on deletion (since a port can be mapped to an IP only, if I am right).
Examples (switch names are casual):
$ rapiddisk -i -P port_number -i interface|ip_address -t tcp|rdma|loop
$ rapiddisk -X -P port_number
A switch to add/remove allowed hostname/s globally
$ rapiddisk -y -H hostname[,hostname,..]
$ rapiddisk -Y -H hostname[,hostname,..]
A switch to add/remove a NQN without linking it to any port/allowed host/s
$ rapiddisk -e -b ramdisk_name
$ rapiddisk -x -b ramdisk_name
A switch to link/unlink an existing port to an existing NQN:
$ rapiddisk -z -P port[,port,..] -b ramdisk_name
$ rapiddisk -Z -P port[,port,..] -b ramdisk_name
A switch to link/unlink an existing allowed host/s to an existing NQN
$ rapiddisk -w -H hostname[,hostname,..] -b ramdisk_name
$ rapiddisk -W -H hostname[,hostname,..] -b ramdisk_name
We can decide what to do when the user tries to remove an NQN/port/hosts with linked NQN/ports/hosts (for example we can add a force switch which will unlink a NQN from all the used resources and then remove the NQN itself, or just return some information about the current configuration).
Tell me your thoughts
Cheers!!
Teo
Beta Was this translation helpful? Give feedback.
All reactions