From c7d3cf2e3ba73e6e3eee36bd1d6ca2eed1fedc55 Mon Sep 17 00:00:00 2001
From: John Ferlan <jferlan@redhat.com>
Date: Mon, 19 Sep 2016 08:27:24 -0400
Subject: [PATCH] conf: Add a formatting macro for all the blkiotune values

Rather than copy-paste - use a macro

Unfortunately due to how the RNG schema was written keeping the 'value'
and 'value'_max next to each other in the XML causes a schema failure,
so the FORMAT has to write out singly rather than optimizing to write
out both values at once

Signed-off-by: John Ferlan <jferlan@redhat.com>
---
 src/conf/domain_conf.c | 77 +++++++++++-------------------------------
 1 file changed, 19 insertions(+), 58 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 7427efbd31..6a772c6666 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -20082,6 +20082,12 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf,
 }
 
 
+#define FORMAT_IOTUNE(val)                                                     \
+        if (def->blkdeviotune.val) {                                           \
+            virBufferAsprintf(buf, "<" #val ">%llu</" #val ">\n",              \
+                              def->blkdeviotune.val);                          \
+        }
+
 static int
 virDomainDiskDefFormat(virBufferPtr buf,
                        virDomainDiskDefPtr def,
@@ -20269,66 +20275,20 @@ virDomainDiskDefFormat(virBufferPtr buf,
         def->blkdeviotune.size_iops_sec) {
         virBufferAddLit(buf, "<iotune>\n");
         virBufferAdjustIndent(buf, 2);
-        if (def->blkdeviotune.total_bytes_sec) {
-            virBufferAsprintf(buf, "<total_bytes_sec>%llu</total_bytes_sec>\n",
-                              def->blkdeviotune.total_bytes_sec);
-        }
-
-        if (def->blkdeviotune.read_bytes_sec) {
-            virBufferAsprintf(buf, "<read_bytes_sec>%llu</read_bytes_sec>\n",
-                              def->blkdeviotune.read_bytes_sec);
-
-        }
-
-        if (def->blkdeviotune.write_bytes_sec) {
-            virBufferAsprintf(buf, "<write_bytes_sec>%llu</write_bytes_sec>\n",
-                              def->blkdeviotune.write_bytes_sec);
-        }
-
-        if (def->blkdeviotune.total_iops_sec) {
-            virBufferAsprintf(buf, "<total_iops_sec>%llu</total_iops_sec>\n",
-                              def->blkdeviotune.total_iops_sec);
-        }
-
-        if (def->blkdeviotune.read_iops_sec) {
-            virBufferAsprintf(buf, "<read_iops_sec>%llu</read_iops_sec>\n",
-                              def->blkdeviotune.read_iops_sec);
-        }
 
-        if (def->blkdeviotune.write_iops_sec) {
-            virBufferAsprintf(buf, "<write_iops_sec>%llu</write_iops_sec>\n",
-                              def->blkdeviotune.write_iops_sec);
-        }
-
-        if (def->blkdeviotune.total_bytes_sec_max) {
-            virBufferAsprintf(buf, "<total_bytes_sec_max>%llu</total_bytes_sec_max>\n",
-                              def->blkdeviotune.total_bytes_sec_max);
-        }
-
-        if (def->blkdeviotune.read_bytes_sec_max) {
-            virBufferAsprintf(buf, "<read_bytes_sec_max>%llu</read_bytes_sec_max>\n",
-                              def->blkdeviotune.read_bytes_sec_max);
-        }
-
-        if (def->blkdeviotune.write_bytes_sec_max) {
-            virBufferAsprintf(buf, "<write_bytes_sec_max>%llu</write_bytes_sec_max>\n",
-                              def->blkdeviotune.write_bytes_sec_max);
-        }
-
-        if (def->blkdeviotune.total_iops_sec_max) {
-            virBufferAsprintf(buf, "<total_iops_sec_max>%llu</total_iops_sec_max>\n",
-                              def->blkdeviotune.total_iops_sec_max);
-        }
+        FORMAT_IOTUNE(total_bytes_sec);
+        FORMAT_IOTUNE(read_bytes_sec);
+        FORMAT_IOTUNE(write_bytes_sec);
+        FORMAT_IOTUNE(total_iops_sec);
+        FORMAT_IOTUNE(read_iops_sec);
+        FORMAT_IOTUNE(write_iops_sec);
 
-        if (def->blkdeviotune.read_iops_sec_max) {
-            virBufferAsprintf(buf, "<read_iops_sec_max>%llu</read_iops_sec_max>\n",
-                              def->blkdeviotune.read_iops_sec_max);
-        }
-
-        if (def->blkdeviotune.write_iops_sec_max) {
-            virBufferAsprintf(buf, "<write_iops_sec_max>%llu</write_iops_sec_max>\n",
-                              def->blkdeviotune.write_iops_sec_max);
-        }
+        FORMAT_IOTUNE(total_bytes_sec_max);
+        FORMAT_IOTUNE(read_bytes_sec_max);
+        FORMAT_IOTUNE(write_bytes_sec_max);
+        FORMAT_IOTUNE(total_iops_sec_max);
+        FORMAT_IOTUNE(read_iops_sec_max);
+        FORMAT_IOTUNE(write_iops_sec_max);
 
         if (def->blkdeviotune.size_iops_sec) {
             virBufferAsprintf(buf, "<size_iops_sec>%llu</size_iops_sec>\n",
@@ -20360,6 +20320,7 @@ virDomainDiskDefFormat(virBufferPtr buf,
     virBufferAddLit(buf, "</disk>\n");
     return 0;
 }
+#undef FORMAT_IOTUNE
 
 
 static int
-- 
GitLab