Skip to content

Commit

Permalink
fix(nvmf): nvme list-subsys prints the address using commas as separator
Browse files Browse the repository at this point in the history
nvme-cli 1.x printed the address using spaces as separator, but nvme-cli 2.x
prints the address using commas as separator (exact output from sysfs). E.g.,
output from `cat /sys/class/nvme/nvme0/address`:

traddr=nn-0x201700a09890f5bf:pn-0x201900a09890f5bf,host_traddr=nn-0x200000109b579ef5:pn-0x100000109b579ef5

Also, I suppress rd.nvmf.discover= cmdline option if all fields are empty.
  • Loading branch information
aafeijoo-suse authored and johannbg committed Sep 30, 2022
1 parent b171284 commit 9664e98
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions modules.d/95nvmf/module-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ cmdline() {
gen_nvmf_cmdline() {
local _dev=$1
local trtype
local traddr
local host_traddr
local trsvcid
local _address
local -a _address_parts

[[ -L "/sys/dev/block/$_dev" ]] || return 0
cd -P "/sys/dev/block/$_dev" || return 0
Expand All @@ -76,9 +81,19 @@ cmdline() {
done

[ -z "$trtype" ] && return 0
nvme list-subsys "${PWD##*/}" | while read -r _ _ trtype traddr host_traddr _; do
[ "$trtype" != "${trtype#NQN}" ] && continue
echo -n " rd.nvmf.discover=$trtype,${traddr#traddr=},${host_traddr#host_traddr=}"
nvme list-subsys "${PWD##*/}" | while read -r _ _ trtype _address _; do
[[ -z $trtype || $trtype != "${trtype#NQN}" ]] && continue
unset traddr
unset host_traddr
unset trsvcid
mapfile -t -d ',' _address_parts < <(printf "%s" "$_address")
for i in "${_address_parts[@]}"; do
[[ $i =~ ^traddr= ]] && traddr="${i#traddr=}"
[[ $i =~ ^host_traddr= ]] && host_traddr="${i#host_traddr=}"
[[ $i =~ ^trsvcid= ]] && trsvcid="${i#trsvcid=}"
done
[[ -z $traddr && -z $host_traddr && -z $trsvcid ]] && continue
echo -n " rd.nvmf.discover=$trtype,$traddr,$host_traddr,$trsvcid"
done
}

Expand Down

0 comments on commit 9664e98

Please sign in to comment.