[libvirt PATCH 31/38] domain_conf: Use virXMLProp(OnOff|YesNo) in virDomainVcpuParse

Tim Wiederhake twiederh at redhat.com
Thu Mar 18 08:01:10 UTC 2021


Signed-off-by: Tim Wiederhake <twiederh at redhat.com>
---
 src/conf/domain_conf.c | 25 ++++++-------------------
 1 file changed, 6 insertions(+), 19 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 9b4c083801..66d3080744 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -19096,7 +19096,7 @@ virDomainVcpuParse(virDomainDefPtr def,
 
         for (i = 0; i < n; i++) {
             virDomainVcpuDefPtr vcpu;
-            int state;
+            virTristateBool state = VIR_TRISTATE_BOOL_ABSENT;
             unsigned int id;
             unsigned int order;
 
@@ -19118,31 +19118,18 @@ virDomainVcpuParse(virDomainDefPtr def,
 
             vcpu = virDomainDefGetVcpu(def, id);
 
-            if (!(tmp = virXMLPropString(nodes[i], "enabled"))) {
+            if (virXMLPropYesNo(nodes[i], "enabled", &state) < 0)
+                return -1;
+            if (state == VIR_TRISTATE_BOOL_ABSENT) {
                 virReportError(VIR_ERR_XML_ERROR, "%s",
                                _("missing vcpu enabled state"));
                 return -1;
             }
 
-            if ((state = virTristateBoolTypeFromString(tmp)) < 0) {
-                virReportError(VIR_ERR_XML_ERROR,
-                               _("invalid vcpu 'enabled' value '%s'"), tmp);
-                return -1;
-            }
-            VIR_FREE(tmp);
-
             vcpu->online = state == VIR_TRISTATE_BOOL_YES;
 
-            if ((tmp = virXMLPropString(nodes[i], "hotpluggable"))) {
-                int hotpluggable;
-                if ((hotpluggable = virTristateBoolTypeFromString(tmp)) < 0) {
-                    virReportError(VIR_ERR_XML_ERROR,
-                                   _("invalid vcpu 'hotpluggable' value '%s'"), tmp);
-                    return -1;
-                }
-                vcpu->hotpluggable = hotpluggable;
-                VIR_FREE(tmp);
-            }
+            if (virXMLPropYesNo(nodes[i], "hotpluggable", &vcpu->hotpluggable) < 0)
+                return -1;
 
             if ((tmp = virXMLPropString(nodes[i], "order"))) {
                 if (virStrToLong_uip(tmp, NULL, 10, &order) < 0) {
-- 
2.26.2




More information about the libvir-list mailing list