On Fri, Nov 13, 2015 at 20:16:40 +0300, Dmitry Andreev wrote:
Only one panic device per model is allowed.
---
src/conf/domain_conf.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 2f17675..b4a46ad 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -3747,6 +3747,30 @@ virDomainDefRejectDuplicateControllers(virDomainDefPtr def)
return ret;
}
+static int
+virDomainDefRejectDuplicatePanics(virDomainDefPtr def)
+{
+ bool exists[VIR_DOMAIN_PANIC_MODEL_LAST];
+ size_t i;
+
+ for (i = 0; i < VIR_DOMAIN_PANIC_MODEL_LAST; i++)
+ exists[i] = false;
+
+ for (i = 0; i < def->npanics; i++) {
+ virDomainPanicModel model = def->panics[i]->model;
+ if (!exists[model]) {
+ exists[model] = true;
Wrong indentation.
+ } else {
+ virReportError(VIR_ERR_XML_ERROR,
+ _("Multiple panic devices with model
'%s'"),
+ virDomainPanicModelTypeToString(model));
+ return -1;
+ }
But I think avoiding negative test would make the code a bit more
readable:
if (exists[model]) {
virReportError(...);
return -1;
}
exists[model] = true;
+
Extra empty line.
> + }
+
> + return 0;
> +}
>
> /**
> * virDomainDefMetadataSanitize:
> @@ -3976,6 +4000,9 @@ virDomainDefPostParseInternal(virDomainDefPtr def,
> if (virDomainDefRejectDuplicateControllers(def) < 0)
> return -1;
>
> + if (virDomainDefRejectDuplicatePanics(def) < 0)
> + return -1;
+
> /* verify settings of guest timers */
> for (i = 0; i < def->clock.ntimers; i++) {
> virDomainTimerDefPtr timer = def->clock.timers[i];
Jirka