Whamcloud - gitweb
LU-7674 lmv: remove unused placement parameter
[fs/lustre-release.git] / lustre / utils / mount_utils_zfs.c
index 0a0280a..60d5552 100644 (file)
  * GPL HEADER END
  */
 /*
- * Copyright (c) 2012, 2013, Intel Corporation.
+ * Copyright (c) 2012, 2014, Intel Corporation.
  * Use is subject to license terms.
- *
  */
 /*
  * Author: Brian Behlendorf <behlendorf1@llnl.gov>
  */
 #include "mount_utils.h"
+#include <stddef.h>
 #include <stdio.h>
 #include <string.h>
 #include <libzfs.h>
@@ -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;
@@ -528,13 +575,12 @@ int zfs_make_lustre(struct mkfs_opts *mop)
        /*
         * Create the ZFS filesystem with any required mkfs options:
         * - canmount=off is set to prevent zfs automounting
-        * - version=4 is set because SA are not yet handled by the osd
+        * - xattr=sa is set to use system attribute based xattrs
         */
        memset(mkfs_cmd, 0, PATH_MAX);
        snprintf(mkfs_cmd, PATH_MAX,
                 "zfs create -o canmount=off -o xattr=sa%s %s",
-                zfs_mkfs_opts(mop, mkfs_tmp, PATH_MAX),
-                ds);
+                zfs_mkfs_opts(mop, mkfs_tmp, PATH_MAX), ds);
 
        vprint("mkfs_cmd = %s\n", mkfs_cmd);
        ret = run_command(mkfs_cmd, PATH_MAX);
@@ -565,8 +611,7 @@ int zfs_enable_quota(struct mkfs_opts *mop)
 }
 
 int zfs_prepare_lustre(struct mkfs_opts *mop,
-               char *default_mountopts, int default_len,
-               char *always_mountopts, int always_len)
+                      char *wanted_mountopts, size_t len)
 {
        if (osd_check_zfs_setup() == 0)
                return EINVAL;
@@ -617,25 +662,14 @@ int zfs_init(void)
 {
        int ret = 0;
 
-       /* If the ZFS libs are not installed, don't print an error to avoid
-        * spamming ldiskfs users. An error message will still be printed if
-        * someone tries to do some real work involving a ZFS backend */
-
-       if (libzfs_load_module("zfs") != 0) {
-               /* The ZFS modules are not installed */
-               ret = EINVAL;
-               goto out;
-       }
-
        g_zfs = libzfs_init();
        if (g_zfs == NULL) {
                fprintf(stderr, "Failed to initialize ZFS library\n");
                ret = EINVAL;
+       } else {
+               osd_zfs_setup = 1;
        }
-out:
-       osd_zfs_setup = 1;
-       if (ret)
-               zfs_fini();
+
        return ret;
 }