From patchwork Thu Jan 23 19:52:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13948599 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 EA9277E105 for ; Thu, 23 Jan 2025 19:52:47 +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=1737661968; cv=none; b=igXhE6lWi5Tk6jccvc0vjuwK2kv80VscJidGdfbp7bmiYVhVxyiKjgyNW5Oh8ECAHJAg2uEpr9zNT8nKlhSkA23ed5Lx5GhETqh6afKBSXQI72u/KIElAGS2r8bxBi6aKIs1rpwzHNKXMIrz0NkzdkZhb8jGPkKfwRyjFKsqEzU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737661968; c=relaxed/simple; bh=XlwZPYpGxHV1byldpoOY4wzN2rz/uZBFH3IV4T33LpQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bmO0cOjOMex/dvNGYENkDIpwACisvQvCzKNNOCjfCoFgxk3mYrM218puIMzPFyaXJ1UoV5XhRghxjbdO4DzsBTTlCVmb6iN1Z0LStQQe+jqcU6PRhn1n+F/B00n0LqmbSHjjdJXyveViWjXZwCIOe1GivbAm2zB/KH06CFnfQnE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kpS86fff; 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="kpS86fff" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CAD36C4CEE2; Thu, 23 Jan 2025 19:52:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737661967; bh=XlwZPYpGxHV1byldpoOY4wzN2rz/uZBFH3IV4T33LpQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kpS86fffG4nHpXYDlEv0RxfgiKrKKmpMJLnfK3BqfW5pasPMDvS3BfJYPMUWZ2ygD aV6mNVHeSg/Vm+Q5eImnsI/RAYMCOZCZydYbjyYYiHQVxcIgPnX3IzyiNbPdwAUaWu WLLARTwCCEIS3xwn+67iRcqWrPW2w6U/kZUZvOaNfGrj6GdaroX9aiPuJ0gBJzXzp2 GLXImV9AF0noe3eJ4NyCXeR0kpdsuVnimmRVq0ys3HUVAX3lz3uewJGJkb59NL7Z1m k5aKDwvnG+nxPDMipFSgj+TfkBFBNCqCfA5ao4l7bn+AyizDDoDlLsmSusDjlIHiJg EdrE52nYur1CA== From: cel@kernel.org To: Neil Brown , Jeff Layton , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: , Chuck Lever Subject: [RFC PATCH 1/4] NFSD: nfsd_unlink() clobbers non-zero status returned from fh_fill_pre_attrs() Date: Thu, 23 Jan 2025 14:52:39 -0500 Message-ID: <20250123195242.1378601-2-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250123195242.1378601-1-cel@kernel.org> References: <20250123195242.1378601-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 If fh_fill_pre_attrs() returns a non-zero status, the error flow takes it through out_unlock, which then overwrites the returned status code with err = nfserrno(host_err); Fixes: a332018a91c4 ("nfsd: handle failure to collect pre/post-op attrs more sanely") Signed-off-by: Chuck Lever --- fs/nfsd/vfs.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index 29cb7b812d71..2d8e27c225f9 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -2011,11 +2011,9 @@ nfsd_unlink(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, * error status. */ err = nfserr_file_open; - } else { - err = nfserrno(host_err); } out: - return err; + return err != nfs_ok ? err : nfserrno(host_err); out_unlock: inode_unlock(dirp); goto out_drop_write; From patchwork Thu Jan 23 19:52:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13948600 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 072057E105 for ; Thu, 23 Jan 2025 19:52:48 +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=1737661969; cv=none; b=St8XDHLk8I3SKZsDaz1LRuWlGjXxYWGI7PLv+vMDcJ2Cr3I5Xolfk59k3NlxoEvyiUX8LFmrLS77ZX74tf3Pf2vEghijw+vCl78PnN7SQVkluxVIxFqulYWQIj6mpgXrmD5vwZQRKOJX8sCrbP3AOeFVz9Mj5OQPYf/ED4cgMRw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737661969; c=relaxed/simple; bh=yaLWrPP93PZLkFvbMLciRxhsYrSzSc/L9aVzzoE56aw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c7d775XJSDIflZKTnhgfNerksBwh5hDj2mM2ZoSqJSmaj4xAX7ENhqOvGdqzNGk6OeWfhR/+F4GzRa1GckrPo3LwMiSqiPUph68A/0Nt8ohTpRd4WclLKi62WPZumvDXGpcqE5VAHetzZrRqVByIlkQ2t3JVWLayAWsUxHfHVAE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pjL1FFaW; 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="pjL1FFaW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B8EA5C4CED3; Thu, 23 Jan 2025 19:52:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737661968; bh=yaLWrPP93PZLkFvbMLciRxhsYrSzSc/L9aVzzoE56aw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pjL1FFaWZdBlxI/KsKk78+gOnScAci1JDQK708e428y9NjNUkppYBX8D/614O0LVY dL/yKmzR+JYPxLst4KsQPl0CA+RDfFv04UqqRhgJMy/9u3TZHrv8vsM4YDmqoXVMl7 aGOJG++Vunm0MaZVLQJPVSXAvGzGLRX2cpzU9k5nYn4j5DLgVLhISQEzCAU6BQRT3q eus363DK9xF8nMiGnn3zcRx4JeRimGu3tuZvqoknpE0DSEhCVqTfCyeyhSndX69foh HkrgKq0ZBBQ9ThgOxLRVkjvdyU2RLjV67j/P9lvRL9FjRfxhm7zO4YXUo02yJwx2Dh RyuHVwXsqjXWA== From: cel@kernel.org To: Neil Brown , Jeff Layton , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: , Chuck Lever , Trond Myklebust Subject: [RFC PATCH 2/4] NFSD: Never return NFS4ERR_FILE_OPEN when removing a directory Date: Thu, 23 Jan 2025 14:52:40 -0500 Message-ID: <20250123195242.1378601-3-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250123195242.1378601-1-cel@kernel.org> References: <20250123195242.1378601-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.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 to nfsd_unlink() for now. Reported-by: Trond Myklebust Fixes: 466e16f0920f ("nfsd: check for EBUSY from vfs_rmdir/vfs_unink.") Signed-off-by: Chuck Lever --- fs/nfsd/vfs.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index 2d8e27c225f9..3ead7fb3bf04 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -1931,9 +1931,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, @@ -2007,10 +2015,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 + * distinguishes between reg file and dir. */ - err = nfserr_file_open; + if (type != S_IFDIR) + err = nfserr_file_open; + else + err = nfserr_acces; } out: return err != nfs_ok ? err : nfserrno(host_err); From patchwork Thu Jan 23 19:52:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13948601 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 D9A7C7E105 for ; Thu, 23 Jan 2025 19:52:49 +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=1737661969; cv=none; b=ilGyg2Rlfyr3DDn0BUeoVDYSBZZJI/IVcC+lSk4DN1DXLPkVQSqvNyFmMQoasFj5rjOLuL2L3sY1WRFrUsP+bTZ+J30ohy66O6EpuAddEuuWoy/+Ie6iCuCvnVIjF2FmLiwzThsSl2QYUR3yVXhvSrSuLyt+fiNu5yFYMzu9LF8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737661969; c=relaxed/simple; bh=Spytuyccow0fo6u3nkrQ6bjUCKHsP46lrURrpOBvSYs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pmoFkPa/AryOsXWvL28lkKHZJ15cnr5s1bEgy2xjo9BXilOfXfylhZYwteedF8J+C+e5BlCunjG+xLxxK9Gy0o+qz9yPFVuXZXdgGfh7lG4dhSJvv/qR5vKvNJ300byrmEY5dsxLYUW8YUB2Gf7UbI8wbiMwSPs/5X/BIbjnZHI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XgHIMSre; 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="XgHIMSre" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2548C4CEE2; Thu, 23 Jan 2025 19:52:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737661969; bh=Spytuyccow0fo6u3nkrQ6bjUCKHsP46lrURrpOBvSYs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XgHIMSreSYL27cb5JdSS0SwkeQYjZoCHKd9AwXmBv4/GZqAjd8mNaAUsignMyc93l ugIVoyhBCOoRs75xnp1/jEBkGwByllDSnwRIvTiL+KFxwLnMUXYLcy3YqDj2KsbkjI dARYfoMAlgwIHkk2F27cYzfuUfwMqgeDfttacezPaCdeZDKEu+x1EKlUZUmsiPjESJ li+br83jSLyn/up0EVjMiV2edmTZl3xgMwhb9x86+yrLqbC7sG7YG4s0Hfe34pbded TYFN9VNXhMqGPSac3vm+lQkbQrZMZGlnMwtbQJXchmcS2DUctAS4/NyxiMS639q/Mx ZyfGUcvNzOodg== From: cel@kernel.org To: Neil Brown , Jeff Layton , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: , Chuck Lever Subject: [RFC PATCH 3/4] NFSD: Return NFS4ERR_FILE_OPEN only when renaming over an open file Date: Thu, 23 Jan 2025 14:52:41 -0500 Message-ID: <20250123195242.1378601-4-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250123195242.1378601-1-cel@kernel.org> References: <20250123195242.1378601-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.26.4 paragraphs 1 - 3 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. Generally I expect that a delegation recall will be triggered in some of these circumstances. In other cases, the VFS might return -EBUSY for other reasons, and NFSD has to ensure that errno does not leak to clients as a status code that is not permitted by spec. There are some error flows where the target dentry hasn't been found yet. The default value for @type therefore is S_IFDIR to return an alternate status code in those cases. Signed-off-by: Chuck Lever --- fs/nfsd/vfs.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index 3ead7fb3bf04..5cfb5eb54c23 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -1795,9 +1795,19 @@ nfsd_has_cached_files(struct dentry *dentry) return ret; } -/* - * Rename a file - * N.B. After this call _both_ ffhp and tfhp need an fh_put +/** + * nfsd_rename - rename a directory entry + * @rqstp: RPC transaction context + * @ffhp: the file handle of parent directory containing the entry to be renamed + * @fname: the filename of directory entry to be renamed + * @flen: the length of @fname in octets + * @tfhp: the file handle of parent directory to contain the renamed entry + * @tname: the filename of the new entry + * @tlen: the length of @tlen in octets + * + * After this call _both_ ffhp and tfhp need an fh_put. + * + * Returns a generic NFS status code in network byte-order. */ __be32 nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen, @@ -1805,6 +1815,7 @@ nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen, { struct dentry *fdentry, *tdentry, *odentry, *ndentry, *trap; struct inode *fdir, *tdir; + int type = S_IFDIR; __be32 err; int host_err; bool close_cached = false; @@ -1867,6 +1878,7 @@ nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen, host_err = PTR_ERR(ndentry); if (IS_ERR(ndentry)) goto out_dput_old; + type = d_inode(ndentry)->i_mode & S_IFMT; host_err = -ENOTEMPTY; if (ndentry == trap) goto out_dput_new; @@ -1904,7 +1916,17 @@ nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen, out_dput_old: dput(odentry); out_nfserr: - err = nfserrno(host_err); + if (host_err == -EBUSY) { + /* + * See RFC 8881 Section 18.26.4 para 1-3: NFSv4 RENAME + * status distinguishes between reg file and dir. + */ + if (type != S_IFDIR) + err = nfserr_file_open; + else + err = nfserr_acces; + } else + err = nfserrno(host_err); if (!close_cached) { fh_fill_post_attrs(ffhp); From patchwork Thu Jan 23 19:52:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13948602 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 C2E137E105 for ; Thu, 23 Jan 2025 19:52:50 +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=1737661970; cv=none; b=kg+bEtN7f4DWqaMDC5OYW7feqEvVLMCopnE+zweEIAUCUVk7c2k52VJw0bTLlWnvnfbRPrsQpgeFmqQd6M05JhX0uuY74CgJ1TfBzzjXxuiiFefAR/Jo9O9PUzYChAIY+vPGeU2SQqzhqRrRsv6RXJcuo3GFIBG0h8/5NKGm0Fk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737661970; c=relaxed/simple; bh=RdLHGc4i0BeNbFMb4ZVieqeEJEHPiEWqsizdAmF6Du4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dcOXlRSPWqOxddR2YBpLPjuXarpkRTo6Yyl9zCAg5VGiiJet6L0m35+ts1GOwp3ew8nR2OX71C8YxvkwkH2tdaMRE2wRJPcqxq9aoDTzkJ5GSOsNCi5WyNUGRMWQxLj8YyB4X16z8BfsA0UNstKtHsCY9QcIo47mVGtSKKdl8bk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jUOWysSh; 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="jUOWysSh" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9BF57C4CEDF; Thu, 23 Jan 2025 19:52:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737661970; bh=RdLHGc4i0BeNbFMb4ZVieqeEJEHPiEWqsizdAmF6Du4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jUOWysShEVLUdfh2TwM2FsePewZGme80kgRiRbn9VoeDoUg4d29xLgspS/5dn7zf/ 82qTnGDvDc22g/nzkixH/zfdBzDs1VIgIsE0Djd7fqWPfQt6ecdBBKWQ3RQxBFa9dY rWmf9ZfjZU+4rYcGjE07A9h4rgRuT7UpPsmhkRGs5qoozov0o81JjnZGpFvfBsbvdE /UHr31eHkBU4zndHiTsZG2KRlGLevsqU/WBXXuoLWm2RslVpA5eL/HLTigUPRqzuvr UHC4yfEdgFigwNNWW/oncPJGEZ4xpiwhCJSSs6s8VA+IoMdLtu3cFYHG6VpL/K+RJe 4uPJhVZm9NtpA== From: cel@kernel.org To: Neil Brown , Jeff Layton , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: , Chuck Lever Subject: [RFC PATCH 4/4] NFSD: Return NFS4ERR_FILE_OPEN only when linking an open file Date: Thu, 23 Jan 2025 14:52:42 -0500 Message-ID: <20250123195242.1378601-5-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250123195242.1378601-1-cel@kernel.org> References: <20250123195242.1378601-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. Generally I expect that a delegation recall will be triggered in some of these circumstances. In other cases, the VFS might return -EBUSY for other reasons, and 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 5cfb5eb54c23..566b9adf2259 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 + * status distinguishes between reg file and dir. + */ + 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);