static int vhost_net_start_one(struct vhost_net *net,

                               VirtIODevice *dev,

                               int vq_index)

{

    struct vhost_vring_file file = { };

    int r;



    if (net->dev.started) {

        return 0;

    }



    net->dev.nvqs = 2;

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

    net->dev.vq_index = vq_index;



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

    if (r < 0) {

        goto fail_notifiers;

    }



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

    if (r < 0) {

        goto fail_start;

    }



    if (net->nc->info->poll) {

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

    }



    if (net->nc->info->type == NET_CLIENT_OPTIONS_KIND_TAP) {

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

        file.fd = net->backend;

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

            const VhostOps *vhost_ops = net->dev.vhost_ops;

            r = vhost_ops->vhost_call(&net->dev, VHOST_NET_SET_BACKEND,

                                      &file);

            if (r < 0) {

                r = -errno;

                goto fail;

            }

        }

    }

    return 0;

fail:

    file.fd = -1;

    if (net->nc->info->type == NET_CLIENT_OPTIONS_KIND_TAP) {

        while (file.index-- > 0) {

            const VhostOps *vhost_ops = net->dev.vhost_ops;

            int r = vhost_ops->vhost_call(&net->dev, VHOST_NET_SET_BACKEND,

                                          &file);

            assert(r >= 0);

        }

    }

    if (net->nc->info->poll) {

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

    }

    vhost_dev_stop(&net->dev, dev);

fail_start:

    vhost_dev_disable_notifiers(&net->dev, dev);

fail_notifiers:

    return r;

}

static int vhost_net_start_one(struct vhost_net *net,

                               VirtIODevice *dev,

                               int vq_index)

{

    struct vhost_vring_file file = { };

    int r;



    if (net->dev.started) {

        return 0;

    }



    net->dev.nvqs = 2;

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

    net->dev.vq_index = vq_index;



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

    if (r < 0) {

        goto fail_notifiers;

    }



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

    if (r < 0) {

        goto fail_start;

    }



    if (net->nc->info->poll) {

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

    }



    if (net->nc->info->type == NET_CLIENT_OPTIONS_KIND_TAP) {

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

        file.fd = net->backend;

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

            const VhostOps *vhost_ops = net->dev.vhost_ops;

            r = vhost_ops->vhost_call(&net->dev, VHOST_NET_SET_BACKEND,

                                      &file);

            if (r < 0) {

                r = -errno;

                goto fail;

            }

        }

    }

    return 0;

fail:

    file.fd = -1;

    if (net->nc->info->type == NET_CLIENT_OPTIONS_KIND_TAP) {

        while (file.index-- > 0) {

            const VhostOps *vhost_ops = net->dev.vhost_ops;

            int r = vhost_ops->vhost_call(&net->dev, VHOST_NET_SET_BACKEND,

                                          &file);

            assert(r >= 0);

        }

    }

    if (net->nc->info->poll) {

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

    }

    vhost_dev_stop(&net->dev, dev);

fail_start:

    vhost_dev_disable_notifiers(&net->dev, dev);

fail_notifiers:

    return r;

}

static int FUNC_0(struct vhost_net *VAR_0,

                               VirtIODevice *VAR_1,

                               int VAR_2)

{

    struct vhost_vring_file VAR_3 = { };

    int VAR_6;



    if (VAR_0->VAR_1.started) {

        return 0;

    }



    VAR_0->VAR_1.nvqs = 2;

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

    VAR_0->VAR_1.VAR_2 = VAR_2;



    VAR_6 = vhost_dev_enable_notifiers(&VAR_0->VAR_1, VAR_1);

    if (VAR_6 < 0) {

        goto fail_notifiers;

    }



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

    if (VAR_6 < 0) {

        goto fail_start;

    }



    if (VAR_0->nc->info->poll) {

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

    }



    if (VAR_0->nc->info->type == NET_CLIENT_OPTIONS_KIND_TAP) {

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

        VAR_3.fd = VAR_0->backend;

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

            const VhostOps *VAR_5 = VAR_0->VAR_1.VAR_5;

            VAR_6 = VAR_5->vhost_call(&VAR_0->VAR_1, VHOST_NET_SET_BACKEND,

                                      &VAR_3);

            if (VAR_6 < 0) {

                VAR_6 = -errno;

                goto fail;

            }

        }

    }

    return 0;

fail:

    VAR_3.fd = -1;

    if (VAR_0->nc->info->type == NET_CLIENT_OPTIONS_KIND_TAP) {

        while (VAR_3.index-- > 0) {

            const VhostOps *VAR_5 = VAR_0->VAR_1.VAR_5;

            int VAR_6 = VAR_5->vhost_call(&VAR_0->VAR_1, VHOST_NET_SET_BACKEND,

                                          &VAR_3);

            assert(VAR_6 >= 0);

        }

    }

    if (VAR_0->nc->info->poll) {

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

    }

    vhost_dev_stop(&VAR_0->VAR_1, VAR_1);

fail_start:

    vhost_dev_disable_notifiers(&VAR_0->VAR_1, VAR_1);

fail_notifiers:

    return VAR_6;

}

static int FUNC_0(struct vhost_net *VAR_0,
VirtIODevice *VAR_1,
int VAR_2)
{ struct vhost_vring_file VAR_3 = { }; int VAR_6; if (VAR_0->VAR_1.started) { return 0; } VAR_0->VAR_1.nvqs = 2; VAR_0->VAR_1.vqs = VAR_0->vqs; VAR_0->VAR_1.VAR_2 = VAR_2; VAR_6 = vhost_dev_enable_notifiers(&VAR_0->VAR_1, VAR_1); if (VAR_6 < 0) { goto fail_notifiers; } VAR_6 = vhost_dev_start(&VAR_0->VAR_1, VAR_1); if (VAR_6 < 0) { goto fail_start; } if (VAR_0->nc->info->poll) { VAR_0->nc->info->poll(VAR_0->nc, false); } if (VAR_0->nc->info->type == NET_CLIENT_OPTIONS_KIND_TAP) { qemu_set_fd_handler(VAR_0->backend, NULL, NULL, NULL); VAR_3.fd = VAR_0->backend; for (VAR_3.index = 0; VAR_3.index < VAR_0->VAR_1.nvqs; ++VAR_3.index) { const VhostOps *VAR_5 = VAR_0->VAR_1.VAR_5; VAR_6 = VAR_5->vhost_call(&VAR_0->VAR_1, VHOST_NET_SET_BACKEND,
&VAR_3); if (VAR_6 < 0) { VAR_6 = -errno; goto fail; } } } return 0; fail:
VAR_3.fd = -1; if (VAR_0->nc->info->type == NET_CLIENT_OPTIONS_KIND_TAP) { while (VAR_3.index-- > 0) { const VhostOps *VAR_5 = VAR_0->VAR_1.VAR_5; int VAR_6 = VAR_5->vhost_call(&VAR_0->VAR_1, VHOST_NET_SET_BACKEND,
&VAR_3); assert(VAR_6 >= 0); } } if (VAR_0->nc->info->poll) { VAR_0->nc->info->poll(VAR_0->nc, true); } vhost_dev_stop(&VAR_0->VAR_1, VAR_1); fail_start:
vhost_dev_disable_notifiers(&VAR_0->VAR_1, VAR_1); fail_notifiers:
return VAR_6; }