Re: [PATCH] file: always lock position

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

 



On 7/25/23 2:51?PM, Linus Torvalds wrote:
> 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.

Ah yes good point. If registered with io_uring and closed, then it won't
matter how many extra references we hold or grab in the future, it won't
be found in the file table. I guess that's obvious...

-- 
Jens Axboe




[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