From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=103.168.172.157 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796191578; b=wysLhtS0aZEx7p5vx2pkhRcgSp0n3gKwoG8SlGvsMqr3MRluoWjUOPS5wABXcbc1KxP1 WNOM7YodqTtrph8xHWrXhQlC19ISWFVb6+zghefxJXVKlQiYq3j2gmrI4mf5TGpLcFPGa Vs5UILvesyIq6Bq9K4Jkn8oIgfM0VTSG3JvyIdhPJMguITfOFGQnYS3aAIA6/kOBGNibE IWEjtCLB7/xgNsmVzVrqs993Hxhv4/55KhfgPmZsursBCZEFR0TJ99WuDhtCjJpnN3Mxf NdcGRpKqQaHoqFe3QsPR1JnbiHGQKTV0hvOtk6lD8vB3IhGjtvU0ptjB9ygHad5OmHg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796191578; 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=CmyZxB8rRWQh+UalulOaqaR6hKhB428/pPRbqcHmOEc=; b=cs+1EiKDQL0ZyGUuKUQX6jB2GwsDH3JUQtWVnV7bWUjJWRWaIEwtYmDvz48DXhbOxVfj /hfbjNTo9CjD/192p8WCVi0wf7CQw2q8TEt4qR9eKJ2RaPWF+zs3y+IcmMsTbXYT0vCmR K5hc3qQYpgz2Eykzo5eUUIogSOx9EXAFYPgsNQQsyEIm4/j+nipCPmZaLYLn1OOwI5e2l 3DJu8Tq8kegUmD7YNhDQSA/MH0zVz/TrIFmNzu/6VAgn6gL63EADSHtF/KdvZAfoX+3F6 V9PFArVvXfUnn31YKFAjXeZB1OAbWwJ5oEqUeEPS4s+anUmcgQCmobMQf1XhlpnV6kw== 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=IDZSerYj; dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=PHwMqY26; arc=none smtp.remote-ip=103.168.172.157 Received: from fhigh-a6-smtp.messagingengine.com (fhigh-a6-smtp.messagingengine.com [103.168.172.157]) (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 4146B606A32D for ; Wed, 2 Dec 2026 06:06:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4146B606A32D 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=IDZSerYj; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=PHwMqY26 Received: from phl-compute-03.internal (phl-compute-03.internal [10.202.2.43]) by mailfhigh.phl.internal (Postfix) with ESMTP id 7B0ED1400195 for ; Wed, 2 Dec 2026 01:06:17 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-03.internal (MEProxy); Wed, 02 Dec 2026 01:06:17 -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=1796191577; x=1796277977; bh=CmyZxB8rRWQh+UalulOaqaR6hKhB428/pPRbqcHmOEc=; b= IDZSerYjIZq7CNNqWbLntOb/YGGTSGP9ct1PTqE2Qo8r80F1GnP+VmEw0IEIHvNB QCgXMhA/CMy7qkKkzrB/JS86b/nKdVbawnqlybD0a9MYQH3MrsCvWNma8dfmLILn 4T98SGS5zvBzHo+U6qX0fPTVzM6Nof3n+N2T0i6qRha4/2792QVF2Ih/2V3pNWIA 3daF/U3bkFPsDzT0gUjY+Rp+j4GC3bJACOImN7FbvKqpTX2XMVCa1ezyqgEdcvQm W5VBxzzfnwRK8HdzzSaH/nc4bc0ILv91pbR5puZaD/jb9p+jDMBiEOfSydlyfHj+ Cyr9NuGOJnAejj1fHbd3aA== 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=1796191577; x=1796277977; bh=C myZxB8rRWQh+UalulOaqaR6hKhB428/pPRbqcHmOEc=; b=PHwMqY26u5+ukw2rS ejirh7YVWWsv4+cx3Ma2lnn8fs9UA8Cwg3GSJ/PGldKFMf62uw6gGLdAcXmYlirn 9pjsZy2hvT6JMzZI2dV/C6Q0rSwvbHR5tgue81HdHda+RZ70JJ9ADIokv2m2CO8z apu32SaY/Sa7Ddt/58mDIDJHFgC5JUjyFRH7dDdPneJ5jV4NxGkVePIblvW2m6Rh fVdfyY465eOo++aQEWzWUqSDWWrWP3a4FPSJvi3myCy6h3FGjFLFsr1G1QT2+dEQ 1ERYA2eiNMIWT8NxWl8UQsa8j3QGKQc42quH4LCeFCyfzYhI4plWG6BbHVYwxThe 7olqA== 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=1796191577; d=ownmail.net; mf=PG5laWxiQG93bm1haWwubmV0Pg==; rt=PGxpbnV4LWtlcm5lbEB2Z2VyLmtlcm5lbC5vcmc+; s=fm3:rsa-sha256:Ax/kj1dWiwGEkIGRyAsKYVWoDUKt9YArtgr1FEKeBvvwLXa 6I5XTDf6M5oO/ug1U6/tHPEIyT6HtWMB/H/7vwRJ9iky04C2QhNXmEHlozEEoTiv EM1+C9n6HbB00t64IHJ6O81tL60Q15I/lKnEvMh+32PeW0kgdOhDm2/JMtVwMyxl PkDW5MBIUTGaPMyTI1/8CLUpATb886ozRzmbTVoNauPlgs6diHs9ub7IaGIFOUcS 5qIJ7z9RI8eY794DZEYPQxjIIqNqrOrfctz8k+lvmSO5OLFE8kn/3eOqWnDNpTpu RTCKKli8DPG8A9VgxMQXZnooJtRwKpPn6MCatpA==; 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:OF6LrJTQiSiVEWYqW1gRHMvECpj59r/i1y844EZpRtc=:rN9A5YdPBQs982ru/w/PgGL8yckNJFQpeBxjsFPEJp0=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTF+3OE88EhpWgI/w8ZImZVa5l5gNXdydDFREH+BjT5PAYmO5emwdtJzpFPmeMwv5U CxnVE6L+FURKoWbTieGf1fBKUKx533eGPCAmmHX9cIHmAtgNv8wxVZUGezbyiP1o7gz89k YgzwTBEBUjT6tihNQK69HshojN/VJvSCyuAYFrKyx4FZLq6grF4sGokz9ZYhSbVupoKdcb 11BGaKA+H1KNQEftu9jrDfq/gaHKs7Qw66b6xDovlIiiJUNzUPrY23yihuoWDlojwfj+m7 aEYv7x6LnfUfyNLsRSAxztxFYo0sDqPyhNrKgRlRRT1ozZgTVijXPvS3oSH49uCc9/FKPj N/KQHWhyuGmw/fx+FBqgORqoi7ipij+VHfxXjwh7rbqfZbgkagrOOxbbPjzepppECY8Ag3 oTs+ZMhxuLETf5khFGK1CRtYYsr7+x+NaLQxS7iYl5HVmrQNb4Aef5MaAnZij+ClX7fRLA XGaCNdb2KSGXxCGq1y8VSa5lgHPVCTzlyaRvdfDg/qnbuBwfgCgDovHQZcjk8fYFR5o41H wenlk/G4kXgeqmwJLoumbsMfOKS2+NC762hqHFGxxvLuQwD7b3KfqDq3LU6t9lNT5Pp1KV 1DsR3H9m2bRd9WgtCHVlde59hgtj1d8qcKyD55DkpHLnPRbcU+X8d2yj+xyQ X-ME-Proxy: Feedback-ID: i9d664b8f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Wed, 2 Dec 2026 01:06:16 -0500 (EST) From: NeilBrown To: linux-kernel@vger.kernel.org Subject: [PATCH 1/8] vfs: revise and expand documentation for atomic_open. Date: Wed, 2 Dec 2026 17:05:01 +1100 Message-ID: <20261202060607.2627366-2-neilb@ownmail.net> X-Mailer: git-send-email 2.50.0.107.gf914562f5916.dirty In-Reply-To: <20261202060607.2627366-1-neilb@ownmail.net> References: <20261202060607.2627366-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 | 3 ++ 2 files changed, 59 insertions(+), 12 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 c79eecffe4ac..64ee0f7ef421 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -5133,6 +5133,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; base-commit: 84fb6f8a1ba91eee3ffe6aa519686fce851a0e42 -- 2.50.0.107.gf914562f5916.dirty