@@ -42,45 +42,39 @@ get_spl_hostid(void)
42
42
env = getenv ("ZFS_HOSTID" );
43
43
if (env ) {
44
44
hostid = strtoull (env , NULL , 0 );
45
- return (hostid & HOSTID_MASK );
45
+ return (hostid );
46
46
}
47
47
48
- f = fopen ("/sys/module /spl/parameters/spl_hostid " , "r" );
48
+ f = fopen ("/proc/ sys/kernel /spl/hostid " , "r" );
49
49
if (!f )
50
50
return (0 );
51
51
52
- if (fscanf (f , "%lu " , & hostid ) != 1 )
52
+ if (fscanf (f , "%lx " , & hostid ) != 1 )
53
53
hostid = 0 ;
54
54
55
55
fclose (f );
56
56
57
- return (hostid & HOSTID_MASK );
57
+ return (hostid );
58
58
}
59
59
60
60
unsigned long
61
61
get_system_hostid (void )
62
62
{
63
- unsigned long system_hostid = get_spl_hostid ();
63
+ unsigned long hostid = get_spl_hostid ();
64
+
64
65
/*
65
- * We do not use the library call gethostid() because
66
- * it generates a hostid value that the kernel is
67
- * unaware of, if the spl_hostid module parameter has not
68
- * been set and there is no system hostid file (e.g.
69
- * /etc/hostid). The kernel and userspace must agree.
66
+ * We do not use gethostid(3) because it can return a bogus ID,
67
+ * depending on the libc and /etc/hostid presence,
68
+ * and the kernel and userspace must agree.
70
69
* See comments above hostid_read() in the SPL.
71
70
*/
72
- if (system_hostid == 0 ) {
73
- int fd , rc ;
74
- unsigned long hostid ;
75
- int hostid_size = 4 ; /* 4 bytes regardless of arch */
76
-
77
- fd = open ("/etc/hostid" , O_RDONLY );
71
+ if (hostid == 0 ) {
72
+ int fd = open ("/etc/hostid" , O_RDONLY );
78
73
if (fd >= 0 ) {
79
- rc = read (fd , & hostid , hostid_size );
80
- if (rc > 0 )
81
- system_hostid = (hostid & HOSTID_MASK );
82
- close (fd );
74
+ int _ = read (fd , & hostid , 4 );
75
+ (void ) _ , close (fd );
83
76
}
84
77
}
85
- return (system_hostid );
78
+
79
+ return (hostid & HOSTID_MASK );
86
80
}
0 commit comments