[openib-general] [PATCH/RFC] libmthca: Match new libibverbs driver loading scheme

Roland Dreier rdreier at cisco.com
Mon Nov 27 15:11:05 PST 2006


Here's the corresponding libmthca patch.
(This should still work against libibverbs 1.0 too)
---
 Makefile.am  |   25 +++++++++++++++++--------
 configure.in |   17 +++++++++++++++--
 src/mthca.c  |   23 ++++++++++++-----------
 3 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..610c8f8 100644
--- a/configure.in
+++ b/configure.in
@@ -28,11 +28,11 @@ dnl Checks for libraries
 AC_CHECK_LIB(ibverbs, ibv_get_device_list, [],
     AC_MSG_ERROR([ibv_get_device_list() not found.  libmthca requires libibverbs.]))
 
+
 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 +44,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/src/mthca.c b/src/mthca.c
index 27a72a4..81ac891 100644
--- a/src/mthca.c
+++ b/src/mthca.c
@@ -43,7 +43,7 @@ #include <sys/mman.h>
 #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 cha
 }
 #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(st
 				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 */




More information about the general mailing list