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;
24a9b8d90fSBenjamin 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,
41e12912d9STrond Myklebust NFS_DELEGATION_DELEGTIME,
42515d8611STrond Myklebust };
43515d8611STrond Myklebust
44a52458b4SNeilBrown int nfs_inode_set_delegation(struct inode *inode, const struct cred *cred,
45e12912d9STrond Myklebust fmode_t type, const nfs4_stateid *stateid,
46e12912d9STrond Myklebust unsigned long pagemod_limit, u32 deleg_type);
47a52458b4SNeilBrown void nfs_inode_reclaim_delegation(struct inode *inode, const struct cred *cred,
48e12912d9STrond Myklebust fmode_t type, const nfs4_stateid *stateid,
49e12912d9STrond Myklebust unsigned long pagemod_limit, u32 deleg_type);
5057ec14c5SBryan Schumaker int nfs4_inode_return_delegation(struct inode *inode);
51b7b7dac6STrond Myklebust void nfs4_inode_return_delegation_on_close(struct inode *inode);
52e047a10cSTrond Myklebust int nfs_async_inode_return_delegation(struct inode *inode, const nfs4_stateid *stateid);
53b47e0e47STrond Myklebust void nfs_inode_evict_delegation(struct inode *inode);
541da177e4SLinus Torvalds
55adfa6f98SDavid Howells struct inode *nfs_delegation_find_inode(struct nfs_client *clp, const struct nfs_fh *fhandle);
56eeebf916SBryan Schumaker void nfs_server_return_all_delegations(struct nfs_server *);
57adfa6f98SDavid Howells void nfs_expire_all_delegations(struct nfs_client *clp);
58826e0013STrond Myklebust void nfs_expire_unused_delegation_types(struct nfs_client *clp, fmode_t flags);
59b7391f44STrond Myklebust void nfs_expire_unreferenced_delegations(struct nfs_client *clp);
60d18cc1fdSTrond Myklebust int nfs_client_return_marked_delegations(struct nfs_client *clp);
61d3978bb3SChuck Lever int nfs_delegations_present(struct nfs_client *clp);
6241020b67STrond Myklebust void nfs_remove_bad_delegation(struct inode *inode, const nfs4_stateid *stateid);
63d51f91d2STrond Myklebust void nfs_delegation_mark_returned(struct inode *inode, const nfs4_stateid *stateid);
641da177e4SLinus Torvalds
65adfa6f98SDavid Howells void nfs_delegation_mark_reclaim(struct nfs_client *clp);
66adfa6f98SDavid Howells void nfs_delegation_reap_unclaimed(struct nfs_client *clp);
671da177e4SLinus Torvalds
6845870d69STrond Myklebust void nfs_mark_test_expired_all_delegations(struct nfs_client *clp);
698ca017c8SScott Mayhew void nfs_test_expired_all_delegations(struct nfs_client *clp);
7045870d69STrond Myklebust void nfs_reap_expired_delegations(struct nfs_client *clp);
7145870d69STrond Myklebust
721da177e4SLinus Torvalds /* NFSv4 delegation-related procedures */
73*b81aca09STrond Myklebust int nfs4_proc_delegreturn(struct inode *inode, const struct cred *cred,
74*b81aca09STrond Myklebust const nfs4_stateid *stateid,
75*b81aca09STrond Myklebust struct nfs_delegation *delegation, int issync);
765eb8d18cSTrond Myklebust int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid);
77db4f2e63STrond Myklebust int nfs4_lock_delegation_recall(struct file_lock *fl, struct nfs4_state *state, const nfs4_stateid *stateid);
78a52458b4SNeilBrown bool nfs4_copy_delegation_stateid(struct inode *inode, fmode_t flags, nfs4_stateid *dst, const struct cred **cred);
7912f275cdSTrond Myklebust bool nfs4_refresh_delegation_stateid(nfs4_stateid *dst, struct inode *inode);
801da177e4SLinus Torvalds
81be3df3ddSTrond Myklebust struct nfs_delegation *nfs4_get_valid_delegation(const struct inode *inode);
82b7391f44STrond Myklebust void nfs_mark_delegation_referenced(struct nfs_delegation *delegation);
834201916fSTrond Myklebust int nfs4_have_delegation(struct inode *inode, fmode_t type, int flags);
844201916fSTrond Myklebust int nfs4_check_delegation(struct inode *inode, fmode_t type);
855445b1fbSTrond Myklebust bool nfs4_delegation_flush_on_close(const struct inode *inode);
866c2d8f8dSTrond Myklebust void nfs_inode_find_delegation_state_and_recover(struct inode *inode,
876c2d8f8dSTrond Myklebust const nfs4_stateid *stateid);
88c01d3645STrond Myklebust int nfs4_inode_make_writeable(struct inode *inode);
89cae7a073STrond Myklebust
901da177e4SLinus Torvalds #endif
911da177e4SLinus Torvalds
92e12912d9STrond Myklebust #define NFS_DELEGATION_FLAG_TIME BIT(1)
93e12912d9STrond Myklebust
94e12912d9STrond Myklebust void nfs_update_delegated_atime(struct inode *inode);
95e12912d9STrond Myklebust void nfs_update_delegated_mtime(struct inode *inode);
96e12912d9STrond Myklebust void nfs_update_delegated_mtime_locked(struct inode *inode);
97e12912d9STrond Myklebust
nfs_have_read_or_write_delegation(struct inode * inode)984201916fSTrond Myklebust static inline int nfs_have_read_or_write_delegation(struct inode *inode)
994201916fSTrond Myklebust {
1004201916fSTrond Myklebust return NFS_PROTO(inode)->have_delegation(inode, FMODE_READ, 0);
1014201916fSTrond Myklebust }
1024201916fSTrond Myklebust
nfs_have_write_delegation(struct inode * inode)1034201916fSTrond Myklebust static inline int nfs_have_write_delegation(struct inode *inode)
1044201916fSTrond Myklebust {
1054201916fSTrond Myklebust return NFS_PROTO(inode)->have_delegation(inode, FMODE_WRITE, 0);
1064201916fSTrond Myklebust }
1074201916fSTrond Myklebust
nfs_have_delegated_attributes(struct inode * inode)108b4d2314bSTrond Myklebust static inline int nfs_have_delegated_attributes(struct inode *inode)
109b4d2314bSTrond Myklebust {
1104201916fSTrond Myklebust return NFS_PROTO(inode)->have_delegation(inode, FMODE_READ, 0);
111b4d2314bSTrond Myklebust }
112b4d2314bSTrond Myklebust
nfs_have_delegated_atime(struct inode * inode)113e12912d9STrond Myklebust static inline int nfs_have_delegated_atime(struct inode *inode)
114e12912d9STrond Myklebust {
115e12912d9STrond Myklebust return NFS_PROTO(inode)->have_delegation(inode, FMODE_READ,
116e12912d9STrond Myklebust NFS_DELEGATION_FLAG_TIME);
117e12912d9STrond Myklebust }
118e12912d9STrond Myklebust
nfs_have_delegated_mtime(struct inode * inode)119e12912d9STrond Myklebust static inline int nfs_have_delegated_mtime(struct inode *inode)
120e12912d9STrond Myklebust {
121e12912d9STrond Myklebust return NFS_PROTO(inode)->have_delegation(inode, FMODE_WRITE,
122e12912d9STrond Myklebust NFS_DELEGATION_FLAG_TIME);
123e12912d9STrond Myklebust }
124e12912d9STrond Myklebust
1251da177e4SLinus Torvalds #endif
126