Skip to content

Commit

Permalink
pybind: work around find_library() not searching LD_LIBRARY_PATH
Browse files Browse the repository at this point in the history
Commit b28b64a ("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 e46d2ca ("fix the
bug  ctypes.util.find_library to search for librados failed on
Centos6.4.")

Signed-off-by: Ilya Dryomov <[email protected]>
  • Loading branch information
idryomov committed Jan 30, 2014
1 parent 03da035 commit dcbe872
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
20 changes: 16 additions & 4 deletions src/pybind/cephfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -125,10 +140,7 @@ def require_state(self, *args):
"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):
Expand Down
10 changes: 8 additions & 2 deletions src/pybind/rbd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down

0 comments on commit dcbe872

Please sign in to comment.