From 1e058463732b647fdf5481208a539c50f1c729cf Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Thu, 28 Jul 2016 18:20:31 +0200 Subject: [PATCH] conf: Catch invalid memory model earlier Consider the following XML snippet: 523264 0 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 --- 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 c1ddb5a09d..a56e0f5d16 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 c4da8b594a..5325f48dbb 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 b3ca993f43..9b439df3b3 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.39.5