bpf: Use bpf_map_delete_elem() from the library
authorMickaël Salaün <mic@digikod.net>
Thu, 9 Feb 2017 23:21:41 +0000 (00:21 +0100)
committerDavid S. Miller <davem@davemloft.net>
Fri, 10 Feb 2017 20:56:07 +0000 (15:56 -0500)
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>
Signed-off-by: David S. Miller <davem@davemloft.net>
tools/lib/bpf/bpf.c
tools/lib/bpf/bpf.h
tools/testing/selftests/bpf/bpf_sys.h
tools/testing/selftests/bpf/test_lru_map.c
tools/testing/selftests/bpf/test_maps.c

index b1a1f58b99e09b7e8544171b2c1cdc8add12f948..eab8c6bfbf8f5ee57f0ee6bdd66e14acbca26a53 100644 (file)
@@ -124,7 +124,7 @@ 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;
 
index 171cf594f78231508a78adb62e4844a83142c6cd..f559f648db45027e7a111c7ace3c541acfb4f356 100644 (file)
@@ -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);
index 0a5a6060db70b1e75d80ad4a7ba89a4bc4d932c8..17581a42e1d9a07ab38fc11e3c26de7bda600819 100644 (file)
@@ -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 = {};
index eccf6d96e551e187d25f883a64cb4cd118b6b071..859c940a6e4108723afd0c3128d509b610589df9 100644 (file)
@@ -324,7 +324,7 @@ static void test_lru_sanity2(int map_type, int map_flags, unsigned int tgt_free)
        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));
@@ -483,8 +483,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;
index 5db1a939af69ab238c2f3b5fd796f4339da17a48..0f9f90455375c58a6a7d7fe6d22ce173da8b640a 100644 (file)
@@ -86,7 +86,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 &&
@@ -98,10 +98,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. */
@@ -172,7 +172,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)) {
@@ -194,10 +194,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. */
@@ -255,7 +255,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);
 }
@@ -310,7 +310,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);
 }
@@ -445,7 +445,7 @@ static void do_work(int fn, void *data)
                        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);
                }
        }
 }