#include <sys/mman.h>
#include <stdint.h>
#include <errno.h>
-#include <sys/file.h>
#include <string.h>
+#include <unistd.h>
#include <rte_common.h>
#include <rte_log.h>
char path[PATH_MAX];
void *map_addr;
- if (ftruncate(fd, len)) {
+ if (eal_file_truncate(fd, len)) {
RTE_LOG(ERR, EAL, "Cannot truncate %s\n", path);
- /* pass errno up the chain */
- rte_errno = errno;
return -1;
}
return 0;
}
-int __rte_experimental
+int
rte_fbarray_init(struct rte_fbarray *arr, const char *name, unsigned int len,
unsigned int elt_sz)
{
}
page_sz = sysconf(_SC_PAGESIZE);
- if (page_sz == (size_t)-1)
- goto fail;
+ if (page_sz == (size_t)-1) {
+ free(ma);
+ return -1;
+ }
/* calculate our memory limits */
mmap_len = calc_data_size(page_sz, elt_sz, len);
data = eal_get_virtual_area(NULL, &mmap_len, page_sz, 0, 0);
- if (data == NULL)
- goto fail;
+ if (data == NULL) {
+ free(ma);
+ return -1;
+ }
rte_spinlock_lock(&mem_area_lock);
* and see if we succeed. If we don't, someone else is using it
* already.
*/
- fd = open(path, O_CREAT | O_RDWR, 0600);
+ fd = eal_file_open(path, EAL_OPEN_CREATE | EAL_OPEN_READWRITE);
if (fd < 0) {
RTE_LOG(DEBUG, EAL, "%s(): couldn't open %s: %s\n",
- __func__, path, strerror(errno));
- rte_errno = errno;
+ __func__, path, rte_strerror(rte_errno));
goto fail;
- } else if (flock(fd, LOCK_EX | LOCK_NB)) {
+ } else if (eal_file_lock(
+ fd, EAL_FLOCK_EXCLUSIVE, EAL_FLOCK_RETURN)) {
RTE_LOG(DEBUG, EAL, "%s(): couldn't lock %s: %s\n",
- __func__, path, strerror(errno));
+ __func__, path, rte_strerror(rte_errno));
rte_errno = EBUSY;
goto fail;
}
* still attach to it, but no other process could reinitialize
* it.
*/
- if (flock(fd, LOCK_SH | LOCK_NB)) {
- rte_errno = errno;
+ if (eal_file_lock(fd, EAL_FLOCK_SHARED, EAL_FLOCK_RETURN))
goto fail;
- }
if (resize_and_map(fd, data, mmap_len))
goto fail;
return -1;
}
-int __rte_experimental
+int
rte_fbarray_attach(struct rte_fbarray *arr)
{
struct mem_area *ma = NULL, *tmp = NULL;
}
page_sz = sysconf(_SC_PAGESIZE);
- if (page_sz == (size_t)-1)
- goto fail;
+ if (page_sz == (size_t)-1) {
+ free(ma);
+ return -1;
+ }
mmap_len = calc_data_size(page_sz, arr->elt_sz, arr->len);
eal_get_fbarray_path(path, sizeof(path), arr->name);
- fd = open(path, O_RDWR);
+ fd = eal_file_open(path, EAL_OPEN_READWRITE);
if (fd < 0) {
- rte_errno = errno;
goto fail;
}
/* lock the file, to let others know we're using it */
- if (flock(fd, LOCK_SH | LOCK_NB)) {
- rte_errno = errno;
+ if (eal_file_lock(fd, EAL_FLOCK_SHARED, EAL_FLOCK_RETURN))
goto fail;
- }
if (resize_and_map(fd, data, mmap_len))
goto fail;
/* we're done */
+ rte_spinlock_unlock(&mem_area_lock);
return 0;
fail:
if (data)
if (fd >= 0)
close(fd);
free(ma);
+ rte_spinlock_unlock(&mem_area_lock);
return -1;
}
-int __rte_experimental
+int
rte_fbarray_detach(struct rte_fbarray *arr)
{
struct mem_area *tmp = NULL;
return ret;
}
-int __rte_experimental
+int
rte_fbarray_destroy(struct rte_fbarray *arr)
{
struct mem_area *tmp = NULL;
* has been detached by all other processes
*/
fd = tmp->fd;
- if (flock(fd, LOCK_EX | LOCK_NB)) {
+ if (eal_file_lock(fd, EAL_FLOCK_EXCLUSIVE, EAL_FLOCK_RETURN)) {
RTE_LOG(DEBUG, EAL, "Cannot destroy fbarray - another process is using it\n");
rte_errno = EBUSY;
ret = -1;
* we're still holding an exclusive lock, so drop it to
* shared.
*/
- flock(fd, LOCK_SH | LOCK_NB);
+ eal_file_lock(fd, EAL_FLOCK_SHARED, EAL_FLOCK_RETURN);
ret = -1;
goto out;
TAILQ_REMOVE(&mem_area_tailq, tmp, next);
free(tmp);
ret = 0;
+
+ /* reset the fbarray structure */
+ memset(arr, 0, sizeof(*arr));
out:
rte_spinlock_unlock(&mem_area_lock);
return ret;
}
-void * __rte_experimental
+void *
rte_fbarray_get(const struct rte_fbarray *arr, unsigned int idx)
{
void *ret = NULL;
return ret;
}
-int __rte_experimental
+int
rte_fbarray_set_used(struct rte_fbarray *arr, unsigned int idx)
{
return set_used(arr, idx, true);
}
-int __rte_experimental
+int
rte_fbarray_set_free(struct rte_fbarray *arr, unsigned int idx)
{
return set_used(arr, idx, false);
}
-int __rte_experimental
+int
rte_fbarray_is_used(struct rte_fbarray *arr, unsigned int idx)
{
struct used_mask *msk;
return ret;
}
-int __rte_experimental
+int
rte_fbarray_find_next_free(struct rte_fbarray *arr, unsigned int start)
{
return fbarray_find(arr, start, true, false);
}
-int __rte_experimental
+int
rte_fbarray_find_next_used(struct rte_fbarray *arr, unsigned int start)
{
return fbarray_find(arr, start, true, true);
}
-int __rte_experimental
+int
rte_fbarray_find_prev_free(struct rte_fbarray *arr, unsigned int start)
{
return fbarray_find(arr, start, false, false);
}
-int __rte_experimental
+int
rte_fbarray_find_prev_used(struct rte_fbarray *arr, unsigned int start)
{
return fbarray_find(arr, start, false, true);
return ret;
}
-int __rte_experimental
+int
rte_fbarray_find_next_n_free(struct rte_fbarray *arr, unsigned int start,
unsigned int n)
{
return fbarray_find_n(arr, start, n, true, false);
}
-int __rte_experimental
+int
rte_fbarray_find_next_n_used(struct rte_fbarray *arr, unsigned int start,
unsigned int n)
{
return fbarray_find_n(arr, start, n, true, true);
}
-int __rte_experimental
+int
rte_fbarray_find_prev_n_free(struct rte_fbarray *arr, unsigned int start,
unsigned int n)
{
return fbarray_find_n(arr, start, n, false, false);
}
-int __rte_experimental
+int
rte_fbarray_find_prev_n_used(struct rte_fbarray *arr, unsigned int start,
unsigned int n)
{
*/
/* the API's called are thread-safe, but something may still happen
- * inbetween the API calls, so lock the fbarray. all other API's are
+ * between the API calls, so lock the fbarray. all other API's are
* read-locking the fbarray, so read lock here is OK.
*/
rte_rwlock_read_lock(&arr->rwlock);
return biggest_idx;
}
-int __rte_experimental
+int
rte_fbarray_find_biggest_free(struct rte_fbarray *arr, unsigned int start)
{
return fbarray_find_biggest(arr, start, false, false);
}
-int __rte_experimental
+int
rte_fbarray_find_biggest_used(struct rte_fbarray *arr, unsigned int start)
{
return fbarray_find_biggest(arr, start, true, false);
}
-int __rte_experimental
+int
rte_fbarray_find_rev_biggest_free(struct rte_fbarray *arr, unsigned int start)
{
return fbarray_find_biggest(arr, start, false, true);
}
-int __rte_experimental
+int
rte_fbarray_find_rev_biggest_used(struct rte_fbarray *arr, unsigned int start)
{
return fbarray_find_biggest(arr, start, true, true);
}
-int __rte_experimental
+int
rte_fbarray_find_contig_free(struct rte_fbarray *arr, unsigned int start)
{
return fbarray_find_contig(arr, start, true, false);
}
-int __rte_experimental
+int
rte_fbarray_find_contig_used(struct rte_fbarray *arr, unsigned int start)
{
return fbarray_find_contig(arr, start, true, true);
}
-int __rte_experimental
+int
rte_fbarray_find_rev_contig_free(struct rte_fbarray *arr, unsigned int start)
{
return fbarray_find_contig(arr, start, false, false);
}
-int __rte_experimental
+int
rte_fbarray_find_rev_contig_used(struct rte_fbarray *arr, unsigned int start)
{
return fbarray_find_contig(arr, start, false, true);
}
-int __rte_experimental
+int
rte_fbarray_find_idx(const struct rte_fbarray *arr, const void *elt)
{
void *end;
return ret;
}
-void __rte_experimental
+void
rte_fbarray_dump_metadata(struct rte_fbarray *arr, FILE *f)
{
struct used_mask *msk;