Commit 370345b4 authored by Chuck Lever's avatar Chuck Lever
Browse files

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: default avatarTrond Myklebust <trondmy@hammerspace.com>
Fixes: 466e16f0 ("nfsd: check for EBUSY from vfs_rmdir/vfs_unink.")
Reviewed-by: default avatarJeff Layton <jlayton@kernel.org>
Cc: stable@vger.kernel.org
Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
parent d7d8e316
Loading
Loading
Loading
Loading
+18 −6
Original line number Diff line number Diff line
@@ -1930,9 +1930,17 @@ nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen,
	return err;
}

/*
 * Unlink a file or directory
 * N.B. After this call fhp needs an fh_put
/**
 * nfsd_unlink - remove a directory entry
 * @rqstp: RPC transaction context
 * @fhp: the file handle of the parent directory to be modified
 * @type: enforced file type of the object to be removed
 * @fname: the name of directory entry to be removed
 * @flen: length of @fname in octets
 *
 * After this call fhp needs an fh_put.
 *
 * Returns a generic NFS status code in network byte-order.
 */
__be32
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,
	fh_drop_write(fhp);
out_nfserr:
	if (host_err == -EBUSY) {
		/* name is mounted-on. There is no perfect
		 * error status.
		/*
		 * See RFC 8881 Section 18.25.4 para 4: NFSv4 REMOVE
		 * wants a status unique to the object type.
		 */
		if (type != S_IFDIR)
			err = nfserr_file_open;
		else
			err = nfserr_acces;
	}
out:
	return err != nfs_ok ? err : nfserrno(host_err);