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 unsigned long cl_cb_slot_busy;
378 struct rpc_wait_queue cl_cb_waitq;
379
380 struct net *net;
381 struct list_head async_copies;
382 spinlock_t async_lock;
383 atomic_t cl_cb_inflight;
384};
385
386
387
388
389
390
391struct nfs4_client_reclaim {
392 struct list_head cr_strhash;
393 struct nfs4_client *cr_clp;
394 struct xdr_netobj cr_name;
395 struct xdr_netobj cr_princhash;
396};
397
398
399
400
401
402
403
404
405#define NFSD4_REPLAY_ISIZE 112
406
407
408
409
410
411struct nfs4_replay {
412 __be32 rp_status;
413 unsigned int rp_buflen;
414 char *rp_buf;
415 struct knfsd_fh rp_openfh;
416 struct mutex rp_mutex;
417 char rp_ibuf[NFSD4_REPLAY_ISIZE];
418};
419
420struct nfs4_stateowner;
421
422struct nfs4_stateowner_operations {
423 void (*so_unhash)(struct nfs4_stateowner *);
424 void (*so_free)(struct nfs4_stateowner *);
425};
426
427
428
429
430
431
432
433struct nfs4_stateowner {
434 struct list_head so_strhash;
435 struct list_head so_stateids;
436 struct nfs4_client *so_client;
437 const struct nfs4_stateowner_operations *so_ops;
438
439
440 atomic_t so_count;
441 u32 so_seqid;
442 struct xdr_netobj so_owner;
443 struct nfs4_replay so_replay;
444 bool so_is_open_owner;
445};
446
447
448
449
450
451
452
453struct nfs4_openowner {
454 struct nfs4_stateowner oo_owner;
455 struct list_head oo_perclient;
456
457
458
459
460
461
462
463 struct list_head oo_close_lru;
464 struct nfs4_ol_stateid *oo_last_closed_stid;
465 time64_t oo_time;
466#define NFS4_OO_CONFIRMED 1
467 unsigned char oo_flags;
468};
469
470
471
472
473
474
475struct nfs4_lockowner {
476 struct nfs4_stateowner lo_owner;
477 struct list_head lo_blocked;
478};
479
480static inline struct nfs4_openowner * openowner(struct nfs4_stateowner *so)
481{
482 return container_of(so, struct nfs4_openowner, oo_owner);
483}
484
485static inline struct nfs4_lockowner * lockowner(struct nfs4_stateowner *so)
486{
487 return container_of(so, struct nfs4_lockowner, lo_owner);
488}
489
490
491
492
493
494struct nfs4_clnt_odstate {
495 struct nfs4_client *co_client;
496 struct nfs4_file *co_file;
497 struct list_head co_perfile;
498 refcount_t co_odcount;
499};
500
501
502
503
504
505
506
507
508
509
510
511
512
513struct nfs4_file {
514 refcount_t fi_ref;
515 spinlock_t fi_lock;
516 struct hlist_node fi_hash;
517 struct list_head fi_stateids;
518 union {
519 struct list_head fi_delegations;
520 struct rcu_head fi_rcu;
521 };
522 struct list_head fi_clnt_odstate;
523
524 struct nfsd_file *fi_fds[3];
525
526
527
528
529
530
531
532 atomic_t fi_access[2];
533 u32 fi_share_deny;
534 struct nfsd_file *fi_deleg_file;
535 int fi_delegees;
536 struct knfsd_fh fi_fhandle;
537 bool fi_had_conflict;
538#ifdef CONFIG_NFSD_PNFS
539 struct list_head fi_lo_states;
540 atomic_t fi_lo_recalls;
541#endif
542};
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558struct nfs4_ol_stateid {
559 struct nfs4_stid st_stid;
560 struct list_head st_perfile;
561 struct list_head st_perstateowner;
562 struct list_head st_locks;
563 struct nfs4_stateowner *st_stateowner;
564 struct nfs4_clnt_odstate *st_clnt_odstate;
565 unsigned char st_access_bmap;
566 unsigned char st_deny_bmap;
567 struct nfs4_ol_stateid *st_openstp;
568 struct mutex st_mutex;
569};
570
571static inline struct nfs4_ol_stateid *openlockstateid(struct nfs4_stid *s)
572{
573 return container_of(s, struct nfs4_ol_stateid, st_stid);
574}
575
576struct nfs4_layout_stateid {
577 struct nfs4_stid ls_stid;
578 struct list_head ls_perclnt;
579 struct list_head ls_perfile;
580 spinlock_t ls_lock;
581 struct list_head ls_layouts;
582 u32 ls_layout_type;
583 struct nfsd_file *ls_file;
584 struct nfsd4_callback ls_recall;
585 stateid_t ls_recall_sid;
586 bool ls_recalled;
587 struct mutex ls_mutex;
588};
589
590static inline struct nfs4_layout_stateid *layoutstateid(struct nfs4_stid *s)
591{
592 return container_of(s, struct nfs4_layout_stateid, ls_stid);
593}
594
595
596#define RD_STATE 0x00000010
597#define WR_STATE 0x00000020
598
599enum nfsd4_cb_op {
600 NFSPROC4_CLNT_CB_NULL = 0,
601 NFSPROC4_CLNT_CB_RECALL,
602 NFSPROC4_CLNT_CB_LAYOUT,
603 NFSPROC4_CLNT_CB_OFFLOAD,
604 NFSPROC4_CLNT_CB_SEQUENCE,
605 NFSPROC4_CLNT_CB_NOTIFY_LOCK,
606};
607
608
609static inline bool nfsd4_stateid_generation_after(stateid_t *a, stateid_t *b)
610{
611 return (s32)(a->si_generation - b->si_generation) > 0;
612}
613
614
615
616
617
618
619struct nfsd4_blocked_lock {
620 struct list_head nbl_list;
621 struct list_head nbl_lru;
622 time64_t nbl_time;
623 struct file_lock nbl_lock;
624 struct knfsd_fh nbl_fh;
625 struct nfsd4_callback nbl_cb;
626};
627
628struct nfsd4_compound_state;
629struct nfsd_net;
630struct nfsd4_copy;
631
632extern __be32 nfs4_preprocess_stateid_op(struct svc_rqst *rqstp,
633 struct nfsd4_compound_state *cstate, struct svc_fh *fhp,
634 stateid_t *stateid, int flags, struct nfsd_file **filp,
635 struct nfs4_stid **cstid);
636__be32 nfsd4_lookup_stateid(struct nfsd4_compound_state *cstate,
637 stateid_t *stateid, unsigned char typemask,
638 struct nfs4_stid **s, struct nfsd_net *nn);
639struct nfs4_stid *nfs4_alloc_stid(struct nfs4_client *cl, struct kmem_cache *slab,
640 void (*sc_free)(struct nfs4_stid *));
641int nfs4_init_copy_state(struct nfsd_net *nn, struct nfsd4_copy *copy);
642void nfs4_free_copy_state(struct nfsd4_copy *copy);
643struct nfs4_cpntf_state *nfs4_alloc_init_cpntf_state(struct nfsd_net *nn,
644 struct nfs4_stid *p_stid);
645void nfs4_unhash_stid(struct nfs4_stid *s);
646void nfs4_put_stid(struct nfs4_stid *s);
647void nfs4_inc_and_copy_stateid(stateid_t *dst, struct nfs4_stid *stid);
648void nfs4_remove_reclaim_record(struct nfs4_client_reclaim *, struct nfsd_net *);
649extern void nfs4_release_reclaim(struct nfsd_net *);
650extern struct nfs4_client_reclaim *nfsd4_find_reclaim_client(struct xdr_netobj name,
651 struct nfsd_net *nn);
652extern __be32 nfs4_check_open_reclaim(struct nfs4_client *);
653extern void nfsd4_probe_callback(struct nfs4_client *clp);
654extern void nfsd4_probe_callback_sync(struct nfs4_client *clp);
655extern void nfsd4_change_callback(struct nfs4_client *clp, struct nfs4_cb_conn *);
656extern void nfsd4_init_cb(struct nfsd4_callback *cb, struct nfs4_client *clp,
657 const struct nfsd4_callback_ops *ops, enum nfsd4_cb_op op);
658extern void nfsd4_run_cb(struct nfsd4_callback *cb);
659extern int nfsd4_create_callback_queue(void);
660extern void nfsd4_destroy_callback_queue(void);
661extern void nfsd4_shutdown_callback(struct nfs4_client *);
662extern void nfsd4_shutdown_copy(struct nfs4_client *clp);
663extern void nfsd4_prepare_cb_recall(struct nfs4_delegation *dp);
664extern struct nfs4_client_reclaim *nfs4_client_to_reclaim(struct xdr_netobj name,
665 struct xdr_netobj princhash, struct nfsd_net *nn);
666extern bool nfs4_has_reclaimed_state(struct xdr_netobj name, struct nfsd_net *nn);
667
668struct nfs4_file *find_file(struct knfsd_fh *fh);
669void put_nfs4_file(struct nfs4_file *fi);
670extern void nfs4_put_copy(struct nfsd4_copy *copy);
671extern struct nfsd4_copy *
672find_async_copy(struct nfs4_client *clp, stateid_t *staetid);
673extern void nfs4_put_cpntf_state(struct nfsd_net *nn,
674 struct nfs4_cpntf_state *cps);
675extern __be32 manage_cpntf_state(struct nfsd_net *nn, stateid_t *st,
676 struct nfs4_client *clp,
677 struct nfs4_cpntf_state **cps);
678static inline void get_nfs4_file(struct nfs4_file *fi)
679{
680 refcount_inc(&fi->fi_ref);
681}
682struct nfsd_file *find_any_file(struct nfs4_file *f);
683
684
685void nfsd4_end_grace(struct nfsd_net *nn);
686
687
688extern int nfsd4_client_tracking_init(struct net *net);
689extern void nfsd4_client_tracking_exit(struct net *net);
690extern void nfsd4_client_record_create(struct nfs4_client *clp);
691extern void nfsd4_client_record_remove(struct nfs4_client *clp);
692extern int nfsd4_client_record_check(struct nfs4_client *clp);
693extern void nfsd4_record_grace_done(struct nfsd_net *nn);
694
695#endif
696