src/dpdk/lib/librte_eal/linux/eal_hugepage_info.c
static int
clear_hugedir(const char * hugedir)
{
	DIR *dir;
	struct dirent *dirent;
	int dir_fd, fd, lck_result;
	const char filter[] = "*map_*"; /* matches hugepage files */

	/* open directory */
	dir = opendir(hugedir);
	if (!dir) {
		RTE_LOG(ERR, EAL, "Unable to open hugepage directory %s\n",
				hugedir);
		goto error;
	}
	dir_fd = dirfd(dir);

	dirent = readdir(dir);
	if (!dirent) {
		RTE_LOG(ERR, EAL, "Unable to read hugepage directory %s\n",
				hugedir);
		goto error;
	}

	while(dirent != NULL){
		/* skip files that don't match the hugepage pattern */
		if (fnmatch(filter, dirent->d_name, 0) > 0) {
			dirent = readdir(dir);
			continue;
		}

		/* try and lock the file */
		fd = openat(dir_fd, dirent->d_name, O_RDONLY);

		/* skip to next file */
		if (fd == -1) {
			dirent = readdir(dir);
			continue;
		}

		/* non-blocking lock */
		lck_result = flock(fd, LOCK_EX | LOCK_NB);

		/* if lock succeeds, remove the file */
		if (lck_result != -1)
			unlinkat(dir_fd, dirent->d_name, 0);
		close (fd);
		dirent = readdir(dir);
	}

	closedir(dir);
	return 0;

error:
	if (dir)
		closedir(dir);

	RTE_LOG(ERR, EAL, "Error while clearing hugepage dir: %s\n",
		strerror(errno));

	return -1;
}
/*
 * Clear the hugepage directory of whatever hugepage files
 * there are. Checks if the file is locked (i.e.
 * if it's in use by another DPDK process).
 */
Clear the hugepage directory of whatever hugepage files
there are. Checks if the file is locked .
Clear the hugepage directory of whatever hugepage files there are . Checks if the file is locked .
static int
clear_hugedir(const char * hugedir)
{
	DIR *dir;
	struct dirent *dirent;
	int dir_fd, fd, lck_result;
	const char filter[] = "*map_*"; 
	dir = opendir(hugedir);
	if (!dir) {
		RTE_LOG(ERR, EAL, "Unable to open hugepage directory %s\n",
				hugedir);
		goto error;
	}
	dir_fd = dirfd(dir);
	dirent = readdir(dir);
	if (!dirent) {
		RTE_LOG(ERR, EAL, "Unable to read hugepage directory %s\n",
				hugedir);
		goto error;
	}
	while(dirent != NULL){
		if (fnmatch(filter, dirent->d_name, 0) > 0) {
			dirent = readdir(dir);
			continue;
		}
		fd = openat(dir_fd, dirent->d_name, O_RDONLY);
		if (fd == -1) {
			dirent = readdir(dir);
			continue;
		}
		lck_result = flock(fd, LOCK_EX | LOCK_NB);
		if (lck_result != -1)
			unlinkat(dir_fd, dirent->d_name, 0);
		close (fd);
		dirent = readdir(dir);
	}
	closedir(dir);
	return 0;
error:
	if (dir)
		closedir(dir);
	RTE_LOG(ERR, EAL, "Error while clearing hugepage dir: %s\n",
		strerror(errno));
	return -1;
}
static int clear_hugedir ( const char * hugedir ) { DIR * dir ; struct dirent * dirent ; int dir_fd , fd , lck_result ; const char filter [ ] = " " ; dir = opendir ( hugedir ) ; if ( ! dir ) { RTE_LOG ( ERR , EAL , " \n " , hugedir ) ; goto error ; } dir_fd = dirfd ( dir ) ; dirent = readdir ( dir ) ; if ( ! dirent ) { RTE_LOG ( ERR , EAL , " \n " , hugedir ) ; goto error ; } while ( dirent != NULL ) { if ( fnmatch ( filter , dirent -> d_name , 0 ) > 0 ) { dirent = readdir ( dir ) ; continue ; } fd = openat ( dir_fd , dirent -> d_name , O_RDONLY ) ; if ( fd == -1 ) { dirent = readdir ( dir ) ; continue ; } lck_result = flock ( fd , LOCK_EX | LOCK_NB ) ; if ( lck_result != -1 ) unlinkat ( dir_fd , dirent -> d_name , 0 ) ; close ( fd ) ; dirent = readdir ( dir ) ; } closedir ( dir ) ; return 0 ; error : if ( dir ) closedir ( dir ) ; RTE_LOG ( ERR , EAL , " \n " , strerror ( errno ) ) ; return -1 ; }
Clear the hugepage directory of whatever hugepage files
 there are.
Clear the hugepage directory of whatever hugepage files there are .
/* matches hugepage files */ /* open directory */ /* skip files that don't match the hugepage pattern */ /* try and lock the file */ /* skip to next file */ /* non-blocking lock */ /* if lock succeeds, remove the file */