]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind: work around find_library() not searching LD_LIBRARY_PATH
authorIlya Dryomov <ilya.dryomov@inktank.com>
Thu, 30 Jan 2014 11:39:15 +0000 (13:39 +0200)
committerIlya Dryomov <ilya.dryomov@inktank.com>
Thu, 30 Jan 2014 11:48:22 +0000 (13:48 +0200)
Commit b28b64a0b6db ("pybind: use find_library for libcephfs and
librbd") switched us to find_library(), but this function doesn't seem
to respect LD_LIBRARY_PATH.  There are numerous python tickets, dating
back several years, but alas.  Work around it by using the soname as
a fallback.  (rados.py has been fixed by commit e46d2ca067b5 ("fix the
bug  ctypes.util.find_library to search for librados failed on
Centos6.4.")

Signed-off-by: Ilya Dryomov <ilya.dryomov@inktank.com>
src/pybind/cephfs.py
src/pybind/rbd.py

index effc6577b689b0f4352f4ff40911050550b925f4..a5e9153a020c05e69580c7289d0328abd904d739 100644 (file)
@@ -115,6 +115,21 @@ class cephfs_stat(Structure):
                 ('__unused2', c_long),
                 ('__unused3', c_long) ]
 
+def load_libcephfs():
+    """
+    Load the libcephfs shared library.
+    """
+    libcephfs_path = find_library('cephfs')
+    if libcephfs_path:
+        return CDLL(libcephfs_path)
+
+    # try harder, find_library() doesn't search LD_LIBRARY_PATH
+    # in addition, it doesn't seem work on centos 6.4 (see e46d2ca067b5)
+    try:
+        return CDLL('libcephfs.so.1')
+    except OSError:
+        raise EnvironmentError("Unable to find libcephfs")
+
 class LibCephFS(object):
     """libcephfs python wrapper"""
     def require_state(self, *args):
@@ -125,10 +140,7 @@ class LibCephFS(object):
                                   "CephFS object in state %s." % (self.state))
 
     def __init__(self, conf=None, conffile=None):
-        libcephfs_path = find_library('cephfs')
-        if not libcephfs_path:
-            raise EnvironmentError("Unable to find libcephfs")
-        self.libcephfs = CDLL(libcephfs_path)
+        self.libcephfs = load_libcephfs()
         self.cluster = c_void_p()
 
         if conffile is not None and not isinstance(conffile, str):
index d456c705e68ff5caff73a1d60c6057aef46d4a19..26c8df296e03d57a27ecee2ef66513c680fddb2b 100644 (file)
@@ -122,9 +122,15 @@ def load_librbd():
     Load the librbd shared library.
     """
     librbd_path = find_library('rbd')
-    if not librbd_path:
+    if librbd_path:
+        return CDLL(librbd_path)
+
+    # try harder, find_library() doesn't search LD_LIBRARY_PATH
+    # in addition, it doesn't seem work on centos 6.4 (see e46d2ca067b5)
+    try:
+        return CDLL('librbd.so.1')
+    except OSError:
         raise EnvironmentError("Unable to find librbd")
-    return CDLL(librbd_path)
 
 class RBD(object):
     """