[Spice-devel] [PATCH 5/6] spicevmc: do not use recv_device_from_client_buf sending compressed data
Frediano Ziglio
fziglio at redhat.com
Thu May 19 12:50:41 UTC 2016
>
> Hi,
>
> On 05/17/2016 01:04 PM, Frediano Ziglio wrote:
> > 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 97eb04c..0c8ba51 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,
> > @@ -338,16 +334,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;
> > uint32_t 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:
> > @@ -359,22 +360,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);
>
> &write_buf should be just write_buf
>
No, was changed quite recently to make easier not forgetting to reset the pointer.
> > 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);
> same
> > 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;
> > }
> >
> > @@ -399,9 +394,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)) {
> Thanks
>
Frediano
More information about the Spice-devel
mailing list