You've already forked linux-apfs
mirror of
https://github.com/linux-apfs/linux-apfs.git
synced 2026-05-01 15:00:59 -07:00
Move FASYNC bit handling to f_op->fasync()
Removing the BKL from FASYNC handling ran into the challenge of keeping the setting of the FASYNC bit in filp->f_flags atomic with regard to calls to the underlying fasync() function. Andi Kleen suggested moving the handling of that bit into fasync(); this patch does exactly that. As a result, we have a couple of internal API changes: fasync() must now manage the FASYNC bit, and it will be called without the BKL held. As it happens, every fasync() implementation in the kernel with one exception calls fasync_helper(). So, if we make fasync_helper() set the FASYNC bit, we can avoid making any changes to the other fasync() functions - as long as those functions, themselves, have proper locking. Most fasync() implementations do nothing but call fasync_helper() - which has its own lock - so they are easily verified as correct. The BKL had already been pushed down into the rest. The networking code has its own version of fasync_helper(), so that code has been augmented with explicit FASYNC bit handling. Cc: Al Viro <viro@ZenIV.linux.org.uk> Cc: David Miller <davem@davemloft.net> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jonathan Corbet <corbet@lwn.net>
This commit is contained in:
+1
-12
@@ -427,19 +427,11 @@ static int ioctl_fioasync(unsigned int fd, struct file *filp,
|
||||
/* Did FASYNC state change ? */
|
||||
if ((flag ^ filp->f_flags) & FASYNC) {
|
||||
if (filp->f_op && filp->f_op->fasync)
|
||||
/* fasync() adjusts filp->f_flags */
|
||||
error = filp->f_op->fasync(fd, filp, on);
|
||||
else
|
||||
error = -ENOTTY;
|
||||
}
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
spin_lock(&filp->f_lock);
|
||||
if (on)
|
||||
filp->f_flags |= FASYNC;
|
||||
else
|
||||
filp->f_flags &= ~FASYNC;
|
||||
spin_unlock(&filp->f_lock);
|
||||
return error;
|
||||
}
|
||||
|
||||
@@ -507,10 +499,7 @@ int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd,
|
||||
break;
|
||||
|
||||
case FIOASYNC:
|
||||
/* BKL needed to avoid races tweaking f_flags */
|
||||
lock_kernel();
|
||||
error = ioctl_fioasync(fd, filp, argp);
|
||||
unlock_kernel();
|
||||
break;
|
||||
|
||||
case FIOQSIZE:
|
||||
|
||||
Reference in New Issue
Block a user