[PATCH 13/14] snapshot: indent domain xml when nesting, round 13

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

 



All remaining aspects of <domain> indentation.

* src/conf/domain_conf.c (virDomainInputDefFormat)
(virDomainGraphicsDefFormat, virDomainGraphicsListenDefFormat)
(virDomainSoundDefFormat, virDomainVideoDefFormat)
(virDomainVideoAccelDefFormat, virDomainHostdevDefFormat)
(virDomainHubDefFormat, virDomainWatchdogDefFormat): Alter
signature.
(virDomainDefFormatInternal): Adjust caller.
---
 src/conf/domain_conf.c |  140 ++++++++++++++++++++++++++++-------------------
 1 files changed, 83 insertions(+), 57 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 16feb27..eb5a33e 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -9839,6 +9839,7 @@ virDomainSmartcardDefFormat(virBufferPtr buf,
 static int
 virDomainSoundDefFormat(virBufferPtr buf,
                         virDomainSoundDefPtr def,
+                        int indent,
                         unsigned int flags)
 {
     const char *model = virDomainSoundModelTypeToString(def->model);
@@ -9849,14 +9850,13 @@ virDomainSoundDefFormat(virBufferPtr buf,
         return -1;
     }

-    virBufferAsprintf(buf, "    <sound model='%s'",
-                      model);
+    virBufferAsprintf(buf, "%*s<sound model='%s'", indent, "",  model);

     if (virDomainDeviceInfoIsSet(&def->info, flags)) {
         virBufferAddLit(buf, ">\n");
-        if (virDomainDeviceInfoFormat(buf, &def->info, 6, flags) < 0)
+        if (virDomainDeviceInfoFormat(buf, &def->info, indent + 2, flags) < 0)
             return -1;
-        virBufferAddLit(buf, "    </sound>\n");
+        virBufferIndentAddLit(buf, indent, "</sound>\n");
     } else {
         virBufferAddLit(buf, "/>\n");
     }
@@ -9868,6 +9868,7 @@ virDomainSoundDefFormat(virBufferPtr buf,
 static int
 virDomainMemballoonDefFormat(virBufferPtr buf,
                              virDomainMemballoonDefPtr def,
+                             int indent,
                              unsigned int flags)
 {
     const char *model = virDomainMemballoonModelTypeToString(def->model);
@@ -9878,14 +9879,14 @@ virDomainMemballoonDefFormat(virBufferPtr buf,
         return -1;
     }

-    virBufferAsprintf(buf, "    <memballoon model='%s'",
+    virBufferAsprintf(buf, "%*s<memballoon model='%s'", indent, "",
                       model);

     if (virDomainDeviceInfoIsSet(&def->info, flags)) {
         virBufferAddLit(buf, ">\n");
-        if (virDomainDeviceInfoFormat(buf, &def->info, 6, flags) < 0)
+        if (virDomainDeviceInfoFormat(buf, &def->info, indent + 2, flags) < 0)
             return -1;
-        virBufferAddLit(buf, "    </memballoon>\n");
+        virBufferIndentAddLit(buf, indent, "</memballoon>\n");
     } else {
         virBufferAddLit(buf, "/>\n");
     }
@@ -9911,6 +9912,7 @@ virDomainSysinfoDefFormat(virBufferPtr buf,
 static int
 virDomainWatchdogDefFormat(virBufferPtr buf,
                            virDomainWatchdogDefPtr def,
+                           int indent,
                            unsigned int flags)
 {
     const char *model = virDomainWatchdogModelTypeToString (def->model);
@@ -9928,14 +9930,14 @@ virDomainWatchdogDefFormat(virBufferPtr buf,
         return -1;
     }

-    virBufferAsprintf(buf, "    <watchdog model='%s' action='%s'",
-                      model, action);
+    virBufferAsprintf(buf, "%*s<watchdog model='%s' action='%s'",
+                      indent, "", model, action);

     if (virDomainDeviceInfoIsSet(&def->info, flags)) {
         virBufferAddLit(buf, ">\n");
-        if (virDomainDeviceInfoFormat(buf, &def->info, 6, flags) < 0)
+        if (virDomainDeviceInfoFormat(buf, &def->info, indent + 2, flags) < 0)
             return -1;
-        virBufferAddLit(buf, "    </watchdog>\n");
+        virBufferIndentAddLit(buf, indent, "</watchdog>\n");
     } else {
         virBufferAddLit(buf, "/>\n");
     }
@@ -9946,9 +9948,10 @@ virDomainWatchdogDefFormat(virBufferPtr buf,

 static void
 virDomainVideoAccelDefFormat(virBufferPtr buf,
-                             virDomainVideoAccelDefPtr def)
+                             virDomainVideoAccelDefPtr def,
+                             int indent)
 {
-    virBufferAsprintf(buf, "        <acceleration accel3d='%s'",
+    virBufferAsprintf(buf, "%*s<acceleration accel3d='%s'", indent, "",
                       def->support3d ? "yes" : "no");
     virBufferAsprintf(buf, " accel2d='%s'",
                       def->support2d ? "yes" : "no");
@@ -9959,6 +9962,7 @@ virDomainVideoAccelDefFormat(virBufferPtr buf,
 static int
 virDomainVideoDefFormat(virBufferPtr buf,
                         virDomainVideoDefPtr def,
+                        int indent,
                         unsigned int flags)
 {
     const char *model = virDomainVideoTypeToString(def->type);
@@ -9969,8 +9973,8 @@ virDomainVideoDefFormat(virBufferPtr buf,
         return -1;
     }

-    virBufferAddLit(buf, "    <video>\n");
-    virBufferAsprintf(buf, "      <model type='%s'",
+    virBufferIndentAddLit(buf, indent, "<video>\n");
+    virBufferAsprintf(buf, "%*s<model type='%s'", indent + 2, "",
                       model);
     if (def->vram)
         virBufferAsprintf(buf, " vram='%u'", def->vram);
@@ -9978,16 +9982,16 @@ virDomainVideoDefFormat(virBufferPtr buf,
         virBufferAsprintf(buf, " heads='%u'", def->heads);
     if (def->accel) {
         virBufferAddLit(buf, ">\n");
-        virDomainVideoAccelDefFormat(buf, def->accel);
-        virBufferAddLit(buf, "      </model>\n");
+        virDomainVideoAccelDefFormat(buf, def->accel, indent + 4);
+        virBufferIndentAddLit(buf, indent + 2, "</model>\n");
     } else {
         virBufferAddLit(buf, "/>\n");
     }

-    if (virDomainDeviceInfoFormat(buf, &def->info, 6, flags) < 0)
+    if (virDomainDeviceInfoFormat(buf, &def->info, indent + 2, flags) < 0)
         return -1;

-    virBufferAddLit(buf, "    </video>\n");
+    virBufferIndentAddLit(buf, indent, "</video>\n");

     return 0;
 }
@@ -9995,6 +9999,7 @@ virDomainVideoDefFormat(virBufferPtr buf,
 static int
 virDomainInputDefFormat(virBufferPtr buf,
                         virDomainInputDefPtr def,
+                        int indent,
                         unsigned int flags)
 {
     const char *type = virDomainInputTypeToString(def->type);
@@ -10011,14 +10016,14 @@ virDomainInputDefFormat(virBufferPtr buf,
         return -1;
     }

-    virBufferAsprintf(buf, "    <input type='%s' bus='%s'",
+    virBufferAsprintf(buf, "%*s<input type='%s' bus='%s'", indent, "",
                       type, bus);

     if (virDomainDeviceInfoIsSet(&def->info, flags)) {
         virBufferAddLit(buf, ">\n");
-        if (virDomainDeviceInfoFormat(buf, &def->info, 6, flags) < 0)
+        if (virDomainDeviceInfoFormat(buf, &def->info, indent + 2, flags) < 0)
             return -1;
-        virBufferAddLit(buf, "    </input>\n");
+        virBufferIndentAddLit(buf, indent, "</input>\n");
     } else {
         virBufferAddLit(buf, "/>\n");
     }
@@ -10144,9 +10149,10 @@ virDomainGraphicsAuthDefFormatAttr(virBufferPtr buf,
 static void
 virDomainGraphicsListenDefFormat(virBufferPtr buf,
                                  virDomainGraphicsListenDefPtr def,
+                                 int indent,
                                  unsigned int flags)
 {
-    virBufferAddLit(buf, "      <listen");
+    virBufferIndentAddLit(buf, indent, "<listen");

     if (def->type) {
         virBufferAsprintf(buf, " type='%s'",
@@ -10174,6 +10180,7 @@ virDomainGraphicsListenDefFormat(virBufferPtr buf,
 static int
 virDomainGraphicsDefFormat(virBufferPtr buf,
                            virDomainGraphicsDefPtr def,
+                           int indent,
                            unsigned int flags)
 {
     const char *type = virDomainGraphicsTypeToString(def->type);
@@ -10198,7 +10205,7 @@ virDomainGraphicsDefFormat(virBufferPtr buf,
         }
     }

-    virBufferAsprintf(buf, "    <graphics type='%s'", type);
+    virBufferAsprintf(buf, "%*s<graphics type='%s'", indent, "", type);

     switch (def->type) {
     case VIR_DOMAIN_GRAPHICS_TYPE_VNC:
@@ -10304,7 +10311,8 @@ virDomainGraphicsDefFormat(virBufferPtr buf,
             virBufferAddLit(buf, ">\n");
             children = 1;
         }
-        virDomainGraphicsListenDefFormat(buf, &def->listens[i], flags);
+        virDomainGraphicsListenDefFormat(buf, &def->listens[i], indent + 2,
+                                         flags);
     }

     if (def->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) {
@@ -10318,7 +10326,8 @@ virDomainGraphicsDefFormat(virBufferPtr buf,
                 children = 1;
             }

-            virBufferAsprintf(buf, "      <channel name='%s' mode='%s'/>\n",
+            virBufferAsprintf(buf, "%*s<channel name='%s' mode='%s'/>\n",
+                              indent + 2, "",
                               virDomainGraphicsSpiceChannelNameTypeToString(i),
                               virDomainGraphicsSpiceChannelModeTypeToString(mode));
         }
@@ -10329,27 +10338,33 @@ virDomainGraphicsDefFormat(virBufferPtr buf,
             children = 1;
         }
         if (def->data.spice.image)
-            virBufferAsprintf(buf, "      <image compression='%s'/>\n",
+            virBufferAsprintf(buf, "%*s<image compression='%s'/>\n",
+                              indent + 2, "",
                               virDomainGraphicsSpiceImageCompressionTypeToString(def->data.spice.image));
         if (def->data.spice.jpeg)
-            virBufferAsprintf(buf, "      <jpeg compression='%s'/>\n",
+            virBufferAsprintf(buf, "%*s<jpeg compression='%s'/>\n",
+                              indent + 2, "",
                               virDomainGraphicsSpiceJpegCompressionTypeToString(def->data.spice.jpeg));
         if (def->data.spice.zlib)
-            virBufferAsprintf(buf, "      <zlib compression='%s'/>\n",
+            virBufferAsprintf(buf, "%*s<zlib compression='%s'/>\n",
+                              indent + 2, "",
                               virDomainGraphicsSpiceZlibCompressionTypeToString(def->data.spice.zlib));
         if (def->data.spice.playback)
-            virBufferAsprintf(buf, "      <playback compression='%s'/>\n",
+            virBufferAsprintf(buf, "%*s<playback compression='%s'/>\n",
+                              indent + 2, "",
                               virDomainGraphicsSpicePlaybackCompressionTypeToString(def->data.spice.playback));
         if (def->data.spice.streaming)
-            virBufferAsprintf(buf, "      <streaming mode='%s'/>\n",
+            virBufferAsprintf(buf, "%*s<streaming mode='%s'/>\n",
+                              indent + 2, "",
                               virDomainGraphicsSpiceStreamingModeTypeToString(def->data.spice.streaming));
         if (def->data.spice.copypaste)
-            virBufferAsprintf(buf, "      <clipboard copypaste='%s'/>\n",
+            virBufferAsprintf(buf, "%*s<clipboard copypaste='%s'/>\n",
+                              indent + 2, "",
                               virDomainGraphicsSpiceClipboardCopypasteTypeToString(def->data.spice.copypaste));
     }

     if (children) {
-        virBufferAddLit(buf, "    </graphics>\n");
+        virBufferIndentAddLit(buf, indent, "</graphics>\n");
     } else {
         virBufferAddLit(buf, "/>\n");
     }
@@ -10361,6 +10376,7 @@ virDomainGraphicsDefFormat(virBufferPtr buf,
 static int
 virDomainHostdevDefFormat(virBufferPtr buf,
                           virDomainHostdevDefPtr def,
+                          int indent,
                           unsigned int flags)
 {
     const char *mode = virDomainHostdevModeTypeToString(def->mode);
@@ -10380,39 +10396,46 @@ virDomainHostdevDefFormat(virBufferPtr buf,
         return -1;
     }

-    virBufferAsprintf(buf, "    <hostdev mode='%s' type='%s' managed='%s'>\n",
+    virBufferAsprintf(buf, "%*s<hostdev mode='%s' type='%s' managed='%s'>\n",
+                      indent, "",
                       mode, type, def->managed ? "yes" : "no");
-    virBufferAddLit(buf, "      <source>\n");
+    virBufferIndentAddLit(buf, indent + 2, "<source>\n");

     if (def->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB) {
         if (def->source.subsys.u.usb.vendor) {
-            virBufferAsprintf(buf, "        <vendor id='0x%.4x'/>\n",
+            virBufferAsprintf(buf, "%*s<vendor id='0x%.4x'/>\n",
+                              indent + 4, "",
                               def->source.subsys.u.usb.vendor);
-            virBufferAsprintf(buf, "        <product id='0x%.4x'/>\n",
+            virBufferAsprintf(buf, "%*s<product id='0x%.4x'/>\n",
+                              indent + 4, "",
                               def->source.subsys.u.usb.product);
         }
         if (def->source.subsys.u.usb.bus ||
             def->source.subsys.u.usb.device)
-            virBufferAsprintf(buf, "        <address bus='%d' device='%d'/>\n",
+            virBufferAsprintf(buf, "%*s<address bus='%d' device='%d'/>\n",
+                              indent + 4, "",
                               def->source.subsys.u.usb.bus,
                               def->source.subsys.u.usb.device);
     } else if (def->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI) {
-        virBufferAsprintf(buf, "        <address domain='0x%.4x' bus='0x%.2x' slot='0x%.2x' function='0x%.1x'/>\n",
+        virBufferAsprintf(buf, "%*s<address domain='0x%.4x' bus='0x%.2x' "
+                          "slot='0x%.2x' function='0x%.1x'/>\n",
+                          indent + 4, "",
                           def->source.subsys.u.pci.domain,
                           def->source.subsys.u.pci.bus,
                           def->source.subsys.u.pci.slot,
                           def->source.subsys.u.pci.function);
     }

-    virBufferAddLit(buf, "      </source>\n");
+    virBufferIndentAddLit(buf, indent + 2, "</source>\n");

     if (def->bootIndex)
-        virBufferAsprintf(buf, "      <boot order='%d'/>\n", def->bootIndex);
+        virBufferAsprintf(buf, "%*s<boot order='%d'/>\n", indent + 2, "",
+                          def->bootIndex);

-    if (virDomainDeviceInfoFormat(buf, &def->info, 6, flags) < 0)
+    if (virDomainDeviceInfoFormat(buf, &def->info, indent + 2, flags) < 0)
         return -1;

-    virBufferAddLit(buf, "    </hostdev>\n");
+    virBufferIndentAddLit(buf, indent, "</hostdev>\n");

     return 0;
 }
@@ -10440,8 +10463,9 @@ virDomainRedirdevDefFormat(virBufferPtr buf,

 static int
 virDomainHubDefFormat(virBufferPtr buf,
-                        virDomainHubDefPtr def,
-                        unsigned int flags)
+                      virDomainHubDefPtr def,
+                      int indent,
+                      unsigned int flags)
 {
     const char *type = virDomainHubTypeToString(def->type);

@@ -10451,13 +10475,13 @@ virDomainHubDefFormat(virBufferPtr buf,
         return -1;
     }

-    virBufferAsprintf(buf, "    <hub type='%s'", type);
+    virBufferAsprintf(buf, "%*s<hub type='%s'", indent, "", type);

     if (virDomainDeviceInfoIsSet(&def->info, flags)) {
         virBufferAddLit(buf, ">\n");
-        if (virDomainDeviceInfoFormat(buf, &def->info, 6, flags) < 0)
+        if (virDomainDeviceInfoFormat(buf, &def->info, indent + 2, flags) < 0)
             return -1;
-        virBufferAddLit(buf, "    </hub>\n");
+        virBufferIndentAddLit(buf, indent, "</hub>\n");
     } else {
         virBufferAddLit(buf, "/>\n");
     }
@@ -10847,7 +10871,7 @@ virDomainDefFormatInternal(virDomainDefPtr def,

     for (n = 0 ; n < def->ninputs ; n++)
         if (def->inputs[n]->bus == VIR_DOMAIN_INPUT_BUS_USB &&
-            virDomainInputDefFormat(buf, def->inputs[n], flags) < 0) /* XXX indent */
+            virDomainInputDefFormat(buf, def->inputs[n], indent, flags) < 0)
             goto cleanup;

     if (def->ngraphics > 0) {
@@ -10859,24 +10883,26 @@ virDomainDefFormatInternal(virDomainDefPtr def,
             { .alias = NULL },
         };

-        if (virDomainInputDefFormat(buf, &autoInput, flags) < 0) /* XXX indent */
+        if (virDomainInputDefFormat(buf, &autoInput, indent, flags) < 0)
             goto cleanup;

         for (n = 0 ; n < def->ngraphics ; n++)
-            if (virDomainGraphicsDefFormat(buf, def->graphics[n], flags) < 0) /* XXX indent */
+            if (virDomainGraphicsDefFormat(buf, def->graphics[n], indent,
+                                           flags) < 0)
                 goto cleanup;
     }

     for (n = 0 ; n < def->nsounds ; n++)
-        if (virDomainSoundDefFormat(buf, def->sounds[n], flags) < 0) /* XXX indent */
+        if (virDomainSoundDefFormat(buf, def->sounds[n], indent, flags) < 0)
             goto cleanup;

     for (n = 0 ; n < def->nvideos ; n++)
-        if (virDomainVideoDefFormat(buf, def->videos[n], flags) < 0) /* XXX indent */
+        if (virDomainVideoDefFormat(buf, def->videos[n], indent, flags) < 0)
             goto cleanup;

     for (n = 0 ; n < def->nhostdevs ; n++)
-        if (virDomainHostdevDefFormat(buf, def->hostdevs[n], flags) < 0) /* XXX indent */
+        if (virDomainHostdevDefFormat(buf, def->hostdevs[n], indent,
+                                      flags) < 0)
             goto cleanup;

     for (n = 0 ; n < def->nredirdevs ; n++)
@@ -10885,14 +10911,14 @@ virDomainDefFormatInternal(virDomainDefPtr def,
             goto cleanup;

     for (n = 0 ; n < def->nhubs ; n++)
-        if (virDomainHubDefFormat(buf, def->hubs[n], flags) < 0) /* XXX indent */
+        if (virDomainHubDefFormat(buf, def->hubs[n], indent, flags) < 0)
             goto cleanup;

     if (def->watchdog)
-        virDomainWatchdogDefFormat (buf, def->watchdog, flags); /* XXX indent */
+        virDomainWatchdogDefFormat(buf, def->watchdog, indent, flags);

     if (def->memballoon)
-        virDomainMemballoonDefFormat (buf, def->memballoon, flags); /* XXX indent */
+        virDomainMemballoonDefFormat(buf, def->memballoon, indent, flags);

     indent -= 2;
     virBufferIndentAddLit(buf, indent, "</devices>\n");
-- 
1.7.4.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]