diff options
Diffstat (limited to 'fs/eventpoll.c')
-rw-r--r-- | fs/eventpoll.c | 63 |
1 files changed, 45 insertions, 18 deletions
diff --git a/fs/eventpoll.c b/fs/eventpoll.c index 1c8b55670804..da72250ddc1c 100644 --- a/fs/eventpoll.c +++ b/fs/eventpoll.c | |||
@@ -346,7 +346,7 @@ static inline struct epitem *ep_item_from_epqueue(poll_table *p) | |||
346 | /* Tells if the epoll_ctl(2) operation needs an event copy from userspace */ | 346 | /* Tells if the epoll_ctl(2) operation needs an event copy from userspace */ |
347 | static inline int ep_op_has_event(int op) | 347 | static inline int ep_op_has_event(int op) |
348 | { | 348 | { |
349 | return op != EPOLL_CTL_DEL; | 349 | return op == EPOLL_CTL_ADD || op == EPOLL_CTL_MOD; |
350 | } | 350 | } |
351 | 351 | ||
352 | /* Initialize the poll safe wake up structure */ | 352 | /* Initialize the poll safe wake up structure */ |
@@ -676,6 +676,34 @@ static int ep_remove(struct eventpoll *ep, struct epitem *epi) | |||
676 | return 0; | 676 | return 0; |
677 | } | 677 | } |
678 | 678 | ||
679 | /* | ||
680 | * Disables a "struct epitem" in the eventpoll set. Returns -EBUSY if the item | ||
681 | * had no event flags set, indicating that another thread may be currently | ||
682 | * handling that item's events (in the case that EPOLLONESHOT was being | ||
683 | * used). Otherwise a zero result indicates that the item has been disabled | ||
684 | * from receiving events. A disabled item may be re-enabled via | ||
685 | * EPOLL_CTL_MOD. Must be called with "mtx" held. | ||
686 | */ | ||
687 | static int ep_disable(struct eventpoll *ep, struct epitem *epi) | ||
688 | { | ||
689 | int result = 0; | ||
690 | unsigned long flags; | ||
691 | |||
692 | spin_lock_irqsave(&ep->lock, flags); | ||
693 | if (epi->event.events & ~EP_PRIVATE_BITS) { | ||
694 | if (ep_is_linked(&epi->rdllink)) | ||
695 | list_del_init(&epi->rdllink); | ||
696 | /* Ensure ep_poll_callback will not add epi back onto ready | ||
697 | list: */ | ||
698 | epi->event.events &= EP_PRIVATE_BITS; | ||
699 | } | ||
700 | else | ||
701 | result = -EBUSY; | ||
702 | spin_unlock_irqrestore(&ep->lock, flags); | ||
703 | |||
704 | return result; | ||
705 | } | ||
706 | |||
679 | static void ep_free(struct eventpoll *ep) | 707 | static void ep_free(struct eventpoll *ep) |
680 | { | 708 | { |
681 | struct rb_node *rbp; | 709 | struct rb_node *rbp; |
@@ -1020,8 +1048,6 @@ static void ep_rbtree_insert(struct eventpoll *ep, struct epitem *epi) | |||
1020 | rb_insert_color(&epi->rbn, &ep->rbr); | 1048 | rb_insert_color(&epi->rbn, &ep->rbr); |
1021 | } | 1049 | } |
1022 | 1050 | ||
1023 | |||
1024 | |||
1025 | #define PATH_ARR_SIZE 5 | 1051 | #define PATH_ARR_SIZE 5 |
1026 | /* | 1052 | /* |
1027 | * These are the number paths of length 1 to 5, that we are allowing to emanate | 1053 | * These are the number paths of length 1 to 5, that we are allowing to emanate |
@@ -1654,8 +1680,8 @@ SYSCALL_DEFINE1(epoll_create1, int, flags) | |||
1654 | error = PTR_ERR(file); | 1680 | error = PTR_ERR(file); |
1655 | goto out_free_fd; | 1681 | goto out_free_fd; |
1656 | } | 1682 | } |
1657 | fd_install(fd, file); | ||
1658 | ep->file = file; | 1683 | ep->file = file; |
1684 | fd_install(fd, file); | ||
1659 | return fd; | 1685 | return fd; |
1660 | 1686 | ||
1661 | out_free_fd: | 1687 | out_free_fd: |
@@ -1787,6 +1813,12 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd, | |||
1787 | } else | 1813 | } else |
1788 | error = -ENOENT; | 1814 | error = -ENOENT; |
1789 | break; | 1815 | break; |
1816 | case EPOLL_CTL_DISABLE: | ||
1817 | if (epi) | ||
1818 | error = ep_disable(ep, epi); | ||
1819 | else | ||
1820 | error = -ENOENT; | ||
1821 | break; | ||
1790 | } | 1822 | } |
1791 | mutex_unlock(&ep->mtx); | 1823 | mutex_unlock(&ep->mtx); |
1792 | 1824 | ||
@@ -1810,7 +1842,7 @@ SYSCALL_DEFINE4(epoll_wait, int, epfd, struct epoll_event __user *, events, | |||
1810 | int, maxevents, int, timeout) | 1842 | int, maxevents, int, timeout) |
1811 | { | 1843 | { |
1812 | int error; | 1844 | int error; |
1813 | struct file *file; | 1845 | struct fd f; |
1814 | struct eventpoll *ep; | 1846 | struct eventpoll *ep; |
1815 | 1847 | ||
1816 | /* The maximum number of event must be greater than zero */ | 1848 | /* The maximum number of event must be greater than zero */ |
@@ -1818,38 +1850,33 @@ SYSCALL_DEFINE4(epoll_wait, int, epfd, struct epoll_event __user *, events, | |||
1818 | return -EINVAL; | 1850 | return -EINVAL; |
1819 | 1851 | ||
1820 | /* Verify that the area passed by the user is writeable */ | 1852 | /* Verify that the area passed by the user is writeable */ |
1821 | if (!access_ok(VERIFY_WRITE, events, maxevents * sizeof(struct epoll_event))) { | 1853 | if (!access_ok(VERIFY_WRITE, events, maxevents * sizeof(struct epoll_event))) |
1822 | error = -EFAULT; | 1854 | return -EFAULT; |
1823 | goto error_return; | ||
1824 | } | ||
1825 | 1855 | ||
1826 | /* Get the "struct file *" for the eventpoll file */ | 1856 | /* Get the "struct file *" for the eventpoll file */ |
1827 | error = -EBADF; | 1857 | f = fdget(epfd); |
1828 | file = fget(epfd); | 1858 | if (!f.file) |
1829 | if (!file) | 1859 | return -EBADF; |
1830 | goto error_return; | ||
1831 | 1860 | ||
1832 | /* | 1861 | /* |
1833 | * We have to check that the file structure underneath the fd | 1862 | * We have to check that the file structure underneath the fd |
1834 | * the user passed to us _is_ an eventpoll file. | 1863 | * the user passed to us _is_ an eventpoll file. |
1835 | */ | 1864 | */ |
1836 | error = -EINVAL; | 1865 | error = -EINVAL; |
1837 | if (!is_file_epoll(file)) | 1866 | if (!is_file_epoll(f.file)) |
1838 | goto error_fput; | 1867 | goto error_fput; |
1839 | 1868 | ||
1840 | /* | 1869 | /* |
1841 | * At this point it is safe to assume that the "private_data" contains | 1870 | * At this point it is safe to assume that the "private_data" contains |
1842 | * our own data structure. | 1871 | * our own data structure. |
1843 | */ | 1872 | */ |
1844 | ep = file->private_data; | 1873 | ep = f.file->private_data; |
1845 | 1874 | ||
1846 | /* Time to fish for events ... */ | 1875 | /* Time to fish for events ... */ |
1847 | error = ep_poll(ep, events, maxevents, timeout); | 1876 | error = ep_poll(ep, events, maxevents, timeout); |
1848 | 1877 | ||
1849 | error_fput: | 1878 | error_fput: |
1850 | fput(file); | 1879 | fdput(f); |
1851 | error_return: | ||
1852 | |||
1853 | return error; | 1880 | return error; |
1854 | } | 1881 | } |
1855 | 1882 | ||