From: Jens Axboe <axboe@kernel.dk>
To: Al Viro <viro@zeniv.linux.org.uk>, linux-fsdevel@vger.kernel.org
Cc: Christian Brauner <christian@brauner.io>,
Todd Kjos <tkjos@google.com>,
Giuseppe Scrivano <gscrivan@redhat.com>
Subject: Re: [RFC] unify the file-closing stuff in fs/file.c
Date: Thu, 12 May 2022 17:48:45 -0600 [thread overview]
Message-ID: <4239a930-2765-a798-4831-d7c0d135c681@kernel.dk> (raw)
In-Reply-To: <Yn16M/fayt6tK/Gp@zeniv-ca.linux.org.uk>
On 5/12/22 3:20 PM, Al Viro wrote:
> Right now we have two places that do such removals - pick_file()
> and {__,}close_fd_get_file().
>
> They are almost identical - the only difference is in calling
> conventions (well, and the fact that __... is called with descriptor
> table locked).
>
> Calling conventions are... interesting.
>
> 1) pick_file() - returns file or ERR_PTR(-EBADF) or ERR_PTR(-EINVAL).
> The latter is for "descriptor is greater than size of descriptor table".
> One of the callers treats all ERR_PTR(...) as "return -EBADF"; another
> uses ERR_PTR(-EINVAL) as "end the loop now" indicator.
>
> 2) {__,}close_fd_get_file() returns 0 or -ENOENT (huh?), with file (or NULL)
> passed to caller by way of struct file ** argument. One of the callers
> (binder) ignores the return value completely and checks if the file is NULL.
> Another (io_uring) checks for return value being negative, then maps
> -ENOENT to -EBADF, not that any other value would be possible.
>
> ERR_PTR(-EINVAL) magic in case of pick_file() is borderline defensible;
> {__,}close_fd_get_file() conventions are insane. The older caller
> (in binder) had never even looked at return value; the newer one
> patches the bogus -ENOENT to what it wants to report, with strange
> "defensive" BS logics just in case __close_fd_get_file() would somehow
> find a different error to report.
>
> At the very least, {__,}close_fd_get_file() callers would've been happier
> if it just returned file or NULL. What's more, I'm seriously tempted
> to make pick_file() do the same thing. close_fd() won't care (checking
> for NULL is just as easy as for IS_ERR) and __range_close() could just
> as well cap the max_fd argument with last_fd(files_fdtable(current->files)).
>
> Does anybody see problems with the following?
Looks good to me, and much better than passing in the pointer to the
file pointer imho.
--
Jens Axboe
next prev parent reply other threads:[~2022-05-12 23:48 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-12 21:20 [RFC] unify the file-closing stuff in fs/file.c Al Viro
2022-05-12 23:26 ` [RFC][PATCH] get rid of the remnants of 'batched' fget/fput stuff Al Viro
2022-05-12 23:48 ` Jens Axboe
2022-05-13 0:48 ` Al Viro
2022-05-13 10:15 ` Christian Brauner
2022-05-12 23:48 ` Jens Axboe [this message]
2022-05-13 0:46 ` [RFC] unify the file-closing stuff in fs/file.c Todd Kjos
2022-05-13 10:52 ` Christian Brauner
2022-05-14 23:33 ` Al Viro
2022-05-16 8:04 ` Christian Brauner
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=4239a930-2765-a798-4831-d7c0d135c681@kernel.dk \
--to=axboe@kernel.dk \
--cc=christian@brauner.io \
--cc=gscrivan@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=tkjos@google.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