From: Jeff Layton <jlayton@kernel.org>
To: NeilBrown <neil@brown.name>,
Christian Brauner <brauner@kernel.org>,
Alexander Viro <viro@zeniv.linux.org.uk>,
David Howells <dhowells@redhat.com>, Jan Kara <jack@suse.cz>,
Chuck Lever <chuck.lever@oracle.com>,
Miklos Szeredi <miklos@szeredi.hu>,
Amir Goldstein <amir73il@gmail.com>,
John Johansen <john.johansen@canonical.com>,
Paul Moore <paul@paul-moore.com>,
James Morris <jmorris@namei.org>,
"Serge E. Hallyn" <serge@hallyn.com>,
Stephen Smalley <stephen.smalley.work@gmail.com>
Cc: linux-kernel@vger.kernel.org, netfs@lists.linux.dev,
linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org,
linux-unionfs@vger.kernel.org, apparmor@lists.ubuntu.com,
linux-security-module@vger.kernel.org, selinux@vger.kernel.org
Subject: Re: [PATCH 09/13] cachefiles: change cachefiles_bury_object to use start_renaming_dentry()
Date: Thu, 05 Feb 2026 07:38:30 -0500 [thread overview]
Message-ID: <4d2c35c1b627f1ad26062a92d653677d7b79bd81.camel@kernel.org> (raw)
In-Reply-To: <20260204050726.177283-10-neilb@ownmail.net>
On Wed, 2026-02-04 at 15:57 +1100, NeilBrown wrote:
> From: NeilBrown <neil@brown.name>
>
> Rather then using lock_rename() and lookup_one() etc we can use
> the new start_renaming_dentry(). This is part of centralising dir
> locking and lookup so that locking rules can be changed.
>
> Some error check are removed as not necessary. Checks for rep being a
> non-dir or IS_DEADDIR and the check that ->graveyard is still a
> directory only provide slightly more informative errors and have been
> dropped.
>
> Signed-off-by: NeilBrown <neil@brown.name>
> ---
> fs/cachefiles/namei.c | 76 ++++++++-----------------------------------
> 1 file changed, 14 insertions(+), 62 deletions(-)
>
> diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
> index e5ec90dccc27..3af42ec78411 100644
> --- a/fs/cachefiles/namei.c
> +++ b/fs/cachefiles/namei.c
> @@ -270,7 +270,8 @@ int cachefiles_bury_object(struct cachefiles_cache *cache,
> struct dentry *rep,
> enum fscache_why_object_killed why)
> {
> - struct dentry *grave, *trap;
> + struct dentry *grave;
> + struct renamedata rd = {};
> struct path path, path_to_graveyard;
> char nbuffer[8 + 8 + 1];
> int ret;
> @@ -302,77 +303,36 @@ int cachefiles_bury_object(struct cachefiles_cache *cache,
> (uint32_t) ktime_get_real_seconds(),
> (uint32_t) atomic_inc_return(&cache->gravecounter));
>
> - /* do the multiway lock magic */
> - trap = lock_rename(cache->graveyard, dir);
> - if (IS_ERR(trap))
> - return PTR_ERR(trap);
> -
> - /* do some checks before getting the grave dentry */
> - if (rep->d_parent != dir || IS_DEADDIR(d_inode(rep))) {
> - /* the entry was probably culled when we dropped the parent dir
> - * lock */
> - unlock_rename(cache->graveyard, dir);
> - _leave(" = 0 [culled?]");
> - return 0;
> - }
> -
> - if (!d_can_lookup(cache->graveyard)) {
> - unlock_rename(cache->graveyard, dir);
> - cachefiles_io_error(cache, "Graveyard no longer a directory");
> - return -EIO;
> - }
> -
> - if (trap == rep) {
> - unlock_rename(cache->graveyard, dir);
> - cachefiles_io_error(cache, "May not make directory loop");
> + rd.mnt_idmap = &nop_mnt_idmap;
> + rd.old_parent = dir;
> + rd.new_parent = cache->graveyard;
> + rd.flags = 0;
> + ret = start_renaming_dentry(&rd, 0, rep, &QSTR(nbuffer));
> + if (ret) {
> + cachefiles_io_error(cache, "Cannot lock/lookup in graveyard");
> return -EIO;
> }
>
> if (d_mountpoint(rep)) {
> - unlock_rename(cache->graveyard, dir);
> + end_renaming(&rd);
> cachefiles_io_error(cache, "Mountpoint in cache");
> return -EIO;
> }
>
> - grave = lookup_one(&nop_mnt_idmap, &QSTR(nbuffer), cache->graveyard);
> - if (IS_ERR(grave)) {
> - unlock_rename(cache->graveyard, dir);
> - trace_cachefiles_vfs_error(object, d_inode(cache->graveyard),
> - PTR_ERR(grave),
> - cachefiles_trace_lookup_error);
> -
> - if (PTR_ERR(grave) == -ENOMEM) {
> - _leave(" = -ENOMEM");
> - return -ENOMEM;
> - }
> -
> - cachefiles_io_error(cache, "Lookup error %ld", PTR_ERR(grave));
> - return -EIO;
> - }
> -
> + grave = rd.new_dentry;
> if (d_is_positive(grave)) {
> - unlock_rename(cache->graveyard, dir);
> - dput(grave);
> + end_renaming(&rd);
> grave = NULL;
> cond_resched();
> goto try_again;
> }
>
> if (d_mountpoint(grave)) {
> - unlock_rename(cache->graveyard, dir);
> - dput(grave);
> + end_renaming(&rd);
> cachefiles_io_error(cache, "Mountpoint in graveyard");
> return -EIO;
> }
>
> - /* target should not be an ancestor of source */
> - if (trap == grave) {
> - unlock_rename(cache->graveyard, dir);
> - dput(grave);
> - cachefiles_io_error(cache, "May not make directory loop");
> - return -EIO;
> - }
> -
> /* attempt the rename */
> path.mnt = cache->mnt;
> path.dentry = dir;
> @@ -382,13 +342,6 @@ int cachefiles_bury_object(struct cachefiles_cache *cache,
> if (ret < 0) {
> cachefiles_io_error(cache, "Rename security error %d", ret);
> } else {
> - struct renamedata rd = {
> - .mnt_idmap = &nop_mnt_idmap,
> - .old_parent = dir,
> - .old_dentry = rep,
> - .new_parent = cache->graveyard,
> - .new_dentry = grave,
> - };
> trace_cachefiles_rename(object, d_inode(rep)->i_ino, why);
> ret = cachefiles_inject_read_error();
> if (ret == 0)
> @@ -402,8 +355,7 @@ int cachefiles_bury_object(struct cachefiles_cache *cache,
> }
>
> __cachefiles_unmark_inode_in_use(object, d_inode(rep));
> - unlock_rename(cache->graveyard, dir);
> - dput(grave);
> + end_renaming(&rd);
> _leave(" = 0");
> return 0;
> }
Reviewed-by: Jeff Layton <jlayton@kernel.org>
next prev parent reply other threads:[~2026-02-05 12:38 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-04 4:57 [PATCH 00/13] Further centralising of directory locking for name ops NeilBrown
2026-02-04 4:57 ` [PATCH 01/13] fs/proc: Don't lock root inode when creating "self" and "thread-self" NeilBrown
2026-02-05 12:33 ` Jeff Layton
2026-02-04 4:57 ` [PATCH 02/13] VFS: move the start_dirop() kerndoc comment to before start_dirop() NeilBrown
2026-02-05 12:33 ` Jeff Layton
2026-02-04 4:57 ` [PATCH 03/13] libfs: change simple_done_creating() to use end_creating() NeilBrown
2026-02-05 12:19 ` Jeff Layton
2026-02-06 2:13 ` NeilBrown
2026-02-04 4:57 ` [PATCH 04/13] Apparmor: Use simple_start_creating() / simple_done_creating() NeilBrown
2026-02-04 10:58 ` kernel test robot
2026-02-05 12:58 ` Jeff Layton
2026-02-06 0:21 ` NeilBrown
2026-02-04 4:57 ` [PATCH 05/13] selinux: " NeilBrown
2026-02-05 12:36 ` Jeff Layton
2026-02-20 22:47 ` Paul Moore
2026-02-21 22:28 ` NeilBrown
2026-02-22 14:19 ` Paul Moore
2026-02-23 0:58 ` NeilBrown
2026-02-04 4:57 ` [PATCH 06/13] nfsd: switch purge_old() to use start_removing_noperm() NeilBrown
2026-02-05 12:36 ` Jeff Layton
2026-02-04 4:57 ` [PATCH 07/13] VFS: make lookup_one_qstr_excl() static NeilBrown
2026-02-05 12:37 ` Jeff Layton
2026-02-04 4:57 ` [PATCH 08/13] ovl: Simplify ovl_lookup_real_one() NeilBrown
2026-02-05 12:38 ` Jeff Layton
2026-02-05 13:04 ` Amir Goldstein
2026-02-06 0:43 ` NeilBrown
2026-02-04 4:57 ` [PATCH 09/13] cachefiles: change cachefiles_bury_object to use start_renaming_dentry() NeilBrown
2026-02-05 12:38 ` Jeff Layton [this message]
2026-02-04 4:57 ` [PATCH 10/13] ovl: change ovl_create_real() to get a new lock when re-opening created file NeilBrown
2026-02-05 12:26 ` Amir Goldstein
2026-02-06 1:11 ` NeilBrown
2026-02-06 13:35 ` Amir Goldstein
2026-02-04 4:57 ` [PATCH 11/13] ovl: use is_subdir() for testing if one thing is a subdir of another NeilBrown
2026-02-05 9:37 ` Amir Goldstein
2026-02-05 12:38 ` Jeff Layton
2026-02-04 4:57 ` [PATCH 12/13] ovl: remove ovl_lock_rename_workdir() NeilBrown
2026-02-05 9:45 ` Amir Goldstein
2026-02-06 1:18 ` NeilBrown
2026-02-05 12:40 ` Jeff Layton
2026-02-05 12:58 ` Jeff Layton
2026-02-04 4:57 ` [PATCH 13/13] VFS: unexport lock_rename(), lock_rename_child(), unlock_rename() NeilBrown
2026-02-05 12:41 ` Jeff Layton
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=4d2c35c1b627f1ad26062a92d653677d7b79bd81.camel@kernel.org \
--to=jlayton@kernel.org \
--cc=amir73il@gmail.com \
--cc=apparmor@lists.ubuntu.com \
--cc=brauner@kernel.org \
--cc=chuck.lever@oracle.com \
--cc=dhowells@redhat.com \
--cc=jack@suse.cz \
--cc=jmorris@namei.org \
--cc=john.johansen@canonical.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=linux-unionfs@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=neil@brown.name \
--cc=netfs@lists.linux.dev \
--cc=paul@paul-moore.com \
--cc=selinux@vger.kernel.org \
--cc=serge@hallyn.com \
--cc=stephen.smalley.work@gmail.com \
--cc=viro@zeniv.linux.org.uk \
/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