From c03c788e6788d38e198e1231b24c99e94a0a0b52 Mon Sep 17 00:00:00 2001 From: Omar Sandoval Date: Wed, 25 Apr 2018 15:15:43 -0700 Subject: [PATCH] nvme: fix _create_nvmet_port 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 --- common/nvme | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/common/nvme b/common/nvme index 73bbfe9..c6718f0 100644 --- a/common/nvme +++ b/common/nvme @@ -29,7 +29,12 @@ _create_nvmet_port() { 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" -- 2.51.0