int vhost_dev_init(struct vhost_dev *hdev, int devfd, bool force)

{

    uint64_t features;

    int r;

    if (devfd >= 0) {

        hdev->control = devfd;

    } else {

        hdev->control = open("/dev/vhost-net", O_RDWR);

        if (hdev->control < 0) {

            return -errno;

        }

    }

    r = ioctl(hdev->control, VHOST_SET_OWNER, NULL);

    if (r < 0) {

        goto fail;

    }



    r = ioctl(hdev->control, VHOST_GET_FEATURES, &features);

    if (r < 0) {

        goto fail;

    }

    hdev->features = features;



    hdev->client.set_memory = vhost_client_set_memory;

    hdev->client.sync_dirty_bitmap = vhost_client_sync_dirty_bitmap;

    hdev->client.migration_log = vhost_client_migration_log;

    hdev->client.log_start = NULL;

    hdev->client.log_stop = NULL;

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

    hdev->log = NULL;

    hdev->log_size = 0;

    hdev->log_enabled = false;

    hdev->started = false;

    cpu_register_phys_memory_client(&hdev->client);

    hdev->force = force;

    return 0;

fail:

    r = -errno;

    close(hdev->control);

    return r;

}

int vhost_dev_init(struct vhost_dev *hdev, int devfd, bool force)

{

    uint64_t features;

    int r;

    if (devfd >= 0) {

        hdev->control = devfd;

    } else {

        hdev->control = open("/dev/vhost-net", O_RDWR);

        if (hdev->control < 0) {

            return -errno;

        }

    }

    r = ioctl(hdev->control, VHOST_SET_OWNER, NULL);

    if (r < 0) {

        goto fail;

    }



    r = ioctl(hdev->control, VHOST_GET_FEATURES, &features);

    if (r < 0) {

        goto fail;

    }

    hdev->features = features;



    hdev->client.set_memory = vhost_client_set_memory;

    hdev->client.sync_dirty_bitmap = vhost_client_sync_dirty_bitmap;

    hdev->client.migration_log = vhost_client_migration_log;

    hdev->client.log_start = NULL;

    hdev->client.log_stop = NULL;

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

    hdev->log = NULL;

    hdev->log_size = 0;

    hdev->log_enabled = false;

    hdev->started = false;

    cpu_register_phys_memory_client(&hdev->client);

    hdev->force = force;

    return 0;

fail:

    r = -errno;

    close(hdev->control);

    return r;

}

    hdev->client.set_memory = vhost_client_set_memory;     hdev->client.sync_dirty_bitmap = vhost_client_sync_dirty_bitmap;     hdev->client.migration_log = vhost_client_migration_log;     hdev->client.log_start = NULL;     hdev->client.log_stop = NULL;     cpu_register_phys_memory_client(&hdev->client);
int FUNC_0(struct vhost_dev *VAR_0, int VAR_1, bool VAR_2)

{

    uint64_t features;

    int VAR_3;

    if (VAR_1 >= 0) {

        VAR_0->control = VAR_1;

    } else {

        VAR_0->control = open("/dev/vhost-net", O_RDWR);

        if (VAR_0->control < 0) {

            return -errno;

        }

    }

    VAR_3 = ioctl(VAR_0->control, VHOST_SET_OWNER, NULL);

    if (VAR_3 < 0) {

        goto fail;

    }



    VAR_3 = ioctl(VAR_0->control, VHOST_GET_FEATURES, &features);

    if (VAR_3 < 0) {

        goto fail;

    }

    VAR_0->features = features;



    VAR_0->client.set_memory = vhost_client_set_memory;

    VAR_0->client.sync_dirty_bitmap = vhost_client_sync_dirty_bitmap;

    VAR_0->client.migration_log = vhost_client_migration_log;

    VAR_0->client.log_start = NULL;

    VAR_0->client.log_stop = NULL;

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

    VAR_0->log = NULL;

    VAR_0->log_size = 0;

    VAR_0->log_enabled = false;

    VAR_0->started = false;

    cpu_register_phys_memory_client(&VAR_0->client);

    VAR_0->VAR_2 = VAR_2;

    return 0;

fail:

    VAR_3 = -errno;

    close(VAR_0->control);

    return VAR_3;

}

int FUNC_0(struct vhost_dev *VAR_0, int VAR_1, bool VAR_2)
{ uint64_t features; int VAR_3; if (VAR_1 >= 0) { VAR_0->control = VAR_1; } else { VAR_0->control = open("/dev/vhost-net", O_RDWR); if (VAR_0->control < 0) { return -errno; } } VAR_3 = ioctl(VAR_0->control, VHOST_SET_OWNER, NULL); if (VAR_3 < 0) { goto fail; } VAR_3 = ioctl(VAR_0->control, VHOST_GET_FEATURES, &features); if (VAR_3 < 0) { goto fail; } VAR_0->features = features; VAR_0->client.set_memory = vhost_client_set_memory; VAR_0->client.sync_dirty_bitmap = vhost_client_sync_dirty_bitmap; VAR_0->client.migration_log = vhost_client_migration_log; VAR_0->client.log_start = NULL; VAR_0->client.log_stop = NULL; VAR_0->mem = g_malloc0(offsetof(struct vhost_memory, regions)); VAR_0->log = NULL; VAR_0->log_size = 0; VAR_0->log_enabled = false; VAR_0->started = false; cpu_register_phys_memory_client(&VAR_0->client); VAR_0->VAR_2 = VAR_2; return 0; fail:
VAR_3 = -errno; close(VAR_0->control); return VAR_3; }