linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Mikhalitsyn <alexander@mihalicyn.com>
To: Christian Brauner <brauner@kernel.org>
Cc: linux-fsdevel@vger.kernel.org, "Jann Horn" <jannh@google.com>,
	"Josef Bacik" <josef@toxicpanda.com>,
	"Jeff Layton" <jlayton@kernel.org>,
	"Daan De Meyer" <daan.j.demeyer@gmail.com>,
	"Lennart Poettering" <lennart@poettering.net>,
	"Mike Yuan" <me@yhndnzj.com>,
	"Zbigniew Jędrzejewski-Szmek" <zbyszek@in.waw.pl>
Subject: Re: [PATCH v2 02/16] libfs: massage path_from_stashed() to allow custom stashing behavior
Date: Sun, 22 Jun 2025 22:40:05 +0200	[thread overview]
Message-ID: <CAJqdLrqXTSPJv4QPcnO4wmvdAUXviyqWPxD7bRP6ULB_shpr4w@mail.gmail.com> (raw)
In-Reply-To: <20250618-work-pidfs-persistent-v2-2-98f3456fd552@kernel.org>

Am Mi., 18. Juni 2025 um 22:53 Uhr schrieb Christian Brauner
<brauner@kernel.org>:
>
> * Add a callback to struct stashed_operations so it's possible to
>   implement custom behavior for pidfs and allow for it to return errors.
>
> * Teach stashed_dentry_get() to handle error pointers.
>
> Signed-off-by: Christian Brauner <brauner@kernel.org>

Reviewed-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>

> ---
>  fs/internal.h |  3 +++
>  fs/libfs.c    | 27 ++++++++++++++++++++-------
>  2 files changed, 23 insertions(+), 7 deletions(-)
>
> diff --git a/fs/internal.h b/fs/internal.h
> index 393f6c5c24f6..22ba066d1dba 100644
> --- a/fs/internal.h
> +++ b/fs/internal.h
> @@ -322,12 +322,15 @@ struct mnt_idmap *alloc_mnt_idmap(struct user_namespace *mnt_userns);
>  struct mnt_idmap *mnt_idmap_get(struct mnt_idmap *idmap);
>  void mnt_idmap_put(struct mnt_idmap *idmap);
>  struct stashed_operations {
> +       struct dentry *(*stash_dentry)(struct dentry **stashed,
> +                                      struct dentry *dentry);
>         void (*put_data)(void *data);
>         int (*init_inode)(struct inode *inode, void *data);
>  };
>  int path_from_stashed(struct dentry **stashed, struct vfsmount *mnt, void *data,
>                       struct path *path);
>  void stashed_dentry_prune(struct dentry *dentry);
> +struct dentry *stash_dentry(struct dentry **stashed, struct dentry *dentry);
>  struct dentry *stashed_dentry_get(struct dentry **stashed);
>  /**
>   * path_mounted - check whether path is mounted
> diff --git a/fs/libfs.c b/fs/libfs.c
> index 9ea0ecc325a8..3541e22c87b5 100644
> --- a/fs/libfs.c
> +++ b/fs/libfs.c
> @@ -2128,6 +2128,8 @@ struct dentry *stashed_dentry_get(struct dentry **stashed)
>         dentry = rcu_dereference(*stashed);
>         if (!dentry)
>                 return NULL;
> +       if (IS_ERR(dentry))
> +               return dentry;
>         if (!lockref_get_not_dead(&dentry->d_lockref))
>                 return NULL;
>         return dentry;
> @@ -2176,8 +2178,7 @@ static struct dentry *prepare_anon_dentry(struct dentry **stashed,
>         return dentry;
>  }
>
> -static struct dentry *stash_dentry(struct dentry **stashed,
> -                                  struct dentry *dentry)
> +struct dentry *stash_dentry(struct dentry **stashed, struct dentry *dentry)
>  {
>         guard(rcu)();
>         for (;;) {
> @@ -2218,12 +2219,15 @@ static struct dentry *stash_dentry(struct dentry **stashed,
>  int path_from_stashed(struct dentry **stashed, struct vfsmount *mnt, void *data,
>                       struct path *path)
>  {
> -       struct dentry *dentry;
> +       struct dentry *dentry, *res;
>         const struct stashed_operations *sops = mnt->mnt_sb->s_fs_info;
>
>         /* See if dentry can be reused. */
> -       path->dentry = stashed_dentry_get(stashed);
> -       if (path->dentry) {
> +       res = stashed_dentry_get(stashed);
> +       if (IS_ERR(res))
> +               return PTR_ERR(res);
> +       if (res) {
> +               path->dentry = res;
>                 sops->put_data(data);
>                 goto out_path;
>         }
> @@ -2234,8 +2238,17 @@ int path_from_stashed(struct dentry **stashed, struct vfsmount *mnt, void *data,
>                 return PTR_ERR(dentry);
>
>         /* Added a new dentry. @data is now owned by the filesystem. */
> -       path->dentry = stash_dentry(stashed, dentry);
> -       if (path->dentry != dentry)
> +       if (sops->stash_dentry)
> +               res = sops->stash_dentry(stashed, dentry);
> +       else
> +               res = stash_dentry(stashed, dentry);
> +       if (IS_ERR(res)) {
> +               dput(dentry);
> +               return PTR_ERR(res);
> +       }
> +       path->dentry = res;
> +       /* A dentry was reused. */
> +       if (res != dentry)
>                 dput(dentry);
>
>  out_path:
>
> --
> 2.47.2
>

  reply	other threads:[~2025-06-22 20:40 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-18 20:53 [PATCH v2 00/16] pidfs: persistent info & xattrs Christian Brauner
2025-06-18 20:53 ` [PATCH v2 01/16] pidfs: raise SB_I_NODEV and SB_I_NOEXEC Christian Brauner
2025-06-22 20:37   ` Alexander Mikhalitsyn
2025-06-18 20:53 ` [PATCH v2 02/16] libfs: massage path_from_stashed() to allow custom stashing behavior Christian Brauner
2025-06-22 20:40   ` Alexander Mikhalitsyn [this message]
2025-06-18 20:53 ` [PATCH v2 03/16] libfs: massage path_from_stashed() Christian Brauner
2025-06-22 20:42   ` Alexander Mikhalitsyn
2025-06-18 20:53 ` [PATCH v2 04/16] pidfs: move to anonymous struct Christian Brauner
2025-06-22 20:44   ` Alexander Mikhalitsyn
2025-06-18 20:53 ` [PATCH v2 05/16] pidfs: persist information Christian Brauner
2025-06-22 21:09   ` Alexander Mikhalitsyn
2025-06-18 20:53 ` [PATCH v2 06/16] pidfs: remove unused members from struct pidfs_inode Christian Brauner
2025-06-22 21:10   ` Alexander Mikhalitsyn
2025-06-18 20:53 ` [PATCH v2 07/16] pidfs: remove custom inode allocation Christian Brauner
2025-06-22 21:10   ` Alexander Mikhalitsyn
2025-06-18 20:53 ` [PATCH v2 08/16] pidfs: remove pidfs_{get,put}_pid() Christian Brauner
2025-06-22 21:11   ` Alexander Mikhalitsyn
2025-06-18 20:53 ` [PATCH v2 09/16] pidfs: remove pidfs_pid_valid() Christian Brauner
2025-06-22 21:13   ` Alexander Mikhalitsyn
2025-06-18 20:53 ` [PATCH v2 10/16] libfs: prepare to allow for non-immutable pidfd inodes Christian Brauner
2025-06-22 21:14   ` Alexander Mikhalitsyn
2025-06-18 20:53 ` [PATCH v2 11/16] pidfs: make inodes mutable Christian Brauner
2025-06-22 21:14   ` Alexander Mikhalitsyn
2025-06-18 20:53 ` [PATCH v2 12/16] pidfs: support xattrs on pidfds Christian Brauner
2025-06-22 21:19   ` Alexander Mikhalitsyn
2025-06-18 20:53 ` [PATCH v2 13/16] selftests/pidfd: test extended attribute support Christian Brauner
2025-06-22 21:21   ` Alexander Mikhalitsyn
2025-06-18 20:53 ` [PATCH v2 14/16] " Christian Brauner
2025-06-22 21:21   ` Alexander Mikhalitsyn
2025-06-18 20:53 ` [PATCH v2 15/16] selftests/pidfd: test setattr support Christian Brauner
2025-06-22 21:22   ` Alexander Mikhalitsyn
2025-06-18 20:53 ` [PATCH v2 16/16] pidfs: add some CONFIG_DEBUG_VFS asserts Christian Brauner
2025-06-22 21:22   ` Alexander Mikhalitsyn

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=CAJqdLrqXTSPJv4QPcnO4wmvdAUXviyqWPxD7bRP6ULB_shpr4w@mail.gmail.com \
    --to=alexander@mihalicyn.com \
    --cc=brauner@kernel.org \
    --cc=daan.j.demeyer@gmail.com \
    --cc=jannh@google.com \
    --cc=jlayton@kernel.org \
    --cc=josef@toxicpanda.com \
    --cc=lennart@poettering.net \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=me@yhndnzj.com \
    --cc=zbyszek@in.waw.pl \
    /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;
as well as URLs for NNTP newsgroup(s).