From nobody Tue Apr 7 16:16:38 2026 Received: from flow-b5-smtp.messagingengine.com (flow-b5-smtp.messagingengine.com [202.12.124.140]) (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 364832FAC14; Fri, 13 Mar 2026 00:43:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.140 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773362597; cv=none; b=PvaOmLI8BRbnyCx7ZfNvAF8Os1ShAyT3wYdX6XBchBiyRLa1V8L1C/FNP4WDqVRG6lkX76xIE2/qCWHBK+p6yzE1rPMatqTePDXRz6ebMojopR4/Jph/B5mtK5ml+mlTLpEj4kZeEt9rQQFuT+dJ6pNR4a+39Jctv3/uwEv947Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773362597; c=relaxed/simple; bh=V1LusLfhIYS279k6+gPTO3CAtyNEfgSX9UJqBDT2m6g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Q9Y+fhHPOc9+2oA1nUHi6kMTNCnLpKPy7BGdEMS4JuF3uzQgx6Q1Pf9m6FfMbj1OKYuuQmZtnGWW/6QOOE5vn867VNqd0x0sORkgXtTn6xErJ2TKyb0FA2HZ+/y3HiVnJmcfRYXq3tkYUCg6xZbi2W39HiH74yLbhyCzb5GfZs4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ownmail.net; spf=pass smtp.mailfrom=ownmail.net; dkim=pass (2048-bit key) header.d=ownmail.net header.i=@ownmail.net header.b=evZBO/FT; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=tlm7pJXg; arc=none smtp.client-ip=202.12.124.140 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) header.d=ownmail.net header.i=@ownmail.net header.b="evZBO/FT"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="tlm7pJXg" Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailflow.stl.internal (Postfix) with ESMTP id 1863C1301B1D; Thu, 12 Mar 2026 20:43:10 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-04.internal (MEProxy); Thu, 12 Mar 2026 20:43:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ownmail.net; h= cc: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=fm1; t=1773362590; x=1773369790; bh=mtJ/saZCLiCxFDNQljniHYoFSU4uzdwtWsgXO8zNDIk=; b= evZBO/FT5uLkrmbp/p/bKHGn86ivpuWIB8uwzomHLGU6kH6lhmmlCRwiDJoWV39q TXhehd3v184kz2tKDZFnYt3nMYpGYs0FHIDP5P1WpT7DuL/s4rQw/xsDTsgE9QLg /164043xlTxtGbkRkgPLxopa5nRZXLGdKExiyrVeEWQB7Z6SjppifuMa+H+nAnt/ Y9UIllgVcpdMC3ryQir69hasMs4sAzed4op96lB/0i6WUn6Uhf0fVcGFEXiSJozk InAA9BqTgm3htPeeddGMpXgGFTZior38m4S57df0DQ4nN26Wz6Bnup7omFSZuA/V bXDsxk1oRwy+oBWG8yzDjw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=fm1; t=1773362590; x=1773369790; bh=m tJ/saZCLiCxFDNQljniHYoFSU4uzdwtWsgXO8zNDIk=; b=tlm7pJXgvMRnwrzqw 361ob53tdiymOgQgABOTedImHhfzfyXrgBfCei5K7ic4kOntEU7/s+f5sGh5Urct yi6RhxZa9AKNdjteFK4EVVHFzPhf0rBHY7+D36NQKzOYqyDZTXwjWo75g7RIoUOt +1Y24Dtef108V7gC/hPAOKuoKHxLQb6ez/GO9OthDEETcJ7ke8mp144qJcMLu188 7QoX5KdxhtTAeNLGhB9EFu+7bHr1B8GbxO8xT5UwDkDbvUE6Kv/LXlywzoVIfx8H 5/sPhbm9H87cFjM4xoYFeNlJ51RwpxBUAAY7/b3qCojyfoXALXgP5SiZxeMBLz3U TvcfA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddvkeekvdehucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhephffvvefufffkofgjfhhrggfgsedtkeertdertddtnecuhfhrohhmpefpvghilheu rhhofihnuceonhgvihhlsgesohifnhhmrghilhdrnhgvtheqnecuggftrfgrthhtvghrnh epveevkeffudeuvefhieeghffgudektdelkeejiedtjedugfeukedvkeffvdefvddunecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepnhgvihhlsg esohifnhhmrghilhdrnhgvthdpnhgspghrtghpthhtohephedupdhmohguvgepshhmthhp ohhuthdprhgtphhtthhopehvihhrohesiigvnhhivhdrlhhinhhugidrohhrghdruhhkpd hrtghpthhtoheplhhinhhugidqgihfshesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgt phhtthhopehlihhnuhigqdhunhhiohhnfhhssehvghgvrhdrkhgvrhhnvghlrdhorhhgpd hrtghpthhtoheplhhinhhugidqthhrrggtvgdqkhgvrhhnvghlsehvghgvrhdrkhgvrhhn vghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqnhhfshesvhhgvghrrdhkvghrnhgvlh drohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgv lhdrohhrghdprhgtphhtthhopehlihhnuhigqdhfshguvghvvghlsehvghgvrhdrkhgvrh hnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqvgigthegsehvghgvrhdrkhgvrhhn vghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqvghfihesvhhgvghrrdhkvghrnhgvlh drohhrgh X-ME-Proxy: Feedback-ID: i9d664b8f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 12 Mar 2026 20:42:56 -0400 (EDT) From: NeilBrown To: Linus Torvalds , Alexander Viro , Christian Brauner , Jan Kara , Jeff Layton , Trond Myklebust , Anna Schumaker , Carlos Maiolino , Miklos Szeredi , Amir Goldstein , Jan Harkes , Hugh Dickins , Baolin Wang , David Howells , Marc Dionne , Steve French , Namjae Jeon , Sungjong Seo , Yuezhang Mo , Andreas Hindborg , Breno Leitao , "Theodore Ts'o" , Andreas Dilger , Steven Rostedt , Masami Hiramatsu , Ilya Dryomov , Alex Markuze , Viacheslav Dubeyko , Tyler Hicks , Andreas Gruenbacher , Richard Weinberger , Anton Ivanov , Johannes Berg , Jeremy Kerr , Ard Biesheuvel Cc: linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-xfs@vger.kernel.org, linux-unionfs@vger.kernel.org, coda@cs.cmu.edu, linux-mm@kvack.org, linux-afs@lists.infradead.org, linux-cifs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, ceph-devel@vger.kernel.org, ecryptfs@vger.kernel.org, gfs2@lists.linux.dev, linux-um@lists.infradead.org, linux-efi@vger.kernel.org Subject: [PATCH 37/53] cephfs: Use d_alloc_noblock() in ceph_readdir_prepopulate() Date: Fri, 13 Mar 2026 08:12:24 +1100 Message-ID: <20260312214330.3885211-38-neilb@ownmail.net> X-Mailer: git-send-email 2.50.0.107.gf914562f5916.dirty In-Reply-To: <20260312214330.3885211-1-neilb@ownmail.net> References: <20260312214330.3885211-1-neilb@ownmail.net> Reply-To: NeilBrown Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: NeilBrown cephfs uses the results of readdir to prime the dcache. Using d_alloc() is no longer safe, even with an exclusive lock on the parent, as d_alloc_parallel() will be allowed to run unlocked. The safe interface is d_alloc_noblock(). In the rare case that this blocks because there is a concurrent lookup for the same name there is little cost in not completing the allocating in the directory code. It it still possible to create an inode at this point so we do that even when there is no dentry. So change to use d_alloc_noblock() and handle -EWOULDBLOCK. Also use QSTR_LEN() to initialise dname, and try_lookup_noperm instead of full_name_hash() and d_lookup(). Signed-off-by: NeilBrown --- fs/ceph/inode.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c index 0982fbda2a82..8557b207d337 100644 --- a/fs/ceph/inode.c +++ b/fs/ceph/inode.c @@ -2011,9 +2011,7 @@ int ceph_readdir_prepopulate(struct ceph_mds_request = *req, struct ceph_mds_reply_dir_entry *rde =3D rinfo->dir_entries + i; struct ceph_vino tvino; =20 - dname.name =3D rde->name; - dname.len =3D rde->name_len; - dname.hash =3D full_name_hash(parent, dname.name, dname.len); + dname =3D QSTR_LEN(rde->name, rde->name_len); =20 tvino.ino =3D le64_to_cpu(rde->inode.in->ino); tvino.snap =3D le64_to_cpu(rde->inode.in->snapid); @@ -2029,20 +2027,24 @@ int ceph_readdir_prepopulate(struct ceph_mds_reques= t *req, } =20 retry_lookup: - dn =3D d_lookup(parent, &dname); + dn =3D try_lookup_noperm(&dname, parent); doutc(cl, "d_lookup on parent=3D%p name=3D%.*s got %p\n", parent, dname.len, dname.name, dn); - - if (!dn) { - dn =3D d_alloc(parent, &dname); - doutc(cl, "d_alloc %p '%.*s' =3D %p\n", parent, + if (IS_ERR(dn)) { + err =3D PTR_ERR(dn); + goto out; + } else if (!dn) { + dn =3D d_alloc_noblock(parent, &dname); + doutc(cl, "d_alloc_noblock %p '%.*s' =3D %p\n", parent, dname.len, dname.name, dn); - if (!dn) { - doutc(cl, "d_alloc badness\n"); - err =3D -ENOMEM; + if (dn =3D=3D ERR_PTR(-EWOULDBLOCK)) { + /* Just handle the inode info */ + dn =3D NULL; + } else if (IS_ERR(dn)) { + doutc(cl, "d_alloc_noblock badness\n"); + err =3D PTR_ERR(dn); goto out; - } - if (rde->is_nokey) { + } else if (rde->is_nokey) { spin_lock(&dn->d_lock); dn->d_flags |=3D DCACHE_NOKEY_NAME; spin_unlock(&dn->d_lock); @@ -2069,7 +2071,7 @@ int ceph_readdir_prepopulate(struct ceph_mds_request = *req, } =20 /* inode */ - if (d_really_is_positive(dn)) { + if (dn && d_really_is_positive(dn)) { in =3D d_inode(dn); } else { in =3D ceph_get_inode(parent->d_sb, tvino, NULL); @@ -2087,21 +2089,22 @@ int ceph_readdir_prepopulate(struct ceph_mds_reques= t *req, if (ret < 0) { pr_err_client(cl, "badness on %p %llx.%llx\n", in, ceph_vinop(in)); - if (d_really_is_negative(dn)) { + if (!dn || d_really_is_negative(dn)) { if (inode_state_read_once(in) & I_NEW) { ihold(in); discard_new_inode(in); } iput(in); } - d_drop(dn); + if (dn) + d_drop(dn); err =3D ret; goto next_item; } if (inode_state_read_once(in) & I_NEW) unlock_new_inode(in); =20 - if (d_really_is_negative(dn)) { + if (d_in_lookup(dn) || d_really_is_negative(dn)) { if (ceph_security_xattr_deadlock(in)) { doutc(cl, " skip splicing dn %p to inode %p" " (security xattr deadlock)\n", dn, in); --=20 2.50.0.107.gf914562f5916.dirty