]> www.infradead.org Git - users/sagi/blktests.git/commitdiff
nvme: fix _create_nvmet_port
authorOmar Sandoval <osandov@fb.com>
Wed, 25 Apr 2018 22:15:43 +0000 (15:15 -0700)
committerOmar Sandoval <osandov@fb.com>
Wed, 25 Apr 2018 22:15:43 +0000 (15:15 -0700)
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>
common/nvme

index 73bbfe9626435e171df721a7ac5486ab99d99eef..c6718f04811b5becb6400c0f31f529e25b39ffa1 100644 (file)
@@ -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"