diff options
Diffstat (limited to 'fs/eventpoll.c')
-rw-r--r-- | fs/eventpoll.c | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/fs/eventpoll.c b/fs/eventpoll.c index 4284cd31eba6..1c2b16fda13a 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,7 +275,7 @@ 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; |
@@ -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 | ||
@@ -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); |