xref: /linux/fs/nfs/delegation.h (revision e047a10c1293ee0ab20258154e7f3ebf8ad502d6)
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;
20bd7bf9d5STrond Myklebust 	fmode_t type;
211da177e4SLinus Torvalds 	loff_t maxsize;
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,
31b7391f44STrond Myklebust 	NFS_DELEGATION_REFERENCED,
32515d8611STrond Myklebust };
33515d8611STrond Myklebust 
341da177e4SLinus Torvalds int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct nfs_openres *res);
351da177e4SLinus Torvalds void nfs_inode_reclaim_delegation(struct inode *inode, struct rpc_cred *cred, struct nfs_openres *res);
3690163027STrond Myklebust int nfs_inode_return_delegation(struct inode *inode);
37*e047a10cSTrond Myklebust int nfs_async_inode_return_delegation(struct inode *inode, const nfs4_stateid *stateid);
38e6f81075STrond Myklebust void nfs_inode_return_delegation_noreclaim(struct inode *inode);
391da177e4SLinus Torvalds 
40adfa6f98SDavid Howells struct inode *nfs_delegation_find_inode(struct nfs_client *clp, const struct nfs_fh *fhandle);
41515d8611STrond Myklebust void nfs_super_return_all_delegations(struct super_block *sb);
42adfa6f98SDavid Howells void nfs_expire_all_delegations(struct nfs_client *clp);
4331f09607SAlexandros Batsakis void nfs_expire_all_delegation_types(struct nfs_client *clp, fmode_t flags);
44b7391f44STrond Myklebust void nfs_expire_unreferenced_delegations(struct nfs_client *clp);
45adfa6f98SDavid Howells void nfs_handle_cb_pathdown(struct nfs_client *clp);
46d18cc1fdSTrond Myklebust int nfs_client_return_marked_delegations(struct nfs_client *clp);
471da177e4SLinus Torvalds 
48adfa6f98SDavid Howells void nfs_delegation_mark_reclaim(struct nfs_client *clp);
49adfa6f98SDavid Howells void nfs_delegation_reap_unclaimed(struct nfs_client *clp);
501da177e4SLinus Torvalds 
511da177e4SLinus Torvalds /* NFSv4 delegation-related procedures */
52e6f81075STrond Myklebust int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync);
5313437e12STrond Myklebust int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid);
54888e694cSTrond Myklebust int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl);
553e4f6290STrond Myklebust int nfs4_copy_delegation_stateid(nfs4_stateid *dst, struct inode *inode);
561da177e4SLinus Torvalds 
57b7391f44STrond Myklebust void nfs_mark_delegation_referenced(struct nfs_delegation *delegation);
58bd7bf9d5STrond Myklebust int nfs_have_delegation(struct inode *inode, fmode_t flags);
59cae7a073STrond Myklebust 
601da177e4SLinus Torvalds #else
61bd7bf9d5STrond Myklebust static inline int nfs_have_delegation(struct inode *inode, fmode_t flags)
621da177e4SLinus Torvalds {
631da177e4SLinus Torvalds 	return 0;
641da177e4SLinus Torvalds }
65cae7a073STrond Myklebust 
66cae7a073STrond Myklebust static inline int nfs_inode_return_delegation(struct inode *inode)
67cae7a073STrond Myklebust {
68cae7a073STrond Myklebust 	return 0;
69cae7a073STrond Myklebust }
701da177e4SLinus Torvalds #endif
711da177e4SLinus Torvalds 
72b4d2314bSTrond Myklebust static inline int nfs_have_delegated_attributes(struct inode *inode)
73b4d2314bSTrond Myklebust {
74b4d2314bSTrond Myklebust 	return nfs_have_delegation(inode, FMODE_READ) &&
75b4d2314bSTrond Myklebust 		!(NFS_I(inode)->cache_validity & NFS_INO_REVAL_FORCED);
76b4d2314bSTrond Myklebust }
77b4d2314bSTrond Myklebust 
781da177e4SLinus Torvalds #endif
79