create memory configuration in shared/mmap memory. Take out * a write lock on the memsegs, so we can auto-detect primary/secondary. * This means we never close the file while running (auto-close on exit). * We also don't lock the whole file, so that in future we can use read-locks * on other parts, e.g. memzones, to detect if there are running secondary * processes. */
| 173 | * on other parts, e.g. memzones, to detect if there are running secondary |
| 174 | * processes. */ |
| 175 | static int |
| 176 | rte_eal_config_create(void) |
| 177 | { |
| 178 | struct rte_config *config = rte_eal_get_configuration(); |
| 179 | size_t page_sz = sysconf(_SC_PAGE_SIZE); |
| 180 | size_t cfg_len = sizeof(*config->mem_config); |
| 181 | size_t cfg_len_aligned = RTE_ALIGN(cfg_len, page_sz); |
| 182 | void *rte_mem_cfg_addr, *mapped_mem_cfg_addr; |
| 183 | int retval; |
| 184 | const struct internal_config *internal_conf = |
| 185 | eal_get_internal_configuration(); |
| 186 | |
| 187 | const char *pathname = eal_runtime_config_path(); |
| 188 | |
| 189 | if (internal_conf->no_shconf) |
| 190 | return 0; |
| 191 | |
| 192 | /* map the config before hugepage address so that we don't waste a page */ |
| 193 | if (internal_conf->base_virtaddr != 0) |
| 194 | rte_mem_cfg_addr = (void *) |
| 195 | RTE_ALIGN_FLOOR(internal_conf->base_virtaddr - |
| 196 | sizeof(struct rte_mem_config), page_sz); |
| 197 | else |
| 198 | rte_mem_cfg_addr = NULL; |
| 199 | |
| 200 | if (mem_cfg_fd < 0){ |
| 201 | mem_cfg_fd = open(pathname, O_RDWR | O_CREAT, 0600); |
| 202 | if (mem_cfg_fd < 0) { |
| 203 | RTE_LOG(ERR, EAL, "Cannot open '%s' for rte_mem_config\n", |
| 204 | pathname); |
| 205 | return -1; |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | retval = ftruncate(mem_cfg_fd, cfg_len); |
| 210 | if (retval < 0){ |
| 211 | close(mem_cfg_fd); |
| 212 | mem_cfg_fd = -1; |
| 213 | RTE_LOG(ERR, EAL, "Cannot resize '%s' for rte_mem_config\n", |
| 214 | pathname); |
| 215 | return -1; |
| 216 | } |
| 217 | |
| 218 | retval = fcntl(mem_cfg_fd, F_SETLK, &wr_lock); |
| 219 | if (retval < 0){ |
| 220 | close(mem_cfg_fd); |
| 221 | mem_cfg_fd = -1; |
| 222 | RTE_LOG(ERR, EAL, "Cannot create lock on '%s'. Is another primary " |
| 223 | "process running?\n", pathname); |
| 224 | return -1; |
| 225 | } |
| 226 | |
| 227 | /* reserve space for config */ |
| 228 | rte_mem_cfg_addr = eal_get_virtual_area(rte_mem_cfg_addr, |
| 229 | &cfg_len_aligned, page_sz, 0, 0); |
| 230 | if (rte_mem_cfg_addr == NULL) { |
| 231 | RTE_LOG(ERR, EAL, "Cannot mmap memory for rte_config\n"); |
| 232 | close(mem_cfg_fd); |
no test coverage detected