Commit Graph

411 Commits

Author SHA1 Message Date
Christophe Fergeau
e270edcbfd Validate surface bounding box before using it
It's possible for a buggy guest driver to pass invalid bounding box
dimensions in QXL commands, which would then cause spice-server to
segfault. This patch checks the size of the bounding box of the QXL
command right after it has been parsed.

This fixes rhbz#1135372
2014-09-18 14:06:55 +02:00
Christophe Fergeau
2cc42d9358 Fix 'abberiviations' typo in comment 2014-09-18 14:06:55 +02:00
Marc-André Lureau
1898f3949c Fix crash when clearing surface memory
The beginning of the surface data needs to be computed correctly if the
stride is negative, otherwise, it should point already to the beginning
of the surface data. This bug seems to exists since 4a208b (0.5.2)

https://bugzilla.redhat.com/show_bug.cgi?id=1029646
2014-08-07 11:38:02 +02:00
Wang Qiang
e7db94d833 Fix make failed when uncommented COMPRESS_STAT in red_worker.c
https://bugs.freedesktop.org/show_bug.cgi?id=79246
As a developer, I maybe want to see the detail compress stat of spice, like this:
Method   	  count  	orig_size(MB)	enc_size(MB)	enc_time(s)
QUIC     	     846	       948.02	      147.22	        7.51
GLZ      	    2895	       594.90	       26.60	        1.33
ZLIB GLZ 	       0	         0.00	        0.00	        0.00
LZ       	       1	         3.15	        0.01	        0.00
JPEG     	       0	         0.00	        0.00	        0.00
JPEG-RGBA	       0	         0.00	        0.00	        0.00
----------------------------------------------------------------------------
Total    	    3742	      1546.07	      173.83	        8.84

But when I uncommented the COMPRESS_STAT and COMPRESS_DEBUG in red_worker.c and make.
I got some error(in Bugzilla). This error because of some simple syntax errors.
Commit this patch to fix this issue.

Signed-off-by: Wang Qiang <wangqiang.hunan@gmail.com>
2014-05-26 18:51:36 +02:00
소병철
3cb746329e Use PRI macros in printf to keep compatibility between 32/64bit system
gcc's some integer type definitions are different between 32/64bit system.
This causes platform dependency problem with printf function. However,
we can avoid this problem by using PRI macros that supports platform
independent printf.
2014-05-15 14:45:58 +02:00
Christophe Fergeau
8b347a641c Add reds_stream.[ch]
Gather common RedsStream code there rather than having it
in reds.c
2014-01-20 12:15:41 +01:00
Christophe Fergeau
df96538e1f Fix 'recive' typo throughout the code base
'receive' was mispelt 'recive' in multiple places.
2013-10-08 19:07:42 +02:00
Christophe Fergeau
394fd0e6b7 Namespace RECEIVE_BUF_SIZE 2013-10-08 19:07:41 +02:00
Marc-André Lureau
b18d867b31 server: handle red_get_surface_cmd() error explicitely
Don't ignore red_get_surface_cmd() error, and explicitely interrupt and
free cmd before processing.
2013-10-07 16:33:21 +02:00
Marc-André Lureau
1f12fa72cc server: plug some leaks on error
Plug what looks like memory leaks, that could be potentially be
triggered by a misbehaving guest.
2013-10-07 16:33:21 +02:00
Marc-André Lureau
9a485b64ea server: remove unused fill_rects_clip
Unused since 62d0c076eb.
2013-09-30 13:58:47 +02:00
Yonit Halperin
90a4761249 red_worker: disconnect the channel instead of shutdown in case of a blocking method failure
rhbz#1004443

The methods that trigger waitings on the client pipe require that
the waiting will succeed in order to continue, or otherwise, that
all the living pipe items will be released (e.g., when
we must destroy a surface, we need that all its related pipe items will
be released). Shutdown of the socket will eventually trigger
red_channel_client_disconnect (*), which will empty the pipe. However,
if the blocking method failed, we need to empty the pipe synchronously.
It is not safe(**) to call red_channel_client_disconnect from ChannelCbs
, but all the blocking calls in red_worker are done from callbacks that
are triggered from the device.
To summarize, calling red_channel_client_disconnect instead of calling
red_channel_client_shutdown will immediately release all the pipe items that are
held by the channel client (by calling red_channel_client_pipe_clear).
If red_clear_surface_drawables_from_pipe timeouts,
red_channel_client_disconnect will make sure that the surface we wish to
release is not referenced by any pipe-item.

(*) After a shutdown of a socket, we expect that later, when
red_peer_handle_incoming is called, it will encounter a socket
error and will call the channel's on_error callback which calls
red_channel_client_disconnect.

(**) I believe it was not safe before commit 2d2121a170 (before adding ref
count to ChannelClient). However, I think it might still be unsafe, because
red_channel_client_disconnect sets rcc->stream to NULL, and rcc->stream
may be referred later inside a red_channel_client method unsafely. So instead
of checking if (stream != NULL) after calling callbacks, we try to avoid
calling red_channel_client_disconnect from callbacks.
2013-09-26 13:58:43 -04:00
Yonit Halperin
bcf9e64f13 red_channel: cleanup of red_channel_client blocking methods
(1) receive timeout as a parameter.
(2) add a return value and pass the handling
    of failures to the calling routine.
2013-09-26 10:48:40 -04:00
Yonit Halperin
6c2ff9864d red_worker: cleanup red_clear_surface_drawables_from_pipes
(1) merge 'force' and 'wait_for_outgoing_item' to one parameter.
    'wait_for_outgoing_item' is a derivative of 'force'.
(2) move the call to red_wait_outgoing_item to red_clear_surface_drawables_from_pipe
2013-09-26 10:48:40 -04:00
Yonit Halperin
d0a1346fda red_worker: fix call to dump_bitmap (too many args) 2013-08-22 16:12:07 -04:00
Alon Levy
ee382109a6 server: split spice_image_cache from red_worker 2013-08-14 12:08:04 +03:00
Alon Levy
1bbce9ba05 server/red_worker: s/image_cache_eaging/image_cache_aging/ 2013-08-14 12:08:04 +03:00
Alon Levy
7241cc9544 server: move surface_format_to_image_type to spice_bitmap_utils 2013-08-14 12:08:04 +03:00
Alon Levy
9b8ff04284 server: s/red_wait_all_sent/red_channel_wait_all_sent/ 2013-08-14 12:08:04 +03:00
Alon Levy
bc50ff0767 server: move three functions to red_channel
Three blocking functions, one was split to leave the display channel
specific referencing of the DrawablePipeItem being sent inside
red_worker, but the rest (most) of the timeout logic was moved to
red_channel, including the associated constants.

Moved functions:
red_channel_client_wait_pipe_item_sent
red_wait_outgoing_item
red_wait_all_sent

Introduces red_time.h & red_time.c for a small helper function dealing
with time.h
2013-08-14 12:08:04 +03:00
Alon Levy
fe38ddf724 server: move bit set/clear utilities out of red_worker.h 2013-08-14 12:08:04 +03:00
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
Alon Levy
51511a51cf server/red_worker.c: remove unused pipe_item_remove 2013-07-24 14:56:54 +03: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
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
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
Alon Levy
3ace9a3333 server/red_worker: simplify monitors_config update 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
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
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
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
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