Skip to content

Commit

Permalink
Merge pull request ceph#6768 from marcan/cython
Browse files Browse the repository at this point in the history
pybind: port the rbd bindings to Cython

Reviewed-by: Josh Durgin <[email protected]>
Reviewed-by: Nathan Cutler <[email protected]>
Reviewed-by: Ken Dreyer <[email protected]>
Reviewed-by: Alfredo Deza <[email protected]>
  • Loading branch information
jdurgin committed Dec 9, 2015
2 parents bcd37cf + 93cdc98 commit 701a662
Show file tree
Hide file tree
Showing 14 changed files with 1,600 additions and 1,277 deletions.
26 changes: 21 additions & 5 deletions admin/build-doc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ TOPDIR=`pwd`
install -d -m0755 build-doc

if command -v dpkg >/dev/null; then
for package in python-dev python-pip python-virtualenv doxygen ditaa ant libxml2-dev libxslt1-dev; do
for package in python-dev python-pip python-virtualenv doxygen ditaa ant libxml2-dev libxslt1-dev cython; do
if [ "$(dpkg --status -- $package|sed -n 's/^Status: //p')" != "install ok installed" ]; then
# add a space after old values
missing="${missing:+$missing }$package"
Expand All @@ -19,7 +19,7 @@ if command -v dpkg >/dev/null; then
exit 1
fi
elif command -v yum >/dev/null; then
for package in python-devel python-pip python-virtualenv doxygen ditaa ant libxml-devel libxslt-devel; do
for package in python-devel python-pip python-virtualenv doxygen ditaa ant libxml-devel libxslt-devel Cython; do
if ! rpm -q $package >/dev/null ; then
missing="${missing:+$missing }$package"
fi
Expand All @@ -30,7 +30,7 @@ elif command -v yum >/dev/null; then
exit 1
fi
else
for command in virtualenv doxygen ant ditaa; do
for command in virtualenv doxygen ant ditaa cython; do
command -v "$command" > /dev/null;
ret_code=$?
if [ $ret_code -ne 0 ]; then
Expand All @@ -56,14 +56,30 @@ cd build-doc
[ -z "$vdir" ] && vdir="./virtualenv"

if [ ! -e $vdir ]; then
virtualenv --no-site-packages $vdir
virtualenv --system-site-packages $vdir
fi
$vdir/bin/pip install --quiet -r ../admin/doc-requirements.txt

install -d -m0755 \
output/html \
output/man
PYTHONPATH=`pwd`/../src/pybind $vdir/bin/sphinx-build -a -n -b dirhtml -d doctrees ../doc output/html

# To avoid having to build librbd to build the Python bindings to build the docs,
# create a dummy librbd.so that allows the module to be imported by sphinx.
mkdir -p $vdir/lib
export LD_LIBRARY_PATH="$vdir/lib"
export PYTHONPATH=`pwd`/../src/pybind
ln -sf librbd.so.1 $vdir/lib/librbd.so
gcc -shared -o $vdir/lib/librbd.so.1 -xc /dev/null
CFLAGS="-iquote `pwd`/../src/include" \
CPPFLAGS="-iquote `pwd`/../src/include" \
LDFLAGS="-L$vdir/lib -Wl,--no-as-needed" \
$vdir/bin/pip install `pwd`/../src/pybind
nm $vdir/lib/python*/*-packages/rbd.so | grep 'U rbd_' | \
awk '{ print "void "$2"(void) {}" }' | \
gcc -shared -o $vdir/lib/librbd.so.1 -xc -

$vdir/bin/sphinx-build -a -n -b dirhtml -d doctrees ../doc output/html
$vdir/bin/sphinx-build -a -b man -d doctrees ../doc output/man

#
Expand Down
8 changes: 7 additions & 1 deletion ceph.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ BuildRequires: boost-devel
BuildRequires: cmake
BuildRequires: cryptsetup
BuildRequires: fuse-devel
%if 0%{?suse_version}
BuildRequires: python-Cython
%else
BuildRequires: Cython
%endif
BuildRequires: gdbm
BuildRequires: hdparm
BuildRequires: leveldb-devel > 1.2
Expand Down Expand Up @@ -1146,7 +1151,8 @@ ln -sf %{_libdir}/librbd.so.1 /usr/lib64/qemu/librbd.so.1
#################################################################################
%files -n python-rbd
%defattr(-,root,root,-)
%{python_sitelib}/rbd.py*
%{python_sitearch}/rbd.so
%{python_sitearch}/rbd-*.egg-info

#################################################################################
%files -n libcephfs1
Expand Down
14 changes: 14 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ AC_ARG_WITH([rbd],
AM_CONDITIONAL(WITH_RBD, test "$with_rbd" = "yes")
#AS_IF([test "$with_rbd" = "yes"], [AC_DEFINE([WITH_RADOS, WITH_RBD])])

AC_ARG_WITH([cython],
[AS_HELP_STRING([--with-cython], [build python bindings for librbd])],
[],
[with_cython=yes])
AM_CONDITIONAL(WITH_CYTHON, test "$with_cython" = "yes")

# cephfs?
# cephfs requires rados
AC_ARG_WITH([cephfs],
Expand Down Expand Up @@ -201,6 +207,14 @@ AC_ARG_ENABLE([server],
AM_CONDITIONAL(ENABLE_SERVER, test "$enable_server" = "yes")
#AS_IF([test "$enable_server" = "yes"], [AC_DEFINE([WITH_MON, WITH_OSD, WITH_MDS, ENABLE_SERVER])])

# cython is required to build librbd python bindings
if test x"$with_cython" = xyes; then
AC_CHECK_PROG(CYTHON_CHECK, cython, yes)
if test x"$CYTHON_CHECK" != xyes; then
AC_MSG_FAILURE([cython not found])
fi
fi

# cond-check if snappy-devel is installed, needed by leveldb that is need by server parts of the project
AS_IF([test "$enable_server" = "yes" -a \( "$with_osd" = "yes" -o "$with_mon" = "yes" \)],
[AC_CHECK_LIB([snappy], [snappy_compress], [true], [AC_MSG_FAILURE([libsnappy not found])])])
Expand Down
3 changes: 2 additions & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Build-Depends: autoconf,
libbz2-dev,
cmake,
cryptsetup-bin | cryptsetup,
cython,
debhelper (>= 6.0.7~),
default-jdk,
git,
Expand Down Expand Up @@ -529,7 +530,7 @@ Description: Python libraries for the Ceph librados library
Package: python-rbd
Architecture: linux-any
Section: python
Depends: librbd1, ${misc:Depends}, ${python:Depends}
Depends: librbd1 (>= ${binary:Version}), ${misc:Depends}, ${python:Depends}
Replaces: python-ceph (<< 0.92-1223)
Breaks: python-ceph (<< 0.92-1223)
X-Python-Version: >= 2.6
Expand Down
3 changes: 2 additions & 1 deletion debian/python-rbd.install
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
usr/lib/python*/dist-packages/rbd.py*
usr/lib/python*/dist-packages/rbd.so
usr/lib/python*/dist-packages/rbd-*.egg-info
1 change: 1 addition & 0 deletions src/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Makefile
/.git_version
/.libs
/acconfig.h*
/build
/ceph
/cephfs
/crushtool
Expand Down
2 changes: 0 additions & 2 deletions src/Makefile-client.am
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ bin_SCRIPTS += \
rbd-replay-many \
rbdmap

python_PYTHON += pybind/rbd.py

libkrbd_la_SOURCES = krbd.cc
libkrbd_la_LIBADD = $(LIBSECRET) $(LIBCOMMON) -lblkid -ludev
if LINUX
Expand Down
19 changes: 17 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ include Makefile-env.am
SUBDIRS += ocf java
DIST_SUBDIRS += gmock ocf java

LOCAL_ALL =
LOCAL_CLEAN =
LOCAL_INSTALLDATA =
LOCAL_INSTALLEXEC =

if NO_GIT_VERSION
export NO_VERSION="yes"
endif
Expand Down Expand Up @@ -43,6 +48,7 @@ include tools/Makefile.am
include Makefile-rocksdb.am
include compressor/Makefile.am
include tracing/Makefile.am
include pybind/Makefile.am


# shell scripts
Expand Down Expand Up @@ -192,11 +198,12 @@ CLEANFILES += ceph_ver.h sample.fetch_config

# cleaning

clean-local::
base-clean-local::
rm -f *.so
find . -name '*.gcno' -o -name '*.gcda' -o -name '*.lcov' -o -name "*.o" -o -name "*.lo" | xargs rm -f
rm -f ceph java/java/com/ceph/crush/Bucket.class

LOCAL_CLEAN += base-clean-local

# pybind

Expand Down Expand Up @@ -242,11 +249,13 @@ if ENABLE_COVERAGE
-test/coverage.sh -d $(srcdir) -o check-coverage make check
endif

install-data-local:: install-coverage
base-install-data-local:: install-coverage
-mkdir -p $(DESTDIR)$(sysconfdir)/ceph
-mkdir -p $(DESTDIR)$(localstatedir)/log/ceph
-mkdir -p $(DESTDIR)$(localstatedir)/lib/ceph/tmp

LOCAL_INSTALLDATA += base-install-data-local

uninstall-local:: uninstall-coverage
-rmdir -p $(DESTDIR)$(sysconfdir)/ceph/
-rmdir -p $(DESTDIR)$(localstatedir)/log/ceph
Expand Down Expand Up @@ -277,3 +286,9 @@ if ENABLE_SERVER
include Makefile-server.am
endif

# local targets

all-local: $(LOCAL_ALL)
clean-local: $(LOCAL_CLEAN)
install-exec-local: $(LOCAL_INSTALLEXEC)
install-data-local: $(LOCAL_INSTALLDATA)
10 changes: 7 additions & 3 deletions src/ceph-detect-init/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ EXTRA_DIST += \
ceph-detect-init/tests/test_all.py \
ceph-detect-init/tox.ini

all-local::
ceph-detect-init-all:
cd $(srcdir)/ceph-detect-init ; python setup.py build

clean-local::
ceph-detect-init-clean:
cd $(srcdir)/ceph-detect-init ; python setup.py clean ; rm -fr wheelhouse .tox build .coverage *.egg-info

install-data-local::
ceph-detect-init-install-data:
cd $(srcdir)/ceph-detect-init ; \
if test "$(DESTDIR)" ; then \
if lsb_release -si | grep --quiet 'Ubuntu\|Debian\|Devuan' ; then \
Expand All @@ -70,3 +70,7 @@ install-data-local::
root="--root=$(DESTDIR)" ; \
fi ; \
python setup.py install $$root $$options

LOCAL_ALL += ceph-detect-init-all
LOCAL_CLEAN += ceph-detect-init-clean
LOCAL_INSTALLDATA += ceph-detect-init-install-data
1 change: 1 addition & 0 deletions src/pybind/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/__pycache__
51 changes: 51 additions & 0 deletions src/pybind/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
EXTRA_DIST += $(srcdir)/pybind/setup.py $(srcdir)/pybind/rbd.pyx

if ENABLE_CLIENT
if WITH_RADOS
if WITH_RBD
if WITH_CYTHON

PY_DISTUTILS = \
CPPFLAGS="-iquote \${abs_srcdir}/include ${AM_CPPFLAGS} ${CPPFLAGS}" \
CFLAGS="-iquote \${abs_srcdir}/include ${AM_CFLAGS} ${CFLAGS}" \
LDFLAGS="-L\${abs_builddir}/.libs $(subst -pie,,${AM_LDFLAGS}) ${LDFLAGS}" \
CYTHON_BUILD_DIR="$(shell readlink -f $(builddir))/build" \
${PYTHON} ./setup.py

pybind-all: librbd.la ${srcdir}/ceph_ver.h
cd $(srcdir)/pybind; $(PY_DISTUTILS) build \
--build-base $(shell readlink -f $(builddir))/build \
--verbose

pybind-clean: ${srcdir}/ceph_ver.h
cd $(srcdir)/pybind; $(PY_DISTUTILS) clean \
--build-base $(shell readlink -f $(builddir))/build \
--verbose

pybind-install-exec: ${srcdir}/ceph_ver.h
if test "$(DESTDIR)" ; then \
if lsb_release -si | grep --quiet 'Ubuntu\|Debian\|Devuan' ; then \
options=--install-layout=deb ; \
else \
options=--prefix=/usr ; \
fi ; \
root="--root=$(DESTDIR)" ; \
else \
options=--prefix=$(prefix) ; \
fi ; \
cd $(srcdir)/pybind; $(PY_DISTUTILS) build \
--build-base $(shell readlink -f $(builddir))/build \
install \
$$options $$root \
--single-version-externally-managed \
--record /dev/null \
--verbose

LOCAL_ALL += pybind-all
LOCAL_CLEAN += pybind-clean
LOCAL_INSTALLEXEC += pybind-install-exec

endif
endif
endif
endif
Loading

0 comments on commit 701a662

Please sign in to comment.