conf: Catch invalid memory model earlier

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@redhat.com>
This commit is contained in:
Michal Privoznik 2016-07-28 18:20:31 +02:00
parent f5f32bcd1b
commit 1e05846373
3 changed files with 1 additions and 5 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}