From patchwork Fri Jan 24 15:15:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13949606 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 228C2111AD for ; Fri, 24 Jan 2025 15:15:57 +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=1737731758; cv=none; b=jA/gSkVV0836s0rjWPc2xS5qAqpmDHxLJuugiyG5b+hAI/B4YUYgTpiO9OJOlol+Qgw+hsFFq6ty2xGeGvmy/GkAA3UgIo0P2GhHxdXEtoHoItHF9sgxOhJgAbv7W9fsQGoeKSP24vK/q2OPWSNR9cYQxSm38yJBnzoVnyILZXQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737731758; c=relaxed/simple; bh=XlwZPYpGxHV1byldpoOY4wzN2rz/uZBFH3IV4T33LpQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bNEvdTeR/Z+n8uAb8/wOOq1/ZHdQGzAucg8d/I2oz6UD6pGdos31V2VJFVELWFwXjtTqyI7P9Cfbw8ps4s8iAOAZOkb3hLUuIYCyyhonD9JDD9J0GtQi4ePY5Aj2cUwZNYj8zOFbguOHJIZBsu1JzvVv3fEHjPxUD07+5XXOT7U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=abulXpTX; 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="abulXpTX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D56F3C4CEE5; Fri, 24 Jan 2025 15:15:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737731757; bh=XlwZPYpGxHV1byldpoOY4wzN2rz/uZBFH3IV4T33LpQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=abulXpTXcei/izbehih3RSjmRSbYrlRfkpVHFkm66AGqinn+BqwXBa5IrJKUUA6WN U35Zh0QAjiZMy8Zmn3hm9Nhm1ohkRdtcerG4FoDhBxkwSP9IdjaiYuwI3Ac2RiySqv bfM5rGV3cdQGc2N/2moAhmwAVKLInATxI3gjaW5BDMmsNf++hn7y9bH/D8l13x4xi/ TBZGDQ6bDeEOmGxy6CzDbfAJipiDr8n8/Ia9Tpn35Wj6E8cy1DaJQNh2BxGxKAwi+A glQGu3VuOx33w0/lQdfTb93YOO3gn0cjzTVX4L72hgSswWMbax1mAda9KgSveW0Ay/ 2zYGti7cQXaBQ== From: cel@kernel.org To: Amir Goldstein , Neil Brown , Jeff Layton , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: , Chuck Lever Subject: [PATCH v2 1/4] NFSD: nfsd_unlink() clobbers non-zero status returned from fh_fill_pre_attrs() Date: Fri, 24 Jan 2025 10:15:50 -0500 Message-ID: <20250124151553.17824-2-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250124151553.17824-1-cel@kernel.org> References: <20250124151553.17824-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 Fri Jan 24 15:15:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13949607 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 4F2FA14D70B for ; Fri, 24 Jan 2025 15:15:58 +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=1737731759; cv=none; b=lg3+xc4Y+iIcPkM7i74XfhtRGiBznIZiNVHVriaFeZrWr8zN6uhQqDbvYzyy/diqk0MxdInpqil1zH5YWGoCtC4FxU2ZL+zIsWkzdivaJ2yxQP86FfTCPaCwSQbDjVrNod5eFSjmtwnwK5ynnGQzJzO/wWrQuC3vkmBH4235x9k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737731759; c=relaxed/simple; bh=xXw90luifKfLIPhezyEdSqttYHmT0msZHUPxaQuTLBQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CN5U7H9d0KgBACg9Jvk25LQA6vVC47+lyKZVI+PnBcSmSt+02UMZJ/ropRm110LTW+2sp+pBzGTczt0fV+2LXgiu3Z03zNOFlQthvMsO8U0H9Mhz1wWVzIAIcNZy7TItmg65SfcjwvX8bg3gwg8/lEiGX3/Sol8YzsmyGaD90TI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Z6jtaLDV; 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="Z6jtaLDV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E30B0C4CEE7; Fri, 24 Jan 2025 15:15:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737731758; bh=xXw90luifKfLIPhezyEdSqttYHmT0msZHUPxaQuTLBQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z6jtaLDVkFbFzLpJNQ9Dd8fvbOOz+Yt+lJBbWUvCFvts0jwxE25eW+emJ7hAJUQ5A efwExICx+SgLdxmcob3GgEvOR49BRJ+P08Ae2fL/yemxWH1gnQhzdv218oSs6lDvVO o8fgYPEX5vIpmeKJZSCjVjBTST6vl0KK7X+IoJe0KVh3Yfoa1J3iCuOvBQPq+3vztV OWNS+LaqktzbDdemGohFPY7RCaBmZI92fovlLkhTko/SX2GG+/tPPTs7WgdnqAkOfF pEpt0dJfH+D5aaDwOCsfC4OaA+rupy2cH+Lb/hbdTJlKMopnpugYkocFAZmfPnRlRR IQ9iVMMOK8wbA== From: cel@kernel.org To: Amir Goldstein , Neil Brown , Jeff Layton , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: , Chuck Lever , Trond Myklebust Subject: [PATCH v2 2/4] NFSD: Never return NFS4ERR_FILE_OPEN when removing a directory Date: Fri, 24 Jan 2025 10:15:51 -0500 Message-ID: <20250124151553.17824-3-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250124151553.17824-1-cel@kernel.org> References: <20250124151553.17824-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..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 Fri Jan 24 15:15:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13949608 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 455B014D70B for ; Fri, 24 Jan 2025 15:15:59 +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=1737731760; cv=none; b=FFyfM/K9gX8SGTa45NtWc3sfVIgX5Eom14s3rLDxTCoIzU+iLxgiqFiKsC2ribktWNr6E62/em6XAeIeSWz16hB1BkpSOrnFbr0Mgkaxa+Ug14dRg51YUMYlE2ndnobgwuXcO9ZsI3UH8Z2YgYMjdcYuWeN3fzSBYZh9ktpiE1Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737731760; c=relaxed/simple; bh=lpNCV+uemF9qbqZ1KLuBEdBLEqE7r+bzQZhA5FKroQE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dXHxsi0RtNBEyWuqRtIHFZuo8iUPBu7RnVfVAv8L/HY3pJOVg/Z1B6fmtZugfZo9vJR/kdDQwk7nNxzTSc1jEZJ1yFV3fAcILRnEi04RzjpnQLDFFWknaVk+uJROoJX6lBKhIcpCAeeZfVutSe1zfI8xDH1B+lpyDkDFCOeRPbg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Y+iOnTY+; 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="Y+iOnTY+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 045BDC4CED2; Fri, 24 Jan 2025 15:15:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737731759; bh=lpNCV+uemF9qbqZ1KLuBEdBLEqE7r+bzQZhA5FKroQE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y+iOnTY+07BtciuTxAfgX8PRA9CISTWjwDTGbHk1LKaRvpGPHb0Zhv5OdQhcSJv/j UaeCU8ZDUFm1kjhffbNeBHBrslhlO9SmLtA7lM3QepdoKjgaWuqIacqiCt5wGXBI+d d02kV8ibDTNT4AxnBcNKG7pdr01o4KorwNR2n8ccC5aMzgZ+Lp6miOW2wUAGABObll 5khQ4LnfnB3TbCaAuMitmFzgBa7ilySTBd+P5dbCdjgbjdOog6e5noNzw4eWtRnufs sGXf+eyvh0Ci4wwi/EEmSi4uet2ICHOmqsjPlMTKi7lNuCtbrj1UvBV0MYdBi+Cfw1 lLIg43E9u1P0w== From: cel@kernel.org To: Amir Goldstein , Neil Brown , Jeff Layton , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: , Chuck Lever Subject: [PATCH v2 3/4] NFSD: Return NFS4ERR_FILE_OPEN only when renaming over an open file Date: Fri, 24 Jan 2025 10:15:52 -0500 Message-ID: <20250124151553.17824-4-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250124151553.17824-1-cel@kernel.org> References: <20250124151553.17824-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 | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index 6cd130b5c2b6..532128b34161 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,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 Fri Jan 24 15:15:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13949609 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 D4AE015534B for ; Fri, 24 Jan 2025 15:16:00 +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=1737731760; cv=none; b=k34iwuGifWgM91E3h/5DhyxXordqLK0ngxCvSYMCtNpTy3Z50HKZlg6uAkH/HuC2ZNGl67WYyMPx09sldeve2hmM8xCZokZgPnNEDQqyvw8EV9wh7/+sBH80YRsYYp/CWDn6A2DHYJe0f5+F8q41JQ4FVLu+tDlLNfdy75I2l+k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737731760; c=relaxed/simple; bh=sSiVgBOKSiUMkm8BTFROvWjivQi03fKFirFyqsuBK8c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bap6MbCZU7I5d9/6nXYDYTbgHmgpayE0UlbvQBa5MrEDbKFG1Y5KCy3/Yb9oKldqTS2/agtOa6S4SSv8bz/g4rJ7i8EHfWaYIR2VFtHoWKXdztKeP3KOafdQqwBnp/TfOV5+7s7IcpcZG0e3A11tGqHL31IZerz1z5AVZaohyT4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=I0rEMyYP; 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="I0rEMyYP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F3B18C4CEE4; Fri, 24 Jan 2025 15:15:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737731760; bh=sSiVgBOKSiUMkm8BTFROvWjivQi03fKFirFyqsuBK8c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I0rEMyYP0+0jTLSpuUAtJ1MZ/B+YqEoWGL9QpgzGnUwD+/bYquBUTZy+n6iRzzlgR aEgKEyJQcH0mYFl4iJO6brZpVtffgRJCUyNspX8gC7M5jKf5mE/XwESPYW9X8gKwXx Xoo3KpOZKoYWoh1YRq8p7m6rvfYmB6rEn9xTRz3fHdfBbhVtZcBUSI8Bl3wJLjJ3Ti zS0GiiqTYjAcD031gM9SsBvjCCXfFNUiN/8XktU2jUIzUyhgQ+RPnte7CYi8kM7l3y tAsLqQUeMoHfSyrQN4GKpGe+jxu/h36T2DrJ1oFMa8FksySdT6eWSFbeVahhyNyb2Y s+rGpliT0PFqg== From: cel@kernel.org To: Amir Goldstein , Neil Brown , Jeff Layton , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: , Chuck Lever Subject: [PATCH v2 4/4] NFSD: Return NFS4ERR_FILE_OPEN only when linking an open file Date: Fri, 24 Jan 2025 10:15:53 -0500 Message-ID: <20250124151553.17824-5-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250124151553.17824-1-cel@kernel.org> References: <20250124151553.17824-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 532128b34161..494f14e122fc 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);