Whamcloud - gitweb
LU-12616 obclass: fix MDS start/stop race
[fs/lustre-release.git] / lustre / utils / libmount_utils_zfs.c
index f77ea7e..770a053 100644 (file)
@@ -20,7 +20,7 @@
  * GPL HEADER END
  */
 /*
- * Copyright (c) 2012, 2016, Intel Corporation.
+ * Copyright (c) 2012, 2017, Intel Corporation.
  * Use is subject to license terms.
  */
 /*
@@ -31,8 +31,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <libzfs.h>
-
-#define HOSTID_PATH "/etc/hostid"
+#include <sys/systeminfo.h>
 
 /* Persistent mount data is stored in these user attributes */
 #define LDD_PREFIX             "lustre:"
@@ -237,13 +236,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();
@@ -262,7 +272,7 @@ static int zfs_check_hostid(struct mkfs_opts *mop)
        if (hostid != 0)
                return 0;
 
-       f = fopen(HOSTID_PATH, "r");
+       f = fopen(HW_HOSTID_PATH, "r");
        if (f == NULL)
                goto out;
 
@@ -270,12 +280,13 @@ static int zfs_check_hostid(struct mkfs_opts *mop)
        fclose(f);
 
        if (rc != 1) {
-               fprintf(stderr, "Failed to read "HOSTID_PATH": %d\n",
+               fprintf(stderr, "Failed to read "HW_HOSTID_PATH": %d\n",
                       rc);
                hostid = 0;
        }
 
 out:
+#endif
        if (hostid == 0) {
                if (mop->mo_flags & MO_NOHOSTID_CHECK) {
                        fprintf(stderr, "WARNING: spl_hostid not set. ZFS has "
@@ -477,8 +488,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;
 }
@@ -543,6 +568,9 @@ static char *zfs_mkfs_opts(struct mkfs_opts *mop, char *str, int len)
 
        if (strlen(mop->mo_mkfsopts) != 0)
                snprintf(str, len, " -o %s", mop->mo_mkfsopts);
+       if (mop->mo_device_kb)
+               snprintf(str, len, " -o quota=%llu",
+                        mop->mo_device_kb * 1024);
 
        return str;
 }
@@ -706,13 +734,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: