Revision a15bb0d6 hw/virtio-serial-bus.c

b/hw/virtio-serial-bus.c
129 129
static void do_flush_queued_data(VirtIOSerialPort *port, VirtQueue *vq,
130 130
                                 VirtIODevice *vdev)
131 131
{
132
    VirtIOSerialPortInfo *info;
133

  
132 134
    assert(port);
133 135
    assert(virtio_queue_ready(vq));
134 136

  
137
    info = DO_UPCAST(VirtIOSerialPortInfo, qdev, port->dev.info);
138

  
135 139
    while (!port->throttled) {
136 140
        unsigned int i;
137 141

  
......
149 153
            ssize_t ret;
150 154

  
151 155
            buf_size = port->elem.out_sg[i].iov_len - port->iov_offset;
152
            ret = port->info->have_data(port,
153
                                        port->elem.out_sg[i].iov_base
154
                                          + port->iov_offset,
155
                                        buf_size);
156
            ret = info->have_data(port,
157
                                  port->elem.out_sg[i].iov_base
158
                                  + port->iov_offset,
159
                                  buf_size);
156 160
            if (ret < 0 && ret != -EAGAIN) {
157 161
                /* We don't handle any other type of errors here */
158 162
                abort();
......
309 313
static void handle_control_message(VirtIOSerial *vser, void *buf, size_t len)
310 314
{
311 315
    struct VirtIOSerialPort *port;
316
    struct VirtIOSerialPortInfo *info;
312 317
    struct virtio_console_control cpkt, *gcpkt;
313 318
    uint8_t *buffer;
314 319
    size_t buffer_len;
......
327 332
    if (!port && cpkt.event != VIRTIO_CONSOLE_DEVICE_READY)
328 333
        return;
329 334

  
335
    info = DO_UPCAST(VirtIOSerialPortInfo, qdev, port->dev.info);
336

  
330 337
    switch(cpkt.event) {
331 338
    case VIRTIO_CONSOLE_DEVICE_READY:
332 339
        if (!cpkt.value) {
......
356 363
         * this port is a console port so that the guest can hook it
357 364
         * up to hvc.
358 365
         */
359
        if (port->info->is_console) {
366
        if (info->is_console) {
360 367
            send_control_event(port, VIRTIO_CONSOLE_CONSOLE_PORT, 1);
361 368
        }
362 369

  
......
385 392
         * initialised. If some app is interested in knowing about
386 393
         * this event, let it know.
387 394
         */
388
        if (port->info->guest_ready) {
389
            port->info->guest_ready(port);
395
        if (info->guest_ready) {
396
            info->guest_ready(port);
390 397
        }
391 398
        break;
392 399

  
393 400
    case VIRTIO_CONSOLE_PORT_OPEN:
394 401
        port->guest_connected = cpkt.value;
395
        if (cpkt.value && port->info->guest_open) {
402
        if (cpkt.value && info->guest_open) {
396 403
            /* Send the guest opened notification if an app is interested */
397
            port->info->guest_open(port);
404
            info->guest_open(port);
398 405
        }
399 406

  
400
        if (!cpkt.value && port->info->guest_close) {
407
        if (!cpkt.value && info->guest_close) {
401 408
            /* Send the guest closed notification if an app is interested */
402
            port->info->guest_close(port);
409
            info->guest_close(port);
403 410
        }
404 411
        break;
405 412
    }
......
448 455
{
449 456
    VirtIOSerial *vser;
450 457
    VirtIOSerialPort *port;
458
    VirtIOSerialPortInfo *info;
451 459

  
452 460
    vser = DO_UPCAST(VirtIOSerial, vdev, vdev);
453 461
    port = find_port_by_vq(vser, vq);
462
    info = port ? DO_UPCAST(VirtIOSerialPortInfo, qdev, port->dev.info) : NULL;
454 463

  
455
    if (!port || !port->host_connected || !port->info->have_data) {
464
    if (!port || !port->host_connected || !info->have_data) {
456 465
        discard_vq_data(vq, vdev);
457 466
        return;
458 467
    }
......
756 765
        return -1;
757 766
    }
758 767

  
759
    port->info = info;
760 768
    ret = info->init(port);
761 769
    if (ret) {
762 770
        return ret;
......
787 795
static int virtser_port_qdev_exit(DeviceState *qdev)
788 796
{
789 797
    VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, qdev);
798
    VirtIOSerialPortInfo *info = DO_UPCAST(VirtIOSerialPortInfo, qdev,
799
                                           port->dev.info);
790 800
    VirtIOSerial *vser = port->vser;
791 801

  
792 802
    qemu_bh_delete(port->bh);
......
794 804

  
795 805
    QTAILQ_REMOVE(&vser->ports, port, next);
796 806

  
797
    if (port->info->exit)
798
        port->info->exit(port);
799

  
807
    if (info->exit) {
808
        info->exit(port);
809
    }
800 810
    return 0;
801 811
}
802 812

  

Also available in: Unified diff