History

bpf: add 'flags' attribute to BPF_MAP_UPDATE_ELEM command

the current meaning of BPF_MAP_UPDATE_ELEM syscall command is: either update existing map element or create a new one. Initially the plan was to add a new command to handle the case of 'create new element if it didn't exist', but 'flags' style looks cleaner and overall diff is much smaller (more code reused), so add 'flags' attribute to BPF_MAP_UPDATE_ELEM command with the following meaning: #define BPF_ANY 0 /* create new element or update existing */ #define BPF_NOEXIST 1 /* create new element if it didn't exist */ #define BPF_EXIST 2 /* update existing element */ bpf_update_elem(fd, key, value, BPF_NOEXIST) call can fail with EEXIST if element already exists. bpf_update_elem(fd, key, value, BPF_EXIST) can fail with ENOENT if element doesn't exist. Userspace will call it as: int bpf_update_elem(int fd, void *key, void *value, __u64 flags) { union bpf_attr attr = { .map_fd = fd, .key = ptr_to_u64(key), .value = ptr_to_u64(value), .flags = flags; }; return bpf(BPF_MAP_UPDATE_ELEM, &attr, sizeof(attr)); } First two bits of 'flags' are used to encode style of bpf_update_elem() command. Bits 2-63 are reserved for future use.

Alexei Starovoitov committed 12 years ago

Commit 3274f521 parent 1bbf1483 files · +10 −4Browse files

Showing the changes to include/uapi/linux (1 of 3 files). Show all

Unified · Split

include/uapi/linux/bpf.h+7−1
@@ -82,7 +82,7 @@ enum bpf_cmd { · 81 unmodified lines
8282
8383 /* create or update key/value pair in a given map
8484 * err = bpf(BPF_MAP_UPDATE_ELEM, union bpf_attr *attr, u32 size)
85− * Using attr->map_fd, attr->key, attr->value
85+ * Using attr->map_fd, attr->key, attr->value, attr->flags
8686 * returns zero or negative error
8787 */
8888 BPF_MAP_UPDATE_ELEM,
@@ -117,6 +117,11 @@ enum bpf_prog_type { · 28 unmodified lines
117117 BPF_PROG_TYPE_UNSPEC,
118118 };
119119
120+/* flags for BPF_MAP_UPDATE_ELEM command */
121+#define BPF_ANY 0 /* create new element or update existing */
122+#define BPF_NOEXIST 1 /* create new element if it didn't exist */
123+#define BPF_EXIST 2 /* update existing element */
124+
120125 union bpf_attr {
121126 struct { /* anonymous struct used by BPF_MAP_CREATE command */
122127 __u32 map_type; /* one of enum bpf_map_type */
@@ -132,6 +137,7 @@ union bpf_attr { · 9 unmodified lines
132137 __aligned_u64 value;
133138 __aligned_u64 next_key;
134139 };
140+ __u64 flags;
135141 };
136142
137143 struct { /* anonymous struct used by BPF_PROG_LOAD command */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t