cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
Blob Blame History Raw
From 22f72cfdac645ac7a47289dbada48a116d19d42d Mon Sep 17 00:00:00 2001
From: "Daniel P. Berrange" <berrange@redhat.com>
Date: Thu, 8 Feb 2018 17:50:22 +0100
Subject: [PATCH 08/27] vnc-jobs: move buffer reset, use new buffer move

RH-Author: Daniel P. Berrange <berrange@redhat.com>
Message-id: <20180208175041.5634-9-berrange@redhat.com>
Patchwork-id: 78938
O-Subject: [RHEL-7.5 qemu-kvm PATCH v1 08/27] vnc-jobs: move buffer reset, use new buffer move
Bugzilla: 1527405
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
RH-Acked-by: Gerd Hoffmann <kraxel@redhat.com>
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>

From: Gerd Hoffmann <kraxel@redhat.com>

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Peter Lieven <pl@kamp.de>
Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
Message-id: 1446203414-4013-10-git-send-email-kraxel@redhat.com
(cherry picked from commit d90340115a3569caa72063775ff927f4dc353551)

 Conflicts:
	ui/vnc-jobs.c - context differences
	ui/vnc.{c.h} - make buffer_empty non-static since we don't
	               have util/buffer.{c,h} yet

Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
---
 ui/vnc-jobs.c | 15 ++++++++-------
 ui/vnc.c      |  2 +-
 ui/vnc.h      |  1 +
 3 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/ui/vnc-jobs.c b/ui/vnc-jobs.c
index a6dfdf6..e553bd9 100644
--- a/ui/vnc-jobs.c
+++ b/ui/vnc-jobs.c
@@ -29,6 +29,7 @@
 #include "vnc.h"
 #include "vnc-jobs.h"
 #include "qemu/sockets.h"
+#include "qemu/main-loop.h"
 
 /*
  * Locking:
@@ -164,8 +165,11 @@ void vnc_jobs_consume_buffer(VncState *vs)
 
     vnc_lock_output(vs);
     if (vs->jobs_buffer.offset) {
-        vnc_write(vs, vs->jobs_buffer.buffer, vs->jobs_buffer.offset);
-        buffer_reset(&vs->jobs_buffer);
+        if (vs->csock != -1 && buffer_empty(&vs->output)) {
+            qemu_set_fd_handler(vs->csock, vnc_client_read,
+                                vnc_client_write, vs);
+        }
+        buffer_move(&vs->output, &vs->jobs_buffer);
     }
     flush = vs->csock != -1 && vs->abort != true;
     vnc_unlock_output(vs);
@@ -192,8 +196,6 @@ static void vnc_async_encoding_start(VncState *orig, VncState *local)
     local->hextile = orig->hextile;
     local->zrle = orig->zrle;
     local->csock = -1; /* Don't do any network work on this thread */
-
-    buffer_reset(&local->output);
 }
 
 static void vnc_async_encoding_end(VncState *orig, VncState *local)
@@ -269,14 +271,13 @@ static int vnc_worker_thread_loop(VncJobQueue *queue)
 
     vnc_lock_output(job->vs);
     if (job->vs->csock != -1) {
-        buffer_reserve(&job->vs->jobs_buffer, vs.output.offset);
-        buffer_append(&job->vs->jobs_buffer, vs.output.buffer,
-                      vs.output.offset);
+        buffer_move(&job->vs->jobs_buffer, &vs.output);
         /* Copy persistent encoding data */
         vnc_async_encoding_end(job->vs, &vs);
 
 	qemu_bh_schedule(job->vs->bh);
     }  else {
+        buffer_reset(&vs.output);
         /* Copy persistent encoding data */
         vnc_async_encoding_end(job->vs, &vs);
     }
diff --git a/ui/vnc.c b/ui/vnc.c
index 95457ad..ebb6484 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -480,7 +480,7 @@ void buffer_reserve(Buffer *buffer, size_t len)
     }
 }
 
-static int buffer_empty(Buffer *buffer)
+int buffer_empty(Buffer *buffer)
 {
     return buffer->offset == 0;
 }
diff --git a/ui/vnc.h b/ui/vnc.h
index 703fef9..d8465ba 100644
--- a/ui/vnc.h
+++ b/ui/vnc.h
@@ -547,6 +547,7 @@ void buffer_reset(Buffer *buffer);
 void buffer_free(Buffer *buffer);
 void buffer_append(Buffer *buffer, const void *data, size_t len);
 void buffer_advance(Buffer *buf, size_t len);
+int buffer_empty(Buffer *buffer);
 uint8_t *buffer_end(Buffer *buffer);
 void buffer_move_empty(Buffer *to, Buffer *from);
 void buffer_move(Buffer *to, Buffer *from);
-- 
1.8.3.1