diff options
author | Jonathon Jongsma <jjongsma@redhat.com> | 2015-01-28 15:52:46 -0600 |
---|---|---|
committer | Fabiano FidĂȘncio <fidencio@redhat.com> | 2015-02-23 23:00:45 +0100 |
commit | 908314271521ef8324243ac8cb81175c2bfb66b2 (patch) | |
tree | 4d19a86ed23eaab5e104bbbe4ce166f2257f571a | |
parent | 30b685937771a6c14d3f0d8d25ecc08244180972 (diff) | |
download | spice-908314271521ef8324243ac8cb81175c2bfb66b2.tar.gz spice-908314271521ef8324243ac8cb81175c2bfb66b2.tar.xz spice-908314271521ef8324243ac8cb81175c2bfb66b2.zip |
Remove use of global 'reds' from VDIReadBuf functions
Add a new 'state' property to VDIReadBuf so that we can refer back to
the VDIPortState struct from the readbuf functions.
-rw-r--r-- | server/reds-private.h | 7 | ||||
-rw-r--r-- | server/reds.c | 37 |
2 files changed, 23 insertions, 21 deletions
diff --git a/server/reds-private.h b/server/reds-private.h index 7f927594..a2841d23 100644 --- a/server/reds-private.h +++ b/server/reds-private.h @@ -25,7 +25,10 @@ typedef struct MonitorMode { uint32_t y_res; } MonitorMode; +typedef struct VDIPortState VDIPortState; + typedef struct VDIReadBuf { + VDIPortState *state; RingItem link; uint32_t refs; @@ -39,7 +42,7 @@ enum { VDI_PORT_READ_STATE_READ_DATA, }; -typedef struct VDIPortState { +struct VDIPortState { SpiceCharDeviceState *base; uint32_t plug_generation; int client_agent_started; @@ -62,7 +65,7 @@ typedef struct VDIPortState { SpiceMigrateDataMain *mig_data; /* storing it when migration data arrives before agent is attached */ -} VDIPortState; +}; /* messages that are addressed to the agent and are created in the server */ typedef struct __attribute__ ((__packed__)) VDInternalBuf { diff --git a/server/reds.c b/server/reds.c index f39afde5..9ad2d5b5 100644 --- a/server/reds.c +++ b/server/reds.c @@ -118,9 +118,9 @@ static void reds_char_device_add_state(RedsState *reds, SpiceCharDeviceState *st static void reds_char_device_remove_state(RedsState *reds, SpiceCharDeviceState *st); static void reds_send_mm_time(RedsState *reds); -static VDIReadBuf *reds_get_vdi_port_read_buf(RedsState *reds); +static VDIReadBuf *vdi_port_state_get_read_buf(VDIPortState *state); static VDIReadBuf *vdi_port_read_buf_ref(VDIReadBuf *buf); -static void vdi_port_read_buf_unref(RedsState *reds, VDIReadBuf *buf); +static void vdi_port_read_buf_unref(VDIReadBuf *buf); static ChannelSecurityOptions *reds_find_channel_security(RedsState *reds, int id) { @@ -341,7 +341,7 @@ static void reds_reset_vdp(RedsState *reds) state->receive_len = sizeof(state->vdi_chunk_header); state->message_receive_len = 0; if (state->current_read_buf) { - vdi_port_read_buf_unref(reds, state->current_read_buf); + vdi_port_read_buf_unref(state->current_read_buf); state->current_read_buf = NULL; } /* Reset read filter to start with clean state when the agent reconnects */ @@ -561,7 +561,7 @@ static void vdi_port_read_buf_release(uint8_t *data, void *opaque) { VDIReadBuf *buf = (VDIReadBuf *)opaque; - vdi_port_read_buf_unref(reds, buf); + vdi_port_read_buf_unref(buf); } /* returns TRUE if the buffer can be forwarded */ @@ -593,9 +593,8 @@ static int vdi_port_read_buf_process(RedsState *reds, int port, VDIReadBuf *buf) } } -static VDIReadBuf *reds_get_vdi_port_read_buf(RedsState *reds) +static VDIReadBuf *vdi_port_state_get_read_buf(VDIPortState *state) { - VDIPortState *state = &reds->agent_state; RingItem *item; VDIReadBuf *buf; @@ -618,17 +617,17 @@ static VDIReadBuf* vdi_port_read_buf_ref(VDIReadBuf *buf) /* FIXME: refactor so that unreffing the VDIReadBuf doesn't require accessing * RedsState? */ -static void vdi_port_read_buf_unref(RedsState *reds, VDIReadBuf *buf) +static void vdi_port_read_buf_unref(VDIReadBuf *buf) { if (!--buf->refs) { - ring_add(&reds->agent_state.read_bufs, &buf->link); + ring_add(&buf->state->read_bufs, &buf->link); /* read_one_msg_from_vdi_port may have never completed because the read_bufs ring was empty. So we call it again so it can complete its work if necessary. Note that since we can be called from spice_char_device_wakeup this can cause recursion, but we have protection for that */ - if (reds->agent_state.base) { - spice_char_device_wakeup(reds->agent_state.base); + if (buf->state->base) { + spice_char_device_wakeup(buf->state->base); } } } @@ -663,7 +662,7 @@ static SpiceCharDeviceMsgToClient *vdi_port_read_one_msg_from_device(SpiceCharDe state->message_receive_len = state->vdi_chunk_header.size; state->read_state = VDI_PORT_READ_STATE_GET_BUFF; case VDI_PORT_READ_STATE_GET_BUFF: { - if (!(state->current_read_buf = reds_get_vdi_port_read_buf(reds))) { + if (!(state->current_read_buf = vdi_port_state_get_read_buf(&reds->agent_state))) { return NULL; } state->receive_pos = state->current_read_buf->data; @@ -695,7 +694,7 @@ static SpiceCharDeviceMsgToClient *vdi_port_read_one_msg_from_device(SpiceCharDe if (vdi_port_read_buf_process(reds, state->vdi_chunk_header.port, dispatch_buf)) { return dispatch_buf; } else { - vdi_port_read_buf_unref(reds, dispatch_buf); + vdi_port_read_buf_unref(dispatch_buf); } } /* END switch */ } /* END while */ @@ -703,16 +702,15 @@ static SpiceCharDeviceMsgToClient *vdi_port_read_one_msg_from_device(SpiceCharDe } static SpiceCharDeviceMsgToClient *vdi_port_ref_msg_to_client(SpiceCharDeviceMsgToClient *msg, - void *opaque) + void *opaque) { return vdi_port_read_buf_ref(msg); } static void vdi_port_unref_msg_to_client(SpiceCharDeviceMsgToClient *msg, - void *opaque) + void *opaque) { - RedsState *reds = opaque; - vdi_port_read_buf_unref(reds, msg); + vdi_port_read_buf_unref(msg); } /* after calling this, we unref the message, and the ref is in the instance side */ @@ -1070,7 +1068,7 @@ void reds_on_main_channel_migrate(RedsState *reds, MainChannelClient *mcc) vdi_port_read_buf_release, read_buf); } else { - vdi_port_read_buf_unref(reds, read_buf); + vdi_port_read_buf_unref(read_buf); } spice_assert(agent_state->receive_len); @@ -1188,7 +1186,7 @@ static int reds_agent_state_restore(RedsState *reds, SpiceMigrateDataMain *mig_d uint32_t cur_buf_size; agent_state->read_state = VDI_PORT_READ_STATE_READ_DATA; - agent_state->current_read_buf = reds_get_vdi_port_read_buf(reds); + agent_state->current_read_buf = vdi_port_state_get_read_buf(&reds->agent_state); spice_assert(agent_state->current_read_buf); partial_msg_header = (uint8_t *)mig_data + mig_data->agent2client.msg_header_ptr - sizeof(SpiceMiniDataHeader); @@ -2841,7 +2839,7 @@ static SpiceCharDeviceState *attach_to_red_agent(RedsState *reds, SpiceCharDevic REDS_TOKENS_TO_SEND, REDS_NUM_INTERNAL_AGENT_MESSAGES, &char_dev_state_cbs, - reds); + NULL); } else { spice_char_device_state_reset_dev_instance(state->base, sin); } @@ -3197,6 +3195,7 @@ static void reds_init_vd_agent_resources(RedsState *reds) for (i = 0; i < REDS_VDI_PORT_NUM_RECEIVE_BUFFS; i++) { VDIReadBuf *buf = spice_new0(VDIReadBuf, 1); + buf->state = state; ring_item_init(&buf->link); ring_add(&reds->agent_state.read_bufs, &buf->link); } |