Skip to content

Commit b8bb1ad

Browse files
nixpanicgluster-ant
authored andcommittedSep 30, 2013
gfapi.py: support dynamic loading of versioned libraries
Currently gfapi.py only loads libraries by filename ending in ".so". On an installed system without development packages, the <lib>.so filenames are not available. ctypes.util.find_library() can be used to detect the files dynamically. In addition to this, also fixing some minor indention errors and package the library into the Python site-packages path. Python applications and libraries can now access libgfapi through 'from glusterfs import gfapi'. Change-Id: I71e38dabd3ade5dcf24813bf2fc25cda91b571c6 BUG: 1005146 Signed-off-by: Niels de Vos <ndevos@redhat.com> Reviewed-on: http://review.gluster.org/5835 Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com> Tested-by: Gluster Build System <jenkins@build.gluster.com>
1 parent 9366f16 commit b8bb1ad

File tree

7 files changed

+80
-22
lines changed

7 files changed

+80
-22
lines changed
 

‎.gitignore

+12-10
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,27 @@ Makefile
2222
stamp-h1
2323

2424
# Generated files
25-
ufo/.tox
26-
ufo/test/unit/.coverage
25+
api/examples/__init__.py*
26+
api/examples/setup.py
27+
argp-standalone/libargp.a
2728
contrib/uuid/uuid_types.h
28-
extras/who-wrote-glusterfs/gitdm
29-
extras/init.d/glusterd.plist
3029
extras/init.d/glusterd-Debian
3130
extras/init.d/glusterd-Redhat
3231
extras/init.d/glusterd-SuSE
32+
extras/init.d/glusterd.plist
3333
extras/ocf/glusterd
3434
extras/ocf/volume
35-
glusterfs.spec
35+
extras/who-wrote-glusterfs/gitdm
3636
glusterfs-api.pc
37-
libtool
38-
xlators/mount/fuse/utils/mount.glusterfs
39-
xlators/mount/fuse/utils/mount_glusterfs
40-
argp-standalone/libargp.a
37+
glusterfs.spec
4138
glusterfsd/src/glusterfsd
39+
libgfchangelog.pc
4240
libglusterfs/src/spec.lex.c
4341
libglusterfs/src/y.tab.c
4442
libglusterfs/src/y.tab.h
45-
libgfchangelog.pc
43+
libtool
4644
run-tests.sh
45+
ufo/.tox
46+
ufo/test/unit/.coverage
47+
xlators/mount/fuse/utils/mount.glusterfs
48+
xlators/mount/fuse/utils/mount_glusterfs

‎api/Makefile.am

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
SUBDIRS = src
1+
SUBDIRS = src examples

‎api/examples/Makefile.am

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
noinst_PROGRAMS = glfsxmp
1+
EXTRA_PROGRAMS = glfsxmp
22
glfsxmp_SOURCES = glfsxmp.c
33
glfsxmp_CFLAGS = $(GLFS_CFLAGS) -Wall
4-
glfsxmp_LDADD = $(GLFS_LIBS)
4+
glfsxmp_LDADD = $(GLFS_LIBS)
5+
6+
EXTRA_DIST = gfapi.py

‎api/examples/gfapi.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
#!/usr/bin/python
22

33
from ctypes import *
4+
from ctypes.util import find_library
45
import os
56
import sys
67
import time
78
import types
89

910
# Looks like ctypes is having trouble with dependencies, so just force them to
1011
# load with RTLD_GLOBAL until I figure that out.
11-
glfs = CDLL("libglusterfs.so",RTLD_GLOBAL)
12-
xdr = CDLL("libgfxdr.so",RTLD_GLOBAL)
13-
api = CDLL("libgfapi.so",RTLD_GLOBAL)
12+
glfs = CDLL(find_library("glusterfs"),RTLD_GLOBAL)
13+
xdr = CDLL(find_library("gfxdr"),RTLD_GLOBAL)
14+
api = CDLL(find_library("gfapi"),RTLD_GLOBAL)
1415

1516
# Wow, the Linux kernel folks really play nasty games with this structure. If
1617
# you look at the man page for stat(2) and then at this definition you'll note
@@ -98,10 +99,12 @@ def read_buffer (self, buf, flags=0):
9899
def write (self, data, flags=0):
99100
return api.glfs_write(self.fd,data,len(data),flags)
100101

101-
def fallocate (self, mode, offset, len):
102-
return api.glfs_fallocate(self.fd, mode, offset, len)
103-
def discard (self, offset, len):
104-
return api.glfs_discard(self.fd, offset, len)
102+
def fallocate (self, mode, offset, len):
103+
return api.glfs_fallocate(self.fd, mode, offset, len)
104+
105+
def discard (self, offset, len):
106+
return api.glfs_discard(self.fd, offset, len)
107+
105108

106109
class Dir(object):
107110

@@ -381,7 +384,7 @@ def test_fallocate (vol, path, data):
381384
test_setxattr,
382385
test_getxattr,
383386
test_listxattr,
384-
test_fallocate,
387+
test_fallocate,
385388
)
386389

387390
ok_to_fail = (

‎api/examples/setup.py.in

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from distutils.core import setup
2+
3+
# generate a __init__.py for the package namespace
4+
fo = open('__init__.py', 'w')
5+
fo.write('__version__ = "@PACKAGE_VERSION@"\n')
6+
fo.close()
7+
8+
DESC = """GlusterFS is a clustered file-system capable of scaling to
9+
several petabytes. It aggregates various storage bricks over Infiniband
10+
RDMA or TCP/IP interconnect into one large parallel network file system.
11+
GlusterFS is one of the most sophisticated file systems in terms of
12+
features and extensibility. It borrows a powerful concept called
13+
Translators from GNU Hurd kernel. Much of the code in GlusterFS is in
14+
user space and easily manageable.
15+
16+
This package contains the Python interface to the libgfapi library."""
17+
18+
setup(
19+
name='glusterfs-api',
20+
version='@PACKAGE_VERSION@',
21+
description='Python client library for the GlusterFS libgfapi',
22+
long_description=DESC,
23+
author='Gluster Community',
24+
author_email='gluster-devel@nongnu.org',
25+
license='LGPLv3',
26+
url='http://gluster.org/',
27+
package_dir={'gluster':''},
28+
packages=['gluster']
29+
)

‎configure.ac

+2
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ AC_CONFIG_FILES([Makefile
164164
libgfchangelog.pc
165165
api/Makefile
166166
api/src/Makefile
167+
api/examples/Makefile
168+
api/examples/setup.py
167169
geo-replication/Makefile
168170
geo-replication/src/Makefile
169171
geo-replication/syncdaemon/Makefile

‎glusterfs.spec.in

+21-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@
6363
%global _with_systemd true
6464
%endif
6565

66+
# From https://fedoraproject.org/wiki/Packaging:Python#Macros
67+
%if ( 0%{?rhel} && 0%{?rhel} <= 5 )
68+
%{!?python_sitelib: %global python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")}
69+
%{!?python_sitearch: %global python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))")}
70+
%endif
71+
6672
Summary: Cluster File System
6773
%if ( 0%{_for_fedora_koji_builds} )
6874
Name: glusterfs
@@ -315,6 +321,8 @@ This package provides the glusterfs server daemon.
315321
Summary: Clustered file-system api library
316322
Group: System Environment/Daemons
317323
Requires: %{name} = %{version}-%{release}
324+
# we provide the Python package/namespace 'gluster'
325+
Provides: python-gluster = %{version}-%{release}
318326

319327
%description api
320328
GlusterFS is a clustered file-system capable of scaling to several
@@ -325,7 +333,7 @@ terms of features and extensibility. It borrows a powerful concept
325333
called Translators from GNU Hurd kernel. Much of the code in GlusterFS
326334
is in user space and easily manageable.
327335

328-
This package provides the glusterfs libgfapi library
336+
This package provides the glusterfs libgfapi library.
329337

330338
%if ( 0%{!?_without_ocf:1} )
331339
%package resource-agents
@@ -437,9 +445,17 @@ regression testing of Gluster.
437445

438446
%{__make} %{?_smp_mflags}
439447

448+
pushd api/examples
449+
FLAGS="$RPM_OPT_FLAGS" %{__python} setup.py build
450+
popd
451+
440452
%install
441453
%{__rm} -rf %{buildroot}
442454
%{__make} install DESTDIR=%{buildroot}
455+
# install the gfapi Python library in /usr/lib/python*/site-packages
456+
pushd api/examples
457+
%{__python} setup.py install --skip-build --verbose --root %{buildroot}
458+
popd
443459
# Install include directory
444460
%{__mkdir_p} %{buildroot}%{_includedir}/glusterfs
445461
%{__install} -p -m 0644 libglusterfs/src/*.h \
@@ -768,6 +784,7 @@ fi
768784
%exclude %{_libdir}/*.so
769785
%{_libdir}/libgfapi.*
770786
%{_libdir}/glusterfs/%{version}%{?prereltag}/xlator/mount/api*
787+
%{python_sitelib}/*
771788

772789
%if ( 0%{!?_without_ocf:1} )
773790
%files resource-agents
@@ -858,6 +875,9 @@ if [ $1 -ge 1 ]; then
858875
fi
859876

860877
%changelog
878+
* Thu Sep 30 2013 Niels de Vos <ndevos@redhat.com>
879+
- Package gfapi.py into the Python site-packages path (#1005146)
880+
861881
* Tue Sep 17 2013 Harshavardhana <fharshav@redhat.com>
862882
- Provide a new package called "glusterfs-regression-tests" for standalone
863883
regression testing.

0 commit comments

Comments
 (0)
Please sign in to comment.