mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-31 06:15:24 +00:00
bpf: update deprecated API
bpf_create_map_xattr() has been replaced with bpf_map_create() https://github.com/libbpf/libbpf/commit/6cfb97c DECLARE_LIBBPF_OPTS has been renamed to LIBBPF_OPTS https://github.com/libbpf/libbpf/commit/ea6c242 Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
This commit is contained in:
committed by
Andrei Vagin
parent
f641e0c4ba
commit
d40b332cef
@@ -1,5 +1,4 @@
|
||||
#include <stdio.h>
|
||||
#include <linux/bpf.h>
|
||||
#include <bpf/bpf.h>
|
||||
|
||||
#include "common/compiler.h"
|
||||
@@ -12,6 +11,11 @@
|
||||
|
||||
#include "protobuf.h"
|
||||
|
||||
#ifndef LIBBPF_OPTS
|
||||
#define LIBBPF_OPTS DECLARE_LIBBPF_OPTS
|
||||
#define LEGACY_LIBBPF /* Using libbpf < 0.7 */
|
||||
#endif
|
||||
|
||||
int is_bpfmap_link(char *link)
|
||||
{
|
||||
return is_anon_link_type(link, "bpf-map");
|
||||
@@ -66,7 +70,7 @@ int restore_bpfmap_data(int map_fd, uint32_t map_id, struct bpfmap_data_rst **bp
|
||||
void *keys = NULL;
|
||||
void *values = NULL;
|
||||
unsigned int count;
|
||||
DECLARE_LIBBPF_OPTS(bpf_map_batch_opts, opts, .elem_flags = 0, .flags = 0, );
|
||||
LIBBPF_OPTS(bpf_map_batch_opts, opts);
|
||||
|
||||
for (map_data = bpf_hash_table[map_id & BPFMAP_DATA_HASH_MASK]; map_data != NULL; map_data = map_data->next) {
|
||||
if (map_data->bde->map_id == map_id)
|
||||
@@ -149,7 +153,7 @@ int dump_one_bpfmap_data(BpfmapFileEntry *bpf, int lfd, const struct fd_parms *p
|
||||
void *keys = NULL, *values = NULL;
|
||||
void *in_batch = NULL, *out_batch = NULL;
|
||||
BpfmapDataEntry bde = BPFMAP_DATA_ENTRY__INIT;
|
||||
DECLARE_LIBBPF_OPTS(bpf_map_batch_opts, opts, .elem_flags = 0, .flags = 0, );
|
||||
LIBBPF_OPTS(bpf_map_batch_opts, opts);
|
||||
int ret;
|
||||
|
||||
key_size = bpf->key_size;
|
||||
@@ -216,9 +220,14 @@ static int dump_one_bpfmap(int lfd, u32 id, const struct fd_parms *p)
|
||||
{
|
||||
BpfmapFileEntry bpf = BPFMAP_FILE_ENTRY__INIT;
|
||||
FileEntry fe = FILE_ENTRY__INIT;
|
||||
struct bpf_map_info map_info;
|
||||
uint32_t info_len = sizeof(struct bpf_map_info);
|
||||
int ret;
|
||||
/* If we are using a bigger struct than the kernel knows of,
|
||||
* ensure all the unknown bits are 0 - i.e. new user-space
|
||||
* does not rely on any unknown kernel feature extensions.
|
||||
* https://github.com/torvalds/linux/blob/a1994480/kernel/bpf/syscall.c#L70
|
||||
*/
|
||||
struct bpf_map_info map_info = {};
|
||||
uint32_t info_len = sizeof(struct bpf_map_info);
|
||||
|
||||
if (parse_fdinfo(lfd, FD_TYPES__BPFMAP, &bpf))
|
||||
return -1;
|
||||
@@ -266,12 +275,19 @@ static int bpfmap_open(struct file_desc *d, int *new_fd)
|
||||
{
|
||||
struct bpfmap_file_info *info;
|
||||
BpfmapFileEntry *bpfe;
|
||||
struct bpf_create_map_attr xattr;
|
||||
int bpfmap_fd;
|
||||
#ifdef LEGACY_LIBBPF
|
||||
struct bpf_create_map_attr xattr;
|
||||
#else
|
||||
LIBBPF_OPTS(bpf_map_create_opts, bpfmap_opts);
|
||||
#endif
|
||||
|
||||
info = container_of(d, struct bpfmap_file_info, d);
|
||||
bpfe = info->bpfe;
|
||||
|
||||
pr_info_bpfmap("Creating and opening ", bpfe);
|
||||
|
||||
#ifdef LEGACY_LIBBPF
|
||||
xattr.name = xstrdup(bpfe->map_name);
|
||||
xattr.map_type = bpfe->map_type;
|
||||
xattr.map_flags = bpfe->map_flags;
|
||||
@@ -285,8 +301,17 @@ static int bpfmap_open(struct file_desc *d, int *new_fd)
|
||||
xattr.map_ifindex = bpfe->ifindex;
|
||||
xattr.inner_map_fd = 0;
|
||||
|
||||
pr_info_bpfmap("Creating and opening ", bpfe);
|
||||
bpfmap_fd = bpf_create_map_xattr(&xattr);
|
||||
#else
|
||||
bpfmap_opts.map_flags = bpfe->map_flags;
|
||||
bpfmap_opts.map_ifindex = bpfe->ifindex;
|
||||
if (bpfe->has_map_extra)
|
||||
bpfmap_opts.map_extra = bpfe->map_extra;
|
||||
|
||||
bpfmap_fd = bpf_map_create(bpfe->map_type, bpfe->map_name, bpfe->key_size, bpfe->value_size, bpfe->max_entries,
|
||||
&bpfmap_opts);
|
||||
#endif
|
||||
|
||||
if (bpfmap_fd < 0) {
|
||||
pr_perror("Can't create bpfmap %#08x", bpfe->id);
|
||||
return -1;
|
||||
|
@@ -1,10 +1,14 @@
|
||||
#include <linux/bpf.h>
|
||||
#include <bpf/bpf.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include "zdtmtst.h"
|
||||
#include "bpfmap_zdtm.h"
|
||||
|
||||
#ifndef LIBBPF_OPTS
|
||||
#define LIBBPF_OPTS DECLARE_LIBBPF_OPTS
|
||||
#define LEGACY_LIBBPF /* Using libbpf < 0.7 */
|
||||
#endif
|
||||
|
||||
const char *test_doc = "Check that data and meta-data for BPF_MAP_TYPE_ARRAY"
|
||||
"is correctly restored";
|
||||
const char *test_author = "Abhishek Vijeev <abhishek.vijeev@gmail.com>";
|
||||
@@ -12,7 +16,7 @@ const char *test_author = "Abhishek Vijeev <abhishek.vijeev@gmail.com>";
|
||||
static int map_batch_update(int map_fd, uint32_t max_entries, int *keys, int *values)
|
||||
{
|
||||
int i, ret;
|
||||
DECLARE_LIBBPF_OPTS(bpf_map_batch_opts, opts, .elem_flags = 0, .flags = 0, );
|
||||
LIBBPF_OPTS(bpf_map_batch_opts, opts);
|
||||
|
||||
for (i = 0; i < max_entries; i++) {
|
||||
keys[i] = i;
|
||||
@@ -61,6 +65,8 @@ int main(int argc, char **argv)
|
||||
struct bpfmap_fdinfo_obj old_fdinfo = {};
|
||||
struct bpfmap_fdinfo_obj new_fdinfo = {};
|
||||
uint32_t info_len = sizeof(struct bpf_map_info);
|
||||
|
||||
#ifdef LEGACY_LIBBPF
|
||||
struct bpf_create_map_attr xattr = {
|
||||
.name = "array_test_map",
|
||||
.map_type = BPF_MAP_TYPE_ARRAY,
|
||||
@@ -69,7 +75,10 @@ int main(int argc, char **argv)
|
||||
.max_entries = max_entries,
|
||||
.map_flags = BPF_F_NUMA_NODE,
|
||||
};
|
||||
DECLARE_LIBBPF_OPTS(bpf_map_batch_opts, opts, .elem_flags = 0, .flags = 0, );
|
||||
#else
|
||||
LIBBPF_OPTS(bpf_map_create_opts, bpf_mapfd_opts, .map_flags = BPF_F_NUMA_NODE);
|
||||
#endif
|
||||
LIBBPF_OPTS(bpf_map_batch_opts, opts);
|
||||
|
||||
keys = mmap(NULL, max_entries * sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0);
|
||||
values = mmap(NULL, max_entries * sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0);
|
||||
@@ -82,7 +91,13 @@ int main(int argc, char **argv)
|
||||
|
||||
test_init(argc, argv);
|
||||
|
||||
#ifdef LEGACY_LIBBPF
|
||||
map_fd = bpf_create_map_xattr(&xattr);
|
||||
#else
|
||||
map_fd = bpf_map_create(BPF_MAP_TYPE_ARRAY, "array_test_map", sizeof(int), sizeof(int), max_entries,
|
||||
&bpf_mapfd_opts);
|
||||
#endif
|
||||
|
||||
if (map_fd == -1) {
|
||||
pr_perror("Can't create BPF map");
|
||||
goto err;
|
||||
|
@@ -1,10 +1,14 @@
|
||||
#include <linux/bpf.h>
|
||||
#include <bpf/bpf.h>
|
||||
#include <sys/mman.h>
|
||||
#include <bpf/bpf.h>
|
||||
|
||||
#include "zdtmtst.h"
|
||||
#include "bpfmap_zdtm.h"
|
||||
|
||||
#ifndef LIBBPF_OPTS
|
||||
#define LIBBPF_OPTS DECLARE_LIBBPF_OPTS
|
||||
#define LEGACY_LIBBPF /* Using libbpf < 0.7 */
|
||||
#endif
|
||||
|
||||
const char *test_doc = "Check that data and meta-data for BPF_MAP_TYPE_HASH"
|
||||
"is correctly restored";
|
||||
const char *test_author = "Abhishek Vijeev <abhishek.vijeev@gmail.com>";
|
||||
@@ -12,7 +16,7 @@ const char *test_author = "Abhishek Vijeev <abhishek.vijeev@gmail.com>";
|
||||
static int map_batch_update(int map_fd, uint32_t max_entries, int *keys, int *values)
|
||||
{
|
||||
int ret;
|
||||
DECLARE_LIBBPF_OPTS(bpf_map_batch_opts, opts, .elem_flags = 0, .flags = 0, );
|
||||
LIBBPF_OPTS(bpf_map_batch_opts, opts);
|
||||
|
||||
for (int i = 0; i < max_entries; i++) {
|
||||
keys[i] = i + 1;
|
||||
@@ -59,6 +63,8 @@ int main(int argc, char **argv)
|
||||
struct bpfmap_fdinfo_obj old_fdinfo = {};
|
||||
struct bpfmap_fdinfo_obj new_fdinfo = {};
|
||||
uint32_t info_len = sizeof(struct bpf_map_info);
|
||||
|
||||
#ifdef LEGACY_LIBBPF
|
||||
struct bpf_create_map_attr xattr = {
|
||||
.name = "hash_test_map",
|
||||
.map_type = BPF_MAP_TYPE_HASH,
|
||||
@@ -67,7 +73,10 @@ int main(int argc, char **argv)
|
||||
.max_entries = max_entries,
|
||||
.map_flags = BPF_F_NO_PREALLOC | BPF_F_NUMA_NODE,
|
||||
};
|
||||
DECLARE_LIBBPF_OPTS(bpf_map_batch_opts, opts, .elem_flags = 0, .flags = 0, );
|
||||
#else
|
||||
LIBBPF_OPTS(bpf_map_create_opts, bpf_mapfd_opts, .map_flags = BPF_F_NO_PREALLOC | BPF_F_NUMA_NODE);
|
||||
#endif
|
||||
LIBBPF_OPTS(bpf_map_batch_opts, opts);
|
||||
|
||||
keys = mmap(NULL, max_entries * sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0);
|
||||
values = mmap(NULL, max_entries * sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0);
|
||||
@@ -80,7 +89,12 @@ int main(int argc, char **argv)
|
||||
|
||||
test_init(argc, argv);
|
||||
|
||||
#ifdef LEGACY_LIBBPF
|
||||
map_fd = bpf_create_map_xattr(&xattr);
|
||||
#else
|
||||
map_fd = bpf_map_create(BPF_MAP_TYPE_HASH, "hash_test_map", sizeof(int), sizeof(int), max_entries,
|
||||
&bpf_mapfd_opts);
|
||||
#endif
|
||||
if (!map_fd) {
|
||||
pr_perror("Can't create BPF map");
|
||||
goto err;
|
||||
|
Reference in New Issue
Block a user