[PATCHv1.5 13/27] conf: Clean up virDomainDiskSourceDefFormatInternal

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

 



Avoid if statements when used with virBufferEscapeString which
automaticaly omits the whole string. Also add some line breaks to
visualy separate the code.
---
 src/conf/domain_conf.c | 48 ++++++++++++++++++++----------------------------
 1 file changed, 20 insertions(+), 28 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index afeadd7..05f8964 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -14374,53 +14374,49 @@ virDomainDiskSourceDefFormatInternal(virBufferPtr buf,
         switch (type) {
         case VIR_DOMAIN_DISK_TYPE_FILE:
             virBufferAddLit(buf, "      <source");
-            if (src)
-                virBufferEscapeString(buf, " file='%s'", src);
-            if (startupPolicy)
-                virBufferEscapeString(buf, " startupPolicy='%s'",
-                                      startupPolicy);
+            virBufferEscapeString(buf, " file='%s'", src);
+            virBufferEscapeString(buf, " startupPolicy='%s'", startupPolicy);
+
             if (nseclabels) {
                 virBufferAddLit(buf, ">\n");
                 virBufferAdjustIndent(buf, 8);
                 for (n = 0; n < nseclabels; n++)
-                    virSecurityDeviceLabelDefFormat(buf, seclabels[n],
-                                                    flags);
+                    virSecurityDeviceLabelDefFormat(buf, seclabels[n], flags);
                 virBufferAdjustIndent(buf, -8);
                 virBufferAddLit(buf, "      </source>\n");
             } else {
                 virBufferAddLit(buf, "/>\n");
             }
             break;
+
         case VIR_DOMAIN_DISK_TYPE_BLOCK:
             virBufferAddLit(buf, "      <source");
             virBufferEscapeString(buf, " dev='%s'", src);
-            if (startupPolicy)
-                virBufferEscapeString(buf, " startupPolicy='%s'",
-                                      startupPolicy);
+            virBufferEscapeString(buf, " startupPolicy='%s'", startupPolicy);
+
             if (nseclabels) {
                 virBufferAddLit(buf, ">\n");
                 virBufferAdjustIndent(buf, 8);
                 for (n = 0; n < nseclabels; n++)
-                    virSecurityDeviceLabelDefFormat(buf, seclabels[n],
-                                                    flags);
+                    virSecurityDeviceLabelDefFormat(buf, seclabels[n], flags);
                 virBufferAdjustIndent(buf, -8);
                 virBufferAddLit(buf, "      </source>\n");
             } else {
                 virBufferAddLit(buf, "/>\n");
             }
             break;
+
         case VIR_DOMAIN_DISK_TYPE_DIR:
-            virBufferEscapeString(buf, "      <source dir='%s'", src);
-            if (startupPolicy)
-                virBufferEscapeString(buf, " startupPolicy='%s'",
-                                      startupPolicy);
+            virBufferAddLit(buf, "      <source");
+            virBufferEscapeString(buf, " dir='%s'", src);
+            virBufferEscapeString(buf, " startupPolicy='%s'", startupPolicy);
             virBufferAddLit(buf, "/>\n");
             break;
+
         case VIR_DOMAIN_DISK_TYPE_NETWORK:
             virBufferAsprintf(buf, "      <source protocol='%s'",
                               virDomainDiskProtocolTypeToString(protocol));
-            if (src)
-                virBufferEscapeString(buf, " name='%s'", src);
+            virBufferEscapeString(buf, " name='%s'", src);

             if (nhosts == 0) {
                 virBufferAddLit(buf, "/>\n");
@@ -14428,25 +14424,21 @@ virDomainDiskSourceDefFormatInternal(virBufferPtr buf,
                 virBufferAddLit(buf, ">\n");
                 for (n = 0; n < nhosts; n++) {
                     virBufferAddLit(buf, "        <host");
-                    if (hosts[n].name)
-                        virBufferEscapeString(buf, " name='%s'", hosts[n].name);
-
-                    if (hosts[n].port)
-                        virBufferEscapeString(buf, " port='%s'",
-                                              hosts[n].port);
+                    virBufferEscapeString(buf, " name='%s'", hosts[n].name);
+                    virBufferEscapeString(buf, " port='%s'", hosts[n].port);

                     if (hosts[n].transport)
                         virBufferAsprintf(buf, " transport='%s'",
                                           virDomainDiskProtocolTransportTypeToString(hosts[n].transport));

-                    if (hosts[n].socket)
-                        virBufferEscapeString(buf, " socket='%s'", hosts[n].socket);
+                    virBufferEscapeString(buf, " socket='%s'", hosts[n].socket);

                     virBufferAddLit(buf, "/>\n");
                 }
                 virBufferAddLit(buf, "      </source>\n");
             }
             break;
+
         case VIR_DOMAIN_DISK_TYPE_VOLUME:
             virBufferAddLit(buf, "      <source");

@@ -14457,8 +14449,7 @@ virDomainDiskSourceDefFormatInternal(virBufferPtr buf,
                     virBufferAsprintf(buf, " mode='%s'",
                                       virDomainDiskSourcePoolModeTypeToString(srcpool->mode));
             }
-            if (startupPolicy)
-                virBufferEscapeString(buf, " startupPolicy='%s'", startupPolicy);
+            virBufferEscapeString(buf, " startupPolicy='%s'", startupPolicy);

             if (nseclabels) {
                 virBufferAddLit(buf, ">\n");
@@ -14472,6 +14463,7 @@ virDomainDiskSourceDefFormatInternal(virBufferPtr buf,
                 virBufferAddLit(buf, "/>\n");
             }
             break;
+
         default:
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("unexpected disk type %s"),
-- 
1.8.4.3

--
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]