[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 07/14] snapshot: indent domain xml when nesting, round 7



Tackle the domain-specific callbacks.

* src/conf/capabilities.h (virDomainDefNamespaceXMLFormat)
(_virCaps): Add indent argument.
* src/conf/domain_conf.c (virDomainObjFormat)
(virDomainDefFormatInternal): Adjust callers.
* src/qemu/qemu_domain.c (qemuDomainObjPrivateXMLFormat)
(qemuDomainDefNamespaceFormatXML): Adjust callbacks.
---
 src/conf/capabilities.h |    6 +++---
 src/conf/domain_conf.c  |    4 ++--
 src/qemu/qemu_domain.c  |   39 +++++++++++++++++++++++----------------
 3 files changed, 28 insertions(+), 21 deletions(-)

diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h
index e2fa1d6..2e2a93d 100644
--- a/src/conf/capabilities.h
+++ b/src/conf/capabilities.h
@@ -1,7 +1,7 @@
 /*
  * capabilities.h: 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
@@ -121,7 +121,7 @@ struct _virCapsHost {
 typedef int (*virDomainDefNamespaceParse)(xmlDocPtr, xmlNodePtr,
                                           xmlXPathContextPtr, void **);
 typedef void (*virDomainDefNamespaceFree)(void *);
-typedef int (*virDomainDefNamespaceXMLFormat)(virBufferPtr, void *);
+typedef int (*virDomainDefNamespaceXMLFormat)(virBufferPtr, int, void *);
 typedef const char *(*virDomainDefNamespaceHref)(void);

 typedef struct _virDomainXMLNamespace virDomainXMLNamespace;
@@ -147,7 +147,7 @@ struct _virCaps {
     int defaultConsoleTargetType;
     void *(*privateDataAllocFunc)(void);
     void (*privateDataFreeFunc)(void *);
-    int (*privateDataXMLFormat)(virBufferPtr, void *);
+    int (*privateDataXMLFormat)(virBufferPtr, int, void *);
     int (*privateDataXMLParse)(xmlXPathContextPtr, void *);
     bool hasWideScsiBus;
     const char *defaultInitPath;
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index f6df921..0a5e50b 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -10903,7 +10903,7 @@ virDomainDefFormatInternal(virDomainDefPtr def,
     }

     if (def->namespaceData && def->ns.format) {
-        if ((def->ns.format)(buf, def->namespaceData) < 0) /* XXX indent */
+        if ((def->ns.format)(buf, indent, def->namespaceData) < 0)
             goto cleanup;
     }

@@ -10958,7 +10958,7 @@ static char *virDomainObjFormat(virCapsPtr caps,
     }

     if (caps->privateDataXMLFormat &&
-        ((caps->privateDataXMLFormat)(&buf, obj->privateData)) < 0)
+        ((caps->privateDataXMLFormat)(&buf, 2, obj->privateData)) < 0)
         goto error;

     if (virDomainDefFormatInternal(obj->def, 2, flags, &buf) < 0)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 4023648..d913cc1 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -241,7 +241,8 @@ static void qemuDomainObjPrivateFree(void *data)
 }


-static int qemuDomainObjPrivateXMLFormat(virBufferPtr buf, void *data)
+static int
+qemuDomainObjPrivateXMLFormat(virBufferPtr buf, int indent, void *data)
 {
     qemuDomainObjPrivatePtr priv = data;
     const char *monitorpath;
@@ -258,7 +259,8 @@ static int qemuDomainObjPrivateXMLFormat(virBufferPtr buf, void *data)
             break;
         }

-        virBufferEscapeString(buf, "  <monitor path='%s'", monitorpath);
+        virBufferIndentEscapeString(buf, indent, "<monitor path='%s'",
+                                    monitorpath);
         if (priv->monJSON)
             virBufferAddLit(buf, " json='1'");
         virBufferAsprintf(buf, " type='%s'/>\n",
@@ -268,30 +270,33 @@ static int qemuDomainObjPrivateXMLFormat(virBufferPtr buf, void *data)

     if (priv->nvcpupids) {
         int i;
-        virBufferAddLit(buf, "  <vcpus>\n");
+        virBufferIndentAddLit(buf, indent, "<vcpus>\n");
         for (i = 0 ; i < priv->nvcpupids ; i++) {
-            virBufferAsprintf(buf, "    <vcpu pid='%d'/>\n", priv->vcpupids[i]);
+            virBufferAsprintf(buf, "%*s<vcpu pid='%d'/>\n", indent + 2, "",
+                              priv->vcpupids[i]);
         }
-        virBufferAddLit(buf, "  </vcpus>\n");
+        virBufferIndentAddLit(buf, indent, "</vcpus>\n");
     }

     if (priv->qemuCaps) {
         int i;
-        virBufferAddLit(buf, "  <qemuCaps>\n");
+        virBufferIndentAddLit(buf, indent, "<qemuCaps>\n");
         for (i = 0 ; i < QEMU_CAPS_LAST ; i++) {
             if (qemuCapsGet(priv->qemuCaps, i)) {
-                virBufferAsprintf(buf, "    <flag name='%s'/>\n",
+                virBufferAsprintf(buf, "%*s<flag name='%s'/>\n",
+                                  indent + 2, "",
                                   qemuCapsTypeToString(i));
             }
         }
-        virBufferAddLit(buf, "  </qemuCaps>\n");
+        virBufferIndentAddLit(buf, indent, "</qemuCaps>\n");
     }

     if (priv->lockState)
-        virBufferAsprintf(buf, "  <lockstate>%s</lockstate>\n", priv->lockState);
+        virBufferAsprintf(buf, "%*s<lockstate>%s</lockstate>\n", indent, "",
+                          priv->lockState);

     if (priv->job.active || priv->job.asyncJob) {
-        virBufferAsprintf(buf, "  <job type='%s' async='%s'",
+        virBufferAsprintf(buf, "%*s<job type='%s' async='%s'", indent, "",
                           qemuDomainJobTypeToString(priv->job.active),
                           qemuDomainAsyncJobTypeToString(priv->job.asyncJob));
         if (priv->job.phase) {
@@ -590,7 +595,7 @@ error:
 }

 static int
-qemuDomainDefNamespaceFormatXML(virBufferPtr buf,
+qemuDomainDefNamespaceFormatXML(virBufferPtr buf, int indent,
                                 void *nsdata)
 {
     qemuDomainCmdlineDefPtr cmd = nsdata;
@@ -599,17 +604,19 @@ qemuDomainDefNamespaceFormatXML(virBufferPtr buf,
     if (!cmd->num_args && !cmd->num_env)
         return 0;

-    virBufferAddLit(buf, "  <qemu:commandline>\n");
+    virBufferIndentAddLit(buf, indent, "<qemu:commandline>\n");
     for (i = 0; i < cmd->num_args; i++)
-        virBufferEscapeString(buf, "    <qemu:arg value='%s'/>\n",
-                              cmd->args[i]);
+        virBufferIndentEscapeString(buf, indent + 2,
+                                    "<qemu:arg value='%s'/>\n",
+                                    cmd->args[i]);
     for (i = 0; i < cmd->num_env; i++) {
-        virBufferAsprintf(buf, "    <qemu:env name='%s'", cmd->env_name[i]);
+        virBufferAsprintf(buf, "%*s<qemu:env name='%s'", indent + 2, "",
+                          cmd->env_name[i]);
         if (cmd->env_value[i])
             virBufferEscapeString(buf, " value='%s'", cmd->env_value[i]);
         virBufferAddLit(buf, "/>\n");
     }
-    virBufferAddLit(buf, "  </qemu:commandline>\n");
+    virBufferIndentAddLit(buf, indent, "</qemu:commandline>\n");

     return 0;
 }
-- 
1.7.4.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]