MCPcopy Create free account
hub / github.com/F-Stack/f-stack / get_seg_fd

Function get_seg_fd

dpdk/lib/eal/linux/eal_memalloc.c:280–367  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

278}
279
280static int
281get_seg_fd(char *path, int buflen, struct hugepage_info *hi,
282 unsigned int list_idx, unsigned int seg_idx,
283 bool *dirty)
284{
285 int fd;
286 int *out_fd;
287 struct stat st;
288 int ret;
289 const struct internal_config *internal_conf =
290 eal_get_internal_configuration();
291
292 if (dirty != NULL)
293 *dirty = false;
294
295 /* for in-memory mode, we only make it here when we're sure we support
296 * memfd, and this is a special case.
297 */
298 if (internal_conf->in_memory)
299 return get_seg_memfd(hi, list_idx, seg_idx);
300
301 if (internal_conf->single_file_segments) {
302 out_fd = &fd_list[list_idx].memseg_list_fd;
303 eal_get_hugefile_path(path, buflen, hi->hugedir, list_idx);
304 } else {
305 out_fd = &fd_list[list_idx].fds[seg_idx];
306 eal_get_hugefile_path(path, buflen, hi->hugedir,
307 list_idx * RTE_MAX_MEMSEG_PER_LIST + seg_idx);
308 }
309 fd = *out_fd;
310 if (fd >= 0)
311 return fd;
312
313 /*
314 * There is no TOCTOU between stat() and unlink()/open()
315 * because the hugepage directory is locked.
316 */
317 ret = stat(path, &st);
318 if (ret < 0 && errno != ENOENT) {
319 RTE_LOG(DEBUG, EAL, "%s(): stat() for '%s' failed: %s\n",
320 __func__, path, strerror(errno));
321 return -1;
322 }
323 if (!internal_conf->hugepage_file.unlink_existing && ret == 0 &&
324 dirty != NULL)
325 *dirty = true;
326
327 /*
328 * The kernel clears a hugepage only when it is mapped
329 * from a particular file for the first time.
330 * If the file already exists, the old content will be mapped.
331 * If the memory manager assumes all mapped pages to be clean,
332 * the file must be removed and created anew.
333 * Otherwise, the primary caller must be notified
334 * that mapped pages will be dirty
335 * (secondary callers receive the segment state from the primary one).
336 * When multiple hugepages are mapped from the same file,
337 * whether they will be dirty depends on the part that is mapped.

Callers 2

alloc_segFunction · 0.85
free_segFunction · 0.85

Calls 7

get_seg_memfdFunction · 0.85
eal_get_hugefile_pathFunction · 0.85
rte_eal_process_typeFunction · 0.85
statClass · 0.70
lockFunction · 0.70
closeFunction · 0.50

Tested by

no test coverage detected