diff options
| author | David S. Miller <davem@davemloft.net> | 2018-05-07 23:35:08 -0400 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2018-05-07 23:35:08 -0400 |
| commit | 01adc4851a8090b46c7a5ed9cfc4b97e65abfbf4 (patch) | |
| tree | 2ae02593d7139962648dff203f3f9701e34ccbc3 /tools/bpf/bpftool/map.c | |
| parent | 18b338f5f9539512e76fd9ebd4c6ca1a0e159e2b (diff) | |
| parent | e94fa1d93117e7f1eb783dc9cae6c70650944449 (diff) | |
Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next
Minor conflict, a CHECK was placed into an if() statement
in net-next, whilst a newline was added to that CHECK
call in 'net'. Thanks to Daniel for the merge resolution.
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'tools/bpf/bpftool/map.c')
| -rw-r--r-- | tools/bpf/bpftool/map.c | 80 |
1 files changed, 13 insertions, 67 deletions
diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c index a6cdb640a0d7..af6766e956ba 100644 --- a/tools/bpf/bpftool/map.c +++ b/tools/bpf/bpftool/map.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (C) 2017 Netronome Systems, Inc. | 2 | * Copyright (C) 2017-2018 Netronome Systems, Inc. |
| 3 | * | 3 | * |
| 4 | * This software is dual licensed under the GNU General License Version 2, | 4 | * This software is dual licensed under the GNU General License Version 2, |
| 5 | * June 1991 as shown in the file COPYING in the top-level directory of this | 5 | * June 1991 as shown in the file COPYING in the top-level directory of this |
| @@ -34,7 +34,6 @@ | |||
| 34 | /* Author: Jakub Kicinski <kubakici@wp.pl> */ | 34 | /* Author: Jakub Kicinski <kubakici@wp.pl> */ |
| 35 | 35 | ||
| 36 | #include <assert.h> | 36 | #include <assert.h> |
| 37 | #include <ctype.h> | ||
| 38 | #include <errno.h> | 37 | #include <errno.h> |
| 39 | #include <fcntl.h> | 38 | #include <fcntl.h> |
| 40 | #include <stdbool.h> | 39 | #include <stdbool.h> |
| @@ -69,61 +68,6 @@ static const char * const map_type_name[] = { | |||
| 69 | [BPF_MAP_TYPE_CPUMAP] = "cpumap", | 68 | [BPF_MAP_TYPE_CPUMAP] = "cpumap", |
| 70 | }; | 69 | }; |
| 71 | 70 | ||
| 72 | static unsigned int get_possible_cpus(void) | ||
| 73 | { | ||
| 74 | static unsigned int result; | ||
| 75 | char buf[128]; | ||
| 76 | long int n; | ||
| 77 | char *ptr; | ||
| 78 | int fd; | ||
| 79 | |||
| 80 | if (result) | ||
| 81 | return result; | ||
| 82 | |||
| 83 | fd = open("/sys/devices/system/cpu/possible", O_RDONLY); | ||
| 84 | if (fd < 0) { | ||
| 85 | p_err("can't open sysfs possible cpus"); | ||
| 86 | exit(-1); | ||
| 87 | } | ||
| 88 | |||
| 89 | n = read(fd, buf, sizeof(buf)); | ||
| 90 | if (n < 2) { | ||
| 91 | p_err("can't read sysfs possible cpus"); | ||
| 92 | exit(-1); | ||
| 93 | } | ||
| 94 | close(fd); | ||
| 95 | |||
| 96 | if (n == sizeof(buf)) { | ||
| 97 | p_err("read sysfs possible cpus overflow"); | ||
| 98 | exit(-1); | ||
| 99 | } | ||
| 100 | |||
| 101 | ptr = buf; | ||
| 102 | n = 0; | ||
| 103 | while (*ptr && *ptr != '\n') { | ||
| 104 | unsigned int a, b; | ||
| 105 | |||
| 106 | if (sscanf(ptr, "%u-%u", &a, &b) == 2) { | ||
| 107 | n += b - a + 1; | ||
| 108 | |||
| 109 | ptr = strchr(ptr, '-') + 1; | ||
| 110 | } else if (sscanf(ptr, "%u", &a) == 1) { | ||
| 111 | n++; | ||
| 112 | } else { | ||
| 113 | assert(0); | ||
| 114 | } | ||
| 115 | |||
| 116 | while (isdigit(*ptr)) | ||
| 117 | ptr++; | ||
| 118 | if (*ptr == ',') | ||
| 119 | ptr++; | ||
| 120 | } | ||
| 121 | |||
| 122 | result = n; | ||
| 123 | |||
| 124 | return result; | ||
| 125 | } | ||
| 126 | |||
| 127 | static bool map_is_per_cpu(__u32 type) | 71 | static bool map_is_per_cpu(__u32 type) |
| 128 | { | 72 | { |
| 129 | return type == BPF_MAP_TYPE_PERCPU_HASH || | 73 | return type == BPF_MAP_TYPE_PERCPU_HASH || |
| @@ -186,8 +130,7 @@ static int map_parse_fd(int *argc, char ***argv) | |||
| 186 | return -1; | 130 | return -1; |
| 187 | } | 131 | } |
| 188 | 132 | ||
| 189 | static int | 133 | int map_parse_fd_and_info(int *argc, char ***argv, void *info, __u32 *info_len) |
| 190 | map_parse_fd_and_info(int *argc, char ***argv, void *info, __u32 *info_len) | ||
| 191 | { | 134 | { |
| 192 | int err; | 135 | int err; |
| 193 | int fd; | 136 | int fd; |
| @@ -873,23 +816,25 @@ static int do_help(int argc, char **argv) | |||
| 873 | 816 | ||
| 874 | fprintf(stderr, | 817 | fprintf(stderr, |
| 875 | "Usage: %s %s { show | list } [MAP]\n" | 818 | "Usage: %s %s { show | list } [MAP]\n" |
| 876 | " %s %s dump MAP\n" | 819 | " %s %s dump MAP\n" |
| 877 | " %s %s update MAP key [hex] BYTES value [hex] VALUE [UPDATE_FLAGS]\n" | 820 | " %s %s update MAP key DATA value VALUE [UPDATE_FLAGS]\n" |
| 878 | " %s %s lookup MAP key [hex] BYTES\n" | 821 | " %s %s lookup MAP key DATA\n" |
| 879 | " %s %s getnext MAP [key [hex] BYTES]\n" | 822 | " %s %s getnext MAP [key DATA]\n" |
| 880 | " %s %s delete MAP key [hex] BYTES\n" | 823 | " %s %s delete MAP key DATA\n" |
| 881 | " %s %s pin MAP FILE\n" | 824 | " %s %s pin MAP FILE\n" |
| 825 | " %s %s event_pipe MAP [cpu N index M]\n" | ||
| 882 | " %s %s help\n" | 826 | " %s %s help\n" |
| 883 | "\n" | 827 | "\n" |
| 884 | " MAP := { id MAP_ID | pinned FILE }\n" | 828 | " MAP := { id MAP_ID | pinned FILE }\n" |
| 829 | " DATA := { [hex] BYTES }\n" | ||
| 885 | " " HELP_SPEC_PROGRAM "\n" | 830 | " " HELP_SPEC_PROGRAM "\n" |
| 886 | " VALUE := { BYTES | MAP | PROG }\n" | 831 | " VALUE := { DATA | MAP | PROG }\n" |
| 887 | " UPDATE_FLAGS := { any | exist | noexist }\n" | 832 | " UPDATE_FLAGS := { any | exist | noexist }\n" |
| 888 | " " HELP_SPEC_OPTIONS "\n" | 833 | " " HELP_SPEC_OPTIONS "\n" |
| 889 | "", | 834 | "", |
| 890 | bin_name, argv[-2], bin_name, argv[-2], bin_name, argv[-2], | 835 | bin_name, argv[-2], bin_name, argv[-2], bin_name, argv[-2], |
| 891 | bin_name, argv[-2], bin_name, argv[-2], bin_name, argv[-2], | 836 | bin_name, argv[-2], bin_name, argv[-2], bin_name, argv[-2], |
| 892 | bin_name, argv[-2], bin_name, argv[-2]); | 837 | bin_name, argv[-2], bin_name, argv[-2], bin_name, argv[-2]); |
| 893 | 838 | ||
| 894 | return 0; | 839 | return 0; |
| 895 | } | 840 | } |
| @@ -904,6 +849,7 @@ static const struct cmd cmds[] = { | |||
| 904 | { "getnext", do_getnext }, | 849 | { "getnext", do_getnext }, |
| 905 | { "delete", do_delete }, | 850 | { "delete", do_delete }, |
| 906 | { "pin", do_pin }, | 851 | { "pin", do_pin }, |
| 852 | { "event_pipe", do_event_pipe }, | ||
| 907 | { 0 } | 853 | { 0 } |
| 908 | }; | 854 | }; |
| 909 | 855 | ||
