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