int vhost_dev_init(struct vhost_dev *hdev, void *opaque,

                   VhostBackendType backend_type, uint32_t busyloop_timeout)

{

    uint64_t features;

    int i, r;



    hdev->migration_blocker = NULL;



    r = vhost_set_backend_type(hdev, backend_type);

    assert(r >= 0);



    r = hdev->vhost_ops->vhost_backend_init(hdev, opaque);

    if (r < 0) {

        goto fail;

    }



    if (used_memslots > hdev->vhost_ops->vhost_backend_memslots_limit(hdev)) {

        fprintf(stderr, "vhost backend memory slots limit is less"

                " than current number of present memory slots\n");

        r = -1;

        goto fail;

    }

    QLIST_INSERT_HEAD(&vhost_devices, hdev, entry);



    r = hdev->vhost_ops->vhost_set_owner(hdev);

    if (r < 0) {

        goto fail;

    }



    r = hdev->vhost_ops->vhost_get_features(hdev, &features);

    if (r < 0) {

        goto fail;

    }



    for (i = 0; i < hdev->nvqs; ++i) {

        r = vhost_virtqueue_init(hdev, hdev->vqs + i, hdev->vq_index + i);

        if (r < 0) {

            goto fail_vq;

        }

    }



    if (busyloop_timeout) {

        for (i = 0; i < hdev->nvqs; ++i) {

            r = vhost_virtqueue_set_busyloop_timeout(hdev, hdev->vq_index + i,

                                                     busyloop_timeout);

            if (r < 0) {

                goto fail_busyloop;

            }

        }

    }



    hdev->features = features;



    hdev->memory_listener = (MemoryListener) {

        .begin = vhost_begin,

        .commit = vhost_commit,

        .region_add = vhost_region_add,

        .region_del = vhost_region_del,

        .region_nop = vhost_region_nop,

        .log_start = vhost_log_start,

        .log_stop = vhost_log_stop,

        .log_sync = vhost_log_sync,

        .log_global_start = vhost_log_global_start,

        .log_global_stop = vhost_log_global_stop,

        .eventfd_add = vhost_eventfd_add,

        .eventfd_del = vhost_eventfd_del,

        .priority = 10

    };



    if (hdev->migration_blocker == NULL) {

        if (!(hdev->features & (0x1ULL << VHOST_F_LOG_ALL))) {

            error_setg(&hdev->migration_blocker,

                       "Migration disabled: vhost lacks VHOST_F_LOG_ALL feature.");

        } else if (!qemu_memfd_check()) {

            error_setg(&hdev->migration_blocker,

                       "Migration disabled: failed to allocate shared memory");

        }

    }



    if (hdev->migration_blocker != NULL) {

        migrate_add_blocker(hdev->migration_blocker);

    }



    hdev->mem = g_malloc0(offsetof(struct vhost_memory, regions));

    hdev->n_mem_sections = 0;

    hdev->mem_sections = NULL;

    hdev->log = NULL;

    hdev->log_size = 0;

    hdev->log_enabled = false;

    hdev->started = false;

    hdev->memory_changed = false;

    memory_listener_register(&hdev->memory_listener, &address_space_memory);

    return 0;

fail_busyloop:

    while (--i >= 0) {

        vhost_virtqueue_set_busyloop_timeout(hdev, hdev->vq_index + i, 0);

    }

    i = hdev->nvqs;

fail_vq:

    while (--i >= 0) {

        vhost_virtqueue_cleanup(hdev->vqs + i);

    }

fail:

    r = -errno;

    hdev->vhost_ops->vhost_backend_cleanup(hdev);

    QLIST_REMOVE(hdev, entry);

    return r;

}

int vhost_dev_init(struct vhost_dev *hdev, void *opaque,

                   VhostBackendType backend_type, uint32_t busyloop_timeout)

{

    uint64_t features;

    int i, r;



    hdev->migration_blocker = NULL;



    r = vhost_set_backend_type(hdev, backend_type);

    assert(r >= 0);



    r = hdev->vhost_ops->vhost_backend_init(hdev, opaque);

    if (r < 0) {

        goto fail;

    }



    if (used_memslots > hdev->vhost_ops->vhost_backend_memslots_limit(hdev)) {

        fprintf(stderr, "vhost backend memory slots limit is less"

                " than current number of present memory slots\n");

        r = -1;

        goto fail;

    }

    QLIST_INSERT_HEAD(&vhost_devices, hdev, entry);



    r = hdev->vhost_ops->vhost_set_owner(hdev);

    if (r < 0) {

        goto fail;

    }



    r = hdev->vhost_ops->vhost_get_features(hdev, &features);

    if (r < 0) {

        goto fail;

    }



    for (i = 0; i < hdev->nvqs; ++i) {

        r = vhost_virtqueue_init(hdev, hdev->vqs + i, hdev->vq_index + i);

        if (r < 0) {

            goto fail_vq;

        }

    }



    if (busyloop_timeout) {

        for (i = 0; i < hdev->nvqs; ++i) {

            r = vhost_virtqueue_set_busyloop_timeout(hdev, hdev->vq_index + i,

                                                     busyloop_timeout);

            if (r < 0) {

                goto fail_busyloop;

            }

        }

    }



    hdev->features = features;



    hdev->memory_listener = (MemoryListener) {

        .begin = vhost_begin,

        .commit = vhost_commit,

        .region_add = vhost_region_add,

        .region_del = vhost_region_del,

        .region_nop = vhost_region_nop,

        .log_start = vhost_log_start,

        .log_stop = vhost_log_stop,

        .log_sync = vhost_log_sync,

        .log_global_start = vhost_log_global_start,

        .log_global_stop = vhost_log_global_stop,

        .eventfd_add = vhost_eventfd_add,

        .eventfd_del = vhost_eventfd_del,

        .priority = 10

    };



    if (hdev->migration_blocker == NULL) {

        if (!(hdev->features & (0x1ULL << VHOST_F_LOG_ALL))) {

            error_setg(&hdev->migration_blocker,

                       "Migration disabled: vhost lacks VHOST_F_LOG_ALL feature.");

        } else if (!qemu_memfd_check()) {

            error_setg(&hdev->migration_blocker,

                       "Migration disabled: failed to allocate shared memory");

        }

    }



    if (hdev->migration_blocker != NULL) {

        migrate_add_blocker(hdev->migration_blocker);

    }



    hdev->mem = g_malloc0(offsetof(struct vhost_memory, regions));

    hdev->n_mem_sections = 0;

    hdev->mem_sections = NULL;

    hdev->log = NULL;

    hdev->log_size = 0;

    hdev->log_enabled = false;

    hdev->started = false;

    hdev->memory_changed = false;

    memory_listener_register(&hdev->memory_listener, &address_space_memory);

    return 0;

fail_busyloop:

    while (--i >= 0) {

        vhost_virtqueue_set_busyloop_timeout(hdev, hdev->vq_index + i, 0);

    }

    i = hdev->nvqs;

fail_vq:

    while (--i >= 0) {

        vhost_virtqueue_cleanup(hdev->vqs + i);

    }

fail:

    r = -errno;

    hdev->vhost_ops->vhost_backend_cleanup(hdev);

    QLIST_REMOVE(hdev, entry);

    return r;

}

    QLIST_INSERT_HEAD(&vhost_devices, hdev, entry);     QLIST_REMOVE(hdev, entry);
int FUNC_0(struct vhost_dev *VAR_0, void *VAR_1,

                   VhostBackendType VAR_2, uint32_t VAR_3)

{

    uint64_t features;

    int VAR_4, VAR_5;



    VAR_0->migration_blocker = NULL;



    VAR_5 = vhost_set_backend_type(VAR_0, VAR_2);

    assert(VAR_5 >= 0);



    VAR_5 = VAR_0->vhost_ops->vhost_backend_init(VAR_0, VAR_1);

    if (VAR_5 < 0) {

        goto fail;

    }



    if (used_memslots > VAR_0->vhost_ops->vhost_backend_memslots_limit(VAR_0)) {

        fprintf(stderr, "vhost backend memory slots limit is less"

                " than current number of present memory slots\n");

        VAR_5 = -1;

        goto fail;

    }

    QLIST_INSERT_HEAD(&vhost_devices, VAR_0, entry);



    VAR_5 = VAR_0->vhost_ops->vhost_set_owner(VAR_0);

    if (VAR_5 < 0) {

        goto fail;

    }



    VAR_5 = VAR_0->vhost_ops->vhost_get_features(VAR_0, &features);

    if (VAR_5 < 0) {

        goto fail;

    }



    for (VAR_4 = 0; VAR_4 < VAR_0->nvqs; ++VAR_4) {

        VAR_5 = vhost_virtqueue_init(VAR_0, VAR_0->vqs + VAR_4, VAR_0->vq_index + VAR_4);

        if (VAR_5 < 0) {

            goto fail_vq;

        }

    }



    if (VAR_3) {

        for (VAR_4 = 0; VAR_4 < VAR_0->nvqs; ++VAR_4) {

            VAR_5 = vhost_virtqueue_set_busyloop_timeout(VAR_0, VAR_0->vq_index + VAR_4,

                                                     VAR_3);

            if (VAR_5 < 0) {

                goto fail_busyloop;

            }

        }

    }



    VAR_0->features = features;



    VAR_0->memory_listener = (MemoryListener) {

        .begin = vhost_begin,

        .commit = vhost_commit,

        .region_add = vhost_region_add,

        .region_del = vhost_region_del,

        .region_nop = vhost_region_nop,

        .log_start = vhost_log_start,

        .log_stop = vhost_log_stop,

        .log_sync = vhost_log_sync,

        .log_global_start = vhost_log_global_start,

        .log_global_stop = vhost_log_global_stop,

        .eventfd_add = vhost_eventfd_add,

        .eventfd_del = vhost_eventfd_del,

        .priority = 10

    };



    if (VAR_0->migration_blocker == NULL) {

        if (!(VAR_0->features & (0x1ULL << VHOST_F_LOG_ALL))) {

            error_setg(&VAR_0->migration_blocker,

                       "Migration disabled: vhost lacks VHOST_F_LOG_ALL feature.");

        } else if (!qemu_memfd_check()) {

            error_setg(&VAR_0->migration_blocker,

                       "Migration disabled: failed to allocate shared memory");

        }

    }



    if (VAR_0->migration_blocker != NULL) {

        migrate_add_blocker(VAR_0->migration_blocker);

    }



    VAR_0->mem = g_malloc0(offsetof(struct vhost_memory, regions));

    VAR_0->n_mem_sections = 0;

    VAR_0->mem_sections = NULL;

    VAR_0->log = NULL;

    VAR_0->log_size = 0;

    VAR_0->log_enabled = false;

    VAR_0->started = false;

    VAR_0->memory_changed = false;

    memory_listener_register(&VAR_0->memory_listener, &address_space_memory);

    return 0;

fail_busyloop:

    while (--VAR_4 >= 0) {

        vhost_virtqueue_set_busyloop_timeout(VAR_0, VAR_0->vq_index + VAR_4, 0);

    }

    VAR_4 = VAR_0->nvqs;

fail_vq:

    while (--VAR_4 >= 0) {

        vhost_virtqueue_cleanup(VAR_0->vqs + VAR_4);

    }

fail:

    VAR_5 = -errno;

    VAR_0->vhost_ops->vhost_backend_cleanup(VAR_0);

    QLIST_REMOVE(VAR_0, entry);

    return VAR_5;

}

int FUNC_0(struct vhost_dev *VAR_0, void *VAR_1,
VhostBackendType VAR_2, uint32_t VAR_3)
{ uint64_t features; int VAR_4, VAR_5; VAR_0->migration_blocker = NULL; VAR_5 = vhost_set_backend_type(VAR_0, VAR_2); assert(VAR_5 >= 0); VAR_5 = VAR_0->vhost_ops->vhost_backend_init(VAR_0, VAR_1); if (VAR_5 < 0) { goto fail; } if (used_memslots > VAR_0->vhost_ops->vhost_backend_memslots_limit(VAR_0)) { fprintf(stderr, "vhost backend memory slots limit is less"
" than current number of present memory slots\n"); VAR_5 = -1; goto fail; } QLIST_INSERT_HEAD(&vhost_devices, VAR_0, entry); VAR_5 = VAR_0->vhost_ops->vhost_set_owner(VAR_0); if (VAR_5 < 0) { goto fail; } VAR_5 = VAR_0->vhost_ops->vhost_get_features(VAR_0, &features); if (VAR_5 < 0) { goto fail; } for (VAR_4 = 0; VAR_4 < VAR_0->nvqs; ++VAR_4) { VAR_5 = vhost_virtqueue_init(VAR_0, VAR_0->vqs + VAR_4, VAR_0->vq_index + VAR_4); if (VAR_5 < 0) { goto fail_vq; } } if (VAR_3) { for (VAR_4 = 0; VAR_4 < VAR_0->nvqs; ++VAR_4) { VAR_5 = vhost_virtqueue_set_busyloop_timeout(VAR_0, VAR_0->vq_index + VAR_4,
VAR_3); if (VAR_5 < 0) { goto fail_busyloop; } } } VAR_0->features = features; VAR_0->memory_listener = (MemoryListener) { .begin = vhost_begin,
.commit = vhost_commit,
.region_add = vhost_region_add,
.region_del = vhost_region_del,
.region_nop = vhost_region_nop,
.log_start = vhost_log_start,
.log_stop = vhost_log_stop,
.log_sync = vhost_log_sync,
.log_global_start = vhost_log_global_start,
.log_global_stop = vhost_log_global_stop,
.eventfd_add = vhost_eventfd_add,
.eventfd_del = vhost_eventfd_del,
.priority = 10
}; if (VAR_0->migration_blocker == NULL) { if (!(VAR_0->features & (0x1ULL << VHOST_F_LOG_ALL))) { error_setg(&VAR_0->migration_blocker,
"Migration disabled: vhost lacks VHOST_F_LOG_ALL feature."); } else if (!qemu_memfd_check()) { error_setg(&VAR_0->migration_blocker,
"Migration disabled: failed to allocate shared memory"); } } if (VAR_0->migration_blocker != NULL) { migrate_add_blocker(VAR_0->migration_blocker); } VAR_0->mem = g_malloc0(offsetof(struct vhost_memory, regions)); VAR_0->n_mem_sections = 0; VAR_0->mem_sections = NULL; VAR_0->log = NULL; VAR_0->log_size = 0; VAR_0->log_enabled = false; VAR_0->started = false; VAR_0->memory_changed = false; memory_listener_register(&VAR_0->memory_listener, &address_space_memory); return 0; fail_busyloop:
while (--VAR_4 >= 0) { vhost_virtqueue_set_busyloop_timeout(VAR_0, VAR_0->vq_index + VAR_4, 0); } VAR_4 = VAR_0->nvqs; fail_vq:
while (--VAR_4 >= 0) { vhost_virtqueue_cleanup(VAR_0->vqs + VAR_4); } fail:
VAR_5 = -errno; VAR_0->vhost_ops->vhost_backend_cleanup(VAR_0); QLIST_REMOVE(VAR_0, entry); return VAR_5; }