Commit Graph

1006 Commits

Author SHA1 Message Date
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
Alon Levy
3ace9a3333 server/red_worker: simplify monitors_config update 2013-05-17 11:06:34 -04:00
Alon Levy
7d6e813b2c server/tests/test_display_base: add missing set_client_capabilities, fix client_monitors_config signature 2013-05-17 11:06:34 -04:00
Alon Levy
f844a995bb server/red_worker: turn critical (assert) non error into warning
The situation causing this assert is unknown but it doesn't cause
correctness issues with later rendering, and it is causing an abort.
2013-05-17 11:06:34 -04:00
Alon Levy
97459ddfdb server/red_worker: s/driver_has_monitors_config/driver_cap_monitors_config/ (plus small comment) 2013-05-17 11:06:29 -04:00
Yonit Halperin
c09faf2382 red_worker: don't get bit_rate from main_channel_client, if it wasn't initialized
When setting an initial video stream bit rate, if the bit rate
wasn't calculated by main_channel_client, and we don't have
estimation from previos streams, use some default values.
The patch also removes updating dcc->streams_max_bit_rate when
the bit_rate held by the main_channel is larger than it. It is not necessary
since we compare those 2 values each time we set the initial bit rate
for a stream.
2013-05-09 17:05:55 -04:00
Yonit Halperin
313e2622d9 reds: fix memory leak when core->base.minor_version < 3 2013-05-08 11:26:57 -04:00
Yonit Halperin
5fb3d2557e reds: move handle_channel_event logic from main_dispatcher to reds
main_dispactcher role is to pass events to the main thread.
The logic that handles the event better not be inside main_dispatcher.
2013-05-08 11:26:57 -04:00
Yonit Halperin
20cc956764 red_worker: fail handle_migrate_data instead of aborting when there is an error during restoration of surfaces 2013-05-08 11:26:57 -04:00
Yonit Halperin
b82351f711 red_channel: notify and shutdown a channel client when its handle_migrate_data fails 2013-05-08 11:26:50 -04:00
Yonit Halperin
dbb99a6517 red_channel: add spice_channel_client_error
spice_channel_client_error prints warning and shutdowns the
channel_client that hit the error.
This macro is useful for errors that are specific for one session
and that are unrecoverable only with respect to this session.
Prefer disconnecting a client over aborting when possible.
2013-05-08 11:18:44 -04:00
Yonit Halperin
f50827e527 red_worker: fix incorrect is_low_bandwidth after migrating a low bandwidth connection
rhbz#956345

After a spice session has been migrated, we don't retest the network
(user experience considerations). Instead, we obtain the is_low_bandwidth flag
from the src-server, via the migration data.
Before this patch, if we migrated from server s1 to s2 and then to s3,
and if the connection to s1 was a low bandwidth one, we erroneously
passed is_low_bandwidth=FALSE from s2 to s3.

Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
2013-05-08 09:41:04 -04:00
Yonit Halperin
0a4d29b2e1 red_worker: cleanup: add is_low_bandwidth flag to CommonChannelClient
Replace the mixed calls to display_channel_client_is_low_bandwidth
and to main_channel_client_is_low_bandwidth, with one flag in
CommonChannelClient that is set upon channel creation.
2013-05-08 09:39:52 -04:00
Yonit Halperin
dd9f882aed main_channel: add routine for checking if a network test had been conducted and completed 2013-05-08 09:39:46 -04:00
Alon Levy
52943d65e7 red_worker: remove wrong TODO
red_create_stream is called even without any client but there is no
encoding since the mjpeg encoder is now associated with StreamAgent
which is only created when we have a client.
2013-05-05 22:39:51 +03:00
Yonit Halperin
b71ccec83e red_channel: on migration target, start sending ping messages only after the client's migration has completed
The connection to the target server is established before migration
starts. However, the client reads and replies to messages from the server only after
migration completes. Thus, we better not send ping msgs from the target
before migration completes (because the observed roundtrip duration will
be bigger than the real one).
2013-05-01 13:04:15 -04:00
Yonit Halperin
df26036552 red_channel: stop sending ping messages after migration has completed
We mustn't send any msg to the client, besides MSG_MIGRATE_DATA, after
we send MSG_MIGRATE.
2013-05-01 13:01:43 -04:00
Yonit Halperin
1c154ea5ec reds: fix not sending the mm-time after migration when there is no audio playback
This bug results in the client dropping all the video frames after
migration in case that (1) the hosts involved in migration have different
mm-time; and that (2) there is no audio playback.
This is relvant only for the client that was connected during the
migration.

rhbz#958276
2013-05-01 11:36:10 -04:00
Yonit Halperin
f0f8d7dd52 red_channel: fix not handling self pipe items in red_channel_client_release_item
When a client disconnects, red_channel_client_pipe_clear is called.
Releasing pipe items of type == MIGRATE||EMPTY_MSG||PING
wasn't handled, and was passed to channel_cbs.release_item.
There, an error occured since the pipe items were not recognized.
2013-04-30 14:56:35 -04:00
Hans de Goede
f7f876a3cb server: Add public spice_qxl_driver_unload method
With a SPICE_DISPLAY_CAP_MONITORS_CONFIG capable client, the client needs to
know what part of the primary to use for each monitor. If the guest driver
does not support this, the server sends messages to the client for a
single monitor spanning the entire primary.

As soon as the guest calls spice_qxl_monitors_config_async once, we set
the red_worker driver_has_monitors_config flag and stop doing this.

This is a problem when the driver gets unloaded, for example after a reboot
or when switching to a text vc with usermode mode-setting under Linux.

To reproduce this start a multi-mon capable Linux guest which uses
usermode mode-setting and then once X has started switch to a text vc. Note
how the client window does not only not resize, if you try to resize it
manually you always keep blackborders since the aspect is wrong.

This patch is the spice-server side of fixing this, it adds a new
spice_qxl_driver_unload method which clears the driver_has_monitors_config
flag.

The other patch needed to fix this is in qemu, and will calls this new method
from qxl_enter_vga_mode.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2013-04-24 09:31:27 +02:00
Yonit Halperin
1013b7a5e4 red_worker: assign mm_time to vga frames 2013-04-22 16:30:55 -04:00
Yonit Halperin
473d41b9f2 red_worker: increase the interval limit for stream frames 2013-04-22 16:30:55 -04:00
Yonit Halperin
1d760551ec collect and print video stream statistics 2013-04-22 16:30:55 -04:00
Yonit Halperin
167f999992 server/red_worker: add an option to supply the bandwidth via env var
SPICE_BIT_RATE can be set for supplying red_worker the available
bandwidth (in Mbps).
2013-04-22 16:30:55 -04:00
Yonit Halperin
4c79f325e2 server/red_worker.c: use the bit rate of old streams as a start point for new streams
mjpeg_encoder modify the initial bit we supply it, according to the
client feedback. If it reaches a bit rate which is higher than the
initial one, we use the higher bit rate as the new bit rate estimation.
2013-04-22 16:30:55 -04:00
Yonit Halperin
bf9e210b21 red_worker: video streams - adjust client playback latency 2013-04-22 16:30:55 -04:00
Yonit Halperin
073aeec569 reds: support mm_time latency adjustments
When there is no audio playback, we set the mm_time in the client to be older
than the one in the server by at least the requested latency (the delta is
actually bigger, due to the network latency).
When there is an audio playback, we adjust the mm_time in the client by
adjusting the playback buffer using SPICE_MSG_PLAYBACK_LATENCY.
2013-04-22 16:30:55 -04:00
Yonit Halperin
a9087c4c8a snd_worker: support sending SPICE_MSG_PLAYBACK_LATENCY
also update spice-common submodule
2013-04-22 16:30:54 -04:00
Yonit Halperin
ba1aaef0fe dispatcher.h: fix - s/#define MAIN_DISPATCHER_H/#define DISPATCHER_H 2013-04-22 16:30:54 -04:00
Yonit Halperin
23730a6c80 red_worker: ignoring video frame drops that are not due to pipe congestion
A frame can be dropped if a new frame was added during the same
call to red_process_command (we didn't attempt to send the older
frame). Such drops are ignored.
2013-04-22 16:30:54 -04:00
Yonit Halperin
ed1654eb11 red_worker: notify mjpeg_encoder on server frame drops 2013-04-22 16:30:54 -04:00
Yonit Halperin
0df9450399 red_worker: support SPICE_MSGC_DISPLAY_STREAM_REPORT
update mjpeg_encoder with reports from the client about
the playback quality.
The patch also updates the spice-common submodule.
2013-04-22 16:30:54 -04:00
Yonit Halperin
ade45ed93a red_worker: start using mjpeg_encoder rate control capabilities
This patch only employs setting the stream parameters based on
the initial given bit-rate, the latency, and the encoding size.
Later patches will also employ mjpeg_encoder response to client reports,
and its control over frame drops.

The patch also removes old stream bit rate calculations that weren't
used.
2013-04-22 16:30:54 -04:00
Yonit Halperin
b0fb03f0ae server/red_worker: enable latency monitoring in the display channel 2013-04-22 16:30:54 -04:00
Yonit Halperin
86fbcf1ddb red_worker: stream - update periodically the input frame rate
Periodically calculate the rate of frames arriving from the guest to the
server.
2013-04-22 16:30:54 -04:00
Yonit Halperin
9a62a9a809 red_channel: monitor connection latency using MSG_PING 2013-04-22 16:30:54 -04:00
Yonit Halperin
d146ae0d92 server/red_worker: assign timer callbacks to worker_core, using spice_timer_queue
display channel - supplying timeouts interface to red_channel, in order to allow
periodic latency monitoring (see next patch).
2013-04-22 16:30:54 -04:00