Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/fs/lockd/svcproc.c |
| 3 | * |
| 4 | * Lockd server procedures. We don't implement the NLM_*_RES |
| 5 | * procedures because we don't use the async procedures. |
| 6 | * |
| 7 | * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de> |
| 8 | */ |
| 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/types.h> |
| 11 | #include <linux/time.h> |
| 12 | #include <linux/slab.h> |
Alexey Dobriyan | 405f557 | 2009-07-11 22:08:37 +0400 | [diff] [blame] | 13 | #include <linux/smp_lock.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/lockd/lockd.h> |
| 15 | #include <linux/lockd/share.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
| 17 | #define NLMDBG_FACILITY NLMDBG_CLIENT |
| 18 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #ifdef CONFIG_LOCKD_V4 |
Al Viro | 52921e0 | 2006-10-19 23:28:46 -0700 | [diff] [blame] | 20 | static __be32 |
| 21 | cast_to_nlm(__be32 status, u32 vers) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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: |
Marc Eshel | 5ea0d75 | 2006-11-28 16:27:06 -0500 | [diff] [blame] | 31 | case nlm_drop_reply: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | */ |
Al Viro | 52921e0 | 2006-10-19 23:28:46 -0700 | [diff] [blame] | 51 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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; |
Al Viro | 52921e0 | 2006-10-19 23:28:46 -0700 | [diff] [blame] | 58 | __be32 error = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
| 60 | /* nfsd callbacks must have been installed for this procedure */ |
| 61 | if (!nlmsvc_ops) |
| 62 | return nlm_lck_denied_nolocks; |
| 63 | |
| 64 | /* Obtain host handle */ |
Olaf Kirch | db4e4c9 | 2006-10-04 02:15:52 -0700 | [diff] [blame] | 65 | if (!(host = nlmsvc_lookup_host(rqstp, lock->caller, lock->len)) |
Olaf Kirch | 977faf3 | 2006-10-04 02:15:51 -0700 | [diff] [blame] | 66 | || (argp->monitor && nsm_monitor(host) < 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | goto no_locks; |
| 68 | *hostp = host; |
| 69 | |
| 70 | /* Obtain file pointer. Not used by FREE_ALL call. */ |
| 71 | if (filp != NULL) { |
| 72 | if ((error = nlm_lookup_file(rqstp, &file, &lock->fh)) != 0) |
| 73 | goto no_locks; |
| 74 | *filp = file; |
| 75 | |
| 76 | /* Set up the missing parts of the file_lock structure */ |
| 77 | lock->fl.fl_file = file->f_file; |
| 78 | lock->fl.fl_owner = (fl_owner_t) host; |
| 79 | lock->fl.fl_lmops = &nlmsvc_lock_operations; |
| 80 | } |
| 81 | |
| 82 | return 0; |
| 83 | |
| 84 | no_locks: |
Jeff Layton | b0e92aa | 2008-07-15 12:35:20 -0400 | [diff] [blame] | 85 | nlm_release_host(host); |
NeilBrown | d343fce | 2006-10-17 00:10:18 -0700 | [diff] [blame] | 86 | if (error) |
| 87 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | return nlm_lck_denied_nolocks; |
| 89 | } |
| 90 | |
| 91 | /* |
| 92 | * NULL: Test for presence of service |
| 93 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 94 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | nlmsvc_proc_null(struct svc_rqst *rqstp, void *argp, void *resp) |
| 96 | { |
| 97 | dprintk("lockd: NULL called\n"); |
| 98 | return rpc_success; |
| 99 | } |
| 100 | |
| 101 | /* |
| 102 | * TEST: Check for conflicting lock |
| 103 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 104 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | nlmsvc_proc_test(struct svc_rqst *rqstp, struct nlm_args *argp, |
| 106 | struct nlm_res *resp) |
| 107 | { |
| 108 | struct nlm_host *host; |
| 109 | struct nlm_file *file; |
Harvey Harrison | 317602f | 2008-07-20 23:41:24 -0700 | [diff] [blame] | 110 | __be32 rc = rpc_success; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
| 112 | dprintk("lockd: TEST called\n"); |
| 113 | resp->cookie = argp->cookie; |
| 114 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | /* Obtain client and file */ |
| 116 | if ((resp->status = nlmsvc_retrieve_args(rqstp, argp, &host, &file))) |
NeilBrown | d343fce | 2006-10-17 00:10:18 -0700 | [diff] [blame] | 117 | return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
| 119 | /* Now check for conflicting locks */ |
Jeff Layton | 8f920d5 | 2008-07-15 14:06:48 -0400 | [diff] [blame] | 120 | resp->status = cast_status(nlmsvc_testlock(rqstp, file, host, &argp->lock, &resp->lock, &resp->cookie)); |
Marc Eshel | 5ea0d75 | 2006-11-28 16:27:06 -0500 | [diff] [blame] | 121 | if (resp->status == nlm_drop_reply) |
Oleg Drokin | b7e6b86 | 2007-11-26 13:35:11 -0500 | [diff] [blame] | 122 | rc = rpc_drop_reply; |
| 123 | else |
| 124 | dprintk("lockd: TEST status %d vers %d\n", |
| 125 | ntohl(resp->status), rqstp->rq_vers); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | nlm_release_host(host); |
| 128 | nlm_release_file(file); |
Oleg Drokin | b7e6b86 | 2007-11-26 13:35:11 -0500 | [diff] [blame] | 129 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | } |
| 131 | |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 132 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | nlmsvc_proc_lock(struct svc_rqst *rqstp, struct nlm_args *argp, |
| 134 | struct nlm_res *resp) |
| 135 | { |
| 136 | struct nlm_host *host; |
| 137 | struct nlm_file *file; |
Harvey Harrison | 317602f | 2008-07-20 23:41:24 -0700 | [diff] [blame] | 138 | __be32 rc = rpc_success; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
| 140 | dprintk("lockd: LOCK called\n"); |
| 141 | |
| 142 | resp->cookie = argp->cookie; |
| 143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | /* Obtain client and file */ |
| 145 | if ((resp->status = nlmsvc_retrieve_args(rqstp, argp, &host, &file))) |
NeilBrown | d343fce | 2006-10-17 00:10:18 -0700 | [diff] [blame] | 146 | return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
| 148 | #if 0 |
| 149 | /* If supplied state doesn't match current state, we assume it's |
| 150 | * an old request that time-warped somehow. Any error return would |
| 151 | * do in this case because it's irrelevant anyway. |
| 152 | * |
| 153 | * NB: We don't retrieve the remote host's state yet. |
| 154 | */ |
| 155 | if (host->h_nsmstate && host->h_nsmstate != argp->state) { |
| 156 | resp->status = nlm_lck_denied_nolocks; |
| 157 | } else |
| 158 | #endif |
| 159 | |
| 160 | /* Now try to lock the file */ |
Jeff Layton | 6cde4de | 2008-07-15 14:26:17 -0400 | [diff] [blame] | 161 | resp->status = cast_status(nlmsvc_lock(rqstp, file, host, &argp->lock, |
J. Bruce Fields | b2b5028 | 2008-02-06 13:59:23 -0500 | [diff] [blame] | 162 | argp->block, &argp->cookie, |
| 163 | argp->reclaim)); |
Marc Eshel | 1a8322b | 2006-11-28 16:27:06 -0500 | [diff] [blame] | 164 | if (resp->status == nlm_drop_reply) |
Oleg Drokin | b7e6b86 | 2007-11-26 13:35:11 -0500 | [diff] [blame] | 165 | rc = rpc_drop_reply; |
| 166 | else |
| 167 | dprintk("lockd: LOCK status %d\n", ntohl(resp->status)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | nlm_release_host(host); |
| 170 | nlm_release_file(file); |
Oleg Drokin | b7e6b86 | 2007-11-26 13:35:11 -0500 | [diff] [blame] | 171 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 174 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | nlmsvc_proc_cancel(struct svc_rqst *rqstp, struct nlm_args *argp, |
| 176 | struct nlm_res *resp) |
| 177 | { |
| 178 | struct nlm_host *host; |
| 179 | struct nlm_file *file; |
| 180 | |
| 181 | dprintk("lockd: CANCEL called\n"); |
| 182 | |
| 183 | resp->cookie = argp->cookie; |
| 184 | |
| 185 | /* Don't accept requests during grace period */ |
J. Bruce Fields | af558e3 | 2007-09-06 12:34:25 -0400 | [diff] [blame] | 186 | if (locks_in_grace()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | resp->status = nlm_lck_denied_grace_period; |
| 188 | return rpc_success; |
| 189 | } |
| 190 | |
| 191 | /* Obtain client and file */ |
| 192 | if ((resp->status = nlmsvc_retrieve_args(rqstp, argp, &host, &file))) |
NeilBrown | d343fce | 2006-10-17 00:10:18 -0700 | [diff] [blame] | 193 | return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | |
| 195 | /* Try to cancel request. */ |
| 196 | resp->status = cast_status(nlmsvc_cancel_blocked(file, &argp->lock)); |
| 197 | |
| 198 | dprintk("lockd: CANCEL status %d\n", ntohl(resp->status)); |
| 199 | nlm_release_host(host); |
| 200 | nlm_release_file(file); |
| 201 | return rpc_success; |
| 202 | } |
| 203 | |
| 204 | /* |
| 205 | * UNLOCK: release a lock |
| 206 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 207 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | nlmsvc_proc_unlock(struct svc_rqst *rqstp, struct nlm_args *argp, |
| 209 | struct nlm_res *resp) |
| 210 | { |
| 211 | struct nlm_host *host; |
| 212 | struct nlm_file *file; |
| 213 | |
| 214 | dprintk("lockd: UNLOCK called\n"); |
| 215 | |
| 216 | resp->cookie = argp->cookie; |
| 217 | |
| 218 | /* Don't accept new lock requests during grace period */ |
J. Bruce Fields | af558e3 | 2007-09-06 12:34:25 -0400 | [diff] [blame] | 219 | if (locks_in_grace()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | resp->status = nlm_lck_denied_grace_period; |
| 221 | return rpc_success; |
| 222 | } |
| 223 | |
| 224 | /* Obtain client and file */ |
| 225 | if ((resp->status = nlmsvc_retrieve_args(rqstp, argp, &host, &file))) |
NeilBrown | d343fce | 2006-10-17 00:10:18 -0700 | [diff] [blame] | 226 | return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | |
| 228 | /* Now try to remove the lock */ |
| 229 | resp->status = cast_status(nlmsvc_unlock(file, &argp->lock)); |
| 230 | |
| 231 | dprintk("lockd: UNLOCK status %d\n", ntohl(resp->status)); |
| 232 | nlm_release_host(host); |
| 233 | nlm_release_file(file); |
| 234 | return rpc_success; |
| 235 | } |
| 236 | |
| 237 | /* |
| 238 | * GRANTED: A server calls us to tell that a process' lock request |
| 239 | * was granted |
| 240 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 241 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | nlmsvc_proc_granted(struct svc_rqst *rqstp, struct nlm_args *argp, |
| 243 | struct nlm_res *resp) |
| 244 | { |
| 245 | resp->cookie = argp->cookie; |
| 246 | |
| 247 | dprintk("lockd: GRANTED called\n"); |
Chuck Lever | dcff09f | 2008-10-03 12:50:36 -0400 | [diff] [blame] | 248 | resp->status = nlmclnt_grant(svc_addr(rqstp), &argp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | dprintk("lockd: GRANTED status %d\n", ntohl(resp->status)); |
| 250 | return rpc_success; |
| 251 | } |
| 252 | |
| 253 | /* |
Trond Myklebust | d471662 | 2006-03-20 13:44:45 -0500 | [diff] [blame] | 254 | * This is the generic lockd callback for async RPC calls |
| 255 | */ |
| 256 | static void nlmsvc_callback_exit(struct rpc_task *task, void *data) |
| 257 | { |
Chuck Lever | c041b5f | 2006-12-05 16:36:03 -0500 | [diff] [blame] | 258 | dprintk("lockd: %5u callback returned %d\n", task->tk_pid, |
Trond Myklebust | d471662 | 2006-03-20 13:44:45 -0500 | [diff] [blame] | 259 | -task->tk_status); |
| 260 | } |
| 261 | |
| 262 | static void nlmsvc_callback_release(void *data) |
| 263 | { |
Trond Myklebust | a86dc49 | 2008-06-11 13:37:09 -0400 | [diff] [blame] | 264 | lock_kernel(); |
Trond Myklebust | d471662 | 2006-03-20 13:44:45 -0500 | [diff] [blame] | 265 | nlm_release_call(data); |
Trond Myklebust | a86dc49 | 2008-06-11 13:37:09 -0400 | [diff] [blame] | 266 | unlock_kernel(); |
Trond Myklebust | d471662 | 2006-03-20 13:44:45 -0500 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | static const struct rpc_call_ops nlmsvc_callback_ops = { |
| 270 | .rpc_call_done = nlmsvc_callback_exit, |
| 271 | .rpc_release = nlmsvc_callback_release, |
| 272 | }; |
| 273 | |
| 274 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | * `Async' versions of the above service routines. They aren't really, |
| 276 | * because we send the callback before the reply proper. I hope this |
| 277 | * doesn't break any clients. |
| 278 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 279 | static __be32 nlmsvc_callback(struct svc_rqst *rqstp, u32 proc, struct nlm_args *argp, |
| 280 | __be32 (*func)(struct svc_rqst *, struct nlm_args *, struct nlm_res *)) |
Trond Myklebust | d471662 | 2006-03-20 13:44:45 -0500 | [diff] [blame] | 281 | { |
| 282 | struct nlm_host *host; |
| 283 | struct nlm_rqst *call; |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 284 | __be32 stat; |
Trond Myklebust | d471662 | 2006-03-20 13:44:45 -0500 | [diff] [blame] | 285 | |
Olaf Kirch | db4e4c9 | 2006-10-04 02:15:52 -0700 | [diff] [blame] | 286 | host = nlmsvc_lookup_host(rqstp, |
| 287 | argp->lock.caller, |
| 288 | argp->lock.len); |
Trond Myklebust | d471662 | 2006-03-20 13:44:45 -0500 | [diff] [blame] | 289 | if (host == NULL) |
| 290 | return rpc_system_err; |
| 291 | |
| 292 | call = nlm_alloc_call(host); |
| 293 | if (call == NULL) |
| 294 | return rpc_system_err; |
| 295 | |
| 296 | stat = func(rqstp, argp, &call->a_res); |
| 297 | if (stat != 0) { |
| 298 | nlm_release_call(call); |
| 299 | return stat; |
| 300 | } |
| 301 | |
| 302 | call->a_flags = RPC_TASK_ASYNC; |
| 303 | if (nlm_async_reply(call, proc, &nlmsvc_callback_ops) < 0) |
| 304 | return rpc_system_err; |
| 305 | return rpc_success; |
| 306 | } |
| 307 | |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 308 | static __be32 nlmsvc_proc_test_msg(struct svc_rqst *rqstp, struct nlm_args *argp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | void *resp) |
| 310 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | dprintk("lockd: TEST_MSG called\n"); |
Trond Myklebust | d471662 | 2006-03-20 13:44:45 -0500 | [diff] [blame] | 312 | return nlmsvc_callback(rqstp, NLMPROC_TEST_RES, argp, nlmsvc_proc_test); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | } |
| 314 | |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 315 | static __be32 nlmsvc_proc_lock_msg(struct svc_rqst *rqstp, struct nlm_args *argp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | void *resp) |
| 317 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | dprintk("lockd: LOCK_MSG called\n"); |
Trond Myklebust | d471662 | 2006-03-20 13:44:45 -0500 | [diff] [blame] | 319 | return nlmsvc_callback(rqstp, NLMPROC_LOCK_RES, argp, nlmsvc_proc_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | } |
| 321 | |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 322 | static __be32 nlmsvc_proc_cancel_msg(struct svc_rqst *rqstp, struct nlm_args *argp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | void *resp) |
| 324 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | dprintk("lockd: CANCEL_MSG called\n"); |
Trond Myklebust | d471662 | 2006-03-20 13:44:45 -0500 | [diff] [blame] | 326 | return nlmsvc_callback(rqstp, NLMPROC_CANCEL_RES, argp, nlmsvc_proc_cancel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | } |
| 328 | |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 329 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | nlmsvc_proc_unlock_msg(struct svc_rqst *rqstp, struct nlm_args *argp, |
| 331 | void *resp) |
| 332 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | dprintk("lockd: UNLOCK_MSG called\n"); |
Trond Myklebust | d471662 | 2006-03-20 13:44:45 -0500 | [diff] [blame] | 334 | return nlmsvc_callback(rqstp, NLMPROC_UNLOCK_RES, argp, nlmsvc_proc_unlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | } |
| 336 | |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 337 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | nlmsvc_proc_granted_msg(struct svc_rqst *rqstp, struct nlm_args *argp, |
| 339 | void *resp) |
| 340 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | dprintk("lockd: GRANTED_MSG called\n"); |
Trond Myklebust | d471662 | 2006-03-20 13:44:45 -0500 | [diff] [blame] | 342 | return nlmsvc_callback(rqstp, NLMPROC_GRANTED_RES, argp, nlmsvc_proc_granted); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | /* |
| 346 | * SHARE: create a DOS share or alter existing share. |
| 347 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 348 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | nlmsvc_proc_share(struct svc_rqst *rqstp, struct nlm_args *argp, |
| 350 | struct nlm_res *resp) |
| 351 | { |
| 352 | struct nlm_host *host; |
| 353 | struct nlm_file *file; |
| 354 | |
| 355 | dprintk("lockd: SHARE called\n"); |
| 356 | |
| 357 | resp->cookie = argp->cookie; |
| 358 | |
| 359 | /* Don't accept new lock requests during grace period */ |
J. Bruce Fields | af558e3 | 2007-09-06 12:34:25 -0400 | [diff] [blame] | 360 | if (locks_in_grace() && !argp->reclaim) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | resp->status = nlm_lck_denied_grace_period; |
| 362 | return rpc_success; |
| 363 | } |
| 364 | |
| 365 | /* Obtain client and file */ |
| 366 | if ((resp->status = nlmsvc_retrieve_args(rqstp, argp, &host, &file))) |
NeilBrown | d343fce | 2006-10-17 00:10:18 -0700 | [diff] [blame] | 367 | return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | |
| 369 | /* Now try to create the share */ |
| 370 | resp->status = cast_status(nlmsvc_share_file(host, file, argp)); |
| 371 | |
| 372 | dprintk("lockd: SHARE status %d\n", ntohl(resp->status)); |
| 373 | nlm_release_host(host); |
| 374 | nlm_release_file(file); |
| 375 | return rpc_success; |
| 376 | } |
| 377 | |
| 378 | /* |
| 379 | * UNSHARE: Release a DOS share. |
| 380 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 381 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | nlmsvc_proc_unshare(struct svc_rqst *rqstp, struct nlm_args *argp, |
| 383 | struct nlm_res *resp) |
| 384 | { |
| 385 | struct nlm_host *host; |
| 386 | struct nlm_file *file; |
| 387 | |
| 388 | dprintk("lockd: UNSHARE called\n"); |
| 389 | |
| 390 | resp->cookie = argp->cookie; |
| 391 | |
| 392 | /* Don't accept requests during grace period */ |
J. Bruce Fields | af558e3 | 2007-09-06 12:34:25 -0400 | [diff] [blame] | 393 | if (locks_in_grace()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | resp->status = nlm_lck_denied_grace_period; |
| 395 | return rpc_success; |
| 396 | } |
| 397 | |
| 398 | /* Obtain client and file */ |
| 399 | if ((resp->status = nlmsvc_retrieve_args(rqstp, argp, &host, &file))) |
NeilBrown | d343fce | 2006-10-17 00:10:18 -0700 | [diff] [blame] | 400 | return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | |
| 402 | /* Now try to unshare the file */ |
| 403 | resp->status = cast_status(nlmsvc_unshare_file(host, file, argp)); |
| 404 | |
| 405 | dprintk("lockd: UNSHARE status %d\n", ntohl(resp->status)); |
| 406 | nlm_release_host(host); |
| 407 | nlm_release_file(file); |
| 408 | return rpc_success; |
| 409 | } |
| 410 | |
| 411 | /* |
| 412 | * NM_LOCK: Create an unmonitored lock |
| 413 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 414 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | nlmsvc_proc_nm_lock(struct svc_rqst *rqstp, struct nlm_args *argp, |
| 416 | struct nlm_res *resp) |
| 417 | { |
| 418 | dprintk("lockd: NM_LOCK called\n"); |
| 419 | |
| 420 | argp->monitor = 0; /* just clean the monitor flag */ |
| 421 | return nlmsvc_proc_lock(rqstp, argp, resp); |
| 422 | } |
| 423 | |
| 424 | /* |
| 425 | * FREE_ALL: Release all locks and shares held by client |
| 426 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 427 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | nlmsvc_proc_free_all(struct svc_rqst *rqstp, struct nlm_args *argp, |
| 429 | void *resp) |
| 430 | { |
| 431 | struct nlm_host *host; |
| 432 | |
| 433 | /* Obtain client */ |
| 434 | if (nlmsvc_retrieve_args(rqstp, argp, &host, NULL)) |
| 435 | return rpc_success; |
| 436 | |
| 437 | nlmsvc_free_host_resources(host); |
| 438 | nlm_release_host(host); |
| 439 | return rpc_success; |
| 440 | } |
| 441 | |
| 442 | /* |
| 443 | * SM_NOTIFY: private callback from statd (not part of official NLM proto) |
| 444 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 445 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | nlmsvc_proc_sm_notify(struct svc_rqst *rqstp, struct nlm_reboot *argp, |
| 447 | void *resp) |
| 448 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | dprintk("lockd: SM_NOTIFY called\n"); |
Chuck Lever | b85e467 | 2008-10-03 12:50:44 -0400 | [diff] [blame] | 450 | |
| 451 | if (!nlm_privileged_requester(rqstp)) { |
Chuck Lever | ad06e4b | 2007-02-12 00:53:32 -0800 | [diff] [blame] | 452 | char buf[RPC_MAX_ADDRBUFLEN]; |
| 453 | printk(KERN_WARNING "lockd: rejected NSM callback from %s\n", |
| 454 | svc_print_addr(rqstp, buf, sizeof(buf))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | return rpc_system_err; |
| 456 | } |
| 457 | |
Chuck Lever | 7fefc9c | 2008-12-05 19:03:31 -0500 | [diff] [blame] | 458 | nlm_host_rebooted(argp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | return rpc_success; |
| 460 | } |
| 461 | |
| 462 | /* |
| 463 | * client sent a GRANTED_RES, let's remove the associated block |
| 464 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 465 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | nlmsvc_proc_granted_res(struct svc_rqst *rqstp, struct nlm_res *argp, |
| 467 | void *resp) |
| 468 | { |
| 469 | if (!nlmsvc_ops) |
| 470 | return rpc_success; |
| 471 | |
| 472 | dprintk("lockd: GRANTED_RES called\n"); |
| 473 | |
Olaf Kirch | 39be450 | 2006-10-04 02:16:03 -0700 | [diff] [blame] | 474 | nlmsvc_grant_reply(&argp->cookie, argp->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | return rpc_success; |
| 476 | } |
| 477 | |
| 478 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | * NLM Server procedures. |
| 480 | */ |
| 481 | |
| 482 | #define nlmsvc_encode_norep nlmsvc_encode_void |
| 483 | #define nlmsvc_decode_norep nlmsvc_decode_void |
| 484 | #define nlmsvc_decode_testres nlmsvc_decode_void |
| 485 | #define nlmsvc_decode_lockres nlmsvc_decode_void |
| 486 | #define nlmsvc_decode_unlockres nlmsvc_decode_void |
| 487 | #define nlmsvc_decode_cancelres nlmsvc_decode_void |
| 488 | #define nlmsvc_decode_grantedres nlmsvc_decode_void |
| 489 | |
| 490 | #define nlmsvc_proc_none nlmsvc_proc_null |
| 491 | #define nlmsvc_proc_test_res nlmsvc_proc_null |
| 492 | #define nlmsvc_proc_lock_res nlmsvc_proc_null |
| 493 | #define nlmsvc_proc_cancel_res nlmsvc_proc_null |
| 494 | #define nlmsvc_proc_unlock_res nlmsvc_proc_null |
| 495 | |
| 496 | struct nlm_void { int dummy; }; |
| 497 | |
| 498 | #define PROC(name, xargt, xrest, argt, rest, respsize) \ |
| 499 | { .pc_func = (svc_procfunc) nlmsvc_proc_##name, \ |
| 500 | .pc_decode = (kxdrproc_t) nlmsvc_decode_##xargt, \ |
| 501 | .pc_encode = (kxdrproc_t) nlmsvc_encode_##xrest, \ |
| 502 | .pc_release = NULL, \ |
| 503 | .pc_argsize = sizeof(struct nlm_##argt), \ |
| 504 | .pc_ressize = sizeof(struct nlm_##rest), \ |
| 505 | .pc_xdrressize = respsize, \ |
| 506 | } |
| 507 | |
| 508 | #define Ck (1+XDR_QUADLEN(NLM_MAXCOOKIELEN)) /* cookie */ |
| 509 | #define St 1 /* status */ |
| 510 | #define No (1+1024/4) /* Net Obj */ |
| 511 | #define Rg 2 /* range - offset + size */ |
| 512 | |
| 513 | struct svc_procedure nlmsvc_procedures[] = { |
| 514 | PROC(null, void, void, void, void, 1), |
| 515 | PROC(test, testargs, testres, args, res, Ck+St+2+No+Rg), |
| 516 | PROC(lock, lockargs, res, args, res, Ck+St), |
| 517 | PROC(cancel, cancargs, res, args, res, Ck+St), |
| 518 | PROC(unlock, unlockargs, res, args, res, Ck+St), |
| 519 | PROC(granted, testargs, res, args, res, Ck+St), |
| 520 | PROC(test_msg, testargs, norep, args, void, 1), |
| 521 | PROC(lock_msg, lockargs, norep, args, void, 1), |
| 522 | PROC(cancel_msg, cancargs, norep, args, void, 1), |
| 523 | PROC(unlock_msg, unlockargs, norep, args, void, 1), |
| 524 | PROC(granted_msg, testargs, norep, args, void, 1), |
| 525 | PROC(test_res, testres, norep, res, void, 1), |
| 526 | PROC(lock_res, lockres, norep, res, void, 1), |
| 527 | PROC(cancel_res, cancelres, norep, res, void, 1), |
| 528 | PROC(unlock_res, unlockres, norep, res, void, 1), |
| 529 | PROC(granted_res, res, norep, res, void, 1), |
| 530 | /* statd callback */ |
| 531 | PROC(sm_notify, reboot, void, reboot, void, 1), |
| 532 | PROC(none, void, void, void, void, 1), |
| 533 | PROC(none, void, void, void, void, 1), |
| 534 | PROC(none, void, void, void, void, 1), |
| 535 | PROC(share, shareargs, shareres, args, res, Ck+St+1), |
| 536 | PROC(unshare, shareargs, shareres, args, res, Ck+St+1), |
| 537 | PROC(nm_lock, lockargs, res, args, res, Ck+St), |
| 538 | PROC(free_all, notify, void, args, void, 0), |
| 539 | |
| 540 | }; |