[PATCH 1/3] Compile iser driver as a loadable module

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

 



Drivers are already modularized in the code, so it is straightforward to
change the build to target a separate loadable module. Also, modify
get_driver_index to try to load a module when lld is unknown.

This will allow packaging of base tgtd and iser module separately, so
the majority of users will not have to install dependencies they don't
need.

Signed-off-by: Andy Grover <agrover@xxxxxxxxxx>
---
 usr/Makefile |   30 ++++++++++++++++++++----------
 usr/tgtd.c   |    4 ++++
 2 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/usr/Makefile b/usr/Makefile
index e15ff6a..b8ab805 100644
--- a/usr/Makefile
+++ b/usr/Makefile
@@ -1,4 +1,5 @@
 sbindir ?= $(PREFIX)/sbin
+libdir ?= $(PREFIX)/lib/tgt
 
 ifneq ($(shell test -e /usr/include/linux/signalfd.h && echo 1),)
 CFLAGS += -DUSE_SIGNALFD
@@ -13,11 +14,6 @@ TGTD_OBJS += $(addprefix iscsi/, conn.o param.o session.o \
 		isns.o)
 TGTD_OBJS += bs_rdwr.o bs_aio.o
 
-ifneq ($(ISCSI_RDMA),)
-TGTD_OBJS += iscsi/iser.o iscsi/iser_text.o
-LIBS += -libverbs -lrdmacm
-endif
-
 INCLUDES += -I.
 
 CFLAGS += -D_GNU_SOURCE
@@ -30,9 +26,13 @@ endif
 CFLAGS += -Wall -Wstrict-prototypes -fPIC
 CFLAGS += -DTGT_VERSION=\"$(VERSION)$(EXTRAVERSION)\"
 
-LIBS += -lpthread
+LIBS += -lpthread -ldl
 
 PROGRAMS += tgtd tgtadm tgtimg
+ifneq ($(ISCSI_RDMA),)
+DRIVERS += tgt-iser.so
+endif
+
 TGTD_OBJS += tgtd.o mgmt.o target.o scsi.o log.o driver.o util.o work.o \
 		parser.o spc.o sbc.o mmc.o osd.o scc.o smc.o \
 		ssc.o bs_ssc.o libssc.o \
@@ -41,10 +41,12 @@ TGTD_OBJS += tgtd.o mgmt.o target.o scsi.o log.o driver.o util.o work.o \
 TGTD_DEP = $(TGTD_OBJS:.o=.d)
 
 .PHONY:all
-all: $(PROGRAMS)
+all: $(PROGRAMS) $(DRIVERS)
+
+LDFLAGS = -Wl,-E,-rpath=$(libdir)
 
 tgtd: $(TGTD_OBJS)
-	$(CC) $^ -o $@ $(LIBS)
+	$(CC) $^ -o $@ $(LDFLAGS) $(LIBS)
 
 -include $(TGTD_DEP)
 
@@ -58,15 +60,23 @@ tgtimg: tgtimg.o libssc.o libcrc32c.o
 
 -include tgtimg.d libssc.d
 
+tgt-iser.so: CFLAGS += -shared -libverbs -lrdmacm
+tgt-iser.so: iscsi/iser.o iscsi/iser_text.o
+	$(CC) $(CFLAGS) -o $@ $^
+
 %.o: %.c
 	$(CC) -c $(CFLAGS) $*.c -o $*.o
 	@$(CC) -MM $(CFLAGS) -MF $*.d -MT $*.o $*.c
 
 .PHONY: install
-install: $(PROGRAMS)
+install: $(PROGRAMS) $(DRIVERS)
 	install -d -m 755 $(DESTDIR)$(sbindir)
 	install -m 755 $(PROGRAMS) $(DESTDIR)$(sbindir)
+ifneq ($(DRIVERS),)
+	install -d -m 755 $(DESTDIR)$(libdir)
+	install -m 755 $(DRIVERS) $(DESTDIR)$(libdir)
+endif
 
 .PHONY: clean
 clean:
-	rm -f *.[od] $(PROGRAMS) iscsi/*.[od] ibmvio/*.[od] fc/*.[od]
+	rm -f *.[od] $(PROGRAMS) *.so iscsi/*.[od] ibmvio/*.[od] fc/*.[od]
diff --git a/usr/tgtd.c b/usr/tgtd.c
index 30d5e9d..a9b2027 100644
--- a/usr/tgtd.c
+++ b/usr/tgtd.c
@@ -35,6 +35,7 @@
 #include <sys/epoll.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <dlfcn.h>
 
 #include "list.h"
 #include "tgtd.h"
@@ -411,6 +412,9 @@ static int lld_init(char *args)
 {
 	int i, err, nr;
 
+	/* iser is modular, try to load it */
+	dlopen("tgt-iser.so", RTLD_LAZY);
+
 	for (i = nr = 0; tgt_drivers[i]; i++) {
 		if (tgt_drivers[i]->init) {
 			err = tgt_drivers[i]->init(i, args);
-- 
1.7.1

--
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