Commit Graph

1973 Commits

Author SHA1 Message Date
Frediano Ziglio
0c5eca97f1 Handle flow control without crashing for agent
RedCharDevice used for the agent has flow control enabled.
This make possible for red_char_device_write_buffer_get to return NULL.
Handle such situation without crashing avoiding NULL dereference.

This fixes https://bugs.freedesktop.org/show_bug.cgi?id=95416.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2016-05-31 16:26:33 +01:00
Frediano Ziglio
5d2fb6a897 Avoid getting channel from client
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-05-27 18:02:29 +01:00
Frediano Ziglio
5841a2abda Move upcast conversion to a safer place
Upcast conversions are by definition unsafe. There are however some
location where such conversion are more safe. In this case send_item
callback is registered specifically for this type of RedChannel making
the conversion more reliable.
The other conversion (CursorChannel -> RedChannel) became safe.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-05-27 09:41:01 +01:00
Frediano Ziglio
8d25e03371 Add some comments to cursor-channel.h header
Explain usage of the class.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-05-27 09:32:58 +01:00
Frediano Ziglio
20373582ac Avoid double conversion
Avoid converting from RedChannelClient* to DisplayChannelClient* and
DisplayChannelClient* to RedChannelClient* just to use RedChannelClient*
('display_channel->clients' is a list of RedChannelClients).

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2016-05-26 16:43:31 +01:00
Frediano Ziglio
a95251c30b Remove useless double conversion
Avoid converting RedChannelClient* to CursorChannelClient* and then
CursorChannelClient* to RedChannelClient* just to use RedChannelClient*.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2016-05-26 16:37:25 +01:00
Frediano Ziglio
8f7419a711 replay: rename red_record_dev_input_primary_surface_create
Rename red_record_dev_input_primary_surface_create to
red_record_primary_surface_create.
Name is more concise and was not clear what "dev_input" was supposed
to specify.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-05-26 16:29:06 +01:00
Frediano Ziglio
82caf14025 replay: allows to specify a filter for record output
This allows compression using external programs or any type
of filters.

To use it set SPICE_WORKER_RECORD_FILTER environment to the
filter command you want to use. The command is executed with
g_spawn_async_with_pipes (which uses execve) so is not a shell
command although the command is parsed using g_shell_parse_argv
which split arguments as shell does.

One easy way to use it is to just use a compressor like gzip with

  export SPICE_WORKER_RECORD_FILENAME=/tmp/qemu_record.gz
  export SPICE_WORKER_RECORD_FILTER=gzip
  qemu ...

The filter will receive the recording on standard input and is
supposed to write in output filename (which is the standard output).
You can use additional arguments in SPICE_WORKER_RECORD_FILTER to
specify for instance compression level.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-05-26 16:28:55 +01:00
Frediano Ziglio
751a0aeb51 replay: better record encapsulation
Remove global/static from red_record_qxl.c.
Defined a structure and use it to hold record state.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-05-26 16:28:43 +01:00
Frediano Ziglio
1d3cd7d617 Hide CursorChannelClient implementation details
The existence of this class can be hidden to user of CursorChannel class

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-05-26 11:02:53 +01:00
Frediano Ziglio
6ad393d82b Make cursor_channel_client_new static
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-05-26 10:23:35 +01:00
Frediano Ziglio
c0a8b69822 Move cursor_connect to CursorChannel
This function was handling mainly CursorChannel state

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-05-26 10:23:33 +01:00
Frediano Ziglio
24b3a8e73c Make some function static
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-05-25 15:41:58 +01:00
Frediano Ziglio
ca5db16cb8 dc: use FOREACH_CLIENT macro for loop
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2016-05-25 14:44:02 +01:00
Frediano Ziglio
25d4a66519 dc: inline dpi computation
Actually not exactly the same as this fix a bug if base is not the
first element (in this case if dpi_ring_item is NULL dpi is not)

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2016-05-25 14:44:02 +01:00
Frediano Ziglio
0c91530b07 dc: join the two loop
They tested the same condition, no break in inside loop (which would
exit all loops)

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2016-05-25 14:44:02 +01:00
Frediano Ziglio
85d3af793d dc: reuse code inside loop
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2016-05-25 14:44:02 +01:00
Frediano Ziglio
a7b0162015 dc: convert break to continue
Both jump to check worker_ring_item (internal or external loops)

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2016-05-25 14:44:02 +01:00
Frediano Ziglio
5fbac6c8cb dc: use while again
Convert from for(;;) { if () break; ... } to while

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2016-05-25 14:44:02 +01:00
Frediano Ziglio
0010656ea4 dc: if link is NULL jumping outside loop will check variable and exit
The outer loop will exit too.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2016-05-25 14:44:02 +01:00
Frediano Ziglio
9a85e3cf34 dc: if dpi is not NULL even dpi_ring_item is not NULL
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2016-05-25 14:44:02 +01:00
Frediano Ziglio
643bf445c5 dc: dpi is always a value computed from dpi_ring_item
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2016-05-25 14:44:02 +01:00
Frediano Ziglio
dec4b7eca5 dc: move code inside if
these lines are only executed then the condition are satisfied

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2016-05-25 14:44:02 +01:00
Frediano Ziglio
7447a9e66c dc: dcc used is always a value from current link
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2016-05-25 14:44:02 +01:00
Frediano Ziglio
a3ad49b326 dc: link is never null here
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2016-05-25 14:44:02 +01:00
Frediano Ziglio
1d39275c3d dc: the link condition make this case terminate loop
dpi_ring_item is changed but ignored

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2016-05-25 14:44:02 +01:00
Frediano Ziglio
a5a9b38f46 dc: split if
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2016-05-25 14:44:02 +01:00
Frediano Ziglio
2d4e1e5e0a dc: convert to infinite loop
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2016-05-25 14:44:02 +01:00
Frediano Ziglio
2cb8b1cc9f Removed unused GET_CODE definition
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-05-25 14:32:42 +01:00
Frediano Ziglio
727d808332 Remove potentially unsafe casts
The id type is already uint64_t, no need to cast using some low
level casts.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-05-25 09:54:03 +01:00
Frediano Ziglio
b921e81f76 Remove unused macro definitions
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-05-25 09:54:03 +01:00
Frediano Ziglio
6ab857b45c Move RedCacheItem size field inside cache_data union
This reduce a bit the structure size and make clear that
the field is used only when the item is a cache item.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-05-25 09:53:57 +01:00
Frediano Ziglio
68d5ca29f8 Remove not necessary inval_type from RedCacheItem
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-05-25 09:53:13 +01:00
Jonathon Jongsma
7a51188891 Fix build warning when RED_WORKER_STAT is undefined
since display_channel_print_stats is now static, the compiler complains
when RED_WORKER_STAT is undefined since this function is not used:

    ../../server/display-channel.c:853:13: error: 'display_channel_print_stats' defined but not used [-Werror=unused-function]

To fix, don't define the function when RED_WORKER_STAT is undefined.
Acked-by: Victor Toso <victortoso@redhat.com>
2016-05-25 09:26:10 +02:00
Jonathon Jongsma
a31efd7e75 RedChannel: Add FOREACH_CLIENT and use it to iterate
Remove the custom FOREACH_DCC macro and use the more generic
FOREACH_CLIENT macro and use it for all channels.
2016-05-24 14:56:45 -05:00
Jonathon Jongsma
4028fb1c79 Replace RedChannel::clients with GList
Instead of using a Ring, use a GList to store the list of channel
clients. This allows us to iterate the clients without poking inside of
the client struct to get the channel_link. This is required in order to
make the RedChannelClient struct private.
2016-05-24 14:56:45 -05:00
Jonathon Jongsma
6c4e86cbe3 Move InputsChannelClient to a separate file
Preparation for converting to GObject

Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-05-24 14:56:41 -05:00
Frediano Ziglio
dbb6e71e8d change main_channel_marshall_mouse_mode call style
Make the call more similar to other marshall function calls in the
same function.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2016-05-24 13:44:01 -05:00
Frediano Ziglio
e4a6a1477e move all item creation in main-channel-client.c
Move all core to create and destroy MainChannel pipe items in a single
place.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2016-05-24 13:41:08 -05:00
Frediano Ziglio
02adcf354e Introduce SPICE_UPCAST macro
This was proposed by Christophe as improvement over some typesafe
patches.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-05-24 18:00:51 +01:00
Jonathon Jongsma
0528c0877c cache-item.h: remove unnecessary channel include
It's only necessary to include red-pipe-item.h

Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-05-24 17:53:22 +01:00
Jonathon Jongsma
5c64e01111 AgentMsgFilter: use typedef
Instead of using the full 'struct AgentMsgFilter', use the typedef name

Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-05-24 17:46:05 +01:00
Frediano Ziglio
8782bb3211 Make some function static
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-05-24 13:39:48 +01:00
Frediano Ziglio
70f04bdab3 Get code more typesafe
Scan remaining code searching for problems with structure
layout assumptions in the code.
Where code required some restructuring put some verify checks
to make sure code won't compile if these assumptions are not
in place anymore.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-05-21 04:14:13 +01:00
Frediano Ziglio
fb655ff481 reduce casts to RedPipeItem and RingItem
Make code more type safe. This allow to move or delete structure
fields more safely

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-05-21 04:11:12 +01:00
Frediano Ziglio
e8a9d3f2b9 rename RedVDIReadBug::parent to base
All other classes using RedPipeItem as base use base as parent name

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-05-21 04:11:12 +01:00
Frediano Ziglio
ab69c3367f make red_pipe_item_unref more typesafe
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-05-21 04:11:12 +01:00
Frediano Ziglio
f75b69fdc8 make red_pipe_item_ref more typesafe
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-05-21 04:11:12 +01:00
Frediano Ziglio
8d764488ca make red_pipe_item_init_full more typesafe
Use a proper type for free callback

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-05-21 04:11:12 +01:00
Frediano Ziglio
e960e00392 Use a marker instead of checking a RedPipeItem presence
This avoids having to retain a pointer just to check item is still in
the queue with ring_item_is_linked(&item->link).

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-05-21 04:11:12 +01:00