[openib-general] Re: libibcm and librdmacm are broken following removal of libsysfs from libibverbs

Roland Dreier rdreier at cisco.com
Thu May 25 09:28:24 PDT 2006


    Jack> Cause: These libs still depend on libsysfs, and leaned on
    Jack> libibverbs also depending on libsysfs

    Jack> If libibcm and librdmacm continue to depend on libsysfs,
    Jack> they must do this include themselves (say in files cm.c and
    Jack> cma.c).

Yes.

    Jack> I tried that, but this did not fix the problem entirely.
    Jack> Still get the following:

    Jack> ./src/.libs/librdmacm.so: undefined reference to
    Jack> `sysfs_read_attribute_value'

This is because they also have to link with libsysfs too.

The best thing to do would be to remove usage of libsysfs entirely,
but for now I just checked in the following change which fixes the
build (I also fixed the libraries so they work with libsysfs 2.0,
which no longer has sysfs_read_attribute_value()).

 - R.

--- libibcm/configure.in	(revision 7485)
+++ libibcm/configure.in	(working copy)
@@ -25,6 +25,8 @@ AC_CHECK_SIZEOF(long)
 dnl Checks for libraries
 if test "$disable_libcheck" != "yes"
 then
+AC_CHECK_LIB(sysfs, sysfs_open_class, [],
+    AC_MSG_ERROR([sysfs_open_class() not found.  libibcm requires libsysfs.]))
 AC_CHECK_LIB(ibverbs, ibv_get_device_list, [],
     AC_MSG_ERROR([ibv_get_device_list() not found.  libibcm requires libibverbs.]))
 #AC_CHECK_LIB(rdmacm, rdma_create_id, [],
@@ -34,6 +36,8 @@ fi
 dnl Checks for header files.
 if test "$disable_libcheck" != "yes"
 then
+AC_CHECK_HEADER(sysfs/libsysfs.h, [],
+    AC_MSG_ERROR([<sysfs/libsysfs.h> not found.  libibcm requires libsysfs.]))
 AC_CHECK_HEADER(infiniband/verbs.h, [],
     AC_MSG_ERROR([<infiniband/verbs.h> not found.  Is libibverbs installed?]))
 AC_CHECK_HEADER(infiniband/marshall.h, [],
--- libibcm/src/cm.c	(revision 7485)
+++ libibcm/src/cm.c	(working copy)
@@ -50,6 +50,8 @@
 #include <endian.h>
 #include <byteswap.h>
 
+#include <sysfs/libsysfs.h>
+
 #include <infiniband/cm.h>
 #include <infiniband/cm_abi.h>
 #include <infiniband/marshall.h>
@@ -115,8 +117,9 @@ static struct dlist *device_list;
 static int check_abi_version(void)
 {
 	char path[256];
-	char val[16];
+	struct sysfs_attribute *attr;
 	int abi_ver;
+	int ret = -1;
 
 	if (sysfs_get_mnt_path(path, sizeof path)) {
 		fprintf(stderr, PFX "couldn't find sysfs mount.\n");
@@ -124,20 +127,32 @@ static int check_abi_version(void)
 	}
 
 	strncat(path, "/class/infiniband_cm/abi_version", sizeof path);
-	if (sysfs_read_attribute_value(path, val, sizeof val)) {
-		fprintf(stderr, PFX "couldn't read ucm ABI version.\n");
+
+	attr = sysfs_open_attribute(path);
+	if (!attr) {
+		fprintf(stderr, PFX "couldn't open ucm ABI version.\n");
 		return -1;
 	}
 
-	abi_ver = strtol(val, NULL, 10);
+	if (sysfs_read_attribute(attr)) {
+		fprintf(stderr, PFX "couldn't read ucm ABI version.\n");
+		goto out;
+	}
+
+	abi_ver = strtol(attr->value, NULL, 10);
 	if (abi_ver < IB_USER_CM_MIN_ABI_VERSION ||
 	    abi_ver > IB_USER_CM_MAX_ABI_VERSION) {
 		fprintf(stderr, PFX "kernel ABI version %d "
 			"doesn't match library version %d.\n",
 			abi_ver, IB_USER_CM_MAX_ABI_VERSION);
-		return -1;
+		goto out;
 	}
-	return 0;
+
+	ret = 0;
+
+out:
+	sysfs_close_attribute(attr);
+	return ret;
 }
 
 static uint64_t get_device_guid(struct sysfs_class_device *ibdev)
--- librdmacm/configure.in	(revision 7485)
+++ librdmacm/configure.in	(working copy)
@@ -25,6 +25,8 @@ AC_CHECK_SIZEOF(long)
 dnl Checks for libraries
 if test "$disable_libcheck" != "yes"
 then
+AC_CHECK_LIB(sysfs, sysfs_open_class, [],
+    AC_MSG_ERROR([sysfs_open_class() not found.  librdmacm requires libsysfs.]))
 AC_CHECK_LIB(ibverbs, ibv_get_device_list, [],
     AC_MSG_ERROR([ibv_get_device_list() not found.  librdmacm requires libibverbs.]))
 fi
@@ -32,6 +34,8 @@ fi
 dnl Checks for header files.
 if test "$disable_libcheck" != "yes"
 then
+AC_CHECK_HEADER(sysfs/libsysfs.h, [],
+    AC_MSG_ERROR([<sysfs/libsysfs.h> not found.  librdmacm requires libsysfs.]))
 AC_CHECK_HEADER(infiniband/verbs.h, [],
     AC_MSG_ERROR([<infiniband/verbs.h> not found.  Is libibverbs installed?]))
 fi
--- librdmacm/src/cma.c	(revision 7485)
+++ librdmacm/src/cma.c	(working copy)
@@ -49,6 +49,8 @@
 #include <endian.h>
 #include <byteswap.h>
 
+#include <sysfs/libsysfs.h>
+
 #include <infiniband/marshall.h>
 #include <rdma/rdma_cma.h>
 #include <rdma/rdma_cma_abi.h>
@@ -140,7 +142,8 @@ static void ucma_cleanup(void)
 static int check_abi_version(void)
 {
 	char path[256];
-	char val[16];
+	struct sysfs_attribute *attr;
+	int ret = -1;
 
 	if (sysfs_get_mnt_path(path, sizeof path)) {
 		fprintf(stderr, "librdmacm: couldn't find sysfs mount.\n");
@@ -148,17 +151,33 @@ static int check_abi_version(void)
 	}
 
 	strncat(path, "/class/misc/rdma_cm/abi_version", sizeof path);
-	if (!sysfs_read_attribute_value(path, val, sizeof val))
-		abi_ver = strtol(val, NULL, 10);
+
+	attr = sysfs_open_attribute(path);
+	if (!attr) {
+		fprintf(stderr, "librdmacm: couldn't open rdma_cm ABI version.\n");
+		return -ENOSYS;
+	}
+
+	if (sysfs_read_attribute(attr)) {
+		fprintf(stderr, "librdmacm: couldn't read rdma_cm ABI version.\n");
+		goto out;
+	}
+
+	abi_ver = strtol(attr->value, NULL, 10);
 
 	if (abi_ver < RDMA_USER_CM_MIN_ABI_VERSION ||
 	    abi_ver > RDMA_USER_CM_MAX_ABI_VERSION) {
 		fprintf(stderr, "librdmacm: kernel ABI version %d "
 				"doesn't match library version %d.\n",
 				abi_ver, RDMA_USER_CM_MAX_ABI_VERSION);
-		return -ENOSYS;
+		goto out;
 	}
-	return 0;
+
+	ret = 0;
+
+out:
+	sysfs_close_attribute(attr);
+	return ret;
 }
 
 static int ucma_init(void)



More information about the general mailing list