Change in vdsm[master]: netlink: ignore_enodev parameter in *_info

phoracek at redhat.com phoracek at redhat.com
Fri Nov 7 10:00:39 UTC 2014


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

Change subject: netlink: ignore_enodev parameter in *_info
......................................................................

netlink: ignore_enodev parameter in *_info

When we try to get information about the removed device without the
cache, _get_link() will end up with ENODEV exception.

This case may happen for example when we catch DELLINK event and then
try to get info about the deleted link.

Now _link/route/addr_functions() have ignore_enodev parameter. If set to
True, when ENODEV is raised, _info returns just indexes of devices.

Change-Id: I41dfc7178144ae35a6b5bb52c185a337c94138ba
Signed-off-by: Petr Horáček <phoracek at redhat.com>
---
M lib/vdsm/netlink/addr.py
M lib/vdsm/netlink/link.py
M lib/vdsm/netlink/route.py
3 files changed, 38 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/25/34925/1

diff --git a/lib/vdsm/netlink/addr.py b/lib/vdsm/netlink/addr.py
index f63b2b9..019e68a 100644
--- a/lib/vdsm/netlink/addr.py
+++ b/lib/vdsm/netlink/addr.py
@@ -18,6 +18,7 @@
 #
 from ctypes import (CFUNCTYPE, byref, c_char, c_int, c_void_p, sizeof)
 from functools import partial
+import errno
 
 from . import _cache_manager, _nl_cache_get_first, _nl_cache_get_next
 from . import _int_char_proto, _int_proto, _void_proto
@@ -38,17 +39,20 @@
                     addr = _nl_cache_get_next(addr)
 
 
-def _addr_info(addr, link_cache=None):
+def _addr_info(addr, link_cache=None, ignore_enodev=False):
     """Returns a dictionary with the address information."""
     index = _rtnl_addr_get_ifindex(addr)
-    return {
-        'label': _link_index_to_name(index, cache=link_cache),
-        'index': index,
-        'family': _af_to_str(_rtnl_addr_get_family(addr)),
-        'prefixlen': _rtnl_addr_get_prefixlen(addr),
-        'scope': _scope_to_str(_rtnl_addr_get_scope(addr)),
-        'flags': _addr_flags(addr),
-        'address': _addr_to_str(_rtnl_addr_get_local(addr))}
+    data = {'index': index,
+            'family': _af_to_str(_rtnl_addr_get_family(addr)),
+            'prefixlen': _rtnl_addr_get_prefixlen(addr),
+            'scope': _scope_to_str(_rtnl_addr_get_scope(addr)),
+            'flags': _addr_flags(addr),
+            'address': _addr_to_str(_rtnl_addr_get_local(addr))}
+    try:
+        data['label'] = _link_index_to_name(index, cache=link_cache),
+    except IOError as err:
+        if err.errno != errno.ENODEV or not ignore_enodev:
+            raise
 
 
 def _addr_flags(addr):
diff --git a/lib/vdsm/netlink/link.py b/lib/vdsm/netlink/link.py
index 9f42a6a..f819257 100644
--- a/lib/vdsm/netlink/link.py
+++ b/lib/vdsm/netlink/link.py
@@ -47,7 +47,7 @@
                 link = _nl_cache_get_next(link)
 
 
-def _link_info(link, cache=None):
+def _link_info(link, cache=None, ignore_enodev=False):
     """Returns a dictionary with the information of the link object."""
     info = {}
     info['address'] = _addr_to_str(_rtnl_link_get_addr(link))
@@ -64,12 +64,24 @@
 
     underlying_device_index = _rtnl_link_get_link(link)
     if underlying_device_index > 0:
-        info['device'] = _link_index_to_name(underlying_device_index,
-                                             cache=cache)
+        try:
+            info['device'] = _link_index_to_name(underlying_device_index,
+                                                 cache=cache)
+        except IOError as err:
+            if err.errno == errno.ENODEV and ignore_enodev:
+                info['device_index'] = underlying_device_index
+            else:
+                raise
 
     master_index = _rtnl_link_get_master(link)
     if master_index > 0:
-        info['master'] = _link_index_to_name(master_index, cache=cache)
+        try:
+            info['master'] = _link_index_to_name(master_index, cache=cache)
+        except IOError as err:
+            if err.errno == errno.ENODEV and ignore_enodev:
+                info['master_index'] = master_index
+            else:
+                raise
 
     vlanid = _rtnl_link_vlan_get_id(link)
     if vlanid >= 0:
diff --git a/lib/vdsm/netlink/route.py b/lib/vdsm/netlink/route.py
index 604de67..0fa4f36 100644
--- a/lib/vdsm/netlink/route.py
+++ b/lib/vdsm/netlink/route.py
@@ -19,6 +19,7 @@
 from ctypes import CFUNCTYPE, c_int, c_void_p, byref
 from functools import partial
 from socket import AF_UNSPEC
+import errno
 
 from . import _cache_manager, _nl_cache_get_first, _nl_cache_get_next
 from . import _char_proto, _int_proto, _void_proto
@@ -42,7 +43,7 @@
                     route = _nl_cache_get_next(route)
 
 
-def _route_info(route, link_cache=None):
+def _route_info(route, link_cache=None, ignore_enodev=False):
     data = {
         'destination': _addr_to_str(_rtnl_route_get_dst(route)),  # network
         'source': _addr_to_str(_rtnl_route_get_src(route)),
@@ -52,7 +53,13 @@
         'scope': _scope_to_str(_rtnl_route_get_scope(route))}
     oif_index = _rtnl_route_get_oif(route)
     if oif_index > 0:
-        data['oif'] = _link_index_to_name(oif_index, cache=link_cache)
+        try:
+            data['oif'] = _link_index_to_name(oif_index, cache=link_cache)
+        except IOError as err:
+            if err.errno == errno.ENODEV and ignore_enodev:
+                data['oif_index'] = oif_index
+            else:
+                raise
     return data
 
 


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I41dfc7178144ae35a6b5bb52c185a337c94138ba
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