xref: /linux/fs/nfs/delegation.h (revision 6c2d8f8d307033a7cdfee3f4cb9dc4679ab69513)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * linux/fs/nfs/delegation.h
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  * Copyright (c) Trond Myklebust
51da177e4SLinus Torvalds  *
61da177e4SLinus Torvalds  * Definitions pertaining to NFS delegated files
71da177e4SLinus Torvalds  */
81da177e4SLinus Torvalds #ifndef FS_NFS_DELEGATION_H
91da177e4SLinus Torvalds #define FS_NFS_DELEGATION_H
101da177e4SLinus Torvalds 
1189d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4)
121da177e4SLinus Torvalds /*
131da177e4SLinus Torvalds  * NFSv4 delegation
141da177e4SLinus Torvalds  */
151da177e4SLinus Torvalds struct nfs_delegation {
161da177e4SLinus Torvalds 	struct list_head super_list;
171da177e4SLinus Torvalds 	struct rpc_cred *cred;
181da177e4SLinus Torvalds 	struct inode *inode;
191da177e4SLinus Torvalds 	nfs4_stateid stateid;
20bd7bf9d5STrond Myklebust 	fmode_t type;
217d160a6cSTrond Myklebust 	unsigned long pagemod_limit;
22beb2a5ecSTrond Myklebust 	__u64 change_attr;
2315c831bfSTrond Myklebust 	unsigned long flags;
2434310430STrond Myklebust 	spinlock_t lock;
258383e460STrond Myklebust 	struct rcu_head rcu;
261da177e4SLinus Torvalds };
271da177e4SLinus Torvalds 
28515d8611STrond Myklebust enum {
29515d8611STrond Myklebust 	NFS_DELEGATION_NEED_RECLAIM = 0,
30515d8611STrond Myklebust 	NFS_DELEGATION_RETURN,
31b757144fSTrond Myklebust 	NFS_DELEGATION_RETURN_IF_CLOSED,
32b7391f44STrond Myklebust 	NFS_DELEGATION_REFERENCED,
33d25be546STrond Myklebust 	NFS_DELEGATION_RETURNING,
34869f9dfaSTrond Myklebust 	NFS_DELEGATION_REVOKED,
3545870d69STrond Myklebust 	NFS_DELEGATION_TEST_EXPIRED,
36515d8611STrond Myklebust };
37515d8611STrond Myklebust 
381da177e4SLinus Torvalds int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct nfs_openres *res);
391da177e4SLinus Torvalds void nfs_inode_reclaim_delegation(struct inode *inode, struct rpc_cred *cred, struct nfs_openres *res);
4057ec14c5SBryan Schumaker int nfs4_inode_return_delegation(struct inode *inode);
41e047a10cSTrond Myklebust int nfs_async_inode_return_delegation(struct inode *inode, const nfs4_stateid *stateid);
42e6f81075STrond Myklebust void nfs_inode_return_delegation_noreclaim(struct inode *inode);
431da177e4SLinus Torvalds 
44adfa6f98SDavid Howells struct inode *nfs_delegation_find_inode(struct nfs_client *clp, const struct nfs_fh *fhandle);
45eeebf916SBryan Schumaker void nfs_server_return_all_delegations(struct nfs_server *);
46adfa6f98SDavid Howells void nfs_expire_all_delegations(struct nfs_client *clp);
47826e0013STrond Myklebust void nfs_expire_unused_delegation_types(struct nfs_client *clp, fmode_t flags);
48b7391f44STrond Myklebust void nfs_expire_unreferenced_delegations(struct nfs_client *clp);
49d18cc1fdSTrond Myklebust int nfs_client_return_marked_delegations(struct nfs_client *clp);
50d3978bb3SChuck Lever int nfs_delegations_present(struct nfs_client *clp);
5141020b67STrond Myklebust void nfs_remove_bad_delegation(struct inode *inode, const nfs4_stateid *stateid);
521da177e4SLinus Torvalds 
53adfa6f98SDavid Howells void nfs_delegation_mark_reclaim(struct nfs_client *clp);
54adfa6f98SDavid Howells void nfs_delegation_reap_unclaimed(struct nfs_client *clp);
551da177e4SLinus Torvalds 
5645870d69STrond Myklebust void nfs_mark_test_expired_all_delegations(struct nfs_client *clp);
5745870d69STrond Myklebust void nfs_reap_expired_delegations(struct nfs_client *clp);
5845870d69STrond Myklebust 
591da177e4SLinus Torvalds /* NFSv4 delegation-related procedures */
60e6f81075STrond Myklebust int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync);
6124311f88STrond Myklebust int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid, fmode_t type);
62db4f2e63STrond Myklebust int nfs4_lock_delegation_recall(struct file_lock *fl, struct nfs4_state *state, const nfs4_stateid *stateid);
63abf4e13cSTrond Myklebust bool nfs4_copy_delegation_stateid(struct inode *inode, fmode_t flags, nfs4_stateid *dst, struct rpc_cred **cred);
641da177e4SLinus Torvalds 
65b7391f44STrond Myklebust void nfs_mark_delegation_referenced(struct nfs_delegation *delegation);
66011e2a7fSBryan Schumaker int nfs4_have_delegation(struct inode *inode, fmode_t flags);
6715bb3afeSPeng Tao int nfs4_check_delegation(struct inode *inode, fmode_t flags);
685445b1fbSTrond Myklebust bool nfs4_delegation_flush_on_close(const struct inode *inode);
69*6c2d8f8dSTrond Myklebust void nfs_inode_find_delegation_state_and_recover(struct inode *inode,
70*6c2d8f8dSTrond Myklebust 		const nfs4_stateid *stateid);
71cae7a073STrond Myklebust 
721da177e4SLinus Torvalds #endif
731da177e4SLinus Torvalds 
74b4d2314bSTrond Myklebust static inline int nfs_have_delegated_attributes(struct inode *inode)
75b4d2314bSTrond Myklebust {
76011e2a7fSBryan Schumaker 	return NFS_PROTO(inode)->have_delegation(inode, FMODE_READ) &&
77b4d2314bSTrond Myklebust 		!(NFS_I(inode)->cache_validity & NFS_INO_REVAL_FORCED);
78b4d2314bSTrond Myklebust }
79b4d2314bSTrond Myklebust 
801da177e4SLinus Torvalds #endif
81