]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: Require nvdimm path in validate step
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 4 Nov 2020 15:09:39 +0000 (16:09 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 4 Dec 2020 15:24:19 +0000 (16:24 +0100)
Our code expects that a nvdimm has a path defined always. And the
parser does check for that. Well, not fully - only when parsing
<source/> (which is an optional element). So if the element is
not in the XML then the check is not performed and the assumption
is broken. Verify in the memory def validator that a path was
set.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Tested-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Tested-by: Han Han <hhan@redhat.com>
src/conf/domain_conf.c
src/security/security_apparmor.c

index d8df18b54294026bce0efac4640e9e4ce5b3aea9..da14760e2df4726ebf75a2ee213ea7d88c38efd4 100644 (file)
@@ -6694,6 +6694,12 @@ virDomainMemoryDefValidate(const virDomainMemoryDef *mem,
                            const virDomainDef *def)
 {
     if (mem->model == VIR_DOMAIN_MEMORY_MODEL_NVDIMM) {
+        if (!mem->nvdimmPath) {
+            virReportError(VIR_ERR_XML_DETAIL, "%s",
+                           _("path is required for model 'nvdimm'"));
+            return -1;
+        }
+
         if (mem->discard == VIR_TRISTATE_BOOL_YES) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                            _("discard is not supported for nvdimms"));
@@ -16690,11 +16696,7 @@ virDomainMemorySourceDefParseXML(xmlNodePtr node,
         break;
 
     case VIR_DOMAIN_MEMORY_MODEL_NVDIMM:
-        if (!(def->nvdimmPath = virXPathString("string(./path)", ctxt))) {
-            virReportError(VIR_ERR_XML_DETAIL, "%s",
-                           _("path is required for model 'nvdimm'"));
-            return -1;
-        }
+        def->nvdimmPath = virXPathString("string(./path)", ctxt);
 
         if (virDomainParseMemory("./alignsize", "./alignsize/@unit", ctxt,
                                  &def->alignsize, false, false) < 0)
index c2d86c6940fdc64c54de165ccc24d21c16d0e17d..f306af8dd31f5b1fab21971f7f08983ed7b19ca1 100644 (file)
@@ -686,12 +686,6 @@ AppArmorSetMemoryLabel(virSecurityManagerPtr mgr,
 
     switch ((virDomainMemoryModel) mem->model) {
     case VIR_DOMAIN_MEMORY_MODEL_NVDIMM:
-        if (mem->nvdimmPath == NULL) {
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("%s: nvdimm without a path"),
-                           __func__);
-            return -1;
-        }
         if (!virFileExists(mem->nvdimmPath)) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("%s: \'%s\' does not exist"),