xref: /linux/include/linux/lockd/bind.h (revision d141ec2825b4d3ec52f27c43bdd864090159273a)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * linux/include/linux/lockd/bind.h
4  *
5  * This is the part of lockd visible to nfsd and the nfs client.
6  *
7  * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de>
8  */
9 
10 #ifndef LINUX_LOCKD_BIND_H
11 #define LINUX_LOCKD_BIND_H
12 
13 struct file_lock;
14 struct nfs_fh;
15 struct svc_rqst;
16 struct rpc_task;
17 struct rpc_clnt;
18 struct super_block;
19 struct module;
20 
21 /**
22  * struct nlmsvc_binding - lockd -> nfsd callback table
23  * @owner:  module that provides this binding.
24  * @fopen:  open a file by NFS file handle on behalf of an NLM request.
25  * @fclose: close a file that was previously opened via @fopen.
26  *          Implementations MUST be semantically equivalent to fput().
27  */
28 struct nlmsvc_binding {
29 	struct module	*owner;
30 	int		(*fopen)(struct svc_rqst *rqstp, struct nfs_fh *f,
31 				 struct file **filp, int flags);
32 	void		(*fclose)(struct file *filp);
33 };
34 
35 extern const struct nlmsvc_binding __rcu *nlmsvc_ops;
36 
37 /*
38  * Similar to nfs_client_initdata, but without the NFS-specific
39  * rpc_ops field.
40  */
41 struct nlmclnt_initdata {
42 	const char		*hostname;
43 	const struct sockaddr	*address;
44 	size_t			addrlen;
45 	unsigned short		protocol;
46 	u32			nfs_version;
47 	int			noresvport;
48 	struct net		*net;
49 	const struct nlmclnt_operations	*nlmclnt_ops;
50 	const struct cred	*cred;
51 };
52 
53 /*
54  * Functions exported by the lockd module
55  */
56 
57 extern struct nlm_host *nlmclnt_init(const struct nlmclnt_initdata *nlm_init);
58 extern void	nlmclnt_done(struct nlm_host *host);
59 extern struct rpc_clnt *nlmclnt_rpc_clnt(struct nlm_host *host);
60 extern void	nlmclnt_shutdown_rpc_clnt(struct nlm_host *host);
61 
62 /*
63  * NLM client operations provide a means to modify RPC processing of NLM
64  * requests.  Callbacks receive a pointer to data passed into the call to
65  * nlmclnt_proc().
66  */
67 struct nlmclnt_operations {
68 	/* Called on successful allocation of nlm_rqst, use for allocation or
69 	 * reference counting. */
70 	void (*nlmclnt_alloc_call)(void *);
71 
72 	/* Called in rpc_task_prepare for unlock.  A return value of true
73 	 * indicates the callback has put the task to sleep on a waitqueue
74 	 * and NLM should not call rpc_call_start(). */
75 	bool (*nlmclnt_unlock_prepare)(struct rpc_task*, void *);
76 
77 	/* Called when the nlm_rqst is freed, callbacks should clean up here */
78 	void (*nlmclnt_release_call)(void *);
79 };
80 
81 extern int	nlmclnt_proc(struct nlm_host *host, int cmd, struct file_lock *fl, void *data);
82 extern int	lockd_up(struct net *net, const struct cred *cred);
83 extern void	lockd_down(struct net *net);
84 
85 /*
86  * Cluster failover support
87  */
88 int nlmsvc_unlock_all_by_sb(struct super_block *sb);
89 int nlmsvc_unlock_all_by_ip(struct sockaddr *server_addr);
90 
91 #endif /* LINUX_LOCKD_BIND_H */
92