From bba1ab1bb8a5391ffe64dc58b17827000e2e0293 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Tue, 31 Mar 2026 17:58:44 +0200 Subject: [PATCH] fabrics: use uuid from hostnqn for hostid In the case the configuration only provides an hostnqn which is using the second valid format, extract the uuid from it and set the hostid explicitly. Extract hostid from the hostnqn when at the place we set the values instead at build_option time, where the context is lost. Signed-off-by: Daniel Wagner --- libnvme/src/nvme/fabrics.c | 16 ++++++++++++++++ libnvme/src/nvme/tree.c | 2 ++ 2 files changed, 18 insertions(+) diff --git a/libnvme/src/nvme/fabrics.c b/libnvme/src/nvme/fabrics.c index 9189808665..a856f6a18f 100644 --- a/libnvme/src/nvme/fabrics.c +++ b/libnvme/src/nvme/fabrics.c @@ -274,10 +274,26 @@ __public int nvmf_context_set_connection(struct nvmf_context *fctx, return 0; } +static const char *hostid_from_hostnqn(const char *hostnqn) +{ + const char *match; + + if (!hostnqn) + return NULL; + + match = strstr(hostnqn, "uuid:"); + if (!match) + return NULL; + + return match + strlen("uuid:"); +} + __public int nvmf_context_set_hostnqn(struct nvmf_context *fctx, const char *hostnqn, const char *hostid) { fctx->hostnqn = hostnqn; + if (!hostid) + hostid = hostid_from_hostnqn(hostnqn); fctx->hostid = hostid; return 0; diff --git a/libnvme/src/nvme/tree.c b/libnvme/src/nvme/tree.c index 1cae0bd8ac..377f6e8ead 100644 --- a/libnvme/src/nvme/tree.c +++ b/libnvme/src/nvme/tree.c @@ -631,6 +631,8 @@ static int nvme_create_host(struct nvme_global_ctx *ctx, const char *hostnqn, return -ENOMEM; h->hostnqn = strdup(hostnqn); + if (!hostid) + hostid = nvme_hostid_from_hostnqn(hostnqn); if (hostid) h->hostid = strdup(hostid); list_head_init(&h->subsystems);