Commit Graph

592 Commits

Author SHA1 Message Date
Christophe Fergeau
41174221fb server: init all fields on SpiceMsgDisplayStreamCreate
red_display_marshall_stream_start initializes a
SpiceMsgDisplayStreamCreate structure before marshalling it and
sending it on the wire. However, it never fills
SpiceMsgDisplayStreamCreate::stamp which then causes a complaint
from valgrind. This patch sets this value to 0, it's not used
by the client so the value shouldn't matter.
2011-09-01 03:57:35 +02:00
Christophe Fergeau
a26f5714e4 fix valgrind warning in test_display__stream
create_test_primary_surface::test_display_base.c creates a
QXLDevSurfaceCreate structure and initialize it, but doesn't set
the position field. Moreover, this structure has 4 bytes of padding
to the end (as shown by pahole from dwarves), so initialize the whole
structure to 0 before using it.
2011-09-01 03:57:35 +02:00
Hans de Goede
731c44d752 fix more inverted memset parameters
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2011-08-25 14:55:39 +02:00
Christophe Fergeau
8c9404374a fix leak in do_jpeg_encode
Issue found by the Coverity scanner.

HDG: Fixup don't free RGB24_line if it was not allocated by do_jpeg_encode

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2011-08-25 14:48:01 +02:00
Christophe Fergeau
2abd83c203 fix inverted memset parameters
Issue found by the Coverity scanner.
2011-08-25 14:37:08 +02:00
Hans de Goede
c030382abb Rename usbredir channel code to spicevmc
While discussing various things with Alon in Vancouver, it came up that
having a channel which simply passes through data coming out of a qemu
chardev frontend unmodified, like the usbredir channel does, can be used
for a lot of other cases too. To facilitate this the usbredir channel code
will be turned into a generic spicevmc channel, which is just a passthrough
to the client, from the spicevmc chardev.

This patch renames usbredir.c to spicevmc.c and changes the prefix of all
functions / structs to match. This should make clear that the code is not
usbredir specific.

Some examples of why having a generic spicevmc pass through is good:
1) We could add a monitor channel, allowing access to the qemu monitor from
the spice client, since the monitor is a chardev frontend we could re-use
the generic spicevmc channel server code, so all that is needed to add this
(server side) would be reserving a new channel id for this.

2) We could allow users to come up with new channels of their own, without
requiring qemu or server modification. The idea is to allow doing something
like this on the qemu startup cmdline:
-chardev spicevmc,name=generic,channelid=128

To ensure these new "generic" channels cannot conflict with newly added
official types, they must start at the SPICE_CHANNEL_USER_DEFINED_START value
(128).

These new user defined channels could then either be used with a special
modified client, with client plugins (if we add support for those), or
by exporting them on the client side for use by an external ap, see below.

3) We could also add support to the client to make user-defined channels
end in a unix socket / pipe, allowing handling of the data by an external app,
we could for example have a new spice client cmdline argument like this:
--custom-channel unixsocket=/tmp/mysocket,channelid=128

This would allow for something like:
$random app on guest -> virtio-serial -> spicevmc chardev ->
 -> spicevmc channel -> unix socket -> $random app on client

4) On hind sight this could also have been used for the smartcard stuff,
with a 1 channel / reader model, rather then the current multiplexing code
where we've our own multiplexing protocol wrapper over the libcacard
smartcard protocol.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2011-08-25 14:04:27 +02:00
Hans de Goede
073cf20ac5 usbredir: Merge UsbRedirState and UsbRedirChannel
Now that the Channel struct is gone and the RedChannel has the same lifetime
as the chardev interface there is no need to have these 2 separate.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2011-08-25 14:04:27 +02:00
Hans de Goede
22a6eef60d usbredir: Fix crash caused by MC changes
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2011-08-25 14:04:27 +02:00
Hans de Goede
e1570ce519 usbredir: Ensure that our msg_rcv_buf is not used re-entrantly
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2011-08-25 14:04:27 +02:00
Hans de Goede
e9d6e86fc8 red_channel: Fix msg buf memleak on parser error
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2011-08-25 14:04:27 +02:00
Alon Levy
51ac99dbf4 server: add tester and todo for multiple client support 2011-08-23 19:18:23 +03:00
Alon Levy
0b169b7014 server/snd_worker.c: add reference counting to SndChannel
Fixes a valgrind discovered possible bug in spice-server - valgrind on
test_playback saw it, didn't see it happen with qemu.

The problem is that the frames buffers returned by spice_server_playback_get_buffer
are part of the malloc'ed SndChannel, whose lifetime is smaller then that of SndWorker.
As a result a pointer to a previously returned spice_server_playback_get_buffer could
remain and be used after SndChannel has been freed because the client disconnected.
2011-08-23 18:30:26 +03:00
Alon Levy
1078dc04ed server/reds: reds_client_disconnect: remove wrong check for reds_main_channel_connected
The "channel->disconnecting" parameter already protects against recursion.

Removed fixed TODOs.
2011-08-23 18:30:06 +03:00
Alon Levy
f15cac7d7d server/reds: fix reds_main_channel_connected
instead of checking just for reds->main_channel check that there is at least
one client as well.
2011-08-23 18:29:45 +03:00
Alon Levy
0410cccde3 server: add public spice_server_get_num_clients 2011-08-23 18:29:21 +03:00
Alon Levy
9255515c15 server/snd_worker.c: add red_channel_client_destroy_dummy 2011-08-23 18:28:59 +03:00
Alon Levy
439993d788 server/red_channel: release channel allocated message buffer
handler->cb->release_msg_buf was not being called except in the error path,
causing a memory leak.
2011-08-23 18:28:39 +03:00
Alon Levy
6ef8d1e844 server/main_channel: reduce verbose agent data command
by using the new SPICE_DEBUG_LEVEL.
2011-08-23 18:28:20 +03:00
Yonit Halperin
16ed3f9f25 drawables count for debug 2011-08-23 18:27:53 +03:00
Yonit Halperin
f84dfeb0aa server: registering RedChannel in reds, instead of Channel
Merging the functionality of reds::channel, into RedChannel.
In addition, cleanup and fix disconnection code: before this patch,
red_dispatcher_disconnect_display_client
could have been called from the red_worker thread
(and it must be called only from the io thread).

RedChannel holds only connected channel clients. RedClient holds all the
channel clients that were created till it is destroyed
(and then it destroys them as well).

Note: snd_channel still doesn't use red_channel, however it
creates dummy channel and channel clients, in order to register itself
in reds.

server/red_channel.c: a channel is connected if it holds at least one channel client

Previously I changed RedChannel to hold only connected channel clients and
RedClient, to hold all the channel clients as long as it is not destroyed.

usbredir: multichannel has not been tested, it just compiles.
2011-08-23 18:27:46 +03:00
Yonit Halperin
1db936e64c server/red_channel.c inroducing client_cbs
client_cbs are supposed to be called from client context (reds). This patch will be used
in future patches for relacing reds::Channel with RedChannel in order to eliminate redundancy.
2011-08-23 18:23:48 +03:00
Yonit Halperin
812d01c060 server/red_channel.c: pack all channel callbacks to ChannelCbs 2011-08-23 18:23:46 +03:00
Alon Levy
67671b2609 server/red_worker: add ref counting to RedDrawable
introduces ref_red_drawable and put_red_drawable (rename from free_red_drawable)

RedDrawable is already references by Drawable and RedGlzDrawable, with
a hack to NULL the drawable field in RedGlzDrawable to indicate RedGlzDrawable
is the last reference holder. Using an explicit reference count instead.
2011-08-23 18:07:10 +03:00
Alon Levy
74ce23a0e8 server/red_worker: add stream_count (for debug purposes) 2011-08-23 18:06:47 +03:00
Alon Levy
11f2ad60ea server/red_worker: validate_surface: print paniced surface_id 2011-08-23 18:06:25 +03:00
Alon Levy
d0e740eeaa server/red_worker: no panic on double destroy primary 2011-08-23 18:06:03 +03:00
Alon Levy
c820b252c1 server/red_worker: DEBUG_CURSORS
Add cursor allocation debugging code that is turned off as long as
DEBUG_CURSORS is not defined.
2011-08-23 18:05:42 +03:00
Alon Levy
f4d07791cc server/red_worker: on_new_display_channel_client: push ack, cleanup
small cleanup patch, only functional change is sending a set ack message.
2011-08-23 18:05:19 +03:00
Alon Levy
969ab70413 server/red_worker: add cursor_channel_client_disconnect
makes RED_WORKER_MESSAGE_CURSOR_DISCONNECT_CLIENT disconnect only a
single client.
2011-08-23 18:04:56 +03:00
Alon Levy
c78e951bff server/red_worker: remove forced disconnect on connect 2011-08-23 18:04:33 +03:00
Yonit Halperin
bed8c9d4f6 server/red_worker.c: fix CursorPipeItem leak
CursorPipeItems and their corresponding cursor_item were not
freed when they were removed from the pipe without sending them.
In addition cursor_channel_hold_pipe_item used wrong conversion
to (CursorItem*) for a (CursorPipeItem*).
2011-08-23 18:04:10 +03:00
Alon Levy
52bff67935 server/red_worker: split cursor pipe item from cursor item
Required to support multiple clients.
Also changes somewhat the way we produce PIPE_ITEM_TYPE_LOCAL_CURSOR. Btw,
I haven't managed to see when we actually produce such an item during my
tests.

Previously we had a single pipe item per CursorItem, this is impossible
with two pipes, which happens when we have two clients.
2011-08-23 18:03:47 +03:00
Alon Levy
24d8340b71 server/red_worker: whitespace fixes 2011-08-23 18:03:24 +03:00
Alon Levy
5117efcff7 server/reds: add RedsState.allow_multiple_clients
Currently set by environment variable SPICE_DEBUG_ALLOW_MC (any value means
to allow multiple connections). Later will be set by spice api from qemu.
2011-08-23 18:03:02 +03:00
Alon Levy
4db9f1d1a9 server/red_channel: introduce client ring in RedChannel
Also adds Drawable pipes and glz rings.

main_channel and red_worker had several locations that still accessed rcc
directly, so they had to be touched too, but the changes are minimal.

Most changes are in red_channel: drop the single client reference in RedChannel
and add a ring of channels.

Things missing / not done right in red_worker:
 * StreamAgents are in DCC - right/wrong?
 * GlzDict is multiplied - multiple compressions.

We still are missing:
 * remove the disconnect calls on new connections
2011-08-23 18:02:38 +03:00
Alon Levy
6a1d657373 server/red_channel: add pipe_size helpers 2011-08-23 18:02:14 +03:00
Alon Levy
9c192980e8 server/red_worker: remove more direct access to RedChannelClient.rcc 2011-08-23 18:01:51 +03:00
Yonit Halperin
d42575feab server/red_worker.c: make dictionary and cache different per client
There is no inter-client shared dictionary and cache yet.

At this point the display channel can be used by multiple clients.

You can still crash on lack of Drawables or CursorItems due to the slower
clients pipe growing uncontrollably.
2011-08-23 18:01:28 +03:00
Alon Levy
a32e90257e server/red_worker: multiple client support - base split
This patch compiles but breaks spice.

Split both display and cursor channels to a client part and channel part.

Introduce DisplayChannelClient, CursorChannelClient, CommonChannelClient.
don't disconnect channel on client disconnect.
Move all caches to the ChannelClient's.

Remove reference counting of the channel.

No new functionality introduced.

NOTE: Introduces a crash in disconnections, a regression, resulting from
incorrect thread access, that is fixed in the patch titled:
"server: registering RedChannel in reds, instead of Channel"
2011-08-23 18:01:04 +03:00
Alon Levy
406751888e server/red_worker: cleanup 2011-08-23 18:00:41 +03:00
Alon Levy
eded227f4c server/smartcard: support multiple clients
each client supplying a smartcard channel gets it's own smartcard. If
there are not enough smartcards provided by the server (read: qemu)
then it will be as though there are none.

currently disabled - later patches that enable smartcard don't make
this channel available to any but the first client.
2011-08-23 18:00:19 +03:00
Alon Levy
9aa62c4baa server/red_tunnel_worker: trivial multi client support
s/TunnelChannel/TunnelChannelClient/

That's about it.  this is probably the wrong way to do it. Not tested
at all. What do we want, a separate interface per client? same interface
for all clients? probably the later. This doesn't do that. Not tested,
so probably doesn't even work.

changes red_channel_pipe_item_is_linked to red_channel_client_pipe_item_is_linked,
since tunnel channel is the only user, must be done in patch to not break compilation.
2011-08-23 17:59:55 +03:00
Alon Levy
82524cec13 server/inputs_channel: support multiple clients
from server events are broadcast - leds change. The rest is client
to server, so it is just passed on.
2011-08-23 17:59:34 +03:00
Alon Levy
9cece23ba3 server/main_channel: support multiple clients
The main channel deals with connecting new clients, announcing mouse mode
changes, and the agent channel. The implementation is currently done without
any changes to the protocol, so everything has to be either broadcast or
to a specific client.

 channels list - specific client
 mouse mode - broadcast
 agent - broadcast
 notify - broadcast (should have two modes, and use the appropriate)

Notable TODOs:
 * migration testing
 * agent tokens are wrongly sent (or did I fix that? check)
2011-08-23 17:59:09 +03:00
Alon Levy
0f0bdb190b server/red_channel: introduce pipes functions
Introduce functions to add (via producer method) the same item to multiple
pipes, all for the same channel.

Note: Right now there is only a single channel, but the next patches will do the
per-channel breakdown to channel and channel_client before actually introducing
a ring in RedChannel, this makes it easier to make smaller changes - the
channel->rcc link will exist until removed in the ring introducing patch.
2011-08-23 17:58:46 +03:00
Alon Levy
03cf66383c server/red_channel: ignore error if already shutdown
on red_channel_peer_on_incoming_error, if we are already shutdown, do not
call the channel's error handler. Since the channel has been shutdown, we
assume this is a second or later error, and handling has already occured.
2011-08-23 17:58:24 +03:00
Alon Levy
4e304ff40f server/main_channel: move connection_id from reds
Expose additional api to find a client given a connection_id. The connection_id
is first set when the first channel connects, which is the main channel.
It could also be kept in the RedClient instead, not sure.

TODO:
 multiple todo's added for multiclient handling. I don't remember why
 I wrote them exactly, and besides if I did any migration tests. So: TODO.
2011-08-23 17:58:01 +03:00
Alon Levy
d65b08e12d server/main_channel: move ping here from reds.
cleanup only. Note that the ping function is half used since the opt parameter
stopped being called with anything but NULL, should be returned at some point,
specifically when we drop the 250kbyte ping on start and do a continuous check
for latency and bandwidth.

See:
 81945d897 - server: add new vd interface QTerm2Interface, Yaniv Kamay
  introducing the usage of ping with a non NULL opt
 3f7ea8e7a - zap qterm interfaces, Gerd Hoffman
  removing it
2011-08-23 17:57:37 +03:00
Alon Levy
5bcdf37997 server/main_channel: move latency and bitrate to channel client
They were globals before. This introduces api for other channels
to query the low bandwidth status. The queries themselves are still done
from the wrong context (channel and not channel client) but that's because
the decoupling of channel and channel client will be done in the following
patches.

Note that snd_worker.c got two copied function declarations that belong to
main_channel.h but can't be easily dragged into snd_worker.c since it still
uses it's own RedChannel struct.
2011-08-23 17:57:13 +03:00
Alon Levy
614df17193 server/reds: add concept of secondary channels
Secondary channels are those that don't support multiple clients. The
support added in this patch just doesn't let the second or more connected
client receive the unsupported channels in the channels list sent by the
server to the client. This doesn't handle the situation where:

client A connects (gets all channels)
client B connects (gets supported multiple client channels)
client A disconnects (Suboptimal 1: B doesn't get new channels at this point)
client C connects (Suboptimal 2: C doesn't get the full list of channels, but
the partial one)

Specifically the channels that only support a single client are:
 sound (both playback and record channels)
 smartcard
 tunnel
2011-08-23 17:56:46 +03:00