From d03cea9afc8ae38737692ecf8bd595072052002c Mon Sep 17 00:00:00 2001
Message-Id: <d03cea9afc8ae38737692ecf8bd595072052002c.1427300678.git.jen@redhat.com>
In-Reply-To: <cd1e5c640073fe9f6f79125f2cbb3f434f1c7897.1427300678.git.jen@redhat.com>
References: <cd1e5c640073fe9f6f79125f2cbb3f434f1c7897.1427300678.git.jen@redhat.com>
From: Vlad Yasevich <vyasevic@redhat.com>
Date: Thu, 12 Mar 2015 19:13:17 -0500
Subject: [CHANGE 21/33] main-loop: drop rfds/wfds/xfds for good
To: rhvirt-patches@redhat.com,
    jen@redhat.com

RH-Author: Vlad Yasevich <vyasevic@redhat.com>
Message-id: <1426187601-21396-22-git-send-email-vyasevic@redhat.com>
Patchwork-id: 64359
O-Subject: [RHEL6.7 qemu-kvm PATCH v2 21/25] main-loop: drop rfds/wfds/xfds for good
Bugzilla: 1005016
RH-Acked-by: Juan Quintela <quintela@redhat.com>
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>

From: Stefan Hajnoczi <stefanha@redhat.com>

Now that all *_fill() and *_poll() functions use GPollFD we no longer
need rfds/wfds/xfds or pollfds_from_select()/pollfds_to_select().

>From now on everything uses GPollFD.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Message-id: 1361356113-11049-8-git-send-email-stefanha@redhat.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
(cherry picked from commit 9cbaacf999b01b27dc3a22502705178057af66de)
Signed-off-by: Jeff E. Nelson <jen@redhat.com>

Conflicts:
	main-loop.c

All the changes done in vl.c. A few extra small rearangements were
done to make the code a bit more readable.

Signed-off-by: Vlad Yasevich <vyasevic@redhat.com>
---
 vl.c | 72 ++------------------------------------------------------------------
 1 file changed, 2 insertions(+), 70 deletions(-)

Signed-off-by: Jeff E. Nelson <jen@redhat.com>
---
 vl.c | 72 ++------------------------------------------------------------------
 1 file changed, 2 insertions(+), 70 deletions(-)

diff --git a/vl.c b/vl.c
index b3ac0f1..95079ff 100644
--- a/vl.c
+++ b/vl.c
@@ -4016,68 +4016,10 @@ void vm_stop(RunState reason)
 #endif
 
 
-static fd_set rfds, wfds, xfds;
-static int nfds;
 static int glib_pollfds_idx;
 static int glib_n_poll_fds;
 static int max_priority;
 
-/* Load rfds/wfds/xfds into gpollfds.  Will be removed a few commits later. */
-static void gpollfds_from_select(void)
-{
-    int fd;
-    for (fd = 0; fd <= nfds; fd++) {
-        int events = 0;
-        if (FD_ISSET(fd, &rfds)) {
-            events |= G_IO_IN | G_IO_HUP | G_IO_ERR;
-        }
-        if (FD_ISSET(fd, &wfds)) {
-            events |= G_IO_OUT | G_IO_ERR;
-        }
-        if (FD_ISSET(fd, &xfds)) {
-            events |= G_IO_PRI;
-        }
-        if (events) {
-            GPollFD pfd = {
-                .fd = fd,
-                .events = events,
-            };
-            g_array_append_val(gpollfds, pfd);
-        }
-    }
-}
-
-/* Store gpollfds revents into rfds/wfds/xfds.  Will be removed a few commits
- * later.
- */
-static void gpollfds_to_select(int ret)
-{
-    int i;
-
-    FD_ZERO(&rfds);
-    FD_ZERO(&wfds);
-    FD_ZERO(&xfds);
-
-    if (ret <= 0) {
-        return;
-    }
-
-    for (i = 0; i < gpollfds->len; i++) {
-        int fd = g_array_index(gpollfds, GPollFD, i).fd;
-        int revents = g_array_index(gpollfds, GPollFD, i).revents;
-
-        if (revents & (G_IO_IN | G_IO_HUP | G_IO_ERR)) {
-            FD_SET(fd, &rfds);
-        }
-        if (revents & (G_IO_OUT | G_IO_ERR)) {
-            FD_SET(fd, &wfds);
-        }
-        if (revents & G_IO_PRI) {
-            FD_SET(fd, &xfds);
-        }
-    }
-}
-
 static void glib_pollfds_fill(int *cur_timeout)
 {
     GMainContext *context = g_main_context_default();
@@ -4121,28 +4063,18 @@ void main_loop_wait(int timeout)
     /* poll any events */
     g_array_set_size(gpollfds, 0); /* reset for new iteration */
     /* XXX: separate device handlers from system ones */
-    nfds = -1;
-    FD_ZERO(&rfds);
-    FD_ZERO(&wfds);
-    FD_ZERO(&xfds);
 
     qemu_iohandler_fill(gpollfds);
     slirp_pollfds_fill(gpollfds);
-
     glib_pollfds_fill(&timeout);
+
     os_host_main_loop_wait(&timeout);
 
-    /* We'll eventually drop fd_set completely.  But for now we still have
-     * *_fill() and *_poll() functions that use rfds/wfds/xfds.
-     */
-    gpollfds_from_select();
-
     qemu_mutex_unlock_iothread();
     ret = g_poll((GPollFD *)gpollfds->data, gpollfds->len, timeout);
     qemu_mutex_lock_iothread();
-    gpollfds_to_select(ret);
+
     qemu_iohandler_poll(gpollfds, ret);
-
     slirp_pollfds_poll(gpollfds, (ret < 0));
     glib_pollfds_poll();
 
-- 
2.1.0

