1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35#ifndef _NFSD4_STATE_H
36#define _NFSD4_STATE_H
37
38#include <linux/idr.h>
39#include <linux/sunrpc/svc_xprt.h>
40#include <linux/nfsd/nfsfh.h>
41#include "nfsfh.h"
42
43typedef struct {
44 u32 cl_boot;
45 u32 cl_id;
46} clientid_t;
47
48typedef struct {
49 clientid_t so_clid;
50 u32 so_id;
51} stateid_opaque_t;
52
53typedef struct {
54 u32 si_generation;
55 stateid_opaque_t si_opaque;
56} stateid_t;
57
58#define STATEID_FMT "(%08x/%08x/%08x/%08x)"
59#define STATEID_VAL(s) \
60 (s)->si_opaque.so_clid.cl_boot, \
61 (s)->si_opaque.so_clid.cl_id, \
62 (s)->si_opaque.so_id, \
63 (s)->si_generation
64
65struct nfsd4_callback {
66 void *cb_op;
67 struct nfs4_client *cb_clp;
68 struct list_head cb_per_client;
69 u32 cb_minorversion;
70 struct rpc_message cb_msg;
71 const struct rpc_call_ops *cb_ops;
72 struct work_struct cb_work;
73 bool cb_done;
74};
75
76struct nfs4_stid {
77#define NFS4_OPEN_STID 1
78#define NFS4_LOCK_STID 2
79#define NFS4_DELEG_STID 4
80
81#define NFS4_CLOSED_STID 8
82 unsigned char sc_type;
83 stateid_t sc_stateid;
84 struct nfs4_client *sc_client;
85};
86
87struct nfs4_delegation {
88 struct nfs4_stid dl_stid;
89 struct list_head dl_perfile;
90 struct list_head dl_perclnt;
91 struct list_head dl_recall_lru;
92 atomic_t dl_count;
93 struct nfs4_file *dl_file;
94 u32 dl_type;
95 time_t dl_time;
96
97 struct knfsd_fh dl_fh;
98 int dl_retries;
99 struct nfsd4_callback dl_recall;
100};
101
102
103struct nfs4_cb_conn {
104
105 struct sockaddr_storage cb_addr;
106 struct sockaddr_storage cb_saddr;
107 size_t cb_addrlen;
108 u32 cb_prog;
109
110 u32 cb_ident;
111 struct svc_xprt *cb_xprt;
112};
113
114static inline struct nfs4_delegation *delegstateid(struct nfs4_stid *s)
115{
116 return container_of(s, struct nfs4_delegation, dl_stid);
117}
118
119
120#define NFSD_MAX_SLOTS_PER_SESSION 160
121
122#define NFSD_MAX_OPS_PER_COMPOUND 16
123
124#define NFSD_SLOT_CACHE_SIZE 1024
125
126#define NFSD_CACHE_SIZE_SLOTS_PER_SESSION 32
127#define NFSD_MAX_MEM_PER_SESSION \
128 (NFSD_CACHE_SIZE_SLOTS_PER_SESSION * NFSD_SLOT_CACHE_SIZE)
129
130struct nfsd4_slot {
131 u32 sl_seqid;
132 __be32 sl_status;
133 u32 sl_datalen;
134 u16 sl_opcnt;
135#define NFSD4_SLOT_INUSE (1 << 0)
136#define NFSD4_SLOT_CACHETHIS (1 << 1)
137#define NFSD4_SLOT_INITIALIZED (1 << 2)
138 u8 sl_flags;
139 char sl_data[];
140};
141
142struct nfsd4_channel_attrs {
143 u32 headerpadsz;
144 u32 maxreq_sz;
145 u32 maxresp_sz;
146 u32 maxresp_cached;
147 u32 maxops;
148 u32 maxreqs;
149 u32 nr_rdma_attrs;
150 u32 rdma_attrs;
151};
152
153struct nfsd4_create_session {
154 clientid_t clientid;
155 struct nfs4_sessionid sessionid;
156 u32 seqid;
157 u32 flags;
158 struct nfsd4_channel_attrs fore_channel;
159 struct nfsd4_channel_attrs back_channel;
160 u32 callback_prog;
161 u32 uid;
162 u32 gid;
163};
164
165struct nfsd4_bind_conn_to_session {
166 struct nfs4_sessionid sessionid;
167 u32 dir;
168};
169
170
171struct nfsd4_clid_slot {
172 u32 sl_seqid;
173 __be32 sl_status;
174 struct nfsd4_create_session sl_cr_ses;
175};
176
177struct nfsd4_conn {
178 struct list_head cn_persession;
179 struct svc_xprt *cn_xprt;
180 struct svc_xpt_user cn_xpt_user;
181 struct nfsd4_session *cn_session;
182
183 unsigned char cn_flags;
184};
185
186struct nfsd4_session {
187 struct kref se_ref;
188 struct list_head se_hash;
189 struct list_head se_perclnt;
190 u32 se_flags;
191 struct nfs4_client *se_client;
192 struct nfs4_sessionid se_sessionid;
193 struct nfsd4_channel_attrs se_fchannel;
194 struct nfsd4_channel_attrs se_bchannel;
195 struct list_head se_conns;
196 u32 se_cb_prog;
197 u32 se_cb_seq_nr;
198 struct nfsd4_slot *se_slots[];
199};
200
201extern void nfsd4_put_session(struct nfsd4_session *ses);
202
203
204struct nfsd4_sessionid {
205 clientid_t clientid;
206 u32 sequence;
207 u32 reserved;
208};
209
210#define HEXDIR_LEN 33
211
212
213
214
215
216
217
218
219
220
221
222struct nfs4_client {
223 struct list_head cl_idhash;
224 struct list_head cl_strhash;
225 struct list_head cl_openowners;
226 struct idr cl_stateids;
227 struct list_head cl_delegations;
228 struct list_head cl_lru;
229 struct xdr_netobj cl_name;
230 char cl_recdir[HEXDIR_LEN];
231 nfs4_verifier cl_verifier;
232 time_t cl_time;
233 struct sockaddr_storage cl_addr;
234 struct svc_cred cl_cred;
235 clientid_t cl_clientid;
236 nfs4_verifier cl_confirm;
237 u32 cl_minorversion;
238
239
240 struct nfs4_cb_conn cl_cb_conn;
241#define NFSD4_CLIENT_CB_UPDATE (0)
242#define NFSD4_CLIENT_CB_KILL (1)
243#define NFSD4_CLIENT_STABLE (2)
244#define NFSD4_CLIENT_RECLAIM_COMPLETE (3)
245#define NFSD4_CLIENT_CB_FLAG_MASK (1 << NFSD4_CLIENT_CB_UPDATE | \
246 1 << NFSD4_CLIENT_CB_KILL)
247 unsigned long cl_flags;
248 struct rpc_clnt *cl_cb_client;
249 u32 cl_cb_ident;
250#define NFSD4_CB_UP 0
251#define NFSD4_CB_UNKNOWN 1
252#define NFSD4_CB_DOWN 2
253#define NFSD4_CB_FAULT 3
254 int cl_cb_state;
255 struct nfsd4_callback cl_cb_null;
256 struct nfsd4_session *cl_cb_session;
257 struct list_head cl_callbacks;
258
259
260 spinlock_t cl_lock;
261
262
263 struct list_head cl_sessions;
264 struct nfsd4_clid_slot cl_cs_slot;
265 u32 cl_exchange_flags;
266
267 atomic_t cl_refcount;
268
269
270
271 unsigned long cl_cb_slot_busy;
272 struct rpc_wait_queue cl_cb_waitq;
273
274};
275
276static inline void
277mark_client_expired(struct nfs4_client *clp)
278{
279 clp->cl_time = 0;
280}
281
282static inline bool
283is_client_expired(struct nfs4_client *clp)
284{
285 return clp->cl_time == 0;
286}
287
288
289
290
291
292
293struct nfs4_client_reclaim {
294 struct list_head cr_strhash;
295 char cr_recdir[HEXDIR_LEN];
296};
297
298static inline void
299update_stateid(stateid_t *stateid)
300{
301 stateid->si_generation++;
302
303 if (stateid->si_generation == 0)
304 stateid->si_generation = 1;
305}
306
307
308
309
310
311
312
313
314#define NFSD4_REPLAY_ISIZE 112
315
316
317
318
319
320struct nfs4_replay {
321 __be32 rp_status;
322 unsigned int rp_buflen;
323 char *rp_buf;
324 struct knfsd_fh rp_openfh;
325 char rp_ibuf[NFSD4_REPLAY_ISIZE];
326};
327
328struct nfs4_stateowner {
329 struct list_head so_strhash;
330 struct list_head so_stateids;
331 struct nfs4_client * so_client;
332
333
334 u32 so_seqid;
335 struct xdr_netobj so_owner;
336 struct nfs4_replay so_replay;
337 bool so_is_open_owner;
338};
339
340struct nfs4_openowner {
341 struct nfs4_stateowner oo_owner;
342 struct list_head oo_perclient;
343
344
345
346
347
348
349
350 struct list_head oo_close_lru;
351 struct nfs4_ol_stateid *oo_last_closed_stid;
352 time_t oo_time;
353#define NFS4_OO_CONFIRMED 1
354#define NFS4_OO_PURGE_CLOSE 2
355#define NFS4_OO_NEW 4
356 unsigned char oo_flags;
357};
358
359struct nfs4_lockowner {
360 struct nfs4_stateowner lo_owner;
361 struct list_head lo_owner_ino_hash;
362 struct list_head lo_perstateid;
363 struct list_head lo_list;
364};
365
366static inline struct nfs4_openowner * openowner(struct nfs4_stateowner *so)
367{
368 return container_of(so, struct nfs4_openowner, oo_owner);
369}
370
371static inline struct nfs4_lockowner * lockowner(struct nfs4_stateowner *so)
372{
373 return container_of(so, struct nfs4_lockowner, lo_owner);
374}
375
376
377
378
379
380
381struct nfs4_file {
382 atomic_t fi_ref;
383 struct list_head fi_hash;
384 struct list_head fi_stateids;
385 struct list_head fi_delegations;
386
387 struct file * fi_fds[3];
388
389
390
391
392
393
394
395 atomic_t fi_access[2];
396 struct file *fi_deleg_file;
397 struct file_lock *fi_lease;
398 atomic_t fi_delegees;
399 struct inode *fi_inode;
400 bool fi_had_conflict;
401};
402
403
404
405static inline struct file *find_writeable_file(struct nfs4_file *f)
406{
407 if (f->fi_fds[O_WRONLY])
408 return f->fi_fds[O_WRONLY];
409 return f->fi_fds[O_RDWR];
410}
411
412static inline struct file *find_readable_file(struct nfs4_file *f)
413{
414 if (f->fi_fds[O_RDONLY])
415 return f->fi_fds[O_RDONLY];
416 return f->fi_fds[O_RDWR];
417}
418
419static inline struct file *find_any_file(struct nfs4_file *f)
420{
421 if (f->fi_fds[O_RDWR])
422 return f->fi_fds[O_RDWR];
423 else if (f->fi_fds[O_WRONLY])
424 return f->fi_fds[O_WRONLY];
425 else
426 return f->fi_fds[O_RDONLY];
427}
428
429
430struct nfs4_ol_stateid {
431 struct nfs4_stid st_stid;
432 struct list_head st_perfile;
433 struct list_head st_perstateowner;
434 struct list_head st_lockowners;
435 struct nfs4_stateowner * st_stateowner;
436 struct nfs4_file * st_file;
437 unsigned long st_access_bmap;
438 unsigned long st_deny_bmap;
439 struct nfs4_ol_stateid * st_openstp;
440};
441
442static inline struct nfs4_ol_stateid *openlockstateid(struct nfs4_stid *s)
443{
444 return container_of(s, struct nfs4_ol_stateid, st_stid);
445}
446
447
448#define RD_STATE 0x00000010
449#define WR_STATE 0x00000020
450
451struct nfsd4_compound_state;
452struct nfsd_net;
453
454extern __be32 nfs4_preprocess_stateid_op(struct net *net,
455 struct nfsd4_compound_state *cstate,
456 stateid_t *stateid, int flags, struct file **filp);
457extern void nfs4_lock_state(void);
458extern void nfs4_unlock_state(void);
459extern int nfs4_in_grace(void);
460extern void nfs4_release_reclaim(void);
461extern struct nfs4_client_reclaim *nfsd4_find_reclaim_client(struct nfs4_client *crp);
462extern __be32 nfs4_check_open_reclaim(clientid_t *clid);
463extern void nfs4_free_openowner(struct nfs4_openowner *);
464extern void nfs4_free_lockowner(struct nfs4_lockowner *);
465extern int set_callback_cred(void);
466extern void nfsd4_probe_callback(struct nfs4_client *clp);
467extern void nfsd4_probe_callback_sync(struct nfs4_client *clp);
468extern void nfsd4_change_callback(struct nfs4_client *clp, struct nfs4_cb_conn *);
469extern void nfsd4_do_callback_rpc(struct work_struct *);
470extern void nfsd4_cb_recall(struct nfs4_delegation *dp);
471extern int nfsd4_create_callback_queue(void);
472extern void nfsd4_destroy_callback_queue(void);
473extern void nfsd4_shutdown_callback(struct nfs4_client *);
474extern void nfs4_put_delegation(struct nfs4_delegation *dp);
475extern __be32 nfs4_make_rec_clidname(char *clidname, struct xdr_netobj *clname);
476extern int nfs4_client_to_reclaim(const char *name);
477extern int nfs4_has_reclaimed_state(const char *name, bool use_exchange_id);
478extern void release_session_client(struct nfsd4_session *);
479extern void nfsd4_purge_closed_stateid(struct nfs4_stateowner *);
480
481
482extern int nfsd4_client_tracking_init(struct net *net);
483extern void nfsd4_client_tracking_exit(struct net *net);
484extern void nfsd4_client_record_create(struct nfs4_client *clp);
485extern void nfsd4_client_record_remove(struct nfs4_client *clp);
486extern int nfsd4_client_record_check(struct nfs4_client *clp);
487extern void nfsd4_record_grace_done(struct net *net, time_t boot_time);
488#endif
489