From: Ilya Dryomov Date: Thu, 30 Jan 2014 11:39:15 +0000 (+0200) Subject: pybind: work around find_library() not searching LD_LIBRARY_PATH X-Git-Tag: v0.78~245^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=dcbe872e06a0c5962f380bc038994e0db829d49f;p=ceph.git pybind: work around find_library() not searching LD_LIBRARY_PATH 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 --- diff --git a/src/pybind/cephfs.py b/src/pybind/cephfs.py index effc6577b689..a5e9153a020c 100644 --- a/src/pybind/cephfs.py +++ b/src/pybind/cephfs.py @@ -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): diff --git a/src/pybind/rbd.py b/src/pybind/rbd.py index d456c705e68f..26c8df296e03 100644 --- a/src/pybind/rbd.py +++ b/src/pybind/rbd.py @@ -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): """