0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 #ifndef _NFSD4_STATE_H
0036 #define _NFSD4_STATE_H
0037
0038 #include <linux/idr.h>
0039 #include <linux/refcount.h>
0040 #include <linux/sunrpc/svc_xprt.h>
0041 #include "nfsfh.h"
0042 #include "nfsd.h"
0043
0044 typedef struct {
0045 u32 cl_boot;
0046 u32 cl_id;
0047 } clientid_t;
0048
0049 typedef struct {
0050 clientid_t so_clid;
0051 u32 so_id;
0052 } stateid_opaque_t;
0053
0054 typedef struct {
0055 u32 si_generation;
0056 stateid_opaque_t si_opaque;
0057 } stateid_t;
0058
0059 typedef struct {
0060 stateid_t stid;
0061 #define NFS4_COPY_STID 1
0062 #define NFS4_COPYNOTIFY_STID 2
0063 unsigned char sc_type;
0064 refcount_t sc_count;
0065 } copy_stateid_t;
0066
0067 struct nfsd4_callback {
0068 struct nfs4_client *cb_clp;
0069 struct rpc_message cb_msg;
0070 const struct nfsd4_callback_ops *cb_ops;
0071 struct work_struct cb_work;
0072 int cb_seq_status;
0073 int cb_status;
0074 bool cb_need_restart;
0075 bool cb_holds_slot;
0076 };
0077
0078 struct nfsd4_callback_ops {
0079 void (*prepare)(struct nfsd4_callback *);
0080 int (*done)(struct nfsd4_callback *, struct rpc_task *);
0081 void (*release)(struct nfsd4_callback *);
0082 };
0083
0084
0085
0086
0087
0088
0089 struct nfs4_stid {
0090 refcount_t sc_count;
0091 #define NFS4_OPEN_STID 1
0092 #define NFS4_LOCK_STID 2
0093 #define NFS4_DELEG_STID 4
0094
0095 #define NFS4_CLOSED_STID 8
0096
0097 #define NFS4_REVOKED_DELEG_STID 16
0098 #define NFS4_CLOSED_DELEG_STID 32
0099 #define NFS4_LAYOUT_STID 64
0100 struct list_head sc_cp_list;
0101 unsigned char sc_type;
0102 stateid_t sc_stateid;
0103 spinlock_t sc_lock;
0104 struct nfs4_client *sc_client;
0105 struct nfs4_file *sc_file;
0106 void (*sc_free)(struct nfs4_stid *);
0107 };
0108
0109
0110
0111
0112 struct nfs4_cpntf_state {
0113 copy_stateid_t cp_stateid;
0114 struct list_head cp_list;
0115 stateid_t cp_p_stateid;
0116 clientid_t cp_p_clid;
0117 time64_t cpntf_time;
0118 };
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141 struct nfs4_delegation {
0142 struct nfs4_stid dl_stid;
0143 struct list_head dl_perfile;
0144 struct list_head dl_perclnt;
0145 struct list_head dl_recall_lru;
0146 struct nfs4_clnt_odstate *dl_clnt_odstate;
0147 u32 dl_type;
0148 time64_t dl_time;
0149
0150 int dl_retries;
0151 struct nfsd4_callback dl_recall;
0152 bool dl_recalled;
0153 };
0154
0155 #define cb_to_delegation(cb) \
0156 container_of(cb, struct nfs4_delegation, dl_recall)
0157
0158
0159 struct nfs4_cb_conn {
0160
0161 struct sockaddr_storage cb_addr;
0162 struct sockaddr_storage cb_saddr;
0163 size_t cb_addrlen;
0164 u32 cb_prog;
0165
0166 u32 cb_ident;
0167 struct svc_xprt *cb_xprt;
0168 };
0169
0170 static inline struct nfs4_delegation *delegstateid(struct nfs4_stid *s)
0171 {
0172 return container_of(s, struct nfs4_delegation, dl_stid);
0173 }
0174
0175
0176 #define NFSD_MAX_SLOTS_PER_SESSION 160
0177
0178 #define NFSD_MAX_OPS_PER_COMPOUND 16
0179
0180 #define NFSD_SLOT_CACHE_SIZE 2048
0181
0182 #define NFSD_CACHE_SIZE_SLOTS_PER_SESSION 32
0183 #define NFSD_MAX_MEM_PER_SESSION \
0184 (NFSD_CACHE_SIZE_SLOTS_PER_SESSION * NFSD_SLOT_CACHE_SIZE)
0185
0186 struct nfsd4_slot {
0187 u32 sl_seqid;
0188 __be32 sl_status;
0189 struct svc_cred sl_cred;
0190 u32 sl_datalen;
0191 u16 sl_opcnt;
0192 #define NFSD4_SLOT_INUSE (1 << 0)
0193 #define NFSD4_SLOT_CACHETHIS (1 << 1)
0194 #define NFSD4_SLOT_INITIALIZED (1 << 2)
0195 #define NFSD4_SLOT_CACHED (1 << 3)
0196 u8 sl_flags;
0197 char sl_data[];
0198 };
0199
0200 struct nfsd4_channel_attrs {
0201 u32 headerpadsz;
0202 u32 maxreq_sz;
0203 u32 maxresp_sz;
0204 u32 maxresp_cached;
0205 u32 maxops;
0206 u32 maxreqs;
0207 u32 nr_rdma_attrs;
0208 u32 rdma_attrs;
0209 };
0210
0211 struct nfsd4_cb_sec {
0212 u32 flavor;
0213 kuid_t uid;
0214 kgid_t gid;
0215 };
0216
0217 struct nfsd4_create_session {
0218 clientid_t clientid;
0219 struct nfs4_sessionid sessionid;
0220 u32 seqid;
0221 u32 flags;
0222 struct nfsd4_channel_attrs fore_channel;
0223 struct nfsd4_channel_attrs back_channel;
0224 u32 callback_prog;
0225 struct nfsd4_cb_sec cb_sec;
0226 };
0227
0228 struct nfsd4_backchannel_ctl {
0229 u32 bc_cb_program;
0230 struct nfsd4_cb_sec bc_cb_sec;
0231 };
0232
0233 struct nfsd4_bind_conn_to_session {
0234 struct nfs4_sessionid sessionid;
0235 u32 dir;
0236 };
0237
0238
0239 struct nfsd4_clid_slot {
0240 u32 sl_seqid;
0241 __be32 sl_status;
0242 struct nfsd4_create_session sl_cr_ses;
0243 };
0244
0245 struct nfsd4_conn {
0246 struct list_head cn_persession;
0247 struct svc_xprt *cn_xprt;
0248 struct svc_xpt_user cn_xpt_user;
0249 struct nfsd4_session *cn_session;
0250
0251 unsigned char cn_flags;
0252 };
0253
0254
0255
0256
0257
0258
0259 struct nfsd4_session {
0260 atomic_t se_ref;
0261 struct list_head se_hash;
0262 struct list_head se_perclnt;
0263
0264 #define NFS4_SESSION_DEAD 0x010
0265 u32 se_flags;
0266 struct nfs4_client *se_client;
0267 struct nfs4_sessionid se_sessionid;
0268 struct nfsd4_channel_attrs se_fchannel;
0269 struct nfsd4_channel_attrs se_bchannel;
0270 struct nfsd4_cb_sec se_cb_sec;
0271 struct list_head se_conns;
0272 u32 se_cb_prog;
0273 u32 se_cb_seq_nr;
0274 struct nfsd4_slot *se_slots[];
0275 };
0276
0277
0278 struct nfsd4_sessionid {
0279 clientid_t clientid;
0280 u32 sequence;
0281 u32 reserved;
0282 };
0283
0284 #define HEXDIR_LEN 33
0285
0286
0287
0288
0289
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302 enum {
0303 NFSD4_ACTIVE = 0,
0304 NFSD4_COURTESY,
0305 NFSD4_EXPIRABLE,
0306 };
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319
0320
0321
0322
0323
0324
0325
0326
0327
0328
0329
0330
0331
0332
0333
0334
0335 struct nfs4_client {
0336 struct list_head cl_idhash;
0337 struct rb_node cl_namenode;
0338 struct list_head *cl_ownerstr_hashtbl;
0339 struct list_head cl_openowners;
0340 struct idr cl_stateids;
0341 struct list_head cl_delegations;
0342 struct list_head cl_revoked;
0343 struct list_head cl_lru;
0344 #ifdef CONFIG_NFSD_PNFS
0345 struct list_head cl_lo_states;
0346 #endif
0347 struct xdr_netobj cl_name;
0348 nfs4_verifier cl_verifier;
0349 time64_t cl_time;
0350 struct sockaddr_storage cl_addr;
0351 bool cl_mach_cred;
0352 struct svc_cred cl_cred;
0353 clientid_t cl_clientid;
0354 nfs4_verifier cl_confirm;
0355 u32 cl_minorversion;
0356
0357 struct xdr_netobj cl_nii_domain;
0358 struct xdr_netobj cl_nii_name;
0359 struct timespec64 cl_nii_time;
0360
0361
0362 struct nfs4_cb_conn cl_cb_conn;
0363 #define NFSD4_CLIENT_CB_UPDATE (0)
0364 #define NFSD4_CLIENT_CB_KILL (1)
0365 #define NFSD4_CLIENT_STABLE (2)
0366 #define NFSD4_CLIENT_RECLAIM_COMPLETE (3)
0367 #define NFSD4_CLIENT_CONFIRMED (4)
0368 #define NFSD4_CLIENT_UPCALL_LOCK (5)
0369 #define NFSD4_CLIENT_CB_FLAG_MASK (1 << NFSD4_CLIENT_CB_UPDATE | \
0370 1 << NFSD4_CLIENT_CB_KILL)
0371 unsigned long cl_flags;
0372 const struct cred *cl_cb_cred;
0373 struct rpc_clnt *cl_cb_client;
0374 u32 cl_cb_ident;
0375 #define NFSD4_CB_UP 0
0376 #define NFSD4_CB_UNKNOWN 1
0377 #define NFSD4_CB_DOWN 2
0378 #define NFSD4_CB_FAULT 3
0379 int cl_cb_state;
0380 struct nfsd4_callback cl_cb_null;
0381 struct nfsd4_session *cl_cb_session;
0382
0383
0384 spinlock_t cl_lock;
0385
0386
0387 struct list_head cl_sessions;
0388 struct nfsd4_clid_slot cl_cs_slot;
0389 u32 cl_exchange_flags;
0390
0391 atomic_t cl_rpc_users;
0392 struct nfsdfs_client cl_nfsdfs;
0393 struct nfs4_op_map cl_spo_must_allow;
0394
0395
0396 struct dentry *cl_nfsd_dentry;
0397
0398
0399
0400 struct dentry *cl_nfsd_info_dentry;
0401
0402
0403
0404 unsigned long cl_cb_slot_busy;
0405 struct rpc_wait_queue cl_cb_waitq;
0406
0407 struct net *net;
0408 struct list_head async_copies;
0409 spinlock_t async_lock;
0410 atomic_t cl_cb_inflight;
0411
0412 unsigned int cl_state;
0413 atomic_t cl_delegs_in_recall;
0414 };
0415
0416
0417
0418
0419
0420
0421 struct nfs4_client_reclaim {
0422 struct list_head cr_strhash;
0423 struct nfs4_client *cr_clp;
0424 struct xdr_netobj cr_name;
0425 struct xdr_netobj cr_princhash;
0426 };
0427
0428
0429
0430
0431
0432
0433
0434
0435 #define NFSD4_REPLAY_ISIZE 112
0436
0437
0438
0439
0440
0441 struct nfs4_replay {
0442 __be32 rp_status;
0443 unsigned int rp_buflen;
0444 char *rp_buf;
0445 struct knfsd_fh rp_openfh;
0446 struct mutex rp_mutex;
0447 char rp_ibuf[NFSD4_REPLAY_ISIZE];
0448 };
0449
0450 struct nfs4_stateowner;
0451
0452 struct nfs4_stateowner_operations {
0453 void (*so_unhash)(struct nfs4_stateowner *);
0454 void (*so_free)(struct nfs4_stateowner *);
0455 };
0456
0457
0458
0459
0460
0461
0462
0463 struct nfs4_stateowner {
0464 struct list_head so_strhash;
0465 struct list_head so_stateids;
0466 struct nfs4_client *so_client;
0467 const struct nfs4_stateowner_operations *so_ops;
0468
0469
0470 atomic_t so_count;
0471 u32 so_seqid;
0472 struct xdr_netobj so_owner;
0473 struct nfs4_replay so_replay;
0474 bool so_is_open_owner;
0475 };
0476
0477
0478
0479
0480
0481
0482
0483 struct nfs4_openowner {
0484 struct nfs4_stateowner oo_owner;
0485 struct list_head oo_perclient;
0486
0487
0488
0489
0490
0491
0492
0493 struct list_head oo_close_lru;
0494 struct nfs4_ol_stateid *oo_last_closed_stid;
0495 time64_t oo_time;
0496 #define NFS4_OO_CONFIRMED 1
0497 unsigned char oo_flags;
0498 };
0499
0500
0501
0502
0503
0504
0505 struct nfs4_lockowner {
0506 struct nfs4_stateowner lo_owner;
0507 struct list_head lo_blocked;
0508 };
0509
0510 static inline struct nfs4_openowner * openowner(struct nfs4_stateowner *so)
0511 {
0512 return container_of(so, struct nfs4_openowner, oo_owner);
0513 }
0514
0515 static inline struct nfs4_lockowner * lockowner(struct nfs4_stateowner *so)
0516 {
0517 return container_of(so, struct nfs4_lockowner, lo_owner);
0518 }
0519
0520
0521
0522
0523
0524 struct nfs4_clnt_odstate {
0525 struct nfs4_client *co_client;
0526 struct nfs4_file *co_file;
0527 struct list_head co_perfile;
0528 refcount_t co_odcount;
0529 };
0530
0531
0532
0533
0534
0535
0536
0537
0538
0539
0540
0541
0542
0543 struct nfs4_file {
0544 refcount_t fi_ref;
0545 struct inode * fi_inode;
0546 bool fi_aliased;
0547 spinlock_t fi_lock;
0548 struct hlist_node fi_hash;
0549 struct list_head fi_stateids;
0550 union {
0551 struct list_head fi_delegations;
0552 struct rcu_head fi_rcu;
0553 };
0554 struct list_head fi_clnt_odstate;
0555
0556 struct nfsd_file *fi_fds[3];
0557
0558
0559
0560
0561
0562
0563
0564 atomic_t fi_access[2];
0565 u32 fi_share_deny;
0566 struct nfsd_file *fi_deleg_file;
0567 int fi_delegees;
0568 struct knfsd_fh fi_fhandle;
0569 bool fi_had_conflict;
0570 #ifdef CONFIG_NFSD_PNFS
0571 struct list_head fi_lo_states;
0572 atomic_t fi_lo_recalls;
0573 #endif
0574 };
0575
0576
0577
0578
0579
0580
0581
0582
0583
0584
0585
0586
0587
0588
0589
0590 struct nfs4_ol_stateid {
0591 struct nfs4_stid st_stid;
0592 struct list_head st_perfile;
0593 struct list_head st_perstateowner;
0594 struct list_head st_locks;
0595 struct nfs4_stateowner *st_stateowner;
0596 struct nfs4_clnt_odstate *st_clnt_odstate;
0597
0598
0599
0600
0601 unsigned char st_access_bmap;
0602 unsigned char st_deny_bmap;
0603 struct nfs4_ol_stateid *st_openstp;
0604 struct mutex st_mutex;
0605 };
0606
0607 static inline struct nfs4_ol_stateid *openlockstateid(struct nfs4_stid *s)
0608 {
0609 return container_of(s, struct nfs4_ol_stateid, st_stid);
0610 }
0611
0612 struct nfs4_layout_stateid {
0613 struct nfs4_stid ls_stid;
0614 struct list_head ls_perclnt;
0615 struct list_head ls_perfile;
0616 spinlock_t ls_lock;
0617 struct list_head ls_layouts;
0618 u32 ls_layout_type;
0619 struct nfsd_file *ls_file;
0620 struct nfsd4_callback ls_recall;
0621 stateid_t ls_recall_sid;
0622 bool ls_recalled;
0623 struct mutex ls_mutex;
0624 };
0625
0626 static inline struct nfs4_layout_stateid *layoutstateid(struct nfs4_stid *s)
0627 {
0628 return container_of(s, struct nfs4_layout_stateid, ls_stid);
0629 }
0630
0631
0632 #define RD_STATE 0x00000010
0633 #define WR_STATE 0x00000020
0634
0635 enum nfsd4_cb_op {
0636 NFSPROC4_CLNT_CB_NULL = 0,
0637 NFSPROC4_CLNT_CB_RECALL,
0638 NFSPROC4_CLNT_CB_LAYOUT,
0639 NFSPROC4_CLNT_CB_OFFLOAD,
0640 NFSPROC4_CLNT_CB_SEQUENCE,
0641 NFSPROC4_CLNT_CB_NOTIFY_LOCK,
0642 };
0643
0644
0645 static inline bool nfsd4_stateid_generation_after(stateid_t *a, stateid_t *b)
0646 {
0647 return (s32)(a->si_generation - b->si_generation) > 0;
0648 }
0649
0650
0651
0652
0653
0654
0655 struct nfsd4_blocked_lock {
0656 struct list_head nbl_list;
0657 struct list_head nbl_lru;
0658 time64_t nbl_time;
0659 struct file_lock nbl_lock;
0660 struct knfsd_fh nbl_fh;
0661 struct nfsd4_callback nbl_cb;
0662 struct kref nbl_kref;
0663 };
0664
0665 struct nfsd4_compound_state;
0666 struct nfsd_net;
0667 struct nfsd4_copy;
0668
0669 extern __be32 nfs4_preprocess_stateid_op(struct svc_rqst *rqstp,
0670 struct nfsd4_compound_state *cstate, struct svc_fh *fhp,
0671 stateid_t *stateid, int flags, struct nfsd_file **filp,
0672 struct nfs4_stid **cstid);
0673 __be32 nfsd4_lookup_stateid(struct nfsd4_compound_state *cstate,
0674 stateid_t *stateid, unsigned char typemask,
0675 struct nfs4_stid **s, struct nfsd_net *nn);
0676 struct nfs4_stid *nfs4_alloc_stid(struct nfs4_client *cl, struct kmem_cache *slab,
0677 void (*sc_free)(struct nfs4_stid *));
0678 int nfs4_init_copy_state(struct nfsd_net *nn, struct nfsd4_copy *copy);
0679 void nfs4_free_copy_state(struct nfsd4_copy *copy);
0680 struct nfs4_cpntf_state *nfs4_alloc_init_cpntf_state(struct nfsd_net *nn,
0681 struct nfs4_stid *p_stid);
0682 void nfs4_unhash_stid(struct nfs4_stid *s);
0683 void nfs4_put_stid(struct nfs4_stid *s);
0684 void nfs4_inc_and_copy_stateid(stateid_t *dst, struct nfs4_stid *stid);
0685 void nfs4_remove_reclaim_record(struct nfs4_client_reclaim *, struct nfsd_net *);
0686 extern void nfs4_release_reclaim(struct nfsd_net *);
0687 extern struct nfs4_client_reclaim *nfsd4_find_reclaim_client(struct xdr_netobj name,
0688 struct nfsd_net *nn);
0689 extern __be32 nfs4_check_open_reclaim(struct nfs4_client *);
0690 extern void nfsd4_probe_callback(struct nfs4_client *clp);
0691 extern void nfsd4_probe_callback_sync(struct nfs4_client *clp);
0692 extern void nfsd4_change_callback(struct nfs4_client *clp, struct nfs4_cb_conn *);
0693 extern void nfsd4_init_cb(struct nfsd4_callback *cb, struct nfs4_client *clp,
0694 const struct nfsd4_callback_ops *ops, enum nfsd4_cb_op op);
0695 extern void nfsd4_run_cb(struct nfsd4_callback *cb);
0696 extern int nfsd4_create_callback_queue(void);
0697 extern void nfsd4_destroy_callback_queue(void);
0698 extern void nfsd4_shutdown_callback(struct nfs4_client *);
0699 extern void nfsd4_shutdown_copy(struct nfs4_client *clp);
0700 extern void nfsd4_prepare_cb_recall(struct nfs4_delegation *dp);
0701 extern struct nfs4_client_reclaim *nfs4_client_to_reclaim(struct xdr_netobj name,
0702 struct xdr_netobj princhash, struct nfsd_net *nn);
0703 extern bool nfs4_has_reclaimed_state(struct xdr_netobj name, struct nfsd_net *nn);
0704
0705 void put_nfs4_file(struct nfs4_file *fi);
0706 extern struct nfsd4_copy *
0707 find_async_copy(struct nfs4_client *clp, stateid_t *staetid);
0708 extern void nfs4_put_cpntf_state(struct nfsd_net *nn,
0709 struct nfs4_cpntf_state *cps);
0710 extern __be32 manage_cpntf_state(struct nfsd_net *nn, stateid_t *st,
0711 struct nfs4_client *clp,
0712 struct nfs4_cpntf_state **cps);
0713 static inline void get_nfs4_file(struct nfs4_file *fi)
0714 {
0715 refcount_inc(&fi->fi_ref);
0716 }
0717 struct nfsd_file *find_any_file(struct nfs4_file *f);
0718
0719
0720 void nfsd4_end_grace(struct nfsd_net *nn);
0721
0722
0723 extern int nfsd4_client_tracking_init(struct net *net);
0724 extern void nfsd4_client_tracking_exit(struct net *net);
0725 extern void nfsd4_client_record_create(struct nfs4_client *clp);
0726 extern void nfsd4_client_record_remove(struct nfs4_client *clp);
0727 extern int nfsd4_client_record_check(struct nfs4_client *clp);
0728 extern void nfsd4_record_grace_done(struct nfsd_net *nn);
0729
0730 static inline bool try_to_expire_client(struct nfs4_client *clp)
0731 {
0732 cmpxchg(&clp->cl_state, NFSD4_COURTESY, NFSD4_EXPIRABLE);
0733 return clp->cl_state == NFSD4_EXPIRABLE;
0734 }
0735 #endif