Exemplo n.º 1
0
/*---------------------------------------------------------------------------*/
static int xio_server_main(void *data)
{
	struct xio_server		*server;
	struct xio_context_params	ctx_params;

	init_xio_rdma_common_test();

	memset(&ctx_params, 0, sizeof(ctx_params));
	ctx_params.flags = XIO_LOOP_GIVEN_THREAD;
	ctx_params.worker = current;

	test_params.ctx = xio_context_create(&ctx_params, 0, 0);
	xio_assert(test_params.ctx);

	session_ops.on_session_event = on_session_event;
	server = xio_bind(test_params.ctx, &session_ops,
			  url, NULL, 0, NULL);
	xio_assert(server);
	pr_info("listen to %s\n", url);

	xio_context_run_loop(test_params.ctx);

	/* normal exit phase */
	pr_info("exit signaled\n");

	/* free the server */
	xio_unbind(server);
	xio_context_destroy(test_params.ctx);
	fini_xio_rdma_common_test();

	complete_and_exit(&cleanup_complete, 0);

	return 0;
}
Exemplo n.º 2
0
int xio_create_listen_ports(const char *bindaddr, int port,
			    int (*callback)(int fd, void *), bool rdma)
{
	char url[256];
	struct xio_server *server;
	struct server_data *server_data;
	int xio_fd;

	server_data = xzalloc(sizeof(*server_data));
	server_data->ctx = xio_get_main_ctx();

	snprintf(url, 256, rdma ? "rdma://%s:%d" : "tcp://%s:%d",
		bindaddr ? bindaddr : "0.0.0.0", port);
	sd_info("accelio binding url: %s", url);

	/* bind a listener server to a portal/url */
	server = xio_bind(server_data->ctx, &portal_server_ops, url, NULL, 0,
			  server_data);
	if (server == NULL) {
		sd_err("xio_bind() failed");
		return -1;
	}

	xio_fd = xio_context_get_poll_fd(server_data->ctx);
	register_event(xio_fd, xio_server_handler, server_data);

	return 0;
}
Exemplo n.º 3
0
/*---------------------------------------------------------------------------*/
static void *balancer_server_cb(void *data)
{
	struct xio_server	*server;	/* server portal */
	struct server_data	*server_data = data;
	char			url[256];
	int			retval = 0;

	/* create thread context for the client */
	server_data->ctx = xio_context_create(NULL,
				server_data->user_param->poll_timeout, -1);

	/* create url to connect to */
	sprintf(url, "%s://*:%d",
		server_data->user_param->transport,
		server_data->user_param->server_port);

	/* bind a listener server to a portal/url */
	server = xio_bind(server_data->ctx, &server_ops, url,
			  NULL, 0, server_data);
	if (server == NULL)
		goto cleanup;

	server_data->running = 1;
	xio_context_run_loop(server_data->ctx, XIO_INFINITE);

	/* free the server */
	xio_unbind(server);
cleanup:
	/* free the context */
	xio_context_destroy(server_data->ctx);

	pthread_exit(&retval);
}
Exemplo n.º 4
0
/*---------------------------------------------------------------------------*/
static void *portal_server_cb(void *data)
{
	struct hw_thread_data	*tdata = data;
	cpu_set_t		cpuset;
	struct xio_context	*ctx;
	struct xio_server	*server;
	char			str[128];
	int			i;

	/* set affinity to thread */

	CPU_ZERO(&cpuset);
	CPU_SET(tdata->affinity, &cpuset);

	pthread_setaffinity_np(tdata->thread_id, sizeof(cpu_set_t), &cpuset);

	/* open default event loop */
	tdata->loop = xio_ev_loop_init();

	/* create thread context for the client */
	ctx = xio_ctx_open(NULL, tdata->loop, 0);

	/* bind a listener server to a portal/url */
	printf("thread [%d] - listen:%s\n", tdata->affinity, tdata->portal);
	server = xio_bind(ctx, &portal_server_ops, tdata->portal, NULL, 0, tdata);
	if (server == NULL)
		goto cleanup;

	sprintf(str,"hello world header response from thread %d",
	        tdata->affinity);
	/* create "hello world" message */
	for (i = 0; i <QUEUE_DEPTH; i++) {
		tdata->rsp[i].out.header.iov_base = strdup(str);
		tdata->rsp[i].out.header.iov_len =
			strlen(tdata->rsp[i].out.header.iov_base);
	}

	/* the default xio supplied main loop */
	xio_ev_loop_run(tdata->loop);

	/* normal exit phase */
	fprintf(stdout, "exit signaled\n");

	/* detach the server */
	xio_unbind(server);

	/* free the message */
	for (i = 0; i <QUEUE_DEPTH; i++)
		free(tdata->rsp[i].out.header.iov_base);

cleanup:
	/* free the context */
	xio_ctx_close(ctx);

	/* destroy the default loop */
	xio_ev_loop_destroy(tdata->loop);

	return NULL;
}
Exemplo n.º 5
0
/*---------------------------------------------------------------------------*/
int main(int argc, char *argv[])
{
	struct xio_server	*server;	/* server portal */
	struct server_data	*server_data;
	char			url[256];
	int			i;
	uint16_t		port = atoi(argv[2]);


	server_data = calloc(1, sizeof(*server_data));
	if (!server_data)
		return -1;

	xio_init();

	/* create thread context for the client */
	server_data->ctx	= xio_context_create(NULL, 0);

	/* create url to connect to */
	sprintf(url, "rdma://%s:%d", argv[1], port);
	/* bind a listener server to a portal/url */
	server = xio_bind(server_data->ctx, &server_ops,
			  url, NULL, 0, server_data);
	if (server == NULL)
		goto cleanup;


	/* spawn portals */
	for (i = 0; i < MAX_THREADS; i++) {
		server_data->tdata[i].affinity = i+1;
		port += 1;
		sprintf(server_data->tdata[i].portal, "rdma://%s:%d",
			argv[1], port);
		pthread_create(&server_data->tdata[i].thread_id, NULL,
			       portal_server_cb, &server_data->tdata[i]);
	}

	xio_context_run_loop(server_data->ctx, XIO_INFINITE);

	/* normal exit phase */
	fprintf(stdout, "exit signaled\n");

	/* join the threads */
	for (i = 0; i < MAX_THREADS; i++)
		pthread_join(server_data->tdata[i].thread_id, NULL);

	/* free the server */
	xio_unbind(server);
cleanup:
	/* free the context */
	xio_context_destroy(server_data->ctx);

	xio_shutdown();

	free(server_data);

	return 0;
}
Exemplo n.º 6
0
/*---------------------------------------------------------------------------*/
static void *portal_server_cb(void *data)
{
    struct thread_data	*tdata = (struct thread_data *)data;
    cpu_set_t		cpuset;
    struct xio_server	*server;
    int			retval = 0;

    /* set affinity to thread */

    CPU_ZERO(&cpuset);
    CPU_SET(tdata->affinity, &cpuset);

    pthread_setaffinity_np(tdata->thread_id, sizeof(cpu_set_t), &cpuset);

    /* prepare data for the cuurent thread */
    tdata->pool = msg_pool_alloc(MAX_POOL_SIZE, 0, 1);
    if (tdata->pool == NULL) {
        retval = -1;
        goto exit;
    }

    /* create thread context for the client */
    tdata->ctx = xio_context_create(NULL, test_config.poll_timeout,
                                    tdata->affinity);

    /* bind a listener server to a portal/url */
    printf("thread [%d] - listen:%s\n", tdata->affinity, tdata->portal);
    server = xio_bind(tdata->ctx, &portal_server_ops, tdata->portal,
                      NULL, 0, tdata);
    if (server == NULL) {
        printf("**** Error - xio_bind failed. %s\n",
               xio_strerror(xio_errno()));
        retval = -1;
        goto cleanup;
    }

    /* the default xio supplied main loop */
    xio_context_run_loop(tdata->ctx, XIO_INFINITE);

    /* normal exit phase */
    fprintf(stdout, "thread [%d] - exit signaled\n", tdata->affinity);

    /* detach the server */
    xio_unbind(server);

    if (tdata->pool)
        msg_pool_free(tdata->pool);

    if (tdata->reg_mem.addr)
        xio_mem_free(&tdata->reg_mem);

cleanup:
    /* free the context */
    xio_context_destroy(tdata->ctx);
exit:
    pthread_exit((void *)(unsigned long)retval);
}
Exemplo n.º 7
0
/*---------------------------------------------------------------------------*/
int main(int argc, char *argv[])
{
	struct xio_server	*server;	/* server portal */
	struct hw_server_data	server_data;
	char			url[256];
	struct xio_context	*ctx;
	void			*loop;
	int			i;
	uint16_t		port = atoi(argv[2]);


	memset(&server_data, 0, sizeof(server_data));

	/* open default event loop */
	loop	= xio_ev_loop_init();

	/* create thread context for the client */
	ctx	= xio_ctx_open(NULL, loop, 0);

	/* create url to connect to */
	sprintf(url, "rdma://%s:%d", argv[1], port);
	/* bind a listener server to a portal/url */
	server = xio_bind(ctx, &server_ops, url, NULL, 0, &server_data);
	if (server == NULL)
		goto cleanup;


	/* spawn portals */
	for (i = 0; i < MAX_THREADS; i++) {
		server_data.tdata[i].affinity = i+1;
		port += 1;
		sprintf(server_data.tdata[i].portal, "rdma://%s:%d",
			argv[1], port);
		pthread_create(&server_data.tdata[i].thread_id, NULL,
			       portal_server_cb, &server_data.tdata[i]);
	}

	xio_ev_loop_run(loop);

	/* normal exit phase */
	fprintf(stdout, "exit signaled\n");

	/* join the threads */
	for (i = 0; i < MAX_THREADS; i++)
		pthread_join(server_data.tdata[i].thread_id, NULL);

	/* free the server */
	xio_unbind(server);
cleanup:
	/* free the context */
	xio_ctx_close(ctx);

	/* destroy the default loop */
	xio_ev_loop_destroy(&loop);

	return 0;
}
Exemplo n.º 8
0
/*---------------------------------------------------------------------------*/
static void *portal_server_cb(void *data)
{
	struct thread_data	*tdata = data;
	cpu_set_t		cpuset;
	struct xio_server	*server;
	int			retval = 0;

	/* set affinity to thread */

	CPU_ZERO(&cpuset);
	CPU_SET(tdata->affinity, &cpuset);

	pthread_setaffinity_np(tdata->thread_id, sizeof(cpu_set_t), &cpuset);

	/* prepare data for the cuurent thread */
	tdata->pool = msg_pool_alloc(tdata->user_param->queue_depth + 64);

	/* create thread context for the client */
	tdata->ctx = xio_context_create(NULL, tdata->user_param->poll_timeout,
					tdata->affinity);

	/* bind a listener server to a portal/url */
	server = xio_bind(tdata->ctx, &portal_server_ops,
			  tdata->user_param->portals_arr[tdata->portal_index],
			  NULL, 0, tdata);
	if (server == NULL)
		goto cleanup;

	/* the default xio supplied main loop */
	xio_context_run_loop(tdata->ctx, XIO_INFINITE);

	/* detach the server */
	xio_unbind(server);

	if (tdata->pool)
		msg_pool_free(tdata->pool);

	if (tdata->mr)
		xio_dereg_mr(&tdata->mr);

	if (tdata->buf)
		free(tdata->buf);

	if (tdata->out_xbuf)
		xio_free(&tdata->out_xbuf);

	if (tdata->in_xbuf)
		xio_free(&tdata->in_xbuf);

cleanup:
	/* free the context */
	xio_context_destroy(tdata->ctx);

	pthread_exit(&retval);
}
Exemplo n.º 9
0
/* Server I/O manager */
void *rdb_r_s_io_worker(void *data)
{
    struct io_worker_data *worker_data;
    struct xio_server *server = NULL;
    cpu_set_t cpuset;

    worker_data = (struct io_worker_data *) data;

    /* set affinity to thread */
    CPU_ZERO(&cpuset);
    CPU_SET(worker_data->affinity, &cpuset);
    pthread_setaffinity_np(worker_data->thread_id, sizeof(cpu_set_t), &cpuset);

    worker_data->ctx = xio_context_create(NULL, POLLING_TIMEOUT,
                                            worker_data->affinity);
    if (!worker_data->ctx) {
        fprintf(stderr, "failed to create context for thread %s. reason %d - (%s)\n",
                worker_data->portal, xio_errno(), xio_strerror(xio_errno()));
        goto out;
    }
    server = xio_bind(worker_data->ctx, &io_worker_ops,
                worker_data->portal, NULL, 0, worker_data);
    if (!server) {
        fprintf(stderr, "failed to bind context for thread %s. reason %d - (%s)\n",
                worker_data->portal, xio_errno(), xio_strerror(xio_errno()));
        goto out;
    }

    xio_mem_alloc(MAX_VALUE_SIZE, &worker_data->reg_mem);
    if (!worker_data->reg_mem.addr) {
        fprintf(stderr, "failed to allocate accelio transfer buffer for thread %s. reason %d - (%s)\n",
                worker_data->portal, xio_errno(), xio_strerror(xio_errno()));
        goto out;
    }

    /* the default xio supplied main loop */
    if (xio_context_run_loop(worker_data->ctx, XIO_INFINITE) != 0) {
        fprintf(stderr, "failed to run event loop for thread %s. reason %d - (%s)\n",
                worker_data->portal, xio_errno(), xio_strerror(xio_errno()));
    }

out:
    /* detach the worker */
    if (server)
        xio_unbind(server);

    if (worker_data->reg_mem.addr)
        xio_mem_free(&worker_data->reg_mem);

    /* free the context */
    if (worker_data->ctx)
        xio_context_destroy(worker_data->ctx);

    return NULL;
}
Exemplo n.º 10
0
/*---------------------------------------------------------------------------*/
static void *portal_server_cb(void *data)
{
	struct thread_data	*tdata = data;
	cpu_set_t		cpuset;
	struct xio_server	*server;
	int			retval = 0;

	/* set affinity to thread */

	CPU_ZERO(&cpuset);
	CPU_SET(tdata->affinity, &cpuset);

	pthread_setaffinity_np(tdata->thread_id, sizeof(cpu_set_t), &cpuset);

	/* prepare data for the cuurent thread */
	tdata->pool = msg_pool_alloc(MAX_POOL_SIZE,
				     test_config.hdr_len, test_config.data_len,
				     0, 0);

	/* create thread context for the client */
	tdata->ctx = xio_context_create(NULL, test_config.poll_timeout);

	/* bind a listener server to a portal/url */
	printf("thread [%d] - listen:%s\n", tdata->affinity, tdata->portal);
	server = xio_bind(tdata->ctx, &portal_server_ops, tdata->portal,
			  NULL, 0, tdata);
	if (server == NULL)
		goto cleanup;

	/* the default xio supplied main loop */
	xio_context_run_loop(tdata->ctx, XIO_INFINITE);

	/* normal exit phase */
	fprintf(stdout, "thread [%d] - exit signaled\n", tdata->affinity);

	/* detach the server */
	xio_unbind(server);

	if (tdata->pool)
		msg_pool_free(tdata->pool);

	if (tdata->mr)
		xio_dereg_mr(&tdata->mr);

	if (tdata->buf)
		free(tdata->buf);

cleanup:
	/* free the context */
	xio_context_destroy(tdata->ctx);

	pthread_exit(&retval);
}
Exemplo n.º 11
0
/* Server session manager */
struct server_data* rdb_r_s_server_create(const char *host, const int *port)
{
    struct server_data *server_data = NULL;
    char url[NAME_LEN];

    server_data = (struct server_data *)calloc(1, sizeof(*server_data));
    if (!server_data) {
        fprintf(stderr, "failed to allocate memory for server_data\n");
        return (NULL);
    }

    /* init the accelio library */
    xio_init();

    /* create thread context */
    server_data->ctx = xio_context_create(NULL, 0, -1);
    if (!server_data->ctx) {
        fprintf(stderr, "failed to create context for server listner. reason %d - (%s)\n",
                xio_errno(), xio_strerror(xio_errno()));
        goto out;
    }

    sprintf(url, "%s://%s:%d", TRANSPORT, host, *port);
    strcpy(server_data->host, host);
    server_data->port = *port;

    /* bind a listner */
    server_data->server = xio_bind(server_data->ctx, &server_ops,
                                    url, NULL, 0, server_data);
    if (!server_data->server) {
        fprintf(stderr, "failed to bind server listner. reason %d - (%s)\n",
                xio_errno(), xio_strerror(xio_errno()));
        goto out;
    }

out:
    return (server_data);
}
Exemplo n.º 12
0
/*---------------------------------------------------------------------------*/
static int xio_server_main(void *data)
{
	struct xio_server		*server;
	struct xio_context_params	ctx_params;
	char				url[256];

	atomic_add(2, &module_state);

	print_test_config(&test_config);

	g_test_params.finite_run = test_config.finite_run;
	g_test_params.disconnect_nr = PRINT_COUNTER * DISCONNECT_FACTOR;

	memset(&ctx_params, 0, sizeof(ctx_params));
	ctx_params.flags = XIO_LOOP_GIVEN_THREAD;
	ctx_params.worker = current;

	g_test_params.ctx = xio_context_create(&ctx_params,
					       0, g_test_params.cpu);
	if (!g_test_params.ctx) {
		int error = xio_errno();

		pr_err("context creation failed. reason %d - (%s)\n",
		       error, xio_strerror(error));
		goto cleanup;
	}

	sprintf(url, "%s://%s:%d",
		test_config.transport,
		test_config.server_addr,
		test_config.server_port);

	server = xio_bind(g_test_params.ctx, &server_ops,
			  url, NULL, 0, &g_test_params);
	if (server) {
		pr_info("listen to %s\n", url);

		if (atomic_add_unless(&module_state, 4, 0x83))
			xio_context_run_loop(g_test_params.ctx);
		atomic_sub(4, &module_state);

		/* normal exit phase */
		pr_info("exit signaled\n");

		/* free the server */
		xio_unbind(server);
	} else {
		pr_err("**** Error - xio_bind failed - %s. " \
		       "Did you load a transport module?\n",
		       xio_strerror(xio_errno()));
		/*xio_assert(0);*/
	}

	xio_context_destroy(g_test_params.ctx);

	kfree(g_test_params.xbuf);
	g_test_params.xbuf = NULL;

cleanup:

	complete_and_exit(&cleanup_complete, 0);

	return 0;
}
Exemplo n.º 13
0
/*---------------------------------------------------------------------------*/
static int xio_server_main(void *data)
{
	char **argv = (char **)data;
	struct xio_server	*server;	/* server portal */
	struct server_data	*server_data;
	char			url[256];
	struct xio_context_params ctx_params;
	struct xio_context	*ctx;
	int			i;
	struct xio_vmsg 	*omsg;
	void 			*buf = NULL;
	unsigned long           data_len = 0;

	atomic_add(2, &module_state);

	server_data = vzalloc(sizeof(*server_data));
	if (!server_data) {
		/*pr_err("server_data alloc failed\n");*/
		return 0;
	}

	/* create thread context for the server */
	memset(&ctx_params, 0, sizeof(ctx_params));
	ctx_params.flags = XIO_LOOP_GIVEN_THREAD;
	ctx_params.worker = current;

	ctx = xio_context_create(&ctx_params, 0, -1);
	if (!ctx) {
		vfree(server_data);
		pr_err("context open filed\n");
		return 0;
	}
	server_data->ctx = ctx;

	/* create "hello world" message */
	if (argv[3] != NULL && kstrtoul(argv[3], 0, &data_len)) { /* check, convert and assign data_len */
		data_len = 0;
	}
	for (i = 0; i < QUEUE_DEPTH; i++) {
		xio_reinit_msg(&server_data->rsp[i]);
		omsg = &server_data->rsp[i].out;

		/* header */
		server_data->rsp[i].out.header.iov_base = kstrdup("hello world header rsp 1", GFP_KERNEL);
		server_data->rsp[i].out.header.iov_len = strlen((const char *) server_data->rsp[i].out.header.iov_base) + 1;
		/* iovec[0]*/
		sg_alloc_table(&omsg->data_tbl, 64, GFP_KERNEL);
		/* currently only one entry */
		xio_init_vmsg(omsg, 1);     /* one entry (max_nents) */
		if (data_len < max_data_len) { /* small msgs */
			buf = kstrdup("hello world iovec rsp", GFP_KERNEL);
		} else { /* big msgs */
			if (!buf) {
				pr_info("allocating xio memory...\n");
				buf = kmalloc(data_len, GFP_KERNEL);
				memcpy(buf, "hello world iovec rsp", 22);
			}
		}
		sg_init_one(omsg->data_tbl.sgl, buf, strlen(buf) + 1);
		/* orig_nents is 64 */
		vmsg_sglist_set_nents(omsg, 1);
	}

	/* create url to connect to */
	sprintf(url, "%s://%s:%s", argv[4], argv[1], argv[2]);
	/* bind a listener server to a portal/url */
	server = xio_bind(ctx, &server_ops, url, NULL, 0, server_data);
	if (server) {
		pr_info("listen to %s\n", url);

		g_server_data = server_data;
		if (atomic_add_unless(&module_state, 4, 0x83))
			xio_context_run_loop(ctx);
		atomic_sub(4, &module_state);

		/* normal exit phase */
		pr_info("exit signaled\n");

		/* free the server */
		xio_unbind(server);
	}

	/* free the message */
	for (i = 0; i < QUEUE_DEPTH; i++) {
		kfree(server_data->rsp[i].out.header.iov_base);
		if (data_len < max_data_len) {
			/* Currently need to release only one entry */
			kfree(sg_virt(server_data->rsp[i].out.data_tbl.sgl));
		}
		xio_fini_vmsg(&server_data->rsp[i].out);
	}

        if (buf){
                pr_info("freeing xio memory...\n");
                kfree(buf);
                buf = NULL;
        }

	/* free the context */
	xio_context_destroy(ctx);

	vfree(server_data);

	complete_and_exit(&cleanup_complete, 0);
	return 0;
}
Exemplo n.º 14
0
/*---------------------------------------------------------------------------*/
int main(int argc, char *const argv[])
{
	struct xio_server	*server;	/* server portal */
	char			url[256];
	int			i;
	struct sigaction	sa;
	int			c;
	char			*addr = NULL;
	char			*port = NULL;
	char			*trans = NULL;

	while (1) {
		c = getopt_long(argc, argv, "a:p:r:hdnV", longopts, NULL);
		if (c == -1)
			break;

		switch (c) {
		case 'a':
			addr = optarg;
			break;
		case 'p':
			port = optarg;
			break;
		case 'r':
			trans = optarg;
			break;
		case 'h':
			usage(argv[0], 0);
		case 'd':
			debug_flag++;
			nofork_flag++;
			break;
		case 'n':
			nofork_flag++;
			break;
		case 'V':
			printf("%s\n", PACKAGE_STRING);
			exit(0);
			break;
		default:
			usage(argv[0], 1);
			break;
		}
	}

	memset(&sa, 0, sizeof(sa));
	sa.sa_handler = signal_handler;
	sigaction(SIGINT, &sa, NULL);
	sigaction(SIGTERM, &sa, NULL);
	sigaction(SIGQUIT, &sa, NULL);
	sigaction(SIGHUP, &sa, NULL);

	sa.sa_handler = SIG_IGN;
	sa.sa_flags = SA_RESTART;
	sigaction(SIGPIPE, &sa, NULL);


	if (!nofork_flag && daemon(0, 0)) {
		logerr("daemon() failed");
		exit(1);
	}

	if (!debug_flag) {
		openlog("xiosrvd", LOG_PID, LOG_DAEMON);
		use_syslog = 1;
	}

	/* Create the process PID file */
	if (create_pidfile(pid_file) != 0)
		exit(EXIT_FAILURE);

	/* initialize library */
	xio_init();

		/* create "hello world" message */
	memset(&server_data, 0, sizeof(server_data));
	for (i = 0; i < QUEUE_DEPTH; i++) {
		server_data.rsp[i].out.header.iov_base =
			strdup("hello world header response");
		server_data.rsp[i].out.header.iov_len =
			strlen((const char *)
				server_data.rsp[i].out.header.iov_base) + 1;
	}

	/* create thread context for the client */
	server_data.ctx	= xio_context_create(NULL, 0, -1);


	/* create url to connect to */
	if (trans)
		sprintf(url, "%s://%s:%s", trans, addr, port);
	else
		sprintf(url, "rdma://%s:%s", addr, port);
reload:
	/* bind a listener server to a portal/url */
	server = xio_bind(server_data.ctx, &server_ops,
			  url, NULL, 0, &server_data);
	if (server) {
		logit(LOG_INFO, "listen to %s", url);
		xio_context_run_loop(server_data.ctx, XIO_INFINITE);

		/* free the server */
		xio_unbind(server);

		if (reload_flag) {
			reload_flag = 0;
			goto reload;
		}
		/* normal exit phase */
		logit(LOG_INFO, "exit signaled");
	}

	/* free the message */
	for (i = 0; i < QUEUE_DEPTH; i++)
		free(server_data.rsp[i].out.header.iov_base);


	/* free the context */
	xio_context_destroy(server_data.ctx);

	xio_shutdown();

	remove_pidfile();

	if (use_syslog)
		closelog();

	return 0;
}
Exemplo n.º 15
0
/*---------------------------------------------------------------------------*/
int main(int argc, char *argv[])
{
	struct xio_server	*server;	/* server portal */
	struct server_data	server_data;
	char			url[256];
	struct	xio_msg		*rsp;
	int			i, opt, optlen;
	struct xio_reg_mem      xbuf;
        int 			msg_size = 0;
        int 			max_msg_size = 0;
        uint8_t 		*data = NULL;

	xbuf.addr		= NULL;
	xbuf.mr			= NULL;

	if (argc < 3) {
		printf("Usage: %s <host> <port> <transport:optional>"\
		       "<finite run:optional> <msg size:optional>\n", argv[0]);
		exit(1);
	}
        if (argc > 4)
                test_disconnect = atoi(argv[4]);
        else
                test_disconnect = 0;
        if (argc > 5)
                msg_size = atoi(argv[5]);

	/* initialize library */
	xio_init();

        /* get max msg size */
        /* this size distinguishes between big and small msgs, where for small msgs rdma_post_send/rdma_post_recv
        are called as opposed to to big msgs where rdma_write/rdma_read are called */
        xio_get_opt(NULL, XIO_OPTLEVEL_ACCELIO,
                    XIO_OPTNAME_MAX_INLINE_XIO_DATA,
                    &opt, &optlen);
        max_msg_size = opt;

	/* create "hello world" message */
	memset(&server_data, 0, sizeof(server_data));
	rsp = server_data.rsp_ring;
	for (i = 0; i < QUEUE_DEPTH; i++) {
		/* header */
		rsp->out.header.iov_base =
			strdup("hello world header response");
		rsp->out.header.iov_len =
			strlen((const char *)
				rsp->out.header.iov_base) + 1;

		rsp->out.sgl_type	   = XIO_SGL_TYPE_IOV;
		rsp->out.data_iov.max_nents = XIO_IOVLEN;

		/* data */
		if (msg_size < max_msg_size) { /* small msgs */
                        rsp->out.data_iov.sglist[0].iov_base =
                                strdup("hello world data response");
                } else { /* big msgs */
			if (data == NULL) {
				printf("allocating xio memory...\n");
				xio_mem_alloc(msg_size, &xbuf);
				if (xbuf.addr != NULL){
					data = (uint8_t *)xbuf.addr;
					memset(data, 0, msg_size);
					sprintf((char *)data, "hello world data response");
				} else {
			                printf("ERROR - xio_mem_alloc failed.\n");
					exit(1);
				}
			}
	                rsp->out.data_iov.sglist[0].mr = xbuf.mr;
			rsp->out.data_iov.sglist[0].iov_base = data;
		}

                rsp->out.data_iov.sglist[0].iov_len =
                        strlen((const char *)
                               rsp->out.data_iov.sglist[0].iov_base) + 1;

		rsp->out.data_iov.nents = 1;

		rsp++;
	}

	/* create thread context for the client */
	server_data.ctx	= xio_context_create(NULL, 0, -1);

	/* create url to connect to */
	if (argc > 3)
		sprintf(url, "%s://%s:%s", argv[3], argv[1], argv[2]);
	else
		sprintf(url, "rdma://%s:%s", argv[1], argv[2]);

	/* bind a listener server to a portal/url */
	server = xio_bind(server_data.ctx, &server_ops,
			  url, NULL, 0, &server_data);
	if (server) {
		printf("listen to %s\n", url);
		xio_context_run_loop(server_data.ctx, XIO_INFINITE);

		/* normal exit phase */
		fprintf(stdout, "exit signaled\n");

		/* free the server */
		xio_unbind(server);
	}

	/* free the message */
	rsp = server_data.rsp_ring;
	for (i = 0; i < QUEUE_DEPTH; i++) {
		free(rsp->out.header.iov_base);
		if (msg_size < max_msg_size) free(rsp->out.data_iov.sglist[0].iov_base);
		rsp++;
	}
	if (data) {
		printf("freeing xio memory...\n");
                xio_mem_free(&xbuf);
                xbuf.addr = NULL;
        }

	/* free the context */
	xio_context_destroy(server_data.ctx);

	xio_shutdown();

	return 0;
}
Exemplo n.º 16
0
/*---------------------------------------------------------------------------*/
static int xio_server_main(void *data)
{
	char **argv = (char **)data;
	struct xio_server	*server;	/* server portal */
	struct server_data	*server_data;
	char			url[256];
	struct xio_context_params ctx_params;
	struct xio_context	*ctx;
	int			i;

	atomic_add(2, &module_state);

	server_data = vzalloc(sizeof(*server_data));
	if (!server_data) {
		/*pr_err("server_data alloc failed\n");*/
		return 0;
	}

	/* create thread context for the server */
	memset(&ctx_params, 0, sizeof(ctx_params));
	ctx_params.flags = XIO_LOOP_GIVEN_THREAD;
	ctx_params.worker = current;

	ctx = xio_context_create(&ctx_params, 0, -1);
	if (!ctx) {
		vfree(server_data);
		pr_err("context open filed\n");
		return 0;
	}
	server_data->ctx = ctx;

	/* create "hello world" message */
	for (i = 0; i < QUEUE_DEPTH; i++) {
		server_data->rsp[i].out.header.iov_base =
			kstrdup("hello world header response", GFP_KERNEL);
		server_data->rsp[i].out.header.iov_len =
			strlen(server_data->rsp[i].out.header.iov_base) + 1;
		server_data->rsp[i].out.sgl_type = XIO_SGL_TYPE_SCATTERLIST;
		server_data->rsp[i].out.data_tbl.orig_nents = 0;
		server_data->rsp[i].out.data_tbl.nents = 0;
		server_data->rsp[i].out.data_tbl.sgl = NULL;
	}

	/* create url to connect to */
	sprintf(url, "rdma://%s:%s", argv[1], argv[2]);
	/* bind a listener server to a portal/url */
	server = xio_bind(ctx, &server_ops, url, NULL, 0, server_data);
	if (server) {
		pr_info("listen to %s\n", url);

		g_server_data = server_data;
		if (atomic_add_unless(&module_state, 4, 0x83))
			xio_context_run_loop(ctx);
		atomic_sub(4, &module_state);

		/* normal exit phase */
		pr_info("exit signaled\n");

		/* free the server */
		xio_unbind(server);
	}

	/* free the message */
	for (i = 0; i < QUEUE_DEPTH; i++)
		kfree(server_data->rsp[i].out.header.iov_base);

	/* free the context */
	xio_context_destroy(ctx);

	vfree(server_data);

	complete_and_exit(&cleanup_complete, 0);

	return 0;
}