Commit Graph

263 Commits

Author SHA1 Message Date
Dan McGee
143a1df24e red_worker: reimplement event loop using poll()
This removes the epoll dependency we had in red_worker, which was the
last Linux-specific call we were using in the entire Spice server. Given
we never have more than 10 file descriptors involved, there is little
performance gain had here by using epoll() over poll().

The biggest change is introduction of a new pre_disconnect callback;
this is because poll, unlike epoll, cannot automatically remove file
descriptors as they are closed from the pollfd set. This cannot be done
in the existing on_disconnect callback; that is too late as the stream
has already been closed and the file descriptor lost. The on_disconnect
callback can not be moved before the close and other operations easily
because of some behavior that relies on client_num being set to a
certain value.

Signed-off-by: Dan McGee <dpmcgee@gmail.com>
2012-02-21 10:20:46 +02:00
Dan McGee
10d79a35c1 Cleanup definitions of disconnect methods
We had multiple stub methods that simply called other disconnect
methods, making my head hurt with the indirection. Call the right
methods at the right time and rip out the stub methods; if they are
truely needed later they can be added again.

Signed-off-by: Dan McGee <dpmcgee@gmail.com>
2012-02-21 10:20:45 +02:00
Dan McGee
a67268cbe1 red_worker: rename epoll_timeout to event_timeout
With future patches in mind that will allow for some other
non-Linux-specific event polling sytem to be used, rename this to a more
generic name. All of the select/poll/epoll/kqueue family of calls are
related to evented I/O, so 'event_' makes sense in this case.

Signed-off-by: Dan McGee <dpmcgee@gmail.com>
2012-02-21 10:20:44 +02:00
Dan McGee
08c514ee85 Remove extra '\n' from red_printf() calls
red_printf() takes care of adding a newline to all messages; remove the
extra newline from all messages and macros that were doubling them up.

Signed-off-by: Dan McGee <dpmcgee@gmail.com>
2012-02-14 18:19:29 +02:00
Dan McGee
c4ddc5ba51 Fix git commit hook errors in red_worker
This ensures all line lengths are down below 100 characters as well as
removing some trailing spaces.

Signed-off-by: Dan McGee <dpmcgee@gmail.com>
2012-01-23 12:28:57 +02:00
Hans de Goede
dc7855967f server: Don't complain if setsockopt NODELAY fails on unix sockets
With Daniel P. Berrange's patches to allow use of pre-supplied fd's
as channels, we can no longer be sure that our connections are TCP
sockets, so it makes no sense to complain if a TCP/IP specific
setsockopt fails with an errno of ENOTSUP.

Note that this extends Daniel's commit 492ddb5d1d
which already added the same check to server/inputs_channel.c

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2012-01-18 11:14:40 +01:00
Daniel P. Berrange
68c2897e5b Remove trailing whitespace from end of lines 2012-01-13 18:11:59 +02:00
Daniel P. Berrange
faf0947ebb Remove useless if() before free()
The free() function allows NULL to be passed in, so any
code which puts a if() before free() is wasting time
2012-01-13 18:11:58 +02:00
Daniel P. Berrange
64f4826b6d Death to all TABs
Source files should all use spaces instead of tabs for
indentation. Update the few files not already in
compliance
2012-01-13 18:11:58 +02:00
Yonit Halperin
65c859ba81 server: add support for SPICE_COMMON_CAP_MINI_HEADER
Support for a header without a serial and without sub list.
red_channel: Support the two types of headers.
             Keep a consistent consecutive messages serial.
red_worker: use urgent marshaller instead of sub list.
snd_worker: Sound channels need special support since they still don't use
            red_channel for sending & receiving.
2012-01-12 16:33:36 +02:00
Yonit Halperin
8b64b95c43 server: Limit the access to SpiceDataHeader of messages - only via red_channel. 2012-01-12 16:17:02 +02:00
Yonit Halperin
a54f26d04e server/red_worker: pass remote caps to display/cursor red_channel_client's 2012-01-12 16:17:01 +02:00
Yonit Halperin
fe001ca19d server: don't reset the display channel when disconnecting all its clients ,FDBZ #43977
The display channel was unnecessarily set to NULL when we disconnect all the clients
(on flush display commands timeout).
As a result, we recreated the display channel when a new client was connected.
The display channel was created with default red_channel.client_cbs, while its
correct client_cbs are the ones that are set by the red_dispatcher when it creates
the first display_channel.
This fix enforces a single creation of the display channel (per qxl), via the red_dispatcher.
2011-12-22 12:58:25 +02:00
Alon Levy
8e049ce3b0 server/red_worker: reuse dispatcher
This patch reuses Dispatcher in RedDispatcher. It adds two helpers
to red_worker to keep RedWorker opaque to the outside. The dispatcher is
abused in three places that use the underlying socket directly:
 once sending a READY after red_init completes
 once for each channel creation, replying with the RedChannel instance
  for cursor and display.

FDO Bugzilla: 42463

rfc->v1:
* move callbacks to red_worker.c including registration (Yonit)
* rename dispatcher to red_dispatcher in red_worker.c and red_dispatcher.c
* add accessor red_dispatcher_get_dispatcher
* s/dispatcher_handle_recv/dispatcher_handle_recv_read/ and change sig to
  just Dispatcher *dispatcher (was the SpiceCoreInterface one)
* remove SpiceCoreInterface parameter from dispatcher_init (Yonit)
* main_dispatcher needed it for channel_event so it has it in
  struct MainDispatcher
* add dispatcher_get_recv_fd for red_worker
2011-11-08 16:23:10 +02:00
Alon Levy
af77bb577d server: add prefix argument to red_printf_debug
printed before function name. No central location for prefixes.
Adding "WORKER", "ASYNC", "MAIN" since those were the current users.
2011-11-07 10:29:32 +02:00
Alon Levy
d5274eeef6 server/red_dispatcher: support concurrent asyncs
This is part of the dispatcher update, extracting the dispatcher routine
from red_dispatcher and main_dispatcher into dispatcher.

Supporting multiple async operations will make it natural to support
async monitor commands and async guest io requests that could overlap in
time.

Use a Ring for AsyncCommands.

Free Desktop Bugzilla: 42463

Related FD: 41622
2011-11-07 10:27:34 +02:00
Yonit Halperin
0bf518cd3d server: set & test channel capabilities in red_channel
The code for setting and testing channel capabilities was
unnecessarily duplicated. Now it is in red_channel.
RedsChannel was dropped from Reds; It was used only for holding
the channels common capabilities, which are now held in RedChannel.
2011-11-02 11:19:48 +02:00
Yonit Halperin
86576aec6a server/red_worker: fix placing of ASSERT(red_channel_client_no_item_being_sent) (fdbz #41523)
Call ASSERT(red_channel_client_no_item_being_sent) only if
red_wait_outgoing_item/s did not timeout.
2011-10-18 15:16:46 +02:00
Christophe Fergeau
6a20050352 replace warning with comment in glz_usr_free_image
When running some xinerama tests, I got several
glz_usr_free_image: error
messages. Looking at the code, this error is reported when this
function is called from a different DisplayChannelClient than the
one which created the glz compressed image.
When this happens, the backtrace is
    at glz_encoder_dictionary.c:362
    0x7fff940b6670) at glz_encoder_dictionary.c:449
    image_type=LZ_IMAGE_TYPE_RGB32, image_width=512, image_height=256, image_stride=2048, first_lines=0x0,
    num_first_lines=0, usr_image_context=0x7fff7420da40, image_head_dist=0x7fff9b2a3194)
    at glz_encoder_dictionary.c:570
    top_down=4, lines=0x0, num_lines=0, stride=2048, io_ptr=0x7fff740ea7c0 "  ZL", num_io_bytes=65536, usr_context=
    0x7fff7420da40, o_enc_dict_context=0x7fff7420da60) at glz_encoder.c:255
    drawable=0x7fff9b46bc08, o_comp_data=0x7fff9b2a3350) at red_worker.c:5753
    0x7fff9b46bc08, can_lossy=0, o_comp_data=0x7fff9b2a3350) at red_worker.c:6211
    0x7fff9b46bc08, can_lossy=0) at red_worker.c:6344
    0x7fff74085c50, dpi=0x7fff7445b890, src_allowed_lossy=0) at red_worker.c:7046
    0x7fff7445b890) at red_worker.c:7720
    at red_worker.c:7964
    at red_worker.c:8431

Since the glz dictionary is shared between all the
DisplayChannelClient instances that belong to the same client, it can
happen that the glz dictionary code decides to free an image from one
thread while it was added from another thread (thread ==
DisplayChannelClient), so the error message that is printed is not an
actual error. This commit removes this message and adds a comment
explaining what's going on.
2011-09-19 18:33:32 +02:00
Christophe Fergeau
011266555a server: fix function prototypes
Several functions in server/ were not specifying an argument list,
ie they were declared as void foo(); When compiling with
-Wstrict-prototypes, this leads to:
test_playback.c:93:5: erreur: function declaration isn’t a prototype
[-Werror=strict-prototypes]
2011-09-05 07:52:20 +02:00
Christophe Fergeau
41174221fb server: init all fields on SpiceMsgDisplayStreamCreate
red_display_marshall_stream_start initializes a
SpiceMsgDisplayStreamCreate structure before marshalling it and
sending it on the wire. However, it never fills
SpiceMsgDisplayStreamCreate::stamp which then causes a complaint
from valgrind. This patch sets this value to 0, it's not used
by the client so the value shouldn't matter.
2011-09-01 03:57:35 +02:00
Yonit Halperin
16ed3f9f25 drawables count for debug 2011-08-23 18:27:53 +03:00
Yonit Halperin
f84dfeb0aa server: registering RedChannel in reds, instead of Channel
Merging the functionality of reds::channel, into RedChannel.
In addition, cleanup and fix disconnection code: before this patch,
red_dispatcher_disconnect_display_client
could have been called from the red_worker thread
(and it must be called only from the io thread).

RedChannel holds only connected channel clients. RedClient holds all the
channel clients that were created till it is destroyed
(and then it destroys them as well).

Note: snd_channel still doesn't use red_channel, however it
creates dummy channel and channel clients, in order to register itself
in reds.

server/red_channel.c: a channel is connected if it holds at least one channel client

Previously I changed RedChannel to hold only connected channel clients and
RedClient, to hold all the channel clients as long as it is not destroyed.

usbredir: multichannel has not been tested, it just compiles.
2011-08-23 18:27:46 +03:00
Yonit Halperin
812d01c060 server/red_channel.c: pack all channel callbacks to ChannelCbs 2011-08-23 18:23:46 +03:00
Alon Levy
67671b2609 server/red_worker: add ref counting to RedDrawable
introduces ref_red_drawable and put_red_drawable (rename from free_red_drawable)

RedDrawable is already references by Drawable and RedGlzDrawable, with
a hack to NULL the drawable field in RedGlzDrawable to indicate RedGlzDrawable
is the last reference holder. Using an explicit reference count instead.
2011-08-23 18:07:10 +03:00
Alon Levy
74ce23a0e8 server/red_worker: add stream_count (for debug purposes) 2011-08-23 18:06:47 +03:00
Alon Levy
11f2ad60ea server/red_worker: validate_surface: print paniced surface_id 2011-08-23 18:06:25 +03:00
Alon Levy
d0e740eeaa server/red_worker: no panic on double destroy primary 2011-08-23 18:06:03 +03:00
Alon Levy
c820b252c1 server/red_worker: DEBUG_CURSORS
Add cursor allocation debugging code that is turned off as long as
DEBUG_CURSORS is not defined.
2011-08-23 18:05:42 +03:00
Alon Levy
f4d07791cc server/red_worker: on_new_display_channel_client: push ack, cleanup
small cleanup patch, only functional change is sending a set ack message.
2011-08-23 18:05:19 +03:00
Alon Levy
969ab70413 server/red_worker: add cursor_channel_client_disconnect
makes RED_WORKER_MESSAGE_CURSOR_DISCONNECT_CLIENT disconnect only a
single client.
2011-08-23 18:04:56 +03:00
Alon Levy
c78e951bff server/red_worker: remove forced disconnect on connect 2011-08-23 18:04:33 +03:00
Yonit Halperin
bed8c9d4f6 server/red_worker.c: fix CursorPipeItem leak
CursorPipeItems and their corresponding cursor_item were not
freed when they were removed from the pipe without sending them.
In addition cursor_channel_hold_pipe_item used wrong conversion
to (CursorItem*) for a (CursorPipeItem*).
2011-08-23 18:04:10 +03:00
Alon Levy
52bff67935 server/red_worker: split cursor pipe item from cursor item
Required to support multiple clients.
Also changes somewhat the way we produce PIPE_ITEM_TYPE_LOCAL_CURSOR. Btw,
I haven't managed to see when we actually produce such an item during my
tests.

Previously we had a single pipe item per CursorItem, this is impossible
with two pipes, which happens when we have two clients.
2011-08-23 18:03:47 +03:00
Alon Levy
24d8340b71 server/red_worker: whitespace fixes 2011-08-23 18:03:24 +03:00
Alon Levy
4db9f1d1a9 server/red_channel: introduce client ring in RedChannel
Also adds Drawable pipes and glz rings.

main_channel and red_worker had several locations that still accessed rcc
directly, so they had to be touched too, but the changes are minimal.

Most changes are in red_channel: drop the single client reference in RedChannel
and add a ring of channels.

Things missing / not done right in red_worker:
 * StreamAgents are in DCC - right/wrong?
 * GlzDict is multiplied - multiple compressions.

We still are missing:
 * remove the disconnect calls on new connections
2011-08-23 18:02:38 +03:00
Alon Levy
6a1d657373 server/red_channel: add pipe_size helpers 2011-08-23 18:02:14 +03:00
Alon Levy
9c192980e8 server/red_worker: remove more direct access to RedChannelClient.rcc 2011-08-23 18:01:51 +03:00
Yonit Halperin
d42575feab server/red_worker.c: make dictionary and cache different per client
There is no inter-client shared dictionary and cache yet.

At this point the display channel can be used by multiple clients.

You can still crash on lack of Drawables or CursorItems due to the slower
clients pipe growing uncontrollably.
2011-08-23 18:01:28 +03:00
Alon Levy
a32e90257e server/red_worker: multiple client support - base split
This patch compiles but breaks spice.

Split both display and cursor channels to a client part and channel part.

Introduce DisplayChannelClient, CursorChannelClient, CommonChannelClient.
don't disconnect channel on client disconnect.
Move all caches to the ChannelClient's.

Remove reference counting of the channel.

No new functionality introduced.

NOTE: Introduces a crash in disconnections, a regression, resulting from
incorrect thread access, that is fixed in the patch titled:
"server: registering RedChannel in reds, instead of Channel"
2011-08-23 18:01:04 +03:00
Alon Levy
406751888e server/red_worker: cleanup 2011-08-23 18:00:41 +03:00
Alon Levy
5bcdf37997 server/main_channel: move latency and bitrate to channel client
They were globals before. This introduces api for other channels
to query the low bandwidth status. The queries themselves are still done
from the wrong context (channel and not channel client) but that's because
the decoupling of channel and channel client will be done in the following
patches.

Note that snd_worker.c got two copied function declarations that belong to
main_channel.h but can't be easily dragged into snd_worker.c since it still
uses it's own RedChannel struct.
2011-08-23 17:57:13 +03:00
Alon Levy
448ed75bd6 server: Add RedClient
That means RedClient tracks a ring of channels. Right now there will be only
a single client because of the disconnection mechanism - whenever a new
client comes we disconnect all existing clients. But this patch adds already
a ring of clients to reds.c (stored in RedServer).

There is a known problem handling many connections and disconnections at the
same time, trigerrable easily by the following script:

export NEW_DISPLAY=:3.0

Xephyr $NEW_DISPLAY -noreset &
for ((i = 0 ; i < 5; ++i)); do
    for ((j = 0 ; j < 10; ++j)); do
        DISPLAY=$NEW_DISPLAY c_win7x86_qxl_tests &
    done
    sleep 2;
done

I fixed a few of the problems resulting from this in the same patch. This
required already introducing a few other changes:
 * make sure all removal of channels happens in the main thread, for that
 two additional dispatcher calls are added to remove a specific channel
 client (RED_WORKER_MESSAGE_CURSOR_DISCONNECT_CLIENT and
 RED_WORKER_MESSAGE_DISPLAY_DISCONNECT_CLIENT).
 * change some asserts in input channel.
 * make main channel disconnect not recursive
 * introduce disconnect call back to red_channel_create_parser

The remaining abort is from a double free in the main channel, still can't
find it (doesn't happen when running under valgrind - probably due to the
slowness resulting from that), but is easy to see when running under gdb.
2011-08-23 17:56:44 +03:00
Alon Levy
2550e825ec server/red_worker: release PIPE_ITEM_TYPE_VERB in display channel
We send a SPICE_MSG_DISPLAY_MARK verb.
2011-08-23 17:46:07 +03:00
Alon Levy
09ae4700d2 server: move pipe from RedChannel to RedChannelClient
Another cleanup patch, no change to behavior (still one client, and it
disconnects previous client if any).

The implementation for multiple client is straightforward: the pipe
remains per (channel,client) pair, so it needs to move from the RedChannel
that to RedChannelClient. Implementation using a single pipe with multiple
consumers (to reflect different latencies) doesn't fit well with pipe rewriting
that is used by the display channel. Additionally this approach is much simpler
to verify. Lastly it doesn't add considerable overhead (but see the display
channel changes in a later patch for a real place to rethink).

This patch is just technical, changing signatures to reflect the first
argument (oop style) so red_channel becomes red_channel_client. Some places
may seem odd but they should be fixed with later comits where the channels
grow to support multiple clients.

Sound (playback/record) channels are the only ones not touched - this is
consistent with previous patches, since they have been left out of the
RedChannel refactoring.  That is left as future work. (note that they don't use
a pipe, which was the reason for not refactoring).
2011-08-23 17:44:54 +03:00
Alon Levy
b6cf68604f server/red_worker: introduce {display,cursor}_is_connected
Instead of checking for worker->{display,cursor}_channel directly.
2011-08-23 17:42:48 +03:00
Alon Levy
7e8e13593e server/red_channel (all): introduce RedChannelClient
This commit adds a RedChannelClient that now owns the stream connection,
but still doesn't own the pipe. There is only a single RCC per RC
right now (and RC still means RedChannel, RedClient will be introduced
later). All internal api changes are in server/red_channel.h, hence
the need to update all channels. red_worker.c is affected the most because
it makes use of direct access to some of RedChannel still.

API changes:

 1. red_channel_client_create added.
  rec_channel_create -> (red_channel_create, red_channel_client_create)
 2. two way connection: rcc->channel, channel->rcc (later channel will
  hold a list, and there will be a RedClient to hold the list of channels
  per client)
 3. seperation of channel disconnect and channel_client_disconnect

TODO:
 usbredir added untested.
2011-08-23 17:42:36 +03:00
Alon Levy
75b6a305ff server/red_worker: drop red_pipe_add_tail, use red_channel_pipe_add_tail
The only difference between them being that the later also does a push.
I don't believe that to be a problem, but if it does I can always introduce
a push'less version.
2011-08-23 17:01:14 +03:00
Alon Levy
8fbc41b717 server/red_channel: renames to use _proc postfix consistently
rename types - we use _proc suffix mostly to indicate function pointer types,
use it for some function pointers that were missing it.

s/channel_handle_migrate_flush_mark/channel_handle_migrate_flush_mark_proc/
s/channel_handle_migrate_data_get_serial/channel_handle_migrate_data_get_serial_proc/
s/channel_handle_migrate_data/channel_handle_migrate_data_proc/
2011-08-23 17:01:14 +03:00
Yonit Halperin
06c2e22fd9 server/red_worker.c: fix - locking the wrong mutex when releasing glz dict 2011-08-23 17:01:14 +03:00