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/refcount.h>
40#include <linux/sunrpc/svc_xprt.h>
41#include "nfsfh.h"
42#include "nfsd.h"
43
44typedef struct {
45 u32 cl_boot;
46 u32 cl_id;
47} clientid_t;
48
49typedef struct {
50 clientid_t so_clid;
51 u32 so_id;
52} stateid_opaque_t;
53
54typedef struct {
55 u32 si_generation;
56 stateid_opaque_t si_opaque;
57} stateid_t;
58
59typedef struct {
60 stateid_t stid;
61#define NFS4_COPY_STID 1
62#define NFS4_COPYNOTIFY_STID 2
63 unsigned char sc_type;
64 refcount_t sc_count;
65} copy_stateid_t;
66
67struct nfsd4_callback {
68 struct nfs4_client *cb_clp;
69 struct rpc_message cb_msg;
70 const struct nfsd4_callback_ops *cb_ops;
71 struct work_struct cb_work;
72 int cb_seq_status;
73 int cb_status;
74 bool cb_need_restart;
75 bool cb_holds_slot;
76};
77
78struct nfsd4_callback_ops {
79 void (*prepare)(struct nfsd4_callback *);
80 int (*done)(struct nfsd4_callback *, struct rpc_task *);
81 void (*release)(struct nfsd4_callback *);
82};
83
84
85
86
87
88
89struct nfs4_stid {
90 refcount_t sc_count;
91#define NFS4_OPEN_STID 1
92#define NFS4_LOCK_STID 2
93#define NFS4_DELEG_STID 4
94
95#define NFS4_CLOSED_STID 8
96
97#define NFS4_REVOKED_DELEG_STID 16
98#define NFS4_CLOSED_DELEG_STID 32
99#define NFS4_LAYOUT_STID 64
100 struct list_head sc_cp_list;
101 unsigned char sc_type;
102 stateid_t sc_stateid;
103 spinlock_t sc_lock;
104 struct nfs4_client *sc_client;
105 struct nfs4_file *sc_file;
106 void (*sc_free)(struct nfs4_stid *);
107};
108
109
110
111
112struct nfs4_cpntf_state {
113 copy_stateid_t cp_stateid;
114 struct list_head cp_list;
115 stateid_t cp_p_stateid;
116 clientid_t cp_p_clid;
117 time64_t cpntf_time;
118};
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141struct nfs4_delegation {
142 struct nfs4_stid dl_stid;
143 struct list_head dl_perfile;
144 struct list_head dl_perclnt;
145 struct list_head dl_recall_lru;
146 struct nfs4_clnt_odstate *dl_clnt_odstate;
147 u32 dl_type;
148 time64_t dl_time;
149
150 int dl_retries;
151 struct nfsd4_callback dl_recall;
152};
153
154#define cb_to_delegation(cb) \
155 container_of(cb, struct nfs4_delegation, dl_recall)
156
157
158struct nfs4_cb_conn {
159
160 struct sockaddr_storage cb_addr;
161 struct sockaddr_storage cb_saddr;
162 size_t cb_addrlen;
163 u32 cb_prog;
164
165 u32 cb_ident;
166 struct svc_xprt *cb_xprt;
167};
168
169static inline struct nfs4_delegation *delegstateid(struct nfs4_stid *s)
170{
171 return container_of(s, struct nfs4_delegation, dl_stid);
172}
173
174
175#define NFSD_MAX_SLOTS_PER_SESSION 160
176
177#define NFSD_MAX_OPS_PER_COMPOUND 16
178
179#define NFSD_SLOT_CACHE_SIZE 2048
180
181#define NFSD_CACHE_SIZE_SLOTS_PER_SESSION 32
182#define NFSD_MAX_MEM_PER_SESSION \
183 (NFSD_CACHE_SIZE_SLOTS_PER_SESSION * NFSD_SLOT_CACHE_SIZE)
184
185struct nfsd4_slot {
186 u32 sl_seqid;
187 __be32 sl_status;
188 struct svc_cred sl_cred;
189 u32 sl_datalen;
190 u16 sl_opcnt;
191#define NFSD4_SLOT_INUSE (1 << 0)
192#define NFSD4_SLOT_CACHETHIS (1 << 1)
193#define NFSD4_SLOT_INITIALIZED (1 << 2)
194#define NFSD4_SLOT_CACHED (1 << 3)
195 u8 sl_flags;
196 char sl_data[];
197};
198
199struct nfsd4_channel_attrs {
200 u32 headerpadsz;
201 u32 maxreq_sz;
202 u32 maxresp_sz;
203 u32 maxresp_cached;
204 u32 maxops;
205 u32 maxreqs;
206 u32 nr_rdma_attrs;
207 u32 rdma_attrs;
208};
209
210struct nfsd4_cb_sec {
211 u32 flavor;
212 kuid_t uid;
213 kgid_t gid;
214};
215
216struct nfsd4_create_session {
217 clientid_t clientid;
218 struct nfs4_sessionid sessionid;
219 u32 seqid;
220 u32 flags;
221 struct nfsd4_channel_attrs fore_channel;
222 struct nfsd4_channel_attrs back_channel;
223 u32 callback_prog;
224 struct nfsd4_cb_sec cb_sec;
225};
226
227struct nfsd4_backchannel_ctl {
228 u32 bc_cb_program;
229 struct nfsd4_cb_sec bc_cb_sec;
230};
231
232struct nfsd4_bind_conn_to_session {
233 struct nfs4_sessionid sessionid;
234 u32 dir;
235};
236
237
238struct nfsd4_clid_slot {
239 u32 sl_seqid;
240 __be32 sl_status;
241 struct nfsd4_create_session sl_cr_ses;
242};
243
244struct nfsd4_conn {
245 struct list_head cn_persession;
246 struct svc_xprt *cn_xprt;
247 struct svc_xpt_user cn_xpt_user;
248 struct nfsd4_session *cn_session;
249
250 unsigned char cn_flags;
251};
252
253
254
255
256
257
258struct nfsd4_session {
259 atomic_t se_ref;
260 struct list_head se_hash;
261 struct list_head se_perclnt;
262
263#define NFS4_SESSION_DEAD 0x010
264 u32 se_flags;
265 struct nfs4_client *se_client;
266 struct nfs4_sessionid se_sessionid;
267 struct nfsd4_channel_attrs se_fchannel;
268 struct nfsd4_channel_attrs se_bchannel;
269 struct nfsd4_cb_sec se_cb_sec;
270 struct list_head se_conns;
271 u32 se_cb_prog;
272 u32 se_cb_seq_nr;
273 struct nfsd4_slot *se_slots[];
274};
275
276
277struct nfsd4_sessionid {
278 clientid_t clientid;
279 u32 sequence;
280 u32 reserved;
281};
282
283#define HEXDIR_LEN 33
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312struct nfs4_client {
313 struct list_head cl_idhash;
314 struct rb_node cl_namenode;
315 struct list_head *cl_ownerstr_hashtbl;
316 struct list_head cl_openowners;
317 struct idr cl_stateids;
318 struct list_head cl_delegations;
319 struct list_head cl_revoked;
320 struct list_head cl_lru;
321#ifdef CONFIG_NFSD_PNFS
322 struct list_head cl_lo_states;
323#endif
324 struct xdr_netobj cl_name;
325 nfs4_verifier cl_verifier;
326 time64_t cl_time;
327 struct sockaddr_storage cl_addr;
328 bool cl_mach_cred;
329 struct svc_cred cl_cred;
330 clientid_t cl_clientid;
331 nfs4_verifier cl_confirm;
332 u32 cl_minorversion;
333
334 struct xdr_netobj cl_nii_domain;
335 struct xdr_netobj cl_nii_name;
336 struct timespec64 cl_nii_time;
337
338
339 struct nfs4_cb_conn cl_cb_conn;
340#define NFSD4_CLIENT_CB_UPDATE (0)
341#define NFSD4_CLIENT_CB_KILL (1)
342#define NFSD4_CLIENT_STABLE (2)
343#define NFSD4_CLIENT_RECLAIM_COMPLETE (3)
344#define NFSD4_CLIENT_CONFIRMED (4)
345#define NFSD4_CLIENT_UPCALL_LOCK (5)
346#define NFSD4_CLIENT_CB_FLAG_MASK (1 << NFSD4_CLIENT_CB_UPDATE | \
347 1 << NFSD4_CLIENT_CB_KILL)
348 unsigned long cl_flags;
349 const struct cred *cl_cb_cred;
350 struct rpc_clnt *cl_cb_client;
351 u32 cl_cb_ident;
352#define NFSD4_CB_UP 0
353#define NFSD4_CB_UNKNOWN 1
354#define NFSD4_CB_DOWN 2
355#define NFSD4_CB_FAULT 3
356 int cl_cb_state;
357 struct nfsd4_callback cl_cb_null;
358 struct nfsd4_session *cl_cb_session;
359
360
361 spinlock_t cl_lock;
362
363
364 struct list_head cl_sessions;
365 struct nfsd4_clid_slot cl_cs_slot;
366 u32 cl_exchange_flags;
367
368 atomic_t cl_rpc_users;
369 struct nfsdfs_client cl_nfsdfs;
370 struct nfs4_op_map cl_spo_must_allow;
371
372
373 struct dentry *cl_nfsd_dentry;
374
375
376
377 struct dentry *cl_nfsd_info_dentry;
378
379
380
381 unsigned long cl_cb_slot_busy;
382 struct rpc_wait_queue cl_cb_waitq;
383
384 struct net *net;
385 struct list_head async_copies;
386 spinlock_t async_lock;
387 atomic_t cl_cb_inflight;
388};
389
390
391
392
393
394
395struct nfs4_client_reclaim {
396 struct list_head cr_strhash;
397 struct nfs4_client *cr_clp;
398 struct xdr_netobj cr_name;
399 struct xdr_netobj cr_princhash;
400};
401
402
403
404
405
406
407
408
409#define NFSD4_REPLAY_ISIZE 112
410
411
412
413
414
415struct nfs4_replay {
416 __be32 rp_status;
417 unsigned int rp_buflen;
418 char *rp_buf;
419 struct knfsd_fh rp_openfh;
420 struct mutex rp_mutex;
421 char rp_ibuf[NFSD4_REPLAY_ISIZE];
422};
423
424struct nfs4_stateowner;
425
426struct nfs4_stateowner_operations {
427 void (*so_unhash)(struct nfs4_stateowner *);
428 void (*so_free)(struct nfs4_stateowner *);
429};
430
431
432
433
434
435
436
437struct nfs4_stateowner {
438 struct list_head so_strhash;
439 struct list_head so_stateids;
440 struct nfs4_client *so_client;
441 const struct nfs4_stateowner_operations *so_ops;
442
443
444 atomic_t so_count;
445 u32 so_seqid;
446 struct xdr_netobj so_owner;
447 struct nfs4_replay so_replay;
448 bool so_is_open_owner;
449};
450
451
452
453
454
455
456
457struct nfs4_openowner {
458 struct nfs4_stateowner oo_owner;
459 struct list_head oo_perclient;
460
461
462
463
464
465
466
467 struct list_head oo_close_lru;
468 struct nfs4_ol_stateid *oo_last_closed_stid;
469 time64_t oo_time;
470#define NFS4_OO_CONFIRMED 1
471 unsigned char oo_flags;
472};
473
474
475
476
477
478
479struct nfs4_lockowner {
480 struct nfs4_stateowner lo_owner;
481 struct list_head lo_blocked;
482};
483
484static inline struct nfs4_openowner * openowner(struct nfs4_stateowner *so)
485{
486 return container_of(so, struct nfs4_openowner, oo_owner);
487}
488
489static inline struct nfs4_lockowner * lockowner(struct nfs4_stateowner *so)
490{
491 return container_of(so, struct nfs4_lockowner, lo_owner);
492}
493
494
495
496
497
498struct nfs4_clnt_odstate {
499 struct nfs4_client *co_client;
500 struct nfs4_file *co_file;
501 struct list_head co_perfile;
502 refcount_t co_odcount;
503};
504
505
506
507
508
509
510
511
512
513
514
515
516
517struct nfs4_file {
518 refcount_t fi_ref;
519 struct inode * fi_inode;
520 bool fi_aliased;
521 spinlock_t fi_lock;
522 struct hlist_node fi_hash;
523 struct list_head fi_stateids;
524 union {
525 struct list_head fi_delegations;
526 struct rcu_head fi_rcu;
527 };
528 struct list_head fi_clnt_odstate;
529
530 struct nfsd_file *fi_fds[3];
531
532
533
534
535
536
537
538 atomic_t fi_access[2];
539 u32 fi_share_deny;
540 struct nfsd_file *fi_deleg_file;
541 int fi_delegees;
542 struct knfsd_fh fi_fhandle;
543 bool fi_had_conflict;
544#ifdef CONFIG_NFSD_PNFS
545 struct list_head fi_lo_states;
546 atomic_t fi_lo_recalls;
547#endif
548};
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564struct nfs4_ol_stateid {
565 struct nfs4_stid st_stid;
566 struct list_head st_perfile;
567 struct list_head st_perstateowner;
568 struct list_head st_locks;
569 struct nfs4_stateowner *st_stateowner;
570 struct nfs4_clnt_odstate *st_clnt_odstate;
571 unsigned char st_access_bmap;
572 unsigned char st_deny_bmap;
573 struct nfs4_ol_stateid *st_openstp;
574 struct mutex st_mutex;
575};
576
577static inline struct nfs4_ol_stateid *openlockstateid(struct nfs4_stid *s)
578{
579 return container_of(s, struct nfs4_ol_stateid, st_stid);
580}
581
582struct nfs4_layout_stateid {
583 struct nfs4_stid ls_stid;
584 struct list_head ls_perclnt;
585 struct list_head ls_perfile;
586 spinlock_t ls_lock;
587 struct list_head ls_layouts;
588 u32 ls_layout_type;
589 struct nfsd_file *ls_file;
590 struct nfsd4_callback ls_recall;
591 stateid_t ls_recall_sid;
592 bool ls_recalled;
593 struct mutex ls_mutex;
594};
595
596static inline struct nfs4_layout_stateid *layoutstateid(struct nfs4_stid *s)
597{
598 return container_of(s, struct nfs4_layout_stateid, ls_stid);
599}
600
601
602#define RD_STATE 0x00000010
603#define WR_STATE 0x00000020
604
605enum nfsd4_cb_op {
606 NFSPROC4_CLNT_CB_NULL = 0,
607 NFSPROC4_CLNT_CB_RECALL,
608 NFSPROC4_CLNT_CB_LAYOUT,
609 NFSPROC4_CLNT_CB_OFFLOAD,
610 NFSPROC4_CLNT_CB_SEQUENCE,
611 NFSPROC4_CLNT_CB_NOTIFY_LOCK,
612};
613
614
615static inline bool nfsd4_stateid_generation_after(stateid_t *a, stateid_t *b)
616{
617 return (s32)(a->si_generation - b->si_generation) > 0;
618}
619
620
621
622
623
624
625struct nfsd4_blocked_lock {
626 struct list_head nbl_list;
627 struct list_head nbl_lru;
628 time64_t nbl_time;
629 struct file_lock nbl_lock;
630 struct knfsd_fh nbl_fh;
631 struct nfsd4_callback nbl_cb;
632};
633
634struct nfsd4_compound_state;
635struct nfsd_net;
636struct nfsd4_copy;
637
638extern __be32 nfs4_preprocess_stateid_op(struct svc_rqst *rqstp,
639 struct nfsd4_compound_state *cstate, struct svc_fh *fhp,
640 stateid_t *stateid, int flags, struct nfsd_file **filp,
641 struct nfs4_stid **cstid);
642__be32 nfsd4_lookup_stateid(struct nfsd4_compound_state *cstate,
643 stateid_t *stateid, unsigned char typemask,
644 struct nfs4_stid **s, struct nfsd_net *nn);
645struct nfs4_stid *nfs4_alloc_stid(struct nfs4_client *cl, struct kmem_cache *slab,
646 void (*sc_free)(struct nfs4_stid *));
647int nfs4_init_copy_state(struct nfsd_net *nn, struct nfsd4_copy *copy);
648void nfs4_free_copy_state(struct nfsd4_copy *copy);
649struct nfs4_cpntf_state *nfs4_alloc_init_cpntf_state(struct nfsd_net *nn,
650 struct nfs4_stid *p_stid);
651void nfs4_unhash_stid(struct nfs4_stid *s);
652void nfs4_put_stid(struct nfs4_stid *s);
653void nfs4_inc_and_copy_stateid(stateid_t *dst, struct nfs4_stid *stid);
654void nfs4_remove_reclaim_record(struct nfs4_client_reclaim *, struct nfsd_net *);
655extern void nfs4_release_reclaim(struct nfsd_net *);
656extern struct nfs4_client_reclaim *nfsd4_find_reclaim_client(struct xdr_netobj name,
657 struct nfsd_net *nn);
658extern __be32 nfs4_check_open_reclaim(struct nfs4_client *);
659extern void nfsd4_probe_callback(struct nfs4_client *clp);
660extern void nfsd4_probe_callback_sync(struct nfs4_client *clp);
661extern void nfsd4_change_callback(struct nfs4_client *clp, struct nfs4_cb_conn *);
662extern void nfsd4_init_cb(struct nfsd4_callback *cb, struct nfs4_client *clp,
663 const struct nfsd4_callback_ops *ops, enum nfsd4_cb_op op);
664extern void nfsd4_run_cb(struct nfsd4_callback *cb);
665extern int nfsd4_create_callback_queue(void);
666extern void nfsd4_destroy_callback_queue(void);
667extern void nfsd4_shutdown_callback(struct nfs4_client *);
668extern void nfsd4_shutdown_copy(struct nfs4_client *clp);
669extern void nfsd4_prepare_cb_recall(struct nfs4_delegation *dp);
670extern struct nfs4_client_reclaim *nfs4_client_to_reclaim(struct xdr_netobj name,
671 struct xdr_netobj princhash, struct nfsd_net *nn);
672extern bool nfs4_has_reclaimed_state(struct xdr_netobj name, struct nfsd_net *nn);
673
674void put_nfs4_file(struct nfs4_file *fi);
675extern void nfs4_put_copy(struct nfsd4_copy *copy);
676extern struct nfsd4_copy *
677find_async_copy(struct nfs4_client *clp, stateid_t *staetid);
678extern void nfs4_put_cpntf_state(struct nfsd_net *nn,
679 struct nfs4_cpntf_state *cps);
680extern __be32 manage_cpntf_state(struct nfsd_net *nn, stateid_t *st,
681 struct nfs4_client *clp,
682 struct nfs4_cpntf_state **cps);
683static inline void get_nfs4_file(struct nfs4_file *fi)
684{
685 refcount_inc(&fi->fi_ref);
686}
687struct nfsd_file *find_any_file(struct nfs4_file *f);
688
689
690void nfsd4_end_grace(struct nfsd_net *nn);
691
692
693extern int nfsd4_client_tracking_init(struct net *net);
694extern void nfsd4_client_tracking_exit(struct net *net);
695extern void nfsd4_client_record_create(struct nfs4_client *clp);
696extern void nfsd4_client_record_remove(struct nfs4_client *clp);
697extern int nfsd4_client_record_check(struct nfs4_client *clp);
698extern void nfsd4_record_grace_done(struct nfsd_net *nn);
699
700#endif
701