[PATCH 07/18] move red_dispatcher_on_vm_stop and red_dispatcher_on_vm_start to RedsState

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Jonathon Jongsma <jjongsma@xxxxxxxxxx>
Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx>
---
 server/red-dispatcher.c | 33 +++++++--------------------------
 server/red-dispatcher.h |  3 +++
 server/reds.c           | 35 +++++++++++++++++++++++++++++++----
 3 files changed, 41 insertions(+), 30 deletions(-)

diff --git a/server/red-dispatcher.c b/server/red-dispatcher.c
index f634d28..40d13fe 100644
--- a/server/red-dispatcher.c
+++ b/server/red-dispatcher.c
@@ -599,7 +599,7 @@ static void qxl_worker_oom(QXLWorker *qxl_worker)
     red_dispatcher_oom((RedDispatcher*)qxl_worker);
 }
 
-static void red_dispatcher_start(RedDispatcher *dispatcher)
+void red_dispatcher_start(RedDispatcher *dispatcher)
 {
     RedWorkerMessageStart payload;
 
@@ -647,7 +647,7 @@ static void red_dispatcher_driver_unload(RedDispatcher *dispatcher)
                             &payload);
 }
 
-static void red_dispatcher_stop(RedDispatcher *dispatcher)
+void red_dispatcher_stop(RedDispatcher *dispatcher)
 {
     RedWorkerMessageStop payload;
 
@@ -682,31 +682,15 @@ static void qxl_worker_loadvm_commands(QXLWorker *qxl_worker,
     red_dispatcher_loadvm_commands((RedDispatcher*)qxl_worker, ext, count);
 }
 
-void red_dispatcher_set_compression_level(RedDispatcher *dispatcher, int level)
-{
-    dispatcher->qxl->st->qif->set_compression_level(dispatcher->qxl, level);
-}
-
-void red_dispatcher_on_vm_stop(void)
+void red_dispatcher_attach_worker(RedDispatcher *dispatcher)
 {
-    RedDispatcher *now = dispatchers;
-
-    spice_debug(NULL);
-    while (now) {
-        red_dispatcher_stop(now);
-        now = now->next;
-    }
+    QXLInstance *qxl = dispatcher->qxl;
+    qxl->st->qif->attache_worker(qxl, &dispatcher->base);
 }
 
-void red_dispatcher_on_vm_start(void)
+void red_dispatcher_set_compression_level(RedDispatcher *dispatcher, int level)
 {
-    RedDispatcher *now = dispatchers;
-
-    spice_debug(NULL);
-    while (now) {
-        red_dispatcher_start(now);
-        now = now->next;
-    }
+    dispatcher->qxl->st->qif->set_compression_level(dispatcher->qxl, level);
 }
 
 uint32_t red_dispatcher_qxl_ram_size(void)
@@ -1028,9 +1012,6 @@ void red_dispatcher_init(QXLInstance *qxl)
     qxl->st->dispatcher = red_dispatcher;
     red_dispatcher->next = dispatchers;
     dispatchers = red_dispatcher;
-
-    qxl->st->qif->attache_worker(qxl, &red_dispatcher->base);
-    qxl->st->qif->set_compression_level(qxl, calc_compression_level(reds));
 }
 
 struct Dispatcher *red_dispatcher_get_dispatcher(RedDispatcher *red_dispatcher)
diff --git a/server/red-dispatcher.h b/server/red-dispatcher.h
index 2279680..9614544 100644
--- a/server/red-dispatcher.h
+++ b/server/red-dispatcher.h
@@ -29,7 +29,10 @@ void red_dispatcher_init(QXLInstance *qxl);
 void red_dispatcher_on_ic_change(RedDispatcher *dispatcher, SpiceImageCompression ic);
 void red_dispatcher_on_sv_change(RedDispatcher *dispatcher, int sv);
 void red_dispatcher_set_mouse_mode(RedDispatcher *dispatcher, uint32_t mode);
+void red_dispatcher_attach_worker(RedDispatcher *dispatcher);
 void red_dispatcher_set_compression_level(RedDispatcher *dispatcher, int level);
+void red_dispatcher_stop(RedDispatcher *dispatcher);
+void red_dispatcher_start(RedDispatcher *dispatcher);
 void red_dispatcher_on_vm_stop(void);
 void red_dispatcher_on_vm_start(void);
 uint32_t red_dispatcher_qxl_ram_size(void);
diff --git a/server/reds.c b/server/reds.c
index 0f8f69a..57b01b0 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -174,6 +174,8 @@ static void reds_char_device_remove_state(RedsState *reds, SpiceCharDeviceState
 static void reds_send_mm_time(RedsState *reds);
 static void reds_on_ic_change(RedsState *reds);
 static void reds_on_sv_change(RedsState *reds);
+static void reds_on_vm_stop(RedsState *reds);
+static void reds_on_vm_start(RedsState *reds);
 
 static VDIReadBuf *vdi_port_state_get_read_buf(VDIPortState *state);
 static VDIReadBuf *vdi_port_read_buf_ref(VDIReadBuf *buf);
@@ -3190,6 +3192,7 @@ SPICE_GNUC_VISIBLE int spice_server_add_interface(SpiceServer *s,
         }
     } else if (strcmp(interface->type, SPICE_INTERFACE_QXL) == 0) {
         QXLInstance *qxl;
+        RedDispatcher *dispatcher;
 
         spice_info("SPICE_INTERFACE_QXL");
         if (interface->major_version != SPICE_INTERFACE_QXL_MAJOR ||
@@ -3204,8 +3207,16 @@ SPICE_GNUC_VISIBLE int spice_server_add_interface(SpiceServer *s,
         qxl->st->scanout.drm_dma_buf_fd = -1;
         qxl->st->qif = SPICE_CONTAINEROF(interface, QXLInterface, base);
         red_dispatcher_init(qxl);
-        reds->dispatchers = g_list_prepend(reds->dispatchers, qxl->st->dispatcher);
-
+        dispatcher = qxl->st->dispatcher;
+        reds->dispatchers = g_list_prepend(reds->dispatchers, dispatcher);
+
+        /* this function has to be called after the dispatcher is on the list
+         * as QXLInstance clients expect the dispatcher to be on the list when
+         * this callback is called. This as clients assume they can start the
+         * dispatchers. Also note that this should be the first callback to
+         * be called. */
+        red_dispatcher_attach_worker(dispatcher);
+        red_dispatcher_set_compression_level(dispatcher, calc_compression_level(reds));
     } else if (strcmp(interface->type, SPICE_INTERFACE_TABLET) == 0) {
         SpiceTabletInstance *tablet = SPICE_CONTAINEROF(sin, SpiceTabletInstance, base);
         spice_info("SPICE_INTERFACE_TABLET");
@@ -3999,7 +4010,7 @@ SPICE_GNUC_VISIBLE void spice_server_vm_start(SpiceServer *s)
         st_item = SPICE_CONTAINEROF(item, SpiceCharDeviceStateItem, link);
         spice_char_device_start(st_item->st);
     }
-    red_dispatcher_on_vm_start();
+    reds_on_vm_start(reds);
 }
 
 SPICE_GNUC_VISIBLE void spice_server_vm_stop(SpiceServer *s)
@@ -4014,7 +4025,7 @@ SPICE_GNUC_VISIBLE void spice_server_vm_stop(SpiceServer *s)
         st_item = SPICE_CONTAINEROF(item, SpiceCharDeviceStateItem, link);
         spice_char_device_stop(st_item->st);
     }
-    red_dispatcher_on_vm_stop();
+    reds_on_vm_stop(reds);
 }
 
 SPICE_GNUC_VISIBLE void spice_server_set_seamless_migration(SpiceServer *s, int enable)
@@ -4087,3 +4098,19 @@ void reds_on_sv_change(RedsState *reds)
         red_dispatcher_on_sv_change(d, reds_get_streaming_video(reds));
     }
 }
+
+void reds_on_vm_stop(RedsState *reds)
+{
+    GList *l;
+
+    for (l = reds->dispatchers; l != NULL; l = l->next)
+        red_dispatcher_stop(l->data);
+}
+
+void reds_on_vm_start(RedsState *reds)
+{
+    GList *l;
+
+    for (l = reds->dispatchers; l != NULL; l = l->next)
+        red_dispatcher_start(l->data);
+}
-- 
2.5.0

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]