From 04d88b7576ecc256d43588598f0176b7e5ba73b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Date: Mon, 1 Apr 2019 10:34:26 -0700 Subject: BpfMap - remove mPinnedPath, getPinnedPath, pinToPath MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Change-Id: Iad84ce7c74bef77e63cf63563d67b7501dd0165b --- libbpf_android/BpfMapTest.cpp | 26 +++----------------------- libbpf_android/include/bpf/BpfMap.h | 26 -------------------------- 2 files changed, 3 insertions(+), 49 deletions(-) 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 @@ class BpfMapTest : public testing::Test { void checkMapInvalid(BpfMap& map) { EXPECT_FALSE(map.isValid()); EXPECT_EQ(-1, map.getMap().get()); - EXPECT_TRUE(map.getPinnedPath().empty()); } void checkMapValid(BpfMap& map) { @@ -118,11 +117,9 @@ TEST_F(BpfMapTest, constructor) { BpfMap testMap2(mMapFd); checkMapValid(testMap2); - EXPECT_TRUE(testMap2.getPinnedPath().empty()); BpfMap 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 @@ TEST_F(BpfMapTest, moveConstructor) { writeToMapAndCheck(testMap2, key, value); } -TEST_F(BpfMapTest, pinnedToPath) { - SKIP_IF_BPF_NOT_SUPPORTED; - - BpfMap 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 testMap2(mapRetrieve(PINNED_MAP_PATH, 0)); - checkMapValid(testMap2); - uint32_t key = TEST_KEY1; - uint32_t value = TEST_VALUE1; - writeToMapAndCheck(testMap1, key, value); - StatusOr value_read = testMap2.readValue(key); - checkValueAndStatus(value, value_read); -} - TEST_F(BpfMapTest, SetUpMap) { SKIP_IF_BPF_NOT_SUPPORTED; - BpfMap 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 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 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 @@ class BpfMap { } } - 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 getFirstKey() const { Key firstKey; if (getFirstMapKey(mMapFd, &firstKey)) { @@ -139,22 +129,14 @@ class BpfMap { const base::unique_fd& getMap() const { return mMapFd; }; - const std::string getPinnedPath() const { return mPinnedPath; }; - // Move constructor void operator=(BpfMap&& 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 @@ class BpfMap { private: base::unique_fd mMapFd; - std::string mPinnedPath; }; template @@ -201,7 +182,6 @@ netdutils::Status BpfMap::getOrCreate(const uint32_t maxEntries, con 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 @@ netdutils::Status BpfMap::getOrCreate(const uint32_t maxEntries, con 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)); -- cgit v1.2.3