]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
1da177e4 LT |
2 | /* |
3 | * linux/fs/lockd/svcproc.c | |
4 | * | |
5 | * Lockd server procedures. We don't implement the NLM_*_RES | |
6 | * procedures because we don't use the async procedures. | |
7 | * | |
8 | * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de> | |
9 | */ | |
10 | ||
1da177e4 LT |
11 | #include <linux/types.h> |
12 | #include <linux/time.h> | |
1da177e4 LT |
13 | #include <linux/lockd/lockd.h> |
14 | #include <linux/lockd/share.h> | |
5ccb0066 | 15 | #include <linux/sunrpc/svc_xprt.h> |
1da177e4 LT |
16 | |
17 | #define NLMDBG_FACILITY NLMDBG_CLIENT | |
18 | ||
1da177e4 | 19 | #ifdef CONFIG_LOCKD_V4 |
52921e02 AV |
20 | static __be32 |
21 | cast_to_nlm(__be32 status, u32 vers) | |
1da177e4 LT |
22 | { |
23 | /* Note: status is assumed to be in network byte order !!! */ | |
24 | if (vers != 4){ | |
25 | switch (status) { | |
26 | case nlm_granted: | |
27 | case nlm_lck_denied: | |
28 | case nlm_lck_denied_nolocks: | |
29 | case nlm_lck_blocked: | |
30 | case nlm_lck_denied_grace_period: | |
5ea0d750 | 31 | case nlm_drop_reply: |
1da177e4 LT |
32 | break; |
33 | case nlm4_deadlock: | |
34 | status = nlm_lck_denied; | |
35 | break; | |
36 | default: | |
37 | status = nlm_lck_denied_nolocks; | |
38 | } | |
39 | } | |
40 | ||
41 | return (status); | |
42 | } | |
43 | #define cast_status(status) (cast_to_nlm(status, rqstp->rq_vers)) | |
44 | #else | |
45 | #define cast_status(status) (status) | |
46 | #endif | |
47 | ||
48 | /* | |
49 | * Obtain client and file from arguments | |
50 | */ | |
52921e02 | 51 | static __be32 |
1da177e4 LT |
52 | nlmsvc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp, |
53 | struct nlm_host **hostp, struct nlm_file **filp) | |
54 | { | |
55 | struct nlm_host *host = NULL; | |
56 | struct nlm_file *file = NULL; | |
57 | struct nlm_lock *lock = &argp->lock; | |
7f024fcd | 58 | int mode; |
52921e02 | 59 | __be32 error = 0; |
1da177e4 LT |
60 | |
61 | /* nfsd callbacks must have been installed for this procedure */ | |
62 | if (!nlmsvc_ops) | |
63 | return nlm_lck_denied_nolocks; | |
64 | ||
65 | /* Obtain host handle */ | |
db4e4c9a | 66 | if (!(host = nlmsvc_lookup_host(rqstp, lock->caller, lock->len)) |
977faf39 | 67 | || (argp->monitor && nsm_monitor(host) < 0)) |
1da177e4 LT |
68 | goto no_locks; |
69 | *hostp = host; | |
70 | ||
71 | /* Obtain file pointer. Not used by FREE_ALL call. */ | |
72 | if (filp != NULL) { | |
2dc6f19e | 73 | error = cast_status(nlm_lookup_file(rqstp, &file, lock)); |
cd0b16c1 | 74 | if (error != 0) |
1da177e4 LT |
75 | goto no_locks; |
76 | *filp = file; | |
77 | ||
78 | /* Set up the missing parts of the file_lock structure */ | |
7f024fcd BF |
79 | mode = lock_to_openmode(&lock->fl); |
80 | lock->fl.fl_file = file->f_file[mode]; | |
646d73e9 | 81 | lock->fl.fl_pid = current->tgid; |
1da177e4 | 82 | lock->fl.fl_lmops = &nlmsvc_lock_operations; |
89e0edfb BC |
83 | nlmsvc_locks_init_private(&lock->fl, host, (pid_t)lock->svid); |
84 | if (!lock->fl.fl_owner) { | |
85 | /* lockowner allocation has failed */ | |
86 | nlmsvc_release_host(host); | |
87 | return nlm_lck_denied_nolocks; | |
88 | } | |
1da177e4 LT |
89 | } |
90 | ||
91 | return 0; | |
92 | ||
93 | no_locks: | |
67216b94 | 94 | nlmsvc_release_host(host); |
d343fce1 N |
95 | if (error) |
96 | return error; | |
1da177e4 LT |
97 | return nlm_lck_denied_nolocks; |
98 | } | |
99 | ||
100 | /* | |
101 | * NULL: Test for presence of service | |
102 | */ | |
7111c66e | 103 | static __be32 |
a6beb732 | 104 | nlmsvc_proc_null(struct svc_rqst *rqstp) |
1da177e4 LT |
105 | { |
106 | dprintk("lockd: NULL called\n"); | |
107 | return rpc_success; | |
108 | } | |
109 | ||
110 | /* | |
111 | * TEST: Check for conflicting lock | |
112 | */ | |
7111c66e | 113 | static __be32 |
a6beb732 | 114 | __nlmsvc_proc_test(struct svc_rqst *rqstp, struct nlm_res *resp) |
1da177e4 | 115 | { |
a6beb732 | 116 | struct nlm_args *argp = rqstp->rq_argp; |
1da177e4 LT |
117 | struct nlm_host *host; |
118 | struct nlm_file *file; | |
184cefbe | 119 | struct nlm_lockowner *test_owner; |
317602f3 | 120 | __be32 rc = rpc_success; |
1da177e4 LT |
121 | |
122 | dprintk("lockd: TEST called\n"); | |
123 | resp->cookie = argp->cookie; | |
124 | ||
1da177e4 LT |
125 | /* Obtain client and file */ |
126 | if ((resp->status = nlmsvc_retrieve_args(rqstp, argp, &host, &file))) | |
d343fce1 | 127 | return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; |
1da177e4 | 128 | |
184cefbe BC |
129 | test_owner = argp->lock.fl.fl_owner; |
130 | ||
1da177e4 | 131 | /* Now check for conflicting locks */ |
8f920d5e | 132 | resp->status = cast_status(nlmsvc_testlock(rqstp, file, host, &argp->lock, &resp->lock, &resp->cookie)); |
5ea0d750 | 133 | if (resp->status == nlm_drop_reply) |
b7e6b869 OD |
134 | rc = rpc_drop_reply; |
135 | else | |
136 | dprintk("lockd: TEST status %d vers %d\n", | |
137 | ntohl(resp->status), rqstp->rq_vers); | |
1da177e4 | 138 | |
184cefbe | 139 | nlmsvc_put_lockowner(test_owner); |
67216b94 | 140 | nlmsvc_release_host(host); |
1da177e4 | 141 | nlm_release_file(file); |
b7e6b869 | 142 | return rc; |
1da177e4 LT |
143 | } |
144 | ||
7111c66e | 145 | static __be32 |
a6beb732 | 146 | nlmsvc_proc_test(struct svc_rqst *rqstp) |
1da177e4 | 147 | { |
a6beb732 CH |
148 | return __nlmsvc_proc_test(rqstp, rqstp->rq_resp); |
149 | } | |
150 | ||
151 | static __be32 | |
152 | __nlmsvc_proc_lock(struct svc_rqst *rqstp, struct nlm_res *resp) | |
153 | { | |
154 | struct nlm_args *argp = rqstp->rq_argp; | |
1da177e4 LT |
155 | struct nlm_host *host; |
156 | struct nlm_file *file; | |
317602f3 | 157 | __be32 rc = rpc_success; |
1da177e4 LT |
158 | |
159 | dprintk("lockd: LOCK called\n"); | |
160 | ||
161 | resp->cookie = argp->cookie; | |
162 | ||
1da177e4 LT |
163 | /* Obtain client and file */ |
164 | if ((resp->status = nlmsvc_retrieve_args(rqstp, argp, &host, &file))) | |
d343fce1 | 165 | return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; |
1da177e4 LT |
166 | |
167 | #if 0 | |
168 | /* If supplied state doesn't match current state, we assume it's | |
169 | * an old request that time-warped somehow. Any error return would | |
170 | * do in this case because it's irrelevant anyway. | |
171 | * | |
172 | * NB: We don't retrieve the remote host's state yet. | |
173 | */ | |
174 | if (host->h_nsmstate && host->h_nsmstate != argp->state) { | |
175 | resp->status = nlm_lck_denied_nolocks; | |
176 | } else | |
177 | #endif | |
178 | ||
179 | /* Now try to lock the file */ | |
6cde4de8 | 180 | resp->status = cast_status(nlmsvc_lock(rqstp, file, host, &argp->lock, |
b2b50289 BF |
181 | argp->block, &argp->cookie, |
182 | argp->reclaim)); | |
1a8322b2 | 183 | if (resp->status == nlm_drop_reply) |
b7e6b869 OD |
184 | rc = rpc_drop_reply; |
185 | else | |
186 | dprintk("lockd: LOCK status %d\n", ntohl(resp->status)); | |
1da177e4 | 187 | |
89e0edfb | 188 | nlmsvc_release_lockowner(&argp->lock); |
67216b94 | 189 | nlmsvc_release_host(host); |
1da177e4 | 190 | nlm_release_file(file); |
b7e6b869 | 191 | return rc; |
1da177e4 LT |
192 | } |
193 | ||
7111c66e | 194 | static __be32 |
a6beb732 CH |
195 | nlmsvc_proc_lock(struct svc_rqst *rqstp) |
196 | { | |
197 | return __nlmsvc_proc_lock(rqstp, rqstp->rq_resp); | |
198 | } | |
199 | ||
200 | static __be32 | |
201 | __nlmsvc_proc_cancel(struct svc_rqst *rqstp, struct nlm_res *resp) | |
1da177e4 | 202 | { |
a6beb732 | 203 | struct nlm_args *argp = rqstp->rq_argp; |
1da177e4 LT |
204 | struct nlm_host *host; |
205 | struct nlm_file *file; | |
5ccb0066 | 206 | struct net *net = SVC_NET(rqstp); |
1da177e4 LT |
207 | |
208 | dprintk("lockd: CANCEL called\n"); | |
209 | ||
210 | resp->cookie = argp->cookie; | |
211 | ||
212 | /* Don't accept requests during grace period */ | |
5ccb0066 | 213 | if (locks_in_grace(net)) { |
1da177e4 LT |
214 | resp->status = nlm_lck_denied_grace_period; |
215 | return rpc_success; | |
216 | } | |
217 | ||
218 | /* Obtain client and file */ | |
219 | if ((resp->status = nlmsvc_retrieve_args(rqstp, argp, &host, &file))) | |
d343fce1 | 220 | return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; |
1da177e4 LT |
221 | |
222 | /* Try to cancel request. */ | |
5ccb0066 | 223 | resp->status = cast_status(nlmsvc_cancel_blocked(net, file, &argp->lock)); |
1da177e4 LT |
224 | |
225 | dprintk("lockd: CANCEL status %d\n", ntohl(resp->status)); | |
89e0edfb | 226 | nlmsvc_release_lockowner(&argp->lock); |
67216b94 | 227 | nlmsvc_release_host(host); |
1da177e4 LT |
228 | nlm_release_file(file); |
229 | return rpc_success; | |
230 | } | |
231 | ||
a6beb732 CH |
232 | static __be32 |
233 | nlmsvc_proc_cancel(struct svc_rqst *rqstp) | |
234 | { | |
235 | return __nlmsvc_proc_cancel(rqstp, rqstp->rq_resp); | |
236 | } | |
237 | ||
1da177e4 LT |
238 | /* |
239 | * UNLOCK: release a lock | |
240 | */ | |
7111c66e | 241 | static __be32 |
a6beb732 | 242 | __nlmsvc_proc_unlock(struct svc_rqst *rqstp, struct nlm_res *resp) |
1da177e4 | 243 | { |
a6beb732 | 244 | struct nlm_args *argp = rqstp->rq_argp; |
1da177e4 LT |
245 | struct nlm_host *host; |
246 | struct nlm_file *file; | |
5ccb0066 | 247 | struct net *net = SVC_NET(rqstp); |
1da177e4 LT |
248 | |
249 | dprintk("lockd: UNLOCK called\n"); | |
250 | ||
251 | resp->cookie = argp->cookie; | |
252 | ||
253 | /* Don't accept new lock requests during grace period */ | |
5ccb0066 | 254 | if (locks_in_grace(net)) { |
1da177e4 LT |
255 | resp->status = nlm_lck_denied_grace_period; |
256 | return rpc_success; | |
257 | } | |
258 | ||
259 | /* Obtain client and file */ | |
260 | if ((resp->status = nlmsvc_retrieve_args(rqstp, argp, &host, &file))) | |
d343fce1 | 261 | return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; |
1da177e4 LT |
262 | |
263 | /* Now try to remove the lock */ | |
5ccb0066 | 264 | resp->status = cast_status(nlmsvc_unlock(net, file, &argp->lock)); |
1da177e4 LT |
265 | |
266 | dprintk("lockd: UNLOCK status %d\n", ntohl(resp->status)); | |
89e0edfb | 267 | nlmsvc_release_lockowner(&argp->lock); |
67216b94 | 268 | nlmsvc_release_host(host); |
1da177e4 LT |
269 | nlm_release_file(file); |
270 | return rpc_success; | |
271 | } | |
272 | ||
a6beb732 CH |
273 | static __be32 |
274 | nlmsvc_proc_unlock(struct svc_rqst *rqstp) | |
275 | { | |
276 | return __nlmsvc_proc_unlock(rqstp, rqstp->rq_resp); | |
277 | } | |
278 | ||
1da177e4 LT |
279 | /* |
280 | * GRANTED: A server calls us to tell that a process' lock request | |
281 | * was granted | |
282 | */ | |
7111c66e | 283 | static __be32 |
a6beb732 | 284 | __nlmsvc_proc_granted(struct svc_rqst *rqstp, struct nlm_res *resp) |
1da177e4 | 285 | { |
a6beb732 CH |
286 | struct nlm_args *argp = rqstp->rq_argp; |
287 | ||
1da177e4 LT |
288 | resp->cookie = argp->cookie; |
289 | ||
290 | dprintk("lockd: GRANTED called\n"); | |
dcff09f1 | 291 | resp->status = nlmclnt_grant(svc_addr(rqstp), &argp->lock); |
1da177e4 LT |
292 | dprintk("lockd: GRANTED status %d\n", ntohl(resp->status)); |
293 | return rpc_success; | |
294 | } | |
295 | ||
a6beb732 CH |
296 | static __be32 |
297 | nlmsvc_proc_granted(struct svc_rqst *rqstp) | |
298 | { | |
299 | return __nlmsvc_proc_granted(rqstp, rqstp->rq_resp); | |
300 | } | |
301 | ||
d4716624 TM |
302 | /* |
303 | * This is the generic lockd callback for async RPC calls | |
304 | */ | |
305 | static void nlmsvc_callback_exit(struct rpc_task *task, void *data) | |
306 | { | |
d4716624 TM |
307 | } |
308 | ||
7db836d4 CL |
309 | void nlmsvc_release_call(struct nlm_rqst *call) |
310 | { | |
fbca30c5 | 311 | if (!refcount_dec_and_test(&call->a_count)) |
7db836d4 | 312 | return; |
67216b94 | 313 | nlmsvc_release_host(call->a_host); |
7db836d4 CL |
314 | kfree(call); |
315 | } | |
316 | ||
d4716624 TM |
317 | static void nlmsvc_callback_release(void *data) |
318 | { | |
7db836d4 | 319 | nlmsvc_release_call(data); |
d4716624 TM |
320 | } |
321 | ||
322 | static const struct rpc_call_ops nlmsvc_callback_ops = { | |
323 | .rpc_call_done = nlmsvc_callback_exit, | |
324 | .rpc_release = nlmsvc_callback_release, | |
325 | }; | |
326 | ||
1da177e4 LT |
327 | /* |
328 | * `Async' versions of the above service routines. They aren't really, | |
329 | * because we send the callback before the reply proper. I hope this | |
330 | * doesn't break any clients. | |
331 | */ | |
a6beb732 CH |
332 | static __be32 nlmsvc_callback(struct svc_rqst *rqstp, u32 proc, |
333 | __be32 (*func)(struct svc_rqst *, struct nlm_res *)) | |
1da177e4 | 334 | { |
a6beb732 | 335 | struct nlm_args *argp = rqstp->rq_argp; |
d4716624 TM |
336 | struct nlm_host *host; |
337 | struct nlm_rqst *call; | |
7111c66e | 338 | __be32 stat; |
1da177e4 | 339 | |
db4e4c9a OK |
340 | host = nlmsvc_lookup_host(rqstp, |
341 | argp->lock.caller, | |
342 | argp->lock.len); | |
d4716624 TM |
343 | if (host == NULL) |
344 | return rpc_system_err; | |
345 | ||
346 | call = nlm_alloc_call(host); | |
446945ab | 347 | nlmsvc_release_host(host); |
d4716624 TM |
348 | if (call == NULL) |
349 | return rpc_system_err; | |
350 | ||
a6beb732 | 351 | stat = func(rqstp, &call->a_res); |
d4716624 | 352 | if (stat != 0) { |
7db836d4 | 353 | nlmsvc_release_call(call); |
d4716624 TM |
354 | return stat; |
355 | } | |
1da177e4 | 356 | |
d4716624 TM |
357 | call->a_flags = RPC_TASK_ASYNC; |
358 | if (nlm_async_reply(call, proc, &nlmsvc_callback_ops) < 0) | |
359 | return rpc_system_err; | |
360 | return rpc_success; | |
1da177e4 LT |
361 | } |
362 | ||
a6beb732 | 363 | static __be32 nlmsvc_proc_test_msg(struct svc_rqst *rqstp) |
1da177e4 | 364 | { |
d4716624 | 365 | dprintk("lockd: TEST_MSG called\n"); |
a6beb732 | 366 | return nlmsvc_callback(rqstp, NLMPROC_TEST_RES, __nlmsvc_proc_test); |
d4716624 | 367 | } |
1da177e4 | 368 | |
a6beb732 | 369 | static __be32 nlmsvc_proc_lock_msg(struct svc_rqst *rqstp) |
d4716624 | 370 | { |
1da177e4 | 371 | dprintk("lockd: LOCK_MSG called\n"); |
a6beb732 | 372 | return nlmsvc_callback(rqstp, NLMPROC_LOCK_RES, __nlmsvc_proc_lock); |
1da177e4 LT |
373 | } |
374 | ||
a6beb732 | 375 | static __be32 nlmsvc_proc_cancel_msg(struct svc_rqst *rqstp) |
1da177e4 | 376 | { |
1da177e4 | 377 | dprintk("lockd: CANCEL_MSG called\n"); |
a6beb732 | 378 | return nlmsvc_callback(rqstp, NLMPROC_CANCEL_RES, __nlmsvc_proc_cancel); |
1da177e4 LT |
379 | } |
380 | ||
7111c66e | 381 | static __be32 |
a6beb732 | 382 | nlmsvc_proc_unlock_msg(struct svc_rqst *rqstp) |
1da177e4 | 383 | { |
1da177e4 | 384 | dprintk("lockd: UNLOCK_MSG called\n"); |
a6beb732 | 385 | return nlmsvc_callback(rqstp, NLMPROC_UNLOCK_RES, __nlmsvc_proc_unlock); |
1da177e4 LT |
386 | } |
387 | ||
7111c66e | 388 | static __be32 |
a6beb732 | 389 | nlmsvc_proc_granted_msg(struct svc_rqst *rqstp) |
1da177e4 | 390 | { |
1da177e4 | 391 | dprintk("lockd: GRANTED_MSG called\n"); |
a6beb732 | 392 | return nlmsvc_callback(rqstp, NLMPROC_GRANTED_RES, __nlmsvc_proc_granted); |
1da177e4 LT |
393 | } |
394 | ||
395 | /* | |
396 | * SHARE: create a DOS share or alter existing share. | |
397 | */ | |
7111c66e | 398 | static __be32 |
a6beb732 | 399 | nlmsvc_proc_share(struct svc_rqst *rqstp) |
1da177e4 | 400 | { |
a6beb732 CH |
401 | struct nlm_args *argp = rqstp->rq_argp; |
402 | struct nlm_res *resp = rqstp->rq_resp; | |
1da177e4 LT |
403 | struct nlm_host *host; |
404 | struct nlm_file *file; | |
405 | ||
406 | dprintk("lockd: SHARE called\n"); | |
407 | ||
408 | resp->cookie = argp->cookie; | |
409 | ||
410 | /* Don't accept new lock requests during grace period */ | |
5ccb0066 | 411 | if (locks_in_grace(SVC_NET(rqstp)) && !argp->reclaim) { |
1da177e4 LT |
412 | resp->status = nlm_lck_denied_grace_period; |
413 | return rpc_success; | |
414 | } | |
415 | ||
416 | /* Obtain client and file */ | |
417 | if ((resp->status = nlmsvc_retrieve_args(rqstp, argp, &host, &file))) | |
d343fce1 | 418 | return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; |
1da177e4 LT |
419 | |
420 | /* Now try to create the share */ | |
421 | resp->status = cast_status(nlmsvc_share_file(host, file, argp)); | |
422 | ||
423 | dprintk("lockd: SHARE status %d\n", ntohl(resp->status)); | |
89e0edfb | 424 | nlmsvc_release_lockowner(&argp->lock); |
67216b94 | 425 | nlmsvc_release_host(host); |
1da177e4 LT |
426 | nlm_release_file(file); |
427 | return rpc_success; | |
428 | } | |
429 | ||
430 | /* | |
431 | * UNSHARE: Release a DOS share. | |
432 | */ | |
7111c66e | 433 | static __be32 |
a6beb732 | 434 | nlmsvc_proc_unshare(struct svc_rqst *rqstp) |
1da177e4 | 435 | { |
a6beb732 CH |
436 | struct nlm_args *argp = rqstp->rq_argp; |
437 | struct nlm_res *resp = rqstp->rq_resp; | |
1da177e4 LT |
438 | struct nlm_host *host; |
439 | struct nlm_file *file; | |
440 | ||
441 | dprintk("lockd: UNSHARE called\n"); | |
442 | ||
443 | resp->cookie = argp->cookie; | |
444 | ||
445 | /* Don't accept requests during grace period */ | |
5ccb0066 | 446 | if (locks_in_grace(SVC_NET(rqstp))) { |
1da177e4 LT |
447 | resp->status = nlm_lck_denied_grace_period; |
448 | return rpc_success; | |
449 | } | |
450 | ||
451 | /* Obtain client and file */ | |
452 | if ((resp->status = nlmsvc_retrieve_args(rqstp, argp, &host, &file))) | |
d343fce1 | 453 | return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; |
1da177e4 LT |
454 | |
455 | /* Now try to unshare the file */ | |
456 | resp->status = cast_status(nlmsvc_unshare_file(host, file, argp)); | |
457 | ||
458 | dprintk("lockd: UNSHARE status %d\n", ntohl(resp->status)); | |
89e0edfb | 459 | nlmsvc_release_lockowner(&argp->lock); |
67216b94 | 460 | nlmsvc_release_host(host); |
1da177e4 LT |
461 | nlm_release_file(file); |
462 | return rpc_success; | |
463 | } | |
464 | ||
465 | /* | |
466 | * NM_LOCK: Create an unmonitored lock | |
467 | */ | |
7111c66e | 468 | static __be32 |
a6beb732 | 469 | nlmsvc_proc_nm_lock(struct svc_rqst *rqstp) |
1da177e4 | 470 | { |
a6beb732 CH |
471 | struct nlm_args *argp = rqstp->rq_argp; |
472 | ||
1da177e4 LT |
473 | dprintk("lockd: NM_LOCK called\n"); |
474 | ||
475 | argp->monitor = 0; /* just clean the monitor flag */ | |
a6beb732 | 476 | return nlmsvc_proc_lock(rqstp); |
1da177e4 LT |
477 | } |
478 | ||
479 | /* | |
480 | * FREE_ALL: Release all locks and shares held by client | |
481 | */ | |
7111c66e | 482 | static __be32 |
a6beb732 | 483 | nlmsvc_proc_free_all(struct svc_rqst *rqstp) |
1da177e4 | 484 | { |
a6beb732 | 485 | struct nlm_args *argp = rqstp->rq_argp; |
1da177e4 LT |
486 | struct nlm_host *host; |
487 | ||
488 | /* Obtain client */ | |
489 | if (nlmsvc_retrieve_args(rqstp, argp, &host, NULL)) | |
490 | return rpc_success; | |
491 | ||
492 | nlmsvc_free_host_resources(host); | |
67216b94 | 493 | nlmsvc_release_host(host); |
1da177e4 LT |
494 | return rpc_success; |
495 | } | |
496 | ||
497 | /* | |
498 | * SM_NOTIFY: private callback from statd (not part of official NLM proto) | |
499 | */ | |
7111c66e | 500 | static __be32 |
a6beb732 | 501 | nlmsvc_proc_sm_notify(struct svc_rqst *rqstp) |
1da177e4 | 502 | { |
a6beb732 CH |
503 | struct nlm_reboot *argp = rqstp->rq_argp; |
504 | ||
1da177e4 | 505 | dprintk("lockd: SM_NOTIFY called\n"); |
b85e4676 CL |
506 | |
507 | if (!nlm_privileged_requester(rqstp)) { | |
ad06e4bd CL |
508 | char buf[RPC_MAX_ADDRBUFLEN]; |
509 | printk(KERN_WARNING "lockd: rejected NSM callback from %s\n", | |
510 | svc_print_addr(rqstp, buf, sizeof(buf))); | |
1da177e4 LT |
511 | return rpc_system_err; |
512 | } | |
513 | ||
0ad95472 | 514 | nlm_host_rebooted(SVC_NET(rqstp), argp); |
1da177e4 LT |
515 | return rpc_success; |
516 | } | |
517 | ||
518 | /* | |
519 | * client sent a GRANTED_RES, let's remove the associated block | |
520 | */ | |
7111c66e | 521 | static __be32 |
a6beb732 | 522 | nlmsvc_proc_granted_res(struct svc_rqst *rqstp) |
1da177e4 | 523 | { |
a6beb732 CH |
524 | struct nlm_res *argp = rqstp->rq_argp; |
525 | ||
1da177e4 LT |
526 | if (!nlmsvc_ops) |
527 | return rpc_success; | |
528 | ||
529 | dprintk("lockd: GRANTED_RES called\n"); | |
530 | ||
39be4502 | 531 | nlmsvc_grant_reply(&argp->cookie, argp->status); |
1da177e4 LT |
532 | return rpc_success; |
533 | } | |
534 | ||
49d99608 CL |
535 | static __be32 |
536 | nlmsvc_proc_unused(struct svc_rqst *rqstp) | |
537 | { | |
538 | return rpc_proc_unavail; | |
539 | } | |
540 | ||
1da177e4 LT |
541 | /* |
542 | * NLM Server procedures. | |
543 | */ | |
544 | ||
1da177e4 LT |
545 | struct nlm_void { int dummy; }; |
546 | ||
1da177e4 LT |
547 | #define Ck (1+XDR_QUADLEN(NLM_MAXCOOKIELEN)) /* cookie */ |
548 | #define St 1 /* status */ | |
549 | #define No (1+1024/4) /* Net Obj */ | |
550 | #define Rg 2 /* range - offset + size */ | |
551 | ||
49d99608 CL |
552 | const struct svc_procedure nlmsvc_procedures[24] = { |
553 | [NLMPROC_NULL] = { | |
554 | .pc_func = nlmsvc_proc_null, | |
555 | .pc_decode = nlmsvc_decode_void, | |
556 | .pc_encode = nlmsvc_encode_void, | |
557 | .pc_argsize = sizeof(struct nlm_void), | |
558 | .pc_ressize = sizeof(struct nlm_void), | |
559 | .pc_xdrressize = St, | |
2289e87b | 560 | .pc_name = "NULL", |
49d99608 CL |
561 | }, |
562 | [NLMPROC_TEST] = { | |
563 | .pc_func = nlmsvc_proc_test, | |
564 | .pc_decode = nlmsvc_decode_testargs, | |
565 | .pc_encode = nlmsvc_encode_testres, | |
566 | .pc_argsize = sizeof(struct nlm_args), | |
567 | .pc_ressize = sizeof(struct nlm_res), | |
568 | .pc_xdrressize = Ck+St+2+No+Rg, | |
2289e87b | 569 | .pc_name = "TEST", |
49d99608 CL |
570 | }, |
571 | [NLMPROC_LOCK] = { | |
572 | .pc_func = nlmsvc_proc_lock, | |
573 | .pc_decode = nlmsvc_decode_lockargs, | |
574 | .pc_encode = nlmsvc_encode_res, | |
575 | .pc_argsize = sizeof(struct nlm_args), | |
576 | .pc_ressize = sizeof(struct nlm_res), | |
577 | .pc_xdrressize = Ck+St, | |
2289e87b | 578 | .pc_name = "LOCK", |
49d99608 CL |
579 | }, |
580 | [NLMPROC_CANCEL] = { | |
581 | .pc_func = nlmsvc_proc_cancel, | |
582 | .pc_decode = nlmsvc_decode_cancargs, | |
583 | .pc_encode = nlmsvc_encode_res, | |
584 | .pc_argsize = sizeof(struct nlm_args), | |
585 | .pc_ressize = sizeof(struct nlm_res), | |
586 | .pc_xdrressize = Ck+St, | |
2289e87b | 587 | .pc_name = "CANCEL", |
49d99608 CL |
588 | }, |
589 | [NLMPROC_UNLOCK] = { | |
590 | .pc_func = nlmsvc_proc_unlock, | |
591 | .pc_decode = nlmsvc_decode_unlockargs, | |
592 | .pc_encode = nlmsvc_encode_res, | |
593 | .pc_argsize = sizeof(struct nlm_args), | |
594 | .pc_ressize = sizeof(struct nlm_res), | |
595 | .pc_xdrressize = Ck+St, | |
2289e87b | 596 | .pc_name = "UNLOCK", |
49d99608 CL |
597 | }, |
598 | [NLMPROC_GRANTED] = { | |
599 | .pc_func = nlmsvc_proc_granted, | |
600 | .pc_decode = nlmsvc_decode_testargs, | |
601 | .pc_encode = nlmsvc_encode_res, | |
602 | .pc_argsize = sizeof(struct nlm_args), | |
603 | .pc_ressize = sizeof(struct nlm_res), | |
604 | .pc_xdrressize = Ck+St, | |
2289e87b | 605 | .pc_name = "GRANTED", |
49d99608 CL |
606 | }, |
607 | [NLMPROC_TEST_MSG] = { | |
608 | .pc_func = nlmsvc_proc_test_msg, | |
609 | .pc_decode = nlmsvc_decode_testargs, | |
610 | .pc_encode = nlmsvc_encode_void, | |
611 | .pc_argsize = sizeof(struct nlm_args), | |
612 | .pc_ressize = sizeof(struct nlm_void), | |
613 | .pc_xdrressize = St, | |
2289e87b | 614 | .pc_name = "TEST_MSG", |
49d99608 CL |
615 | }, |
616 | [NLMPROC_LOCK_MSG] = { | |
617 | .pc_func = nlmsvc_proc_lock_msg, | |
618 | .pc_decode = nlmsvc_decode_lockargs, | |
619 | .pc_encode = nlmsvc_encode_void, | |
620 | .pc_argsize = sizeof(struct nlm_args), | |
621 | .pc_ressize = sizeof(struct nlm_void), | |
622 | .pc_xdrressize = St, | |
2289e87b | 623 | .pc_name = "LOCK_MSG", |
49d99608 CL |
624 | }, |
625 | [NLMPROC_CANCEL_MSG] = { | |
626 | .pc_func = nlmsvc_proc_cancel_msg, | |
627 | .pc_decode = nlmsvc_decode_cancargs, | |
628 | .pc_encode = nlmsvc_encode_void, | |
629 | .pc_argsize = sizeof(struct nlm_args), | |
630 | .pc_ressize = sizeof(struct nlm_void), | |
631 | .pc_xdrressize = St, | |
2289e87b | 632 | .pc_name = "CANCEL_MSG", |
49d99608 CL |
633 | }, |
634 | [NLMPROC_UNLOCK_MSG] = { | |
635 | .pc_func = nlmsvc_proc_unlock_msg, | |
636 | .pc_decode = nlmsvc_decode_unlockargs, | |
637 | .pc_encode = nlmsvc_encode_void, | |
638 | .pc_argsize = sizeof(struct nlm_args), | |
639 | .pc_ressize = sizeof(struct nlm_void), | |
640 | .pc_xdrressize = St, | |
2289e87b | 641 | .pc_name = "UNLOCK_MSG", |
49d99608 CL |
642 | }, |
643 | [NLMPROC_GRANTED_MSG] = { | |
644 | .pc_func = nlmsvc_proc_granted_msg, | |
645 | .pc_decode = nlmsvc_decode_testargs, | |
646 | .pc_encode = nlmsvc_encode_void, | |
647 | .pc_argsize = sizeof(struct nlm_args), | |
648 | .pc_ressize = sizeof(struct nlm_void), | |
649 | .pc_xdrressize = St, | |
2289e87b | 650 | .pc_name = "GRANTED_MSG", |
49d99608 CL |
651 | }, |
652 | [NLMPROC_TEST_RES] = { | |
653 | .pc_func = nlmsvc_proc_null, | |
654 | .pc_decode = nlmsvc_decode_void, | |
655 | .pc_encode = nlmsvc_encode_void, | |
656 | .pc_argsize = sizeof(struct nlm_res), | |
657 | .pc_ressize = sizeof(struct nlm_void), | |
658 | .pc_xdrressize = St, | |
2289e87b | 659 | .pc_name = "TEST_RES", |
49d99608 CL |
660 | }, |
661 | [NLMPROC_LOCK_RES] = { | |
662 | .pc_func = nlmsvc_proc_null, | |
663 | .pc_decode = nlmsvc_decode_void, | |
664 | .pc_encode = nlmsvc_encode_void, | |
665 | .pc_argsize = sizeof(struct nlm_res), | |
666 | .pc_ressize = sizeof(struct nlm_void), | |
667 | .pc_xdrressize = St, | |
2289e87b | 668 | .pc_name = "LOCK_RES", |
49d99608 CL |
669 | }, |
670 | [NLMPROC_CANCEL_RES] = { | |
671 | .pc_func = nlmsvc_proc_null, | |
672 | .pc_decode = nlmsvc_decode_void, | |
673 | .pc_encode = nlmsvc_encode_void, | |
674 | .pc_argsize = sizeof(struct nlm_res), | |
675 | .pc_ressize = sizeof(struct nlm_void), | |
676 | .pc_xdrressize = St, | |
2289e87b | 677 | .pc_name = "CANCEL_RES", |
49d99608 CL |
678 | }, |
679 | [NLMPROC_UNLOCK_RES] = { | |
680 | .pc_func = nlmsvc_proc_null, | |
681 | .pc_decode = nlmsvc_decode_void, | |
682 | .pc_encode = nlmsvc_encode_void, | |
683 | .pc_argsize = sizeof(struct nlm_res), | |
684 | .pc_ressize = sizeof(struct nlm_void), | |
685 | .pc_xdrressize = St, | |
2289e87b | 686 | .pc_name = "UNLOCK_RES", |
49d99608 CL |
687 | }, |
688 | [NLMPROC_GRANTED_RES] = { | |
689 | .pc_func = nlmsvc_proc_granted_res, | |
690 | .pc_decode = nlmsvc_decode_res, | |
691 | .pc_encode = nlmsvc_encode_void, | |
692 | .pc_argsize = sizeof(struct nlm_res), | |
693 | .pc_ressize = sizeof(struct nlm_void), | |
694 | .pc_xdrressize = St, | |
2289e87b | 695 | .pc_name = "GRANTED_RES", |
49d99608 CL |
696 | }, |
697 | [NLMPROC_NSM_NOTIFY] = { | |
698 | .pc_func = nlmsvc_proc_sm_notify, | |
699 | .pc_decode = nlmsvc_decode_reboot, | |
700 | .pc_encode = nlmsvc_encode_void, | |
701 | .pc_argsize = sizeof(struct nlm_reboot), | |
702 | .pc_ressize = sizeof(struct nlm_void), | |
703 | .pc_xdrressize = St, | |
2289e87b | 704 | .pc_name = "SM_NOTIFY", |
49d99608 CL |
705 | }, |
706 | [17] = { | |
707 | .pc_func = nlmsvc_proc_unused, | |
708 | .pc_decode = nlmsvc_decode_void, | |
709 | .pc_encode = nlmsvc_encode_void, | |
710 | .pc_argsize = sizeof(struct nlm_void), | |
711 | .pc_ressize = sizeof(struct nlm_void), | |
712 | .pc_xdrressize = St, | |
2289e87b | 713 | .pc_name = "UNUSED", |
49d99608 CL |
714 | }, |
715 | [18] = { | |
716 | .pc_func = nlmsvc_proc_unused, | |
717 | .pc_decode = nlmsvc_decode_void, | |
718 | .pc_encode = nlmsvc_encode_void, | |
719 | .pc_argsize = sizeof(struct nlm_void), | |
720 | .pc_ressize = sizeof(struct nlm_void), | |
721 | .pc_xdrressize = St, | |
2289e87b | 722 | .pc_name = "UNUSED", |
49d99608 CL |
723 | }, |
724 | [19] = { | |
725 | .pc_func = nlmsvc_proc_unused, | |
726 | .pc_decode = nlmsvc_decode_void, | |
727 | .pc_encode = nlmsvc_encode_void, | |
728 | .pc_argsize = sizeof(struct nlm_void), | |
729 | .pc_ressize = sizeof(struct nlm_void), | |
730 | .pc_xdrressize = St, | |
2289e87b | 731 | .pc_name = "UNUSED", |
49d99608 CL |
732 | }, |
733 | [NLMPROC_SHARE] = { | |
734 | .pc_func = nlmsvc_proc_share, | |
735 | .pc_decode = nlmsvc_decode_shareargs, | |
736 | .pc_encode = nlmsvc_encode_shareres, | |
737 | .pc_argsize = sizeof(struct nlm_args), | |
738 | .pc_ressize = sizeof(struct nlm_res), | |
739 | .pc_xdrressize = Ck+St+1, | |
2289e87b | 740 | .pc_name = "SHARE", |
49d99608 CL |
741 | }, |
742 | [NLMPROC_UNSHARE] = { | |
743 | .pc_func = nlmsvc_proc_unshare, | |
744 | .pc_decode = nlmsvc_decode_shareargs, | |
745 | .pc_encode = nlmsvc_encode_shareres, | |
746 | .pc_argsize = sizeof(struct nlm_args), | |
747 | .pc_ressize = sizeof(struct nlm_res), | |
748 | .pc_xdrressize = Ck+St+1, | |
2289e87b | 749 | .pc_name = "UNSHARE", |
49d99608 CL |
750 | }, |
751 | [NLMPROC_NM_LOCK] = { | |
752 | .pc_func = nlmsvc_proc_nm_lock, | |
753 | .pc_decode = nlmsvc_decode_lockargs, | |
754 | .pc_encode = nlmsvc_encode_res, | |
755 | .pc_argsize = sizeof(struct nlm_args), | |
756 | .pc_ressize = sizeof(struct nlm_res), | |
757 | .pc_xdrressize = Ck+St, | |
2289e87b | 758 | .pc_name = "NM_LOCK", |
49d99608 CL |
759 | }, |
760 | [NLMPROC_FREE_ALL] = { | |
761 | .pc_func = nlmsvc_proc_free_all, | |
762 | .pc_decode = nlmsvc_decode_notify, | |
763 | .pc_encode = nlmsvc_encode_void, | |
764 | .pc_argsize = sizeof(struct nlm_args), | |
765 | .pc_ressize = sizeof(struct nlm_void), | |
766 | .pc_xdrressize = 0, | |
2289e87b | 767 | .pc_name = "FREE_ALL", |
49d99608 | 768 | }, |
1da177e4 | 769 | }; |