From 5e62552e7fc6e9da4068bb29f62eb2cf7a42970e Mon Sep 17 00:00:00 2001 From: Nathaniel Clark Date: Sat, 3 Nov 2018 00:03:43 -0400 Subject: [PATCH] LU-11555 utils: ZFS check multihost enabled in read_ldd() 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 Change-Id: Iddb5871afc6fb6808a25921c8d3e8516d675f15c Reviewed-on: https://review.whamcloud.com/33491 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Olaf Faaland-LLNL Reviewed-by: Oleg Drokin --- config/lustre-build-zfs.m4 | 13 +++++++++++++ lustre/utils/libmount_utils_zfs.c | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/config/lustre-build-zfs.m4 b/config/lustre-build-zfs.m4 index eb82bb4..dd59485 100644 --- a/config/lustre-build-zfs.m4 +++ b/config/lustre-build-zfs.m4 @@ -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 + ],[ + 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'], diff --git a/lustre/utils/libmount_utils_zfs.c b/lustre/utils/libmount_utils_zfs.c index 148260c..ebbee5c 100644 --- a/lustre/utils/libmount_utils_zfs.c +++ b/lustre/utils/libmount_utils_zfs.c @@ -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: -- 1.8.3.1