From mboxrd@z Thu Jan 1 00:00:00 1970 From: valdis.kletnieks@vt.edu (valdis.kletnieks at vt.edu) Date: Mon, 04 Jun 2018 12:10:07 -0400 Subject: develoment workflow: how to avoid duplicate work ? In-Reply-To: <20180604033303.GX14048@gavran.carpriv.carnet.hr> References: <20180529030706.GD1845@hle-laptop.local> <80132.1527564735@turing-police.cc.vt.edu> <20180530025657.GB1919@hle-laptop.local> <22501.1527692619@turing-police.cc.vt.edu> <20180531014432.GA3722@hle-laptop.local> <20180603192336.GV14048@gavran.carpriv.carnet.hr> <20180603222556.GB20060@hle-laptop.local> <20180604033303.GX14048@gavran.carpriv.carnet.hr> Message-ID: <12368.1528128607@turing-police.cc.vt.edu> To: kernelnewbies@lists.kernelnewbies.org List-Id: kernelnewbies.lists.kernelnewbies.org On Mon, 04 Jun 2018 05:33:03 +0200, Valentin Vidic said: > On Sun, Jun 03, 2018 at 06:25:56PM -0400, Hugo Lefeuvre wrote: > > The vfs documentation states: release() is "called when the last > > reference to an open file is closed". > > > > Let's say we have a program with threads T1 and T2. > > > > - T1 calls ioctl on a file descriptor FD. > > - (on another processor) T2 closes FD. > > > > Since the last reference to FD was closed by T2, release is called. That's subtly wrong. T2 releases its reference to the file descriptor. > > But while release is being called, the ioctl call from T1 may still > > be running, right ? Remember that ioctl needs an open FD as well - so the ioctl() grabs its own reference, and then *that* reference to the file descriptor stays in place at least until the ioctl() return. At *that* point, the reference count goes to zero and the file is actually closed.