xref: /OK3568_Linux_fs/kernel/fs/nfsd/lockd.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * This file contains all the stubs needed when communicating with lockd.
4*4882a593Smuzhiyun  * This level of indirection is necessary so we can run nfsd+lockd without
5*4882a593Smuzhiyun  * requiring the nfs client to be compiled in/loaded, and vice versa.
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de>
8*4882a593Smuzhiyun  */
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun #include <linux/file.h>
11*4882a593Smuzhiyun #include <linux/lockd/bind.h>
12*4882a593Smuzhiyun #include "nfsd.h"
13*4882a593Smuzhiyun #include "vfs.h"
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun #define NFSDDBG_FACILITY		NFSDDBG_LOCKD
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun #ifdef CONFIG_LOCKD_V4
18*4882a593Smuzhiyun #define nlm_stale_fh	nlm4_stale_fh
19*4882a593Smuzhiyun #define nlm_failed	nlm4_failed
20*4882a593Smuzhiyun #else
21*4882a593Smuzhiyun #define nlm_stale_fh	nlm_lck_denied_nolocks
22*4882a593Smuzhiyun #define nlm_failed	nlm_lck_denied_nolocks
23*4882a593Smuzhiyun #endif
24*4882a593Smuzhiyun /*
25*4882a593Smuzhiyun  * Note: we hold the dentry use count while the file is open.
26*4882a593Smuzhiyun  */
27*4882a593Smuzhiyun static __be32
nlm_fopen(struct svc_rqst * rqstp,struct nfs_fh * f,struct file ** filp)28*4882a593Smuzhiyun nlm_fopen(struct svc_rqst *rqstp, struct nfs_fh *f, struct file **filp)
29*4882a593Smuzhiyun {
30*4882a593Smuzhiyun 	__be32		nfserr;
31*4882a593Smuzhiyun 	struct svc_fh	fh;
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun 	/* must initialize before using! but maxsize doesn't matter */
34*4882a593Smuzhiyun 	fh_init(&fh,0);
35*4882a593Smuzhiyun 	fh.fh_handle.fh_size = f->size;
36*4882a593Smuzhiyun 	memcpy((char*)&fh.fh_handle.fh_base, f->data, f->size);
37*4882a593Smuzhiyun 	fh.fh_export = NULL;
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun 	nfserr = nfsd_open(rqstp, &fh, S_IFREG, NFSD_MAY_LOCK, filp);
40*4882a593Smuzhiyun 	fh_put(&fh);
41*4882a593Smuzhiyun  	/* We return nlm error codes as nlm doesn't know
42*4882a593Smuzhiyun 	 * about nfsd, but nfsd does know about nlm..
43*4882a593Smuzhiyun 	 */
44*4882a593Smuzhiyun 	switch (nfserr) {
45*4882a593Smuzhiyun 	case nfs_ok:
46*4882a593Smuzhiyun 		return 0;
47*4882a593Smuzhiyun 	case nfserr_dropit:
48*4882a593Smuzhiyun 		return nlm_drop_reply;
49*4882a593Smuzhiyun 	case nfserr_stale:
50*4882a593Smuzhiyun 		return nlm_stale_fh;
51*4882a593Smuzhiyun 	default:
52*4882a593Smuzhiyun 		return nlm_failed;
53*4882a593Smuzhiyun 	}
54*4882a593Smuzhiyun }
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun static void
nlm_fclose(struct file * filp)57*4882a593Smuzhiyun nlm_fclose(struct file *filp)
58*4882a593Smuzhiyun {
59*4882a593Smuzhiyun 	fput(filp);
60*4882a593Smuzhiyun }
61*4882a593Smuzhiyun 
62*4882a593Smuzhiyun static const struct nlmsvc_binding nfsd_nlm_ops = {
63*4882a593Smuzhiyun 	.fopen		= nlm_fopen,		/* open file for locking */
64*4882a593Smuzhiyun 	.fclose		= nlm_fclose,		/* close file */
65*4882a593Smuzhiyun };
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun void
nfsd_lockd_init(void)68*4882a593Smuzhiyun nfsd_lockd_init(void)
69*4882a593Smuzhiyun {
70*4882a593Smuzhiyun 	dprintk("nfsd: initializing lockd\n");
71*4882a593Smuzhiyun 	nlmsvc_ops = &nfsd_nlm_ops;
72*4882a593Smuzhiyun }
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun void
nfsd_lockd_shutdown(void)75*4882a593Smuzhiyun nfsd_lockd_shutdown(void)
76*4882a593Smuzhiyun {
77*4882a593Smuzhiyun 	nlmsvc_ops = NULL;
78*4882a593Smuzhiyun }
79