Commit Graph

686 Commits

Author SHA1 Message Date
Alon Levy
910a3f8419 server/red_worker: don't typedef SpiceWatch twice
First defined in spice.h, fixes build failure with gcc 4.4.6
2012-03-20 15:39:02 +02:00
Hans de Goede
914e50814f red_worker: Check for NULL watches
If we run out of watches slots, we return NULL from watch_add, which
means that the other watch_foo functions may get called with a NULL
parameter, protect them against this.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2012-03-13 16:41:02 +01:00
Nahum Shalman
42ac95e125 server: remove superfluous check
no need to duplicate the check that the fd isn't -1
2012-03-12 22:58:49 +02:00
Nahum Shalman
198ffb92d4 server: listen on a pre-opened file descriptor
Allow applications to pre-open a file descriptor and have spice listen
on it.

Thanks to Daniel Berrange for his comments
2012-03-12 12:33:20 +01:00
Nahum Shalman
20c7323c9e server: don't fail on ENOPROTOOPT from setsockopt
If we allow listening on arbitrary sockets like unix sockets,
we can get ENOPROTOOPT errors from setsockopt calls that set TCP
specific options.  This should be allowed to happen.
2012-03-12 12:32:58 +01:00
Hans de Goede
9a41e55296 red_channel: remove pre_disconnect hook
Now that red_worker's EventListener is gone there are no more users of it.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2012-03-12 12:10:51 +01:00
Hans de Goede
a7841325b2 red_worker: Rework poll code to use the watch interface
Commit 143a1df24e changed red_worker_main
from epoll to poll. But epoll has edge triggered semantics (when requested
and we requested them), where as poll is always level triggered. And
red_worker was relying on the edge triggered semantics, as it was always
polling for POLLOUT, which, when edge triggered, would only cause poll
to register an event after we had blocked on a write. But after the
switch to regular poll, with its level triggered semantics, the POLLOUT
condition would almost always be true, causing red_worker_main to not
block on the poll and burn CPU as fast as it can as soon as a client was
connected.

Luckily we already have a mechanism to switch from polling for read only
to polling for read+write and back again in the form of watches. So this
patch changes the red_worker dummy watch implementation into a proper watch
implementation, and drops the entire EventListener concept since that then is
no longer needed.

This fixes spice-server using 400% CPU on my quad core machine as soon as
a client was connected to a multi head vm, and as an added bonus is a nice
cleanup IMHO.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2012-03-12 12:10:51 +01:00
Hans de Goede
b023f85ebd red_channel: Use the channel core to remove the stream watch on disconnect
We allow channels to have different core implementations, but we were
relying on reds_stream_free to remove the stream watch on disconnect,
and reds_stream_free always uses the qemu core implementation.

So far we were getting away with this since all the alternative core
implementations always return NULL from watch_add.

But:
1) The code before this patch clearly was not correct, since it was matching
   a channel-core watch_add with a qemu-core watch_remove
2) I plan to move red_worker over to actually using an alternative watch
   implementation at which point this becomes a real problem

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2012-03-12 12:10:22 +01:00
Hans de Goede
63e1514ccb red_worker: Remove ref counting from the EventListener struct
The red_worker EventListener struct is either embedded in one of:
1) DisplayChannelClient
2) CursorChannelClient
3) RedWorker

And as such gets destroyed when these get destroyed, in case 1 & 2 through
a call to red_channel_client_destroy().

So free-ing it when the ref-count becomes 0 is wrong, for cases:
1) and 2) this will lead to a double free;
3) this will lead to passing memory to free which was not returned by malloc.

This is not causing any issues as the ref-count never gets decremented, other
then in red_worker_main where it gets incremented before it gets decremented,
so it never becomes 0.

So we might just as well completely remove it.

Notes:
1) This is mainly a preparation patch for fixing issues introduced by
   the move from epoll to poll
2) Since removing the ref-counting removes the one code path where listeners
   would get set to NULL, this patch moves the setting of NULL to
   pre_disconnect, where it should have been done in the first place since
   red_client_destroy calls red_channel_client_disconnect
   (through the dispatcher) followed by red_channel_client_destroy, so
   after pre_disconnect the listener may be gone.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2012-03-10 13:56:29 +01:00
Hans de Goede
f24203e122 Ensure all members of ChannelCbs and ClientCbs are either assigned or NULL
While git-bisecting another issue I ended up hitting and not recognizing
the bug fixed by commit 7a079b452b.

While fixing this (again) I noticed that (even after the fix) not all
users of ChannelCbs first zero it. So this patch ensures that all users of
ChannelCbs first zero it, and does the same for ClientCbs while at it.

Since before this patch there were multiple zero-ing styles, some using
memset and other using a zero initializer this patch also unifies all
the zero-ing to use a NULL initializer for the first element.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2012-03-10 11:51:54 +01:00
Alon Levy
1029e7fd4d server/red_worker: fix use after free for listeners
This fixes a core dumped observed once by repeated migration. So far 100
migrations and no recurrence.

Core was generated by `/home/alon/spice/upstream/bin/qemu-system-x86_64 --enable-kvm -qmp unix:/tmp/mi'.
Program terminated with signal 11, Segmentation fault.
11197	                if (evt_listener && evt_listener->refs > 1) {
Missing separate debuginfos, use: debuginfo-install bluez-libs-4.98-3.fc17.x86_64 brlapi-0.5.6-4.fc17.x86_64 bzip2-libs-1.0.6-4.fc17.x86_64 cryptopp-5.6.1-6.fc17.x86_64 keyutils-libs-1.5.5-2.fc17.x86_64 libssh2-1.4.0-1.fc17.x86_64 nss-softokn-freebl-3.13.1-20.fc17.x86_64 xen-libs-4.1.2-11.fc17.x86_64 xz-libs-5.1.1-2alpha.fc17.x86_64
(gdb) bt
(gdb) l
11192	        for (i = 0; i < MAX_EVENT_SOURCES; i++) {
11193	            struct pollfd *pfd = worker.poll_fds + i;
11194	            if (pfd->revents) {
11195	                EventListener *evt_listener = worker.listeners[i];
11196
11197	                if (evt_listener && evt_listener->refs > 1) {
11198	                    evt_listener->action(evt_listener, pfd);
11199	                    if (--evt_listener->refs) {
11200	                        continue;
11201	                    }
(gdb) p evt_listener
$1 = (EventListener *) 0x7f15a9a5d1e0
(gdb) p *evt_listener
Cannot access memory at address 0x7f15a9a5d1e0
(gdb) p i
$2 = 2
(gdb) p worker.listeners
$3 = {0x7f15bc832520, 0x7f15a406e1a0, 0x7f15a9a5d1e0, 0x0 <repeats 17 times>}
2012-03-06 16:45:12 +02:00
Marc-André Lureau
36d8da6283 Send name & uuid to capable clients
Add spice_server_set_name() and spice_server_set_uuid() that allows
the client to identify a Spice server (useful to associate settings
with a particular server)

The SPICE_MSG_MAIN_NAME and SPICE_MSG_MAIN_UUID messages are only sent
to capable clients, announcing SPICE_MAIN_CAP_NAME_AND_UUID.
2012-03-05 18:19:07 +01:00
Christophe Fergeau
15808ea7f5 server: more logging about certificates used
This commit adds some log messages indicating which certificates
could be loaded (or not).

Fixes rhbz#787678
2012-03-05 10:14:36 +01:00
Christophe Fergeau
8f8e73986b Add log for invalid/expired tickets
Currently, when a ticket has already expired, or is invalid, there is
no qemu log to tell what went wrong. This commit adds such a log.

Fixes rhbz#787669
2012-03-05 10:14:36 +01:00
Marc-André Lureau
534b71dfaa build-sys: fix make distcheck
- Do not refer to .c files managed by another makefile (this will fail
  make distclean)
- Do not refer to files by relative path (should use $top_srcdir for ex)
- Use LDADD for object linking instead of LDFLAGS, for linker flags
2012-03-01 16:24:10 +01:00
Marc-André Lureau
22ee470d4e build-sys: cleanup server/tests/Makefile.am 2012-03-01 16:24:10 +01:00
Alon Levy
7a079b452b server: fix segfault on client disconnect
..as a result of missing initialization of newly introduced
pre_disconnect in main channel.
2012-02-26 13:34:39 +01:00
Fabiano Fidêncio
65f89aca2c Enabling cursor in server/tests
Now, cursor is being shown in all tests as a white rectangle and is
    running in the screen doing a diagonal movement. It's a very simple
    way to test cursor commands and is sufficient for our tests.
2012-02-26 13:10:25 +01:00
Dan McGee
016bc7513f Use standard IOV_MAX definition where applicable
This is provided by <limits.h> on all platforms as long as _XOPEN_SOURCE
is defined. On Linux, this is 1024, on Solaris, this is 16, and on any
other platform, we now respect the value supported by the OS.

Signed-off-by: Dan McGee <dpmcgee@gmail.com>
2012-02-21 10:20:47 +02:00
Dan McGee
bdfd6c234b Respect IOV_MAX if defined
Solaris has a pitiful maximum writev vector size of only 16, so the ping
request at initial startup destroyed this call and broke things
immediately. Reimplement stream_writev_cb() to respect IOV_MAX and break
the writev() calls into chunks as necessary. Care was taken to return
the correct values as necessary so the EAGAIN handling logic can
determine where to resume the writev call the next time around.

Signed-off-by: Dan McGee <dpmcgee@gmail.com>
2012-02-21 10:20:46 +02:00
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
dfbac622bf Use memcpy call in red_channel_create
Rather than assign the callbacks one-by-one, we can just memcpy the
struct into the one we have allocated in our RedChannel object, which is
much more efficient, not to mention future-proof when more callbacks are
added.

Signed-off-by: Dan McGee <dpmcgee@gmail.com>
2012-02-21 10:20:45 +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
0e3ff74b84 Add configure-time check for -Wl, --version-script option
This is supported by the GNU linker, but not the Solaris linker, which
is used as the default on that platform even when compiling with GCC.
Omit passing the option to the linker on platforms that do not support
it.

Signed-off-by: Dan McGee <dpmcgee@gmail.com>
2012-02-21 10:20:44 +02:00
Hans de Goede
f3f8ebe91b server/spicevmc: Don't destroy the rcc twice
spicevmc calls red_channel_client_destroy() on the rcc when it disconnects
since we don't want to delay the destroy until the session gets closed as
spicevmc channels can be opened, closed and opened again during a single
session.

This causes red_channel_client_destroy() to get called twice, triggering
an assert, when a connected channel gets destroyed.

This was fixed with commit ffc4de01e6 for
the case where: a spicevmc channel was open on client disconnected, and
the main channel disconnect gets handled first.

But the channel can also be destroyed when the chardev gets unregistered
with the spice-server. This path still triggers the assert.

This patch fixes this by adding a destroying flag to the rcc struct, and
also moves the previous fix over to the same, more clean, method of
detecting this special case.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2012-02-20 16:32:31 +01:00
Alon Levy
7e3fb815cc server/tests/basic_event_loop: print something on channel_event 2012-02-15 15:09:13 +02:00
Alon Levy
5ec8515508 server, separate SpiceChannelEventInfo from RedStream
fixes rhbz 790749 use after free of SpiceChannelEventInfo.

The lifetime of the SpiceChannelEventInfo was that of RedsStream, but it
is used by main_dispatcher_handle_channel_event after the RedsStream is
freed for the cursor and display channels. Making SCEI allocation be at
RedsStream allocation, and deallocation after the DESTROY event is
processed by core->channel_event, fixes use after free.
2012-02-15 15:04:04 +02:00
Dan McGee
3f303d6014 Remove all usages of bzero()
As recommended by modern C practice, we should just be using memset().

Signed-off-by: Dan McGee <dpmcgee@gmail.com>
2012-02-14 18:19:43 +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
Alon Levy
e4a92b177a server/tests: use getopt_long 2012-02-14 17:30:50 +02:00
Fabiano Fidêncio
33bd5d2797 Adding image to be used as "correct" in regression tests 2012-02-14 14:53:47 +02:00
Fabiano Fidêncio
1e8e2f9ee0 Adding support to automated tests
As suggested by Alon, a simple automated test to try to find
    regressions in Spice code.
    To use this, compile Spice with --enable-automated-tests and
    run test_display_streaming passing --automated-tests as parameter.
2012-02-14 14:53:44 +02:00
Dan McGee
aebe837d3a Add casts for compatibility purposes
Some non-Linux platforms return a (caddr_t *) result for the return
value of mmap(), which is very unfortunate. Add a (void *) cast to
explicitly avoid the warning when compiling with -Werror.

For the IO vector related stuff, signed vs. unsigned comes into play so
adding a (void *) cast here is technically correct for all platforms.

Signed-off-by: Dan McGee <dpmcgee@gmail.com>
2012-02-14 10:44:49 +02:00
Yonit Halperin
5868c99da6 server: support IPV6 addresses in channel events sent to qemu
RHBZ #788444

CC: Gerd Hoffmann <kraxel@redhat.com>

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Yonit Halperin <yhalperi@redhat.com>
2012-02-12 13:15:18 +02:00
Hans de Goede
8817549795 Release 0.10.1 2012-01-23 15:58:13 +01:00
Alon Levy
459a4dba56 server/red_channel: red_peer_handle_incoming: comment on null check
Signed-off-by: Alon Levy <alevy@redhat.com>
2012-01-23 12:58:30 +02:00
Alon Levy
51d7598a2e server/tests/test_empty_success: fix warning on bzero
Signed-off-by: Alon Levy <alevy@redhat.com>
2012-01-23 12:41:56 +02:00
Nahum Shalman
781706ea0d server: don't complain if setsockopt(SO_PRIORITY) call fails
dc7855967f did this for the TCP_NODELAY and IP_TOS calls; we should do
it for priority as well if necessary.

We also #ifdef the setting of the low-level socket priority based on
whether we have a definition of SO_PRIORITY available. This option is
not available on Illumos/Solaris platforms; however, since we set IP_TOS
anyway it is not a big deal to omit it here.
2012-01-23 12:28:58 +02:00
Dan McGee
89cc196a1b server/inputs_channel: don't set O_ASYNC option on socket
output to send a SIGIO signal to the running program. However, we don't
handle this signal anywhere in the code, so setting the option is
unnecessary.

Signed-off-by: Dan McGee <dpmcgee@gmail.com>
2012-01-23 12:28:58 +02:00
Dan McGee
b0b19f4b25 Update .gitignore with a few more generated files
Signed-off-by: Dan McGee <dpmcgee@gmail.com>
2012-01-23 12:28:58 +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
Dan McGee
046b88ec64 Fix line length errors in main_channel
These are all existing errors; fix them so they don't block future
commits in this file unnecessarily.

    error (1): length @ server/main_channel.c +369
    error (2): length @ server/main_channel.c +444
    error (3): length @ server/main_channel.c +764
    error (4): length @ server/main_channel.c +932
    error (5): length @ server/main_channel.c +1044

Signed-off-by: Dan McGee <dpmcgee@gmail.com>
2012-01-23 12:28:57 +02:00
Alon Levy
88f68f5329 server/red_channel: avoid segfault if stream == NULL 2012-01-22 15:13:32 +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
7427b23d84 Add missing includes of config.h
Not all files were including config.h
2012-01-13 18:11:59 +02:00
Daniel P. Berrange
d46bc77278 Remove bogus include of strings.h
The tests include strings.h but don't need any of its functions
2012-01-13 18:11:59 +02:00
Daniel P. Berrange
02d56750bd Remove trailing blank lines
Remove any blank lines at the end of all source files
2012-01-13 18:11:59 +02:00
Daniel P. Berrange
8ab7c4535a Remove 'the the' typos 2012-01-13 18:11:59 +02:00