First of all, we get a shellcheck warning:
common/nvme:32:18: note: Use find instead of ls to better handle
non-alphanumeric filenames. [SC2012]
Secondly, it's not _technically_ correct to just count the number of
ports, since there could be just one port numbered 1. Instead, find the
first free port.
Signed-off-by: Omar Sandoval <osandov@fb.com>
local trtype="$1"
local nvmet_cfs="/sys/kernel/config/nvmet/"
- local port=$(($(ls "${nvmet_cfs}/ports" | wc -l) + 1))
+ local port
+ for ((port = 0; ; port++)); do
+ if [[ ! -e "${nvmet_cfs}/${port}" ]]; then
+ break
+ fi
+ done
mkdir "${nvmet_cfs}/ports/${port}"
echo "${trtype}" > "${nvmet_cfs}/ports/${port}/addr_trtype"