diff mbox series

[v2,07/11] qemu: Partially convert to net model enum

Message ID bc0aa4651091d9bc438c274b40211eec9e1baa52.1552492022.git.crobinso@redhat.com
State Accepted
Commit 41b002f934a22a6875a9bda3e41fca40029c4f3e
Headers show
Series conf: partial net model enum conversion | expand

Commit Message

Cole Robinson March 13, 2019, 3:51 p.m. UTC
This converts the qemu driver to the net model enum, for all
the model values that we have hardcoded for various checks,
which adds e1000e, virtio-transitional, virtio-non-transitional,
usb-net, spapr-vlan, lan9118, smc91c111

Because the qemu driver has historically also allowed the raw
model string onto the qemu command line, this isn't a full
conversion. Unwinding that will require more thought. However
for all new driver code we should be adding explicit enum
values for any model name we have special handling for.

Remove the now unused virDomainNetStreqModelString

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

---
 src/conf/domain_conf.c         | 22 ++++++++++------------
 src/conf/domain_conf.h         |  9 +++++++--
 src/libvirt_private.syms       |  1 -
 src/qemu/qemu_command.c        |  6 ++----
 src/qemu/qemu_domain.c         | 29 +++++++++++++----------------
 src/qemu/qemu_domain_address.c | 12 ++++++------
 6 files changed, 38 insertions(+), 41 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 854b8eb045..a5882f27d9 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -478,6 +478,13 @@  VIR_ENUM_IMPL(virDomainNetModel, VIR_DOMAIN_NET_MODEL_LAST,
               "rtl8139",
               "virtio",
               "e1000",
+              "e1000e",
+              "virtio-transitional",
+              "virtio-non-transitional",
+              "usb-net",
+              "spapr-vlan",
+              "lan9118",
+              "scm91c111",
 );
 
 VIR_ENUM_IMPL(virDomainNetBackend, VIR_DOMAIN_NET_BACKEND_TYPE_LAST,
@@ -29413,15 +29420,6 @@  virDomainNetSetModelString(virDomainNetDefPtr net,
     return 0;
 }
 
-int
-virDomainNetStreqModelString(const virDomainNetDef *net,
-                             const char *model)
-{
-    if (net->model)
-        return net->model == virDomainNetModelTypeFromString(model);
-    return STREQ_NULLABLE(net->modelstr, model);
-}
-
 int
 virDomainNetStrcaseeqModelString(const virDomainNetDef *net,
                                  const char *model)
@@ -29434,9 +29432,9 @@  virDomainNetStrcaseeqModelString(const virDomainNetDef *net,
 bool
 virDomainNetIsVirtioModel(const virDomainNetDef *net)
 {
-    return (virDomainNetStreqModelString(net, "virtio") ||
-            virDomainNetStreqModelString(net, "virtio-transitional") ||
-            virDomainNetStreqModelString(net, "virtio-non-transitional"));
+    return (net->model == VIR_DOMAIN_NET_MODEL_VIRTIO ||
+            net->model == VIR_DOMAIN_NET_MODEL_VIRTIO_TRANSITIONAL ||
+            net->model == VIR_DOMAIN_NET_MODEL_VIRTIO_NON_TRANSITIONAL);
 }
 
 
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 780f878fd8..ed95deebf1 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -967,6 +967,13 @@  typedef enum {
     VIR_DOMAIN_NET_MODEL_RTL8139,
     VIR_DOMAIN_NET_MODEL_VIRTIO,
     VIR_DOMAIN_NET_MODEL_E1000,
+    VIR_DOMAIN_NET_MODEL_E1000E,
+    VIR_DOMAIN_NET_MODEL_VIRTIO_TRANSITIONAL,
+    VIR_DOMAIN_NET_MODEL_VIRTIO_NON_TRANSITIONAL,
+    VIR_DOMAIN_NET_MODEL_USB_NET,
+    VIR_DOMAIN_NET_MODEL_SPAPR_VLAN,
+    VIR_DOMAIN_NET_MODEL_LAN9118,
+    VIR_DOMAIN_NET_MODEL_SMC91C111,
 
     VIR_DOMAIN_NET_MODEL_LAST
 } virDomainNetModelType;
@@ -3329,8 +3336,6 @@  bool virDomainNetGetActualTrustGuestRxFilters(virDomainNetDefPtr iface);
 const char *virDomainNetGetModelString(const virDomainNetDef *net);
 int virDomainNetSetModelString(virDomainNetDefPtr et,
                                const char *model);
-int virDomainNetStreqModelString(const virDomainNetDef *net,
-                                 const char *model);
 int virDomainNetStrcaseeqModelString(const virDomainNetDef *net,
                                      const char *model);
 bool virDomainNetIsVirtioModel(const virDomainNetDef *net);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 3a0699d724..2639446720 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -487,7 +487,6 @@  virDomainNetResolveActualType;
 virDomainNetSetDeviceImpl;
 virDomainNetSetModelString;
 virDomainNetStrcaseeqModelString;
-virDomainNetStreqModelString;
 virDomainNetTypeFromString;
 virDomainNetTypeSharesHostView;
 virDomainNetTypeToString;
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 0388ebc5af..a5deffbef2 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -479,10 +479,8 @@  qemuBuildVirtioDevStr(virBufferPtr buf,
             break;
 
         case VIR_DOMAIN_DEVICE_NET:
-            has_tmodel = virDomainNetStreqModelString(device.data.net,
-                                                      "virtio-transitional");
-            has_ntmodel = virDomainNetStreqModelString(device.data.net,
-                                                       "virtio-non-transitional");
+            has_tmodel = device.data.net->model == VIR_DOMAIN_NET_MODEL_VIRTIO_TRANSITIONAL;
+            has_ntmodel = device.data.net->model == VIR_DOMAIN_NET_MODEL_VIRTIO_NON_TRANSITIONAL;
             break;
 
         case VIR_DOMAIN_DEVICE_HOSTDEV:
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 7b001bca52..6718dfbc22 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -6230,49 +6230,49 @@  qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
  * is NULL this function may return NULL if the default model depends on the
  * capabilities.
  */
-static const char *
+static int
 qemuDomainDefaultNetModel(const virDomainDef *def,
                           virQEMUCapsPtr qemuCaps)
 {
     if (ARCH_IS_S390(def->os.arch))
-        return "virtio";
+        return VIR_DOMAIN_NET_MODEL_VIRTIO;
 
     if (def->os.arch == VIR_ARCH_ARMV6L ||
         def->os.arch == VIR_ARCH_ARMV7L ||
         def->os.arch == VIR_ARCH_AARCH64) {
         if (STREQ(def->os.machine, "versatilepb"))
-            return "smc91c111";
+            return VIR_DOMAIN_NET_MODEL_SMC91C111;
 
         if (qemuDomainIsARMVirt(def))
-            return "virtio";
+            return VIR_DOMAIN_NET_MODEL_VIRTIO;
 
         /* Incomplete. vexpress (and a few others) use this, but not all
          * arm boards */
-        return "lan9118";
+        return VIR_DOMAIN_NET_MODEL_LAN9118;
     }
 
     /* virtio is a sensible default for RISC-V virt guests */
     if (qemuDomainIsRISCVVirt(def))
-        return "virtio";
+        return VIR_DOMAIN_NET_MODEL_VIRTIO;
 
     /* In all other cases the model depends on the capabilities. If they were
      * not provided don't report any default. */
     if (!qemuCaps)
-        return NULL;
+        return VIR_DOMAIN_NET_MODEL_UNKNOWN;
 
     /* Try several network devices in turn; each of these devices is
      * less likely be supported out-of-the-box by the guest operating
      * system than the previous one */
     if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_RTL8139))
-        return "rtl8139";
+        return VIR_DOMAIN_NET_MODEL_RTL8139;
     else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_E1000))
-        return "e1000";
+        return VIR_DOMAIN_NET_MODEL_E1000;
     else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VIRTIO_NET))
-        return "virtio";
+        return VIR_DOMAIN_NET_MODEL_VIRTIO;
 
     /* We've had no luck detecting support for any network device,
      * but we have to return something: might as well be rtl8139 */
-    return "rtl8139";
+    return VIR_DOMAIN_NET_MODEL_RTL8139;
 }
 
 
@@ -6727,11 +6727,8 @@  qemuDomainDeviceNetDefPostParse(virDomainNetDefPtr net,
                                 virQEMUCapsPtr qemuCaps)
 {
     if (net->type != VIR_DOMAIN_NET_TYPE_HOSTDEV &&
-        !virDomainNetGetModelString(net)) {
-        if (virDomainNetSetModelString(net,
-                       qemuDomainDefaultNetModel(def, qemuCaps)) < 0)
-            return -1;
-    }
+        !virDomainNetGetModelString(net))
+        net->model = qemuDomainDefaultNetModel(def, qemuCaps);
 
     return 0;
 }
diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
index 380c5bffcc..976ddaf3e0 100644
--- a/src/qemu/qemu_domain_address.c
+++ b/src/qemu/qemu_domain_address.c
@@ -230,7 +230,7 @@  qemuDomainAssignSpaprVIOAddresses(virDomainDefPtr def)
     for (i = 0; i < def->nnets; i++) {
         virDomainNetDefPtr net = def->nets[i];
 
-        if (virDomainNetStreqModelString(net, "spapr-vlan"))
+        if (net->model == VIR_DOMAIN_NET_MODEL_SPAPR_VLAN)
             net->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO;
 
         if (qemuDomainAssignSpaprVIOAddress(def, &net->info, VIO_ADDR_NET) < 0)
@@ -715,18 +715,18 @@  qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
          * addresses for other hostdev devices.
          */
         if (net->type == VIR_DOMAIN_NET_TYPE_HOSTDEV ||
-            virDomainNetStreqModelString(net, "usb-net")) {
+            net->model == VIR_DOMAIN_NET_MODEL_USB_NET) {
             return 0;
         }
 
-        if (virDomainNetStreqModelString(net, "virtio") ||
-            virDomainNetStreqModelString(net, "virtio-non-transitional"))
+        if (net->model == VIR_DOMAIN_NET_MODEL_VIRTIO ||
+            net->model == VIR_DOMAIN_NET_MODEL_VIRTIO_NON_TRANSITIONAL)
             return virtioFlags;
 
-        if (virDomainNetStreqModelString(net, "virtio-transitional"))
+        if (net->model == VIR_DOMAIN_NET_MODEL_VIRTIO_TRANSITIONAL)
             return pciFlags;
 
-        if (virDomainNetStreqModelString(net, "e1000e"))
+        if (net->model == VIR_DOMAIN_NET_MODEL_E1000E)
             return pcieFlags;
 
         return pciFlags;