From: James Simmons Date: Tue, 1 Aug 2017 05:37:40 +0000 (-0400) Subject: LU-7356 build: handle configure options for mount plugin X-Git-Tag: 2.10.52~45 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=d6f57eda898cc80a1cff49ad3875021749563dbf LU-7356 build: handle configure options for mount plugin Currently if you build lustre with configure options --disable-shared and/or --disable-static it will fail to build in the case of the mount plugins. The mount plugins are always built to be sharable code using libtool but this is not compatiable with the confiure --disable-share option. The solution was to create a temporary static library and for the static case we directly link into the lustre utilites. If shared libraries are enabled then that temporary library is turned into a dynamic plugin. The lustre utilites was updated to handle both cases. Test-Parameters: trivial Change-Id: I0eec25c8bce71c0e5c533ff3dfbe752677f37a26 Signed-off-by: James Simmons Signed-off-by: Nathaniel Clark Reviewed-on: https://review.whamcloud.com/17581 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Dmitry Eremin Reviewed-by: Bob Glossman Reviewed-by: Oleg Drokin --- diff --git a/config/lustre-build.m4 b/config/lustre-build.m4 index 69f77e5..014ecdc 100644 --- a/config/lustre-build.m4 +++ b/config/lustre-build.m4 @@ -346,6 +346,7 @@ AC_SUBST(EXTRA_KCFLAGS) # (so that portals/lustre can disable some if needed) # AC_DEFUN([LB_CONDITIONALS], [ +AM_CONDITIONAL([PLUGINS], [test x$enable_shared = xyes]) AM_CONDITIONAL([MODULES], [test x$enable_modules = xyes]) AM_CONDITIONAL([UTILS], [test x$enable_utils = xyes]) AM_CONDITIONAL([TESTS], [test x$enable_tests = xyes]) diff --git a/lustre.spec.in b/lustre.spec.in index 8d066df..21be1a7 100644 --- a/lustre.spec.in +++ b/lustre.spec.in @@ -455,6 +455,7 @@ echo '%{_sbindir}/wiretest' >>lustre-tests.files %endif %if %{with lustre_modules} +%if %{with shared} %if %{with ldiskfs} %if %{with lustre_utils} %files osd-ldiskfs-mount @@ -462,7 +463,9 @@ echo '%{_sbindir}/wiretest' >>lustre-tests.files %{_libdir}/@PACKAGE@/mount_osd_ldiskfs.so %endif %endif +%endif +%if %{with shared} %if %{with zfs} %if %{with lustre_utils} %files osd-zfs-mount @@ -470,6 +473,7 @@ echo '%{_sbindir}/wiretest' >>lustre-tests.files %{_libdir}/@PACKAGE@/mount_osd_zfs.so %endif %endif +%endif %endif # with lustre_modules diff --git a/lustre/utils/Makefile.am b/lustre/utils/Makefile.am index 4e3d03c..82e7381 100644 --- a/lustre/utils/Makefile.am +++ b/lustre/utils/Makefile.am @@ -4,9 +4,6 @@ AM_CFLAGS := -fPIC -D_GNU_SOURCE \ -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 -DLUSTRE_UTILS=1 AM_LDFLAGS := -L$(top_builddir)/lnet/utils -MNTMODLDFLAGS := -rdynamic -ldl -MNTMODCFLAGS := -DPLUGIN_DIR=\"${pkglibdir}\" - LIBPTLCTL := $(top_builddir)/lnet/utils/libptlctl.a \ $(top_builddir)/libcfs/libcfs/libcfsutil.a \ $(top_builddir)/libcfs/libcfs/libcfs.a @@ -98,20 +95,36 @@ liblustreapitmp_a_SOURCES = liblustreapi.c liblustreapi_hsm.c \ $(top_builddir)/libcfs/libcfs/util/param.c \ liblustreapi_ladvise.c liblustreapi_chlg.c if UTILS +LIB_TARGETS = liblustreapi.so +if PLUGINS +if LDISKFS_ENABLED +LIB_TARGETS += mount_osd_ldiskfs.so +endif +if ZFS_ENABLED +LIB_TARGETS += mount_osd_zfs.so +endif +endif + # build static and shared lib lustreapi liblustreapi.a : liblustreapitmp.a rm -f liblustreapi.a liblustreapi.so $(CC) $(LDFLAGS) -shared -o liblustreapi.so `$(AR) -t liblustreapitmp.a` mv liblustreapitmp.a liblustreapi.a -install-exec-hook: liblustreapi.so +install-exec-hook: @$(NORMAL_INSTALL) $(mkinstalldirs) $(DESTDIR)$(libdir) - @list=$< ; for p in $$list; do \ + $(mkinstalldirs) $(DESTDIR)$(libdir)/lustre + for p in $(LIB_TARGETS); do \ if test -f $$p; then \ f="`echo $$p | sed -e 's|^.*/||'`"; \ - echo " $(INSTALL_DATA) $$p $(DESTDIR)$(libdir)/$$f"; \ - $(INSTALL_DATA) $$p $(DESTDIR)$(libdir)/$$f; \ + if `echo -n $$p | grep -q mount`; then \ + echo " $(INSTALL_DATA) $$p $(DESTDIR)$(libdir)/lustre/$$f"; \ + $(INSTALL_DATA) $$p $(DESTDIR)$(libdir)/lustre/$$f; \ + else \ + echo " $(INSTALL_DATA) $$p $(DESTDIR)$(libdir)/$$f"; \ + $(INSTALL_DATA) $$p $(DESTDIR)$(libdir)/$$f; \ + fi; \ else :; fi; \ done endif # UTILS @@ -126,42 +139,65 @@ llog_reader_DEPENDENCIES := $(LIBPTLCTL) liblustreapi.a lr_reader_SOURCES = lr_reader.c +lib_LTLIBRARIES = + if UTILS +PLUGIN_LIB = +if PLUGINS +MNTMODLDFLAGS := -rdynamic -ldl +MNTMODCFLAGS := -DPLUGIN_DIR=\"${pkglibdir}\" +endif # PLUGINS + if ZFS_ENABLED -pkglib_LTLIBRARIES += mount_osd_zfs.la +noinst_LIBRARIES += libmount_utils_zfs.a -mount_osd_zfs_la_SOURCES = mount_utils_zfs.c -mount_osd_zfs_la_CPPFLAGS := -DHAVE_IOCTL_IN_UNISTD_H $(ZFS_LIBZFS_INCLUDE) -mount_osd_zfs_la_LDFLAGS := -pthread $(ZFS_LIBZFS_LDFLAGS) -mount_osd_zfs_la_LDFLAGS += -shared -export-dynamic -module -avoid-version +libmount_utils_zfs_a_SOURCES = libmount_utils_zfs.c +libmount_utils_zfs_a_CPPFLAGS := -DHAVE_IOCTL_IN_UNISTD_H $(ZFS_LIBZFS_INCLUDE) + +if PLUGINS +lib_LTLIBRARIES += libmount_utils_zfs.la +libmount_utils_zfs.la : libmount_utils_zfs.a + $(CC) $(LDFLAGS) $(MNTMODLDFLAGS) -shared -export-dynamic -pthread \ + $(ZFS_LIBZFS_LDFLAGS) -o mount_osd_zfs.so \ + `$(AR) -t libmount_utils_zfs.a` +else +MNTMODLDFLAGS := $(ZFS_LIBZFS_LDFLAGS) +PLUGIN_LIB += libmount_utils_zfs.a +endif # PLUGINS endif # ZFS_ENABLED if LDISKFS_ENABLED -pkglib_LTLIBRARIES += mount_osd_ldiskfs.la +noinst_LIBRARIES += libmount_utils_ldiskfs.a -mount_osd_ldiskfs_la_SOURCES = mount_utils_ldiskfs.c -mount_osd_ldiskfs_la_LDFLAGS := -shared -export-dynamic -module -avoid-version -mount_osd_ldiskfs_la_LIBADD := $(SELINUX) +libmount_utils_ldiskfs_a_SOURCES = libmount_utils_ldiskfs.c +libmount_utils_ldiskfs_a_CPPFLAGS := $(SELINUX) + +if PLUGINS +lib_LTLIBRARIES += libmount_utils_ldiskfs.la +libmount_utils_ldiskfs.la : libmount_utils_ldiskfs.a + $(CC) $(LDFLAGS) $(MNTMODLDFLAGS) -shared -export-dynamic \ + $(SELINUX) -o mount_osd_ldiskfs.so \ + `$(AR) -t libmount_utils_ldiskfs.a` +else +PLUGIN_LIB += libmount_utils_ldiskfs.a +endif # PLUGINS endif # LDISKFS_ENABLED mount_lustre_SOURCES = mount_lustre.c mount_utils.c mount_utils.h $(GSSSRC) mount_lustre_CPPFLAGS := ${MNTMODCFLAGS} mount_lustre_LDFLAGS := ${MNTMODLDFLAGS} -mount_lustre_LDADD := $(LIBPTLCTL) $(SELINUX) $(LDLIBMOUNT) $(GSSLIB) -mount_lustre_DEPENDENCIES := $(LIBPTLCTL) +mount_lustre_LDADD := $(LIBPTLCTL) $(SELINUX) $(LDLIBMOUNT) $(PLUGIN_LIB) $(GSSLIB) mkfs_lustre_SOURCES = mkfs_lustre.c mount_utils.c mount_utils.h $(GSSSRC) mkfs_lustre_CPPFLAGS := -UTUNEFS ${MNTMODCFLAGS} mkfs_lustre_LDFLAGS := ${MNTMODLDFLAGS} -mkfs_lustre_LDADD := $(LIBPTLCTL) $(LDLIBMOUNT) $(GSSLIB) -mkfs_lustre_DEPENDENCIES := $(LIBPTLCTL) +mkfs_lustre_LDADD := $(mount_lustre_LDADD) tunefs_lustre_SOURCES = mkfs_lustre.c mount_utils.c mount_utils.h $(GSSSRC) tunefs_lustre_CPPFLAGS := -DTUNEFS ${MNTMODCFLAGS} tunefs_lustre_LDFLAGS := ${MNTMODLDFLAGS} tunefs_lustre_LDADD := $(mkfs_lustre_LDADD) -tunefs_lustre_DEPENDENCIES := $(mkfs_lustre_DEPENDENCIES) l_getidentity_SOURCES = l_getidentity.c l_getidentity_LDADD := $(LIBPTLCTL) diff --git a/lustre/utils/mount_utils_ldiskfs.c b/lustre/utils/libmount_utils_ldiskfs.c similarity index 98% rename from lustre/utils/mount_utils_ldiskfs.c rename to lustre/utils/libmount_utils_ldiskfs.c index 94a795f..d6b9ca6 100644 --- a/lustre/utils/mount_utils_ldiskfs.c +++ b/lustre/utils/libmount_utils_ldiskfs.c @@ -1453,3 +1453,21 @@ void ldiskfs_fini(void) return; } +#ifndef PLUGIN_DIR +struct module_backfs_ops ldiskfs_ops = { + .init = ldiskfs_init, + .fini = ldiskfs_fini, + .read_ldd = ldiskfs_read_ldd, + .write_ldd = ldiskfs_write_ldd, + .erase_ldd = ldiskfs_erase_ldd, + .print_ldd_params = ldiskfs_print_ldd_params, + .is_lustre = ldiskfs_is_lustre, + .make_lustre = ldiskfs_make_lustre, + .prepare_lustre = ldiskfs_prepare_lustre, + .fix_mountopts = ldiskfs_fix_mountopts, + .tune_lustre = ldiskfs_tune_lustre, + .label_lustre = ldiskfs_label_lustre, + .enable_quota = ldiskfs_enable_quota, + .rename_fsname = ldiskfs_rename_fsname, +}; +#endif /* PLUGIN_DIR */ diff --git a/lustre/utils/mount_utils_zfs.c b/lustre/utils/libmount_utils_zfs.c similarity index 97% rename from lustre/utils/mount_utils_zfs.c rename to lustre/utils/libmount_utils_zfs.c index ea495e3..920682c 100644 --- a/lustre/utils/mount_utils_zfs.c +++ b/lustre/utils/libmount_utils_zfs.c @@ -869,6 +869,7 @@ int zfs_init(void) int ret = 0; g_zfs = libzfs_init(); + if (g_zfs == NULL) { /* Try to load zfs.ko and retry libzfs_init() */ @@ -883,7 +884,6 @@ int zfs_init(void) if (ret == 0) osd_zfs_setup = 1; - else fprintf(stderr, "Failed to initialize ZFS library: %d\n", ret); @@ -898,3 +898,21 @@ void zfs_fini(void) } osd_zfs_setup = 0; } + +#ifndef PLUGIN_DIR +struct module_backfs_ops zfs_ops = { + .init = zfs_init, + .fini = zfs_fini, + .read_ldd = zfs_read_ldd, + .write_ldd = zfs_write_ldd, + .erase_ldd = zfs_erase_ldd, + .print_ldd_params = zfs_print_ldd_params, + .is_lustre = zfs_is_lustre, + .make_lustre = zfs_make_lustre, + .prepare_lustre = zfs_prepare_lustre, + .tune_lustre = zfs_tune_lustre, + .label_lustre = zfs_label_lustre, + .enable_quota = zfs_enable_quota, + .rename_fsname = zfs_rename_fsname, +}; +#endif /* PLUGIN_DIR */ diff --git a/lustre/utils/mount_utils.c b/lustre/utils/mount_utils.c index ccb33cd..21c0968 100644 --- a/lustre/utils/mount_utils.c +++ b/lustre/utils/mount_utils.c @@ -521,12 +521,14 @@ int loop_format(struct mkfs_opts *mop) return 0; } +#ifdef PLUGIN_DIR #define DLSYM(prefix, sym, func) \ do { \ char _fname[64]; \ snprintf(_fname, sizeof(_fname), "%s_%s", prefix, #func); \ sym->func = (typeof(sym->func))dlsym(sym->dl_handle, _fname); \ } while (0) +#endif /* PLUGIN_DIR */ /** * Load plugin for a given mount_type from ${pkglibdir}/mount_osd_FSTYPE.so and @@ -538,9 +540,10 @@ int loop_format(struct mkfs_opts *mop) */ struct module_backfs_ops *load_backfs_module(enum ldd_mount_type mount_type) { - void *handle; - char *error, filename[512], fsname[512], *name; struct module_backfs_ops *ops; +#ifdef PLUGIN_DIR + char *error, filename[512], fsname[512], *name; + void *handle; /* This deals with duplicate ldd_mount_types resolving to same OSD layer * plugin (e.g. ext3/ldiskfs/ldiskfs2 all being ldiskfs) */ @@ -606,7 +609,23 @@ struct module_backfs_ops *load_backfs_module(enum ldd_mount_type mount_type) /* optional methods */ DLSYM(name, ops, fix_mountopts); - +#else + switch (mount_type) { +#ifdef HAVE_LDISKFS_OSD + case LDD_MT_LDISKFS: + ops = &ldiskfs_ops; + break; +#endif /* HAVE_LDISKFS_OSD */ +#ifdef HAVE_ZFS_OSD + case LDD_MT_ZFS: + ops = &zfs_ops; + break; +#endif /* HAVE_ZFS_OSD */ + default: + ops = NULL; + break; + } +#endif return ops; } @@ -616,11 +635,13 @@ struct module_backfs_ops *load_backfs_module(enum ldd_mount_type mount_type) */ void unload_backfs_module(struct module_backfs_ops *ops) { +#ifdef PLUGIN_DIR if (ops == NULL) return; dlclose(ops->dl_handle); free(ops); +#endif } /* Return true if backfs_ops has operations for the given mount_type. */ @@ -814,14 +835,15 @@ int osd_init(void) for (i = 0; i < LDD_MT_LAST; ++i) { rc = 0; backfs_ops[i] = load_backfs_module(i); - if (backfs_ops[i] != NULL) + if (backfs_ops[i] != NULL) { rc = backfs_ops[i]->init(); - if (rc != 0) { - backfs_ops[i]->fini(); - unload_backfs_module(backfs_ops[i]); - backfs_ops[i] = NULL; - } else - ret = 0; + if (rc != 0) { + backfs_ops[i]->fini(); + unload_backfs_module(backfs_ops[i]); + backfs_ops[i] = NULL; + } else + ret = 0; + } } return ret; diff --git a/lustre/utils/mount_utils.h b/lustre/utils/mount_utils.h index 7540d06..251a1fc 100644 --- a/lustre/utils/mount_utils.h +++ b/lustre/utils/mount_utils.h @@ -215,6 +215,9 @@ struct module_backfs_ops { void *dl_handle; }; +struct module_backfs_ops zfs_ops; +struct module_backfs_ops ldiskfs_ops; + struct module_backfs_ops *load_backfs_module(enum ldd_mount_type mount_type); void unload_backfs_ops(struct module_backfs_ops *ops); #ifdef HAVE_OPENSSL_SSK