BpfMap - remove mPinnedPath, getPinnedPath, pinToPath
Test: builds, git grep 'mPinnedPath|getPinnedPath|pinToPath' 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: Iad84ce7c74bef77e63cf63563d67b7501dd0165b
diff --git a/libbpf_android/BpfMapTest.cpp b/libbpf_android/BpfMapTest.cpp
index 692442d..74fc2b8 100644
--- a/libbpf_android/BpfMapTest.cpp
+++ b/libbpf_android/BpfMapTest.cpp
@@ -76,7 +76,6 @@
void checkMapInvalid(BpfMap<uint32_t, uint32_t>& map) {
EXPECT_FALSE(map.isValid());
EXPECT_EQ(-1, map.getMap().get());
- EXPECT_TRUE(map.getPinnedPath().empty());
}
void checkMapValid(BpfMap<uint32_t, uint32_t>& map) {
@@ -118,11 +117,9 @@
BpfMap<uint32_t, uint32_t> testMap2(mMapFd);
checkMapValid(testMap2);
- EXPECT_TRUE(testMap2.getPinnedPath().empty());
BpfMap<uint32_t, uint32_t> testMap3(BPF_MAP_TYPE_HASH, TEST_MAP_SIZE, BPF_F_NO_PREALLOC);
checkMapValid(testMap3);
- EXPECT_TRUE(testMap3.getPinnedPath().empty());
}
TEST_F(BpfMapTest, basicHelpers) {
@@ -168,34 +165,17 @@
writeToMapAndCheck(testMap2, key, value);
}
-TEST_F(BpfMapTest, pinnedToPath) {
- SKIP_IF_BPF_NOT_SUPPORTED;
-
- BpfMap<uint32_t, uint32_t> testMap1(mMapFd);
- EXPECT_OK(testMap1.pinToPath(PINNED_MAP_PATH));
- EXPECT_EQ(0, access(PINNED_MAP_PATH, R_OK));
- EXPECT_EQ(0, testMap1.getPinnedPath().compare(PINNED_MAP_PATH));
- BpfMap<uint32_t, uint32_t> testMap2(mapRetrieve(PINNED_MAP_PATH, 0));
- checkMapValid(testMap2);
- uint32_t key = TEST_KEY1;
- uint32_t value = TEST_VALUE1;
- writeToMapAndCheck(testMap1, key, value);
- StatusOr<uint32_t> value_read = testMap2.readValue(key);
- checkValueAndStatus(value, value_read);
-}
-
TEST_F(BpfMapTest, SetUpMap) {
SKIP_IF_BPF_NOT_SUPPORTED;
- BpfMap<uint32_t, uint32_t> testMap1;
- EXPECT_OK(testMap1.getOrCreate(TEST_MAP_SIZE, PINNED_MAP_PATH, BPF_MAP_TYPE_HASH));
+ EXPECT_NE(0, access(PINNED_MAP_PATH, R_OK));
+ BpfMap<uint32_t, uint32_t> testMap1(BPF_MAP_TYPE_HASH, TEST_MAP_SIZE, BPF_F_NO_PREALLOC);
+ ASSERT_EQ(0, bpfFdPin(testMap1.getMap(), PINNED_MAP_PATH));
EXPECT_EQ(0, access(PINNED_MAP_PATH, R_OK));
checkMapValid(testMap1);
- EXPECT_EQ(0, testMap1.getPinnedPath().compare(PINNED_MAP_PATH));
BpfMap<uint32_t, uint32_t> testMap2;
EXPECT_OK(testMap2.getOrCreate(TEST_MAP_SIZE, PINNED_MAP_PATH, BPF_MAP_TYPE_HASH));
checkMapValid(testMap2);
- EXPECT_EQ(0, testMap2.getPinnedPath().compare(PINNED_MAP_PATH));
uint32_t key = TEST_KEY1;
uint32_t value = TEST_VALUE1;
writeToMapAndCheck(testMap1, key, value);
diff --git a/libbpf_android/include/bpf/BpfMap.h b/libbpf_android/include/bpf/BpfMap.h
index deeed14..a274b01 100644
--- a/libbpf_android/include/bpf/BpfMap.h
+++ b/libbpf_android/include/bpf/BpfMap.h
@@ -57,16 +57,6 @@
}
}
- netdutils::Status pinToPath(const std::string& path) {
- int ret = bpfFdPin(mMapFd, path.c_str());
- if (ret) {
- return netdutils::statusFromErrno(errno,
- base::StringPrintf("pin to %s failed", path.c_str()));
- }
- mPinnedPath = path;
- return netdutils::status::ok;
- }
-
netdutils::StatusOr<Key> getFirstKey() const {
Key firstKey;
if (getFirstMapKey(mMapFd, &firstKey)) {
@@ -139,22 +129,14 @@
const base::unique_fd& getMap() const { return mMapFd; };
- const std::string getPinnedPath() const { return mPinnedPath; };
-
// Move constructor
void operator=(BpfMap<Key, Value>&& other) noexcept {
mMapFd = std::move(other.mMapFd);
- if (!other.mPinnedPath.empty()) {
- mPinnedPath = other.mPinnedPath;
- } else {
- mPinnedPath.clear();
- }
other.reset();
}
void reset(int fd = -1) {
mMapFd.reset(fd);
- mPinnedPath.clear();
}
bool isValid() const { return mMapFd != -1; }
@@ -183,7 +165,6 @@
private:
base::unique_fd mMapFd;
- std::string mPinnedPath;
};
template <class Key, class Value>
@@ -201,7 +182,6 @@
errno,
base::StringPrintf("pinned map not accessible or does not exist: (%s)\n", path));
}
- mPinnedPath = path;
} else if (ret == -1 && errno == ENOENT) {
mMapFd = base::unique_fd(
createMap(mapType, sizeof(Key), sizeof(Value), maxEntries, BPF_F_NO_PREALLOC));
@@ -210,12 +190,6 @@
return netdutils::statusFromErrno(errno,
base::StringPrintf("map create failed!: %s", path));
}
- netdutils::Status pinStatus = pinToPath(path);
- if (!isOk(pinStatus)) {
- reset();
- return pinStatus;
- }
- mPinnedPath = path;
} else {
return netdutils::statusFromErrno(
errno, base::StringPrintf("pinned map not accessible: %s", path));