From: "Mickaël Salaün" <mic@digikod.net>
To: linux-kernel@vger.kernel.org
Cc: "Mickaël Salaün" <mic@digikod.net>,
"Alexei Starovoitov" <ast@fb.com>,
"Arnaldo Carvalho de Melo" <acme@redhat.com>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"David S . Miller" <davem@davemloft.net>,
netdev@vger.kernel.org, "Shuah Khan" <shuah@kernel.org>
Subject: [PATCH net-next v3 07/11] bpf: Use bpf_map_delete_elem() from the library
Date: Tue, 7 Feb 2017 22:44:56 +0100 [thread overview]
Message-ID: <20170207214500.27496-8-mic@digikod.net> (raw)
In-Reply-To: <20170207214500.27496-1-mic@digikod.net>
Replace bpf_map_delete() with bpf_map_delete_elem() calls.
Signed-off-by: Mickaël Salaün <mic@digikod.net>
Cc: Alexei Starovoitov <ast@fb.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Shuah Khan <shuah@kernel.org>
---
tools/lib/bpf/bpf.c | 5 ++---
tools/lib/bpf/bpf.h | 2 +-
tools/testing/selftests/bpf/bpf_sys.h | 10 ----------
tools/testing/selftests/bpf/test_lru_map.c | 6 +++---
tools/testing/selftests/bpf/test_maps.c | 22 +++++++++++-----------
5 files changed, 17 insertions(+), 28 deletions(-)
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
index 81505801fa33..ee3a87de15ba 100644
--- a/tools/lib/bpf/bpf.c
+++ b/tools/lib/bpf/bpf.c
@@ -121,11 +121,10 @@ int bpf_map_lookup_elem(int fd, const void *key, void *value)
return sys_bpf(BPF_MAP_LOOKUP_ELEM, &attr, sizeof(attr));
}
-int bpf_map_delete_elem(int fd, void *key)
+int bpf_map_delete_elem(int fd, const void *key)
{
- union bpf_attr attr;
+ union bpf_attr attr = {};
- bzero(&attr, sizeof(attr));
attr.map_fd = fd;
attr.key = ptr_to_u64(key);
diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
index 171cf594f782..f559f648db45 100644
--- a/tools/lib/bpf/bpf.h
+++ b/tools/lib/bpf/bpf.h
@@ -37,7 +37,7 @@ int bpf_map_update_elem(int fd, const void *key, const void *value,
__u64 flags);
int bpf_map_lookup_elem(int fd, const void *key, void *value);
-int bpf_map_delete_elem(int fd, void *key);
+int bpf_map_delete_elem(int fd, const void *key);
int bpf_map_get_next_key(int fd, void *key, void *next_key);
int bpf_obj_pin(int fd, const char *pathname);
int bpf_obj_get(const char *pathname);
diff --git a/tools/testing/selftests/bpf/bpf_sys.h b/tools/testing/selftests/bpf/bpf_sys.h
index 0a5a6060db70..17581a42e1d9 100644
--- a/tools/testing/selftests/bpf/bpf_sys.h
+++ b/tools/testing/selftests/bpf/bpf_sys.h
@@ -24,16 +24,6 @@ static inline int bpf(int cmd, union bpf_attr *attr, unsigned int size)
#endif
}
-static inline int bpf_map_delete(int fd, const void *key)
-{
- union bpf_attr attr = {};
-
- attr.map_fd = fd;
- attr.key = bpf_ptr_to_u64(key);
-
- return bpf(BPF_MAP_DELETE_ELEM, &attr, sizeof(attr));
-}
-
static inline int bpf_map_next_key(int fd, const void *key, void *next_key)
{
union bpf_attr attr = {};
diff --git a/tools/testing/selftests/bpf/test_lru_map.c b/tools/testing/selftests/bpf/test_lru_map.c
index 53155009bdb6..d375fac1a49c 100644
--- a/tools/testing/selftests/bpf/test_lru_map.c
+++ b/tools/testing/selftests/bpf/test_lru_map.c
@@ -318,7 +318,7 @@ static void test_lru_sanity2(int map_type, int map_flags, unsigned int tgt_free)
key = 1;
if (map_type == BPF_MAP_TYPE_LRU_PERCPU_HASH) {
assert(!bpf_map_update_elem(lru_map_fd, &key, value, BPF_NOEXIST));
- assert(!bpf_map_delete(lru_map_fd, &key));
+ assert(!bpf_map_delete_elem(lru_map_fd, &key));
} else {
assert(bpf_map_update_elem(lru_map_fd, &key, value, BPF_EXIST));
}
@@ -470,8 +470,8 @@ static void test_lru_sanity4(int map_type, int map_flags, unsigned int tgt_free)
}
for (; key <= 2 * tgt_free; key++) {
- assert(!bpf_map_delete(lru_map_fd, &key));
- assert(bpf_map_delete(lru_map_fd, &key));
+ assert(!bpf_map_delete_elem(lru_map_fd, &key));
+ assert(bpf_map_delete_elem(lru_map_fd, &key));
}
end_key = key + 2 * tgt_free;
diff --git a/tools/testing/selftests/bpf/test_maps.c b/tools/testing/selftests/bpf/test_maps.c
index c73a1fbc5bcc..ae22fdc93172 100644
--- a/tools/testing/selftests/bpf/test_maps.c
+++ b/tools/testing/selftests/bpf/test_maps.c
@@ -85,7 +85,7 @@ static void test_hashmap(int task, void *data)
/* Check that key = 0 doesn't exist. */
key = 0;
- assert(bpf_map_delete(fd, &key) == -1 && errno == ENOENT);
+ assert(bpf_map_delete_elem(fd, &key) == -1 && errno == ENOENT);
/* Iterate over two elements. */
assert(bpf_map_next_key(fd, &key, &next_key) == 0 &&
@@ -97,10 +97,10 @@ static void test_hashmap(int task, void *data)
/* Delete both elements. */
key = 1;
- assert(bpf_map_delete(fd, &key) == 0);
+ assert(bpf_map_delete_elem(fd, &key) == 0);
key = 2;
- assert(bpf_map_delete(fd, &key) == 0);
- assert(bpf_map_delete(fd, &key) == -1 && errno == ENOENT);
+ assert(bpf_map_delete_elem(fd, &key) == 0);
+ assert(bpf_map_delete_elem(fd, &key) == -1 && errno == ENOENT);
key = 0;
/* Check that map is empty. */
@@ -170,7 +170,7 @@ static void test_hashmap_percpu(int task, void *data)
errno == E2BIG);
/* Check that key = 0 doesn't exist. */
- assert(bpf_map_delete(fd, &key) == -1 && errno == ENOENT);
+ assert(bpf_map_delete_elem(fd, &key) == -1 && errno == ENOENT);
/* Iterate over two elements. */
while (!bpf_map_next_key(fd, &key, &next_key)) {
@@ -192,10 +192,10 @@ static void test_hashmap_percpu(int task, void *data)
/* Delete both elements. */
key = 1;
- assert(bpf_map_delete(fd, &key) == 0);
+ assert(bpf_map_delete_elem(fd, &key) == 0);
key = 2;
- assert(bpf_map_delete(fd, &key) == 0);
- assert(bpf_map_delete(fd, &key) == -1 && errno == ENOENT);
+ assert(bpf_map_delete_elem(fd, &key) == 0);
+ assert(bpf_map_delete_elem(fd, &key) == -1 && errno == ENOENT);
key = 0;
/* Check that map is empty. */
@@ -253,7 +253,7 @@ static void test_arraymap(int task, void *data)
/* Delete shouldn't succeed. */
key = 1;
- assert(bpf_map_delete(fd, &key) == -1 && errno == EINVAL);
+ assert(bpf_map_delete_elem(fd, &key) == -1 && errno == EINVAL);
close(fd);
}
@@ -308,7 +308,7 @@ static void test_arraymap_percpu(int task, void *data)
/* Delete shouldn't succeed. */
key = 1;
- assert(bpf_map_delete(fd, &key) == -1 && errno == EINVAL);
+ assert(bpf_map_delete_elem(fd, &key) == -1 && errno == EINVAL);
close(fd);
}
@@ -441,7 +441,7 @@ static void do_work(int fn, void *data)
assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) == 0);
assert(bpf_map_update_elem(fd, &key, &value, BPF_EXIST) == 0);
} else {
- assert(bpf_map_delete(fd, &key) == 0);
+ assert(bpf_map_delete_elem(fd, &key) == 0);
}
}
}
--
2.11.0
next prev parent reply other threads:[~2017-02-07 21:49 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-07 21:44 [PATCH net-next v3 00/11] Improve BPF selftests and use the library (net-next tree) Mickaël Salaün
2017-02-07 21:44 ` [PATCH net-next v3 01/11] tools: Sync {,tools/}include/uapi/linux/bpf.h Mickaël Salaün
2017-02-07 21:44 ` [PATCH net-next v3 02/11] bpf: Change the include directory for selftest Mickaël Salaün
2017-02-07 21:44 ` [PATCH net-next v3 03/11] bpf: Always test unprivileged programs Mickaël Salaün
2017-02-07 21:44 ` [PATCH net-next v3 04/11] bpf: Use bpf_load_program() from the library Mickaël Salaün
2017-02-07 23:17 ` Alexei Starovoitov
2017-02-08 19:41 ` Arnaldo Carvalho de Melo
2017-02-08 19:46 ` Arnaldo Carvalho de Melo
2017-02-08 20:08 ` Mickaël Salaün
2017-02-07 21:44 ` [PATCH net-next v3 05/11] bpf: Use bpf_map_update_elem() " Mickaël Salaün
2017-02-07 21:44 ` [PATCH net-next v3 06/11] bpf: Use bpf_map_lookup_elem() " Mickaël Salaün
2017-02-07 21:44 ` Mickaël Salaün [this message]
2017-02-07 21:44 ` [PATCH net-next v3 08/11] bpf: Use bpf_map_get_next_key() " Mickaël Salaün
2017-02-07 21:44 ` [PATCH net-next v3 09/11] bpf: Use bpf_create_map() " Mickaël Salaün
2017-02-07 21:44 ` [PATCH net-next v3 10/11] bpf: Remove bpf_sys.h from selftests Mickaël Salaün
2017-02-07 21:45 ` [PATCH net-next v3 11/11] bpf: Add test_tag to .gitignore Mickaël Salaün
2017-02-08 19:15 ` [PATCH net-next v3 00/11] Improve BPF selftests and use the library (net-next tree) David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170207214500.27496-8-mic@digikod.net \
--to=mic@digikod.net \
--cc=acme@redhat.com \
--cc=ast@fb.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).