Whamcloud - gitweb
LU-8816 utils: Check /etc/hostid instead of failing for ZFS 04/23804/4
authorNathaniel Clark <nathaniel.l.clark@intel.com>
Wed, 16 Nov 2016 16:52:57 +0000 (11:52 -0500)
committerOleg Drokin <oleg.drokin@intel.com>
Fri, 18 Nov 2016 20:06:53 +0000 (20:06 +0000)
Since ZFS doesn't check /etc/hostid until a pool is created or
imported.  Check for it's existance instead of just failing after
spl_hostid is checked.

Test-Parameters: trivial

Signed-off-by: Nathaniel Clark <nathaniel.l.clark@intel.com>
Change-Id: Ia00b1e357c629ad6a7a2b636a2fc149036d03546
Reviewed-on: http://review.whamcloud.com/23804
Reviewed-by: Bob Glossman <bob.glossman@intel.com>
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/utils/mount_utils_zfs.c

index 755c218..cdb45cb 100644 (file)
@@ -32,6 +32,8 @@
 #include <string.h>
 #include <libzfs.h>
 
 #include <string.h>
 #include <libzfs.h>
 
+#define HOSTID_PATH "/etc/hostid"
+
 /* Persistent mount data is stored in these user attributes */
 #define LDD_PREFIX             "lustre:"
 #define LDD_VERSION_PROP       LDD_PREFIX "version"
 /* Persistent mount data is stored in these user attributes */
 #define LDD_PREFIX             "lustre:"
 #define LDD_VERSION_PROP       LDD_PREFIX "version"
@@ -198,6 +200,23 @@ static int zfs_check_hostid(struct mkfs_opts *mop)
                return rc;
        }
 
                return rc;
        }
 
+       if (hostid != 0)
+               return 0;
+
+       f = fopen(HOSTID_PATH, "r");
+       if (f == NULL)
+               goto out;
+
+       rc = fread(&hostid, sizeof(uint32_t), 1, f);
+       fclose(f);
+
+       if (rc != 1) {
+               fprintf(stderr, "Failed to read "HOSTID_PATH": %d\n",
+                      rc);
+               hostid = 0;
+       }
+
+out:
        if (hostid == 0) {
                if (mop->mo_flags & MO_NOHOSTID_CHECK) {
                        fprintf(stderr, "WARNING: spl_hostid not set. ZFS has "
        if (hostid == 0) {
                if (mop->mo_flags & MO_NOHOSTID_CHECK) {
                        fprintf(stderr, "WARNING: spl_hostid not set. ZFS has "