dynamic engines: fix several issues
cover dynamic engines: fix several issues
1) Fix the build
2) Fix engine loading
3) Fix engine listing
Thanks,
-Eric
PATCH 1/3 fix dynamic engine buil
Builds with --dynamic-libengines are currently broken, because the rule to build the libraries was moved out of the template that creates them:
make: *** No rule to make target 'engines/libpmem.so', needed by 'all'. Stop.
make: *** Waiting for unfinished jobs....
Fix this by moving the rule back into the template, calling the template to create rules only after FIO_CFLAGS has been incorporated into CFLAGS, and using CFLAGS + -fPIC in that rule rather than FIO_CFLAGS.
--- Makefile | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
Makefile +5 -8
@@ -255,7 +255,9 @@ ifdef CONFIG_DYNAMIC_ENGINES DYNAMIC_ENGS := $(ENGINES) define engine_template = $(1)_OBJS := $$($(1)_SRCS:.c=.o) -$$($(1)_OBJS): FIO_CFLAGS += -fPIC $$($(1)_CFLAGS) +$$($(1)_OBJS): CFLAGS := -fPIC $$($(1)_CFLAGS) $(CFLAGS) +engines/lib$(1).so: $$($(1)_OBJS) + $$(QUIET_LINK)$(CC) -shared -rdynamic -fPIC -Wl,-soname,fio-$(1).so.1 $$($(1)_LIBS) -o $$@ $$< ENGS_OBJS += engines/lib$(1).so endef else # !CONFIG_DYNAMIC_ENGINES
@@ -266,6 +268,8 @@ CFLAGS += $$($(1)_CFLAGS) endef endif +override CFLAGS := -DFIO_VERSION='"$(FIO_VERSION)"' $(FIO_CFLAGS) $(CFLAGS) + $(foreach eng,$(ENGINES),$(eval $(call engine_template,$(eng)))) OBJS := $(SOURCE:.c=.o)
@@ -438,8 +442,6 @@ FIO-VERSION-FILE: FORCE @$(SHELL) $(SRCDIR)/FIO-VERSION-GEN -include FIO-VERSION-FILE -override CFLAGS := -DFIO_VERSION='"$(FIO_VERSION)"' $(FIO_CFLAGS) $(CFLAGS) - %.o : %.c @mkdir -p $(dir $@) $(QUIET_CC)$(CC) -o $@ $(CFLAGS) $(CPPFLAGS) -c $<
@@ -567,11 +569,6 @@ unittests/unittest: $(UT_OBJS) $(UT_TARGET_OBJS) $(QUIET_LINK)$(CC) $(LDFLAGS) -o $@ $(UT_OBJS) $(UT_TARGET_OBJS) -lcunit $(LIBS) endif -ifdef CONFIG_DYNAMIC_ENGINES -engines/lib$(1).so: $$($(1)_OBJS) - $$(QUIET_LINK)$(CC) -shared -rdynamic -fPIC -Wl,-soname,fio-$(1).so.1 $$($(1)_LIBS) -o $$@ $$< -endif - clean: FORCE @rm -f .depend $(FIO_OBJS) $(GFIO_OBJS) $(OBJS) $(T_OBJS) $(UT_OBJS) $(PROGS) $(T_PROGS) $(T_TEST_PROGS) core.* core gfio unittests/unittest FIO-VERSION-FILE *.[do] lib/*.d oslib/*.[do] crc/*.d engines/*.[do] engines/*.so profiles/*.[do] t/*.[do] unittests/*.[do] unittests/*/*.[do] config-host.mak config-host.h y.tab.[ch] lex.yy.c exp/*.[do] lexer.h @rm -f t/fio-btrace2fio t/io_uring t/read-to-pipe-async
Signature · 1 line
1.8.3.1
PATCH 2/3 fix dynamic engine loading for libaio engine etc
In reply to Eric SandeenThe dynamic engine loading for libaio (and some others) currently fails because the dlopen routine is looking for ("lib%s", enginename) which translates into "liblibiscsi.so":
openat(AT_FDCWD, "/usr/lib64/fio/liblibiscsi.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) Engine libiscsi not found; Either name is invalid, was not built, or fio-engine-libiscsi package is missing.
fio: engine libiscsi not loadable
IO engine libiscsi not found
The Makefile decide to name this engine "iscsi" instead of "libiscsi", which leads to "libiscsi.so" not "liblibiscsi.so" hence the mismatch.
OTOH, "liblibiscsi.so" seems a bit bonkers.
Try to resolve all this by:
1) make all of the engine names match the documented engine names in the Makefile, i.e. "iscsi" -> "libiscsi"
2) change the created library filenames to "fio-$(ENGINENAME)" from "lib$(ENGINENAME)" to avoid the "liblib" prefix.
So now we consistently have the libraries named "fio-$(ENGINENAME).so"
fio-http.so
fio-libaio.so
etc.
--- Makefile | 34 +++++++++++++++++----------------- ioengines.c | 2 +- 2 files changed, 18 insertions(+), 18 deletions(-)
Makefile +17 -17
@@ -66,10 +66,10 @@ ifdef CONFIG_LIBHDFS endif ifdef CONFIG_LIBISCSI - iscsi_SRCS = engines/libiscsi.c - iscsi_LIBS = $(LIBISCSI_LIBS) - iscsi_CFLAGS = $(LIBISCSI_CFLAGS) - ENGINES += iscsi + libiscsi_SRCS = engines/libiscsi.c + libiscsi_LIBS = $(LIBISCSI_LIBS) + libiscsi_CFLAGS = $(LIBISCSI_CFLAGS) + ENGINES += libiscsi endif ifdef CONFIG_LIBNBD
@@ -85,14 +85,14 @@ else ifdef CONFIG_32BIT CPPFLAGS += -DBITS_PER_LONG=32 endif ifdef CONFIG_LIBAIO - aio_SRCS = engines/libaio.c - aio_LIBS = -laio + libaio_SRCS = engines/libaio.c + libaio_LIBS = -laio ifdef CONFIG_LIBAIO_URING - aio_LIBS = -luring + libaio_LIBS = -luring else - aio_LIBS = -laio + libaio_LIBS = -laio endif - ENGINES += aio + ENGINES += libaio endif ifdef CONFIG_RDMA rdma_SRCS = engines/rdma.c
@@ -179,17 +179,17 @@ ifdef CONFIG_LINUX_DEVDAX ENGINES += dev-dax endif ifdef CONFIG_LIBPMEM - pmem_SRCS = engines/libpmem.c - pmem_LIBS = -lpmem - ENGINES += pmem + libpmem_SRCS = engines/libpmem.c + libpmem_LIBS = -lpmem + ENGINES += libpmem endif ifdef CONFIG_IME SOURCE += engines/ime.c endif ifdef CONFIG_LIBZBC - zbc_SRCS = engines/libzbc.c - zbc_LIBS = -lzbc - ENGINES += zbc + libzbc_SRCS = engines/libzbc.c + libzbc_LIBS = -lzbc + ENGINES += libzbc endif ifeq ($(CONFIG_TARGET_OS), Linux)
@@ -256,9 +256,9 @@ ifdef CONFIG_DYNAMIC_ENGINES define engine_template = $(1)_OBJS := $$($(1)_SRCS:.c=.o) $$($(1)_OBJS): CFLAGS := -fPIC $$($(1)_CFLAGS) $(CFLAGS) -engines/lib$(1).so: $$($(1)_OBJS) +engines/fio-$(1).so: $$($(1)_OBJS) $$(QUIET_LINK)$(CC) -shared -rdynamic -fPIC -Wl,-soname,fio-$(1).so.1 $$($(1)_LIBS) -o $$@ $$< -ENGS_OBJS += engines/lib$(1).so +ENGS_OBJS += engines/fio-$(1).so endef else # !CONFIG_DYNAMIC_ENGINES define engine_template =
ioengines.c +1 -1
@@ -91,7 +91,7 @@ static void *dlopen_external(struct thread_data *td, const char *engine)char engine_path[PATH_MAX ];void *dlhandle; -sprintf (engine_path,"%s/lib%s.so" ,FIO_EXT_ENG_DIR , engine); +sprintf (engine_path,"%s/fio-%s.so" ,FIO_EXT_ENG_DIR , engine); dlhandle =dlopen (engine_path,RTLD_LAZY );if (!dlhandle)
Signature · 1 line
1.8.3.1
PATCH 3/3 list all available dynamic ioengines with --enghelp
In reply to Eric SandeenWhen dynamic engines are enabled, "fio --enghelp" does not list all available engines as the man page says it will:
If no ioengine is given, list all available ioengines.
Fix this by opening FIO_EXT_ENG_DIR and attempting dlopen_ioengine everything that's found there.
--- ioengines.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-)
ioengines.c +33 -1
@@ -15,6 +15,8 @@#include <dlfcn.h> #include <fcntl.h> #include <assert.h> +#include <sys/types.h> +#include <dirent.h> #include "fio.h" #include "diskutil.h"
@@ -630,6 +632,34 @@ int td_io_get_file_size(struct thread_data *td, struct fio_file *f)return td->io_ops->get_file_size (td, f); } +#ifdef CONFIG_DYNAMIC_ENGINES +/* Load all dynamic engines in FIO_EXT_ENG_DIR for enghelp command */ +static void +fio_load_dynamic_engines (struct thread_data *td) +{ +DIR *dirhandle =NULL ; +struct dirent *dirent =NULL ; +char engine_path[PATH_MAX ]; + + dirhandle =opendir (FIO_EXT_ENG_DIR ); +if (!dirhandle) +return ; + +while ((dirent =readdir (dirhandle)) !=NULL ) { +if (!strcmp (dirent->d_name,"." ) || + !strcmp (dirent->d_name,".." )) +continue ; + +sprintf (engine_path,"%s/%s" ,FIO_EXT_ENG_DIR , dirent->d_name); +dlopen_ioengine (td, engine_path); + } + +closedir (dirhandle); +} +#else +#define fio_load_dynamic_engines (td) do { } while (0) +#endif +int fio_show_ioengine_help (const char *engine) {struct flist_head *entry;
@@ -638,8 +668,11 @@ int fio_show_ioengine_help(const char *engine)char *sep;int ret =1 ; +memset (&td,0 ,sizeof (struct thread_data )); +if (!engine || !*engine) {log_info ("Available IO engines:\n" ); +fio_load_dynamic_engines (&td);flist_for_each (entry, &engine_list) { io_ops = flist_entry(entry, struct ioengine_ops, list);log_info ("\t%s\n" , io_ops->name);
@@ -652,7 +685,6 @@ int fio_show_ioengine_help(const char *engine) sep++; } -memset (&td,0 ,sizeof (struct thread_data )); td.o.ioengine = (char *)engine; io_ops =load_ioengine (&td);
Signature · 1 line
1.8.3.1
Quoted 3 lines · Eric Sandeen
1) Fix the build
2) Fix engine loading
3) Fix engine listing
Applied this, and a change for the default lookup path so that it at least matches the default install path. On second thought, that should probably just match prefix, but even that won't be correct. More work needed there, but it's no more broken that before at least.
And a fix for the linking order, so that dynamic engines actually work now.
Signature · 1 line
Jens Axboe