[Spice-devel] [RFC v4 22/62] server/red_tunnel_worker: trivial multi client support
Marc-André Lureau
marcandre.lureau at gmail.com
Mon May 2 16:56:36 PDT 2011
On Tue, Apr 26, 2011 at 12:54 PM, Alon Levy <alevy at redhat.com> wrote:
> s/TunnelChannel/TunnelChannelClient/
>
> That's about it. this is probably the wrong way to do it. Not tested
> at all. What do we want, a separate interface per client? same interface
> for all clients? probably the later. This doesn't do that. Not tested,
> so probably doesn't even work.
ack, since we are not supporting it for now, it's enough if it builds.
> changes red_channel_pipe_item_is_linked to red_channel_client_pipe_item_is_linked,
> since tunnel channel is the only user, must be done in patch to not break compilation.
> ---
> server/red_channel.c | 5 -
> server/red_channel.h | 2 +-
> server/red_tunnel_worker.c | 257 +++++++++++++++++++++++---------------------
> 3 files changed, 135 insertions(+), 129 deletions(-)
>
> diff --git a/server/red_channel.c b/server/red_channel.c
> index 24ad67f..c6e23d9 100644
> --- a/server/red_channel.c
> +++ b/server/red_channel.c
> @@ -758,11 +758,6 @@ int red_channel_client_pipe_item_is_linked(RedChannelClient *rcc,
> return ring_item_is_linked(&item->link);
> }
>
> -int red_channel_pipe_item_is_linked(RedChannel *channel, PipeItem *item)
> -{
> - return channel->rcc && red_channel_client_pipe_item_is_linked(channel->rcc, item);
> -}
> -
> void red_channel_client_pipe_add_tail_no_push(RedChannelClient *rcc,
> PipeItem *item)
> {
> diff --git a/server/red_channel.h b/server/red_channel.h
> index 844e374..99b273a 100644
> --- a/server/red_channel.h
> +++ b/server/red_channel.h
> @@ -285,7 +285,7 @@ void red_channel_pipes_new_add_tail(RedChannel *channel, new_pipe_item_t creator
> void red_channel_client_pipe_add_push(RedChannelClient *rcc, PipeItem *item);
> void red_channel_client_pipe_add(RedChannelClient *rcc, PipeItem *item);
> void red_channel_client_pipe_add_after(RedChannelClient *rcc, PipeItem *item, PipeItem *pos);
> -int red_channel_pipe_item_is_linked(RedChannel *channel, PipeItem *item);
> +int red_channel_client_pipe_item_is_linked(RedChannelClient *rcc, PipeItem *item);
> void red_channel_pipe_item_remove(RedChannel *channel, PipeItem *item);
> void red_channel_client_pipe_remove_and_release(RedChannelClient *rcc, PipeItem *item);
> void red_channel_client_pipe_add_tail(RedChannelClient *rcc, PipeItem *item);
> diff --git a/server/red_tunnel_worker.c b/server/red_tunnel_worker.c
> index 0392c9b..dc2f28d 100644
> --- a/server/red_tunnel_worker.c
> +++ b/server/red_tunnel_worker.c
> @@ -340,7 +340,7 @@ static const ServiceCallback SERVICES_CALLBACKS[3][2] = {
> /****************************************************
> * Migration data
> ****************************************************/
> -typedef struct TunnelChannel TunnelChannel;
> +typedef struct TunnelChannelClient TunnelChannelClient;
>
> #define TUNNEL_MIGRATE_DATA_MAGIC (*(uint32_t *)"TMDA")
> #define TUNNEL_MIGRATE_DATA_VERSION 1
> @@ -468,7 +468,7 @@ typedef struct TunnelMigrateItem {
> TunnelMigrateSocketItem sockets_data[MAX_SOCKETS_NUM];
> } TunnelMigrateItem;
>
> -static inline void tunnel_channel_activate_migrated_sockets(TunnelChannel *channel);
> +static inline void tunnel_channel_activate_migrated_sockets(TunnelChannelClient *channel);
>
> /*******************************************************************************************/
>
> @@ -482,8 +482,8 @@ static inline void tunnel_channel_activate_migrated_sockets(TunnelChannel *chann
> /* should be checked after each subroutine that may cause error or after calls to slirp routines */
> #define CHECK_TUNNEL_ERROR(channel) (channel->tunnel_error)
>
> -struct TunnelChannel {
> - RedChannel base;
> +struct TunnelChannelClient {
> + RedChannelClient base;
> TunnelWorker *worker;
> int mig_inprogress;
> int expect_migrate_mark;
> @@ -535,7 +535,7 @@ typedef struct TunnelPrintService {
>
> struct TunnelWorker {
> Channel channel_interface; // for reds
> - TunnelChannel *channel;
> + TunnelChannelClient *channel;
>
> SpiceCoreInterface *core_interface;
> SpiceNetWireInstance *sin;
> @@ -599,9 +599,11 @@ static void arm_timer(SlirpUsrNetworkInterface *usr_interface, UserTimer *timer,
>
>
> /* reds interface */
> -static void handle_tunnel_channel_link(Channel *channel, RedClient *client, RedsStream *stream,
> - int migration, int num_common_caps, uint32_t *common_caps,
> - int num_caps, uint32_t *caps);
> +static void handle_tunnel_channel_link(Channel *channel, RedClient *client,
> + RedsStream *stream, int migration,
> + int num_common_caps,
> + uint32_t *common_caps, int num_caps,
> + uint32_t *caps);
> static void handle_tunnel_channel_shutdown(struct Channel *channel);
> static void handle_tunnel_channel_migrate(struct Channel *channel);
>
> @@ -612,7 +614,7 @@ static void tunnel_shutdown(TunnelWorker *worker)
> red_printf("");
> /* shutdown input from channel */
> if (worker->channel) {
> - red_channel_shutdown(&worker->channel->base);
> + red_channel_shutdown(worker->channel->base.channel);
> }
>
> /* shutdown socket pipe items */
> @@ -721,9 +723,9 @@ static inline RedSocketRawRcvBuf *__tunnel_worker_alloc_socket_rcv_buf(TunnelWor
> return ret;
> }
>
> -static inline void __process_rcv_buf_tokens(TunnelChannel *channel, RedSocket *sckt)
> +static inline void __process_rcv_buf_tokens(TunnelChannelClient *channel, RedSocket *sckt)
> {
> - if ((sckt->client_status != CLIENT_SCKT_STATUS_OPEN) || red_channel_pipe_item_is_linked(
> + if ((sckt->client_status != CLIENT_SCKT_STATUS_OPEN) || red_channel_client_pipe_item_is_linked(
> &channel->base, &sckt->out_data.token_pipe_item) || channel->mig_inprogress) {
> return;
> }
> @@ -731,7 +733,7 @@ static inline void __process_rcv_buf_tokens(TunnelChannel *channel, RedSocket *s
> if ((sckt->in_data.num_tokens >= SOCKET_TOKENS_TO_SEND) ||
> (!sckt->in_data.client_total_num_tokens && !sckt->in_data.ready_chunks_queue.head)) {
> sckt->out_data.token_pipe_item.type = PIPE_ITEM_TYPE_SOCKET_TOKEN;
> - red_channel_client_pipe_add(channel->base.rcc, &sckt->out_data.token_pipe_item);
> + red_channel_client_pipe_add(&channel->base, &sckt->out_data.token_pipe_item);
> }
> }
>
> @@ -968,7 +970,7 @@ __visible__ void spice_server_net_wire_recv_packet(SpiceNetWireInstance *sin,
> TunnelWorker *worker = sin->st->worker;
> ASSERT(worker);
>
> - if (worker->channel && worker->channel->base.migrate) {
> + if (worker->channel && worker->channel->base.channel->migrate) {
> return; // during migration and the tunnel state hasn't been restored yet.
> }
>
> @@ -1091,7 +1093,7 @@ static inline TunnelService *__tunnel_worker_add_service(TunnelWorker *worker, u
> #endif
> if (!virt_ip) {
> new_service->pipe_item.type = PIPE_ITEM_TYPE_SERVICE_IP_MAP;
> - red_channel_client_pipe_add(worker->channel->base.rcc, &new_service->pipe_item);
> + red_channel_client_pipe_add(&worker->channel->base, &new_service->pipe_item);
> }
>
> return new_service;
> @@ -1149,7 +1151,7 @@ static TunnelPrintService *tunnel_worker_add_print_service(TunnelWorker *worker,
> return service;
> }
>
> -static int tunnel_channel_handle_service_add(TunnelChannel *channel,
> +static int tunnel_channel_handle_service_add(TunnelChannelClient *channel,
> SpiceMsgcTunnelAddGenericService *service_msg)
> {
> TunnelService *out_service = NULL;
> @@ -1288,23 +1290,23 @@ static RedSocket *tunnel_worker_create_socket(TunnelWorker *worker, uint16_t loc
> static void tunnel_worker_free_socket(TunnelWorker *worker, RedSocket *sckt)
> {
> if (worker->channel) {
> - if (red_channel_pipe_item_is_linked(&worker->channel->base,
> + if (red_channel_client_pipe_item_is_linked(&worker->channel->base,
> &sckt->out_data.data_pipe_item)) {
> - red_channel_pipe_item_remove(&worker->channel->base,
> + red_channel_client_pipe_remove_and_release(&worker->channel->base,
> &sckt->out_data.data_pipe_item);
> return;
> }
>
> - if (red_channel_pipe_item_is_linked(&worker->channel->base,
> + if (red_channel_client_pipe_item_is_linked(&worker->channel->base,
> &sckt->out_data.status_pipe_item)) {
> - red_channel_pipe_item_remove(&worker->channel->base,
> + red_channel_client_pipe_remove_and_release(&worker->channel->base,
> &sckt->out_data.status_pipe_item);
> return;
> }
>
> - if (red_channel_pipe_item_is_linked(&worker->channel->base,
> + if (red_channel_client_pipe_item_is_linked(&worker->channel->base,
> &sckt->out_data.token_pipe_item)) {
> - red_channel_pipe_item_remove(&worker->channel->base,
> + red_channel_client_pipe_remove_and_release(&worker->channel->base,
> &sckt->out_data.token_pipe_item);
> return;
> }
> @@ -1340,39 +1342,41 @@ static inline RedSocket *tunnel_worker_find_socket(TunnelWorker *worker,
> return NULL;
> }
>
> -static inline void __tunnel_socket_add_fin_to_pipe(TunnelChannel *channel, RedSocket *sckt)
> +static inline void __tunnel_socket_add_fin_to_pipe(TunnelChannelClient *channel, RedSocket *sckt)
> {
> - ASSERT(!red_channel_pipe_item_is_linked(&channel->base, &sckt->out_data.status_pipe_item));
> + ASSERT(!red_channel_client_pipe_item_is_linked(&channel->base, &sckt->out_data.status_pipe_item));
> sckt->out_data.status_pipe_item.type = PIPE_ITEM_TYPE_SOCKET_FIN;
> - red_channel_client_pipe_add(channel->base.rcc, &sckt->out_data.status_pipe_item);
> + red_channel_client_pipe_add(&channel->base, &sckt->out_data.status_pipe_item);
> }
>
> -static inline void __tunnel_socket_add_close_to_pipe(TunnelChannel *channel, RedSocket *sckt)
> +static inline void __tunnel_socket_add_close_to_pipe(TunnelChannelClient *channel, RedSocket *sckt)
> {
> ASSERT(!channel->mig_inprogress);
>
> - if (red_channel_pipe_item_is_linked(&channel->base, &sckt->out_data.status_pipe_item)) {
> + if (red_channel_client_pipe_item_is_linked(&channel->base, &sckt->out_data.status_pipe_item)) {
> ASSERT(sckt->out_data.status_pipe_item.type == PIPE_ITEM_TYPE_SOCKET_FIN);
> // close is stronger than FIN
> - red_channel_pipe_item_remove(&channel->base, &sckt->out_data.status_pipe_item);
> + red_channel_client_pipe_remove_and_release(&channel->base,
> + &sckt->out_data.status_pipe_item);
> }
> sckt->pushed_close = TRUE;
> sckt->out_data.status_pipe_item.type = PIPE_ITEM_TYPE_SOCKET_CLOSE;
> - red_channel_client_pipe_add(channel->base.rcc, &sckt->out_data.status_pipe_item);
> + red_channel_client_pipe_add(&channel->base, &sckt->out_data.status_pipe_item);
> }
>
> -static inline void __tunnel_socket_add_close_ack_to_pipe(TunnelChannel *channel, RedSocket *sckt)
> +static inline void __tunnel_socket_add_close_ack_to_pipe(TunnelChannelClient *channel, RedSocket *sckt)
> {
> ASSERT(!channel->mig_inprogress);
>
> - if (red_channel_pipe_item_is_linked(&channel->base, &sckt->out_data.status_pipe_item)) {
> + if (red_channel_client_pipe_item_is_linked(&channel->base, &sckt->out_data.status_pipe_item)) {
> ASSERT(sckt->out_data.status_pipe_item.type == PIPE_ITEM_TYPE_SOCKET_FIN);
> // close is stronger than FIN
> - red_channel_pipe_item_remove(&channel->base, &sckt->out_data.status_pipe_item);
> + red_channel_client_pipe_remove_and_release(&channel->base,
> + &sckt->out_data.status_pipe_item);
> }
>
> sckt->out_data.status_pipe_item.type = PIPE_ITEM_TYPE_SOCKET_CLOSED_ACK;
> - red_channel_client_pipe_add(channel->base.rcc, &sckt->out_data.status_pipe_item);
> + red_channel_client_pipe_add(&channel->base, &sckt->out_data.status_pipe_item);
> }
>
> /*
> @@ -1380,14 +1384,14 @@ static inline void __tunnel_socket_add_close_ack_to_pipe(TunnelChannel *channel,
> If possible, notify slirp to recv data (which will return 0)
> When close ack is received from client, we notify slirp (maybe again) if needed.
> */
> -static void tunnel_socket_force_close(TunnelChannel *channel, RedSocket *sckt)
> +static void tunnel_socket_force_close(TunnelChannelClient *channel, RedSocket *sckt)
> {
> - if (red_channel_pipe_item_is_linked(&channel->base, &sckt->out_data.token_pipe_item)) {
> - red_channel_pipe_item_remove(&channel->base, &sckt->out_data.token_pipe_item);
> + if (red_channel_client_pipe_item_is_linked(&channel->base, &sckt->out_data.token_pipe_item)) {
> + red_channel_client_pipe_remove_and_release(&channel->base, &sckt->out_data.token_pipe_item);
> }
>
> - if (red_channel_pipe_item_is_linked(&channel->base, &sckt->out_data.data_pipe_item)) {
> - red_channel_pipe_item_remove(&channel->base, &sckt->out_data.data_pipe_item);
> + if (red_channel_client_pipe_item_is_linked(&channel->base, &sckt->out_data.data_pipe_item)) {
> + red_channel_client_pipe_remove_and_release(&channel->base, &sckt->out_data.data_pipe_item);
> }
>
>
> @@ -1409,13 +1413,13 @@ static void tunnel_socket_force_close(TunnelChannel *channel, RedSocket *sckt)
> }
> }
>
> -static int tunnel_channel_handle_socket_connect_ack(TunnelChannel *channel, RedSocket *sckt,
> +static int tunnel_channel_handle_socket_connect_ack(TunnelChannelClient *channel, RedSocket *sckt,
> uint32_t tokens)
> {
> #ifdef DEBUG_NETWORK
> red_printf("TUNNEL_DBG");
> #endif
> - if (channel->mig_inprogress || channel->base.migrate) {
> + if (channel->mig_inprogress || channel->base.channel->migrate) {
> sckt->mig_client_status_msg = SPICE_MSGC_TUNNEL_SOCKET_OPEN_ACK;
> sckt->mig_open_ack_tokens = tokens;
> return TRUE;
> @@ -1443,12 +1447,12 @@ static int tunnel_channel_handle_socket_connect_ack(TunnelChannel *channel, RedS
> return (!CHECK_TUNNEL_ERROR(channel));
> }
>
> -static int tunnel_channel_handle_socket_connect_nack(TunnelChannel *channel, RedSocket *sckt)
> +static int tunnel_channel_handle_socket_connect_nack(TunnelChannelClient *channel, RedSocket *sckt)
> {
> #ifdef DEBUG_NETWORK
> PRINT_SCKT(sckt);
> #endif
> - if (channel->mig_inprogress || channel->base.migrate) {
> + if (channel->mig_inprogress || channel->base.channel->migrate) {
> sckt->mig_client_status_msg = SPICE_MSGC_TUNNEL_SOCKET_OPEN_NACK;
> return TRUE;
> }
> @@ -1468,12 +1472,12 @@ static int tunnel_channel_handle_socket_connect_nack(TunnelChannel *channel, Red
> return (!CHECK_TUNNEL_ERROR(channel));
> }
>
> -static int tunnel_channel_handle_socket_fin(TunnelChannel *channel, RedSocket *sckt)
> +static int tunnel_channel_handle_socket_fin(TunnelChannelClient *channel, RedSocket *sckt)
> {
> #ifdef DEBUG_NETWORK
> PRINT_SCKT(sckt);
> #endif
> - if (channel->mig_inprogress || channel->base.migrate) {
> + if (channel->mig_inprogress || channel->base.channel->migrate) {
> sckt->mig_client_status_msg = SPICE_MSGC_TUNNEL_SOCKET_FIN;
> return TRUE;
> }
> @@ -1503,7 +1507,7 @@ static int tunnel_channel_handle_socket_fin(TunnelChannel *channel, RedSocket *s
> return (!CHECK_TUNNEL_ERROR(channel));
> }
>
> -static int tunnel_channel_handle_socket_closed(TunnelChannel *channel, RedSocket *sckt)
> +static int tunnel_channel_handle_socket_closed(TunnelChannelClient *channel, RedSocket *sckt)
> {
> int prev_client_status = sckt->client_status;
>
> @@ -1511,7 +1515,7 @@ static int tunnel_channel_handle_socket_closed(TunnelChannel *channel, RedSocket
> PRINT_SCKT(sckt);
> #endif
>
> - if (channel->mig_inprogress || channel->base.migrate) {
> + if (channel->mig_inprogress || channel->base.channel->migrate) {
> sckt->mig_client_status_msg = SPICE_MSGC_TUNNEL_SOCKET_CLOSED;
> return TRUE;
> }
> @@ -1552,12 +1556,12 @@ static int tunnel_channel_handle_socket_closed(TunnelChannel *channel, RedSocket
> return (!CHECK_TUNNEL_ERROR(channel));
> }
>
> -static int tunnel_channel_handle_socket_closed_ack(TunnelChannel *channel, RedSocket *sckt)
> +static int tunnel_channel_handle_socket_closed_ack(TunnelChannelClient *channel, RedSocket *sckt)
> {
> #ifdef DEBUG_NETWORK
> PRINT_SCKT(sckt);
> #endif
> - if (channel->mig_inprogress || channel->base.migrate) {
> + if (channel->mig_inprogress || channel->base.channel->migrate) {
> sckt->mig_client_status_msg = SPICE_MSGC_TUNNEL_SOCKET_CLOSED_ACK;
> return TRUE;
> }
> @@ -1579,7 +1583,7 @@ static int tunnel_channel_handle_socket_closed_ack(TunnelChannel *channel, RedSo
> return (!CHECK_TUNNEL_ERROR(channel));
> }
>
> -static int tunnel_channel_handle_socket_receive_data(TunnelChannel *channel, RedSocket *sckt,
> +static int tunnel_channel_handle_socket_receive_data(TunnelChannelClient *channel, RedSocket *sckt,
> RedSocketRawRcvBuf *recv_data, int buf_size)
> {
> if ((sckt->client_status == CLIENT_SCKT_STATUS_SHUTDOWN_SEND) ||
> @@ -1595,7 +1599,7 @@ static int tunnel_channel_handle_socket_receive_data(TunnelChannel *channel, Red
> __tunnel_worker_free_socket_rcv_buf(sckt->worker, recv_data);
> return (!CHECK_TUNNEL_ERROR(channel));
> } else if ((sckt->in_data.num_buffers == MAX_SOCKET_IN_BUFFERS) &&
> - !channel->mig_inprogress && !channel->base.migrate) {
> + !channel->mig_inprogress && !channel->base.channel->migrate) {
> red_printf("socket in buffers overflow, socket will be closed"
> " (local_port=%d, service_id=%d)",
> ntohs(sckt->local_port), sckt->far_service->id);
> @@ -1627,16 +1631,16 @@ static inline int __client_socket_can_receive(RedSocket *sckt)
> !sckt->worker->channel->mig_inprogress);
> }
>
> -static int tunnel_channel_handle_socket_token(TunnelChannel *channel, RedSocket *sckt,
> +static int tunnel_channel_handle_socket_token(TunnelChannelClient *channel, RedSocket *sckt,
> SpiceMsgcTunnelSocketTokens *message)
> {
> sckt->out_data.num_tokens += message->num_tokens;
>
> if (__client_socket_can_receive(sckt) && sckt->out_data.ready_chunks_queue.head &&
> - !red_channel_pipe_item_is_linked(&channel->base, &sckt->out_data.data_pipe_item)) {
> + !red_channel_client_pipe_item_is_linked(&channel->base, &sckt->out_data.data_pipe_item)) {
> // data is pending to be sent
> sckt->out_data.data_pipe_item.type = PIPE_ITEM_TYPE_SOCKET_DATA;
> - red_channel_client_pipe_add(channel->base.rcc, &sckt->out_data.data_pipe_item);
> + red_channel_client_pipe_add(&channel->base, &sckt->out_data.data_pipe_item);
> }
>
> return TRUE;
> @@ -1645,7 +1649,7 @@ static int tunnel_channel_handle_socket_token(TunnelChannel *channel, RedSocket
> static uint8_t *tunnel_channel_alloc_msg_rcv_buf(RedChannelClient *rcc,
> SpiceDataHeader *msg_header)
> {
> - TunnelChannel *tunnel_channel = (TunnelChannel *)rcc->channel;
> + TunnelChannelClient *tunnel_channel = (TunnelChannelClient *)rcc->channel;
>
> if (msg_header->type == SPICE_MSGC_TUNNEL_SOCKET_DATA) {
> return (__tunnel_worker_alloc_socket_rcv_buf(tunnel_channel->worker)->buf);
> @@ -1661,7 +1665,7 @@ static uint8_t *tunnel_channel_alloc_msg_rcv_buf(RedChannelClient *rcc,
> static void tunnel_channel_release_msg_rcv_buf(RedChannelClient *rcc, SpiceDataHeader *msg_header,
> uint8_t *msg)
> {
> - TunnelChannel *tunnel_channel = (TunnelChannel *)rcc->channel;
> + TunnelChannelClient *tunnel_channel = (TunnelChannelClient *)rcc->channel;
>
> if (msg_header->type == SPICE_MSGC_TUNNEL_SOCKET_DATA) {
> ASSERT(!(SPICE_CONTAINEROF(msg, RedSocketRawRcvBuf, buf)->base.usr_opaque));
> @@ -1670,7 +1674,7 @@ static void tunnel_channel_release_msg_rcv_buf(RedChannelClient *rcc, SpiceDataH
> }
> }
>
> -static void __tunnel_channel_fill_service_migrate_item(TunnelChannel *channel,
> +static void __tunnel_channel_fill_service_migrate_item(TunnelChannelClient *channel,
> TunnelService *service,
> TunnelMigrateServiceItem *migrate_item)
> {
> @@ -1692,7 +1696,7 @@ static void __tunnel_channel_fill_service_migrate_item(TunnelChannel *channel,
> memcpy(general_data->virt_ip, &service->virt_ip.s_addr, 4);
> }
>
> -static void __tunnel_channel_fill_socket_migrate_item(TunnelChannel *channel, RedSocket *sckt,
> +static void __tunnel_channel_fill_socket_migrate_item(TunnelChannelClient *channel, RedSocket *sckt,
> TunnelMigrateSocketItem *migrate_item)
> {
> TunnelMigrateSocket *mig_sckt = &migrate_item->mig_socket;
> @@ -1744,9 +1748,9 @@ static void __tunnel_channel_fill_socket_migrate_item(TunnelChannel *channel, Re
> }
>
> static void release_migrate_item(TunnelMigrateItem *item);
> -static int tunnel_channel_handle_migrate_mark(RedChannelClient *rcc)
> +static int tunnel_channel_handle_migrate_mark(RedChannelClient *base)
> {
> - TunnelChannel *channel = SPICE_CONTAINEROF(rcc->channel, TunnelChannel, base);
> + TunnelChannelClient *channel = SPICE_CONTAINEROF(base->channel, TunnelChannelClient, base);
> TunnelMigrateItem *migrate_item = NULL;
> TunnelService *service;
> TunnelMigrateServiceItem *mig_service;
> @@ -1806,7 +1810,7 @@ static int tunnel_channel_handle_migrate_mark(RedChannelClient *rcc)
> }
> }
>
> - red_channel_client_pipe_add(channel->base.rcc, &migrate_item->base);
> + red_channel_client_pipe_add(&channel->base, &migrate_item->base);
>
> return TRUE;
> error:
> @@ -1936,7 +1940,7 @@ static void __restore_process_queue(RedSocket *sckt, TunneledBufferProcessQueue
> }
> }
>
> -static void tunnel_channel_restore_migrated_service(TunnelChannel *channel,
> +static void tunnel_channel_restore_migrated_service(TunnelChannelClient *channel,
> TunnelMigrateService *mig_service,
> uint8_t *data_buf)
> {
> @@ -1971,7 +1975,7 @@ static void tunnel_channel_restore_migrated_service(TunnelChannel *channel,
> }
> }
>
> -static void tunnel_channel_restore_migrated_socket(TunnelChannel *channel,
> +static void tunnel_channel_restore_migrated_socket(TunnelChannelClient *channel,
> TunnelMigrateSocket *mig_socket,
> uint8_t *data_buf)
> {
> @@ -2057,7 +2061,7 @@ static void tunnel_channel_restore_migrated_socket(TunnelChannel *channel,
> }
> }
>
> -static void tunnel_channel_restore_socket_state(TunnelChannel *channel, RedSocket *sckt)
> +static void tunnel_channel_restore_socket_state(TunnelChannelClient *channel, RedSocket *sckt)
> {
> int ret = TRUE;
> red_printf("");
> @@ -2107,10 +2111,10 @@ static void tunnel_channel_restore_socket_state(TunnelChannel *channel, RedSocke
>
> // handling data transfer
> if (__client_socket_can_receive(sckt) && sckt->out_data.ready_chunks_queue.head) {
> - if (!red_channel_pipe_item_is_linked(
> + if (!red_channel_client_pipe_item_is_linked(
> &channel->base, &sckt->out_data.data_pipe_item)) {
> sckt->out_data.data_pipe_item.type = PIPE_ITEM_TYPE_SOCKET_DATA;
> - red_channel_client_pipe_add(channel->base.rcc, &sckt->out_data.data_pipe_item);
> + red_channel_client_pipe_add(&channel->base, &sckt->out_data.data_pipe_item);
> }
> }
>
> @@ -2136,7 +2140,7 @@ static void tunnel_channel_restore_socket_state(TunnelChannel *channel, RedSocke
> __process_rcv_buf_tokens(channel, sckt);
> }
>
> -static inline void tunnel_channel_activate_migrated_sockets(TunnelChannel *channel)
> +static inline void tunnel_channel_activate_migrated_sockets(TunnelChannelClient *channel)
> {
> // if we are overgoing migration again, no need to restore the state, we will wait
> // for the next host.
> @@ -2159,7 +2163,7 @@ static inline void tunnel_channel_activate_migrated_sockets(TunnelChannel *chann
> }
> }
>
> -static uint64_t tunnel_channel_handle_migrate_data_get_serial_proc(RedChannelClient *rcc,
> +static uint64_t tunnel_channel_handle_migrate_data_get_serial(RedChannelClient *base,
> uint32_t size, void *msg)
> {
> TunnelMigrateData *migrate_data = msg;
> @@ -2172,10 +2176,10 @@ static uint64_t tunnel_channel_handle_migrate_data_get_serial_proc(RedChannelCli
> return migrate_data->message_serial;
> }
>
> -static uint64_t tunnel_channel_handle_migrate_data(RedChannelClient *rcc,
> +static uint64_t tunnel_channel_handle_migrate_data(RedChannelClient *base,
> uint32_t size, void *msg)
> {
> - TunnelChannel *channel = SPICE_CONTAINEROF(rcc->channel, TunnelChannel, base);
> + TunnelChannelClient *channel = SPICE_CONTAINEROF(base->channel, TunnelChannelClient, base);
> TunnelMigrateSocketList *sockets_list;
> TunnelMigrateServicesList *services_list;
> TunnelMigrateData *migrate_data = msg;
> @@ -2226,8 +2230,8 @@ static uint64_t tunnel_channel_handle_migrate_data(RedChannelClient *rcc,
> }
>
> // activate channel
> - channel->base.migrate = FALSE;
> - red_channel_init_outgoing_messages_window(&channel->base);
> + channel->base.channel->migrate = FALSE;
> + red_channel_init_outgoing_messages_window(channel->base.channel);
>
> tunnel_channel_activate_migrated_sockets(channel);
>
> @@ -2244,7 +2248,7 @@ error:
> // msg was allocated by tunnel_channel_alloc_msg_rcv_buf
> static int tunnel_channel_handle_message(RedChannelClient *rcc, SpiceDataHeader *header, uint8_t *msg)
> {
> - TunnelChannel *tunnel_channel = (TunnelChannel *)rcc->channel;
> + TunnelChannelClient *tunnel_channel = (TunnelChannelClient *)rcc->channel;
> RedSocket *sckt = NULL;
> // retrieve the sckt
> switch (header->type) {
> @@ -2348,10 +2352,10 @@ static int tunnel_channel_handle_message(RedChannelClient *rcc, SpiceDataHeader
>
> static void tunnel_channel_marshall_migrate(RedChannelClient *rcc, SpiceMarshaller *m, PipeItem *item)
> {
> - TunnelChannel *tunnel_channel;
> + TunnelChannelClient *tunnel_channel;
>
> ASSERT(rcc);
> - tunnel_channel = SPICE_CONTAINEROF(rcc->channel, TunnelChannel, base);
> + tunnel_channel = SPICE_CONTAINEROF(rcc->channel, TunnelChannelClient, base);
> tunnel_channel->send_data.u.migrate.flags =
> SPICE_MIGRATE_NEED_FLUSH | SPICE_MIGRATE_NEED_DATA_TRANSFER;
> tunnel_channel->expect_migrate_mark = TRUE;
> @@ -2361,7 +2365,7 @@ static void tunnel_channel_marshall_migrate(RedChannelClient *rcc, SpiceMarshall
> sizeof(SpiceMsgMigrate));
> }
>
> -static int __tunnel_channel_marshall_process_bufs_migrate_data(TunnelChannel *channel,
> +static int __tunnel_channel_marshall_process_bufs_migrate_data(TunnelChannelClient *channel,
> SpiceMarshaller *m, TunneledBufferProcessQueue *queue)
> {
> int buf_offset = queue->head_offset;
> @@ -2378,7 +2382,7 @@ static int __tunnel_channel_marshall_process_bufs_migrate_data(TunnelChannel *ch
> return size;
> }
>
> -static int __tunnel_channel_marshall_ready_bufs_migrate_data(TunnelChannel *channel,
> +static int __tunnel_channel_marshall_ready_bufs_migrate_data(TunnelChannelClient *channel,
> SpiceMarshaller *m, ReadyTunneledChunkQueue *queue)
> {
> int offset = queue->offset;
> @@ -2395,7 +2399,7 @@ static int __tunnel_channel_marshall_ready_bufs_migrate_data(TunnelChannel *chan
> }
>
> // returns the size to send
> -static int __tunnel_channel_marshall_service_migrate_data(TunnelChannel *channel,
> +static int __tunnel_channel_marshall_service_migrate_data(TunnelChannelClient *channel,
> SpiceMarshaller *m,
> TunnelMigrateServiceItem *item,
> int offset)
> @@ -2430,7 +2434,7 @@ static int __tunnel_channel_marshall_service_migrate_data(TunnelChannel *channel
> }
>
> // returns the size to send
> -static int __tunnel_channel_marshall_socket_migrate_data(TunnelChannel *channel,
> +static int __tunnel_channel_marshall_socket_migrate_data(TunnelChannelClient *channel,
> SpiceMarshaller *m, TunnelMigrateSocketItem *item, int offset)
> {
> RedSocket *sckt = item->socket;
> @@ -2498,14 +2502,14 @@ static int __tunnel_channel_marshall_socket_migrate_data(TunnelChannel *channel,
> static void tunnel_channel_marshall_migrate_data(RedChannelClient *rcc,
> SpiceMarshaller *m, PipeItem *item)
> {
> - TunnelChannel *tunnel_channel;
> + TunnelChannelClient *tunnel_channel;
> TunnelMigrateData *migrate_data;
> TunnelMigrateItem *migrate_item = (TunnelMigrateItem *)item;
> int i;
>
> uint32_t data_buf_offset = 0; // current location in data[0] field
> ASSERT(rcc);
> - tunnel_channel = SPICE_CONTAINEROF(rcc->channel, TunnelChannel, base);
> + tunnel_channel = SPICE_CONTAINEROF(rcc->channel, TunnelChannelClient, base);
> migrate_data = &tunnel_channel->send_data.u.migrate_data;
>
> migrate_data->magic = TUNNEL_MIGRATE_DATA_MAGIC;
> @@ -2546,10 +2550,10 @@ static void tunnel_channel_marshall_migrate_data(RedChannelClient *rcc,
>
> static void tunnel_channel_marshall_init(RedChannelClient *rcc, SpiceMarshaller *m, PipeItem *item)
> {
> - TunnelChannel *channel;
> + TunnelChannelClient *channel;
>
> ASSERT(rcc);
> - channel = SPICE_CONTAINEROF(rcc->channel, TunnelChannel, base);
> + channel = SPICE_CONTAINEROF(rcc->channel, TunnelChannelClient, base);
> channel->send_data.u.init.max_socket_data_size = MAX_SOCKET_DATA_SIZE;
> channel->send_data.u.init.max_num_of_sockets = MAX_SOCKETS_NUM;
>
> @@ -2559,10 +2563,10 @@ static void tunnel_channel_marshall_init(RedChannelClient *rcc, SpiceMarshaller
>
> static void tunnel_channel_marshall_service_ip_map(RedChannelClient *rcc, SpiceMarshaller *m, PipeItem *item)
> {
> - TunnelChannel *tunnel_channel;
> + TunnelChannelClient *tunnel_channel;
> TunnelService *service = SPICE_CONTAINEROF(item, TunnelService, pipe_item);
>
> - tunnel_channel = SPICE_CONTAINEROF(rcc->channel, TunnelChannel, base);
> + tunnel_channel = SPICE_CONTAINEROF(rcc->channel, TunnelChannelClient, base);
> tunnel_channel->send_data.u.service_ip.service_id = service->id;
> tunnel_channel->send_data.u.service_ip.virtual_ip.type = SPICE_TUNNEL_IP_TYPE_IPv4;
>
> @@ -2574,11 +2578,11 @@ static void tunnel_channel_marshall_service_ip_map(RedChannelClient *rcc, SpiceM
>
> static void tunnel_channel_marshall_socket_open(RedChannelClient *rcc, SpiceMarshaller *m, PipeItem *item)
> {
> - TunnelChannel *tunnel_channel;
> + TunnelChannelClient *tunnel_channel;
> RedSocketOutData *sckt_out_data = SPICE_CONTAINEROF(item, RedSocketOutData, status_pipe_item);
> RedSocket *sckt = SPICE_CONTAINEROF(sckt_out_data, RedSocket, out_data);
>
> - tunnel_channel = SPICE_CONTAINEROF(rcc->channel, TunnelChannel, base);
> + tunnel_channel = SPICE_CONTAINEROF(rcc->channel, TunnelChannelClient, base);
> tunnel_channel->send_data.u.socket_open.connection_id = sckt->connection_id;
> tunnel_channel->send_data.u.socket_open.service_id = sckt->far_service->id;
> tunnel_channel->send_data.u.socket_open.tokens = SOCKET_WINDOW_SIZE;
> @@ -2595,13 +2599,13 @@ static void tunnel_channel_marshall_socket_open(RedChannelClient *rcc, SpiceMars
>
> static void tunnel_channel_marshall_socket_fin(RedChannelClient *rcc, SpiceMarshaller *m, PipeItem *item)
> {
> - TunnelChannel *tunnel_channel;
> + TunnelChannelClient *tunnel_channel;
> RedSocketOutData *sckt_out_data = SPICE_CONTAINEROF(item, RedSocketOutData, status_pipe_item);
> RedSocket *sckt = SPICE_CONTAINEROF(sckt_out_data, RedSocket, out_data);
>
> ASSERT(!sckt->out_data.ready_chunks_queue.head);
>
> - tunnel_channel = SPICE_CONTAINEROF(rcc->channel, TunnelChannel, base);
> + tunnel_channel = SPICE_CONTAINEROF(rcc->channel, TunnelChannelClient, base);
> if (sckt->out_data.process_queue->head) {
> red_printf("socket sent FIN but there are still buffers in outgoing process queue"
> "(local_port=%d, service_id=%d)",
> @@ -2620,11 +2624,11 @@ static void tunnel_channel_marshall_socket_fin(RedChannelClient *rcc, SpiceMarsh
>
> static void tunnel_channel_marshall_socket_close(RedChannelClient *rcc, SpiceMarshaller *m, PipeItem *item)
> {
> - TunnelChannel *tunnel_channel;
> + TunnelChannelClient *tunnel_channel;
> RedSocketOutData *sckt_out_data = SPICE_CONTAINEROF(item, RedSocketOutData, status_pipe_item);
> RedSocket *sckt = SPICE_CONTAINEROF(sckt_out_data, RedSocket, out_data);
>
> - tunnel_channel = SPICE_CONTAINEROF(rcc->channel, TunnelChannel, base);
> + tunnel_channel = SPICE_CONTAINEROF(rcc->channel, TunnelChannelClient, base);
> // can happen when it is a forced close
> if (sckt->out_data.ready_chunks_queue.head) {
> red_printf("socket closed but there are still buffers in outgoing ready queue"
> @@ -2651,11 +2655,11 @@ static void tunnel_channel_marshall_socket_close(RedChannelClient *rcc, SpiceMar
>
> static void tunnel_channel_marshall_socket_closed_ack(RedChannelClient *rcc, SpiceMarshaller *m, PipeItem *item)
> {
> - TunnelChannel *tunnel_channel;
> + TunnelChannelClient *tunnel_channel;
> RedSocketOutData *sckt_out_data = SPICE_CONTAINEROF(item, RedSocketOutData, status_pipe_item);
> RedSocket *sckt = SPICE_CONTAINEROF(sckt_out_data, RedSocket, out_data);
>
> - tunnel_channel = SPICE_CONTAINEROF(rcc->channel, TunnelChannel, base);
> + tunnel_channel = SPICE_CONTAINEROF(rcc->channel, TunnelChannelClient, base);
> tunnel_channel->send_data.u.socket_close_ack.connection_id = sckt->connection_id;
>
> // pipe item is null because we free the sckt.
> @@ -2675,14 +2679,14 @@ static void tunnel_channel_marshall_socket_closed_ack(RedChannelClient *rcc, Spi
>
> static void tunnel_channel_marshall_socket_token(RedChannelClient *rcc, SpiceMarshaller *m, PipeItem *item)
> {
> - TunnelChannel *tunnel_channel;
> + TunnelChannelClient *tunnel_channel;
> RedSocketOutData *sckt_out_data = SPICE_CONTAINEROF(item, RedSocketOutData, token_pipe_item);
> RedSocket *sckt = SPICE_CONTAINEROF(sckt_out_data, RedSocket, out_data);
>
> /* notice that the num of tokens sent can be > SOCKET_TOKENS_TO_SEND, since
> the sending is performed after the pipe item was pushed */
>
> - tunnel_channel = SPICE_CONTAINEROF(rcc->channel, TunnelChannel, base);
> + tunnel_channel = SPICE_CONTAINEROF(rcc->channel, TunnelChannelClient, base);
> tunnel_channel->send_data.u.socket_token.connection_id = sckt->connection_id;
>
> if (sckt->in_data.num_tokens > 0) {
> @@ -2702,8 +2706,8 @@ static void tunnel_channel_marshall_socket_token(RedChannelClient *rcc, SpiceMar
>
> static void tunnel_channel_marshall_socket_out_data(RedChannelClient *rcc, SpiceMarshaller *m, PipeItem *item)
> {
> - TunnelChannel *tunnel_channel;
> - tunnel_channel = SPICE_CONTAINEROF(rcc->channel, TunnelChannel, base);
> + TunnelChannelClient *tunnel_channel;
> + tunnel_channel = SPICE_CONTAINEROF(rcc->channel, TunnelChannelClient, base);
> RedSocketOutData *sckt_out_data = SPICE_CONTAINEROF(item, RedSocketOutData, data_pipe_item);
> RedSocket *sckt = SPICE_CONTAINEROF(sckt_out_data, RedSocket, out_data);
> ReadyTunneledChunk *chunk;
> @@ -2789,10 +2793,10 @@ static void tunnel_worker_release_socket_out_data(TunnelWorker *worker, PipeItem
> if (sckt_out_data->ready_chunks_queue.head) {
> // the pipe item may already be linked, if for example the send was
> // blocked and before it finished and called release, tunnel_socket_send was called
> - if (!red_channel_pipe_item_is_linked(
> + if (!red_channel_client_pipe_item_is_linked(
> &worker->channel->base, &sckt_out_data->data_pipe_item)) {
> sckt_out_data->data_pipe_item.type = PIPE_ITEM_TYPE_SOCKET_DATA;
> - red_channel_client_pipe_add(worker->channel->base.rcc, &sckt_out_data->data_pipe_item);
> + red_channel_client_pipe_add(&worker->channel->base, &sckt_out_data->data_pipe_item);
> }
> } else if ((sckt->slirp_status == SLIRP_SCKT_STATUS_SHUTDOWN_SEND) ||
> (sckt->slirp_status == SLIRP_SCKT_STATUS_WAIT_CLOSE)) {
> @@ -2873,7 +2877,8 @@ static void tunnel_channel_release_pipe_item(RedChannelClient *rcc, PipeItem *it
> break;
> case PIPE_ITEM_TYPE_SOCKET_DATA:
> if (item_pushed) {
> - tunnel_worker_release_socket_out_data(((TunnelChannel *)rcc->channel)->worker, item);
> + tunnel_worker_release_socket_out_data(
> + SPICE_CONTAINEROF(rcc, TunnelChannelClient, base)->worker, item);
> }
> break;
> case PIPE_ITEM_TYPE_MIGRATE:
> @@ -2956,7 +2961,7 @@ static int tunnel_socket_connect(SlirpUsrNetworkInterface *usr_interface,
> #endif
> *o_usr_s = sckt;
> sckt->out_data.status_pipe_item.type = PIPE_ITEM_TYPE_SOCKET_OPEN;
> - red_channel_client_pipe_add(worker->channel->base.rcc, &sckt->out_data.status_pipe_item);
> + red_channel_client_pipe_add(&worker->channel->base, &sckt->out_data.status_pipe_item);
>
> errno = EINPROGRESS;
> return -1;
> @@ -3042,10 +3047,10 @@ static int tunnel_socket_send(SlirpUsrNetworkInterface *usr_interface, UserSocke
> sckt->out_data.data_size += size_to_send;
>
> if (sckt->out_data.ready_chunks_queue.head &&
> - !red_channel_pipe_item_is_linked(&worker->channel->base,
> + !red_channel_client_pipe_item_is_linked(&worker->channel->base,
> &sckt->out_data.data_pipe_item)) {
> sckt->out_data.data_pipe_item.type = PIPE_ITEM_TYPE_SOCKET_DATA;
> - red_channel_client_pipe_add(worker->channel->base.rcc, &sckt->out_data.data_pipe_item);
> + red_channel_client_pipe_add(&worker->channel->base, &sckt->out_data.data_pipe_item);
> }
> }
>
> @@ -3392,7 +3397,7 @@ static void tunnel_worker_disconnect_slirp(TunnelWorker *worker)
> since it closes all its sockets and slirp is not aware of it */
> static void tunnel_channel_disconnect(RedChannel *channel)
> {
> - TunnelChannel *tunnel_channel = (TunnelChannel *)channel;
> + TunnelChannelClient *tunnel_channel = (TunnelChannelClient *)channel;
> TunnelWorker *worker;
> if (!channel) {
> return;
> @@ -3415,15 +3420,15 @@ static void tunnel_channel_disconnect_client(RedChannelClient *rcc)
>
> /* interface for reds */
>
> -static void on_new_tunnel_channel(TunnelChannel *channel)
> +static void on_new_tunnel_channel(TunnelChannelClient *tcc)
> {
> - red_channel_push_set_ack(&channel->base);
> + red_channel_client_push_set_ack(&tcc->base);
>
> - if (channel->base.migrate) {
> - channel->expect_migrate_data = TRUE;
> + if (tcc->base.channel->migrate) {
> + tcc->expect_migrate_data = TRUE;
> } else {
> - red_channel_init_outgoing_messages_window(&channel->base);
> - red_channel_client_pipe_add_type(channel->base.rcc, PIPE_ITEM_TYPE_TUNNEL_INIT);
> + red_channel_init_outgoing_messages_window(tcc->base.channel);
> + red_channel_client_pipe_add_type(&tcc->base, PIPE_ITEM_TYPE_TUNNEL_INIT);
> }
> }
>
> @@ -3431,18 +3436,22 @@ static void tunnel_channel_hold_pipe_item(RedChannelClient *rcc, PipeItem *item)
> {
> }
>
> -static void handle_tunnel_channel_link(Channel *channel, RedClient *client, RedsStream *stream,
> - int migration, int num_common_caps, uint32_t *common_caps,
> - int num_caps, uint32_t *caps)
> +static void handle_tunnel_channel_link(Channel *channel, RedClient *client,
> + RedsStream *stream, int migration,
> + int num_common_caps,
> + uint32_t *common_caps, int num_caps,
> + uint32_t *caps)
> {
> - TunnelChannel *tunnel_channel;
> + TunnelChannelClient *tcc;
> TunnelWorker *worker = (TunnelWorker *)channel->data;
> + RedChannel *tunnel_channel;
> +
> if (worker->channel) {
> - tunnel_channel_disconnect(&worker->channel->base);
> + tunnel_channel_disconnect(worker->channel->base.channel);
> }
>
> - tunnel_channel =
> - (TunnelChannel *)red_channel_create(sizeof(*tunnel_channel), worker->core_interface,
> + tunnel_channel = red_channel_create(sizeof(RedChannel),
> + worker->core_interface,
> migration, TRUE,
> tunnel_channel_config_socket,
> tunnel_channel_disconnect_client,
> @@ -3454,23 +3463,25 @@ static void handle_tunnel_channel_link(Channel *channel, RedClient *client, Reds
> tunnel_channel_release_pipe_item,
> tunnel_channel_handle_migrate_mark,
> tunnel_channel_handle_migrate_data,
> - tunnel_channel_handle_migrate_data_get_serial_proc);
> + tunnel_channel_handle_migrate_data_get_serial);
>
> if (!tunnel_channel) {
> return;
> }
> - red_channel_client_create(sizeof(RedChannelClient), &tunnel_channel->base, client, stream);
> + tcc = (TunnelChannelClient*)red_channel_client_create(
> + sizeof(TunnelChannelClient),
> + tunnel_channel, client, stream);
>
> - tunnel_channel->worker = worker;
> - tunnel_channel->worker->channel = tunnel_channel;
> + tcc->worker = worker;
> + tcc->worker->channel = tcc;
> net_slirp_set_net_interface(&worker->tunnel_interface.base);
>
> - on_new_tunnel_channel(tunnel_channel);
> + on_new_tunnel_channel(tcc);
> }
>
> static void handle_tunnel_channel_shutdown(struct Channel *channel)
> {
> - tunnel_channel_disconnect(&((TunnelWorker *)channel->data)->channel->base);
> + tunnel_channel_disconnect(((TunnelWorker *)channel->data)->channel->base.channel);
> }
>
> static void handle_tunnel_channel_migrate(struct Channel *channel)
> @@ -3478,9 +3489,9 @@ static void handle_tunnel_channel_migrate(struct Channel *channel)
> #ifdef DEBUG_NETWORK
> red_printf("TUNNEL_DBG: MIGRATE STARTED");
> #endif
> - TunnelChannel *tunnel_channel = ((TunnelWorker *)channel->data)->channel;
> + TunnelChannelClient *tunnel_channel = ((TunnelWorker *)channel->data)->channel;
> tunnel_channel->mig_inprogress = TRUE;
> net_slirp_freeze();
> - red_channel_client_pipe_add_type(tunnel_channel->base.rcc, PIPE_ITEM_TYPE_MIGRATE);
> + red_channel_client_pipe_add_type(&tunnel_channel->base, PIPE_ITEM_TYPE_MIGRATE);
> }
>
> --
> 1.7.4.4
>
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/spice-devel
>
--
Marc-André Lureau
More information about the Spice-devel
mailing list