1 Star 0 Fork 9

vegbir/lxcfs

forked from src-openEuler/lxcfs 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0012-lxcfs-adapt-4.18-kernel.patch 6.02 KB
一键复制 编辑 原始数据 按行查看 历史
vegbir 提交于 2023-07-27 09:31 . upgrade to 5.0.4
From 60eefa396251acebd02f06538ccee1081dcdcd0d Mon Sep 17 00:00:00 2001
From: vegbir <[email protected]>
Date: Thu, 27 Jul 2023 09:10:52 +0000
Subject: [PATCH 12/15] lxcfs adapt 4.18 kernel
Signed-off-by: vegbir <[email protected]>
---
src/proc_fuse.c | 69 +++++++++++++++++++++----------------------------
1 file changed, 30 insertions(+), 39 deletions(-)
diff --git a/src/proc_fuse.c b/src/proc_fuse.c
index 0dbbefe..392115c 100644
--- a/src/proc_fuse.c
+++ b/src/proc_fuse.c
@@ -686,8 +686,8 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
struct devinfo *container_devinfo = NULL, *ptr = NULL;
struct lxcfs_diskstats stats = {};
/* helper fields */
- uint64_t read_service_time, write_service_time, discard_service_time, read_wait_time,
- write_wait_time, discard_wait_time;
+ uint64_t read_service_time = 0, write_service_time = 0, discard_service_time = 0, read_wait_time = 0,
+ write_wait_time = 0, discard_wait_time = 0, total_ticks = 0;
char *cache = d->buf;
size_t cache_size = d->buflen;
size_t linelen = 0, total_len = 0;
@@ -726,29 +726,15 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
return read_file_fuse("/proc/diskstats", buf, size, d);
}
- ret = cgroup_ops->get_io_merged(cgroup_ops, cg, &io_merged_str);
- if (ret < 0) {
- if (ret == -EOPNOTSUPP)
- return read_file_fuse("/proc/diskstats", buf, size, d);
- }
-
ret = cgroup_ops->get_io_service_bytes(cgroup_ops, cg, &io_service_bytes_str);
if (ret < 0) {
if (ret == -EOPNOTSUPP)
return read_file_fuse("/proc/diskstats", buf, size, d);
}
- ret = cgroup_ops->get_io_wait_time(cgroup_ops, cg, &io_wait_time_str);
- if (ret < 0) {
- if (ret == -EOPNOTSUPP)
- return read_file_fuse("/proc/diskstats", buf, size, d);
- }
-
- ret = cgroup_ops->get_io_service_time(cgroup_ops, cg, &io_service_time_str);
- if (ret < 0) {
- if (ret == -EOPNOTSUPP)
- return read_file_fuse("/proc/diskstats", buf, size, d);
- }
+ cgroup_ops->get_io_merged(cgroup_ops, cg, &io_merged_str);
+ cgroup_ops->get_io_wait_time(cgroup_ops, cg, &io_wait_time_str);
+ cgroup_ops->get_io_service_time(cgroup_ops, cg, &io_service_time_str);
f = fopen_cached("/proc/diskstats", "re", &fopen_cache);
if (!f)
@@ -784,9 +770,11 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
get_blkio_io_value(io_serviced_str, stats.major, stats.minor, "Write", &stats.write);
get_blkio_io_value(io_serviced_str, stats.major, stats.minor, "Discard", &stats.discard);
- get_blkio_io_value(io_merged_str, stats.major, stats.minor, "Read", &stats.read_merged);
- get_blkio_io_value(io_merged_str, stats.major, stats.minor, "Write", &stats.write_merged);
- get_blkio_io_value(io_merged_str, stats.major, stats.minor, "Discard", &stats.discard_merged);
+ if (io_merged_str != NULL) {
+ get_blkio_io_value(io_merged_str, stats.major, stats.minor, "Read", &stats.read_merged);
+ get_blkio_io_value(io_merged_str, stats.major, stats.minor, "Write", &stats.write_merged);
+ get_blkio_io_value(io_merged_str, stats.major, stats.minor, "Discard", &stats.discard_merged);
+ }
get_blkio_io_value(io_service_bytes_str, stats.major, stats.minor, "Read", &stats.read_sectors);
stats.read_sectors = stats.read_sectors / 512;
@@ -795,26 +783,29 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
get_blkio_io_value(io_service_bytes_str, stats.major, stats.minor, "Discard", &stats.discard_sectors);
stats.discard_sectors = stats.discard_sectors / 512;
- get_blkio_io_value(io_service_time_str, stats.major, stats.minor, "Read", &read_service_time);
- read_service_time = read_service_time / 1000000;
- get_blkio_io_value(io_wait_time_str, stats.major, stats.minor, "Read", &read_wait_time);
- read_wait_time = read_wait_time / 1000000;
- stats.read_ticks = read_service_time + read_wait_time;
+ if (io_service_time_str != NULL) {
+ get_blkio_io_value(io_service_time_str, stats.major, stats.minor, "Read", &read_service_time);
+ read_service_time = read_service_time / 1000000;
+ get_blkio_io_value(io_service_time_str, stats.major, stats.minor, "Write", &write_service_time);
+ write_service_time = write_service_time / 1000000;
+ get_blkio_io_value(io_service_time_str, stats.major, stats.minor, "Discard", &discard_service_time);
+ discard_service_time = discard_service_time / 1000000;
+ get_blkio_io_value(io_service_time_str, stats.major, stats.minor, "Total", &total_ticks);
+ }
- get_blkio_io_value(io_service_time_str, stats.major, stats.minor, "Write", &write_service_time);
- write_service_time = write_service_time / 1000000;
- get_blkio_io_value(io_wait_time_str, stats.major, stats.minor, "Write", &write_wait_time);
- write_wait_time = write_wait_time / 1000000;
- stats.write_ticks = write_service_time + write_wait_time;
+ if (io_wait_time_str != NULL) {
+ get_blkio_io_value(io_wait_time_str, stats.major, stats.minor, "Read", &read_wait_time);
+ read_wait_time = read_wait_time / 1000000;
+ get_blkio_io_value(io_wait_time_str, stats.major, stats.minor, "Write", &write_wait_time);
+ write_wait_time = write_wait_time / 1000000;
+ get_blkio_io_value(io_wait_time_str, stats.major, stats.minor, "Discard", &discard_wait_time);
+ discard_wait_time = discard_wait_time / 1000000;
+ }
- get_blkio_io_value(io_service_time_str, stats.major, stats.minor, "Discard", &discard_service_time);
- discard_service_time = discard_service_time / 1000000;
- get_blkio_io_value(io_wait_time_str, stats.major, stats.minor, "Discard", &discard_wait_time);
- discard_wait_time = discard_wait_time / 1000000;
+ stats.read_ticks = read_service_time + read_wait_time;
+ stats.write_ticks = write_service_time + write_wait_time;
stats.discard_ticks = discard_service_time + discard_wait_time;
-
- get_blkio_io_value(io_service_time_str, stats.major, stats.minor, "Total", &stats.total_ticks);
- stats.total_ticks = stats.total_ticks / 1000000;
+ stats.total_ticks = total_ticks / 1000000;
memset(lbuf, 0, sizeof(lbuf));
if (stats.read || stats.write || stats.read_merged || stats.write_merged ||
--
2.41.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/vegbir/lxcfs.git
[email protected]:vegbir/lxcfs.git
vegbir
lxcfs
lxcfs
master

搜索帮助