]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
1da177e4 LT |
2 | /* |
3 | * linux/fs/lockd/mon.c | |
4 | * | |
5 | * The kernel statd client. | |
6 | * | |
7 | * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de> | |
8 | */ | |
9 | ||
10 | #include <linux/types.h> | |
1da177e4 | 11 | #include <linux/kernel.h> |
94da7663 | 12 | #include <linux/ktime.h> |
5a0e3ad6 | 13 | #include <linux/slab.h> |
94da7663 | 14 | |
1da177e4 | 15 | #include <linux/sunrpc/clnt.h> |
5976687a | 16 | #include <linux/sunrpc/addr.h> |
0896a725 | 17 | #include <linux/sunrpc/xprtsock.h> |
1da177e4 LT |
18 | #include <linux/sunrpc/svc.h> |
19 | #include <linux/lockd/lockd.h> | |
1da177e4 | 20 | |
ad5b365c MR |
21 | #include <asm/unaligned.h> |
22 | ||
e9406db2 SK |
23 | #include "netns.h" |
24 | ||
1da177e4 | 25 | #define NLMDBG_FACILITY NLMDBG_MONITOR |
36e8e668 CL |
26 | #define NSM_PROGRAM 100024 |
27 | #define NSM_VERSION 1 | |
28 | ||
29 | enum { | |
30 | NSMPROC_NULL, | |
31 | NSMPROC_STAT, | |
32 | NSMPROC_MON, | |
33 | NSMPROC_UNMON, | |
34 | NSMPROC_UNMON_ALL, | |
35 | NSMPROC_SIMU_CRASH, | |
36 | NSMPROC_NOTIFY, | |
37 | }; | |
1da177e4 | 38 | |
9c1bfd03 | 39 | struct nsm_args { |
cab2d3c9 | 40 | struct nsm_private *priv; |
9c1bfd03 CL |
41 | u32 prog; /* RPC callback info */ |
42 | u32 vers; | |
43 | u32 proc; | |
44 | ||
45 | char *mon_name; | |
0d0f4aab | 46 | const char *nodename; |
9c1bfd03 CL |
47 | }; |
48 | ||
49 | struct nsm_res { | |
50 | u32 status; | |
51 | u32 state; | |
52 | }; | |
53 | ||
a613fa16 | 54 | static const struct rpc_program nsm_program; |
67c6d107 | 55 | static DEFINE_SPINLOCK(nsm_lock); |
1da177e4 LT |
56 | |
57 | /* | |
58 | * Local NSM state | |
59 | */ | |
6c9dc425 | 60 | u32 __read_mostly nsm_local_state; |
90ab5ee9 | 61 | bool __read_mostly nsm_use_hostnames; |
1da177e4 | 62 | |
8529bc51 CL |
63 | static inline struct sockaddr *nsm_addr(const struct nsm_handle *nsm) |
64 | { | |
65 | return (struct sockaddr *)&nsm->sm_addr; | |
66 | } | |
67 | ||
03a9a42a | 68 | static struct rpc_clnt *nsm_create(struct net *net, const char *nodename) |
49b5699b CL |
69 | { |
70 | struct sockaddr_in sin = { | |
71 | .sin_family = AF_INET, | |
72 | .sin_addr.s_addr = htonl(INADDR_LOOPBACK), | |
73 | }; | |
74 | struct rpc_create_args args = { | |
0e1cb5c0 | 75 | .net = net, |
e9406db2 | 76 | .protocol = XPRT_TRANSPORT_TCP, |
49b5699b CL |
77 | .address = (struct sockaddr *)&sin, |
78 | .addrsize = sizeof(sin), | |
79 | .servername = "rpc.statd", | |
03a9a42a | 80 | .nodename = nodename, |
49b5699b CL |
81 | .program = &nsm_program, |
82 | .version = NSM_VERSION, | |
83 | .authflavor = RPC_AUTH_NULL, | |
0e5c2632 | 84 | .flags = RPC_CLNT_CREATE_NOPING, |
49b5699b CL |
85 | }; |
86 | ||
87 | return rpc_create(&args); | |
88 | } | |
89 | ||
0e1cb5c0 | 90 | static int nsm_mon_unmon(struct nsm_handle *nsm, u32 proc, struct nsm_res *res, |
0d0f4aab | 91 | const struct nlm_host *host) |
1da177e4 | 92 | { |
1da177e4 | 93 | int status; |
0d0f4aab | 94 | struct rpc_clnt *clnt; |
a4846750 | 95 | struct nsm_args args = { |
cab2d3c9 | 96 | .priv = &nsm->sm_priv, |
a4846750 CL |
97 | .prog = NLM_PROGRAM, |
98 | .vers = 3, | |
99 | .proc = NLMPROC_NSM_NOTIFY, | |
29ed1407 | 100 | .mon_name = nsm->sm_mon_name, |
0d0f4aab | 101 | .nodename = host->nodename, |
a4846750 | 102 | }; |
dead28da CL |
103 | struct rpc_message msg = { |
104 | .rpc_argp = &args, | |
105 | .rpc_resp = res, | |
106 | }; | |
1da177e4 | 107 | |
1da177e4 LT |
108 | memset(res, 0, sizeof(*res)); |
109 | ||
0d0f4aab AR |
110 | clnt = nsm_create(host->net, host->nodename); |
111 | if (IS_ERR(clnt)) { | |
112 | dprintk("lockd: failed to create NSM upcall transport, " | |
113 | "status=%ld, net=%p\n", PTR_ERR(clnt), host->net); | |
114 | return PTR_ERR(clnt); | |
115 | } | |
116 | ||
dead28da | 117 | msg.rpc_proc = &clnt->cl_procinfo[proc]; |
e9406db2 | 118 | status = rpc_call_sync(clnt, &msg, RPC_TASK_SOFTCONN); |
173b3afc BC |
119 | if (status == -ECONNREFUSED) { |
120 | dprintk("lockd: NSM upcall RPC failed, status=%d, forcing rebind\n", | |
121 | status); | |
122 | rpc_force_rebind(clnt); | |
123 | status = rpc_call_sync(clnt, &msg, RPC_TASK_SOFTCONN); | |
124 | } | |
1da177e4 | 125 | if (status < 0) |
5acf4315 CL |
126 | dprintk("lockd: NSM upcall RPC failed, status=%d\n", |
127 | status); | |
1da177e4 LT |
128 | else |
129 | status = 0; | |
0d0f4aab AR |
130 | |
131 | rpc_shutdown_client(clnt); | |
1da177e4 LT |
132 | return status; |
133 | } | |
134 | ||
1e49323c CL |
135 | /** |
136 | * nsm_monitor - Notify a peer in case we reboot | |
137 | * @host: pointer to nlm_host of peer to notify | |
138 | * | |
139 | * If this peer is not already monitored, this function sends an | |
140 | * upcall to the local rpc.statd to record the name/address of | |
141 | * the peer to notify in case we reboot. | |
142 | * | |
143 | * Returns zero if the peer is monitored by the local rpc.statd; | |
144 | * otherwise a negative errno value is returned. | |
1da177e4 | 145 | */ |
1e49323c | 146 | int nsm_monitor(const struct nlm_host *host) |
1da177e4 | 147 | { |
8dead0db | 148 | struct nsm_handle *nsm = host->h_nsmhandle; |
1da177e4 LT |
149 | struct nsm_res res; |
150 | int status; | |
151 | ||
9fee4902 | 152 | dprintk("lockd: nsm_monitor(%s)\n", nsm->sm_name); |
8dead0db OK |
153 | |
154 | if (nsm->sm_monitored) | |
977faf39 | 155 | return 0; |
1da177e4 | 156 | |
29ed1407 CL |
157 | /* |
158 | * Choose whether to record the caller_name or IP address of | |
159 | * this peer in the local rpc.statd's database. | |
160 | */ | |
161 | nsm->sm_mon_name = nsm_use_hostnames ? nsm->sm_name : nsm->sm_addrbuf; | |
162 | ||
0d0f4aab | 163 | status = nsm_mon_unmon(nsm, NSMPROC_MON, &res, host); |
6c9dc425 | 164 | if (unlikely(res.status != 0)) |
5d254b11 | 165 | status = -EIO; |
6c9dc425 | 166 | if (unlikely(status < 0)) { |
9af94fc4 | 167 | pr_notice_ratelimited("lockd: cannot monitor %s\n", nsm->sm_name); |
6c9dc425 CL |
168 | return status; |
169 | } | |
170 | ||
171 | nsm->sm_monitored = 1; | |
172 | if (unlikely(nsm_local_state != res.state)) { | |
173 | nsm_local_state = res.state; | |
174 | dprintk("lockd: NSM state changed to %d\n", nsm_local_state); | |
175 | } | |
176 | return 0; | |
1da177e4 LT |
177 | } |
178 | ||
356c3eb4 CL |
179 | /** |
180 | * nsm_unmonitor - Unregister peer notification | |
181 | * @host: pointer to nlm_host of peer to stop monitoring | |
182 | * | |
183 | * If this peer is monitored, this function sends an upcall to | |
184 | * tell the local rpc.statd not to send this peer a notification | |
185 | * when we reboot. | |
1da177e4 | 186 | */ |
356c3eb4 | 187 | void nsm_unmonitor(const struct nlm_host *host) |
1da177e4 | 188 | { |
8dead0db | 189 | struct nsm_handle *nsm = host->h_nsmhandle; |
1da177e4 | 190 | struct nsm_res res; |
356c3eb4 | 191 | int status; |
1da177e4 | 192 | |
9502c522 OK |
193 | if (atomic_read(&nsm->sm_count) == 1 |
194 | && nsm->sm_monitored && !nsm->sm_sticky) { | |
9fee4902 | 195 | dprintk("lockd: nsm_unmonitor(%s)\n", nsm->sm_name); |
9502c522 | 196 | |
0d0f4aab | 197 | status = nsm_mon_unmon(nsm, NSMPROC_UNMON, &res, host); |
0c7aef45 CL |
198 | if (res.status != 0) |
199 | status = -EIO; | |
977faf39 | 200 | if (status < 0) |
9502c522 | 201 | printk(KERN_NOTICE "lockd: cannot unmonitor %s\n", |
9fee4902 | 202 | nsm->sm_name); |
9502c522 OK |
203 | else |
204 | nsm->sm_monitored = 0; | |
977faf39 | 205 | } |
1da177e4 LT |
206 | } |
207 | ||
0ad95472 AR |
208 | static struct nsm_handle *nsm_lookup_hostname(const struct list_head *nsm_handles, |
209 | const char *hostname, const size_t len) | |
3420a8c4 CL |
210 | { |
211 | struct nsm_handle *nsm; | |
212 | ||
0ad95472 | 213 | list_for_each_entry(nsm, nsm_handles, sm_link) |
3420a8c4 CL |
214 | if (strlen(nsm->sm_name) == len && |
215 | memcmp(nsm->sm_name, hostname, len) == 0) | |
216 | return nsm; | |
217 | return NULL; | |
218 | } | |
219 | ||
0ad95472 AR |
220 | static struct nsm_handle *nsm_lookup_addr(const struct list_head *nsm_handles, |
221 | const struct sockaddr *sap) | |
77a3ef33 CL |
222 | { |
223 | struct nsm_handle *nsm; | |
224 | ||
0ad95472 | 225 | list_for_each_entry(nsm, nsm_handles, sm_link) |
4516fc04 | 226 | if (rpc_cmp_addr(nsm_addr(nsm), sap)) |
77a3ef33 CL |
227 | return nsm; |
228 | return NULL; | |
229 | } | |
230 | ||
0ad95472 AR |
231 | static struct nsm_handle *nsm_lookup_priv(const struct list_head *nsm_handles, |
232 | const struct nsm_private *priv) | |
3420a8c4 CL |
233 | { |
234 | struct nsm_handle *nsm; | |
235 | ||
0ad95472 | 236 | list_for_each_entry(nsm, nsm_handles, sm_link) |
3420a8c4 CL |
237 | if (memcmp(nsm->sm_priv.data, priv->data, |
238 | sizeof(priv->data)) == 0) | |
239 | return nsm; | |
240 | return NULL; | |
241 | } | |
242 | ||
7e44d3be CL |
243 | /* |
244 | * Construct a unique cookie to match this nsm_handle to this monitored | |
245 | * host. It is passed to the local rpc.statd via NSMPROC_MON, and | |
246 | * returned via NLMPROC_SM_NOTIFY, in the "priv" field of these | |
247 | * requests. | |
248 | * | |
94da7663 CL |
249 | * The NSM protocol requires that these cookies be unique while the |
250 | * system is running. We prefer a stronger requirement of making them | |
251 | * unique across reboots. If user space bugs cause a stale cookie to | |
252 | * be sent to the kernel, it could cause the wrong host to lose its | |
253 | * lock state if cookies were not unique across reboots. | |
254 | * | |
255 | * The cookies are exposed only to local user space via loopback. They | |
256 | * do not appear on the physical network. If we want greater security | |
257 | * for some reason, nsm_init_private() could perform a one-way hash to | |
258 | * obscure the contents of the cookie. | |
7e44d3be CL |
259 | */ |
260 | static void nsm_init_private(struct nsm_handle *nsm) | |
261 | { | |
94da7663 | 262 | u64 *p = (u64 *)&nsm->sm_priv.data; |
ad5b365c | 263 | s64 ns; |
94da7663 | 264 | |
5eaaed4f | 265 | ns = ktime_get_ns(); |
ad5b365c MR |
266 | put_unaligned(ns, p); |
267 | put_unaligned((unsigned long)nsm, p + 1); | |
7e44d3be CL |
268 | } |
269 | ||
b39b897c CL |
270 | static struct nsm_handle *nsm_create_handle(const struct sockaddr *sap, |
271 | const size_t salen, | |
272 | const char *hostname, | |
273 | const size_t hostname_len) | |
274 | { | |
275 | struct nsm_handle *new; | |
276 | ||
277 | new = kzalloc(sizeof(*new) + hostname_len + 1, GFP_KERNEL); | |
278 | if (unlikely(new == NULL)) | |
279 | return NULL; | |
280 | ||
281 | atomic_set(&new->sm_count, 1); | |
282 | new->sm_name = (char *)(new + 1); | |
283 | memcpy(nsm_addr(new), sap, salen); | |
284 | new->sm_addrlen = salen; | |
285 | nsm_init_private(new); | |
c15128c5 CL |
286 | |
287 | if (rpc_ntop(nsm_addr(new), new->sm_addrbuf, | |
288 | sizeof(new->sm_addrbuf)) == 0) | |
289 | (void)snprintf(new->sm_addrbuf, sizeof(new->sm_addrbuf), | |
290 | "unsupported address family"); | |
b39b897c CL |
291 | memcpy(new->sm_name, hostname, hostname_len); |
292 | new->sm_name[hostname_len] = '\0'; | |
293 | ||
294 | return new; | |
295 | } | |
296 | ||
67c6d107 | 297 | /** |
92fd91b9 | 298 | * nsm_get_handle - Find or create a cached nsm_handle |
0ad95472 | 299 | * @net: network namespace |
67c6d107 CL |
300 | * @sap: pointer to socket address of handle to find |
301 | * @salen: length of socket address | |
302 | * @hostname: pointer to C string containing hostname to find | |
303 | * @hostname_len: length of C string | |
67c6d107 | 304 | * |
92fd91b9 | 305 | * Behavior is modulated by the global nsm_use_hostnames variable. |
67c6d107 | 306 | * |
92fd91b9 CL |
307 | * Returns a cached nsm_handle after bumping its ref count, or |
308 | * returns a fresh nsm_handle if a handle that matches @sap and/or | |
309 | * @hostname cannot be found in the handle cache. Returns NULL if | |
310 | * an error occurs. | |
67c6d107 | 311 | */ |
0ad95472 AR |
312 | struct nsm_handle *nsm_get_handle(const struct net *net, |
313 | const struct sockaddr *sap, | |
92fd91b9 CL |
314 | const size_t salen, const char *hostname, |
315 | const size_t hostname_len) | |
67c6d107 | 316 | { |
77a3ef33 | 317 | struct nsm_handle *cached, *new = NULL; |
0ad95472 | 318 | struct lockd_net *ln = net_generic(net, lockd_net_id); |
67c6d107 | 319 | |
67c6d107 CL |
320 | if (hostname && memchr(hostname, '/', hostname_len) != NULL) { |
321 | if (printk_ratelimit()) { | |
322 | printk(KERN_WARNING "Invalid hostname \"%.*s\" " | |
323 | "in NFS lock request\n", | |
324 | (int)hostname_len, hostname); | |
325 | } | |
326 | return NULL; | |
327 | } | |
328 | ||
329 | retry: | |
330 | spin_lock(&nsm_lock); | |
77a3ef33 CL |
331 | |
332 | if (nsm_use_hostnames && hostname != NULL) | |
0ad95472 AR |
333 | cached = nsm_lookup_hostname(&ln->nsm_handles, |
334 | hostname, hostname_len); | |
77a3ef33 | 335 | else |
0ad95472 | 336 | cached = nsm_lookup_addr(&ln->nsm_handles, sap); |
77a3ef33 CL |
337 | |
338 | if (cached != NULL) { | |
339 | atomic_inc(&cached->sm_count); | |
340 | spin_unlock(&nsm_lock); | |
341 | kfree(new); | |
342 | dprintk("lockd: found nsm_handle for %s (%s), " | |
343 | "cnt %d\n", cached->sm_name, | |
344 | cached->sm_addrbuf, | |
345 | atomic_read(&cached->sm_count)); | |
346 | return cached; | |
67c6d107 | 347 | } |
77a3ef33 CL |
348 | |
349 | if (new != NULL) { | |
0ad95472 | 350 | list_add(&new->sm_link, &ln->nsm_handles); |
77a3ef33 | 351 | spin_unlock(&nsm_lock); |
5cf1c4b1 | 352 | dprintk("lockd: created nsm_handle for %s (%s)\n", |
77a3ef33 CL |
353 | new->sm_name, new->sm_addrbuf); |
354 | return new; | |
67c6d107 | 355 | } |
77a3ef33 | 356 | |
67c6d107 CL |
357 | spin_unlock(&nsm_lock); |
358 | ||
77a3ef33 CL |
359 | new = nsm_create_handle(sap, salen, hostname, hostname_len); |
360 | if (unlikely(new == NULL)) | |
67c6d107 | 361 | return NULL; |
67c6d107 | 362 | goto retry; |
67c6d107 CL |
363 | } |
364 | ||
3420a8c4 CL |
365 | /** |
366 | * nsm_reboot_lookup - match NLMPROC_SM_NOTIFY arguments to an nsm_handle | |
0ad95472 | 367 | * @net: network namespace |
3420a8c4 CL |
368 | * @info: pointer to NLMPROC_SM_NOTIFY arguments |
369 | * | |
7e469af9 JL |
370 | * Returns a matching nsm_handle if found in the nsm cache. The returned |
371 | * nsm_handle's reference count is bumped. Otherwise returns NULL if some | |
372 | * error occurred. | |
3420a8c4 | 373 | */ |
0ad95472 AR |
374 | struct nsm_handle *nsm_reboot_lookup(const struct net *net, |
375 | const struct nlm_reboot *info) | |
3420a8c4 CL |
376 | { |
377 | struct nsm_handle *cached; | |
0ad95472 | 378 | struct lockd_net *ln = net_generic(net, lockd_net_id); |
3420a8c4 CL |
379 | |
380 | spin_lock(&nsm_lock); | |
381 | ||
0ad95472 | 382 | cached = nsm_lookup_priv(&ln->nsm_handles, &info->priv); |
3420a8c4 CL |
383 | if (unlikely(cached == NULL)) { |
384 | spin_unlock(&nsm_lock); | |
385 | dprintk("lockd: never saw rebooted peer '%.*s' before\n", | |
386 | info->len, info->mon); | |
387 | return cached; | |
388 | } | |
389 | ||
390 | atomic_inc(&cached->sm_count); | |
391 | spin_unlock(&nsm_lock); | |
392 | ||
3420a8c4 CL |
393 | dprintk("lockd: host %s (%s) rebooted, cnt %d\n", |
394 | cached->sm_name, cached->sm_addrbuf, | |
395 | atomic_read(&cached->sm_count)); | |
396 | return cached; | |
397 | } | |
398 | ||
67c6d107 CL |
399 | /** |
400 | * nsm_release - Release an NSM handle | |
401 | * @nsm: pointer to handle to be released | |
402 | * | |
403 | */ | |
404 | void nsm_release(struct nsm_handle *nsm) | |
405 | { | |
67c6d107 CL |
406 | if (atomic_dec_and_lock(&nsm->sm_count, &nsm_lock)) { |
407 | list_del(&nsm->sm_link); | |
408 | spin_unlock(&nsm_lock); | |
5cf1c4b1 CL |
409 | dprintk("lockd: destroyed nsm_handle for %s (%s)\n", |
410 | nsm->sm_name, nsm->sm_addrbuf); | |
67c6d107 CL |
411 | kfree(nsm); |
412 | } | |
413 | } | |
414 | ||
1da177e4 LT |
415 | /* |
416 | * XDR functions for NSM. | |
2ca7754d CL |
417 | * |
418 | * See http://www.opengroup.org/ for details on the Network | |
419 | * Status Monitor wire protocol. | |
1da177e4 LT |
420 | */ |
421 | ||
49b17004 | 422 | static void encode_nsm_string(struct xdr_stream *xdr, const char *string) |
099bd05f | 423 | { |
03eb1dcb CL |
424 | const u32 len = strlen(string); |
425 | __be32 *p; | |
426 | ||
49b17004 | 427 | p = xdr_reserve_space(xdr, 4 + len); |
03eb1dcb | 428 | xdr_encode_opaque(p, string, len); |
099bd05f CL |
429 | } |
430 | ||
49695174 CL |
431 | /* |
432 | * "mon_name" specifies the host to be monitored. | |
49695174 | 433 | */ |
49b17004 | 434 | static void encode_mon_name(struct xdr_stream *xdr, const struct nsm_args *argp) |
49695174 | 435 | { |
49b17004 | 436 | encode_nsm_string(xdr, argp->mon_name); |
49695174 CL |
437 | } |
438 | ||
850c95fd CL |
439 | /* |
440 | * The "my_id" argument specifies the hostname and RPC procedure | |
441 | * to be called when the status manager receives notification | |
36e8e668 | 442 | * (via the NLMPROC_SM_NOTIFY call) that the state of host "mon_name" |
850c95fd CL |
443 | * has changed. |
444 | */ | |
49b17004 | 445 | static void encode_my_id(struct xdr_stream *xdr, const struct nsm_args *argp) |
850c95fd | 446 | { |
03eb1dcb CL |
447 | __be32 *p; |
448 | ||
303a7ce9 | 449 | encode_nsm_string(xdr, argp->nodename); |
49b17004 CL |
450 | p = xdr_reserve_space(xdr, 4 + 4 + 4); |
451 | *p++ = cpu_to_be32(argp->prog); | |
452 | *p++ = cpu_to_be32(argp->vers); | |
453 | *p = cpu_to_be32(argp->proc); | |
850c95fd CL |
454 | } |
455 | ||
ea72a7f1 CL |
456 | /* |
457 | * The "mon_id" argument specifies the non-private arguments | |
36e8e668 | 458 | * of an NSMPROC_MON or NSMPROC_UNMON call. |
ea72a7f1 | 459 | */ |
49b17004 | 460 | static void encode_mon_id(struct xdr_stream *xdr, const struct nsm_args *argp) |
ea72a7f1 | 461 | { |
49b17004 CL |
462 | encode_mon_name(xdr, argp); |
463 | encode_my_id(xdr, argp); | |
ea72a7f1 CL |
464 | } |
465 | ||
0490a54a CL |
466 | /* |
467 | * The "priv" argument may contain private information required | |
36e8e668 CL |
468 | * by the NSMPROC_MON call. This information will be supplied in the |
469 | * NLMPROC_SM_NOTIFY call. | |
0490a54a | 470 | */ |
49b17004 | 471 | static void encode_priv(struct xdr_stream *xdr, const struct nsm_args *argp) |
0490a54a | 472 | { |
03eb1dcb CL |
473 | __be32 *p; |
474 | ||
475 | p = xdr_reserve_space(xdr, SM_PRIV_SIZE); | |
cab2d3c9 | 476 | xdr_encode_opaque_fixed(p, argp->priv->data, SM_PRIV_SIZE); |
0490a54a CL |
477 | } |
478 | ||
9f06c719 | 479 | static void nsm_xdr_enc_mon(struct rpc_rqst *req, struct xdr_stream *xdr, |
bf96391e | 480 | const void *argp) |
1da177e4 | 481 | { |
9f06c719 CL |
482 | encode_mon_id(xdr, argp); |
483 | encode_priv(xdr, argp); | |
1da177e4 LT |
484 | } |
485 | ||
9f06c719 | 486 | static void nsm_xdr_enc_unmon(struct rpc_rqst *req, struct xdr_stream *xdr, |
bf96391e | 487 | const void *argp) |
1da177e4 | 488 | { |
9f06c719 | 489 | encode_mon_id(xdr, argp); |
1da177e4 LT |
490 | } |
491 | ||
bf269551 CL |
492 | static int nsm_xdr_dec_stat_res(struct rpc_rqst *rqstp, |
493 | struct xdr_stream *xdr, | |
1fa23391 | 494 | void *data) |
1da177e4 | 495 | { |
1fa23391 | 496 | struct nsm_res *resp = data; |
bf269551 | 497 | __be32 *p; |
03eb1dcb | 498 | |
bf269551 | 499 | p = xdr_inline_decode(xdr, 4 + 4); |
03eb1dcb CL |
500 | if (unlikely(p == NULL)) |
501 | return -EIO; | |
49b17004 CL |
502 | resp->status = be32_to_cpup(p++); |
503 | resp->state = be32_to_cpup(p); | |
03eb1dcb | 504 | |
bf269551 CL |
505 | dprintk("lockd: %s status %d state %d\n", |
506 | __func__, resp->status, resp->state); | |
1da177e4 LT |
507 | return 0; |
508 | } | |
509 | ||
bf269551 CL |
510 | static int nsm_xdr_dec_stat(struct rpc_rqst *rqstp, |
511 | struct xdr_stream *xdr, | |
1fa23391 | 512 | void *data) |
1da177e4 | 513 | { |
1fa23391 | 514 | struct nsm_res *resp = data; |
bf269551 | 515 | __be32 *p; |
03eb1dcb | 516 | |
bf269551 | 517 | p = xdr_inline_decode(xdr, 4); |
03eb1dcb CL |
518 | if (unlikely(p == NULL)) |
519 | return -EIO; | |
49b17004 | 520 | resp->state = be32_to_cpup(p); |
03eb1dcb | 521 | |
bf269551 | 522 | dprintk("lockd: %s state %d\n", __func__, resp->state); |
1da177e4 LT |
523 | return 0; |
524 | } | |
525 | ||
526 | #define SM_my_name_sz (1+XDR_QUADLEN(SM_MAXSTRLEN)) | |
2ca7754d CL |
527 | #define SM_my_id_sz (SM_my_name_sz+3) |
528 | #define SM_mon_name_sz (1+XDR_QUADLEN(SM_MAXSTRLEN)) | |
529 | #define SM_mon_id_sz (SM_mon_name_sz+SM_my_id_sz) | |
0490a54a CL |
530 | #define SM_priv_sz (XDR_QUADLEN(SM_PRIV_SIZE)) |
531 | #define SM_mon_sz (SM_mon_id_sz+SM_priv_sz) | |
1da177e4 LT |
532 | #define SM_monres_sz 2 |
533 | #define SM_unmonres_sz 1 | |
534 | ||
499b4988 | 535 | static const struct rpc_procinfo nsm_procedures[] = { |
36e8e668 CL |
536 | [NSMPROC_MON] = { |
537 | .p_proc = NSMPROC_MON, | |
bf96391e | 538 | .p_encode = nsm_xdr_enc_mon, |
1fa23391 | 539 | .p_decode = nsm_xdr_dec_stat_res, |
2bea90d4 CL |
540 | .p_arglen = SM_mon_sz, |
541 | .p_replen = SM_monres_sz, | |
36e8e668 | 542 | .p_statidx = NSMPROC_MON, |
cc0175c1 | 543 | .p_name = "MONITOR", |
1da177e4 | 544 | }, |
36e8e668 CL |
545 | [NSMPROC_UNMON] = { |
546 | .p_proc = NSMPROC_UNMON, | |
bf96391e | 547 | .p_encode = nsm_xdr_enc_unmon, |
1fa23391 | 548 | .p_decode = nsm_xdr_dec_stat, |
2bea90d4 CL |
549 | .p_arglen = SM_mon_id_sz, |
550 | .p_replen = SM_unmonres_sz, | |
36e8e668 | 551 | .p_statidx = NSMPROC_UNMON, |
cc0175c1 | 552 | .p_name = "UNMONITOR", |
1da177e4 LT |
553 | }, |
554 | }; | |
555 | ||
1c5876dd | 556 | static unsigned int nsm_version1_counts[ARRAY_SIZE(nsm_procedures)]; |
a613fa16 | 557 | static const struct rpc_version nsm_version1 = { |
cdfa31e9 CH |
558 | .number = 1, |
559 | .nrprocs = ARRAY_SIZE(nsm_procedures), | |
1c5876dd CH |
560 | .procs = nsm_procedures, |
561 | .counts = nsm_version1_counts, | |
1da177e4 LT |
562 | }; |
563 | ||
a613fa16 | 564 | static const struct rpc_version *nsm_version[] = { |
1da177e4 LT |
565 | [1] = &nsm_version1, |
566 | }; | |
567 | ||
568 | static struct rpc_stat nsm_stats; | |
569 | ||
a613fa16 | 570 | static const struct rpc_program nsm_program = { |
cdfa31e9 CH |
571 | .name = "statd", |
572 | .number = NSM_PROGRAM, | |
573 | .nrvers = ARRAY_SIZE(nsm_version), | |
574 | .version = nsm_version, | |
575 | .stats = &nsm_stats | |
1da177e4 | 576 | }; |