[PATCH v2 09/11] vmx: convert to net model enum

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

 



Convert the vmware/vmx driver to net model enum, which requires
adding enum values for vlance, vmxnet, vmxnet2, and vmxnet3.

Signed-off-by: Cole Robinson <crobinso@xxxxxxxxxx>
---
 src/conf/domain_conf.c |  4 ++++
 src/conf/domain_conf.h |  4 ++++
 src/vmx/vmx.c          | 52 ++++++++++++++++++++++--------------------
 3 files changed, 35 insertions(+), 25 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 93b511d9bc..3b5f27300e 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -485,6 +485,10 @@ VIR_ENUM_IMPL(virDomainNetModel, VIR_DOMAIN_NET_MODEL_LAST,
               "spapr-vlan",
               "lan9118",
               "scm91c111",
+              "vlance",
+              "vmxnet",
+              "vmxnet2",
+              "vmxnet3",
 );
 
 VIR_ENUM_IMPL(virDomainNetBackend, VIR_DOMAIN_NET_BACKEND_TYPE_LAST,
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index ed95deebf1..71ab8e5bf4 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -974,6 +974,10 @@ typedef enum {
     VIR_DOMAIN_NET_MODEL_SPAPR_VLAN,
     VIR_DOMAIN_NET_MODEL_LAN9118,
     VIR_DOMAIN_NET_MODEL_SMC91C111,
+    VIR_DOMAIN_NET_MODEL_VLANCE,
+    VIR_DOMAIN_NET_MODEL_VMXNET,
+    VIR_DOMAIN_NET_MODEL_VMXNET2,
+    VIR_DOMAIN_NET_MODEL_VMXNET3,
 
     VIR_DOMAIN_NET_MODEL_LAST
 } virDomainNetModelType;
diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index 7a557847ba..eb68c3acc4 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -2546,6 +2546,8 @@ virVMXParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def)
     char networkName_name[48] = "";
     char *networkName = NULL;
 
+    int netmodel = VIR_DOMAIN_NET_MODEL_UNKNOWN;
+
     if (def == NULL || *def != NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
         return -1;
@@ -2630,11 +2632,17 @@ virVMXParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def)
     }
 
     if (virtualDev != NULL) {
-        if (STRCASENEQ(virtualDev, "vlance") &&
-            STRCASENEQ(virtualDev, "vmxnet") &&
-            STRCASENEQ(virtualDev, "vmxnet3") &&
-            STRCASENEQ(virtualDev, "e1000") &&
-            STRCASENEQ(virtualDev, "e1000e")) {
+        if (STRCASEEQ(virtualDev, "vlance")) {
+            netmodel = VIR_DOMAIN_NET_MODEL_VLANCE;
+        } else if (STRCASEEQ(virtualDev, "vmxnet")) {
+            netmodel = VIR_DOMAIN_NET_MODEL_VMXNET;
+        } else if (STRCASEEQ(virtualDev, "vmxnet3")) {
+            netmodel = VIR_DOMAIN_NET_MODEL_VMXNET3;
+        } else if (STRCASEEQ(virtualDev, "e1000")) {
+            netmodel = VIR_DOMAIN_NET_MODEL_E1000;
+        } else if (STRCASEEQ(virtualDev, "e1000e")) {
+            netmodel = VIR_DOMAIN_NET_MODEL_E1000E;
+        } else {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Expecting VMX entry '%s' to be 'vlance' or 'vmxnet' or "
                              "'vmxnet3' or 'e1000' or 'e1000e' but found '%s'"),
@@ -2642,12 +2650,8 @@ virVMXParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def)
             goto cleanup;
         }
 
-        if (STRCASEEQ(virtualDev, "vmxnet") && features == 15) {
-            VIR_FREE(virtualDev);
-
-            if (VIR_STRDUP(virtualDev, "vmxnet2") < 0)
-                goto cleanup;
-        }
+        if (netmodel == VIR_DOMAIN_NET_MODEL_VMXNET && features == 15)
+            netmodel = VIR_DOMAIN_NET_MODEL_VMXNET2;
     }
 
     /* vmx:networkName -> def:data.bridge.brname */
@@ -2697,10 +2701,7 @@ virVMXParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def)
         goto cleanup;
     }
 
-    if (virDomainNetSetModelString((*def), virtualDev) < 0)
-        goto cleanup;
-    VIR_FREE(virtualDev);
-
+    (*def)->model = netmodel;
     result = 0;
 
  cleanup:
@@ -3738,29 +3739,30 @@ virVMXFormatEthernet(virDomainNetDefPtr def, int controller,
     virBufferAsprintf(buffer, "ethernet%d.present = \"true\"\n", controller);
 
     /* def:model -> vmx:virtualDev, vmx:features */
-    if (virDomainNetGetModelString(def)) {
-        if (!virDomainNetStrcaseeqModelString(def, "vlance") &&
-            !virDomainNetStrcaseeqModelString(def, "vmxnet") &&
-            !virDomainNetStrcaseeqModelString(def, "vmxnet2") &&
-            !virDomainNetStrcaseeqModelString(def, "vmxnet3") &&
-            !virDomainNetStrcaseeqModelString(def, "e1000") &&
-            !virDomainNetStrcaseeqModelString(def, "e1000e")) {
+    if (def->model) {
+        if (def->model != VIR_DOMAIN_NET_MODEL_VLANCE &&
+            def->model != VIR_DOMAIN_NET_MODEL_VMXNET &&
+            def->model != VIR_DOMAIN_NET_MODEL_VMXNET2 &&
+            def->model != VIR_DOMAIN_NET_MODEL_VMXNET3 &&
+            def->model != VIR_DOMAIN_NET_MODEL_E1000 &&
+            def->model != VIR_DOMAIN_NET_MODEL_E1000E) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Expecting domain XML entry 'devices/interface/model' "
                              "to be 'vlance' or 'vmxnet' or 'vmxnet2' or 'vmxnet3' "
                              "or 'e1000' or 'e1000e' but found '%s'"),
-                            virDomainNetGetModelString(def));
+                            virDomainNetModelTypeToString(def->model));
             return -1;
         }
 
-        if (virDomainNetStrcaseeqModelString(def, "vmxnet2")) {
+        if (def->model == VIR_DOMAIN_NET_MODEL_VMXNET2) {
             virBufferAsprintf(buffer, "ethernet%d.virtualDev = \"vmxnet\"\n",
                               controller);
             virBufferAsprintf(buffer, "ethernet%d.features = \"15\"\n",
                               controller);
         } else {
             virBufferAsprintf(buffer, "ethernet%d.virtualDev = \"%s\"\n",
-                              controller, virDomainNetGetModelString(def));
+                              controller,
+                              virDomainNetModelTypeToString(def->model));
         }
     }
 
-- 
2.20.1

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

  Powered by Linux