dynamically link libibverbs and librdma for using stgt without having userspace IB (e.g tcp mode). Signed-off-by: Doron Shoham <dorons@xxxxxxxxxxxx> --- usr/Makefile | 36 ++++++++++++++++----- usr/iscsi/iscsi_rdma.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++ usr/iscsi/libtgt_rdma.c | 6 +++- 3 files changed, 109 insertions(+), 10 deletions(-) create mode 100644 usr/iscsi/iscsi_rdma.c diff --git a/usr/Makefile b/usr/Makefile index 82ddf07..8867e43 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 @@ -14,11 +16,16 @@ TGTD_OBJS += $(addprefix iscsi/, conn.o param.o session.o \ TGTD_OBJS += bs_rdwr.o bs_aio.o LIBS += -lcrypto -ifneq ($(ISCSI_RDMA),) -CFLAGS += -DISCSI_RDMA + +ifneq ($(findstring verbs.h,$(wildcard /usr/include/infiniband/*.h)), ) +ifneq ($(findstring rdma_cma.h,$(wildcard /usr/include/rdma/*.h)), ) TGTD_OBJS += iscsi/iscsi_rdma.o -LIBS += -libverbs -lrdmacm +ISER_OBJS = iscsi/libtgt_rdma.o +SO_NAME = libtgtrdma.so +SO_LIBS = $(SO_NAME).0.0 +endif endif + endif ifneq ($(FCP),) @@ -54,6 +61,7 @@ CFLAGS += -g -O2 -Wall -Wstrict-prototypes -fPIC LIBS += -lpthread + PROGRAMS += tgtd tgtadm SCRIPTS += ../scripts/tgt-setup-lun ../scripts/tgt-admin TGTD_OBJS += tgtd.o mgmt.o target.o scsi.o log.o driver.o util.o work.o \ @@ -65,10 +73,10 @@ MANPAGES = ../doc/manpages/tgtadm.8 ../doc/manpages/tgt-admin.8 \ TGTD_DEP = $(TGTD_OBJS:.o=.d) .PHONY:all -all: $(PROGRAMS) +all: $(PROGRAMS) $(SO_LIBS) tgtd: $(TGTD_OBJS) - $(CC) $^ -o $@ $(LIBS) + $(CC) -Xlinker -E $^ -o $@ $(LIBS) -include $(TGTD_DEP) @@ -81,10 +89,20 @@ tgtadm: tgtadm.o $(CC) -c $(CFLAGS) $*.c -o $*.o @$(CC) -MM $(CFLAGS) -MF $*.d -MT $*.o $*.c +$(SO_LIBS): $(ISER_OBJS) + rm -f $@ $(SO_NAME) + $(LD) -shared -soname $(SO_LIBS) -o $(SO_LIBS) $(ISER_OBJS) + ln -s $(SO_LIBS) $(SO_NAME) + .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: $(SO_LIBS) + rm -f $(DESTDIR)$(libdir)/$(SO_NAME) + install -m 755 $(SO_LIBS) $(DESTDIR)$(libdir) + ln -s $(DESTDIR)/usr/lib64/$(SO_LIBS) $(DESTDIR)$(libdir)/$(SO_NAME) install_doc: $(MANPAGES) install -d -m 755 $(DESTDIR)$(mandir)/man8 @@ -92,4 +110,4 @@ install_doc: $(MANPAGES) .PHONY: clean clean: - rm -f *.[od] $(PROGRAMS) iscsi/*.[od] ibmvio/*.[od] fc/*.[od] fcoe/*.[od] + rm -f *.[od] $(PROGRAMS) $(SO_LIBS) iscsi/*.[od] ibmvio/*.[od] fc/*.[od] fcoe/*.[od] diff --git a/usr/iscsi/iscsi_rdma.c b/usr/iscsi/iscsi_rdma.c new file mode 100644 index 0000000..31b04a4 --- /dev/null +++ b/usr/iscsi/iscsi_rdma.c @@ -0,0 +1,77 @@ +/* + * iSCSI extensions for RDMA (iSER) data path + * + * Copyright (C) 2007 Dennis Dalessandro (dennis@xxxxxxx) + * Copyright (C) 2007 Ananth Devulapalli (ananth@xxxxxxx) + * Copyright (C) 2007 Pete Wyckoff (pw@xxxxxxx) + * + * 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> +#include <syslog.h> + +static void *pverbs; +static void *prdma; +static void *ptgtrdma; + +__attribute__((constructor)) static void iser_transport_init(void) +{ + void (*iser_init)(void); + char *error; + + pverbs = dlopen("libibverbs.so",RTLD_NOW|RTLD_GLOBAL); + if (!pverbs) { + goto Exit; /* do not register iser transport */ + } + + prdma = dlopen("librdmacm.so",RTLD_NOW|RTLD_GLOBAL); + if (!prdma) { + goto Exit; /* do not register iser transport */ + } + + ptgtrdma = dlopen("libtgtrdma.so",RTLD_NOW|RTLD_GLOBAL); + if (!ptgtrdma) { + goto Exit; + } + + dlerror(); /* Clear any existing error */ + iser_init = dlsym(ptgtrdma, "iser_transport_init"); + if ((error = dlerror()) != NULL) { + syslog(LOG_ERR, "%s\n", error); + goto Exit; + } + + (*iser_init)(); + return; +Exit: + syslog(LOG_ERR, "%s - iser transport not used", dlerror()); + if (pverbs) + dlclose(pverbs); + if (prdma) + dlclose(prdma); +} + +__attribute__((destructor)) static void iser_transport_close(void) +{ + syslog(LOG_INFO, "iser transport cleanup"); + if (pverbs) + dlclose(pverbs); + if (prdma) + dlclose(prdma); + if (ptgtrdma) + dlclose(ptgtrdma); +} diff --git a/usr/iscsi/libtgt_rdma.c b/usr/iscsi/libtgt_rdma.c index d3b5147..d6ba5fa 100644 --- a/usr/iscsi/libtgt_rdma.c +++ b/usr/iscsi/libtgt_rdma.c @@ -30,6 +30,8 @@ #include <sys/epoll.h> #include <infiniband/verbs.h> #include <rdma/rdma_cma.h> +#include <dlfcn.h> +#include <syslog.h> #include "util.h" #include "iscsid.h" @@ -1754,7 +1756,9 @@ static struct iscsi_transport iscsi_iser = { .ep_getpeername = iscsi_rdma_getpeername, }; -__attribute__((constructor)) static void iser_transport_init(void) +void iser_transport_init(void) { + syslog(LOG_INFO, "iser transport register"); iscsi_transport_register(&iscsi_iser); + return; } -- 1.5.3.8 -- 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