Skip to content

Commit 8036bf7

Browse files
committed
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 <[email protected]>
1 parent 99dd46f commit 8036bf7

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

libnvme/src/nvme/fabrics.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,28 @@ __public int nvmf_context_set_connection(struct nvmf_context *fctx,
274274
return 0;
275275
}
276276

277+
static const char *hostid_from_hostnqn(const char *hostnqn)
278+
{
279+
const char *match;
280+
281+
if (!hostnqn)
282+
return NULL;
283+
284+
match = strstr(hostnqn, "uuid:");
285+
if (!match)
286+
return NULL;
287+
288+
return match + strlen("uuid:");
289+
}
290+
277291
__public int nvmf_context_set_hostnqn(struct nvmf_context *fctx,
278292
const char *hostnqn, const char *hostid)
279293
{
280294
fctx->hostnqn = hostnqn;
281-
fctx->hostid = hostid;
295+
if (!hostid)
296+
fctx->hostid = hostid_from_hostnqn(hostnqn);
297+
else
298+
fctx->hostid = hostid;
282299

283300
return 0;
284301
}

libnvme/src/nvme/tree.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,9 @@ static int nvme_create_host(struct nvme_global_ctx *ctx, const char *hostnqn,
631631
return -ENOMEM;
632632

633633
h->hostnqn = strdup(hostnqn);
634-
if (hostid)
634+
if (!hostid)
635+
h->hostid = nvme_hostid_from_hostnqn(hostnqn);
636+
else
635637
h->hostid = strdup(hostid);
636638
list_head_init(&h->subsystems);
637639
list_node_init(&h->entry);

0 commit comments

Comments
 (0)