[libvirt] [PATCH v6 04/23] conf: add APIs to convert virDomainNetDef to virNetworkPortDef
John Ferlan
jferlan at redhat.com
Tue Jun 18 16:22:25 UTC 2019
[...]
> +virNetworkPortDefPtr
> +virDomainNetDefToNetworkPort(virDomainDefPtr dom,
> + virDomainNetDefPtr iface)
> +{
> + virNetworkPortDefPtr port;
> +
> + if (iface->type != VIR_DOMAIN_NET_TYPE_NETWORK) {
> + virReportError(VIR_ERR_INTERNAL_ERROR,
> + _("Expected an interface of type 'network' not '%s'"),
> + virDomainNetTypeToString(iface->type));
> + return NULL;
> + }
> +
> + if (VIR_ALLOC(port) < 0)
> + return NULL;
> +
> + virUUIDGenerate(port->uuid);
Coverity notes that here and ...
[...]
> +
> +virNetworkPortDefPtr
> +virDomainNetDefActualToNetworkPort(virDomainDefPtr dom,
> + virDomainNetDefPtr iface)
> +{
> + virDomainActualNetDefPtr actual;
> + virNetworkPortDefPtr port;
> +
> + if (!iface->data.network.actual) {
> + virReportError(VIR_ERR_INTERNAL_ERROR,
> + _("Missing actual data for interface '%s'"),
> + iface->ifname);
> + return NULL;
> + }
> +
> + actual = iface->data.network.actual;
> +
> + if (iface->type != VIR_DOMAIN_NET_TYPE_NETWORK) {
> + virReportError(VIR_ERR_INTERNAL_ERROR,
> + _("Expected an interface of type 'network' not '%s'"),
> + virDomainNetTypeToString(iface->type));
> + return NULL;
> + }
> +
> + if (VIR_ALLOC(port) < 0)
> + return NULL;
> +
> + /* Bad - we need to preserve original port uuid */
> + virUUIDGenerate(port->uuid);
... here calls are made to virUUIDGenerate that could fail, but we don't
return on that failure
John
> +
> + memcpy(port->owneruuid, dom->uuid, VIR_UUID_BUFLEN);
> + if (VIR_STRDUP(port->ownername, dom->name) < 0)
> + goto error;
> +
> + if (VIR_STRDUP(port->group, iface->data.network.portgroup) < 0)
> + goto error;
> +
> + memcpy(&port->mac, &iface->mac, VIR_MAC_BUFLEN);
> +
[...]
More information about the libvir-list
mailing list