コード例 #1
0
ファイル: init_ut.c プロジェクト: spdk/spdk
static struct spdk_conf *
spdk_config_init_scsi_params(char *key, char *value)
{
	struct spdk_conf *spdk_config;
	FILE *f;
	int fd, rc;
	char filename[] = "/tmp/scsi_init_ut.XXXXXX";

	/* Create temporary file to hold config */
	fd = mkstemp(filename);
	SPDK_CU_ASSERT_FATAL(fd != -1);

	f = fdopen(fd, "wb+");
	SPDK_CU_ASSERT_FATAL(f != NULL);

	fprintf(f, "[Scsi]\n");
	fprintf(f, "%s %s\n", key, value);

	fclose(f);

	spdk_config = spdk_conf_allocate();
	SPDK_CU_ASSERT_FATAL(spdk_config != NULL);

	rc = spdk_conf_read(spdk_config, filename);
	SPDK_CU_ASSERT_FATAL(rc == 0);

	spdk_conf_set_as_default(spdk_config);

	remove(filename);

	return spdk_config;
}
コード例 #2
0
ファイル: init_ut.c プロジェクト: spdk/spdk
static void
scsi_init_sp_null(void)
{
	struct spdk_conf *config;
	int rc;

	config = spdk_conf_allocate();
	SPDK_CU_ASSERT_FATAL(config != NULL);

	spdk_conf_set_as_default(config);

	rc = spdk_scsi_subsystem_init();

	/* sp = null; set default scsi params */
	CU_ASSERT_EQUAL(rc, 0);

	spdk_conf_set_as_default(NULL);
	spdk_conf_free(config);
}
コード例 #3
0
ファイル: app.c プロジェクト: lkpdn/spdk
void
spdk_app_init(struct spdk_app_opts *opts)
{
	struct spdk_conf		*config;
	struct spdk_conf_section	*sp;
	struct sigaction	sigact;
	sigset_t		signew;
	char			shm_name[64];
	int			rc;
	uint64_t		tpoint_group_mask;
	char			*end;

	if (opts->enable_coredump) {
		struct rlimit core_limits;

		core_limits.rlim_cur = core_limits.rlim_max = RLIM_INFINITY;
		setrlimit(RLIMIT_CORE, &core_limits);
	}

	config = spdk_conf_allocate();
	RTE_VERIFY(config != NULL);
	if (opts->config_file) {
		rc = spdk_conf_read(config, opts->config_file);
		if (rc != 0) {
			fprintf(stderr, "Could not read config file %s\n", opts->config_file);
			exit(EXIT_FAILURE);
		}
		if (config->section == NULL) {
			fprintf(stderr, "Invalid config file %s\n", opts->config_file);
			exit(EXIT_FAILURE);
		}
	}
	spdk_conf_set_as_default(config);

	if (opts->instance_id == -1) {
		sp = spdk_conf_find_section(config, "Global");
		if (sp != NULL) {
			opts->instance_id = spdk_conf_section_get_intval(sp, "InstanceID");
		}
	}

	if (opts->instance_id < 0) {
		opts->instance_id = 0;
	}

	memset(&g_spdk_app, 0, sizeof(g_spdk_app));
	g_spdk_app.config = config;
	g_spdk_app.instance_id = opts->instance_id;
	g_spdk_app.shutdown_cb = opts->shutdown_cb;
	snprintf(g_spdk_app.pidfile, sizeof(g_spdk_app.pidfile), "%s/%s.pid.%d",
		 SPDK_APP_PIDFILE_PREFIX, opts->name, opts->instance_id);
	spdk_app_write_pidfile();

	/* open log files */
	if (opts->log_facility == NULL) {
		opts->log_facility = spdk_get_log_facility(g_spdk_app.config);
		if (opts->log_facility == NULL) {
			fprintf(stderr, "NULL logfacility\n");
			spdk_conf_free(g_spdk_app.config);
			exit(EXIT_FAILURE);
		}
	}
	rc = spdk_set_log_facility(opts->log_facility);
	if (rc < 0) {
		fprintf(stderr, "log facility error\n");
		spdk_conf_free(g_spdk_app.config);
		exit(EXIT_FAILURE);
	}

	rc = spdk_set_log_priority(SPDK_APP_DEFAULT_LOG_PRIORITY);
	if (rc < 0) {
		fprintf(stderr, "log priority error\n");
		spdk_conf_free(g_spdk_app.config);
		exit(EXIT_FAILURE);
	}
	spdk_open_log();

	if (opts->reactor_mask == NULL) {
		sp = spdk_conf_find_section(g_spdk_app.config, "Global");
		if (sp != NULL) {
			if (spdk_conf_section_get_val(sp, "ReactorMask")) {
				opts->reactor_mask = spdk_conf_section_get_val(sp, "ReactorMask");
			} else {
				opts->reactor_mask = SPDK_APP_DPDK_DEFAULT_CORE_MASK;
			}
		} else {
			opts->reactor_mask = SPDK_APP_DPDK_DEFAULT_CORE_MASK;
		}
	}

	spdk_dpdk_framework_init(opts);

	/*
	 * If mask not specified on command line or in configuration file,
	 *  reactor_mask will be NULL which will enable all cores to run
	 *  reactors.
	 */
	if (spdk_reactors_init(opts->reactor_mask)) {
		fprintf(stderr, "Invalid reactor mask.\n");
		exit(EXIT_FAILURE);
	}

	/* setup signal handler thread */
	pthread_sigmask(SIG_SETMASK, NULL, &signew);

	memset(&sigact, 0, sizeof(sigact));
	sigact.sa_handler = SIG_IGN;
	sigemptyset(&sigact.sa_mask);
	rc = sigaction(SIGPIPE, &sigact, NULL);
	if (rc < 0) {
		SPDK_ERRLOG("sigaction(SIGPIPE) failed\n");
		exit(EXIT_FAILURE);
	}

	if (opts->shutdown_cb != NULL) {
		g_shutdown_event = spdk_event_allocate(rte_lcore_id(), __shutdown_event_cb,
						       NULL, NULL, NULL);

		sigact.sa_handler = __shutdown_signal;
		sigemptyset(&sigact.sa_mask);
		rc = sigaction(SIGINT, &sigact, NULL);
		if (rc < 0) {
			SPDK_ERRLOG("sigaction(SIGINT) failed\n");
			exit(EXIT_FAILURE);
		}
		sigaddset(&signew, SIGINT);

		sigact.sa_handler = __shutdown_signal;
		sigemptyset(&sigact.sa_mask);
		rc = sigaction(SIGTERM, &sigact, NULL);
		if (rc < 0) {
			SPDK_ERRLOG("sigaction(SIGTERM) failed\n");
			exit(EXIT_FAILURE);
		}
		sigaddset(&signew, SIGTERM);
	}

	if (opts->usr1_handler != NULL) {
		sigact.sa_handler = opts->usr1_handler;
		sigemptyset(&sigact.sa_mask);
		rc = sigaction(SIGUSR1, &sigact, NULL);
		if (rc < 0) {
			SPDK_ERRLOG("sigaction(SIGUSR1) failed\n");
			exit(EXIT_FAILURE);
		}
		sigaddset(&signew, SIGUSR1);
	}

	sigaddset(&signew, SIGQUIT);
	sigaddset(&signew, SIGHUP);
	pthread_sigmask(SIG_SETMASK, &signew, NULL);

	snprintf(shm_name, sizeof(shm_name), "/%s_trace.%d", opts->name, opts->instance_id);
	spdk_trace_init(shm_name);

	if (opts->tpoint_group_mask == NULL) {
		sp = spdk_conf_find_section(g_spdk_app.config, "Global");
		if (sp != NULL) {
			opts->tpoint_group_mask = spdk_conf_section_get_val(sp, "TpointGroupMask");
		}
	}

	if (opts->tpoint_group_mask != NULL) {
		errno = 0;
		tpoint_group_mask = strtoull(opts->tpoint_group_mask, &end, 16);
		if (*end != '\0' || errno) {
			SPDK_ERRLOG("invalid tpoint mask %s\n", opts->tpoint_group_mask);
		} else {
			spdk_trace_set_tpoint_group_mask(tpoint_group_mask);
		}
	}

	rc = spdk_subsystem_init();
	if (rc < 0) {
		SPDK_ERRLOG("spdk_subsystem_init() failed\n");
		exit(EXIT_FAILURE);
	}
}