Skip to content

Commit 4201916

Browse files
trondmypdamschuma-ntap
authored andcommitted
NFSv4: Add a flags argument to the 'have_delegation' callback
This argument will be used to allow the caller to specify whether or not they need to know that this is an attribute delegation. Signed-off-by: Trond Myklebust <[email protected]> Signed-off-by: Lance Shelton <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Trond Myklebust <[email protected]> Signed-off-by: Anna Schumaker <[email protected]>
1 parent 43df711 commit 4201916

File tree

10 files changed

+43
-34
lines changed

10 files changed

+43
-34
lines changed

fs/nfs/delegation.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,10 @@ static void nfs_mark_return_delegation(struct nfs_server *server,
8282
set_bit(NFS4CLNT_DELEGRETURN, &server->nfs_client->cl_state);
8383
}
8484

85-
static bool
86-
nfs4_is_valid_delegation(const struct nfs_delegation *delegation,
87-
fmode_t flags)
85+
static bool nfs4_is_valid_delegation(const struct nfs_delegation *delegation,
86+
fmode_t type)
8887
{
89-
if (delegation != NULL && (delegation->type & flags) == flags &&
88+
if (delegation != NULL && (delegation->type & type) == type &&
9089
!test_bit(NFS_DELEGATION_REVOKED, &delegation->flags) &&
9190
!test_bit(NFS_DELEGATION_RETURNING, &delegation->flags))
9291
return true;
@@ -103,16 +102,16 @@ struct nfs_delegation *nfs4_get_valid_delegation(const struct inode *inode)
103102
return NULL;
104103
}
105104

106-
static int
107-
nfs4_do_check_delegation(struct inode *inode, fmode_t flags, bool mark)
105+
static int nfs4_do_check_delegation(struct inode *inode, fmode_t type,
106+
int flags, bool mark)
108107
{
109108
struct nfs_delegation *delegation;
110109
int ret = 0;
111110

112-
flags &= FMODE_READ|FMODE_WRITE;
111+
type &= FMODE_READ|FMODE_WRITE;
113112
rcu_read_lock();
114113
delegation = rcu_dereference(NFS_I(inode)->delegation);
115-
if (nfs4_is_valid_delegation(delegation, flags)) {
114+
if (nfs4_is_valid_delegation(delegation, type)) {
116115
if (mark)
117116
nfs_mark_delegation_referenced(delegation);
118117
ret = 1;
@@ -124,22 +123,23 @@ nfs4_do_check_delegation(struct inode *inode, fmode_t flags, bool mark)
124123
* nfs4_have_delegation - check if inode has a delegation, mark it
125124
* NFS_DELEGATION_REFERENCED if there is one.
126125
* @inode: inode to check
127-
* @flags: delegation types to check for
126+
* @type: delegation types to check for
127+
* @flags: various modifiers
128128
*
129129
* Returns one if inode has the indicated delegation, otherwise zero.
130130
*/
131-
int nfs4_have_delegation(struct inode *inode, fmode_t flags)
131+
int nfs4_have_delegation(struct inode *inode, fmode_t type, int flags)
132132
{
133-
return nfs4_do_check_delegation(inode, flags, true);
133+
return nfs4_do_check_delegation(inode, type, flags, true);
134134
}
135135

136136
/*
137137
* nfs4_check_delegation - check if inode has a delegation, do not mark
138138
* NFS_DELEGATION_REFERENCED if it has one.
139139
*/
140-
int nfs4_check_delegation(struct inode *inode, fmode_t flags)
140+
int nfs4_check_delegation(struct inode *inode, fmode_t type)
141141
{
142-
return nfs4_do_check_delegation(inode, flags, false);
142+
return nfs4_do_check_delegation(inode, type, 0, false);
143143
}
144144

145145
static int nfs_delegation_claim_locks(struct nfs4_state *state, const nfs4_stateid *stateid)

fs/nfs/delegation.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,28 @@ bool nfs4_refresh_delegation_stateid(nfs4_stateid *dst, struct inode *inode);
7575

7676
struct nfs_delegation *nfs4_get_valid_delegation(const struct inode *inode);
7777
void nfs_mark_delegation_referenced(struct nfs_delegation *delegation);
78-
int nfs4_have_delegation(struct inode *inode, fmode_t flags);
79-
int nfs4_check_delegation(struct inode *inode, fmode_t flags);
78+
int nfs4_have_delegation(struct inode *inode, fmode_t type, int flags);
79+
int nfs4_check_delegation(struct inode *inode, fmode_t type);
8080
bool nfs4_delegation_flush_on_close(const struct inode *inode);
8181
void nfs_inode_find_delegation_state_and_recover(struct inode *inode,
8282
const nfs4_stateid *stateid);
8383
int nfs4_inode_make_writeable(struct inode *inode);
8484

8585
#endif
8686

87+
static inline int nfs_have_read_or_write_delegation(struct inode *inode)
88+
{
89+
return NFS_PROTO(inode)->have_delegation(inode, FMODE_READ, 0);
90+
}
91+
92+
static inline int nfs_have_write_delegation(struct inode *inode)
93+
{
94+
return NFS_PROTO(inode)->have_delegation(inode, FMODE_WRITE, 0);
95+
}
96+
8797
static inline int nfs_have_delegated_attributes(struct inode *inode)
8898
{
89-
return NFS_PROTO(inode)->have_delegation(inode, FMODE_READ);
99+
return NFS_PROTO(inode)->have_delegation(inode, FMODE_READ, 0);
90100
}
91101

92102
#endif

fs/nfs/dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1437,7 +1437,7 @@ static void nfs_set_verifier_locked(struct dentry *dentry, unsigned long verf)
14371437

14381438
if (!dir || !nfs_verify_change_attribute(dir, verf))
14391439
return;
1440-
if (inode && NFS_PROTO(inode)->have_delegation(inode, FMODE_READ))
1440+
if (inode && NFS_PROTO(inode)->have_delegation(inode, FMODE_READ, 0))
14411441
nfs_set_verifier_delegated(&verf);
14421442
dentry->d_time = verf;
14431443
}

fs/nfs/file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ do_getlk(struct file *filp, int cmd, struct file_lock *fl, int is_local)
732732
}
733733
fl->c.flc_type = saved_type;
734734

735-
if (NFS_PROTO(inode)->have_delegation(inode, FMODE_READ))
735+
if (nfs_have_read_or_write_delegation(inode))
736736
goto out_noconflict;
737737

738738
if (is_local)
@@ -815,7 +815,7 @@ do_setlk(struct file *filp, int cmd, struct file_lock *fl, int is_local)
815815
* This makes locking act as a cache coherency point.
816816
*/
817817
nfs_sync_mapping(filp->f_mapping);
818-
if (!NFS_PROTO(inode)->have_delegation(inode, FMODE_READ)) {
818+
if (!nfs_have_read_or_write_delegation(inode)) {
819819
nfs_zap_caches(inode);
820820
if (mapping_mapped(filp->f_mapping))
821821
nfs_revalidate_mapping(inode, filp->f_mapping);

fs/nfs/inode.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,8 @@ static bool nfs_has_xattr_cache(const struct nfs_inode *nfsi)
190190
void nfs_set_cache_invalid(struct inode *inode, unsigned long flags)
191191
{
192192
struct nfs_inode *nfsi = NFS_I(inode);
193-
bool have_delegation = NFS_PROTO(inode)->have_delegation(inode, FMODE_READ);
194193

195-
if (have_delegation) {
194+
if (nfs_have_delegated_attributes(inode)) {
196195
if (!(flags & NFS_INO_REVAL_FORCED))
197196
flags &= ~(NFS_INO_INVALID_MODE |
198197
NFS_INO_INVALID_OTHER |
@@ -1013,7 +1012,7 @@ void nfs_close_context(struct nfs_open_context *ctx, int is_sync)
10131012
if (!is_sync)
10141013
return;
10151014
inode = d_inode(ctx->dentry);
1016-
if (NFS_PROTO(inode)->have_delegation(inode, FMODE_READ))
1015+
if (nfs_have_read_or_write_delegation(inode))
10171016
return;
10181017
nfsi = NFS_I(inode);
10191018
if (inode->i_mapping->nrpages == 0)
@@ -1483,7 +1482,7 @@ static int nfs_check_inode_attributes(struct inode *inode, struct nfs_fattr *fat
14831482
unsigned long invalid = 0;
14841483
struct timespec64 ts;
14851484

1486-
if (NFS_PROTO(inode)->have_delegation(inode, FMODE_READ))
1485+
if (nfs_have_delegated_attributes(inode))
14871486
return 0;
14881487

14891488
if (!(fattr->valid & NFS_ATTR_FATTR_FILEID)) {

fs/nfs/nfs3proc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ nfs3_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
979979
return status;
980980
}
981981

982-
static int nfs3_have_delegation(struct inode *inode, fmode_t flags)
982+
static int nfs3_have_delegation(struct inode *inode, fmode_t type, int flags)
983983
{
984984
return 0;
985985
}

fs/nfs/nfs4proc.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ static void nfs4_bitmap_copy_adjust(__u32 *dst, const __u32 *src,
293293
unsigned long cache_validity;
294294

295295
memcpy(dst, src, NFS4_BITMASK_SZ*sizeof(*dst));
296-
if (!inode || !nfs4_have_delegation(inode, FMODE_READ))
296+
if (!inode || !nfs_have_read_or_write_delegation(inode))
297297
return;
298298

299299
cache_validity = READ_ONCE(NFS_I(inode)->cache_validity) | flags;
@@ -1264,7 +1264,7 @@ nfs4_update_changeattr_locked(struct inode *inode,
12641264
if (S_ISDIR(inode->i_mode))
12651265
nfs_force_lookup_revalidate(inode);
12661266

1267-
if (!NFS_PROTO(inode)->have_delegation(inode, FMODE_READ))
1267+
if (!nfs_have_delegated_attributes(inode))
12681268
cache_validity |=
12691269
NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL |
12701270
NFS_INO_INVALID_SIZE | NFS_INO_INVALID_OTHER |
@@ -3700,7 +3700,7 @@ static void nfs4_close_prepare(struct rpc_task *task, void *data)
37003700

37013701
if (calldata->arg.fmode == 0 || calldata->arg.fmode == FMODE_READ) {
37023702
/* Close-to-open cache consistency revalidation */
3703-
if (!nfs4_have_delegation(inode, FMODE_READ)) {
3703+
if (!nfs4_have_delegation(inode, FMODE_READ, 0)) {
37043704
nfs4_bitmask_set(calldata->arg.bitmask_store,
37053705
server->cache_consistency_bitmask,
37063706
inode, 0);
@@ -4638,7 +4638,7 @@ static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry
46384638
};
46394639
int status = 0;
46404640

4641-
if (!nfs4_have_delegation(inode, FMODE_READ)) {
4641+
if (!nfs4_have_delegation(inode, FMODE_READ, 0)) {
46424642
res.fattr = nfs_alloc_fattr();
46434643
if (res.fattr == NULL)
46444644
return -ENOMEM;
@@ -5607,7 +5607,7 @@ bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header *hdr)
56075607
/* Otherwise, request attributes if and only if we don't hold
56085608
* a delegation
56095609
*/
5610-
return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0;
5610+
return nfs4_have_delegation(hdr->inode, FMODE_READ, 0) == 0;
56115611
}
56125612

56135613
void nfs4_bitmask_set(__u32 bitmask[], const __u32 src[],
@@ -7654,10 +7654,10 @@ static int nfs4_add_lease(struct file *file, int arg, struct file_lease **lease,
76547654
int ret;
76557655

76567656
/* No delegation, no lease */
7657-
if (!nfs4_have_delegation(inode, type))
7657+
if (!nfs4_have_delegation(inode, type, 0))
76587658
return -EAGAIN;
76597659
ret = generic_setlease(file, arg, lease, priv);
7660-
if (ret || nfs4_have_delegation(inode, type))
7660+
if (ret || nfs4_have_delegation(inode, type, 0))
76617661
return ret;
76627662
/* We raced with a delegation return */
76637663
nfs4_delete_lease(file, priv);

fs/nfs/proc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ static int nfs_lock_check_bounds(const struct file_lock *fl)
687687
return -EINVAL;
688688
}
689689

690-
static int nfs_have_delegation(struct inode *inode, fmode_t flags)
690+
static int nfs_have_delegation(struct inode *inode, fmode_t type, int flags)
691691
{
692692
return 0;
693693
}

fs/nfs/write.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1320,7 +1320,7 @@ static int nfs_can_extend_write(struct file *file, struct folio *folio,
13201320
return 0;
13211321
if (!nfs_folio_write_uptodate(folio, pagelen))
13221322
return 0;
1323-
if (NFS_PROTO(inode)->have_delegation(inode, FMODE_WRITE))
1323+
if (nfs_have_write_delegation(inode))
13241324
return 1;
13251325
if (!flctx || (list_empty_careful(&flctx->flc_flock) &&
13261326
list_empty_careful(&flctx->flc_posix)))

include/linux/nfs_xdr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1830,7 +1830,7 @@ struct nfs_rpc_ops {
18301830
int open_flags,
18311831
struct iattr *iattr,
18321832
int *);
1833-
int (*have_delegation)(struct inode *, fmode_t);
1833+
int (*have_delegation)(struct inode *, fmode_t, int);
18341834
struct nfs_client *(*alloc_client) (const struct nfs_client_initdata *);
18351835
struct nfs_client *(*init_client) (struct nfs_client *,
18361836
const struct nfs_client_initdata *);

0 commit comments

Comments
 (0)