[libvirt] [PATCH] conf: Catch invalid memory model earlier

Michal Privoznik mprivozn at redhat.com
Thu Jul 28 16:28:40 UTC 2016


Consider the following XML snippet:

    <memory model=''>
      <target>
        <size unit='KiB'>523264</size>
        <node>0</node>
      </target>
    </memory>

Whats wrong you ask? The @model attribute. This should result in
an error thrown into users faces during virDomainDefine phase.
Except it doesn't. The XML validation catches this error, but if
users chose to ignore that, they will end up with invalid XML.
Well, they won't be able to start the machine - that's when error
is produced currently. But it would be nice if we could catch the
error like this earlier.

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 src/conf/domain_conf.c  | 2 +-
 src/qemu/qemu_command.c | 2 --
 src/qemu/qemu_domain.c  | 2 --
 3 files changed, 1 insertion(+), 5 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index c1ddb5a..a56e0f5 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -13215,7 +13215,7 @@ virDomainMemoryDefParseXML(xmlNodePtr memdevNode,
         goto error;
     }
 
-    if ((def->model = virDomainMemoryModelTypeFromString(tmp)) < 0) {
+    if ((def->model = virDomainMemoryModelTypeFromString(tmp)) <= 0) {
         virReportError(VIR_ERR_XML_ERROR,
                        _("invalid memory model '%s'"), tmp);
         goto error;
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index c4da8b5..5325f48 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3397,8 +3397,6 @@ qemuBuildMemoryDeviceStr(virDomainMemoryDefPtr mem)
 
     case VIR_DOMAIN_MEMORY_MODEL_NONE:
     case VIR_DOMAIN_MEMORY_MODEL_LAST:
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("invalid memory device type"));
         break;
 
     }
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index b3ca993..9b439df 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -5183,8 +5183,6 @@ qemuDomainDefValidateMemoryHotplugDevice(const virDomainMemoryDef *mem,
 
     case VIR_DOMAIN_MEMORY_MODEL_NONE:
     case VIR_DOMAIN_MEMORY_MODEL_LAST:
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("invalid memory device type"));
         return -1;
     }
 
-- 
2.8.4




More information about the libvir-list mailing list