Skip to content

Commit bb4d53d

Browse files
neilbrownchucklever
authored andcommitted
NFSD: use (un)lock_inode instead of fh_(un)lock for file operations
When locking a file to access ACLs and xattrs etc, use explicit locking with inode_lock() instead of fh_lock(). This means that the calls to fh_fill_pre/post_attr() are also explicit which improves readability and allows us to place them only where they are needed. Only the xattr calls need pre/post information. When locking a file we don't need I_MUTEX_PARENT as the file is not a parent of anything, so we can use inode_lock() directly rather than the inode_lock_nested() call that fh_lock() uses. Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: NeilBrown <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent debf16f commit bb4d53d

File tree

4 files changed

+30
-23
lines changed

4 files changed

+30
-23
lines changed

fs/nfsd/nfs2acl.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ static __be32 nfsacld_proc_setacl(struct svc_rqst *rqstp)
111111
if (error)
112112
goto out_errno;
113113

114-
fh_lock(fh);
114+
inode_lock(inode);
115115

116116
error = set_posix_acl(&init_user_ns, inode, ACL_TYPE_ACCESS,
117117
argp->acl_access);
@@ -122,7 +122,7 @@ static __be32 nfsacld_proc_setacl(struct svc_rqst *rqstp)
122122
if (error)
123123
goto out_drop_lock;
124124

125-
fh_unlock(fh);
125+
inode_unlock(inode);
126126

127127
fh_drop_write(fh);
128128

@@ -136,7 +136,7 @@ static __be32 nfsacld_proc_setacl(struct svc_rqst *rqstp)
136136
return rpc_success;
137137

138138
out_drop_lock:
139-
fh_unlock(fh);
139+
inode_unlock(inode);
140140
fh_drop_write(fh);
141141
out_errno:
142142
resp->status = nfserrno(error);

fs/nfsd/nfs3acl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static __be32 nfsd3_proc_setacl(struct svc_rqst *rqstp)
101101
if (error)
102102
goto out_errno;
103103

104-
fh_lock(fh);
104+
inode_lock(inode);
105105

106106
error = set_posix_acl(&init_user_ns, inode, ACL_TYPE_ACCESS,
107107
argp->acl_access);
@@ -111,7 +111,7 @@ static __be32 nfsd3_proc_setacl(struct svc_rqst *rqstp)
111111
argp->acl_default);
112112

113113
out_drop_lock:
114-
fh_unlock(fh);
114+
inode_unlock(inode);
115115
fh_drop_write(fh);
116116
out_errno:
117117
resp->status = nfserrno(error);

fs/nfsd/nfs4state.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7397,21 +7397,22 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
73977397
static __be32 nfsd_test_lock(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file_lock *lock)
73987398
{
73997399
struct nfsd_file *nf;
7400+
struct inode *inode;
74007401
__be32 err;
74017402

74027403
err = nfsd_file_acquire(rqstp, fhp, NFSD_MAY_READ, &nf);
74037404
if (err)
74047405
return err;
7405-
fh_lock(fhp); /* to block new leases till after test_lock: */
7406-
err = nfserrno(nfsd_open_break_lease(fhp->fh_dentry->d_inode,
7407-
NFSD_MAY_READ));
7406+
inode = fhp->fh_dentry->d_inode;
7407+
inode_lock(inode); /* to block new leases till after test_lock: */
7408+
err = nfserrno(nfsd_open_break_lease(inode, NFSD_MAY_READ));
74087409
if (err)
74097410
goto out;
74107411
lock->fl_file = nf->nf_file;
74117412
err = nfserrno(vfs_test_lock(nf->nf_file, lock));
74127413
lock->fl_file = NULL;
74137414
out:
7414-
fh_unlock(fhp);
7415+
inode_unlock(inode);
74157416
nfsd_file_put(nf);
74167417
return err;
74177418
}

fs/nfsd/vfs.c

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
416416
return err;
417417
}
418418

419-
fh_lock(fhp);
419+
inode_lock(inode);
420420
if (size_change) {
421421
/*
422422
* RFC5661, Section 18.30.4:
@@ -464,7 +464,7 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
464464
attr->na_aclerr = set_posix_acl(&init_user_ns,
465465
inode, ACL_TYPE_DEFAULT,
466466
attr->na_dpacl);
467-
fh_unlock(fhp);
467+
inode_unlock(inode);
468468
if (size_change)
469469
put_write_access(inode);
470470
out:
@@ -2155,13 +2155,16 @@ nfsd_listxattr(struct svc_rqst *rqstp, struct svc_fh *fhp, char **bufp,
21552155
return err;
21562156
}
21572157

2158-
/*
2159-
* Removexattr and setxattr need to call fh_lock to both lock the inode
2160-
* and set the change attribute. Since the top-level vfs_removexattr
2161-
* and vfs_setxattr calls already do their own inode_lock calls, call
2162-
* the _locked variant. Pass in a NULL pointer for delegated_inode,
2163-
* and let the client deal with NFS4ERR_DELAY (same as with e.g.
2164-
* setattr and remove).
2158+
/**
2159+
* nfsd_removexattr - Remove an extended attribute
2160+
* @rqstp: RPC transaction being executed
2161+
* @fhp: NFS filehandle of object with xattr to remove
2162+
* @name: name of xattr to remove (NUL-terminate)
2163+
*
2164+
* Pass in a NULL pointer for delegated_inode, and let the client deal
2165+
* with NFS4ERR_DELAY (same as with e.g. setattr and remove).
2166+
*
2167+
* Returns nfs_ok on success, or an nfsstat in network byte order.
21652168
*/
21662169
__be32
21672170
nfsd_removexattr(struct svc_rqst *rqstp, struct svc_fh *fhp, char *name)
@@ -2177,12 +2180,14 @@ nfsd_removexattr(struct svc_rqst *rqstp, struct svc_fh *fhp, char *name)
21772180
if (ret)
21782181
return nfserrno(ret);
21792182

2180-
fh_lock(fhp);
2183+
inode_lock(fhp->fh_dentry->d_inode);
2184+
fh_fill_pre_attrs(fhp);
21812185

21822186
ret = __vfs_removexattr_locked(&init_user_ns, fhp->fh_dentry,
21832187
name, NULL);
21842188

2185-
fh_unlock(fhp);
2189+
fh_fill_post_attrs(fhp);
2190+
inode_unlock(fhp->fh_dentry->d_inode);
21862191
fh_drop_write(fhp);
21872192

21882193
return nfsd_xattr_errno(ret);
@@ -2202,12 +2207,13 @@ nfsd_setxattr(struct svc_rqst *rqstp, struct svc_fh *fhp, char *name,
22022207
ret = fh_want_write(fhp);
22032208
if (ret)
22042209
return nfserrno(ret);
2205-
fh_lock(fhp);
2210+
inode_lock(fhp->fh_dentry->d_inode);
2211+
fh_fill_pre_attrs(fhp);
22062212

22072213
ret = __vfs_setxattr_locked(&init_user_ns, fhp->fh_dentry, name, buf,
22082214
len, flags, NULL);
2209-
2210-
fh_unlock(fhp);
2215+
fh_fill_post_attrs(fhp);
2216+
inode_unlock(fhp->fh_dentry->d_inode);
22112217
fh_drop_write(fhp);
22122218

22132219
return nfsd_xattr_errno(ret);

0 commit comments

Comments
 (0)