Home | History | Annotate | Line # | Download | only in common
nfsrvstate.h revision 1.1.1.1.4.2
      1  1.1.1.1.4.2  rmind /*	$NetBSD: nfsrvstate.h,v 1.1.1.1.4.2 2014/05/18 17:46:05 rmind Exp $	*/
      2  1.1.1.1.4.2  rmind /*-
      3  1.1.1.1.4.2  rmind  * Copyright (c) 2009 Rick Macklem, University of Guelph
      4  1.1.1.1.4.2  rmind  * All rights reserved.
      5  1.1.1.1.4.2  rmind  *
      6  1.1.1.1.4.2  rmind  * Redistribution and use in source and binary forms, with or without
      7  1.1.1.1.4.2  rmind  * modification, are permitted provided that the following conditions
      8  1.1.1.1.4.2  rmind  * are met:
      9  1.1.1.1.4.2  rmind  * 1. Redistributions of source code must retain the above copyright
     10  1.1.1.1.4.2  rmind  *    notice, this list of conditions and the following disclaimer.
     11  1.1.1.1.4.2  rmind  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.1.1.1.4.2  rmind  *    notice, this list of conditions and the following disclaimer in the
     13  1.1.1.1.4.2  rmind  *    documentation and/or other materials provided with the distribution.
     14  1.1.1.1.4.2  rmind  *
     15  1.1.1.1.4.2  rmind  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     16  1.1.1.1.4.2  rmind  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     17  1.1.1.1.4.2  rmind  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     18  1.1.1.1.4.2  rmind  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     19  1.1.1.1.4.2  rmind  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     20  1.1.1.1.4.2  rmind  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     21  1.1.1.1.4.2  rmind  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     22  1.1.1.1.4.2  rmind  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     23  1.1.1.1.4.2  rmind  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     24  1.1.1.1.4.2  rmind  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     25  1.1.1.1.4.2  rmind  * SUCH DAMAGE.
     26  1.1.1.1.4.2  rmind  *
     27  1.1.1.1.4.2  rmind  * FreeBSD: head/sys/fs/nfs/nfsrvstate.h 205941 2010-03-30 23:11:50Z rmacklem
     28  1.1.1.1.4.2  rmind  * $NetBSD: nfsrvstate.h,v 1.1.1.1.4.2 2014/05/18 17:46:05 rmind Exp $
     29  1.1.1.1.4.2  rmind  */
     30  1.1.1.1.4.2  rmind 
     31  1.1.1.1.4.2  rmind #ifndef _NFS_NFSRVSTATE_H_
     32  1.1.1.1.4.2  rmind #define	_NFS_NFSRVSTATE_H_
     33  1.1.1.1.4.2  rmind 
     34  1.1.1.1.4.2  rmind /*
     35  1.1.1.1.4.2  rmind  * Definitions for NFS V4 server state handling.
     36  1.1.1.1.4.2  rmind  */
     37  1.1.1.1.4.2  rmind 
     38  1.1.1.1.4.2  rmind /*
     39  1.1.1.1.4.2  rmind  * List heads for nfsclient, nfsstate and nfslockfile.
     40  1.1.1.1.4.2  rmind  * (Some systems seem to like to dynamically size these things, but I
     41  1.1.1.1.4.2  rmind  *  don't see any point in doing so for these ones.)
     42  1.1.1.1.4.2  rmind  */
     43  1.1.1.1.4.2  rmind LIST_HEAD(nfsclienthashhead, nfsclient);
     44  1.1.1.1.4.2  rmind LIST_HEAD(nfsstatehead, nfsstate);
     45  1.1.1.1.4.2  rmind LIST_HEAD(nfslockhead, nfslock);
     46  1.1.1.1.4.2  rmind LIST_HEAD(nfslockhashhead, nfslockfile);
     47  1.1.1.1.4.2  rmind 
     48  1.1.1.1.4.2  rmind /*
     49  1.1.1.1.4.2  rmind  * List head for nfsusrgrp.
     50  1.1.1.1.4.2  rmind  */
     51  1.1.1.1.4.2  rmind LIST_HEAD(nfsuserhashhead, nfsusrgrp);
     52  1.1.1.1.4.2  rmind TAILQ_HEAD(nfsuserlruhead, nfsusrgrp);
     53  1.1.1.1.4.2  rmind 
     54  1.1.1.1.4.2  rmind #define	NFSCLIENTHASH(id)						\
     55  1.1.1.1.4.2  rmind 	(&nfsclienthash[(id).lval[1] % NFSCLIENTHASHSIZE])
     56  1.1.1.1.4.2  rmind #define	NFSSTATEHASH(clp, id)						\
     57  1.1.1.1.4.2  rmind 	(&((clp)->lc_stateid[(id).other[2] % NFSSTATEHASHSIZE]))
     58  1.1.1.1.4.2  rmind #define	NFSUSERHASH(id)							\
     59  1.1.1.1.4.2  rmind 	(&nfsuserhash[(id) % NFSUSERHASHSIZE])
     60  1.1.1.1.4.2  rmind #define	NFSUSERNAMEHASH(p, l)						\
     61  1.1.1.1.4.2  rmind 	(&nfsusernamehash[((l)>=4?(*(p)+*((p)+1)+*((p)+2)+*((p)+3)):*(p)) \
     62  1.1.1.1.4.2  rmind 		% NFSUSERHASHSIZE])
     63  1.1.1.1.4.2  rmind #define	NFSGROUPHASH(id)						\
     64  1.1.1.1.4.2  rmind 	(&nfsgrouphash[(id) % NFSGROUPHASHSIZE])
     65  1.1.1.1.4.2  rmind #define	NFSGROUPNAMEHASH(p, l)						\
     66  1.1.1.1.4.2  rmind 	(&nfsgroupnamehash[((l)>=4?(*(p)+*((p)+1)+*((p)+2)+*((p)+3)):*(p)) \
     67  1.1.1.1.4.2  rmind 		% NFSGROUPHASHSIZE])
     68  1.1.1.1.4.2  rmind 
     69  1.1.1.1.4.2  rmind /*
     70  1.1.1.1.4.2  rmind  * Client server structure for V4. It is doubly linked into two lists.
     71  1.1.1.1.4.2  rmind  * The first is a hash table based on the clientid and the second is a
     72  1.1.1.1.4.2  rmind  * list of all clients maintained in LRU order.
     73  1.1.1.1.4.2  rmind  * The actual size malloc'd is large enough to accomodate the id string.
     74  1.1.1.1.4.2  rmind  */
     75  1.1.1.1.4.2  rmind struct nfsclient {
     76  1.1.1.1.4.2  rmind 	LIST_ENTRY(nfsclient) lc_hash;		/* Clientid hash list */
     77  1.1.1.1.4.2  rmind 	struct nfsstatehead lc_stateid[NFSSTATEHASHSIZE]; /* stateid hash */
     78  1.1.1.1.4.2  rmind 	struct nfsstatehead lc_open;		/* Open owner list */
     79  1.1.1.1.4.2  rmind 	struct nfsstatehead lc_deleg;		/* Delegations */
     80  1.1.1.1.4.2  rmind 	struct nfsstatehead lc_olddeleg;	/* and old delegations */
     81  1.1.1.1.4.2  rmind 	time_t		lc_expiry;		/* Expiry time (sec) */
     82  1.1.1.1.4.2  rmind 	time_t		lc_delegtime;		/* Old deleg expiry (sec) */
     83  1.1.1.1.4.2  rmind 	nfsquad_t	lc_clientid;		/* 64 bit clientid */
     84  1.1.1.1.4.2  rmind 	nfsquad_t	lc_confirm;		/* 64 bit confirm value */
     85  1.1.1.1.4.2  rmind 	u_int32_t	lc_program;		/* RPC Program # */
     86  1.1.1.1.4.2  rmind 	u_int32_t	lc_callback;		/* Callback id */
     87  1.1.1.1.4.2  rmind 	u_int32_t	lc_stateindex;		/* Current state index# */
     88  1.1.1.1.4.2  rmind 	u_int32_t	lc_statemaxindex;	/* Max state index# */
     89  1.1.1.1.4.2  rmind 	u_int32_t	lc_cbref;		/* Cnt of callbacks */
     90  1.1.1.1.4.2  rmind 	uid_t		lc_uid;			/* User credential */
     91  1.1.1.1.4.2  rmind 	gid_t		lc_gid;
     92  1.1.1.1.4.2  rmind 	u_int16_t	lc_namelen;
     93  1.1.1.1.4.2  rmind 	u_char		*lc_name;
     94  1.1.1.1.4.2  rmind 	struct nfssockreq lc_req;		/* Callback info */
     95  1.1.1.1.4.2  rmind 	u_short		lc_idlen;		/* Length of id string */
     96  1.1.1.1.4.2  rmind 	u_int32_t	lc_flags;		/* LCL_ flag bits */
     97  1.1.1.1.4.2  rmind 	u_char		lc_verf[NFSX_VERF];	 /* client verifier */
     98  1.1.1.1.4.2  rmind 	u_char		lc_id[1];		/* Malloc'd correct size */
     99  1.1.1.1.4.2  rmind };
    100  1.1.1.1.4.2  rmind 
    101  1.1.1.1.4.2  rmind #define	CLOPS_CONFIRM		0x0001
    102  1.1.1.1.4.2  rmind #define	CLOPS_RENEW		0x0002
    103  1.1.1.1.4.2  rmind #define	CLOPS_RENEWOP		0x0004
    104  1.1.1.1.4.2  rmind 
    105  1.1.1.1.4.2  rmind /*
    106  1.1.1.1.4.2  rmind  * Nfs state structure. I couldn't resist overloading this one, since
    107  1.1.1.1.4.2  rmind  * it makes cleanup, etc. simpler. These structures are used in four ways:
    108  1.1.1.1.4.2  rmind  * - open_owner structures chained off of nfsclient
    109  1.1.1.1.4.2  rmind  * - open file structures chained off an open_owner structure
    110  1.1.1.1.4.2  rmind  * - lock_owner structures chained off an open file structure
    111  1.1.1.1.4.2  rmind  * - delegated file structures chained off of nfsclient and nfslockfile
    112  1.1.1.1.4.2  rmind  * - the ls_list field is used for the chain it is in
    113  1.1.1.1.4.2  rmind  * - the ls_head structure is used to chain off the sibling structure
    114  1.1.1.1.4.2  rmind  *   (it is a union between an nfsstate and nfslock structure head)
    115  1.1.1.1.4.2  rmind  *    If it is a lockowner stateid, nfslock structures hang off it.
    116  1.1.1.1.4.2  rmind  * For the open file and lockowner cases, it is in the hash table in
    117  1.1.1.1.4.2  rmind  * nfsclient for stateid.
    118  1.1.1.1.4.2  rmind  */
    119  1.1.1.1.4.2  rmind struct nfsstate {
    120  1.1.1.1.4.2  rmind 	LIST_ENTRY(nfsstate)	ls_hash;	/* Hash list entry */
    121  1.1.1.1.4.2  rmind 	LIST_ENTRY(nfsstate)	ls_list;	/* List of opens/delegs */
    122  1.1.1.1.4.2  rmind 	LIST_ENTRY(nfsstate)	ls_file;	/* Opens/Delegs for a file */
    123  1.1.1.1.4.2  rmind 	union {
    124  1.1.1.1.4.2  rmind 		struct nfsstatehead	open; /* Opens list */
    125  1.1.1.1.4.2  rmind 		struct nfslockhead	lock; /* Locks list */
    126  1.1.1.1.4.2  rmind 	} ls_head;
    127  1.1.1.1.4.2  rmind 	nfsv4stateid_t		ls_stateid;	/* The state id */
    128  1.1.1.1.4.2  rmind 	u_int32_t		ls_seq;		/* seq id */
    129  1.1.1.1.4.2  rmind 	uid_t			ls_uid;		/* uid of locker */
    130  1.1.1.1.4.2  rmind 	u_int32_t		ls_flags;	/* Type of lock, etc. */
    131  1.1.1.1.4.2  rmind 	union {
    132  1.1.1.1.4.2  rmind 		struct nfsstate	*openowner;	/* Open only */
    133  1.1.1.1.4.2  rmind 		u_int32_t	opentolockseq;	/* Lock call only */
    134  1.1.1.1.4.2  rmind 		u_int32_t	noopens;	/* Openowner only */
    135  1.1.1.1.4.2  rmind 		struct {
    136  1.1.1.1.4.2  rmind 			u_quad_t	filerev; /* Delegations only */
    137  1.1.1.1.4.2  rmind 			time_t		expiry;
    138  1.1.1.1.4.2  rmind 			time_t		limit;
    139  1.1.1.1.4.2  rmind 			u_int64_t	compref;
    140  1.1.1.1.4.2  rmind 		} deleg;
    141  1.1.1.1.4.2  rmind 	} ls_un;
    142  1.1.1.1.4.2  rmind 	struct nfslockfile	*ls_lfp;	/* Back pointer */
    143  1.1.1.1.4.2  rmind 	struct nfsrvcache	*ls_op;		/* Op cache reference */
    144  1.1.1.1.4.2  rmind 	struct nfsclient	*ls_clp;	/* Back pointer */
    145  1.1.1.1.4.2  rmind 	u_short			ls_ownerlen;	/* Length of ls_owner */
    146  1.1.1.1.4.2  rmind 	u_char			ls_owner[1];	/* malloc'd the correct size */
    147  1.1.1.1.4.2  rmind };
    148  1.1.1.1.4.2  rmind #define	ls_lock			ls_head.lock
    149  1.1.1.1.4.2  rmind #define	ls_open			ls_head.open
    150  1.1.1.1.4.2  rmind #define	ls_opentolockseq	ls_un.opentolockseq
    151  1.1.1.1.4.2  rmind #define	ls_openowner		ls_un.openowner
    152  1.1.1.1.4.2  rmind #define	ls_openstp		ls_un.openowner
    153  1.1.1.1.4.2  rmind #define	ls_noopens		ls_un.noopens
    154  1.1.1.1.4.2  rmind #define	ls_filerev		ls_un.deleg.filerev
    155  1.1.1.1.4.2  rmind #define	ls_delegtime		ls_un.deleg.expiry
    156  1.1.1.1.4.2  rmind #define	ls_delegtimelimit	ls_un.deleg.limit
    157  1.1.1.1.4.2  rmind #define	ls_compref		ls_un.deleg.compref
    158  1.1.1.1.4.2  rmind 
    159  1.1.1.1.4.2  rmind /*
    160  1.1.1.1.4.2  rmind  * Nfs lock structure.
    161  1.1.1.1.4.2  rmind  * This structure is chained off of the nfsstate (the lockowner) and
    162  1.1.1.1.4.2  rmind  * nfslockfile (the file) structures, for the file and owner it
    163  1.1.1.1.4.2  rmind  * refers to. It holds flags and a byte range.
    164  1.1.1.1.4.2  rmind  * It also has back pointers to the associated lock_owner and lockfile.
    165  1.1.1.1.4.2  rmind  */
    166  1.1.1.1.4.2  rmind struct nfslock {
    167  1.1.1.1.4.2  rmind 	LIST_ENTRY(nfslock)	lo_lckowner;
    168  1.1.1.1.4.2  rmind 	LIST_ENTRY(nfslock)	lo_lckfile;
    169  1.1.1.1.4.2  rmind 	struct nfsstate		*lo_stp;
    170  1.1.1.1.4.2  rmind 	struct nfslockfile	*lo_lfp;
    171  1.1.1.1.4.2  rmind 	u_int64_t		lo_first;
    172  1.1.1.1.4.2  rmind 	u_int64_t		lo_end;
    173  1.1.1.1.4.2  rmind 	u_int32_t		lo_flags;
    174  1.1.1.1.4.2  rmind };
    175  1.1.1.1.4.2  rmind 
    176  1.1.1.1.4.2  rmind /*
    177  1.1.1.1.4.2  rmind  * Structure used to return a conflicting lock. (Must be large
    178  1.1.1.1.4.2  rmind  * enough for the largest lock owner we can have.)
    179  1.1.1.1.4.2  rmind  */
    180  1.1.1.1.4.2  rmind struct nfslockconflict {
    181  1.1.1.1.4.2  rmind 	nfsquad_t		cl_clientid;
    182  1.1.1.1.4.2  rmind 	u_int64_t		cl_first;
    183  1.1.1.1.4.2  rmind 	u_int64_t		cl_end;
    184  1.1.1.1.4.2  rmind 	u_int32_t		cl_flags;
    185  1.1.1.1.4.2  rmind 	u_short			cl_ownerlen;
    186  1.1.1.1.4.2  rmind 	u_char			cl_owner[NFSV4_OPAQUELIMIT];
    187  1.1.1.1.4.2  rmind };
    188  1.1.1.1.4.2  rmind 
    189  1.1.1.1.4.2  rmind /*
    190  1.1.1.1.4.2  rmind  * This structure is used to keep track of local locks that might need
    191  1.1.1.1.4.2  rmind  * to be rolled back.
    192  1.1.1.1.4.2  rmind  */
    193  1.1.1.1.4.2  rmind struct nfsrollback {
    194  1.1.1.1.4.2  rmind 	LIST_ENTRY(nfsrollback)	rlck_list;
    195  1.1.1.1.4.2  rmind 	uint64_t		rlck_first;
    196  1.1.1.1.4.2  rmind 	uint64_t		rlck_end;
    197  1.1.1.1.4.2  rmind 	int			rlck_type;
    198  1.1.1.1.4.2  rmind };
    199  1.1.1.1.4.2  rmind 
    200  1.1.1.1.4.2  rmind /*
    201  1.1.1.1.4.2  rmind  * This structure refers to a file for which lock(s) and/or open(s) exist.
    202  1.1.1.1.4.2  rmind  * Searched via hash table on file handle or found via the back pointer from an
    203  1.1.1.1.4.2  rmind  * open or lock owner.
    204  1.1.1.1.4.2  rmind  */
    205  1.1.1.1.4.2  rmind struct nfslockfile {
    206  1.1.1.1.4.2  rmind 	LIST_HEAD(, nfsstate)	lf_open;	/* Open list */
    207  1.1.1.1.4.2  rmind 	LIST_HEAD(, nfsstate)	lf_deleg;	/* Delegation list */
    208  1.1.1.1.4.2  rmind 	LIST_HEAD(, nfslock)	lf_lock;	/* Lock list */
    209  1.1.1.1.4.2  rmind 	LIST_HEAD(, nfslock)	lf_locallock;	/* Local lock list */
    210  1.1.1.1.4.2  rmind 	LIST_HEAD(, nfsrollback) lf_rollback;	/* Local lock rollback list */
    211  1.1.1.1.4.2  rmind 	LIST_ENTRY(nfslockfile)	lf_hash;	/* Hash list entry */
    212  1.1.1.1.4.2  rmind 	fhandle_t		lf_fh;		/* The file handle */
    213  1.1.1.1.4.2  rmind 	struct nfsv4lock	lf_locallock_lck; /* serialize local locking */
    214  1.1.1.1.4.2  rmind 	int			lf_usecount;	/* Ref count for locking */
    215  1.1.1.1.4.2  rmind };
    216  1.1.1.1.4.2  rmind 
    217  1.1.1.1.4.2  rmind /*
    218  1.1.1.1.4.2  rmind  * This structure is malloc'd an chained off hash lists for user/group
    219  1.1.1.1.4.2  rmind  * names.
    220  1.1.1.1.4.2  rmind  */
    221  1.1.1.1.4.2  rmind struct nfsusrgrp {
    222  1.1.1.1.4.2  rmind 	TAILQ_ENTRY(nfsusrgrp)	lug_lru;	/* LRU list */
    223  1.1.1.1.4.2  rmind 	LIST_ENTRY(nfsusrgrp)	lug_numhash;	/* Hash by id# */
    224  1.1.1.1.4.2  rmind 	LIST_ENTRY(nfsusrgrp)	lug_namehash;	/* and by name */
    225  1.1.1.1.4.2  rmind 	time_t			lug_expiry;	/* Expiry time in sec */
    226  1.1.1.1.4.2  rmind 	union {
    227  1.1.1.1.4.2  rmind 		uid_t		un_uid;		/* id# */
    228  1.1.1.1.4.2  rmind 		gid_t		un_gid;
    229  1.1.1.1.4.2  rmind 	} lug_un;
    230  1.1.1.1.4.2  rmind 	int			lug_namelen;	/* Name length */
    231  1.1.1.1.4.2  rmind 	u_char			lug_name[1];	/* malloc'd correct length */
    232  1.1.1.1.4.2  rmind };
    233  1.1.1.1.4.2  rmind #define	lug_uid		lug_un.un_uid
    234  1.1.1.1.4.2  rmind #define	lug_gid		lug_un.un_gid
    235  1.1.1.1.4.2  rmind 
    236  1.1.1.1.4.2  rmind /*
    237  1.1.1.1.4.2  rmind  * These structures are used for the stable storage restart stuff.
    238  1.1.1.1.4.2  rmind  */
    239  1.1.1.1.4.2  rmind /*
    240  1.1.1.1.4.2  rmind  * Record at beginning of file.
    241  1.1.1.1.4.2  rmind  */
    242  1.1.1.1.4.2  rmind struct nfsf_rec {
    243  1.1.1.1.4.2  rmind 	u_int32_t	lease;			/* Lease duration */
    244  1.1.1.1.4.2  rmind 	u_int32_t	numboots;		/* Number of boottimes */
    245  1.1.1.1.4.2  rmind };
    246  1.1.1.1.4.2  rmind 
    247  1.1.1.1.4.2  rmind #if defined(_KERNEL) || defined(KERNEL)
    248  1.1.1.1.4.2  rmind void nfsrv_cleanclient(struct nfsclient *, NFSPROC_T *);
    249  1.1.1.1.4.2  rmind void nfsrv_freedeleglist(struct nfsstatehead *);
    250  1.1.1.1.4.2  rmind #endif
    251  1.1.1.1.4.2  rmind 
    252  1.1.1.1.4.2  rmind #endif	/* _NFS_NFSRVSTATE_H_ */
    253