Change in vdsm[master]: libnl: workaround for NLE_OPNOTSUPP

phoracek at redhat.com phoracek at redhat.com
Fri Nov 28 12:13:26 UTC 2014


Petr Horáček has uploaded a new change for review.

Change subject: libnl: workaround for NLE_OPNOTSUPP
......................................................................

libnl: workaround for NLE_OPNOTSUPP

Introducing a workaround for older libnl which does not support
NLE_OPNOTSUPP error (libnl: b54775d3169b56d9c0aee47d6937b0358a5443e0,
BZ: 1168915). When that patch will be backported, we could use vdsm
patch b54775d3169b56d9c0aee47d6937b0358a54 which handles older kernels
which do not support getting link by iface name.

Change-Id: If44a30be72cdfc506225224e95f81a26ffaa8fcd
Signed-off-by: Petr Horáček <phoracek at redhat.com>
---
M lib/vdsm/netlink/link.py
1 file changed, 31 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/05/35705/1

diff --git a/lib/vdsm/netlink/link.py b/lib/vdsm/netlink/link.py
index af87969..b96f418 100644
--- a/lib/vdsm/netlink/link.py
+++ b/lib/vdsm/netlink/link.py
@@ -21,11 +21,16 @@
 from functools import partial
 from socket import AF_UNSPEC
 import errno
+import os.uname
+
+from vdsm.utils import memoized
 
 from . import _cache_manager, _nl_cache_get_first, _nl_cache_get_next
 from . import _char_proto, _int_char_proto, _int_proto, _void_proto
 from . import LIBNL_ROUTE, _nl_geterror, _pool
 from . import _addr_to_str, CHARBUFFSIZE
+
+NLE_SUCCESS = 0
 
 
 def get_link(name):
@@ -133,6 +138,22 @@
         return -1
 
 
+# TODO: This is a workaround for older libnl which does not support
+# NLE_OPNOTSUPP error (libnl: b54775d3169b56d9c0aee47d6937b0358a5443e0,
+# BZ: 1168915). When that patch will be backported, we could use vdsm patch
+# b54775d3169b56d9c0aee47d6937b0358a54 which handles older kernels which
+# do not support getting link by iface name.
+ at memoized
+def _kernel_26():
+    kernel_ver = os.uname()[2][:3]
+    return kernel_ver == '2.6'
+
+
+def _rtnl_link_get_kernel_workaround(sock, name):
+    with _nl_link_cache(sock) as cache:
+        return _rtnl_link_get_by_name(cache, name)
+
+
 def _get_link(name=None, index=0, sock=None):
     """ If defined both name and index, index is primary """
     if name is None and index == 0:
@@ -140,9 +161,17 @@
     link = c_void_p()
     if sock is None:
         with _pool.socket() as sock:
-            err = _rtnl_link_get_kernel(sock, index, name, byref(link))
+            if _kernel_26():
+                link = _rtnl_link_get_kernel_workaround(sock, name)
+                err = NLE_SUCCESS
+            else:
+                err = _rtnl_link_get_kernel(sock, index, name, byref(link))
     else:
-        err = _rtnl_link_get_kernel(sock, index, name, byref(link))
+        if _kernel_26():
+            link = _rtnl_link_get_kernel_workaround(sock, name)
+            err = NLE_SUCCESS
+        else:
+            err = _rtnl_link_get_kernel(sock, index, name, byref(link))
     if err:
         raise IOError(-err, _nl_geterror())
     return link


-- 
To view, visit http://gerrit.ovirt.org/35705
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If44a30be72cdfc506225224e95f81a26ffaa8fcd
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Petr Horáček <phoracek at redhat.com>


More information about the vdsm-patches mailing list