vfs: do bulk POLL* -> EPOLL* replacement
[linux-block.git] / fs / eventpoll.c
index 42e35a6977c9e5cafc8a0eafd02e8e3af359e3af..0f3494ed3ed0cf17f0bc7c7148c312512abb32b4 100644 (file)
@@ -95,9 +95,9 @@
 /* Epoll private bits inside the event mask */
 #define EP_PRIVATE_BITS (EPOLLWAKEUP | EPOLLONESHOT | EPOLLET | EPOLLEXCLUSIVE)
 
-#define EPOLLINOUT_BITS (POLLIN | POLLOUT)
+#define EPOLLINOUT_BITS (EPOLLIN | EPOLLOUT)
 
-#define EPOLLEXCLUSIVE_OK_BITS (EPOLLINOUT_BITS | POLLERR | POLLHUP | \
+#define EPOLLEXCLUSIVE_OK_BITS (EPOLLINOUT_BITS | EPOLLERR | EPOLLHUP | \
                                EPOLLWAKEUP | EPOLLET | EPOLLEXCLUSIVE)
 
 /* Maximum number of nesting allowed inside epoll sets */
@@ -260,6 +260,7 @@ struct ep_pqueue {
 struct ep_send_events_data {
        int maxevents;
        struct epoll_event __user *events;
+       int res;
 };
 
 /*
@@ -554,7 +555,7 @@ static int ep_poll_wakeup_proc(void *priv, void *cookie, int call_nests)
        wait_queue_head_t *wqueue = (wait_queue_head_t *)cookie;
 
        spin_lock_irqsave_nested(&wqueue->lock, flags, call_nests + 1);
-       wake_up_locked_poll(wqueue, POLLIN);
+       wake_up_locked_poll(wqueue, EPOLLIN);
        spin_unlock_irqrestore(&wqueue->lock, flags);
 
        return 0;
@@ -574,7 +575,7 @@ static void ep_poll_safewake(wait_queue_head_t *wq)
 
 static void ep_poll_safewake(wait_queue_head_t *wq)
 {
-       wake_up_poll(wq, POLLIN);
+       wake_up_poll(wq, EPOLLIN);
 }
 
 #endif
@@ -660,12 +661,13 @@ static inline void ep_pm_stay_awake_rcu(struct epitem *epi)
  *
  * Returns: The same integer error code returned by the @sproc callback.
  */
-static int ep_scan_ready_list(struct eventpoll *ep,
-                             int (*sproc)(struct eventpoll *,
+static __poll_t ep_scan_ready_list(struct eventpoll *ep,
+                             __poll_t (*sproc)(struct eventpoll *,
                                           struct list_head *, void *),
                              void *priv, int depth, bool ep_locked)
 {
-       int error, pwake = 0;
+       __poll_t res;
+       int pwake = 0;
        unsigned long flags;
        struct epitem *epi, *nepi;
        LIST_HEAD(txlist);
@@ -694,7 +696,7 @@ static int ep_scan_ready_list(struct eventpoll *ep,
        /*
         * Now call the callback function.
         */
-       error = (*sproc)(ep, &txlist, priv);
+       res = (*sproc)(ep, &txlist, priv);
 
        spin_lock_irqsave(&ep->lock, flags);
        /*
@@ -747,7 +749,7 @@ static int ep_scan_ready_list(struct eventpoll *ep,
        if (pwake)
                ep_poll_safewake(&ep->poll_wait);
 
-       return error;
+       return res;
 }
 
 static void epi_rcu_free(struct rcu_head *head)
@@ -864,7 +866,7 @@ static int ep_eventpoll_release(struct inode *inode, struct file *file)
        return 0;
 }
 
-static int ep_read_events_proc(struct eventpoll *ep, struct list_head *head,
+static __poll_t ep_read_events_proc(struct eventpoll *ep, struct list_head *head,
                               void *priv);
 static void ep_ptable_queue_proc(struct file *file, wait_queue_head_t *whead,
                                 poll_table *pt);
@@ -874,7 +876,7 @@ static void ep_ptable_queue_proc(struct file *file, wait_queue_head_t *whead,
  * the ep->mtx so we need to start from depth=1, such that mutex_lock_nested()
  * is correctly annotated.
  */
-static unsigned int ep_item_poll(const struct epitem *epi, poll_table *pt,
+static __poll_t ep_item_poll(const struct epitem *epi, poll_table *pt,
                                 int depth)
 {
        struct eventpoll *ep;
@@ -894,7 +896,7 @@ static unsigned int ep_item_poll(const struct epitem *epi, poll_table *pt,
                                  locked) & epi->event.events;
 }
 
-static int ep_read_events_proc(struct eventpoll *ep, struct list_head *head,
+static __poll_t ep_read_events_proc(struct eventpoll *ep, struct list_head *head,
                               void *priv)
 {
        struct epitem *epi, *tmp;
@@ -906,7 +908,7 @@ static int ep_read_events_proc(struct eventpoll *ep, struct list_head *head,
 
        list_for_each_entry_safe(epi, tmp, head, rdllink) {
                if (ep_item_poll(epi, &pt, depth)) {
-                       return POLLIN | POLLRDNORM;
+                       return EPOLLIN | EPOLLRDNORM;
                } else {
                        /*
                         * Item has been dropped into the ready list by the poll
@@ -1179,12 +1181,12 @@ static int ep_poll_callback(wait_queue_entry_t *wait, unsigned mode, int sync, v
                if ((epi->event.events & EPOLLEXCLUSIVE) &&
                                        !(pollflags & POLLFREE)) {
                        switch (pollflags & EPOLLINOUT_BITS) {
-                       case POLLIN:
-                               if (epi->event.events & POLLIN)
+                       case EPOLLIN:
+                               if (epi->event.events & EPOLLIN)
                                        ewake = 1;
                                break;
-                       case POLLOUT:
-                               if (epi->event.events & POLLOUT)
+                       case EPOLLOUT:
+                               if (epi->event.events & EPOLLOUT)
                                        ewake = 1;
                                break;
                        case 0:
@@ -1414,7 +1416,8 @@ static noinline void ep_destroy_wakeup_source(struct epitem *epi)
 static int ep_insert(struct eventpoll *ep, const struct epoll_event *event,
                     struct file *tfile, int fd, int full_check)
 {
-       int error, revents, pwake = 0;
+       int error, pwake = 0;
+       __poll_t revents;
        unsigned long flags;
        long user_watches;
        struct epitem *epi;
@@ -1612,12 +1615,11 @@ static int ep_modify(struct eventpoll *ep, struct epitem *epi,
        return 0;
 }
 
-static int ep_send_events_proc(struct eventpoll *ep, struct list_head *head,
+static __poll_t ep_send_events_proc(struct eventpoll *ep, struct list_head *head,
                               void *priv)
 {
        struct ep_send_events_data *esed = priv;
-       int eventcnt;
-       unsigned int revents;
+       __poll_t revents;
        struct epitem *epi;
        struct epoll_event __user *uevent;
        struct wakeup_source *ws;
@@ -1630,8 +1632,8 @@ static int ep_send_events_proc(struct eventpoll *ep, struct list_head *head,
         * Items cannot vanish during the loop because ep_scan_ready_list() is
         * holding "mtx" during this call.
         */
-       for (eventcnt = 0, uevent = esed->events;
-            !list_empty(head) && eventcnt < esed->maxevents;) {
+       for (esed->res = 0, uevent = esed->events;
+            !list_empty(head) && esed->res < esed->maxevents;) {
                epi = list_first_entry(head, struct epitem, rdllink);
 
                /*
@@ -1665,9 +1667,11 @@ static int ep_send_events_proc(struct eventpoll *ep, struct list_head *head,
                            __put_user(epi->event.data, &uevent->data)) {
                                list_add(&epi->rdllink, head);
                                ep_pm_stay_awake(epi);
-                               return eventcnt ? eventcnt : -EFAULT;
+                               if (!esed->res)
+                                       esed->res = -EFAULT;
+                               return 0;
                        }
-                       eventcnt++;
+                       esed->res++;
                        uevent++;
                        if (epi->event.events & EPOLLONESHOT)
                                epi->event.events &= EP_PRIVATE_BITS;
@@ -1689,7 +1693,7 @@ static int ep_send_events_proc(struct eventpoll *ep, struct list_head *head,
                }
        }
 
-       return eventcnt;
+       return 0;
 }
 
 static int ep_send_events(struct eventpoll *ep,
@@ -1700,7 +1704,8 @@ static int ep_send_events(struct eventpoll *ep,
        esed.maxevents = maxevents;
        esed.events = events;
 
-       return ep_scan_ready_list(ep, ep_send_events_proc, &esed, 0, false);
+       ep_scan_ready_list(ep, ep_send_events_proc, &esed, 0, false);
+       return esed.res;
 }
 
 static inline struct timespec64 ep_set_mstimeout(long ms)
@@ -2100,7 +2105,7 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd,
        switch (op) {
        case EPOLL_CTL_ADD:
                if (!epi) {
-                       epds.events |= POLLERR | POLLHUP;
+                       epds.events |= EPOLLERR | EPOLLHUP;
                        error = ep_insert(ep, &epds, tf.file, fd, full_check);
                } else
                        error = -EEXIST;
@@ -2116,7 +2121,7 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd,
        case EPOLL_CTL_MOD:
                if (epi) {
                        if (!(epi->event.events & EPOLLEXCLUSIVE)) {
-                               epds.events |= POLLERR | POLLHUP;
+                               epds.events |= EPOLLERR | EPOLLHUP;
                                error = ep_modify(ep, epi, &epds);
                        }
                } else