xref: /illumos-gate/usr/src/uts/common/nfs/nfs4x.h (revision 0250c53ad267726f2438e3c6556199a0bbf588a2)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2017 RackTop Systems.
14  */
15 
16 #ifndef _NFS4X_H
17 #define	_NFS4X_H
18 
19 #ifdef	__cplusplus
20 extern "C" {
21 #endif
22 
23 #ifdef _KERNEL
24 
25 #include <sys/cred.h>
26 #include <nfs/nfs4_kprot.h>
27 
28 /*
29  * NFSv4.1: slot support (reply cache)
30  */
31 
32 #define	RFS4_SLOT_INUSE		(1 << 0)
33 #define	RFS4_SLOT_CACHED	(1 << 1)
34 
35 /* Slot entry structure */
36 typedef struct rfs4_slot {
37 	uint32_t	se_flags;
38 	sequenceid4	se_seqid;
39 	COMPOUND4res	se_buf;	/* Buf for slot and replays */
40 	kmutex_t	se_lock;
41 } rfs4_slot_t;
42 
43 /*
44  * NFSv4.1 Sessions
45  */
46 
47 typedef struct rfs41_csr {	/* contrived create_session result */
48 	sequenceid4		xi_sid;		/* seqid response to EXCHG_ID */
49 	nfsstat4		cs_status;
50 	CREATE_SESSION4resok	cs_res;		/* cached results if NFS4_OK */
51 } rfs41_csr_t;
52 
53 /*
54  * Sessions Callback Infrastructure
55  *
56  * Locking:
57  *
58  * . cn_lock protects all fields in sess_channel_t, but since
59  *   fore/back and dir don't change often, we serialize only
60  *   the occasional update.
61  *
62  * cn_lock:	cn_lock
63  * bsd_rwlock:	cn_lock -> bsd_rwlock
64  */
65 
66 #define		MAX_CH_CACHE	10
67 typedef struct {				/* Back Chan Specific Data */
68 	rfs4_slot_t		 *bsd_slots;	/* opaque token for slot tab */
69 	nfsstat4		  bsd_stat;
70 	krwlock_t		  bsd_rwlock;	/* protect slot tab info */
71 	uint64_t		  bsd_idx;	/* Index of next spare CLNT */
72 	uint64_t		  bsd_cur;	/* Most recent added CLNT */
73 	int			  bsd_ch_free;
74 	CLIENT			 *bsd_clnt[MAX_CH_CACHE];
75 } sess_bcsd_t;
76 
77 typedef struct {
78 	channel_dir_from_server4 cn_dir;		/* Chan Direction */
79 	channel_attrs4		 cn_attrs;		/* chan Attrs */
80 	channel_attrs4		 cn_back_attrs;		/* back channel Attrs */
81 	sess_bcsd_t		*cn_csd;		/* Chan Specific Data */
82 	krwlock_t		 cn_lock;
83 } sess_channel_t;
84 
85 /*
86  * Maximum number of concurrent COMPOUND requests per session
87  */
88 #define	MAXSLOTS	256
89 #define	MAXSLOTS_BACK	4
90 
91 typedef struct {
92 	state_protect_how4	 sp_type;
93 } rfs41_sprot_t;
94 
95 /*
96  * NFSv4.1 Sessions (cont'd)
97  *
98  *   rfs4_session_t             rfs4_client_t
99  *   +-------------+           +--------------------+
100  *   | sn_sessid   |           | clientid           |
101  *   | sn_clnt *  -|---------->|    :               |
102  *   | sn_fore     |           +--------------------+
103  *   | sn_back     |
104  *   | sn_slots * -|---------> +--------------------------------+
105  *   +-------------+           |        (slot_ent_t)            |
106  *                             |  +----------------------------+|
107  *                             |  | status, slot, seqid, resp *||------><Res>
108  *                             |  +----------------------------+|
109  *                             |  | status, slot, seqid, resp *||
110  *                             |  +----------------------------+|
111  *                             |  | status, slot, seqid, resp *||
112  *                             |  +----------------------------+|
113  *			       | .				|
114  *			       | :				|
115  *                             +--------------------------------+
116  *                             stok_t
117  */
118 struct rfs4_client;
119 struct rfs4_dbe;
120 
121 typedef struct {
122 	nfsstat4		 cs_error;
123 	struct rfs4_client	*cs_client;
124 	struct svc_req		*cs_req;
125 	uint32_t		 cs_id;
126 	CREATE_SESSION4args	 cs_aotw;
127 } session41_create_t;
128 
129 /*
130  * sn_seq4 - sequence result bit accounting info (session scope)
131  *	CB_PATH_DOWN_SESSION, CB_GSS_CONTEXT_EXPIRING,
132  *	CB_GSS_CONTEXT_EXPIRED, BACKCHANNEL_FAULT
133  */
134 typedef struct rfs4_session {
135 	struct rfs4_dbe		*sn_dbe;
136 	sessionid4		 sn_sessid;	/* session id */
137 	struct rfs4_client	*sn_clnt;	/* back ptr to client state */
138 	sess_channel_t		*sn_fore;	/* fore chan for this session */
139 	sess_channel_t		*sn_back;	/* back chan for this session */
140 	rfs4_slot_t		*sn_slots;	/* slot replay cache */
141 	time_t			 sn_laccess;	/* struct was last accessed */
142 	int			 sn_csflags;	/* create_session only flags */
143 	uint32_t		 sn_flags;	/* SEQ4 status bits */
144 	list_node_t		 sn_node;	/* link node to rfs4_client */
145 	struct	{
146 		uint32_t	pngcnt;		/* conn pings outstanding */
147 		uint32_t	progno;		/* cb_program number */
148 		uint32_t	failed:1;	/* TRUE if no cb path avail */
149 		uint32_t	pnginprog:1;
150 	} sn_bc;
151 	uint32_t		 sn_rcached;	/* cached replies, for stat */
152 } rfs4_session_t;
153 
154 #define	SN_CB_CHAN_EST(x)	((x)->sn_back != NULL)
155 #define	SN_CB_CHAN_OK(x)	((x)->sn_bc.failed == 0)
156 
157 /* error code for internal use */
158 #define	nfserr_replay_cache NFS4ERR_REPLAY_CACHE
159 
160 /* Session end */
161 
162 /*
163  * Set of RPC credentials used for a particular operation.
164  * Used for operations like SETCLIENTID_CONFIRM where the
165  * credentials needs to match those used at SETCLIENTID.
166  * For EXCHANGE_ID (NFSv4.1+)
167  */
168 
169 typedef struct {
170 	cred_t	*cp_cr;
171 	int	 cp_aflavor;
172 	int	 cp_secmod;
173 	caddr_t	 cp_princ;
174 } cred_set_t;
175 
176 /* NFSv4.1 Functions */
177 extern int rfs4x_dispatch(struct svc_req *, SVCXPRT *, char *);
178 
179 void rfs4_free_cred_set(cred_set_t *);
180 void rfs4x_session_rele(rfs4_session_t *);
181 rfs4_session_t *rfs4x_createsession(session41_create_t *);
182 nfsstat4 rfs4x_destroysession(rfs4_session_t *, unsigned useref);
183 void rfs4x_client_session_remove(struct rfs4_client *);
184 rfs4_session_t *rfs4x_findsession_by_id(sessionid4);
185 void rfs4x_session_hold(rfs4_session_t *);
186 void rfs4x_session_rele(rfs4_session_t *);
187 
188 /* Some init/fini helpers */
189 struct rfs4_srv;
190 struct compound_state;
191 void rfs4x_state_init_locked(struct nfs4_srv *);
192 void rfs4x_state_fini(struct nfs4_srv *);
193 int rfs4x_sequence_prep(COMPOUND4args *, COMPOUND4res *,
194     struct compound_state *);
195 void rfs4x_sequence_done(COMPOUND4res *, struct compound_state *);
196 
197 #endif	/* _KERNEL */
198 
199 #ifdef	__cplusplus
200 }
201 #endif
202 
203 #endif	/* _NFS4X_H */
204