int vhost_net_start(struct vhost_net *net,

                    VirtIODevice *dev)

{

    struct vhost_vring_file file = { };

    int r;

    if (net->dev.acked_features & (1 << VIRTIO_NET_F_MRG_RXBUF)) {

        tap_set_vnet_hdr_len(net->vc,

                             sizeof(struct virtio_net_hdr_mrg_rxbuf));

    }



    net->dev.nvqs = 2;

    net->dev.vqs = net->vqs;

    r = vhost_dev_start(&net->dev, dev);

    if (r < 0) {

        return r;

    }



    net->vc->info->poll(net->vc, false);

    qemu_set_fd_handler(net->backend, NULL, NULL, NULL);

    file.fd = net->backend;

    for (file.index = 0; file.index < net->dev.nvqs; ++file.index) {

        r = ioctl(net->dev.control, VHOST_NET_SET_BACKEND, &file);

        if (r < 0) {

            r = -errno;

            goto fail;

        }

    }

    return 0;

fail:

    file.fd = -1;

    while (--file.index >= 0) {

        int r = ioctl(net->dev.control, VHOST_NET_SET_BACKEND, &file);

        assert(r >= 0);

    }

    net->vc->info->poll(net->vc, true);

    vhost_dev_stop(&net->dev, dev);

    if (net->dev.acked_features & (1 << VIRTIO_NET_F_MRG_RXBUF)) {

        tap_set_vnet_hdr_len(net->vc, sizeof(struct virtio_net_hdr));

    }

    return r;

}

int vhost_net_start(struct vhost_net *net,

                    VirtIODevice *dev)

{

    struct vhost_vring_file file = { };

    int r;

    if (net->dev.acked_features & (1 << VIRTIO_NET_F_MRG_RXBUF)) {

        tap_set_vnet_hdr_len(net->vc,

                             sizeof(struct virtio_net_hdr_mrg_rxbuf));

    }



    net->dev.nvqs = 2;

    net->dev.vqs = net->vqs;

    r = vhost_dev_start(&net->dev, dev);

    if (r < 0) {

        return r;

    }



    net->vc->info->poll(net->vc, false);

    qemu_set_fd_handler(net->backend, NULL, NULL, NULL);

    file.fd = net->backend;

    for (file.index = 0; file.index < net->dev.nvqs; ++file.index) {

        r = ioctl(net->dev.control, VHOST_NET_SET_BACKEND, &file);

        if (r < 0) {

            r = -errno;

            goto fail;

        }

    }

    return 0;

fail:

    file.fd = -1;

    while (--file.index >= 0) {

        int r = ioctl(net->dev.control, VHOST_NET_SET_BACKEND, &file);

        assert(r >= 0);

    }

    net->vc->info->poll(net->vc, true);

    vhost_dev_stop(&net->dev, dev);

    if (net->dev.acked_features & (1 << VIRTIO_NET_F_MRG_RXBUF)) {

        tap_set_vnet_hdr_len(net->vc, sizeof(struct virtio_net_hdr));

    }

    return r;

}

int FUNC_0(struct vhost_net *VAR_0,

                    VirtIODevice *VAR_1)

{

    struct vhost_vring_file VAR_2 = { };

    int VAR_4;

    if (VAR_0->VAR_1.acked_features & (1 << VIRTIO_NET_F_MRG_RXBUF)) {

        tap_set_vnet_hdr_len(VAR_0->vc,

                             sizeof(struct virtio_net_hdr_mrg_rxbuf));

    }



    VAR_0->VAR_1.nvqs = 2;

    VAR_0->VAR_1.vqs = VAR_0->vqs;

    VAR_4 = vhost_dev_start(&VAR_0->VAR_1, VAR_1);

    if (VAR_4 < 0) {

        return VAR_4;

    }



    VAR_0->vc->info->poll(VAR_0->vc, false);

    qemu_set_fd_handler(VAR_0->backend, NULL, NULL, NULL);

    VAR_2.fd = VAR_0->backend;

    for (VAR_2.index = 0; VAR_2.index < VAR_0->VAR_1.nvqs; ++VAR_2.index) {

        VAR_4 = ioctl(VAR_0->VAR_1.control, VHOST_NET_SET_BACKEND, &VAR_2);

        if (VAR_4 < 0) {

            VAR_4 = -errno;

            goto fail;

        }

    }

    return 0;

fail:

    VAR_2.fd = -1;

    while (--VAR_2.index >= 0) {

        int VAR_4 = ioctl(VAR_0->VAR_1.control, VHOST_NET_SET_BACKEND, &VAR_2);

        assert(VAR_4 >= 0);

    }

    VAR_0->vc->info->poll(VAR_0->vc, true);

    vhost_dev_stop(&VAR_0->VAR_1, VAR_1);

    if (VAR_0->VAR_1.acked_features & (1 << VIRTIO_NET_F_MRG_RXBUF)) {

        tap_set_vnet_hdr_len(VAR_0->vc, sizeof(struct virtio_net_hdr));

    }

    return VAR_4;

}

int FUNC_0(struct vhost_net *VAR_0,
VirtIODevice *VAR_1)
{ struct vhost_vring_file VAR_2 = { }; int VAR_4; if (VAR_0->VAR_1.acked_features & (1 << VIRTIO_NET_F_MRG_RXBUF)) { tap_set_vnet_hdr_len(VAR_0->vc,
sizeof(struct virtio_net_hdr_mrg_rxbuf)); } VAR_0->VAR_1.nvqs = 2; VAR_0->VAR_1.vqs = VAR_0->vqs; VAR_4 = vhost_dev_start(&VAR_0->VAR_1, VAR_1); if (VAR_4 < 0) { return VAR_4; } VAR_0->vc->info->poll(VAR_0->vc, false); qemu_set_fd_handler(VAR_0->backend, NULL, NULL, NULL); VAR_2.fd = VAR_0->backend; for (VAR_2.index = 0; VAR_2.index < VAR_0->VAR_1.nvqs; ++VAR_2.index) { VAR_4 = ioctl(VAR_0->VAR_1.control, VHOST_NET_SET_BACKEND, &VAR_2); if (VAR_4 < 0) { VAR_4 = -errno; goto fail; } } return 0; fail:
VAR_2.fd = -1; while (--VAR_2.index >= 0) { int VAR_4 = ioctl(VAR_0->VAR_1.control, VHOST_NET_SET_BACKEND, &VAR_2); assert(VAR_4 >= 0); } VAR_0->vc->info->poll(VAR_0->vc, true); vhost_dev_stop(&VAR_0->VAR_1, VAR_1); if (VAR_0->VAR_1.acked_features & (1 << VIRTIO_NET_F_MRG_RXBUF)) { tap_set_vnet_hdr_len(VAR_0->vc, sizeof(struct virtio_net_hdr)); } return VAR_4; }