From 0d77156572c2b77581f01d960c0e5738b369de6a Mon Sep 17 00:00:00 2001 From: Nathaniel Clark Date: Thu, 1 May 2014 17:13:45 -0400 Subject: [PATCH] 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. Lustre-change: http://review.whamcloud.com/10193 Lustre-commit: 3e8c354c09725a97b90e477a77411cc6fb306f09 LU-5091 build: Support alternate locations of libzfs.so Due to the change for with-zfs-devel (LU-3497), also add support to search for libzfs.so along with the alternate locations supplied with the header files. Also need to unpack zfs{,-devel}. The zfs RPM is needed because it has the actual libraries in it and the zfs-devel RPM only has un- versioned symlinks to the libraries in the zfs RPM. This will all change one day when we have a libzfs RPM per https://github.com/zfsonlinux/zfs/issues/2329 and it looks like it could be one day soon: https://github.com/zfsonlinux/zfs/pull/2341. Lustre-change: http://review.whamcloud.com/10401 Lustre-commit: b2659030edb7d34c91430ff924bab23881b6c230 Signed-off-by: Nathaniel Clark Signed-off-by: Brian J. Murrell Reviewed-by: James Simmons Reviewed-by: Oleg Drokin Change-Id: I1d69b64eec1589f63e24f20cc624778a4be2ec60 Reviewed-on: http://review.whamcloud.com/11297 Tested-by: Jenkins Tested-by: Maloo --- .gitignore | 4 + autogen.sh | 1 + config/.gitignore | 6 + config/lustre-build-zfs.m4 | 27 +++- configure.ac | 1 + contrib/lbuild/lbuild | 118 +++++++------- lustre.spec.in | 8 +- lustre/utils/Makefile.am | 63 ++++---- lustre/utils/mount_utils.c | 317 ++++++++++++++++++------------------- lustre/utils/mount_utils.h | 49 ++---- lustre/utils/mount_utils_ldiskfs.c | 240 ++++++++++++++-------------- lustre/utils/mount_utils_zfs.c | 106 +------------ snmp/Makefile.am | 10 +- 13 files changed, 434 insertions(+), 516 deletions(-) diff --git a/.gitignore b/.gitignore index d43a74f..93046e9 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*.tar.gz /mkinstalldirs diff --git a/autogen.sh b/autogen.sh index 6edec5b..8496f34 100644 --- a/autogen.sh +++ b/autogen.sh @@ -39,6 +39,7 @@ done PWD_SAVE=$PWD +run_cmd "libtoolize -q" run_cmd "aclocal -I $PWD/config $ACLOCAL_FLAGS" run_cmd "autoheader" run_cmd "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 df78230..40ca661 100644 --- a/config/lustre-build-zfs.m4 +++ b/config/lustre-build-zfs.m4 @@ -22,6 +22,11 @@ dnl # --with-zfs-devel=path dnl # - User provided directory where zfs development headers dnl # are located. This option is typically used when user dnl # uses rpm2cpio to unpack src rpm. +dnl # Assumes layout of: +dnl # ${zfs-devel-path}/usr/include/libzfs +dnl # ${zfs-devel-path}/usr/include/libspl +dnl # ${zfs-devel-path}/lib64/libzfs.so.* or +dnl # ${zfs-devel-path}/lib/libzfs.so.* dnl # dnl # --with-zfs=path - Enable zfs support and use the zfs headers in the dnl # provided path. No autodetection is performed and @@ -277,12 +282,13 @@ AC_DEFUN([LB_ZFS_DEVEL], [ AC_MSG_CHECKING([user provided zfs devel headers]) AS_IF([test ! -z "${zfsdevel}"], [ AS_IF([test -d "${zfsdevel}/usr/include/libspl" && test -d "${zfsdevel}/usr/include/libzfs"], [ - zfslib="-I $zfsdevel/usr/include/libspl -I $zfsdevel/usr/include/libzfs" + zfsinc="-I $zfsdevel/usr/include/libspl -I $zfsdevel/usr/include/libzfs" + zfslib="-L$zfsdevel/lib64 -L$zfsdevel/lib" ], [ AC_MSG_ERROR([Path to development headers directory does not exist]) ]) ]) - AC_MSG_RESULT([$zfslib]) + AC_MSG_RESULT([$zfsinc]) ]) AC_DEFUN([LB_ZFS_USER], [ @@ -290,20 +296,25 @@ AC_DEFUN([LB_ZFS_USER], [ dnl # Detect user space zfs development headers. dnl # AC_MSG_CHECKING([zfs devel headers]) - AS_IF([test -z "${zfslib}"], [ + AS_IF([test -z "${zfsinc}"], [ AS_IF([test -e "${zfssrc}/include/libzfs.h" && test -e "${zfssrc}/lib/libspl/include"], [ - zfslib="-I $zfssrc/lib/libspl/include -I $zfssrc/include" + zfsinc="-I $zfssrc/lib/libspl/include -I $zfssrc/include" + zfslib="-L$zfssrc/lib/libzfs/.libs/" ], [test -d /usr/include/libzfs && test -d /usr/include/libspl], [ - zfslib="-I /usr/include/libspl -I /usr/include/libzfs" + zfsinc="-I/usr/include/libspl -I /usr/include/libzfs" + zfslib="" ], [ - zfslib="[Not Found]" + zfsinc="[Not Found]" + zfslib="" enable_zfs=no ]) ]) - AC_MSG_RESULT([$zfslib]) + AC_MSG_RESULT([$zfsinc]) - ZFS_LIBZFS_INCLUDE=${zfslib} + ZFS_LIBZFS_INCLUDE=${zfsinc} + ZFS_LIBZFS_LDFLAGS="-lzfs ${zfslib}" 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/contrib/lbuild/lbuild b/contrib/lbuild/lbuild index 7f9856d..219934f 100755 --- a/contrib/lbuild/lbuild +++ b/contrib/lbuild/lbuild @@ -1076,24 +1076,24 @@ build_spl_zfs() { git clone ${SPLZFSGITREPO:-"https://github.com/zfsonlinux"}/$pkg.git $pkg 2>&1 pushd $pkg || return 255 - if [ -n "$SPLZFSTAG" ]; then - git checkout $SPLZFSTAG - else - git checkout -b lbuild $pkg-$SPLZFSVER - fi - - # This differentiates between older zfs versions - if [ -f $pkg-modules.spec.in ]; then - rpmpkg=$pkg-modules - specdir=. - speclist="$pkg.spec $rpmpkg.spec" - else + if [ -n "$SPLZFSTAG" ]; then + git checkout $SPLZFSTAG + else + git checkout -b lbuild $pkg-$SPLZFSVER + fi + + # This differentiates between older zfs versions + if [ -f $pkg-modules.spec.in ]; then + rpmpkg=$pkg-modules + specdir=. + speclist="$pkg.spec $rpmpkg.spec" + else rpmpkg=kmod-$pkg-devel - specdir=rpm/generic - speclist="$pkg.spec $pkg-kmod.spec $pkg-dkms.spec" - fi + specdir=rpm/generic + speclist="$pkg.spec $pkg-kmod.spec $pkg-dkms.spec" + fi - sh autogen.sh || return 255 + sh autogen.sh || return 255 if ! ./configure --with-linux=${LINUX} --with-linux-obj=${LINUXOBJ:-$LINUX} \ ${spldir:+--with-spl="${spldir}"} 2>&1 || @@ -1105,40 +1105,36 @@ build_spl_zfs() { ln -f $pkg/$pkg-*.tar.gz $TOPDIR/SOURCES || error "failed to link $pkg/$pkg-*.tar.gz into $TOPDIR/SOURCES" - if [ -f $pkg/scripts/kmodtool ]; then - ln -f $pkg/scripts/kmodtool $TOPDIR/SOURCES/ - fi - - local rpmb - if $DO_SRC; then - rpmb=-ba - else - rpmb=-bb - fi - - # set search dir for our own kmodtool to find correct - # directories - export KERNELSOURCE=$(dirname ${LINUX}) - # Manually build rpms - for spec in $speclist; do - echo "Building RPMs from $pkg/$specdir/$spec" + if [ -f $pkg/scripts/kmodtool ]; then + ln -f $pkg/scripts/kmodtool $TOPDIR/SOURCES/ + fi + + local rpmb + if $DO_SRC; then + rpmb=-ba + else + rpmb=-bb + fi + + # set search dir for our own kmodtool to find correct + # directories + export KERNELSOURCE=$(dirname ${LINUX}) + # Manually build rpms + for spec in $speclist; do + echo "Building RPMs from $pkg/$specdir/$spec" if ! $RPMBUILD $rpmb $pkg/$specdir/$spec \ - --nodeps -v \ - --define "require_kdir ${LINUX}" \ - ${LINUXOBJ:+--define "require_kobj ${LINUXOBJ}"} \ - ${spldir:+--define "require_spldir ${spldir}"} \ - --define "kver $kver" \ - --define "kernels $kver" \ - --define "_tmppath /var/tmp" \ - --define "kernelbuildroot $TOPDIR/reused" \ - --define "_topdir $TOPDIR" 2>&1; then - return 255 + --nodeps -v \ + --define "require_kdir ${LINUX}" \ + ${LINUXOBJ:+--define "require_kobj ${LINUXOBJ}"} \ + ${spldir:+--define "require_spldir ${spldir}"} \ + --define "kver $kver" \ + --define "kernels $kver" \ + --define "_tmppath /var/tmp" \ + --define "kernelbuildroot $TOPDIR/reused" \ + --define "_topdir $TOPDIR" 2>&1; then + return 255 fi - done - -# $DO_SRC && mv $pkg*.src.rpm $TOPDIR/SRPMS/ -# mv $pkg*.noarch.rpm $TOPDIR/RPMS/noarch/ -# mv *$pkg*.$TARGET_ARCH.rpm $TOPDIR/RPMS/$(basearch $TARGET_ARCH)/ + done # We have built the rpms for the package. Now we need to extract the # contained files so we can build further things against them @@ -1146,19 +1142,25 @@ build_spl_zfs() { # cpio only extract to pwd so we need to go there. pushd $TOPDIR - local rpm - for rpm in $rpms; do + local rpm + for rpm in $rpms; do rpm2cpio $rpm | cpio -id - done + done if [ "$pkg" == "zfs" ]; then - mkdir -p $TOPDIR/zfsdevel - pushd $TOPDIR/zfsdevel - # We also need to extract zfs-devel rpm - local devel_rpm=$(ls -1 $TOPDIR/RPMS/*/$pkg-devel-*.rpm) - rpm2cpio $devel_rpm | cpio -id - popd - CONFIGURE_FLAGS="--with-$pkg-devel=$TOPDIR/zfsdevel ${CONFIGURE_FLAGS}" + # We also need to extract both the zfs and zfs-devel rpms + # the zfs rpm is needed because it has the actual libraries in + # it and the zfs-devel rpm only has unversioned symlinks to the + # libraries in the zfs rpm + # this will all change one day when we have a libzfs rpm per + # https://github.com/zfsonlinux/zfs/issues/2329 + # and it looks like it could be one day soon: + # https://github.com/zfsonlinux/zfs/pull/2341 + local devel_rpms=$(ls -1 $TOPDIR/RPMS/*/{$pkg-devel,$pkg-$SPLZFSVER}-*.rpm) + for rpm in $devel_rpms; do + rpm2cpio $rpm | cpio -id + done + CONFIGURE_FLAGS="--with-$pkg-devel=$TOPDIR ${CONFIGURE_FLAGS}" fi popd diff --git a/lustre.spec.in b/lustre.spec.in index 6b5b6e7..7ae63e0 100644 --- a/lustre.spec.in +++ b/lustre.spec.in @@ -99,6 +99,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 @@ -415,6 +416,8 @@ if [ -f $RPM_BUILD_DIR/lustre-%{version}/lustre/include/linux/lustre_types.h ] ; echo '%attr(-, root, root) %{_includedir}/linux/lustre_types.h' >>lustre.files fi +find $RPM_BUILD_ROOT%{_libdir}/@PACKAGE@/ -name \*.la -delete + %if %{with lustre_tests} echo '%attr(-, root, root) %{_libdir}/lustre/tests/*' >lustre-tests.files echo '%attr(-, root, root) %{_bindir}/mcreate' >>lustre-tests.files @@ -477,6 +480,7 @@ find $RPM_BUILD_ROOT%{?rootdir}/lib/modules/%{kversion}/%{kmoddir} -name "*.ko" %attr(-, root, root) %{?rootdir}/lib/modules/%{kversion}/%{kmoddir}/kernel/fs/@PACKAGE@/ldiskfs.ko %attr(-, root, root) %{?rootdir}/lib/modules/%{kversion}/%{kmoddir}/kernel/fs/@PACKAGE@/fsfilt_ldiskfs.ko %attr(-, root, root) %{?rootdir}/lib/modules/%{kversion}/%{kmoddir}/kernel/fs/@PACKAGE@/osd_ldiskfs.ko +%attr(-, root, root) %{_libdir}/@PACKAGE@/mount_osd_ldiskfs.so %if %{defined rpm_post_base} %attr(0555, root, root) %{rpm_post_base}-osd-ldiskfs.sh %endif @@ -484,7 +488,9 @@ find $RPM_BUILD_ROOT%{?rootdir}/lib/modules/%{kversion}/%{kmoddir} -name "*.ko" %if %{with zfs} %files osd-zfs -%attr(-, root, root) %{?rootdir}/lib/modules/%{kversion}/%{kmoddir}/kernel/fs/@PACKAGE@/osd_zfs.ko +%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/utils/Makefile.am b/lustre/utils/Makefile.am index bc8783d..fb43481 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 @@ -34,6 +37,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 @@ -117,49 +121,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) @@ -176,6 +174,7 @@ wiretest_SOURCES = wiretest.c lhsmtool_posix_SOURCES = lhsmtool_posix.c lhsmtool_posix_LDADD := liblustreapi.a $(PTHREAD_LIBS) lhsmtool_posix_DEPENDENCIES := liblustreapi.a +endif EXTRA_DIST = $(sbin_scripts) $(bin_scripts) diff --git a/lustre/utils/mount_utils.c b/lustre/utils/mount_utils.c index 68b448c..cb721cd 100644 --- a/lustre/utils/mount_utils.c +++ b/lustre/utils/mount_utils.c @@ -46,6 +46,7 @@ #include #include #include +#include extern char *progname; extern int verbose; @@ -53,6 +54,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; @@ -407,31 +410,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; } @@ -441,25 +527,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; } @@ -467,20 +539,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; @@ -492,25 +561,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; } @@ -522,29 +577,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; } @@ -554,25 +593,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; } @@ -582,25 +607,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; } @@ -611,59 +622,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 7f9cda8..709dc95 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 e91a0aa..80cb249 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; @@ -825,7 +941,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; @@ -843,7 +959,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; @@ -856,7 +972,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; @@ -904,7 +1020,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; @@ -1112,118 +1228,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 66ee68d..281a54c 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 -- 1.8.3.1