conf: Rewrite virNetDevVPortProfileCopy

This makes it nicer to use as since it cannot fail shortens the usage in all
callers.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Martin Kletzander 2022-08-11 14:59:09 +02:00
parent 9c9fc39ded
commit f519f77d81
3 changed files with 16 additions and 16 deletions

View File

@ -29348,8 +29348,7 @@ virDomainNetDefToNetworkPort(virDomainDef *dom,
memcpy(&port->mac, &iface->mac, VIR_MAC_BUFLEN); memcpy(&port->mac, &iface->mac, VIR_MAC_BUFLEN);
if (virNetDevVPortProfileCopy(&port->virtPortProfile, iface->virtPortProfile) < 0) port->virtPortProfile = virNetDevVPortProfileCopy(iface->virtPortProfile);
return NULL;
if (virNetDevBandwidthCopy(&port->bandwidth, iface->bandwidth) < 0) if (virNetDevBandwidthCopy(&port->bandwidth, iface->bandwidth) < 0)
return NULL; return NULL;
@ -29448,8 +29447,7 @@ virDomainNetDefActualFromNetworkPort(virDomainNetDef *iface,
goto error; goto error;
} }
if (virNetDevVPortProfileCopy(&actual->virtPortProfile, port->virtPortProfile) < 0) actual->virtPortProfile = virNetDevVPortProfileCopy(port->virtPortProfile);
goto error;
if (virNetDevBandwidthCopy(&actual->bandwidth, port->bandwidth) < 0) if (virNetDevBandwidthCopy(&actual->bandwidth, port->bandwidth) < 0)
goto error; goto error;
@ -29589,8 +29587,7 @@ virDomainNetDefActualToNetworkPort(virDomainDef *dom,
return NULL; return NULL;
} }
if (virNetDevVPortProfileCopy(&port->virtPortProfile, actual->virtPortProfile) < 0) port->virtPortProfile = virNetDevVPortProfileCopy(actual->virtPortProfile);
return NULL;
if (virNetDevBandwidthCopy(&port->bandwidth, actual->bandwidth) < 0) if (virNetDevBandwidthCopy(&port->bandwidth, actual->bandwidth) < 0)
return NULL; return NULL;

View File

@ -122,16 +122,18 @@ virNetDevVPortProfileEqual(const virNetDevVPortProfile *a, const virNetDevVPortP
} }
int virNetDevVPortProfileCopy(virNetDevVPortProfile **dst, const virNetDevVPortProfile *src) virNetDevVPortProfile *
virNetDevVPortProfileCopy(const virNetDevVPortProfile *src)
{ {
if (!src) { virNetDevVPortProfile *ret = NULL;
*dst = NULL;
return 0;
}
*dst = g_new0(virNetDevVPortProfile, 1); if (!src)
memcpy(*dst, src, sizeof(*src)); return NULL;
return 0;
ret = g_new0(virNetDevVPortProfile, 1);
memcpy(ret, src, sizeof(*ret));
return ret;
} }

View File

@ -77,8 +77,9 @@ struct _virNetDevVPortProfile {
bool virNetDevVPortProfileEqual(const virNetDevVPortProfile *a, bool virNetDevVPortProfileEqual(const virNetDevVPortProfile *a,
const virNetDevVPortProfile *b); const virNetDevVPortProfile *b);
int virNetDevVPortProfileCopy(virNetDevVPortProfile **dst,
const virNetDevVPortProfile *src); virNetDevVPortProfile *
virNetDevVPortProfileCopy(const virNetDevVPortProfile *src);
int virNetDevVPortProfileCheckComplete(virNetDevVPortProfile *virtport, int virNetDevVPortProfileCheckComplete(virNetDevVPortProfile *virtport,
bool generateMissing); bool generateMissing);