[libvirt] [PATCH 05/18] virDomainControllerDefFormat: move PCI model and target formatting

Ján Tomko posted 18 patches 7 years, 11 months ago
[libvirt] [PATCH 05/18] virDomainControllerDefFormat: move PCI model and target formatting
Posted by Ján Tomko 7 years, 11 months ago
These can be formatted right when we know we will need them.
No need for separate bool variables.
---
 src/conf/domain_conf.c | 30 +++++++++++-------------------
 1 file changed, 11 insertions(+), 19 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 81385d6..b47a376 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -21396,7 +21396,7 @@ virDomainControllerDefFormat(virBufferPtr buf,
     const char *type = virDomainControllerTypeToString(def->type);
     const char *model = NULL;
     const char *modelName = NULL;
-    bool pcihole64 = false, pciModel = false, pciTarget = false;
+    bool pcihole64 = false;
     virBuffer childBuf = VIR_BUFFER_INITIALIZER;
 
     virBufferAdjustIndent(&childBuf, virBufferGetIndent(buf, false) + 2);
@@ -21446,22 +21446,7 @@ virDomainControllerDefFormat(virBufferPtr buf,
     case VIR_DOMAIN_CONTROLLER_TYPE_PCI:
         if (def->opts.pciopts.pcihole64)
             pcihole64 = true;
-        if (def->opts.pciopts.modelName != VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_NONE)
-            pciModel = true;
-        if (def->opts.pciopts.chassisNr != -1 ||
-            def->opts.pciopts.chassis != -1 ||
-            def->opts.pciopts.port != -1 ||
-            def->opts.pciopts.busNr != -1 ||
-            def->opts.pciopts.numaNode != -1)
-            pciTarget = true;
-        break;
-
-    default:
-        break;
-    }
-
-    if (pciModel || pciTarget) {
-        if (pciModel) {
+        if (def->opts.pciopts.modelName != VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_NONE) {
             modelName = virDomainControllerPCIModelNameTypeToString(def->opts.pciopts.modelName);
             if (!modelName) {
                 virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -21471,8 +21456,11 @@ virDomainControllerDefFormat(virBufferPtr buf,
             }
             virBufferAsprintf(&childBuf, "<model name='%s'/>\n", modelName);
         }
-
-        if (pciTarget) {
+        if (def->opts.pciopts.chassisNr != -1 ||
+            def->opts.pciopts.chassis != -1 ||
+            def->opts.pciopts.port != -1 ||
+            def->opts.pciopts.busNr != -1 ||
+            def->opts.pciopts.numaNode != -1) {
             virBufferAddLit(&childBuf, "<target");
             if (def->opts.pciopts.chassisNr != -1)
                 virBufferAsprintf(&childBuf, " chassisNr='%d'",
@@ -21497,6 +21485,10 @@ virDomainControllerDefFormat(virBufferPtr buf,
                 virBufferAddLit(&childBuf, "</target>\n");
             }
         }
+        break;
+
+    default:
+        break;
     }
 
     virDomainControllerDriverFormat(&childBuf, def);
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 05/18] virDomainControllerDefFormat: move PCI model and target formatting
Posted by Pavel Hrdina 7 years, 11 months ago
On Tue, May 30, 2017 at 02:50:28PM +0200, Ján Tomko wrote:
> These can be formatted right when we know we will need them.
> No need for separate bool variables.
> ---
>  src/conf/domain_conf.c | 30 +++++++++++-------------------
>  1 file changed, 11 insertions(+), 19 deletions(-)

I don't think that we should mix formatting controller attributes with
controller sub-elements into one switch.

We can drop "VIR_DOMAIN_CONTROLLER_TYPE_PCI" from that switch and drop
all the pci(hole64|Model|Target) variables and use this instead:

if (def->type == VIR_DOMAIN_CONTROLLER_TYPE_PCI) {
    if (def->opts.pciopts.modelName != VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_NONE) {
        format model
    }

    if (def->opts.pciopts.chassisNr != -1 || ...) {
        format target
    }
}

...

if (def->type == VIR_DOMAIN_CONTROLLER_TYPE_PCI &&
    def->opts.pciopts.pcihole64) {
    format holes64    
}

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