Fix off-by-1 truncation of hw_serial when converting from integer to string, when writing to /proc/sys/kernel/spl/spl_hostid.
Fixes hostid mismatch which leads to assertion failure when the hostid/hw_serial is a 10-character decimal number: $ zpool status pool: lustre state: ONLINE lt-zpool: zpool_main.c:3176: status_callback: Assertion `reason == ZPOOL_STATUS_OK' failed. zsh: 5262 abort zpool status
This commit is contained in:
parent
6c33eb8162
commit
a0b5ae8aca
@ -457,23 +457,24 @@ proc_dohostid(struct ctl_table *table, int write, struct file *filp,
|
|||||||
int len, rc = 0;
|
int len, rc = 0;
|
||||||
int32_t val;
|
int32_t val;
|
||||||
char *end, str[32];
|
char *end, str[32];
|
||||||
ENTRY;
|
ENTRY;
|
||||||
|
|
||||||
if (write) {
|
if (write) {
|
||||||
/* We can't use proc_doulongvec_minmax() in the write
|
/* We can't use proc_doulongvec_minmax() in the write
|
||||||
* case hear because hostid while a hex value has no
|
* case hear because hostid while a hex value has no
|
||||||
* leading 0x which confuses the helper function. */
|
* leading 0x which confuses the helper function. */
|
||||||
rc = proc_copyin_string(str, sizeof(str), buffer, *lenp);
|
rc = proc_copyin_string(str, sizeof(str), buffer, *lenp);
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
RETURN(rc);
|
RETURN(rc);
|
||||||
|
|
||||||
val = simple_strtol(str, &end, 16);
|
val = simple_strtol(str, &end, 16);
|
||||||
if (str == end)
|
if (str == end)
|
||||||
RETURN(-EINVAL);
|
RETURN(-EINVAL);
|
||||||
|
|
||||||
spl_hostid = (long)val;
|
spl_hostid = (long) val;
|
||||||
(void)snprintf(hw_serial, HW_HOSTID_LEN-1, "%u",
|
(void) snprintf(hw_serial, HW_HOSTID_LEN, "%u",
|
||||||
(val >= 0) ? val : -val);
|
(val >= 0) ? val : -val);
|
||||||
|
hw_serial[HW_HOSTID_LEN - 1] = '\0';
|
||||||
*ppos += *lenp;
|
*ppos += *lenp;
|
||||||
} else {
|
} else {
|
||||||
len = snprintf(str, sizeof(str), "%lx", spl_hostid);
|
len = snprintf(str, sizeof(str), "%lx", spl_hostid);
|
||||||
|
Loading…
Reference in New Issue
Block a user