[openib-general] [PATCH 2/7] libmthca: Update libmthca for new libibverbs driver handling

Roland Dreier rolandd at cisco.com
Wed Jan 10 14:21:50 PST 2007


The latest libibverbs development tree changes how low-level drivers
are found.  The driver must be in a shared object like
libmthca-rdmav2.so in the ordinary library path, rather than
infiniband/mthca.so as for libibverbs 1.0.  In addition, the driver
must call ibv_register_driver() to pass its entry point to libibverbs,
rather than exporting an ibv_driver_init() function.

This patch adds autoconf tests to libmthca to detect whether it is
being built against a stable libibverbs 1.0 tree or the new libibverbs
development tree.  Then based on the result, it builds a library with
the appropriate name and with the correct driver initialization handling.

Signed-off-by: Roland Dreier <rolandd at cisco.com>
---
 Makefile.am  |   25 +++++++++++++++++--------
 configure.in |   16 ++++++++++++++--
 mthca.driver |    1 +
 src/mthca.c  |   23 ++++++++++++-----------
 4 files changed, 44 insertions(+), 21 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index d98bf05..e9be461 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,20 +1,29 @@
-mthcalibdir = $(libdir)/infiniband
-
-mthcalib_LTLIBRARIES = src/mthca.la
-
-src_mthca_la_CFLAGS = -g -Wall -D_GNU_SOURCE
+AM_CFLAGS = -g -Wall -D_GNU_SOURCE
 
 mthca_version_script = @MTHCA_VERSION_SCRIPT@
 
-src_mthca_la_SOURCES = src/ah.c src/buf.c src/cq.c src/memfree.c src/mthca.c \
+MTHCA_SOURCES = src/ah.c src/buf.c src/cq.c src/memfree.c src/mthca.c \
     src/qp.c src/srq.c src/verbs.c
-src_mthca_la_LDFLAGS = -avoid-version -module $(mthca_version_script)
+
+if HAVE_IBV_DEVICE_LIBRARY_EXTENSION
+    lib_LTLIBRARIES = src/libmthca.la
+    src_libmthca_la_SOURCES = $(MTHCA_SOURCES)
+    src_libmthca_la_LDFLAGS = -avoid-version -release @IBV_DEVICE_LIBRARY_EXTENSION@ \
+        $(mthca_version_script)
+    mthcaconfdir = $(sysconfdir)/libibverbs.d
+    mthcaconf_DATA = mthca.driver
+else
+    mthcalibdir = $(libdir)/infiniband
+    mthcalib_LTLIBRARIES = src/mthca.la
+    src_mthca_la_SOURCES = $(MTHCA_SOURCES)
+    src_mthca_la_LDFLAGS = -avoid-version -module $(mthca_version_script)
+endif
 
 DEBIAN = debian/changelog debian/compat debian/control debian/copyright \
     debian/libmthca1.install debian/libmthca-dev.install debian/rules
 
 EXTRA_DIST = src/doorbell.h src/mthca.h src/mthca-abi.h src/wqe.h \
-    src/mthca.map libmthca.spec.in
+    src/mthca.map libmthca.spec.in mthca.driver
 
 dist-hook: libmthca.spec
 	cp libmthca.spec $(distdir)
diff --git a/configure.in b/configure.in
index 475fd56..a749a93 100644
--- a/configure.in
+++ b/configure.in
@@ -32,7 +32,6 @@ dnl Checks for header files.
 AC_CHECK_HEADER(infiniband/driver.h, [],
     AC_MSG_ERROR([<infiniband/driver.h> not found.  libmthca requires libibverbs.]))
 AC_HEADER_STDC
-AC_CHECK_HEADERS(sysfs/libsysfs.h)
 AC_CHECK_HEADER(valgrind/memcheck.h, memcheck_ok=yes, memcheck_ok=no)
 
 if test $want_valgrind = yes && test $memcheck_ok = no; then
@@ -44,7 +43,20 @@ AC_C_CONST
 AC_CHECK_SIZEOF(long)
 
 dnl Checks for library functions
-AC_CHECK_FUNCS(ibv_read_sysfs_file ibv_dontfork_range ibv_dofork_range)
+AC_CHECK_FUNCS(ibv_read_sysfs_file ibv_dontfork_range ibv_dofork_range \
+    ibv_register_driver)
+
+dnl Now check if for libibverbs 1.0 vs 1.1
+dummy=if$$
+cat <<IBV_VERSION > $dummy.c
+#include <infiniband/driver.h>
+IBV_DEVICE_LIBRARY_EXTENSION
+IBV_VERSION
+IBV_DEVICE_LIBRARY_EXTENSION=`$CC $CPPFLAGS -E $dummy.c 2> /dev/null | tail -1`
+rm -f $dummy.c
+AM_CONDITIONAL(HAVE_IBV_DEVICE_LIBRARY_EXTENSION,
+    test $IBV_DEVICE_LIBRARY_EXTENSION != IBV_DEVICE_LIBRARY_EXTENSION)
+AC_SUBST(IBV_DEVICE_LIBRARY_EXTENSION)
 
 AC_CACHE_CHECK(whether ld accepts --version-script, ac_cv_version_script,
     [if test -n "`$LD --help < /dev/null 2>/dev/null | grep version-script`"; then
diff --git a/mthca.driver b/mthca.driver
new file mode 100644
index 0000000..5880a47
--- /dev/null
+++ b/mthca.driver
@@ -0,0 +1 @@
+driver mthca
diff --git a/src/mthca.c b/src/mthca.c
index 27a72a4..81ac891 100644
--- a/src/mthca.c
+++ b/src/mthca.c
@@ -43,7 +43,7 @@
 #include <pthread.h>
 #include <string.h>
 
-#ifdef HAVE_SYSFS_LIBSYSFS_H
+#ifndef HAVE_IBV_REGISTER_DRIVER
 #include <sysfs/libsysfs.h>
 #endif
 
@@ -256,8 +256,8 @@ static int ibv_read_sysfs_file(const char *dir, const char *file,
 }
 #endif /* HAVE_IBV_READ_SYSFS_FILE */
 
-struct ibv_device *ibv_driver_init(const char *uverbs_sys_path,
-				   int abi_version)
+static struct ibv_device *mthca_driver_init(const char *uverbs_sys_path,
+					    int abi_version)
 {
 	char			value[8];
 	struct mthca_device    *dev;
@@ -296,15 +296,16 @@ found:
 	return &dev->ibv_dev;
 }
 
+#ifdef HAVE_IBV_REGISTER_DRIVER
+static __attribute__((constructor)) void mthca_register_driver(void)
+{
+	ibv_register_driver("mthca", mthca_driver_init);
+}
+#else
 /*
  * Export the old libsysfs sysfs_class_device-based driver entry point
- * if libsysfs headers are installed.  It doesn't hurt to export it,
- * even if libibverbs is new enough not to use it; but if libsysfs
- * headers are not installed, we can assume that the version of
- * libibverbs we are building against is new enough not to use
- * openib_driver_init().
+ * if libibverbs does not export an ibv_register_driver() function.
  */
-#ifdef HAVE_SYSFS_LIBSYSFS_H
 struct ibv_device *openib_driver_init(struct sysfs_class_device *sysdev)
 {
 	int abi_ver = 0;
@@ -314,6 +315,6 @@ struct ibv_device *openib_driver_init(struct sysfs_class_device *sysdev)
 				value, sizeof value) > 0)
 		abi_ver = strtol(value, NULL, 10);
 
-	return ibv_driver_init(sysdev->path, abi_ver);
+	return mthca_driver_init(sysdev->path, abi_ver);
 }
-#endif /* HAVE_SYSFS_LIBSYSFS_H */
+#endif /* HAVE_IBV_REGISTER_DRIVER */
-- 
1.4.4.1





More information about the general mailing list