From: Nathaniel Clark Date: Tue, 15 Sep 2015 19:26:53 +0000 (-0400) Subject: LU-7134 utils: Ensure hostid set for ZFS during mkfs X-Git-Tag: 2.8.54~28 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=7b654fc673a2570ab4a828c2a7b213cee8b5b0cc LU-7134 utils: Ensure hostid set for ZFS during mkfs Ensure import protection in ZFS. spl_hostid must be set to a non-zero value for it to work correctly. Error out during mkfs and tunefs unless override is passed. Also print error during mount. Ensure hostid is set in conf-sanity.sh Signed-off-by: Nathaniel Clark Change-Id: If37318c20e4502a643992e6bc21ac4bc4ad20ed7 Reviewed-on: http://review.whamcloud.com/16611 Reviewed-by: Andreas Dilger Reviewed-by: Alex Zhuravlev Tested-by: Jenkins Tested-by: Maloo --- diff --git a/lustre/doc/mkfs.lustre.8 b/lustre/doc/mkfs.lustre.8 index 9f0bc47..3c256b5 100644 --- a/lustre/doc/mkfs.lustre.8 +++ b/lustre/doc/mkfs.lustre.8 @@ -147,6 +147,11 @@ avoids having the target try to register as a new target with the MGS. .BI \--stripe-count-hint= stripes Used for optizing MDT inode size .TP +.BI \--force-nohostid +Ignore unset hostid for ZFS import protection. To set hostid either set +spl_hostid parameter for spl.ko or set /etc/hostid, see genhostid(1). + +.TP .BI \--verbose Print more information. .TP diff --git a/lustre/doc/tunefs.lustre.8 b/lustre/doc/tunefs.lustre.8 index 8e49b45..10228c8 100644 --- a/lustre/doc/tunefs.lustre.8 +++ b/lustre/doc/tunefs.lustre.8 @@ -75,6 +75,10 @@ Set the NID(s) of the MGS node, required for all targets other than the MGS. .BI \--nomgs Remove a configuration management service to this target .TP +.BI \--force-nohostid +Ignore unset hostid for ZFS import protection. To set hostid either set +spl_hostid option for spl.ko or set /etc/hostid, see genhostid(1). +.TP .BI \--quiet Print less information. .TP diff --git a/lustre/tests/test-framework.sh b/lustre/tests/test-framework.sh index b323882..5bde188 100755 --- a/lustre/tests/test-framework.sh +++ b/lustre/tests/test-framework.sh @@ -1190,6 +1190,15 @@ set_default_debug_facet () { set_default_debug_nodes $node } +set_hostid () { + local hostid=${1:-$(hostid)} + + if [ ! -s /etc/hostid ]; then + printf $(echo -n $hostid | + sed 's/\(..\)\(..\)\(..\)\(..\)/\\x\4\\x\3\\x\2\\x\1/') >/etc/hostid + fi +} + # Facet functions mount_facets () { local facets=${1:-$(get_facets)} @@ -3537,6 +3546,9 @@ format_ost() { formatall() { stopall + # Set hostid for ZFS/SPL zpool import protection + do_rpc_nodes "$(comma_list $(remote_nodes_list))" set_hostid + # We need ldiskfs here, may as well load them all load_modules [ "$CLIENTONLY" ] && return diff --git a/lustre/utils/mkfs_lustre.c b/lustre/utils/mkfs_lustre.c index ca7d5f9..456c37e 100644 --- a/lustre/utils/mkfs_lustre.c +++ b/lustre/utils/mkfs_lustre.c @@ -165,6 +165,8 @@ void usage(FILE *out) "\t\t--comment=: arbitrary string (%d bytes)\n" "\t\t--dryrun: report what we would do; don't write to disk\n" "\t\t--verbose: e.g. show mkfs progress\n" + "\t\t--force-nohostid: Ignore hostid requirement for ZFS " + "import\n" "\t\t-V|--version: output build version of the utility and\n" "\t\t\texit\n" "\t\t--quiet\n", @@ -294,6 +296,7 @@ int parse_opts(int argc, char *const argv[], struct mkfs_opts *mop, { "servicenode", required_argument, NULL, 's' }, { "network", required_argument, NULL, 't' }, { "comment", required_argument, NULL, 'u' }, + { "force-nohostid", no_argument, NULL, 'U' }, { "verbose", no_argument, NULL, 'v' }, { "version", no_argument, NULL, 'V' }, #ifndef TUNEFS @@ -468,6 +471,9 @@ int parse_opts(int argc, char *const argv[], struct mkfs_opts *mop, strscpy(ldd->ldd_userdata, optarg, sizeof(ldd->ldd_userdata)); break; + case 'U': + mop->mo_flags |= MO_NOHOSTID_CHECK; + break; case 'v': verbose++; break; diff --git a/lustre/utils/mount_lustre.c b/lustre/utils/mount_lustre.c index dfa65f4..b247327 100644 --- a/lustre/utils/mount_lustre.c +++ b/lustre/utils/mount_lustre.c @@ -341,6 +341,7 @@ static int clear_update_ondisk(char *source, struct lustre_disk_data *ldd) memset(&mkop, 0, sizeof(mkop)); mkop.mo_ldd = *ldd; mkop.mo_ldd.ldd_flags &= ~LDD_F_UPDATE; + mkop.mo_flags = MO_NOHOSTID_CHECK; /* Ignore missing hostid */ if (strlen(source) > sizeof(mkop.mo_device)-1) { fatal(); fprintf(stderr, "Device name too long: %s\n", source); diff --git a/lustre/utils/mount_utils.h b/lustre/utils/mount_utils.h index 915b48f..ae238eb 100644 --- a/lustre/utils/mount_utils.h +++ b/lustre/utils/mount_utils.h @@ -74,6 +74,7 @@ extern int failover; #define MO_FAILOVER 0x04 #define MO_DRYRUN 0x08 #define MO_QUOTA 0x10 +#define MO_NOHOSTID_CHECK 0x20 #define MAX_LOOP_DEVICES 16 #define INDEX_UNASSIGNED 0xFFFF diff --git a/lustre/utils/mount_utils_zfs.c b/lustre/utils/mount_utils_zfs.c index b1ca83d..60d5552 100644 --- a/lustre/utils/mount_utils_zfs.c +++ b/lustre/utils/mount_utils_zfs.c @@ -174,6 +174,45 @@ static int zfs_set_prop_params(zfs_handle_t *zhp, char *params) return ret; } +static int zfs_check_hostid(struct mkfs_opts *mop) +{ + FILE *f; + unsigned long hostid; + int rc; + + if (strstr(mop->mo_ldd.ldd_params, PARAM_FAILNODE) == NULL) + return 0; + + 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) { + if (mop->mo_flags & MO_NOHOSTID_CHECK) { + fprintf(stderr, "WARNING: spl_hostid not set. ZFS has " + "no zpool import protection\n"); + } else { + fatal(); + fprintf(stderr, "spl_hostid not set. See %s(8)", + progname); + return EINVAL; + } + } + + return 0; +} + static int osd_check_zfs_setup(void) { if (osd_zfs_setup == 0) { @@ -195,7 +234,7 @@ int zfs_write_ldd(struct mkfs_opts *mop) int i, ret = EINVAL; if (osd_check_zfs_setup() == 0) - return EINVAL; + goto out; zhp = zfs_open(g_zfs, ds, ZFS_TYPE_FILESYSTEM); if (zhp == NULL) { @@ -203,6 +242,10 @@ int zfs_write_ldd(struct mkfs_opts *mop) goto out; } + ret = zfs_check_hostid(mop); + if (ret != 0) + goto out; + vprint("Writing %s properties\n", ds); for (i = 0; special_ldd_prop_params[i].zlpb_prop_name != NULL; i++) { @@ -451,6 +494,10 @@ int zfs_make_lustre(struct mkfs_opts *mop) return EINVAL; } + ret = zfs_check_hostid(mop); + if (ret != 0) + goto out; + pool = strdup(ds); if (pool == NULL) return ENOMEM;