Commit Graph

890 Commits

Author SHA1 Message Date
Frediano Ziglio
3c933f53bf channel-main: Fix indentation
Some mistake in recent patch, thanks to Marc-André's eagle eyes.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2020-03-20 12:50:03 +00:00
Frediano Ziglio
7363d1a0a6 channel-main: Avoid macro side effects
In big endian system GUINT32_TO_LE macro uses the parameter
multiple time causing serial to be incremented multiple times
instead of one.
Avoid side effects using a temporary variable.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2020-03-19 17:07:45 +00:00
Frediano Ziglio
1defa5c0f0 channel-main: Fix indentation
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2020-03-19 17:05:34 +00:00
Victor Toso
3fa9c072be Remove PulseAudio backend
GStreamer is a hard requirement since ac0e50f or v0.36 wich is the
same release that PulseAudio backend was deprecated:

    9a4b3bc "build-sys: deprecate the pulseaudio backend" in 2019-01-14

Signed-off-by: Victor Toso <victortoso@redhat.com>
Acked-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2020-03-17 18:25:38 +01:00
Victor Toso
6e9d8cfc02 Remove celt support
Follow up of spice-protocol's deprecation of celt mode.
See: https://gitlab.freedesktop.org/spice/spice-protocol/-/merge_requests/15

Signed-off-by: Victor Toso <victortoso@redhat.com>
Acked-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2020-03-17 18:23:44 +01:00
Marc-André Lureau
039f03bbd0 clipboard: implement CAP_CLIPBOARD_GRAB_SERIAL
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2020-03-10 16:38:34 +01:00
Marc-André Lureau
d46ddd21b4 clipboard: pre-condition on selection value <= 255
The protocol uses a u8 for the selection value. Make sure the given
argument value fits there, or throw a critical.

The other places seem to use u8 variables already.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2020-03-10 16:36:45 +01:00
Marc-André Lureau
a723bf67c5 clipboard: do not delay release if agent has "no release on regrab"
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2020-03-10 15:24:44 +01:00
Marc-André Lureau
2b6ffaa369 clipboard: do not release between remote grabs
Delay the release events for 0.5 sec. If no further grab comes in,
then release the grab. Otherwise, let's skip the release. This avoids
some races with clipboard managers.

Related to:
https://gitlab.freedesktop.org/spice/spice-gtk/issues/82

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2020-03-10 15:24:44 +01:00
Marc-André Lureau
2a75ddb97d clipboard: do not release between client grabs
On the client side, whenever the grab owner changes (and the clipboard
was previously grabbed), spice-gtk sends a clipboard release followed
immediately by a new grab. But some clipboard managers on the remote
side react to clipboard release events by taking a clipboard grab,
presumably to avoid empty clipboards.

The two grabs, coming from the client and from the remote sides, will
race in both directions, which may confuse the client & remote side,
as both believe the other side is the current grab owner, and thus
further clipboard data requests are likely to fail.

Let's avoid sending a release event when re-grabing.

The race described above may still happen in other rare circunstances,
and will require a protocol change. To avoid the conflict, a discussed
solution could use a clipboard serial number.

Tested with current linux & windows vdagent. Looking at earlier
version of the code, it doesn't seem like subsequent grabs will be
treated as an error.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2020-03-10 15:24:44 +01:00
Francesco Giudici
d41bf3e9f7 meson: fix indentation
Signed-off-by: Francesco Giudici <fgiudici@redhat.com>
Acked-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
2020-03-05 18:44:17 +01:00
Victor Toso
308df96bef build: egl: remove libdrm/drm_fourcc.h
Same result but removing the single directly usage of libdrm include
which is not being checked. The header epoxy/egl_generated.h contains
the macro EGL_LINUX_DRM_FOURCC_EXT that we use in spice-widget-egl.c
and that is included in epoxy/egl.h already.

Signed-off-by: Victor Toso <victortoso@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2020-02-06 16:44:01 +00:00
Frediano Ziglio
d24a27b962 Add a comment to spice_usb_device_manager_is_device_shared_cd
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-02-02 15:53:28 +00:00
Frediano Ziglio
93c7225546 Do not export spice_usb_device_manager_remove_shared_cd_device
This function is defined and called only from usb-device-manager.c.
Avoids to export it making an ABI to maintain in the future.
This API was added in commit 2a256ad0b4
(cfr "add spice_usb_device_manager shared CD related api functions"),
no release contains it so it's fine to remove it.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-02-02 15:53:28 +00:00
Alexander Nezhinsky
fc67c42656 fix check widget identification in usb-device-widget::set_inactive_by_usb_device()
check widget was identified by taking the child of the passed widget
but the check widget itself is being passed

Acked-by: Frediano Ziglio <fziglio@redhat.com>
2020-02-01 11:52:26 +00:00
Alexander Nezhinsky
c4c7eb34c4 remove shared cd in usb-dev-manager on any disconnect event
When a shared cd fails to connect, experiences a device error
or gets disconnected, its device should be removed to avoid the
'existing but not connected' state, which is disallowed for cd devices.

Acked-by: Frediano Ziglio <fziglio@redhat.com>
2020-02-01 11:52:22 +00:00
Alexander Nezhinsky
33f7e09ef0 auto-connect shared CD devices added using command line
Shared CD devices have special lifecycle requirements: they are always
auto-redirected after being created and always destroyed after being
disconnected. Thus the intermediate state of an existing but not connected
device, which is normal for the physical devices, is not supported.

For the devices added using the corresponding command line options it
means that they should be auto-connected on the viewer start.
By default such devices are redirected subject to the 'redirect-on-connect'
filter, which does not fit the shared CD connecting requirements above.
Instead, CDs are redirected unconditionally by this patch.

Acked-by: Frediano Ziglio <fziglio@redhat.com>
2020-02-01 11:52:17 +00:00
Alexander Nezhinsky
37433379bd Add --spice-share-cd command line option
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2020-02-01 11:52:13 +00:00
Alexander Nezhinsky
7a9076266b Add empty CD entry to usb-device-widget, create shared CD when toggled
The empty CD entry is a placeholder and appears every time the widget is created.
When it is toggled, a file chooser dialog is popped up. If a file or device is
selected, a new CD device is created. The new CD device is auto-connected.

This device is communicated to the widget through the 'device-added' signal.
The list entry responsible for the new device corresponds to the entity
provided by usb-device-manager. The empty CD entry is automatically moved to
the top of the list.

Acked-by: Frediano Ziglio <fziglio@redhat.com>
2020-02-01 11:52:09 +00:00
Alexander Nezhinsky
2a256ad0b4 add spice_usb_device_manager shared CD related api functions
The following functions are added:
spice_usb_device_manager_create_shared_cd_device
spice_usb_device_manager_is_device_shared_cd
spice_usb_device_manager_remove_shared_cd_device

Acked-by: Frediano Ziglio <fziglio@redhat.com>
2020-02-01 11:52:05 +00:00
Victor Toso
8c86fd98df Revert "channel: Abort migration in delayed unref"
This reverts commit 109e575 "channel: Abort migration in delayed
unref" in 2016-05-02 by Pavel Grunt <pgrunt@redhat.com>

This commit is being reverted because it calls
spice_session_abort_migration() on the SpiceSession for the target
host while the function should receive the SpiceSession for current
host.

I can actually reproduce a bug where the password expires for the
current Spice session and the migration is going to fail because of
that. Before reverting this commit, remote-viewer would hang and the
following logs would occur:

- Migration starts on channel-main
 > ../src/channel-main.c:2174 migrate_channel_connect 1:0

- Using TLS
 > ../src/spice-channel.c:1934 main-1:0: switching to tls

- Following logs are related to failure to connect due Authentication
 > ../src/spice-channel.c:2000 main-1:0: use mini header: 1
 > ../src/spice-channel.c:1274 main-1:0: link result: reply 7
 > ../src/spice-channel.c:2680 main-1:0: Coroutine exit main-1:0
 > ../src/spice-channel.c:2871 main-1:0: reset

Remote-viewer would hang because we are in a state of migration and
SpiceMainChannel does not know that it failed because
spice_session_abort_migration() is being called on SpiceSession of
target host and no SpiceChannel::channel-event is being emitted.

Reverting this patch does abort migration thanks to
SpiceChannel::channel-event being emitted and caught by
SpiceMainChannel at migrate_channel_event_cb() with the log:

 > ../src/channel-main.c:2247 main-1:0: error or unhandled channel event during migration: 23
 > ../src/channel-main.c:2373 main-1:0: migrate failed: some channels failed to connect

Note that the reverted patch mentions the fix of bug [0] which is also
a virt-viewer with a hanging state. Looking back to the logs, the
interesting part around issues around usbredir, that is:

 > GSpice-DEBUG: channel-main.c:2236 migration: channel opened chan:0x29ddce0, left 6
 > GSpice-DEBUG: spice-channel.c:916 usbredir-9:0: Read error Error receiving data: Connection reset by peer
 > GSpice-DEBUG: spice-channel.c:1210 usbredir-9:0: error, switching to protocol 1 (spice 0.4)
 > GSpice-DEBUG: spice-channel.c:2433 usbredir-9:0: Coroutine exit usbredir-9:0
 > GSpice-DEBUG: spice-channel.c:2455 usbredir-9:0: Open coroutine starting 0x29e10d0
 > GSpice-DEBUG: spice-channel.c:2289 usbredir-9:0: Started background coroutine 0x29e0750
 > GSpice-DEBUG: spice-channel.c:916 usbredir-9:1: Read error Error receiving data: Connection reset by peer
 > GSpice-DEBUG: spice-channel.c:1076 usbredir-9:1: incomplete auth reply (-104/4)
 > GSpice-DEBUG: spice-channel.c:916 playback-5:0: Read error Error receiving data: Connection reset by peer
 > GSpice-DEBUG: spice-channel.c:1076 playback-5:0: incomplete auth reply (-104/4)
 > GSpice-DEBUG: spice-channel.c:916 display-2:0: Read error Error receiving data: Connection reset by peer
 > GSpice-DEBUG: spice-channel.c:1076 display-2:0: incomplete auth reply (-104/4)
 > GSpice-DEBUG: spice-session.c:1775 connecting 0x7f12bffffa50...
 > GSpice-DEBUG: spice-session.c:1850 open host lab.test.me:5900
 > GSpice-DEBUG: channel-main.c:2241 error or unhandled channel event during migration: 22
 > GSpice-DEBUG: spice-session.c:1665 session: disconnecting 0
 > GSpice-DEBUG: spice-channel.c:2160 usbredir-9:1: channel got error
 > GSpice-DEBUG: spice-channel.c:2433 usbredir-9:1: Coroutine exit usbredir-9:1
 > GSpice-DEBUG: channel-main.c:2241 error or unhandled channel event during migration: 22

So, the expected behavior was happening on error, which is
channel-main aborting the migration due SpiceChannel::channel-event
being emitted with some failure.

Also note that, with this commit reverted, I don't experience any
hanging after migration is aborted. Likely the original bug was fixed.

[0] https://bugzilla.redhat.com/show_bug.cgi?id=1318574

Related: https://bugzilla.redhat.com/show_bug.cgi?id=1695618

Signed-off-by: Victor Toso <victortoso@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2020-01-23 09:53:04 +00:00
Snir Sheriber
9e4a09b480 gstreamer: add debug message for each element added to pipeline
This helps to debug plugins load related issues, also factory name
is usually a bit more accurate (if factory exists the elements name
may also include some suffix).

Signed-off-by: Snir Sheriber <ssheribe@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2020-01-21 09:25:43 +00:00
Frediano Ziglio
3b485d5a44 channel-usbredir: Remove duplicate field
"spice_device" and "device" points to the same object.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Francesco Giudici <fgiudici@redhat.com>
2020-01-19 11:22:08 +02:00
Frediano Ziglio
d4f7a71508 Rename SpiceUsbBackendDevice to SpiceUsbDevice
They are the same structure now.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Francesco Giudici <fgiudici@redhat.com>
2020-01-19 11:21:34 +02:00
Frediano Ziglio
7d1c1a4861 channel-usbredir: Remove duplicate argument to spice_usbredir_channel_connect_device_async
Now that SpiceUsbBackendDevice and SpiceUsbDevice are the same
structure is useless to pass the same argument twice.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Francesco Giudici <fgiudici@redhat.com>
2020-01-19 11:21:18 +02:00
Frediano Ziglio
f3d42c570e usb-device-manager: Remove spice_usb_device_manager_device_to_bdev
Now that SpiceUsbBackendDevice and SpiceUsbDevice are the same
there's no much sense to call it.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Francesco Giudici <fgiudici@redhat.com>
2020-01-19 11:21:07 +02:00
Francois Gouget
a4b9d5a46b channel-display: Fix wording of the deep_element_added_cb() documentation
Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
Acked-by: Uri Lublin <uril@redhat.com>
2020-01-13 09:16:33 +00:00
Jakub Janků
f784f4e6d1 main: remove msg from c->flushing asap
The msg is no longer valid after spice_msg_out_send_internal(),
so it shouldn't be present in c->flushing since the same
memory can be assigned to a new message.

This currently causes issues when transferring multiple big
files at once (tested 4 × 200 MB).
The following can happen in agent_send_msg_queue(),
after msg is flushed:

(task1, task2 refers to two distinct SpiceFileTransferTasks,
 one per file)

g_task_return_boolean(task1) ->
file_xfer_data_flushed_cb(task1) ->
spice_file_transfer_task_read_async(task1) ->
g_coroutine_object_notify() [switches from coroutine context to main]
...
file_xfer_read_async_cb(task2) ->
file_xfer_queue_msg_to_agent(task2)
[allocates new msg for task2 at the same address as the old msg] ->
file_xfer_flush_async(task2)
[inserts to c->flushing, but the old msg is still present,
 so the data in the hash table changes from task1 to task2]
...
program returns to coroutine context,
g_task_return_boolean(task1) returns ->
g_hash_table_remove() [removes the entry that now contains task2]

Consequently, flush task for task2 never finishes
and it gets stuck.

This issue is present since 2261e50a64,
that replaced g_object_notify() in spice_file_transfer_task_read_async()
with g_coroutine_object_notify().

To solve it, remove the msg from c->flushing
before finishing the flush task.

Signed-off-by: Jakub Janků <jjanku@redhat.com>
2020-01-10 11:04:48 +01:00
Frediano Ziglio
f851db2299 channel-main: Fix possible crash on Windows
agent_msg_queue_many is a variadic function reading parameters
after the third using va_arg.
Specifically it read sizes of buffers using the "gsize" type.
On x64 for Windows platform only first 4 argument of
agent_msg_queue_many are passed by registers while the rest is
passed on the stack. So the size is written in the stack.
On x64 gsize is 64 bit while data_size in
file_xfer_queue_msg_to_agent is an int which is 32 bit.
So in some cases when data_size is stored in the stack in order
to call agent_msg_queue_many from file_xfer_queue_msg_to_agent
the compiler will write only 32 bit, like for instance with:

   mov %ebx,0x28(%rsp)

The problem is that agent_msg_queue_many will use "va_arg(args, gsize)"
reading 64 bit instead of 32. In this case the lower 32 bit
part will be the "data_size" but the higher 32 bit part will be the
previous content of the stack, basically garbage.
This will cause the read size to be a huge value and program will
crash.

This could not be exploited the operation will lead to only read
extra bytes and then crash.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2019-12-18 13:59:46 +00:00
Frediano Ziglio
e2898dfd9e usb-device-manager: Remove disconnect_cb_data
"device" field is just written, never read.
"manager" field can be retrieved using g_task_get_source_object.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Signed-off-by: Snir Sheriber <ssheribe@redhat.com>
2019-12-18 15:50:11 +02:00
Frediano Ziglio
db59d50f5c Use g_clear_object instead of g_clear_pointer if possible
If the pointer is freed with g_object_unref the two do the
same.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Signed-off-by: Snir Sheriber <ssheribe@redhat.com>
2019-12-18 14:40:50 +02:00
Frediano Ziglio
7f7542f490 spice-session: Remove goto statement and label
Just a style change.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Signed-off-by: Snir Sheriber <ssheribe@redhat.com>
2019-12-18 14:40:38 +02:00
Frediano Ziglio
67cf1f704b spice-session: Remove only assigned "pci_ram_size" field
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2019-12-16 16:31:28 +00:00
Frediano Ziglio
adc5651ef1 spice-session: Removed unused "palettes" field
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2019-12-16 16:31:28 +00:00
Alexander Nezhinsky
6685b013d7 fix style in usb-device-widget: always place curly brackets after if
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-12-12 14:50:48 +00:00
Alexander Nezhinsky
3b1afefcf3 fix style in usb-device-widget: arguments and parameters alignment
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-12-12 14:50:46 +00:00
Alexander Nezhinsky
c32fc36f02 fix style in usb-device-manager: always place curly brackets after if
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-12-12 14:50:44 +00:00
Alexander Nezhinsky
7e2e1ed462 fix style in usb-device-manager: arguments and parameters alignment
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-12-12 14:50:42 +00:00
Alexander Nezhinsky
d09a35603d fix style in usb-device-manager: rename 'self' to 'manager'
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-12-12 14:50:39 +00:00
Alexander Nezhinsky
e1ba69c255 implement spice_usb_device_widget_add_err_msg() in usb-device-widget
This is a common function for adding an error status message.

If an old message exists, checks if the new message is not already contained
in the old one. The new message is ignored if it is, added if it's not.

New message string should be dynamically allocated, it's always g_free-ed.

Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-12-12 14:50:36 +00:00
Alexander Nezhinsky
dbe4aec78c move spice_usb_backend_device_{eject|report_change} to usb_backend.h
These functions belong to usb_backend_device api

Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-12-12 14:50:34 +00:00
Victor Toso
0c52ce8937 display: remove dangling pointer
It just holds a reference to the primary surface which is being
removed and freed from the hash table. This ends up generating a
warning below in the same function before setting the new primary
surface reference.

Signed-off-by: Victor Toso <victortoso@redhat.com>
2019-10-31 00:27:24 +01:00
Frediano Ziglio
33ca9d412c spice-widget: Fix invalidate region in case of image is scaled
In case the drawing on the screen is scaled the scaling required to
invalidate a slightly bigger region.
This is due to the interpolation done during the resize.
So if scaling is performed invalidate also the adjacent pixels.

This fixes https://gitlab.freedesktop.org/spice/spice-gtk/issues/19.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-10-14 13:16:35 +01:00
Victor Toso
ee35577c7e channel-main: add debug related to migration
Migration can start with different messages and the code could take
different paths. By having a debug on which message started can help
pinpoint issues faster.

Signed-off-by: Victor Toso <victortoso@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-09-30 10:15:45 +02:00
Frediano Ziglio
d7f743f617 build: Do not build usbredir dependent file if usbredir is disabled
These files would end up to compile empty code, no reason
to compile and link them.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-09-23 15:51:50 +01:00
Yuri Benditovich
50953f2360 usb-redir: enable redirection of emulated CD drive
Add implementation of emulated device to build.
Now it is possible to create emulated CD devices.

Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-09-23 14:01:58 +01:00
Yuri Benditovich
f771f701ad usb-redir: add implementation of emulated CD device
This module contains implementation of emulated device
interface for shared CD.

Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-09-23 13:58:31 +01:00
Frediano Ziglio
5bf98b3926 cd-scsi: Do not export sense code constants
They are used only inside the module.
Use a macro to simplify declaration which is pretty long.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-09-23 13:58:31 +01:00
Yuri Benditovich
ef0bee2e56 usb-redir: add files for SCSI and USB MSC implementation
Files added without including them in compilation.
They contain implementation of SCSI commands for logical
units of mass-storage device class and USB bulk-only
mass-storage device protocol.

Signed-off-by: Alexander Nezhinsky<anezhins@redhat.com>
Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-09-23 13:58:31 +01:00
Yuri Benditovich
3e20f17b90 usb-redir: extend USB backend to support emulated devices
Redirection of emulated devices requires special approach, as
usbredirhost can't be used for that (it works only with libusb
devices). For emulated devices we create instance of usbredirparser
that implements USB redirection protocol.  In order to work with the
same set of protocol capabilities that usbredirhost sets up with
remote side, the parser shall: - not send its own 'hello' to the
server
- initialize the same capabilities that usbredirhost
- receive the same 'hello' response
For that we analyze 'hello' sent by USB redir parser and extract set
of capabilities from it and upon receive of 'hello' response we
provide it also to the parser.  When libusb device is redirected via a
channel, instance of usbredirhost serves it.  When emulated device is
redirected via a channel, instance of usbredirparser does the job.

Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2019-09-23 13:58:31 +01:00