*
* This work is licensed under the terms of the GNU GPL, version 2. See
* the COPYING file in the top-level directory.
+ *
+ * Contributions after 2012-01-13 are licensed under the terms of the
+ * GNU GPL, version 2 or (at your option) any later version.
*/
#include "iov.h"
assert(port);
assert(virtio_queue_ready(vq));
- info = DO_UPCAST(VirtIOSerialPortInfo, qdev, port->dev.info);
+ info = DO_UPCAST(VirtIOSerialPortInfo, qdev, qdev_get_info(&port->dev));
while (!port->throttled) {
unsigned int i;
abort();
}
if (ret == -EAGAIN || (ret >= 0 && ret < buf_size)) {
- virtio_serial_throttle_port(port, true);
+ /*
+ * this is a temporary check until chardevs can signal to
+ * frontends that they are writable again. This prevents
+ * the console from going into throttled mode (forever)
+ * if virtio-console is connected to a pty without a
+ * listener. Otherwise the guest spins forever.
+ * We can revert this if
+ * 1: chardevs can notify frondends
+ * 2: the guest driver does not spin in these cases
+ */
+ if (!info->is_console) {
+ virtio_serial_throttle_port(port, true);
+ }
port->iov_idx = i;
if (ret > 0) {
port->iov_offset += ret;
trace_virtio_serial_handle_control_message_port(port->id);
- info = DO_UPCAST(VirtIOSerialPortInfo, qdev, port->dev.info);
+ info = DO_UPCAST(VirtIOSerialPortInfo, qdev, qdev_get_info(&port->dev));
switch(cpkt.event) {
case VIRTIO_CONSOLE_PORT_READY:
stw_p(&cpkt.value, 1);
buffer_len = sizeof(cpkt) + strlen(port->name) + 1;
- buffer = qemu_malloc(buffer_len);
+ buffer = g_malloc(buffer_len);
memcpy(buffer, &cpkt, sizeof(cpkt));
memcpy(buffer + sizeof(cpkt), port->name, strlen(port->name));
buffer[buffer_len - 1] = 0;
send_control_msg(port, buffer, buffer_len);
- qemu_free(buffer);
+ g_free(buffer);
}
if (port->host_connected) {
* if the size of the buf differs
*/
if (cur_len > len) {
- qemu_free(buf);
+ g_free(buf);
- buf = qemu_malloc(cur_len);
+ buf = g_malloc(cur_len);
len = cur_len;
}
copied = iov_to_buf(elem.out_sg, elem.out_num, buf, 0, len);
handle_control_message(vser, buf, copied);
virtqueue_push(vq, &elem, 0);
}
- qemu_free(buf);
+ g_free(buf);
virtio_notify(vdev, vq);
}
{
VirtIOSerial *vser;
VirtIOSerialPort *port;
- VirtIOSerialPortInfo *info;
vser = DO_UPCAST(VirtIOSerial, vdev, vdev);
port = find_port_by_vq(vser, vq);
- info = port ? DO_UPCAST(VirtIOSerialPortInfo, qdev, port->dev.info) : NULL;
- if (!port || !port->host_connected || !info->have_data) {
+ if (!port || !port->host_connected) {
discard_vq_data(vq, vdev);
return;
}
port->vser = bus->vser;
port->bh = qemu_bh_new(flush_queued_data_bh, port);
+ assert(info->have_data);
+
/*
* Is the first console port we're seeing? If so, put it up at
* location 0. This is done for backward compatibility (old
{
VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, qdev);
VirtIOSerialPortInfo *info = DO_UPCAST(VirtIOSerialPortInfo, qdev,
- port->dev.info);
+ qdev_get_info(&port->dev));
VirtIOSerial *vser = port->vser;
qemu_bh_delete(port->bh);
QTAILQ_INIT(&vser->ports);
vser->bus.max_nr_ports = conf->max_virtserial_ports;
- vser->ivqs = qemu_malloc(conf->max_virtserial_ports * sizeof(VirtQueue *));
- vser->ovqs = qemu_malloc(conf->max_virtserial_ports * sizeof(VirtQueue *));
+ vser->ivqs = g_malloc(conf->max_virtserial_ports * sizeof(VirtQueue *));
+ vser->ovqs = g_malloc(conf->max_virtserial_ports * sizeof(VirtQueue *));
/* Add a queue for host to guest transfers for port 0 (backward compat) */
vser->ivqs[0] = virtio_add_queue(vdev, 128, handle_input);
}
vser->config.max_nr_ports = tswap32(conf->max_virtserial_ports);
- vser->ports_map = qemu_mallocz(((conf->max_virtserial_ports + 31) / 32)
+ vser->ports_map = g_malloc0(((conf->max_virtserial_ports + 31) / 32)
* sizeof(vser->ports_map[0]));
/*
* Reserve location 0 for a console port for backward compat
unregister_savevm(vser->qdev, "virtio-console", vser);
- qemu_free(vser->ivqs);
- qemu_free(vser->ovqs);
- qemu_free(vser->ports_map);
+ g_free(vser->ivqs);
+ g_free(vser->ovqs);
+ g_free(vser->ports_map);
virtio_cleanup(vdev);
}