Whamcloud - gitweb
LU-12400 zfs: zfs mainline 0.8+ with mainline (5.2) kernel 18/35518/11
authorShaun Tancheff <stancheff@cray.com>
Fri, 30 Aug 2019 16:57:40 +0000 (11:57 -0500)
committerOleg Drokin <green@whamcloud.com>
Fri, 4 Oct 2019 03:44:13 +0000 (03:44 +0000)
Compile tests need to resolve using Module.symvers from the zfs
kmod kernel version.

dsl_pool_config_enter signature changed

Use spa_get_hostid() if it is available (zfs 0.7.0 and later).
For zfs 0.6.x use /proc/sys/kernel/spl/hostid with a fallback
to reading the spl module parameters and manually decoding
the hostid file.

list_move_tail() in libzfs conflicts with normal kernel/lustre
list API. Move it out of the way before libcfs/util/list.h is
included.

Cray-bug-id: LUS-7600
Signed-off-by: Shaun Tancheff <stancheff@cray.com>
Change-Id: Ia16e226239d33555ba7d906b39e37e20f012a02c
Reviewed-on: https://review.whamcloud.com/35518
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Nathaniel Clark <nclark@whamcloud.com>
Reviewed-by: Petros Koutoupis <pkoutoupis@cray.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
config/lustre-build-linux.m4
lustre/osd-zfs/osd_internal.h
lustre/utils/libmount_utils_zfs.c

index ce8eb98..42a9339 100644 (file)
@@ -544,7 +544,7 @@ AC_DEFUN([LB_LINUX_COMPILE_IFELSE],
 [m4_ifvaln([$1], [AC_LANG_CONFTEST([AC_LANG_SOURCE([$1])])])dnl
 rm -f build/conftest.o build/conftest.mod.c build/conftest.ko
 SUBARCH=$(echo $target_cpu | sed -e 's/powerpc.*/powerpc/' -e 's/ppc.*/powerpc/' -e 's/x86_64/x86/' -e 's/i.86/x86/' -e 's/k1om/x86/' -e 's/aarch64.*/arm64/' -e 's/armv7.*/arm/')
-AS_IF([AC_TRY_COMMAND(cp conftest.c build && make -d [$2] LDFLAGS= ${LD:+LD="$LD"} CC="$CC" -f $PWD/build/Makefile LUSTRE_LINUX_CONFIG=$LINUX_CONFIG LINUXINCLUDE="$EXTRA_CHECK_INCLUDE -I$LINUX/arch/$SUBARCH/include -Iinclude -Iarch/$SUBARCH/include/generated -I$LINUX/include -Iinclude2 -I$LINUX/include/uapi -Iinclude/generated -I$LINUX/arch/$SUBARCH/include/uapi -Iarch/$SUBARCH/include/generated/uapi -I$LINUX/include/uapi -Iinclude/generated/uapi ${SPL_OBJ:+-include $SPL_OBJ/spl_config.h} ${ZFS_OBJ:+-include $ZFS_OBJ/zfs_config.h} ${SPL:+-I$SPL/include } ${ZFS:+-I$ZFS -I$ZFS/include -I${SPL:-$ZFS/include/spl}} -include $CONFIG_INCLUDE" -o tmp_include_depends -o scripts -o include/config/MARKER -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $MODULE_TARGET=$PWD/build) >/dev/null && AC_TRY_COMMAND([$3])],
+AS_IF([AC_TRY_COMMAND(cp conftest.c build && make -d [$2] LDFLAGS= ${LD:+LD="$LD"} CC="$CC" -f $PWD/build/Makefile LUSTRE_LINUX_CONFIG=$LINUX_CONFIG LINUXINCLUDE="$EXTRA_CHECK_INCLUDE -I$LINUX/arch/$SUBARCH/include -Iinclude -Iarch/$SUBARCH/include/generated -I$LINUX/include -Iinclude2 -I$LINUX/include/uapi -Iinclude/generated -I$LINUX/arch/$SUBARCH/include/uapi -Iarch/$SUBARCH/include/generated/uapi -I$LINUX/include/uapi -Iinclude/generated/uapi ${SPL_OBJ:+-include $SPL_OBJ/spl_config.h} ${ZFS_OBJ:+-include $ZFS_OBJ/zfs_config.h} ${SPL:+-I$SPL/include } ${ZFS:+-I$ZFS -I$ZFS/include -I${SPL:-$ZFS/include/spl}} -include $CONFIG_INCLUDE" KBUILD_EXTRA_SYMBOLS=${ZFS_OBJ:+$ZFS_OBJ/Module.symvers} -o tmp_include_depends -o scripts -o include/config/MARKER -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $MODULE_TARGET=$PWD/build) >/dev/null && AC_TRY_COMMAND([$3])],
        [$4],
        [_AC_MSG_LOG_CONFTEST
 m4_ifvaln([$5],[$5])dnl])
index 304b309..4e5b480 100644 (file)
@@ -812,11 +812,11 @@ static inline uint32_t attrs_zfs2fs(const uint64_t flags)
 #endif
 
 #ifndef HAVE_DSL_POOL_CONFIG
-static inline void dsl_pool_config_enter(dsl_pool_t *dp, char *name)
+static inline void dsl_pool_config_enter(dsl_pool_t *dp, void *name)
 {
 }
 
-static inline void dsl_pool_config_exit(dsl_pool_t *dp, char *name)
+static inline void dsl_pool_config_exit(dsl_pool_t *dp, void *name)
 {
 }
 #endif
index 770a053..a4fe85e 100644 (file)
 /*
  * Author: Brian Behlendorf <behlendorf1@llnl.gov>
  */
+#ifndef HAVE_ZFS_MULTIHOST
+#include <sys/list.h>
+#define list_move_tail(a, b) spl_list_move_tail(a, b)
+#include <sys/spa.h>
+#endif
 #include "mount_utils.h"
 #include <stddef.h>
 #include <stdio.h>
@@ -187,6 +192,114 @@ static int zfs_erase_allprops(zfs_handle_t *zhp)
 
        return 0;
 }
+/*
+ * ZFS on linux 0.7.0-rc5 commit 379ca9cf2beba802f096273e89e30914a2d6bafc
+ * Multi-modifier protection (MMP)
+ *
+ * Introduced spa_get_hostid() along with a few constants like
+ * ZPOOL_CONFIG_MMP_HOSTID that can be checked to imply availablity of
+ * spa_get_hostid. Supply a fallback when spa_get_hostid is not
+ * available.
+ *
+ * This can be removed when zfs 0.6.x support is dropped.
+ */
+#if !defined(ZPOOL_CONFIG_MMP_HOSTID) && !defined(HAVE_ZFS_MULTIHOST)
+unsigned long _hostid_from_proc(void)
+{
+       FILE *f;
+       unsigned long hostid;
+       int rc;
+
+       f = fopen("/proc/sys/kernel/spl/hostid", "r");
+       if (f == NULL)
+               goto out;
+
+       rc = fscanf(f, "%lx", &hostid);
+       fclose(f);
+       if (rc == 1)
+               return hostid;
+out:
+       return 0;
+}
+
+unsigned long _hostid_from_module_param(void)
+{
+       FILE *f;
+       unsigned long hostid;
+       int rc;
+
+       f = fopen("/sys/module/spl/parameters/spl_hostid", "r");
+       if (f == NULL)
+               goto out;
+
+       rc = fscanf(f, "%li", &hostid);
+       fclose(f);
+       if (rc == 1)
+               return hostid;
+out:
+       return 0;
+}
+
+unsigned long _from_module_param_indirect(void)
+{
+       FILE *f;
+       unsigned long hostid = 0;
+       uint32_t hwid;
+       int rc;
+       char *spl_hostid_path = NULL;
+
+       /* read the module parameter for HW_HOSTID_PATH */
+       f = fopen("/sys/module/spl/parameters/spl_hostid_path", "r");
+       if (f == NULL) {
+               fatal();
+               fprintf(stderr, "Failed to open spl_hostid_path param: %s\n",
+                       strerror(errno));
+               goto out;
+       }
+
+       rc = fscanf(f, "%ms%*[\n]", &spl_hostid_path);
+       fclose(f);
+       if (rc == 0 || !spl_hostid_path)
+               goto out;
+
+       /* read the hostid from the file */
+       f = fopen(spl_hostid_path, "r");
+       if (f == NULL) {
+               fatal();
+               fprintf(stderr, "Failed to open %s param: %s\n",
+                       spl_hostid_path, strerror(errno));
+               goto out;
+       }
+
+       /* hostid is the first 4 bytes in native endian order */
+       rc = fread(&hwid, sizeof(uint32_t), 1, f);
+       fclose(f);
+       if (rc == 1)
+               hostid = (unsigned long)hwid;
+
+out:
+       if (spl_hostid_path)
+               free(spl_hostid_path);
+
+       return hostid;
+}
+
+unsigned long spa_get_hostid(void)
+{
+       unsigned long hostid;
+
+       hostid = _hostid_from_proc();
+       if (hostid)
+               return hostid;
+
+       /* if /proc isn't available, try /sys */
+       hostid = _hostid_from_module_param();
+       if (hostid)
+               return hostid;
+
+       return _from_module_param_indirect();
+}
+#endif
 
 /*
  * Map '<key>=<value> ...' pairs in the passed string to dataset properties
@@ -237,10 +350,6 @@ static int zfs_set_prop_params(zfs_handle_t *zhp, char *params)
 static int zfs_check_hostid(struct mkfs_opts *mop)
 {
        unsigned long hostid;
-#ifndef HAVE_ZFS_MULTIHOST
-       FILE *f;
-       int rc;
-#endif
 
        if (strstr(mop->mo_ldd.ldd_params, PARAM_FAILNODE) == NULL)
                return 0;
@@ -248,44 +357,7 @@ static int zfs_check_hostid(struct mkfs_opts *mop)
 #ifdef HAVE_ZFS_MULTIHOST
        hostid = get_system_hostid();
 #else
-       /* This reimplements libzfs2::get_system_hostid() from 0.7+ because
-        * prior to 0.7.0 (MULTIHOST support), get_system_hostid() would return
-        * gethostid() if spl_hostid was 0, which would generate a hostid if
-        * /etc/hostid wasn't set, which is incompatible with the kernel
-        * implementation.
-        */
-       f = fopen("/sys/module/spl/parameters/spl_hostid", "r");
-       if (f == NULL) {
-               fatal();
-               fprintf(stderr, "Failed to open spl_hostid: %s\n",
-                       strerror(errno));
-               return errno;
-       }
-       rc = fscanf(f, "%li", &hostid);
-       fclose(f);
-       if (rc != 1) {
-               fatal();
-               fprintf(stderr, "Failed to read spl_hostid: %d\n", rc);
-               return rc;
-       }
-
-       if (hostid != 0)
-               return 0;
-
-       f = fopen(HW_HOSTID_PATH, "r");
-       if (f == NULL)
-               goto out;
-
-       rc = fread(&hostid, sizeof(uint32_t), 1, f);
-       fclose(f);
-
-       if (rc != 1) {
-               fprintf(stderr, "Failed to read "HW_HOSTID_PATH": %d\n",
-                      rc);
-               hostid = 0;
-       }
-
-out:
+       hostid = spa_get_hostid();
 #endif
        if (hostid == 0) {
                if (mop->mo_flags & MO_NOHOSTID_CHECK) {