Home | History | Annotate | Line # | Download | only in nlm
      1 /*	$NetBSD: nlm.h,v 1.2 2016/07/07 06:55:42 msaitoh Exp $	*/
      2 /*-
      3  * Copyright (c) 2008 Isilon Inc http://www.isilon.com/
      4  * Authors: Doug Rabson <dfr (at) rabson.org>
      5  * Developed with Red Inc: Alfred Perlstein <alfred (at) freebsd.org>
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  * SUCH DAMAGE.
     27  *
     28  * FreeBSD: head/sys/nlm/nlm.h 197840 2009-10-07 19:50:14Z zml
     29  * $NetBSD: nlm.h,v 1.2 2016/07/07 06:55:42 msaitoh Exp $
     30  */
     31 
     32 #ifndef _NLM_NLM_H_
     33 #define _NLM_NLM_H_
     34 
     35 #ifdef _KERNEL
     36 
     37 #ifdef _SYS_MALLOC_H_
     38 MALLOC_DECLARE(M_NLM);
     39 #endif
     40 
     41 /*
     42  * This value is added to host system IDs when recording NFS client
     43  * locks in the local lock manager.
     44  */
     45 #define NLM_SYSID_CLIENT	0x1000000
     46 
     47 struct nlm_host;
     48 struct vnode;
     49 
     50 extern struct timeval nlm_zero_tv;
     51 extern int nlm_nsm_state;
     52 
     53 /*
     54  * Make a struct netobj.
     55  */
     56 extern void nlm_make_netobj(struct netobj *dst, caddr_t srt,
     57     size_t srcsize, struct malloc_type *type);
     58 
     59 /*
     60  * Copy a struct netobj.
     61  */
     62 extern void nlm_copy_netobj(struct netobj *dst, struct netobj *src,
     63     struct malloc_type *type);
     64 
     65 /*
     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.
     74  */
     75 extern struct nlm_host *nlm_find_host_by_name(const char *name,
     76     const struct sockaddr *addr, rpcvers_t vers);
     77 
     78 /*
     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.
     84  */
     85 extern struct nlm_host *nlm_find_host_by_addr(const struct sockaddr *addr,
     86     int vers);
     87 
     88 /*
     89  * Register this NLM host with the local NSM so that we can be
     90  * notified if it reboots.
     91  */
     92 extern void nlm_host_monitor(struct nlm_host *host, int state);
     93 
     94 /*
     95  * Decrement the host reference count, freeing resources if the
     96  * reference count reaches zero.
     97  */
     98 extern void nlm_host_release(struct nlm_host *host);
     99 
    100 /*
    101  * Return an RPC client handle that can be used to talk to the NLM
    102  * running on the given host.
    103  */
    104 extern CLIENT *nlm_host_get_rpc(struct nlm_host *host, bool_t isserver);
    105 
    106 /*
    107  * Return the system ID for a host.
    108  */
    109 extern int nlm_host_get_sysid(struct nlm_host *host);
    110 
    111 /*
    112  * Return the remote NSM state value for a host.
    113  */
    114 extern int nlm_host_get_state(struct nlm_host *host);
    115 
    116 /*
    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.
    124  */
    125 extern void *nlm_register_wait_lock(struct nlm4_lock *lock, struct vnode *vp);
    126 
    127 /*
    128  * Deregister a blocking lock request. Call this if the lock succeeded
    129  * without blocking.
    130  */
    131 extern void nlm_deregister_wait_lock(void *handle);
    132 
    133 /*
    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
    139  * list.
    140  */
    141 extern int nlm_wait_lock(void *handle, int timo);
    142 
    143 /*
    144  * Cancel any pending waits for this vnode - called on forcible unmounts.
    145  */
    146 extern void nlm_cancel_wait(struct vnode *vp);
    147 
    148 /*
    149  * Called when a host restarts.
    150  */
    151 extern void nlm_sm_notify(nlm_sm_status *argp);
    152 
    153 /*
    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
    158  * otherwise.
    159  */
    160 extern int nlm_do_test(nlm4_testargs *argp, nlm4_testres *result,
    161     struct svc_req *rqstp, CLIENT **rpcp);
    162 
    163 /*
    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
    168  * otherwise.
    169  */
    170 extern int nlm_do_lock(nlm4_lockargs *argp, nlm4_res *result,
    171     struct svc_req *rqstp, bool_t monitor, CLIENT **rpcp);
    172 
    173 /*
    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.
    179  */
    180 extern int nlm_do_cancel(nlm4_cancargs *argp, nlm4_res *result,
    181     struct svc_req *rqstp, CLIENT **rpcp);
    182 
    183 /*
    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
    188  * otherwise.
    189  */
    190 extern int nlm_do_unlock(nlm4_unlockargs *argp, nlm4_res *result,
    191     struct svc_req *rqstp, CLIENT **rpcp);
    192 
    193 /*
    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
    198  * otherwise.
    199  */
    200 extern int nlm_do_granted(nlm4_testargs *argp, nlm4_res *result,
    201     struct svc_req *rqstp, CLIENT **rpcp);
    202 
    203 /*
    204  * Implementation for the granted result RPC. The client may reject the granted
    205  * message, in which case we need to handle it appropriately.
    206  */
    207 extern void nlm_do_granted_res(nlm4_res *argp, struct svc_req *rqstp);
    208 
    209 /*
    210  * Free all locks associated with the hostname argp->name.
    211  */
    212 extern void nlm_do_free_all(nlm4_notify *argp);
    213 
    214 /*
    215  * Recover client lock state after a server reboot.
    216  */
    217 extern void nlm_client_recovery(struct nlm_host *);
    218 
    219 /*
    220  * Interface from NFS client code to the NLM.
    221  */
    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);
    226 
    227 /*
    228  * Acquire the next sysid for remote locks not handled by the NLM.
    229  */
    230 extern uint32_t nlm_acquire_next_sysid(void);
    231 
    232 #endif
    233 
    234 #endif
    235