xref: /linux/fs/nfs/delegation.h (revision 8383e4602c89857ef926f29ca61ac0a83a614443)
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 
111da177e4SLinus Torvalds #if defined(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;
201da177e4SLinus Torvalds 	int type;
211da177e4SLinus Torvalds #define NFS_DELEGATION_NEED_RECLAIM 1
221da177e4SLinus Torvalds 	long flags;
231da177e4SLinus Torvalds 	loff_t maxsize;
24beb2a5ecSTrond Myklebust 	__u64 change_attr;
25*8383e460STrond Myklebust 	struct rcu_head rcu;
261da177e4SLinus Torvalds };
271da177e4SLinus Torvalds 
281da177e4SLinus Torvalds int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct nfs_openres *res);
291da177e4SLinus Torvalds void nfs_inode_reclaim_delegation(struct inode *inode, struct rpc_cred *cred, struct nfs_openres *res);
3090163027STrond Myklebust int nfs_inode_return_delegation(struct inode *inode);
311da177e4SLinus Torvalds int nfs_async_inode_return_delegation(struct inode *inode, const nfs4_stateid *stateid);
321da177e4SLinus Torvalds 
33adfa6f98SDavid Howells struct inode *nfs_delegation_find_inode(struct nfs_client *clp, const struct nfs_fh *fhandle);
341da177e4SLinus Torvalds void nfs_return_all_delegations(struct super_block *sb);
35adfa6f98SDavid Howells void nfs_expire_all_delegations(struct nfs_client *clp);
36adfa6f98SDavid Howells void nfs_handle_cb_pathdown(struct nfs_client *clp);
371da177e4SLinus Torvalds 
38adfa6f98SDavid Howells void nfs_delegation_mark_reclaim(struct nfs_client *clp);
39adfa6f98SDavid Howells void nfs_delegation_reap_unclaimed(struct nfs_client *clp);
401da177e4SLinus Torvalds 
411da177e4SLinus Torvalds /* NFSv4 delegation-related procedures */
421da177e4SLinus Torvalds int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid);
4313437e12STrond Myklebust int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid);
44888e694cSTrond Myklebust int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl);
453e4f6290STrond Myklebust int nfs4_copy_delegation_stateid(nfs4_stateid *dst, struct inode *inode);
461da177e4SLinus Torvalds 
471da177e4SLinus Torvalds static inline int nfs_have_delegation(struct inode *inode, int flags)
481da177e4SLinus Torvalds {
49*8383e460STrond Myklebust 	struct nfs_delegation *delegation;
50*8383e460STrond Myklebust 	int ret = 0;
51*8383e460STrond Myklebust 
521da177e4SLinus Torvalds 	flags &= FMODE_READ|FMODE_WRITE;
53*8383e460STrond Myklebust 	rcu_read_lock();
54*8383e460STrond Myklebust 	delegation = rcu_dereference(NFS_I(inode)->delegation);
55*8383e460STrond Myklebust 	if (delegation != NULL && (delegation->type & flags) == flags)
56*8383e460STrond Myklebust 		ret = 1;
57*8383e460STrond Myklebust 	rcu_read_unlock();
58*8383e460STrond Myklebust 	return ret;
591da177e4SLinus Torvalds }
60cae7a073STrond Myklebust 
611da177e4SLinus Torvalds #else
621da177e4SLinus Torvalds static inline int nfs_have_delegation(struct inode *inode, int flags)
631da177e4SLinus Torvalds {
641da177e4SLinus Torvalds 	return 0;
651da177e4SLinus Torvalds }
66cae7a073STrond Myklebust 
67cae7a073STrond Myklebust static inline int nfs_inode_return_delegation(struct inode *inode)
68cae7a073STrond Myklebust {
69cae7a073STrond Myklebust 	return 0;
70cae7a073STrond Myklebust }
711da177e4SLinus Torvalds #endif
721da177e4SLinus Torvalds 
731da177e4SLinus Torvalds #endif
74