From patchwork Fri Mar 15 16:52:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13593685 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 61B464CB2E; Fri, 15 Mar 2024 16:53:10 +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=1710521590; cv=none; b=SnyJj3kgCKVscIuXKMYjLuOQOsqTkLFkr90L3Zex4P4C+HbBoDPpTDBGat6nQWU1OnIIlK5F6lXt7vQn664t4A1PVB2vmbH9O6M5py8jEsY9BN+y/zPOrqrjLtGZPEvEjYslZVepMpWlAVuWx1vjal/0N7aBFx5i9CdTdR/E150= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710521590; c=relaxed/simple; bh=8T+6AOlfeQNDoOcwsJEzBNC68QavdbxR38E+z9RzRco=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=afb3MXSTdZKVZGCaNc1I1G2hFyrLkmvjuGga9YO7hgjM992oSycPUMdjEcjoZkcPlohvqw/d1d3nHGwCtP52vxW/pYvInnJU+kO/fFOV9odNDRvTCvxFDdXYcSYNMcyp5+Y3bCCvHpVbOCxJRxg1ttdqMw5jfeW7F9TvcFjgc44= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AUDyOe+Q; 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="AUDyOe+Q" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3CE9CC43330; Fri, 15 Mar 2024 16:53:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710521590; bh=8T+6AOlfeQNDoOcwsJEzBNC68QavdbxR38E+z9RzRco=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=AUDyOe+Q5lZxtJzsCf7qTK7H4/hxOvfkImC2NcB/evyqNClohpHmxZM/hQPJsf62W DS2OP7iHyOMqCuLZSAdcO+7bfYHpQsQGMz75vrfBzjd4ZrD8EPsdjA9TtraEMbWkso pBvJ6alqfXf36Cg0xIL/2JH07c1Rf2G+4+BkQco4koJVWwTdXCtdeSV7KHARTZ0sFu kcVjcqI2sbJyJR9MH2SG0adqDaYmkiT+9sJLBpCKLr5m4Ch9dkMvAf1J7DlHh55TjN TwkjEDioYr1cUN6SH3fAMVdXAEP9umrPP+UZfogGhXNBKKReHUEEkIO01aZ1+QeQIK J02PcEkUH6g+Q== From: Jeff Layton Date: Fri, 15 Mar 2024 12:52:52 -0400 Subject: [PATCH RFC 01/24] filelock: push the S_ISREG check down to ->setlease handlers Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240315-dir-deleg-v1-1-a1d6209a3654@kernel.org> References: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> In-Reply-To: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Chuck Lever , Alexander Aring , Trond Myklebust , Anna Schumaker , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Greg Kroah-Hartman , "Rafael J. Wysocki" , David Howells , Tyler Hicks , Neil Brown , Olga Kornievskaia , Dai Ngo , Miklos Szeredi , Amir Goldstein , Namjae Jeon , Sergey Senozhatsky , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, netfs@lists.linux.dev, ecryptfs@vger.kernel.org, linux-unionfs@vger.kernel.org, netdev@vger.kernel.org, Jeff Layton X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=2248; i=jlayton@kernel.org; h=from:subject:message-id; bh=8T+6AOlfeQNDoOcwsJEzBNC68QavdbxR38E+z9RzRco=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBl9HzsJ1CBEsrq8i5Ktjn9sZVvT1iJpsa6mUcrE MFBp+WpUjyJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZfR87AAKCRAADmhBGVaC FQ69D/9Gv0ui46+5Z7asnVv3ONO1FfD1Q27hfM+zoxC44Kn2IQR1AW8gU2Y8zAvnx+bPM2W6rdZ uNMueRm6pIHtjRX3LpIkRbXADPaQBhtMoLBO95opU0PQe3b3Fv04BN+drlyJvG5NsxclTzqAy2R swCVQh2cvBjPik90E2d4gGpaddqJgzmThyhFzcvpJEyECheSWljRSj81tlcXZMlOQBvwDaxHnNT fHnWxSvqLaIpDh/7XJgnNFp0/auy/nV4mM2KfUv5dm9Oxu3Dnm82zIB0130RZMj6vce9aLWT/+n rexsrTOF/SLE+jSDlfaHy9NxF6CPDaj8vSNDWf3fVfuquN+kLhLOgvmO0ug/zNncgBCM0nP5JyC P0XUPWUvlXqlL7+liFs5YZ80jR7FJRWmE1bZzSRI8PTmj6YEU3p5mvocnBQLfMJnz4pFr7Dh6xX 7ZaGDJNdZXagKsz8fn0abO9543C8hej+RSPpR58Ma9HcYvobnDub4aU0WbQr29FTsrCzGxKERih +WjetRDcMl+QrhIU148tacvuu/wT8fZXaAOUjtDkGG7WOC5UG9NnJwL+blCyM/wKNnAerlLitmS UBJmG7hTqXYUtBqb/01UE30rbth48Q2cc/4qu8TZqt5hC0C1LpETknJMBmZNaZF9EgdhI10RYw3 KVk/Jrr27U64+Dw== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 When nfsd starts requesting directory delegations, setlease handlers may see requests for leases on directories. Push the !S_ISREG check down into the non-trivial setlease handlers, so we can selectively enable them where they're supported. Signed-off-by: Jeff Layton --- fs/locks.c | 5 +++-- fs/nfs/nfs4file.c | 2 ++ fs/smb/client/cifsfs.c | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/fs/locks.c b/fs/locks.c index 90c8746874de..cb4b35d26162 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -1925,6 +1925,9 @@ static int generic_delete_lease(struct file *filp, void *owner) int generic_setlease(struct file *filp, int arg, struct file_lease **flp, void **priv) { + if (!S_ISREG(file_inode(filp)->i_mode)) + return -EINVAL; + switch (arg) { case F_UNLCK: return generic_delete_lease(filp, *priv); @@ -2014,8 +2017,6 @@ vfs_setlease(struct file *filp, int arg, struct file_lease **lease, void **priv) if ((!vfsuid_eq_kuid(vfsuid, current_fsuid())) && !capable(CAP_LEASE)) return -EACCES; - if (!S_ISREG(inode->i_mode)) - return -EINVAL; error = security_file_lock(filp, arg); if (error) return error; diff --git a/fs/nfs/nfs4file.c b/fs/nfs/nfs4file.c index 1cd9652f3c28..b7630a437ad2 100644 --- a/fs/nfs/nfs4file.c +++ b/fs/nfs/nfs4file.c @@ -442,6 +442,8 @@ void nfs42_ssc_unregister_ops(void) static int nfs4_setlease(struct file *file, int arg, struct file_lease **lease, void **priv) { + if (!S_ISREG(file_inode(file)->i_mode)) + return -EINVAL; return nfs4_proc_setlease(file, arg, lease, priv); } diff --git a/fs/smb/client/cifsfs.c b/fs/smb/client/cifsfs.c index fb368b191eef..81a96fbfa3ed 100644 --- a/fs/smb/client/cifsfs.c +++ b/fs/smb/client/cifsfs.c @@ -1094,6 +1094,9 @@ cifs_setlease(struct file *file, int arg, struct file_lease **lease, void **priv struct inode *inode = file_inode(file); struct cifsFileInfo *cfile = file->private_data; + if (!S_ISREG(inode->i_mode)) + return -EINVAL; + /* Check if file is oplocked if this is request for new lease */ if (arg == F_UNLCK || ((arg == F_RDLCK) && CIFS_CACHE_READ(CIFS_I(inode))) || From patchwork Fri Mar 15 16:52:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13593686 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 D1E6050A60; Fri, 15 Mar 2024 16:53:13 +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=1710521594; cv=none; b=WAK0p5056l7mOMei4iJMHxXLikWw1SkPDX3wQdD/OiPbwFWahqsY92FgkD9p1LnODhDwDk6RtXk8fmkVnGRdfMx7IzS8wo0FIHFvgv7W85G95wi6IYL/+279BPktkfYLXb1Sq2ZnbOyndC+4FA/e8cOQDLuY9N2m6mwwMWWT/Dk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710521594; c=relaxed/simple; bh=yoiNJ2WMy08Z/jmvwgFEmuwGurlE5zLX34Ydm7pIfCE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XjA6w0lbfsfCd44dASjqWF6unHW4GneHnPO/5doV+PJapFFZjTQuwOjh1N0+Ni5C5o/Lu3BrfGiJSh8wLzV7cr/Hw5FmyaEvI93O5WB+3EfQg0TofXjkhGE++5jPhrrj+P24cAo9IwZ1R8Mt0uyewGjhOHHPivcMfX4mXG1XhT4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XEY+uGi+; 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="XEY+uGi+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75A6CC433A6; Fri, 15 Mar 2024 16:53:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710521593; bh=yoiNJ2WMy08Z/jmvwgFEmuwGurlE5zLX34Ydm7pIfCE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=XEY+uGi+XMfNO7Nb9q1mLl4Bfrs/QaMERD5P8XHgsE2J6AyHsA6licbS7dt+lLy2t KM0eaSgrJ59Koop917ozXPgeF6uTMZEP918pHrzQLXSL03vEFVh51sClvgH6k0vOUR 2PeS5U7F2I05DTJA54hYL5sGQzW7yYX2yJ/tSVUNWroH4kRN0WOQqVTnxr9T6awvoe nFgi9nhNxa+3XTCLMBpVJhoehe1rMjgiebXSozDVnZgwPQY6cCIct+aH7NlPcY6Upl H7w6YxbygBaPaVf5PIgvj96wnZDBzV0HptW2ZGvonXw+4R4lbEEKC70h33YvkH5tM8 9/Fa/diGIy0lA== From: Jeff Layton Date: Fri, 15 Mar 2024 12:52:53 -0400 Subject: [PATCH RFC 02/24] filelock: add a lm_set_conflict lease_manager callback Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240315-dir-deleg-v1-2-a1d6209a3654@kernel.org> References: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> In-Reply-To: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Chuck Lever , Alexander Aring , Trond Myklebust , Anna Schumaker , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Greg Kroah-Hartman , "Rafael J. Wysocki" , David Howells , Tyler Hicks , Neil Brown , Olga Kornievskaia , Dai Ngo , Miklos Szeredi , Amir Goldstein , Namjae Jeon , Sergey Senozhatsky , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, netfs@lists.linux.dev, ecryptfs@vger.kernel.org, linux-unionfs@vger.kernel.org, netdev@vger.kernel.org, Jeff Layton X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1797; i=jlayton@kernel.org; h=from:subject:message-id; bh=yoiNJ2WMy08Z/jmvwgFEmuwGurlE5zLX34Ydm7pIfCE=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBl9Hzs2+8zYCAzKB5/98GTlmhyG+aP5LQ4QlhAD oFPU5y3oqqJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZfR87AAKCRAADmhBGVaC FZYbD/9PgexRfP/oZyLnzXj1LQWbdWuafLMR1PrMfcQdA8nLyj3/XcZVj2tQW5hRtHbc1/GScMU yYZdODfDWam9emdF6YJ/+OhumYMhsUydbjCmkDn8q0AaXNW355kf+uqC5F+k+1fQlSMMykC1K2Z QEQnObzc18vZmuUlY4UeMotErRi+UVV2ZAZT+YAnIoK0o/r7sXEbwUdlzlz0BBV1wxCBEv5wGQX h/aNQk9ECgurxf0qnWemYcGZA4kbJenOXPHG3mpleUBOO/tMcKUyUWKZVfdd8khpEQFd5cdWqDk xX1W5Ez+Hg6MJhufoEvl0ulX62KFJIexDpJIh1ZpqgNe+RzEoXXx1DaZ2dRJ+fD4RFiSw8RDGzh 7P02ZSdU95bgAICsLfo7ojqsfatE2cN40aDVw4/nui8+h+60jsLjYKirmVGJ60gI9WRw/I1VDMs 9Hbv0fCP36t1OpGXXG//745DiBd8rrv0fmBSwFuy4/f1DBDywPZudFYUCaU9rl5FlDw4NFxEM3/ 2arcncljpxeoVmWuGp3VUg/B+82OWTDnbaxZfRQH7Sn4f4yzgTwvqIW8bk+lSmYcvdcvbbF9PDa i60bc0vUKjfjiCDeGSP8ou4pL/07m1Dyhlc6e/t4O4Kk/NrnxGN71aEYWCgqeU8EmnCYTCDjmrM XfcREeDkf4rMEBA== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 The NFSv4.1 protocol adds support for directory delegations, but it specifies that if you already have a delegation and try to request a new one on the same filehandle, the server must reply that the delegation is unavailable. Add a new lease_manager callback to allow the lease manager (nfsd in this case) to impose extra checks when performing a setlease. Signed-off-by: Jeff Layton --- fs/locks.c | 5 +++++ include/linux/filelock.h | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/fs/locks.c b/fs/locks.c index cb4b35d26162..415cca8e9565 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -1822,6 +1822,11 @@ generic_add_lease(struct file *filp, int arg, struct file_lease **flp, void **pr continue; } + /* Allow the lease manager to veto the setlease */ + if (lease->fl_lmops->lm_set_conflict && + lease->fl_lmops->lm_set_conflict(lease, fl)) + goto out; + /* * No exclusive leases if someone else has a lease on * this file: diff --git a/include/linux/filelock.h b/include/linux/filelock.h index daee999d05f3..c5fc768087df 100644 --- a/include/linux/filelock.h +++ b/include/linux/filelock.h @@ -49,6 +49,16 @@ struct lease_manager_operations { int (*lm_change)(struct file_lease *, int, struct list_head *); void (*lm_setup)(struct file_lease *, void **); bool (*lm_breaker_owns_lease)(struct file_lease *); + + /** + * lm_set_conflict - extra conditions for setlease + * @new: new file_lease being set + * @old: old (extant) file_lease + * + * This allows the lease manager to add extra conditions when + * setting a lease. + */ + bool (*lm_set_conflict)(struct file_lease *new, struct file_lease *old); }; struct lock_manager { From patchwork Fri Mar 15 16:52:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13593687 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 13DE553383; Fri, 15 Mar 2024 16:53:16 +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=1710521597; cv=none; b=GxF64s2MEkDKAlJCLRRSJ9O7HmVmCh/rvjozEUe3nPLxITrvTucjw7LaAuc3A1kPOo7qH4XP9yWW74z1g4CuJszrOKiKIX22U+bThLBENlt/o+AReiITw0V1kF+dbEt64eMB/T6+9I7Qh+Oh67i6NCcPYvUwh+fPrMnhZDwBbGc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710521597; c=relaxed/simple; bh=fKwiuKl53KobzjbKSb1MXdgcO5uYAnMu6jBhF4A2PpI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dRvo652+pvgffeAqghjyTai9nqlgCXD82TX++JQAaqQYpIvj8aTE/RuKXhgABJ/KGXU0Mu1vZZAUMWghOGadOTLYrLsSfq7+631JHplKlsefn/zIxbEBKpUC4eq/wpKAJ7Z61yp81aWg+qnkakAQxeAXV7hVYumO93X6vYJE8Os= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=g11P8Vlm; 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="g11P8Vlm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A520CC4166A; Fri, 15 Mar 2024 16:53:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710521596; bh=fKwiuKl53KobzjbKSb1MXdgcO5uYAnMu6jBhF4A2PpI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=g11P8Vlm2QTCw1CH+0YoJtXmCt+YyoAw2XSXSSmPSO+8uzsTW2Vvu9hzzwBraEYJp eeQ8X1IXqvmNKGcBNgRCV4Vj8gS7pERvhzS14SVld3HYTeWjZV0h3qLmmluZmsrmL0 lqkZdL0GWfZsXLbs8bQuufw03lN7aDpSS1mjc7Sejie7mIbAScfPRDyrsa3B3ZVZqx /WwsawQl6/lBGsFlZe6Dh/jOJS5Kmh8P8yCsQmomMt6OsfIjE8ymc1mqKTOuqtmxix /Jh6A6vl0GZvHzqQ+vRQ/+nng7bZKnPBdXD9K3lmVPWwiHHjPjTmGJtAPQ9i46pCEC JQrfg/IMuZx6Q== From: Jeff Layton Date: Fri, 15 Mar 2024 12:52:54 -0400 Subject: [PATCH RFC 03/24] vfs: add try_break_deleg calls for parents to vfs_{link,rename,unlink} Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240315-dir-deleg-v1-3-a1d6209a3654@kernel.org> References: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> In-Reply-To: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Chuck Lever , Alexander Aring , Trond Myklebust , Anna Schumaker , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Greg Kroah-Hartman , "Rafael J. Wysocki" , David Howells , Tyler Hicks , Neil Brown , Olga Kornievskaia , Dai Ngo , Miklos Szeredi , Amir Goldstein , Namjae Jeon , Sergey Senozhatsky , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, netfs@lists.linux.dev, ecryptfs@vger.kernel.org, linux-unionfs@vger.kernel.org, netdev@vger.kernel.org, Jeff Layton X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1924; i=jlayton@kernel.org; h=from:subject:message-id; bh=fKwiuKl53KobzjbKSb1MXdgcO5uYAnMu6jBhF4A2PpI=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBl9HzsfnDeU1npZ9UPd6x10BjoUFU4+T+gGmHrG pQmiDL15LCJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZfR87AAKCRAADmhBGVaC FSfZD/sHqk1hYBvTn5PMwdUn2UqE4oW7xjGgxauc2340L4WCReb3aBWqjBHXlnJp4KFoJlCF8/R CY4BOYfemuI1eHF7hDnuLNdqA5T9SIspmGjKDBnpFYsbwN5w/+iG14qbGkbvib7PJwIa+BVHoIW 7X5C6Ymhe9esmQ6Jxa15ZznmII+UCZsOIfEOtEvoWtKlGccvKkYnCsJQUPUvW/pkku6z+HAxT4a Q0Av79s8GFcU+Bk1DaU7AILv3sLz0zDECwM57TaUxfIFr5epPFmYDI/f8m6+ArFd94UeQJL69bH PvhGPth7Pssc0zFSqcLs+A3vLPGlvMHaYXoxW35roYab4rjwke4CKmujzgVT92JZRTdzj7XdPOX lg6fYZBJqgOuNGCeEHu1TAK+caqKJht7/zNrChpMFUp6zzKJDbJldLplPSsNcbpBB6iax3fXGxF Uklmy8p7Ebz0AJjGGASCaBr/vbIhTzZbNvNjHsfTuHMB4r9anPCTlqCoDOTVOk9nm285gZItuib 41cdQBAXvpZKsFhcJcsYjUuwZnO8ex9gSI5V6FiRb0uiugwr+vRmU65EDYxhcYHwRFCdjtA+68G iGtvhqN4sQA8lQhNYQd9ZAvMfqeC5X8PPEC9EAs4Kf/i+RTl6sThgvMpbizXcaA4TO+HpExKJUa Qlqa4vWYaEEsB5w== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 In order to add directory delegation support, we need to break delegations on the parent whenever there is going to be a change in the directory. vfs_link, vfs_unlink, and vfs_rename all have existing delegation break handling for the children in the rename. Add the necessary calls for breaking delegations in the parent(s) as well. Signed-off-by: Jeff Layton --- fs/namei.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 9342fa6a38c2..56d3ebed7bac 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -4332,6 +4332,9 @@ int vfs_unlink(struct mnt_idmap *idmap, struct inode *dir, else { error = security_inode_unlink(dir, dentry); if (!error) { + error = try_break_deleg(dir, delegated_inode); + if (error) + goto out; error = try_break_deleg(target, delegated_inode); if (error) goto out; @@ -4603,9 +4606,12 @@ int vfs_link(struct dentry *old_dentry, struct mnt_idmap *idmap, else if (max_links && inode->i_nlink >= max_links) error = -EMLINK; else { - error = try_break_deleg(inode, delegated_inode); - if (!error) - error = dir->i_op->link(old_dentry, dir, new_dentry); + error = try_break_deleg(dir, delegated_inode); + if (!error) { + error = try_break_deleg(inode, delegated_inode); + if (!error) + error = dir->i_op->link(old_dentry, dir, new_dentry); + } } if (!error && (inode->i_state & I_LINKABLE)) { @@ -4870,6 +4876,14 @@ int vfs_rename(struct renamedata *rd) old_dir->i_nlink >= max_links) goto out; } + error = try_break_deleg(old_dir, delegated_inode); + if (error) + goto out; + if (new_dir != old_dir) { + error = try_break_deleg(new_dir, delegated_inode); + if (error) + goto out; + } if (!is_dir) { error = try_break_deleg(source, delegated_inode); if (error) From patchwork Fri Mar 15 16:52:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13593688 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 3FF0E5476B; Fri, 15 Mar 2024 16:53:19 +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=1710521600; cv=none; b=HrPpBnBiMTD4apcGj5D2dQ7SLBD5a3o0v5chHhrPifCJiJeAbOIRPFJUg80BMaPmIuJZyaLzEsI53kyvbC8I8pfXAmlYEekEa7DPKD9f6aL6GWdtLdIamMsZpoDPWLrNrlD+7Fgl4NNOLMOiYxfWzcI3TyZUh8LCYpxGwSsBSGU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710521600; c=relaxed/simple; bh=dYFxokjKa1qkijO4rvlZtg8suVitMd6Maf1anlNcBeo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=F/u3F2aMBlYaNk/rfyctSAxp0H+2WOQCKFj2AktIrjXFul8ekjjxY76Ko9tKqDo27fcE2eggS3FQEDtx/Z1pDzcoc8gX3+9UdkzoFVxvBIZNt/TxHJXK9KmR+0gOot94berOS7djrEUiGAsiH/4oit6Te9PPqF0QKg3qB0Pg2lk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dY22mtdp; 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="dY22mtdp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D60F9C43390; Fri, 15 Mar 2024 16:53:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710521599; bh=dYFxokjKa1qkijO4rvlZtg8suVitMd6Maf1anlNcBeo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=dY22mtdp8I4Lw1p+jspcjYw3FPUZ2tA76A3yQ+5QvWSDLBLCCsEWeFvLtQxHBlrhm 9q/YpywBlcMbfj7kNYwnbhTpEAon5efpJIKJkCzHwJ8dXzKyZW8U8VI9JCoNF8ydaH d522wue/Bds2QDfkur6Ykfk4rM5z45uWosouYEln+jSZGX5kOw6+wwicomBTJJgOPy ydSTRaIL2fvCNWzvQqdq5VdZOQogTsEGP+Xj+pQbxbG0izAFaYjr8Vov+nYfPPUISN K/L0o5132ayJIEgJ/9hyCBUsZIjHB6nN1IkyrRzpvlRgqvlUsVyaUX5BC4GPJ4qpby ql15tpb2aBQMA== From: Jeff Layton Date: Fri, 15 Mar 2024 12:52:55 -0400 Subject: [PATCH RFC 04/24] vfs: allow mkdir to wait for delegation break on parent Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240315-dir-deleg-v1-4-a1d6209a3654@kernel.org> References: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> In-Reply-To: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Chuck Lever , Alexander Aring , Trond Myklebust , Anna Schumaker , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Greg Kroah-Hartman , "Rafael J. Wysocki" , David Howells , Tyler Hicks , Neil Brown , Olga Kornievskaia , Dai Ngo , Miklos Szeredi , Amir Goldstein , Namjae Jeon , Sergey Senozhatsky , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, netfs@lists.linux.dev, ecryptfs@vger.kernel.org, linux-unionfs@vger.kernel.org, netdev@vger.kernel.org, Jeff Layton X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=7376; i=jlayton@kernel.org; h=from:subject:message-id; bh=dYFxokjKa1qkijO4rvlZtg8suVitMd6Maf1anlNcBeo=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBl9Hzt2YNTHp03zBF3TkT69pRtsIg/EwN1lwb+0 DNF7I1m+CiJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZfR87QAKCRAADmhBGVaC FVWBEACABlZC1oNdEVOjMMtqfTwWD7iCcDQX+oI8naMY1y4jsOXn5COAN2wyDD/QkFaBB9GZRag jGbN68ItVtP2FVFEwM0D/gY/mOH8BO9m6CbsLBVXdSZ82DcAPk5dDN9lRvHgVquyKpW+VXFdgIb xS1rKJ0hOzNesNYV/Gpe4ZwCfdgiSo4zsk14LQU48YtcS67inPIRgDdnsZFxafpfP7k4VX42Wmp k1NFfK1T3Nblr/xxAAiOPJouQsXWCaIi33jJPdFETHRB3n6elTJujufZEzxwCr6KasE8Nm3fPtq /MNn1P3gmZIdfkazUhgIpZIfb8ZTEFQg0sl8pqvAKml8/ViZ8kQfxFI8znVeiqR+W7NNS2aReDE ZkUCeuyH8pmm7zEXbOzhDaCZuiDizF2N8pcyEhgL2clYRk2FtOKXj6nAO/bbGiZdAflD+4jENVB 504/JNpZFJudybsqPz2w1kM/5LDD6Q+XLsxQ3kSeX+A29JRdtyv8y8yXgECScXF0fkASmaTJCVR aWOgDQGOjhSGAdDzAPXUNBFPSDOMn1S+uqoEyhl/6dubT5kGJ+7pX8UejAKvfqSu8ALsxkETLre +xqJWXOrZfC1tbZPG9WFV/UpP6D2sihSS7IPOp2vyfE5S798+HkB7gzx65MHJMw2AlE52Eqi7sV urPcS/YCYaLhlfg== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 In order to add directory delegation support, we need to break delegations on the parent whenever there is going to be a change in the directory. Add a new delegated_inode parameter to vfs_mkdir. Most callers will set that to NULL, but do_mkdirat can use that to wait for the delegation break to complete and then retry. Signed-off-by: Jeff Layton --- drivers/base/devtmpfs.c | 2 +- fs/cachefiles/namei.c | 2 +- fs/ecryptfs/inode.c | 2 +- fs/init.c | 2 +- fs/namei.c | 17 +++++++++++++---- fs/nfsd/nfs4recover.c | 2 +- fs/nfsd/vfs.c | 2 +- fs/overlayfs/overlayfs.h | 2 +- fs/smb/server/vfs.c | 2 +- include/linux/fs.h | 2 +- 10 files changed, 22 insertions(+), 13 deletions(-) diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c index b848764ef018..8d1dbcad69f7 100644 --- a/drivers/base/devtmpfs.c +++ b/drivers/base/devtmpfs.c @@ -166,7 +166,7 @@ static int dev_mkdir(const char *name, umode_t mode) if (IS_ERR(dentry)) return PTR_ERR(dentry); - err = vfs_mkdir(&nop_mnt_idmap, d_inode(path.dentry), dentry, mode); + err = vfs_mkdir(&nop_mnt_idmap, d_inode(path.dentry), dentry, mode, NULL); if (!err) /* mark as kernel-created inode */ d_inode(dentry)->i_private = &thread; diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c index 7ade836beb58..4e3e31320275 100644 --- a/fs/cachefiles/namei.c +++ b/fs/cachefiles/namei.c @@ -130,7 +130,7 @@ struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache, goto mkdir_error; ret = cachefiles_inject_write_error(); if (ret == 0) - ret = vfs_mkdir(&nop_mnt_idmap, d_inode(dir), subdir, 0700); + ret = vfs_mkdir(&nop_mnt_idmap, d_inode(dir), subdir, 0700, NULL); if (ret < 0) { trace_cachefiles_vfs_error(NULL, d_inode(dir), ret, cachefiles_trace_mkdir_error); diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c index 5ed1e4cf6c0b..d26b4484fa60 100644 --- a/fs/ecryptfs/inode.c +++ b/fs/ecryptfs/inode.c @@ -513,7 +513,7 @@ static int ecryptfs_mkdir(struct mnt_idmap *idmap, struct inode *dir, rc = lock_parent(dentry, &lower_dentry, &lower_dir); if (!rc) rc = vfs_mkdir(&nop_mnt_idmap, lower_dir, - lower_dentry, mode); + lower_dentry, mode, NULL); if (rc || d_really_is_negative(lower_dentry)) goto out; rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb); diff --git a/fs/init.c b/fs/init.c index e9387b6c4f30..325c9e4d9b20 100644 --- a/fs/init.c +++ b/fs/init.c @@ -232,7 +232,7 @@ int __init init_mkdir(const char *pathname, umode_t mode) error = security_path_mkdir(&path, dentry, mode); if (!error) error = vfs_mkdir(mnt_idmap(path.mnt), path.dentry->d_inode, - dentry, mode); + dentry, mode, NULL); done_path_create(&path, dentry); return error; } diff --git a/fs/namei.c b/fs/namei.c index 56d3ebed7bac..6a22517f9938 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -4103,7 +4103,7 @@ SYSCALL_DEFINE3(mknod, const char __user *, filename, umode_t, mode, unsigned, d * raw inode simply pass @nop_mnt_idmap. */ int vfs_mkdir(struct mnt_idmap *idmap, struct inode *dir, - struct dentry *dentry, umode_t mode) + struct dentry *dentry, umode_t mode, struct inode **delegated_inode) { int error; unsigned max_links = dir->i_sb->s_max_links; @@ -4123,6 +4123,10 @@ int vfs_mkdir(struct mnt_idmap *idmap, struct inode *dir, if (max_links && dir->i_nlink >= max_links) return -EMLINK; + error = try_break_deleg(dir, delegated_inode); + if (error) + return error; + error = dir->i_op->mkdir(idmap, dir, dentry, mode); if (!error) fsnotify_mkdir(dir, dentry); @@ -4136,6 +4140,7 @@ int do_mkdirat(int dfd, struct filename *name, umode_t mode) struct path path; int error; unsigned int lookup_flags = LOOKUP_DIRECTORY; + struct inode *delegated_inode = NULL; retry: dentry = filename_create(dfd, name, &path, lookup_flags); @@ -4145,11 +4150,15 @@ int do_mkdirat(int dfd, struct filename *name, umode_t mode) error = security_path_mkdir(&path, dentry, mode_strip_umask(path.dentry->d_inode, mode)); - if (!error) { + if (!error) error = vfs_mkdir(mnt_idmap(path.mnt), path.dentry->d_inode, - dentry, mode); - } + dentry, mode, &delegated_inode); done_path_create(&path, dentry); + if (delegated_inode) { + error = break_deleg_wait(&delegated_inode); + if (!error) + goto retry; + } if (retry_estale(error, lookup_flags)) { lookup_flags |= LOOKUP_REVAL; goto retry; diff --git a/fs/nfsd/nfs4recover.c b/fs/nfsd/nfs4recover.c index 2c060e0b1604..5bfced783a70 100644 --- a/fs/nfsd/nfs4recover.c +++ b/fs/nfsd/nfs4recover.c @@ -234,7 +234,7 @@ nfsd4_create_clid_dir(struct nfs4_client *clp) * as well be forgiving and just succeed silently. */ goto out_put; - status = vfs_mkdir(&nop_mnt_idmap, d_inode(dir), dentry, S_IRWXU); + status = vfs_mkdir(&nop_mnt_idmap, d_inode(dir), dentry, S_IRWXU, NULL); out_put: dput(dentry); out_unlock: diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index 6a4c506038e0..e42e58825590 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -1496,7 +1496,7 @@ nfsd_create_locked(struct svc_rqst *rqstp, struct svc_fh *fhp, nfsd_check_ignore_resizing(iap); break; case S_IFDIR: - host_err = vfs_mkdir(&nop_mnt_idmap, dirp, dchild, iap->ia_mode); + host_err = vfs_mkdir(&nop_mnt_idmap, dirp, dchild, iap->ia_mode, NULL); if (!host_err && unlikely(d_unhashed(dchild))) { struct dentry *d; d = lookup_one_len(dchild->d_name.name, diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h index ee949f3e7c77..baa371947f86 100644 --- a/fs/overlayfs/overlayfs.h +++ b/fs/overlayfs/overlayfs.h @@ -242,7 +242,7 @@ static inline int ovl_do_mkdir(struct ovl_fs *ofs, struct inode *dir, struct dentry *dentry, umode_t mode) { - int err = vfs_mkdir(ovl_upper_mnt_idmap(ofs), dir, dentry, mode); + int err = vfs_mkdir(ovl_upper_mnt_idmap(ofs), dir, dentry, mode, NULL); pr_debug("mkdir(%pd2, 0%o) = %i\n", dentry, mode, err); return err; } diff --git a/fs/smb/server/vfs.c b/fs/smb/server/vfs.c index c487e834331a..3760e0dda349 100644 --- a/fs/smb/server/vfs.c +++ b/fs/smb/server/vfs.c @@ -227,7 +227,7 @@ int ksmbd_vfs_mkdir(struct ksmbd_work *work, const char *name, umode_t mode) idmap = mnt_idmap(path.mnt); mode |= S_IFDIR; - err = vfs_mkdir(idmap, d_inode(path.dentry), dentry, mode); + err = vfs_mkdir(idmap, d_inode(path.dentry), dentry, mode, NULL); if (!err && d_unhashed(dentry)) { struct dentry *d; diff --git a/include/linux/fs.h b/include/linux/fs.h index 8dfcddafdb3d..18eb7d628290 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1839,7 +1839,7 @@ bool inode_owner_or_capable(struct mnt_idmap *idmap, int vfs_create(struct mnt_idmap *, struct inode *, struct dentry *, umode_t, bool); int vfs_mkdir(struct mnt_idmap *, struct inode *, - struct dentry *, umode_t); + struct dentry *, umode_t, struct inode **); int vfs_mknod(struct mnt_idmap *, struct inode *, struct dentry *, umode_t, dev_t); int vfs_symlink(struct mnt_idmap *, struct inode *, From patchwork Fri Mar 15 16:52:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13593689 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 63E6054910; Fri, 15 Mar 2024 16:53:23 +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=1710521603; cv=none; b=dRK7DH+NSso+NTORJZqEFSXRoXm/wBiiNrZn9a+VpIno0YtvITrqnpT9oEZ7iKBYyCo6hXUw7k5N/Nubq+dwGOQS38ih+fnDYZdEfhOtbv7XoOeUyOJpFClm4KSmkpha+PloQYMEHVzDxrKMtSBYXJJ8dJv84OA+qH5yd7O7gew= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710521603; c=relaxed/simple; bh=4Hh6J09N40Wh6o7Y7XvcqF+EG8cxj/8qFYbo024OMkU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GtFK1KUu+wsCOpUBimT7F48cu1xhiHOVDXV5HNdetKVJWALxr96IaNlFcxCq2uG3DmTJOdbxK1+VLl08vHqs1jRJK4xP2fP1AHPHAGHO23gc265pTgc95638DrSl4Q/Oa4VfHhu282jnGOgs67sEoJwO6xj8bl1kM8uQ2fJsgTM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ode0hfFu; 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="ode0hfFu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1351DC43609; Fri, 15 Mar 2024 16:53:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710521603; bh=4Hh6J09N40Wh6o7Y7XvcqF+EG8cxj/8qFYbo024OMkU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ode0hfFu6Gg9RHfhivzCeASVGZsOe/RdUmf1C493jkcyVJGUDp0hzALLCup4zs3tx hWWSZOheFCmuPgxgTJ1sb9DU5YfYfL6GOi7Ywr0tH3M+03imNCNwBPkbzO5mujObcP 21HALFvYvdm1eusUYjhfR+V8Tp9r6DgU3Z14qYk9XNiLxZJhV6T5/a2f6+/4oMrD62 rljvNgtBN4p9w4n/bXLKF/eD66NIGAya0zP3I5WKhVoEZ6+MtjEJ1UpvOb23avBTM2 /Xqri7PfTXUZZIl6teaGZpK1sB0tfrtGk7ItxbkkmdUvCMkt0l15ivwfxrYUQ9+AuA 3jTo44hNLi4xw== From: Jeff Layton Date: Fri, 15 Mar 2024 12:52:56 -0400 Subject: [PATCH RFC 05/24] vfs: allow rmdir to wait for delegation break on parent Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240315-dir-deleg-v1-5-a1d6209a3654@kernel.org> References: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> In-Reply-To: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Chuck Lever , Alexander Aring , Trond Myklebust , Anna Schumaker , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Greg Kroah-Hartman , "Rafael J. Wysocki" , David Howells , Tyler Hicks , Neil Brown , Olga Kornievskaia , Dai Ngo , Miklos Szeredi , Amir Goldstein , Namjae Jeon , Sergey Senozhatsky , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, netfs@lists.linux.dev, ecryptfs@vger.kernel.org, linux-unionfs@vger.kernel.org, netdev@vger.kernel.org, Jeff Layton X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=7032; i=jlayton@kernel.org; h=from:subject:message-id; bh=4Hh6J09N40Wh6o7Y7XvcqF+EG8cxj/8qFYbo024OMkU=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBl9Hzt9k6/585HV65ukYqnWWqAbMCrWWWQNmCTg kTMzxFXcRiJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZfR87QAKCRAADmhBGVaC FUIKD/9z8JZIU07s513G0XxxneuCrd9u7hEEB1Mib4EnmqFq5ThTbEwUs5mCIte9khpQ/5NArX/ 3wzTpaF7+Om8T074fwYQaVKp0YsOP5BtipNh71epmC0lE7WjJHhcDoRt1sJtd7inaWWKXr0TmoD 8x28NBfcvENlifSpkvC6PVPRCMRZZbmCAh5XhVSE7CcfEFJunhNywWO/QKoDxibi2guxymBnLHk Ra4Mv6zj1IhqAORmYpc36R5/hp2qxCzsgp3b3XzzPXKFO8YMjZecAbB/+PvbbNR0SuaOx+kcEYz ylqsJq4lhL9wULmtcXGSREKC7P1mJzyZGyYBU6LeBSFjVgXWOG6K3ert+g0teM7CABspgJVy9le VfDF+seu6N2LLDd+sAUwH+7VpOxsx/DQOPuHY5WYZ/vrZpXlDAkObTVCVITW6hmd/cOzNs+Ksi8 VhYfjl8Vk+NHHQ5ijsnmloBGNy8KPUq73ZZTcjXqbz+fKAG/7fto81A7xt1uYrahVywY/Bp17m6 jmCNMf0N1KRcOvU6I/q/pvQ4PKGxMIvMj1rODVeyWauRMJbonrWX9Or6f13QDO6F35zIF/4NEIW wlFzRF5hF9Z6/a6/cvvX9Nkx1pzVqzicrkynMwudYWJ7Lxgjmq+xwIhaFoQ/F2URj2vdcIn/9g9 dvaoqH0SMWfYEZQ== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 In order to add directory delegation support, we need to break delegations on the parent whenever there is going to be a change in the directory. Add a new delegated_inode parameter to vfs_rmdir. Most callers will set that to NULL, but do_rmdir can use that to wait for the delegation break to complete and then retry. Signed-off-by: Jeff Layton --- drivers/base/devtmpfs.c | 2 +- fs/ecryptfs/inode.c | 2 +- fs/namei.c | 16 ++++++++++++++-- fs/nfsd/nfs4recover.c | 4 ++-- fs/nfsd/vfs.c | 2 +- fs/overlayfs/overlayfs.h | 2 +- fs/smb/server/vfs.c | 4 ++-- include/linux/fs.h | 3 ++- 8 files changed, 24 insertions(+), 11 deletions(-) diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c index 8d1dbcad69f7..c00126796f79 100644 --- a/drivers/base/devtmpfs.c +++ b/drivers/base/devtmpfs.c @@ -248,7 +248,7 @@ static int dev_rmdir(const char *name) if (d_really_is_positive(dentry)) { if (d_inode(dentry)->i_private == &thread) err = vfs_rmdir(&nop_mnt_idmap, d_inode(parent.dentry), - dentry); + dentry, NULL); else err = -EPERM; } else { diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c index d26b4484fa60..3d0cddbf037c 100644 --- a/fs/ecryptfs/inode.c +++ b/fs/ecryptfs/inode.c @@ -541,7 +541,7 @@ static int ecryptfs_rmdir(struct inode *dir, struct dentry *dentry) if (d_unhashed(lower_dentry)) rc = -EINVAL; else - rc = vfs_rmdir(&nop_mnt_idmap, lower_dir, lower_dentry); + rc = vfs_rmdir(&nop_mnt_idmap, lower_dir, lower_dentry, NULL); } if (!rc) { clear_nlink(d_inode(dentry)); diff --git a/fs/namei.c b/fs/namei.c index 6a22517f9938..f00d8d708001 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -4183,6 +4183,7 @@ SYSCALL_DEFINE2(mkdir, const char __user *, pathname, umode_t, mode) * @idmap: idmap of the mount the inode was found from * @dir: inode of @dentry * @dentry: pointer to dentry of the base directory + * @delegated_inode: return pointer for delegated inode * * Remove a directory. * @@ -4193,7 +4194,7 @@ SYSCALL_DEFINE2(mkdir, const char __user *, pathname, umode_t, mode) * raw inode simply pass @nop_mnt_idmap. */ int vfs_rmdir(struct mnt_idmap *idmap, struct inode *dir, - struct dentry *dentry) + struct dentry *dentry, struct inode **delegated_inode) { int error = may_delete(idmap, dir, dentry, 1); @@ -4215,6 +4216,10 @@ int vfs_rmdir(struct mnt_idmap *idmap, struct inode *dir, if (error) goto out; + error = try_break_deleg(dir, delegated_inode); + if (error) + goto out; + error = dir->i_op->rmdir(dir, dentry); if (error) goto out; @@ -4241,6 +4246,7 @@ int do_rmdir(int dfd, struct filename *name) struct qstr last; int type; unsigned int lookup_flags = 0; + struct inode *delegated_inode = NULL; retry: error = filename_parentat(dfd, name, lookup_flags, &path, &last, &type); if (error) @@ -4274,7 +4280,8 @@ int do_rmdir(int dfd, struct filename *name) error = security_path_rmdir(&path, dentry); if (error) goto exit4; - error = vfs_rmdir(mnt_idmap(path.mnt), path.dentry->d_inode, dentry); + error = vfs_rmdir(mnt_idmap(path.mnt), path.dentry->d_inode, + dentry, &delegated_inode); exit4: dput(dentry); exit3: @@ -4282,6 +4289,11 @@ int do_rmdir(int dfd, struct filename *name) mnt_drop_write(path.mnt); exit2: path_put(&path); + if (delegated_inode) { + error = break_deleg_wait(&delegated_inode); + if (!error) + goto retry; + } if (retry_estale(error, lookup_flags)) { lookup_flags |= LOOKUP_REVAL; goto retry; diff --git a/fs/nfsd/nfs4recover.c b/fs/nfsd/nfs4recover.c index 5bfced783a70..0e82f79471cf 100644 --- a/fs/nfsd/nfs4recover.c +++ b/fs/nfsd/nfs4recover.c @@ -354,7 +354,7 @@ nfsd4_unlink_clid_dir(char *name, int namlen, struct nfsd_net *nn) status = -ENOENT; if (d_really_is_negative(dentry)) goto out; - status = vfs_rmdir(&nop_mnt_idmap, d_inode(dir), dentry); + status = vfs_rmdir(&nop_mnt_idmap, d_inode(dir), dentry, NULL); out: dput(dentry); out_unlock: @@ -444,7 +444,7 @@ purge_old(struct dentry *parent, struct dentry *child, struct nfsd_net *nn) if (nfs4_has_reclaimed_state(name, nn)) goto out_free; - status = vfs_rmdir(&nop_mnt_idmap, d_inode(parent), child); + status = vfs_rmdir(&nop_mnt_idmap, d_inode(parent), child, NULL); if (status) printk("failed to remove client recovery directory %pd\n", child); diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index e42e58825590..34cc2d1a4944 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -2003,7 +2003,7 @@ nfsd_unlink(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, break; } } else { - host_err = vfs_rmdir(&nop_mnt_idmap, dirp, rdentry); + host_err = vfs_rmdir(&nop_mnt_idmap, dirp, rdentry, NULL); } fh_fill_post_attrs(fhp); diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h index baa371947f86..5b1f56294c4d 100644 --- a/fs/overlayfs/overlayfs.h +++ b/fs/overlayfs/overlayfs.h @@ -203,7 +203,7 @@ static inline int ovl_do_notify_change(struct ovl_fs *ofs, static inline int ovl_do_rmdir(struct ovl_fs *ofs, struct inode *dir, struct dentry *dentry) { - int err = vfs_rmdir(ovl_upper_mnt_idmap(ofs), dir, dentry); + int err = vfs_rmdir(ovl_upper_mnt_idmap(ofs), dir, dentry, NULL); pr_debug("rmdir(%pd2) = %i\n", dentry, err); return err; diff --git a/fs/smb/server/vfs.c b/fs/smb/server/vfs.c index 3760e0dda349..5b4e5876c2ac 100644 --- a/fs/smb/server/vfs.c +++ b/fs/smb/server/vfs.c @@ -611,7 +611,7 @@ int ksmbd_vfs_remove_file(struct ksmbd_work *work, const struct path *path) idmap = mnt_idmap(path->mnt); if (S_ISDIR(d_inode(path->dentry)->i_mode)) { - err = vfs_rmdir(idmap, d_inode(parent), path->dentry); + err = vfs_rmdir(idmap, d_inode(parent), path->dentry, NULL); if (err && err != -ENOTEMPTY) ksmbd_debug(VFS, "rmdir failed, err %d\n", err); } else { @@ -1084,7 +1084,7 @@ int ksmbd_vfs_unlink(struct file *filp) dget(dentry); if (S_ISDIR(d_inode(dentry)->i_mode)) - err = vfs_rmdir(idmap, d_inode(dir), dentry); + err = vfs_rmdir(idmap, d_inode(dir), dentry, NULL); else err = vfs_unlink(idmap, d_inode(dir), dentry, NULL); diff --git a/include/linux/fs.h b/include/linux/fs.h index 18eb7d628290..e72c825476de 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1846,7 +1846,8 @@ int vfs_symlink(struct mnt_idmap *, struct inode *, struct dentry *, const char *); int vfs_link(struct dentry *, struct mnt_idmap *, struct inode *, struct dentry *, struct inode **); -int vfs_rmdir(struct mnt_idmap *, struct inode *, struct dentry *); +int vfs_rmdir(struct mnt_idmap *, struct inode *, struct dentry *, + struct inode **); int vfs_unlink(struct mnt_idmap *, struct inode *, struct dentry *, struct inode **); From patchwork Fri Mar 15 16:52:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13593690 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 A00FC56758; Fri, 15 Mar 2024 16:53: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=1710521606; cv=none; b=oXe6FOA+/6KN8+NzhlKriSic6Ll6pWyVfA8LQ25aWsKZUvu8fX/Uc/C5DollD0XChhUeypIjyF3F1IclT22rukC5mjRPsBNvWzmFxeDyEOX4+BnLkCUdto+BYXWIzTnkHfr6xW5Tpf+O/BaAqFv61yh36TjrA7f9uT/3sHH6WM0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710521606; c=relaxed/simple; bh=pNsngRzgw8CEGDxcLrFjYZpk10rAX7yWtKnMHw2YxwE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Rp3VRwMdQeFdnfyjTjWZvR95zX6q6YAMUGP32jcFClo5yQQFYuzx+BjNMjJhBA7rcoh6Tj4vd4R/ZBsADpQpZyJnuKu+BBnr5VNYMy1/bAjKf8wnYofjg2ov42+aJRTZ/QPXxbNmbxedU0U7z51COuViCHhPhowpELgQXg7Zhb0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=taAB791R; 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="taAB791R" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43AAFC43601; Fri, 15 Mar 2024 16:53:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710521606; bh=pNsngRzgw8CEGDxcLrFjYZpk10rAX7yWtKnMHw2YxwE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=taAB791R5Xdjx0ThiJdW+vqwgJ+WDVR5BELTZ9zupxXhg6Bkc+GotPp+PPLOTQcu5 Jl+RUQuAa54BcCD2IPeyBKB4+YjtyvJakN+R0EPtGatqoH2m1z9BKDxOC7+jDu1AVr 5wAHTvNaSTobg7b+42t2SuGZf6gzP+0ECNT3uckB/km51Bf+p/AqMIxHor+ZqGVOie uE2sAYylN8qtVz353c51w4I1wQfgrCYiIUElTUwLCI6VYiDWVoduUiqPTxiIewjmxe lMUgWA5r9AQGmYaz28YEQc4VSoHUfoclXASRCXM+O4n7QOQ94Qeym91b6PlmMj5nJA G6dSWDl0MILcQ== From: Jeff Layton Date: Fri, 15 Mar 2024 12:52:57 -0400 Subject: [PATCH RFC 06/24] vfs: break parent dir delegations in open(..., O_CREAT) codepath Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240315-dir-deleg-v1-6-a1d6209a3654@kernel.org> References: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> In-Reply-To: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Chuck Lever , Alexander Aring , Trond Myklebust , Anna Schumaker , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Greg Kroah-Hartman , "Rafael J. Wysocki" , David Howells , Tyler Hicks , Neil Brown , Olga Kornievskaia , Dai Ngo , Miklos Szeredi , Amir Goldstein , Namjae Jeon , Sergey Senozhatsky , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, netfs@lists.linux.dev, ecryptfs@vger.kernel.org, linux-unionfs@vger.kernel.org, netdev@vger.kernel.org, Jeff Layton X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=2943; i=jlayton@kernel.org; h=from:subject:message-id; bh=pNsngRzgw8CEGDxcLrFjYZpk10rAX7yWtKnMHw2YxwE=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBl9HztCX4vyElQrHztHrMIhenbB3r+5vTs620Ft ibHnhreb96JAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZfR87QAKCRAADmhBGVaC FeVWD/9HXrfF8C9gMMmlb/yPm/eZKZ+0UHcF/vvMd2O+2tMmSMQqO0lAD0BNjn+q02XGoga3GXJ y2q3eR+ez9xLCEVoICGz7rJXG9laxCleebaQk8p9mroi2ULPwIzkqb6HDx5dChIahfT9dtUneOO WiXzmgW+fBPkXHL5Bzrl3aKL32BeV6r7HOeX2AqPZC8li35Kl9zlvfpKbu0mRn+44K6hWamilLo vCuAOJTrnxuvPv3gxdTJW4ly5A5l/Bcn2SE1Ah0EEcQysluzy183G34X9taw7eDIpa1QJ5pmqaY tuDw0A4BEpk20WymMN92EtfdTJ/FM2c+gdg3tQxOsSdmxSzljb15j0YqfzTm9UJWc/wjriBIETe ll4FDW16YLwAxN167qoEBhbd+Kg/EAIlePcFD3YpFcU7Zjr5W/cOu0HKYaipxFiGOoN8Y11zMMo mohdx5hBYkcmqcYgHIgIqjFOSNNudIEdhkKZpZJP7jxPkHJZCa9MlqpbVwp+uX9NPaV9N9Y3bGU hqN7nf3kPGs9t6ZZGbPLCRW+nsyzgD24cGBsrXCWktlbYU/i8DWAsd3JxTBuVlT07rDUcidJefA Q0yElVrkmg3clEvHNQGaei1uVg1aps5SAgp5rVHf642TFdxajBoAtlbqzQXUvE74OHkpzrGsHrl b6afdnHiFZjlC1w== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 In order to add directory delegation support, we need to break delegations on the parent whenever there is going to be a change in the directory. Add a delegated_inode parameter to lookup_open and have it break the delegation. Then, open_last_lookups can wait for the delegation break and retry the call to lookup_open once it's done. Signed-off-by: Jeff Layton --- fs/namei.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index f00d8d708001..88598a62ec64 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3404,7 +3404,7 @@ static struct dentry *atomic_open(struct nameidata *nd, struct dentry *dentry, */ static struct dentry *lookup_open(struct nameidata *nd, struct file *file, const struct open_flags *op, - bool got_write) + bool got_write, struct inode **delegated_inode) { struct mnt_idmap *idmap; struct dentry *dir = nd->path.dentry; @@ -3490,6 +3490,11 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file, /* Negative dentry, just create the file */ if (!dentry->d_inode && (open_flag & O_CREAT)) { + /* but break the directory lease first! */ + error = try_break_deleg(dir_inode, delegated_inode); + if (error) + goto out_dput; + file->f_mode |= FMODE_CREATED; audit_inode_child(dir_inode, dentry, AUDIT_TYPE_CHILD_CREATE); if (!dir_inode->i_op->create) { @@ -3517,6 +3522,7 @@ static const char *open_last_lookups(struct nameidata *nd, struct file *file, const struct open_flags *op) { struct dentry *dir = nd->path.dentry; + struct inode *delegated_inode = NULL; int open_flag = op->open_flag; bool got_write = false; struct dentry *dentry; @@ -3553,7 +3559,7 @@ static const char *open_last_lookups(struct nameidata *nd, if (unlikely(nd->last.name[nd->last.len])) return ERR_PTR(-EISDIR); } - +retry: if (open_flag & (O_CREAT | O_TRUNC | O_WRONLY | O_RDWR)) { got_write = !mnt_want_write(nd->path.mnt); /* @@ -3566,7 +3572,7 @@ static const char *open_last_lookups(struct nameidata *nd, inode_lock(dir->d_inode); else inode_lock_shared(dir->d_inode); - dentry = lookup_open(nd, file, op, got_write); + dentry = lookup_open(nd, file, op, got_write, &delegated_inode); if (!IS_ERR(dentry) && (file->f_mode & FMODE_CREATED)) fsnotify_create(dir->d_inode, dentry); if (open_flag & O_CREAT) @@ -3577,8 +3583,16 @@ static const char *open_last_lookups(struct nameidata *nd, if (got_write) mnt_drop_write(nd->path.mnt); - if (IS_ERR(dentry)) + if (IS_ERR(dentry)) { + if (delegated_inode) { + int error = break_deleg_wait(&delegated_inode); + + if (!error) + goto retry; + return ERR_PTR(error); + } return ERR_CAST(dentry); + } if (file->f_mode & (FMODE_OPENED | FMODE_CREATED)) { dput(nd->path.dentry); From patchwork Fri Mar 15 16:52:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13593691 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 89E925789A; Fri, 15 Mar 2024 16:53:29 +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=1710521609; cv=none; b=uZC11cwNWTWbNLlsz67vttcpZO8XfGgrsIGM/j19J7J/SpI1qf++hfzDjNz+UG6miufms7nVHa+Hs/e59rtRLcn8mjX8a8hm2bjpb2bVRhIfh6meqceHA/qowvZtydV0SwK56/+6WB5lVuzng+SnDaBxTxYE0JwGPNAgwRUDrH8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710521609; c=relaxed/simple; bh=glgM3noZVvpgC18bf/O/H9XbEIKtml3KkdNnOiy8zrM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=loNXr8hSaJqdcGLWZt3igTXtXvzAMax8QrBci+VqWNjOzXL8UCg7iOX7D7SAOzf2HHYqBj5QTit0QVawpGUqf+/3xLtY56rYk2wWxAVTCetkbCi87ZuzRBVMeOhtyAwP1m7elOEF4nWTsW/I7XzxZtnqCX71XDkYC3v9onGJY08= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VdVoPRdS; 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="VdVoPRdS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75E3AC433B2; Fri, 15 Mar 2024 16:53:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710521609; bh=glgM3noZVvpgC18bf/O/H9XbEIKtml3KkdNnOiy8zrM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=VdVoPRdS9rWL+OtiSBwfMZSVrxf5PYEtpWN6TxBcbQjAyTwRJJQ4UTV+3Zvc5682A b4Ox2Coe/lFOnomcVJigs43Lgkwu2ezvgnHYVCyuf3d6Q/5DMg1pyHZmF8OlIHri1Z t/pA7Tf3EqRoKEZeNNnldgTeJ7KYXmOg1I6KuhFanOGU5u0bQZz2MZlJwjJAuBnutG 01C5N07R8a1WXy71M1wLuSIvxWRKaKGtYfIumdLDoxwooS0QC7gQmGloeRgL2mX0fX fXhmerZjC77g6y922Rs0Q/x3/sYk77aadNc38cJmUC31WjDvoFxlQkMYuCww3Wg8Ij 1u04AzH7TQGbg== From: Jeff Layton Date: Fri, 15 Mar 2024 12:52:58 -0400 Subject: [PATCH RFC 07/24] vfs: make vfs_create break delegations on parent directory Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240315-dir-deleg-v1-7-a1d6209a3654@kernel.org> References: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> In-Reply-To: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Chuck Lever , Alexander Aring , Trond Myklebust , Anna Schumaker , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Greg Kroah-Hartman , "Rafael J. Wysocki" , David Howells , Tyler Hicks , Neil Brown , Olga Kornievskaia , Dai Ngo , Miklos Szeredi , Amir Goldstein , Namjae Jeon , Sergey Senozhatsky , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, netfs@lists.linux.dev, ecryptfs@vger.kernel.org, linux-unionfs@vger.kernel.org, netdev@vger.kernel.org, Jeff Layton X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=6464; i=jlayton@kernel.org; h=from:subject:message-id; bh=glgM3noZVvpgC18bf/O/H9XbEIKtml3KkdNnOiy8zrM=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBl9Hztj02A0ox+G3fk9c35abnyHv3ewQW8y77IN UsVqKDGetGJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZfR87QAKCRAADmhBGVaC FYn1D/4u9cH/KKPFevh9JevmDnEzcvgiG2JXDGRTokqAPxsRMA9XL/nlKGK80vAGVfXpnP1sIri nC0Cr94CFOIPMr+nC9v11y/qI/IkjtY7ekq/pKXGrIajvynPx69f+OsLUOIfeAlC4lzKmDye47u CIhdtAUb3UbcPwEceV69AUdDw2yfNd2zoOrQLDsp+Z41xCX70juLmOPFE6OnrwII2XmJsFT5gFg P2H5iw+STZTkKuLMP72816+1oWO09Zc5ZhSaFTG1xXNggjpVk6zAb+7OsbvHlGf/tiyPvK+XGlV 8ccjpRvAUx7oBCtyyXhFy4EBFGB7668+qOH/39Hdhnm/icffHBzIKQfsxM+nf8fjRWijnubMksM Qr1+Diztt2hYsO6FpW0yfdt29ZGcPjh4WMTNMI/jbCwyqTZL9kWrKinmE9QzD3me17lEhbB6oZp mjd4c1Ut8MhTEXvMb20LyNBZyEz8xMppipjxXH7qx3y6V7BAXKGnD+qX8OxhrbkbhWFgUjAM1Bq axlJ4F/uDHSSyPD17NnBRj1NpvVYQJsSE1+jBz3OOP+QM2NbFt+DKcEIbl/KdEhLW/awo2LvIjw aDz7yktrvz4fQgELpfoA7MzB4S2RogS+3A0TODKTeQrHD0NELk9GFs+8k49JyIypqmgSdM0bLHF zWUYZZRUnre6OvA== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 In order to add directory delegation support, we need to break delegations on the parent whenever there is going to be a change in the directory. Add a new delegated_inode parameter to vfs_create. Most callers will set that to NULL, but do_mknodat can use that to synchronously wait for the delegation break to complete. Signed-off-by: Jeff Layton --- fs/ecryptfs/inode.c | 2 +- fs/namei.c | 15 +++++++++++++-- fs/nfsd/nfs3proc.c | 2 +- fs/nfsd/vfs.c | 2 +- fs/open.c | 2 +- fs/overlayfs/overlayfs.h | 2 +- fs/smb/server/vfs.c | 2 +- include/linux/fs.h | 2 +- 8 files changed, 20 insertions(+), 9 deletions(-) diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c index 3d0cddbf037c..a99b1e264c46 100644 --- a/fs/ecryptfs/inode.c +++ b/fs/ecryptfs/inode.c @@ -189,7 +189,7 @@ ecryptfs_do_create(struct inode *directory_inode, rc = lock_parent(ecryptfs_dentry, &lower_dentry, &lower_dir); if (!rc) rc = vfs_create(&nop_mnt_idmap, lower_dir, - lower_dentry, mode, true); + lower_dentry, mode, true, NULL); if (rc) { printk(KERN_ERR "%s: Failure to create dentry in lower fs; " "rc = [%d]\n", __func__, rc); diff --git a/fs/namei.c b/fs/namei.c index 88598a62ec64..01e04cf155eb 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3174,6 +3174,7 @@ static inline umode_t vfs_prepare_mode(struct mnt_idmap *idmap, * @dentry: pointer to dentry of the base directory * @mode: mode of the new file * @want_excl: whether the file must not yet exist + * @delegated_inode: return pointer for delegated_inode * * Create a new file. * @@ -3184,7 +3185,8 @@ static inline umode_t vfs_prepare_mode(struct mnt_idmap *idmap, * raw inode simply pass @nop_mnt_idmap. */ int vfs_create(struct mnt_idmap *idmap, struct inode *dir, - struct dentry *dentry, umode_t mode, bool want_excl) + struct dentry *dentry, umode_t mode, bool want_excl, + struct inode **delegated_inode) { int error; @@ -3197,6 +3199,9 @@ int vfs_create(struct mnt_idmap *idmap, struct inode *dir, mode = vfs_prepare_mode(idmap, dir, mode, S_IALLUGO, S_IFREG); error = security_inode_create(dir, dentry, mode); + if (error) + return error; + error = try_break_deleg(dir, delegated_inode); if (error) return error; error = dir->i_op->create(idmap, dir, dentry, mode, want_excl); @@ -4047,6 +4052,7 @@ static int do_mknodat(int dfd, struct filename *name, umode_t mode, struct path path; int error; unsigned int lookup_flags = 0; + struct inode *delegated_inode = NULL; error = may_mknod(mode); if (error) @@ -4066,7 +4072,7 @@ static int do_mknodat(int dfd, struct filename *name, umode_t mode, switch (mode & S_IFMT) { case 0: case S_IFREG: error = vfs_create(idmap, path.dentry->d_inode, - dentry, mode, true); + dentry, mode, true, &delegated_inode); if (!error) ima_post_path_mknod(idmap, dentry); break; @@ -4081,6 +4087,11 @@ static int do_mknodat(int dfd, struct filename *name, umode_t mode, } out2: done_path_create(&path, dentry); + if (delegated_inode) { + error = break_deleg_wait(&delegated_inode); + if (!error) + goto retry; + } if (retry_estale(error, lookup_flags)) { lookup_flags |= LOOKUP_REVAL; goto retry; diff --git a/fs/nfsd/nfs3proc.c b/fs/nfsd/nfs3proc.c index dfcc957e460d..e920a6291f2d 100644 --- a/fs/nfsd/nfs3proc.c +++ b/fs/nfsd/nfs3proc.c @@ -313,7 +313,7 @@ nfsd3_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, status = fh_fill_pre_attrs(fhp); if (status != nfs_ok) goto out; - host_err = vfs_create(&nop_mnt_idmap, inode, child, iap->ia_mode, true); + host_err = vfs_create(&nop_mnt_idmap, inode, child, iap->ia_mode, true, NULL); if (host_err < 0) { status = nfserrno(host_err); goto out; diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index 34cc2d1a4944..47b8ab1d4b17 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -1491,7 +1491,7 @@ nfsd_create_locked(struct svc_rqst *rqstp, struct svc_fh *fhp, switch (type) { case S_IFREG: host_err = vfs_create(&nop_mnt_idmap, dirp, dchild, - iap->ia_mode, true); + iap->ia_mode, true, NULL); if (!host_err) nfsd_check_ignore_resizing(iap); break; diff --git a/fs/open.c b/fs/open.c index 0a73afe04d34..0b50ea7e8aec 100644 --- a/fs/open.c +++ b/fs/open.c @@ -1137,7 +1137,7 @@ struct file *dentry_create(const struct path *path, int flags, umode_t mode, error = vfs_create(mnt_idmap(path->mnt), d_inode(path->dentry->d_parent), - path->dentry, mode, true); + path->dentry, mode, true, NULL); if (!error) error = vfs_open(path, f); diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h index 5b1f56294c4d..be2518e6da95 100644 --- a/fs/overlayfs/overlayfs.h +++ b/fs/overlayfs/overlayfs.h @@ -232,7 +232,7 @@ static inline int ovl_do_create(struct ovl_fs *ofs, struct inode *dir, struct dentry *dentry, umode_t mode) { - int err = vfs_create(ovl_upper_mnt_idmap(ofs), dir, dentry, mode, true); + int err = vfs_create(ovl_upper_mnt_idmap(ofs), dir, dentry, mode, true, NULL); pr_debug("create(%pd2, 0%o) = %i\n", dentry, mode, err); return err; diff --git a/fs/smb/server/vfs.c b/fs/smb/server/vfs.c index 5b4e5876c2ac..b313eb5a1d28 100644 --- a/fs/smb/server/vfs.c +++ b/fs/smb/server/vfs.c @@ -187,7 +187,7 @@ int ksmbd_vfs_create(struct ksmbd_work *work, const char *name, umode_t mode) mode |= S_IFREG; err = vfs_create(mnt_idmap(path.mnt), d_inode(path.dentry), - dentry, mode, true); + dentry, mode, true, NULL); if (!err) { ksmbd_vfs_inherit_owner(work, d_inode(path.dentry), d_inode(dentry)); diff --git a/include/linux/fs.h b/include/linux/fs.h index e72c825476de..8fb4101fea49 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1837,7 +1837,7 @@ bool inode_owner_or_capable(struct mnt_idmap *idmap, * VFS helper functions.. */ int vfs_create(struct mnt_idmap *, struct inode *, - struct dentry *, umode_t, bool); + struct dentry *, umode_t, bool, struct inode **); int vfs_mkdir(struct mnt_idmap *, struct inode *, struct dentry *, umode_t, struct inode **); int vfs_mknod(struct mnt_idmap *, struct inode *, struct dentry *, From patchwork Fri Mar 15 16:52:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13593692 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 2544158ADE; Fri, 15 Mar 2024 16:53:32 +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=1710521613; cv=none; b=IDIlACKw6WAtC6Hsvg0SzoopB3/ibHScn4ZlgLA4Tz4F3oeVZP/M2NjSxJpZCA9D6R5IrsJQc+f7CJweLNTi8Id7k0jV9566JVuCOQsgEac7iFp7BgK8qK6jJ/KVti77ECRgbomJdMhG8SlpeCM9R8DHnzhTJrxcNvnOTU3OeaM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710521613; c=relaxed/simple; bh=A/Nofv6jvEBl49XHLBGXua/1eUYdkgzdVhY0jmU9xq8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ospHGYvza96F3RgXGQ7nIjwS4O1+8a/r/uqMWttEuAtG7y/z5/HjVeV0sbEEPz2wpxaMvyj+LjxPuZCOqycOQdI7iiT+xc+F/ES4XUovv8qfZU8pLCQpsYXOhr4wL/nfTQ8KYIjHJAltr10MTM7DZNFtHZQ+osLv+kG3qgsFjBQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WpMNJ5yK; 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="WpMNJ5yK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A81FCC43394; Fri, 15 Mar 2024 16:53:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710521612; bh=A/Nofv6jvEBl49XHLBGXua/1eUYdkgzdVhY0jmU9xq8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=WpMNJ5yKdtUExT0NtExNsSwOKpWxCFORz1Imkn5kgGGbjKKD3XGQYJ0Ix6ASoSFvy WXMMUBQ8HTJQYQ1NWdwvhOVFCRLcvJ4ZDBJCyuSD7TMtHiR192VydhyO2lwBQxUGSa V0epqfbYNwwKTzy260g3iGFNO72njDi1iGn61+9MYUHrKsQaa8XwvsTUCsLQlJSXNl ML9XyHxoBLSqS9LmLI/3n6+OoSgEHd6Cl0tZK0010ayaKiX0/qV7wfs8EDXjqi5PNd D6yPJG3LXFVm08JM7uW1P2WkuG/SdkkdPHqMdEKOawaIW4X5wZbB/A1wji0rsG5SCu oUSTZKzTmdMVg== From: Jeff Layton Date: Fri, 15 Mar 2024 12:52:59 -0400 Subject: [PATCH RFC 08/24] vfs: make vfs_mknod break delegations on parent directory Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240315-dir-deleg-v1-8-a1d6209a3654@kernel.org> References: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> In-Reply-To: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Chuck Lever , Alexander Aring , Trond Myklebust , Anna Schumaker , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Greg Kroah-Hartman , "Rafael J. Wysocki" , David Howells , Tyler Hicks , Neil Brown , Olga Kornievskaia , Dai Ngo , Miklos Szeredi , Amir Goldstein , Namjae Jeon , Sergey Senozhatsky , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, netfs@lists.linux.dev, ecryptfs@vger.kernel.org, linux-unionfs@vger.kernel.org, netdev@vger.kernel.org, Jeff Layton X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=6152; i=jlayton@kernel.org; h=from:subject:message-id; bh=A/Nofv6jvEBl49XHLBGXua/1eUYdkgzdVhY0jmU9xq8=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBl9Hzt6FbvM1BM7CP4UXM+6W1njDcNK0c5kl7c6 XmwmbqwbiiJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZfR87QAKCRAADmhBGVaC FQ4AEACThSeI6+TIG1kW9UqOnWQeo3HAg9T3swR2ryWmmPBYfMC8YOjGUQ4zalxhyC7ulplluuu WY58OEjlFnlRH9+584tktokXhQU9ZQ9yx5hUlpKbeBWOO6N6LPAMyIUGD5VT79riv7OCVvgr7Re rYdSgfmDFGZl3dcWf0D+9K2MZmOCHDnvaCLb+1vC3GscGfc+IcgXvEqY2AyWHruVn/TpalthhjF Jt8PjRCjf18/hHEm7Jr3eXwA7FcaC2bvWWt6zp3H/guan5GwtvT447i6UlxTWsTeNF3/Slx3qq4 jNwLWpZGjM21C8LHY6+3t7Yo3dYTUpg6l5w8fg9DAQreFJUXhVEpG0SRWfYEdU/7ZJ09qqWX0eP bk25vEDF+cEyz1TCgSD+10anAXfwzhoMnRslPoJw6s0VLOOIrAbhvsQygDGrguVx7TrLdnUIOqK 3xLy9Eda5ZkMhGDX7FWngE69fsNfgLROAgoZ0I3pIjvpjkmMID0+0xry/wmcESz3714Oa2zGSN0 3K1SO6fWsSfRBXcOrtS8wQ0BqKsYvCzFw5sMT0NyIQBYMGWMuNsUq4CyAmkJWCMHGyMv6V430z5 4fHiE92XenLjSwKTzv8qpXwgnvNwzQgZ+j0iOpijB4S06LhjY91QG5/+ipENUaumU7VEarDukQk OJsNC2Ncebk4E6Q== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 In order to add directory delegation support, we need to break delegations on the parent whenever there is going to be a change in the directory. Add a new delegated_inode parameter to vfs_mknod. Most callers will set that to NULL, but do_mknodat can use that to synchronously wait for the delegation break to complete. Signed-off-by: Jeff Layton --- drivers/base/devtmpfs.c | 2 +- fs/ecryptfs/inode.c | 2 +- fs/init.c | 2 +- fs/namei.c | 11 ++++++++--- fs/nfsd/vfs.c | 2 +- fs/overlayfs/overlayfs.h | 2 +- include/linux/fs.h | 4 ++-- net/unix/af_unix.c | 2 +- 8 files changed, 16 insertions(+), 11 deletions(-) diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c index c00126796f79..8c0a872e3165 100644 --- a/drivers/base/devtmpfs.c +++ b/drivers/base/devtmpfs.c @@ -217,7 +217,7 @@ static int handle_create(const char *nodename, umode_t mode, kuid_t uid, return PTR_ERR(dentry); err = vfs_mknod(&nop_mnt_idmap, d_inode(path.dentry), dentry, mode, - dev->devt); + dev->devt, NULL); if (!err) { struct iattr newattrs; diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c index a99b1e264c46..c6442b8caa2f 100644 --- a/fs/ecryptfs/inode.c +++ b/fs/ecryptfs/inode.c @@ -566,7 +566,7 @@ ecryptfs_mknod(struct mnt_idmap *idmap, struct inode *dir, rc = lock_parent(dentry, &lower_dentry, &lower_dir); if (!rc) rc = vfs_mknod(&nop_mnt_idmap, lower_dir, - lower_dentry, mode, dev); + lower_dentry, mode, dev, NULL); if (rc || d_really_is_negative(lower_dentry)) goto out; rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb); diff --git a/fs/init.c b/fs/init.c index 325c9e4d9b20..99c6b413adad 100644 --- a/fs/init.c +++ b/fs/init.c @@ -157,7 +157,7 @@ int __init init_mknod(const char *filename, umode_t mode, unsigned int dev) error = security_path_mknod(&path, dentry, mode, dev); if (!error) error = vfs_mknod(mnt_idmap(path.mnt), path.dentry->d_inode, - dentry, mode, new_decode_dev(dev)); + dentry, mode, new_decode_dev(dev), NULL); done_path_create(&path, dentry); return error; } diff --git a/fs/namei.c b/fs/namei.c index 01e04cf155eb..a185974c1a55 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3996,7 +3996,8 @@ EXPORT_SYMBOL(user_path_create); * raw inode simply pass @nop_mnt_idmap. */ int vfs_mknod(struct mnt_idmap *idmap, struct inode *dir, - struct dentry *dentry, umode_t mode, dev_t dev) + struct dentry *dentry, umode_t mode, dev_t dev, + struct inode **delegated_inode) { bool is_whiteout = S_ISCHR(mode) && dev == WHITEOUT_DEV; int error = may_create(idmap, dir, dentry); @@ -4020,6 +4021,10 @@ int vfs_mknod(struct mnt_idmap *idmap, struct inode *dir, if (error) return error; + error = try_break_deleg(dir, delegated_inode); + if (error) + return error; + error = dir->i_op->mknod(idmap, dir, dentry, mode, dev); if (!error) fsnotify_create(dir, dentry); @@ -4078,11 +4083,11 @@ static int do_mknodat(int dfd, struct filename *name, umode_t mode, break; case S_IFCHR: case S_IFBLK: error = vfs_mknod(idmap, path.dentry->d_inode, - dentry, mode, new_decode_dev(dev)); + dentry, mode, new_decode_dev(dev), &delegated_inode); break; case S_IFIFO: case S_IFSOCK: error = vfs_mknod(idmap, path.dentry->d_inode, - dentry, mode, 0); + dentry, mode, 0, &delegated_inode); break; } out2: diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index 47b8ab1d4b17..fe088e7c49c8 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -1525,7 +1525,7 @@ nfsd_create_locked(struct svc_rqst *rqstp, struct svc_fh *fhp, case S_IFIFO: case S_IFSOCK: host_err = vfs_mknod(&nop_mnt_idmap, dirp, dchild, - iap->ia_mode, rdev); + iap->ia_mode, rdev, NULL); break; default: printk(KERN_WARNING "nfsd: bad file type %o in nfsd_create\n", diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h index be2518e6da95..26cdef6c3579 100644 --- a/fs/overlayfs/overlayfs.h +++ b/fs/overlayfs/overlayfs.h @@ -251,7 +251,7 @@ static inline int ovl_do_mknod(struct ovl_fs *ofs, struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev) { - int err = vfs_mknod(ovl_upper_mnt_idmap(ofs), dir, dentry, mode, dev); + int err = vfs_mknod(ovl_upper_mnt_idmap(ofs), dir, dentry, mode, dev, NULL); pr_debug("mknod(%pd2, 0%o, 0%o) = %i\n", dentry, mode, dev, err); return err; diff --git a/include/linux/fs.h b/include/linux/fs.h index 8fb4101fea49..4b396c9a7a84 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1841,7 +1841,7 @@ int vfs_create(struct mnt_idmap *, struct inode *, int vfs_mkdir(struct mnt_idmap *, struct inode *, struct dentry *, umode_t, struct inode **); int vfs_mknod(struct mnt_idmap *, struct inode *, struct dentry *, - umode_t, dev_t); + umode_t, dev_t, struct inode **); int vfs_symlink(struct mnt_idmap *, struct inode *, struct dentry *, const char *); int vfs_link(struct dentry *, struct mnt_idmap *, struct inode *, @@ -1879,7 +1879,7 @@ static inline int vfs_whiteout(struct mnt_idmap *idmap, struct inode *dir, struct dentry *dentry) { return vfs_mknod(idmap, dir, dentry, S_IFCHR | WHITEOUT_MODE, - WHITEOUT_DEV); + WHITEOUT_DEV, NULL); } struct file *kernel_tmpfile_open(struct mnt_idmap *idmap, diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index 0748e7ea5210..34fbcc90c984 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -1227,7 +1227,7 @@ static int unix_bind_bsd(struct sock *sk, struct sockaddr_un *sunaddr, idmap = mnt_idmap(parent.mnt); err = security_path_mknod(&parent, dentry, mode, 0); if (!err) - err = vfs_mknod(idmap, d_inode(parent.dentry), dentry, mode, 0); + err = vfs_mknod(idmap, d_inode(parent.dentry), dentry, mode, 0, NULL); if (err) goto out_path; err = mutex_lock_interruptible(&u->bindlock); From patchwork Fri Mar 15 16:53:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13593693 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 57AC059B75; Fri, 15 Mar 2024 16:53:35 +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=1710521616; cv=none; b=HoJWz7RQmDSLX7gWWU7Xfm4RhuNHOOguZk0K0g6gs2vlzGbEJo/nwNzScl1RG7iW5A22RaWg/kuGj6yeZ8lxu+cIbWAbWh854Flkj25m6TYM8XHNguLGoa8ndZ4yt+OWAOlEc/ElzCNJN/ovguyS6+eXmfPfNddLqk32OrnYwAI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710521616; c=relaxed/simple; bh=WHR8repRSXOg/bX4tw/xWusjAXs7tEvWrqZw+/zetag=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mwFGoQSnxzG70P4L7RrgX+PSLn3cyc/IRRR0kVrPqfH5CZf020qyZCVefv5xl8LWw8XXzwU6hQfbXttgVERLC3DcV+naMIDKPSjTK+1YNsGALhwmjzvqNSmnjgqHJvp/cgGyFC0zVQhvD5K9ND/5PjL9Cl7SNBw0sjVat2+jSFs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Q2RtZ7Pr; 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="Q2RtZ7Pr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DAFF4C43142; Fri, 15 Mar 2024 16:53:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710521615; bh=WHR8repRSXOg/bX4tw/xWusjAXs7tEvWrqZw+/zetag=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Q2RtZ7Prk5x46NfLwePZ9aGqyTpWzhnebOuRfvTCC1Nk2oq2qEwpTvJEHNcV2Olqh HKgtEUJlgdg+pAlUjDp/jeK/oV5GHIbsboK5j1+IO/uak6O0mH+45mpJbrOQwDVXDp 9Z1dbmWimyEisRjGaQu9XcI+C/js7sqHesJU+ReRbFRXShJar1YJx2ofmFbooEd0WZ DFPxB5Ilx83/bFS6LEs6qILgSXc07sn9FIBKEbtA7Ny8q25PqeRo3yAtjDUX7edTDP +6B+uJPMM+x2Cy1yUiSY7pwwSNInRPgZwz4wCNSkkEnFILkoPL7Hd0+SKGaIrGnEW3 5w9VjKaywordw== From: Jeff Layton Date: Fri, 15 Mar 2024 12:53:00 -0400 Subject: [PATCH RFC 09/24] filelock: lift the ban on directory leases in generic_setlease Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240315-dir-deleg-v1-9-a1d6209a3654@kernel.org> References: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> In-Reply-To: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Chuck Lever , Alexander Aring , Trond Myklebust , Anna Schumaker , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Greg Kroah-Hartman , "Rafael J. Wysocki" , David Howells , Tyler Hicks , Neil Brown , Olga Kornievskaia , Dai Ngo , Miklos Szeredi , Amir Goldstein , Namjae Jeon , Sergey Senozhatsky , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, netfs@lists.linux.dev, ecryptfs@vger.kernel.org, linux-unionfs@vger.kernel.org, netdev@vger.kernel.org, Jeff Layton X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=967; i=jlayton@kernel.org; h=from:subject:message-id; bh=WHR8repRSXOg/bX4tw/xWusjAXs7tEvWrqZw+/zetag=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBl9HzthWUpDx8ETW9Fi2Al1/RV3U0tsuiy2ls5f mz6cruFq16JAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZfR87QAKCRAADmhBGVaC FRqVD/9y35me6HJkny+mAq1uSbH4iLg1wTF7OEDQUz7izYzLDq4+vCIKz9P7ZA4FrR3CyeaHI4Z FCK2EOqTo+3bdDJFVyKKpc7yAiuZ3VQoN88Je2aTVJv1Abpyip1Koo0Iq5r6CijI8s9UCmSR3wU w7cxBqTBPM2HA04visTag4kLfaNYdwMty7AFZHIo3m8/4dXvMeojFHuorohuWKyLhyJIclJPdk2 mqwUWptrN64t0cpP+qAy8DQdIcxd3kZNsuHasFk392Jw5kJrtu8hRx7/zGwlhR6sFpn+1Z0G5dr UXr9KHoVBdsuhwco4rKKltWANpY/qVwTPc+vOXjdb/LtLFRVqC3AVtbYzJuIrqlxryL/BaOlZFN NBO220wtzimaryQEdVInXs2fjNnKqbeCEWDsBAoz2wufknoFSsKM5dsUbuHtFW6jAHqSf+/koqn TZkALB5y6OggwTItwKY4pIy9/HoNITIt4OPnXmEfwmwA1bIpWXl2NRYV+FrExxCgKRi9nEVsnhp qQIcln7xiClGCxIImqasdwPJKvoR8goLsWdPQypbcwFheoCQ671aPQWnvrXF2nCVv+YwevDCk2N WLP3Fr4KOjLbxtAh72fSENFF59r/I9qb0eewGzsq8bnPaQ3t+HAaeyxUnmHmlX21xIfBNjqX6WN Oq7PC96G/sM9/lQ== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 With the addition of the try_break_lease calls in directory changing operations, allow generic_setlease to hand them out. Note that this also makes directory leases available to userland via fcntl(). I don't see a real reason to prevent userland from acquiring one, but we could reinstate the prohibition if that's preferable. Signed-off-by: Jeff Layton --- fs/locks.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/locks.c b/fs/locks.c index 415cca8e9565..ba6b6f9ea4c7 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -1930,7 +1930,9 @@ static int generic_delete_lease(struct file *filp, void *owner) int generic_setlease(struct file *filp, int arg, struct file_lease **flp, void **priv) { - if (!S_ISREG(file_inode(filp)->i_mode)) + struct inode *inode = file_inode(filp); + + if (!S_ISREG(inode->i_mode) && !S_ISDIR(inode->i_mode)) return -EINVAL; switch (arg) { From patchwork Fri Mar 15 16:53:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13593694 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 2CD475A781; Fri, 15 Mar 2024 16:53:39 +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=1710521619; cv=none; b=eN5jKVqTGS1qWA9N1mfrZJXCzUSUgTSuaEAxYBxpujUVKGysD8HSs4rQ7ckb1EG/z5XNW11Anh2EO09zXeRDlBTcrYeKx3FVV0qGDvZmcELSXVw9+FJ3e30VuzYM8WhuopuObZx+2x9EnamYXzpbvLCt5k4MJwqeBJra8OJPjwY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710521619; c=relaxed/simple; bh=CD3w7e6TBoYw/V9/hui6oM/jYFbSpiUuU+kvpTyfg1Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=s+D/zI29Sbb2zzagHrwVPSlBFfRIyCAu3lfiE7byEPZOfiWhn/20Ib2S1U+OV+DP0Hsvu9NwNEWzkWqqlJA6VeYiKk4YjSr0CKnPWTpQFQtKze2V7dtBtqPaZQG3Xjo286WEVwUuzIYfbWWs9L2iC5POiA25kQVDH9Cuh1q/SuQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dQD40j7o; 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="dQD40j7o" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1999BC433B2; Fri, 15 Mar 2024 16:53:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710521619; bh=CD3w7e6TBoYw/V9/hui6oM/jYFbSpiUuU+kvpTyfg1Q=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=dQD40j7oid4/iuqhNMERS4VZ8nm5mP6XM9EX3RiRv0tBpAQQMkb/yqt8ASKuu4vE6 oV2uEStJ3uDcq3baGTKj+9aprALhb1rt4Hcvlu63fgKEb8MzQL1ueyrzA2xJRSBIsm YbZPNoQb7ox2bqmeCwkN4H0I92beN/3FdL+Umia4DFMAvr+tKSJR3aYHYwdJPz2PBA PpMP6Q2xokY4n6Rw/fKBihtuOQY4+HW0RhLmNkw05g7BGWdW7RqyH/S8exqkBz8UrF Zpa9NWFJsAHxzKRW9gKlj9H1If7ty5wPT1XWM11zpf0opiUAtWtU7U7oCbkfzm8cQm +VQmmq2JbeA/w== From: Jeff Layton Date: Fri, 15 Mar 2024 12:53:01 -0400 Subject: [PATCH RFC 10/24] nfsd: allow filecache to hold S_IFDIR files Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240315-dir-deleg-v1-10-a1d6209a3654@kernel.org> References: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> In-Reply-To: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Chuck Lever , Alexander Aring , Trond Myklebust , Anna Schumaker , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Greg Kroah-Hartman , "Rafael J. Wysocki" , David Howells , Tyler Hicks , Neil Brown , Olga Kornievskaia , Dai Ngo , Miklos Szeredi , Amir Goldstein , Namjae Jeon , Sergey Senozhatsky , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, netfs@lists.linux.dev, ecryptfs@vger.kernel.org, linux-unionfs@vger.kernel.org, netdev@vger.kernel.org, Jeff Layton X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=5740; i=jlayton@kernel.org; h=from:subject:message-id; bh=CD3w7e6TBoYw/V9/hui6oM/jYFbSpiUuU+kvpTyfg1Q=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBl9HztVEGIOXi32wZD0v7/ZrnQr+jTt63ZR0Qxq GOaYid8YHeJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZfR87QAKCRAADmhBGVaC FcAjEACpdhaheJd+4qxrhuIClBQkjkXswazHDJvdD5jbGO4xW+pKfm0kQ/mijipJKWSgpa/jVQd 9CoTxap3ZI+GUmALtkgolvV/Wdp6NN8/N3tf0DgNETc6QGxa6IlhwQ/6HB1HZpBx1FqyUKbdCN7 jdAbAfpNXoaJqD6Rf1Awez2tGS6fFSxPgkhhnUWD50CqXYQ7O4JMrqiOrAhKoO8RFlIa7RHxEIb F/SlaUSAg8k3kMCS/mztNVFAc21L8LoYZExNcNSEgJkA1Py2TrqIAxOjqqYZp8PRcxJg+c1BW2z 4+bVisvcqAxDsGoN59iYxmmeZCW2frrI5rWXWH0zKzsLQ5M53BjCG6iqpSzXaqfyb4mN0mOwNX9 W8iS30S5p1Mg4IWhr986l0VHATmJ000GHDOlg0iDpNVCaqTn4hbYh+uU9qPx2Kg9PbSLnR6mw4R 5gaYwYNzlDdi3FOCoysnIqCwgyuis2ctVx/6SY72an9XGgn/oWGYH6GJI9r2fsC5uTzcULWRP9d PnWhFJotKKf0YxLIFn25k8KOUnva+saIhc4y/gdOvdas45jOJCts0SxbTkymK22OuboycjH+x1G HbHl/pwaSA0ZqUWYn4sdStmSfSahIxUpCNpMyHPGCQhkeiGLxrhzd+4+UkA7eeOI78XrhHymL+5 92N5qHz4Odc34eg== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 The filecache infrastructure will only handle S_ISREG files at the moment. Plumb a "type" variable into nfsd_file_do_acquire and have all of the existing callers set it to S_ISREG. Add a new nfsd_file_acquire_dir() wrapper that we can then call to request a nfsd_file that holds a directory open. Signed-off-by: Jeff Layton --- fs/nfsd/filecache.c | 37 +++++++++++++++++++++++++++++++------ fs/nfsd/filecache.h | 2 ++ fs/nfsd/vfs.c | 5 +++-- fs/nfsd/vfs.h | 2 +- 4 files changed, 37 insertions(+), 9 deletions(-) diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c index ddd3e0d9cfa6..ba66d571d567 100644 --- a/fs/nfsd/filecache.c +++ b/fs/nfsd/filecache.c @@ -979,7 +979,7 @@ nfsd_file_is_cached(struct inode *inode) static __be32 nfsd_file_do_acquire(struct svc_rqst *rqstp, struct svc_fh *fhp, unsigned int may_flags, struct file *file, - struct nfsd_file **pnf, bool want_gc) + umode_t type, bool want_gc, struct nfsd_file **pnf) { unsigned char need = may_flags & NFSD_FILE_MAY_MASK; struct net *net = SVC_NET(rqstp); @@ -991,7 +991,7 @@ nfsd_file_do_acquire(struct svc_rqst *rqstp, struct svc_fh *fhp, int ret; retry: - status = fh_verify(rqstp, fhp, S_IFREG, + status = fh_verify(rqstp, fhp, type, may_flags|NFSD_MAY_OWNER_OVERRIDE); if (status != nfs_ok) return status; @@ -1083,7 +1083,7 @@ nfsd_file_do_acquire(struct svc_rqst *rqstp, struct svc_fh *fhp, trace_nfsd_file_opened(nf, status); } else { ret = nfsd_open_verified(rqstp, fhp, may_flags, - &nf->nf_file); + type, &nf->nf_file); if (ret == -EOPENSTALE && stale_retry) { stale_retry = false; nfsd_file_unhash(nf); @@ -1139,7 +1139,7 @@ __be32 nfsd_file_acquire_gc(struct svc_rqst *rqstp, struct svc_fh *fhp, unsigned int may_flags, struct nfsd_file **pnf) { - return nfsd_file_do_acquire(rqstp, fhp, may_flags, NULL, pnf, true); + return nfsd_file_do_acquire(rqstp, fhp, may_flags, NULL, S_IFREG, true, pnf); } /** @@ -1163,7 +1163,7 @@ __be32 nfsd_file_acquire(struct svc_rqst *rqstp, struct svc_fh *fhp, unsigned int may_flags, struct nfsd_file **pnf) { - return nfsd_file_do_acquire(rqstp, fhp, may_flags, NULL, pnf, false); + return nfsd_file_do_acquire(rqstp, fhp, may_flags, NULL, S_IFREG, false, pnf); } /** @@ -1189,7 +1189,32 @@ nfsd_file_acquire_opened(struct svc_rqst *rqstp, struct svc_fh *fhp, unsigned int may_flags, struct file *file, struct nfsd_file **pnf) { - return nfsd_file_do_acquire(rqstp, fhp, may_flags, file, pnf, false); + return nfsd_file_do_acquire(rqstp, fhp, may_flags, file, S_IFREG, false, pnf); +} + +/** + * nfsd_file_acquire_dir - Get a struct nfsd_file with an open directory + * @rqstp: the RPC transaction being executed + * @fhp: the NFS filehandle of the file to be opened + * @pnf: OUT: new or found "struct nfsd_file" object + * + * The nfsd_file_object returned by this API is reference-counted + * but not garbage-collected. The object is unhashed after the + * final nfsd_file_put(). This opens directories only, and only + * in O_RDONLY mode. + * + * Return values: + * %nfs_ok - @pnf points to an nfsd_file with its reference + * count boosted. + * + * On error, an nfsstat value in network byte order is returned. + */ +__be32 +nfsd_file_acquire_dir(struct svc_rqst *rqstp, struct svc_fh *fhp, + struct nfsd_file **pnf) +{ + return nfsd_file_do_acquire(rqstp, fhp, NFSD_MAY_READ|NFSD_MAY_64BIT_COOKIE, + NULL, S_IFDIR, false, pnf); } /* diff --git a/fs/nfsd/filecache.h b/fs/nfsd/filecache.h index c61884def906..de29a1c9d949 100644 --- a/fs/nfsd/filecache.h +++ b/fs/nfsd/filecache.h @@ -65,5 +65,7 @@ __be32 nfsd_file_acquire(struct svc_rqst *rqstp, struct svc_fh *fhp, __be32 nfsd_file_acquire_opened(struct svc_rqst *rqstp, struct svc_fh *fhp, unsigned int may_flags, struct file *file, struct nfsd_file **nfp); +__be32 nfsd_file_acquire_dir(struct svc_rqst *rqstp, struct svc_fh *fhp, + struct nfsd_file **pnf); int nfsd_file_cache_stats_show(struct seq_file *m, void *v); #endif /* _FS_NFSD_FILECACHE_H */ diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index fe088e7c49c8..a8313bba2a6f 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -950,6 +950,7 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, umode_t type, * nfsd_open_verified - Open a regular file for the filecache * @rqstp: RPC request * @fhp: NFS filehandle of the file to open + * @type: S_IFMT inode type allowed (0 means any type is allowed) * @may_flags: internal permission flags * @filp: OUT: open "struct file *" * @@ -957,9 +958,9 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, umode_t type, */ int nfsd_open_verified(struct svc_rqst *rqstp, struct svc_fh *fhp, int may_flags, - struct file **filp) + umode_t type, struct file **filp) { - return __nfsd_open(rqstp, fhp, S_IFREG, may_flags, filp); + return __nfsd_open(rqstp, fhp, type, may_flags, filp); } /* diff --git a/fs/nfsd/vfs.h b/fs/nfsd/vfs.h index c60fdb6200fd..c7f0349c179e 100644 --- a/fs/nfsd/vfs.h +++ b/fs/nfsd/vfs.h @@ -105,7 +105,7 @@ int nfsd_open_break_lease(struct inode *, int); __be32 nfsd_open(struct svc_rqst *, struct svc_fh *, umode_t, int, struct file **); int nfsd_open_verified(struct svc_rqst *rqstp, struct svc_fh *fhp, - int may_flags, struct file **filp); + int may_flags, umode_t type, struct file **filp); __be32 nfsd_splice_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file, loff_t offset, unsigned long *count, From patchwork Fri Mar 15 16:53:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13593695 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 5E3795B664; Fri, 15 Mar 2024 16:53:42 +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=1710521622; cv=none; b=t18JExnXdcTK8p2L9WIrz1pUOl5e4S4npUd7P+JPd7qOE4rFz5u2eaqj9llLSJVEic7vWtD7+riemB5xsXlOl9OehRQyxAtJoOF7tpMTKSQG07Ex6bWcvlpQUQOBJr+zidMKDfwx8TQq779Gy1upnooOLLB5To6b7TR2BNpnjSc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710521622; c=relaxed/simple; bh=OiEZefexIM68VHJefg6W7dC1hIlEpf01M9ECnJ7jCAM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hHD+e9sApbpAVPIn7s+RxTE5y/S4o3WkjoRhPY8ERd2iYE0Nc6RYft4rUv8G53NqCXGBV5j5N0/Yf4R0Te3atzmjtPKnWUE3J8Hi/jHktVhlJxiwAsaySyARSbnnByjjhfwLe710wYxgRUkKDoynmCMyVP29m8PIk2bJlQN7vtw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JUnW5RJd; 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="JUnW5RJd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4A3FEC43601; Fri, 15 Mar 2024 16:53:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710521622; bh=OiEZefexIM68VHJefg6W7dC1hIlEpf01M9ECnJ7jCAM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=JUnW5RJd+BgZBkpS/H86jl0Iis4Orkp4l5LoP/m44lmU/zoqYFK5iOf+zPcpWW2DP EHmnGAFj+9oxTTUV+hUeZW+YeyDFSYBtFh1jFrsp3IVHtp/GFREBwMIGelt7jLzcsc 11UP6HuKVCcCGMBf74lxFJ+ryCvvwEt24SHE+O0PS7O8zTzrHxWUEh8EABSIjnidBE UdhK5rdamea0Lc/ScOKeaFrBJvU+0Bipb3nX+7uNZHgFzAzR4DT1Uy/hBkDa7GM9WV GesOK9Vmx11/M/YvQGi9FQOhQfA3ZGT74ighkkvs107Xq8hSSzpRLGomrkjVnzCElr 44X3ZAU62Iscg== From: Jeff Layton Date: Fri, 15 Mar 2024 12:53:02 -0400 Subject: [PATCH RFC 11/24] nfsd: allow DELEGRETURN on directories Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240315-dir-deleg-v1-11-a1d6209a3654@kernel.org> References: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> In-Reply-To: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Chuck Lever , Alexander Aring , Trond Myklebust , Anna Schumaker , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Greg Kroah-Hartman , "Rafael J. Wysocki" , David Howells , Tyler Hicks , Neil Brown , Olga Kornievskaia , Dai Ngo , Miklos Szeredi , Amir Goldstein , Namjae Jeon , Sergey Senozhatsky , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, netfs@lists.linux.dev, ecryptfs@vger.kernel.org, linux-unionfs@vger.kernel.org, netdev@vger.kernel.org, Jeff Layton X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1334; i=jlayton@kernel.org; h=from:subject:message-id; bh=OiEZefexIM68VHJefg6W7dC1hIlEpf01M9ECnJ7jCAM=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBl9HzusMS1CmGt3vVgFg6eaeQpLE4HDnWTQ53Hm +kXZ6P2QvOJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZfR87gAKCRAADmhBGVaC FZyfD/9hH9KoMcs5bPmR43gVXALqNXpGQKiLRBR1clk3cQsQO71gxXwRFQA1sIlvrvzw6IL6X/K eAN+ucfon4aVD2fvfQMmAzL9VHPiMXJSIIoouZwcPp9mudKmtf3BWBMNsY2FmvxkdVW4MbxfUP9 ERB4QWjAsgQVWv6SUcQhjjoZ0MVZiG3yvuH//TVNLH16xPrzxFp40siRB/utynoxxWMMxtnPpBW Gz76hsrBQhUDoSx6s9NIv6BHV3eO/3XFBmuNSu5qFSiN19o3VR5fJFvM3pjhbXS2O2d1Sem2Omh n01ucuOAs7hV5rgrht5FhrnQqVDlo761Cay8wAWeVCpEXrGP7IsP1efVJlJkhpeRWGYnuQ9YRLY O/DH3NPIeqWWohCiLBBxYTipIR2+gdA5F9QVXK0xr+JpzfbBj+cCxuKDK8QtNOiS0FnJ8L2yWLc McVABjaXpVmiA0StQufkkX2d49h+pLQugA9XMVJ51fVR/SmrU7eFfq6vnaP7qJoObC1MQ5/+YX8 udTuhAaxuRPxMMFfhVIuH4eCcC49+ZTY1o0grohOjsq2SnvSJ2xpfgpKnflZrdswNYSQ+kU7miV R0dEJWMNloeZlU7dvof3AQCs95xEGIKDSKtOtMyZRydk09Tq2jv0neVSM6lOiGmmePst7q6ZnCs WPDTujwK2c2XFig== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 fh_verify only allows you to filter on a single type of inode, so have nfsd4_delegreturn not filter by type. Once fh_verify returns, do the appropriate check of the type and return an error if it's not a regular file or directory. Signed-off-by: Jeff Layton --- fs/nfsd/nfs4state.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 17d09d72632b..c52e807f9672 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -7425,12 +7425,24 @@ nfsd4_delegreturn(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfs4_delegation *dp; stateid_t *stateid = &dr->dr_stateid; struct nfs4_stid *s; + umode_t mode; __be32 status; struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); - if ((status = fh_verify(rqstp, &cstate->current_fh, S_IFREG, 0))) + if ((status = fh_verify(rqstp, &cstate->current_fh, 0, 0))) return status; + mode = d_inode(cstate->current_fh.fh_dentry)->i_mode & S_IFMT; + switch(mode) { + case S_IFREG: + case S_IFDIR: + break; + case S_IFLNK: + return nfserr_symlink; + default: + return nfserr_inval; + } + status = nfsd4_lookup_stateid(cstate, stateid, SC_TYPE_DELEG, 0, &s, nn); if (status) goto out; From patchwork Fri Mar 15 16:53:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13593696 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 96E1A5BAE0; Fri, 15 Mar 2024 16:53:45 +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=1710521625; cv=none; b=IRa15Go2Lyn627zMuLFUxNfUUitWMLLwS1a4m3V0QUTcpkRTd0hHR3OT/8bGJvp41tptFSCnPhJDxrj2hOi4Nlym4sODRFDbj9giy7eUnMIQVOfbS2JPOHfPkQerveu1Msdgr6c2EfNnXQ7hUGQftEcde6N+NuoRww+DBanNS4E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710521625; c=relaxed/simple; bh=eWqiPxkORa/jrz1Vpk1ANB4N2FUMiPwwSkg+tEGN67g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BR2L+8ROlufyekzV038NuZZ9B7hyGqwrSYDaawH7jCy/WUspbRKaxc6j8OusjyMjvy4tJs9e3JmOFZWpn92nAMwsn8qF/M3Ei6PzARz8xWp5mQDpvSyb8aXF+CO7hN0vCceDCGeuwGb4nWdgu2Hk6262mEkRCyIV7V2EIC+Mmdc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DaLjsm6W; 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="DaLjsm6W" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7BCD3C433C7; Fri, 15 Mar 2024 16:53:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710521625; bh=eWqiPxkORa/jrz1Vpk1ANB4N2FUMiPwwSkg+tEGN67g=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=DaLjsm6W/cWSlQSAQt35MPc9Zvw094Gl7MELDI4FTPVOOpT1fKMt5DsBli3Ipej0R 1dVgCEofeJInRk29a2Ta9N82rgQf07sr0VssqYuZn+2WAiJD//WcbzJw9lQl08aCSU tIsjbdFLmAygkGv6f0+87SH3lgLX+u1HqnuEj1BUKtnKmBcvb1OGVC2iQ8I9yIYtkR C5Z89987p1Prp6NMZ3UhUywjt7nVEtPVsEVJRhWrhxJXCmaiIosLpq5fjRjdogHh0X jjWdeB6Q0T7vIdkUKJabaAxKEed4005kwO/w03pv6KzqsbeQNwEEWJmGNqiz0xM3yP sYZD2V24y06Tg== From: Jeff Layton Date: Fri, 15 Mar 2024 12:53:03 -0400 Subject: [PATCH RFC 12/24] nfsd: encoders and decoders for GET_DIR_DELEGATION Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240315-dir-deleg-v1-12-a1d6209a3654@kernel.org> References: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> In-Reply-To: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Chuck Lever , Alexander Aring , Trond Myklebust , Anna Schumaker , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Greg Kroah-Hartman , "Rafael J. Wysocki" , David Howells , Tyler Hicks , Neil Brown , Olga Kornievskaia , Dai Ngo , Miklos Szeredi , Amir Goldstein , Namjae Jeon , Sergey Senozhatsky , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, netfs@lists.linux.dev, ecryptfs@vger.kernel.org, linux-unionfs@vger.kernel.org, netdev@vger.kernel.org, Jeff Layton X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=7250; i=jlayton@kernel.org; h=from:subject:message-id; bh=eWqiPxkORa/jrz1Vpk1ANB4N2FUMiPwwSkg+tEGN67g=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBl9Hzux84pP1BToC0cXEcy2JAB+wMmRTWbjNYm5 XHEP5hDfFWJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZfR87gAKCRAADmhBGVaC FRmxD/0Ufx0/2UuQ6C25+vBZuUnPRr9VhDlbCwMDlCy9cXI8txz2UVOoYZLmjGCYg1SZLLi50u7 lm90hF04X/7njqEQcfyguWVWxeGtclJpzpxln1YOdrbLAbGxaCItoyAKylyIlDlIn6noZGMssuW 5Br5yitk0S2CXTkjJaaSGaeEXIWMS2ao4ms1Iymowan9+9mo+wXMWB/OxOycWkB9Mct2eJhKGfT XkAHS+zWYRhEQ3vlyalw/q2h0rbPTomMLThTscs/J7UjpQF93VmdQiftcNLGK8JmzGcnoKZvgTj yNS8f9YrDheyDGGETOjEZjjt9VmO2onTb6oaiJegojkRbH6xQlUrd/tfhrbcHZoZhand2hiy09p Moz6+2Xcxl0B+GLAqT0MvA8B7shcD3OCYa1mbd9wjxdhh9x+GMO3hO24LNa5o9iBSjAZfuibTsU yDNTfMayUPx6saiZUrIeqwBJPrxBPeTHauxmuiYKNOVeVgDP4NUcv85C5P6MxeN+5ZBKqHDDO3g kjp3S4fjyIN/9oHw3lUkrI13rLLcwuMPOwJh9w7+/9n1yzNUotX2MJ+35SsObSUDCjMWlpFtzeU 1C1xCzQmSjuarhFsLWbSHVYR31rWwePTrhUbdtzsyYpwOuxYSGDGo6xcidIZAmQcHmYv0YDMqxL sqNrVxjUU5D2fFg== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 This adds basic infrastructure for handing GET_DIR_DELEGATION calls from clients, including the decoders and encoders. For now, the server side always just returns that the delegation is GDDR_UNAVAIL (and that we won't call back). Signed-off-by: Jeff Layton --- fs/nfsd/nfs4proc.c | 30 ++++++++++++++++++++++ fs/nfsd/nfs4xdr.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++-- fs/nfsd/xdr4.h | 8 ++++++ include/linux/nfs4.h | 5 ++++ 4 files changed, 113 insertions(+), 2 deletions(-) diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index 2927b1263f08..7973fe17bf3c 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -2173,6 +2173,18 @@ nfsd4_layout_verify(struct svc_export *exp, unsigned int layout_type) return nfsd4_layout_ops[layout_type]; } +static __be32 +nfsd4_get_dir_delegation(struct svc_rqst *rqstp, + struct nfsd4_compound_state *cstate, + union nfsd4_op_u *u) +{ + struct nfsd4_get_dir_delegation *gdd = &u->get_dir_delegation; + + /* FIXME: actually return a delegation */ + gdd->nf_status = GDD4_UNAVAIL; + return nfs_ok; +} + static __be32 nfsd4_getdeviceinfo(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, union nfsd4_op_u *u) @@ -3082,6 +3094,18 @@ static u32 nfsd4_copy_notify_rsize(const struct svc_rqst *rqstp, * sizeof(__be32); } +static u32 nfsd4_get_dir_delegation_rsize(const struct svc_rqst *rqstp, + const struct nfsd4_op *op) +{ + return (op_encode_hdr_size + + 1 /* gddr_status */ + + op_encode_verifier_maxsz + + op_encode_stateid_maxsz + + 2 /* gddr_notification */ + + 2 /* gddr_child_attributes */ + + 2 /* gddr_dir_attributes */); +} + #ifdef CONFIG_NFSD_PNFS static u32 nfsd4_getdeviceinfo_rsize(const struct svc_rqst *rqstp, const struct nfsd4_op *op) @@ -3470,6 +3494,12 @@ static const struct nfsd4_operation nfsd4_ops[] = { .op_get_currentstateid = nfsd4_get_freestateid, .op_rsize_bop = nfsd4_only_status_rsize, }, + [OP_GET_DIR_DELEGATION] = { + .op_func = nfsd4_get_dir_delegation, + .op_flags = OP_MODIFIES_SOMETHING, + .op_name = "OP_GET_DIR_DELEGATION", + .op_rsize_bop = nfsd4_get_dir_delegation_rsize, + }, #ifdef CONFIG_NFSD_PNFS [OP_GETDEVICEINFO] = { .op_func = nfsd4_getdeviceinfo, diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index fac938f563ad..3718bef74e9f 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -1732,6 +1732,40 @@ nfsd4_decode_free_stateid(struct nfsd4_compoundargs *argp, return nfsd4_decode_stateid4(argp, &free_stateid->fr_stateid); } +static __be32 +nfsd4_decode_get_dir_delegation(struct nfsd4_compoundargs *argp, + union nfsd4_op_u *u) +{ + struct nfsd4_get_dir_delegation *gdd = &u->get_dir_delegation; + struct timespec64 ts; + u32 signal_deleg_avail; + u32 attrs[1]; + __be32 status; + + memset(gdd, 0, sizeof(*gdd)); + + /* No signal_avail support for now (and maybe never) */ + if (xdr_stream_decode_bool(argp->xdr, &signal_deleg_avail) < 0) + return nfserr_bad_xdr; + status = nfsd4_decode_bitmap4(argp, gdd->notification_types, + ARRAY_SIZE(gdd->notification_types)); + if (status) + return status; + + /* For now, we don't support child or dir attr change notification */ + status = nfsd4_decode_nfstime4(argp, &ts); + if (status) + return status; + /* No dir attr notification support yet either */ + status = nfsd4_decode_nfstime4(argp, &ts); + if (status) + return status; + status = nfsd4_decode_bitmap4(argp, attrs, ARRAY_SIZE(attrs)); + if (status) + return status; + return nfsd4_decode_bitmap4(argp, attrs, ARRAY_SIZE(attrs)); +} + #ifdef CONFIG_NFSD_PNFS static __be32 nfsd4_decode_getdeviceinfo(struct nfsd4_compoundargs *argp, @@ -2370,7 +2404,7 @@ static const nfsd4_dec nfsd4_dec_ops[] = { [OP_CREATE_SESSION] = nfsd4_decode_create_session, [OP_DESTROY_SESSION] = nfsd4_decode_destroy_session, [OP_FREE_STATEID] = nfsd4_decode_free_stateid, - [OP_GET_DIR_DELEGATION] = nfsd4_decode_notsupp, + [OP_GET_DIR_DELEGATION] = nfsd4_decode_get_dir_delegation, #ifdef CONFIG_NFSD_PNFS [OP_GETDEVICEINFO] = nfsd4_decode_getdeviceinfo, [OP_GETDEVICELIST] = nfsd4_decode_notsupp, @@ -5002,6 +5036,40 @@ nfsd4_encode_device_addr4(struct xdr_stream *xdr, return nfserr_toosmall; } +static __be32 +nfsd4_encode_get_dir_delegation(struct nfsd4_compoundres *resp, __be32 nfserr, + union nfsd4_op_u *u) +{ + struct xdr_stream *xdr = resp->xdr; + struct nfsd4_get_dir_delegation *gdd = &u->get_dir_delegation; + + /* Encode the GDDR_* status code */ + if (xdr_stream_encode_u32(xdr, gdd->nf_status) != XDR_UNIT) + return nfserr_resource; + + /* if it's GDD4_UNAVAIL then we're (almost) done */ + if (gdd->nf_status == GDD4_UNAVAIL) { + /* We never call back */ + return nfsd4_encode_bool(xdr, false); + } + + /* GDD4_OK case */ + nfserr = nfsd4_encode_verifier4(xdr, &gdd->cookieverf); + if (nfserr) + return nfserr; + nfserr = nfsd4_encode_stateid4(xdr, &gdd->stateid); + if (nfserr) + return nfserr; + /* No notifications (yet) */ + nfserr = nfsd4_encode_bitmap4(xdr, 0, 0, 0); + if (nfserr) + return nfserr; + nfserr = nfsd4_encode_bitmap4(xdr, 0, 0, 0); + if (nfserr) + return nfserr; + return nfsd4_encode_bitmap4(xdr, 0, 0, 0); +} + static __be32 nfsd4_encode_getdeviceinfo(struct nfsd4_compoundres *resp, __be32 nfserr, union nfsd4_op_u *u) @@ -5580,7 +5648,7 @@ static const nfsd4_enc nfsd4_enc_ops[] = { [OP_CREATE_SESSION] = nfsd4_encode_create_session, [OP_DESTROY_SESSION] = nfsd4_encode_noop, [OP_FREE_STATEID] = nfsd4_encode_noop, - [OP_GET_DIR_DELEGATION] = nfsd4_encode_noop, + [OP_GET_DIR_DELEGATION] = nfsd4_encode_get_dir_delegation, #ifdef CONFIG_NFSD_PNFS [OP_GETDEVICEINFO] = nfsd4_encode_getdeviceinfo, [OP_GETDEVICELIST] = nfsd4_encode_noop, diff --git a/fs/nfsd/xdr4.h b/fs/nfsd/xdr4.h index 415516c1b27e..27de75f32dea 100644 --- a/fs/nfsd/xdr4.h +++ b/fs/nfsd/xdr4.h @@ -518,6 +518,13 @@ struct nfsd4_free_stateid { stateid_t fr_stateid; /* request */ }; +struct nfsd4_get_dir_delegation { + u32 notification_types[1]; /* request */ + u32 nf_status; /* response */ + nfs4_verifier cookieverf; /* response */ + stateid_t stateid; /* response */ +}; + /* also used for NVERIFY */ struct nfsd4_verify { u32 ve_bmval[3]; /* request */ @@ -797,6 +804,7 @@ struct nfsd4_op { struct nfsd4_reclaim_complete reclaim_complete; struct nfsd4_test_stateid test_stateid; struct nfsd4_free_stateid free_stateid; + struct nfsd4_get_dir_delegation get_dir_delegation; struct nfsd4_getdeviceinfo getdeviceinfo; struct nfsd4_layoutget layoutget; struct nfsd4_layoutcommit layoutcommit; diff --git a/include/linux/nfs4.h b/include/linux/nfs4.h index ef8d2d618d5b..11ad088b411d 100644 --- a/include/linux/nfs4.h +++ b/include/linux/nfs4.h @@ -701,6 +701,11 @@ enum state_protect_how4 { SP4_SSV = 2 }; +enum get_dir_delegation_non_fatal_res { + GDD4_OK = 0, + GDD4_UNAVAIL = 1 +}; + enum pnfs_layouttype { LAYOUT_NFSV4_1_FILES = 1, LAYOUT_OSD2_OBJECTS = 2, From patchwork Fri Mar 15 16:53:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13593697 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 C036B5C5FA; Fri, 15 Mar 2024 16:53: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=1710521628; cv=none; b=pSOXeylz3F/ml+QLXo/AQbYeu6TnahU1mOq6hN6ejboRNF+I0rpc0GS+kyHJF/4p5p63Cfmhv/EHhqQh9XrcSMz7atVZIkS+FRw9F8OChWL6XXfcjfPrM+Wpfche9jW/kJu1MDmuCjYUn7VDSlfXh0Q7fubuTXX1l9wEKDbmz5I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710521628; c=relaxed/simple; bh=ljfAQPv8SeghXncJudqqzHNlIKkPlPHDHVqidwfmElY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aFTei/07zszNDXX/2uA8/9EoLlhTLoAzk9M76EZKL69SbOqJRXaEN+dxc/dRKuKyJkO83MLSqAvUVgBU06NXNEGNnB2ViaGK3KA73a+c2y3d/4bA885vZT5CAuRjA2RVPyYPVGvo6Jk/PU/dJz+oo1Ppps9mRFxYMB2QXm1lGfw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=L5OVqFXM; 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="L5OVqFXM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE1D3C43601; Fri, 15 Mar 2024 16:53:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710521628; bh=ljfAQPv8SeghXncJudqqzHNlIKkPlPHDHVqidwfmElY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=L5OVqFXMG3yzOuJfCE3MrXJQ+Mf1tkLr7lCvot4eRiRHsH7ZpVLRjuL9QGV6ZI7cg mIjwvBTcY9/Cyk2wshFhjwGgFvWSd2hPtiEgGc0Vbug/YmaiY+oqmY9tWN3oZNnETY LxTEwkJvxl95xaXQpYvvhUn6ikNacD1y2a+18MUObH1TLh+lhIbp0E8GLisBjHN1Tv NEtO3ThsBCc4y/rtGaKCuPKNTMHcDRM8ccp8G0nggVB4d95cENDC0cZhvNqHnbvoBX K0JzYY1ujVM38K+nosFbuhRtDFucDJqnI9jPY9ScwIt7moGd6jvmGT9698cdSzubSU Gy6m3N//1dcpw== From: Jeff Layton Date: Fri, 15 Mar 2024 12:53:04 -0400 Subject: [PATCH RFC 13/24] nfsd: check for delegation conflicts vs. the same client Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240315-dir-deleg-v1-13-a1d6209a3654@kernel.org> References: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> In-Reply-To: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Chuck Lever , Alexander Aring , Trond Myklebust , Anna Schumaker , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Greg Kroah-Hartman , "Rafael J. Wysocki" , David Howells , Tyler Hicks , Neil Brown , Olga Kornievskaia , Dai Ngo , Miklos Szeredi , Amir Goldstein , Namjae Jeon , Sergey Senozhatsky , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, netfs@lists.linux.dev, ecryptfs@vger.kernel.org, linux-unionfs@vger.kernel.org, netdev@vger.kernel.org, Jeff Layton X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=2577; i=jlayton@kernel.org; h=from:subject:message-id; bh=ljfAQPv8SeghXncJudqqzHNlIKkPlPHDHVqidwfmElY=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBl9HzuZG1C9GcHSunh24sr9Db67Qw+SIGDz0sjv OWi/9rr9/iJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZfR87gAKCRAADmhBGVaC FXTJD/9h2vD0EFl2BzLQ11an322nL8117C5bpnqClsrmJl4Co0TnaVOG3vyTMAwK8por1WAasN6 k+/1POyLZn1bTc3w5Byzzs88DNhDufzBiPwzCkW6gKjXeP9oVfa/n1IKvfX7Qz3t0wmnW0r2RZk HOUT30c/9BbcXqAKzvQpKZeSuX3dhVdDnAjKkVP0FdYW1eFrKdxfwN6Y8j1NtrS7FF9UIBc4Ut+ csrRXoz2zY25GyTNYKA1lMxLsQHIBXUqmuPNH5FnvTji/saxVFG95ExoKLoglL1mzGmXTLefHig LU+IbRvgKm1v3rdwBJsFhazvJRL9ww3P1y0+nfZ6BxzZdRSjlTIoJQ/VkxcHk3Dvmt4gZr1DHLp WHUU6EH69V9V9p/kBYTBck8w9RfeaLZha+6KiYsRa+OjBDpvYv3MX7Fdj7Jtp7DAs9NSxGjhHzl TnU6Rz5CJYrfxoQcO9GnOSlp+ygAbKmTwkXwzyCYH4TtszXO3/42S0R9Ig9EK/3ORlh9efM+K9j jxIjwDLYlbguoNwyc0WxwJr0TEmzL3z3IR29gs6ag9WEjr3wFpQSDPtoNTFqdyZBAYu5aCMnsGW t/boh7DvKk63x1DAkDq+ibjEyFMUr6jAe+sF2CTZ0iJFaAXCqr11RzrjWeNGWpThMUo5vZN1wTF ag5O22Ysl6sEYdQ== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 RFC 8881 requires that the server reply with GDD_UNAVAIL when the client requests a directory delegation that it already holds. When setting a directory delegation, check that the client assocated with the stateid doesn't match an existing delegation. If it does, reject the setlease attempt. Signed-off-by: Jeff Layton --- fs/nfsd/nfs4state.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index c52e807f9672..778c1c6e3b54 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -88,6 +88,7 @@ void nfsd4_end_grace(struct nfsd_net *nn); static void _free_cpntf_state_locked(struct nfsd_net *nn, struct nfs4_cpntf_state *cps); static void nfsd4_file_hash_remove(struct nfs4_file *fi); static void deleg_reaper(struct nfsd_net *nn); +static bool nfsd_dir_deleg_conflict(struct file_lease *new, struct file_lease *old); /* Locking: */ @@ -5262,6 +5263,31 @@ static const struct lease_manager_operations nfsd_lease_mng_ops = { .lm_change = nfsd_change_deleg_cb, }; +static const struct lease_manager_operations nfsd_dir_lease_mng_ops = { + .lm_breaker_owns_lease = nfsd_breaker_owns_lease, + .lm_break = nfsd_break_deleg_cb, + .lm_change = nfsd_change_deleg_cb, + .lm_set_conflict = nfsd_dir_deleg_conflict, +}; + +static bool +nfsd_dir_deleg_conflict(struct file_lease *new, struct file_lease *old) +{ + struct nfs4_delegation *od, *nd; + + /* Only conflicts with other nfsd dir delegs */ + if (old->fl_lmops != &nfsd_dir_lease_mng_ops) + return false; + + od = old->c.flc_owner; + nd = new->c.flc_owner; + + /* Are these for the same client? No bueno if so */ + if (od->dl_stid.sc_client == nd->dl_stid.sc_client) + return true; + return false; +} + static __be32 nfsd4_check_seqid(struct nfsd4_compound_state *cstate, struct nfs4_stateowner *so, u32 seqid) { if (nfsd4_has_session(cstate)) @@ -5609,12 +5635,13 @@ static struct file_lease *nfs4_alloc_init_lease(struct nfs4_delegation *dp, fl = locks_alloc_lease(); if (!fl) return NULL; - fl->fl_lmops = &nfsd_lease_mng_ops; fl->c.flc_flags = FL_DELEG; fl->c.flc_type = flag == NFS4_OPEN_DELEGATE_READ? F_RDLCK: F_WRLCK; fl->c.flc_owner = (fl_owner_t)dp; fl->c.flc_pid = current->tgid; fl->c.flc_file = dp->dl_stid.sc_file->fi_deleg_file->nf_file; + fl->fl_lmops = S_ISDIR(file_inode(fl->c.flc_file)->i_mode) ? + &nfsd_dir_lease_mng_ops : &nfsd_lease_mng_ops; return fl; } From patchwork Fri Mar 15 16:53:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13593698 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 F1AAA5C915; Fri, 15 Mar 2024 16:53:51 +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=1710521632; cv=none; b=SRhE03AmPwqc9U6OPyTvZ27pEUnFQhIUBLqizULbwo5dDR7179tlqsY6qv3quzQGp9lg9nmpcArCpoxeDPZVjD8qGFoGyHyH5K/kuqbS9gbFmUwoGNqmwNVcuLfxWoAYtQhJAdIxvEkcX0nERMzSxrMylOpYwsVXQeCqfnTjUwk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710521632; c=relaxed/simple; bh=E3Rg3kkD+gy8X3aCYOuF+O+8BvFkDxP+5wAmPwAh5m0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tfPcMAb0UZ26dX9YbReNqvsEVvQZlD2CuJt4q0iQG/bX/BTzOhJFQ689rCEZeGr2Y7eyNluh6bFcRVKE3AC4WTjpLqCgMMHgCkdK9ThrSoUiWzR3HMuOBiVqca9HQxSXAmKFShJ4mQAxTMRBcp3zjsprb9InT8wIT89y1WeoPgk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Wb+Qc0GX; 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="Wb+Qc0GX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DEB99C433B2; Fri, 15 Mar 2024 16:53:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710521631; bh=E3Rg3kkD+gy8X3aCYOuF+O+8BvFkDxP+5wAmPwAh5m0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Wb+Qc0GXVF7eeAiW+XKy9AlNdqMfznl8Erywiln6xVKUveWp7DHTWR8N4bRH2hN7p DY1AzJudXZV5DoG5S3GUsGHEXj4Y2TlBSYqkvVtW7St0VrMIBWxpR7DD7FfgklOmbG +S8c31NjUoVOhxjxD+hJ659/eqLloGuUEqt7UDDdSqlji0yWpJLVzSfCvwP/v5Hni5 t/TuD+hL9QpTMDwo+eVSvJ/QPWPw1YdshOg3gTRDXbYQLffp5QBaSExcZcNynbLvdn llYD0SbHZ3xYfzyB86BsPO6yN0kL+XnJEEr/OyJ5GiF/3HDWexqo4P/G6F2OfjCAuO DCKg3OFRQqtiQ== From: Jeff Layton Date: Fri, 15 Mar 2024 12:53:05 -0400 Subject: [PATCH RFC 14/24] nfsd: wire up GET_DIR_DELEGATION handling Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240315-dir-deleg-v1-14-a1d6209a3654@kernel.org> References: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> In-Reply-To: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Chuck Lever , Alexander Aring , Trond Myklebust , Anna Schumaker , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Greg Kroah-Hartman , "Rafael J. Wysocki" , David Howells , Tyler Hicks , Neil Brown , Olga Kornievskaia , Dai Ngo , Miklos Szeredi , Amir Goldstein , Namjae Jeon , Sergey Senozhatsky , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, netfs@lists.linux.dev, ecryptfs@vger.kernel.org, linux-unionfs@vger.kernel.org, netdev@vger.kernel.org, Jeff Layton X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=4280; i=jlayton@kernel.org; h=from:subject:message-id; bh=E3Rg3kkD+gy8X3aCYOuF+O+8BvFkDxP+5wAmPwAh5m0=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBl9Hzu4JN3etDmC5GP88NjXXGCimqbuhBMctpmW a/PlYZk/9+JAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZfR87gAKCRAADmhBGVaC FYJGD/4sn1x3g06/fMwln0LglXhz+4hJ9Bu4hx1uvW3du3FRFkKsGBFWg2NzpMmcUWNti1x8MgQ YVfYP3Ewh2aWAahDrQvRnbJ5R0esrxyqsGHHmPKLmIKNw0mn/6kS/cZzKa9kLx8kBwPaYS5yje2 t/3vTIKXj3B5ktY+2Lb5v5yuyxmAchDQaw3dvtRRV4cTh4nM7VqjTOMUtaR/9TTzsHosB0V2sJo 2uNy1mWyvpd5/mc23wMhFZtNCUVM8AbAiXbzWAHZz6HmWncsBJNHsAUhnOk4pE8jqNhqFzXxdjb tvSLeLxNSEgpEkSPLFkfYawn7LLCWYBTtMST8cK6AMbBJDgLhmZZ/FY881vGWXhfWceg7xXZC2M BPHDpz6u64ISPl6R19Kzgjf0CILwSwZuljdm+aU9v3c9tX/J75sOOUFvteCHTK7vHjWUWQs1nmg WqosuPrKt7cJGx9G+SHArcIPSYw58Q+xPVOre8oSYuojtVjNJkS7jfpCKVKI90vjGkx0dwkq2cm qB8Clgab166AYivaYzaniYr+B0riJuJezZ7J1q+n2LATX40ogD2MAGULw6FxzIpZAyc6sLJdfpF RBhFbi7Iv5sqEFTPhMDx86jeMzVtyV67ThY+FFt//dVTZE2+P+PN2iuMbzIoBUMSXKDiIEJlPQ0 22I4esVSA1gdzKw== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 Add a new routine for acquiring a read delegation on a directory. Since the same CB_RECALL/DELEGRETURN infrastrure is used for regular and directory delegations, we can just use a normal nfs4_delegation to represent it. Signed-off-by: Jeff Layton --- fs/nfsd/nfs4proc.c | 23 ++++++++++++++++-- fs/nfsd/nfs4state.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++- fs/nfsd/state.h | 5 ++++ 3 files changed, 94 insertions(+), 3 deletions(-) diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index 7973fe17bf3c..1a2c90f4ea53 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -2179,9 +2179,28 @@ nfsd4_get_dir_delegation(struct svc_rqst *rqstp, union nfsd4_op_u *u) { struct nfsd4_get_dir_delegation *gdd = &u->get_dir_delegation; + struct nfs4_delegation *dd; + struct nfsd_file *nf; + __be32 status; + + status = nfsd_file_acquire_dir(rqstp, &cstate->current_fh, &nf); + if (status != nfs_ok) + return status; + + dd = nfsd_get_dir_deleg(cstate, gdd, nf); + if (IS_ERR(dd)) { + int err = PTR_ERR(dd); + + if (err != -EAGAIN) + return nfserrno(err); + gdd->nf_status = GDD4_UNAVAIL; + return nfs_ok; + } - /* FIXME: actually return a delegation */ - gdd->nf_status = GDD4_UNAVAIL; + gdd->nf_status = GDD4_OK; + memcpy(&gdd->stateid, &dd->dl_stid.sc_stateid, sizeof(gdd->stateid)); + memset(&gdd->cookieverf, '\0', sizeof(gdd->cookieverf)); + nfs4_put_stid(&dd->dl_stid); return nfs_ok; } diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 778c1c6e3b54..36574aedc211 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -8874,7 +8874,7 @@ nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, struct inode *inode, } break_lease: nfsd_stats_wdeleg_getattr_inc(nn); - dp = fl->fl_owner; + dp = fl->c.flc_owner; ncf = &dp->dl_cb_fattr; nfs4_cb_getattr(&dp->dl_cb_fattr); spin_unlock(&ctx->flc_lock); @@ -8912,3 +8912,70 @@ nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, struct inode *inode, spin_unlock(&ctx->flc_lock); return 0; } + +struct nfs4_delegation * +nfsd_get_dir_deleg(struct nfsd4_compound_state *cstate, + struct nfsd4_get_dir_delegation *gdd, + struct nfsd_file *nf) +{ + struct nfs4_client *clp = cstate->clp; + struct nfs4_delegation *dp; + struct file_lease *fl; + struct nfs4_file *fp; + int status = 0; + + fp = nfsd4_alloc_file(); + if (!fp) + return ERR_PTR(-ENOMEM); + + nfsd4_file_init(&cstate->current_fh, fp); + fp->fi_deleg_file = nf; + fp->fi_delegees = 1; + + spin_lock(&state_lock); + spin_lock(&fp->fi_lock); + if (nfs4_delegation_exists(clp, fp)) + status = -EAGAIN; + spin_unlock(&fp->fi_lock); + spin_unlock(&state_lock); + + if (status) + goto out_delegees; + + status = -ENOMEM; + dp = alloc_init_deleg(clp, fp, NULL, NFS4_OPEN_DELEGATE_READ); + if (!dp) + goto out_delegees; + + fl = nfs4_alloc_init_lease(dp, NFS4_OPEN_DELEGATE_READ); + if (!fl) + goto out_put_stid; + + status = kernel_setlease(nf->nf_file, + fl->c.flc_type, &fl, NULL); + if (fl) + locks_free_lease(fl); + if (status) + goto out_put_stid; + + spin_lock(&state_lock); + spin_lock(&clp->cl_lock); + spin_lock(&fp->fi_lock); + status = hash_delegation_locked(dp, fp); + spin_unlock(&fp->fi_lock); + spin_unlock(&clp->cl_lock); + spin_unlock(&state_lock); + + if (status) + goto out_unlock; + + return dp; +out_unlock: + kernel_setlease(fp->fi_deleg_file->nf_file, F_UNLCK, NULL, (void **)&dp); +out_put_stid: + nfs4_put_stid(&dp->dl_stid); +out_delegees: + put_deleg_file(fp); + return ERR_PTR(status); +} + diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h index 01c6f3445646..20551483cc7b 100644 --- a/fs/nfsd/state.h +++ b/fs/nfsd/state.h @@ -782,4 +782,9 @@ static inline bool try_to_expire_client(struct nfs4_client *clp) extern __be32 nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, struct inode *inode, bool *file_modified, u64 *size); + +struct nfsd4_get_dir_delegation; +struct nfs4_delegation *nfsd_get_dir_deleg(struct nfsd4_compound_state *cstate, + struct nfsd4_get_dir_delegation *gdd, + struct nfsd_file *nf); #endif /* NFSD4_STATE_H */ From patchwork Fri Mar 15 16:53:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13593699 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 2A99E5D463; Fri, 15 Mar 2024 16:53:55 +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=1710521635; cv=none; b=ZYFCDR2dzusmrqKJL7rYMYKvKr1efm8EbjB+4fB/+R1vAiX/Nc0jNQBWXH4zn5/v2LXocKx+KAOUKSiB+a9g2ass7l6HiKshCQ8Tvz+suRg5r5G45RaSXDpItU+5vIQLY61FH8VexS0VoYWJNMMWGfbfGUQWVPuqb9MHQpSD3HU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710521635; c=relaxed/simple; bh=Unfgd+Xo7evIfZLg6ZS/YCO4C8AeO+s1DYe1G/oc9jk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SrXcHophNhW1jJo52Ln4wApssohyTXKVWlZQmDh7OF4sX4TtQsDB9m31deP1vXSB2blU7iNySomv5TnDxJVAd3LVtvAfHOn0FxLc5ty3amvLJxJTxyDT2DyhPTPhhXwuPbwAc0/exT+oD39oDaeF0nkWryRgzV3LzOeSMzs3g8w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WRG9xjFq; 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="WRG9xjFq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1BC13C433F1; Fri, 15 Mar 2024 16:53:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710521635; bh=Unfgd+Xo7evIfZLg6ZS/YCO4C8AeO+s1DYe1G/oc9jk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=WRG9xjFq5lq1t4ya5wUUvSRDISmfJwnGyNAwNuwKwZ3w1S8MRE0g9Dgt2LLUboKgK 4l8PsohndrCH9u+hcXWxKhY+K/ctoG6UmTaQlj428p3IUHB8d6fTnTDLoAnAzDhcuj qbe8nlQ6a/JbSmFkE7tWVTfwJi8RLfqqLaQbg2ziVArNTge2yxoQhguribCNBwOV6w 9NKrVODl12GhcU8+ivcbkmA49HGkCx28AvlES3LIpmUURQRsxYc2WjBMqGfQ3oZzEn FgUwRXEmbH+IIwmqns6mgcqYj5R60qqV4DOM19XZDcW1TiM5XjBlfRJP7axaB1Gv7n saY+9LKKzZziA== From: Jeff Layton Date: Fri, 15 Mar 2024 12:53:06 -0400 Subject: [PATCH RFC 15/24] nfs: fix nfs_stateid_hash prototype when CONFIG_CRC32 isn't set Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240315-dir-deleg-v1-15-a1d6209a3654@kernel.org> References: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> In-Reply-To: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Chuck Lever , Alexander Aring , Trond Myklebust , Anna Schumaker , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Greg Kroah-Hartman , "Rafael J. Wysocki" , David Howells , Tyler Hicks , Neil Brown , Olga Kornievskaia , Dai Ngo , Miklos Szeredi , Amir Goldstein , Namjae Jeon , Sergey Senozhatsky , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, netfs@lists.linux.dev, ecryptfs@vger.kernel.org, linux-unionfs@vger.kernel.org, netdev@vger.kernel.org, Jeff Layton X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=647; i=jlayton@kernel.org; h=from:subject:message-id; bh=Unfgd+Xo7evIfZLg6ZS/YCO4C8AeO+s1DYe1G/oc9jk=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBl9Hzu6GGwi+3pppCEg0zxTXFkEQi6CqOj2kP0i Yw1YrlLkLGJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZfR87gAKCRAADmhBGVaC FUJfD/wOsHEBcEpCyDNgQJJp58wR6PtoKRtA0ZFwKb4I6wyAGH3nQer6Hzf/wHpuzW75Hz0DF2B ViYoZwUKCh20Ae7hHgQtB4pL+qcRKbNeC9sAyOnWUCegkf66tr66RZ+8hpYh2xk5qBA4aU7f8/r 7k1Jy7/dEYe2gX4AuM8p4eBf23g438LQWSM6MWKVV1VYSYjQIL5Hl6RO1FNMjwxXOKCgHk2sKtf urxXibgGb0pdxb4hn/8Wq3KuJFpg2hdUE4NJ3S7pLrv/5bpO3jURHaFCZMl8vD1Yt8K7H7rxXwx 9cEAnpvHafcCLljmu50L+90Jx5mf9tm9VXO5Vr3JFMjdSJocBO32/cv30Ez7Sxd7WZEQA7E5I9K N7zcXTGvVFl9+0pQyXwz8y+PznNYkEva8I6qe2iwwgf8/J1HNG7PrCZN25oaUpCpgiQiz3Ir1Lf iOJhS6Vv2RMtO/R2qEhLzogWWgS+dzKpFNLN0Wp51xhOqbfPjxBD3XOKZk2avRrXB3Ry8B5GpKo SSQzsvq6qiBSGiYCjSN96AnwzXodCyVw5v722mpye66XDRMdtycJN749JWFZsJKy1VCVamrcCrc E39rksN7CTbXPNFgl11TzIsNMgehQG1za+hB5tmSmwMpdUM+LKJEtQe9TiVoDCdDWHl5iCyTZA5 4UIAnEMzddkQeNg== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 The alternate version without CONFIG_CRC32 should have the argument as const. Signed-off-by: Jeff Layton --- fs/nfs/internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h index e3722ce6722e..9203b3bb78b3 100644 --- a/fs/nfs/internal.h +++ b/fs/nfs/internal.h @@ -868,7 +868,7 @@ static inline u32 nfs_stateid_hash(const nfs4_stateid *stateid) NFS4_STATEID_OTHER_SIZE); } #else -static inline u32 nfs_stateid_hash(nfs4_stateid *stateid) +static inline u32 nfs_stateid_hash(const nfs4_stateid *stateid) { return 0; } From patchwork Fri Mar 15 16:53:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13593700 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 66C6A5D74A; Fri, 15 Mar 2024 16:53: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=1710521638; cv=none; b=pM0EzXUNQ4bIebjzj45kYj6Snro0GdZg8ToXf2U1gK2FyaMsZgVdUzRt8kePAxUBl3Llq8buaHxtIfoqOopkxFmRCwPKZf/eoid3LZ88JNbYzyIKX6z7/BrEz90Lnuz0/jLrIc/Ukl9gCA/2+FElVA3WD/ZJaZ+8XQ8vWg50ckM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710521638; c=relaxed/simple; bh=P09PKo+whz8zrLueysD1j/ntdbO/a/jX/vfqgwpWye4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=m+h0iYqtLgJ39dosk5NY21/nyDKUEFauflKrkMh3LzFmX1HXzrBfKh6vQm6r7OBa7w9i/r6ClnOBGgRBm44ZVkkwcd3RFUxb7whI1oVq7hKNpikivHc4b0EEpSQ1vqLg/WVeWl5DqpAhh0ll8BDMD38C57rkrwHu7Br/NvywK2w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pO5E64OF; 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="pO5E64OF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4BFDDC43394; Fri, 15 Mar 2024 16:53:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710521638; bh=P09PKo+whz8zrLueysD1j/ntdbO/a/jX/vfqgwpWye4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=pO5E64OF9eWs53Lx4dQ210ryMhYJEUxDCICazhfEN4JyO6jiNtXbcrfUR+bOAptNE c2lvK7YQE7i/BsS5l+Y4oeknY+3ek8gB7XotCZgiZV7XWlKmLzdc8Wu42l4bY4Md6c lJdCI9jeWITyOvoALl1ZInjyo7zObPSwgSSBEeAfoMiXi++nMqE838TT+cBoaEaIhV yFjyfhqWCr/7q3J+Yd5zHSe6NXfDqr3AUSytPdU9bAfAAV6uo3dlFL8a92ujP/T+4E qtdVkaEbIVlEdo17BaXVy5duvtqNGVraePVRgLBZfU10il2qC7iucXARTbWAiSiKIH jl1n6MJ//rCCQ== From: Jeff Layton Date: Fri, 15 Mar 2024 12:53:07 -0400 Subject: [PATCH RFC 16/24] nfs: remove unused NFS_CALL macro Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240315-dir-deleg-v1-16-a1d6209a3654@kernel.org> References: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> In-Reply-To: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Chuck Lever , Alexander Aring , Trond Myklebust , Anna Schumaker , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Greg Kroah-Hartman , "Rafael J. Wysocki" , David Howells , Tyler Hicks , Neil Brown , Olga Kornievskaia , Dai Ngo , Miklos Szeredi , Amir Goldstein , Namjae Jeon , Sergey Senozhatsky , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, netfs@lists.linux.dev, ecryptfs@vger.kernel.org, linux-unionfs@vger.kernel.org, netdev@vger.kernel.org, Jeff Layton X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=697; i=jlayton@kernel.org; h=from:subject:message-id; bh=P09PKo+whz8zrLueysD1j/ntdbO/a/jX/vfqgwpWye4=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBl9HzuV4GxWMKhi5EkvV/w/bQyxolJkrNEc3E61 tLkk1OxdAeJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZfR87gAKCRAADmhBGVaC FSnZD/9KD+nv25bgMB3Htqx3wHiC2z6De4pIniEkhzlXQTfIHtsacWj7beBSTVjNys4sEsAyPId fQD6pjGjKh7qh6MMNeySTeTcgmBdDpz1ajU3MTGM/NxzG7ACRppdSuFBeZRixNDaJSOdFZ/i8tZ Il71BpSuE24Fs6S/p4K9h6xMcuiFH7CklYBi+VntZ/SHbVxKy/2s9LlhE5ZDBReKFDkQkFRAe+g egZx1PFw4I35meRubEt+4TvQZcIMOzkJp/Xuol7aoRAA2dPUYSqGxRIWlqg1VyQn6SIeYu0qkbk 4VZu2N8nGCSoj2yg3XHr7bS2zL5dDsP+cZxXzQHpi/vg+K5uhrdJDaucuZosQqY/zcjluQfnctS 1CD6i0Nz29PBaiTfI5nbxDv7zyzAtZ9q5Jn5LixRPfCMU5FFKcEzPW5qXv8sDGfd33rzYqcI1sD nZ2CiEB5Q1b5oqEA+95nxws/2kxi45yQYinUcOfFwF5xVdGW57SzFRjTv0bkezdyzL6kgEHnxzD mVPidjI0jJ+EizqMZ2MIepURlJKIB2HNZHZO1ktdBqkzUFiRRfrNIkOWYKqaMuXR8zXOIE2yJKo 6lsEYhdirnjH+xETbDikyv7IzCzn09RbN2BVADNuLdWeJAqR0+JDNjjir1FGLuM4JYgWptMX822 +5jGlQ/VG31XYkA== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 Nothing uses this, and thank goodness as the syntax is horrid. Signed-off-by: Jeff Layton --- include/linux/nfs_xdr.h | 7 ------- 1 file changed, 7 deletions(-) diff --git a/include/linux/nfs_xdr.h b/include/linux/nfs_xdr.h index 539b57fbf3ce..d09b9773b20c 100644 --- a/include/linux/nfs_xdr.h +++ b/include/linux/nfs_xdr.h @@ -1820,13 +1820,6 @@ struct nfs_rpc_ops { void (*disable_swap)(struct inode *inode); }; -/* - * NFS_CALL(getattr, inode, (fattr)); - * into - * NFS_PROTO(inode)->getattr(fattr); - */ -#define NFS_CALL(op, inode, args) NFS_PROTO(inode)->op args - /* * Function vectors etc. for the NFS client */ From patchwork Fri Mar 15 16:53:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13593701 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 D6B4346444; Fri, 15 Mar 2024 16:54:01 +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=1710521642; cv=none; b=oq7K+ZeAiJBFoc2G1KaC0/lLkeRU0t3EsAX7IMAZARpOBpS/hOzK1uE9+Gv++U2WkcZkDRf5wIC+FD7+7hp8WDhUQF9Cg8Q7iuEIIZD7qoen9bI/gRY2z9p0Wpi812NTUW7ua8JeYRfZXYrlSci+C3Hkj1QVCO7WulCDjXbhL58= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710521642; c=relaxed/simple; bh=P3P+nenUv6VvukNKiPfmxlsB6i7HdvY08p8t+ZTGZvQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jrOqPBHMecBfmxYp/3RHpfZub/Rj96+BWHjHv/0H+XNouftnEWpgkC23GQC9hKIDf4p6YZAe9FqyC5cAqVIpmB8SDqOSscGyud95mAlw8t748isH0b47ub4F2mPMmViZA9NlujsobM54RNjnTt16R5pgSrKkMBGA1c5tTGNylnA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bA0JHACJ; 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="bA0JHACJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7D4B4C433C7; Fri, 15 Mar 2024 16:53:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710521641; bh=P3P+nenUv6VvukNKiPfmxlsB6i7HdvY08p8t+ZTGZvQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=bA0JHACJ4ODIfzBcjkQNec/1i3GwGfPX1XO4vav7s1TnyjdlA3Ai7XJBTetakBPIi IDeYNJpPufcNi2bhKyQjNL8PnbNlpwqXcIaVejSxLrpp8s+x/ARHSBZ3s05qZKCAC4 BxrxURM+BIWz9InwPb8QNgVIkfmGuDFQ8+dkU0JOpWyNz6bD746s+rXg+ySz3hNwr+ vVS5NMLoD4yBzXbzcK+N+vK8aRz2rv9+9QWdtOlezW9105CArD4duChX13QkCTVqa4 ufi0ideAIXlaDVahH6wsWH5BgbrHskAZu4bRpFhAv5M4FxurCn8+BNzxEEMP2VW0x+ O+apPmFY+MZTg== From: Jeff Layton Date: Fri, 15 Mar 2024 12:53:08 -0400 Subject: [PATCH RFC 17/24] nfs: add cache_validity to the nfs_inode_event tracepoints Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240315-dir-deleg-v1-17-a1d6209a3654@kernel.org> References: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> In-Reply-To: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Chuck Lever , Alexander Aring , Trond Myklebust , Anna Schumaker , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Greg Kroah-Hartman , "Rafael J. Wysocki" , David Howells , Tyler Hicks , Neil Brown , Olga Kornievskaia , Dai Ngo , Miklos Szeredi , Amir Goldstein , Namjae Jeon , Sergey Senozhatsky , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, netfs@lists.linux.dev, ecryptfs@vger.kernel.org, linux-unionfs@vger.kernel.org, netdev@vger.kernel.org, Jeff Layton X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1399; i=jlayton@kernel.org; h=from:subject:message-id; bh=P3P+nenUv6VvukNKiPfmxlsB6i7HdvY08p8t+ZTGZvQ=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBl9Hzuw88TNqkwCTRIrEoLMgta3Sg0NHy64s1yu mjRVl3KkxWJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZfR87gAKCRAADmhBGVaC FasaEACuCD1+QHJLojJYk7/ZwEUGejIPwEWap+++JOPIdRPuGRKC8aDvaOaQD2V1gAoWvZ47y8a I9XxuUjcpfkniTYoJb1Vvy7rz/6uTRGV/91UFdLPY/N19gjH5ZdvP+ZgKpcxsTpscRCyZNSj4br PKYcfDpjLymWsxaQZAvoEq5CGJOJjij+oJwTwXG04n0+hBXAdsDGS0oeUQG3A3FWr5Q2QjsYPfa cQ+G1aoNF1dw88GvPPXh3X2N8hGu/gmDyKXXhzD4jCp1spW+3ffSBQ6dhOXhLOQyUmAS0IWeWB3 nujqVPjSUgjK0yaE/SIII5RNggdSMIZXCgg6XSBGt3rxjvLIpw4XHOfk44ZXnYKzvpwMBfqszdF VrGm4HFamuj+O9HHv+VSd4140KbfULTBr3txJviII7n2ri9V3BnbXUCPmiLnMQmjs26Qe91ZRnp +ZTOdmV1IM/LR4xnXjCPPAYO2cSU+gZVb7mnDd5i30nCWGZhQDSiW6TnYeHU+w+EU0eXMNvIxcx fwEWWo/uy8U0gwJC/N6ZHz4rM2e3KylUA5GQVvUmLzn0l75LRWYvAC3F0LK7lxcxK3P/QawY2Ym Ztm7wFSUOQZjAsx2PwIqKSBubWclBpFRn3KXQyMmp7xX/TZ9TB9Z2hxLH7+2hy7DUTFixYnKOY1 LAsxr375bCYSywg== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 Managing the cache_validity flags is the deep voodoo of NFS cache coherency. Let's have a little extra visibility into that value via the nfs_inode_event tracepoints. Signed-off-by: Jeff Layton --- fs/nfs/nfstrace.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fs/nfs/nfstrace.h b/fs/nfs/nfstrace.h index afedb449b54f..e0cd3601d1f7 100644 --- a/fs/nfs/nfstrace.h +++ b/fs/nfs/nfstrace.h @@ -56,6 +56,7 @@ DECLARE_EVENT_CLASS(nfs_inode_event, __field(u32, fhandle) __field(u64, fileid) __field(u64, version) + __field(unsigned long, cache_validity) ), TP_fast_assign( @@ -64,14 +65,17 @@ DECLARE_EVENT_CLASS(nfs_inode_event, __entry->fileid = nfsi->fileid; __entry->fhandle = nfs_fhandle_hash(&nfsi->fh); __entry->version = inode_peek_iversion_raw(inode); + __entry->cache_validity = nfsi->cache_validity; ), TP_printk( - "fileid=%02x:%02x:%llu fhandle=0x%08x version=%llu ", + "fileid=%02x:%02x:%llu fhandle=0x%08x version=%llu cache_validity=0x%lx (%s)", MAJOR(__entry->dev), MINOR(__entry->dev), (unsigned long long)__entry->fileid, __entry->fhandle, - (unsigned long long)__entry->version + (unsigned long long)__entry->version, + __entry->cache_validity, + nfs_show_cache_validity(__entry->cache_validity) ) ); From patchwork Fri Mar 15 16:53:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13593702 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 329D05DF3A; Fri, 15 Mar 2024 16:54:04 +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=1710521645; cv=none; b=VCdWWhsRGdiGlaCE/BgUHejTjULhgHoLUF1cB3se7S3anzKjjeIXO5tQp/Erbg83sSsSfC79xsY4bJ4MyD+CTuKZbXw4pcv96lg5Gystmnf1ZqyYGZJugLrXrsI9e7+L1w6spSqdAmXMTkNfV/LWmQTQ6LKFjVRro5MIQJ97KDo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710521645; c=relaxed/simple; bh=XiLoCX5bhdIOKqVgg6TYQoclvr1Nu5zRdr/p/ktT9jI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qmvvTutwcBUWA0gyJ4705t5+nAgkef/EpR2X61nQgdBd+KwRHC3mJmqGpnmZQfgf4JI8O6264lKhU9c8a0i2GE2RaURmWuicofhxK6dZmB7ZY815EXND8UdZOP0VLtz8OttTEy9wER1IGBaU0LXWbPQ5ODrNnW3hn8Yj2P/CY0g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BLPvsPtQ; 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="BLPvsPtQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE688C43141; Fri, 15 Mar 2024 16:54:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710521644; bh=XiLoCX5bhdIOKqVgg6TYQoclvr1Nu5zRdr/p/ktT9jI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=BLPvsPtQdNH5QPkGe5nrzfrhOhLNi2qwiwA2ylgWSBrlb8XTozNQ95eRiDkApXBll Eq/eMNeqMJxZDFAbeyaPJb8yLCrV1oTKxOV4sRgugj+PnBh8S6DZfOmNr4wSWICVab I5QqpFrWSpRjYP1+RlK5lZifRgcaXmY54Fm2zkhqTwoveWgpZXmf5R3c7Todz0zo81 pI+rzNF1Jp0ez4zvsj7YUucHPhITnQWcxkyFNmAcDyfNWcSSIMqYF29mAECLJJOmvz SVdnJUW4+S1K8Mapl2DOyY4KX5QyBbkA/+cgzyLr6AqS/Jpro5R9JA+INPyQubZ3dF mxOhzh3d1u28g== From: Jeff Layton Date: Fri, 15 Mar 2024 12:53:09 -0400 Subject: [PATCH RFC 18/24] nfs: add a tracepoint to nfs_inode_detach_delegation_locked Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240315-dir-deleg-v1-18-a1d6209a3654@kernel.org> References: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> In-Reply-To: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Chuck Lever , Alexander Aring , Trond Myklebust , Anna Schumaker , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Greg Kroah-Hartman , "Rafael J. Wysocki" , David Howells , Tyler Hicks , Neil Brown , Olga Kornievskaia , Dai Ngo , Miklos Szeredi , Amir Goldstein , Namjae Jeon , Sergey Senozhatsky , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, netfs@lists.linux.dev, ecryptfs@vger.kernel.org, linux-unionfs@vger.kernel.org, netdev@vger.kernel.org, Jeff Layton X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1244; i=jlayton@kernel.org; h=from:subject:message-id; bh=XiLoCX5bhdIOKqVgg6TYQoclvr1Nu5zRdr/p/ktT9jI=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBl9HzuFU9/qcgtCrWHrKJL7PuqWD46v0PKpVFYD d0wkTeXPv2JAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZfR87gAKCRAADmhBGVaC Ff3SEACwqsjqTGfQkWOWe61DrYWuJK3UYZgCteOaTcV+W2NWpxdnkFRovxC3Se9EQLFO4XYdz9h sn0mFfChkDAvBCMdBVVXnmiUSbyibhezGotYkv/OvUgiXR7EBtFEkB+gHkwRKlMDjJ26di0puOO uSrdJuCp0u73L9RkjUAQldmInEzMQ0/BoGkzflTS6JtvfYM2lWk8Vl3zPA1d+PC4V5GbewJQ+EM V5H4uqj2ZMEpL9R8oGjTpMT7MANepirW1NOyv6fwvSqbNg9q9q8sbCSyDJ3SBvLOeNcvC9ftk2d aTdXJSePeMTuALlxkeoa+KdleIx7qwV5d0pYLnLp5Ln6LfRe0m3pybLzBcLyKgIZ2evFWpbm/KP EROuJMgNarMgNsejXdkODcuHcKrt77wRFe4HC93mAQQSJVCxzF8BexykjGwbkBmEM2Qy3HQy1QS PVEMszQUJhJ7Ljm4y97zwWZftIkSfahruJsqoRXJd16/qLTJHrb5p1dkZFAvGwsmaMozMu6EOaf 3EVaCPZVvYPu+Q5ovAeQuueGEkvAoZcV7dwrvlFmpWuFv4YfE38lxbNby4N+UNXQsL5H1GbLRJf PXVHfP5hiziscco0g7ByP2lUwWP2uvoj/h5wG1zJT9XgMaBX9nQ3pjZNb+f8BYuBV4j+0qxneoO 5NqX/6yGWQJ5Gsw== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 We have a tracepoint for setting a delegation and reclaiming them. Add a tracepoint for when the delegation is being detached from the inode. Signed-off-by: Jeff Layton --- fs/nfs/delegation.c | 2 ++ fs/nfs/nfs4trace.h | 1 + 2 files changed, 3 insertions(+) diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c index d4a42ce0c7e3..a331a2dbae12 100644 --- a/fs/nfs/delegation.c +++ b/fs/nfs/delegation.c @@ -342,6 +342,8 @@ nfs_detach_delegation_locked(struct nfs_inode *nfsi, rcu_dereference_protected(nfsi->delegation, lockdep_is_held(&clp->cl_lock)); + trace_nfs4_detach_delegation(&nfsi->vfs_inode, delegation->type); + if (deleg_cur == NULL || delegation != deleg_cur) return NULL; diff --git a/fs/nfs/nfs4trace.h b/fs/nfs/nfs4trace.h index fd7cb15b08b2..b4ebac1961cc 100644 --- a/fs/nfs/nfs4trace.h +++ b/fs/nfs/nfs4trace.h @@ -926,6 +926,7 @@ DECLARE_EVENT_CLASS(nfs4_set_delegation_event, TP_ARGS(inode, fmode)) DEFINE_NFS4_SET_DELEGATION_EVENT(nfs4_set_delegation); DEFINE_NFS4_SET_DELEGATION_EVENT(nfs4_reclaim_delegation); +DEFINE_NFS4_SET_DELEGATION_EVENT(nfs4_detach_delegation); TRACE_EVENT(nfs4_delegreturn_exit, TP_PROTO( From patchwork Fri Mar 15 16:53:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13593703 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 521EF5EE72; Fri, 15 Mar 2024 16:54:07 +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=1710521648; cv=none; b=oBrOqqwhUTUdre77ifZdHakXlF3vJBSFZXwQroxB6YDo2T/gtpZMvVYfomWgBIHHK7n4DyyPPlkFN4R5ZXJuGAjL/enVltTjeXWDn/oXIRP15sihf+bg3abB8s0GBjQ4s4R2DEDQj9YFUxKAfMX9jB+a1h+EPgiWv/jfnwItVA4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710521648; c=relaxed/simple; bh=9chmKcIKKKzx4wiFjA6GZHLU6rDBlxqhwWoI/uEcrUU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=a4qKA29nFKWF9C90Jth6zh5YmYhAPy7i1JaI5w2+RJtd3AGSB6VBFLEzxPiqp+mZFyK6PmDIOspXLKLjZnGt0x40ZjsxlihDlQK/iT90npu13S08W76mjbXA+vc0NmiKBYiDAZt48KIEYr43Tre+XezctHnaMIvbsfhFRV9+LzY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FQcjuNwr; 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="FQcjuNwr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DF968C43609; Fri, 15 Mar 2024 16:54:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710521647; bh=9chmKcIKKKzx4wiFjA6GZHLU6rDBlxqhwWoI/uEcrUU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=FQcjuNwrvn2abT6HRblgJnmtN0oyn8AsfV+GwF/na6KmAs3behS8JmXwQCjVsPI+Y yr9Fd+y3+KZtYdRBdNVTX/AQ9m9JdEXiFnocFwUbxvgQxRjxIy4+NuY1bez0dRZwme 2G6u8Kzxlq6ShHYKj8/hwXPGzFi8DLTTD+bSjIbLIjavrMMP4PCFlTtG20ez30T+Hh K5RweCefPmuaXSNPjHYI8eQ/oiDuZ9S7kPoyqWwRvjg4m8+OQf1bKWo6MugLflHrW8 5a2oLTfSpxW1OFZVaCOQh1v8WJVr+6hPJ4tjBxGeauaF2fBHCmOh3XoLgPKtbBYl3L KbovwrSB6fpoA== From: Jeff Layton Date: Fri, 15 Mar 2024 12:53:10 -0400 Subject: [PATCH RFC 19/24] nfs: new tracepoint in nfs_delegation_need_return Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240315-dir-deleg-v1-19-a1d6209a3654@kernel.org> References: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> In-Reply-To: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Chuck Lever , Alexander Aring , Trond Myklebust , Anna Schumaker , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Greg Kroah-Hartman , "Rafael J. Wysocki" , David Howells , Tyler Hicks , Neil Brown , Olga Kornievskaia , Dai Ngo , Miklos Szeredi , Amir Goldstein , Namjae Jeon , Sergey Senozhatsky , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, netfs@lists.linux.dev, ecryptfs@vger.kernel.org, linux-unionfs@vger.kernel.org, netdev@vger.kernel.org, Jeff Layton X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=2950; i=jlayton@kernel.org; h=from:subject:message-id; bh=9chmKcIKKKzx4wiFjA6GZHLU6rDBlxqhwWoI/uEcrUU=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBl9Hzv07jA46HEdrPEpbu9KUs+t+dT0TuGhYw8U 0l2zVbU5sGJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZfR87wAKCRAADmhBGVaC FewED/9pQa7cC+u8jYnK4XdPPAVW7u+Z3/GhEDioItysl4TeWHxviBhXxdtxuKvvjWjDJ3lY77p AeVS7ugRv9+XZM71qj0UXrAoKARZevFhOTzXzDE2T229Z/koSizUvlwfJNaxk7GM1n3wFv5e2B1 TJUOmPFr4lN2/SIeCv8ZbR+kva3c2KaRy7HtEGF6J4fn4wnWtsU0G5AYLuyibb6zmd6ory8964/ Nbv8IHiRI/k4VPH+oPO+jXwvTY1EIRLsNdmZhmQ8zwNr9RVNcP24/4EmFcATlfLzTv5/r6guIrA 03cI/J69xlX1pNt1lIQV+VTBLneSV62JiLGu2fLHgHB/ynp02d0QpfxH0Grhviop8eFSnJgbQzu 1aHjhYBM1xO8uATiMfT4mfl5aVBzw1Aaq1HivvLFTTdYx7hQsUuI9pI7ZlvIxKGz2A/+LcbzZMv kXLEjBbiOmXJt30wHOLNriDCsVWwcx4F1BI2dRAybX/TUkOBVT1P2IjS/ObuG4KDeD1BZvTP8ei bVMuS0upLkS8KN4HE+8hnAt8qIFiHka1zbf4FPnJrGUuC9dDzLKzsNEIJ5DMb5VMxFnpxqM89M2 WphpMPAtqWYioxQM5xoJrzJlmJNRPuJCHIpY3CyYLNKZ+Iwnej1iaRksnXzxrfvGfaLRf/LWsh9 wjPnoUaUGo/7KQQ== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 Add a tracepoint in the function that decides whether to return a delegation to the server. Signed-off-by: Jeff Layton --- fs/nfs/delegation.c | 2 ++ fs/nfs/nfs4trace.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c index a331a2dbae12..88dbec4739d3 100644 --- a/fs/nfs/delegation.c +++ b/fs/nfs/delegation.c @@ -571,6 +571,8 @@ static bool nfs_delegation_need_return(struct nfs_delegation *delegation) { bool ret = false; + trace_nfs_delegation_need_return(delegation); + if (test_and_clear_bit(NFS_DELEGATION_RETURN, &delegation->flags)) ret = true; else if (test_bit(NFS_DELEGATION_RETURN_IF_CLOSED, &delegation->flags)) { diff --git a/fs/nfs/nfs4trace.h b/fs/nfs/nfs4trace.h index b4ebac1961cc..e5adfb755dc7 100644 --- a/fs/nfs/nfs4trace.h +++ b/fs/nfs/nfs4trace.h @@ -14,6 +14,8 @@ #include #include +#include "delegation.h" + #define show_nfs_fattr_flags(valid) \ __print_flags((unsigned long)valid, "|", \ { NFS_ATTR_FATTR_TYPE, "TYPE" }, \ @@ -928,6 +930,51 @@ DEFINE_NFS4_SET_DELEGATION_EVENT(nfs4_set_delegation); DEFINE_NFS4_SET_DELEGATION_EVENT(nfs4_reclaim_delegation); DEFINE_NFS4_SET_DELEGATION_EVENT(nfs4_detach_delegation); +#define show_delegation_flags(flags) \ + __print_flags(flags, "|", \ + { BIT(NFS_DELEGATION_NEED_RECLAIM), "NEED_RECLAIM" }, \ + { BIT(NFS_DELEGATION_RETURN), "RETURN" }, \ + { BIT(NFS_DELEGATION_RETURN_IF_CLOSED), "RETURN_IF_CLOSED" }, \ + { BIT(NFS_DELEGATION_REFERENCED), "REFERENCED" }, \ + { BIT(NFS_DELEGATION_RETURNING), "RETURNING" }, \ + { BIT(NFS_DELEGATION_REVOKED), "REVOKED" }, \ + { BIT(NFS_DELEGATION_TEST_EXPIRED), "TEST_EXPIRED" }, \ + { BIT(NFS_DELEGATION_INODE_FREEING), "INODE_FREEING" }, \ + { BIT(NFS_DELEGATION_RETURN_DELAYED), "RETURN_DELAYED" }) + +DECLARE_EVENT_CLASS(nfs4_delegation_event, + TP_PROTO( + const struct nfs_delegation *delegation + ), + + TP_ARGS(delegation), + + TP_STRUCT__entry( + __field(u32, fhandle) + __field(unsigned int, fmode) + __field(unsigned long, flags) + ), + + TP_fast_assign( + __entry->fhandle = nfs_fhandle_hash(NFS_FH(delegation->inode)); + __entry->fmode = delegation->type; + __entry->flags = delegation->flags; + ), + + TP_printk( + "fhandle=0x%08x fmode=%s flags=%s", + __entry->fhandle, show_fs_fmode_flags(__entry->fmode), + show_delegation_flags(__entry->flags) + ) +); +#define DEFINE_NFS4_DELEGATION_EVENT(name) \ + DEFINE_EVENT(nfs4_delegation_event, name, \ + TP_PROTO( \ + const struct nfs_delegation *delegation \ + ), \ + TP_ARGS(delegation)) +DEFINE_NFS4_DELEGATION_EVENT(nfs_delegation_need_return); + TRACE_EVENT(nfs4_delegreturn_exit, TP_PROTO( const struct nfs4_delegreturnargs *args, From patchwork Fri Mar 15 16:53:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13593704 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 35F495F46B; Fri, 15 Mar 2024 16:54:11 +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=1710521651; cv=none; b=paDVFid15KPiPxgPAuTPzgeI36qMy9cYc8uM59iKENOLgyBBzZKMY0cuwh818RenQkGkwe5BxaA4/FkOFPhMGpXykAo1QbNRYtlpyxFv3Nvp4cFNOOvPdIHCZyPbWmELjqiwsM+0lfF64c8Tc3OVBVisTBdBBKwXvV14P/oO/l8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710521651; c=relaxed/simple; bh=lxV7izHPE+zlnqW3U+dTQR3CCp98pGncwQ1zL/XGIzA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=i/UoVAvfcs+XQcludAM2qKkDw+mwGyED+NpAwHe1mGXOKy/HJEHM5l2Zv3KN2tHNFHDPleHjOyf4FzrGhlN6679ydEmyC792zbLhYra/UKptKeB+lSzD3N98MgCM2MiNiVAFE6nVRAWWjzEv7HvMHBf/QclOr+tmGdS+K8+ovy8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TjyekGU7; 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="TjyekGU7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1F5B3C433A6; Fri, 15 Mar 2024 16:54:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710521651; bh=lxV7izHPE+zlnqW3U+dTQR3CCp98pGncwQ1zL/XGIzA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=TjyekGU7X/ycYls+a9oMTXm4AxG9GbWbVuPiPjf7qg6vAItdVfuEl+v39HJ+YZ7Nr h6unXUAshinq+mq8S1xdj6aYRUGakFqAVfihUkiUIiPWKqfjQUv0idpkwyslHgwfle iT105IfnP7dmsrnFqjwzd4n4kC7HjOYQqXDMo5DfBYc2ImApyTyZRyi8WCjsfQph3R oApCUYdeYSpyhBbMYPp+89FdBbM0bi9jAn7nIvs34uA0WQQN+2/9S6AA5zQy97nUnR tY2vpPk8EroU+VE5GFlN4MKpFIRYEsxnUg17000kDBOjynrkuuY4lqv5ReSTkB5yza Z/eZ7YskP3D1A== From: Jeff Layton Date: Fri, 15 Mar 2024 12:53:11 -0400 Subject: [PATCH RFC 20/24] nfs: new tracepoint in match_stateid operation Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240315-dir-deleg-v1-20-a1d6209a3654@kernel.org> References: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> In-Reply-To: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Chuck Lever , Alexander Aring , Trond Myklebust , Anna Schumaker , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Greg Kroah-Hartman , "Rafael J. Wysocki" , David Howells , Tyler Hicks , Neil Brown , Olga Kornievskaia , Dai Ngo , Miklos Szeredi , Amir Goldstein , Namjae Jeon , Sergey Senozhatsky , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, netfs@lists.linux.dev, ecryptfs@vger.kernel.org, linux-unionfs@vger.kernel.org, netdev@vger.kernel.org, Jeff Layton X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=3036; i=jlayton@kernel.org; h=from:subject:message-id; bh=lxV7izHPE+zlnqW3U+dTQR3CCp98pGncwQ1zL/XGIzA=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBl9Hzv6J2chYdV0t8vLEOXVZhJ40E7hMoQpCAVh RHtnRSKWaOJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZfR87wAKCRAADmhBGVaC FTzzEAC7hUKavoEeDCntzRNdIHCTFTR2R1SfnG7m0K5BQB3F5OhjGBFyfx9wCOn9b+p6h1S/fX5 9AGnQBfoRKjeMp2Pw5Nv3BjEinIrY5HgHi7r00tA7AY4Cyz6f0YlE5ArUOt5arGyRuGxl1eIfVh iucv6ZF1hJz3Uc2akJ0JvmEDY289882z04rYSaxPQcGKyudfg/ML8ulETzYnmExuy8tRt7b2sHO 9QUSUhBv5oitzj4kgrhfwHFtneUrK9FkxsdNbI8wO+kF0ECY/7D2BsAB0G1evArYZe3LR+TzlNl 1vabY5cSEhr6xa8Mq2qXwcXj8dDIIzkmP3EIWJt2PJqlHpLyzMd1aPgNslQpCxUaHq5nhU//DPT gE64opgPAVQBEz2Tl0F8LSnli7uqvhCPyELAmRgj6z9oBfoeXacHimcUqP2/VKIqdLwC6Ss2uIy IqigI0PXXUZYvH6D5taPTBFgsP3OswfpgAnLWjWCZTLpkDt8HSmkC1qUG3fvwCyRhYjBXYsjCE3 HSJr96+h/PRgf02son2ugSC8Mxtl14dxdb6G8JmKrWa9hSnOp3fHcWd3bhNv8Y5CO2c9V77+7r/ PjX1F7uHkcJa1fr1wOo0UR5Fxi5KgxjKjtiqeGflNDtj2yjnfs+cbmxvG9+vXpKtJKJpF31v5eq PLXJwUeP2Ayvilg== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 Add new tracepoints in the NFSv4 match_stateid minorversion op that show the info in both stateids. Signed-off-by: Jeff Layton --- fs/nfs/nfs4proc.c | 4 ++++ fs/nfs/nfs4trace.h | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 815996cb27fc..d518388bd0d6 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -10432,6 +10432,8 @@ nfs41_free_lock_state(struct nfs_server *server, struct nfs4_lock_state *lsp) static bool nfs41_match_stateid(const nfs4_stateid *s1, const nfs4_stateid *s2) { + trace_nfs41_match_stateid(s1, s2); + if (s1->type != s2->type) return false; @@ -10449,6 +10451,8 @@ static bool nfs41_match_stateid(const nfs4_stateid *s1, static bool nfs4_match_stateid(const nfs4_stateid *s1, const nfs4_stateid *s2) { + trace_nfs4_match_stateid(s1, s2); + return nfs4_stateid_match(s1, s2); } diff --git a/fs/nfs/nfs4trace.h b/fs/nfs/nfs4trace.h index e5adfb755dc7..f531728a5b4a 100644 --- a/fs/nfs/nfs4trace.h +++ b/fs/nfs/nfs4trace.h @@ -1467,6 +1467,62 @@ DECLARE_EVENT_CLASS(nfs4_inode_stateid_callback_event, DEFINE_NFS4_INODE_STATEID_CALLBACK_EVENT(nfs4_cb_recall); DEFINE_NFS4_INODE_STATEID_CALLBACK_EVENT(nfs4_cb_layoutrecall_file); +#define show_stateid_type(type) \ + __print_symbolic(type, \ + { NFS4_INVALID_STATEID_TYPE, "INVALID" }, \ + { NFS4_SPECIAL_STATEID_TYPE, "SPECIAL" }, \ + { NFS4_OPEN_STATEID_TYPE, "OPEN" }, \ + { NFS4_LOCK_STATEID_TYPE, "LOCK" }, \ + { NFS4_DELEGATION_STATEID_TYPE, "DELEGATION" }, \ + { NFS4_LAYOUT_STATEID_TYPE, "LAYOUT" }, \ + { NFS4_PNFS_DS_STATEID_TYPE, "PNFS_DS" }, \ + { NFS4_REVOKED_STATEID_TYPE, "REVOKED" }) + +DECLARE_EVENT_CLASS(nfs4_match_stateid_event, + TP_PROTO( + const nfs4_stateid *s1, + const nfs4_stateid *s2 + ), + + TP_ARGS(s1, s2), + + TP_STRUCT__entry( + __field(int, s1_seq) + __field(int, s2_seq) + __field(u32, s1_hash) + __field(u32, s2_hash) + __field(int, s1_type) + __field(int, s2_type) + ), + + TP_fast_assign( + __entry->s1_seq = s1->seqid; + __entry->s1_hash = nfs_stateid_hash(s1); + __entry->s1_type = s1->type; + __entry->s2_seq = s2->seqid; + __entry->s2_hash = nfs_stateid_hash(s2); + __entry->s2_type = s2->type; + ), + + TP_printk( + "s1=%s:%x:%u s2=%s:%x:%u", + show_stateid_type(__entry->s1_type), + __entry->s1_hash, __entry->s1_seq, + show_stateid_type(__entry->s2_type), + __entry->s2_hash, __entry->s2_seq + ) +); + +#define DEFINE_NFS4_MATCH_STATEID_EVENT(name) \ + DEFINE_EVENT(nfs4_match_stateid_event, name, \ + TP_PROTO( \ + const nfs4_stateid *s1, \ + const nfs4_stateid *s2 \ + ), \ + TP_ARGS(s1, s2)) +DEFINE_NFS4_MATCH_STATEID_EVENT(nfs41_match_stateid); +DEFINE_NFS4_MATCH_STATEID_EVENT(nfs4_match_stateid); + DECLARE_EVENT_CLASS(nfs4_idmap_event, TP_PROTO( const char *name, From patchwork Fri Mar 15 16:53:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13593705 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 B207B5F551; Fri, 15 Mar 2024 16:54:14 +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=1710521654; cv=none; b=kj2aGbZV1Uvknu3jFMLlfGjfCr2KH0/SWhrC7TmBfQWzc2x/ut37R299h2KdKKMsnSZhFy9wVAU81OvHFE4ot3FouV5iLrAiMkHcPCTNeyp6jG8Pp3e8zF9klSS09H4CIHkELNiGyhmNxtIVH1zhRFaYsib4FWiT996yt4bASao= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710521654; c=relaxed/simple; bh=r/E0+ttZBJ+9OQpGAaGdbsceE93QLD/K8Cil0//zQ0Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SBGPFCDvK8TJLFpmVtXH71Xcre6FrPMGYyEajBG++y5uUteqGqiYPYJr+fP6WocnDdmzGWEaSFBFW25/4h7hmDO5LhHZ9W5Ee3X2G4JKaZgDIfGOg97TaXftk7O4ezqo/ka6Sb7pd0OG0meeNbJHZ/vfSLnwsdEqGKYGQ2WIG4I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PBTcnOtq; 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="PBTcnOtq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 51B15C43143; Fri, 15 Mar 2024 16:54:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710521654; bh=r/E0+ttZBJ+9OQpGAaGdbsceE93QLD/K8Cil0//zQ0Y=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=PBTcnOtqQm2xViXydU0vepOlwiFedPt0uzMfQQLybF1pooU8JSPuuCegpM6TWwmEm Pi2Ole2yA9ebT9I8DQ2OlsU+c49znZ9R0KtQFJ2SdHbUvkmmG8XHIRISIhCB8bhQk1 1FQt5NA+aXFSpwf5csS2xwlJs+4r3HzYzgrOv5NAO5Y7NjRHDjcGqNp1ZQ21arASZC ZnSdP5Qn/D1wqStrbMUoKU1/YCqFtMRfPEMx8uB4XUSrDj1rHpTGNE70BYlSv7jhfE E3MVjEgV7s2aXr4bjfwuSR69rIxwbQBPzppLSO5yc2u0ZhbFvm2Wq2MpzdjaZv/Tmg /liS757mOJ/rA== From: Jeff Layton Date: Fri, 15 Mar 2024 12:53:12 -0400 Subject: [PATCH RFC 21/24] nfs: add a GDD_GETATTR rpc operation Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240315-dir-deleg-v1-21-a1d6209a3654@kernel.org> References: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> In-Reply-To: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Chuck Lever , Alexander Aring , Trond Myklebust , Anna Schumaker , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Greg Kroah-Hartman , "Rafael J. Wysocki" , David Howells , Tyler Hicks , Neil Brown , Olga Kornievskaia , Dai Ngo , Miklos Szeredi , Amir Goldstein , Namjae Jeon , Sergey Senozhatsky , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, netfs@lists.linux.dev, ecryptfs@vger.kernel.org, linux-unionfs@vger.kernel.org, netdev@vger.kernel.org, Jeff Layton X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=7304; i=jlayton@kernel.org; h=from:subject:message-id; bh=r/E0+ttZBJ+9OQpGAaGdbsceE93QLD/K8Cil0//zQ0Y=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBl9HzvbrxGDH4zPVZvjnQ6UxSQDBPK33TlO88hC 0zSIPsb0LeJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZfR87wAKCRAADmhBGVaC FSdJD/9tS/UejUix07NO9BdxnZuzLrlwwKs/m6NSoZmz4cbO7yQFRg0uPP5nBQm3J7Htzwdn+qn vpiWw2be2z8qQ6G3xz86gw3ISuxMKjGD8pPTrSzcC8cbWo6ZxNFWEK8Z47CxbTVZdwf6mVh+CLl yI57OGn7NFhVVTTwaXfRlRAFc2UsW2GkqSP0w//AfPTaKF/bDxWCfJAZqHXvebQ6O0wOA/5GB8R QQYUvXmXALLk+QlVW+5RhwJkQ32CchFzyPkf2atp7LeapKFS7+HOOAQJTY1QsR7xwI+phRAGvaH uavHdaoj0ljpxAUdUXLd3pPsPPd4rOWNuhsUZxm5xhsAyCCMwwDmtKAeWQKwx+pbaIPbdxQT0kw rPGk2i3hxbf9DLp4LTtC10XBZm93oDGIFxRzt4Uohl+4P0nPPJ5hT6DaU5sXTdXyrExEyIvNHB3 B36PSaiqoZbwvx86ujqnNQiY8oZcA0UgF9Lfs3sn/FDuuYkqkSNRksqIk2IUiwvIgKOzeDGXZWb O29C+uEmc4TNpAqkWcMfee/p1G+E9NExobEwNEewBvlZE96osbGbp8AtAVgVO6oO1lIOrC8Vvz7 lxvkCLtG7TbWMs1RO8iqLNO5mE9V/EwfaB43TTPOcyI5jeJIasffpSxtGhnIByLdz6tW0VTy658 Buj/Zz0JicD+VGQ== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 Add a new compound that does a GET_DIR_DELEGATION just before doing a GETATTR on an inode. Add a delegation stateid and a nf_status code to struct nfs4_getattr_res to store the result. Signed-off-by: Jeff Layton --- fs/nfs/nfs4xdr.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/nfs4.h | 1 + include/linux/nfs_xdr.h | 2 + 3 files changed, 139 insertions(+) diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c index 1416099dfcd1..c28025018bda 100644 --- a/fs/nfs/nfs4xdr.c +++ b/fs/nfs/nfs4xdr.c @@ -391,6 +391,22 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req, XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) #define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4) #define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4) +#define encode_get_dir_delegation_maxsz (op_encode_hdr_maxsz + \ + 4 /* gdda_signal_deleg_avail */ + \ + 8 /* gdda_notification_types */ + \ + nfstime4_maxsz /* gdda_child_attr_delay */ + \ + nfstime4_maxsz /* gdda_dir_attr_delay */ + \ + nfs4_fattr_bitmap_maxsz /* gdda_child_attributes */ + \ + nfs4_fattr_bitmap_maxsz /* gdda_dir_attributes */) + +#define decode_get_dir_delegation_maxsz (op_encode_hdr_maxsz + \ + 4 /* gddrnf_status */ + \ + encode_verifier_maxsz /* gddr_cookieverf */ + \ + encode_stateid_maxsz /* gddr_stateid */ + \ + 8 /* gddr_notification */ + \ + nfs4_fattr_bitmap_maxsz /* gddr_child_attributes */ + \ + nfs4_fattr_bitmap_maxsz /* gddr_dir_attributes */) + #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \ XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \ 1 /* layout type */ + \ @@ -636,6 +652,18 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req, decode_putfh_maxsz + \ decode_getattr_maxsz + \ decode_renew_maxsz) +#define NFS4_enc_gdd_getattr_sz (compound_encode_hdr_maxsz + \ + encode_sequence_maxsz + \ + encode_putfh_maxsz + \ + encode_get_dir_delegation_maxsz + \ + encode_getattr_maxsz + \ + encode_renew_maxsz) +#define NFS4_dec_gdd_getattr_sz (compound_decode_hdr_maxsz + \ + decode_sequence_maxsz + \ + decode_putfh_maxsz + \ + decode_get_dir_delegation_maxsz + \ + decode_getattr_maxsz + \ + decode_renew_maxsz) #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \ encode_sequence_maxsz + \ encode_putfh_maxsz + \ @@ -1981,6 +2009,30 @@ static void encode_sequence(struct xdr_stream *xdr, } #ifdef CONFIG_NFS_V4_1 +static void +encode_get_dir_delegation(struct xdr_stream *xdr, struct compound_hdr *hdr) +{ + __be32 *p; + struct timespec64 ts = {}; + u32 zerobm[1] = {}; + + encode_op_hdr(xdr, OP_GET_DIR_DELEGATION, decode_get_dir_delegation_maxsz, hdr); + + /* We can't handle CB_RECALLABLE_OBJ_AVAIL yet */ + xdr_stream_encode_bool(xdr, false); + + /* for now, we request no notification types */ + xdr_encode_bitmap4(xdr, zerobm, ARRAY_SIZE(zerobm)); + + /* Request no attribute updates */ + p = reserve_space(xdr, 12 + 12); + p = xdr_encode_nfstime4(p, &ts); + xdr_encode_nfstime4(p, &ts); + + xdr_encode_bitmap4(xdr, zerobm, ARRAY_SIZE(zerobm)); + xdr_encode_bitmap4(xdr, zerobm, ARRAY_SIZE(zerobm)); +} + static void encode_getdeviceinfo(struct xdr_stream *xdr, const struct nfs4_getdeviceinfo_args *args, @@ -2334,6 +2386,25 @@ static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr, encode_nops(&hdr); } +/* + * Encode GDD_GETATTR request + */ +static void nfs4_xdr_enc_gdd_getattr(struct rpc_rqst *req, struct xdr_stream *xdr, + const void *data) +{ + const struct nfs4_getattr_arg *args = data; + struct compound_hdr hdr = { + .minorversion = nfs4_xdr_minorversion(&args->seq_args), + }; + + encode_compound_hdr(xdr, req, &hdr); + encode_sequence(xdr, &args->seq_args, &hdr); + encode_putfh(xdr, args->fh, &hdr); + encode_get_dir_delegation(xdr, &hdr); + encode_getfattr(xdr, args->bitmask, &hdr); + encode_nops(&hdr); +} + /* * Encode a CLOSE request */ @@ -5919,6 +5990,43 @@ static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) return decode_stateid(xdr, stateid); } +static int decode_get_dir_delegation(struct xdr_stream *xdr, + struct nfs4_getattr_res *res) +{ + nfs4_verifier cookieverf; + int status; + u32 bm[1]; + + status = decode_op_hdr(xdr, OP_GET_DIR_DELEGATION); + if (status) + return status; + + if (xdr_stream_decode_u32(xdr, &res->nf_status)) + return -EIO; + + if (res->nf_status == GDD4_UNAVAIL) + return xdr_inline_decode(xdr, 4) ? 0 : -EIO; + + status = decode_verifier(xdr, &cookieverf); + if (status) + return status; + + status = decode_delegation_stateid(xdr, &res->deleg); + if (status) + return status; + + status = decode_bitmap4(xdr, bm, ARRAY_SIZE(bm)); + if (status < 0) + return status; + status = decode_bitmap4(xdr, bm, ARRAY_SIZE(bm)); + if (status < 0) + return status; + status = decode_bitmap4(xdr, bm, ARRAY_SIZE(bm)); + if (status < 0) + return status; + return 0; +} + static int decode_getdeviceinfo(struct xdr_stream *xdr, struct nfs4_getdeviceinfo_res *res) { @@ -6455,6 +6563,33 @@ static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr, return status; } +/* + * Decode GDD_GETATTR response + */ +static int nfs4_xdr_dec_gdd_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr, + void *data) +{ + struct nfs4_getattr_res *res = data; + struct compound_hdr hdr; + int status; + + status = decode_compound_hdr(xdr, &hdr); + if (status) + goto out; + status = decode_sequence(xdr, &res->seq_res, rqstp); + if (status) + goto out; + status = decode_putfh(xdr); + if (status) + goto out; + status = decode_get_dir_delegation(xdr, res); + if (status) + goto out; + status = decode_getfattr(xdr, res->fattr, res->server); +out: + return status; +} + /* * Encode an SETACL request */ @@ -7704,6 +7839,7 @@ const struct rpc_procinfo nfs4_procedures[] = { PROC41(BIND_CONN_TO_SESSION, enc_bind_conn_to_session, dec_bind_conn_to_session), PROC41(DESTROY_CLIENTID,enc_destroy_clientid, dec_destroy_clientid), + PROC41(GDD_GETATTR, enc_gdd_getattr, dec_gdd_getattr), PROC42(SEEK, enc_seek, dec_seek), PROC42(ALLOCATE, enc_allocate, dec_allocate), PROC42(DEALLOCATE, enc_deallocate, dec_deallocate), diff --git a/include/linux/nfs4.h b/include/linux/nfs4.h index 11ad088b411d..86cbfd50ecd1 100644 --- a/include/linux/nfs4.h +++ b/include/linux/nfs4.h @@ -681,6 +681,7 @@ enum { NFSPROC4_CLNT_LISTXATTRS, NFSPROC4_CLNT_REMOVEXATTR, NFSPROC4_CLNT_READ_PLUS, + NFSPROC4_CLNT_GDD_GETATTR, }; /* nfs41 types */ diff --git a/include/linux/nfs_xdr.h b/include/linux/nfs_xdr.h index d09b9773b20c..85ee37ccc25e 100644 --- a/include/linux/nfs_xdr.h +++ b/include/linux/nfs_xdr.h @@ -1072,6 +1072,8 @@ struct nfs4_getattr_res { struct nfs4_sequence_res seq_res; const struct nfs_server * server; struct nfs_fattr * fattr; + nfs4_stateid deleg; + u32 nf_status; }; struct nfs4_link_arg { From patchwork Fri Mar 15 16:53:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13593706 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 E6E215F552; Fri, 15 Mar 2024 16:54:17 +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=1710521658; cv=none; b=dBJp9vyfrzmDXm+U8UNWK/taPZ7w+lRIcVaUFDuOLhK2QTQUbBQdB1Tw5uTMaZt5ntlkacpqSvqeERtQ8meeIbBQh5najxrKg4wdujynddon+u/+tsMrgjUuly0Mad4p/8zqp2uM+w4wzEirNlnZW8fkXzJDoYsGvgDa8dKcSD0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710521658; c=relaxed/simple; bh=cwlCJIwXq4jLYj8xEadkur+JgJytFkV45+NwlxKS2a8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ubs367vwC/T4JJZQiQV4Z6+M2WzllvedS2tLALXpsQGLLbtM1lkGxBXtPtB3RTLI6xfFSINng5e6wBQTfMlD8iFdL6JWqxGJa67On2FoKSp5qcva7etwEBHW7TQoSX/pN8br29K+jljP3WELN57qUx1O1RUq5gL5+g6A6rljN5g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tPqL1sgn; 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="tPqL1sgn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 81FF7C43399; Fri, 15 Mar 2024 16:54:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710521657; bh=cwlCJIwXq4jLYj8xEadkur+JgJytFkV45+NwlxKS2a8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=tPqL1sgnIbKuNXMdfr6Nq20Jxh4ZY8k3BC/LIY8ogvxyKLhNu0pFcUKaUZXIRADB9 LtNZUmZhMG7uOJXJBAKgInIZZruVxf/w2KdWIqEm1qq29EfLCKGcXgQweQc8snGBcx KR+fDqHBDmqxBeejTd7wRXW/JVOpiJv2sVmhZJDtHBR95sDA68tTLjpCsMlwpJVKXM Ec6oNeT4luagh4UXxg8T+hXPd11kiIF7m+mTAkYQSdf6HnsSVeWCMZf92j3Fx8HsvD xOv8xowmAZwYC3Xba10LT5vwbn1G8bf23UyuaMXLqGlr3a+qBnsgPmFv23o03/QHK2 JWlp6rWlExcZw== From: Jeff Layton Date: Fri, 15 Mar 2024 12:53:13 -0400 Subject: [PATCH RFC 22/24] nfs: skip dentry revalidation when parent dir has a delegation Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240315-dir-deleg-v1-22-a1d6209a3654@kernel.org> References: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> In-Reply-To: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Chuck Lever , Alexander Aring , Trond Myklebust , Anna Schumaker , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Greg Kroah-Hartman , "Rafael J. Wysocki" , David Howells , Tyler Hicks , Neil Brown , Olga Kornievskaia , Dai Ngo , Miklos Szeredi , Amir Goldstein , Namjae Jeon , Sergey Senozhatsky , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, netfs@lists.linux.dev, ecryptfs@vger.kernel.org, linux-unionfs@vger.kernel.org, netdev@vger.kernel.org, Jeff Layton X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1400; i=jlayton@kernel.org; h=from:subject:message-id; bh=cwlCJIwXq4jLYj8xEadkur+JgJytFkV45+NwlxKS2a8=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBl9HzvUGXRZhpo+O5qRvOO/lXxItvQyNLMF8p79 zQf7Owopu+JAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZfR87wAKCRAADmhBGVaC FdfPEACrH+59z1NoZpi+wFkOJRpdR/q/s3fax50n67RvHg1kVtQvAVxXOGBKmKtnKX76SZTgO+H 6x/qrY7yukKkFiqdZb7ovq74b6xgfzdl/UKCTRntf/TkkdbmYF3TyWSdweJSVakj2bMXDxZMlW9 F6ezSmEPaEpTnQZ/1jBJ4x4UYAwV6nBKBFF4orFUjraxWjbE4PymCErndXXEIrbsT3psnzcL4OO 94j3ujIdoDBGoyRSIi/ecqEISHT9Ba728/gYtCtgf8/hlLXnMZaxRLEnUq9++B0AKj/CbcL19Yj xNqSsv4LxTjX9d/WoMy/paRt2jkgI3YYwg4eqZGB6+3gjsuKnmv2SACmOw41IIo7aFMGyGDT3jX XhPrlvFuP2l9nJvHvGH5hi0WEQ0owON4os9IaXwcU4SWeukYhv5HJOfkwrvIGgjrPC+CM7lt9yH xBkU/7rqPMe2+kuIhYjDW8X8myF7StjHbfZb9ANxGYDRzcAkzeQtc1tUaUTn4v7MmQW65kr4Xth yEgpKlKSixMD9QfvSCaUPp4Go8X5tzipgwGU91IfNP7bJgvz+oWMi3VX6Cj4ehAXIlHgHOSy68S znaKqznDxWnxikviYE+FXPJW1Ov13luk71gN2iPY189OJdP0ypVIxXcShOFnhOw8e+Z+tMA4/Yb WKQM8jp5lLcH/mg== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 If the parent has a valid delegation, then test whether the dentry->d_time matches the current change attr on the directory. If it does, then we can declare the dentry valid with no further checks. Signed-off-by: Jeff Layton --- fs/nfs/dir.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index ac505671efbd..061648c73116 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -2188,6 +2188,15 @@ int nfs_atomic_open(struct inode *dir, struct dentry *dentry, } EXPORT_SYMBOL_GPL(nfs_atomic_open); +static int +nfs_lookup_revalidate_delegated_parent(struct inode *dir, struct dentry *dentry, + struct inode *inode) +{ + return nfs_lookup_revalidate_done(dir, dentry, inode, + nfs_verify_change_attribute(dir, dentry->d_time) ? + 1 : 0); +} + static int nfs4_do_lookup_revalidate(struct inode *dir, struct dentry *dentry, unsigned int flags) @@ -2212,6 +2221,9 @@ nfs4_do_lookup_revalidate(struct inode *dir, struct dentry *dentry, if (nfs_verifier_is_delegated(dentry)) return nfs_lookup_revalidate_delegated(dir, dentry, inode); + if (nfs_have_delegated_attributes(dir)) + return nfs_lookup_revalidate_delegated_parent(dir, dentry, inode); + /* NFS only supports OPEN on regular files */ if (!S_ISREG(inode->i_mode)) goto full_reval; From patchwork Fri Mar 15 16:53:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13593707 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 C71055FBAE; Fri, 15 Mar 2024 16:54:20 +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=1710521660; cv=none; b=ogFrxk3gx10Oa2z4uo2KbyjyBn73YNrxnJRQqre3vlZwpLzQF+QKpFp3a3iqq+VQPTAIxDXW1+lRler3rKULnWNtX1Zws2wbVlYeTow5dpPRTSvAIhfho7ShsZvvdoPDzu+HhNvzJErsWNQY7x8mcIBzs6jgoIB5T3griWTehtU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710521660; c=relaxed/simple; bh=HqSajQkHgNfbJ2Z8x7T3Rdj/LkayLnr5zzZhTW9vu30=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=UJrz1xiwAEnICNAzdVeaV2qcBdGYtn89wIYBjBhdFcbuWNomw5orr9WZ0MP2Majd0DtDiGTbKS9TKUsSRanERR2WVe5viOsQ/sFZ1h7iKRclPM9Y+3y7uHCkQriFimuhHrIPX7Y2fJZdXUIfj9M+lzFToK7321ADftqbyIK4N4U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Aw/sJ1Iw; 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="Aw/sJ1Iw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4A32C43394; Fri, 15 Mar 2024 16:54:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710521660; bh=HqSajQkHgNfbJ2Z8x7T3Rdj/LkayLnr5zzZhTW9vu30=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Aw/sJ1IwefqKWawHzfrH/1WUpi/69CvZgmL2U0hJ7IsoJviGRY+iLZmVI3HTdHOYc Kf6mfyhTCQkuwK91mJ5heipQR+LtkfltMmkEVd6ayaXuxTlLnQLde92wiLZYkFMYJO lKQ7vjqEcyThCrZLWKJLmB9Gph5bR5fBp+ybSzM5ePoC8Nc3UFU4BQM4JGqwagVRIP 017L5h4miRCjpRdM8sCNPmicWGmKabzsP+PlywSZzciHEnKuk/hmq7mNl6wMPfbI9x el0vlSZ3CN4FxSorWi3kU72bjpQqjUOsVsqCdSpCsYeF+PkJKXh21rh0kmCnKGhx59 tDzE6m31nz+Uw== From: Jeff Layton Date: Fri, 15 Mar 2024 12:53:14 -0400 Subject: [PATCH RFC 23/24] nfs: optionally request a delegation on GETATTR Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240315-dir-deleg-v1-23-a1d6209a3654@kernel.org> References: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> In-Reply-To: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Chuck Lever , Alexander Aring , Trond Myklebust , Anna Schumaker , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Greg Kroah-Hartman , "Rafael J. Wysocki" , David Howells , Tyler Hicks , Neil Brown , Olga Kornievskaia , Dai Ngo , Miklos Szeredi , Amir Goldstein , Namjae Jeon , Sergey Senozhatsky , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, netfs@lists.linux.dev, ecryptfs@vger.kernel.org, linux-unionfs@vger.kernel.org, netdev@vger.kernel.org, Jeff Layton X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=6739; i=jlayton@kernel.org; h=from:subject:message-id; bh=HqSajQkHgNfbJ2Z8x7T3Rdj/LkayLnr5zzZhTW9vu30=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBl9HzvFjVT4jXwJdhnMv42oNu0gHhdRkwCaXeCy BE5PQkA5DmJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZfR87wAKCRAADmhBGVaC Fa6HEADKSei76E9Guc9KUDVOm1qUI7V0l7prDFGS2AkZrmx2axqtOUlPABnSWhKDVlSGtMvrrp1 GyhF58ODp0WXw1+XtWzbWzt6YYxJBJKjixjPnCYQzba8NY9Abr6lVD8rgkLD2dblTmitOqJzToA GzfKMW+9jSOWl9x/+QKBqB9cV6YJQbYN+iHLGZR1z/kquhYk38RASDbihV167/IsbMJyOBgUi98 kX1gG/uwsT88Ir9webAnGT/lzDHIB9VxmOp++twBDIEaVCx1sVk9p8Xl+14Pu+oG7j/pz5ksLkv 54AmD8cDltnbpmfrm5tA8RUg5wnGge/LFnAtUSZoqXYrPQJW2f3s0o7U2HCz74aImGkK8j681Hv r/SczzwcVYVuJb1j3kPwa8/W/ODmajDxA8X7KSbJH1wPp1wOfz1jdxFWHQ/8DXxx1PrlHCzZ8NP OJ5veH9r/utlO0qhliLkIy3OI5LLn53/GpByjKnXHEQCr8xxgRsPXc/uzzLsU0Ij6RzvmbDbJpg aI5rkT9Xkf1Jnwaxryyh73T1t/7b/8cf4XD9SykoaYdkP59TkfLgYwDdntlTmeMpvq8Q2JOq/vo SOSUmXirsZTFUaZUVW6OBA8EjFSNOTPE/EYGjQ0kaD8vIjPPo2IMMXERbK2clBXsoMjbpkf8OK8 QoQSuL9P4g83Fig== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 We expect directory delegations to most helpful when their children have frequently revalidated dentries. The way we usually revalidate them is to check that the dentry's d_time field matches the change attribute on the parent. Most dentry revalidations that have to issue an RPC end up as a GETATTR on the wire for the parent, if the parent hasn't changed, then the dentry is fine. Add a new NFS_INO_GDD_GETATTR flag to the nfsi->flags field. Whenever we validate a dentry vs. its parent, set that flag on the parent. Then, when we next do a GETATTR vs. the parent, test and clear the flag and do a GDD_GETATTR if it was set. If the the GET_DIR_DELEGATION succeeds, set the delegation in the inode. Finally, a lot of servers don't support GET_DIR_DELEGATION, so add a NFS_CAP_* bit to track whether the server supports it, and enable it by default on v4.1+, and retry without a delegation if we get back an ENOTSUPP. Signed-off-by: Jeff Layton --- fs/nfs/delegation.c | 1 + fs/nfs/dir.c | 8 ++++++++ fs/nfs/nfs4proc.c | 45 ++++++++++++++++++++++++++++++++++++++++++--- include/linux/nfs_fs.h | 1 + include/linux/nfs_fs_sb.h | 1 + 5 files changed, 53 insertions(+), 3 deletions(-) diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c index 88dbec4739d3..14c14bd03465 100644 --- a/fs/nfs/delegation.c +++ b/fs/nfs/delegation.c @@ -356,6 +356,7 @@ nfs_detach_delegation_locked(struct nfs_inode *nfsi, delegation->inode = NULL; rcu_assign_pointer(nfsi->delegation, NULL); spin_unlock(&delegation->lock); + clear_bit(NFS_INO_GDD_GETATTR, &nfsi->flags); return delegation; } diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index 061648c73116..930fe7e14914 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -1504,12 +1504,20 @@ static int nfs_dentry_verify_change(struct inode *dir, struct dentry *dentry) static int nfs_check_verifier(struct inode *dir, struct dentry *dentry, int rcu_walk) { + struct nfs_inode *nfsi = NFS_I(dir); + if (IS_ROOT(dentry)) return 1; if (NFS_SERVER(dir)->flags & NFS_MOUNT_LOOKUP_CACHE_NONE) return 0; if (!nfs_dentry_verify_change(dir, dentry)) return 0; + /* + * The dentry matches the directory's change attribute, so + * we're likely revalidating here. Flag the dir so that we + * ask for a delegation on the next getattr. + */ + set_bit(NFS_INO_GDD_GETATTR, &nfsi->flags); /* Revalidate nfsi->cache_change_attribute before we declare a match */ if (nfs_mapping_need_revalidate_inode(dir)) { if (rcu_walk) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index d518388bd0d6..3dbe9a18c9be 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -4318,6 +4318,21 @@ static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, return status; } +static bool should_request_dir_deleg(struct inode *inode) +{ + if (!inode) + return false; + if (!S_ISDIR(inode->i_mode)) + return false; + if (!nfs_server_capable(inode, NFS_CAP_GET_DIR_DELEG)) + return false; + if (!test_and_clear_bit(NFS_INO_GDD_GETATTR, &(NFS_I(inode)->flags))) + return false; + if (nfs4_have_delegation(inode, FMODE_READ)) + return false; + return true; +} + static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr, struct inode *inode) { @@ -4331,11 +4346,12 @@ static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, .server = server, }; struct rpc_message msg = { - .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], .rpc_argp = &args, .rpc_resp = &res, }; unsigned short task_flags = 0; + bool gdd; + int status; if (nfs4_has_session(server->nfs_client)) task_flags = RPC_TASK_MOVEABLE; @@ -4344,11 +4360,32 @@ static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, if (inode && (server->flags & NFS_MOUNT_SOFTREVAL)) task_flags |= RPC_TASK_TIMEOUT; +retry: + gdd = should_request_dir_deleg(inode); + if (gdd) + msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GDD_GETATTR]; + else + msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR]; + nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, fattr->label), inode, 0); nfs_fattr_init(fattr); nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); - return nfs4_do_call_sync(server->client, server, &msg, - &args.seq_args, &res.seq_res, task_flags); + status = nfs4_do_call_sync(server->client, server, &msg, + &args.seq_args, &res.seq_res, task_flags); + switch (status) { + case 0: + if (gdd && res.nf_status == GDD4_OK) + status = nfs_inode_set_delegation(inode, current_cred(), FMODE_READ, + &res.deleg, 0); + break; + case -ENOTSUPP: + /* If the server doesn't support GET_DIR_DELEGATION, retry without it */ + if (gdd) { + server->caps &= ~NFS_CAP_GET_DIR_DELEG; + goto retry; + } + } + return status; } int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, @@ -10552,6 +10589,7 @@ static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { .minor_version = 1, .init_caps = NFS_CAP_READDIRPLUS | NFS_CAP_ATOMIC_OPEN + | NFS_CAP_GET_DIR_DELEG | NFS_CAP_POSIX_LOCK | NFS_CAP_STATEID_NFSV41 | NFS_CAP_ATOMIC_OPEN_V1 @@ -10578,6 +10616,7 @@ static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { .minor_version = 2, .init_caps = NFS_CAP_READDIRPLUS | NFS_CAP_ATOMIC_OPEN + | NFS_CAP_GET_DIR_DELEG | NFS_CAP_POSIX_LOCK | NFS_CAP_STATEID_NFSV41 | NFS_CAP_ATOMIC_OPEN_V1 diff --git a/include/linux/nfs_fs.h b/include/linux/nfs_fs.h index f5ce7b101146..5140e4dac98a 100644 --- a/include/linux/nfs_fs.h +++ b/include/linux/nfs_fs.h @@ -318,6 +318,7 @@ struct nfs4_copy_state { #define NFS_INO_LAYOUTCOMMITTING (10) /* layoutcommit inflight */ #define NFS_INO_LAYOUTSTATS (11) /* layoutstats inflight */ #define NFS_INO_ODIRECT (12) /* I/O setting is O_DIRECT */ +#define NFS_INO_GDD_GETATTR (13) /* Ask for dir deleg on next GETATTR */ static inline struct nfs_inode *NFS_I(const struct inode *inode) { diff --git a/include/linux/nfs_fs_sb.h b/include/linux/nfs_fs_sb.h index 92de074e63b9..0ab744cf52d7 100644 --- a/include/linux/nfs_fs_sb.h +++ b/include/linux/nfs_fs_sb.h @@ -278,6 +278,7 @@ struct nfs_server { #define NFS_CAP_LGOPEN (1U << 5) #define NFS_CAP_CASE_INSENSITIVE (1U << 6) #define NFS_CAP_CASE_PRESERVING (1U << 7) +#define NFS_CAP_GET_DIR_DELEG (1U << 13) #define NFS_CAP_POSIX_LOCK (1U << 14) #define NFS_CAP_UIDGID_NOMAP (1U << 15) #define NFS_CAP_STATEID_NFSV41 (1U << 16) From patchwork Fri Mar 15 16:53:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13593708 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 4C6745FBB8; Fri, 15 Mar 2024 16:54:24 +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=1710521664; cv=none; b=AvNcAEhHh5sQ/HsvNoqB5boBaSqCUExkS0ICuGsJbN4l7dOJo/kT7VNCrCeFjSbnyppfyEKWIN9PTMB3vN5ZvDhnsam55ffg/fJKAK41XoKNTfLbtHTcoSHuFijy0WYghxzv3waOGiyMwgYE4utSIBMSuiHWbPVhN4sWn8KG1jg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710521664; c=relaxed/simple; bh=StkPzzZHH/6sgQn/lGKnzt3PeV9NBoE/z0Ovl4GDfww=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aH6OrAZik8HVA9aMovi+Q2SMgnz2+eCpORSl8T247mpwbDMVwCUijTzIH40LWeU2/NrGi/QVPJ5u4GcTbqRQi8RB6I01doJW+TBtgMdlyz8PiSQjDIOyN/YVV4zwahmirU2q/gTjxjtHPfn7h0Gml+vQKW8+P/Y92RXMQYSWNec= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hk+BlFs/; 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="hk+BlFs/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E62B1C43399; Fri, 15 Mar 2024 16:54:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710521663; bh=StkPzzZHH/6sgQn/lGKnzt3PeV9NBoE/z0Ovl4GDfww=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=hk+BlFs/46YBuOmmaTEQkfxTZxnnerqXEMm+Xem5ye8UtB1tdpiAgNHDunBA5g8tX xMzHDC9pxO+cN0tsSjEOtLC3r2u2fOrpfR3BYWwTpSMsoHzRwugShAWfxFYIwL4Fbx 2PwC/PmPU64fqM+r7W80cE/1eGlC/TIHqNIqWUPvZZSzZTV7h8E+3aAhSATMKmKuY7 wmQ9jnP3Cl6opaoLow/Zv4v41dm5J8jCjlvPyIZPfeTxuvf5gKTg3t7kNaVAX0uAuz hcxDc2EFXKgXFYR6VWLS7koCod9Ycxe5HjaeSXVIiLL7MD6RtP5ZycJ702c2x57eZe fcwaUwmp3t4Zg== From: Jeff Layton Date: Fri, 15 Mar 2024 12:53:15 -0400 Subject: [PATCH RFC 24/24] nfs: add a module parameter to disable directory delegations Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240315-dir-deleg-v1-24-a1d6209a3654@kernel.org> References: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> In-Reply-To: <20240315-dir-deleg-v1-0-a1d6209a3654@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Chuck Lever , Alexander Aring , Trond Myklebust , Anna Schumaker , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Greg Kroah-Hartman , "Rafael J. Wysocki" , David Howells , Tyler Hicks , Neil Brown , Olga Kornievskaia , Dai Ngo , Miklos Szeredi , Amir Goldstein , Namjae Jeon , Sergey Senozhatsky , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, netfs@lists.linux.dev, ecryptfs@vger.kernel.org, linux-unionfs@vger.kernel.org, netdev@vger.kernel.org, Jeff Layton X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=898; i=jlayton@kernel.org; h=from:subject:message-id; bh=StkPzzZHH/6sgQn/lGKnzt3PeV9NBoE/z0Ovl4GDfww=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBl9Hzvnm7j0meGlRrWzgXFZfUMFw6VkWwUuEoG4 wZ3oi+xA5mJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZfR87wAKCRAADmhBGVaC FUYcEADP07H5ISVCANeNprhNf4hZQPgKVBg3xSg77ohhLcb2ru884PWGa4XdW65vfN4NAIfhart wRbEXNPv6moeTSg5QUn86pEHa1UCSx0Jo4c+ZXmTqlBTHiHCoPs9UoC0+lKIbgA2+WqQnhruNSw ExBSumhHvhDtKfJrDuiPX9Y1+2EGIZ6n3l1zFv4Gvfw4Wp63Ta2lHLgLdXTlfT11hacg0bflVfG DYCn3WrpI/jXOYWyIxSv1iVDUMGP61SuF8OAkB90fImIl8yVQM8g1Swz42Qmq1BJIorWlnxBMO/ SYG38TiIL46dL5C7etD+9kZZlfHRQLFaAnzimJpq9AOhIzC2C1OlTzCyCpkip1Uh+BK2iDlSksh PHb4oUnakFjG/tJ4yQI+gMsd0/x3W7pQcLpe+Gghd3RyMxw7v06ZcKVb6DzhwFO7y/Le1Bxv/uh igvya5ZrOiRtyD7v4gUx2ICKDQIZrVbbJXTVsWAzthXQBsPbS8d/v9Cwtgpf+68HMuVWv9trceB rlfKd7jv+5ciGtBQc7Nj1/quh7QD5GOIFOncB8nPcyNnmc87y6kxn1tJA59WV/XFIFHMq+pWCp7 j5huGMP0IVakAbwQdmjqnx4kQO5aZ8T0DC2Rd82lm8TaqCgRrXuJnlQB7oTw4ept4UypzTsCxwU Zmx1EZYZozo7PFg== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 For testing purposes, add a module parameter that will prevent the client from requesting further directory delegations. Signed-off-by: Jeff Layton --- fs/nfs/nfs4proc.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 3dbe9a18c9be..a85a594cad88 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -4318,8 +4318,14 @@ static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, return status; } +static bool nfs_dir_delegation_enabled = true; +module_param(nfs_dir_delegation_enabled, bool, 0644); +MODULE_PARM_DESC(nfs_dir_delegation_enabled, "Enable directory delegations?"); + static bool should_request_dir_deleg(struct inode *inode) { + if (!nfs_dir_delegation_enabled) + return false; if (!inode) return false; if (!S_ISDIR(inode->i_mode))