render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
e6dfe8
From 5ca21a5c83e1c712d4d90f1981a23117ec8010f9 Mon Sep 17 00:00:00 2001
e6dfe8
Message-Id: <5ca21a5c83e1c712d4d90f1981a23117ec8010f9@dist-git>
e6dfe8
From: Pino Toscano <ptoscano@redhat.com>
e6dfe8
Date: Thu, 12 Apr 2018 17:26:18 +0200
e6dfe8
Subject: [PATCH] vmx: check for present/enabled devices earlier
e6dfe8
MIME-Version: 1.0
e6dfe8
Content-Type: text/plain; charset=UTF-8
e6dfe8
Content-Transfer-Encoding: 8bit
e6dfe8
e6dfe8
When parsing filesystems, network interfaces, serial ports, and
e6dfe8
parallel ports, check earlier whether they are present/enabled, delaying
e6dfe8
the allocation of the objects.
e6dfe8
e6dfe8
This is mostly a small optimization, with no behaviour change.
e6dfe8
e6dfe8
Signed-off-by: Pino Toscano <ptoscano@redhat.com>
e6dfe8
(cherry picked from commit 5d5430e1fc6f853f79da39fbef08e97bebffc8eb)
e6dfe8
e6dfe8
https: //bugzilla.redhat.com/show_bug.cgi?id=1566524
e6dfe8
Signed-off-by: Pino Toscano <ptoscano@redhat.com>
e6dfe8
Reviewed-by: Ján Tomko <jtomko@redhat.com>
e6dfe8
---
e6dfe8
 src/vmx/vmx.c | 92 +++++++++++++++++----------------------------------
e6dfe8
 1 file changed, 30 insertions(+), 62 deletions(-)
e6dfe8
e6dfe8
diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
e6dfe8
index 622f22f037..85bf195cd7 100644
e6dfe8
--- a/src/vmx/vmx.c
e6dfe8
+++ b/src/vmx/vmx.c
e6dfe8
@@ -2439,11 +2439,6 @@ int virVMXParseFileSystem(virConfPtr conf, int number, virDomainFSDefPtr *def)
e6dfe8
         return -1;
e6dfe8
     }
e6dfe8
 
e6dfe8
-    if (!(*def = virDomainFSDefNew()))
e6dfe8
-        return -1;
e6dfe8
-
e6dfe8
-    (*def)->type = VIR_DOMAIN_FS_TYPE_MOUNT;
e6dfe8
-
e6dfe8
     snprintf(prefix, sizeof(prefix), "sharedFolder%d", number);
e6dfe8
 
e6dfe8
     VMX_BUILD_NAME(present);
e6dfe8
@@ -2454,14 +2449,19 @@ int virVMXParseFileSystem(virConfPtr conf, int number, virDomainFSDefPtr *def)
e6dfe8
 
e6dfe8
     /* vmx:present */
e6dfe8
     if (virVMXGetConfigBoolean(conf, present_name, &present, false, true) < 0)
e6dfe8
-        goto cleanup;
e6dfe8
+        return -1;
e6dfe8
 
e6dfe8
     /* vmx:enabled */
e6dfe8
     if (virVMXGetConfigBoolean(conf, enabled_name, &enabled, false, true) < 0)
e6dfe8
-        goto cleanup;
e6dfe8
+        return -1;
e6dfe8
 
e6dfe8
     if (!(present && enabled))
e6dfe8
-        goto ignore;
e6dfe8
+        return 0;
e6dfe8
+
e6dfe8
+    if (!(*def = virDomainFSDefNew()))
e6dfe8
+        return -1;
e6dfe8
+
e6dfe8
+    (*def)->type = VIR_DOMAIN_FS_TYPE_MOUNT;
e6dfe8
 
e6dfe8
     /* vmx:hostPath */
e6dfe8
     if (virVMXGetConfigString(conf, hostPath_name, &hostPath, false) < 0)
e6dfe8
@@ -2497,14 +2497,6 @@ int virVMXParseFileSystem(virConfPtr conf, int number, virDomainFSDefPtr *def)
e6dfe8
     VIR_FREE(guestName);
e6dfe8
 
e6dfe8
     return result;
e6dfe8
-
e6dfe8
- ignore:
e6dfe8
-    virDomainFSDefFree(*def);
e6dfe8
-    *def = NULL;
e6dfe8
-
e6dfe8
-    result = 0;
e6dfe8
-
e6dfe8
-    goto cleanup;
e6dfe8
 }
e6dfe8
 
e6dfe8
 
e6dfe8
@@ -2557,9 +2549,6 @@ virVMXParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def)
e6dfe8
         return -1;
e6dfe8
     }
e6dfe8
 
e6dfe8
-    if (VIR_ALLOC(*def) < 0)
e6dfe8
-        return -1;
e6dfe8
-
e6dfe8
     snprintf(prefix, sizeof(prefix), "ethernet%d", controller);
e6dfe8
 
e6dfe8
     VMX_BUILD_NAME(present);
e6dfe8
@@ -2575,17 +2564,20 @@ virVMXParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def)
e6dfe8
 
e6dfe8
     /* vmx:present */
e6dfe8
     if (virVMXGetConfigBoolean(conf, present_name, &present, false, true) < 0)
e6dfe8
-        goto cleanup;
e6dfe8
+        return -1;
e6dfe8
 
e6dfe8
     /* vmx:startConnected */
e6dfe8
     if (virVMXGetConfigBoolean(conf, startConnected_name, &startConnected,
e6dfe8
                                true, true) < 0) {
e6dfe8
-        goto cleanup;
e6dfe8
+        return -1;
e6dfe8
     }
e6dfe8
 
e6dfe8
     /* FIXME: Need to distiguish between active and inactive domains here */
e6dfe8
     if (! present/* && ! startConnected*/)
e6dfe8
-        goto ignore;
e6dfe8
+        return 0;
e6dfe8
+
e6dfe8
+    if (VIR_ALLOC(*def) < 0)
e6dfe8
+        return -1;
e6dfe8
 
e6dfe8
     /* vmx:connectionType -> def:type */
e6dfe8
     if (virVMXGetConfigString(conf, connectionType_name, &connectionType,
e6dfe8
@@ -2726,14 +2718,6 @@ virVMXParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def)
e6dfe8
     VIR_FREE(vnet);
e6dfe8
 
e6dfe8
     return result;
e6dfe8
-
e6dfe8
- ignore:
e6dfe8
-    virDomainNetDefFree(*def);
e6dfe8
-    *def = NULL;
e6dfe8
-
e6dfe8
-    result = 0;
e6dfe8
-
e6dfe8
-    goto cleanup;
e6dfe8
 }
e6dfe8
 
e6dfe8
 
e6dfe8
@@ -2773,11 +2757,6 @@ virVMXParseSerial(virVMXContext *ctx, virConfPtr conf, int port,
e6dfe8
         return -1;
e6dfe8
     }
e6dfe8
 
e6dfe8
-    if (!(*def = virDomainChrDefNew(NULL)))
e6dfe8
-        return -1;
e6dfe8
-
e6dfe8
-    (*def)->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL;
e6dfe8
-
e6dfe8
     snprintf(prefix, sizeof(prefix), "serial%d", port);
e6dfe8
 
e6dfe8
     VMX_BUILD_NAME(present);
e6dfe8
@@ -2788,17 +2767,22 @@ virVMXParseSerial(virVMXContext *ctx, virConfPtr conf, int port,
e6dfe8
 
e6dfe8
     /* vmx:present */
e6dfe8
     if (virVMXGetConfigBoolean(conf, present_name, &present, false, true) < 0)
e6dfe8
-        goto cleanup;
e6dfe8
+        return -1;
e6dfe8
 
e6dfe8
     /* vmx:startConnected */
e6dfe8
     if (virVMXGetConfigBoolean(conf, startConnected_name, &startConnected,
e6dfe8
                                true, true) < 0) {
e6dfe8
-        goto cleanup;
e6dfe8
+        return -1;
e6dfe8
     }
e6dfe8
 
e6dfe8
     /* FIXME: Need to distiguish between active and inactive domains here */
e6dfe8
     if (! present/* && ! startConnected*/)
e6dfe8
-        goto ignore;
e6dfe8
+        return 0;
e6dfe8
+
e6dfe8
+    if (!(*def = virDomainChrDefNew(NULL)))
e6dfe8
+        return -1;
e6dfe8
+
e6dfe8
+    (*def)->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL;
e6dfe8
 
e6dfe8
     /* vmx:fileType -> def:type */
e6dfe8
     if (virVMXGetConfigString(conf, fileType_name, &fileType, true) < 0)
e6dfe8
@@ -2919,14 +2903,6 @@ virVMXParseSerial(virVMXContext *ctx, virConfPtr conf, int port,
e6dfe8
     virURIFree(parsedUri);
e6dfe8
 
e6dfe8
     return result;
e6dfe8
-
e6dfe8
- ignore:
e6dfe8
-    virDomainChrDefFree(*def);
e6dfe8
-    *def = NULL;
e6dfe8
-
e6dfe8
-    result = 0;
e6dfe8
-
e6dfe8
-    goto cleanup;
e6dfe8
 }
e6dfe8
 
e6dfe8
 
e6dfe8
@@ -2961,11 +2937,6 @@ virVMXParseParallel(virVMXContext *ctx, virConfPtr conf, int port,
e6dfe8
         return -1;
e6dfe8
     }
e6dfe8
 
e6dfe8
-    if (!(*def = virDomainChrDefNew(NULL)))
e6dfe8
-        return -1;
e6dfe8
-
e6dfe8
-    (*def)->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL;
e6dfe8
-
e6dfe8
     snprintf(prefix, sizeof(prefix), "parallel%d", port);
e6dfe8
 
e6dfe8
     VMX_BUILD_NAME(present);
e6dfe8
@@ -2975,17 +2946,22 @@ virVMXParseParallel(virVMXContext *ctx, virConfPtr conf, int port,
e6dfe8
 
e6dfe8
     /* vmx:present */
e6dfe8
     if (virVMXGetConfigBoolean(conf, present_name, &present, false, true) < 0)
e6dfe8
-        goto cleanup;
e6dfe8
+        return -1;
e6dfe8
 
e6dfe8
     /* vmx:startConnected */
e6dfe8
     if (virVMXGetConfigBoolean(conf, startConnected_name, &startConnected,
e6dfe8
                                true, true) < 0) {
e6dfe8
-        goto cleanup;
e6dfe8
+        return -1;
e6dfe8
     }
e6dfe8
 
e6dfe8
     /* FIXME: Need to distiguish between active and inactive domains here */
e6dfe8
     if (! present/* && ! startConnected*/)
e6dfe8
-        goto ignore;
e6dfe8
+        return 0;
e6dfe8
+
e6dfe8
+    if (!(*def = virDomainChrDefNew(NULL)))
e6dfe8
+        return -1;
e6dfe8
+
e6dfe8
+    (*def)->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL;
e6dfe8
 
e6dfe8
     /* vmx:fileType -> def:type */
e6dfe8
     if (virVMXGetConfigString(conf, fileType_name, &fileType, false) < 0)
e6dfe8
@@ -3029,14 +3005,6 @@ virVMXParseParallel(virVMXContext *ctx, virConfPtr conf, int port,
e6dfe8
     VIR_FREE(fileName);
e6dfe8
 
e6dfe8
     return result;
e6dfe8
-
e6dfe8
- ignore:
e6dfe8
-    virDomainChrDefFree(*def);
e6dfe8
-    *def = NULL;
e6dfe8
-
e6dfe8
-    result = 0;
e6dfe8
-
e6dfe8
-    goto cleanup;
e6dfe8
 }
e6dfe8
 
e6dfe8
 
e6dfe8
-- 
e6dfe8
2.17.0
e6dfe8