diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 183a9194d7..e6868b55fd 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2113,6 +2113,7 @@ virNetDevGetMTU; virNetDevGetName; virNetDevGetOnline; virNetDevGetPhysicalFunction; +virNetDevGetPhysPortID; virNetDevGetPromiscuous; virNetDevGetRcvAllMulti; virNetDevGetRcvMulti; diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 90b7bee34a..e72d0dc248 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -1169,6 +1169,46 @@ virNetDevGetPCIDevice(const char *devName) } +/** + * virNetDevGetPhysPortID: + * + * @ifname: name of a netdev + * + * @physPortID: pointer to char* that will receive @ifname's + * phys_port_id from sysfs (null terminated + * string). Could be NULL if @ifname's net driver doesn't + * support phys_port_id (most netdev drivers + * don't). Caller is responsible for freeing the string + * when finished. + * + * Returns 0 on success or -1 on failure. + */ +int +virNetDevGetPhysPortID(const char *ifname, + char **physPortID) +{ + int ret = -1; + char *physPortIDFile = NULL; + + *physPortID = NULL; + + if (virNetDevSysfsFile(&physPortIDFile, ifname, "phys_port_id") < 0) + goto cleanup; + + /* a failure to read just means the driver doesn't support + * phys_port_id, so set success now and ignore the return from + * virFileReadAllQuiet(). + */ + ret = 0; + + ignore_value(virFileReadAllQuiet(physPortIDFile, 1024, physPortID)); + + cleanup: + VIR_FREE(physPortIDFile); + return ret; +} + + /** * virNetDevGetVirtualFunctions: * @@ -1432,6 +1472,17 @@ virNetDevGetVirtualFunctionInfo(const char *vfname, char **pfname, } #else /* !__linux__ */ +int +virNetDevGetPhysPortID(const char *ifname ATTRIBUTE_UNUSED, + char **physPortID) +{ + /* this actually should never be called, and is just here to + * satisfy the linker. + */ + *physPortID = NULL; + return 0; +} + int virNetDevGetVirtualFunctions(const char *pfname ATTRIBUTE_UNUSED, char ***vfname ATTRIBUTE_UNUSED, diff --git a/src/util/virnetdev.h b/src/util/virnetdev.h index 51fcae544e..9205c0e86c 100644 --- a/src/util/virnetdev.h +++ b/src/util/virnetdev.h @@ -226,6 +226,11 @@ int virNetDevGetPhysicalFunction(const char *ifname, char **pfname) int virNetDevPFGetVF(const char *pfname, int vf, char **vfname) ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK; +int virNetDevGetPhysPortID(const char *ifname, + char **physPortID) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) + ATTRIBUTE_RETURN_CHECK; + int virNetDevGetVirtualFunctions(const char *pfname, char ***vfname, virPCIDeviceAddressPtr **virt_fns,