mem: revert to using flock and add per-segment lockfiles
[dpdk.git] / lib / librte_eal / linuxapp / eal / eal_hugepage_info.c
index 485a89e..7eca711 100644 (file)
@@ -236,18 +236,6 @@ get_hugepage_dir(uint64_t hugepage_sz, char *hugedir, int len)
        return retval;
 }
 
-/*
- * uses fstat to report the size of a file on disk
- */
-static off_t
-get_file_size(int fd)
-{
-       struct stat st;
-       if (fstat(fd, &st) < 0)
-               return 0;
-       return st.st_size;
-}
-
 /*
  * Clear the hugepage directory of whatever hugepage files
  * there are. Checks if the file is locked (i.e.
@@ -278,8 +266,6 @@ clear_hugedir(const char * hugedir)
        }
 
        while(dirent != NULL){
-               struct flock lck = {0};
-
                /* skip files that don't match the hugepage pattern */
                if (fnmatch(filter, dirent->d_name, 0) > 0) {
                        dirent = readdir(dir);
@@ -296,14 +282,9 @@ clear_hugedir(const char * hugedir)
                }
 
                /* non-blocking lock */
-               lck.l_type = F_RDLCK;
-               lck.l_whence = SEEK_SET;
-               lck.l_start = 0;
-               lck.l_len = get_file_size(fd);
-
-               lck_result = fcntl(fd, F_SETLK, &lck);
+               lck_result = flock(fd, LOCK_EX | LOCK_NB);
 
-               /* if lock succeeds, unlock and remove the file */
+               /* if lock succeeds, remove the file */
                if (lck_result != -1)
                        unlinkat(dir_fd, dirent->d_name, 0);
                close (fd);