From: Daniel Wagner <dwagner@suse.de>
To: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Cc: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org,
Daniel Wagner <dwagner@suse.de>
Subject: [PATCH blktests v2 2/9] contrib/nvme-target-control: pick a free service ID for new nvmet ports
Date: Wed, 18 Nov 2026 10:26:40 +0100 [thread overview]
Message-ID: <20261118-nvme-target-control-v2-2-d191bbbf5dd6@suse.de> (raw)
In-Reply-To: <20261118-nvme-target-control-v2-0-d191bbbf5dd6@suse.de>
The nvmet target derives the service ID from the port ID. On a target
that already has ports this clashes with existing ports, and nvme/003
connects to a service ID nothing listens on. Use the lowest free
service ID starting at trsvid instead.
Fixes: 79c32fb31b7b ("contrib: make nvme-target-control a standalone project")
Signed-off-by: Daniel Wagner <dwagner@suse.de>
---
contrib/nvme-target-control/README.md | 13 +++++++------
.../nvme_target_control/targets/nvmet.sh | 7 ++++++-
2 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/contrib/nvme-target-control/README.md b/contrib/nvme-target-control/README.md
index dc421b00b788..9abd7f30932d 100644
--- a/contrib/nvme-target-control/README.md
+++ b/contrib/nvme-target-control/README.md
@@ -61,12 +61,13 @@ is set, the namespace is a loop device on an image file in
subsystem, the ports which don't export another subsystem, the hosts no
other subsystem allows, and the loop device and image file.
-A new port gets the lowest free nvmet port ID N, starting at 1, and listens
-on `traddr` at service ID `trsvid` + N - 1. The first port of a target
-without other ports listens on `trsvid`. The nvmet target implements all
-port commands: `add-ports`, `add-port`, `remove-port`, `list-ports`,
-`show-port` and `set-ana`, and `set-host`, which changes the DH-CHAP keys,
-hash and DH group of the host.
+A new port gets the lowest free nvmet port ID, starting at 1, and the
+lowest service ID from `trsvid` up which no other port uses: the first
+port listens on `traddr` at `trsvid` unless another port of the target
+does. The nvmet target implements all port commands: `add-ports`,
+`add-port`, `remove-port`, `list-ports`, `show-port` and `set-ana`, and
+`set-host`, which changes the DH-CHAP keys, hash and DH group of the
+host.
| Option | Meaning |
| --- | --- |
diff --git a/contrib/nvme-target-control/nvme_target_control/targets/nvmet.sh b/contrib/nvme-target-control/nvme_target_control/targets/nvmet.sh
index 33f383eb17f0..7d6e9cd40da0 100644
--- a/contrib/nvme-target-control/nvme_target_control/targets/nvmet.sh
+++ b/contrib/nvme-target-control/nvme_target_control/targets/nvmet.sh
@@ -59,6 +59,11 @@ add_port() {
while [ -e "${cfs}/ports/${port}" ]; do
port=$((port + 1))
done
+ # The target may have other ports, take the first free service ID.
+ while cat "${cfs}"/ports/*/addr_trsvcid 2> /dev/null |
+ grep -qx "${trsvcid}"; do
+ trsvcid=$((trsvcid + 1))
+ done
case "${traddr}" in
*:*) adrfam=ipv6 ;;
*) adrfam=ipv4 ;;
@@ -68,7 +73,7 @@ add_port() {
echo "${trtype}" > "${cfs}/ports/${port}/addr_trtype"
echo "${adrfam}" > "${cfs}/ports/${port}/addr_adrfam"
echo "${traddr}" > "${cfs}/ports/${port}/addr_traddr"
- echo $((trsvcid + port - 1)) > "${cfs}/ports/${port}/addr_trsvcid"
+ echo "${trsvcid}" > "${cfs}/ports/${port}/addr_trsvcid"
case "${tls}" in
none)
;;
--
2.56.1
next prev parent reply other threads:[~2026-11-18 9:26 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 9:26 [PATCH blktests v2 0/9] nvme: make NVME_TARGET_CONTROL work with remote targets Daniel Wagner
2026-11-18 9:26 ` [PATCH blktests v2 1/9] nvme/047: look up the namespace again after reconnecting Daniel Wagner
2026-11-20 11:23 ` Hannes Reinecke
2026-11-18 9:26 ` Daniel Wagner [this message]
2026-11-18 9:26 ` [PATCH blktests v2 3/9] nvme/042, nvme/043: iterate over the DH-HMAC-CHAP hashes by name Daniel Wagner
2026-11-28 2:31 ` Shin'ichiro Kawasaki
2026-11-18 9:26 ` [PATCH blktests v2 4/9] nvme: skip tests that need a feature the remote target lacks Daniel Wagner
2026-11-18 9:26 ` [PATCH blktests v2 5/9] contrib/nvme-target-control: list the DH-HMAC-CHAP algorithms Daniel Wagner
2026-11-18 9:26 ` [PATCH blktests v2 6/9] nvme: skip the DH-HMAC-CHAP algorithms the target doesn't support Daniel Wagner
2026-11-28 2:30 ` Shin'ichiro Kawasaki
2026-11-18 9:26 ` [PATCH blktests v2 7/9] common/nvme: support the ports of a remote target Daniel Wagner
2026-11-18 9:26 ` [PATCH blktests v2 8/9] nvme/rc: change the host keys on " Daniel Wagner
2026-11-18 9:26 ` [PATCH blktests v2 9/9] contrib/nvme-target-control: add a NetApp ONTAP target Daniel Wagner
2026-11-20 11:25 ` [PATCH blktests v2 0/9] nvme: make NVME_TARGET_CONTROL work with remote targets Hannes Reinecke
2026-11-28 2:34 ` Shin'ichiro Kawasaki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261118-nvme-target-control-v2-2-d191bbbf5dd6@suse.de \
--to=dwagner@suse.de \
--cc=linux-block@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=shinichiro.kawasaki@wdc.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox