From patchwork Sun Jan 26 21:50:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13950906 X-Patchwork-Delegate: cel@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 13AB2176AC5 for ; Sun, 26 Jan 2025 21:50:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737928228; cv=none; b=RBf6fLLU9lcxrxT7bISfvHvHL90JyXXFwm98oXGjcLtKpJm8MGha2LBvSb+ysH5BJTBp2QA/z6Fs6tgETK4Ieq6Cldjie9tXuDomqLCG217j//H7qWFVS0JaImVyfLbfsQxprhJzxpqyZ0ReGPZ/YS8U8p60FdvmirctimpP4QI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737928228; c=relaxed/simple; bh=aRzgRyc9DyZcW6+L0CLLAvWRycz2gYpH1EqF3HSShMM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lWQjDgLERmmFUjHw7Mz/htiXcySM3Q2ZioSvrJkLQi7o0+qC+lqJXws4ET2sv23oO1eQCeDLOwp0gcJMrLGXSXiI/h6pdFTD8HzC3TiN7ub3+1Pza2p8DRIWU6ZyPDwShb62CzLKKO6UJREndAMC/+PVHqTOGBpd4S/+lXsxz2U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BgtKrUrn; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BgtKrUrn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3638EC4CEE1; Sun, 26 Jan 2025 21:50:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737928227; bh=aRzgRyc9DyZcW6+L0CLLAvWRycz2gYpH1EqF3HSShMM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BgtKrUrnskEDVZRT+tlayyGJOacxR3vULQ44z6gqHKzTvGnmnL8jXAR4DQYcAjqiP AQIzLwd24j9uxvLUq5pHn/QjSm5hIxMRYqABZcPvjEG+el/UzD4Yt6/NWON42IrMZ5 JDLfYrT2fxm/BeamwwVr6XF/HF6Jzx0u4hMdxR+fUB9/UWJ0btpSC8F9FxJTv8EUXu 0D9jE3vNOMbpPRO1KqYSkXAAFafuv+mFOX0QdpXWR/LldvjeEXijHui9M6brPbeesj JgxpswLvmKd+xfYzgJ0KVo225GrP+SYFFAZh6S35v5Cq+6TtVjitaSMd/WuMpqVEHO 5qWIMIiq7lHPQ== From: cel@kernel.org To: Amir Goldstein , Neil Brown , Jeff Layton , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: , Chuck Lever Subject: [PATCH v3 4/4] NFSD: Return NFS4ERR_FILE_OPEN only when linking an open file Date: Sun, 26 Jan 2025 16:50:20 -0500 Message-ID: <20250126215020.2466-5-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250126215020.2466-1-cel@kernel.org> References: <20250126215020.2466-1-cel@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Chuck Lever RFC 8881 Section 18.9.4 paragraphs 1 - 2 tell us that RENAME should return NFS4ERR_FILE_OPEN only when the target object is a file that is currently open. If the target is a directory, some other status must be returned. The VFS is unlikely to return -EBUSY, but NFSD has to ensure that errno does not leak to clients as a status code that is not permitted by spec. Signed-off-by: Chuck Lever --- fs/nfsd/vfs.c | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index 347114da4fd0..41fb1654dd52 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -1699,9 +1699,17 @@ nfsd_symlink(struct svc_rqst *rqstp, struct svc_fh *fhp, return err; } -/* - * Create a hardlink - * N.B. After this call _both_ ffhp and tfhp need an fh_put +/** + * nfsd_link - create a link + * @rqstp: RPC transaction context + * @ffhp: the file handle of the directory where the new link is to be created + * @name: the filename of the new link + * @len: the length of @name in octets + * @tfhp: the file handle of an existing file object + * + * After this call _both_ ffhp and tfhp need an fh_put. + * + * Returns a generic NFS status code in network byte-order. */ __be32 nfsd_link(struct svc_rqst *rqstp, struct svc_fh *ffhp, @@ -1709,6 +1717,7 @@ nfsd_link(struct svc_rqst *rqstp, struct svc_fh *ffhp, { struct dentry *ddir, *dnew, *dold; struct inode *dirp; + int type; __be32 err; int host_err; @@ -1728,11 +1737,11 @@ nfsd_link(struct svc_rqst *rqstp, struct svc_fh *ffhp, if (isdotent(name, len)) goto out; + err = nfs_ok; + type = d_inode(tfhp->fh_dentry)->i_mode & S_IFMT; host_err = fh_want_write(tfhp); - if (host_err) { - err = nfserrno(host_err); + if (host_err) goto out; - } ddir = ffhp->fh_dentry; dirp = d_inode(ddir); @@ -1740,7 +1749,7 @@ nfsd_link(struct svc_rqst *rqstp, struct svc_fh *ffhp, dnew = lookup_one_len(name, ddir, len); if (IS_ERR(dnew)) { - err = nfserrno(PTR_ERR(dnew)); + host_err = PTR_ERR(dnew); goto out_unlock; } @@ -1756,17 +1765,26 @@ nfsd_link(struct svc_rqst *rqstp, struct svc_fh *ffhp, fh_fill_post_attrs(ffhp); inode_unlock(dirp); if (!host_err) { - err = nfserrno(commit_metadata(ffhp)); - if (!err) - err = nfserrno(commit_metadata(tfhp)); - } else { - err = nfserrno(host_err); + host_err = commit_metadata(ffhp); + if (!host_err) + host_err = commit_metadata(tfhp); } + dput(dnew); out_drop_write: fh_drop_write(tfhp); + if (host_err == -EBUSY) { + /* + * See RFC 8881 Section 18.9.4 para 1-2: NFSv4 LINK + * wants a status unique to the object type. + */ + if (type != S_IFDIR) + err = nfserr_file_open; + else + err = nfserr_acces; + } out: - return err; + return err != nfs_ok ? err : nfserrno(host_err); out_dput: dput(dnew);