[libvirt] [PATCH 10/19] util: new function virNetDevPFGetVF()
Michal Privoznik
mprivozn at redhat.com
Fri Mar 17 13:32:46 UTC 2017
On 03/10/2017 09:35 PM, Laine Stump wrote:
> Given an SRIOV PF netdev name (e.g. "enp2s0f0") and VF#, this new
> function returns the netdev name of the referenced VF device
> (e.g. "enp2s11f6"), or NULL if the device isn't bound to a net driver.
> ---
> src/libvirt_private.syms | 1 +
> src/util/virnetdev.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++
> src/util/virnetdev.h | 3 +++
> 3 files changed, 62 insertions(+)
>
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index ef027cc..e9705ae 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -1997,6 +1997,7 @@ virNetDevGetVLanID;
> virNetDevIfStateTypeFromString;
> virNetDevIfStateTypeToString;
> virNetDevIsVirtualFunction;
> +virNetDevPFGetVF;
> virNetDevReplaceMacAddress;
> virNetDevReplaceNetConfig;
> virNetDevRestoreMacAddress;
> diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
> index ffc2fb4..49a11f3 100644
> --- a/src/util/virnetdev.c
> +++ b/src/util/virnetdev.c
> @@ -1311,6 +1311,54 @@ virNetDevGetPhysicalFunction(const char *ifname, char **pfname)
> return ret;
> }
>
> +
> +/**
> + * virNetDevPFGetVF:
> + *
> + * @pfname: netdev name of the physical function (PF)
> + * @vf: virtual function (VF) number for the device of interest
> + * @vfname: name of the physical function interface name
> + *
> + * Finds the netdev name of VF# @vf of SRIOV PF @pfname, and puts it
> + * in @vfname. The caller must free @vfname when it's finished with
> + * it.
> + *
> + * Returns 0 on success, -1 on failure
Not entirely true. After your patch of 06/19 virPCIGetNetName() can
return 0 (which in turn is the return value of virNetDevPFGetVF()), and
still not fetch vfname - if virDirOpenQuiet() fails. I'd recommend to at
least note this in the comment.
> + *
> + */
> +int
> +virNetDevPFGetVF(const char *pfname, int vf, char **vfname)
> +{
> + char *virtfnName = NULL;
> + char *virtfnSysfsPath = NULL;
> + int ret = -1;
> +
> + if (virAsprintf(&virtfnName, "virtfn%d", vf) < 0)
> + goto cleanup;
> +
> + /* this provides the path to the VF's directory in sysfs,
> + * e.g. "/sys/class/net/enp2s0f0/virtfn3"
> + */
> + if (virNetDevSysfsDeviceFile(&virtfnSysfsPath, pfname, virtfnName) < 0)
> + goto cleanup;
> +
> + /* and this gets the netdev name associated with it, which is a
> + * directory entry in [virtfnSysfsPath]/net,
> + * e.g. "/sys/class/net/enp2s0f0/virtfn3/net/enp2s11f4" - in this
> + * example the VF for enp2s0f0 vf#3 is "enp2s11f4". (If the VF
> + * isn't bound to a netdev driver, it won't have a netdev name,
> + * and vfname will be NULL).
> + */
> + ret = virPCIGetNetName(virtfnSysfsPath, vfname);
> +
> + cleanup:
> + VIR_FREE(virtfnName);
> + VIR_FREE(virtfnSysfsPath);
> +
> + return ret;
> +}
> +
> +
ACK with that fixed.
Michal
More information about the libvir-list
mailing list