char/spice: discard write() if backend is disconnected

Most chardev backend handle write() as discarded data if underlying
system is disconnected. For unknown historical reasons, the Spice
backend has "reliable" write: it will wait until the client end is
reconnected to do further successful write().

To decide whether it make sense to wait until the client is
reconnected (or queue the writes), let's review Spice chardev usage
and handling of a disconnected client:

 * spice vdagent
   The agents reopen the virtio port on disconnect. In qemu side,
   virtio_serial_close() will also discard pending data.

 * usb redirection
   A disconnect creates a device disconnection.

 * smartcard emulation
   Data is discarded in passthru_apdu_from_guest().

   (Spice doesn't explicitly open the smartcard char device until
   upcoming 0.14.2, commit 69a5cfc74131ec0459f2eb5a231139f5a69a8037)

 * spice webdavd
   The daemon will restart the service, and reopen the virtio port.

 * spice ports (serial console, qemu monitor..)
   Depends on the associated device or usage.

   - serial, may be throttled or discarded on write, depending on
     device

   - QMP/HMP monitor have some CLOSED event handling, but want to
     flush the write, which will finish when a new client connects.

On disconnect/reconnect, the client starts with fresh sessions. If it
is a seamless migration, the client disconnects after the source
migrated. The handling of source disconnect in qemu is thus irrelevant
for the Spice session migration.

For all these use cases, it is better to discard writes when the
client is disconnected, and require the vm-side device/agent to behave
correctly on CHR_EVENT_CLOSED, to stop reading and writing from
the spice chardev.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Tested-by: Victor Toso <victortoso@redhat.com>
Message-id: 20190221110703.5775-3-marcandre.lureau@redhat.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
Marc-André Lureau 2019-02-21 12:06:54 +01:00 committed by Gerd Hoffmann
parent 805189ab14
commit a2dc3c8ecb
2 changed files with 13 additions and 0 deletions

View File

@ -208,6 +208,12 @@ static int spice_chr_write(Chardev *chr, const uint8_t *buf, int len)
int read_bytes;
assert(s->datalen == 0);
if (!chr->be_open) {
trace_spice_chr_discard_write(len);
return len;
}
s->datapos = buf;
s->datalen = len;
spice_server_char_device_wakeup(&s->sin);
@ -300,6 +306,12 @@ static void qemu_chr_open_spice_vmc(Chardev *chr,
}
*be_opened = false;
#if SPICE_SERVER_VERSION < 0x000e02
/* Spice < 0.14.2 doesn't explicitly open smartcard chardev */
if (strcmp(type, "smartcard") == 0) {
*be_opened = true;
}
#endif
chr_open(chr, type);
}

View File

@ -10,6 +10,7 @@ wct_cmd_other(const char *cmd) "%s"
wct_speed(int speed) "%d"
# chardev/spice.c
spice_chr_discard_write(int len) "spice chr write discarded %d"
spice_vmc_write(ssize_t out, int len) "spice wrote %zd of requested %d"
spice_vmc_read(int bytes, int len) "spice read %d of requested %d"
spice_vmc_register_interface(void *scd) "spice vmc registered interface %p"