[Spice-devel] [PATCH 04/10] spicevmc: Move SpiceVmcState::pipe_item to RedCharDeviceSpiceVmc

Jonathon Jongsma jjongsma at redhat.com
Wed Mar 30 19:28:57 UTC 2016


see my comments at 
https://lists.freedesktop.org/archives/spice-devel/2016-March/027794.html

On Wed, 2016-03-30 at 18:21 +0100, Frediano Ziglio wrote:
> From: Christophe Fergeau <cfergeau at redhat.com>
> 
> This pipe item belongs to the char device, not to the spicevmc channel.
> ---
>  server/spicevmc.c | 35 ++++++++++++++++++++++++++++-------
>  1 file changed, 28 insertions(+), 7 deletions(-)
> 
> diff --git a/server/spicevmc.c b/server/spicevmc.c
> index 666941f..b047b66 100644
> --- a/server/spicevmc.c
> +++ b/server/spicevmc.c
> @@ -56,7 +56,6 @@ typedef struct SpiceVmcState {
>      RedChannelClient *rcc;
>      SpiceCharDeviceState *chardev_st;
>      SpiceCharDeviceInstance *chardev_sin;
> -    SpiceVmcPipeItem *pipe_item;
>      SpiceCharDeviceWriteBuffer *recv_from_client_buf;
>      uint8_t port_opened;
>  } SpiceVmcState;
> @@ -71,9 +70,11 @@ typedef struct SpiceVmcState {
>  
>  typedef struct RedCharDeviceSpiceVmc RedCharDeviceSpiceVmc;
>  typedef struct RedCharDeviceSpiceVmcClass RedCharDeviceSpiceVmcClass;
> +typedef struct RedCharDeviceSpiceVmcPrivate RedCharDeviceSpiceVmcPrivate;
>  
>  struct RedCharDeviceSpiceVmc {
>      RedCharDevice parent;
> +    RedCharDeviceSpiceVmcPrivate *priv;
>  };
>  
>  struct RedCharDeviceSpiceVmcClass
> @@ -81,6 +82,10 @@ struct RedCharDeviceSpiceVmcClass
>      RedCharDeviceClass parent_class;
>  };
>  
> +struct RedCharDeviceSpiceVmcPrivate {
> +    SpiceVmcPipeItem *pipe_item;
> +};
> +
>  static GType red_char_device_spicevmc_get_type(void) G_GNUC_CONST;
>  static RedCharDevice *red_char_device_spicevmc_new(SpiceCharDeviceInstance
> *sin,
>                                                     RedsState *reds,
> @@ -88,6 +93,8 @@ static RedCharDevice
> *red_char_device_spicevmc_new(SpiceCharDeviceInstance *sin,
>  
>  G_DEFINE_TYPE(RedCharDeviceSpiceVmc, red_char_device_spicevmc,
> RED_TYPE_CHAR_DEVICE)
>  
> +#define RED_CHAR_DEVICE_SPICEVMC_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE
> ((o), RED_TYPE_CHAR_DEVICE_SPICEVMC, RedCharDeviceSpiceVmcPrivate))
> +
>  typedef struct PortInitPipeItem {
>      PipeItem base;
>      char* name;
> @@ -135,6 +142,7 @@ static SpiceCharDeviceMsgToClient
> *spicevmc_chardev_read_msg_from_dev(SpiceCharD
>                                                                        void
> *opaque)
>  {
>      SpiceVmcState *state = opaque;
> +    RedCharDeviceSpiceVmc *dev = RED_CHAR_DEVICE_SPICEVMC(sin->st);
>      SpiceCharDeviceInterface *sif;
>      SpiceVmcPipeItem *msg_item;
>      int n;
> @@ -145,14 +153,14 @@ static SpiceCharDeviceMsgToClient
> *spicevmc_chardev_read_msg_from_dev(SpiceCharD
>          return NULL;
>      }
>  
> -    if (!state->pipe_item) {
> +    if (!dev->priv->pipe_item) {
>          msg_item = spice_new0(SpiceVmcPipeItem, 1);
>          msg_item->refs = 1;
>          pipe_item_init(&msg_item->base, 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(dev->priv->pipe_item->buf_used == 0);
> +        msg_item = dev->priv->pipe_item;
> +        dev->priv->pipe_item = NULL;
>      }
>  
>      n = sif->read(sin, msg_item->buf,
> @@ -162,7 +170,7 @@ static SpiceCharDeviceMsgToClient
> *spicevmc_chardev_read_msg_from_dev(SpiceCharD
>          msg_item->buf_used = n;
>          return msg_item;
>      } else {
> -        state->pipe_item = msg_item;
> +        dev->priv->pipe_item = msg_item;
>          return NULL;
>      }
>  }
> @@ -578,7 +586,6 @@ void spicevmc_device_disconnect(RedsState *reds,
> SpiceCharDeviceInstance *sin)
>      sin->st = NULL;
>  
>      reds_unregister_channel(reds, &state->channel);
> -    free(state->pipe_item);
>      red_channel_destroy(&state->channel);
>  }
>  
> @@ -606,13 +613,27 @@ SPICE_GNUC_VISIBLE void
> spice_server_port_event(SpiceCharDeviceInstance *sin, ui
>  }
>  
>  static void
> +red_char_device_spicevmc_finalize(GObject *object)
> +{
> +    RedCharDeviceSpiceVmc *self = RED_CHAR_DEVICE_SPICEVMC(object);
> +
> +    free(self->priv->pipe_item);
> +}
> +
> +static void
>  red_char_device_spicevmc_class_init(RedCharDeviceSpiceVmcClass *klass)
>  {
> +    GObjectClass *object_class = G_OBJECT_CLASS(klass);
> +
> +    g_type_class_add_private(klass, sizeof (RedCharDeviceSpiceVmcPrivate));
> +
> +    object_class->finalize = red_char_device_spicevmc_finalize;
>  }
>  
>  static void
>  red_char_device_spicevmc_init(RedCharDeviceSpiceVmc *self)
>  {
> +    self->priv = RED_CHAR_DEVICE_SPICEVMC_PRIVATE(self);
>  }
>  
>  static RedCharDevice *


More information about the Spice-devel mailing list