2 * Copyright (c) 2008 Isilon Inc http://www.isilon.com/
3 * Authors: Doug Rabson <dfr@rabson.org>
4 * Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 MALLOC_DECLARE(M_NLM);
40 * This value is added to host system IDs when recording NFS client
41 * locks in the local lock manager.
43 #define NLM_SYSID_CLIENT 0x1000000
48 extern struct timeval nlm_zero_tv;
49 extern int nlm_nsm_state;
52 * Make a struct netobj.
54 extern void nlm_make_netobj(struct netobj *dst, caddr_t srt,
55 size_t srcsize, struct malloc_type *type);
58 * Copy a struct netobj.
60 extern void nlm_copy_netobj(struct netobj *dst, struct netobj *src,
61 struct malloc_type *type);
64 * Search for an existing NLM host that matches the given name
65 * (typically the caller_name element of an nlm4_lock). If none is
66 * found, create a new host. If 'addr' is non-NULL, record the remote
67 * address of the host so that we can call it back for async
68 * responses. If 'vers' is greater than zero then record the NLM
69 * program version to use to communicate with this client. The host
70 * reference count is incremented - the caller must call
71 * nlm_host_release when it has finished using it.
73 extern struct nlm_host *nlm_find_host_by_name(const char *name,
74 const struct sockaddr *addr, rpcvers_t vers);
77 * Search for an existing NLM host that matches the given remote
78 * address. If none is found, create a new host with the requested
79 * address and remember 'vers' as the NLM protocol version to use for
80 * that host. The host reference count is incremented - the caller
81 * must call nlm_host_release when it has finished using it.
83 extern struct nlm_host *nlm_find_host_by_addr(const struct sockaddr *addr,
87 * Register this NLM host with the local NSM so that we can be
88 * notified if it reboots.
90 extern void nlm_host_monitor(struct nlm_host *host, int state);
93 * Decrement the host reference count, freeing resources if the
94 * reference count reaches zero.
96 extern void nlm_host_release(struct nlm_host *host);
99 * Return an RPC client handle that can be used to talk to the NLM
100 * running on the given host.
102 extern CLIENT *nlm_host_get_rpc(struct nlm_host *host, bool_t isserver);
105 * Return the system ID for a host.
107 extern int nlm_host_get_sysid(struct nlm_host *host);
110 * Return the remote NSM state value for a host.
112 extern int nlm_host_get_state(struct nlm_host *host);
115 * When sending a blocking lock request, we need to track the request
116 * in our waiting lock list. We add an entry to the waiting list
117 * before we send the lock RPC so that we can cope with a granted
118 * message arriving at any time. Call this function before sending the
119 * lock rpc. If the lock succeeds, call nlm_deregister_wait_lock with
120 * the handle this function returns, otherwise nlm_wait_lock. Both
121 * will remove the entry from the waiting list.
123 extern void *nlm_register_wait_lock(struct nlm4_lock *lock, struct vnode *vp);
126 * Deregister a blocking lock request. Call this if the lock succeeded
129 extern void nlm_deregister_wait_lock(void *handle);
132 * Wait for a granted callback for a blocked lock request, waiting at
133 * most timo ticks. If no granted message is received within the
134 * timeout, return EWOULDBLOCK. If a signal interrupted the wait,
135 * return EINTR - the caller must arrange to send a cancellation to
136 * the server. In both cases, the request is removed from the waiting
139 extern int nlm_wait_lock(void *handle, int timo);
142 * Cancel any pending waits for this vnode - called on forcible unmounts.
144 extern void nlm_cancel_wait(struct vnode *vp);
147 * Called when a host restarts.
149 extern void nlm_sm_notify(nlm_sm_status *argp);
152 * Implementation for lock testing RPCs. If the request was handled
153 * successfully and rpcp is non-NULL, *rpcp is set to an RPC client
154 * handle which can be used to send an async rpc reply. Returns zero
155 * if the request was handled, or a suitable unix error code
158 extern int nlm_do_test(nlm4_testargs *argp, nlm4_testres *result,
159 struct svc_req *rqstp, CLIENT **rpcp);
162 * Implementation for lock setting RPCs. If the request was handled
163 * successfully and rpcp is non-NULL, *rpcp is set to an RPC client
164 * handle which can be used to send an async rpc reply. Returns zero
165 * if the request was handled, or a suitable unix error code
168 extern int nlm_do_lock(nlm4_lockargs *argp, nlm4_res *result,
169 struct svc_req *rqstp, bool_t monitor, CLIENT **rpcp);
172 * Implementation for cancelling a pending lock request. If the
173 * request was handled successfully and rpcp is non-NULL, *rpcp is set
174 * to an RPC client handle which can be used to send an async rpc
175 * reply. Returns zero if the request was handled, or a suitable unix
176 * error code otherwise.
178 extern int nlm_do_cancel(nlm4_cancargs *argp, nlm4_res *result,
179 struct svc_req *rqstp, CLIENT **rpcp);
182 * Implementation for unlocking RPCs. If the request was handled
183 * successfully and rpcp is non-NULL, *rpcp is set to an RPC client
184 * handle which can be used to send an async rpc reply. Returns zero
185 * if the request was handled, or a suitable unix error code
188 extern int nlm_do_unlock(nlm4_unlockargs *argp, nlm4_res *result,
189 struct svc_req *rqstp, CLIENT **rpcp);
192 * Implementation for granted RPCs. If the request was handled
193 * successfully and rpcp is non-NULL, *rpcp is set to an RPC client
194 * handle which can be used to send an async rpc reply. Returns zero
195 * if the request was handled, or a suitable unix error code
198 extern int nlm_do_granted(nlm4_testargs *argp, nlm4_res *result,
199 struct svc_req *rqstp, CLIENT **rpcp);
202 * Implementation for the granted result RPC. The client may reject the granted
203 * message, in which case we need to handle it appropriately.
205 extern void nlm_do_granted_res(nlm4_res *argp, struct svc_req *rqstp);
208 * Free all locks associated with the hostname argp->name.
210 extern void nlm_do_free_all(nlm4_notify *argp);
213 * Recover client lock state after a server reboot.
215 extern void nlm_client_recovery(struct nlm_host *);
218 * Interface from NFS client code to the NLM.
220 struct vop_advlock_args;
221 struct vop_reclaim_args;
222 extern int nlm_advlock(struct vop_advlock_args *ap);
223 extern int nlm_reclaim(struct vop_reclaim_args *ap);
226 * Acquire the next sysid for remote locks not handled by the NLM.
228 extern uint32_t nlm_acquire_next_sysid(void);