Пример #1
0
// Called from CGO code.
int dpdk_init(void)
{
    int i;

    engine_start_notify = (sem_t*)
                    malloc(sizeof(sem_t) * sysconf (_SC_NPROCESSORS_CONF));

    for (i = 0; i < sysconf (_SC_NPROCESSORS_CONF); i++)
        sem_init(&engine_start_notify[i], 0, 0);

    // Call dpdk_main from a thread
    pthread_create(&engine_thread, NULL, dpdk_init_worker, NULL);

    // Wait till all cores are in engine loop
    for (i = 0; i < sysconf (_SC_NPROCESSORS_CONF); i++)
        sem_wait(&engine_start_notify[i]);

    // Initialize the lock for virtio net linked list
    pthread_mutex_init(&ll_virtio_net_lock, NULL);

    // Initialize virtio framework
    if (rte_vhost_driver_callback_register(&virtio_ops) < 0) {
        log_crit( "rte_vhost_driver_callback_register failed\n");
        return -1;
    }

    // Run vhost-user listener
    if (pthread_create(&vhost_thread, NULL, vhost_worker, NULL) < 0) {
        log_crit( "Failed to create cmd thread\n");
        return -1;
    }

    log_info( "VHOST Socket is up and running!\n");
    return 0;
}
Пример #2
0
static struct vhost_scsi_ctrlr *
vhost_scsi_ctrlr_construct(const char *ctrlr_name)
{
	int ret;
	struct vhost_scsi_ctrlr *ctrlr;
	char *path;
	char cwd[PATH_MAX];

	/* always use current directory */
	path = getcwd(cwd, PATH_MAX);
	if (!path) {
		fprintf(stderr, "Cannot get current working directory\n");
		return NULL;
	}
	snprintf(dev_pathname, sizeof(dev_pathname), "%s/%s", path, ctrlr_name);

	if (access(dev_pathname, F_OK) != -1) {
		if (unlink(dev_pathname) != 0)
			rte_exit(EXIT_FAILURE, "Cannot remove %s.\n",
				 dev_pathname);
	}

	if (rte_vhost_driver_register(dev_pathname, 0) != 0) {
		fprintf(stderr, "socket %s already exists\n", dev_pathname);
		return NULL;
	}

	fprintf(stdout, "socket file: %s created\n", dev_pathname);

	ret = rte_vhost_driver_set_features(dev_pathname, VIRTIO_SCSI_FEATURES);
	if (ret != 0) {
		fprintf(stderr, "Set vhost driver features failed\n");
		return NULL;
	}

	ctrlr = rte_zmalloc(NULL, sizeof(*ctrlr), RTE_CACHE_LINE_SIZE);
	if (!ctrlr)
		return NULL;

	rte_vhost_driver_callback_register(dev_pathname,
					   &vhost_scsi_device_ops);

	return ctrlr;
}