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>
This commit is contained in:
parent
7f5c330b26
commit
5f71f3c325
2 changed files with 66 additions and 21 deletions
|
@ -399,6 +399,8 @@ struct svc_procedure {
|
||||||
/*
|
/*
|
||||||
* Function prototypes.
|
* Function prototypes.
|
||||||
*/
|
*/
|
||||||
|
int sunrpc_set_pool_mode(const char *val);
|
||||||
|
int sunrpc_get_pool_mode(char *val, size_t size);
|
||||||
int svc_rpcb_setup(struct svc_serv *serv, struct net *net);
|
int svc_rpcb_setup(struct svc_serv *serv, struct net *net);
|
||||||
void svc_rpcb_cleanup(struct svc_serv *serv, struct net *net);
|
void svc_rpcb_cleanup(struct svc_serv *serv, struct net *net);
|
||||||
int svc_bind(struct svc_serv *serv, struct net *net);
|
int svc_bind(struct svc_serv *serv, struct net *net);
|
||||||
|
|
|
@ -72,57 +72,100 @@ static struct svc_pool_map svc_pool_map = {
|
||||||
static DEFINE_MUTEX(svc_pool_map_mutex);/* protects svc_pool_map.count only */
|
static DEFINE_MUTEX(svc_pool_map_mutex);/* protects svc_pool_map.count only */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
param_set_pool_mode(const char *val, const struct kernel_param *kp)
|
__param_set_pool_mode(const char *val, struct svc_pool_map *m)
|
||||||
{
|
{
|
||||||
int *ip = (int *)kp->arg;
|
int err, mode;
|
||||||
struct svc_pool_map *m = &svc_pool_map;
|
|
||||||
int err;
|
|
||||||
|
|
||||||
mutex_lock(&svc_pool_map_mutex);
|
mutex_lock(&svc_pool_map_mutex);
|
||||||
|
|
||||||
err = -EBUSY;
|
|
||||||
if (m->count)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
err = 0;
|
err = 0;
|
||||||
if (!strncmp(val, "auto", 4))
|
if (!strncmp(val, "auto", 4))
|
||||||
*ip = SVC_POOL_AUTO;
|
mode = SVC_POOL_AUTO;
|
||||||
else if (!strncmp(val, "global", 6))
|
else if (!strncmp(val, "global", 6))
|
||||||
*ip = SVC_POOL_GLOBAL;
|
mode = SVC_POOL_GLOBAL;
|
||||||
else if (!strncmp(val, "percpu", 6))
|
else if (!strncmp(val, "percpu", 6))
|
||||||
*ip = SVC_POOL_PERCPU;
|
mode = SVC_POOL_PERCPU;
|
||||||
else if (!strncmp(val, "pernode", 7))
|
else if (!strncmp(val, "pernode", 7))
|
||||||
*ip = SVC_POOL_PERNODE;
|
mode = SVC_POOL_PERNODE;
|
||||||
else
|
else
|
||||||
err = -EINVAL;
|
err = -EINVAL;
|
||||||
|
|
||||||
|
if (err)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (m->count == 0)
|
||||||
|
m->mode = mode;
|
||||||
|
else if (mode != m->mode)
|
||||||
|
err = -EBUSY;
|
||||||
out:
|
out:
|
||||||
mutex_unlock(&svc_pool_map_mutex);
|
mutex_unlock(&svc_pool_map_mutex);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
param_get_pool_mode(char *buf, const struct kernel_param *kp)
|
param_set_pool_mode(const char *val, const struct kernel_param *kp)
|
||||||
{
|
{
|
||||||
int *ip = (int *)kp->arg;
|
struct svc_pool_map *m = kp->arg;
|
||||||
|
|
||||||
switch (*ip)
|
return __param_set_pool_mode(val, m);
|
||||||
|
}
|
||||||
|
|
||||||
|
int sunrpc_set_pool_mode(const char *val)
|
||||||
|
{
|
||||||
|
return __param_set_pool_mode(val, &svc_pool_map);
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL(sunrpc_set_pool_mode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sunrpc_get_pool_mode - get the current pool_mode for the host
|
||||||
|
* @buf: where to write the current pool_mode
|
||||||
|
* @size: size of @buf
|
||||||
|
*
|
||||||
|
* Grab the current pool_mode from the svc_pool_map and write
|
||||||
|
* the resulting string to @buf. Returns the number of characters
|
||||||
|
* written to @buf (a'la snprintf()).
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
sunrpc_get_pool_mode(char *buf, size_t size)
|
||||||
|
{
|
||||||
|
struct svc_pool_map *m = &svc_pool_map;
|
||||||
|
|
||||||
|
switch (m->mode)
|
||||||
{
|
{
|
||||||
case SVC_POOL_AUTO:
|
case SVC_POOL_AUTO:
|
||||||
return sysfs_emit(buf, "auto\n");
|
return snprintf(buf, size, "auto");
|
||||||
case SVC_POOL_GLOBAL:
|
case SVC_POOL_GLOBAL:
|
||||||
return sysfs_emit(buf, "global\n");
|
return snprintf(buf, size, "global");
|
||||||
case SVC_POOL_PERCPU:
|
case SVC_POOL_PERCPU:
|
||||||
return sysfs_emit(buf, "percpu\n");
|
return snprintf(buf, size, "percpu");
|
||||||
case SVC_POOL_PERNODE:
|
case SVC_POOL_PERNODE:
|
||||||
return sysfs_emit(buf, "pernode\n");
|
return snprintf(buf, size, "pernode");
|
||||||
default:
|
default:
|
||||||
return sysfs_emit(buf, "%d\n", *ip);
|
return snprintf(buf, size, "%d", m->mode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
EXPORT_SYMBOL(sunrpc_get_pool_mode);
|
||||||
|
|
||||||
|
static int
|
||||||
|
param_get_pool_mode(char *buf, const struct kernel_param *kp)
|
||||||
|
{
|
||||||
|
char str[16];
|
||||||
|
int len;
|
||||||
|
|
||||||
|
len = sunrpc_get_pool_mode(str, ARRAY_SIZE(str));
|
||||||
|
|
||||||
|
/* Ensure we have room for newline and NUL */
|
||||||
|
len = min_t(int, len, ARRAY_SIZE(str) - 2);
|
||||||
|
|
||||||
|
/* tack on the newline */
|
||||||
|
str[len] = '\n';
|
||||||
|
str[len + 1] = '\0';
|
||||||
|
|
||||||
|
return sysfs_emit(buf, str);
|
||||||
|
}
|
||||||
|
|
||||||
module_param_call(pool_mode, param_set_pool_mode, param_get_pool_mode,
|
module_param_call(pool_mode, param_set_pool_mode, param_get_pool_mode,
|
||||||
&svc_pool_map.mode, 0644);
|
&svc_pool_map, 0644);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Detect best pool mapping mode heuristically,
|
* Detect best pool mapping mode heuristically,
|
||||||
|
|
Loading…
Add table
Reference in a new issue