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) {
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) {
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++) {
return EINVAL;
}
+ ret = zfs_check_hostid(mop);
+ if (ret != 0)
+ goto out;
+
pool = strdup(ds);
if (pool == NULL)
return ENOMEM;