[Spice-devel] [PATCH 07.5/10] Rename VDIPortState to RedCharDeviceVDIPort
Christophe Fergeau
cfergeau at redhat.com
Wed Apr 6 16:24:57 UTC 2016
Hey,
On Fri, Apr 01, 2016 at 04:58:22PM -0500, Jonathon Jongsma wrote:
> /* reads from the device till completes reading a message that is addressed to
> the client,
> * or otherwise, when reading from the device fails */
> static RedCharDeviceMsgToClient
> *vdi_port_read_one_msg_from_device(SpiceCharDeviceInstance *sin,
> void
> *opaque)
> {
> RedsState *reds = opaque;
> - VDIPortState *state = reds->agent_state;
> + RedCharDeviceVDIPort *dev = reds->agent_dev;
> SpiceCharDeviceInterface *sif;
> VDIReadBuf *dispatch_buf;
> int n;
>
> if (!reds->vdagent) {
> return NULL;
> }
> spice_assert(reds->vdagent == sin);
> sif = spice_char_device_get_interface(reds->vdagent);
> while (reds->vdagent) {
> - switch (state->priv->read_state) {
> + switch (dev->priv->read_state) {
> case VDI_PORT_READ_STATE_READ_HEADER:
> - n = sif->read(reds->vdagent, state->priv->receive_pos, state->priv
> ->receive_len);
> + n = sif->read(reds->vdagent, dev->priv->receive_pos, dev->priv
> ->receive_len);
> if (!n) {
> return NULL;
> }
> - if ((state->priv->receive_len -= n)) {
> - state->priv->receive_pos += n;
> + if ((dev->priv->receive_len -= n)) {
> + dev->priv->receive_pos += n;
> return NULL;
> }
> - state->priv->message_receive_len = state->priv
> ->vdi_chunk_header.size;
> - state->priv->read_state = VDI_PORT_READ_STATE_GET_BUFF;
> + dev->priv->message_receive_len = dev->priv->vdi_chunk_header.size;
> + dev->priv->read_state = VDI_PORT_READ_STATE_GET_BUFF;
> case VDI_PORT_READ_STATE_GET_BUFF: {
> - if (!(state->priv->current_read_buf =
> vdi_port_state_get_read_buf(reds->agent_state))) {
> + if (!(dev->priv->current_read_buf = vdi_port_get_read_buf(reds
> ->agent_dev))) {
> return NULL;
> }
> - state->priv->receive_pos = state->priv->current_read_buf->data;
> - state->priv->receive_len = MIN(state->priv->message_receive_len,
> - sizeof(state->priv->current_read_buf
> ->data));
> - state->priv->current_read_buf->len = state->priv->receive_len;
> - state->priv->message_receive_len -= state->priv->receive_len;
> - state->priv->read_state = VDI_PORT_READ_STATE_READ_DATA;
> + dev->priv->receive_pos = dev->priv->current_read_buf->data;
> + dev->priv->receive_len = MIN(dev->priv->message_receive_len,
> + sizeof(dev->priv->current_read_buf
> ->data));
Alignment seems off here
> + dev->priv->current_read_buf->len = dev->priv->receive_len;
> + dev->priv->message_receive_len -= dev->priv->receive_len;
> + dev->priv->read_state = VDI_PORT_READ_STATE_READ_DATA;
> }
> case VDI_PORT_READ_STATE_READ_DATA: {
> gboolean error = FALSE;
> - n = sif->read(reds->vdagent, state->priv->receive_pos, state->priv
> ->receive_len);
> + n = sif->read(reds->vdagent, dev->priv->receive_pos, dev->priv
> ->receive_len);
> if (!n) {
> return NULL;
> }
> - if ((state->priv->receive_len -= n)) {
> - state->priv->receive_pos += n;
> + if ((dev->priv->receive_len -= n)) {
> + dev->priv->receive_pos += n;
> break;
> }
> - dispatch_buf = state->priv->current_read_buf;
> - state->priv->current_read_buf = NULL;
> - state->priv->receive_pos = NULL;
> - if (state->priv->message_receive_len == 0) {
> - state->priv->read_state = VDI_PORT_READ_STATE_READ_HEADER;
> - state->priv->receive_pos = (uint8_t *)&state->priv
> ->vdi_chunk_header;
> - state->priv->receive_len = sizeof(state->priv
> ->vdi_chunk_header);
> + dispatch_buf = dev->priv->current_read_buf;
> + dev->priv->current_read_buf = NULL;
> + dev->priv->receive_pos = NULL;
> + if (dev->priv->message_receive_len == 0) {
> + dev->priv->read_state = VDI_PORT_READ_STATE_READ_HEADER;
> + dev->priv->receive_pos = (uint8_t *)&dev->priv
> ->vdi_chunk_header;
> + dev->priv->receive_len = sizeof(dev->priv->vdi_chunk_header);
> } else {
> - state->priv->read_state = VDI_PORT_READ_STATE_GET_BUFF;
> + dev->priv->read_state = VDI_PORT_READ_STATE_GET_BUFF;
> }
> - if (vdi_port_read_buf_process(reds->agent_state, dispatch_buf,
> &error)) {
> + if (vdi_port_read_buf_process(reds->agent_dev, dispatch_buf,
> &error)) {
> return dispatch_buf;
> } else {
> if (error) {
> reds_agent_remove(reds);
> }
> vdi_port_read_buf_unref(dispatch_buf);
> }
> }
> } /* END switch */
> } /* END while */
> return NULL;
> }
> @@ -885,52 +885,52 @@ static void vdi_port_remove_client(RedClient *client, void
> *opaque)
>
> int reds_has_vdagent(RedsState *reds)
> {
> return !!reds->vdagent;
> }
>
> void reds_handle_agent_mouse_event(RedsState *reds, const VDAgentMouseState
> *mouse_state)
> {
> RedCharDeviceWriteBuffer *char_dev_buf;
> VDInternalBuf *internal_buf;
> uint32_t total_msg_size;
>
> - if (!reds->inputs_channel || !reds->agent_state->priv->base) {
> + if (!reds->inputs_channel || !reds->agent_dev->priv->base) {
> return;
> }
>
> total_msg_size = sizeof(VDIChunkHeader) + sizeof(VDAgentMessage) +
> sizeof(VDAgentMouseState);
> - char_dev_buf = red_char_device_write_buffer_get(reds->agent_state->priv
> ->base,
> + char_dev_buf = red_char_device_write_buffer_get(reds->agent_dev->priv
> ->base,
> NULL,
> total_msg_size);
Wrong alignment here too
> [snip]
>
> static int reds_agent_state_restore(RedsState *reds, SpiceMigrateDataMain
> *mig_data)
> {
> - VDIPortState *agent_state = reds->agent_state;
> + RedCharDeviceVDIPort *agent_dev = reds->agent_dev;
> uint32_t chunk_header_remaining;
>
> - agent_state->priv->vdi_chunk_header = mig_data->agent2client.chunk_header;
> + agent_dev->priv->vdi_chunk_header = mig_data->agent2client.chunk_header;
> spice_assert(mig_data->agent2client.chunk_header_size <=
> sizeof(VDIChunkHeader));
> chunk_header_remaining = sizeof(VDIChunkHeader) - mig_data
> ->agent2client.chunk_header_size;
> if (chunk_header_remaining) {
> - agent_state->priv->read_state = VDI_PORT_READ_STATE_READ_HEADER;
> - agent_state->priv->receive_pos = (uint8_t *)&agent_state->priv
> ->vdi_chunk_header +
> + agent_dev->priv->read_state = VDI_PORT_READ_STATE_READ_HEADER;
> + agent_dev->priv->receive_pos = (uint8_t *)&agent_dev->priv
> ->vdi_chunk_header +
> mig_data->agent2client.chunk_header_size;
> - agent_state->priv->receive_len = chunk_header_remaining;
> + agent_dev->priv->receive_len = chunk_header_remaining;
> } else {
> - agent_state->priv->message_receive_len = agent_state->priv
> ->vdi_chunk_header.size;
> + agent_dev->priv->message_receive_len = agent_dev->priv
> ->vdi_chunk_header.size;
> }
>
> if (!mig_data->agent2client.msg_header_done) {
> uint8_t *partial_msg_header;
>
> if (!chunk_header_remaining) {
> uint32_t cur_buf_size;
>
> - agent_state->priv->read_state = VDI_PORT_READ_STATE_READ_DATA;
> - agent_state->priv->current_read_buf =
> vdi_port_state_get_read_buf(reds->agent_state);
> - spice_assert(agent_state->priv->current_read_buf);
> + agent_dev->priv->read_state = VDI_PORT_READ_STATE_READ_DATA;
> + agent_dev->priv->current_read_buf = vdi_port_get_read_buf(reds
> ->agent_dev);
> + spice_assert(agent_dev->priv->current_read_buf);
> partial_msg_header = (uint8_t *)mig_data + mig_data
> ->agent2client.msg_header_ptr -
> sizeof(SpiceMiniDataHeader);
> - memcpy(agent_state->priv->current_read_buf->data,
> + memcpy(agent_dev->priv->current_read_buf->data,
> partial_msg_header,
> mig_data->agent2client.msg_header_partial_len);
> - agent_state->priv->receive_pos = agent_state->priv
> ->current_read_buf->data +
> + agent_dev->priv->receive_pos = agent_dev->priv->current_read_buf
> ->data +
> mig_data
> ->agent2client.msg_header_partial_len;
> - cur_buf_size = sizeof(agent_state->priv->current_read_buf->data) -
> + cur_buf_size = sizeof(agent_dev->priv->current_read_buf->data) -
> mig_data->agent2client.msg_header_partial_len;
> - agent_state->priv->receive_len = MIN(agent_state->priv
> ->message_receive_len, cur_buf_size);
> - agent_state->priv->current_read_buf->len = agent_state->priv
> ->receive_len +
> + agent_dev->priv->receive_len = MIN(agent_dev->priv
> ->message_receive_len, cur_buf_size);
> + agent_dev->priv->current_read_buf->len = agent_dev->priv
> ->receive_len +
> mig_data
> ->agent2client.msg_header_partial_len;
> - agent_state->priv->message_receive_len -= agent_state->priv
> ->receive_len;
> + agent_dev->priv->message_receive_len -= agent_dev->priv
> ->receive_len;
> } else {
> spice_assert(mig_data->agent2client.msg_header_partial_len == 0);
> }
> } else {
> - agent_state->priv->read_state = VDI_PORT_READ_STATE_GET_BUFF;
> - agent_state->priv->current_read_buf = NULL;
> - agent_state->priv->receive_pos = NULL;
> - agent_state->priv->read_filter.msg_data_to_read = mig_data
> ->agent2client.msg_remaining;
> - agent_state->priv->read_filter.result = mig_data
> ->agent2client.msg_filter_result;
> + agent_dev->priv->read_state = VDI_PORT_READ_STATE_GET_BUFF;
> + agent_dev->priv->current_read_buf = NULL;
> + agent_dev->priv->receive_pos = NULL;
> + agent_dev->priv->read_filter.msg_data_to_read = mig_data
> ->agent2client.msg_remaining;
> + agent_dev->priv->read_filter.result = mig_data
> ->agent2client.msg_filter_result;
> }
>
> - agent_state->priv->read_filter.discard_all = FALSE;
> - agent_state->priv->write_filter.discard_all = !mig_data
> ->client_agent_started;
> - agent_state->priv->client_agent_started = mig_data->client_agent_started;
> + agent_dev->priv->read_filter.discard_all = FALSE;
> + agent_dev->priv->write_filter.discard_all = !mig_data
> ->client_agent_started;
> + agent_dev->priv->client_agent_started = mig_data->client_agent_started;
>
> - agent_state->priv->write_filter.msg_data_to_read = mig_data
> ->client2agent.msg_remaining;
> - agent_state->priv->write_filter.result = mig_data
> ->client2agent.msg_filter_result;
> + agent_dev->priv->write_filter.msg_data_to_read = mig_data
> ->client2agent.msg_remaining;
> + agent_dev->priv->write_filter.result = mig_data
> ->client2agent.msg_filter_result;
>
> spice_debug("to agent filter: discard all %d, wait_msg %u,
> msg_filter_result %d",
> - agent_state->priv->write_filter.discard_all,
> - agent_state->priv->write_filter.msg_data_to_read,
> - agent_state->priv->write_filter.result);
> + agent_dev->priv->write_filter.discard_all,
> + agent_dev->priv->write_filter.msg_data_to_read,
> + agent_dev->priv->write_filter.result);
> spice_debug("from agent filter: discard all %d, wait_msg %u,
> msg_filter_result %d",
> - agent_state->priv->read_filter.discard_all,
> - agent_state->priv->read_filter.msg_data_to_read,
> - agent_state->priv->read_filter.result);
> - return red_char_device_restore(agent_state->priv->base, &mig_data
> ->agent_base);
> + agent_dev->priv->read_filter.discard_all,
> + agent_dev->priv->read_filter.msg_data_to_read,
> + agent_dev->priv->read_filter.result);
You could fix the aligment here even if it's preexisting
> + return red_char_device_restore(agent_dev->priv->base, &mig_data
> ->agent_base);
> }
>
>[snip]
> static RedCharDevice *attach_to_red_agent(RedsState *reds,
> SpiceCharDeviceInstance *sin)
> {
> - VDIPortState *state = reds->agent_state;
> + RedCharDeviceVDIPort *dev = reds->agent_dev;
> SpiceCharDeviceInterface *sif;
> RedCharDeviceCallbacks char_dev_state_cbs;
>
> - if (!state->priv->base) {
> + if (!dev->priv->base) {
> char_dev_state_cbs.read_one_msg_from_device =
> vdi_port_read_one_msg_from_device;
> char_dev_state_cbs.ref_msg_to_client = vdi_port_ref_msg_to_client;
> char_dev_state_cbs.unref_msg_to_client = vdi_port_unref_msg_to_client;
> char_dev_state_cbs.send_msg_to_client = vdi_port_send_msg_to_client;
> char_dev_state_cbs.send_tokens_to_client =
> vdi_port_send_tokens_to_client;
> char_dev_state_cbs.remove_client = vdi_port_remove_client;
> char_dev_state_cbs.on_free_self_token = vdi_port_on_free_self_token;
>
> - state->priv->base = red_char_device_create(sin,
> + dev->priv->base = red_char_device_create(sin,
> reds,
> REDS_TOKENS_TO_SEND,
Alignment.
Acked-by: Christophe Fergeau <cfergeau at redhat.com>
Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20160406/35135f7b/attachment.sig>
More information about the Spice-devel
mailing list