[Spice-devel] [PATCH 08/10] reds: Make VDIPortState a GObject

Christophe Fergeau cfergeau at redhat.com
Wed Apr 6 16:39:37 UTC 2016


On Fri, Apr 01, 2016 at 03:51:42PM -0500, Jonathon Jongsma wrote:
> From: Christophe Fergeau <cfergeau at redhat.com>
> 
> This inherits from RedCharDevice.
> 
> Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>
> ---
>  server/reds-private.h |   2 +-
>  server/reds.c         | 246 ++++++++++++++++++++++++++++++++------------------
>  2 files changed, 159 insertions(+), 89 deletions(-)
> 
> diff --git a/server/reds-private.h b/server/reds-private.h
> index 8842aad..b3dac6d 100644
> --- a/server/reds-private.h
> +++ b/server/reds-private.h
> @@ -573,7 +599,7 @@ void reds_client_disconnect(RedsState *reds, RedClient *client)
>              internal_buf->header.opaque = 0;
>              internal_buf->header.size = 0;
>  
> -            red_char_device_write_buffer_add(reds->agent_state->priv->base,
> +            red_char_device_write_buffer_add(RED_CHAR_DEVICE(reds->agent_state),
>                                                 char_dev_buf);

Alignment issue

>          }
>  
> @@ -1415,8 +1441,8 @@ int reds_handle_migrate_data(RedsState *reds, MainChannelClient *mcc,
>          spice_debug("agent was not attached on the source host");
>          if (reds->vdagent) {
>              /* red_char_device_client_remove disables waiting for migration data */
> -            red_char_device_client_remove(agent_state->priv->base,
> -                                          main_channel_client_get_base(mcc)->client);
> +            red_char_device_client_remove(RED_CHAR_DEVICE(agent_state),
> +                                            main_channel_client_get_base(mcc)->client);

and one more (feel free to ignore these comments in this patch and the
previous one if this causes too many rebase conflicts).


>              main_channel_push_agent_connected(reds->main_channel);
>          }
>      }
> @@ -3106,7 +3119,7 @@ static RedCharDevice *attach_to_red_agent(RedsState *reds, SpiceCharDeviceInstan
>          main_channel_push_agent_connected(reds->main_channel);
>      }
>  
> -    return state->priv->base;
> +    return RED_CHAR_DEVICE(state);
>  }
>  
>  SPICE_GNUC_VISIBLE void spice_server_char_device_wakeup(SpiceCharDeviceInstance* sin)
> @@ -3363,33 +3376,6 @@ SPICE_GNUC_VISIBLE int spice_server_remove_interface(SpiceBaseInstance *sin)
>      return 0;
>  }
>  
> -static void reds_init_vd_agent_resources(RedsState *reds)
> -{
> -    VDIPortState *state;
> -    int i;
> -
> -    reds->agent_state = g_new0(VDIPortState, 1);
> -    state = reds->agent_state;
> -    ring_init(&state->priv->read_bufs);
> -    agent_msg_filter_init(&state->priv->write_filter, reds->agent_copypaste,
> -                          reds->agent_file_xfer,
> -                          reds_use_client_monitors_config(reds), TRUE);
> -    agent_msg_filter_init(&state->priv->read_filter, reds->agent_copypaste,
> -                          reds->agent_file_xfer,
> -                          reds_use_client_monitors_config(reds), TRUE);
> -
> -    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);
> -
> -    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->priv->read_bufs, &buf->link);
> -    }
> -}
> -
>  static int do_spice_init(RedsState *reds, SpiceCoreInterface *core_interface)
>  {
>      spice_info("starting %s", VERSION);
> @@ -3402,7 +3388,7 @@ static int do_spice_init(RedsState *reds, SpiceCoreInterface *core_interface)
>      reds->core = &core_interface_adapter;
>      reds->listen_socket = -1;
>      reds->secure_listen_socket = -1;
> -    reds_init_vd_agent_resources(reds);
> +    reds->agent_state = red_char_device_vdi_port_new(reds);
>      ring_init(&reds->clients);
>      reds->num_clients = 0;
>      reds->main_dispatcher = main_dispatcher_new(reds, reds->core);
> @@ -4279,3 +4265,87 @@ MainDispatcher* reds_get_main_dispatcher(RedsState *reds)
>  {
>      return reds->main_dispatcher;
>  }
> +
> +static void red_char_device_vdi_port_constructed(GObject *object)
> +{
> +    RedCharDeviceVDIPort *dev = RED_CHAR_DEVICE_VDIPORT(object);
> +    RedsState *reds;
> +
> +    G_OBJECT_CLASS(red_char_device_vdi_port_parent_class)->constructed(object);
> +
> +    g_object_get(dev, "spice-server", &reds, NULL);
> +
> +    agent_msg_filter_init(&dev->priv->write_filter, reds->agent_copypaste,
> +                          reds->agent_file_xfer,
> +                          reds_use_client_monitors_config(reds),
> +                          TRUE);
> +    agent_msg_filter_init(&dev->priv->read_filter, reds->agent_copypaste,
> +                          reds->agent_file_xfer,
> +                          reds_use_client_monitors_config(reds),
> +                          TRUE);
> +}
> +
> +static void
> +red_char_device_vdi_port_init(RedCharDeviceVDIPort *self)
> +{
> +    int i;
> +
> +    self->priv = RED_CHAR_DEVICE_VDIPORT_PRIVATE(self);
> +
> +    ring_init(&self->priv->read_bufs);
> +
> +    self->priv->read_state = VDI_PORT_READ_STATE_READ_HEADER;
> +    self->priv->receive_pos = (uint8_t *)&self->priv->vdi_chunk_header;
> +    self->priv->receive_len = sizeof(self->priv->vdi_chunk_header);
> +
> +    for (i = 0; i < REDS_VDI_PORT_NUM_RECEIVE_BUFFS; i++) {
> +        VDIReadBuf *buf = spice_new0(VDIReadBuf, 1);
> +        buf->state = self;
> +        ring_item_init(&buf->link);
> +        ring_add(&self->priv->read_bufs, &buf->link);
> +    }
> +}
> +
> +static void
> +red_char_device_vdi_port_finalize(GObject *object)
> +{
> +    RedCharDeviceVDIPort *dev = RED_CHAR_DEVICE_VDIPORT(object);
> +
> +   free(dev->priv->mig_data);
> +   /* FIXME: need to free the VDIReadBuf allocated previously */

Would indeed be nicer to fix that FIXME :) (I can send a patch for that tomorrow).

Otherwise looks good to me.

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/5d977533/attachment-0001.sig>


More information about the Spice-devel mailing list