Exemplo n.º 1
0
static int blockdev_malloc_initialize(void)
{
	struct spdk_conf_section *sp = spdk_conf_find_section(NULL, "Malloc");
	int NumberOfLuns, LunSizeInMB, BlockSize, i;
	uint64_t size;
	struct malloc_disk *mdisk;

	if (sp != NULL) {
		NumberOfLuns = spdk_conf_section_get_intval(sp, "NumberOfLuns");
		LunSizeInMB = spdk_conf_section_get_intval(sp, "LunSizeInMB");
		BlockSize = spdk_conf_section_get_intval(sp, "BlockSize");
		if ((NumberOfLuns < 1) || (LunSizeInMB < 1)) {
			SPDK_ERRLOG("Malloc section present, but no devices specified\n");
			return EINVAL;
		}
		if (BlockSize < 1) {
			/* Default is 512 bytes */
			BlockSize = 512;
		}
		size = (uint64_t)LunSizeInMB * 1024 * 1024;
		for (i = 0; i < NumberOfLuns; i++) {
			mdisk = create_malloc_disk(size / BlockSize, BlockSize);
			if (mdisk == NULL) {
				SPDK_ERRLOG("Could not create malloc disk\n");
				return EINVAL;
			}
		}
	}
	return 0;
}
Exemplo n.º 2
0
Arquivo: conf.c Projeto: 64116278/spdk
static int
spdk_nvmf_parse_nvmf_tgt(void)
{
	struct spdk_conf_section *sp;
	char *nodebase;
	int max_in_capsule_data;
	int max_sessions_per_subsystem;
	int max_queue_depth;
	int max_conn_per_sess;
	int max_recv_seg_len;
	int listen_port;
	int rc;

	sp = spdk_conf_find_section(NULL, "Nvmf");
	if (sp == NULL) {
		SPDK_ERRLOG("No Nvmf section in configuration file.\n");
		return -1;
	}

	nodebase = spdk_conf_section_get_val(sp, "NodeBase");
	if (nodebase == NULL) {
		nodebase = SPDK_NVMF_DEFAULT_NODEBASE;
	}

	max_in_capsule_data = spdk_conf_section_get_intval(sp, "MaxInCapsuleData");
	if (max_in_capsule_data < 0) {
		max_in_capsule_data = SPDK_NVMF_DEFAULT_IN_CAPSULE_DATA_SIZE;
	}

	max_sessions_per_subsystem = spdk_conf_section_get_intval(sp, "MaxSessionsPerSubsystem");
	if (max_sessions_per_subsystem < 0) {
		max_sessions_per_subsystem = SPDK_NVMF_DEFAULT_MAX_SESSIONS_PER_SUBSYSTEM;
	}

	max_queue_depth = spdk_conf_section_get_intval(sp, "MaxQueueDepth");
	if (max_queue_depth < 0) {
		max_queue_depth = SPDK_NVMF_DEFAULT_MAX_QUEUE_DEPTH;
	}

	max_conn_per_sess = spdk_conf_section_get_intval(sp, "MaxConnectionsPerSession");
	if (max_conn_per_sess < 0) {
		max_conn_per_sess = SPDK_NVMF_DEFAULT_MAX_CONNECTIONS_PER_SESSION;
	}

	max_recv_seg_len = SPDK_NVMF_MAX_RECV_DATA_TRANSFER_SIZE;
	listen_port = SPDK_NVMF_DEFAULT_SIN_PORT;

	rc = nvmf_tgt_init(nodebase, max_in_capsule_data, max_sessions_per_subsystem,
			   max_queue_depth, max_conn_per_sess, max_recv_seg_len, listen_port);

	return rc;
}
Exemplo n.º 3
0
static int
spdk_read_config_scsi_parameters(void)
{
	struct spdk_conf_section *sp;
	const char *val;

	sp = spdk_conf_find_section(NULL, "Scsi");
	if (sp == NULL) {
		spdk_set_default_scsi_parameters();
		return 0;
	}

	val = spdk_conf_section_get_val(sp, "MaxUnmapLbaCount");
	g_spdk_scsi.scsi_params.max_unmap_lba_count = (val == NULL) ?
			DEFAULT_MAX_UNMAP_LBA_COUNT : strtoul(val, NULL, 10);

	val = spdk_conf_section_get_val(sp, "MaxUnmapBlockDescriptorCount");
	g_spdk_scsi.scsi_params.max_unmap_block_descriptor_count = (val == NULL) ?
			DEFAULT_MAX_UNMAP_BLOCK_DESCRIPTOR_COUNT : strtoul(val, NULL, 10);
	val = spdk_conf_section_get_val(sp, "OptimalUnmapGranularity");
	g_spdk_scsi.scsi_params.optimal_unmap_granularity = (val == NULL) ?
			DEFAULT_OPTIMAL_UNMAP_GRANULARITY : strtoul(val, NULL, 10);

	val = spdk_conf_section_get_val(sp, "UnmapGranularityAlignment");
	g_spdk_scsi.scsi_params.unmap_granularity_alignment = (val == NULL) ?
			DEFAULT_UNMAP_GRANULARITY_ALIGNMENT : strtoul(val, NULL, 10);

	val = spdk_conf_section_get_val(sp, "Ugavalid");
	if (val == NULL) {
		g_spdk_scsi.scsi_params.ugavalid = DEFAULT_UGAVALID;
	} else if (strcasecmp(val, "Yes") == 0) {
		g_spdk_scsi.scsi_params.ugavalid = 1;
	} else if (strcasecmp(val, "No") == 0) {
		g_spdk_scsi.scsi_params.ugavalid = 0;
	} else {
		SPDK_ERRLOG("unknown value %s\n", val);
		return -1;
	}

	val = spdk_conf_section_get_val(sp, "MaxWriteSameLength");
	g_spdk_scsi.scsi_params.max_write_same_length = (val == NULL) ?
			DEFAULT_MAX_WRITE_SAME_LENGTH : strtoul(val, NULL, 10);

	return 0;
}
Exemplo n.º 4
0
Arquivo: app.c Projeto: lkpdn/spdk
static const char *
spdk_get_log_facility(struct spdk_conf *config)
{
	struct spdk_conf_section *sp;
	const char *logfacility;

	sp = spdk_conf_find_section(config, "Global");
	if (sp == NULL) {
		return SPDK_APP_DEFAULT_LOG_FACILITY;
	}

	logfacility = spdk_conf_section_get_val(sp, "LogFacility");
	if (logfacility == NULL) {
		return SPDK_APP_DEFAULT_LOG_FACILITY;
	}

	return logfacility;
}
Exemplo n.º 5
0
static int blockdev_aio_initialize(void)
{
	struct spdk_bdev *bdev;
	int i;
	const char *val = NULL;
	char *file;
	struct spdk_conf_section *sp = spdk_conf_find_section(NULL, "AIO");
	bool skip_missing = false;

	if (sp != NULL) {
		val = spdk_conf_section_get_val(sp, "SkipMissingFiles");
	}
	if (val != NULL && !strcmp(val, "Yes")) {
		skip_missing = true;
	}

	if (sp != NULL) {
		for (i = 0; ; i++) {
			val = spdk_conf_section_get_nval(sp, "AIO", i);
			if (val == NULL)
				break;
			file = spdk_conf_section_get_nmval(sp, "AIO", i, 0);
			if (file == NULL) {
				SPDK_ERRLOG("AIO%d: format error\n", i);
				return -1;
			}

			bdev = create_aio_disk(file);

			if (bdev == NULL && !skip_missing) {
				return -1;
			}
		}
	}
	return 0;
}
Exemplo n.º 6
0
Arquivo: app.c Projeto: 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);
	}
}
Exemplo n.º 7
0
Arquivo: conf.c Projeto: chennqqi/spdk
static int
parse_line(struct spdk_conf *cp, char *lp)
{
	struct spdk_conf_section *sp;
	struct spdk_conf_item *ip;
	struct spdk_conf_value *vp;
	char *arg;
	char *key;
	char *val;
	char *p;
	int num;

	arg = spdk_str_trim(lp);
	if (arg == NULL) {
		fprintf(stderr, "no section\n");
		return -1;
	}

	if (arg[0] == '[') {
		/* section */
		arg++;
		key = spdk_strsepq(&arg, "]");
		if (key == NULL || arg != NULL) {
			fprintf(stderr, "broken section\n");
			return -1;
		}
		/* determine section number */
		for (p = key; *p != '\0' && !isdigit((int) *p); p++)
			;
		if (*p != '\0') {
			num = (int)strtol(p, NULL, 10);
		} else {
			num = 0;
		}

		sp = spdk_conf_find_section(cp, key);
		if (sp == NULL) {
			sp = allocate_cf_section();
			append_cf_section(cp, sp);
		}
		cp->current_section = sp;
		sp->name = strdup(key);
		if (sp->name == NULL) {
			perror("strdup sp->name");
			return -1;
		}

		sp->num = num;
	} else {
		/* parameters */
		sp = cp->current_section;
		if (sp == NULL) {
			fprintf(stderr, "unknown section\n");
			return -1;
		}
		key = spdk_strsepq(&arg, CF_DELIM);
		if (key == NULL) {
			fprintf(stderr, "broken key\n");
			return -1;
		}

		ip = allocate_cf_item();
		if (ip == NULL) {
			fprintf(stderr, "cannot allocate cf item\n");
			return -1;
		}
		append_cf_item(sp, ip);
		ip->key = strdup(key);
		if (ip->key == NULL) {
			perror("strdup ip->key");
			return -1;
		}
		ip->val = NULL;
		if (arg != NULL) {
			/* key has value(s) */
			while (arg != NULL) {
				val = spdk_strsepq(&arg, CF_DELIM);
				vp = allocate_cf_value();
				if (vp == NULL) {
					fprintf(stderr,
						"cannot allocate cf value\n");
					return -1;
				}
				append_cf_value(ip, vp);
				vp->value = strdup(val);
				if (vp->value == NULL) {
					perror("strdup vp->value");
					return -1;
				}
			}
		}
	}

	return 0;
}