1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0 21da177e4SLinus Torvalds /* 31da177e4SLinus Torvalds * linux/fs/lockd/svc4proc.c 41da177e4SLinus Torvalds * 51da177e4SLinus Torvalds * Lockd server procedures. We don't implement the NLM_*_RES 61da177e4SLinus Torvalds * procedures because we don't use the async procedures. 71da177e4SLinus Torvalds * 81da177e4SLinus Torvalds * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de> 91da177e4SLinus Torvalds */ 101da177e4SLinus Torvalds 111da177e4SLinus Torvalds #include <linux/types.h> 121da177e4SLinus Torvalds #include <linux/time.h> 131da177e4SLinus Torvalds #include <linux/lockd/lockd.h> 141da177e4SLinus Torvalds #include <linux/lockd/share.h> 155ccb0066SStanislav Kinsbursky #include <linux/sunrpc/svc_xprt.h> 161da177e4SLinus Torvalds 171da177e4SLinus Torvalds #define NLMDBG_FACILITY NLMDBG_CLIENT 181da177e4SLinus Torvalds 191da177e4SLinus Torvalds /* 201da177e4SLinus Torvalds * Obtain client and file from arguments 211da177e4SLinus Torvalds */ 2252921e02SAl Viro static __be32 231da177e4SLinus Torvalds nlm4svc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp, 241da177e4SLinus Torvalds struct nlm_host **hostp, struct nlm_file **filp) 251da177e4SLinus Torvalds { 261da177e4SLinus Torvalds struct nlm_host *host = NULL; 271da177e4SLinus Torvalds struct nlm_file *file = NULL; 281da177e4SLinus Torvalds struct nlm_lock *lock = &argp->lock; 2952921e02SAl Viro __be32 error = 0; 301da177e4SLinus Torvalds 311da177e4SLinus Torvalds /* nfsd callbacks must have been installed for this procedure */ 321da177e4SLinus Torvalds if (!nlmsvc_ops) 331da177e4SLinus Torvalds return nlm_lck_denied_nolocks; 341da177e4SLinus Torvalds 351da177e4SLinus Torvalds /* Obtain host handle */ 36db4e4c9aSOlaf Kirch if (!(host = nlmsvc_lookup_host(rqstp, lock->caller, lock->len)) 37977faf39SOlaf Kirch || (argp->monitor && nsm_monitor(host) < 0)) 381da177e4SLinus Torvalds goto no_locks; 391da177e4SLinus Torvalds *hostp = host; 401da177e4SLinus Torvalds 411da177e4SLinus Torvalds /* Obtain file pointer. Not used by FREE_ALL call. */ 421da177e4SLinus Torvalds if (filp != NULL) { 431da177e4SLinus Torvalds if ((error = nlm_lookup_file(rqstp, &file, &lock->fh)) != 0) 441da177e4SLinus Torvalds goto no_locks; 451da177e4SLinus Torvalds *filp = file; 461da177e4SLinus Torvalds 471da177e4SLinus Torvalds /* Set up the missing parts of the file_lock structure */ 481da177e4SLinus Torvalds lock->fl.fl_file = file->f_file; 491da177e4SLinus Torvalds lock->fl.fl_lmops = &nlmsvc_lock_operations; 50*89e0edfbSBenjamin Coddington nlmsvc_locks_init_private(&lock->fl, host, (pid_t)lock->svid); 51*89e0edfbSBenjamin Coddington if (!lock->fl.fl_owner) { 52*89e0edfbSBenjamin Coddington /* lockowner allocation has failed */ 53*89e0edfbSBenjamin Coddington nlmsvc_release_host(host); 54*89e0edfbSBenjamin Coddington return nlm_lck_denied_nolocks; 55*89e0edfbSBenjamin Coddington } 561da177e4SLinus Torvalds } 571da177e4SLinus Torvalds 581da177e4SLinus Torvalds return 0; 591da177e4SLinus Torvalds 601da177e4SLinus Torvalds no_locks: 6167216b94SChuck Lever nlmsvc_release_host(host); 621da177e4SLinus Torvalds if (error) 631da177e4SLinus Torvalds return error; 641da177e4SLinus Torvalds return nlm_lck_denied_nolocks; 651da177e4SLinus Torvalds } 661da177e4SLinus Torvalds 671da177e4SLinus Torvalds /* 681da177e4SLinus Torvalds * NULL: Test for presence of service 691da177e4SLinus Torvalds */ 707111c66eSAl Viro static __be32 71a6beb732SChristoph Hellwig nlm4svc_proc_null(struct svc_rqst *rqstp) 721da177e4SLinus Torvalds { 731da177e4SLinus Torvalds dprintk("lockd: NULL called\n"); 741da177e4SLinus Torvalds return rpc_success; 751da177e4SLinus Torvalds } 761da177e4SLinus Torvalds 771da177e4SLinus Torvalds /* 781da177e4SLinus Torvalds * TEST: Check for conflicting lock 791da177e4SLinus Torvalds */ 807111c66eSAl Viro static __be32 81a6beb732SChristoph Hellwig __nlm4svc_proc_test(struct svc_rqst *rqstp, struct nlm_res *resp) 821da177e4SLinus Torvalds { 83a6beb732SChristoph Hellwig struct nlm_args *argp = rqstp->rq_argp; 841da177e4SLinus Torvalds struct nlm_host *host; 851da177e4SLinus Torvalds struct nlm_file *file; 86317602f3SHarvey Harrison __be32 rc = rpc_success; 871da177e4SLinus Torvalds 881da177e4SLinus Torvalds dprintk("lockd: TEST4 called\n"); 891da177e4SLinus Torvalds resp->cookie = argp->cookie; 901da177e4SLinus Torvalds 911da177e4SLinus Torvalds /* Obtain client and file */ 921da177e4SLinus Torvalds if ((resp->status = nlm4svc_retrieve_args(rqstp, argp, &host, &file))) 93d343fce1SNeilBrown return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; 941da177e4SLinus Torvalds 951da177e4SLinus Torvalds /* Now check for conflicting locks */ 968f920d5eSJeff Layton resp->status = nlmsvc_testlock(rqstp, file, host, &argp->lock, &resp->lock, &resp->cookie); 975ea0d750SMarc Eshel if (resp->status == nlm_drop_reply) 98b7e6b869SOleg Drokin rc = rpc_drop_reply; 99b7e6b869SOleg Drokin else 1001da177e4SLinus Torvalds dprintk("lockd: TEST4 status %d\n", ntohl(resp->status)); 101b7e6b869SOleg Drokin 102*89e0edfbSBenjamin Coddington nlmsvc_release_lockowner(&argp->lock); 10367216b94SChuck Lever nlmsvc_release_host(host); 1041da177e4SLinus Torvalds nlm_release_file(file); 105b7e6b869SOleg Drokin return rc; 1061da177e4SLinus Torvalds } 1071da177e4SLinus Torvalds 1087111c66eSAl Viro static __be32 109a6beb732SChristoph Hellwig nlm4svc_proc_test(struct svc_rqst *rqstp) 1101da177e4SLinus Torvalds { 111a6beb732SChristoph Hellwig return __nlm4svc_proc_test(rqstp, rqstp->rq_resp); 112a6beb732SChristoph Hellwig } 113a6beb732SChristoph Hellwig 114a6beb732SChristoph Hellwig static __be32 115a6beb732SChristoph Hellwig __nlm4svc_proc_lock(struct svc_rqst *rqstp, struct nlm_res *resp) 116a6beb732SChristoph Hellwig { 117a6beb732SChristoph Hellwig struct nlm_args *argp = rqstp->rq_argp; 1181da177e4SLinus Torvalds struct nlm_host *host; 1191da177e4SLinus Torvalds struct nlm_file *file; 120317602f3SHarvey Harrison __be32 rc = rpc_success; 1211da177e4SLinus Torvalds 1221da177e4SLinus Torvalds dprintk("lockd: LOCK called\n"); 1231da177e4SLinus Torvalds 1241da177e4SLinus Torvalds resp->cookie = argp->cookie; 1251da177e4SLinus Torvalds 1261da177e4SLinus Torvalds /* Obtain client and file */ 1271da177e4SLinus Torvalds if ((resp->status = nlm4svc_retrieve_args(rqstp, argp, &host, &file))) 128d343fce1SNeilBrown return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; 1291da177e4SLinus Torvalds 1301da177e4SLinus Torvalds #if 0 1311da177e4SLinus Torvalds /* If supplied state doesn't match current state, we assume it's 1321da177e4SLinus Torvalds * an old request that time-warped somehow. Any error return would 1331da177e4SLinus Torvalds * do in this case because it's irrelevant anyway. 1341da177e4SLinus Torvalds * 1351da177e4SLinus Torvalds * NB: We don't retrieve the remote host's state yet. 1361da177e4SLinus Torvalds */ 1371da177e4SLinus Torvalds if (host->h_nsmstate && host->h_nsmstate != argp->state) { 1381da177e4SLinus Torvalds resp->status = nlm_lck_denied_nolocks; 1391da177e4SLinus Torvalds } else 1401da177e4SLinus Torvalds #endif 1411da177e4SLinus Torvalds 1421da177e4SLinus Torvalds /* Now try to lock the file */ 1436cde4de8SJeff Layton resp->status = nlmsvc_lock(rqstp, file, host, &argp->lock, 144b2b50289SJ. Bruce Fields argp->block, &argp->cookie, 145b2b50289SJ. Bruce Fields argp->reclaim); 1461a8322b2SMarc Eshel if (resp->status == nlm_drop_reply) 147b7e6b869SOleg Drokin rc = rpc_drop_reply; 148b7e6b869SOleg Drokin else 1491da177e4SLinus Torvalds dprintk("lockd: LOCK status %d\n", ntohl(resp->status)); 150b7e6b869SOleg Drokin 151*89e0edfbSBenjamin Coddington nlmsvc_release_lockowner(&argp->lock); 15267216b94SChuck Lever nlmsvc_release_host(host); 1531da177e4SLinus Torvalds nlm_release_file(file); 154b7e6b869SOleg Drokin return rc; 1551da177e4SLinus Torvalds } 1561da177e4SLinus Torvalds 1577111c66eSAl Viro static __be32 158a6beb732SChristoph Hellwig nlm4svc_proc_lock(struct svc_rqst *rqstp) 1591da177e4SLinus Torvalds { 160a6beb732SChristoph Hellwig return __nlm4svc_proc_lock(rqstp, rqstp->rq_resp); 161a6beb732SChristoph Hellwig } 162a6beb732SChristoph Hellwig 163a6beb732SChristoph Hellwig static __be32 164a6beb732SChristoph Hellwig __nlm4svc_proc_cancel(struct svc_rqst *rqstp, struct nlm_res *resp) 165a6beb732SChristoph Hellwig { 166a6beb732SChristoph Hellwig struct nlm_args *argp = rqstp->rq_argp; 1671da177e4SLinus Torvalds struct nlm_host *host; 1681da177e4SLinus Torvalds struct nlm_file *file; 1691da177e4SLinus Torvalds 1701da177e4SLinus Torvalds dprintk("lockd: CANCEL called\n"); 1711da177e4SLinus Torvalds 1721da177e4SLinus Torvalds resp->cookie = argp->cookie; 1731da177e4SLinus Torvalds 1741da177e4SLinus Torvalds /* Don't accept requests during grace period */ 1755ccb0066SStanislav Kinsbursky if (locks_in_grace(SVC_NET(rqstp))) { 1761da177e4SLinus Torvalds resp->status = nlm_lck_denied_grace_period; 1771da177e4SLinus Torvalds return rpc_success; 1781da177e4SLinus Torvalds } 1791da177e4SLinus Torvalds 1801da177e4SLinus Torvalds /* Obtain client and file */ 1811da177e4SLinus Torvalds if ((resp->status = nlm4svc_retrieve_args(rqstp, argp, &host, &file))) 182d343fce1SNeilBrown return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; 1831da177e4SLinus Torvalds 1841da177e4SLinus Torvalds /* Try to cancel request. */ 1855ccb0066SStanislav Kinsbursky resp->status = nlmsvc_cancel_blocked(SVC_NET(rqstp), file, &argp->lock); 1861da177e4SLinus Torvalds 1871da177e4SLinus Torvalds dprintk("lockd: CANCEL status %d\n", ntohl(resp->status)); 188*89e0edfbSBenjamin Coddington nlmsvc_release_lockowner(&argp->lock); 18967216b94SChuck Lever nlmsvc_release_host(host); 1901da177e4SLinus Torvalds nlm_release_file(file); 1911da177e4SLinus Torvalds return rpc_success; 1921da177e4SLinus Torvalds } 1931da177e4SLinus Torvalds 194a6beb732SChristoph Hellwig static __be32 195a6beb732SChristoph Hellwig nlm4svc_proc_cancel(struct svc_rqst *rqstp) 196a6beb732SChristoph Hellwig { 197a6beb732SChristoph Hellwig return __nlm4svc_proc_cancel(rqstp, rqstp->rq_resp); 198a6beb732SChristoph Hellwig } 199a6beb732SChristoph Hellwig 2001da177e4SLinus Torvalds /* 2011da177e4SLinus Torvalds * UNLOCK: release a lock 2021da177e4SLinus Torvalds */ 2037111c66eSAl Viro static __be32 204a6beb732SChristoph Hellwig __nlm4svc_proc_unlock(struct svc_rqst *rqstp, struct nlm_res *resp) 2051da177e4SLinus Torvalds { 206a6beb732SChristoph Hellwig struct nlm_args *argp = rqstp->rq_argp; 2071da177e4SLinus Torvalds struct nlm_host *host; 2081da177e4SLinus Torvalds struct nlm_file *file; 2091da177e4SLinus Torvalds 2101da177e4SLinus Torvalds dprintk("lockd: UNLOCK called\n"); 2111da177e4SLinus Torvalds 2121da177e4SLinus Torvalds resp->cookie = argp->cookie; 2131da177e4SLinus Torvalds 2141da177e4SLinus Torvalds /* Don't accept new lock requests during grace period */ 2155ccb0066SStanislav Kinsbursky if (locks_in_grace(SVC_NET(rqstp))) { 2161da177e4SLinus Torvalds resp->status = nlm_lck_denied_grace_period; 2171da177e4SLinus Torvalds return rpc_success; 2181da177e4SLinus Torvalds } 2191da177e4SLinus Torvalds 2201da177e4SLinus Torvalds /* Obtain client and file */ 2211da177e4SLinus Torvalds if ((resp->status = nlm4svc_retrieve_args(rqstp, argp, &host, &file))) 222d343fce1SNeilBrown return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; 2231da177e4SLinus Torvalds 2241da177e4SLinus Torvalds /* Now try to remove the lock */ 2255ccb0066SStanislav Kinsbursky resp->status = nlmsvc_unlock(SVC_NET(rqstp), file, &argp->lock); 2261da177e4SLinus Torvalds 2271da177e4SLinus Torvalds dprintk("lockd: UNLOCK status %d\n", ntohl(resp->status)); 228*89e0edfbSBenjamin Coddington nlmsvc_release_lockowner(&argp->lock); 22967216b94SChuck Lever nlmsvc_release_host(host); 2301da177e4SLinus Torvalds nlm_release_file(file); 2311da177e4SLinus Torvalds return rpc_success; 2321da177e4SLinus Torvalds } 2331da177e4SLinus Torvalds 234a6beb732SChristoph Hellwig static __be32 235a6beb732SChristoph Hellwig nlm4svc_proc_unlock(struct svc_rqst *rqstp) 236a6beb732SChristoph Hellwig { 237a6beb732SChristoph Hellwig return __nlm4svc_proc_unlock(rqstp, rqstp->rq_resp); 238a6beb732SChristoph Hellwig } 239a6beb732SChristoph Hellwig 2401da177e4SLinus Torvalds /* 2411da177e4SLinus Torvalds * GRANTED: A server calls us to tell that a process' lock request 2421da177e4SLinus Torvalds * was granted 2431da177e4SLinus Torvalds */ 2447111c66eSAl Viro static __be32 245a6beb732SChristoph Hellwig __nlm4svc_proc_granted(struct svc_rqst *rqstp, struct nlm_res *resp) 2461da177e4SLinus Torvalds { 247a6beb732SChristoph Hellwig struct nlm_args *argp = rqstp->rq_argp; 248a6beb732SChristoph Hellwig 2491da177e4SLinus Torvalds resp->cookie = argp->cookie; 2501da177e4SLinus Torvalds 2511da177e4SLinus Torvalds dprintk("lockd: GRANTED called\n"); 252dcff09f1SChuck Lever resp->status = nlmclnt_grant(svc_addr(rqstp), &argp->lock); 2531da177e4SLinus Torvalds dprintk("lockd: GRANTED status %d\n", ntohl(resp->status)); 2541da177e4SLinus Torvalds return rpc_success; 2551da177e4SLinus Torvalds } 2561da177e4SLinus Torvalds 257a6beb732SChristoph Hellwig static __be32 258a6beb732SChristoph Hellwig nlm4svc_proc_granted(struct svc_rqst *rqstp) 259a6beb732SChristoph Hellwig { 260a6beb732SChristoph Hellwig return __nlm4svc_proc_granted(rqstp, rqstp->rq_resp); 261a6beb732SChristoph Hellwig } 262a6beb732SChristoph Hellwig 2631da177e4SLinus Torvalds /* 264d4716624STrond Myklebust * This is the generic lockd callback for async RPC calls 265d4716624STrond Myklebust */ 266d4716624STrond Myklebust static void nlm4svc_callback_exit(struct rpc_task *task, void *data) 267d4716624STrond Myklebust { 268c041b5ffSChuck Lever dprintk("lockd: %5u callback returned %d\n", task->tk_pid, 269d4716624STrond Myklebust -task->tk_status); 270d4716624STrond Myklebust } 271d4716624STrond Myklebust 272d4716624STrond Myklebust static void nlm4svc_callback_release(void *data) 273d4716624STrond Myklebust { 2747db836d4SChuck Lever nlmsvc_release_call(data); 275d4716624STrond Myklebust } 276d4716624STrond Myklebust 277d4716624STrond Myklebust static const struct rpc_call_ops nlm4svc_callback_ops = { 278d4716624STrond Myklebust .rpc_call_done = nlm4svc_callback_exit, 279d4716624STrond Myklebust .rpc_release = nlm4svc_callback_release, 280d4716624STrond Myklebust }; 281d4716624STrond Myklebust 282d4716624STrond Myklebust /* 2831da177e4SLinus Torvalds * `Async' versions of the above service routines. They aren't really, 2841da177e4SLinus Torvalds * because we send the callback before the reply proper. I hope this 2851da177e4SLinus Torvalds * doesn't break any clients. 2861da177e4SLinus Torvalds */ 287a6beb732SChristoph Hellwig static __be32 nlm4svc_callback(struct svc_rqst *rqstp, u32 proc, 288a6beb732SChristoph Hellwig __be32 (*func)(struct svc_rqst *, struct nlm_res *)) 289d4716624STrond Myklebust { 290a6beb732SChristoph Hellwig struct nlm_args *argp = rqstp->rq_argp; 291d4716624STrond Myklebust struct nlm_host *host; 292d4716624STrond Myklebust struct nlm_rqst *call; 2937111c66eSAl Viro __be32 stat; 294d4716624STrond Myklebust 295db4e4c9aSOlaf Kirch host = nlmsvc_lookup_host(rqstp, 296db4e4c9aSOlaf Kirch argp->lock.caller, 297db4e4c9aSOlaf Kirch argp->lock.len); 298d4716624STrond Myklebust if (host == NULL) 299d4716624STrond Myklebust return rpc_system_err; 300d4716624STrond Myklebust 301d4716624STrond Myklebust call = nlm_alloc_call(host); 302446945abSAl Viro nlmsvc_release_host(host); 303d4716624STrond Myklebust if (call == NULL) 304d4716624STrond Myklebust return rpc_system_err; 305d4716624STrond Myklebust 306a6beb732SChristoph Hellwig stat = func(rqstp, &call->a_res); 307d4716624STrond Myklebust if (stat != 0) { 3087db836d4SChuck Lever nlmsvc_release_call(call); 309d4716624STrond Myklebust return stat; 310d4716624STrond Myklebust } 311d4716624STrond Myklebust 312d4716624STrond Myklebust call->a_flags = RPC_TASK_ASYNC; 313d4716624STrond Myklebust if (nlm_async_reply(call, proc, &nlm4svc_callback_ops) < 0) 314d4716624STrond Myklebust return rpc_system_err; 315d4716624STrond Myklebust return rpc_success; 316d4716624STrond Myklebust } 317d4716624STrond Myklebust 318a6beb732SChristoph Hellwig static __be32 nlm4svc_proc_test_msg(struct svc_rqst *rqstp) 3191da177e4SLinus Torvalds { 3201da177e4SLinus Torvalds dprintk("lockd: TEST_MSG called\n"); 321a6beb732SChristoph Hellwig return nlm4svc_callback(rqstp, NLMPROC_TEST_RES, __nlm4svc_proc_test); 3221da177e4SLinus Torvalds } 3231da177e4SLinus Torvalds 324a6beb732SChristoph Hellwig static __be32 nlm4svc_proc_lock_msg(struct svc_rqst *rqstp) 3251da177e4SLinus Torvalds { 3261da177e4SLinus Torvalds dprintk("lockd: LOCK_MSG called\n"); 327a6beb732SChristoph Hellwig return nlm4svc_callback(rqstp, NLMPROC_LOCK_RES, __nlm4svc_proc_lock); 3281da177e4SLinus Torvalds } 3291da177e4SLinus Torvalds 330a6beb732SChristoph Hellwig static __be32 nlm4svc_proc_cancel_msg(struct svc_rqst *rqstp) 3311da177e4SLinus Torvalds { 3321da177e4SLinus Torvalds dprintk("lockd: CANCEL_MSG called\n"); 333a6beb732SChristoph Hellwig return nlm4svc_callback(rqstp, NLMPROC_CANCEL_RES, __nlm4svc_proc_cancel); 3341da177e4SLinus Torvalds } 3351da177e4SLinus Torvalds 336a6beb732SChristoph Hellwig static __be32 nlm4svc_proc_unlock_msg(struct svc_rqst *rqstp) 3371da177e4SLinus Torvalds { 3381da177e4SLinus Torvalds dprintk("lockd: UNLOCK_MSG called\n"); 339a6beb732SChristoph Hellwig return nlm4svc_callback(rqstp, NLMPROC_UNLOCK_RES, __nlm4svc_proc_unlock); 3401da177e4SLinus Torvalds } 3411da177e4SLinus Torvalds 342a6beb732SChristoph Hellwig static __be32 nlm4svc_proc_granted_msg(struct svc_rqst *rqstp) 3431da177e4SLinus Torvalds { 3441da177e4SLinus Torvalds dprintk("lockd: GRANTED_MSG called\n"); 345a6beb732SChristoph Hellwig return nlm4svc_callback(rqstp, NLMPROC_GRANTED_RES, __nlm4svc_proc_granted); 3461da177e4SLinus Torvalds } 3471da177e4SLinus Torvalds 3481da177e4SLinus Torvalds /* 3491da177e4SLinus Torvalds * SHARE: create a DOS share or alter existing share. 3501da177e4SLinus Torvalds */ 3517111c66eSAl Viro static __be32 352a6beb732SChristoph Hellwig nlm4svc_proc_share(struct svc_rqst *rqstp) 3531da177e4SLinus Torvalds { 354a6beb732SChristoph Hellwig struct nlm_args *argp = rqstp->rq_argp; 355a6beb732SChristoph Hellwig struct nlm_res *resp = rqstp->rq_resp; 3561da177e4SLinus Torvalds struct nlm_host *host; 3571da177e4SLinus Torvalds struct nlm_file *file; 3581da177e4SLinus Torvalds 3591da177e4SLinus Torvalds dprintk("lockd: SHARE called\n"); 3601da177e4SLinus Torvalds 3611da177e4SLinus Torvalds resp->cookie = argp->cookie; 3621da177e4SLinus Torvalds 3631da177e4SLinus Torvalds /* Don't accept new lock requests during grace period */ 3645ccb0066SStanislav Kinsbursky if (locks_in_grace(SVC_NET(rqstp)) && !argp->reclaim) { 3651da177e4SLinus Torvalds resp->status = nlm_lck_denied_grace_period; 3661da177e4SLinus Torvalds return rpc_success; 3671da177e4SLinus Torvalds } 3681da177e4SLinus Torvalds 3691da177e4SLinus Torvalds /* Obtain client and file */ 3701da177e4SLinus Torvalds if ((resp->status = nlm4svc_retrieve_args(rqstp, argp, &host, &file))) 371d343fce1SNeilBrown return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; 3721da177e4SLinus Torvalds 3731da177e4SLinus Torvalds /* Now try to create the share */ 3741da177e4SLinus Torvalds resp->status = nlmsvc_share_file(host, file, argp); 3751da177e4SLinus Torvalds 3761da177e4SLinus Torvalds dprintk("lockd: SHARE status %d\n", ntohl(resp->status)); 377*89e0edfbSBenjamin Coddington nlmsvc_release_lockowner(&argp->lock); 37867216b94SChuck Lever nlmsvc_release_host(host); 3791da177e4SLinus Torvalds nlm_release_file(file); 3801da177e4SLinus Torvalds return rpc_success; 3811da177e4SLinus Torvalds } 3821da177e4SLinus Torvalds 3831da177e4SLinus Torvalds /* 3841da177e4SLinus Torvalds * UNSHARE: Release a DOS share. 3851da177e4SLinus Torvalds */ 3867111c66eSAl Viro static __be32 387a6beb732SChristoph Hellwig nlm4svc_proc_unshare(struct svc_rqst *rqstp) 3881da177e4SLinus Torvalds { 389a6beb732SChristoph Hellwig struct nlm_args *argp = rqstp->rq_argp; 390a6beb732SChristoph Hellwig struct nlm_res *resp = rqstp->rq_resp; 3911da177e4SLinus Torvalds struct nlm_host *host; 3921da177e4SLinus Torvalds struct nlm_file *file; 3931da177e4SLinus Torvalds 3941da177e4SLinus Torvalds dprintk("lockd: UNSHARE called\n"); 3951da177e4SLinus Torvalds 3961da177e4SLinus Torvalds resp->cookie = argp->cookie; 3971da177e4SLinus Torvalds 3981da177e4SLinus Torvalds /* Don't accept requests during grace period */ 3995ccb0066SStanislav Kinsbursky if (locks_in_grace(SVC_NET(rqstp))) { 4001da177e4SLinus Torvalds resp->status = nlm_lck_denied_grace_period; 4011da177e4SLinus Torvalds return rpc_success; 4021da177e4SLinus Torvalds } 4031da177e4SLinus Torvalds 4041da177e4SLinus Torvalds /* Obtain client and file */ 4051da177e4SLinus Torvalds if ((resp->status = nlm4svc_retrieve_args(rqstp, argp, &host, &file))) 406d343fce1SNeilBrown return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; 4071da177e4SLinus Torvalds 4081da177e4SLinus Torvalds /* Now try to lock the file */ 4091da177e4SLinus Torvalds resp->status = nlmsvc_unshare_file(host, file, argp); 4101da177e4SLinus Torvalds 4111da177e4SLinus Torvalds dprintk("lockd: UNSHARE status %d\n", ntohl(resp->status)); 412*89e0edfbSBenjamin Coddington nlmsvc_release_lockowner(&argp->lock); 41367216b94SChuck Lever nlmsvc_release_host(host); 4141da177e4SLinus Torvalds nlm_release_file(file); 4151da177e4SLinus Torvalds return rpc_success; 4161da177e4SLinus Torvalds } 4171da177e4SLinus Torvalds 4181da177e4SLinus Torvalds /* 4191da177e4SLinus Torvalds * NM_LOCK: Create an unmonitored lock 4201da177e4SLinus Torvalds */ 4217111c66eSAl Viro static __be32 422a6beb732SChristoph Hellwig nlm4svc_proc_nm_lock(struct svc_rqst *rqstp) 4231da177e4SLinus Torvalds { 424a6beb732SChristoph Hellwig struct nlm_args *argp = rqstp->rq_argp; 425a6beb732SChristoph Hellwig 4261da177e4SLinus Torvalds dprintk("lockd: NM_LOCK called\n"); 4271da177e4SLinus Torvalds 4281da177e4SLinus Torvalds argp->monitor = 0; /* just clean the monitor flag */ 429a6beb732SChristoph Hellwig return nlm4svc_proc_lock(rqstp); 4301da177e4SLinus Torvalds } 4311da177e4SLinus Torvalds 4321da177e4SLinus Torvalds /* 4331da177e4SLinus Torvalds * FREE_ALL: Release all locks and shares held by client 4341da177e4SLinus Torvalds */ 4357111c66eSAl Viro static __be32 436a6beb732SChristoph Hellwig nlm4svc_proc_free_all(struct svc_rqst *rqstp) 4371da177e4SLinus Torvalds { 438a6beb732SChristoph Hellwig struct nlm_args *argp = rqstp->rq_argp; 4391da177e4SLinus Torvalds struct nlm_host *host; 4401da177e4SLinus Torvalds 4411da177e4SLinus Torvalds /* Obtain client */ 4421da177e4SLinus Torvalds if (nlm4svc_retrieve_args(rqstp, argp, &host, NULL)) 4431da177e4SLinus Torvalds return rpc_success; 4441da177e4SLinus Torvalds 4451da177e4SLinus Torvalds nlmsvc_free_host_resources(host); 44667216b94SChuck Lever nlmsvc_release_host(host); 4471da177e4SLinus Torvalds return rpc_success; 4481da177e4SLinus Torvalds } 4491da177e4SLinus Torvalds 4501da177e4SLinus Torvalds /* 4511da177e4SLinus Torvalds * SM_NOTIFY: private callback from statd (not part of official NLM proto) 4521da177e4SLinus Torvalds */ 4537111c66eSAl Viro static __be32 454a6beb732SChristoph Hellwig nlm4svc_proc_sm_notify(struct svc_rqst *rqstp) 4551da177e4SLinus Torvalds { 456a6beb732SChristoph Hellwig struct nlm_reboot *argp = rqstp->rq_argp; 457a6beb732SChristoph Hellwig 4581da177e4SLinus Torvalds dprintk("lockd: SM_NOTIFY called\n"); 459b85e4676SChuck Lever 460b85e4676SChuck Lever if (!nlm_privileged_requester(rqstp)) { 461ad06e4bdSChuck Lever char buf[RPC_MAX_ADDRBUFLEN]; 462ad06e4bdSChuck Lever printk(KERN_WARNING "lockd: rejected NSM callback from %s\n", 463ad06e4bdSChuck Lever svc_print_addr(rqstp, buf, sizeof(buf))); 4641da177e4SLinus Torvalds return rpc_system_err; 4651da177e4SLinus Torvalds } 4661da177e4SLinus Torvalds 4670ad95472SAndrey Ryabinin nlm_host_rebooted(SVC_NET(rqstp), argp); 4681da177e4SLinus Torvalds return rpc_success; 4691da177e4SLinus Torvalds } 4701da177e4SLinus Torvalds 4711da177e4SLinus Torvalds /* 4721da177e4SLinus Torvalds * client sent a GRANTED_RES, let's remove the associated block 4731da177e4SLinus Torvalds */ 4747111c66eSAl Viro static __be32 475a6beb732SChristoph Hellwig nlm4svc_proc_granted_res(struct svc_rqst *rqstp) 4761da177e4SLinus Torvalds { 477a6beb732SChristoph Hellwig struct nlm_res *argp = rqstp->rq_argp; 478a6beb732SChristoph Hellwig 4791da177e4SLinus Torvalds if (!nlmsvc_ops) 4801da177e4SLinus Torvalds return rpc_success; 4811da177e4SLinus Torvalds 4821da177e4SLinus Torvalds dprintk("lockd: GRANTED_RES called\n"); 4831da177e4SLinus Torvalds 48439be4502SOlaf Kirch nlmsvc_grant_reply(&argp->cookie, argp->status); 4851da177e4SLinus Torvalds return rpc_success; 4861da177e4SLinus Torvalds } 4871da177e4SLinus Torvalds 4881da177e4SLinus Torvalds 4891da177e4SLinus Torvalds /* 4901da177e4SLinus Torvalds * NLM Server procedures. 4911da177e4SLinus Torvalds */ 4921da177e4SLinus Torvalds 4931da177e4SLinus Torvalds #define nlm4svc_encode_norep nlm4svc_encode_void 4941da177e4SLinus Torvalds #define nlm4svc_decode_norep nlm4svc_decode_void 4951da177e4SLinus Torvalds #define nlm4svc_decode_testres nlm4svc_decode_void 4961da177e4SLinus Torvalds #define nlm4svc_decode_lockres nlm4svc_decode_void 4971da177e4SLinus Torvalds #define nlm4svc_decode_unlockres nlm4svc_decode_void 4981da177e4SLinus Torvalds #define nlm4svc_decode_cancelres nlm4svc_decode_void 4991da177e4SLinus Torvalds #define nlm4svc_decode_grantedres nlm4svc_decode_void 5001da177e4SLinus Torvalds 5011da177e4SLinus Torvalds #define nlm4svc_proc_none nlm4svc_proc_null 5021da177e4SLinus Torvalds #define nlm4svc_proc_test_res nlm4svc_proc_null 5031da177e4SLinus Torvalds #define nlm4svc_proc_lock_res nlm4svc_proc_null 5041da177e4SLinus Torvalds #define nlm4svc_proc_cancel_res nlm4svc_proc_null 5051da177e4SLinus Torvalds #define nlm4svc_proc_unlock_res nlm4svc_proc_null 5061da177e4SLinus Torvalds 5071da177e4SLinus Torvalds struct nlm_void { int dummy; }; 5081da177e4SLinus Torvalds 5091da177e4SLinus Torvalds #define PROC(name, xargt, xrest, argt, rest, respsize) \ 510a6beb732SChristoph Hellwig { .pc_func = nlm4svc_proc_##name, \ 511026fec7eSChristoph Hellwig .pc_decode = nlm4svc_decode_##xargt, \ 51263f8de37SChristoph Hellwig .pc_encode = nlm4svc_encode_##xrest, \ 5131da177e4SLinus Torvalds .pc_release = NULL, \ 5141da177e4SLinus Torvalds .pc_argsize = sizeof(struct nlm_##argt), \ 5151da177e4SLinus Torvalds .pc_ressize = sizeof(struct nlm_##rest), \ 5161da177e4SLinus Torvalds .pc_xdrressize = respsize, \ 5171da177e4SLinus Torvalds } 5181da177e4SLinus Torvalds #define Ck (1+XDR_QUADLEN(NLM_MAXCOOKIELEN)) /* cookie */ 5191da177e4SLinus Torvalds #define No (1+1024/4) /* netobj */ 5201da177e4SLinus Torvalds #define St 1 /* status */ 5211da177e4SLinus Torvalds #define Rg 4 /* range (offset + length) */ 522860bda29SChristoph Hellwig const struct svc_procedure nlmsvc_procedures4[] = { 5231da177e4SLinus Torvalds PROC(null, void, void, void, void, 1), 5241da177e4SLinus Torvalds PROC(test, testargs, testres, args, res, Ck+St+2+No+Rg), 5251da177e4SLinus Torvalds PROC(lock, lockargs, res, args, res, Ck+St), 5261da177e4SLinus Torvalds PROC(cancel, cancargs, res, args, res, Ck+St), 5271da177e4SLinus Torvalds PROC(unlock, unlockargs, res, args, res, Ck+St), 5281da177e4SLinus Torvalds PROC(granted, testargs, res, args, res, Ck+St), 5291da177e4SLinus Torvalds PROC(test_msg, testargs, norep, args, void, 1), 5301da177e4SLinus Torvalds PROC(lock_msg, lockargs, norep, args, void, 1), 5311da177e4SLinus Torvalds PROC(cancel_msg, cancargs, norep, args, void, 1), 5321da177e4SLinus Torvalds PROC(unlock_msg, unlockargs, norep, args, void, 1), 5331da177e4SLinus Torvalds PROC(granted_msg, testargs, norep, args, void, 1), 5341da177e4SLinus Torvalds PROC(test_res, testres, norep, res, void, 1), 5351da177e4SLinus Torvalds PROC(lock_res, lockres, norep, res, void, 1), 5361da177e4SLinus Torvalds PROC(cancel_res, cancelres, norep, res, void, 1), 5371da177e4SLinus Torvalds PROC(unlock_res, unlockres, norep, res, void, 1), 5381da177e4SLinus Torvalds PROC(granted_res, res, norep, res, void, 1), 5391da177e4SLinus Torvalds /* statd callback */ 5401da177e4SLinus Torvalds PROC(sm_notify, reboot, void, reboot, void, 1), 5411da177e4SLinus Torvalds PROC(none, void, void, void, void, 0), 5421da177e4SLinus Torvalds PROC(none, void, void, void, void, 0), 5431da177e4SLinus Torvalds PROC(none, void, void, void, void, 0), 5441da177e4SLinus Torvalds PROC(share, shareargs, shareres, args, res, Ck+St+1), 5451da177e4SLinus Torvalds PROC(unshare, shareargs, shareres, args, res, Ck+St+1), 5461da177e4SLinus Torvalds PROC(nm_lock, lockargs, res, args, res, Ck+St), 5471da177e4SLinus Torvalds PROC(free_all, notify, void, args, void, 1), 5481da177e4SLinus Torvalds 5491da177e4SLinus Torvalds }; 550