From: Jeff Layton <[email protected]>
To: Jens Axboe <[email protected]>, [email protected]
Cc: [email protected], [email protected]
Subject: Re: [PATCH 1/6] fs: add namei support for doing a non-blocking path lookup
Date: Sat, 25 Jan 2020 08:15:01 -0500 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
On Tue, 2020-01-07 at 10:00 -0700, Jens Axboe wrote:
> If the fast lookup fails, then return -EAGAIN to have the caller retry
> the path lookup. Assume that a dentry having any of:
>
> ->d_revalidate()
> ->d_automount()
> ->d_manage()
>
> could block in those callbacks. Preemptively return -EAGAIN if any of
> these are present.
>
> This is in preparation for supporting non-blocking open.
>
> Signed-off-by: Jens Axboe <[email protected]>
> ---
> fs/namei.c | 21 ++++++++++++++++++++-
> include/linux/namei.h | 2 ++
> 2 files changed, 22 insertions(+), 1 deletion(-)
>
> diff --git a/fs/namei.c b/fs/namei.c
> index b367fdb91682..ed108a41634f 100644
> --- a/fs/namei.c
> +++ b/fs/namei.c
> @@ -1641,6 +1641,17 @@ static struct dentry *__lookup_hash(const struct qstr *name,
> return dentry;
> }
>
> +static inline bool lookup_could_block(struct dentry *dentry, unsigned int flags)
> +{
> + const struct dentry_operations *ops = dentry->d_op;
> +
> + if (!ops || !(flags & LOOKUP_NONBLOCK))
> + return 0;
> +
> + /* assume these dentry ops may block */
> + return ops->d_revalidate || ops->d_automount || ops->d_manage;
> +}
> +
d_revalidate shouldn't block if LOOKUP_RCU is set.
> static int lookup_fast(struct nameidata *nd,
> struct path *path, struct inode **inode,
> unsigned *seqp)
> @@ -1665,6 +1676,9 @@ static int lookup_fast(struct nameidata *nd,
> return 0;
> }
>
> + if (unlikely(lookup_could_block(dentry, nd->flags)))
> + return -EAGAIN;
> +
> /*
> * This sequence count validates that the inode matches
> * the dentry name information from lookup.
> @@ -1707,7 +1721,10 @@ static int lookup_fast(struct nameidata *nd,
> dentry = __d_lookup(parent, &nd->last);
> if (unlikely(!dentry))
> return 0;
> - status = d_revalidate(dentry, nd->flags);
> + if (unlikely(lookup_could_block(dentry, nd->flags)))
> + status = -EAGAIN;
> + else
> + status = d_revalidate(dentry, nd->flags);
> }
> if (unlikely(status <= 0)) {
> if (!status)
> @@ -1912,6 +1929,8 @@ static int walk_component(struct nameidata *nd, int flags)
> if (unlikely(err <= 0)) {
> if (err < 0)
> return err;
> + if (nd->flags & LOOKUP_NONBLOCK)
> + return -EAGAIN;
> path.dentry = lookup_slow(&nd->last, nd->path.dentry,
> nd->flags);
> if (IS_ERR(path.dentry))
> diff --git a/include/linux/namei.h b/include/linux/namei.h
> index 4e77068f7a1a..392eb439f88b 100644
> --- a/include/linux/namei.h
> +++ b/include/linux/namei.h
> @@ -49,6 +49,8 @@ enum {LAST_NORM, LAST_ROOT, LAST_DOT, LAST_DOTDOT, LAST_BIND};
> /* LOOKUP_* flags which do scope-related checks based on the dirfd. */
> #define LOOKUP_IS_SCOPED (LOOKUP_BENEATH | LOOKUP_IN_ROOT)
>
> +#define LOOKUP_NONBLOCK 0x200000 /* don't block for lookup */
> +
> extern int path_pts(struct path *path);
>
> extern int user_path_at_empty(int, const char __user *, unsigned, struct path *, int *empty);
--
Jeff Layton <[email protected]>
next prev parent reply other threads:[~2020-01-25 13:15 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-07 17:00 [PATCHSET v2 0/6] io_uring: add support for open/close Jens Axboe
2020-01-07 17:00 ` [PATCH 1/6] fs: add namei support for doing a non-blocking path lookup Jens Axboe
2020-01-25 13:15 ` Jeff Layton [this message]
2020-01-07 17:00 ` [PATCH 2/6] fs: make build_open_flags() available internally Jens Axboe
2020-01-07 17:00 ` [PATCH 3/6] io_uring: add support for IORING_OP_OPENAT Jens Axboe
2020-01-08 13:05 ` Stefan Metzmacher
2020-01-08 16:20 ` Jens Axboe
2020-01-08 16:32 ` Stefan Metzmacher
2020-01-08 16:40 ` Jens Axboe
2020-01-08 17:04 ` Stefan Metzmacher
2020-01-08 22:53 ` Jens Axboe
2020-01-08 23:03 ` Stefan Metzmacher
2020-01-08 23:05 ` Jens Axboe
2020-01-08 23:11 ` Stefan Metzmacher
2020-01-08 23:22 ` Jens Axboe
2020-01-09 10:40 ` Stefan Metzmacher
2020-01-09 21:31 ` Jens Axboe
2020-01-16 22:42 ` Stefan Metzmacher
2020-01-17 0:16 ` Jens Axboe
2020-01-07 17:00 ` [PATCH 4/6] fs: move filp_close() outside of __close_fd_get_file() Jens Axboe
2020-01-07 17:00 ` [PATCH 5/6] io-wq: add support for uncancellable work Jens Axboe
2020-01-07 17:00 ` [PATCH 6/6] io_uring: add support for IORING_OP_CLOSE Jens Axboe
2020-01-08 21:17 ` [PATCHSET v2 0/6] io_uring: add support for open/close Stefan Metzmacher
2020-01-08 22:57 ` Jens Axboe
2020-01-08 23:05 ` Stefan Metzmacher
2020-01-09 1:02 ` Jens Axboe
2020-01-09 2:03 ` Jens Axboe
2020-01-16 22:50 ` Stefan Metzmacher
2020-01-17 0:18 ` Jens Axboe
2020-01-20 12:15 ` Stefan Metzmacher
2020-01-20 13:04 ` Pavel Begunkov
2020-01-17 0:44 ` Colin Walters
2020-01-17 0:51 ` Jens Axboe
2020-01-17 9:32 ` Pavel Begunkov
2020-01-17 15:21 ` Jens Axboe
2020-01-17 22:27 ` Pavel Begunkov
2020-01-17 22:36 ` Jens Axboe
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=c49d8fb5f7a056cddfa19f9b48af878ac14536d2.camel@kernel.org \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/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