1dfdcada3SDoug Rabson /*- 2dfdcada3SDoug Rabson * Copyright (c) 2008 Isilon Inc http://www.isilon.com/ 3dfdcada3SDoug Rabson * Authors: Doug Rabson <dfr@rabson.org> 4dfdcada3SDoug Rabson * Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org> 5dfdcada3SDoug Rabson * 6dfdcada3SDoug Rabson * Redistribution and use in source and binary forms, with or without 7dfdcada3SDoug Rabson * modification, are permitted provided that the following conditions 8dfdcada3SDoug Rabson * are met: 9dfdcada3SDoug Rabson * 1. Redistributions of source code must retain the above copyright 10dfdcada3SDoug Rabson * notice, this list of conditions and the following disclaimer. 11dfdcada3SDoug Rabson * 2. Redistributions in binary form must reproduce the above copyright 12dfdcada3SDoug Rabson * notice, this list of conditions and the following disclaimer in the 13dfdcada3SDoug Rabson * documentation and/or other materials provided with the distribution. 14dfdcada3SDoug Rabson * 15dfdcada3SDoug Rabson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16dfdcada3SDoug Rabson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17dfdcada3SDoug Rabson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18dfdcada3SDoug Rabson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19dfdcada3SDoug Rabson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20dfdcada3SDoug Rabson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21dfdcada3SDoug Rabson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22dfdcada3SDoug Rabson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23dfdcada3SDoug Rabson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24dfdcada3SDoug Rabson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25dfdcada3SDoug Rabson * SUCH DAMAGE. 26dfdcada3SDoug Rabson * 27dfdcada3SDoug Rabson * $FreeBSD$ 28dfdcada3SDoug Rabson */ 29dfdcada3SDoug Rabson 30dfdcada3SDoug Rabson #ifndef _NLM_NLM_H_ 31dfdcada3SDoug Rabson #define _NLM_NLM_H_ 32dfdcada3SDoug Rabson 33dfdcada3SDoug Rabson #ifdef _KERNEL 34dfdcada3SDoug Rabson 35dfdcada3SDoug Rabson #ifdef _SYS_MALLOC_H_ 36dfdcada3SDoug Rabson MALLOC_DECLARE(M_NLM); 37dfdcada3SDoug Rabson #endif 38dfdcada3SDoug Rabson 39c675522fSDoug Rabson /* 40c675522fSDoug Rabson * This value is added to host system IDs when recording NFS client 41c675522fSDoug Rabson * locks in the local lock manager. 42c675522fSDoug Rabson */ 43c675522fSDoug Rabson #define NLM_SYSID_CLIENT 0x1000000 44c675522fSDoug Rabson 45dfdcada3SDoug Rabson struct nlm_host; 46c675522fSDoug Rabson struct vnode; 47c675522fSDoug Rabson 48c675522fSDoug Rabson extern struct timeval nlm_zero_tv; 49c675522fSDoug Rabson extern int nlm_nsm_state; 50dfdcada3SDoug Rabson 51dfdcada3SDoug Rabson /* 52dfdcada3SDoug Rabson * Copy a struct netobj. 53dfdcada3SDoug Rabson */ 54dfdcada3SDoug Rabson extern void nlm_copy_netobj(struct netobj *dst, struct netobj *src, 55dfdcada3SDoug Rabson struct malloc_type *type); 56dfdcada3SDoug Rabson 57dfdcada3SDoug Rabson /* 58dfdcada3SDoug Rabson * Search for an existing NLM host that matches the given name 59dfdcada3SDoug Rabson * (typically the caller_name element of an nlm4_lock). If none is 60c675522fSDoug Rabson * found, create a new host. If 'addr' is non-NULL, record the remote 61dfdcada3SDoug Rabson * address of the host so that we can call it back for async 62c675522fSDoug Rabson * responses. If 'vers' is greater than zero then record the NLM 63c675522fSDoug Rabson * program version to use to communicate with this client. The host 64c675522fSDoug Rabson * reference count is incremented - the caller must call 65c675522fSDoug Rabson * nlm_host_release when it has finished using it. 66dfdcada3SDoug Rabson */ 67dfdcada3SDoug Rabson extern struct nlm_host *nlm_find_host_by_name(const char *name, 68c675522fSDoug Rabson const struct sockaddr *addr, rpcvers_t vers); 69dfdcada3SDoug Rabson 70dfdcada3SDoug Rabson /* 71dfdcada3SDoug Rabson * Search for an existing NLM host that matches the given remote 72dfdcada3SDoug Rabson * address. If none is found, create a new host with the requested 73dfdcada3SDoug Rabson * address and remember 'vers' as the NLM protocol version to use for 74c675522fSDoug Rabson * that host. The host reference count is incremented - the caller 75c675522fSDoug Rabson * must call nlm_host_release when it has finished using it. 76dfdcada3SDoug Rabson */ 77dfdcada3SDoug Rabson extern struct nlm_host *nlm_find_host_by_addr(const struct sockaddr *addr, 78dfdcada3SDoug Rabson int vers); 79dfdcada3SDoug Rabson 80dfdcada3SDoug Rabson /* 81c675522fSDoug Rabson * Register this NLM host with the local NSM so that we can be 82c675522fSDoug Rabson * notified if it reboots. 83c675522fSDoug Rabson */ 84c675522fSDoug Rabson extern void nlm_host_monitor(struct nlm_host *host, int state); 85c675522fSDoug Rabson 86c675522fSDoug Rabson /* 87c675522fSDoug Rabson * Decrement the host reference count, freeing resources if the 88c675522fSDoug Rabson * reference count reaches zero. 89c675522fSDoug Rabson */ 90c675522fSDoug Rabson extern void nlm_host_release(struct nlm_host *host); 91c675522fSDoug Rabson 92c675522fSDoug Rabson /* 93dfdcada3SDoug Rabson * Return an RPC client handle that can be used to talk to the NLM 94dfdcada3SDoug Rabson * running on the given host. 95dfdcada3SDoug Rabson */ 96dfdcada3SDoug Rabson extern CLIENT *nlm_host_get_rpc(struct nlm_host *host); 97dfdcada3SDoug Rabson 98dfdcada3SDoug Rabson /* 99c675522fSDoug Rabson * Return the system ID for a host. 100c675522fSDoug Rabson */ 101c675522fSDoug Rabson extern int nlm_host_get_sysid(struct nlm_host *host); 102c675522fSDoug Rabson 103c675522fSDoug Rabson /* 104c675522fSDoug Rabson * Return the remote NSM state value for a host. 105c675522fSDoug Rabson */ 106c675522fSDoug Rabson extern int nlm_host_get_state(struct nlm_host *host); 107c675522fSDoug Rabson 108c675522fSDoug Rabson /* 109c675522fSDoug Rabson * When sending a blocking lock request, we need to track the request 110c675522fSDoug Rabson * in our waiting lock list. We add an entry to the waiting list 111c675522fSDoug Rabson * before we send the lock RPC so that we can cope with a granted 112c675522fSDoug Rabson * message arriving at any time. Call this function before sending the 113c675522fSDoug Rabson * lock rpc. If the lock succeeds, call nlm_deregister_wait_lock with 114c675522fSDoug Rabson * the handle this function returns, otherwise nlm_wait_lock. Both 115c675522fSDoug Rabson * will remove the entry from the waiting list. 116c675522fSDoug Rabson */ 117c675522fSDoug Rabson extern void *nlm_register_wait_lock(struct nlm4_lock *lock, struct vnode *vp); 118c675522fSDoug Rabson 119c675522fSDoug Rabson /* 120c675522fSDoug Rabson * Deregister a blocking lock request. Call this if the lock succeeded 121c675522fSDoug Rabson * without blocking. 122c675522fSDoug Rabson */ 123c675522fSDoug Rabson extern void nlm_deregister_wait_lock(void *handle); 124c675522fSDoug Rabson 125c675522fSDoug Rabson /* 126c675522fSDoug Rabson * Wait for a granted callback for a blocked lock request, waiting at 127c675522fSDoug Rabson * most timo ticks. If no granted message is received within the 128c675522fSDoug Rabson * timeout, return EWOULDBLOCK. If a signal interrupted the wait, 129c675522fSDoug Rabson * return EINTR - the caller must arrange to send a cancellation to 130c675522fSDoug Rabson * the server. In both cases, the request is removed from the waiting 131c675522fSDoug Rabson * list. 132c675522fSDoug Rabson */ 133c675522fSDoug Rabson extern int nlm_wait_lock(void *handle, int timo); 134c675522fSDoug Rabson 135c675522fSDoug Rabson /* 136c675522fSDoug Rabson * Cancel any pending waits for this vnode - called on forcible unmounts. 137c675522fSDoug Rabson */ 138c675522fSDoug Rabson extern void nlm_cancel_wait(struct vnode *vp); 139c675522fSDoug Rabson 140c675522fSDoug Rabson /* 141dfdcada3SDoug Rabson * Called when a host restarts. 142dfdcada3SDoug Rabson */ 143dfdcada3SDoug Rabson extern void nlm_sm_notify(nlm_sm_status *argp); 144dfdcada3SDoug Rabson 145dfdcada3SDoug Rabson /* 146c675522fSDoug Rabson * Implementation for lock testing RPCs. If the request was handled 147c675522fSDoug Rabson * successfully and rpcp is non-NULL, *rpcp is set to an RPC client 148c675522fSDoug Rabson * handle which can be used to send an async rpc reply. Returns zero 149c675522fSDoug Rabson * if the request was handled, or a suitable unix error code 150c675522fSDoug Rabson * otherwise. 151dfdcada3SDoug Rabson */ 152c675522fSDoug Rabson extern int nlm_do_test(nlm4_testargs *argp, nlm4_testres *result, 153c675522fSDoug Rabson struct svc_req *rqstp, CLIENT **rpcp); 154dfdcada3SDoug Rabson 155dfdcada3SDoug Rabson /* 156c675522fSDoug Rabson * Implementation for lock setting RPCs. If the request was handled 157c675522fSDoug Rabson * successfully and rpcp is non-NULL, *rpcp is set to an RPC client 158c675522fSDoug Rabson * handle which can be used to send an async rpc reply. Returns zero 159c675522fSDoug Rabson * if the request was handled, or a suitable unix error code 160c675522fSDoug Rabson * otherwise. 161dfdcada3SDoug Rabson */ 162c675522fSDoug Rabson extern int nlm_do_lock(nlm4_lockargs *argp, nlm4_res *result, 163c675522fSDoug Rabson struct svc_req *rqstp, bool_t monitor, CLIENT **rpcp); 164dfdcada3SDoug Rabson 165dfdcada3SDoug Rabson /* 166c675522fSDoug Rabson * Implementation for cancelling a pending lock request. If the 167c675522fSDoug Rabson * request was handled successfully and rpcp is non-NULL, *rpcp is set 168c675522fSDoug Rabson * to an RPC client handle which can be used to send an async rpc 169c675522fSDoug Rabson * reply. Returns zero if the request was handled, or a suitable unix 170c675522fSDoug Rabson * error code otherwise. 171dfdcada3SDoug Rabson */ 172c675522fSDoug Rabson extern int nlm_do_cancel(nlm4_cancargs *argp, nlm4_res *result, 173c675522fSDoug Rabson struct svc_req *rqstp, CLIENT **rpcp); 174dfdcada3SDoug Rabson 175dfdcada3SDoug Rabson /* 176c675522fSDoug Rabson * Implementation for unlocking RPCs. If the request was handled 177c675522fSDoug Rabson * successfully and rpcp is non-NULL, *rpcp is set to an RPC client 178c675522fSDoug Rabson * handle which can be used to send an async rpc reply. Returns zero 179c675522fSDoug Rabson * if the request was handled, or a suitable unix error code 180c675522fSDoug Rabson * otherwise. 181dfdcada3SDoug Rabson */ 182c675522fSDoug Rabson extern int nlm_do_unlock(nlm4_unlockargs *argp, nlm4_res *result, 183c675522fSDoug Rabson struct svc_req *rqstp, CLIENT **rpcp); 184c675522fSDoug Rabson 185c675522fSDoug Rabson /* 186c675522fSDoug Rabson * Implementation for granted RPCs. If the request was handled 187c675522fSDoug Rabson * successfully and rpcp is non-NULL, *rpcp is set to an RPC client 188c675522fSDoug Rabson * handle which can be used to send an async rpc reply. Returns zero 189c675522fSDoug Rabson * if the request was handled, or a suitable unix error code 190c675522fSDoug Rabson * otherwise. 191c675522fSDoug Rabson */ 192c675522fSDoug Rabson extern int nlm_do_granted(nlm4_testargs *argp, nlm4_res *result, 193c675522fSDoug Rabson struct svc_req *rqstp, CLIENT **rpcp); 194dfdcada3SDoug Rabson 195dfdcada3SDoug Rabson /* 196dfdcada3SDoug Rabson * Free all locks associated with the hostname argp->name. 197dfdcada3SDoug Rabson */ 198dfdcada3SDoug Rabson extern void nlm_do_free_all(nlm4_notify *argp); 199dfdcada3SDoug Rabson 200dfdcada3SDoug Rabson /* 201c675522fSDoug Rabson * Recover client lock state after a server reboot. 202dfdcada3SDoug Rabson */ 203c675522fSDoug Rabson extern void nlm_client_recovery(struct nlm_host *); 204c675522fSDoug Rabson 205c675522fSDoug Rabson /* 206c675522fSDoug Rabson * Interface from NFS client code to the NLM. 207c675522fSDoug Rabson */ 208c675522fSDoug Rabson struct vop_advlock_args; 209c675522fSDoug Rabson struct vop_reclaim_args; 210c675522fSDoug Rabson extern int nlm_advlock(struct vop_advlock_args *ap); 211c675522fSDoug Rabson extern int nlm_reclaim(struct vop_reclaim_args *ap); 212dfdcada3SDoug Rabson 213dfdcada3SDoug Rabson #endif 214dfdcada3SDoug Rabson 215dfdcada3SDoug Rabson #endif 216