From patchwork Sun Jan 26 21:50:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13950903 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 7079825A64F for ; Sun, 26 Jan 2025 21:50:25 +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=1737928225; cv=none; b=P1SDx+sD6CdKIjwtZkb+annX7h/hVq0POLXyaNVop0yikaclXut/pVDprqrI4dP7CqJnQyq+Zva43k1imYHnssTqTfe2drMqjLSl5D0qxc5iXU1qzIh7PsT1VW+wIOvSXaLxGwIkgYHi3n0DKSYeXtnKR1veAbZcs8+HjUBJHUY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737928225; c=relaxed/simple; bh=XlwZPYpGxHV1byldpoOY4wzN2rz/uZBFH3IV4T33LpQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tG41/D2xb344leueQOr3kIkmFRio6rKcOS7UxJEJ4TT4X2ebHm20RHgQRE4iSy+MmNwrv4v6MHG/U7VQWtza3GVN9Jf0iaClY/y4D9c7XqH53Gmp4zQyrQbdgdzXE2ljlexfcAZbuotPKRCzWnBLSUh5PloQMUPCSS5LPEUu9No= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=r4wcSADj; 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="r4wcSADj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 373CCC4CEE4; Sun, 26 Jan 2025 21:50:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737928225; bh=XlwZPYpGxHV1byldpoOY4wzN2rz/uZBFH3IV4T33LpQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r4wcSADjRo1wtHCtZRF/OeQb8X1RvfxN5H56SFfsfMYXdIK5e/Sq0tQUG+eGx1Aw9 ojFR/kzghX/NoXuuSLWEV3iqpSfQxzAK3wMTYxhQ3lzC8s+3aua+OoHogloyjvNMO7 ABm/y/MS/WL7Ah8fi6I5oL03TWkQvMrNlIGJtphvO+vf40w6X448GiLaU9IRl0pCQy TYhbeJOn8yVzzmRL5fhQS/dc2Cr0acwnc3SphIkVfgoITxWDGYIUQAjYKl8R7xmWA5 5M1cxo0g5K/J/Cjoclb+2QDIw3YuyBIVUgQQphEPEl7A525o3Mqh2aHKQ+2YwLmob0 q8qgrDMDYvmrw== From: cel@kernel.org To: Amir Goldstein , Neil Brown , Jeff Layton , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: , Chuck Lever Subject: [PATCH v3 1/4] NFSD: nfsd_unlink() clobbers non-zero status returned from fh_fill_pre_attrs() Date: Sun, 26 Jan 2025 16:50:17 -0500 Message-ID: <20250126215020.2466-2-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 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 Sun Jan 26 21:50:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13950904 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 8A32225A64F for ; Sun, 26 Jan 2025 21:50:26 +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=1737928226; cv=none; b=qY0DWTzrRdKcnXph2/id1btRFPm6d6Of0AqOSChXo6HBRjIJNVyZrc1sf6MgSAOQv9NiUH2EJVx6EUH0NABBSUJKPgHa22THJh6cn2K+EoB8QefBf0wke3ZJaTvBdqWxfd/xa6MMnYfeZPWTE268hTT9nT0CLZDEEoT2zv34Cgc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737928226; c=relaxed/simple; bh=mZUHBZ4A4sEnSTaCQ5MyMjWrK0FDdPsYWqeujrtmVOg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q1aDsl5WHYcPQc65jtQXmh5NFdY6UJOPr+UDpFsVD6VpVuItumLv2Q/WO8Iv6uzq9SFJpEcGhqxVC6aEzvD2Zexwh63aQq1VvreW0NOsWg3HaQ3ksZioFr1D9etOETJ0ZGWzvTm336SBUzbiZM16MLhxNfACL5GI7kO700V4MP0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hzJ1zoHa; 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="hzJ1zoHa" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31710C4CEE5; Sun, 26 Jan 2025 21:50:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737928226; bh=mZUHBZ4A4sEnSTaCQ5MyMjWrK0FDdPsYWqeujrtmVOg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hzJ1zoHaR/SJS8u4OEiHZqzN2OgBKPfkuRivBe6f3HeDIHd1uS+qQfAhe17JPL6V4 Tz5TxpGJWyUcoZgGKxpV4SPbcEh2hlzzlPftwGGVXYOznIJFj2vWfYFAtp2SaKWZIG QASrXicDKUD3Tg36vPz0SEQTXX04x3MbD6U3s5LmhXhDa09FeTOZDEimTGMz+N8w0m a5CWNbMJvnRYV66l/KyFwtaEkLVnuYGaL+GSYag5+yr5Oixy/U8DZ4QJj1BkdbI0xD m4VCpFll+XNkmw+f9mrn3LRuILO9eMGARg9BPusGycrlVhpketCjsi0F1oKlvmYn+1 jRwhKsYpMQLUw== From: cel@kernel.org To: Amir Goldstein , Neil Brown , Jeff Layton , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: , Chuck Lever , Trond Myklebust Subject: [PATCH v3 2/4] NFSD: Never return NFS4ERR_FILE_OPEN when removing a directory Date: Sun, 26 Jan 2025 16:50:18 -0500 Message-ID: <20250126215020.2466-3-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.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 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..6cd130b5c2b6 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 + * wants a status unique to the object type. */ - 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 Sun Jan 26 21:50:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13950905 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 8378F25A64F for ; Sun, 26 Jan 2025 21:50:27 +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=1737928227; cv=none; b=Txiwpbvy6nhDePoe4aU5VJUgdBeyy2ydaZURrpAiEsTas9Mr6i1Gm2EgSRkqtdJPZPMUbryioXv0pNoScttaybxnPZEOJBc04v+6URmJPf1Edo5ajSVf9av3NlSGUYjT08A9kuUeR2hKYWddiKhFaR/WS/ZNqpBhawWShW39y9U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737928227; c=relaxed/simple; bh=ctRaMSQCF8ndZCswqoz+G5wXIBNqy1MQ5SX5tZq9stE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pocs4t6YNTLThZwAsIMzpf/qDhlRrkLJ3MW6GS8X/Wkbp8RiUvUCrp8/V2V2zirzGUfl2u+adFP58VNIZL2eqhV0FCL73ZKPyhmpdeDNMyiBgoF/8RWN+P6n9rhs6eavWoA1/Bhimn3lo2FFZH1TWgklLbgCwjf/KahS55fytB8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GVI+DpRD; 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="GVI+DpRD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3E3F4C4CED3; Sun, 26 Jan 2025 21:50:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737928227; bh=ctRaMSQCF8ndZCswqoz+G5wXIBNqy1MQ5SX5tZq9stE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GVI+DpRDPP8ENwXhBYnQiyYEv48Kg7H52lidRA6nMP/Q+K//nPlo4SMcWHgytBOMC ycuWD6+83YwlnKm+y45hJ63uAY7fPgOAMQSZr4MLfbV09PbaszcLy8JBPNmBZgqDCV jYJjQqJZh6gT4wrOWXhZ87Cpc1C3XAvxEm5Kg9UEZydyQ8OyUOBWgvKpcUsZPSnj+C +dlV692APKJRS88cmcZDv6eXGW3aIcAJdNO/x0rQ5wQUxmoZPPD/deqitZIw2mzA4l B1c0xFv2Nz6o3pt0SnYGdBjCUeBvNsFRLr37i8ziaRrB/kxD9IVkQupi1ZAuRAMhQO 5noL38xSgC5fA== From: cel@kernel.org To: Amir Goldstein , Neil Brown , Jeff Layton , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: , Chuck Lever Subject: [PATCH v3 3/4] NFSD: Return NFS4ERR_FILE_OPEN only when renaming over an open file Date: Sun, 26 Jan 2025 16:50:19 -0500 Message-ID: <20250126215020.2466-4-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.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 | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index 6cd130b5c2b6..347114da4fd0 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; @@ -1862,11 +1873,14 @@ nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen, host_err = -EINVAL; if (odentry == trap) goto out_dput_old; + type = d_inode(odentry)->i_mode & S_IFMT; ndentry = lookup_one_len(tname, tdentry, tlen); host_err = PTR_ERR(ndentry); if (IS_ERR(ndentry)) goto out_dput_old; + if (d_inode(ndentry)) + type = d_inode(ndentry)->i_mode & S_IFMT; host_err = -ENOTEMPTY; if (ndentry == trap) goto out_dput_new; @@ -1904,7 +1918,18 @@ 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 + * wants a status unique to the object type. + */ + 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 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);