diff options
Diffstat (limited to 'fs/eventpoll.c')
-rw-r--r-- | fs/eventpoll.c | 44 |
1 files changed, 18 insertions, 26 deletions
diff --git a/fs/eventpoll.c b/fs/eventpoll.c index 4284cd31eba6..242fe1a66ce5 100644 --- a/fs/eventpoll.c +++ b/fs/eventpoll.c | |||
@@ -34,6 +34,7 @@ | |||
34 | #include <linux/eventpoll.h> | 34 | #include <linux/eventpoll.h> |
35 | #include <linux/mount.h> | 35 | #include <linux/mount.h> |
36 | #include <linux/bitops.h> | 36 | #include <linux/bitops.h> |
37 | #include <linux/mutex.h> | ||
37 | #include <asm/uaccess.h> | 38 | #include <asm/uaccess.h> |
38 | #include <asm/system.h> | 39 | #include <asm/system.h> |
39 | #include <asm/io.h> | 40 | #include <asm/io.h> |
@@ -46,7 +47,7 @@ | |||
46 | * LOCKING: | 47 | * LOCKING: |
47 | * There are three level of locking required by epoll : | 48 | * There are three level of locking required by epoll : |
48 | * | 49 | * |
49 | * 1) epsem (semaphore) | 50 | * 1) epmutex (mutex) |
50 | * 2) ep->sem (rw_semaphore) | 51 | * 2) ep->sem (rw_semaphore) |
51 | * 3) ep->lock (rw_lock) | 52 | * 3) ep->lock (rw_lock) |
52 | * | 53 | * |
@@ -67,9 +68,9 @@ | |||
67 | * if a file has been pushed inside an epoll set and it is then | 68 | * if a file has been pushed inside an epoll set and it is then |
68 | * close()d without a previous call toepoll_ctl(EPOLL_CTL_DEL). | 69 | * close()d without a previous call toepoll_ctl(EPOLL_CTL_DEL). |
69 | * It is possible to drop the "ep->sem" and to use the global | 70 | * It is possible to drop the "ep->sem" and to use the global |
70 | * semaphore "epsem" (together with "ep->lock") to have it working, | 71 | * semaphore "epmutex" (together with "ep->lock") to have it working, |
71 | * but having "ep->sem" will make the interface more scalable. | 72 | * but having "ep->sem" will make the interface more scalable. |
72 | * Events that require holding "epsem" are very rare, while for | 73 | * Events that require holding "epmutex" are very rare, while for |
73 | * normal operations the epoll private "ep->sem" will guarantee | 74 | * normal operations the epoll private "ep->sem" will guarantee |
74 | * a greater scalability. | 75 | * a greater scalability. |
75 | */ | 76 | */ |
@@ -274,22 +275,22 @@ static struct super_block *eventpollfs_get_sb(struct file_system_type *fs_type, | |||
274 | /* | 275 | /* |
275 | * This semaphore is used to serialize ep_free() and eventpoll_release_file(). | 276 | * This semaphore is used to serialize ep_free() and eventpoll_release_file(). |
276 | */ | 277 | */ |
277 | static struct semaphore epsem; | 278 | static struct mutex epmutex; |
278 | 279 | ||
279 | /* Safe wake up implementation */ | 280 | /* Safe wake up implementation */ |
280 | static struct poll_safewake psw; | 281 | static struct poll_safewake psw; |
281 | 282 | ||
282 | /* Slab cache used to allocate "struct epitem" */ | 283 | /* Slab cache used to allocate "struct epitem" */ |
283 | static kmem_cache_t *epi_cache; | 284 | static kmem_cache_t *epi_cache __read_mostly; |
284 | 285 | ||
285 | /* Slab cache used to allocate "struct eppoll_entry" */ | 286 | /* Slab cache used to allocate "struct eppoll_entry" */ |
286 | static kmem_cache_t *pwq_cache; | 287 | static kmem_cache_t *pwq_cache __read_mostly; |
287 | 288 | ||
288 | /* Virtual fs used to allocate inodes for eventpoll files */ | 289 | /* Virtual fs used to allocate inodes for eventpoll files */ |
289 | static struct vfsmount *eventpoll_mnt; | 290 | static struct vfsmount *eventpoll_mnt __read_mostly; |
290 | 291 | ||
291 | /* File callbacks that implement the eventpoll file behaviour */ | 292 | /* File callbacks that implement the eventpoll file behaviour */ |
292 | static struct file_operations eventpoll_fops = { | 293 | static const struct file_operations eventpoll_fops = { |
293 | .release = ep_eventpoll_close, | 294 | .release = ep_eventpoll_close, |
294 | .poll = ep_eventpoll_poll | 295 | .poll = ep_eventpoll_poll |
295 | }; | 296 | }; |
@@ -451,15 +452,6 @@ static void ep_poll_safewake(struct poll_safewake *psw, wait_queue_head_t *wq) | |||
451 | } | 452 | } |
452 | 453 | ||
453 | 454 | ||
454 | /* Used to initialize the epoll bits inside the "struct file" */ | ||
455 | void eventpoll_init_file(struct file *file) | ||
456 | { | ||
457 | |||
458 | INIT_LIST_HEAD(&file->f_ep_links); | ||
459 | spin_lock_init(&file->f_ep_lock); | ||
460 | } | ||
461 | |||
462 | |||
463 | /* | 455 | /* |
464 | * This is called from eventpoll_release() to unlink files from the eventpoll | 456 | * This is called from eventpoll_release() to unlink files from the eventpoll |
465 | * interface. We need to have this facility to cleanup correctly files that are | 457 | * interface. We need to have this facility to cleanup correctly files that are |
@@ -477,10 +469,10 @@ void eventpoll_release_file(struct file *file) | |||
477 | * cleanup path, and this means that noone is using this file anymore. | 469 | * cleanup path, and this means that noone is using this file anymore. |
478 | * The only hit might come from ep_free() but by holding the semaphore | 470 | * The only hit might come from ep_free() but by holding the semaphore |
479 | * will correctly serialize the operation. We do need to acquire | 471 | * will correctly serialize the operation. We do need to acquire |
480 | * "ep->sem" after "epsem" because ep_remove() requires it when called | 472 | * "ep->sem" after "epmutex" because ep_remove() requires it when called |
481 | * from anywhere but ep_free(). | 473 | * from anywhere but ep_free(). |
482 | */ | 474 | */ |
483 | down(&epsem); | 475 | mutex_lock(&epmutex); |
484 | 476 | ||
485 | while (!list_empty(lsthead)) { | 477 | while (!list_empty(lsthead)) { |
486 | epi = list_entry(lsthead->next, struct epitem, fllink); | 478 | epi = list_entry(lsthead->next, struct epitem, fllink); |
@@ -492,7 +484,7 @@ void eventpoll_release_file(struct file *file) | |||
492 | up_write(&ep->sem); | 484 | up_write(&ep->sem); |
493 | } | 485 | } |
494 | 486 | ||
495 | up(&epsem); | 487 | mutex_unlock(&epmutex); |
496 | } | 488 | } |
497 | 489 | ||
498 | 490 | ||
@@ -607,7 +599,7 @@ sys_epoll_ctl(int epfd, int op, int fd, struct epoll_event __user *event) | |||
607 | switch (op) { | 599 | switch (op) { |
608 | case EPOLL_CTL_ADD: | 600 | case EPOLL_CTL_ADD: |
609 | if (!epi) { | 601 | if (!epi) { |
610 | epds.events |= POLLERR | POLLHUP; | 602 | epds.events |= POLLERR | POLLHUP | POLLRDHUP; |
611 | 603 | ||
612 | error = ep_insert(ep, &epds, tfile, fd); | 604 | error = ep_insert(ep, &epds, tfile, fd); |
613 | } else | 605 | } else |
@@ -621,7 +613,7 @@ sys_epoll_ctl(int epfd, int op, int fd, struct epoll_event __user *event) | |||
621 | break; | 613 | break; |
622 | case EPOLL_CTL_MOD: | 614 | case EPOLL_CTL_MOD: |
623 | if (epi) { | 615 | if (epi) { |
624 | epds.events |= POLLERR | POLLHUP; | 616 | epds.events |= POLLERR | POLLHUP | POLLRDHUP; |
625 | error = ep_modify(ep, epi, &epds); | 617 | error = ep_modify(ep, epi, &epds); |
626 | } else | 618 | } else |
627 | error = -ENOENT; | 619 | error = -ENOENT; |
@@ -819,9 +811,9 @@ static void ep_free(struct eventpoll *ep) | |||
819 | * We do not need to hold "ep->sem" here because the epoll file | 811 | * We do not need to hold "ep->sem" here because the epoll file |
820 | * is on the way to be removed and no one has references to it | 812 | * is on the way to be removed and no one has references to it |
821 | * anymore. The only hit might come from eventpoll_release_file() but | 813 | * anymore. The only hit might come from eventpoll_release_file() but |
822 | * holding "epsem" is sufficent here. | 814 | * holding "epmutex" is sufficent here. |
823 | */ | 815 | */ |
824 | down(&epsem); | 816 | mutex_lock(&epmutex); |
825 | 817 | ||
826 | /* | 818 | /* |
827 | * Walks through the whole tree by unregistering poll callbacks. | 819 | * Walks through the whole tree by unregistering poll callbacks. |
@@ -843,7 +835,7 @@ static void ep_free(struct eventpoll *ep) | |||
843 | ep_remove(ep, epi); | 835 | ep_remove(ep, epi); |
844 | } | 836 | } |
845 | 837 | ||
846 | up(&epsem); | 838 | mutex_unlock(&epmutex); |
847 | } | 839 | } |
848 | 840 | ||
849 | 841 | ||
@@ -1615,7 +1607,7 @@ static int __init eventpoll_init(void) | |||
1615 | { | 1607 | { |
1616 | int error; | 1608 | int error; |
1617 | 1609 | ||
1618 | init_MUTEX(&epsem); | 1610 | mutex_init(&epmutex); |
1619 | 1611 | ||
1620 | /* Initialize the structure used to perform safe poll wait head wake ups */ | 1612 | /* Initialize the structure used to perform safe poll wait head wake ups */ |
1621 | ep_poll_safewake_init(&psw); | 1613 | ep_poll_safewake_init(&psw); |