mirror of https://gitee.com/openkylin/qemu.git
Merge remote-tracking branch 'spice/spice.v69' into staging
# By Hans de Goede (5) and others # Via Gerd Hoffmann * spice/spice.v69: spice-qemu-char: vmc_write: Don't write more bytes then we're asked too spice-qemu-char: Remove intermediate buffer spice-qemu-char: Add watch support spice-qemu-char: Remove #ifdef-ed code for old spice-server compat virtio-console: Remove any pending watches on close virtio-console: Also throttle when less was written then requested spice: (32 bit only) fix surface cmd tracking destruction qxl: add 2000x2000 and 2048x2048 video modes qxl: add 4k + 8k resolutions Message-id: 1366106194-28826-1-git-send-email-kraxel@redhat.com Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
commit
6f8111a16d
|
@ -18,6 +18,7 @@
|
|||
typedef struct VirtConsole {
|
||||
VirtIOSerialPort port;
|
||||
CharDriverState *chr;
|
||||
guint watch;
|
||||
} VirtConsole;
|
||||
|
||||
/*
|
||||
|
@ -29,12 +30,14 @@ static gboolean chr_write_unblocked(GIOChannel *chan, GIOCondition cond,
|
|||
{
|
||||
VirtConsole *vcon = opaque;
|
||||
|
||||
vcon->watch = 0;
|
||||
virtio_serial_throttle_port(&vcon->port, false);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Callback function that's called when the guest sends us data */
|
||||
static ssize_t flush_buf(VirtIOSerialPort *port, const uint8_t *buf, size_t len)
|
||||
static ssize_t flush_buf(VirtIOSerialPort *port,
|
||||
const uint8_t *buf, ssize_t len)
|
||||
{
|
||||
VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port);
|
||||
ssize_t ret;
|
||||
|
@ -47,7 +50,7 @@ static ssize_t flush_buf(VirtIOSerialPort *port, const uint8_t *buf, size_t len)
|
|||
ret = qemu_chr_fe_write(vcon->chr, buf, len);
|
||||
trace_virtio_console_flush_buf(port->id, len, ret);
|
||||
|
||||
if (ret <= 0) {
|
||||
if (ret < len) {
|
||||
VirtIOSerialPortClass *k = VIRTIO_SERIAL_PORT_GET_CLASS(port);
|
||||
|
||||
/*
|
||||
|
@ -56,11 +59,14 @@ static ssize_t flush_buf(VirtIOSerialPort *port, const uint8_t *buf, size_t len)
|
|||
* we had a finer-grained message, like -EPIPE, we could close
|
||||
* this connection.
|
||||
*/
|
||||
if (ret < 0)
|
||||
ret = 0;
|
||||
if (!k->is_console) {
|
||||
virtio_serial_throttle_port(port, true);
|
||||
qemu_chr_fe_add_watch(vcon->chr, G_IO_OUT, chr_write_unblocked,
|
||||
vcon);
|
||||
if (!vcon->watch) {
|
||||
vcon->watch = qemu_chr_fe_add_watch(vcon->chr, G_IO_OUT,
|
||||
chr_write_unblocked, vcon);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
@ -104,6 +110,10 @@ static void chr_event(void *opaque, int event)
|
|||
virtio_serial_open(&vcon->port);
|
||||
break;
|
||||
case CHR_EVENT_CLOSED:
|
||||
if (vcon->watch) {
|
||||
g_source_remove(vcon->watch);
|
||||
vcon->watch = 0;
|
||||
}
|
||||
virtio_serial_close(&vcon->port);
|
||||
break;
|
||||
}
|
||||
|
@ -128,6 +138,17 @@ static int virtconsole_initfn(VirtIOSerialPort *port)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int virtconsole_exitfn(VirtIOSerialPort *port)
|
||||
{
|
||||
VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port);
|
||||
|
||||
if (vcon->watch) {
|
||||
g_source_remove(vcon->watch);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static Property virtconsole_properties[] = {
|
||||
DEFINE_PROP_CHR("chardev", VirtConsole, chr),
|
||||
DEFINE_PROP_END_OF_LIST(),
|
||||
|
@ -140,6 +161,7 @@ static void virtconsole_class_init(ObjectClass *klass, void *data)
|
|||
|
||||
k->is_console = true;
|
||||
k->init = virtconsole_initfn;
|
||||
k->exit = virtconsole_exitfn;
|
||||
k->have_data = flush_buf;
|
||||
k->set_guest_connected = set_guest_connected;
|
||||
dc->props = virtconsole_properties;
|
||||
|
|
|
@ -109,13 +109,19 @@ static QXLMode qxl_modes[] = {
|
|||
/* these modes need more than 8 MB video memory */
|
||||
QXL_MODE_EX(1920, 1200),
|
||||
QXL_MODE_EX(1920, 1440),
|
||||
QXL_MODE_EX(2000, 2000),
|
||||
QXL_MODE_EX(2048, 1536),
|
||||
QXL_MODE_EX(2048, 2048),
|
||||
QXL_MODE_EX(2560, 1440),
|
||||
QXL_MODE_EX(2560, 1600),
|
||||
/* these modes need more than 16 MB video memory */
|
||||
QXL_MODE_EX(2560, 2048),
|
||||
QXL_MODE_EX(2800, 2100),
|
||||
QXL_MODE_EX(3200, 2400),
|
||||
QXL_MODE_EX(3840, 2160), /* 4k mainstream */
|
||||
QXL_MODE_EX(4096, 2160), /* 4k */
|
||||
QXL_MODE_EX(7680, 4320), /* 8k mainstream */
|
||||
QXL_MODE_EX(8192, 4320), /* 8k */
|
||||
};
|
||||
|
||||
static void qxl_send_events(PCIQXLDevice *d, uint32_t events);
|
||||
|
@ -224,7 +230,7 @@ static void qxl_spice_destroy_surfaces_complete(PCIQXLDevice *qxl)
|
|||
trace_qxl_spice_destroy_surfaces_complete(qxl->id);
|
||||
qemu_mutex_lock(&qxl->track_lock);
|
||||
memset(qxl->guest_surfaces.cmds, 0,
|
||||
sizeof(qxl->guest_surfaces.cmds) * qxl->ssd.num_surfaces);
|
||||
sizeof(qxl->guest_surfaces.cmds[0]) * qxl->ssd.num_surfaces);
|
||||
qxl->guest_surfaces.count = 0;
|
||||
qemu_mutex_unlock(&qxl->track_lock);
|
||||
}
|
||||
|
|
|
@ -104,7 +104,7 @@ typedef struct VirtIOSerialPortClass {
|
|||
* 'len'. In this case, throttling will be enabled for this port.
|
||||
*/
|
||||
ssize_t (*have_data)(VirtIOSerialPort *port, const uint8_t *buf,
|
||||
size_t len);
|
||||
ssize_t len);
|
||||
} VirtIOSerialPortClass;
|
||||
|
||||
/*
|
||||
|
|
|
@ -13,12 +13,17 @@ typedef struct SpiceCharDriver {
|
|||
SpiceCharDeviceInstance sin;
|
||||
char *subtype;
|
||||
bool active;
|
||||
uint8_t *buffer;
|
||||
uint8_t *datapos;
|
||||
ssize_t bufsize, datalen;
|
||||
bool blocked;
|
||||
const uint8_t *datapos;
|
||||
int datalen;
|
||||
QLIST_ENTRY(SpiceCharDriver) next;
|
||||
} SpiceCharDriver;
|
||||
|
||||
typedef struct SpiceCharSource {
|
||||
GSource source;
|
||||
SpiceCharDriver *scd;
|
||||
} SpiceCharSource;
|
||||
|
||||
static QLIST_HEAD(, SpiceCharDriver) spice_chars =
|
||||
QLIST_HEAD_INITIALIZER(spice_chars);
|
||||
|
||||
|
@ -30,7 +35,8 @@ static int vmc_write(SpiceCharDeviceInstance *sin, const uint8_t *buf, int len)
|
|||
uint8_t* p = (uint8_t*)buf;
|
||||
|
||||
while (len > 0) {
|
||||
last_out = MIN(len, qemu_chr_be_can_write(scd->chr));
|
||||
int can_write = qemu_chr_be_can_write(scd->chr);
|
||||
last_out = MIN(len, can_write);
|
||||
if (last_out <= 0) {
|
||||
break;
|
||||
}
|
||||
|
@ -54,9 +60,10 @@ static int vmc_read(SpiceCharDeviceInstance *sin, uint8_t *buf, int len)
|
|||
scd->datapos += bytes;
|
||||
scd->datalen -= bytes;
|
||||
assert(scd->datalen >= 0);
|
||||
}
|
||||
if (scd->datalen == 0) {
|
||||
scd->datapos = 0;
|
||||
}
|
||||
scd->blocked = false;
|
||||
}
|
||||
trace_spice_vmc_read(bytes, len);
|
||||
return bytes;
|
||||
|
@ -85,21 +92,6 @@ static void vmc_state(SpiceCharDeviceInstance *sin, int connected)
|
|||
{
|
||||
SpiceCharDriver *scd = container_of(sin, SpiceCharDriver, sin);
|
||||
|
||||
#if SPICE_SERVER_VERSION < 0x000901
|
||||
/*
|
||||
* spice-server calls the state callback for the agent channel when the
|
||||
* spice client connects / disconnects. Given that not the client but
|
||||
* the server is doing the parsing of the messages this is wrong as the
|
||||
* server is still listening. Worse, this causes the parser in the server
|
||||
* to go out of sync, so we ignore state calls for subtype vdagent
|
||||
* spicevmc chardevs. For the full story see:
|
||||
* http://lists.freedesktop.org/archives/spice-devel/2011-July/004837.html
|
||||
*/
|
||||
if (strcmp(sin->subtype, "vdagent") == 0) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((scd->chr->be_open && connected) ||
|
||||
(!scd->chr->be_open && !connected)) {
|
||||
return;
|
||||
|
@ -144,21 +136,67 @@ static void vmc_unregister_interface(SpiceCharDriver *scd)
|
|||
trace_spice_vmc_unregister_interface(scd);
|
||||
}
|
||||
|
||||
static gboolean spice_char_source_prepare(GSource *source, gint *timeout)
|
||||
{
|
||||
SpiceCharSource *src = (SpiceCharSource *)source;
|
||||
|
||||
*timeout = -1;
|
||||
|
||||
return !src->scd->blocked;
|
||||
}
|
||||
|
||||
static gboolean spice_char_source_check(GSource *source)
|
||||
{
|
||||
SpiceCharSource *src = (SpiceCharSource *)source;
|
||||
|
||||
return !src->scd->blocked;
|
||||
}
|
||||
|
||||
static gboolean spice_char_source_dispatch(GSource *source,
|
||||
GSourceFunc callback, gpointer user_data)
|
||||
{
|
||||
GIOFunc func = (GIOFunc)callback;
|
||||
|
||||
return func(NULL, G_IO_OUT, user_data);
|
||||
}
|
||||
|
||||
GSourceFuncs SpiceCharSourceFuncs = {
|
||||
.prepare = spice_char_source_prepare,
|
||||
.check = spice_char_source_check,
|
||||
.dispatch = spice_char_source_dispatch,
|
||||
};
|
||||
|
||||
static GSource *spice_chr_add_watch(CharDriverState *chr, GIOCondition cond)
|
||||
{
|
||||
SpiceCharDriver *scd = chr->opaque;
|
||||
SpiceCharSource *src;
|
||||
|
||||
assert(cond == G_IO_OUT);
|
||||
|
||||
src = (SpiceCharSource *)g_source_new(&SpiceCharSourceFuncs,
|
||||
sizeof(SpiceCharSource));
|
||||
src->scd = scd;
|
||||
|
||||
return (GSource *)src;
|
||||
}
|
||||
|
||||
static int spice_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
|
||||
{
|
||||
SpiceCharDriver *s = chr->opaque;
|
||||
int read_bytes;
|
||||
|
||||
assert(s->datalen == 0);
|
||||
if (s->bufsize < len) {
|
||||
s->bufsize = len;
|
||||
s->buffer = g_realloc(s->buffer, s->bufsize);
|
||||
}
|
||||
memcpy(s->buffer, buf, len);
|
||||
s->datapos = s->buffer;
|
||||
s->datapos = buf;
|
||||
s->datalen = len;
|
||||
spice_server_char_device_wakeup(&s->sin);
|
||||
return len;
|
||||
read_bytes = len - s->datalen;
|
||||
if (read_bytes != len) {
|
||||
/* We'll get passed in the unconsumed data with the next call */
|
||||
s->datalen = 0;
|
||||
s->datapos = NULL;
|
||||
s->blocked = true;
|
||||
}
|
||||
return read_bytes;
|
||||
}
|
||||
|
||||
static void spice_chr_close(struct CharDriverState *chr)
|
||||
|
@ -214,6 +252,7 @@ static CharDriverState *chr_open(const char *subtype)
|
|||
s->sin.subtype = g_strdup(subtype);
|
||||
chr->opaque = s;
|
||||
chr->chr_write = spice_chr_write;
|
||||
chr->chr_add_watch = spice_chr_add_watch;
|
||||
chr->chr_close = spice_chr_close;
|
||||
chr->chr_set_fe_open = spice_chr_set_fe_open;
|
||||
|
||||
|
@ -224,7 +263,6 @@ static CharDriverState *chr_open(const char *subtype)
|
|||
|
||||
CharDriverState *qemu_chr_open_spice_vmc(const char *type)
|
||||
{
|
||||
CharDriverState *chr;
|
||||
const char **psubtype = spice_server_char_device_recognized_subtypes();
|
||||
|
||||
if (type == NULL) {
|
||||
|
@ -243,16 +281,7 @@ CharDriverState *qemu_chr_open_spice_vmc(const char *type)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
chr = chr_open(type);
|
||||
|
||||
#if SPICE_SERVER_VERSION < 0x000901
|
||||
/* See comment in vmc_state() */
|
||||
if (strcmp(type, "vdagent") == 0) {
|
||||
qemu_chr_generic_open(chr);
|
||||
}
|
||||
#endif
|
||||
|
||||
return chr;
|
||||
return chr_open(type);
|
||||
}
|
||||
|
||||
#if SPICE_SERVER_VERSION >= 0x000c02
|
||||
|
|
Loading…
Reference in New Issue