diff --git a/0009-fix-procfs-interface.patch b/0009-fix-procfs-interface.patch new file mode 100644 index 0000000000000000000000000000000000000000..694ddbef9359a9a7daba185e971fb8007ffde1b3 --- /dev/null +++ b/0009-fix-procfs-interface.patch @@ -0,0 +1,146 @@ +From 6cb56b2a4e9b19b744f029de0ffb82a24611ee25 Mon Sep 17 00:00:00 2001 +From: wo_cow +Date: Tue, 15 Jul 2025 15:06:14 +0800 +Subject: [PATCH] fix the problem that procfs interface may fail + +--- + ko/bwm.c | 31 ++++++++++++++++--------------- + ko/bwm.h | 3 ++- + 2 files changed, 18 insertions(+), 16 deletions(-) + +diff --git a/ko/bwm.c b/ko/bwm.c +index 8951217..4f66d7d 100644 +--- a/ko/bwm.c ++++ b/ko/bwm.c +@@ -6,9 +6,9 @@ + + static char *envp[] = { "HOME=/", "PATH=/sbin:/usr/sbin:/bin:/usr/bin", NULL }; + +-static ssize_t proc_value_get(const char __user *buffer, unsigned long count, char *value) ++static ssize_t proc_value_get(const char __user *buffer, unsigned long max_buffer, unsigned long count, char *value) + { +- if (count == 0 || count >= MAX_BUF_SIZE) { ++ if (count == 0 || count >= max_buffer) { + return -EINVAL; + } + +@@ -16,8 +16,9 @@ static ssize_t proc_value_get(const char __user *buffer, unsigned long count, ch + return -EINVAL; + } + +- value[count - 1] = '\0'; +- ++ if (value[count - 1] == '\n') { ++ value[count - 1] = '\0'; ++ } + return 0; + } + +@@ -57,7 +58,7 @@ static ssize_t proc_net_qos_enable_write(struct file *file, const char __user *b + char nspid[MAX_BUF_SIZE] = { 0 }; + char cmd[MAX_CMD_LEN] = { 0 }; + +- ret = proc_value_get(buffer, count, nspid); ++ ret = proc_value_get(buffer, MAX_BUF_SIZE, count, nspid); + if (ret != 0) { + BWM_LOG_ERR("proc_value_get failed"); + return count; +@@ -97,7 +98,7 @@ static ssize_t proc_net_qos_disable_write(struct file *file, const char __user * + char nspid[MAX_BUF_SIZE] = { 0 }; + char cmd[MAX_CMD_LEN] = { 0 }; + +- ret = proc_value_get(buffer, count, nspid); ++ ret = proc_value_get(buffer, MAX_BUF_SIZE, count, nspid); + if (ret != 0) { + BWM_LOG_ERR("proc_value_get failed"); + return count; +@@ -137,7 +138,7 @@ static ssize_t proc_net_qos_bandwidth_write(struct file *file, const char __user + char bandwidth[MAX_BUF_SIZE] = { 0 }; + char cmd[MAX_CMD_LEN] = { 0 }; + +- ret = proc_value_get(buffer, count, bandwidth); ++ ret = proc_value_get(buffer, MAX_BUF_SIZE, count, bandwidth); + if (ret != 0) { + BWM_LOG_ERR("proc_value_get failed"); + return count; +@@ -184,7 +185,7 @@ static ssize_t proc_net_qos_waterline_write(struct file *file, const char __user + char waterline[MAX_BUF_SIZE] = { 0 }; + char cmd[MAX_CMD_LEN] = { 0 }; + +- ret = proc_value_get(buffer, count, waterline); ++ ret = proc_value_get(buffer, MAX_BUF_SIZE, count, waterline); + if (ret != 0) { + BWM_LOG_ERR("proc_value_get failed"); + return count; +@@ -231,7 +232,7 @@ static ssize_t proc_net_qos_devs_write(struct file *file, const char __user *buf + char nspid[MAX_BUF_SIZE] = { 0 }; + char cmd[MAX_CMD_LEN] = { 0 }; + +- ret = proc_value_get(buffer, count, nspid); ++ ret = proc_value_get(buffer, MAX_BUF_SIZE, count, nspid); + if (ret != 0) { + BWM_LOG_ERR("proc_value_get failed"); + return count; +@@ -269,15 +270,15 @@ static ssize_t proc_net_qos_devstatus_write(struct file *file, const char __user + unsigned long count, loff_t *ppos) + { + int ret = 0; +- char data[MAX_BUF_SIZE] = { 0 }; ++ char data[MAX_DEVDATA_SIZE] = { 0 }; + +- ret = proc_value_get(buffer, count, data); ++ ret = proc_value_get(buffer, MAX_DEVDATA_SIZE, count, data); + if (ret != 0) { + BWM_LOG_ERR("proc_value_get failed"); + return count; + } + +- ret = snprintf(net_qos_devstatus, MAX_DATA_SIZE, "%s", data); ++ ret = snprintf(net_qos_devstatus, MAX_DEVDATA_SIZE, "%s", data); + if (ret < 0) { + BWM_LOG_ERR("write net_qos_devstatus failed"); + } +@@ -320,9 +321,9 @@ static ssize_t proc_net_qos_stats_write(struct file *file, const char __user *bu + unsigned long count, loff_t *ppos) + { + int ret = 0; +- char stats[MAX_BUF_SIZE] = { 0 }; ++ char stats[MAX_DATA_SIZE] = { 0 }; + +- ret = proc_value_get(buffer, count, stats); ++ ret = proc_value_get(buffer, MAX_DATA_SIZE, count, stats); + if (ret != 0) { + BWM_LOG_ERR("proc_value_get failed"); + return count; +@@ -365,7 +366,7 @@ static ssize_t proc_net_qos_debug_write(struct file *file, const char __user *bu + char debug_mode[MAX_BUF_SIZE] = { 0 }; + unsigned int net_qos_debug_new = net_qos_debug; + +- ret = proc_value_get(buffer, count, debug_mode); ++ ret = proc_value_get(buffer, MAX_BUF_SIZE, count, debug_mode); + if (ret != 0) { + BWM_LOG_ERR("proc_value_get failed"); + return count; +diff --git a/ko/bwm.h b/ko/bwm.h +index 7955b0c..84fcae5 100644 +--- a/ko/bwm.h ++++ b/ko/bwm.h +@@ -23,13 +23,14 @@ + #define MAX_BUF_SIZE 128 + #define MAX_CMD_LEN (256 + NAME_MAX) + #define MAX_DATA_SIZE 1024 ++#define MAX_DEVDATA_SIZE 1024 + + static char net_qos_disable[] = "please write to net_qos_disable to disable qos"; + static char net_qos_enable[] = "please write to net_qos_enable to enable qos"; + static char net_qos_bandwidth[MAX_BUF_SIZE]; + static char net_qos_waterline[MAX_BUF_SIZE]; + static char net_qos_devs[] = "please write to net_qos_devs and read dev status from net_qos_devstatus"; +-static char net_qos_devstatus[MAX_DATA_SIZE]; ++static char net_qos_devstatus[MAX_DEVDATA_SIZE]; + static char net_qos_stats[MAX_DATA_SIZE]; + static char net_qos_version[] = "1.1"; + static unsigned int net_qos_debug = 0; +-- +2.28.0.windows.1 + diff --git a/README.md b/README.md index 42b74b8ef7a99b1c9035aa9d4330676128677fba..db81dbd8dcbfe100284e582b4400cb4e8b6f377a 100644 --- a/README.md +++ b/README.md @@ -143,6 +143,12 @@ enp2s2 : disabled ### proc文件接口说明 +proc接口主要作为编程接口,不建议手动调用。使用proc接口前需要安装bwm.ko + +``` +insmod /lib/modules/bwm/bwm.ko +``` + **接口1** 说明 @@ -153,7 +159,7 @@ enp2s2 : disabled 示例 ``` # 使能对应namespace中网络设备的qos功能 -echo $nspid > /proc/qos/net_qos_enable +echo $pid > /proc/qos/net_qos_enable ``` **接口2** @@ -166,7 +172,7 @@ echo $nspid > /proc/qos/net_qos_enable 示例 ``` # 除能对应namespace中网络设备的qos功能 -echo $nspid > /proc/qos/net_qos_disable +echo $pid > /proc/qos/net_qos_disable ``` **接口3** @@ -204,17 +210,19 @@ cat /proc/qos/net_qos_waterline 说明 ``` 接口5、6为组合接口 -/proc/qos/net_qos_devs:将需要查询的容器对应的nspid输入该接口,该容器网络设备的qos状态将被记录在/proc/qos/net_qos_devstatus中 +/proc/qos/net_qos_devs:将需要查询的容器对应的pid输入该接口,该容器网络设备的qos状态将被记录在/proc/qos/net_qos_devstatus中 /proc/qos/net_qos_devstatus:用于输出/proc/qos/net_qos_devs中对应容器网络设备的qos状态 ``` 示例 ``` -# 输入对应容器环境的nspid,对应容器中网络设备的qos使能状态记录在/proc/qos/net_qos_devstatus中 -echo $nspid > /proc/qos/net_qos_devs +# 输入对应容器进程的pid,对应容器中网络设备的qos使能状态记录在/proc/qos/net_qos_devstatus中 +echo $pid > /proc/qos/net_qos_devs cat /proc/qos/net_qos_devstatus ``` +[^注意:重复查询同一个pid的使能状态也是需要执行5、6接口,若只执行6接口则获取到的状态不是最新]: + **接口7** 说明 @@ -228,6 +236,29 @@ cat /proc/qos/net_qos_devstatus cat /proc/qos/net_qos_stats ``` +**接口8** + +说明 + +``` +/sys/fs/cgroup/net_cls/docker/${CONTAINER_ID}/net_cls.classid:设置/查询容器的网络qos优先级 +``` + +示例 + +``` +# 设置容器优先级为在线 +echo 0 > /sys/fs/cgroup/net_cls/docker/${CONTAINER_ID}/net_cls.classid +# 设置容器优先级为离线 +echo 4294967295 > /sys/fs/cgroup/net_cls/docker/${CONTAINER_ID}/net_cls.classid +# 查看容器优先级 +cat /sys/fs/cgroup/net_cls/docker/${CONTAINER_ID}/net_cls.classid +``` + +[^离线容器优先级为-1,但内核设定net_cls.classid文件不支持写入负数,所以这里写入-1的uint32值4294967295]: + + + ## 使用案例 ### 基本使用案例 diff --git a/oncn-bwm.spec b/oncn-bwm.spec index 4e7f137718980686495e7eb4cd7f48acf423bbca..e6008d3777c78809fbfc21c69824430aa9a7cffe 100644 --- a/oncn-bwm.spec +++ b/oncn-bwm.spec @@ -1,6 +1,6 @@ Name: oncn-bwm Version: 1.1 -Release: 10 +Release: 11 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 @@ -22,6 +22,7 @@ Patch9005: 0005-fix-some-review-issues.patch Patch9006: 0006-fix-input-options-unused-warning.patch Patch9007: 0007-fix-net_qos_stats-warning-when-qos-not-enable.patch Patch9008: 0008-adapt-map-define-for-libbpf-1.2.2.patch +Patch9009: 0009-fix-procfs-interface.patch %description Pod bandwidth management in mixed deployment scenarios of online and offline services @@ -116,6 +117,9 @@ depmod -a %changelog +* Wed Jul 16 2025 wo_cow - 1.1-11 +- fix the problem that procfs interface may fail + * Fri Jan 10 2025 Funda Wang - 1.1-10 - fix build with tighted permissions when installing