Merge branch 'bkl-removal' of git://git.lwn.net/linux-2.6
* 'bkl-removal' of git://git.lwn.net/linux-2.6: Rationalize fasync return values Move FASYNC bit handling to f_op->fasync() Use f_lock to protect f_flags Rename struct file->f_ep_lock
···437437can and should be done using the internal locking with smaller critical areas).438438Current worst offender is ext2_get_block()...439439440440-->fasync() is a mess. This area needs a big cleanup and that will probably441441-affect locking.440440+->fasync() is called without BKL protection, and is responsible for441441+maintaining the FASYNC bit in filp->f_flags. Most instances call442442+fasync_helper(), which does that maintenance, so it's not normally443443+something one needs to worry about. Return values > 0 will be mapped to444444+zero in the VFS layer.442445443446->readdir() and ->ioctl() on directories must be changed. Ideally we would444447move ->readdir() to inode_operations and use a separate method for directory
+1-6
drivers/char/sonypi.c
···888888889889static int sonypi_misc_fasync(int fd, struct file *filp, int on)890890{891891- int retval;892892-893893- retval = fasync_helper(fd, filp, on, &sonypi_device.fifo_async);894894- if (retval < 0)895895- return retval;896896- return 0;891891+ return fasync_helper(fd, filp, on, &sonypi_device.fifo_async);897892}898893899894static int sonypi_misc_release(struct inode *inode, struct file *file)
+2-3
drivers/char/tty_io.c
···21622162 if (get_user(nonblock, p))21632163 return -EFAULT;2164216421652165- /* file->f_flags is still BKL protected in the fs layer - vomit */21662166- lock_kernel();21652165+ spin_lock(&file->f_lock);21672166 if (nonblock)21682167 file->f_flags |= O_NONBLOCK;21692168 else21702169 file->f_flags &= ~O_NONBLOCK;21712171- unlock_kernel();21702170+ spin_unlock(&file->f_lock);21722171 return 0;21732172}21742173
+1-5
drivers/gpu/drm/drm_fops.c
···337337{338338 struct drm_file *priv = filp->private_data;339339 struct drm_device *dev = priv->minor->dev;340340- int retcode;341340342341 DRM_DEBUG("fd = %d, device = 0x%lx\n", fd,343342 (long)old_encode_dev(priv->minor->device));344344- retcode = fasync_helper(fd, filp, on, &dev->buf_async);345345- if (retcode < 0)346346- return retcode;347347- return 0;343343+ return fasync_helper(fd, filp, on, &dev->buf_async);348344}349345EXPORT_SYMBOL(drm_fasync);350346
+1-4
drivers/hid/usbhid/hiddev.c
···227227 */228228static int hiddev_fasync(int fd, struct file *file, int on)229229{230230- int retval;231230 struct hiddev_list *list = file->private_data;232231233233- retval = fasync_helper(fd, file, on, &list->fasync);234234-235235- return retval < 0 ? retval : 0;232232+ return fasync_helper(fd, file, on, &list->fasync);236233}237234238235
+1-5
drivers/ieee1394/dv1394.c
···1325132513261326 struct video_card *video = file_to_video_card(file);1327132713281328- int retval = fasync_helper(fd, file, on, &video->fasync);13291329-13301330- if (retval < 0)13311331- return retval;13321332- return 0;13281328+ return fasync_helper(fd, file, on, &video->fasync);13331329}1334133013351331static ssize_t dv1394_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
+1-4
drivers/input/evdev.c
···9494static int evdev_fasync(int fd, struct file *file, int on)9595{9696 struct evdev_client *client = file->private_data;9797- int retval;98979999- retval = fasync_helper(fd, file, on, &client->fasync);100100-101101- return retval < 0 ? retval : 0;9898+ return fasync_helper(fd, file, on, &client->fasync);10299}103100104101static int evdev_flush(struct file *file, fl_owner_t id)
+1-4
drivers/input/joydev.c
···159159160160static int joydev_fasync(int fd, struct file *file, int on)161161{162162- int retval;163162 struct joydev_client *client = file->private_data;164163165165- retval = fasync_helper(fd, file, on, &client->fasync);166166-167167- return retval < 0 ? retval : 0;164164+ return fasync_helper(fd, file, on, &client->fasync);168165}169166170167static void joydev_free(struct device *dev)
+1-4
drivers/input/mousedev.c
···403403404404static int mousedev_fasync(int fd, struct file *file, int on)405405{406406- int retval;407406 struct mousedev_client *client = file->private_data;408407409409- retval = fasync_helper(fd, file, on, &client->fasync);410410-411411- return retval < 0 ? retval : 0;408408+ return fasync_helper(fd, file, on, &client->fasync);412409}413410414411static void mousedev_free(struct device *dev)
+1-3
drivers/input/serio/serio_raw.c
···5858static int serio_raw_fasync(int fd, struct file *file, int on)5959{6060 struct serio_raw_list *list = file->private_data;6161- int retval;62616363- retval = fasync_helper(fd, file, on, &list->fasync);6464- return retval < 0 ? retval : 0;6262+ return fasync_helper(fd, file, on, &list->fasync);6563}66646765static struct serio_raw *serio_raw_locate(int minor)
+2-2
drivers/net/wan/cosa.c
···998998static int cosa_fasync(struct inode *inode, struct file *file, int on)999999{10001000 int port = iminor(inode);10011001- int rv = fasync_helper(inode, file, on, &fasync[port]);10021002- return rv < 0 ? rv : 0;10011001+10021002+ return fasync_helper(inode, file, on, &fasync[port]);10031003}10041004#endif10051005
+1-6
drivers/platform/x86/sony-laptop.c
···1917191719181918static int sonypi_misc_fasync(int fd, struct file *filp, int on)19191919{19201920- int retval;19211921-19221922- retval = fasync_helper(fd, filp, on, &sonypi_compat.fifo_async);19231923- if (retval < 0)19241924- return retval;19251925- return 0;19201920+ return fasync_helper(fd, filp, on, &sonypi_compat.fifo_async);19261921}1927192219281923static int sonypi_misc_release(struct inode *inode, struct file *file)
···17111711 curlun->sense_data = SS_WRITE_PROTECTED;17121712 return -EINVAL;17131713 }17141714+ spin_lock(&curlun->filp->f_lock);17141715 curlun->filp->f_flags &= ~O_SYNC; // Default is not to wait17161716+ spin_unlock(&curlun->filp->f_lock);1715171717161718 /* Get the starting Logical Block Address and check that it's17171719 * not too big */···17301728 curlun->sense_data = SS_INVALID_FIELD_IN_CDB;17311729 return -EINVAL;17321730 }17331733- if (fsg->cmnd[1] & 0x08) // FUA17311731+ if (fsg->cmnd[1] & 0x08) { // FUA17321732+ spin_lock(&curlun->filp->f_lock);17341733 curlun->filp->f_flags |= O_SYNC;17341734+ spin_unlock(&curlun->filp->f_lock);17351735+ }17351736 }17361737 if (lba >= curlun->num_sectors) {17371738 curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
+7-5
fs/eventpoll.c
···417417 ep_unregister_pollwait(ep, epi);418418419419 /* Remove the current item from the list of epoll hooks */420420- spin_lock(&file->f_ep_lock);420420+ spin_lock(&file->f_lock);421421 if (ep_is_linked(&epi->fllink))422422 list_del_init(&epi->fllink);423423- spin_unlock(&file->f_ep_lock);423423+ spin_unlock(&file->f_lock);424424425425 rb_erase(&epi->rbn, &ep->rbr);426426···538538 struct epitem *epi;539539540540 /*541541- * We don't want to get "file->f_ep_lock" because it is not541541+ * We don't want to get "file->f_lock" because it is not542542 * necessary. It is not necessary because we're in the "struct file"543543 * cleanup path, and this means that noone is using this file anymore.544544 * So, for example, epoll_ctl() cannot hit here sicne if we reach this···547547 * will correctly serialize the operation. We do need to acquire548548 * "ep->mtx" after "epmutex" because ep_remove() requires it when called549549 * from anywhere but ep_free().550550+ *551551+ * Besides, ep_remove() acquires the lock, so we can't hold it here.550552 */551553 mutex_lock(&epmutex);552554···787785 goto error_unregister;788786789787 /* Add the current item to the list of active epoll hook for this file */790790- spin_lock(&tfile->f_ep_lock);788788+ spin_lock(&tfile->f_lock);791789 list_add_tail(&epi->fllink, &tfile->f_ep_links);792792- spin_unlock(&tfile->f_ep_lock);790790+ spin_unlock(&tfile->f_lock);793791794792 /*795793 * Add the current item to the RB tree. All RB tree operations are
+20-13
fs/fcntl.c
···141141 return ret;142142}143143144144-#define SETFL_MASK (O_APPEND | O_NONBLOCK | O_NDELAY | FASYNC | O_DIRECT | O_NOATIME)144144+#define SETFL_MASK (O_APPEND | O_NONBLOCK | O_NDELAY | O_DIRECT | O_NOATIME)145145146146static int setfl(int fd, struct file * filp, unsigned long arg)147147{···177177 return error;178178179179 /*180180- * We still need a lock here for now to keep multiple FASYNC calls181181- * from racing with each other.180180+ * ->fasync() is responsible for setting the FASYNC bit.182181 */183183- lock_kernel();184184- if ((arg ^ filp->f_flags) & FASYNC) {185185- if (filp->f_op && filp->f_op->fasync) {186186- error = filp->f_op->fasync(fd, filp, (arg & FASYNC) != 0);187187- if (error < 0)188188- goto out;189189- }182182+ if (((arg ^ filp->f_flags) & FASYNC) && filp->f_op &&183183+ filp->f_op->fasync) {184184+ error = filp->f_op->fasync(fd, filp, (arg & FASYNC) != 0);185185+ if (error < 0)186186+ goto out;187187+ if (error > 0)188188+ error = 0;190189 }191191-190190+ spin_lock(&filp->f_lock);192191 filp->f_flags = (arg & SETFL_MASK) | (filp->f_flags & ~SETFL_MASK);192192+ spin_unlock(&filp->f_lock);193193+193194 out:194194- unlock_kernel();195195 return error;196196}197197···516516static struct kmem_cache *fasync_cache __read_mostly;517517518518/*519519- * fasync_helper() is used by some character device drivers (mainly mice)519519+ * fasync_helper() is used by almost all character device drivers520520 * to set up the fasync queue. It returns negative on error, 0 if it did521521 * no changes and positive if it added/deleted the entry.522522 */···555555 result = 1;556556 }557557out:558558+ /* Fix up FASYNC bit while still holding fasync_lock */559559+ spin_lock(&filp->f_lock);560560+ if (on)561561+ filp->f_flags |= FASYNC;562562+ else563563+ filp->f_flags &= ~FASYNC;564564+ spin_unlock(&filp->f_lock);558565 write_unlock_irq(&fasync_lock);559566 return result;560567}