From db521e7d03e5e97a743a1c35decb50dd50e3e8db Mon Sep 17 00:00:00 2001
From: Luyao Zhong
Date: Thu, 20 Dec 2018 17:14:42 +0800
Subject: [PATCH] conf: Introduce 'readonly' element into xml for NVDIMM memory
The 'readonly' option allows users to mark vNVDIMM read-only:
...
/dev/dax0.0
4094
0
2
...
Signed-off-by: Luyao Zhong
Reviewed-by: John Ferlan
---
docs/formatdomain.html.in | 45 ++++++++++----
docs/schemas/domaincommon.rng | 5 ++
src/conf/domain_conf.c | 12 ++++
src/conf/domain_conf.h | 1 +
.../memory-hotplug-nvdimm-readonly.xml | 58 +++++++++++++++++++
.../memory-hotplug-nvdimm-readonly.xml | 1 +
tests/qemuxml2xmltest.c | 1 +
7 files changed, 111 insertions(+), 12 deletions(-)
create mode 100644 tests/qemuxml2argvdata/memory-hotplug-nvdimm-readonly.xml
create mode 120000 tests/qemuxml2xmloutdata/memory-hotplug-nvdimm-readonly.xml
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 0b1b478b2a..7f07bb7f55 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -8330,6 +8330,7 @@ qemu-kvm -net nic,model=? /dev/null
<label>
<size unit='KiB'>128</size>
</label>
+ <readonly/>
</target>
</memory>
<memory model='nvdimm'>
@@ -8465,19 +8466,39 @@ qemu-kvm -net nic,model=? /dev/null
NUMA nodes configured.
- For NVDIMM type devices one can optionally use
- label
and its subelement size
- to configure the size of namespaces label storage
- within the NVDIMM module. The size
element
- has usual meaning described
- here .
- For QEMU domains the following restrictions apply:
+ The following optional elements may be used:
-
- the minimum label size is 128KiB,
- the remaining size (total-size - label-size) has to be aligned to
- 4KiB
-
+
+
+ label
+
+
+ For NVDIMM type devices one can optionally use
+ label
and its subelement size
+ to configure the size of namespaces label storage
+ within the NVDIMM module. The size
element
+ has usual meaning described
+ here .
+ For QEMU domains the following restrictions apply:
+
+
+ the minimum label size is 128KiB,
+ the remaining size (total-size - label-size) will be aligned
+ to 4KiB as default.
+
+
+
+ readonly
+
+
+ The readonly
element is used to mark the vNVDIMM
+ as read-only. Only the real NVDIMM device backend can guarantee
+ the guest write persistence, so other backend types should use
+ the readonly
element.
+ Since 5.0.0
+
+
+
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index a7b7164ad1..6518aff73a 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -5422,6 +5422,11 @@
+
+
+
+
+
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 9edaf6d493..222bb8c482 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -15844,6 +15844,9 @@ virDomainMemoryTargetDefParseXML(xmlNodePtr node,
_("label size must be smaller than NVDIMM size"));
goto cleanup;
}
+
+ if (virXPathBoolean("boolean(./readonly)", ctxt))
+ def->readonly = true;
}
ret = 0;
@@ -22766,6 +22769,13 @@ virDomainMemoryDefCheckABIStability(virDomainMemoryDefPtr src,
"source NVDIMM pmem flag"));
return false;
}
+
+ if (src->readonly != dst->readonly) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("Target NVDIMM readonly flag doesn't match "
+ "source NVDIMM readonly flag"));
+ return false;
+ }
}
return virDomainDeviceInfoCheckABIStability(&src->info, &dst->info);
@@ -26344,6 +26354,8 @@ virDomainMemoryTargetDefFormat(virBufferPtr buf,
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "\n");
}
+ if (def->readonly)
+ virBufferAddLit(buf, " \n");
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "\n");
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index a63afdca12..fae130668f 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2155,6 +2155,7 @@ struct _virDomainMemoryDef {
int targetNode;
unsigned long long size; /* kibibytes */
unsigned long long labelsize; /* kibibytes; valid only for NVDIMM */
+ bool readonly; /* valid only for NVDIMM */
virDomainDeviceInfo info;
};
diff --git a/tests/qemuxml2argvdata/memory-hotplug-nvdimm-readonly.xml b/tests/qemuxml2argvdata/memory-hotplug-nvdimm-readonly.xml
new file mode 100644
index 0000000000..170992c9fc
--- /dev/null
+++ b/tests/qemuxml2argvdata/memory-hotplug-nvdimm-readonly.xml
@@ -0,0 +1,58 @@
+
+ QEMUGuest1
+ c7a5fdbd-edaf-9455-926a-d65c16db1809
+ 1099511627776
+ 1267710
+ 1267710
+ 2
+
+ hvm
+
+
+
+
+
+
+
+
+
+ |
+
+
+
+ destroy
+ restart
+ destroy
+
+ /usr/bin/qemu-system-i686
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ /tmp/nvdimm
+
+
+ 523264
+ 0
+
+
+
+
+
+
diff --git a/tests/qemuxml2xmloutdata/memory-hotplug-nvdimm-readonly.xml b/tests/qemuxml2xmloutdata/memory-hotplug-nvdimm-readonly.xml
new file mode 120000
index 0000000000..10be8447a8
--- /dev/null
+++ b/tests/qemuxml2xmloutdata/memory-hotplug-nvdimm-readonly.xml
@@ -0,0 +1 @@
+../qemuxml2argvdata/memory-hotplug-nvdimm-readonly.xml
\ No newline at end of file
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index ef3ece8902..82e2c0ee0f 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -1118,6 +1118,7 @@ mymain(void)
DO_TEST("memory-hotplug-nvdimm-label", NONE);
DO_TEST("memory-hotplug-nvdimm-align", NONE);
DO_TEST("memory-hotplug-nvdimm-pmem", NONE);
+ DO_TEST("memory-hotplug-nvdimm-readonly", NONE);
DO_TEST("net-udp", NONE);
DO_TEST("video-virtio-gpu-device", NONE);
--
2.39.5