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; }
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; }
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); } }