Commit Graph

1164 Commits

Author SHA1 Message Date
Marc-André Lureau
3dcd287fcb reds-stream: add reds_stream_get_family() function 2015-01-15 18:29:36 +01:00
Marc-André Lureau
5365caeaae reds: add Unix socket support
Learn to listen on a Unix address. In this case, the connection is plain
only (non-tls).
2015-01-15 18:29:36 +01:00
Christophe Fergeau
a19867e713 inputs: Remove unneeded variable
inputs_channel_handle_parsed() is casting its void * argument to
a uint8_t * buf before recasting this 'buf' variable to different
other types. This intermediate 'buf' variable is not needed, especially
as we can then benefit from implicit casts from void * to the type we
need.
2014-12-15 12:02:24 +01:00
Christophe Fergeau
0d35c3e930 inputs: Split overlong line
Cosmetic change.
2014-12-15 12:02:24 +01:00
Christophe Fergeau
9f2145ac45 inputs: Fix key_up/key_down mismatch
When handling a KEY_UP message, the various variables were called
'key_down', and they were called 'key_up' when handling KEY_DOWN
messages. This commit makes the naming consistent.
2014-12-15 12:02:21 +01:00
Christophe Fergeau
69f3f86ff7 Remove unused SPICE_CANVAS_INTERNAL 2014-12-03 18:32:04 +01:00
Javier Celaya
b532ef0866 Add LZ4 compression support.
- Add lz4 encoder to compress an image of type LZ4 (see spice_common).
- Add code in red_worker to use LZ4 when it is enabled, and the client
  supports it through its display capability, or fallback to LZ.
- Add enable_lz4 switch in the configure script. Show LZ4 support at the
  end.
2014-12-02 19:41:17 +01:00
Marc-André Lureau
6a49d59e7e build-sys: fix out-of-tree build of tests
Fixes the following build error:
In file included from
/home/elmarco/src/spice-new/src/spice/server/tests/test_display_base.h:4:0,
                 from
                 /home/elmarco/src/spice-new/src/spice/server/tests/test_display_no_ssl.c:11:
                 /home/elmarco/src/spice-new/src/spice/server/spice.h:23:27:
                 fatal error: spice-version.h: No such file or directory
                  #include "spice-version.h"
                                             ^
2014-11-29 15:32:44 +01:00
Marc-André Lureau
238765fb7b Add explicit spice-core.h include
Several functions use core interfaces, add and explicit include.
2014-11-27 15:03:44 +01:00
Marc-André Lureau
116d84a229 Move spice_server_get_num_clients() declaration
This function is not related to migration.
2014-11-27 15:03:38 +01:00
Marc-André Lureau
ea4e9f28bf Rename mm_timer/mm_time
As suggested by Christophe on the mailing list.
2014-11-27 14:32:37 +01:00
Marc-André Lureau
c541d7e29d Remove guest side video time-stamping
The multimedia time is defined by the server side monotonic time [1],
but the drawing time-stamp is done in guest side, so it requires
synchronization between host and guest. This is expensive, when no audio
is playing, there is a ~30x/sec wakeup to update the qxl device mmtime,
and it requires marking dirty the rom region.

Instead, the video timestamping can be done more efficiently on server
side, without visible drawbacks.

[1] a better timestamp could be the audio time, since audio players are
    usually sync with audio time)

Related to:
https://bugzilla.redhat.com/show_bug.cgi?id=912763
2014-11-27 14:27:41 +01:00
Marc-André Lureau
ab12cf414c build-sys: generate spice-version.h
Editing the hexadecimal value of spice-version and keeping it in sync
with actual release is a bit tedious. Let's generate it
automatically (although handling of bumps will need temporarily static
versions, when 0.12 -> 1.0 for example)
2014-11-27 14:27:33 +01:00
Marc-André Lureau
6f798ba1f7 Split spice.h
Make it easier to read the Spice server API.
2014-11-27 14:27:18 +01:00
Marc-André Lureau
d26604ce65 spice.h: remove redundant declarations
Those are already declared in <spice/qxl_dev.h>.
2014-11-27 12:56:42 +01:00
Marc-André Lureau
c9685014e7 Validate RedDrawable before allocating drawable
Avoid unnecessary allocation (and possibly leaking) if the RedDrawable
is not valid.

Related to: rhbz#1135372
2014-11-25 15:37:45 +01:00
Marc-André Lureau
697f3214fd chardev: remove write polling
In an effort to reduce the wakeups per second, get rid of the
"write_to_dev" timer when the implementation supports
SPICE_CHAR_DEVICE_NOTIFY_WRITABLE.

When this flag is set, the frontend instance is responsible for calling
spice_char_device_wakeup() when the device is ready to perform IO.

Related to:
https://bugzilla.redhat.com/show_bug.cgi?id=912763
2014-11-25 14:57:23 +01:00
Christophe Fergeau
1ac4dfb317 Don't set SpiceLinkReply::pub_key if client advertises SASL cap
If the client advertises the SASL cap, it means it guarantees it will be
able to use SASL if the server supports, and that it does not need a valid
SpiceLinkReply::pub_key field when using SASL.

When the client cap is set, we thus don't need to create a RSA public key
if SASL is enabled server side.

The reason for needing client guarantees about not looking at the pub_key
field is that its presence and size is hardcoded in the protocol, but in
some hardened setups (using fips mode), generating a RSA 1024 bit key as
expected is forbidden and fails. With this new capability, the server
knows the client will be able to handle SASL if needed, and can skip
the generation of the key altogether. This means that on the setups
described above, SASL authentication has to be used.
2014-11-24 17:37:17 +01:00
Christophe Fergeau
24bebaa855 Introduce red_link_info_test_capability()
This just hides a bit of pointer arithmetic away from reds_send_link_ack.
This helper will be used in the next commits.
2014-11-24 17:37:17 +01:00
Christophe Fergeau
ef44803a3a Add const to test_capability first argument
We don't modify the capabilities content, so it can be marked as const.
2014-11-24 17:37:17 +01:00
Marc-André Lureau
4639817f0e server: fix crash when restarting VM with old client
The server will reset the vdagent char device when the client does not
implement SPICE_MAIN_CAP_AGENT_CONNECTED_TOKENS. This will nullify
dev->sin and the following crash will be reached on restart:

 #0  0x00007fb05aa264a1 in spice_char_device_write_to_device (dev=dev@entry=0x7fb066ae5d30) at char_device.c:443
 #1  0x00007fb05aa27137 in spice_char_device_write_to_device (dev=0x7fb066ae5d30) at char_device.c:436
 #2  spice_char_device_start (dev=0x7fb066ae5d30) at char_device.c:798
 #3  0x00007fb05aa6a981 in spice_server_vm_start (s=<optimized out>) at reds.c:3795
 #4  0x00007fb0644b7f89 in qdev_reset_one (dev=<optimized out>, opaque=<optimized out>) at hw/core/qdev.c:241
 #5  0x00007fb0644b7918 in qbus_walk_children (bus=0x7fb06661e870, pre_devfn=0x0, pre_busfn=0x0,
     post_devfn=0x7fb0644b7f80 <qdev_reset_one>, post_busfn=0x7fb0644b6350 <qbus_reset_one>, opaque=0x0)
     at hw/core/qdev.c:422
 #6  0x00007fb0644b7848 in qdev_walk_children (dev=0x7fb0665f47a0, pre_devfn=0x0, pre_busfn=0x0,
     post_devfn=0x7fb0644b7f80 <qdev_reset_one>, post_busfn=0x7fb0644b6350 <qbus_reset_one>, opaque=0x0)
     at hw/core/qdev.c:456
 #7  0x00007fb0644b7918 in qbus_walk_children (bus=0x7fb06647cde0, pre_devfn=0x0, pre_busfn=0x0,
     post_devfn=0x7fb0644b7f80 <qdev_reset_one>, post_busfn=0x7fb0644b6350 <qbus_reset_one>, opaque=0x0)
     at hw/core/qdev.c:422
 #8  0x00007fb0644399fd in qemu_devices_reset () at vl.c:1830

After restart, qemu will reset the device instance (sin) when virtio
port is opened:

 #0  spice_char_device_state_reset_dev_instance (state=0x7fe4873876d0, sin=sin@entry=0x7fe486fb0c68)
     at char_device.c:667
 #1  0x00007fe47b277516 in attach_to_red_agent (sin=0x7fe486fb0c68) at reds.c:2838
 #2  spice_server_char_device_add_interface (sin=0x7fe486fb0c68, s=0x7fe486fb2e60) at reds.c:2962
 #3  spice_server_add_interface (s=0x7fe486fb2e60, sin=0x7fe486fb0c68) at reds.c:3104
 #4  0x00007fe484c69e57 in vmc_register_interface (scd=0x7fe486fb0c60) at spice-qemu-char.c:123
 #5  0x00007fe484ce96b4 in set_guest_connected (port=<optimized out>, guest_connected=1)
     at hw/char/virtio-console.c:89
 #6  0x00007fe484ba70ed in handle_control_message (len=8, buf=0x7fe486fbdf70, vser=0x7fe48739ae98)
     at /usr/src/debug/qemu-2.1.0/hw/char/virtio-serial-bus.c:382

Let's ignore the call to spice_char_device_{write,read}_to_device() when
dev->sin is NULL, similary to other conditions, such as dev->running.

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1145919
2014-10-17 17:38:52 +02:00
Uri Lublin
2d1c00a659 migration: Don't assert() if MIGRATE_DATA comes before attaching the agent
During seamless migration, after switching host, if a client was connected
during the migration, it will have data to send back to the new
qemu/spice-server instance. This is handled through MIGRATE_DATA messages.
SPICE char devices use such MIGRATE_DATA messages to restore their state.

However, the MIGRATE_DATA message can arrive any time after the new qemu
instance has started, this can happen before or after the SPICE char
devices have been created. In order to handle this, if the migrate data
arrives early, it's stored in reds->agent_state.mig_data, and
attach_to_red_agent() will restore the agent state as appropriate.

Unfortunately this does not work as expected, for main
channel (agent messages).
If attach_to_red_agent() is called before the MIGRATE_DATA
message reaches the server, all goes well,
but if MIGRATE_DATA reaches the server before
attach_to_red_agent() gets called, then some assert() gets
triggered in spice_char_device_state_restore():

((null):32507): Spice-ERROR **: char_device.c:937:spice_char_device_state_restore: assertion `dev->num_clients == 1 && dev->wait_for_migrate_data' failed
Thread 3 (Thread 0x7f406b543700 (LWP 32543)):
Thread 2 (Thread 0x7f40697ff700 (LWP 32586)):
Thread 1 (Thread 0x7f4079b45a40 (LWP 32507)):

When restoring state, a client must already be added to the
spice-char-device.
What happens is that a client is not being added to the char-device
when when MIGRATE_DATA arrives first, which leaves both
dev->num_clients and dev->wait_for_migrate_data value at 0.

This commit changes the logic in spice_server_char_device_add_interface(),
such that if there is migrate data pending in reds->agent_state.mig_data
but no client was added to the spice-char-device yet,
then first the client is added to the device by calling
spice_char_device_client_add(), and only then the state is restored.

=== How to Reproduce
To reproduce, add delays to the migration connection between
qmeu-kvm on the source host (SRC) and on the destination (DST).

Specifically I added a man in the middle DLY host between
migration ports from SRC to DST.

+-----+    +-----+     +-----+
| SRC |--> | DLY | --> | DST |
+-----+    +-----+     +-----+

DLY listens on port P1 (e.g. 4444) and DST listens on port
PINCOMING (e.g. 4444, from qemu-kvm '-incoming' command line option)

Precondition: make sure port P1 on DLY is accessible in iptables.
Option 1: use ssh tcp port forwarding
On DLY host run ssh:
  ssh DLY:P1:DST:PINCOMING DST
Then use the following migration command (on qemu-kvm monitor):
  client_migrate_info spice DST PSPICE
  migrate -d tcp:DLY:P1

Option 2: Use a simple proxy program that forwards
packets from SRC to DST while adding some delays.
The program runs on DLY, listens to port D1, upon
accept connects to DST:PINCOMING and forward all
packets from DLY:D1 to DST:PINCOMING.
Then use the same migrate command as in option 1:
  client_migrate_info spice DST PSPICE
  migrate -d tcp:DLY:P1

=== How to Reproduce Ends

This fixes https://bugzilla.redhat.com/show_bug.cgi?id=1035184

Based-on-a-patch-by: Christophe Fergeau <cfergeau@redhat.com>
2014-10-14 15:48:02 +03:00
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
Christophe Fergeau
30273776ed Fix indentation in red_get_opaque_ptr
This removes one extra space
2014-09-18 14:06:55 +02:00
Christophe Fergeau
504d027bb2 server/tests/Makefile.am: White-space cleanup
Make sure the \ at the end of lines are nicely aligned
2014-09-18 14:06:55 +02:00
Fabiano Fidêncio
93b4f4050c Fix -Wunused-function 2014-09-12 18:00:30 +02:00
Fabiano Fidêncio
b76e561d82 Fix -Wmissing-field-initializers 2014-09-12 18:00:30 +02:00
Fabiano Fidêncio
fb938c210a Fix -Wnonnull 2014-09-12 18:00:30 +02:00
Fabiano Fidêncio
63180f6ce3 Fix -Wformat 2014-09-12 18:00:30 +02:00
Fabiano Fidêncio
4bf5fd35c4 Fix -Wswitch 2014-09-12 18:00:30 +02:00
Fabiano Fidêncio
08b3e1d8f1 Fix -Wsign 2014-09-12 18:00:30 +02:00
Fabiano Fidêncio
79e5a52d05 Fix -Wunused-value 2014-09-12 18:00:30 +02:00
Fabiano Fidêncio
5ea7de3bcc Fix -Wunused-parameter 2014-09-12 18:00:30 +02:00
Fabiano Fidêncio
94edda2255 server: Don't dump the bitmap when the format is invalid
Caught by covscan:
spice/server/spice_bitmap_utils.c:54: var_decl: Declaring variable "n_pixel_bits" without initializer.
spice/server/spice_bitmap_utils.c:106: uninit_use: Using uninitialized value "n_pixel_bits".
2014-09-12 18:00:30 +02:00
Marc-André Lureau
5eb9967dbc clean-up: remove unused function 2014-09-08 14:49:29 +02:00
Marc-André Lureau
004744fd2f build-sys: check for spicy-screenshot 2014-09-08 14:49:29 +02:00
Marc-André Lureau
a434543eb1 reds: lookup corresponding channel id
In reds_send_link_ack(), lookup the channel with the same id as the link
message.

The bug was found during code review a while ago.

A reproducer bug was later reported:
https://bugzilla.redhat.com/show_bug.cgi?id=1058625
2014-09-08 14:48:08 +02:00
Marc-André Lureau
5972452b28 dispatcher: lower a monitor-config warning to a debug level
Some QXLInterface implementations might not have or succeed
with client_monitors_config(). Thus, lower warning to debug
level.

https://bugzilla.redhat.com/show_bug.cgi?id=1119220
2014-09-08 12:04:15 +02:00
Christophe Fergeau
288cf77f80 spice.h: Don't use 48kHz for playback/recording rates
When adding Opus support, SPICE_INTERFACE_PLAYBACK_FREQ and
SPICE_INTERFACE_RECORD_FREQ in the public header 'spice.h' were changed
from 44100 to 48000.
However, this was not really useful as these constants are not used in
spice-server, but only by users of spice-server (ie QEMU).
It turns out changing these values is actually harmful. QEMU uses these
constants in 2 situations:
1. when it's a version of QEMU with this commit, but we are compiling
   against older spice-server headers (before Opus support was added)
2. when it's a version of QEMU without commit 795ca114d35 which added
   what is needed for Opus support

When we are in the second situation, having 48000 in the public header
will actually cause issues as spice-server will know QEMU does not
support Opus, so internally spice-server will be using a 44100 rate for
audio. However, QEMU will be using SPICE_INTERFACE_.*_FREQ and think it
should use a 48000 rate, which will cause distorsions as experienced in
bug https://bugzilla.redhat.com/show_bug.cgi?id=1129961

Reverting these constants back to 44100 will fix audio in the 'new
spice-server/old QEMU' scenario, and won't cause issues either when both
support Opus as in this case these constants are not used.
2014-08-20 16:12:31 +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
Marc-André Lureau
3c25192ee9 server: don't assert on invalid client message
Some users have been reaching this error:
snd_receive: ASSERT n failed

A misbehaving client could easily hit that condition by sending too big
messages. Instead of assert(), replace with a warning. When a message
too big to fit is received, it will simply disconnect the channel.

https://bugzilla.redhat.com/show_bug.cgi?id=962187
2014-07-25 17:25:29 +02:00
Jonathon Jongsma
284cca2a5e Fix assert in mjpeg_encoder_adjust_params_to_bit_rate()
If mjpeg_encoder_reset_quality() is called with the same quality as currently
set, it will not reset last_enc_size but not reset num_recent_enc_frames,
violating some assumptions in _adjust_params_to_bit_rate(). To avoid aborting
the server, simply return early from this function.

Resolves: rhbz#1086820
2014-05-30 13:45:02 -05: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
Marc-André Lureau
8904dfc768 server: use a warning when disconnecting unresponsive client
The debug level is not visible by default, since it is an unsolicited
server behaviour, make it a warning.
2014-05-16 19:20:51 +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
91a6feb9f4 Add missing buffer (re)allocation to reds_sasl_handle_auth_steplen()
We need to make sure we have a buffer big enough to accomodate the data
sent by the coming SASL step.
2014-04-16 17:11:38 +02:00
Christophe Fergeau
27f968afd2 Call correct SASL helper in reds_handle_auth_sasl_step
sasl_handle_auth_start() was called instead of reds_sasl_handle_auth_step()
2014-04-16 17:11:38 +02:00
Christophe Fergeau
390a36ea34 Add G_GNUC_UNUSED annotations to async_read_handler args
2 of the arguments are not used, the G_GNUC_UNUSED annotation will make
this explicit.
2014-04-16 17:11:38 +02:00
Christophe Fergeau
e36c7efe81 Make struct AsyncRead/async_read_handler private
All users are now contained in reds_stream.c
2014-04-16 17:11:38 +02:00