[Spice-devel] [PATCH 4/4] spicevmc: use 'channel' instead of 'state'
Frediano Ziglio
fziglio at redhat.com
Fri Nov 4 11:22:51 UTC 2016
>
> After renaming the object to RedVmcChannel, the local variables still
> used the old 'state' terminology. Changing these variables to 'channel'
> makes things a bit more consistent.
> ---
> server/spicevmc.c | 146
> +++++++++++++++++++++++++++---------------------------
> 1 file changed, 73 insertions(+), 73 deletions(-)
>
> diff --git a/server/spicevmc.c b/server/spicevmc.c
> index 49de9cc..664896c 100644
> --- a/server/spicevmc.c
> +++ b/server/spicevmc.c
> @@ -328,12 +328,12 @@ static void
> spicevmc_red_channel_release_msg_rcv_buf(RedChannelClient *rcc,
> * - a new pipe item with the compressed data in it upon success
> */
> #ifdef USE_LZ4
> -static RedVmcPipeItem* try_compress_lz4(RedVmcChannel *state, int n,
> RedVmcPipeItem *msg_item)
> +static RedVmcPipeItem* try_compress_lz4(RedVmcChannel *channel, int n,
> RedVmcPipeItem *msg_item)
> {
> RedVmcPipeItem *msg_item_compressed;
> int compressed_data_count;
>
> - if (reds_stream_get_family(red_channel_client_get_stream(state->rcc)) ==
> AF_UNIX) {
> + if (reds_stream_get_family(red_channel_client_get_stream(channel->rcc))
> == AF_UNIX) {
> /* AF_LOCAL - data will not be compressed */
> return NULL;
> }
> @@ -341,7 +341,7 @@ static RedVmcPipeItem* try_compress_lz4(RedVmcChannel
> *state, int n, RedVmcPipeI
> /* n <= threshold - data will not be compressed */
> return NULL;
> }
> - if (!red_channel_test_remote_cap(RED_CHANNEL(state),
> SPICE_SPICEVMC_CAP_DATA_COMPRESS_LZ4)) {
> + if (!red_channel_test_remote_cap(RED_CHANNEL(channel),
> SPICE_SPICEVMC_CAP_DATA_COMPRESS_LZ4)) {
> /* Client doesn't have compression cap - data will not be compressed
> */
> return NULL;
> }
> @@ -370,25 +370,25 @@ static RedPipeItem
> *spicevmc_chardev_read_msg_from_dev(RedCharDevice *self,
> SpiceCharDeviceInstance
> *sin)
> {
> RedCharDeviceSpiceVmc *vmc = RED_CHAR_DEVICE_SPICEVMC(self);
> - RedVmcChannel *state = RED_VMC_CHANNEL(vmc->channel);
> + RedVmcChannel *channel = RED_VMC_CHANNEL(vmc->channel);
> SpiceCharDeviceInterface *sif;
> RedVmcPipeItem *msg_item;
> int n;
>
> sif = spice_char_device_get_interface(sin);
>
> - if (!state->rcc) {
> + if (!channel->rcc) {
> return NULL;
> }
>
> - if (!state->pipe_item) {
> + if (!channel->pipe_item) {
> msg_item = spice_new0(RedVmcPipeItem, 1);
> msg_item->type = SPICE_DATA_COMPRESSION_TYPE_NONE;
> red_pipe_item_init(&msg_item->base,
> RED_PIPE_ITEM_TYPE_SPICEVMC_DATA);
> } else {
> - spice_assert(state->pipe_item->buf_used == 0);
> - msg_item = state->pipe_item;
> - state->pipe_item = NULL;
> + spice_assert(channel->pipe_item->buf_used == 0);
> + msg_item = channel->pipe_item;
> + channel->pipe_item = NULL;
> }
>
> n = sif->read(sin, msg_item->buf,
> @@ -398,7 +398,7 @@ static RedPipeItem
> *spicevmc_chardev_read_msg_from_dev(RedCharDevice *self,
> #ifdef USE_LZ4
> RedVmcPipeItem *msg_item_compressed;
>
> - msg_item_compressed = try_compress_lz4(state, n, msg_item);
> + msg_item_compressed = try_compress_lz4(channel, n, msg_item);
> if (msg_item_compressed != NULL) {
> return &msg_item_compressed->base;
> }
> @@ -407,7 +407,7 @@ static RedPipeItem
> *spicevmc_chardev_read_msg_from_dev(RedCharDevice *self,
> msg_item->buf_used = n;
> return &msg_item->base;
> } else {
> - state->pipe_item = msg_item;
> + channel->pipe_item = msg_item;
> return NULL;
> }
> }
> @@ -417,24 +417,24 @@ static void
> spicevmc_chardev_send_msg_to_client(RedCharDevice *self,
> RedClient *client)
> {
> RedCharDeviceSpiceVmc *vmc = RED_CHAR_DEVICE_SPICEVMC(self);
> - RedVmcChannel *state = RED_VMC_CHANNEL(vmc->channel);
> + RedVmcChannel *channel = RED_VMC_CHANNEL(vmc->channel);
>
> - spice_assert(red_channel_client_get_client(state->rcc) == client);
> + spice_assert(red_channel_client_get_client(channel->rcc) == client);
> red_pipe_item_ref(msg);
> - red_channel_client_pipe_add_push(state->rcc, msg);
> + red_channel_client_pipe_add_push(channel->rcc, msg);
> }
>
> static void spicevmc_port_send_init(RedChannelClient *rcc)
> {
> - RedVmcChannel *state =
> RED_VMC_CHANNEL(red_channel_client_get_channel(rcc));
> + RedVmcChannel *channel =
> RED_VMC_CHANNEL(red_channel_client_get_channel(rcc));
> SpiceCharDeviceInstance *sin;
> RedPortInitPipeItem *item = spice_malloc(sizeof(RedPortInitPipeItem));
>
> - g_object_get(state->chardev, "sin", &sin, NULL);
> + g_object_get(channel->chardev, "sin", &sin, NULL);
>
> red_pipe_item_init(&item->base, RED_PIPE_ITEM_TYPE_PORT_INIT);
> item->name = strdup(sin->portname);
> - item->opened = state->port_opened;
> + item->opened = channel->port_opened;
> red_channel_client_pipe_add_push(rcc, &item->base);
> }
>
> @@ -458,13 +458,13 @@ static void
> spicevmc_char_dev_remove_client(RedCharDevice *self,
> RedClient *client)
> {
> RedCharDeviceSpiceVmc *vmc = RED_CHAR_DEVICE_SPICEVMC(self);
> - RedVmcChannel *state = RED_VMC_CHANNEL(vmc->channel);
> + RedVmcChannel *channel = RED_VMC_CHANNEL(vmc->channel);
>
> - spice_printerr("vmc state %p, client %p", state, client);
> - spice_assert(state->rcc &&
> - red_channel_client_get_client(state->rcc) == client);
> + spice_printerr("vmc channel %p, client %p", channel, client);
> + spice_assert(channel->rcc &&
> + red_channel_client_get_client(channel->rcc) == client);
>
> - red_channel_client_shutdown(state->rcc);
> + red_channel_client_shutdown(channel->rcc);
> }
>
> static int spicevmc_red_channel_client_config_socket(RedChannelClient *rcc)
> @@ -490,7 +490,7 @@ static int
> spicevmc_red_channel_client_config_socket(RedChannelClient *rcc)
>
> static void spicevmc_red_channel_client_on_disconnect(RedChannelClient *rcc)
> {
> - RedVmcChannel *state;
> + RedVmcChannel *channel;
> SpiceCharDeviceInstance *sin;
> SpiceCharDeviceInterface *sif;
> RedClient *client = red_channel_client_get_client(rcc);
> @@ -499,17 +499,17 @@ static void
> spicevmc_red_channel_client_on_disconnect(RedChannelClient *rcc)
> return;
> }
>
> - state = RED_VMC_CHANNEL(red_channel_client_get_channel(rcc));
> + channel = RED_VMC_CHANNEL(red_channel_client_get_channel(rcc));
>
> /* partial message which wasn't pushed to device */
> - red_char_device_write_buffer_release(state->chardev,
> &state->recv_from_client_buf);
> + red_char_device_write_buffer_release(channel->chardev,
> &channel->recv_from_client_buf);
>
> - g_object_get(state->chardev, "sin", &sin, NULL);
> - if (red_char_device_client_exists(state->chardev, client)) {
> - red_char_device_client_remove(state->chardev, client);
> + g_object_get(channel->chardev, "sin", &sin, NULL);
> + if (red_char_device_client_exists(channel->chardev, client)) {
> + red_char_device_client_remove(channel->chardev, client);
> } else {
> spice_printerr("client %p have already been removed from char dev
> %p",
> - client, state->chardev);
> + client, channel->chardev);
> }
>
> /* Don't destroy the rcc if it is already being destroyed, as then
> @@ -517,7 +517,7 @@ static void
> spicevmc_red_channel_client_on_disconnect(RedChannelClient *rcc)
> if (!red_channel_client_is_destroying(rcc))
> red_channel_client_destroy(rcc);
>
> - state->rcc = NULL;
> + channel->rcc = NULL;
> sif = spice_char_device_get_interface(sin);
> if (sif->state) {
> sif->state(sin, 0);
> @@ -535,9 +535,9 @@ static int
> spicevmc_channel_client_handle_migrate_data(RedChannelClient *rcc,
> {
> SpiceMigrateDataHeader *header;
> SpiceMigrateDataSpiceVmc *mig_data;
> - RedVmcChannel *state;
> + RedVmcChannel *channel;
>
> - state = RED_VMC_CHANNEL(red_channel_client_get_channel(rcc));
> + channel = RED_VMC_CHANNEL(red_channel_client_get_channel(rcc));
>
> header = (SpiceMigrateDataHeader *)message;
> mig_data = (SpiceMigrateDataSpiceVmc *)(header + 1);
> @@ -549,17 +549,17 @@ static int
> spicevmc_channel_client_handle_migrate_data(RedChannelClient *rcc,
> spice_error("bad header");
> return FALSE;
> }
> - return red_char_device_restore(state->chardev, &mig_data->base);
> + return red_char_device_restore(channel->chardev, &mig_data->base);
> }
>
> -static int handle_compressed_msg(RedVmcChannel *state, RedChannelClient
> *rcc,
> +static int handle_compressed_msg(RedVmcChannel *channel, RedChannelClient
> *rcc,
> SpiceMsgCompressedData
> *compressed_data_msg)
> {
> /* NOTE: *decompressed is free by the char-device */
> int decompressed_size;
> RedCharDeviceWriteBuffer *write_buf;
>
> - write_buf = red_char_device_write_buffer_get(state->chardev,
> + write_buf = red_char_device_write_buffer_get(channel->chardev,
> red_channel_client_get_client(rcc),
> compressed_data_msg->uncompressed_size);
> if (!write_buf) {
> @@ -579,16 +579,16 @@ static int handle_compressed_msg(RedVmcChannel *state,
> RedChannelClient *rcc,
> #endif
> default:
> spice_warning("Invalid Compression Type");
> - red_char_device_write_buffer_release(state->chardev, &write_buf);
> + red_char_device_write_buffer_release(channel->chardev, &write_buf);
> return FALSE;
> }
> if (decompressed_size != compressed_data_msg->uncompressed_size) {
> spice_warning("Decompression Error");
> - red_char_device_write_buffer_release(state->chardev, &write_buf);
> + red_char_device_write_buffer_release(channel->chardev, &write_buf);
> return FALSE;
> }
> write_buf->buf_used = decompressed_size;
> - red_char_device_write_buffer_add(state->chardev, write_buf);
> + red_char_device_write_buffer_add(channel->chardev, write_buf);
> return TRUE;
> }
>
> @@ -599,23 +599,23 @@ static int
> spicevmc_red_channel_client_handle_message_parsed(RedChannelClient *r
> {
> /* NOTE: *msg free by free() (when cb to
> spicevmc_red_channel_release_msg_rcv_buf
> * with the compressed msg type) */
> - RedVmcChannel *state;
> + RedVmcChannel *channel;
> SpiceCharDeviceInstance *sin;
> SpiceCharDeviceInterface *sif;
>
> - state = RED_VMC_CHANNEL(red_channel_client_get_channel(rcc));
> - g_object_get(state->chardev, "sin", &sin, NULL);
> + channel = RED_VMC_CHANNEL(red_channel_client_get_channel(rcc));
> + g_object_get(channel->chardev, "sin", &sin, NULL);
> sif = spice_char_device_get_interface(sin);
>
> switch (type) {
> case SPICE_MSGC_SPICEVMC_DATA:
> - spice_assert(state->recv_from_client_buf->buf == msg);
> - state->recv_from_client_buf->buf_used = size;
> - red_char_device_write_buffer_add(state->chardev,
> state->recv_from_client_buf);
> - state->recv_from_client_buf = NULL;
> + spice_assert(channel->recv_from_client_buf->buf == msg);
> + channel->recv_from_client_buf->buf_used = size;
> + red_char_device_write_buffer_add(channel->chardev,
> channel->recv_from_client_buf);
> + channel->recv_from_client_buf = NULL;
> break;
> case SPICE_MSGC_SPICEVMC_COMPRESSED_DATA:
> - return handle_compressed_msg(state, rcc,
> (SpiceMsgCompressedData*)msg);
> + return handle_compressed_msg(channel, rcc,
> (SpiceMsgCompressedData*)msg);
> break;
> case SPICE_MSGC_PORT_EVENT:
> if (size != sizeof(uint8_t)) {
> @@ -636,23 +636,23 @@ static uint8_t
> *spicevmc_red_channel_alloc_msg_rcv_buf(RedChannelClient *rcc,
> uint16_t type,
> uint32_t size)
> {
> - RedVmcChannel *state;
> + RedVmcChannel *channel;
> RedClient *client = red_channel_client_get_client(rcc);
>
> - state = RED_VMC_CHANNEL(red_channel_client_get_channel(rcc));
> + channel = RED_VMC_CHANNEL(red_channel_client_get_channel(rcc));
>
> switch (type) {
> case SPICE_MSGC_SPICEVMC_DATA:
> - assert(!state->recv_from_client_buf);
> + assert(!channel->recv_from_client_buf);
>
> - state->recv_from_client_buf =
> red_char_device_write_buffer_get(state->chardev,
> -
> client,
> -
> size);
> - if (!state->recv_from_client_buf) {
> + channel->recv_from_client_buf =
> red_char_device_write_buffer_get(channel->chardev,
> +
> client,
> +
> size);
> + if (!channel->recv_from_client_buf) {
> spice_error("failed to allocate write buffer");
> return NULL;
> }
> - return state->recv_from_client_buf->buf;
> + return channel->recv_from_client_buf->buf;
>
> default:
> return spice_malloc(size);
> @@ -665,14 +665,14 @@ static void
> spicevmc_red_channel_release_msg_rcv_buf(RedChannelClient *rcc,
> uint32_t size,
> uint8_t *msg)
> {
> - RedVmcChannel *state;
> + RedVmcChannel *channel;
>
> - state = RED_VMC_CHANNEL(red_channel_client_get_channel(rcc));
> + channel = RED_VMC_CHANNEL(red_channel_client_get_channel(rcc));
>
> switch (type) {
> case SPICE_MSGC_SPICEVMC_DATA:
> /* buffer wasn't pushed to device */
> - red_char_device_write_buffer_release(state->chardev,
> &state->recv_from_client_buf);
> + red_char_device_write_buffer_release(channel->chardev,
> &channel->recv_from_client_buf);
> break;
> default:
> free(msg);
> @@ -704,14 +704,14 @@ static void
> spicevmc_red_channel_send_migrate_data(RedChannelClient *rcc,
> SpiceMarshaller *m,
> RedPipeItem *item)
> {
> - RedVmcChannel *state;
> + RedVmcChannel *channel;
>
> - state = RED_VMC_CHANNEL(red_channel_client_get_channel(rcc));
> + channel = RED_VMC_CHANNEL(red_channel_client_get_channel(rcc));
> red_channel_client_init_send_data(rcc, SPICE_MSG_MIGRATE_DATA, item);
> spice_marshaller_add_uint32(m, SPICE_MIGRATE_DATA_SPICEVMC_MAGIC);
> spice_marshaller_add_uint32(m, SPICE_MIGRATE_DATA_SPICEVMC_VERSION);
>
> - red_char_device_migrate_data_marshall(state->chardev, m);
> + red_char_device_migrate_data_marshall(channel->chardev, m);
> }
>
> static void spicevmc_red_channel_send_port_init(RedChannelClient *rcc,
> @@ -828,18 +828,18 @@ static void spicevmc_connect(RedChannel *channel,
> RedClient *client,
> uint32_t *common_caps, int num_caps, uint32_t *caps)
> {
> RedChannelClient *rcc;
> - RedVmcChannel *state;
> + RedVmcChannel *vmc_channel;
> SpiceCharDeviceInstance *sin;
> SpiceCharDeviceInterface *sif;
> uint32_t type, id;
>
> - state = RED_VMC_CHANNEL(channel);
> + vmc_channel = RED_VMC_CHANNEL(channel);
> g_object_get(channel, "channel-type", &type, "id", &id, NULL);
> - g_object_get(state->chardev, "sin", &sin, NULL);
> + g_object_get(vmc_channel->chardev, "sin", &sin, NULL);
>
> - if (state->rcc) {
> + if (vmc_channel->rcc) {
> spice_printerr("channel client %d:%d (%p) already connected,
> refusing second connection",
> - type, id, state->rcc);
> + type, id, vmc_channel->rcc);
> // TODO: notify client in advance about the in use channel using
> // SPICE_MSG_MAIN_CHANNEL_IN_USE (for example)
> reds_stream_free(stream);
> @@ -851,14 +851,14 @@ static void spicevmc_connect(RedChannel *channel,
> RedClient *client,
> if (!rcc) {
> return;
> }
> - state->rcc = rcc;
> + vmc_channel->rcc = rcc;
> red_channel_client_ack_zero_messages_window(rcc);
>
> if (strcmp(sin->subtype, "port") == 0) {
> spicevmc_port_send_init(rcc);
> }
>
> - if (!red_char_device_client_add(state->chardev, client, FALSE, 0, ~0,
> ~0,
> + if (!red_char_device_client_add(vmc_channel->chardev, client, FALSE, 0,
> ~0, ~0,
> red_channel_client_is_waiting_for_migrate_data(rcc)))
> {
> spice_warning("failed to add client to spicevmc");
> red_channel_client_disconnect(rcc);
> @@ -887,7 +887,7 @@ void spicevmc_device_disconnect(RedsState *reds,
> SpiceCharDeviceInstance *sin)
>
> SPICE_GNUC_VISIBLE void spice_server_port_event(SpiceCharDeviceInstance
> *sin, uint8_t event)
> {
> - RedVmcChannel *state;
> + RedVmcChannel *channel;
> RedCharDeviceSpiceVmc *device = RED_CHAR_DEVICE_SPICEVMC(sin->st);
>
> if (sin->st == NULL) {
> @@ -895,19 +895,19 @@ SPICE_GNUC_VISIBLE void
> spice_server_port_event(SpiceCharDeviceInstance *sin, ui
> return;
> }
>
> - state = RED_VMC_CHANNEL(device->channel);
> + channel = RED_VMC_CHANNEL(device->channel);
>
> if (event == SPICE_PORT_EVENT_OPENED) {
> - state->port_opened = TRUE;
> + channel->port_opened = TRUE;
> } else if (event == SPICE_PORT_EVENT_CLOSED) {
> - state->port_opened = FALSE;
> + channel->port_opened = FALSE;
> }
>
> - if (state->rcc == NULL) {
> + if (channel->rcc == NULL) {
> return;
> }
>
> - spicevmc_port_send_event(state->rcc, event);
> + spicevmc_port_send_event(channel->rcc, event);
> }
>
> static void
Acked-by: Frediano Ziglio <fziglio at redhat.com>
Yes, state was quite confusing.
Frediano
More information about the Spice-devel
mailing list