@@ -40,47 +40,40 @@ get_spl_hostid(void)
40
40
* Allow the hostid to be subverted for testing.
41
41
*/
42
42
env = getenv ("ZFS_HOSTID" );
43
- if (env ) {
44
- hostid = strtoull (env , NULL , 0 );
45
- return (hostid & HOSTID_MASK );
46
- }
43
+ if (env )
44
+ return (strtoull (env , NULL , 0 ));
47
45
48
- f = fopen ("/sys/module /spl/parameters/spl_hostid " , "r" );
46
+ f = fopen ("/proc/ sys/kernel /spl/hostid " , "r" );
49
47
if (!f )
50
48
return (0 );
51
49
52
- if (fscanf (f , "%lu " , & hostid ) != 1 )
50
+ if (fscanf (f , "%lx " , & hostid ) != 1 )
53
51
hostid = 0 ;
54
52
55
53
fclose (f );
56
54
57
- return (hostid & HOSTID_MASK );
55
+ return (hostid );
58
56
}
59
57
60
58
unsigned long
61
59
get_system_hostid (void )
62
60
{
63
- unsigned long system_hostid = get_spl_hostid ();
61
+ unsigned long hostid = get_spl_hostid ();
62
+
64
63
/*
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.
64
+ * We do not use gethostid(3) because it can return a bogus ID,
65
+ * depending on the libc and /etc/hostid presence,
66
+ * and the kernel and userspace must agree.
70
67
* See comments above hostid_read() in the SPL.
71
68
*/
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 );
69
+ if (hostid == 0 ) {
70
+ int fd = open ("/etc/hostid" , O_RDONLY );
78
71
if (fd >= 0 ) {
79
- rc = read (fd , & hostid , hostid_size );
80
- if (rc > 0 )
81
- system_hostid = (hostid & HOSTID_MASK );
82
- close (fd );
72
+ if (read (fd , & hostid , 4 ) < 0 )
73
+ hostid = 0 ;
74
+ (void ) close (fd );
83
75
}
84
76
}
85
- return (system_hostid );
77
+
78
+ return (hostid & HOSTID_MASK );
86
79
}
0 commit comments