]> xenbits.xensource.com Git - libvirt.git/commitdiff
snapshot: simplify indentation of cpu features
authorEric Blake <eblake@redhat.com>
Wed, 21 Sep 2011 23:42:07 +0000 (17:42 -0600)
committerEric Blake <eblake@redhat.com>
Thu, 20 Oct 2011 22:56:28 +0000 (16:56 -0600)
Auto-indent makes life a bit easier; this patch also drops unused
arguments and replaces a misspelled flag name with two entry points
instead, so that callers don't have to worry about how much spacing
is present when embedding cpu elements.

* src/conf/cpu_conf.h (virCPUFormatFlags): Delete.
(virCPUDefFormat): Drop unused argument.
(virCPUDefFormatBuf): Alter signature.
(virCPUDefFormatBufFull): New prototype.
* src/conf/cpu_conf.c (virCPUDefFormatBuf): Split...
(virCPUDefFormatBufFull): ...into new function.
(virCPUDefFormat): Adjust caller.
* src/conf/domain_conf.c (virDomainDefFormatInternal): Likewise.
* src/conf/capabilities.c (virCapabilitiesFormatXML): Likewise.
* src/cpu/cpu.c (cpuBaselineXML): Likewise.
* tests/cputest.c (cpuTestCompareXML): Likewise.

src/conf/capabilities.c
src/conf/cpu_conf.c
src/conf/cpu_conf.h
src/conf/domain_conf.c
src/cpu/cpu.c
tests/cputest.c

index 2f243ae4675347730b09f4af41dc22c2b2d95e16..40e297678a37308e13e0bfeb6a94a3af245dbb6e 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * capabilities.c: hypervisor capabilities
  *
- * Copyright (C) 2006-2008, 2010 Red Hat, Inc.
+ * Copyright (C) 2006-2008, 2010-2011 Red Hat, Inc.
  * Copyright (C) 2006-2008 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -681,8 +681,9 @@ virCapabilitiesFormatXML(virCapsPtr caps)
         virBufferAddLit(&xml, "      </features>\n");
     }
 
-    virCPUDefFormatBuf(&xml, caps->host.cpu, "    ",
-                       VIR_CPU_FORMAT_EMBEDED);
+    virBufferAdjustIndent(&xml, 6);
+    virCPUDefFormatBuf(&xml, caps->host.cpu);
+    virBufferAdjustIndent(&xml, -6);
 
     virBufferAddLit(&xml, "    </cpu>\n");
 
index 5cecda2f2b09f924893d9b6f5f66f5792c16e6b7..41e997ea979b5940f0dfcac310e094476f2c5b73 100644 (file)
@@ -305,13 +305,11 @@ error:
 
 
 char *
-virCPUDefFormat(virCPUDefPtr def,
-                const char *indent,
-                unsigned int flags)
+virCPUDefFormat(virCPUDefPtr def)
 {
     virBuffer buf = VIR_BUFFER_INITIALIZER;
 
-    if (virCPUDefFormatBuf(&buf, def, indent, flags) < 0)
+    if (virCPUDefFormatBufFull(&buf, def) < 0)
         goto cleanup;
 
     if (virBufferError(&buf))
@@ -327,54 +325,63 @@ cleanup:
 }
 
 
+int
+virCPUDefFormatBufFull(virBufferPtr buf,
+                       virCPUDefPtr def)
+{
+    if (!def)
+        return 0;
+
+    if (def->type == VIR_CPU_TYPE_GUEST && def->model) {
+        const char *match;
+        if (!(match = virCPUMatchTypeToString(def->match))) {
+            virCPUReportError(VIR_ERR_INTERNAL_ERROR,
+                              _("Unexpected CPU match policy %d"), def->match);
+            return -1;
+        }
+
+        virBufferAsprintf(buf, "<cpu match='%s'>\n", match);
+    } else {
+        virBufferAddLit(buf, "<cpu>\n");
+    }
+
+    if (def->arch)
+        virBufferAsprintf(buf, "  <arch>%s</arch>\n", def->arch);
+
+    virBufferAdjustIndent(buf, 2);
+    if (virCPUDefFormatBuf(buf, def) < 0)
+        return -1;
+    virBufferAdjustIndent(buf, -2);
+
+    virBufferAddLit(buf, "</cpu>\n");
+
+    return 0;
+}
+
 int
 virCPUDefFormatBuf(virBufferPtr buf,
-                   virCPUDefPtr def,
-                   const char *indent,
-                   unsigned int flags)
+                   virCPUDefPtr def)
 {
     unsigned int i;
 
     if (!def)
         return 0;
 
-    if (indent == NULL)
-        indent = "";
-
     if (!def->model && def->nfeatures) {
         virCPUReportError(VIR_ERR_INTERNAL_ERROR,
                 "%s", _("Non-empty feature list specified without CPU model"));
         return -1;
     }
 
-    if (!(flags & VIR_CPU_FORMAT_EMBEDED)) {
-        if (def->type == VIR_CPU_TYPE_GUEST && def->model) {
-            const char *match;
-            if (!(match = virCPUMatchTypeToString(def->match))) {
-                virCPUReportError(VIR_ERR_INTERNAL_ERROR,
-                        _("Unexpected CPU match policy %d"), def->match);
-                return -1;
-            }
-
-            virBufferAsprintf(buf, "%s<cpu match='%s'>\n", indent, match);
-        }
-        else
-            virBufferAsprintf(buf, "%s<cpu>\n", indent);
-
-        if (def->arch)
-            virBufferAsprintf(buf, "%s  <arch>%s</arch>\n", indent, def->arch);
-    }
-
     if (def->model)
-        virBufferAsprintf(buf, "%s  <model>%s</model>\n", indent, def->model);
+        virBufferAsprintf(buf, "<model>%s</model>\n", def->model);
 
     if (def->vendor) {
-        virBufferAsprintf(buf, "%s  <vendor>%s</vendor>\n",
-                          indent, def->vendor);
+        virBufferAsprintf(buf, "<vendor>%s</vendor>\n", def->vendor);
     }
 
     if (def->sockets && def->cores && def->threads) {
-        virBufferAsprintf(buf, "%s  <topology", indent);
+        virBufferAddLit(buf, "<topology");
         virBufferAsprintf(buf, " sockets='%u'", def->sockets);
         virBufferAsprintf(buf, " cores='%u'", def->cores);
         virBufferAsprintf(buf, " threads='%u'", def->threads);
@@ -399,18 +406,14 @@ virCPUDefFormatBuf(virBufferPtr buf,
                         _("Unexpected CPU feature policy %d"), feature->policy);
                 return -1;
             }
-            virBufferAsprintf(buf, "%s  <feature policy='%s' name='%s'/>\n",
-                    indent, policy, feature->name);
-        }
-        else {
-            virBufferAsprintf(buf, "%s  <feature name='%s'/>\n",
-                    indent, feature->name);
+            virBufferAsprintf(buf, "<feature policy='%s' name='%s'/>\n",
+                              policy, feature->name);
+        } else {
+            virBufferAsprintf(buf, "<feature name='%s'/>\n",
+                              feature->name);
         }
     }
 
-    if (!(flags & VIR_CPU_FORMAT_EMBEDED))
-        virBufferAsprintf(buf, "%s</cpu>\n", indent);
-
     return 0;
 }
 
index 57b85e14f18445fea4193d387064363159dad59a..4406cba05a88742717f231bc217d33c4216573c7 100644 (file)
@@ -95,25 +95,19 @@ virCPUDefParseXML(const xmlNodePtr node,
                   xmlXPathContextPtr ctxt,
                   enum virCPUType mode);
 
-enum virCPUFormatFlags {
-    VIR_CPU_FORMAT_EMBEDED  = (1 << 0)  /* embed into existing <cpu/> element
-                                         * in host capabilities */
-};
-
 bool
 virCPUDefIsEqual(virCPUDefPtr src,
                  virCPUDefPtr dst);
 
 char *
-virCPUDefFormat(virCPUDefPtr def,
-                const char *indent,
-                unsigned int flags);
+virCPUDefFormat(virCPUDefPtr def);
 
 int
 virCPUDefFormatBuf(virBufferPtr buf,
-                   virCPUDefPtr def,
-                   const char *indent,
-                   unsigned int flags);
+                   virCPUDefPtr def);
+int
+virCPUDefFormatBufFull(virBufferPtr buf,
+                       virCPUDefPtr def);
 
 int
 virCPUDefAddFeature(virCPUDefPtr cpu,
index 9a461229614e9f61e9330169a02bccd6be5f6b9d..304d1a82aa8e125b620704f5d849dd1b241225f6 100644 (file)
@@ -10825,8 +10825,10 @@ virDomainDefFormatInternal(virDomainDefPtr def,
         virBufferAddLit(buf, "  </features>\n");
     }
 
-    if (virCPUDefFormatBuf(buf, def->cpu, "  ", 0) < 0)
+    virBufferAdjustIndent(buf, 2);
+    if (virCPUDefFormatBufFull(buf, def->cpu) < 0)
         goto cleanup;
+    virBufferAdjustIndent(buf, -2);
 
     virBufferAsprintf(buf, "  <clock offset='%s'",
                       virDomainClockOffsetTypeToString(def->clock.offset));
index 2906be9a1471466593bbbe7cb533a12b219bc45b..b919b6e2e022c0a68930d653ee4c591e7598456c 100644 (file)
@@ -320,7 +320,7 @@ cpuBaselineXML(const char **xmlCPUs,
     if (!(cpu = cpuBaseline(cpus, ncpus, models, nmodels)))
         goto error;
 
-    cpustr = virCPUDefFormat(cpu, "", 0);
+    cpustr = virCPUDefFormat(cpu);
 
 cleanup:
     if (cpus) {
index b5272c16249eb4fcc3ec960f3c05e26dc3b02899..36b3eb4b8ed2f514b2c4a623e65c8213b2011954 100644 (file)
@@ -176,7 +176,7 @@ cpuTestCompareXML(const char *arch,
     if (virtTestLoadFile(xml, &expected) < 0)
         goto cleanup;
 
-    if (!(actual = virCPUDefFormat(cpu, NULL, 0)))
+    if (!(actual = virCPUDefFormat(cpu)))
         goto cleanup;
 
     if (STRNEQ(expected, actual)) {