On Sat, Jul 27, 2019 at 9:28 AM Linus Torvalds
<[email protected]> wrote:
>
> Something like
>
>   struct pid *fd_to_pid(unsigned int fd)
>   {
>         struct fd f;
>         struct pid *pid;
...

I forgot to put my usual disclaimer about TOTALLY UNTESTED GARBAGE in
that email. I want to make that part clear: that code snippet was
meant as a rough guide of direction, not as a "this works".

Hopefully that was clear.

Also note again that one of the reasons I would prefer that
"fd_to_pid()" interface is that you _can_ do it cleverly with RCU
lookup, but that requires a lot of care.

In particular, I think all of our _existing_
"proc_pid(file_inode(file))" users are done while you actually hold a
reference to "struct file *", so they don't have to worry about races
with another thread doing the final ->release(). So the "clever" thing
is possible, but might need a _lot_ of care to make sure the 'struct
pid *' associated with the file still exists.

The example code sequence was not doing the clever thing, obviously.
So it was untested _and_ simple-stupid. But it has the interface that
I'd prefer.

              Linus

Reply via email to