From f3b6702ab914845f56fbdd5fd4bb9b5b1329cc76 Mon Sep 17 00:00:00 2001
From: Gerd Hoffmann <kraxel@redhat.com>
Date: Wed, 15 Jun 2011 11:05:13 -0300
Subject: [RHEL6 qemu-kvm PATCH 04/10] Revert "qxl/spice-display: move pipe to ssd"

RH-Author: Gerd Hoffmann <kraxel@redhat.com>
Message-id: <1308135919-4065-5-git-send-email-kraxel@redhat.com>
Patchwork-id: 27148
O-Subject: [RHEL-6.2 kvm PATCH 04/10] Revert "qxl/spice-display: move pipe to ssd"
Bugzilla: 674583 705070
RH-Acked-by: Alon Levy <alevy@redhat.com>
RH-Acked-by: Hans de Goede <hdegoede@redhat.com>
RH-Acked-by: Jes Sorensen <Jes.Sorensen@redhat.com>
RH-Acked-by: Arnon Gilboa <agilboa@redhat.com>

This reverts commit 1178a90836d6727d0ddaf56754c5da1f9663ab19.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/qxl.c           |   22 +++++++++++++++++-----
 hw/qxl.h           |    4 ++++
 ui/spice-display.c |   21 ---------------------
 ui/spice-display.h |    8 --------
 4 files changed, 21 insertions(+), 34 deletions(-)

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/qxl.c           |   22 +++++++++++++++++-----
 hw/qxl.h           |    4 ++++
 ui/spice-display.c |   21 ---------------------
 ui/spice-display.h |    8 --------
 4 files changed, 21 insertions(+), 34 deletions(-)

diff --git a/hw/qxl.c b/hw/qxl.c
index 4ed4c2e..61fd1fc 100644
--- a/hw/qxl.c
+++ b/hw/qxl.c
@@ -1062,7 +1062,7 @@ static void pipe_read(void *opaque)
     int len;
 
     do {
-        len = read(d->ssd.pipe[0], &dummy, sizeof(dummy));
+        len = read(d->pipe[0], &dummy, sizeof(dummy));
     } while (len == sizeof(dummy));
     qxl_set_irq(d);
 }
@@ -1078,11 +1078,10 @@ static void qxl_send_events(PCIQXLDevice *d, uint32_t events)
     if ((old_pending & le_events) == le_events) {
         return;
     }
-    if (pthread_self() == d->ssd.main) {
-        /* running in io_thread thread */
+    if (pthread_self() == d->main) {
         qxl_set_irq(d);
     } else {
-        if (write(d->ssd.pipe[1], d, 1) != 1) {
+        if (write(d->pipe[1], d, 1) != 1) {
             dprint(d, 1, "%s: write to pipe failed\n", __FUNCTION__);
         }
     }
@@ -1090,7 +1089,20 @@ static void qxl_send_events(PCIQXLDevice *d, uint32_t events)
 
 static void init_pipe_signaling(PCIQXLDevice *d)
 {
-   qxl_create_server_to_iothread_pipe(&d->ssd, pipe_read);
+   if (pipe(d->pipe) < 0) {
+       dprint(d, 1, "%s: pipe creation failed\n", __FUNCTION__);
+       return;
+   }
+#ifdef CONFIG_IOTHREAD
+   fcntl(d->pipe[0], F_SETFL, O_NONBLOCK);
+#else
+   fcntl(d->pipe[0], F_SETFL, O_NONBLOCK /* | O_ASYNC */);
+#endif
+   fcntl(d->pipe[1], F_SETFL, O_NONBLOCK);
+   fcntl(d->pipe[0], F_SETOWN, getpid());
+
+   d->main = pthread_self();
+   qemu_set_fd_handler(d->pipe[0], pipe_read, NULL, d);
 }
 
 /* graphics console */
diff --git a/hw/qxl.h b/hw/qxl.h
index 701245f..f6c450d 100644
--- a/hw/qxl.h
+++ b/hw/qxl.h
@@ -55,6 +55,10 @@ typedef struct PCIQXLDevice {
     } guest_surfaces;
     QXLPHYSICAL        guest_cursor;
 
+    /* thread signaling */
+    pthread_t          main;
+    int                pipe[2];
+
     /* ram pci bar */
     QXLRam             *ram;
     VGACommonState     vga;
diff --git a/ui/spice-display.c b/ui/spice-display.c
index b838e01..99d9fd6 100644
--- a/ui/spice-display.c
+++ b/ui/spice-display.c
@@ -395,27 +395,6 @@ static DisplayChangeListener display_listener = {
     .dpy_refresh = display_refresh,
 };
 
-void qxl_create_server_to_iothread_pipe(SimpleSpiceDisplay *ssd,
-    IOHandler *pipe_read)
-{
-    if (pipe(ssd->pipe) < 0) {
-        fprintf(stderr, "%s: pipe creation failed\n", __FUNCTION__);
-        return;
-    }
-
-#ifdef CONFIG_IOTHREAD
-    fcntl(ssd->pipe[0], F_SETFL, O_NONBLOCK);
-#else
-    fcntl(ssd->pipe[0], F_SETFL, O_NONBLOCK /* | O_ASYNC */);
-#endif
-    fcntl(ssd->pipe[1], F_SETFL, O_NONBLOCK);
-
-    fcntl(ssd->pipe[0], F_SETOWN, getpid());
-
-    qemu_set_fd_handler(ssd->pipe[0], pipe_read, NULL, ssd);
-    ssd->main = pthread_self();
-}
-
 void qemu_spice_display_init(DisplayState *ds)
 {
     assert(sdpy.ds == NULL);
diff --git a/ui/spice-display.h b/ui/spice-display.h
index 3e6cf7c..aef0464 100644
--- a/ui/spice-display.h
+++ b/ui/spice-display.h
@@ -43,11 +43,6 @@ typedef struct SimpleSpiceDisplay {
     QXLRect dirty;
     int notify;
     int running;
-
-    /* thread signaling - used both in qxl (in vga mode
-     * and in native mode) and without qxl */
-    pthread_t          main;
-    int                pipe[2];     /* to iothread */
 } SimpleSpiceDisplay;
 
 typedef struct SimpleSpiceUpdate {
@@ -71,6 +66,3 @@ void qemu_spice_display_update(SimpleSpiceDisplay *ssd,
                                int x, int y, int w, int h);
 void qemu_spice_display_resize(SimpleSpiceDisplay *ssd);
 void qemu_spice_display_refresh(SimpleSpiceDisplay *ssd);
-/* used by both qxl and spice-display */
-void qxl_create_server_to_iothread_pipe(SimpleSpiceDisplay *ssd,
-    IOHandler *pipe_read);
-- 
1.7.3.2

