]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: Make net model enum compare case insensitive
authorCole Robinson <crobinso@redhat.com>
Wed, 13 Mar 2019 15:02:41 +0000 (11:02 -0400)
committerCole Robinson <crobinso@redhat.com>
Tue, 16 Apr 2019 17:11:08 +0000 (13:11 -0400)
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.

Acked-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
src/conf/domain_conf.c
tests/qemuxml2argvdata/net-many-models.xml

index 7146b6fa15caa8d16ee61102c420f224997a1992..9c0bb19fb9ac99f0c6d42dc6aa3fed64c0668633 100644 (file)
@@ -29503,14 +29503,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"));
index 2b8f9b18eb88f4cb9a26dd0e386bdefad2198045..40fc5de06cffca2a75040f75657f7f0651606db1 100644 (file)
@@ -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'/>