Re: [PATCH] file: always lock position

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 25 Jul 2023 at 13:41, Jens Axboe <axboe@xxxxxxxxx> wrote:
>
> Right, but what if the original app closes the file descriptor? Now you
> have the io_uring file table still holding a reference to it, but it'd
> just be 1. Which is enough to keep it alive, but you can still have
> multiple IOs inflight against this file.

Note that fdget_pos() fundamentally only works on file descriptors
that are there - it's literally looking them up in the file table as
it goes along. And it looks at the count of the file description as it
is looked up. So that refcount is guaranteed to exist.

If the file has been closed, fdget_pos() will just fail because it
doesn't find it.

And if it's then closed *afterwards*, that's fine and doesn't affect
anything, because the locking has been done and we saved away the
status bit as FDPUT_POS_UNLOCK, so the code knows to unlock even if
the file descriptor in the meantime has turned back to having just a
single refcount.

     Linus



[Index of Archives]     [Linux Kernel]     [Kernel Development Newbies]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux