Skip to content

Commit 5f71f3c

Browse files
jtlaytonchucklever
authored andcommitted
sunrpc: refactor pool_mode setting code
Allow the pool_mode setting code to be called from internal callers so we can call it from a new netlink op. Add a new svc_pool_map_get function to return the current setting. Change the existing module parameter handling to use the new interfaces under the hood. Signed-off-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
1 parent 7f5c330 commit 5f71f3c

File tree

2 files changed

+66
-21
lines changed

2 files changed

+66
-21
lines changed

include/linux/sunrpc/svc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,8 @@ struct svc_procedure {
399399
/*
400400
* Function prototypes.
401401
*/
402+
int sunrpc_set_pool_mode(const char *val);
403+
int sunrpc_get_pool_mode(char *val, size_t size);
402404
int svc_rpcb_setup(struct svc_serv *serv, struct net *net);
403405
void svc_rpcb_cleanup(struct svc_serv *serv, struct net *net);
404406
int svc_bind(struct svc_serv *serv, struct net *net);

net/sunrpc/svc.c

Lines changed: 64 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -72,57 +72,100 @@ static struct svc_pool_map svc_pool_map = {
7272
static DEFINE_MUTEX(svc_pool_map_mutex);/* protects svc_pool_map.count only */
7373

7474
static int
75-
param_set_pool_mode(const char *val, const struct kernel_param *kp)
75+
__param_set_pool_mode(const char *val, struct svc_pool_map *m)
7676
{
77-
int *ip = (int *)kp->arg;
78-
struct svc_pool_map *m = &svc_pool_map;
79-
int err;
77+
int err, mode;
8078

8179
mutex_lock(&svc_pool_map_mutex);
8280

83-
err = -EBUSY;
84-
if (m->count)
85-
goto out;
86-
8781
err = 0;
8882
if (!strncmp(val, "auto", 4))
89-
*ip = SVC_POOL_AUTO;
83+
mode = SVC_POOL_AUTO;
9084
else if (!strncmp(val, "global", 6))
91-
*ip = SVC_POOL_GLOBAL;
85+
mode = SVC_POOL_GLOBAL;
9286
else if (!strncmp(val, "percpu", 6))
93-
*ip = SVC_POOL_PERCPU;
87+
mode = SVC_POOL_PERCPU;
9488
else if (!strncmp(val, "pernode", 7))
95-
*ip = SVC_POOL_PERNODE;
89+
mode = SVC_POOL_PERNODE;
9690
else
9791
err = -EINVAL;
9892

93+
if (err)
94+
goto out;
95+
96+
if (m->count == 0)
97+
m->mode = mode;
98+
else if (mode != m->mode)
99+
err = -EBUSY;
99100
out:
100101
mutex_unlock(&svc_pool_map_mutex);
101102
return err;
102103
}
103104

104105
static int
105-
param_get_pool_mode(char *buf, const struct kernel_param *kp)
106+
param_set_pool_mode(const char *val, const struct kernel_param *kp)
107+
{
108+
struct svc_pool_map *m = kp->arg;
109+
110+
return __param_set_pool_mode(val, m);
111+
}
112+
113+
int sunrpc_set_pool_mode(const char *val)
114+
{
115+
return __param_set_pool_mode(val, &svc_pool_map);
116+
}
117+
EXPORT_SYMBOL(sunrpc_set_pool_mode);
118+
119+
/**
120+
* sunrpc_get_pool_mode - get the current pool_mode for the host
121+
* @buf: where to write the current pool_mode
122+
* @size: size of @buf
123+
*
124+
* Grab the current pool_mode from the svc_pool_map and write
125+
* the resulting string to @buf. Returns the number of characters
126+
* written to @buf (a'la snprintf()).
127+
*/
128+
int
129+
sunrpc_get_pool_mode(char *buf, size_t size)
106130
{
107-
int *ip = (int *)kp->arg;
131+
struct svc_pool_map *m = &svc_pool_map;
108132

109-
switch (*ip)
133+
switch (m->mode)
110134
{
111135
case SVC_POOL_AUTO:
112-
return sysfs_emit(buf, "auto\n");
136+
return snprintf(buf, size, "auto");
113137
case SVC_POOL_GLOBAL:
114-
return sysfs_emit(buf, "global\n");
138+
return snprintf(buf, size, "global");
115139
case SVC_POOL_PERCPU:
116-
return sysfs_emit(buf, "percpu\n");
140+
return snprintf(buf, size, "percpu");
117141
case SVC_POOL_PERNODE:
118-
return sysfs_emit(buf, "pernode\n");
142+
return snprintf(buf, size, "pernode");
119143
default:
120-
return sysfs_emit(buf, "%d\n", *ip);
144+
return snprintf(buf, size, "%d", m->mode);
121145
}
122146
}
147+
EXPORT_SYMBOL(sunrpc_get_pool_mode);
148+
149+
static int
150+
param_get_pool_mode(char *buf, const struct kernel_param *kp)
151+
{
152+
char str[16];
153+
int len;
154+
155+
len = sunrpc_get_pool_mode(str, ARRAY_SIZE(str));
156+
157+
/* Ensure we have room for newline and NUL */
158+
len = min_t(int, len, ARRAY_SIZE(str) - 2);
159+
160+
/* tack on the newline */
161+
str[len] = '\n';
162+
str[len + 1] = '\0';
163+
164+
return sysfs_emit(buf, str);
165+
}
123166

124167
module_param_call(pool_mode, param_set_pool_mode, param_get_pool_mode,
125-
&svc_pool_map.mode, 0644);
168+
&svc_pool_map, 0644);
126169

127170
/*
128171
* Detect best pool mapping mode heuristically,

0 commit comments

Comments
 (0)