From: Omar Sandoval Date: Wed, 25 Apr 2018 22:15:43 +0000 (-0700) Subject: nvme: fix _create_nvmet_port X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=c03c788e6788d38e198e1231b24c99e94a0a0b52;p=users%2Fsagi%2Fblktests.git 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 --- 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"