Exemple #1
0
struct dnet_node *dnet_server_node_create(struct dnet_config *cfg)
{
	struct dnet_node *n;
	struct dnet_raw_id *ids = NULL;
	int id_num = 0;
	int err = -ENOMEM;

	n = dnet_node_create(cfg);
	if (!n) {
		goto err_out_exit;
	}

	if (!n->notify_hash_size) {
		n->notify_hash_size = DNET_DEFAULT_NOTIFY_HASH_SIZE;

	err = dnet_notify_init(n);
	if (err)
		goto err_out_node_destroy;

		dnet_log(n, DNET_LOG_NOTICE, "No notify hash size provided, using default %d.\n",
				n->notify_hash_size);
	}

	err = dnet_cache_init(n);
	if (err)
		goto err_out_notify_exit;

	if (cfg->flags & DNET_CFG_JOIN_NETWORK) {
		int s;

		err = dnet_locks_init(n, cfg->oplock_num);
		if (err)
			goto err_out_cache_cleanup;

		ids = dnet_ids_init(n, cfg->history_env, &id_num, cfg->storage_free);
		if (!ids)
			goto err_out_locks_destroy;

		n->addr.addr_len = sizeof(n->addr.addr);
		err = dnet_socket_create(n, cfg, &n->addr, 1);
		if (err < 0)
			goto err_out_ids_cleanup;

		s = err;
		dnet_setup_id(&n->id, cfg->group_id, ids[0].id);

		n->st = dnet_state_create(n, cfg->group_id, ids, id_num, &n->addr, s, &err, DNET_JOIN, dnet_state_accept_process);
		if (!n->st) {
			close(s);
			goto err_out_state_destroy;
		}

		free(ids);
		ids = NULL;

		err = dnet_srw_init(n, cfg);
		if (err) {
			dnet_log(n, DNET_LOG_ERROR, "srw: initialization failure: %s %d\n", strerror(-err), err);
		}
	}

	dnet_log(n, DNET_LOG_DSA, "New server node has been created at %s, ids: %d.\n",
			dnet_dump_node(n), id_num);

	return n;

err_out_state_destroy:
	dnet_srw_cleanup(n);
	dnet_state_put(n->st);
err_out_ids_cleanup:
	free(ids);
err_out_locks_destroy:
	dnet_locks_destroy(n);
err_out_cache_cleanup:
	dnet_cache_cleanup(n);
err_out_notify_exit:
	dnet_notify_exit(n);
err_out_node_destroy:
	dnet_node_destroy(n);
err_out_exit:
	return NULL;
}
Exemple #2
0
struct dnet_node *dnet_server_node_create(struct dnet_config_data *cfg_data, struct dnet_config *cfg, struct dnet_addr *addrs, int addr_num)
{
	struct dnet_node *n;
	struct dnet_raw_id *ids = NULL;
	int id_num = 0;
	int err = -ENOMEM;

	sigset_t previous_sigset;
	sigset_t sigset;
	sigemptyset(&sigset);
	sigaddset(&sigset, SIGINT);
	sigaddset(&sigset, SIGTERM);
	sigaddset(&sigset, SIGALRM);
	sigaddset(&sigset, SIGQUIT);
	pthread_sigmask(SIG_BLOCK, &sigset, &previous_sigset);

	n = dnet_node_create(cfg);
	if (!n)
		goto err_out_exit;

	n->config_data = cfg_data;

	err = dnet_node_check_stack(n);
	if (err)
		goto err_out_node_destroy;

	if (!n->notify_hash_size) {
		n->notify_hash_size = DNET_DEFAULT_NOTIFY_HASH_SIZE;

		err = dnet_notify_init(n);
		if (err)
			goto err_out_node_destroy;

		dnet_log(n, DNET_LOG_NOTICE, "No notify hash size provided, using default %d.\n",
				n->notify_hash_size);
	}

	err = dnet_cache_init(n);
	if (err)
		goto err_out_notify_exit;

	err = dnet_local_addr_add(n, addrs, addr_num);
	if (err)
		goto err_out_cache_cleanup;

	if (cfg->flags & DNET_CFG_JOIN_NETWORK) {
		struct dnet_addr la;
		int s;

		err = dnet_locks_init(n, 1024);
		if (err)
			goto err_out_addr_cleanup;

		ids = dnet_ids_init(n, cfg->history_env, &id_num, cfg->storage_free, cfg_data->cfg_addrs, cfg_data->cfg_remotes);
		if (!ids)
			goto err_out_locks_destroy;

		memset(&la, 0, sizeof(struct dnet_addr));
		la.addr_len = sizeof(la.addr);
		la.family = cfg->family;

		err = dnet_socket_create(n, NULL, cfg->port, &la, 1);
		if (err < 0)
			goto err_out_ids_cleanup;

		s = err;
		dnet_setup_id(&n->id, cfg->group_id, ids[0].id);

		n->st = dnet_state_create(n, cfg->group_id, ids, id_num, &la, s, &err, DNET_JOIN, -1, dnet_state_accept_process);
		if (!n->st) {
			close(s);
			goto err_out_state_destroy;
		}

		free(ids);
		ids = NULL;

		if (!cfg->srw.config) {
			dnet_log(n, DNET_LOG_INFO, "srw: no config\n");
			n->srw = NULL;
		} else {
			err = dnet_srw_init(n, cfg);
			if (err) {
				dnet_log(n, DNET_LOG_ERROR, "srw: initialization failure: %s %d\n", strerror(-err), err);
				goto err_out_state_destroy;
			}
		}
	}

	dnet_log(n, DNET_LOG_DEBUG, "New server node has been created at port %d, ids: %d.\n", cfg->port, id_num);

	pthread_sigmask(SIG_SETMASK, &previous_sigset, NULL);
	return n;

	dnet_srw_cleanup(n);
err_out_state_destroy:
	dnet_state_put(n->st);
err_out_ids_cleanup:
	free(ids);
err_out_locks_destroy:
	dnet_locks_destroy(n);
err_out_addr_cleanup:
	dnet_local_addr_cleanup(n);
err_out_cache_cleanup:
	dnet_cache_cleanup(n);
err_out_notify_exit:
	dnet_notify_exit(n);
err_out_node_destroy:
	dnet_node_destroy(n);
err_out_exit:
	pthread_sigmask(SIG_SETMASK, &previous_sigset, NULL);
	return NULL;
}