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