[stgt] [PATCH 1/2] Compile iser driver as a loadable module
Andy Grover
agrover at redhat.com
Wed Sep 28 22:26:24 CEST 2011
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 at redhat.com>
---
usr/Makefile | 30 ++++++++++++++++++++----------
usr/driver.c | 15 +++++++++++++++
2 files changed, 35 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/driver.c b/usr/driver.c
index f9e0d57..8e7e368 100644
--- a/usr/driver.c
+++ b/usr/driver.c
@@ -22,6 +22,8 @@
#include <errno.h>
#include <string.h>
#include <inttypes.h>
+#include <stdio.h>
+#include <dlfcn.h>
#include "list.h"
#include "tgtd.h"
@@ -36,12 +38,25 @@ struct tgt_driver *tgt_drivers[MAX_NR_DRIVERS] = {
int get_driver_index(char *name)
{
int i;
+ char tmp_name[32];
+ void *handle;
for (i = 0; tgt_drivers[i]; i++) {
if (!strcmp(name, tgt_drivers[i]->name))
return i;
}
+ /* try loading a driver, then check again */
+ snprintf(tmp_name, sizeof(tmp_name), "tgt-%s.so", name);
+
+ handle = dlopen(tmp_name, RTLD_LAZY);
+ if (handle) {
+ for (i = 0; tgt_drivers[i]; i++) {
+ if (!strcmp(name, tgt_drivers[i]->name))
+ return i;
+ }
+ }
+
return -ENOENT;
}
--
1.7.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