Re: [PATCH 2/2] dynamically link libibverbs and librdma

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Pete,

Below are my changes to your patch.
Please tell me if you are ok with it.
If you are good with my changes I think that it is very
important that this patch will be part of tgt.

Thanks,
Doron

Compile iscsi_rdma as a separate object that can be dynamically
loaded, if the system has the libraries to support it.

Signed-off-by: Doron Shoham <dorons@xxxxxxxxxxxx>
---
 usr/Makefile                |   28 +++++++++++++++++++---------
 usr/iscsi/iscsi_rdma_load.c |   33 +++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 9 deletions(-)
 create mode 100644 usr/iscsi/iscsi_rdma_load.c

diff --git a/usr/Makefile b/usr/Makefile
index fba86c0..39a1dbe 100644
--- a/usr/Makefile
+++ b/usr/Makefile
@@ -1,4 +1,6 @@
 mandir = /usr/share/man
+libdir = /usr/lib64
+bindir = /usr/sbin
 
 ifneq ($(IBMVIO),)
 CFLAGS += -DIBMVIO -DUSE_KERNEL
@@ -15,9 +17,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 -Wl,-rpath -Wl,/usr/lib64
 endif
 endif
 
@@ -66,10 +70,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)
 
@@ -93,9 +100,12 @@ dump_tape: dump_tape.o libssc.o libcrc32c.o
 	@$(CC) -MM $(CFLAGS) -MF $*.d -MT $*.o $*.c
 
 .PHONY: install
-install: $(PROGRAMS) $(SCRIPTS) install_doc
-	install -d -m 755 $(DESTDIR)/usr/sbin
-	install -m 755 $(PROGRAMS) $(SCRIPTS) $(DESTDIR)/usr/sbin
+install: $(PROGRAMS) $(SCRIPTS) install_doc install_lib
+	install -d -m 755 $(DESTDIR)$(bindir)
+	install -m 755 $(PROGRAMS) $(SCRIPTS) $(DESTDIR)$(bindir)
+
+install_lib: $(ISER_SO)
+	install -m 755 $(ISER_SO) $(DESTDIR)$(libdir)
 
 install_doc: $(MANPAGES)
 	install -d -m 755 $(DESTDIR)$(mandir)/man8
@@ -103,4 +113,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..8f392d9
--- /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@xxxxxxxx>
+ *
+ * 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_rdma.so", RTLD_NOW);
+	if (!h)
+		fprintf(stderr, "%s: dlopen: %s\n", __func__, dlerror());
+}
+
-- 
1.5.3.6

--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux SCSI]     [Linux RAID]     [Linux Clusters]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]

  Powered by Linux