[PATCH 0/2] virnetdevvportprofile: Misc cleanups

*** BLURB HERE *** Michal Prívozník (2): virnetdevvportprofile: Drop explicit enum virNetDevVPortProfile declaration virnetdevvportprofile: Turn 'virtPortType' of virNetDevVPortProfile into proper enum type src/conf/netdev_vport_profile_conf.c | 11 +++++------ src/hypervisor/virhostdev.c | 1 + src/qemu/qemu_migration_cookie.c | 2 ++ src/util/virnetdevvportprofile.c | 19 ++++++++++++++++--- src/util/virnetdevvportprofile.h | 4 ++-- 5 files changed, 26 insertions(+), 11 deletions(-) -- 2.49.1

From: Michal Privoznik <mprivozn@redhat.com> The virNetDevVPortProfile enum is both explicitly declared and also typedef-ed. This repetition is redundant. Just use typedef. To make matters worse, there's another type with the same name, but because in the code, those few places used 'enum virNetDevVPortProfile var;' to declare variables compilers didn't complain. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/conf/netdev_vport_profile_conf.c | 2 +- src/util/virnetdevvportprofile.c | 2 +- src/util/virnetdevvportprofile.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/conf/netdev_vport_profile_conf.c b/src/conf/netdev_vport_profile_conf.c index 523d9b642c..f7928a5679 100644 --- a/src/conf/netdev_vport_profile_conf.c +++ b/src/conf/netdev_vport_profile_conf.c @@ -169,7 +169,7 @@ void virNetDevVPortProfileFormat(const virNetDevVPortProfile *virtPort, virBuffer *buf) { - enum virNetDevVPortProfile type; + virNetDevVPortProfileType type; bool noParameters; if (!virtPort) diff --git a/src/util/virnetdevvportprofile.c b/src/util/virnetdevvportprofile.c index c755fa79ec..221e0888b3 100644 --- a/src/util/virnetdevvportprofile.c +++ b/src/util/virnetdevvportprofile.c @@ -279,7 +279,7 @@ static int virNetDevVPortProfileMerge(virNetDevVPortProfile *orig, const virNetDevVPortProfile *mods) { - enum virNetDevVPortProfile otype; + virNetDevVPortProfileType otype; if (!orig || !mods) return 0; diff --git a/src/util/virnetdevvportprofile.h b/src/util/virnetdevvportprofile.h index 600b2093c5..43ccb891e7 100644 --- a/src/util/virnetdevvportprofile.h +++ b/src/util/virnetdevvportprofile.h @@ -25,7 +25,7 @@ #define LIBVIRT_IFLA_VF_PORT_PROFILE_MAX 40 -typedef enum virNetDevVPortProfile { +typedef enum { VIR_NETDEV_VPORT_PROFILE_NONE, VIR_NETDEV_VPORT_PROFILE_8021QBG, VIR_NETDEV_VPORT_PROFILE_8021QBH, -- 2.49.1

From: Michal Privoznik <mprivozn@redhat.com> 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> --- src/conf/netdev_vport_profile_conf.c | 9 ++++----- src/hypervisor/virhostdev.c | 1 + src/qemu/qemu_migration_cookie.c | 2 ++ src/util/virnetdevvportprofile.c | 17 +++++++++++++++-- src/util/virnetdevvportprofile.h | 2 +- 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/conf/netdev_vport_profile_conf.c b/src/conf/netdev_vport_profile_conf.c index f7928a5679..6106130a39 100644 --- a/src/conf/netdev_vport_profile_conf.c +++ b/src/conf/netdev_vport_profile_conf.c @@ -28,16 +28,15 @@ 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; } diff --git a/src/hypervisor/virhostdev.c b/src/hypervisor/virhostdev.c index 0a1d8500d4..7d7df4418d 100644 --- a/src/hypervisor/virhostdev.c +++ b/src/hypervisor/virhostdev.c @@ -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"), diff --git a/src/qemu/qemu_migration_cookie.c b/src/qemu/qemu_migration_cookie.c index 90cc079c1a..01529c99b8 100644 --- a/src/qemu/qemu_migration_cookie.c +++ b/src/qemu/qemu_migration_cookie.c @@ -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; } diff --git a/src/util/virnetdevvportprofile.c b/src/util/virnetdevvportprofile.c index 221e0888b3..d6674390a7 100644 --- a/src/util/virnetdevvportprofile.c +++ b/src/util/virnetdevvportprofile.c @@ -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; diff --git a/src/util/virnetdevvportprofile.h b/src/util/virnetdevvportprofile.h index 43ccb891e7..c15fd4163a 100644 --- a/src/util/virnetdevvportprofile.h +++ b/src/util/virnetdevvportprofile.h @@ -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; -- 2.49.1

On a Wednesday in 2025, Michal Privoznik via Devel wrote:
*** BLURB HERE ***
Michal Prívozník (2): virnetdevvportprofile: Drop explicit enum virNetDevVPortProfile declaration virnetdevvportprofile: Turn 'virtPortType' of virNetDevVPortProfile into proper enum type
src/conf/netdev_vport_profile_conf.c | 11 +++++------ src/hypervisor/virhostdev.c | 1 + src/qemu/qemu_migration_cookie.c | 2 ++ src/util/virnetdevvportprofile.c | 19 ++++++++++++++++--- src/util/virnetdevvportprofile.h | 4 ++-- 5 files changed, 26 insertions(+), 11 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano
participants (2)
-
Ján Tomko
-
Michal Privoznik