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, 41*e12912d9STrond Myklebust NFS_DELEGATION_DELEGTIME, 42515d8611STrond Myklebust }; 43515d8611STrond Myklebust 44a52458b4SNeilBrown int nfs_inode_set_delegation(struct inode *inode, const struct cred *cred, 45*e12912d9STrond Myklebust fmode_t type, const nfs4_stateid *stateid, 46*e12912d9STrond Myklebust unsigned long pagemod_limit, u32 deleg_type); 47a52458b4SNeilBrown void nfs_inode_reclaim_delegation(struct inode *inode, const struct cred *cred, 48*e12912d9STrond Myklebust fmode_t type, const nfs4_stateid *stateid, 49*e12912d9STrond 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 */ 73a52458b4SNeilBrown int nfs4_proc_delegreturn(struct inode *inode, const struct cred *cred, const nfs4_stateid *stateid, int issync); 745eb8d18cSTrond Myklebust int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid); 75db4f2e63STrond Myklebust int nfs4_lock_delegation_recall(struct file_lock *fl, struct nfs4_state *state, const nfs4_stateid *stateid); 76a52458b4SNeilBrown bool nfs4_copy_delegation_stateid(struct inode *inode, fmode_t flags, nfs4_stateid *dst, const struct cred **cred); 7712f275cdSTrond Myklebust bool nfs4_refresh_delegation_stateid(nfs4_stateid *dst, struct inode *inode); 781da177e4SLinus Torvalds 79be3df3ddSTrond Myklebust struct nfs_delegation *nfs4_get_valid_delegation(const struct inode *inode); 80b7391f44STrond Myklebust void nfs_mark_delegation_referenced(struct nfs_delegation *delegation); 814201916fSTrond Myklebust int nfs4_have_delegation(struct inode *inode, fmode_t type, int flags); 824201916fSTrond Myklebust int nfs4_check_delegation(struct inode *inode, fmode_t type); 835445b1fbSTrond Myklebust bool nfs4_delegation_flush_on_close(const struct inode *inode); 846c2d8f8dSTrond Myklebust void nfs_inode_find_delegation_state_and_recover(struct inode *inode, 856c2d8f8dSTrond Myklebust const nfs4_stateid *stateid); 86c01d3645STrond Myklebust int nfs4_inode_make_writeable(struct inode *inode); 87cae7a073STrond Myklebust 881da177e4SLinus Torvalds #endif 891da177e4SLinus Torvalds 90*e12912d9STrond Myklebust #define NFS_DELEGATION_FLAG_TIME BIT(1) 91*e12912d9STrond Myklebust 92*e12912d9STrond Myklebust void nfs_update_delegated_atime(struct inode *inode); 93*e12912d9STrond Myklebust void nfs_update_delegated_mtime(struct inode *inode); 94*e12912d9STrond Myklebust void nfs_update_delegated_mtime_locked(struct inode *inode); 95*e12912d9STrond Myklebust 964201916fSTrond Myklebust static inline int nfs_have_read_or_write_delegation(struct inode *inode) 974201916fSTrond Myklebust { 984201916fSTrond Myklebust return NFS_PROTO(inode)->have_delegation(inode, FMODE_READ, 0); 994201916fSTrond Myklebust } 1004201916fSTrond Myklebust 1014201916fSTrond Myklebust static inline int nfs_have_write_delegation(struct inode *inode) 1024201916fSTrond Myklebust { 1034201916fSTrond Myklebust return NFS_PROTO(inode)->have_delegation(inode, FMODE_WRITE, 0); 1044201916fSTrond Myklebust } 1054201916fSTrond Myklebust 106b4d2314bSTrond Myklebust static inline int nfs_have_delegated_attributes(struct inode *inode) 107b4d2314bSTrond Myklebust { 1084201916fSTrond Myklebust return NFS_PROTO(inode)->have_delegation(inode, FMODE_READ, 0); 109b4d2314bSTrond Myklebust } 110b4d2314bSTrond Myklebust 111*e12912d9STrond Myklebust static inline int nfs_have_delegated_atime(struct inode *inode) 112*e12912d9STrond Myklebust { 113*e12912d9STrond Myklebust return NFS_PROTO(inode)->have_delegation(inode, FMODE_READ, 114*e12912d9STrond Myklebust NFS_DELEGATION_FLAG_TIME); 115*e12912d9STrond Myklebust } 116*e12912d9STrond Myklebust 117*e12912d9STrond Myklebust static inline int nfs_have_delegated_mtime(struct inode *inode) 118*e12912d9STrond Myklebust { 119*e12912d9STrond Myklebust return NFS_PROTO(inode)->have_delegation(inode, FMODE_WRITE, 120*e12912d9STrond Myklebust NFS_DELEGATION_FLAG_TIME); 121*e12912d9STrond Myklebust } 122*e12912d9STrond Myklebust 1231da177e4SLinus Torvalds #endif 124