Skip to content

Commit 370345b

Browse files
committed
NFSD: Never return NFS4ERR_FILE_OPEN when removing a directory
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 <[email protected]> Fixes: 466e16f ("nfsd: check for EBUSY from vfs_rmdir/vfs_unink.") Reviewed-by: Jeff Layton <[email protected]> Cc: [email protected] Signed-off-by: Chuck Lever <[email protected]>
1 parent d7d8e31 commit 370345b

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

fs/nfsd/vfs.c

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

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

0 commit comments

Comments
 (0)