From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=202.12.124.150 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796256550; b=uzKmsGc0OSi6Pq9HkHgGAPlha4ZADBlibzjHM5d2NzBytaI0Rf+BEVExNUvRChaxYyN7 mzROctHFY/AhsfjzGSvxVN0tXN68vyIQIg2lpFYzUvU5l7EJAx9lqd348t6slevN9+9oQ MlAYtfQN2O2smBBm/ygR1sPZ0crDs/8rEwLNS7+TQ0opfmA2lDaJRPspLkcNaJ/sZmEQU sWo2kYKzcks44QREjGrK+lmef8HGGZcHJkdvsNzJ/j1rwgvg8aeUhw/HfSEWTToH49I7F 0sGhttIQFYXoRFuFXQMnhIVaJUBfqgZiPLjSA/sT+pFxc9iaIdOrO6kVAsOKLGJTjtg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796256550; h=DMARC-Filter:Received:Received:DKIM-Signature:DKIM-Signature: X-DKIM2-Info:DKIM2-Signature:X-DKIM2-Info:Message-Instance: X-ME-Sender:X-ME-Received:X-ME-Proxy-Cause:X-ME-Proxy:Feedback-ID: Received:From:To:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:Reply-To:MIME-Version:Content-Transfer-Encoding; bh=BZ8J/lEOvNLF3sQ8z08dRu8MIFScXLkLnbjwa0ot1y0=; b=j9rwubRg1DjW0t7rxA9HIE/rhfGDCHxTpb5vgiaUcfgh7VCN0jmaq8igMw4yKIg0+qQu kUlJWBzYQgrCFEpzBM26dObQIS3fbY7zRAGUjIf4dLlVuaP1HfkdOLYt5c25QGWD0PLOe JuMe8dCinMuM3FaTtFTEz6tx/XtQfT+kKgyfSlO0MGLn6GiCyjpuqOHYSiiphajJrdCTh WjXcPBJM1F/nCpos3ZvuHlQs0Gqn79EkR6zVZ/yUD1fG7TH2VrLXfo4F1UVXqau1PHW1K yi58oMq43iYMfCH2VukJMj0NQHWvmNdrGg1ONLOjYzAZZgvjVoa+t+9rNn52+L0omew== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=ownmail.net; spf=pass smtp.mailfrom=ownmail.net; dkim=pass header.d=ownmail.net header.i=@ownmail.net header.a=rsa-sha256 header.s=fm3 header.b=0vK5nY2V; dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=1CV3mjmt; arc=none smtp.remote-ip=202.12.124.150 Received: from fout-b7-smtp.messagingengine.com (fout-b7-smtp.messagingengine.com [202.12.124.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA1B1606A322 for ; Thu, 3 Dec 2026 00:09:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AA1B1606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ownmail.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ownmail.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=ownmail.net header.i=@ownmail.net header.a=rsa-sha256 header.s=fm3 header.b=0vK5nY2V; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=1CV3mjmt Received: from phl-compute-02.internal (phl-compute-02.internal [10.202.2.42]) by mailfout.stl.internal (Postfix) with ESMTP id 128F41D00210 for ; Wed, 2 Dec 2026 19:09:09 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Wed, 02 Dec 2026 19:09:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ownmail.net; h= cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:reply-to:subject:subject:to:to; s=fm3; t=1796256548; x=1796342948; bh=BZ8J/lEOvNLF3sQ8z08dRu8MIFScXLkLnbjwa0ot1y0=; b= 0vK5nY2VpTGYy+iJ/YmCcZ8BwC+yL4ME6e6XkJf7Z5gZXVwajk2Va6bqeWoyXjJy tzLmA2/szVUzwcDKRW6fDyNo0Jh3BfkssgBzhbu2dPnxR3q4Zr3gjChMj5+sJj8l OzPc46YeCf9+jbFqc4dYO1vyOFixWFPLzVZCa7/A3XhuQjpUTnCY1piDU7UEVYd2 y2PXq9nP3OoHr9Bd3NAosa9VBTV11u74j3RTcZmBBM8GHlMHmsAHauUNpEEUw6Lm OpWebq2WcVIeNEjjaTGJPS7phhLzn0mdMxs85PekB0b3SRr9smYGeCj9nO9xADoR 3hF0coDCPUwBVaPsy3FZ7A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:date:feedback-id:feedback-id:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1796256548; x=1796342948; bh=B Z8J/lEOvNLF3sQ8z08dRu8MIFScXLkLnbjwa0ot1y0=; b=1CV3mjmt5Nc+t5dp4 Rhubf6L+msjhVeILXKRMjKxA9DkkhEnXPnlfGuWbaa8Ule3XqCKBH2BVy60+vniw MhZg3hBwn9YUrmfC4LKm8br49DiQMn1hdZ3BQmcc/Qgg+mYkrJ79hDsPTytmv5aN EaOw3Q0t4U/embgs4wkiuRgfAUCJchF+NnCFe/K+YeloT7SxvIf3tgkGl1sEJQjY uVVZANUi9B4jDGj5AlthIHXkRHWiE1ood+Ar1Fg6QUeHdcgJyhfBlSu9SZnPiZki dca/M2vrJfGWqBUGI6fCKmOLQ63byGfG0xWiVbrCgq6C11CZ/mqhTZWp7vpZPVta T0shg== X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=sign d=ownmail.net a=rsa-sha256; DKIM2-Signature: i=1; m=1; t=1796256548; d=ownmail.net; mf=PG5laWxiQG93bm1haWwubmV0Pg==; rt=PGxpbnV4LWtlcm5lbEB2Z2VyLmtlcm5lbC5vcmc+; s=fm3:rsa-sha256:c6OVDeaR7Y7wt+u3p+YzZq5eFEWwpG6PF5o6wDSYDSr3MTo vOMzEF3o5FC3/QhWoeQLGSiRNDQDvaMkOsIPYA7AhCyPQ6+jC4kFzpJFItNJtF8x 0G083eK8ZDuWxGlcVx2WDyobCsBKgGj2Azcoj5AjYyGQnaGWrOxrZIjkhOEb2irT 5JdTZJdXm3XFxYL0/9/yvFhlXubDHaYpE2o+XBfdkorHFwihZ+wCaxby0Slyk1iX 4Yn+gsFCvCZSJh/lfIH9VsgKqdVs+b/Il0vVQzQGsZY9C0vv+4U09/4YzDUvMOQy 6NLeBkyIb828UEGYYXi+a0Dz45OSsZriUEkpyJw==; X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=mi-m=1; hc=11; hn=content-transfer-encoding,date,feedback-id,from,in-reply-to, message-id,mime-version,references,reply-to,subject,to; Message-Instance: m=1; h=sha256:GcFPFcg9KHTVwFIeu3bK17vWaFzMahVFS4UGJRRHi6c=:NlrFxZxHmSQV3hg3260D+9aJs5Cihwo+N2kVPRM0ORs=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTEI0yrQRdgErELF5Hqv1ypV8ueQNNQ5V0eKTlKo0OYu4O2CL9U2qzC/vJBhKexaf+ G6b78UGhGW9qHwD3z5bESHoECdQbAuGV7mxsrUiJWfX3JVpQIOcEvKq5MFlKN8p8CzzMnG nNw3z7/hzDbqA87fTN+mF6ixA2tk2ZMUd/8AdSdE73bDUBmKnSYf+FdYcFKNkl7seY8ZKe tqsV6mBjGyT+LY/66xwU28EJ8+jdi1Z7e/SYWj/jyGqM9+dL+5CYnCU6T2f/r170Fg66zD 7XZon78Y6jtDx/xZNhwAIcLuXf6bLtwdQ1QZfTGIgmXWeZRVc+oxZkI3uuJZUzwUyqtmZp VmnA+YD7rWWuzcTH25a64rphToglDGUv6cxCWQZ2bELA5rqsEbhm8fE4KzLGdEpRPkB9h0 b4Rzpv20MB/rhG0t1XSR7tHWVANFnTBpnNqbY115bT/Cu+nQO5xB4B9OG4le8UtcZdoFy5 Zi7vjZ+uYX8mMclteHugEKRcBGzSySvjGbf3B7ceIEFN4f2isB0LDxUUxGE7p4Y0K4omVi DgoG1BiAdGJBX0nFTAewrtCG/RwovS3eOjG0gJhKhpBu9MnWBPfr7JlV/W3gtcicqxdL2A QoJmODty8A8c2K32L33y6hdrTGtD7DPxXfEHU87rR6dRhBTuKrthCsV5TcBQ X-ME-Proxy: Feedback-ID: i9d664b8f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Wed, 2 Dec 2026 19:09:08 -0500 (EST) From: NeilBrown To: linux-kernel@vger.kernel.org Subject: [PATCH 2/9] vfs: revise and expand documentation for atomic_open. Date: Thu, 3 Dec 2026 11:07:57 +1100 Message-ID: <20261203000848.2986775-3-neilb@ownmail.net> X-Mailer: git-send-email 2.50.0.107.gf914562f5916.dirty In-Reply-To: <20261203000848.2986775-1-neilb@ownmail.net> References: <20261203000848.2986775-1-neilb@ownmail.net> Reply-To: NeilBrown X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: NeilBrown atomic_open is a complex operation which different filesystems implement quite differently. The available documentation doesn't give clear guidance on how it should be implemented. nfsd has a particular need to open only regular files, but to get precise information about what was found if it wasn't a regular file. This is slightly different to the syscall calling needs. In particular it suggests that __O_REGULAR shouldn't always result in -EFTYPE. In any case that does involve creating open state, using finish_no_open() is simplest as it reduces the need to check __O_REGULAR, O_DIRECTORY, O_NOFOLLOW. So refresh the documentation to give guidance on the choice between finish_no_open, finish_open, and an error. Efficiency always wins, but when that isn't an issue, prefer finish_no_open(). Also clarify the required behaviour when __O_REGULAR is given. This should return -EISDIR if a directory is found as nfsd needs this. If a symlink is found then __O_REGULAR does NOT apply: O_NOFOLLOW must be used to decided if it is safe to not return the looked-up dentry. Assorted improvements thanks to Andreas Gruenbacher Reviewed-by: Jeff Layton Signed-off-by: NeilBrown --- Documentation/filesystems/vfs.rst | 68 +++++++++++++++++++++++++------ fs/namei.c | 6 ++- 2 files changed, 61 insertions(+), 13 deletions(-) diff --git a/Documentation/filesystems/vfs.rst b/Documentation/filesystems/vfs.rst index 9ab182dbbd73..c1f3ea7aad67 100644 --- a/Documentation/filesystems/vfs.rst +++ b/Documentation/filesystems/vfs.rst @@ -600,18 +600,62 @@ otherwise noted. inode. ``atomic_open`` - called on the last component of an open. Using this optional - method the filesystem can look up, possibly create and open the - file in one atomic operation. If it wants to leave actual - opening to the caller (e.g. if the file turned out to be a - symlink, device, or just something filesystem won't do atomic - open for), it may signal this by returning finish_no_open(file, - dentry). This method is only called if the last component is - negative or needs lookup. Cached positive dentries are still - handled by f_op->open(). If the file was created, FMODE_CREATED - flag should be set in file->f_mode. In case of O_EXCL the - method must only succeed if the file didn't exist and hence - FMODE_CREATED shall always be set on success. + called on the last component of an open. This optional method + can look up, create, truncate, and open the file in one atomic + operation. This is needed if the filesystem content can change + asynchronously and specifically, if a negative dentry is not a + guarantee that the object doesn't exist. It is also useful if + combinations of revalidate, lookup, create, open, and truncate + can be performed more efficiently than with a sequence of + individual operations. + + If the object found is not a file or directory, or if + lookup/create succeeded without establishing any "open" state, + then finish_no_open() should be called to indicate that the + dentry is ready to be handled by normal VFS processing. + FMODE_CREATED should be set in file->f_mode if the object was + created; this will prevent further access permission checks and + handling of O_TRUNC and O_EXCL. + + If the lookup/create operation established some open state for a + file or directory, the operation should be completed by calling + finish_open(). Passing NULL as the "open" function to + finish_open() is unlikely to be useful as that assumes that no + open state has been established. + + atomic_open() may generate errors related to O_DIRECTORY, + __O_REGULAR, O_EXCL, O_NOFOLLOW, but is not required to as the + caller will check those against the resulting dentry and + generate any error needed, possibly closing the file if it was + opened by finish_open(). atomic_open() is encouraged to handle + these flags only when doing so is more efficient than not. + + If __O_REGULAR is handled, it should generate -EISDIR if the + name is known to be a directory, and -EFTYPE if it is some other + non-regular file other than a symbolic link. Handling of + symbolic links should be guided by O_NOFOLLOW, not __O_REGULAR: + -ELOOP can be returned if O_NOFOLLOW is set; otherwise the symlink + should be returned through finish_no_open(). + + The focus for atomic_open() is to provide the correct dentry and + to set FMODE_CREATED as accurately as possible. If O_EXCL is + set, FMODE_CREATED should only be set if this operation + certainly created the object. If O_EXCL is not set, + FMODE_CREATED should be set if it is possible that this operation + created the object. + + This method is only called if the last component is negative or + needs lookup. Cached positive dentries are still handled by + f_op->open(). + + If the dentry provided is negative (not in-lookup) and O_CREAT + isn't set, then there is no guarantee of exclusive access to the + dentry - another thread might call ->atomic_open() on the same + dentry at the same time. If needed, a filesystem can ensure this + doesn't happen by returning 0 from ->d_revalidate when that is + called with LOOKUP_OPEN on a negative dentry. This will ensure + that ->atomic_open() only receives an in-lookup dentry, which + always ensures exclusive access. ``tmpfile`` called in the end of O_TMPFILE open(). Optional, equivalent to diff --git a/fs/namei.c b/fs/namei.c index 5bf77dca0c53..b1abed93d17d 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -4932,7 +4932,8 @@ static int do_open(struct nameidata *nd, return error; } - if ((open_flag & __O_REGULAR) && !d_is_reg(nd->path.dentry)) + if ((open_flag & __O_REGULAR) && !d_is_reg(nd->path.dentry) + && !d_is_symlink(nd->path.dentry)) return -EFTYPE; if ((nd->flags & LOOKUP_DIRECTORY) && !d_can_lookup(nd->path.dentry)) @@ -5133,6 +5134,9 @@ static struct file *path_openat(struct nameidata *nd, error = -EINVAL; } fput_close(file); + if (error == -EISDIR && + (op->open_flag & __O_REGULAR)) + error = -EFTYPE; if (error == -EOPENSTALE) { if (flags & LOOKUP_RCU) error = -ECHILD; -- 2.50.0.107.gf914562f5916.dirty