@samitouri / QOSamiQemu / commits / 51b4260c98

hw/nvme: add user controlled 'model' property

This enables overriding the built in default "QEMU NVMe Ctrl" string with a user specified string. The value can be at most 40 characters in length. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Signed-off-by: Klaus Jensen <k.jensen@samsung.com>

Daniel P. Berrangé committed Mar 6, 2026 at 16:57 UTC 51b4260c98e0f0389367ca5bc08ae9cadf8c2336
3 files changed +18 -2
docs/system/devices/nvme.rst
+5
@@ -60,6 +60,11 @@ parameters.
60 the SMART / Health information extended log become available in the
61 controller. We emulate version 5 of this log page.
62
63 +``model`` (default: ``QEMU NVMe Ctrl``)
64 + Override the default reported model, which can be used when needing
65 + to more closely impersonate a particular device type. The model name
66 + can be a maximum of 40 characters in length.
67 +
68 Additional Namespaces
69 ---------------------
70
hw/nvme/ctrl.c
+12 -2
@@ -43,7 +43,8 @@
43 * atomic.dn=<on|off[optional]>, \
44 * atomic.awun<N[optional]>, \
45 * atomic.awupf<N[optional]>, \
46 - * subsys=<subsys_id>
46 + * subsys=<subsys_id>, \
47 + * model=<model-str>
48 * -device nvme-ns,drive=<drive_id>,bus=<bus_name>,nsid=<nsid>,\
49 * zoned=<true|false[optional]>, \
50 * subsys=<subsys_id>,shared=<true|false[optional]>, \
@@ -8608,6 +8609,13 @@ static bool nvme_check_params(NvmeCtrl *n, Error **errp)
8609 return false;
8610 }
8611
8612 + if (params->model &&
8613 + strlen(params->model) > NVME_ID_CTRL_MN_MAX_LEN) {
8614 + error_setg(errp, "'model' parameter '%s' can be at most '%d' characters",
8615 + params->model, NVME_ID_CTRL_MN_MAX_LEN);
8616 + return false;
8617 + }
8618 +
8619 if (params->mqes < 1) {
8620 error_setg(errp, "mqes property cannot be less than 1");
8621 return false;
@@ -9101,7 +9109,8 @@ static void nvme_init_ctrl(NvmeCtrl *n, PCIDevice *pci_dev)
9109
9110 id->vid = cpu_to_le16(pci_get_word(pci_conf + PCI_VENDOR_ID));
9111 id->ssvid = cpu_to_le16(pci_get_word(pci_conf + PCI_SUBSYSTEM_VENDOR_ID));
9104 - strpadcpy((char *)id->mn, sizeof(id->mn), "QEMU NVMe Ctrl", ' ');
9112 + strpadcpy((char *)id->mn, sizeof(id->mn),
9113 + n->params.model ? n->params.model : "QEMU NVMe Ctrl", ' ');
9114 strpadcpy((char *)id->fr, sizeof(id->fr), QEMU_VERSION, ' ');
9115 strpadcpy((char *)id->sn, sizeof(id->sn), n->params.serial, ' ');
9116
@@ -9381,6 +9390,7 @@ static const Property nvme_props[] = {
9390 DEFINE_PROP_LINK("subsys", NvmeCtrl, subsys, TYPE_NVME_SUBSYS,
9391 NvmeSubsystem *),
9392 DEFINE_PROP_STRING("serial", NvmeCtrl, params.serial),
9393 + DEFINE_PROP_STRING("model", NvmeCtrl, params.model),
9394 DEFINE_PROP_UINT32("cmb_size_mb", NvmeCtrl, params.cmb_size_mb, 0),
9395 DEFINE_PROP_UINT32("num_queues", NvmeCtrl, params.num_queues, 0),
9396 DEFINE_PROP_UINT32("max_ioqpairs", NvmeCtrl, params.max_ioqpairs, 64),
hw/nvme/nvme.h
+1
@@ -542,6 +542,7 @@ typedef struct NvmeCQueue {
542
543 typedef struct NvmeParams {
544 char *serial;
545 + char *model;
546 uint32_t num_queues; /* deprecated since 5.1 */
547 uint32_t max_ioqpairs;
548 uint16_t msix_qsize;