Skip to content

Commit 0050607

Browse files
jtlaytonchucklever
authored andcommitted
nfsd: new netlink ops to get/set server pool_mode
Signed-off-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
1 parent 5f71f3c commit 0050607

File tree

5 files changed

+113
-0
lines changed

5 files changed

+113
-0
lines changed

Documentation/netlink/specs/nfsd.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,15 @@ attribute-sets:
115115
type: nest
116116
nested-attributes: sock
117117
multi-attr: true
118+
-
119+
name: pool-mode
120+
attributes:
121+
-
122+
name: mode
123+
type: string
124+
-
125+
name: npools
126+
type: u32
118127

119128
operations:
120129
list:
@@ -195,3 +204,21 @@ operations:
195204
reply:
196205
attributes:
197206
- addr
207+
-
208+
name: pool-mode-set
209+
doc: set the current server pool-mode
210+
attribute-set: pool-mode
211+
flags: [ admin-perm ]
212+
do:
213+
request:
214+
attributes:
215+
- mode
216+
-
217+
name: pool-mode-get
218+
doc: get info about server pool-mode
219+
attribute-set: pool-mode
220+
do:
221+
reply:
222+
attributes:
223+
- mode
224+
- npools

fs/nfsd/netlink.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ static const struct nla_policy nfsd_listener_set_nl_policy[NFSD_A_SERVER_SOCK_AD
4040
[NFSD_A_SERVER_SOCK_ADDR] = NLA_POLICY_NESTED(nfsd_sock_nl_policy),
4141
};
4242

43+
/* NFSD_CMD_POOL_MODE_SET - do */
44+
static const struct nla_policy nfsd_pool_mode_set_nl_policy[NFSD_A_POOL_MODE_MODE + 1] = {
45+
[NFSD_A_POOL_MODE_MODE] = { .type = NLA_NUL_STRING, },
46+
};
47+
4348
/* Ops table for nfsd */
4449
static const struct genl_split_ops nfsd_nl_ops[] = {
4550
{
@@ -83,6 +88,18 @@ static const struct genl_split_ops nfsd_nl_ops[] = {
8388
.doit = nfsd_nl_listener_get_doit,
8489
.flags = GENL_CMD_CAP_DO,
8590
},
91+
{
92+
.cmd = NFSD_CMD_POOL_MODE_SET,
93+
.doit = nfsd_nl_pool_mode_set_doit,
94+
.policy = nfsd_pool_mode_set_nl_policy,
95+
.maxattr = NFSD_A_POOL_MODE_MODE,
96+
.flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO,
97+
},
98+
{
99+
.cmd = NFSD_CMD_POOL_MODE_GET,
100+
.doit = nfsd_nl_pool_mode_get_doit,
101+
.flags = GENL_CMD_CAP_DO,
102+
},
86103
};
87104

88105
struct genl_family nfsd_nl_family __ro_after_init = {

fs/nfsd/netlink.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ int nfsd_nl_version_set_doit(struct sk_buff *skb, struct genl_info *info);
2323
int nfsd_nl_version_get_doit(struct sk_buff *skb, struct genl_info *info);
2424
int nfsd_nl_listener_set_doit(struct sk_buff *skb, struct genl_info *info);
2525
int nfsd_nl_listener_get_doit(struct sk_buff *skb, struct genl_info *info);
26+
int nfsd_nl_pool_mode_set_doit(struct sk_buff *skb, struct genl_info *info);
27+
int nfsd_nl_pool_mode_get_doit(struct sk_buff *skb, struct genl_info *info);
2628

2729
extern struct genl_family nfsd_nl_family;
2830

fs/nfsd/nfsctl.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2156,6 +2156,63 @@ int nfsd_nl_listener_get_doit(struct sk_buff *skb, struct genl_info *info)
21562156
return err;
21572157
}
21582158

2159+
/**
2160+
* nfsd_nl_pool_mode_set_doit - set the number of running threads
2161+
* @skb: reply buffer
2162+
* @info: netlink metadata and command arguments
2163+
*
2164+
* Return 0 on success or a negative errno.
2165+
*/
2166+
int nfsd_nl_pool_mode_set_doit(struct sk_buff *skb, struct genl_info *info)
2167+
{
2168+
const struct nlattr *attr;
2169+
2170+
if (GENL_REQ_ATTR_CHECK(info, NFSD_A_POOL_MODE_MODE))
2171+
return -EINVAL;
2172+
2173+
attr = info->attrs[NFSD_A_POOL_MODE_MODE];
2174+
return sunrpc_set_pool_mode(nla_data(attr));
2175+
}
2176+
2177+
/**
2178+
* nfsd_nl_pool_mode_get_doit - get info about pool_mode
2179+
* @skb: reply buffer
2180+
* @info: netlink metadata and command arguments
2181+
*
2182+
* Return 0 on success or a negative errno.
2183+
*/
2184+
int nfsd_nl_pool_mode_get_doit(struct sk_buff *skb, struct genl_info *info)
2185+
{
2186+
struct net *net = genl_info_net(info);
2187+
char buf[16];
2188+
void *hdr;
2189+
int err;
2190+
2191+
if (sunrpc_get_pool_mode(buf, ARRAY_SIZE(buf)) >= ARRAY_SIZE(buf))
2192+
return -ERANGE;
2193+
2194+
skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL);
2195+
if (!skb)
2196+
return -ENOMEM;
2197+
2198+
err = -EMSGSIZE;
2199+
hdr = genlmsg_iput(skb, info);
2200+
if (!hdr)
2201+
goto err_free_msg;
2202+
2203+
err = nla_put_string(skb, NFSD_A_POOL_MODE_MODE, buf) |
2204+
nla_put_u32(skb, NFSD_A_POOL_MODE_NPOOLS, nfsd_nrpools(net));
2205+
if (err)
2206+
goto err_free_msg;
2207+
2208+
genlmsg_end(skb, hdr);
2209+
return genlmsg_reply(skb, info);
2210+
2211+
err_free_msg:
2212+
nlmsg_free(skb);
2213+
return err;
2214+
}
2215+
21592216
/**
21602217
* nfsd_net_init - Prepare the nfsd_net portion of a new net namespace
21612218
* @net: a freshly-created network namespace

include/uapi/linux/nfsd_netlink.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ enum {
7070
NFSD_A_SERVER_SOCK_MAX = (__NFSD_A_SERVER_SOCK_MAX - 1)
7171
};
7272

73+
enum {
74+
NFSD_A_POOL_MODE_MODE = 1,
75+
NFSD_A_POOL_MODE_NPOOLS,
76+
77+
__NFSD_A_POOL_MODE_MAX,
78+
NFSD_A_POOL_MODE_MAX = (__NFSD_A_POOL_MODE_MAX - 1)
79+
};
80+
7381
enum {
7482
NFSD_CMD_RPC_STATUS_GET = 1,
7583
NFSD_CMD_THREADS_SET,
@@ -78,6 +86,8 @@ enum {
7886
NFSD_CMD_VERSION_GET,
7987
NFSD_CMD_LISTENER_SET,
8088
NFSD_CMD_LISTENER_GET,
89+
NFSD_CMD_POOL_MODE_SET,
90+
NFSD_CMD_POOL_MODE_GET,
8191

8292
__NFSD_CMD_MAX,
8393
NFSD_CMD_MAX = (__NFSD_CMD_MAX - 1)

0 commit comments

Comments
 (0)