]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: Refactor formating of 'capabilities' features
authorPeter Krempa <pkrempa@redhat.com>
Tue, 5 Mar 2019 12:48:20 +0000 (13:48 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 6 Mar 2019 14:53:53 +0000 (15:53 +0100)
Use virXMLFormatElement for the formatting which allows us to avoid
looking through the array to see if any feature is enabled.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/conf/domain_conf.c

index 90aa02a7eab33ae7f9146721be956950df32a67a..beabbace940d90fc11679be5f52508423f164f6b 100644 (file)
@@ -27928,30 +27928,23 @@ virDomainDefFormatFeatures(virBufferPtr buf,
             break;
 
         case VIR_DOMAIN_FEATURE_CAPABILITIES:
-            if (def->features[i] == VIR_DOMAIN_CAPABILITIES_POLICY_DEFAULT &&
-                !virDomainDefHasCapabilitiesFeatures(def)) {
-                break;
-            }
+            virBufferSetChildIndent(&tmpChildBuf, buf);
 
-            virBufferAsprintf(buf, "<capabilities policy='%s'",
-                              virDomainCapabilitiesPolicyTypeToString(def->features[i]));
-
-            if (!virDomainDefHasCapabilitiesFeatures(def)) {
-                virBufferAddLit(buf, "/>\n");
-                break;
-            } else {
-                virBufferAddLit(buf, ">\n");
-            }
-            virBufferAdjustIndent(buf, 2);
             for (j = 0; j < VIR_DOMAIN_CAPS_FEATURE_LAST; j++) {
                 if (def->caps_features[j] != VIR_TRISTATE_SWITCH_ABSENT)
-                    virBufferAsprintf(buf, "<%s state='%s'/>\n",
+                    virBufferAsprintf(&tmpChildBuf, "<%s state='%s'/>\n",
                                       virDomainCapsFeatureTypeToString(j),
-                                      virTristateSwitchTypeToString(
-                                          def->caps_features[j]));
+                                      virTristateSwitchTypeToString(def->caps_features[j]));
             }
-            virBufferAdjustIndent(buf, -2);
-            virBufferAddLit(buf, "</capabilities>\n");
+
+            /* the 'default' policy should be printed if any capability is present */
+            if (def->features[i] != VIR_DOMAIN_CAPABILITIES_POLICY_DEFAULT ||
+                virBufferUse(&tmpChildBuf))
+                virBufferAsprintf(&tmpAttrBuf, " policy='%s'",
+                                  virDomainCapabilitiesPolicyTypeToString(def->features[i]));
+
+            if (virXMLFormatElement(buf, "capabilities", &tmpAttrBuf, &tmpChildBuf) < 0)
+                return -1;
             break;
 
         case VIR_DOMAIN_FEATURE_GIC: