xref: /linux/fs/nfs/delegation.h (revision a9b8d90f87263f985fa14250fc8caf7bfcde8803)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds  * linux/fs/nfs/delegation.h
41da177e4SLinus Torvalds  *
51da177e4SLinus Torvalds  * Copyright (c) Trond Myklebust
61da177e4SLinus Torvalds  *
71da177e4SLinus Torvalds  * Definitions pertaining to NFS delegated files
81da177e4SLinus Torvalds  */
91da177e4SLinus Torvalds #ifndef FS_NFS_DELEGATION_H
101da177e4SLinus Torvalds #define FS_NFS_DELEGATION_H
111da177e4SLinus Torvalds 
1289d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4)
131da177e4SLinus Torvalds /*
141da177e4SLinus Torvalds  * NFSv4 delegation
151da177e4SLinus Torvalds  */
161da177e4SLinus Torvalds struct nfs_delegation {
171da177e4SLinus Torvalds 	struct list_head super_list;
18a52458b4SNeilBrown 	const struct cred *cred;
191da177e4SLinus Torvalds 	struct inode *inode;
201da177e4SLinus Torvalds 	nfs4_stateid stateid;
21bd7bf9d5STrond Myklebust 	fmode_t type;
227d160a6cSTrond Myklebust 	unsigned long pagemod_limit;
23beb2a5ecSTrond Myklebust 	__u64 change_attr;
24*a9b8d90fSBenjamin Coddington 	unsigned long test_gen;
2515c831bfSTrond Myklebust 	unsigned long flags;
268c75593cSTrond Myklebust 	refcount_t refcount;
2734310430STrond Myklebust 	spinlock_t lock;
288383e460STrond Myklebust 	struct rcu_head rcu;
291da177e4SLinus Torvalds };
301da177e4SLinus Torvalds 
31515d8611STrond Myklebust enum {
32515d8611STrond Myklebust 	NFS_DELEGATION_NEED_RECLAIM = 0,
33515d8611STrond Myklebust 	NFS_DELEGATION_RETURN,
34b757144fSTrond Myklebust 	NFS_DELEGATION_RETURN_IF_CLOSED,
35b7391f44STrond Myklebust 	NFS_DELEGATION_REFERENCED,
36d25be546STrond Myklebust 	NFS_DELEGATION_RETURNING,
37869f9dfaSTrond Myklebust 	NFS_DELEGATION_REVOKED,
3845870d69STrond Myklebust 	NFS_DELEGATION_TEST_EXPIRED,
396f9449beSTrond Myklebust 	NFS_DELEGATION_INODE_FREEING,
40be200377STrond Myklebust 	NFS_DELEGATION_RETURN_DELAYED,
41515d8611STrond Myklebust };
42515d8611STrond Myklebust 
43a52458b4SNeilBrown int nfs_inode_set_delegation(struct inode *inode, const struct cred *cred,
4435156bffSTrond Myklebust 		fmode_t type, const nfs4_stateid *stateid, unsigned long pagemod_limit);
45a52458b4SNeilBrown void nfs_inode_reclaim_delegation(struct inode *inode, const struct cred *cred,
4635156bffSTrond Myklebust 		fmode_t type, const nfs4_stateid *stateid, unsigned long pagemod_limit);
4757ec14c5SBryan Schumaker int nfs4_inode_return_delegation(struct inode *inode);
48b7b7dac6STrond Myklebust void nfs4_inode_return_delegation_on_close(struct inode *inode);
49e047a10cSTrond Myklebust int nfs_async_inode_return_delegation(struct inode *inode, const nfs4_stateid *stateid);
50b47e0e47STrond Myklebust void nfs_inode_evict_delegation(struct inode *inode);
511da177e4SLinus Torvalds 
52adfa6f98SDavid Howells struct inode *nfs_delegation_find_inode(struct nfs_client *clp, const struct nfs_fh *fhandle);
53eeebf916SBryan Schumaker void nfs_server_return_all_delegations(struct nfs_server *);
54adfa6f98SDavid Howells void nfs_expire_all_delegations(struct nfs_client *clp);
55826e0013STrond Myklebust void nfs_expire_unused_delegation_types(struct nfs_client *clp, fmode_t flags);
56b7391f44STrond Myklebust void nfs_expire_unreferenced_delegations(struct nfs_client *clp);
57d18cc1fdSTrond Myklebust int nfs_client_return_marked_delegations(struct nfs_client *clp);
58d3978bb3SChuck Lever int nfs_delegations_present(struct nfs_client *clp);
5941020b67STrond Myklebust void nfs_remove_bad_delegation(struct inode *inode, const nfs4_stateid *stateid);
60d51f91d2STrond Myklebust void nfs_delegation_mark_returned(struct inode *inode, const nfs4_stateid *stateid);
611da177e4SLinus Torvalds 
62adfa6f98SDavid Howells void nfs_delegation_mark_reclaim(struct nfs_client *clp);
63adfa6f98SDavid Howells void nfs_delegation_reap_unclaimed(struct nfs_client *clp);
641da177e4SLinus Torvalds 
6545870d69STrond Myklebust void nfs_mark_test_expired_all_delegations(struct nfs_client *clp);
668ca017c8SScott Mayhew void nfs_test_expired_all_delegations(struct nfs_client *clp);
6745870d69STrond Myklebust void nfs_reap_expired_delegations(struct nfs_client *clp);
6845870d69STrond Myklebust 
691da177e4SLinus Torvalds /* NFSv4 delegation-related procedures */
70a52458b4SNeilBrown int nfs4_proc_delegreturn(struct inode *inode, const struct cred *cred, const nfs4_stateid *stateid, int issync);
715eb8d18cSTrond Myklebust int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid);
72db4f2e63STrond Myklebust int nfs4_lock_delegation_recall(struct file_lock *fl, struct nfs4_state *state, const nfs4_stateid *stateid);
73a52458b4SNeilBrown bool nfs4_copy_delegation_stateid(struct inode *inode, fmode_t flags, nfs4_stateid *dst, const struct cred **cred);
7412f275cdSTrond Myklebust bool nfs4_refresh_delegation_stateid(nfs4_stateid *dst, struct inode *inode);
751da177e4SLinus Torvalds 
76be3df3ddSTrond Myklebust struct nfs_delegation *nfs4_get_valid_delegation(const struct inode *inode);
77b7391f44STrond Myklebust void nfs_mark_delegation_referenced(struct nfs_delegation *delegation);
78011e2a7fSBryan Schumaker int nfs4_have_delegation(struct inode *inode, fmode_t flags);
7915bb3afeSPeng Tao int nfs4_check_delegation(struct inode *inode, fmode_t flags);
805445b1fbSTrond Myklebust bool nfs4_delegation_flush_on_close(const struct inode *inode);
816c2d8f8dSTrond Myklebust void nfs_inode_find_delegation_state_and_recover(struct inode *inode,
826c2d8f8dSTrond Myklebust 		const nfs4_stateid *stateid);
83c01d3645STrond Myklebust int nfs4_inode_make_writeable(struct inode *inode);
84cae7a073STrond Myklebust 
851da177e4SLinus Torvalds #endif
861da177e4SLinus Torvalds 
87b4d2314bSTrond Myklebust static inline int nfs_have_delegated_attributes(struct inode *inode)
88b4d2314bSTrond Myklebust {
89cc7f2daeSTrond Myklebust 	return NFS_PROTO(inode)->have_delegation(inode, FMODE_READ);
90b4d2314bSTrond Myklebust }
91b4d2314bSTrond Myklebust 
921da177e4SLinus Torvalds #endif
93