Linux NFS development
 help / color / mirror / Atom feed
From: Konstantin Adzer <info@massivetech.ru>
To: Alexander Viro <viro@zeniv.linux.org.uk>,
	Christian Brauner <brauner@kernel.org>
Cc: Jonathan Corbet <corbet@lwn.net>,
	Shuah Khan <skhan@linuxfoundation.org>,
	Randy Dunlap <rdunlap@infradead.org>,
	Dan Williams <djbw@kernel.org>,
	Vishal Verma <vishal.l.verma@intel.com>,
	Dave Jiang <dave.jiang@intel.com>,
	Alison Schofield <alison.schofield@intel.com>,
	Eric Van Hensbergen <ericvh@kernel.org>,
	Latchesar Ionkov <lucho@ionkov.net>,
	Dominique Martinet <asmadeus@codewreck.org>,
	Christian Schoenebeck <linux_oss@crudebyte.com>,
	David Sterba <dsterba@suse.com>,
	David Howells <dhowells@redhat.com>,
	Marc Dionne <marc.dionne@auristor.com>,
	Luis de Bethencourt <luisbg@kernel.org>,
	Salah Triki <salah.triki@gmail.com>,
	Chris Mason <mason@kernel.org>, Ilya Dryomov <idryomov@gmail.com>,
	Alex Markuze <amarkuze@redhat.com>, Xiubo Li <xiubo.li@clyso.com>,
	Viacheslav Dubeyko <slava@dubeyko.com>,
	Jan Harkes <jaharkes@cs.cmu.edu>,
	coda@cs.cmu.edu, Nicolas Pitre <nico@fluxnic.net>,
	Tyler Hicks <code@tyhicks.com>, Gao Xiang <xiang@kernel.org>,
	Chao Yu <chao@kernel.org>, Yue Hu <zbestahu@gmail.com>,
	Jingbo Xu <jefflexu@163.com>,
	Sandeep Dhavale <dhavale@google.com>,
	Hongbo Li <hongbohbli@tencent.com>,
	Chunhai Guo <guochunhai@vivo.com>, Jan Kara <jack@suse.cz>,
	"Theodore Ts'o" <tytso@mit.edu>,
	Andreas Dilger <adilger.kernel@dilger.ca>,
	Baokun Li <libaokun@linux.alibaba.com>,
	Ojaswin Mujoo <ojaswin@linux.ibm.com>,
	"Ritesh Harjani (IBM)" <ritesh.list@gmail.com>,
	Zhang Yi <yi.zhang@huawei.com>, Jaegeuk Kim <jaegeuk@kernel.org>,
	Miklos Szeredi <miklos@szeredi.hu>,
	Andreas Gruenbacher <agruenba@redhat.com>,
	John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>,
	Yangtao Li <frank.li@vivo.com>,
	Richard Weinberger <richard@nod.at>,
	Anton Ivanov <anton.ivanov@cambridgegreys.com>,
	Johannes Berg <johannes@sipsolutions.net>,
	Mikulas Patocka <mikulas@artax.karlin.mff.cuni.cz>,
	David Woodhouse <dwmw2@infradead.org>,
	Dave Kleikamp <shaggy@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Tejun Heo <tj@kernel.org>, Trond Myklebust <trondmy@kernel.org>,
	Anna Schumaker <anna@kernel.org>,
	Ryusuke Konishi <konishi.ryusuke@gmail.com>,
	Namjae Jeon <linkinjeon@kernel.org>,
	Hyunchul Lee <hyc.lee@gmail.com>,
	Konstantin Komarov <almaz.alexandrovich@paragon-software.com>,
	Mark Fasheh <mark@fasheh.com>, Joel Becker <jlbec@evilplan.org>,
	Joseph Qi <joseph.qi@linux.alibaba.com>,
	Heming Zhao <heming.zhao@suse.com>,
	Mike Marshall <hubcap@omnibond.com>,
	Martin Brandenburg <martin@omnibond.com>,
	Amir Goldstein <amir73il@gmail.com>,
	Anders Larsen <al@alarsen.net>,
	Paulo Alcantara <pc@manguebit.org>,
	Ronnie Sahlberg <ronniesahlberg@gmail.com>,
	Shyam Prasad N <sprasad@microsoft.com>,
	Tom Talpey <tom@talpey.com>, Bharath SM <bharathsm@microsoft.com>,
	Phillip Lougher <phillip@squashfs.org.uk>,
	Zhihao Cheng <chengzhihao1@huawei.com>,
	Jori Koolstra <jkoolstra@xs4all.nl>,
	Damien Le Moal <dlemoal@kernel.org>,
	Naohiro Aota <naohiro.aota@wdc.com>,
	Johannes Thumshirn <jth@kernel.org>,
	Johannes Weiner <hannes@cmpxchg.org>,
	"Michal Koutný" <mkoutny@suse.com>,
	linux-doc@vger.kernel.org, nvdimm@lists.linux.dev,
	linux-cxl@vger.kernel.org, v9fs@lists.linux.dev,
	linux-fsdevel@vger.kernel.org, linux-afs@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-btrfs@vger.kernel.org,
	ceph-devel@vger.kernel.org, codalist@coda.cs.cmu.edu,
	ecryptfs@vger.kernel.org, linux-erofs@lists.ozlabs.org,
	linux-ext4@vger.kernel.org,
	linux-f2fs-devel@lists.sourceforge.net,
	fuse-devel@lists.linux.dev, gfs2@lists.linux.dev,
	linux-um@lists.infradead.org, linux-mtd@lists.infradead.org,
	jfs-discussion@lists.sourceforge.net,
	driver-core@lists.linux.dev, linux-nfs@vger.kernel.org,
	linux-nilfs@vger.kernel.org, ntfs@lists.linux.dev,
	ntfs3@lists.linux.dev, ocfs2-devel@lists.linux.dev,
	devel@lists.orangefs.org, linux-unionfs@vger.kernel.org,
	linux-cifs@vger.kernel.org, samba-technical@lists.samba.org,
	cgroups@vger.kernel.org
Subject: [PATCH 0/3] fs: return ERR_PTR() from iget_locked() and friends
Date: Tue, 1 Dec 2026 16:34:50 +0300	[thread overview]
Message-ID: <cover.1796132090.git.info@massivetech.ru> (raw)

iget_locked(), iget5_locked(), iget5_locked_rcu() and inode_insert5()
return NULL for a failed allocation and also for an inode under
creation, which find_inode() and find_inode_fast() report as -ESTALE.
Callers read NULL as -ENOMEM. As reported in [1], open_by_handle_at() on
ext4 then fails with ENOMEM, and nfsd returns a jukebox/DELAY error, for
the handle of a deleted inode whose number is being reused. Following
the discussion in [2], this series makes the helpers return ERR_PTR().

Patches 1 and 2 make fuse_iget() and hfs_iget() return ERR_PTR(), so
that patch 3 can convert the four helpers and all their callers at once.

Testing:
- The reproducer below, in virtme-ng (x86_64 defconfig, 4 CPUs, ext4 on
  a loop device, 10 seconds): one process creates and unlinks a file in
  a loop, the other calls open_by_handle_at() with the handle of an
  earlier, deleted file of that name.
    vfs.all at 84fb6f8a1ba9: ESTALE 2312698 ENOMEM 637252
    with this series:        ESTALE 3394396 ENOMEM 0
  dmesg has no messages from the test in either run.
- allmodconfig x86_64 builds of every directory the series touches, with
  all three patches and with patches 1-2 only; ARCH=um for hostfs;
  sparc64 for openpromfs. No new warnings. checkpatch --strict reports
  no errors.
- Not done: run-time tests of filesystems other than ext4 and of the
  changed error paths in the callers.

The series was written with Claude Code (claude-opus-5-5). I asked it to
find out why open_by_handle_at() returns ENOMEM to our file scanner and
to fix the cause in the kernel. It traced the error to iget_locked(),
wrote the reproducer, the patches, their changelogs and this letter, and
ran the builds and the tests above.

[1] https://lore.kernel.org/179612584364.3457081.15142720814992093613@massivetech.ru
[2] https://lore.kernel.org/all/20261201-advent-fahrkarte-zierlich-b5b73df9e312@brauner/

Reproducer, run as root: ./iget-repro <empty directory on ext4> <seconds>

#define _GNU_SOURCE
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>

int main(int argc, char **argv)
{
	long estale = 0, enomem = 0, other = 0, opened = 0;
	struct file_handle *fh;
	int mount_id, mfd, fd;
	time_t end;
	pid_t pid;

	if (argc != 3) {
		fprintf(stderr, "usage: %s DIR SECONDS\n", argv[0]);
		return 2;
	}
	if (chdir(argv[1]))
		return perror("chdir"), 1;

	fh = malloc(sizeof(*fh) + MAX_HANDLE_SZ);
	fh->handle_bytes = MAX_HANDLE_SZ;
	fd = open("f", O_CREAT | O_EXCL | O_WRONLY, 0600);
	if (fd < 0 || name_to_handle_at(AT_FDCWD, "f", fh, &mount_id, 0))
		return perror("name_to_handle_at"), 1;
	close(fd);
	unlink("f");

	mfd = open(".", O_RDONLY | O_DIRECTORY);
	pid = fork();
	if (!pid) {
		for (;;) {
			fd = open("f", O_CREAT | O_EXCL | O_WRONLY, 0600);
			if (fd >= 0)
				close(fd);
			unlink("f");
		}
	}

	end = time(NULL) + atoi(argv[2]);
	while (time(NULL) < end) {
		fd = open_by_handle_at(mfd, fh, O_RDONLY);
		if (fd >= 0) {
			opened++;
			close(fd);
		} else if (errno == ESTALE) {
			estale++;
		} else if (errno == ENOMEM) {
			enomem++;
		} else {
			other++;
		}
	}
	kill(pid, SIGKILL);
	waitpid(pid, NULL, 0);
	printf("ESTALE %ld ENOMEM %ld other %ld opened %ld\n",
	       estale, enomem, other, opened);
	return enomem != 0;
}

Konstantin Adzer (3):
  fuse: return ERR_PTR() from fuse_iget()
  hfs: return ERR_PTR() from hfs_iget()
  fs: return ERR_PTR() from iget_locked() and friends

 Documentation/filesystems/porting.rst |   9 ++
 drivers/dax/super.c                   |   8 +-
 fs/9p/vfs_inode.c                     |   4 +-
 fs/9p/vfs_inode_dotl.c                |   4 +-
 fs/affs/inode.c                       |   4 +-
 fs/afs/dynroot.c                      |  14 +--
 fs/afs/inode.c                        |  12 +--
 fs/befs/linuxvfs.c                    |   4 +-
 fs/btrfs/inode.c                      |  12 +--
 fs/ceph/inode.c                       |   4 +-
 fs/coda/cnode.c                       |   4 +-
 fs/cramfs/inode.c                     |   4 +-
 fs/ecryptfs/inode.c                   |   4 +-
 fs/erofs/inode.c                      |   4 +-
 fs/erofs/ishare.c                     |   6 +-
 fs/ext2/inode.c                       |   4 +-
 fs/ext4/inode.c                       |   4 +-
 fs/f2fs/inode.c                       |   4 +-
 fs/fuse/dir.c                         |  13 +--
 fs/fuse/inode.c                       |  16 ++--
 fs/fuse/readdir.c                     |   4 +-
 fs/gfs2/inode.c                       |   4 +-
 fs/hfs/btree.c                        |   2 +-
 fs/hfs/dir.c                          |   2 -
 fs/hfs/inode.c                        |   8 +-
 fs/hfs/super.c                        |   4 +-
 fs/hfsplus/super.c                    |   4 +-
 fs/hostfs/hostfs_kern.c               |   4 +-
 fs/hpfs/dir.c                         |   3 +-
 fs/hpfs/inode.c                       |   2 +-
 fs/hpfs/super.c                       |   2 +-
 fs/inode.c                            | 126 +++++++++++++++-----------
 fs/isofs/inode.c                      |   4 +-
 fs/jffs2/fs.c                         |   4 +-
 fs/jfs/inode.c                        |   4 +-
 fs/kernfs/inode.c                     |   8 +-
 fs/kernfs/mount.c                     |   4 +-
 fs/minix/inode.c                      |   4 +-
 fs/nfs/inode.c                        |   4 +-
 fs/nilfs2/cpfile.c                    |   4 +-
 fs/nilfs2/dat.c                       |   4 +-
 fs/nilfs2/ifile.c                     |   4 +-
 fs/nilfs2/inode.c                     |  16 ++--
 fs/nilfs2/sufile.c                    |   4 +-
 fs/ntfs/inode.c                       |  12 +--
 fs/ntfs3/inode.c                      |   4 +-
 fs/ocfs2/inode.c                      |   3 +-
 fs/openpromfs/inode.c                 |   5 +-
 fs/orangefs/inode.c                   |   4 +-
 fs/overlayfs/inode.c                  |  10 +-
 fs/qnx4/inode.c                       |   4 +-
 fs/qnx6/inode.c                       |   4 +-
 fs/romfs/super.c                      |   4 +-
 fs/smb/client/file.c                  |   5 +-
 fs/smb/client/inode.c                 |  12 ++-
 fs/smb/client/readdir.c               |   2 -
 fs/squashfs/inode.c                   |   4 +-
 fs/ubifs/super.c                      |   4 +-
 fs/udf/inode.c                        |   4 +-
 fs/ufs/inode.c                        |   4 +-
 fs/vboxsf/super.c                     |   4 +-
 fs/zonefs/super.c                     |   8 +-
 include/linux/kernfs.h                |   2 +-
 kernel/cgroup/cgroup.c                |   4 +-
 64 files changed, 251 insertions(+), 219 deletions(-)


base-commit: 84fb6f8a1ba91eee3ffe6aa519686fce851a0e42
-- 
2.56.1


             reply	other threads:[~2026-12-01 13:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 13:34 Konstantin Adzer [this message]
2026-12-01 13:06 ` [PATCH 1/3] fuse: return ERR_PTR() from fuse_iget() Konstantin Adzer
2026-12-01 13:06 ` [PATCH 2/3] hfs: return ERR_PTR() from hfs_iget() Konstantin Adzer
2026-12-01 13:09 ` [PATCH 3/3] fs: return ERR_PTR() from iget_locked() and friends Konstantin Adzer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cover.1796132090.git.info@massivetech.ru \
    --to=info@massivetech.ru \
    --cc=adilger.kernel@dilger.ca \
    --cc=agruenba@redhat.com \
    --cc=al@alarsen.net \
    --cc=alison.schofield@intel.com \
    --cc=almaz.alexandrovich@paragon-software.com \
    --cc=amarkuze@redhat.com \
    --cc=amir73il@gmail.com \
    --cc=anna@kernel.org \
    --cc=anton.ivanov@cambridgegreys.com \
    --cc=asmadeus@codewreck.org \
    --cc=bharathsm@microsoft.com \
    --cc=brauner@kernel.org \
    --cc=ceph-devel@vger.kernel.org \
    --cc=cgroups@vger.kernel.org \
    --cc=chao@kernel.org \
    --cc=chengzhihao1@huawei.com \
    --cc=coda@cs.cmu.edu \
    --cc=codalist@coda.cs.cmu.edu \
    --cc=code@tyhicks.com \
    --cc=corbet@lwn.net \
    --cc=dave.jiang@intel.com \
    --cc=devel@lists.orangefs.org \
    --cc=dhavale@google.com \
    --cc=dhowells@redhat.com \
    --cc=djbw@kernel.org \
    --cc=dlemoal@kernel.org \
    --cc=driver-core@lists.linux.dev \
    --cc=dsterba@suse.com \
    --cc=dwmw2@infradead.org \
    --cc=ecryptfs@vger.kernel.org \
    --cc=ericvh@kernel.org \
    --cc=frank.li@vivo.com \
    --cc=fuse-devel@lists.linux.dev \
    --cc=gfs2@lists.linux.dev \
    --cc=glaubitz@physik.fu-berlin.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=guochunhai@vivo.com \
    --cc=hannes@cmpxchg.org \
    --cc=heming.zhao@suse.com \
    --cc=hongbohbli@tencent.com \
    --cc=hubcap@omnibond.com \
    --cc=hyc.lee@gmail.com \
    --cc=idryomov@gmail.com \
    --cc=jack@suse.cz \
    --cc=jaegeuk@kernel.org \
    --cc=jaharkes@cs.cmu.edu \
    --cc=jefflexu@163.com \
    --cc=jfs-discussion@lists.sourceforge.net \
    --cc=jkoolstra@xs4all.nl \
    --cc=jlbec@evilplan.org \
    --cc=johannes@sipsolutions.net \
    --cc=joseph.qi@linux.alibaba.com \
    --cc=jth@kernel.org \
    --cc=konishi.ryusuke@gmail.com \
    --cc=libaokun@linux.alibaba.com \
    --cc=linkinjeon@kernel.org \
    --cc=linux-afs@lists.infradead.org \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-cifs@vger.kernel.org \
    --cc=linux-cxl@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-erofs@lists.ozlabs.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=linux-nilfs@vger.kernel.org \
    --cc=linux-um@lists.infradead.org \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=linux_oss@crudebyte.com \
    --cc=lucho@ionkov.net \
    --cc=luisbg@kernel.org \
    --cc=marc.dionne@auristor.com \
    --cc=mark@fasheh.com \
    --cc=martin@omnibond.com \
    --cc=mason@kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=mikulas@artax.karlin.mff.cuni.cz \
    --cc=mkoutny@suse.com \
    --cc=naohiro.aota@wdc.com \
    --cc=nico@fluxnic.net \
    --cc=ntfs3@lists.linux.dev \
    --cc=ntfs@lists.linux.dev \
    --cc=nvdimm@lists.linux.dev \
    --cc=ocfs2-devel@lists.linux.dev \
    --cc=ojaswin@linux.ibm.com \
    --cc=pc@manguebit.org \
    --cc=phillip@squashfs.org.uk \
    --cc=rdunlap@infradead.org \
    --cc=richard@nod.at \
    --cc=ritesh.list@gmail.com \
    --cc=ronniesahlberg@gmail.com \
    --cc=salah.triki@gmail.com \
    --cc=samba-technical@lists.samba.org \
    --cc=shaggy@kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=slava@dubeyko.com \
    --cc=sprasad@microsoft.com \
    --cc=tj@kernel.org \
    --cc=tom@talpey.com \
    --cc=trondmy@kernel.org \
    --cc=tytso@mit.edu \
    --cc=v9fs@lists.linux.dev \
    --cc=viro@zeniv.linux.org.uk \
    --cc=vishal.l.verma@intel.com \
    --cc=xiang@kernel.org \
    --cc=xiubo.li@clyso.com \
    --cc=yi.zhang@huawei.com \
    --cc=zbestahu@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox