]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virnetdevvportprofile: Turn 'virtPortType' of virNetDevVPortProfile into proper enum...
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 23 Jul 2025 11:00:29 +0000 (13:00 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 1 Aug 2025 10:24:20 +0000 (12:24 +0200)
Convert the member to the appropriate type, fix few missing cases
in switch() and switch to virXMLPropEnum() in parsing.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/conf/netdev_vport_profile_conf.c
src/hypervisor/virhostdev.c
src/qemu/qemu_migration_cookie.c
src/util/virnetdevvportprofile.c
src/util/virnetdevvportprofile.h

index f7928a5679b4d28f719484c857abc300040fd1f1..6106130a3953ebc018ba98ef2facd474489b9744 100644 (file)
 virNetDevVPortProfile *
 virNetDevVPortProfileParse(xmlNodePtr node, unsigned int flags)
 {
-    g_autofree char *virtPortType = NULL;
     g_autofree virNetDevVPortProfile *virtPort = NULL;
     xmlNodePtr parameters;
 
     virtPort = g_new0(virNetDevVPortProfile, 1);
 
-    if ((virtPortType = virXMLPropString(node, "type")) &&
-        (virtPort->virtPortType = virNetDevVPortTypeFromString(virtPortType)) <= 0) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("unknown virtualport type %1$s"), virtPortType);
+    if (virXMLPropEnum(node, "type",
+                       virNetDevVPortTypeFromString,
+                       VIR_XML_PROP_NONZERO,
+                       &virtPort->virtPortType) < 0) {
         return NULL;
     }
 
index 0a1d8500d46612e427c19f892944494ae1c4184a..7d7df4418d1159ea23632b48a57f8422788310ce 100644 (file)
@@ -370,6 +370,7 @@ virHostdevNetConfigVirtPortProfile(const char *linkdev, int vf,
     case VIR_NETDEV_VPORT_PROFILE_NONE:
     case VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH:
     case VIR_NETDEV_VPORT_PROFILE_8021QBG:
+    case VIR_NETDEV_VPORT_PROFILE_MIDONET:
     case VIR_NETDEV_VPORT_PROFILE_LAST:
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("virtualport type %1$s is currently not supported on interfaces of type hostdev"),
index 90cc079c1a294caaffa0be4ab80916921a48c02f..01529c99b864cb4beae9ae42402ede159187c98d 100644 (file)
@@ -283,6 +283,7 @@ qemuMigrationCookieNetworkAlloc(virQEMUDriver *driver G_GNUC_UNUSED,
             case VIR_NETDEV_VPORT_PROFILE_NONE:
             case VIR_NETDEV_VPORT_PROFILE_8021QBG:
             case VIR_NETDEV_VPORT_PROFILE_8021QBH:
+            case VIR_NETDEV_VPORT_PROFILE_MIDONET:
                break;
             case VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH:
                 if (virNetDevOpenvswitchGetMigrateData(&mig->net[i].portdata,
@@ -293,6 +294,7 @@ qemuMigrationCookieNetworkAlloc(virQEMUDriver *driver G_GNUC_UNUSED,
                         return NULL;
                 }
                 break;
+            case VIR_NETDEV_VPORT_PROFILE_LAST:
             default:
                 break;
             }
index 221e0888b31bb54a2aa9d47b46245d403354fc09..d6674390a74f049d7d77e7e0f6142d076e76a0d6 100644 (file)
@@ -109,11 +109,13 @@ virNetDevVPortProfileEqual(const virNetDevVPortProfile *a, const virNetDevVPortP
         break;
 
     case VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH:
+    case VIR_NETDEV_VPORT_PROFILE_MIDONET:
         if (STRNEQ(a->profileID, b->profileID) ||
             memcmp(a->interfaceID, b->interfaceID, VIR_UUID_BUFLEN) != 0)
             return false;
         break;
 
+    case VIR_NETDEV_VPORT_PROFILE_LAST:
     default:
         break;
     }
@@ -151,7 +153,7 @@ virNetDevVPortProfileCheckComplete(virNetDevVPortProfile *virtport,
 {
     const char *missing = NULL;
 
-    if (!virtport || virtport->virtPortType == VIR_NETDEV_VPORT_PROFILE_NONE)
+    if (!virtport)
         return 0;
 
     switch (virtport->virtPortType) {
@@ -201,6 +203,10 @@ virNetDevVPortProfileCheckComplete(virNetDevVPortProfile *virtport,
        if (!virtport->interfaceID_specified)
           missing = "interfaceid";
        break;
+
+    case VIR_NETDEV_VPORT_PROFILE_NONE:
+    case VIR_NETDEV_VPORT_PROFILE_LAST:
+       break;
     }
 
     if (missing) {
@@ -224,7 +230,7 @@ virNetDevVPortProfileCheckNoExtras(const virNetDevVPortProfile *virtport)
 {
     const char *extra = NULL;
 
-    if (!virtport || virtport->virtPortType == VIR_NETDEV_VPORT_PROFILE_NONE)
+    if (!virtport)
         return 0;
 
     switch (virtport->virtPortType) {
@@ -249,6 +255,7 @@ virNetDevVPortProfileCheckNoExtras(const virNetDevVPortProfile *virtport)
         break;
 
     case VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH:
+    case VIR_NETDEV_VPORT_PROFILE_MIDONET:
         if (virtport->managerID_specified)
             extra = "managerid";
         else if (virtport->typeID_specified)
@@ -258,6 +265,10 @@ virNetDevVPortProfileCheckNoExtras(const virNetDevVPortProfile *virtport)
         else if (virtport->instanceID_specified)
             extra = "instanceid";
         break;
+
+    case VIR_NETDEV_VPORT_PROFILE_NONE:
+    case VIR_NETDEV_VPORT_PROFILE_LAST:
+        break;
     }
 
     if (extra) {
@@ -1238,6 +1249,7 @@ virNetDevVPortProfileAssociate(const char *macvtap_ifname,
     switch (virtPort->virtPortType) {
     case VIR_NETDEV_VPORT_PROFILE_NONE:
     case VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH:
+    case VIR_NETDEV_VPORT_PROFILE_MIDONET:
     case VIR_NETDEV_VPORT_PROFILE_LAST:
         break;
 
@@ -1303,6 +1315,7 @@ virNetDevVPortProfileDisassociate(const char *macvtap_ifname,
     switch (virtPort->virtPortType) {
     case VIR_NETDEV_VPORT_PROFILE_NONE:
     case VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH:
+    case VIR_NETDEV_VPORT_PROFILE_MIDONET:
     case VIR_NETDEV_VPORT_PROFILE_LAST:
         break;
 
index 43ccb891e75195547bbfe95febabeb74ef8942ac..c15fd4163ab5ad96d30e4a5ebdd477c00b79c35e 100644 (file)
@@ -53,7 +53,7 @@ VIR_ENUM_DECL(virNetDevVPortProfileOp);
 /* profile data for macvtap (VEPA) and openvswitch */
 typedef struct _virNetDevVPortProfile virNetDevVPortProfile;
 struct _virNetDevVPortProfile {
-    int           virtPortType; /* enum virNetDevVPortProfile */
+    virNetDevVPortProfileType virtPortType;
     /* these members are used when virtPortType == 802.1Qbg */
     uint8_t       managerID;
     bool          managerID_specified;