diff mbox series

[v2,08/11] conf: Make net model enum compare case insensitive

Message ID 2397df40619875bb6e65040ce45880d59a035fca.1552492022.git.crobinso@redhat.com
State Accepted
Commit 79c8bc7d6e460cff7fdc30186bf1d99f1c902121
Headers show
Series conf: partial net model enum conversion | expand

Commit Message

Cole Robinson March 13, 2019, 3:51 p.m. UTC
vbox and vmx drivers do net case insensitive net model comparisons,
so for example 'VMXNET3' and 'vmxnet3' and 'VmxNeT3' in the XML will
translate to the same driver configuration. To convert these drivers
to use net model enum, we will need to do case insensitive comparisons
as well.

Essentially we implement virEnumToString, but with case insensitive
comparison. XML will always be formatted with the enum model string
we track internally, but we will accept any case insensitive variant.

Signed-off-by: Cole Robinson <crobinso@redhat.com>

---
 src/conf/domain_conf.c                     | 12 +++++++++---
 tests/qemuxml2argvdata/net-many-models.xml |  3 ++-
 2 files changed, 11 insertions(+), 4 deletions(-)

-- 
2.20.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
diff mbox series

Patch

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index a5882f27d9..93b511d9bc 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -29401,14 +29401,20 @@  int
 virDomainNetSetModelString(virDomainNetDefPtr net,
                            const char *model)
 {
-    VIR_FREE(net->modelstr);
-    if ((net->model = virDomainNetModelTypeFromString(model)) >= 0)
-        return 0;
+    size_t i;
 
+    VIR_FREE(net->modelstr);
     net->model = VIR_DOMAIN_NET_MODEL_UNKNOWN;
     if (!model)
         return 0;
 
+    for (i = 0; i < ARRAY_CARDINALITY(virDomainNetModelTypeList); i++) {
+        if (STRCASEEQ(virDomainNetModelTypeList[i], model)) {
+            net->model = i;
+            return 0;
+        }
+    }
+
     if (strspn(model, NET_MODEL_CHARS) < strlen(model)) {
         virReportError(VIR_ERR_INVALID_ARG, "%s",
                        _("Model name contains invalid characters"));
diff --git a/tests/qemuxml2argvdata/net-many-models.xml b/tests/qemuxml2argvdata/net-many-models.xml
index 2b8f9b18eb..40fc5de06c 100644
--- a/tests/qemuxml2argvdata/net-many-models.xml
+++ b/tests/qemuxml2argvdata/net-many-models.xml
@@ -21,7 +21,8 @@ 
     </interface>
     <interface type='user'>
       <mac address='00:11:22:33:44:58'/>
-      <model type='virtio'/>
+      <!-- explicitly testing case insensitive model compare -->
+      <model type='ViRtIo'/>
     </interface>
     <interface type='user'>
       <mac address='00:11:22:33:44:58'/>