[stgt] [PATCH 2/2] dynamically link libibverbs and librdma
Pete Wyckoff
pw at padd.com
Wed Oct 15 13:28:10 CEST 2008
dorons at Voltaire.COM wrote on Sun, 12 Oct 2008 11:55 +0200:
> This is the current patch (with your comment about the libdir).
> The real problem is how to fix the symboling issue while not
> making the rpm to be depended on userspace IB.
What you sent did not include your file rename and new file to do
the dlopen. But I didn't need them anyway.
Here is the approach you should follow.
1. Do not rename iscsi_rdma.c, it just adds confusion.
2. Compile just iscsi_rdma.c -> iscsi_rdma.so.
3. Add a small file to dlopen() iscsi_rdma.so. If it works, that
transport is now available; if not, no problem.
The patch below does these steps, and is nice and small. It uses
RDMA if it finds iscsi/iscsi_rdma.so and librdmacm.so and
libibverbs.so. If any of these is missing, it complains, but
continues to operate fine with just TCP.
The dependencies are just what they are supposed to be: only the
rdma so pulls libibverbs.
ib26$ ldd tgtd
linux-vdso.so.1 => (0x00007fffab7fe000)
libcrypto.so.7 => /lib64/libcrypto.so.7 (0x00000030ea400000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x000000316a400000)
libc.so.6 => /lib64/libc.so.6 (0x00000030de400000)
libdl.so.2 => /lib64/libdl.so.2 (0x00000030dec00000)
libz.so.1 => /lib64/libz.so.1 (0x00000030df400000)
/lib64/ld-linux-x86-64.so.2 (0x00000030de000000)
ib26$ ldd iscsi/iscsi_rdma.so
linux-vdso.so.1 => (0x00007fff1d7fe000)
libibverbs.so.1 => /usr/lib64/libibverbs.so.1 (0x00002b928d533000)
librdmacm.so.1 => /usr/lib64/librdmacm.so.1 (0x00002b928d740000)
libc.so.6 => /lib64/libc.so.6 (0x00002b928d945000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00002b928dcb1000)
libdl.so.2 => /lib64/libdl.so.2 (0x00002b928decd000)
/lib64/ld-linux-x86-64.so.2 (0x00000030de000000)
If you're having RPM dependency problems, that's a different issue,
and we can figure it out separately.
After doing this, I now believe that this patch should not be part
of tgt. People who want RDMA will compile it in on purpose. For
your RPM, the patch is small enough that you can carry it there.
You need so much more machinery to make a proper RPM, like all the
install paths and shlib versioning. I explicitly left out the
/usr/lib64 bit you had added, because there is no way to get that
right without a autoconf-like setup. This is also part of the job
for the spec file.
-- Pete
From: Pete Wyckoff <pw at padd.com>
Date: Wed, 15 Oct 2008 07:08:47 -0400
Subject: [PATCH] iser shlib
Compile iscsi_rdma as a separate object that can be dynamically
loaded, if the system has the libraries to support it.
Signed-off-by: Pete Wyckoff <pw at padd.com>
---
usr/Makefile | 17 +++++++++++------
usr/iscsi/iscsi_rdma_load.c | 33 +++++++++++++++++++++++++++++++++
2 files changed, 44 insertions(+), 6 deletions(-)
create mode 100644 usr/iscsi/iscsi_rdma_load.c
diff --git a/usr/Makefile b/usr/Makefile
index fba86c0..c82eced 100644
--- a/usr/Makefile
+++ b/usr/Makefile
@@ -15,9 +15,11 @@ TGTD_OBJS += bs_rdwr.o bs_aio.o
LIBS += -lcrypto
ifneq ($(ISCSI_RDMA),)
-CFLAGS += -DISCSI_RDMA
-TGTD_OBJS += iscsi/iscsi_rdma.o
-LIBS += -libverbs -lrdmacm
+ISER_SO := iscsi/iscsi_rdma.so
+ISER_OBJS += iscsi/iscsi_rdma.o
+ISER_LIBS += -libverbs -lrdmacm
+TGTD_OBJS += iscsi/iscsi_rdma_load.o
+TGTD_LDOPTS += -Wl,--export-dynamic
endif
endif
@@ -66,10 +68,13 @@ MANPAGES = ../doc/manpages/tgtadm.8 ../doc/manpages/tgt-admin.8 \
TGTD_DEP = $(TGTD_OBJS:.o=.d)
.PHONY:all
-all: $(PROGRAMS)
+all: $(PROGRAMS) $(ISER_SO)
tgtd: $(TGTD_OBJS)
- $(CC) $^ -o $@ $(LIBS)
+ $(CC) $(TGTD_LDOPTS) $^ -o $@ $(LIBS)
+
+$(ISER_SO): $(ISER_OBJS)
+ $(CC) -shared -o $@ $^ $(ISER_LIBS)
-include $(TGTD_DEP)
@@ -103,4 +108,4 @@ install_doc: $(MANPAGES)
.PHONY: clean
clean:
- rm -f *.[od] $(PROGRAMS) iscsi/*.[od] ibmvio/*.[od] fc/*.[od] fcoe/*.[od]
+ rm -f *.[od] $(PROGRAMS) iscsi/*.[od] ibmvio/*.[od] fc/*.[od] fcoe/*.[od] $(ISER_SO) $(ISER_OBJS)
diff --git a/usr/iscsi/iscsi_rdma_load.c b/usr/iscsi/iscsi_rdma_load.c
new file mode 100644
index 0000000..581f4f1
--- /dev/null
+++ b/usr/iscsi/iscsi_rdma_load.c
@@ -0,0 +1,33 @@
+/*
+ * Try to load RDMA transport, if libraries are available
+ *
+ * Copyright (C) 2008 Pete Wyckoff <pw at padd.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, version 2 of the
+ * License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+#include <stdio.h>
+#include <dlfcn.h>
+
+
+__attribute__((constructor)) static void iser_rdma_load(void)
+{
+ void *h;
+
+ h = dlopen("iscsi/iscsi_rdma.so", RTLD_NOW);
+ if (!h)
+ fprintf(stderr, "%s: dlopen: %s\n", __func__, dlerror());
+}
+
--
1.5.5.1
--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
More information about the stgt
mailing list