Commit Graph

620 Commits

Author SHA1 Message Date
Yonit Halperin
fe001ca19d server: don't reset the display channel when disconnecting all its clients ,FDBZ #43977
The display channel was unnecessarily set to NULL when we disconnect all the clients
(on flush display commands timeout).
As a result, we recreated the display channel when a new client was connected.
The display channel was created with default red_channel.client_cbs, while its
correct client_cbs are the ones that are set by the red_dispatcher when it creates
the first display_channel.
This fix enforces a single creation of the display channel (per qxl), via the red_dispatcher.
2011-12-22 12:58:25 +02:00
Hans de Goede
ffc4de01e6 spicevmc: Fix assert when still connected on session disconnect (fdo#43903)
Currently when the main channel disconnects while a spicevmc channel
(such as a usbredir channel) is still connected, qemu will abort with the
following message:
ring_remove: ASSERT item->next != NULL && item->prev != NULL failed

This is caused by red_client_destroy() first calling:
rcc->channel->client_cbs.disconnect(rcc);
And then calling:
red_channel_client_destroy(rcc);

For each channel. This is fine, but the spicevmc disconnect code does a
red_channel_client_destroy(rcc) itself since as usb devices are added
/ removed, the channels carrying their traffic get connected / disconnected
and they get re-used for new devices, which won't work if the old channel is
still there when the new connection comes in.

This patch fixes the double destroy when there are still spicevmc channels
connected by not doing the red_channel_client_destroy from the spicevmc
disconnect code when not just the channel, but the entire client is
disconnecting.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2011-12-18 11:20:12 +01:00
Hans de Goede
ee315779a0 server/red_parse_qxl.h: License should be LGPLv2+ rather then GPLv2+
Also fixup the header of server/red_parse_qxl.c, which still contained
some GPL (program rather then library) text in its header.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2011-12-15 13:12:31 +01:00
Jürg Billeter
dedaa9ac39 server: Move $(Z_LIBS) from INCLUDES to LIBADD in Makefile.am
This fixes undefined references to deflate* when building tests.

Signed-off-by: Jürg Billeter <j@bitron.ch>
2011-11-28 11:05:49 +01:00
Alon Levy
2548cd713d server/mjpeg_encoder: use size_t * consistently
fix another 64 bit-ism. unsigned long != size_t in general.
2011-11-10 16:29:19 +02:00
Alon Levy
6d89b2ba4c server/main_channel: fix pointer-to-int-cast error
64 bit-ism removed.
2011-11-10 16:28:07 +02:00
Alon Levy
ebfa95cd47 server/main_channel: use PRIu64 where needed 2011-11-10 16:25:18 +02:00
Alon Levy
1b8a8b2517 server/spice-server.syms: fix 0.8 compatibility
spice_server_migrate_connect is in 0.8.3 in the released 0.8 branch,
and so should not be changed in 0.10. This doesn't break the 0.9.1
release which didn't contain this symbol at all, only 0.9.2 release
that hopefully no one actually packaged.
2011-11-08 17:10:47 +02:00
Alon Levy
8e049ce3b0 server/red_worker: reuse dispatcher
This patch reuses Dispatcher in RedDispatcher. It adds two helpers
to red_worker to keep RedWorker opaque to the outside. The dispatcher is
abused in three places that use the underlying socket directly:
 once sending a READY after red_init completes
 once for each channel creation, replying with the RedChannel instance
  for cursor and display.

FDO Bugzilla: 42463

rfc->v1:
* move callbacks to red_worker.c including registration (Yonit)
* rename dispatcher to red_dispatcher in red_worker.c and red_dispatcher.c
* add accessor red_dispatcher_get_dispatcher
* s/dispatcher_handle_recv/dispatcher_handle_recv_read/ and change sig to
  just Dispatcher *dispatcher (was the SpiceCoreInterface one)
* remove SpiceCoreInterface parameter from dispatcher_init (Yonit)
* main_dispatcher needed it for channel_event so it has it in
  struct MainDispatcher
* add dispatcher_get_recv_fd for red_worker
2011-11-08 16:23:10 +02:00
Alon Levy
ca5776f40e server/dispatcher: add dispatcher_register_async_done_callback 2011-11-08 16:22:21 +02:00
Alon Levy
fff04e867c introduce DISPATCHER_{NONE,ACK,ASYNC} 2011-11-08 14:59:51 +02:00
Alon Levy
776bdd6c95 server: introduce dispatcher
used for main_dispatcher only in this patch.

Dispatcher is meant to be used for Main<->any low frequency messages.

It's interface is meant to include the red_dispatcher usage:
 fixed size messages per message type
 some messages require an ack

Some methods are added to be used by RedDispatcher later:
 dispatcher_handle_read - to be called directly by RedDispatcher epoll
  based loop
 dispatcher_set_opaque - to be set from red_worker pthread
 dispatcher_init - allow NULL core as used by red_worker

Read and Write behavior:
 Sender: blocking write, blocking read for ack (if any).
 Reader: poll for any data, if such then blocking read for a
 message_type and following message. repeat until poll returns
 with no pending data to read.

FDO Bugzilla: 42463
2011-11-08 14:59:49 +02:00
Alon Levy
9174b67160 server/red_dispatcher: remove semicolon from DBG_ASYNC 2011-11-07 12:11:29 +02:00
Alon Levy
af77bb577d server: add prefix argument to red_printf_debug
printed before function name. No central location for prefixes.
Adding "WORKER", "ASYNC", "MAIN" since those were the current users.
2011-11-07 10:29:32 +02:00
Alon Levy
d5274eeef6 server/red_dispatcher: support concurrent asyncs
This is part of the dispatcher update, extracting the dispatcher routine
from red_dispatcher and main_dispatcher into dispatcher.

Supporting multiple async operations will make it natural to support
async monitor commands and async guest io requests that could overlap in
time.

Use a Ring for AsyncCommands.

Free Desktop Bugzilla: 42463

Related FD: 41622
2011-11-07 10:27:34 +02:00
Yonit Halperin
aefe01c02c Release 0.9.2 2011-11-02 11:30:33 +02:00
Yonit Halperin
7696657174 server: turn spice_server_migrate_start into a valid call
We will add a qemu call to spice_server_migrate_start when migration starts.
For now, it does nothing, but we may need this notification in the future.
(cherry picked from commit b821316771 branch 0.8)
2011-11-02 11:30:18 +02:00
Yonit Halperin
f683815ad5 server: handling semi-seamless migration in the target side
(1) not sending anything to a migrated client till we recieve SPICE_MSGC_MIGRATE_END
(2) start a new client migration (handle client_migrate_info) only after SPICE_MSGC_MIGRATE_END
    from the previous migration was received for this client
(3) use the correct ticket

Note: we assume the same channles are linked before and ater migration. i.e.,
      SPICE_MSGC_MAIN_ATTACH_CHANNELS is not sent from the clients.
2011-11-02 11:25:59 +02:00
Yonit Halperin
c88e927fc7 server: move the linking of channels to a separate routine 2011-11-02 11:21:58 +02:00
Yonit Halperin
e62521ca51 server: handle spice_server_migrate_end
If the migration has completed successfully:
(1) send MSG_MAIN_MIGRATE_END to the clients that are connected to the target
(2) send MSG_MAIN_SWITCH_HOST to all the other clients

If the migration failed, send MSG_MAIN_MIGRATE_CANCEL to clients that are
connected to the target.

(cherry picked from commit 4b82580fc3 branch 0.8;
 Was modified to support multiple clients, and the separation of main_channel from reds)

Conflicts:

	server/reds.c
2011-11-02 11:21:41 +02:00
Yonit Halperin
70d1161430 server,proto: tell the clients to connect to the migration target before migraton starts
(1) send SPICE_MSG_MAIN_MIGRATE_BEGIN upon spice_server_migrate_connect
    (to all the clients that support it)
(2) wait for SPICE_MSGC_MAIN_MIGRATE_(CONNECTED|CONNECT_ERROR) from all the relevant clients,
    or a timeout, in order to complete client_migrate_info monitor command
(cherry picked from commit 5560c56ef0 branch 0.8;
 Was modified to support the separation of main channel from reds, and multiple clients)

Conflicts:

	server/reds.c
2011-11-02 11:21:08 +02:00
Yonit Halperin
38a96b4084 server: handle migration interface addition
(cherry picked from commit 3ac0075cda branch 0.8)

Conflicts:

	server/reds.h
2011-11-02 11:20:25 +02:00
Yonit Halperin
cd402151de server/spice.h: semi-seamless migration interface, RHBZ #738266
semi-seamless migration details:

migration source side
---------------------
(1) spice_server_migrate_connect (*): tell client to link
    to the target side - send SPICE_MSG_MAIN_MIGRATE_BEGIN.
    This should be called upon client_migrate_info cmd.
    client_migrate_info is asynchronous.
(2) Complete spice_server_migrate_connect only when the client has been connected
    to the target - wait for SPICE_MSGC_MAIN_MIGRATE_(CONNECTED|CONNECT_ERROR) or a timeout.
(3) spice_server_migrate_end: tell client migration it can switch to the target - send
    SPICE_MSG_MAIN_MIGRATE_END.
(4) client cleans up all data related to the connection to the source and switches to the target.
    It sends SPICE_MSGC_MAIN_MIGRATE_END.

migration target side
---------------------
(1) the server identifies itself as a migraiton target since the client is linked with (connection_id != 0)
(2) server doesn't start the channels' logic (channel->link) till it receives SPICE_MSGC_MAIN_MIGRATE_END
    from the client.

*   After migration starts, the target qemu is blocked and cannot accept new spice client
    connections. Thus, we trigger the connection to the target upon client_migrate_info
    command.
(cherry picked from commit 6e56bea67c branch 0.8)

Conflicts:

	server/spice.h
2011-11-02 11:20:08 +02:00
Yonit Halperin
0bf518cd3d server: set & test channel capabilities in red_channel
The code for setting and testing channel capabilities was
unnecessarily duplicated. Now it is in red_channel.
RedsChannel was dropped from Reds; It was used only for holding
the channels common capabilities, which are now held in RedChannel.
2011-11-02 11:19:48 +02:00
Alon Levy
bd8771adbc [0.8 branch] server: add main_dispatcher
add main_dispatcher, a message passing mechanism for sending messages to
the main thread. The main thread is the thread that implements
SpiceCoreInterface, which is assumed to be a single thread.

Similar to the async operation of red_worker, a socket pair is created
and used to pass messages. The messages are a fixed size to ease
parsing. A single message is defined to pass a channel_event.

RHBZ: 746950
FDBZ: 41858

This patch is 0.8 branch only, for the master branch there should be a
better approach to share code with red_dispatcher and ready the way for
later adding more threads.

cherry-pick from 0.8 80caf07e09

Conflicts:

	server/reds.c
2011-10-31 17:35:54 +02:00
Yonit Halperin
86576aec6a server/red_worker: fix placing of ASSERT(red_channel_client_no_item_being_sent) (fdbz #41523)
Call ASSERT(red_channel_client_no_item_being_sent) only if
red_wait_outgoing_item/s did not timeout.
2011-10-18 15:16:46 +02:00
Christophe Fergeau
6a20050352 replace warning with comment in glz_usr_free_image
When running some xinerama tests, I got several
glz_usr_free_image: error
messages. Looking at the code, this error is reported when this
function is called from a different DisplayChannelClient than the
one which created the glz compressed image.
When this happens, the backtrace is
    at glz_encoder_dictionary.c:362
    0x7fff940b6670) at glz_encoder_dictionary.c:449
    image_type=LZ_IMAGE_TYPE_RGB32, image_width=512, image_height=256, image_stride=2048, first_lines=0x0,
    num_first_lines=0, usr_image_context=0x7fff7420da40, image_head_dist=0x7fff9b2a3194)
    at glz_encoder_dictionary.c:570
    top_down=4, lines=0x0, num_lines=0, stride=2048, io_ptr=0x7fff740ea7c0 "  ZL", num_io_bytes=65536, usr_context=
    0x7fff7420da40, o_enc_dict_context=0x7fff7420da60) at glz_encoder.c:255
    drawable=0x7fff9b46bc08, o_comp_data=0x7fff9b2a3350) at red_worker.c:5753
    0x7fff9b46bc08, can_lossy=0, o_comp_data=0x7fff9b2a3350) at red_worker.c:6211
    0x7fff9b46bc08, can_lossy=0) at red_worker.c:6344
    0x7fff74085c50, dpi=0x7fff7445b890, src_allowed_lossy=0) at red_worker.c:7046
    0x7fff7445b890) at red_worker.c:7720
    at red_worker.c:7964
    at red_worker.c:8431

Since the glz dictionary is shared between all the
DisplayChannelClient instances that belong to the same client, it can
happen that the glz dictionary code decides to free an image from one
thread while it was added from another thread (thread ==
DisplayChannelClient), so the error message that is printed is not an
actual error. This commit removes this message and adds a comment
explaining what's going on.
2011-09-19 18:33:32 +02:00
Christophe Fergeau
011266555a server: fix function prototypes
Several functions in server/ were not specifying an argument list,
ie they were declared as void foo(); When compiling with
-Wstrict-prototypes, this leads to:
test_playback.c:93:5: erreur: function declaration isn’t a prototype
[-Werror=strict-prototypes]
2011-09-05 07:52:20 +02:00
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