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