Skip to content

Commit a9d4c12

Browse files
chucklevergregkh
authored andcommitted
NFSD: Never return NFS4ERR_FILE_OPEN when removing a directory
commit 370345b upstream. RFC 8881 Section 18.25.4 paragraph 5 tells us that the server should return NFS4ERR_FILE_OPEN only if the target object is an opened file. This suggests that returning this status when removing a directory will confuse NFS clients. This is a version-specific issue; nfsd_proc_remove/rmdir() and nfsd3_proc_remove/rmdir() already return nfserr_access as appropriate. Unfortunately there is no quick way for nfsd4_remove() to determine whether the target object is a file or not, so the check is done in in nfsd_unlink() for now. Reported-by: Trond Myklebust <trondmy@hammerspace.com> Fixes: 466e16f ("nfsd: check for EBUSY from vfs_rmdir/vfs_unink.") Reviewed-by: Jeff Layton <jlayton@kernel.org> Cc: stable@vger.kernel.org Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c2ed21a commit a9d4c12

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

fs/nfsd/vfs.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1931,9 +1931,17 @@ nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen,
19311931
return err;
19321932
}
19331933

1934-
/*
1935-
* Unlink a file or directory
1936-
* N.B. After this call fhp needs an fh_put
1934+
/**
1935+
* nfsd_unlink - remove a directory entry
1936+
* @rqstp: RPC transaction context
1937+
* @fhp: the file handle of the parent directory to be modified
1938+
* @type: enforced file type of the object to be removed
1939+
* @fname: the name of directory entry to be removed
1940+
* @flen: length of @fname in octets
1941+
*
1942+
* After this call fhp needs an fh_put.
1943+
*
1944+
* Returns a generic NFS status code in network byte-order.
19371945
*/
19381946
__be32
19391947
nfsd_unlink(struct svc_rqst *rqstp, struct svc_fh *fhp, int type,
@@ -2007,10 +2015,14 @@ nfsd_unlink(struct svc_rqst *rqstp, struct svc_fh *fhp, int type,
20072015
fh_drop_write(fhp);
20082016
out_nfserr:
20092017
if (host_err == -EBUSY) {
2010-
/* name is mounted-on. There is no perfect
2011-
* error status.
2018+
/*
2019+
* See RFC 8881 Section 18.25.4 para 4: NFSv4 REMOVE
2020+
* wants a status unique to the object type.
20122021
*/
2013-
err = nfserr_file_open;
2022+
if (type != S_IFDIR)
2023+
err = nfserr_file_open;
2024+
else
2025+
err = nfserr_acces;
20142026
}
20152027
out:
20162028
return err != nfs_ok ? err : nfserrno(host_err);

0 commit comments

Comments
 (0)