From: Nathaniel Clark Date: Thu, 1 May 2014 21:13:45 +0000 (-0400) Subject: LU-4606 utils: Mount uses so for backing fstype X-Git-Tag: 2.5.60~68 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=3e8c354c09725a97b90e477a77411cc6fb306f09;p=fs%2Flustre-release.git LU-4606 utils: Mount uses so for backing fstype Make mount/mkfs/tunefs functionality a per backing FSTYPE shared object that is loadable, and seperately buildable and installable in the appropriate lustre-osd-FSTYPE rpm. For ZFS this allows the shared object to be directly linked to libzfs and thus remove the hardcoding of a libzfs.so version in the lustre source. This also has the benefit of making lustre-osd-zfs explicitly requires libzfs (which it needs to do mount/mkfs operations). Adjust build system to allow building of loadable module. Including requiering libtool as part of the build. Signed-off-by: Nathaniel Clark Change-Id: I8fc0f41161dc08405c1f951f12e675f364ff62c3 Reviewed-on: http://review.whamcloud.com/10193 Tested-by: Jenkins Reviewed-by: Dmitry Eremin Tested-by: Maloo Reviewed-by: Alex Zhuravlev Reviewed-by: Oleg Drokin --- diff --git a/.gitignore b/.gitignore index 7016003..16c65d3 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ .*.cmd .*.d .*.flags +.libs .tmp_versions .Xrefs *~ @@ -28,6 +29,8 @@ *.dSYM *.i *.ko +*.la +*.lo *.mod.c *.o *.orig @@ -67,6 +70,7 @@ TAGS /config.h /config.h.in /INSTALL +/libtool /lustre.spec /lustre-dkms.spec /lustre*.tar.gz diff --git a/autogen.sh b/autogen.sh index 50b5424..3f5031c 100644 --- a/autogen.sh +++ b/autogen.sh @@ -8,6 +8,7 @@ for dir in libcfs lnet lustre snmp ; do ACLOCAL_FLAGS="$ACLOCAL_FLAGS -I $PWD/$dir/autoconf" done +libtoolize -q aclocal -I $PWD/config $ACLOCAL_FLAGS autoheader automake -a -c diff --git a/config/.gitignore b/config/.gitignore index 34eb9d3..01131af 100644 --- a/config/.gitignore +++ b/config/.gitignore @@ -3,4 +3,10 @@ /config.sub /depcomp /install-sh +/libtool.m4 +/ltmain.sh +/ltoptions.m4 +/ltsugar.m4 +/ltversion.m4 +/lt~obsolete.m4 /missing diff --git a/config/lustre-build-zfs.m4 b/config/lustre-build-zfs.m4 index 548753e..51c606b 100644 --- a/config/lustre-build-zfs.m4 +++ b/config/lustre-build-zfs.m4 @@ -303,7 +303,9 @@ AC_DEFUN([LB_ZFS_USER], [ AC_MSG_RESULT([$zfslib]) ZFS_LIBZFS_INCLUDE=${zfslib} + ZFS_LIBZFS_LDFLAGS=-lzfs AC_SUBST(ZFS_LIBZFS_INCLUDE) + AC_SUBST(ZFS_LIBZFS_LDFLAGS) ]) AC_DEFUN([LB_CONFIG_ZFS], [ diff --git a/configure.ac b/configure.ac index 3876d62..b772a0f 100644 --- a/configure.ac +++ b/configure.ac @@ -15,6 +15,7 @@ AM_INIT_AUTOMAKE([1.10 tar-ustar -Wno-portability]) AM_MAINTAINER_MODE([enable]) AC_PROG_CC +AC_PROG_LIBTOOL AM_PROG_AS diff --git a/lustre.spec.in b/lustre.spec.in index 9673957..7d687a3 100644 --- a/lustre.spec.in +++ b/lustre.spec.in @@ -94,6 +94,7 @@ BuildRoot: %{_tmppath}/lustre-%{version}-root Obsoletes: lustre-lite, lustre-lite-utils, lustre-ldap nfs-utils-lustre Provides: lustre-lite = %{version}, lustre-lite-utils = %{version} Requires: %{name}-modules = %{version} +BuildRequires: libtool %if %{with servers} Requires: lustre-osd %endif @@ -284,6 +285,10 @@ CONFIGURE_ARGS="$CONFIGURE_ARGS --enable-modules" CONFIGURE_ARGS="$CONFIGURE_ARGS --disable-modules" %endif +%if %{without zfs} +CONFIGURE_ARGS="$CONFIGURE_ARGS --without-zfs" +%endif + # if %%kdir was given, make sure it's not in the configure arguments if [ -n "%kdir" ]; then CONFIGURE_ARGS=$(echo $CONFIGURE_ARGS | sed -e 's/"\?--with-linux=[^ ][^ ]* \?//') @@ -349,6 +354,8 @@ if [ -d $RPM_BUILD_ROOT%{_libdir}/lustre/snmp ] ; then echo '%{_datadir}/lustre/snmp/mibs' >>lustre.files fi +find $RPM_BUILD_ROOT%{_libdir}/@PACKAGE@/ -name \*.la -delete + %if %{with lustre_tests} echo '%{_libdir}/lustre/tests/*' >>lustre-tests.files echo '%{_bindir}/mcreate' >>lustre-tests.files @@ -435,6 +442,7 @@ find $RPM_BUILD_ROOT%{?rootdir}/lib/modules/%{kversion}/%{kmoddir} -name "*.ko" %defattr(-,root,root) %{?rootdir}/lib/modules/%{kversion}/%{kmoddir}/kernel/fs/@PACKAGE@/ldiskfs.ko %{?rootdir}/lib/modules/%{kversion}/%{kmoddir}/kernel/fs/@PACKAGE@/osd_ldiskfs.ko +%{_libdir}/@PACKAGE@/mount_osd_ldiskfs.so %if %{defined rpm_post_base} %attr(0555, root, root) %{rpm_post_base}-osd-ldiskfs.sh %endif @@ -444,6 +452,7 @@ find $RPM_BUILD_ROOT%{?rootdir}/lib/modules/%{kversion}/%{kmoddir} -name "*.ko" %files osd-zfs %defattr(-,root,root) %{?rootdir}/lib/modules/%{kversion}/%{kmoddir}/kernel/fs/@PACKAGE@/osd_zfs.ko +%{_libdir}/@PACKAGE@/mount_osd_zfs.so %if %{defined rpm_post_base} %attr(0555, root, root) %{rpm_post_base}-osd-zfs.sh %endif diff --git a/lustre/tests/.gitignore b/lustre/tests/.gitignore index ebd19e6..bccb334 100644 --- a/lustre/tests/.gitignore +++ b/lustre/tests/.gitignore @@ -2,6 +2,7 @@ /*.xml /Makefile.in /XMLCONFIG +/badarea_io /check_fhandle_syscalls /checkfiemap /checkstat diff --git a/lustre/utils/Makefile.am b/lustre/utils/Makefile.am index 7731442..5effd90 100644 --- a/lustre/utils/Makefile.am +++ b/lustre/utils/Makefile.am @@ -8,6 +8,9 @@ AM_CFLAGS=$(LLCFLAGS) AM_CPPFLAGS=$(LLCPPFLAGS) -DLUSTRE_UTILS=1 -D_FILE_OFFSET_BITS=64 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 @@ -33,6 +36,7 @@ bin_PROGRAMS = lfs req_layout bin_SCRIPTS = $(bin_scripts) sbin_SCRIPTS = $(sbin_scripts) +pkglib_LTLIBRARIES = lib_LIBRARIES = liblustreapi.a if LDISKFS_ENABLED lib_LIBRARIES += libiam.a @@ -115,49 +119,43 @@ llog_reader_DEPENDENCIES := $(LIBPTLCTL) lr_reader_SOURCES = lr_reader.c +if UTILS + +if ZFS_ENABLED +pkglib_LTLIBRARIES += mount_osd_zfs.la + +mount_osd_zfs_la_SOURCES = mount_utils_zfs.c +mount_osd_zfs_la_CPPFLAGS = -DHAVE_IOCTL_IN_UNISTD_H +mount_osd_zfs_la_CPPFLAGS += $(ZFS_LIBZFS_INCLUDE) +mount_osd_zfs_la_LDFLAGS = -pthread $(ZFS_LIBZFS_LDFLAGS) +mount_osd_zfs_la_LDFLAGS += -shared -export-dynamic -module -avoid-version +endif + +if LDISKFS_ENABLED +pkglib_LTLIBRARIES += mount_osd_ldiskfs.la + +mount_osd_ldiskfs_la_SOURCES = mount_utils_ldiskfs.c +mount_osd_ldiskfs_la_LDFLAGS = -shared -export-dynamic -module -avoid-version +mount_osd_ldiskfs_LDADD = libiam.a +endif + mount_lustre_SOURCES = mount_lustre.c mount_utils.c mount_utils.h -mount_lustre_CPPFLAGS = $(AM_CPPFLAGS) +mount_lustre_CPPFLAGS = $(AM_CPPFLAGS) ${MNTMODCFLAGS} mount_lustre_LDADD := $(LIBPTLCTL) $(SELINUX) mount_lustre_DEPENDENCIES := $(LIBPTLCTL) -if LDISKFS_ENABLED -mount_lustre_SOURCES += mount_utils_ldiskfs.c -endif -if ZFS_ENABLED -mount_lustre_SOURCES += mount_utils_zfs.c -mount_lustre_CPPFLAGS += -DHAVE_IOCTL_IN_UNISTD_H -mount_lustre_CPPFLAGS += $(ZFS_LIBZFS_INCLUDE) -mount_lustre_LDFLAGS = -pthread -rdynamic -ldl -endif +mount_lustre_LDFLAGS = ${MNTMODLDFLAGS} mkfs_lustre_SOURCES = mkfs_lustre.c mount_utils.c mount_utils.h -mkfs_lustre_CPPFLAGS = -UTUNEFS $(AM_CPPFLAGS) +mkfs_lustre_CPPFLAGS = -UTUNEFS $(AM_CPPFLAGS) ${MNTMODCFLAGS} mkfs_lustre_LDADD := $(LIBPTLCTL) mkfs_lustre_DEPENDENCIES := $(LIBPTLCTL) -if LDISKFS_ENABLED -mkfs_lustre_SOURCES += mount_utils_ldiskfs.c -mkfs_lustre_LDADD += libiam.a -mkfs_lustre_DEPENDENCIES += $(LIBPTLCTL) -endif -if ZFS_ENABLED -mkfs_lustre_SOURCES += mount_utils_zfs.c -mkfs_lustre_CPPFLAGS += -DHAVE_IOCTL_IN_UNISTD_H -mkfs_lustre_CPPFLAGS += $(ZFS_LIBZFS_INCLUDE) -mkfs_lustre_LDFLAGS = -pthread -rdynamic -ldl -endif +mkfs_lustre_LDFLAGS = ${MNTMODLDFLAGS} tunefs_lustre_SOURCES = mkfs_lustre.c mount_utils.c mount_utils.h -tunefs_lustre_CPPFLAGS = -DTUNEFS $(AM_CPPFLAGS) +tunefs_lustre_CPPFLAGS = -DTUNEFS $(AM_CPPFLAGS) ${MNTMODCFLAGS} tunefs_lustre_LDADD := $(mkfs_lustre_LDADD) tunefs_lustre_DEPENDENCIES := $(mkfs_lustre_DEPENDENCIES) -if LDISKFS_ENABLED -tunefs_lustre_SOURCES += mount_utils_ldiskfs.c -endif -if ZFS_ENABLED -tunefs_lustre_SOURCES += mount_utils_zfs.c -tunefs_lustre_CPPFLAGS += -DHAVE_IOCTL_IN_UNISTD_H -tunefs_lustre_CPPFLAGS += $(ZFS_LIBZFS_INCLUDE) -tunefs_lustre_LDFLAGS = -pthread -rdynamic -ldl -endif +tunefs_lustre_LDFLAGS = ${MNTMODLDFLAGS} l_getidentity_SOURCES = l_getidentity.c l_getidentity_LDADD := $(LIBPTLCTL) @@ -174,6 +172,8 @@ wirecheck_CPPFLAGS = -DCC="\"$(CC)\"" wiretest_SOURCES = wiretest.c +endif + EXTRA_DIST = $(sbin_scripts) $(bin_scripts) # NOTE: this should only be run on i386. diff --git a/lustre/utils/mount_utils.c b/lustre/utils/mount_utils.c index d754d49..bb83f45 100644 --- a/lustre/utils/mount_utils.c +++ b/lustre/utils/mount_utils.c @@ -47,6 +47,7 @@ #include #include #include +#include extern char *progname; extern int verbose; @@ -54,6 +55,8 @@ extern int verbose; #define vprint(fmt, arg...) if (verbose > 0) printf(fmt, ##arg) #define verrprint(fmt, arg...) if (verbose >= 0) fprintf(stderr, fmt, ##arg) +static struct module_backfs_ops *backfs_ops[LDD_MT_LAST]; + void fatal(void) { verbose = 0; @@ -424,31 +427,114 @@ int loop_format(struct mkfs_opts *mop) return 0; } +#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) + +/** + * Load plugin for a given mount_type from ${pkglibdir}/mount_osd_FSTYPE.so and + * return struct of function pointers (will be freed in unloack_backfs_module). + * + * \param[in] mount_type Mount type to load module for. + * \retval Value of backfs_ops struct + * \retval NULL if no module exists + */ +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; + + /* This deals with duplicate ldd_mount_types resolving to same OSD layer + * plugin (e.g. ext3/ldiskfs/ldiskfs2 all being ldiskfs) */ + strncpy(fsname, mt_type(mount_type), sizeof(fsname)); + name = fsname + sizeof("osd-") - 1; + + /* change osd- to osd_ */ + fsname[sizeof("osd-") - 2] = '_'; + + snprintf(filename, sizeof(filename), PLUGIN_DIR"/mount_%s.so", fsname); + + handle = dlopen(filename, RTLD_LAZY); + if (handle == NULL) + /* Do not clutter up console with missing types */ + return NULL; + + ops = malloc(sizeof(*ops)); + if (ops == NULL) { + dlclose(handle); + return NULL; + } + + ops->dl_handle = handle; + dlerror(); /* Clear any existing error */ + + DLSYM(name, ops, init); + DLSYM(name, ops, fini); + DLSYM(name, ops, read_ldd); + DLSYM(name, ops, write_ldd); + DLSYM(name, ops, is_lustre); + DLSYM(name, ops, make_lustre); + DLSYM(name, ops, prepare_lustre); + DLSYM(name, ops, tune_lustre); + DLSYM(name, ops, label_lustre); + DLSYM(name, ops, enable_quota); + + error = dlerror(); + if (error != NULL) { + fatal(); + fprintf(stderr, "%s\n", error); + dlclose(handle); + free(ops); + return NULL; + } + return ops; +} + +/** + * Unload plugin and free backfs_ops structure. Must be called the same number + * of times as load_backfs_module is. + */ +void unload_backfs_module(struct module_backfs_ops *ops) +{ + if (ops == NULL) + return; + + dlclose(ops->dl_handle); + free(ops); +} + +/* Return true if backfs_ops has operations for the given mount_type. */ +int backfs_mount_type_okay(enum ldd_mount_type mount_type) +{ + if (unlikely(mount_type >= LDD_MT_LAST || mount_type < 0)) { + fatal(); + fprintf(stderr, "fs type out of range %d\n", mount_type); + return 0; + } + if (backfs_ops[mount_type] == NULL) { + fatal(); + fprintf(stderr, "unhandled fs type %d '%s'\n", + mount_type, mt_str(mount_type)); + return 0; + } + return 1; +} + /* Write the server config files */ int osd_write_ldd(struct mkfs_opts *mop) { struct lustre_disk_data *ldd = &mop->mo_ldd; int ret; - switch (ldd->ldd_mount_type) { -#ifdef HAVE_LDISKFS_OSD - case LDD_MT_LDISKFS: - case LDD_MT_LDISKFS2: - ret = ldiskfs_write_ldd(mop); - break; -#endif /* HAVE_LDISKFS_OSD */ -#ifdef HAVE_ZFS_OSD - case LDD_MT_ZFS: - ret = zfs_write_ldd(mop); - break; -#endif /* HAVE_ZFS_OSD */ - default: - fatal(); - fprintf(stderr, "unknown fs type %d '%s'\n", - ldd->ldd_mount_type, MT_STR(ldd)); + if (backfs_mount_type_okay(ldd->ldd_mount_type)) + ret = backfs_ops[ldd->ldd_mount_type]->write_ldd(mop); + + else ret = EINVAL; - break; - } return ret; } @@ -458,25 +544,11 @@ int osd_read_ldd(char *dev, struct lustre_disk_data *ldd) { int ret; - switch (ldd->ldd_mount_type) { -#ifdef HAVE_LDISKFS_OSD - case LDD_MT_LDISKFS: - case LDD_MT_LDISKFS2: - ret = ldiskfs_read_ldd(dev, ldd); - break; -#endif /* HAVE_LDISKFS_OSD */ -#ifdef HAVE_ZFS_OSD - case LDD_MT_ZFS: - ret = zfs_read_ldd(dev, ldd); - break; -#endif /* HAVE_ZFS_OSD */ - default: - fatal(); - fprintf(stderr, "unknown fs type %d '%s'\n", - ldd->ldd_mount_type, MT_STR(ldd)); + if (backfs_mount_type_okay(ldd->ldd_mount_type)) + ret = backfs_ops[ldd->ldd_mount_type]->read_ldd(dev, ldd); + + else ret = EINVAL; - break; - } return ret; } @@ -484,20 +556,17 @@ int osd_read_ldd(char *dev, struct lustre_disk_data *ldd) /* Was this device formatted for Lustre */ int osd_is_lustre(char *dev, unsigned *mount_type) { + int i; + vprint("checking for existing Lustre data: "); -#ifdef HAVE_LDISKFS_OSD - if (ldiskfs_is_lustre(dev, mount_type)) { - vprint("found\n"); - return 1; - } -#endif /* HAVE_LDISKFS_OSD */ -#ifdef HAVE_ZFS_OSD - if (zfs_is_lustre(dev, mount_type)) { - vprint("found\n"); - return 1; + for (i = 0; i < LDD_MT_LAST; ++i) { + if (backfs_ops[i] != NULL && + backfs_ops[i]->is_lustre(dev, mount_type)) { + vprint("found\n"); + return 1; + } } -#endif /* HAVE_ZFS_OSD */ vprint("not found\n"); return 0; @@ -509,25 +578,11 @@ int osd_make_lustre(struct mkfs_opts *mop) struct lustre_disk_data *ldd = &mop->mo_ldd; int ret; - switch (ldd->ldd_mount_type) { -#ifdef HAVE_LDISKFS_OSD - case LDD_MT_LDISKFS: - case LDD_MT_LDISKFS2: - ret = ldiskfs_make_lustre(mop); - break; -#endif /* HAVE_LDISKFS_OSD */ -#ifdef HAVE_ZFS_OSD - case LDD_MT_ZFS: - ret = zfs_make_lustre(mop); - break; -#endif /* HAVE_ZFS_OSD */ - default: - fatal(); - fprintf(stderr, "unknown fs type %d '%s'\n", - ldd->ldd_mount_type, MT_STR(ldd)); + if (backfs_mount_type_okay(ldd->ldd_mount_type)) + ret = backfs_ops[ldd->ldd_mount_type]->make_lustre(mop); + + else ret = EINVAL; - break; - } return ret; } @@ -539,29 +594,13 @@ int osd_prepare_lustre(struct mkfs_opts *mop, struct lustre_disk_data *ldd = &mop->mo_ldd; int ret; - switch (ldd->ldd_mount_type) { -#ifdef HAVE_LDISKFS_OSD - case LDD_MT_LDISKFS: - case LDD_MT_LDISKFS2: - ret = ldiskfs_prepare_lustre(mop, - default_mountopts, default_len, - always_mountopts, always_len); - break; -#endif /* HAVE_LDISKFS_OSD */ -#ifdef HAVE_ZFS_OSD - case LDD_MT_ZFS: - ret = zfs_prepare_lustre(mop, - default_mountopts, default_len, - always_mountopts, always_len); - break; -#endif /* HAVE_ZFS_OSD */ - default: - fatal(); - fprintf(stderr, "unknown fs type %d '%s'\n", - ldd->ldd_mount_type, MT_STR(ldd)); + if (backfs_mount_type_okay(ldd->ldd_mount_type)) + ret = backfs_ops[ldd->ldd_mount_type]->prepare_lustre(mop, + default_mountopts, default_len, + always_mountopts, always_len); + + else ret = EINVAL; - break; - } return ret; } @@ -571,25 +610,11 @@ int osd_tune_lustre(char *dev, struct mount_opts *mop) struct lustre_disk_data *ldd = &mop->mo_ldd; int ret; - switch (ldd->ldd_mount_type) { -#ifdef HAVE_LDISKFS_OSD - case LDD_MT_LDISKFS: - case LDD_MT_LDISKFS2: - ret = ldiskfs_tune_lustre(dev, mop); - break; -#endif /* HAVE_LDISKFS_OSD */ -#ifdef HAVE_ZFS_OSD - case LDD_MT_ZFS: - ret = zfs_tune_lustre(dev, mop); - break; -#endif /* HAVE_ZFS_OSD */ - default: - fatal(); - fprintf(stderr, "unknown fs type %d '%s'\n", - ldd->ldd_mount_type, MT_STR(ldd)); + if (backfs_mount_type_okay(ldd->ldd_mount_type)) + ret = backfs_ops[ldd->ldd_mount_type]->tune_lustre(dev, mop); + + else ret = EINVAL; - break; - } return ret; } @@ -599,25 +624,11 @@ int osd_label_lustre(struct mount_opts *mop) struct lustre_disk_data *ldd = &mop->mo_ldd; int ret; - switch (ldd->ldd_mount_type) { -#ifdef HAVE_LDISKFS_OSD - case LDD_MT_LDISKFS: - case LDD_MT_LDISKFS2: - ret = ldiskfs_label_lustre(mop); - break; -#endif /* HAVE_LDISKFS_OSD */ -#ifdef HAVE_ZFS_OSD - case LDD_MT_ZFS: - ret = zfs_label_lustre(mop); - break; -#endif /* HAVE_ZFS_OSD */ - default: - fatal(); - fprintf(stderr, "unknown fs type %d '%s'\n", - ldd->ldd_mount_type, MT_STR(ldd)); + if (backfs_mount_type_okay(ldd->ldd_mount_type)) + ret = backfs_ops[ldd->ldd_mount_type]->label_lustre(mop); + + else ret = EINVAL; - break; - } return ret; } @@ -628,59 +639,41 @@ int osd_enable_quota(struct mkfs_opts *mop) struct lustre_disk_data *ldd = &mop->mo_ldd; int ret; - switch (ldd->ldd_mount_type) { -#ifdef HAVE_LDISKFS_OSD - case LDD_MT_EXT3: - case LDD_MT_LDISKFS: - case LDD_MT_LDISKFS2: - ret = ldiskfs_enable_quota(mop); - break; -#endif /* HAVE_LDISKFS_OSD */ -#ifdef HAVE_ZFS_OSD - case LDD_MT_ZFS: - fprintf(stderr, "this option is only valid for ldiskfs\n"); - ret = EINVAL; - break; -#endif /* HAVE_ZFS_OSD */ - default: - fatal(); - fprintf(stderr, "unknown fs type %d '%s'\n", - ldd->ldd_mount_type, MT_STR(ldd)); + if (backfs_mount_type_okay(ldd->ldd_mount_type)) + ret = backfs_ops[ldd->ldd_mount_type]->enable_quota(mop); + + else ret = EINVAL; - break; - } return ret; } int osd_init(void) { - int ret = 0; + int i, ret = 0; -#ifdef HAVE_LDISKFS_OSD - ret = ldiskfs_init(); - if (ret) - return ret; -#endif /* HAVE_LDISKFS_OSD */ -#ifdef HAVE_ZFS_OSD - ret = zfs_init(); - /* we want to be able to set up a ldiskfs-based filesystem w/o - * the ZFS modules installed, see ORI-425 */ - if (ret) - ret = 0; -#endif /* HAVE_ZFS_OSD */ + for (i = 0; i < LDD_MT_LAST; ++i) { + backfs_ops[i] = load_backfs_module(i); + if (backfs_ops[i] != NULL) + ret = backfs_ops[i]->init(); + if (ret) + break; + } return ret; } void osd_fini(void) { -#ifdef HAVE_LDISKFS_OSD - ldiskfs_fini(); -#endif /* HAVE_LDISKFS_OSD */ -#ifdef HAVE_ZFS_OSD - zfs_fini(); -#endif /* HAVE_ZFS_OSD */ + int i; + + for (i = 0; i < LDD_MT_LAST; ++i) { + if (backfs_ops[i] != NULL) { + backfs_ops[i]->fini(); + unload_backfs_module(backfs_ops[i]); + backfs_ops[i] = NULL; + } + } } __u64 get_device_size(char* device) diff --git a/lustre/utils/mount_utils.h b/lustre/utils/mount_utils.h index ce220c1..8a26c5e 100644 --- a/lustre/utils/mount_utils.h +++ b/lustre/utils/mount_utils.h @@ -123,13 +123,6 @@ int check_mountfsoptions(char *mountopts, char *wanted_mountopts, int justwarn); void trim_mountfsoptions(char *s); __u64 get_device_size(char* device); -int is_block(char *devname); -void disp_old_e2fsprogs_msg(const char *feature, int make_backfs); -int make_lustre_backfs(struct mkfs_opts *mop); -int write_local_files(struct mkfs_opts *mop); -int read_local_files(struct mkfs_opts *mop); -int is_lustre_target(struct mkfs_opts *mop); - /* loopback helper functions */ int file_create(char *path, __u64 size); int loop_format(struct mkfs_opts *mop); @@ -150,31 +143,23 @@ int osd_enable_quota(struct mkfs_opts *mop); int osd_init(void); void osd_fini(void); -int ldiskfs_write_ldd(struct mkfs_opts *mop); -int ldiskfs_read_ldd(char *dev, struct lustre_disk_data *ldd); -int ldiskfs_is_lustre(char *dev, unsigned *mount_type); -int ldiskfs_make_lustre(struct mkfs_opts *mop); -int ldiskfs_prepare_lustre(struct mkfs_opts *mop, - char *default_mountopts, int default_len, - char *always_mountopts, int always_len); -int ldiskfs_tune_lustre(char *dev, struct mount_opts *mop); -int ldiskfs_label_lustre(struct mount_opts *mop); -int ldiskfs_enable_quota(struct mkfs_opts *mop); -int ldiskfs_init(void); -void ldiskfs_fini(void); +struct module_backfs_ops { + int (*init)(void); + void (*fini)(void); + int (*read_ldd)(char *ds, struct lustre_disk_data *ldd); + int (*write_ldd)(struct mkfs_opts *mop); + int (*is_lustre)(char *dev, enum ldd_mount_type *mount_type); + int (*make_lustre)(struct mkfs_opts *mop); + int (*prepare_lustre)(struct mkfs_opts *mop, + char *default_mountopts, int default_len, + char *always_mountopts, int always_len); + int (*tune_lustre)(char *dev, struct mount_opts *mop); + int (*label_lustre)(struct mount_opts *mop); + int (*enable_quota)(struct mkfs_opts *mop); + void *dl_handle; +}; -#ifdef HAVE_ZFS_OSD -int zfs_write_ldd(struct mkfs_opts *mop); -int zfs_read_ldd(char *ds, struct lustre_disk_data *ldd); -int zfs_is_lustre(char *dev, unsigned *mount_type); -int zfs_make_lustre(struct mkfs_opts *mop); -int zfs_prepare_lustre(struct mkfs_opts *mop, - char *default_mountopts, int default_len, - char *always_mountopts, int always_len); -int zfs_tune_lustre(char *dev, struct mount_opts *mop); -int zfs_label_lustre(struct mount_opts *mop); -int zfs_init(void); -void zfs_fini(void); -#endif +struct module_backfs_ops *load_backfs_module(enum ldd_mount_type mount_type); +void unload_backfs_ops(struct module_backfs_ops *ops); #endif diff --git a/lustre/utils/mount_utils_ldiskfs.c b/lustre/utils/mount_utils_ldiskfs.c index dfb9e6c..9e1ec14 100644 --- a/lustre/utils/mount_utils_ldiskfs.c +++ b/lustre/utils/mount_utils_ldiskfs.c @@ -102,7 +102,7 @@ extern char *progname; * Concatenate context of the temporary mount point iff selinux is enabled */ #ifdef HAVE_SELINUX -void append_context_for_mount(char *mntpt, struct mkfs_opts *mop) +static void append_context_for_mount(char *mntpt, struct mkfs_opts *mop) { security_context_t fcontext; @@ -121,6 +121,122 @@ void append_context_for_mount(char *mntpt, struct mkfs_opts *mop) } #endif +/* return canonicalized absolute pathname, even if the target file does not + * exist, unlike realpath */ +static char *absolute_path(char *devname) +{ + char buf[PATH_MAX + 1] = ""; + char *path; + char *ptr; + int len; + + path = malloc(sizeof(buf)); + if (path == NULL) + return NULL; + + if (devname[0] != '/') { + if (getcwd(buf, sizeof(buf) - 1) == NULL) { + free(path); + return NULL; + } + len = snprintf(path, sizeof(buf), "%s/%s", buf, devname); + if (len >= sizeof(buf)) { + free(path); + return NULL; + } + } else { + len = snprintf(path, sizeof(buf), "%s", devname); + if (len >= sizeof(buf)) { + free(path); + return NULL; + } + } + + /* truncate filename before calling realpath */ + ptr = strrchr(path, '/'); + if (ptr == NULL) { + free(path); + return NULL; + } + *ptr = '\0'; + if (buf != realpath(path, buf)) { + free(path); + return NULL; + } + /* add the filename back */ + len = snprintf(path, PATH_MAX, "%s/%s", buf, ptr+1); + if (len >= PATH_MAX) { + free(path); + return NULL; + } + return path; +} + +/* Determine if a device is a block device (as opposed to a file) */ +static int is_block(char *devname) +{ + struct stat st; + int ret = 0; + char *devpath; + + devpath = absolute_path(devname); + if (devpath == NULL) { + fprintf(stderr, "%s: failed to resolve path to %s\n", + progname, devname); + return -1; + } + + ret = access(devname, F_OK); + if (ret != 0) { + if (strncmp(devpath, "/dev/", 5) == 0) { + /* nobody sane wants to create a loopback file under + * /dev. Let's just report the device doesn't exist */ + fprintf(stderr, "%s: %s apparently does not exist\n", + progname, devpath); + ret = -1; + goto out; + } + ret = 0; + goto out; + } + ret = stat(devpath, &st); + if (ret != 0) { + fprintf(stderr, "%s: cannot stat %s\n", progname, devpath); + goto out; + } + ret = S_ISBLK(st.st_mode); +out: + free(devpath); + return ret; +} + +static int is_feature_enabled(const char *feature, const char *devpath) +{ + char cmd[PATH_MAX]; + FILE *fp; + char enabled_features[4096] = ""; + int ret = 1; + + snprintf(cmd, sizeof(cmd), "%s -R features %s 2>&1", + DEBUGFS, devpath); + + /* Using popen() instead of run_command() since debugfs does + * not return proper error code if command is not supported */ + fp = popen(cmd, "r"); + if (!fp) { + fprintf(stderr, "%s: %s\n", progname, strerror(errno)); + return 0; + } + + ret = fread(enabled_features, 1, sizeof(enabled_features) - 1, fp); + enabled_features[ret] = '\0'; + pclose(fp); + + if (strstr(enabled_features, feature)) + return 1; + return 0; +} + /* Write the server config files */ int ldiskfs_write_ldd(struct mkfs_opts *mop) { @@ -276,7 +392,7 @@ int ldiskfs_read_ldd(char *dev, struct lustre_disk_data *mo_ldd) /* Display the need for the latest e2fsprogs to be installed. make_backfs * indicates if the caller is make_lustre_backfs() or not. */ -void disp_old_e2fsprogs_msg(const char *feature, int make_backfs) +static void disp_old_e2fsprogs_msg(const char *feature, int make_backfs) { static int msg_displayed; @@ -832,7 +948,7 @@ int ldiskfs_prepare_lustre(struct mkfs_opts *mop, return 0; } -int read_file(const char *path, char *buf, int size) +static int read_file(const char *path, char *buf, int size) { FILE *fd; @@ -850,7 +966,7 @@ int read_file(const char *path, char *buf, int size) return 0; } -int write_file(const char *path, const char *buf) +static int write_file(const char *path, const char *buf) { FILE *fd; @@ -863,7 +979,7 @@ int write_file(const char *path, const char *buf) return 0; } -int set_blockdev_scheduler(const char *path, const char *scheduler) +static int set_blockdev_scheduler(const char *path, const char *scheduler) { char buf[PATH_MAX], *c; int rc; @@ -911,7 +1027,7 @@ int set_blockdev_scheduler(const char *path, const char *scheduler) /* This is to tune the kernel for good SCSI performance. * For that we set the value of /sys/block/{dev}/queue/max_sectors_kb * to the value of /sys/block/{dev}/queue/max_hw_sectors_kb */ -int set_blockdev_tunables(char *source, struct mount_opts *mop) +static int set_blockdev_tunables(char *source, struct mount_opts *mop) { glob_t glob_info = { 0 }; struct stat stat_buf; @@ -1119,118 +1235,6 @@ int ldiskfs_label_lustre(struct mount_opts *mop) return rc; } -/* return canonicalized absolute pathname, even if the target file does not - * exist, unlike realpath */ -static char *absolute_path(char *devname) -{ - char buf[PATH_MAX + 1]; - char *path; - char *ptr; - - path = malloc(PATH_MAX + 1); - if (path == NULL) - return NULL; - - if (devname[0] != '/') { - if (getcwd(buf, sizeof(buf) - 1) == NULL) { - free(path); - return NULL; - } - strcat(buf, "/"); - if (strlen(devname) > sizeof(buf)-strlen(buf)-1) { - free(path); - return NULL; - } - strncat(buf, devname, sizeof(buf)-strlen(buf)-1); - } else { - if (strlen(devname) > sizeof(buf)-1) { - free(path); - return NULL; - } - strncpy(buf, devname, sizeof(buf)); - } - /* truncate filename before calling realpath */ - ptr = strrchr(buf, '/'); - if (ptr == NULL) { - free(path); - return NULL; - } - *ptr = '\0'; - if (path != realpath(buf, path)) { - free(path); - return NULL; - } - /* add the filename back */ - strcat(path, "/"); - strcat(path, ptr + 1); - return path; -} - -/* Determine if a device is a block device (as opposed to a file) */ -int is_block(char* devname) -{ - struct stat st; - int ret = 0; - char *devpath; - - devpath = absolute_path(devname); - if (devpath == NULL) { - fprintf(stderr, "%s: failed to resolve path to %s\n", - progname, devname); - return -1; - } - - ret = access(devname, F_OK); - if (ret != 0) { - if (strncmp(devpath, "/dev/", 5) == 0) { - /* nobody sane wants to create a loopback file under - * /dev. Let's just report the device doesn't exist */ - fprintf(stderr, "%s: %s apparently does not exist\n", - progname, devpath); - ret = -1; - goto out; - } - ret = 0; - goto out; - } - ret = stat(devpath, &st); - if (ret != 0) { - fprintf(stderr, "%s: cannot stat %s\n", progname, devpath); - goto out; - } - ret = S_ISBLK(st.st_mode); -out: - free(devpath); - return ret; -} - -static int is_feature_enabled(const char *feature, const char *devpath) -{ - char cmd[PATH_MAX]; - FILE *fp; - char enabled_features[4096] = ""; - int ret = 1; - - snprintf(cmd, sizeof(cmd), "%s -R features %s 2>&1", - DEBUGFS, devpath); - - /* Using popen() instead of run_command() since debugfs does - * not return proper error code if command is not supported */ - fp = popen(cmd, "r"); - if (!fp) { - fprintf(stderr, "%s: %s\n", progname, strerror(errno)); - return 0; - } - - ret = fread(enabled_features, 1, sizeof(enabled_features) - 1, fp); - enabled_features[ret] = '\0'; - pclose(fp); - - if (strstr(enabled_features, feature)) - return 1; - return 0; -} - /* Enable quota accounting */ int ldiskfs_enable_quota(struct mkfs_opts *mop) { diff --git a/lustre/utils/mount_utils_zfs.c b/lustre/utils/mount_utils_zfs.c index 4bc5751..0a0280a 100644 --- a/lustre/utils/mount_utils_zfs.c +++ b/lustre/utils/mount_utils_zfs.c @@ -31,7 +31,6 @@ #include #include #include -#include /* Persistent mount data is stored in these user attributes */ #define LDD_PREFIX "lustre:" @@ -104,84 +103,8 @@ static int osd_zfs_setup = 0; static libzfs_handle_t *g_zfs; -/* dynamic linking handles for libzfs & libnvpair */ -static void *handle_libzfs; -static void *handle_nvpair; - -/* symbol table looked up with dlsym */ -struct zfs_symbols { - libzfs_handle_t *(*libzfs_init)(void); - void (*libzfs_fini)(libzfs_handle_t *); - int (*libzfs_load_module)(char *); - zfs_handle_t* (*zfs_open)(libzfs_handle_t *, const char *, int); - int (*zfs_destroy)(zfs_handle_t *, boolean_t); - void (*zfs_close)(zfs_handle_t *); - int (*zfs_prop_set)(zfs_handle_t*, const char*, const char*); - nvlist_t* (*zfs_get_user_props) (zfs_handle_t *); - int (*zfs_name_valid)(const char *, zfs_type_t); - zpool_handle_t* (*zpool_open)(libzfs_handle_t *, const char *); - void (*zpool_close)(zpool_handle_t *zhp); - int (*nvlist_lookup_string)(nvlist_t*, const char*, char**); - int (*nvlist_lookup_nvlist)(nvlist_t *, const char *, nvlist_t **); - nvpair_t * (*nvlist_next_nvpair)(nvlist_t *, nvpair_t *); - char * (*nvpair_name)(nvpair_t *); -}; - -static struct zfs_symbols sym; void zfs_fini(void); -#define DLSYM(handle, func) \ - do { \ - sym.func = (typeof(sym.func))dlsym(handle, #func); \ - } while(0) - -/* populate the symbol table after a successful call to dlopen() */ -static int zfs_populate_symbols(void) -{ - char *error; - - dlerror(); /* Clear any existing error */ - - DLSYM(handle_libzfs, libzfs_init); -#define libzfs_init (*sym.libzfs_init) - DLSYM(handle_libzfs, libzfs_fini); -#define libzfs_fini (*sym.libzfs_fini) - DLSYM(handle_libzfs, libzfs_load_module); -#define libzfs_load_module (*sym.libzfs_load_module) - DLSYM(handle_libzfs, zfs_open); -#define zfs_open (*sym.zfs_open) - DLSYM(handle_libzfs, zfs_destroy); -#define zfs_destroy (*sym.zfs_destroy) - DLSYM(handle_libzfs, zfs_close); -#define zfs_close (*sym.zfs_close) - DLSYM(handle_libzfs, zfs_prop_set); -#define zfs_prop_set (*sym.zfs_prop_set) - DLSYM(handle_libzfs, zfs_get_user_props); -#define zfs_get_user_props (*sym.zfs_get_user_props) - DLSYM(handle_libzfs, zfs_name_valid); -#define zfs_name_valid (*sym.zfs_name_valid) - DLSYM(handle_libzfs, zpool_open); -#define zpool_open (*sym.zpool_open) - DLSYM(handle_libzfs, zpool_close); -#define zpool_close (*sym.zpool_close) - DLSYM(handle_nvpair, nvlist_lookup_string); -#define nvlist_lookup_string (*sym.nvlist_lookup_string) - DLSYM(handle_nvpair, nvlist_lookup_nvlist); -#define nvlist_lookup_nvlist (*sym.nvlist_lookup_nvlist) - DLSYM(handle_nvpair, nvlist_next_nvpair); -#define nvlist_next_nvpair (*sym.nvlist_next_nvpair) - DLSYM(handle_nvpair, nvpair_name); -#define nvpair_name (*sym.nvpair_name) - - error = dlerror(); - if (error != NULL) { - fatal(); - fprintf(stderr, "%s\n", error); - return EINVAL; - } - return 0; -} - static int zfs_set_prop_int(zfs_handle_t *zhp, char *prop, void *val) { char str[64]; @@ -635,6 +558,12 @@ out: return ret; } +int zfs_enable_quota(struct mkfs_opts *mop) +{ + fprintf(stderr, "this option is not only valid for zfs\n"); + return ENOSYS; +} + int zfs_prepare_lustre(struct mkfs_opts *mop, char *default_mountopts, int default_len, char *always_mountopts, int always_len) @@ -692,20 +621,6 @@ int zfs_init(void) * spamming ldiskfs users. An error message will still be printed if * someone tries to do some real work involving a ZFS backend */ - handle_libzfs = dlopen("libzfs.so.1", RTLD_LAZY); - if (handle_libzfs == NULL) - return EINVAL; - - handle_nvpair = dlopen("libnvpair.so.1", RTLD_LAZY); - if (handle_nvpair == NULL) { - ret = EINVAL; - goto out; - } - - ret = zfs_populate_symbols(); - if (ret) - goto out; - if (libzfs_load_module("zfs") != 0) { /* The ZFS modules are not installed */ ret = EINVAL; @@ -730,14 +645,5 @@ void zfs_fini(void) libzfs_fini(g_zfs); g_zfs = NULL; } - if (handle_nvpair) { - dlclose(handle_nvpair); - handle_nvpair = NULL; - } - if (handle_libzfs) { - dlclose(handle_libzfs); - handle_libzfs = NULL; - } - osd_zfs_setup = 0; } diff --git a/snmp/Makefile.am b/snmp/Makefile.am index fe2a153..729031a 100644 --- a/snmp/Makefile.am +++ b/snmp/Makefile.am @@ -1,7 +1,7 @@ -agent_PROGRAMS = lustresnmp.so +agent_LTLIBRARIES = lustresnmp.la mib_DATA = Lustre-MIB.txt -lustresnmp_so_SOURCES = \ +lustresnmp_la_SOURCES = \ lustre-snmp.c \ lustre-snmp.h \ lustre-snmp-trap.c \ @@ -9,9 +9,9 @@ lustresnmp_so_SOURCES = \ lustre-snmp-util.c \ lustre-snmp-util.h -lustresnmp_so_LDADD := $(NET_SNMP_LIBS) -lustresnmp_so_CFLAGS := -fPIC $(NET_SNMP_CFLAGS) -lustresnmp_so_LDFLAGS = -fPIC -shared +lustresnmp_la_LIBADD := $(NET_SNMP_LIBS) +lustresnmp_la_CFLAGS := -fPIC $(NET_SNMP_CFLAGS) +lustresnmp_la_LDFLAGS = -fPIC -shared -module -avoid-version SUBDIRS = DIST_SUBDIRS = autoconf