adapt libbpf-0.8.1: bpf_prog_load_xattr will deprecated and use another way to load bpf prog

(cherry picked from commit f42913126f406711fe3a090c74d7e760926f7326)
This commit is contained in:
JofDiamonds 2023-05-19 16:02:47 +08:00 committed by openeuler-sync-bot
parent 19dac48875
commit b0a75506f2
2 changed files with 17 additions and 47 deletions

View File

@ -1,12 +1,12 @@
From 555072cbb13cb6cb45abb862f2b1a268c0fba660 Mon Sep 17 00:00:00 2001
From 5e488bdb1ebb14cd16e2df640e90e7eb39ff9efa Mon Sep 17 00:00:00 2001
From: JofDiamonds <kwb0523@163.com>
Date: Mon, 17 Apr 2023 19:23:55 +0800
Date: Sat, 20 May 2023 16:38:45 +0800
Subject: [PATCH] adapt libbpf-0.8.1
---
bpf/bwm_prio_kern.c | 14 ++++++-------
bwmcli.c | 51 ++++++++++++++++++++++++++++++---------------
2 files changed, 41 insertions(+), 24 deletions(-)
bpf/bwm_prio_kern.c | 14 +++++++-------
bwmcli.c | 41 +++++++++++++++++++++++++++++------------
2 files changed, 36 insertions(+), 19 deletions(-)
diff --git a/bpf/bwm_prio_kern.c b/bpf/bwm_prio_kern.c
index 1c59322..68127f9 100644
@ -34,15 +34,15 @@ index 1c59322..68127f9 100644
SEC("cgroup_skb/egress")
int _bwm_out_cg(struct __sk_buff *skb)
diff --git a/bwmcli.c b/bwmcli.c
index f087ea6..d9b59ad 100644
index f087ea6..c9fe698 100644
--- a/bwmcli.c
+++ b/bwmcli.c
@@ -212,40 +212,60 @@ static int BreakArgs(char *s, char *arg1, char *arg2, unsigned long arg1Len, uns
@@ -212,40 +212,57 @@ static int BreakArgs(char *s, char *arg1, char *arg2, unsigned long arg1Len, uns
return EXIT_OK;
}
-static int ProgLoad(char *prog, struct bpf_object ** obj, int * bpfprogFd)
+static int ProgLoad(char *prog, int * bpfprogFd)
+static int ProgLoad(char *prog, struct bpf_object **obj, int * bpfprogFd)
{
- struct bpf_prog_load_attr progLoadAttr = {
- .prog_type = BPF_PROG_TYPE_CGROUP_SKB,
@ -53,7 +53,6 @@ index f087ea6..d9b59ad 100644
- };
int mapFd;
struct bpf_map *map = NULL;
+ struct bpf_object *obj = NULL;
+ struct bpf_program *program = NULL;
if (access(prog, O_RDONLY) < 0) {
@ -63,14 +62,13 @@ index f087ea6..d9b59ad 100644
- if (bpf_prog_load_xattr(&progLoadAttr, &(*obj), bpfprogFd)) {
- BWM_LOG_ERR("ERROR: bpf_prog_load_xattr failed for: %s. errno:%d\n", prog, errno);
+
+ obj = bpf_object__open(prog);
+ if (libbpf_get_error(obj)) {
+ *obj = bpf_object__open(prog);
+ if (libbpf_get_error(*obj)) {
+ BWM_LOG_ERR("ERROR: bpf_object__open failed for: %s. errno:%d\n", prog, errno);
return -1;
}
- map = bpf_object__find_map_by_name(*obj, "cgrp_prio");
+ program = bpf_object__next_program(obj, NULL);
+ program = bpf_object__next_program(*obj, NULL);
+ if (!program) {
+ BWM_LOG_ERR("ERROR: bpf_object__next_program failed for: %s. errno:%d\n", prog, errno);
+ goto err;
@ -78,7 +76,7 @@ index f087ea6..d9b59ad 100644
+
+ bpf_program__set_type(program, BPF_PROG_TYPE_CGROUP_SKB);
+
+ if (bpf_object__load(obj)) {
+ if (bpf_object__load(*obj)) {
+ BWM_LOG_ERR("ERROR: bpf_object__load failed for: %s. errno:%d\n", prog, errno);
+ goto err;
+ }
@ -89,7 +87,7 @@ index f087ea6..d9b59ad 100644
+ goto err;
+ }
+
+ map = bpf_object__find_map_by_name(obj, "cgrp_prio");
map = bpf_object__find_map_by_name(*obj, "cgrp_prio");
if (!map) {
BWM_LOG_ERR("Failed to load map cgrp_prio from bpf prog. errno:%d\n", errno);
- return -1;
@ -103,43 +101,12 @@ index f087ea6..d9b59ad 100644
+ goto err;
}
+ bpf_object__close(obj);
return mapFd;
+err:
+ bpf_object__close(obj);
+ return -1;
}
static int GetMapFdByProgId(__u32 progId)
@@ -377,7 +397,6 @@ static int CgrpV2PrioSet(const char *cgrpPath, int prio)
int key = 0;
int cgFd;
int mapFd;
- struct bpf_object *obj = NULL;
int bpfprogFd;
cgFd = open(cgrpPath, O_RDONLY);
@@ -392,7 +411,7 @@ static int CgrpV2PrioSet(const char *cgrpPath, int prio)
return EXIT_FAIL;
}
- mapFd = ProgLoad(CGRP_PRIO_PROG, &obj, &bpfprogFd);
+ mapFd = ProgLoad(CGRP_PRIO_PROG, &bpfprogFd);
if (mapFd == -1) {
goto err;
}
@@ -416,11 +435,9 @@ static int CgrpV2PrioSet(const char *cgrpPath, int prio)
BWM_LOG_INFO("set prio success\n");
(void)close(cgFd);
- bpf_object__close(obj);
return EXIT_OK;
err:
(void)close(cgFd);
- bpf_object__close(obj);
return EXIT_FAIL_BPF;
}
--
2.33.0

View File

@ -1,6 +1,6 @@
Name: oncn-bwm
Version: 1.1
Release: 2
Release: 3
Summary: Pod bandwidth management in mixed deployment scenarios of online and offline services
License: GPL-2.0
URL: https://gitee.com/src-openeuler/oncn-bwm
@ -111,6 +111,9 @@ depmod -a
%changelog
* Fri May 19 2023 JofDiamonds <kwb0523@163.com> - 1.1-3
- adapt libbpf-0.8.1: prog_load_xattr will deprecated and use another way to load bpf prog
* Mon Apr 17 2023 JofDiamonds <kwb0523@163.com> - 1.1-2
- add proc file interface