tools: Add definitions for devmap_hash map type
authorToke Høiland-Jørgensen <toke@redhat.com>
Fri, 26 Jul 2019 16:06:58 +0000 (18:06 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Mon, 29 Jul 2019 20:50:48 +0000 (13:50 -0700)
This adds selftest and bpftool updates for the devmap_hash map type.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
Acked-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/bpf/bpftool/Documentation/bpftool-map.rst
tools/bpf/bpftool/bash-completion/bpftool
tools/bpf/bpftool/map.c
tools/testing/selftests/bpf/test_maps.c

index 490b4501cb6ee021e802c96e088ac42e34fcb19f..61d1d270eb5eb577a28e178710ea59cd5fec60c8 100644 (file)
@@ -46,7 +46,7 @@ MAP COMMANDS
 |      *TYPE* := { **hash** | **array** | **prog_array** | **perf_event_array** | **percpu_hash**
 |              | **percpu_array** | **stack_trace** | **cgroup_array** | **lru_hash**
 |              | **lru_percpu_hash** | **lpm_trie** | **array_of_maps** | **hash_of_maps**
-|              | **devmap** | **sockmap** | **cpumap** | **xskmap** | **sockhash**
+|              | **devmap** | **devmap_hash** | **sockmap** | **cpumap** | **xskmap** | **sockhash**
 |              | **cgroup_storage** | **reuseport_sockarray** | **percpu_cgroup_storage**
 |              | **queue** | **stack** }
 
index c8f42e1fcbc994d859ede556b1a6a5a4e4e75e1b..6b961a5ed10067a9078fbf696c9f23172a72b0d8 100644 (file)
@@ -489,8 +489,8 @@ _bpftool()
                                 perf_event_array percpu_hash percpu_array \
                                 stack_trace cgroup_array lru_hash \
                                 lru_percpu_hash lpm_trie array_of_maps \
-                                hash_of_maps devmap sockmap cpumap xskmap \
-                                sockhash cgroup_storage reuseport_sockarray \
+                                hash_of_maps devmap devmap_hash sockmap cpumap \
+                                xskmap sockhash cgroup_storage reuseport_sockarray \
                                 percpu_cgroup_storage queue stack' -- \
                                                    "$cur" ) )
                             return 0
index 5da5a7311f13050773e82194621c317c08d1c482..bfbbc6b4cb83c7c7db9029cebbd5f49118fb66a3 100644 (file)
@@ -37,6 +37,7 @@ const char * const map_type_name[] = {
        [BPF_MAP_TYPE_ARRAY_OF_MAPS]            = "array_of_maps",
        [BPF_MAP_TYPE_HASH_OF_MAPS]             = "hash_of_maps",
        [BPF_MAP_TYPE_DEVMAP]                   = "devmap",
+       [BPF_MAP_TYPE_DEVMAP_HASH]              = "devmap_hash",
        [BPF_MAP_TYPE_SOCKMAP]                  = "sockmap",
        [BPF_MAP_TYPE_CPUMAP]                   = "cpumap",
        [BPF_MAP_TYPE_XSKMAP]                   = "xskmap",
@@ -1271,7 +1272,7 @@ static int do_help(int argc, char **argv)
                "       TYPE := { hash | array | prog_array | perf_event_array | percpu_hash |\n"
                "                 percpu_array | stack_trace | cgroup_array | lru_hash |\n"
                "                 lru_percpu_hash | lpm_trie | array_of_maps | hash_of_maps |\n"
-               "                 devmap | sockmap | cpumap | xskmap | sockhash |\n"
+               "                 devmap | devmap_hash | sockmap | cpumap | xskmap | sockhash |\n"
                "                 cgroup_storage | reuseport_sockarray | percpu_cgroup_storage }\n"
                "       " HELP_SPEC_OPTIONS "\n"
                "",
index 5443b9bd75ed7c2d772a65a73b763f7b3a9ca572..e1f1becda52901abeaddccacf433b714d65ceeb1 100644 (file)
@@ -508,6 +508,21 @@ static void test_devmap(unsigned int task, void *data)
        close(fd);
 }
 
+static void test_devmap_hash(unsigned int task, void *data)
+{
+       int fd;
+       __u32 key, value;
+
+       fd = bpf_create_map(BPF_MAP_TYPE_DEVMAP_HASH, sizeof(key), sizeof(value),
+                           2, 0);
+       if (fd < 0) {
+               printf("Failed to create devmap_hash '%s'!\n", strerror(errno));
+               exit(1);
+       }
+
+       close(fd);
+}
+
 static void test_queuemap(unsigned int task, void *data)
 {
        const int MAP_SIZE = 32;
@@ -1684,6 +1699,7 @@ static void run_all_tests(void)
        test_arraymap_percpu_many_keys();
 
        test_devmap(0, NULL);
+       test_devmap_hash(0, NULL);
        test_sockmap(0, NULL);
 
        test_map_large();