[Spice-devel] [PATCH server 5/7] spicevmc: do not use recv_device_from_client_buf sending compressed data

Snir Sheriber ssheribe at redhat.com
Sun May 29 14:30:17 UTC 2016


From: Frediano Ziglio <fziglio at redhat.com>

Allocate buffer directly from RedCharDevice.
This avoids to attach a buffer to SpiceVmsState just for detaching in
the same function.
RedCharDevice already use pooling on RedCharDeviceWriteBuffer.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 server/spicevmc.c | 37 +++++++++++++++----------------------
 1 file changed, 15 insertions(+), 22 deletions(-)

diff --git a/server/spicevmc.c b/server/spicevmc.c
index d7ef5ba..28ea8e9 100644
--- a/server/spicevmc.c
+++ b/server/spicevmc.c
@@ -111,10 +111,6 @@ enum {
     RED_PIPE_ITEM_TYPE_PORT_EVENT,
 };
 
-static uint8_t *spicevmc_red_channel_alloc_msg_rcv_buf(RedChannelClient *rcc,
-                                                       uint16_t type,
-                                                       uint32_t size);
-
 static void spicevmc_red_channel_release_msg_rcv_buf(RedChannelClient *rcc,
                                                      uint16_t type,
                                                      uint32_t size,
@@ -337,16 +333,21 @@ static int spicevmc_channel_client_handle_migrate_data(RedChannelClient *rcc,
     return red_char_device_restore(state->chardev, &mig_data->base);
 }
 
-static int try_handle_compressed_msg(RedChannelClient *rcc, SpiceMsgCompressedData *compressed_data_msg)
+static int handle_compressed_msg(SpiceVmcState *state, RedChannelClient *rcc,
+                                 SpiceMsgCompressedData *compressed_data_msg)
 {
     /* NOTE: *decompressed is free by the char-device */
-    SpiceVmcState *state;
     int decompressed_size;
     uint8_t *decompressed;
+    RedCharDeviceWriteBuffer *write_buf;
+
+    write_buf = red_char_device_write_buffer_get(state->chardev, rcc->client,
+                                                 compressed_data_msg->uncompressed_size);
+    if (!write_buf) {
+        return FALSE;
+    }
+    decompressed = write_buf->buf;
 
-    state = spicevmc_red_channel_client_get_state(rcc);
-    decompressed = spicevmc_red_channel_alloc_msg_rcv_buf(rcc,SPICE_MSGC_SPICEVMC_DATA,
-                                                          compressed_data_msg->uncompressed_size);
     switch (compressed_data_msg->type) {
 #ifdef USE_LZ4
     case SPICE_DATA_COMPRESSION_TYPE_LZ4:
@@ -358,22 +359,16 @@ static int try_handle_compressed_msg(RedChannelClient *rcc, SpiceMsgCompressedDa
 #endif
     default:
         spice_warning("Invalid Compression Type");
-        spicevmc_red_channel_release_msg_rcv_buf(rcc,SPICE_MSGC_SPICEVMC_DATA,
-                                                 compressed_data_msg->uncompressed_size,
-                                                 decompressed);
+        red_char_device_write_buffer_release(state->chardev, &write_buf);
         return FALSE;
     }
     if (decompressed_size != compressed_data_msg->uncompressed_size) {
         spice_warning("Decompression Error");
-        spicevmc_red_channel_release_msg_rcv_buf(rcc, SPICE_MSGC_SPICEVMC_DATA,
-                                                 compressed_data_msg->uncompressed_size,
-                                                 decompressed);
+        red_char_device_write_buffer_release(state->chardev, &write_buf);
         return FALSE;
     }
-    spice_assert(state->recv_from_client_buf->buf == decompressed);
-    state->recv_from_client_buf->buf_used = decompressed_size;
-    red_char_device_write_buffer_add(state->chardev, state->recv_from_client_buf);
-    state->recv_from_client_buf = NULL;
+    write_buf->buf_used = decompressed_size;
+    red_char_device_write_buffer_add(state->chardev, write_buf);
     return TRUE;
 }
 
@@ -398,9 +393,7 @@ static int spicevmc_red_channel_client_handle_message_parsed(RedChannelClient *r
         state->recv_from_client_buf = NULL;
         break;
     case SPICE_MSGC_SPICEVMC_COMPRESSED_DATA:
-        if (!try_handle_compressed_msg(rcc, (SpiceMsgCompressedData*)msg)) {
-            return FALSE;
-        }
+        return handle_compressed_msg(state, rcc, (SpiceMsgCompressedData*)msg);
         break;
     case SPICE_MSGC_PORT_EVENT:
         if (size != sizeof(uint8_t)) {
-- 
2.5.5



More information about the Spice-devel mailing list