From: David Laight <David.Laight@ACULAB.COM>
To: 'Stas Sergeev' <stsp2@yandex.ru>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: Eric Biederman <ebiederm@xmission.com>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
Andy Lutomirski <luto@kernel.org>,
"linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>
Subject: RE: [PATCH 1/2] fs: reorganize path_openat()
Date: Wed, 24 Apr 2024 09:17:57 +0000 [thread overview]
Message-ID: <858f6fb6afcd450d85d1ff900f82d396@AcuMS.aculab.com> (raw)
In-Reply-To: <20240422084505.3465238-1-stsp2@yandex.ru>
From: Stas Sergeev
> Sent: 22 April 2024 09:45
I seem to have 5 copies of this patch.....
> This patch moves the call to alloc_empty_file() below the call to
> path_init(). That changes is needed for the next patch, which adds
> a cred override for alloc_empty_file(). The needed cred info is only
> available after the call to path_init().
>
> No functional changes are intended by that patch.
...
> ---
> fs/namei.c | 26 +++++++++++++++++---------
> 1 file changed, 17 insertions(+), 9 deletions(-)
>
> diff --git a/fs/namei.c b/fs/namei.c
> index c5b2a25be7d0..2fde2c320ae9 100644
> --- a/fs/namei.c
> +++ b/fs/namei.c
> @@ -3782,22 +3782,30 @@ static struct file *path_openat(struct nameidata *nd,
> struct file *file;
> int error;
>
> - file = alloc_empty_file(op->open_flag, current_cred());
> - if (IS_ERR(file))
> - return file;
> -
> - if (unlikely(file->f_flags & __O_TMPFILE)) {
> + if (unlikely(op->open_flag & __O_TMPFILE)) {
> + file = alloc_empty_file(op->open_flag, current_cred());
> + if (IS_ERR(file))
> + return file;
> error = do_tmpfile(nd, flags, op, file);
> - } else if (unlikely(file->f_flags & O_PATH)) {
> + } else if (unlikely(op->open_flag & O_PATH)) {
> + file = alloc_empty_file(op->open_flag, current_cred());
> + if (IS_ERR(file))
> + return file;
> error = do_o_path(nd, flags, file);
You probably ought to merge the two 'unlikely' tests.
Otherwise there'll be two conditionals in the 'hot path'.
(There probably always were.)
So something like:
if (unlikely(op->open_flag & (__O_TMPFILE | O_PATH))) {
file = alloc_empty_file(op->open_flag, current_cred());
if (IS_ERR(file))
return file;
if (op->open_flag & __O_TMFILE)
error = do_tmpfile(nd, flags, op, file);
else
error = do_o_path(nd, flags, file);
} else {
Copying op->open_flag to a local may also generate better code.
David
> } else {
> const char *s = path_init(nd, flags);
> - while (!(error = link_path_walk(s, nd)) &&
> - (s = open_last_lookups(nd, file, op)) != NULL)
> - ;
> + file = alloc_empty_file(op->open_flag, current_cred());
> + error = PTR_ERR_OR_ZERO(file);
> + if (!error) {
> + while (!(error = link_path_walk(s, nd)) &&
> + (s = open_last_lookups(nd, file, op)) != NULL)
> + ;
> + }
> if (!error)
> error = do_open(nd, file, op);
> terminate_walk(nd);
> + if (IS_ERR(file))
> + return file;
> }
> if (likely(!error)) {
> if (likely(file->f_mode & FMODE_OPENED))
> --
> 2.44.0
>
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
next prev parent reply other threads:[~2024-04-24 9:18 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-22 8:45 Stas Sergeev
2024-04-22 8:45 ` [PATCH 2/2] openat2: add OA2_INHERIT_CRED flag Stas Sergeev
2024-04-22 19:53 ` Stefan Metzmacher
2024-04-22 20:18 ` stsp
2024-04-23 22:59 ` stsp
2024-04-24 9:17 ` David Laight [this message]
2024-04-24 9:24 ` [PATCH 1/2] fs: reorganize path_openat() stsp
2024-04-24 10:58 ` stsp
2024-04-24 15:07 ` David Laight
2024-04-24 17:41 ` stsp
2024-04-23 10:40 [PATCH v2 0/2] implement OA2_INHERIT_CRED flag for openat2() Stas Sergeev
2024-04-23 10:40 ` [PATCH 1/2] fs: reorganize path_openat() Stas Sergeev
2024-04-23 10:48 [PATCH v2 0/2] implement OA2_INHERIT_CRED flag for openat2() Stas Sergeev
2024-04-23 10:48 ` [PATCH 1/2] fs: reorganize path_openat() Stas Sergeev
2024-04-23 11:01 [PATCH v2 0/2] implement OA2_INHERIT_CRED flag for openat2() Stas Sergeev
2024-04-23 11:01 ` [PATCH 1/2] fs: reorganize path_openat() Stas Sergeev
2024-04-23 22:46 [PATCH v3 0/2] implement OA2_INHERIT_CRED flag for openat2() Stas Sergeev
2024-04-23 22:46 ` [PATCH 1/2] fs: reorganize path_openat() Stas Sergeev
2024-04-24 10:52 [PATCH v4 0/2] implement OA2_INHERIT_CRED flag for openat2() Stas Sergeev
2024-04-24 10:52 ` [PATCH 1/2] fs: reorganize path_openat() Stas Sergeev
2024-04-25 8:13 ` kernel test robot
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=858f6fb6afcd450d85d1ff900f82d396@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=brauner@kernel.org \
--cc=ebiederm@xmission.com \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=stsp2@yandex.ru \
--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
all inboxes | Powered by JetHome®