From b0a80710ec70e07ce805433f79450b5e3a3920de Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Tue, 29 Aug 2017 13:02:50 -0700 Subject: [PATCH] nvmf: don't generate cntlids in reserved range The NVMe-oF 1.0 spec says: "The NVM subsystem shall not allocate a Controller ID in the range FFF0h to FFFFh as a valid Controller ID" Change-Id: If0b7dc4948e40b3bdf370a1da97199a25d362e71 Signed-off-by: Daniel Verkamp Reviewed-on: https://review.gerrithub.io/376247 Tested-by: SPDK Automated Test System Reviewed-by: Ziye Yang --- lib/nvmf/nvmf.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/nvmf/nvmf.c b/lib/nvmf/nvmf.c index d32fe4be0..8d446f4d2 100644 --- a/lib/nvmf/nvmf.c +++ b/lib/nvmf/nvmf.c @@ -171,18 +171,16 @@ spdk_nvmf_tgt_gen_cntlid(struct spdk_nvmf_tgt *tgt) struct spdk_nvmf_ctrlr *ctrlr; uint16_t count; - count = UINT16_MAX - 1; + /* + * In the worst case, we might have to try all CNTLID values between 1 and 0xFFF0 - 1 + * before we find one that is unused (or find that all values are in use). + */ + count = 0xFFF0 - 1; do { - /* cntlid is an unsigned 16-bit integer, so let it overflow - * back to 0 if necessary. - */ tgt->next_cntlid++; - if (tgt->next_cntlid == 0) { - /* 0 is not a valid cntlid because it is the reserved value in the RDMA - * private data for cntlid. This is the value sent by pre-NVMe-oF 1.1 - * initiators. - */ - tgt->next_cntlid++; + if (tgt->next_cntlid >= 0xFFF0) { + /* The spec reserves cntlid values in the range FFF0h to FFFFh. */ + tgt->next_cntlid = 1; } /* Check if a subsystem with this cntlid currently exists. This could