[libvirt] [PATCH] virNetDevGetLinkInfo: Don't report link speed if NIC's down

Martin Kletzander mkletzan at redhat.com
Fri Jun 13 07:10:32 UTC 2014


On Fri, Jun 13, 2014 at 08:46:59AM +0200, Michal Privoznik wrote:
>The kernel's more broken than one would think. Various drivers report
>various (usually spurious) values if the interface is down. While on
>some we experience -EINVAL when read()-ing the speed sysfs file, with
>other drivers we might get anything from 0 to UINT_MAX. If that's the
>case it's better to not report link speed. Well, the interface is down
>anyway.
>
>Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
>---
> src/util/virnetdev.c | 13 ++++++++++++-
> 1 file changed, 12 insertions(+), 1 deletion(-)
>
>diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
>index 6f3a202..80ef572 100644
>--- a/src/util/virnetdev.c
>+++ b/src/util/virnetdev.c
>@@ -1843,7 +1843,7 @@ virNetDevGetLinkInfo(const char *ifname,
>     char *buf = NULL;
>     char *tmp;
>     int tmp_state;
>-    unsigned int tmp_speed;
>+    unsigned int tmp_speed; /* virInterfaceState */
>

You probably wanted to put this comment next to the line with
tmp_state and not tmp_speed.

>     if (virNetDevSysfsFile(&path, ifname, "operstate") < 0)
>         goto cleanup;
>@@ -1875,6 +1875,16 @@ virNetDevGetLinkInfo(const char *ifname,
>
>     lnk->state = tmp_state;
>
>+    /* Shortcut to avoid some kernel issues. If link is down (and possibly in
>+     * other states too) several drivers report several values. While igb
>+     * reports 65535, realtek goes with 10. To avoid muddying XML with insane
>+     * values, don't report link speed */
>+    if (lnk->state == VIR_INTERFACE_STATE_DOWN) {
>+        lnk->speed = 0;
>+        ret = 0;
>+        goto cleanup;
>+    }
>+

Pity that's not standardized, but what you did makes more sense than
anything else.  If the link is down, then no need to report it.

>     VIR_FREE(path);
>     VIR_FREE(buf);
>
>@@ -1884,6 +1894,7 @@ virNetDevGetLinkInfo(const char *ifname,
>     if (virFileReadAll(path, 1024, &buf) < 0) {
>         /* Some devices doesn't report speed, in which case we get EINVAL */
>         if (errno == EINVAL) {
>+            lnk->speed = 0;
>             ret = 0;
>             goto cleanup;
>         }
>--
>1.8.5.5
>

ACK,

Martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20140613/459659b4/attachment-0001.sig>


More information about the libvir-list mailing list