diff options
author | Maciej Żenczykowski <maze@google.com> | 2019-04-01 10:41:13 -0700 |
---|---|---|
committer | Maciej Żenczykowski <maze@google.com> | 2019-04-01 16:54:08 -0700 |
commit | 52108bf52ca39f20c50078fdfde5eec5ceac8476 (patch) | |
tree | 071dc7cd4ea2a350f01129f7fceddc0222aa9975 | |
parent | 04d88b7576ecc256d43588598f0176b7e5ba73b5 (diff) | |
download | android_system_bpf-52108bf52ca39f20c50078fdfde5eec5ceac8476.tar.gz android_system_bpf-52108bf52ca39f20c50078fdfde5eec5ceac8476.tar.bz2 android_system_bpf-52108bf52ca39f20c50078fdfde5eec5ceac8476.zip |
BpfMap.getOrCreate(size, path, type) -> BpfMap.init(path)
We don't have the appropriate selinux privs to create the maps anyway.
Test: builds (when combined with system/netd change)
'git grep getOrCreate' in system/{bpf,netd} comes up empty
atest netd_unit_test netd_integration_test libbpf_android_test
Bug: 65674744
Bug: 129654883
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Idffbce5b28b723943c6495cfafdecddc7a0f4e67
-rw-r--r-- | libbpf_android/BpfMapTest.cpp | 2 | ||||
-rw-r--r-- | libbpf_android/include/bpf/BpfMap.h | 34 |
2 files changed, 8 insertions, 28 deletions
diff --git a/libbpf_android/BpfMapTest.cpp b/libbpf_android/BpfMapTest.cpp index 74fc2b8..cfa9d88 100644 --- a/libbpf_android/BpfMapTest.cpp +++ b/libbpf_android/BpfMapTest.cpp @@ -174,7 +174,7 @@ TEST_F(BpfMapTest, SetUpMap) { EXPECT_EQ(0, access(PINNED_MAP_PATH, R_OK)); checkMapValid(testMap1); BpfMap<uint32_t, uint32_t> testMap2; - EXPECT_OK(testMap2.getOrCreate(TEST_MAP_SIZE, PINNED_MAP_PATH, BPF_MAP_TYPE_HASH)); + EXPECT_OK(testMap2.init(PINNED_MAP_PATH)); checkMapValid(testMap2); uint32_t key = TEST_KEY1; uint32_t value = TEST_VALUE1; 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; } |