summaryrefslogtreecommitdiffstats
path: root/libbpf_android/include/bpf/BpfMap.h
diff options
context:
space:
mode:
Diffstat (limited to 'libbpf_android/include/bpf/BpfMap.h')
-rw-r--r--libbpf_android/include/bpf/BpfMap.h34
1 files changed, 7 insertions, 27 deletions
diff --git a/libbpf_android/include/bpf/BpfMap.h b/libbpf_android/include/bpf/BpfMap.h
index a274b01..d47698e 100644
--- a/libbpf_android/include/bpf/BpfMap.h
+++ b/libbpf_android/include/bpf/BpfMap.h
@@ -100,10 +100,8 @@ class BpfMap {
return netdutils::status::ok;
}
- // Function that tries to get map from a pinned path, if the map doesn't
- // exist yet, create a new one and pinned to the path.
- netdutils::Status getOrCreate(const uint32_t maxEntries, const char* path,
- const bpf_map_type mapType);
+ // Function that tries to get map from a pinned path.
+ netdutils::Status init(const char* path);
// Iterate through the map and handle each key retrieved based on the filter
// without modification of map content.
@@ -168,31 +166,13 @@ class BpfMap {
};
template <class Key, class Value>
-netdutils::Status BpfMap<Key, Value>::getOrCreate(const uint32_t maxEntries, const char* path,
- bpf_map_type mapType) {
- int ret = access(path, R_OK);
- /* Check the pinned location first to check if the map is already there.
- * otherwise create a new one.
- */
- if (ret == 0) {
- mMapFd = base::unique_fd(mapRetrieve(path, 0));
- if (mMapFd == -1) {
- reset();
- return netdutils::statusFromErrno(
+netdutils::Status BpfMap<Key, Value>::init(const char* path) {
+ mMapFd = base::unique_fd(mapRetrieve(path, 0));
+ if (mMapFd == -1) {
+ reset();
+ return netdutils::statusFromErrno(
errno,
base::StringPrintf("pinned map not accessible or does not exist: (%s)\n", path));
- }
- } else if (ret == -1 && errno == ENOENT) {
- mMapFd = base::unique_fd(
- createMap(mapType, sizeof(Key), sizeof(Value), maxEntries, BPF_F_NO_PREALLOC));
- if (mMapFd == -1) {
- reset();
- return netdutils::statusFromErrno(errno,
- base::StringPrintf("map create failed!: %s", path));
- }
- } else {
- return netdutils::statusFromErrno(
- errno, base::StringPrintf("pinned map not accessible: %s", path));
}
return netdutils::status::ok;
}