Commit 941c3ff3 authored by Kinglong Mee's avatar Kinglong Mee Committed by Trond Myklebust

Sunrpc: Supports hexadecimal number for sysctl files of sunrpc debug

The sunrpc debug sysctl files only accept decimal number right now.
But all the XXXDBUG_XXX macros are defined as hexadecimal.
It is not easy to set or check an separate flag.

This patch let those files support accepting hexadecimal number,
(decimal number is also supported). Also, display it as hexadecimal.

v2,
Remove duplicate parsing of '0x...', just using simple_strtol(tmpbuf, &s, 0)
Fix a bug of isspace() checking after parsing
Signed-off-by: default avatarKinglong Mee <kinglongmee@gmail.com>
Signed-off-by: default avatarTrond Myklebust <trond.myklebust@primarydata.com>
parent 1ca843a2
...@@ -76,7 +76,7 @@ static int ...@@ -76,7 +76,7 @@ static int
proc_dodebug(struct ctl_table *table, int write, proc_dodebug(struct ctl_table *table, int write,
void __user *buffer, size_t *lenp, loff_t *ppos) void __user *buffer, size_t *lenp, loff_t *ppos)
{ {
char tmpbuf[20], c, *s; char tmpbuf[20], c, *s = NULL;
char __user *p; char __user *p;
unsigned int value; unsigned int value;
size_t left, len; size_t left, len;
...@@ -103,23 +103,24 @@ proc_dodebug(struct ctl_table *table, int write, ...@@ -103,23 +103,24 @@ proc_dodebug(struct ctl_table *table, int write,
return -EFAULT; return -EFAULT;
tmpbuf[left] = '\0'; tmpbuf[left] = '\0';
for (s = tmpbuf, value = 0; '0' <= *s && *s <= '9'; s++, left--) value = simple_strtol(tmpbuf, &s, 0);
value = 10 * value + (*s - '0'); if (s) {
if (*s && !isspace(*s)) left -= (s - tmpbuf);
return -EINVAL; if (left && !isspace(*s))
while (left && isspace(*s)) return -EINVAL;
left--, s++; while (left && isspace(*s))
left--, s++;
} else
left = 0;
*(unsigned int *) table->data = value; *(unsigned int *) table->data = value;
/* Display the RPC tasks on writing to rpc_debug */ /* Display the RPC tasks on writing to rpc_debug */
if (strcmp(table->procname, "rpc_debug") == 0) if (strcmp(table->procname, "rpc_debug") == 0)
rpc_show_tasks(&init_net); rpc_show_tasks(&init_net);
} else { } else {
if (!access_ok(VERIFY_WRITE, buffer, left)) len = sprintf(tmpbuf, "0x%04x", *(unsigned int *) table->data);
return -EFAULT;
len = sprintf(tmpbuf, "%d", *(unsigned int *) table->data);
if (len > left) if (len > left)
len = left; len = left;
if (__copy_to_user(buffer, tmpbuf, len)) if (copy_to_user(buffer, tmpbuf, len))
return -EFAULT; return -EFAULT;
if ((left -= len) > 0) { if ((left -= len) > 0) {
if (put_user('\n', (char __user *)buffer + len)) if (put_user('\n', (char __user *)buffer + len))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment