+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;
+}
+