bhyve supports setting NVMe controller serial number using
the "ser=<SN>" option. Update bhyveBuildNVMeControllerArgStr()
to set that if "serial" is specified for the controller.

We do it in the controller's disks loop, but as we prohibit more than 1
disk per controller in bhyveDomainDefValidate(), there is no
repetition here.

Signed-off-by: Roman Bogorodskiy <[email protected]>
---
 src/bhyve/bhyve_command.c                     |  2 ++
 ...hyvexml2argv-nvme-explicit-controller.args |  9 ++++++
 ...vexml2argv-nvme-explicit-controller.ldargs |  4 +++
 ...bhyvexml2argv-nvme-explicit-controller.xml | 20 +++++++++++++
 tests/bhyvexml2argvtest.c                     |  1 +
 ...yvexml2xmlout-nvme-explicit-controller.xml | 28 +++++++++++++++++++
 tests/bhyvexml2xmltest.c                      |  1 +
 7 files changed, 65 insertions(+)
 create mode 100644 
tests/bhyvexml2argvdata/x86_64/bhyvexml2argv-nvme-explicit-controller.args
 create mode 100644 
tests/bhyvexml2argvdata/x86_64/bhyvexml2argv-nvme-explicit-controller.ldargs
 create mode 100644 
tests/bhyvexml2argvdata/x86_64/bhyvexml2argv-nvme-explicit-controller.xml
 create mode 100644 
tests/bhyvexml2xmloutdata/x86_64/bhyvexml2xmlout-nvme-explicit-controller.xml

diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c
index f0c3cf03c5..956fcab06c 100644
--- a/src/bhyve/bhyve_command.c
+++ b/src/bhyve/bhyve_command.c
@@ -479,6 +479,8 @@ bhyveBuildNVMeControllerArgStr(const virDomainDef *def,
             virBufferAsprintf(&opt, ",maxq=%d", disk->queues);
         if (disk->queue_size)
             virBufferAsprintf(&opt, ",qsz=%d", disk->queue_size);
+        if (controller->opts.nvmeopts.serial)
+            virBufferAsprintf(&opt, ",ser=%s", 
controller->opts.nvmeopts.serial);
 
         nvme_opts = virBufferContentAndReset(&opt);
 
diff --git 
a/tests/bhyvexml2argvdata/x86_64/bhyvexml2argv-nvme-explicit-controller.args 
b/tests/bhyvexml2argvdata/x86_64/bhyvexml2argv-nvme-explicit-controller.args
new file mode 100644
index 0000000000..74dd4baa37
--- /dev/null
+++ b/tests/bhyvexml2argvdata/x86_64/bhyvexml2argv-nvme-explicit-controller.args
@@ -0,0 +1,9 @@
+bhyve \
+-c 1 \
+-m 214 \
+-u \
+-H \
+-P \
+-s 0:0,hostbridge \
+-s 2:0,nvme,/tmp/freebsd.img,maxq=2,qsz=256,ser=BHYVE-NVME0-01234 \
+bhyve
diff --git 
a/tests/bhyvexml2argvdata/x86_64/bhyvexml2argv-nvme-explicit-controller.ldargs 
b/tests/bhyvexml2argvdata/x86_64/bhyvexml2argv-nvme-explicit-controller.ldargs
new file mode 100644
index 0000000000..5905f4b3e6
--- /dev/null
+++ 
b/tests/bhyvexml2argvdata/x86_64/bhyvexml2argv-nvme-explicit-controller.ldargs
@@ -0,0 +1,4 @@
+bhyveload \
+-m 214 \
+-d /tmp/freebsd.img \
+bhyve
diff --git 
a/tests/bhyvexml2argvdata/x86_64/bhyvexml2argv-nvme-explicit-controller.xml 
b/tests/bhyvexml2argvdata/x86_64/bhyvexml2argv-nvme-explicit-controller.xml
new file mode 100644
index 0000000000..9781d3aaef
--- /dev/null
+++ b/tests/bhyvexml2argvdata/x86_64/bhyvexml2argv-nvme-explicit-controller.xml
@@ -0,0 +1,20 @@
+<domain type='bhyve'>
+  <name>bhyve</name>
+  <uuid>df3be7e7-a104-11e3-aeb0-50e5492bd3dc</uuid>
+  <memory>219136</memory>
+  <vcpu>1</vcpu>
+  <os>
+    <type>hvm</type>
+  </os>
+  <devices>
+    <controller type='nvme' index='0'>
+      <serial>BHYVE-NVME0-01234</serial>
+    </controller>
+    <disk type='file'>
+      <driver name='file' type='raw' queues='2' queue_size='256'/>
+      <source file='/tmp/freebsd.img'/>
+      <target dev='nvme0n1' bus='nvme'/>
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+    </disk>
+  </devices>
+</domain>
diff --git a/tests/bhyvexml2argvtest.c b/tests/bhyvexml2argvtest.c
index 71322d1330..436eecb003 100644
--- a/tests/bhyvexml2argvtest.c
+++ b/tests/bhyvexml2argvtest.c
@@ -280,6 +280,7 @@ mymain(void)
     DO_TEST_FAILURE("serial-invalid-port");
     DO_TEST("nvme");
     DO_TEST("2-nvme-2-controllers");
+    DO_TEST("nvme-explicit-controller");
     DO_TEST_FAILURE("2-nvme-same-controller");
     DO_TEST("sata-rotation-rate");
     DO_TEST_FAILURE("disk-virtio-rotation-rate");
diff --git 
a/tests/bhyvexml2xmloutdata/x86_64/bhyvexml2xmlout-nvme-explicit-controller.xml 
b/tests/bhyvexml2xmloutdata/x86_64/bhyvexml2xmlout-nvme-explicit-controller.xml
new file mode 100644
index 0000000000..f646267ec5
--- /dev/null
+++ 
b/tests/bhyvexml2xmloutdata/x86_64/bhyvexml2xmlout-nvme-explicit-controller.xml
@@ -0,0 +1,28 @@
+<domain type='bhyve'>
+  <name>bhyve</name>
+  <uuid>df3be7e7-a104-11e3-aeb0-50e5492bd3dc</uuid>
+  <memory unit='KiB'>219136</memory>
+  <currentMemory unit='KiB'>219136</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='x86_64'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <disk type='file' device='disk'>
+      <driver name='file' type='raw' queues='2' queue_size='256'/>
+      <source file='/tmp/freebsd.img'/>
+      <target dev='nvme0n1' bus='nvme'/>
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+    </disk>
+    <controller type='nvme' index='0'>
+      <serial>BHYVE-NVME0-01234</serial>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' 
function='0x0'/>
+    </controller>
+    <controller type='pci' index='0' model='pci-root'/>
+  </devices>
+</domain>
diff --git a/tests/bhyvexml2xmltest.c b/tests/bhyvexml2xmltest.c
index 120bdd42e5..51ce2adb33 100644
--- a/tests/bhyvexml2xmltest.c
+++ b/tests/bhyvexml2xmltest.c
@@ -129,6 +129,7 @@ mymain(void)
     DO_TEST_DIFFERENT("4-consoles");
     DO_TEST_DIFFERENT("nvme");
     DO_TEST_DIFFERENT("2-nvme-2-controllers");
+    DO_TEST_DIFFERENT("nvme-explicit-controller");
     DO_TEST_DIFFERENT("passthru-multiple-devs");
     DO_TEST_DIFFERENT("slirp");
     DO_TEST_DIFFERENT("virtio-scsi");
-- 
2.52.0

Reply via email to