nvmf_tgt: use public API to set serial number

Also move the validation of serial number length into the library.

Change-Id: Ibc9384fc1fccb87bd15b75da7f3942570900bd96
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/363304
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Daniel Verkamp 2017-05-31 16:46:17 -07:00 committed by Ben Walker
parent 7999c01b76
commit bbfcb0943b
2 changed files with 14 additions and 19 deletions

View File

@ -291,20 +291,6 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid,
ctx->found = true; ctx->found = true;
} }
static int
spdk_nvmf_validate_sn(const char *sn)
{
size_t len;
len = strlen(sn);
if (len > MAX_SN_LEN) {
SPDK_ERRLOG("Invalid sn \"%s\": length %zu > max %d\n", sn, len, MAX_SN_LEN);
return -1;
}
return 0;
}
static int static int
spdk_nvmf_allocate_lcore(uint64_t mask, uint32_t lcore) spdk_nvmf_allocate_lcore(uint64_t mask, uint32_t lcore)
{ {
@ -590,16 +576,15 @@ spdk_nvmf_construct_subsystem(const char *name,
SPDK_ERRLOG("Subsystem %s: missing serial number\n", name); SPDK_ERRLOG("Subsystem %s: missing serial number\n", name);
goto error; goto error;
} }
if (spdk_nvmf_validate_sn(sn) != 0) {
goto error;
}
if (num_devs > MAX_VIRTUAL_NAMESPACE) { if (num_devs > MAX_VIRTUAL_NAMESPACE) {
goto error; goto error;
} }
subsystem->dev.virt.ns_count = 0; if (spdk_nvmf_subsystem_set_sn(subsystem, sn)) {
snprintf(subsystem->dev.virt.sn, MAX_SN_LEN, "%s", sn); SPDK_ERRLOG("Subsystem %s: invalid serial number '%s'\n", name, sn);
goto error;
}
for (i = 0; i < num_devs; i++) { for (i = 0; i < num_devs; i++) {
namespace = dev_list[i]; namespace = dev_list[i];

View File

@ -412,10 +412,20 @@ spdk_nvmf_subsystem_add_ns(struct spdk_nvmf_subsystem *subsystem, struct spdk_bd
int int
spdk_nvmf_subsystem_set_sn(struct spdk_nvmf_subsystem *subsystem, const char *sn) spdk_nvmf_subsystem_set_sn(struct spdk_nvmf_subsystem *subsystem, const char *sn)
{ {
size_t len, max_len;
if (subsystem->mode != NVMF_SUBSYSTEM_MODE_VIRTUAL) { if (subsystem->mode != NVMF_SUBSYSTEM_MODE_VIRTUAL) {
return -1; return -1;
} }
max_len = sizeof(subsystem->dev.virt.sn) - 1;
len = strlen(sn);
if (len > max_len) {
SPDK_TRACELOG(SPDK_TRACE_NVMF, "Invalid sn \"%s\": length %zu > max %zu\n",
sn, len, max_len);
return -1;
}
snprintf(subsystem->dev.virt.sn, sizeof(subsystem->dev.virt.sn), "%s", sn); snprintf(subsystem->dev.virt.sn, sizeof(subsystem->dev.virt.sn), "%s", sn);
return 0; return 0;