xref: /netbsd-src/sys/fs/nfs/common/nfsclstate.h (revision 0342d5080b4aa2e64ad6d1da61f9e3e072466754)
1*0342d508Spgoyette /*	$NetBSD: nfsclstate.h,v 1.2 2016/12/13 22:52:46 pgoyette Exp $	*/
26ca35587Sdholland /*-
36ca35587Sdholland  * Copyright (c) 2009 Rick Macklem, University of Guelph
46ca35587Sdholland  * All rights reserved.
56ca35587Sdholland  *
66ca35587Sdholland  * Redistribution and use in source and binary forms, with or without
76ca35587Sdholland  * modification, are permitted provided that the following conditions
86ca35587Sdholland  * are met:
96ca35587Sdholland  * 1. Redistributions of source code must retain the above copyright
106ca35587Sdholland  *    notice, this list of conditions and the following disclaimer.
116ca35587Sdholland  * 2. Redistributions in binary form must reproduce the above copyright
126ca35587Sdholland  *    notice, this list of conditions and the following disclaimer in the
136ca35587Sdholland  *    documentation and/or other materials provided with the distribution.
146ca35587Sdholland  *
156ca35587Sdholland  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
166ca35587Sdholland  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
176ca35587Sdholland  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
186ca35587Sdholland  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
196ca35587Sdholland  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
206ca35587Sdholland  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
216ca35587Sdholland  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
226ca35587Sdholland  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
236ca35587Sdholland  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
246ca35587Sdholland  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
256ca35587Sdholland  * SUCH DAMAGE.
266ca35587Sdholland  *
27e81f0ea2Spgoyette  * FreeBSD: head/sys/fs/nfs/nfsclstate.h 268115 2014-07-01 20:47:16Z rmacklem
28*0342d508Spgoyette  * $NetBSD: nfsclstate.h,v 1.2 2016/12/13 22:52:46 pgoyette Exp $
296ca35587Sdholland  */
306ca35587Sdholland 
316ca35587Sdholland #ifndef _NFS_NFSCLSTATE_H_
326ca35587Sdholland #define	_NFS_NFSCLSTATE_H_
336ca35587Sdholland 
346ca35587Sdholland /*
356ca35587Sdholland  * Definitions for NFS V4 client state handling.
366ca35587Sdholland  */
376ca35587Sdholland LIST_HEAD(nfsclopenhead, nfsclopen);
386ca35587Sdholland LIST_HEAD(nfscllockownerhead, nfscllockowner);
396ca35587Sdholland SLIST_HEAD(nfscllockownerfhhead, nfscllockownerfh);
406ca35587Sdholland LIST_HEAD(nfscllockhead, nfscllock);
416ca35587Sdholland LIST_HEAD(nfsclhead, nfsclclient);
426ca35587Sdholland LIST_HEAD(nfsclownerhead, nfsclowner);
436ca35587Sdholland TAILQ_HEAD(nfscldeleghead, nfscldeleg);
446ca35587Sdholland LIST_HEAD(nfscldeleghash, nfscldeleg);
456ca35587Sdholland TAILQ_HEAD(nfscllayouthead, nfscllayout);
466ca35587Sdholland LIST_HEAD(nfscllayouthash, nfscllayout);
476ca35587Sdholland LIST_HEAD(nfsclflayouthead, nfsclflayout);
486ca35587Sdholland LIST_HEAD(nfscldevinfohead, nfscldevinfo);
496ca35587Sdholland LIST_HEAD(nfsclrecalllayouthead, nfsclrecalllayout);
506ca35587Sdholland #define	NFSCLDELEGHASHSIZE	256
516ca35587Sdholland #define	NFSCLDELEGHASH(c, f, l)							\
526ca35587Sdholland 	(&((c)->nfsc_deleghash[ncl_hash((f), (l)) % NFSCLDELEGHASHSIZE]))
536ca35587Sdholland #define	NFSCLLAYOUTHASHSIZE	256
546ca35587Sdholland #define	NFSCLLAYOUTHASH(c, f, l)						\
556ca35587Sdholland 	(&((c)->nfsc_layouthash[ncl_hash((f), (l)) % NFSCLLAYOUTHASHSIZE]))
566ca35587Sdholland 
576ca35587Sdholland /* Structure for NFSv4.1 session stuff. */
586ca35587Sdholland struct nfsclsession {
59*0342d508Spgoyette 	kmutex_t	nfsess_mtx;
606ca35587Sdholland 	struct nfsslot	nfsess_cbslots[NFSV4_CBSLOTS];
616ca35587Sdholland 	nfsquad_t	nfsess_clientid;
62e81f0ea2Spgoyette 	SVCXPRT		*nfsess_xprt;		/* For backchannel callback */
636ca35587Sdholland 	uint32_t	nfsess_slotseq[64];	/* Max for 64bit nm_slots */
646ca35587Sdholland 	uint64_t	nfsess_slots;
656ca35587Sdholland 	uint32_t	nfsess_sequenceid;
666ca35587Sdholland 	uint32_t	nfsess_maxcache;	/* Max size for cached reply. */
676ca35587Sdholland 	uint16_t	nfsess_foreslots;
686ca35587Sdholland 	uint16_t	nfsess_backslots;
696ca35587Sdholland 	uint8_t		nfsess_sessionid[NFSX_V4SESSIONID];
706ca35587Sdholland };
716ca35587Sdholland 
726ca35587Sdholland /*
736ca35587Sdholland  * This structure holds the session, clientid and related information
746ca35587Sdholland  * needed for an NFSv4.1 Meta Data Server (MDS) or Data Server (DS).
756ca35587Sdholland  * It is malloc'd to the correct length.
766ca35587Sdholland  */
776ca35587Sdholland struct nfsclds {
786ca35587Sdholland 	TAILQ_ENTRY(nfsclds)	nfsclds_list;
796ca35587Sdholland 	struct nfsclsession	nfsclds_sess;
80*0342d508Spgoyette 	kmutex_t		nfsclds_mtx;
816ca35587Sdholland 	struct nfssockreq	*nfsclds_sockp;
826ca35587Sdholland 	time_t			nfsclds_expire;
836ca35587Sdholland 	uint16_t		nfsclds_flags;
846ca35587Sdholland 	uint16_t		nfsclds_servownlen;
856ca35587Sdholland 	uint8_t			nfsclds_verf[NFSX_VERF];
866ca35587Sdholland 	uint8_t			nfsclds_serverown[0];
876ca35587Sdholland };
886ca35587Sdholland 
896ca35587Sdholland /*
906ca35587Sdholland  * Flags for nfsclds_flags.
916ca35587Sdholland  */
926ca35587Sdholland #define	NFSCLDS_HASWRITEVERF	0x0001
936ca35587Sdholland #define	NFSCLDS_MDS		0x0002
946ca35587Sdholland #define	NFSCLDS_DS		0x0004
956ca35587Sdholland 
966ca35587Sdholland struct nfsclclient {
976ca35587Sdholland 	LIST_ENTRY(nfsclclient) nfsc_list;
986ca35587Sdholland 	struct nfsclownerhead	nfsc_owner;
996ca35587Sdholland 	struct nfscldeleghead	nfsc_deleg;
1006ca35587Sdholland 	struct nfscldeleghash	nfsc_deleghash[NFSCLDELEGHASHSIZE];
1016ca35587Sdholland 	struct nfscllayouthead	nfsc_layout;
1026ca35587Sdholland 	struct nfscllayouthash	nfsc_layouthash[NFSCLLAYOUTHASHSIZE];
1036ca35587Sdholland 	struct nfscldevinfohead	nfsc_devinfo;
1046ca35587Sdholland 	struct nfsv4lock	nfsc_lock;
1056ca35587Sdholland 	struct proc		*nfsc_renewthread;
1066ca35587Sdholland 	struct nfsmount		*nfsc_nmp;
1076ca35587Sdholland 	time_t			nfsc_expire;
1086ca35587Sdholland 	u_int32_t		nfsc_clientidrev;
1096ca35587Sdholland 	u_int32_t		nfsc_rev;
1106ca35587Sdholland 	u_int32_t		nfsc_renew;
1116ca35587Sdholland 	u_int32_t		nfsc_cbident;
1126ca35587Sdholland 	u_int16_t		nfsc_flags;
1136ca35587Sdholland 	u_int16_t		nfsc_idlen;
1146ca35587Sdholland 	u_int8_t		nfsc_id[1];	/* Malloc'd to correct length */
1156ca35587Sdholland };
1166ca35587Sdholland 
1176ca35587Sdholland /*
1186ca35587Sdholland  * Bits for nfsc_flags.
1196ca35587Sdholland  */
1206ca35587Sdholland #define	NFSCLFLAGS_INITED	0x0001
1216ca35587Sdholland #define	NFSCLFLAGS_HASCLIENTID	0x0002
1226ca35587Sdholland #define	NFSCLFLAGS_RECOVER	0x0004
1236ca35587Sdholland #define	NFSCLFLAGS_UMOUNT	0x0008
1246ca35587Sdholland #define	NFSCLFLAGS_HASTHREAD	0x0010
1256ca35587Sdholland #define	NFSCLFLAGS_AFINET6	0x0020
1266ca35587Sdholland #define	NFSCLFLAGS_EXPIREIT	0x0040
1276ca35587Sdholland #define	NFSCLFLAGS_FIRSTDELEG	0x0080
1286ca35587Sdholland #define	NFSCLFLAGS_GOTDELEG	0x0100
1296ca35587Sdholland #define	NFSCLFLAGS_RECVRINPROG	0x0200
1306ca35587Sdholland 
1316ca35587Sdholland struct nfsclowner {
1326ca35587Sdholland 	LIST_ENTRY(nfsclowner)	nfsow_list;
1336ca35587Sdholland 	struct nfsclopenhead	nfsow_open;
1346ca35587Sdholland 	struct nfsclclient	*nfsow_clp;
1356ca35587Sdholland 	u_int32_t		nfsow_seqid;
1366ca35587Sdholland 	u_int32_t		nfsow_defunct;
1376ca35587Sdholland 	struct nfsv4lock	nfsow_rwlock;
1386ca35587Sdholland 	u_int8_t		nfsow_owner[NFSV4CL_LOCKNAMELEN];
1396ca35587Sdholland };
1406ca35587Sdholland 
1416ca35587Sdholland /*
1426ca35587Sdholland  * MALLOC'd to the correct length to accommodate the file handle.
1436ca35587Sdholland  */
1446ca35587Sdholland struct nfscldeleg {
1456ca35587Sdholland 	TAILQ_ENTRY(nfscldeleg)	nfsdl_list;
1466ca35587Sdholland 	LIST_ENTRY(nfscldeleg)	nfsdl_hash;
1476ca35587Sdholland 	struct nfsclownerhead	nfsdl_owner;	/* locally issued state */
1486ca35587Sdholland 	struct nfscllockownerhead nfsdl_lock;
1496ca35587Sdholland 	nfsv4stateid_t		nfsdl_stateid;
1506ca35587Sdholland 	struct acl_entry	nfsdl_ace;	/* Delegation ace */
1516ca35587Sdholland 	struct nfsclclient	*nfsdl_clp;
1526ca35587Sdholland 	struct nfsv4lock	nfsdl_rwlock;	/* for active I/O ops */
1536ca35587Sdholland 	struct nfscred		nfsdl_cred;	/* Cred. used for Open */
1546ca35587Sdholland 	time_t			nfsdl_timestamp; /* used for stale cleanup */
1556ca35587Sdholland 	u_int64_t		nfsdl_sizelimit; /* Limit for file growth */
1566ca35587Sdholland 	u_int64_t		nfsdl_size;	/* saved copy of file size */
1576ca35587Sdholland 	u_int64_t		nfsdl_change;	/* and change attribute */
1586ca35587Sdholland 	struct timespec		nfsdl_modtime;	/* local modify time */
1596ca35587Sdholland 	u_int16_t		nfsdl_fhlen;
1606ca35587Sdholland 	u_int8_t		nfsdl_flags;
1616ca35587Sdholland 	u_int8_t		nfsdl_fh[1];	/* must be last */
1626ca35587Sdholland };
1636ca35587Sdholland 
1646ca35587Sdholland /*
1656ca35587Sdholland  * nfsdl_flags bits.
1666ca35587Sdholland  */
1676ca35587Sdholland #define	NFSCLDL_READ		0x01
1686ca35587Sdholland #define	NFSCLDL_WRITE		0x02
1696ca35587Sdholland #define	NFSCLDL_RECALL		0x04
1706ca35587Sdholland #define	NFSCLDL_NEEDRECLAIM	0x08
1716ca35587Sdholland #define	NFSCLDL_ZAPPED		0x10
1726ca35587Sdholland #define	NFSCLDL_MODTIMESET	0x20
1736ca35587Sdholland #define	NFSCLDL_DELEGRET	0x40
1746ca35587Sdholland 
1756ca35587Sdholland /*
1766ca35587Sdholland  * MALLOC'd to the correct length to accommodate the file handle.
1776ca35587Sdholland  */
1786ca35587Sdholland struct nfsclopen {
1796ca35587Sdholland 	LIST_ENTRY(nfsclopen)	nfso_list;
1806ca35587Sdholland 	struct nfscllockownerhead nfso_lock;
1816ca35587Sdholland 	nfsv4stateid_t		nfso_stateid;
1826ca35587Sdholland 	struct nfsclowner	*nfso_own;
1836ca35587Sdholland 	struct nfscred		nfso_cred;	/* Cred. used for Open */
1846ca35587Sdholland 	u_int32_t		nfso_mode;
1856ca35587Sdholland 	u_int32_t		nfso_opencnt;
1866ca35587Sdholland 	u_int16_t		nfso_fhlen;
1876ca35587Sdholland 	u_int8_t		nfso_posixlock;	/* 1 for POSIX type locking */
1886ca35587Sdholland 	u_int8_t		nfso_fh[1];	/* must be last */
1896ca35587Sdholland };
1906ca35587Sdholland 
1916ca35587Sdholland /*
1926ca35587Sdholland  * Return values for nfscl_open(). NFSCLOPEN_OK must == 0.
1936ca35587Sdholland  */
1946ca35587Sdholland #define	NFSCLOPEN_OK		0
1956ca35587Sdholland #define	NFSCLOPEN_DOOPEN	1
1966ca35587Sdholland #define	NFSCLOPEN_DOOPENDOWNGRADE 2
1976ca35587Sdholland #define	NFSCLOPEN_SETCRED	3
1986ca35587Sdholland 
1996ca35587Sdholland struct nfscllockowner {
2006ca35587Sdholland 	LIST_ENTRY(nfscllockowner) nfsl_list;
2016ca35587Sdholland 	struct nfscllockhead	nfsl_lock;
2026ca35587Sdholland 	struct nfsclopen	*nfsl_open;
2036ca35587Sdholland 	NFSPROC_T		*nfsl_inprog;
2046ca35587Sdholland 	nfsv4stateid_t		nfsl_stateid;
2056ca35587Sdholland 	int			nfsl_lockflags;
2066ca35587Sdholland 	u_int32_t		nfsl_seqid;
2076ca35587Sdholland 	struct nfsv4lock	nfsl_rwlock;
2086ca35587Sdholland 	u_int8_t		nfsl_owner[NFSV4CL_LOCKNAMELEN];
2096ca35587Sdholland 	u_int8_t		nfsl_openowner[NFSV4CL_LOCKNAMELEN];
2106ca35587Sdholland };
2116ca35587Sdholland 
2126ca35587Sdholland /*
2136ca35587Sdholland  * Byte range entry for the above lock owner.
2146ca35587Sdholland  */
2156ca35587Sdholland struct nfscllock {
2166ca35587Sdholland 	LIST_ENTRY(nfscllock)	nfslo_list;
2176ca35587Sdholland 	u_int64_t		nfslo_first;
2186ca35587Sdholland 	u_int64_t		nfslo_end;
2196ca35587Sdholland 	short			nfslo_type;
2206ca35587Sdholland };
2216ca35587Sdholland 
2226ca35587Sdholland /* This structure is used to collect a list of lockowners to free up. */
2236ca35587Sdholland struct nfscllockownerfh {
2246ca35587Sdholland 	SLIST_ENTRY(nfscllockownerfh)	nfslfh_list;
2256ca35587Sdholland 	struct nfscllockownerhead	nfslfh_lock;
2266ca35587Sdholland 	int				nfslfh_len;
2276ca35587Sdholland 	uint8_t				nfslfh_fh[NFSX_V4FHMAX];
2286ca35587Sdholland };
2296ca35587Sdholland 
2306ca35587Sdholland /*
2316ca35587Sdholland  * MALLOC'd to the correct length to accommodate the file handle.
2326ca35587Sdholland  */
2336ca35587Sdholland struct nfscllayout {
2346ca35587Sdholland 	TAILQ_ENTRY(nfscllayout)	nfsly_list;
2356ca35587Sdholland 	LIST_ENTRY(nfscllayout)		nfsly_hash;
2366ca35587Sdholland 	nfsv4stateid_t			nfsly_stateid;
2376ca35587Sdholland 	struct nfsv4lock		nfsly_lock;
2386ca35587Sdholland 	uint64_t			nfsly_filesid[2];
2396ca35587Sdholland 	uint64_t			nfsly_lastbyte;
2406ca35587Sdholland 	struct nfsclflayouthead		nfsly_flayread;
2416ca35587Sdholland 	struct nfsclflayouthead		nfsly_flayrw;
2426ca35587Sdholland 	struct nfsclrecalllayouthead	nfsly_recall;
2436ca35587Sdholland 	time_t				nfsly_timestamp;
2446ca35587Sdholland 	struct nfsclclient		*nfsly_clp;
2456ca35587Sdholland 	uint16_t			nfsly_flags;
2466ca35587Sdholland 	uint16_t			nfsly_fhlen;
2476ca35587Sdholland 	uint8_t				nfsly_fh[1];
2486ca35587Sdholland };
2496ca35587Sdholland 
2506ca35587Sdholland /*
2516ca35587Sdholland  * Flags for nfsly_flags.
2526ca35587Sdholland  */
2536ca35587Sdholland #define	NFSLY_FILES		0x0001
2546ca35587Sdholland #define	NFSLY_BLOCK		0x0002
2556ca35587Sdholland #define	NFSLY_OBJECT		0x0004
2566ca35587Sdholland #define	NFSLY_RECALL		0x0008
2576ca35587Sdholland #define	NFSLY_RECALLFILE	0x0010
2586ca35587Sdholland #define	NFSLY_RECALLFSID	0x0020
2596ca35587Sdholland #define	NFSLY_RECALLALL		0x0040
2606ca35587Sdholland #define	NFSLY_RETONCLOSE	0x0080
2616ca35587Sdholland #define	NFSLY_WRITTEN		0x0100	/* Has been used to write to a DS. */
2626ca35587Sdholland 
2636ca35587Sdholland /*
2646ca35587Sdholland  * MALLOC'd to the correct length to accommodate the file handle list.
2656ca35587Sdholland  * These hang off of nfsly_flayread and nfsly_flayrw, sorted in increasing
2666ca35587Sdholland  * offset order.
2676ca35587Sdholland  * The nfsly_flayread list holds the ones with iomode == NFSLAYOUTIOMODE_READ,
2686ca35587Sdholland  * whereas the nfsly_flayrw holds the ones with iomode == NFSLAYOUTIOMODE_RW.
2696ca35587Sdholland  */
2706ca35587Sdholland struct nfsclflayout {
2716ca35587Sdholland 	LIST_ENTRY(nfsclflayout)	nfsfl_list;
2726ca35587Sdholland 	uint8_t				nfsfl_dev[NFSX_V4DEVICEID];
2736ca35587Sdholland 	uint64_t			nfsfl_off;
2746ca35587Sdholland 	uint64_t			nfsfl_end;
2756ca35587Sdholland 	uint64_t			nfsfl_patoff;
2766ca35587Sdholland 	struct nfscldevinfo		*nfsfl_devp;
2776ca35587Sdholland 	uint32_t			nfsfl_iomode;
2786ca35587Sdholland 	uint32_t			nfsfl_util;
2796ca35587Sdholland 	uint32_t			nfsfl_stripe1;
2806ca35587Sdholland 	uint16_t			nfsfl_flags;
2816ca35587Sdholland 	uint16_t			nfsfl_fhcnt;
2826ca35587Sdholland 	struct nfsfh			*nfsfl_fh[1];	/* FH list for DS */
2836ca35587Sdholland };
2846ca35587Sdholland 
2856ca35587Sdholland /*
2866ca35587Sdholland  * Flags for nfsfl_flags.
2876ca35587Sdholland  */
2886ca35587Sdholland #define	NFSFL_RECALL	0x0001		/* File layout has been recalled */
2896ca35587Sdholland 
2906ca35587Sdholland /*
2916ca35587Sdholland  * Structure that is used to store a LAYOUTRECALL.
2926ca35587Sdholland  */
2936ca35587Sdholland struct nfsclrecalllayout {
2946ca35587Sdholland 	LIST_ENTRY(nfsclrecalllayout)	nfsrecly_list;
2956ca35587Sdholland 	uint64_t			nfsrecly_off;
2966ca35587Sdholland 	uint64_t			nfsrecly_len;
2976ca35587Sdholland 	int				nfsrecly_recalltype;
2986ca35587Sdholland 	uint32_t			nfsrecly_iomode;
2996ca35587Sdholland 	uint32_t			nfsrecly_stateseqid;
3006ca35587Sdholland };
3016ca35587Sdholland 
3026ca35587Sdholland /*
3036ca35587Sdholland  * Stores the NFSv4.1 Device Info. Malloc'd to the correct length to
3046ca35587Sdholland  * store the list of network connections and list of indices.
3056ca35587Sdholland  * nfsdi_data[] is allocated the following way:
3066ca35587Sdholland  * - nfsdi_addrcnt * struct nfsclds
3076ca35587Sdholland  * - stripe indices, each stored as one byte, since there can be many
3086ca35587Sdholland  *   of them. (This implies a limit of 256 on nfsdi_addrcnt, since the
3096ca35587Sdholland  *   indices select which address.)
3106ca35587Sdholland  */
3116ca35587Sdholland struct nfscldevinfo {
3126ca35587Sdholland 	LIST_ENTRY(nfscldevinfo)	nfsdi_list;
3136ca35587Sdholland 	uint8_t				nfsdi_deviceid[NFSX_V4DEVICEID];
3146ca35587Sdholland 	struct nfsclclient		*nfsdi_clp;
3156ca35587Sdholland 	uint32_t			nfsdi_refcnt;
3166ca35587Sdholland 	uint32_t			nfsdi_layoutrefs;
3176ca35587Sdholland 	uint16_t			nfsdi_stripecnt;
3186ca35587Sdholland 	uint16_t			nfsdi_addrcnt;
3196ca35587Sdholland 	struct nfsclds			*nfsdi_data[0];
3206ca35587Sdholland };
3216ca35587Sdholland 
3226ca35587Sdholland /* These inline functions return values from nfsdi_data[]. */
3236ca35587Sdholland /*
3246ca35587Sdholland  * Return a pointer to the address at "pos".
3256ca35587Sdholland  */
3266ca35587Sdholland static __inline struct nfsclds **
nfsfldi_addr(struct nfscldevinfo * ndi,int pos)3276ca35587Sdholland nfsfldi_addr(struct nfscldevinfo *ndi, int pos)
3286ca35587Sdholland {
3296ca35587Sdholland 
3306ca35587Sdholland 	if (pos >= ndi->nfsdi_addrcnt)
3316ca35587Sdholland 		return (NULL);
3326ca35587Sdholland 	return (&ndi->nfsdi_data[pos]);
3336ca35587Sdholland }
3346ca35587Sdholland 
3356ca35587Sdholland /*
3366ca35587Sdholland  * Return the Nth ("pos") stripe index.
3376ca35587Sdholland  */
3386ca35587Sdholland static __inline int
nfsfldi_stripeindex(struct nfscldevinfo * ndi,int pos)3396ca35587Sdholland nfsfldi_stripeindex(struct nfscldevinfo *ndi, int pos)
3406ca35587Sdholland {
3416ca35587Sdholland 	uint8_t *valp;
3426ca35587Sdholland 
3436ca35587Sdholland 	if (pos >= ndi->nfsdi_stripecnt)
3446ca35587Sdholland 		return (-1);
3456ca35587Sdholland 	valp = (uint8_t *)&ndi->nfsdi_data[ndi->nfsdi_addrcnt];
3466ca35587Sdholland 	valp += pos;
3476ca35587Sdholland 	return ((int)*valp);
3486ca35587Sdholland }
3496ca35587Sdholland 
3506ca35587Sdholland /*
3516ca35587Sdholland  * Set the Nth ("pos") stripe index to "val".
3526ca35587Sdholland  */
3536ca35587Sdholland static __inline void
nfsfldi_setstripeindex(struct nfscldevinfo * ndi,int pos,uint8_t val)3546ca35587Sdholland nfsfldi_setstripeindex(struct nfscldevinfo *ndi, int pos, uint8_t val)
3556ca35587Sdholland {
3566ca35587Sdholland 	uint8_t *valp;
3576ca35587Sdholland 
3586ca35587Sdholland 	if (pos >= ndi->nfsdi_stripecnt)
3596ca35587Sdholland 		return;
3606ca35587Sdholland 	valp = (uint8_t *)&ndi->nfsdi_data[ndi->nfsdi_addrcnt];
3616ca35587Sdholland 	valp += pos;
3626ca35587Sdholland 	*valp = val;
3636ca35587Sdholland }
3646ca35587Sdholland 
3656ca35587Sdholland /*
3666ca35587Sdholland  * Macro for incrementing the seqid#.
3676ca35587Sdholland  */
3686ca35587Sdholland #define	NFSCL_INCRSEQID(s, n)	do { 					\
3696ca35587Sdholland 	    if (((n)->nd_flag & ND_INCRSEQID))				\
3706ca35587Sdholland 		(s)++; 							\
3716ca35587Sdholland 	} while (0)
3726ca35587Sdholland 
3736ca35587Sdholland #endif	/* _NFS_NFSCLSTATE_H_ */
374