2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2008 Isilon Inc http://www.isilon.com/
5 * Authors: Doug Rabson <dfr@rabson.org>
6 * Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 MALLOC_DECLARE(M_NLM);
42 * This value is added to host system IDs when recording NFS client
43 * locks in the local lock manager.
45 #define NLM_SYSID_CLIENT 0x1000000
50 extern struct timeval nlm_zero_tv;
51 extern int nlm_nsm_state;
54 * Make a struct netobj.
56 extern void nlm_make_netobj(struct netobj *dst, caddr_t srt,
57 size_t srcsize, struct malloc_type *type);
60 * Copy a struct netobj.
62 extern void nlm_copy_netobj(struct netobj *dst, struct netobj *src,
63 struct malloc_type *type);
66 * Search for an existing NLM host that matches the given name
67 * (typically the caller_name element of an nlm4_lock). If none is
68 * found, create a new host. If 'addr' is non-NULL, record the remote
69 * address of the host so that we can call it back for async
70 * responses. If 'vers' is greater than zero then record the NLM
71 * program version to use to communicate with this client. The host
72 * reference count is incremented - the caller must call
73 * nlm_host_release when it has finished using it.
75 extern struct nlm_host *nlm_find_host_by_name(const char *name,
76 const struct sockaddr *addr, rpcvers_t vers);
79 * Search for an existing NLM host that matches the given remote
80 * address. If none is found, create a new host with the requested
81 * address and remember 'vers' as the NLM protocol version to use for
82 * that host. The host reference count is incremented - the caller
83 * must call nlm_host_release when it has finished using it.
85 extern struct nlm_host *nlm_find_host_by_addr(const struct sockaddr *addr,
89 * Register this NLM host with the local NSM so that we can be
90 * notified if it reboots.
92 extern void nlm_host_monitor(struct nlm_host *host, int state);
95 * Decrement the host reference count, freeing resources if the
96 * reference count reaches zero.
98 extern void nlm_host_release(struct nlm_host *host);
101 * Return an RPC client handle that can be used to talk to the NLM
102 * running on the given host.
104 extern CLIENT *nlm_host_get_rpc(struct nlm_host *host, bool_t isserver);
107 * Return the system ID for a host.
109 extern int nlm_host_get_sysid(struct nlm_host *host);
112 * Return the remote NSM state value for a host.
114 extern int nlm_host_get_state(struct nlm_host *host);
117 * When sending a blocking lock request, we need to track the request
118 * in our waiting lock list. We add an entry to the waiting list
119 * before we send the lock RPC so that we can cope with a granted
120 * message arriving at any time. Call this function before sending the
121 * lock rpc. If the lock succeeds, call nlm_deregister_wait_lock with
122 * the handle this function returns, otherwise nlm_wait_lock. Both
123 * will remove the entry from the waiting list.
125 extern void *nlm_register_wait_lock(struct nlm4_lock *lock, struct vnode *vp);
128 * Deregister a blocking lock request. Call this if the lock succeeded
131 extern void nlm_deregister_wait_lock(void *handle);
134 * Wait for a granted callback for a blocked lock request, waiting at
135 * most timo ticks. If no granted message is received within the
136 * timeout, return EWOULDBLOCK. If a signal interrupted the wait,
137 * return EINTR - the caller must arrange to send a cancellation to
138 * the server. In both cases, the request is removed from the waiting
141 extern int nlm_wait_lock(void *handle, int timo);
144 * Cancel any pending waits for this vnode - called on forcible unmounts.
146 extern void nlm_cancel_wait(struct vnode *vp);
149 * Called when a host restarts.
151 extern void nlm_sm_notify(nlm_sm_status *argp);
154 * Implementation for lock testing RPCs. If the request was handled
155 * successfully and rpcp is non-NULL, *rpcp is set to an RPC client
156 * handle which can be used to send an async rpc reply. Returns zero
157 * if the request was handled, or a suitable unix error code
160 extern int nlm_do_test(nlm4_testargs *argp, nlm4_testres *result,
161 struct svc_req *rqstp, CLIENT **rpcp);
164 * Implementation for lock setting RPCs. If the request was handled
165 * successfully and rpcp is non-NULL, *rpcp is set to an RPC client
166 * handle which can be used to send an async rpc reply. Returns zero
167 * if the request was handled, or a suitable unix error code
170 extern int nlm_do_lock(nlm4_lockargs *argp, nlm4_res *result,
171 struct svc_req *rqstp, bool_t monitor, CLIENT **rpcp);
174 * Implementation for cancelling a pending lock request. If the
175 * request was handled successfully and rpcp is non-NULL, *rpcp is set
176 * to an RPC client handle which can be used to send an async rpc
177 * reply. Returns zero if the request was handled, or a suitable unix
178 * error code otherwise.
180 extern int nlm_do_cancel(nlm4_cancargs *argp, nlm4_res *result,
181 struct svc_req *rqstp, CLIENT **rpcp);
184 * Implementation for unlocking RPCs. If the request was handled
185 * successfully and rpcp is non-NULL, *rpcp is set to an RPC client
186 * handle which can be used to send an async rpc reply. Returns zero
187 * if the request was handled, or a suitable unix error code
190 extern int nlm_do_unlock(nlm4_unlockargs *argp, nlm4_res *result,
191 struct svc_req *rqstp, CLIENT **rpcp);
194 * Implementation for granted RPCs. If the request was handled
195 * successfully and rpcp is non-NULL, *rpcp is set to an RPC client
196 * handle which can be used to send an async rpc reply. Returns zero
197 * if the request was handled, or a suitable unix error code
200 extern int nlm_do_granted(nlm4_testargs *argp, nlm4_res *result,
201 struct svc_req *rqstp, CLIENT **rpcp);
204 * Implementation for the granted result RPC. The client may reject the granted
205 * message, in which case we need to handle it appropriately.
207 extern void nlm_do_granted_res(nlm4_res *argp, struct svc_req *rqstp);
210 * Free all locks associated with the hostname argp->name.
212 extern void nlm_do_free_all(nlm4_notify *argp);
215 * Recover client lock state after a server reboot.
217 extern void nlm_client_recovery(struct nlm_host *);
220 * Interface from NFS client code to the NLM.
222 struct vop_advlock_args;
223 struct vop_reclaim_args;
224 extern int nlm_advlock(struct vop_advlock_args *ap);
225 extern int nlm_reclaim(struct vop_reclaim_args *ap);
228 * Acquire the next sysid for remote locks not handled by the NLM.
230 extern uint32_t nlm_acquire_next_sysid(void);