From: Klaus Jensen Date: Fri, 29 Apr 2022 08:33:32 +0000 (+0200) Subject: hw/nvme: enforce common serial per subsystem X-Git-Tag: qemu-xen-4.18.0-rc5~673^2~6 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=a859eb9f8f64e116671048a43a07d87bc6527a55;p=qemu-xen.git hw/nvme: enforce common serial per subsystem The Identify Controller Serial Number (SN) is the serial number for the NVM subsystem and must be the same across all controller in the NVM subsystem. Enforce this. Reviewed-by: Christoph Hellwig Reviewed-by: Keith Busch Signed-off-by: Klaus Jensen --- diff --git a/hw/nvme/nvme.h b/hw/nvme/nvme.h index 6773819325..e41771604f 100644 --- a/hw/nvme/nvme.h +++ b/hw/nvme/nvme.h @@ -48,6 +48,7 @@ typedef struct NvmeSubsystem { DeviceState parent_obj; NvmeBus bus; uint8_t subnqn[256]; + char *serial; NvmeCtrl *ctrls[NVME_MAX_CONTROLLERS]; NvmeNamespace *namespaces[NVME_MAX_NAMESPACES + 1]; diff --git a/hw/nvme/subsys.c b/hw/nvme/subsys.c index fb58d63950..691a90d209 100644 --- a/hw/nvme/subsys.c +++ b/hw/nvme/subsys.c @@ -27,6 +27,13 @@ int nvme_subsys_register_ctrl(NvmeCtrl *n, Error **errp) return -1; } + if (!subsys->serial) { + subsys->serial = g_strdup(n->params.serial); + } else if (strcmp(subsys->serial, n->params.serial)) { + error_setg(errp, "invalid controller serial"); + return -1; + } + subsys->ctrls[cntlid] = n; for (nsid = 1; nsid < ARRAY_SIZE(subsys->namespaces); nsid++) {