]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: Report errors on cputune parameter parsing
authorPeter Krempa <pkrempa@redhat.com>
Wed, 20 Feb 2013 15:15:34 +0000 (16:15 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 5 Mar 2013 07:35:28 +0000 (08:35 +0100)
This patch adds proper error reporting if parsing of cputune parameters
fails due to incorrect values provided by the user. Previously no errors
were reported in such a case and the failure was silently ignored.

src/conf/domain_conf.c

index dc1bd6e6eb0cb78422ee5c3b61edc4abdbdee761..f7c8af1eb3a1fc0d45c469d887db76628a473742 100644 (file)
@@ -9478,29 +9478,43 @@ virDomainDefParseXML(virCapsPtr caps,
 
     /* Extract cpu tunables. */
     if (virXPathULong("string(./cputune/shares[1])", ctxt,
-                      &def->cputune.shares) < 0)
-        def->cputune.shares = 0;
+                      &def->cputune.shares) < -1) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("can't parse cputune shares value"));
+        goto error;
+    }
 
     if (virXPathULongLong("string(./cputune/period[1])", ctxt,
-                          &def->cputune.period) < 0)
-        def->cputune.period = 0;
+                          &def->cputune.period) < -1) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("can't parse cputune period value"));
+        goto error;
+    }
 
     if (virXPathLongLong("string(./cputune/quota[1])", ctxt,
-                         &def->cputune.quota) < 0)
-        def->cputune.quota = 0;
+                         &def->cputune.quota) < -1) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("can't parse cputune quota value"));
+        goto error;
+    }
 
     if (virXPathULongLong("string(./cputune/emulator_period[1])", ctxt,
-                          &def->cputune.emulator_period) < 0)
-        def->cputune.emulator_period = 0;
+                          &def->cputune.emulator_period) < -1) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("can't parse cputune emulator period value"));
+        goto error;
+    }
 
     if (virXPathLongLong("string(./cputune/emulator_quota[1])", ctxt,
-                         &def->cputune.emulator_quota) < 0)
-        def->cputune.emulator_quota = 0;
-
-    if ((n = virXPathNodeSet("./cputune/vcpupin", ctxt, &nodes)) < 0) {
+                         &def->cputune.emulator_quota) < -1) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("can't parse cputune emulator quota value"));
         goto error;
     }
 
+    if ((n = virXPathNodeSet("./cputune/vcpupin", ctxt, &nodes)) < 0)
+        goto error;
+
     if (n && VIR_ALLOC_N(def->cputune.vcpupin, n) < 0)
         goto no_memory;