Whamcloud - gitweb
LU-11555 utils: ZFS check multihost enabled in read_ldd() 91/33491/5
authorNathaniel Clark <nclark@whamcloud.com>
Sat, 3 Nov 2018 04:03:43 +0000 (00:03 -0400)
committerOleg Drokin <green@whamcloud.com>
Wed, 23 Jan 2019 09:18:32 +0000 (09:18 +0000)
For ZFS check that multihost is enabled if failover host is defined.
Print a warning if it's not.

Test-Parameters: trivial mdtfilesystemtype=zfs ostfilesystemtype=zfs
Signed-off-by: Nathaniel Clark <nclark@whamcloud.com>
Change-Id: Iddb5871afc6fb6808a25921c8d3e8516d675f15c
Reviewed-on: https://review.whamcloud.com/33491
Tested-by: Jenkins
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Olaf Faaland-LLNL <faaland1@llnl.gov>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
config/lustre-build-zfs.m4
lustre/utils/libmount_utils_zfs.c

index eb82bb4..dd59485 100644 (file)
@@ -533,6 +533,19 @@ your distribution.
                        AC_DEFINE(HAVE_DMU_USEROBJ_ACCOUNTING, 1,
                                [Have native dnode accounting in ZFS])
                ])
+               dnl #
+               dnl # ZFS 0.7.0 feature: MULTIHOST
+               dnl #
+               LB_CHECK_COMPILE([if ZFS has multihost protection],
+               spa_multihost, [
+                       #include <sys/spa.h>
+               ],[
+                       spa_multihost(NULL);
+               ],[
+                       AC_DEFINE(HAVE_ZFS_MULTIHOST, 1,
+                               [Have multihost protection in ZFS])
+               ])
+               dnl #
                dnl # ZFS 0.7.x adds new method zap_lookup_by_dnode
                dnl #
                LB_CHECK_COMPILE([if ZFS has 'zap_lookup_by_dnode'],
index 148260c..ebbee5c 100644 (file)
@@ -237,13 +237,24 @@ static int zfs_set_prop_params(zfs_handle_t *zhp, char *params)
 
 static int zfs_check_hostid(struct mkfs_opts *mop)
 {
-       FILE *f;
        unsigned long hostid;
+#ifndef HAVE_ZFS_MULTIHOST
+       FILE *f;
        int rc;
+#endif
 
        if (strstr(mop->mo_ldd.ldd_params, PARAM_FAILNODE) == NULL)
                return 0;
 
+#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();
@@ -276,6 +287,7 @@ static int zfs_check_hostid(struct mkfs_opts *mop)
        }
 
 out:
+#endif
        if (hostid == 0) {
                if (mop->mo_flags & MO_NOHOSTID_CHECK) {
                        fprintf(stderr, "WARNING: spl_hostid not set. ZFS has "
@@ -477,8 +489,22 @@ int zfs_read_ldd(char *ds,  struct lustre_disk_data *ldd)
 
        ldd->ldd_mount_type = LDD_MT_ZFS;
        ret = 0;
+
+#ifdef HAVE_ZFS_MULTIHOST
+       if (strstr(ldd->ldd_params, PARAM_FAILNODE) != NULL) {
+               zpool_handle_t *pool = zfs_get_pool_handle(zhp);
+               uint64_t mh = zpool_get_prop_int(pool, ZPOOL_PROP_MULTIHOST,
+                                                NULL);
+               if (!mh)
+                       fprintf(stderr, "%s: %s is configured for failover "
+                               "but zpool does not have multihost enabled\n",
+                               progname, ds);
+       }
+#endif
+
 out_close:
        zfs_close(zhp);
+
 out:
        return ret;
 }
@@ -709,13 +735,18 @@ int zfs_make_lustre(struct mkfs_opts *mop)
         * 0.7.0 - multihost=on
         * 0.7.0 - feature@userobj_accounting=enabled
         */
+#if defined(HAVE_ZFS_MULTIHOST) || defined(HAVE_DMU_USEROBJ_ACCOUNTING)
        php = zpool_open(g_zfs, pool);
        if (php) {
+#ifdef HAVE_ZFS_MULTIHOST
                zpool_set_prop(php, "multihost", "on");
+#endif
+#ifdef HAVE_DMU_USEROBJ_ACCOUNTING
                zpool_set_prop(php, "feature@userobj_accounting", "enabled");
-
+#endif
                zpool_close(php);
        }
+#endif
 
        /*
         * Create the ZFS filesystem with any required mkfs options: