Commit Graph

1042 Commits

Author SHA1 Message Date
Alon Levy
376264b009 server: move dump_bitmap to separate file 2013-08-14 12:08:04 +03:00
Alon Levy
ff672924ca server/red_worker.c:red_process_drawable: rename item to drawable 2013-08-14 12:08:04 +03:00
Alon Levy
3a25c20704 server/red_worker.c:red_process_drawable: rename drawable to red_drawable 2013-08-14 12:08:04 +03:00
Alon Levy
478a1906b0 red_worker: mark DRAW_ALL as broken
setting DRAW_ALL define doesn't produce correct rendering. Using
update_area instead of red_draw_qxl_drawable will work but it shouldn't
be required. This is not work I intend to do right now, so marking it
for anyone looking at this in the future.
2013-08-14 12:07:50 +03:00
Yonit Halperin
6ced0f6985 red_worker: decrease the timeout when flushing commands and waiting for the client.
150 seconds is way too long period for holding the guest driver and
waiting for a response for the client. This timeout was 15 seconds, but
when off-screen surfaces ware introduced it was arbitrarily multiplied by
10.
Other existing related bugs emphasize why it is important to decrease
the timeout:
(1) 994211 - the qxl driver waits for an async-io reponse for 60 seconds
    and after that, it switches to sync-io mode. Not only that the
    driver might use invalid data (since it didn't wait for the query to
    complete), falling back to sync-io mode introduces other errors.
(2) 994175 - spice server sometimes doesn't recognize that the client
             has disconnected.
(3) There might be cache inconsistency between the client and the server,
and then the display channel waits indefinitely for a cache item (e.g., bug
977998)

This patch changes the timeout to 30 seconds. I tested it under wifi +emulating 2.5Mbps network,
together with playing video on the guest and changing resolutions in a loop. The timeout didn't expired
during my tests.

This bug is related to rhbz#964136 (but from rhbz#964136 info it is still not
clear why the client wasn't responsive).
2013-08-06 14:28:34 -04:00
Yonit Halperin
c2e46b926e log: improve debug information related to client disconnection 2013-07-29 11:35:17 -04:00
Yonit Halperin
02f44c137d snd_worker/snd_disconnect_channel: don't call snd_channel_put if the channel has already been disconnected
The snd channels has one reference as long as their socket is active.
The playback channel has an additional reference for each frame that is
currently filled by the sound device.
Once the channel is disconnected (the socket has been freed and the
first reference is released) snd_disconnect_channel shouldn't release
a reference again.
2013-07-29 11:35:17 -04:00
Yonit Halperin
134b7f310d snd_worker: fix memory leak of PlaybackChannel
When the sequence of calls bellow occurs, the PlaybackChannel
is not released (snd_channel_put is not called for the
samples that refer to the channel).

    spice_server_playback_get_buffer
    snd_channel_disconnect
    spice_server_playback_put_samples
2013-07-29 11:35:17 -04:00
Yonit Halperin
46c2ce8f1a reds: s/red_client_disconnect/red_channel_client_shutdown inside callbacks
When we want to disconnect the main channel from a callback, it is
safer to use red_channel_client_shutdown, instead of directly
destroying the client. It is also more consistent with how other
channels treat errors.
red_channel_client_shutdown will trigger socket error in the main channel.
Then, main_channel_client_on_disconnect will be called,
and eventually, main_dispatcher_client_disconnect.

I didn't replace calls to reds_disconnect/reds_client_disconnect in
places where those calls were safe && that might need immediate client
disconnection.
2013-07-29 11:35:17 -04:00
Yonit Halperin
8490f83e1f decouple disconnection of the main channel from client destruction
Fixes rhbz#918169

Some channels make direct calls to reds/main_channel routines. If
these routines try to read/write to the socket, and they get socket
error, main_channel_client_on_disconnect is called, and triggers
red_client_destroy. In order to prevent accessing expired references
to RedClient, RedChannelClient, or other objects (inside the original call, after
red_client_destroy has been called) I made the call to
red_client_destroy asynchronous with respect to main_channel_client_on_disconnect.
I added MAIN_DISPATCHER_CLIENT_DISCONNECT to main_dispatcher.
main_channel_client_on_disconnect pushes this msg to the dispatcher,
instead of calling directly to reds_client_disconnect.

The patch uses RedClient ref-count in order to handle a case where
reds_client_disconnect is called directly (e.g., when a new client connects while
another one is connected), while there is already CLIENT_DISCONNECT msg
pending in the main_dispatcher.

Examples:
(1) snd_worker.c

    snd_disconnect_channel()
        channel->cleanup() //snd_playback_cleanup
            reds_enable_mm_timer()
                .
                .
                main_channel_push_multi_media_time()...socket_error
                    .
                    .
                    red_client_destory()
                        .
                        .
                        snd_disconnect_channel()
                            channel->cleanup()
                                celt051_encoder_destroy()
            celt051_encoder_destory() // double release

Note that this bug could have been solved by changing the order of
calls: e.g., channel->stream = NULL before calling cleanup, and
some other changes + reference counting. However, I found other
places in the code with similar problems, and I looked for a general
solution, at least till we redesign red_channel to handle reference
counting more consistently.

(2) inputs_channel.c

    inputs_connect()
        main_channel_client_push_notify()...socket_error
                .
                .
            red_client_destory()
                .
                .
        red_channel_client_create() // refers to client which is already destroyed

(3) reds.c

    reds_handle_main_link()
       main_channel_push_init() ...socket error
                .
                .
            red_client_destory()
                .
                .
       main_channel_client_start_net_test(mcc) // refers to mcc which is already destroyed

    This can explain the assert in rhbz#964136, comment #1 (but not the hang that occurred before).
2013-07-29 11:35:17 -04:00
Yonit Halperin
06ba03b7b3 main_dispatcher: add ref count protection to RedClient instances 2013-07-29 11:35:17 -04:00
Yonit Halperin
aab45618cc red_channel: add ref count to RedClient 2013-07-29 11:35:16 -04:00
Yonit Halperin
47e722b85c red_channel: prevent adding and pushing pipe items after a channel_client has diconnected
Fixes: leaks of pipe items & "red_client_destroy: assertion `rcc->send_data.size == 0'"

red_channel_disconnect clears the pipe. It is called only once. After,
it was called, not items should be added to the pipe.

An example of when this assert can occur:
on_new_cursor_channel (red_worker.c), pushes 2 pipe items.
When it pushes the first pipe item, if the client has disconnected,
it can hit a socket error, and then, red_channel_client_disconnect is called.
The second call to adding a pipe item, will add the item to
the pipe. red_channel_client_pipe_add_type also calls
red_channel_client_push, which will update the send_data.size.
Then, the push will also hit a socket error, but red_channel_client_disconnect
won't clear the pending pipe item again, since it was already called.
When red_client_destory is called, we hit assertion `rcc->send_data.size
== 0'.
Note that if a pipe item is added to the pipe after
red_channel_client_disconnect was called, but without pushing it,
we should hit "spice_assert(rcc->pipe_size == 0)".
2013-07-29 11:35:16 -04:00
Alon Levy
3ef0480658 server/red_channel: fix unused variable
unused variable 'so_unsent_size' [-Werror=unused-variable]
2013-07-28 22:12:01 +03:00
Alon Levy
51511a51cf server/red_worker.c: remove unused pipe_item_remove 2013-07-24 14:56:54 +03:00
Nahum Shalman
c07ba1cd4f TIOCOUTQ -> SIOCOUTQ and portability ifdefs
The ioctl on sockets is actually named SIOCOUTQ though its value
is identical to TIOCOUTQ which is for terminals.
SIOCOUTQ is linux specific so we add a header check and ifdef based
on the presence of the header
This prevents bogus ioctls on non-Linux platforms
2013-07-22 12:01:59 -04:00
Uri Lublin
d6092f11b6 syntax-check: remove trailing whitespaces
Only whitespace changes in this commit.
2013-07-16 23:37:29 +03:00
Uri Lublin
d45f3bdc6b syntax-check: make sure config.h is the first included .h file 2013-07-16 23:37:29 +03:00
Uri Lublin
8b4dde347b syntax-check: use test A && test B instead of test A -a B 2013-07-16 23:37:29 +03:00
Uri Lublin
bc77805b5f syntax-check: fix no-newline or empty line at EOF 2013-07-16 23:37:29 +03:00
Uri Lublin
cfe81e1a98 syntax-check: s/the the/the/ in a comment 2013-07-16 23:37:28 +03:00
Uri Lublin
413883ecf8 syntax-check: fix cast_of_argument_to_free
In this case, make syntax-check is wrong, and we actually do
need the cast.
A cast is needed when types are   uint64_t <--> pointer

Using a local "ptr" variable makes both gcc and syntax-check happy.
2013-07-16 23:37:28 +03:00
Uri Lublin
a89b1b5543 syntax-check: fix avoid_if_before_free 2013-07-16 23:37:28 +03:00
Uri Lublin
8511c747d1 server/tests: fix timer for test_empty_success 2013-07-16 23:37:28 +03:00
Uri Lublin
3ede55b2ba server/tests: test_display_width_stride: add destroy command
Otherwise, the test exits after the first iteration over all tests,
on the second attempt to create an already created surface.
2013-07-16 23:37:28 +03:00
Uri Lublin
b66d755447 server/tests: remove option from usage if AUTOMATED_TESTS is not configured 2013-07-16 23:37:27 +03:00
Uri Lublin
cbcd9eea36 server/tests: invalid-option: print the bad argument
optind points to the next argument to parse.
2013-07-16 23:37:27 +03:00
Uri Lublin
694f4b9e57 server/tests: fix produce_command for create surface
Earlier in this function, test->target_surface is set to 1, which
is the only allowed non-primary surface currently.

If surface parameters are given (and specifically data is checked)
they are being used, otherwise a default surface is used.

Earlier in this function, "command" is set to a non-NULL value.
Thus, the else part was unreachable code, which is fixed now.
2013-07-16 23:37:27 +03:00
Uri Lublin
ff03d8dd2a server/tests: test_display_base: set rect according to appropriate surface
When surface_id == 0, primary is used.
Otherwise (currently 1), secondary is used.

Also, remove unused test_width and test_height.
Since commit caea769943,
test->width and test->height are used.
2013-07-16 23:37:27 +03:00
Uri Lublin
1960ebb5b3 red_channel: replace RING_FOREACH with RING_FOREACH_SAFE in some places
This was originally intended to fix the problem fixed by
commit 53488f0275.

What is left are FOREACH loops that are at less risk and maybe safe (no
read/write or disconnect/destroy are called from within them).
2013-07-16 23:37:26 +03:00
Uri Lublin
cf905b7b68 red_worker: use a generic SAFE_FOREACH macro
Introduce SAFE_FOREACH macro

Make other safe iterators use SAFE_FOREACH
2013-07-16 23:37:26 +03:00
Uri Lublin
6c95bb3c59 red_worker: delete unused CCC_FOREACH 2013-07-16 23:37:26 +03:00
Uri Lublin
57dba5615e red_worker: make DRAWABLE_FOREACH_DPI safe 2013-07-16 23:37:26 +03:00
Uri Lublin
2af81e96f5 red_worker: use only DRAWABLE_FOREACH_GLZ_SAFE 2013-07-16 23:37:25 +03:00
Uri Lublin
b1330fcd5d red_worker: make WORKER_FOREACH_DCC safe
Specifically, the loop in red_pipes_add_draw can cause spice to abort.

In red_worker.c (WORKER_FOREACH_DCC):
  red_pipes_add_drawable
    red_pipe_add_drawable
      red_handle_drawable_surfaces_client_synced
        red_push_surface_image
          red_channel_client_push
            red_channel_client_send
              red_peer_handle_outgoing
                reds_stream_writev (if fails -- EPIPE)
                handler->cb->on_error = red_channel_client_disconnect()
                  red_channel_remove_client()
                  ring_remove() -- of rcc from channel.clients ring.
2013-07-16 23:37:25 +03:00
Uri Lublin
e4029833da red_worker: reuse DCC_FOREACH in WORKER_DCC_FOREACH
The only thing that is needed is to get the channel out of the worker.
2013-07-16 23:37:25 +03:00
Uri Lublin
255abf0a57 red_worker: use only RCC_FOREACH_SAFE
RCC_FOREACH may be dangerous

The following patches replace FOREACH loops with a SAFE version.
Using unsafe loops may cause spice-server to abort (assert fails).
Specifically a read/write fail in those loops, may cause the client
to disconnect, removing the node currently iterated, which cause spice
to abort in ring_next():
 -- assertion `pos->next != NULL && pos->prev != NULL' failed
2013-07-16 23:37:25 +03:00
David Gibson
53488f0275 Use RING_FOREACH_SAFE in red_channel.c functions which are missing it
Currently, both red_channel_pipes_add_type() and
red_channel_pipes_add_empty_msg() use plaing RING_FOREACH() which is not
safe versus removals from the ring within the loop body.

Although it's rare, such a removal can occur in both cases.  In the case
of red_channel_pipes_add_type() we have:
    red_channel_pipes_add_type()
    -> red_channel_client_pipe_add_type()
        -> red_channel_client_push()

And in the case of red_channel_client_pipes_add_empty_msg() we have:
    red_channel_client_pipes_add_empty_msg()
    -> red_channel_client_pipe_add_empty_msg()
        -> red_channel_client_push()

But red_channel_client_push() can cause a removal from the clients ring if
a network error occurs:
    red_channel_client_push()
    -> red_channel_client_send()
        -> red_peer_handle_outgoing()
            -> handler->cb->on_error callback
            =  red_channel_client_default_peer_on_error()
                -> red_channel_client_disconnect()
                    -> red_channel_remove_client()
                        -> ring_remove()

When this error path does occur, the assertion in RING_FOREACH()'s
ring_next() trips, and the process containing the spice server is aborted.
i.e. your whole VM dies, as a result of an unfortunately timed network
error on the spice channel.

Please apply.

Signed-off-by: David Gibson <dgibson@redhat.com>
2013-07-05 14:59:58 +02:00
Yonit Halperin
b83c0fbf7f red_worker: fix for stuck display_channel over WAN (jpeg_enabled=true)
The image descriptor flags shouldn't be copied as is from the flags that
were set by the driver. Specifically, the CACHE_ME flag shouldn't be copied,
since it is possible that (a) the image won't be cached (b) the image
is already cached, but in its lossy version, and we may want to set the bit for
CACHE_REPLACE_ME, in order to cache it in its lossless version.
In case (b), the client first looks for the CACHE_ME flag, and only if
it is not set it looks for CACHE_REPLACE_ME (see canvas_base.c). Since both flags where set,
the client ignored REPLACE_ME, and didn't turned off the lossy flag of the
cach item. Then, when a request from this lossles item reached the
client (FROM_CACHE_LOSSLESS), the client display channel waited
endlessly for the lossless version of the image.
2013-06-25 14:13:13 -04:00
Yonit Halperin
648117544f red_worker: improve stream stats readability and ease of parsing
also added start/end-bit-rate and avg-quality to the final stream stats.
2013-06-24 15:23:34 -04:00
Yonit Halperin
a9f1a4b75d mjpeg_encoder: add mjpeg_encoder_get_stats 2013-06-24 15:23:34 -04:00
Yonit Halperin
1377732805 spice: silencing most of the ping/pong logging
Those messages are too frequent and don't contribute much
2013-06-24 15:22:59 -04:00
Hans de Goede
db278430f8 server: Add support for filtering out agent file-xfer msgs (rhbz#961848)
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2013-06-06 16:07:30 +02:00
Yonit Halperin
b30daf38bf red_channel: replace an assert upon threads mismatch with a warning
The assert:
spice_assert(pthread_equal(pthread_self(), client->thread_id))
and the assert:
spice_assert(pthread_equal(pthread_self(), rcc->channel->thread_id))
were coded in order to protect data that is accessed from the main
context (red_client and most of the channels), from
access by threads of other channels (namely, the display and cursor
channels), and vice versa.
However, some of the calls to the sound channel interface,
and also the char_device interface, can be done from the vcpu thread.
It doesn't endanger these channels internal data, since qemu use global
mutex for the vcpu and io threads.
Thus, pthread_self() can be !=  channel->thread_id, if one of them is
the vcpu thread and the other is the io-thread, and we shouldn't assert.

Future plans: A more complete and complicated solution would be to manage our own thread for
spice-channels, and push input from qemu to this thread, instead of
counting on the global mutex of qemu

rhbz#823472
2013-05-24 16:27:31 -04:00
Yonit Halperin
67471d046b main_channel: fix double release of migration target data
If client_migrate_info was called once with cert-host-subject and
then again without cert-host-subject, on a third call to
client_migrate info, the cert-host-subject from the first call would
have been freed for the second time.
2013-05-23 16:59:04 -04:00
Christophe Fergeau
fd18dbaa02 Log actual address spice-server binds to
It's not always obvious what address spice-server will bind to,
in particular when the 'addr' parameter is omitted on QEMU
commandline. The decision of what address to bind to is made
in reds_init_socket with a call to getaddrinfo. Surprisingly,
that function had a call to getnameinfo() already, but it does
not seem to be using the result of that call in any way.
This commit moves this call after the socket is successfully bound
and add a log message to indicate which address it's bound to.
2013-05-19 16:04:31 +02:00
Alon Levy
5170589c21 server/red_parse_qxl: two coding convention pointer cast fix 2013-05-17 11:06:34 -04:00
Alon Levy
e9cf575938 server/dispatchers: initialize stack to 0 for valgrind 2013-05-17 11:06:34 -04:00
Alon Levy
feb913e56b server/red_dispatcher: close pa hole in RedWorkerMessageDisplayConnect for valgrind 2013-05-17 11:06:34 -04:00
Alon Levy
bcd7c4e097 server/tests: test_display_width_stride 2013-05-17 11:06:34 -04:00